support decals properly

This commit is contained in:
David Rose 2003-04-09 22:35:05 +00:00
parent 27fc54e678
commit 6f7dc609e6
4 changed files with 118 additions and 21 deletions

View File

@ -86,7 +86,7 @@ MayaToEggConverter(const string &program_name) :
_from_selection = false; _from_selection = false;
_polygon_output = false; _polygon_output = false;
_polygon_tolerance = 0.01; _polygon_tolerance = 0.01;
_ignore_transforms = false; _transform_type = TT_model;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -816,7 +816,25 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
return; return;
} }
if (_ignore_transforms) { switch (_transform_type) {
case TT_all:
break;
case TT_model:
if (!egg_group->get_model_flag() &&
!egg_group->get_dcs_flag()) {
return;
}
break;
case TT_dcs:
if (!egg_group->get_dcs_flag()) {
return;
}
break;
case TT_none:
case TT_invalid:
return; return;
} }
@ -850,15 +868,24 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
} }
MMatrix mat = matrix.asMatrix(); MMatrix mat = matrix.asMatrix();
MMatrix ident_mat; LMatrix4d m4d(mat[0][0], mat[0][1], mat[0][2], mat[0][3],
ident_mat.setToIdentity(); mat[1][0], mat[1][1], mat[1][2], mat[1][3],
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
if (!mat.isEquivalent(ident_mat, 0.0001)) { // Now convert the matrix to the local frame.
egg_group->set_transform mat = dag_path.inclusiveMatrix(&status);
(LMatrix4d(mat[0][0], mat[0][1], mat[0][2], mat[0][3], if (!status) {
mat[1][0], mat[1][1], mat[1][2], mat[1][3], status.perror("Can't get coordinate space for matrix");
mat[2][0], mat[2][1], mat[2][2], mat[2][3], return;
mat[3][0], mat[3][1], mat[3][2], mat[3][3])); }
LMatrix4d n2w(mat[0][0], mat[0][1], mat[0][2], mat[0][3],
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
m4d = m4d * n2w * egg_group->get_node_frame_inv();
if (!m4d.almost_equal(LMatrix4d::ident_mat(), 0.0001)) {
egg_group->set_transform(m4d);
} }
} }
@ -1658,6 +1685,22 @@ r_get_egg_group(const string &name, const MDagPath &dag_path,
egg_group->remove_object_type("billboard"); egg_group->remove_object_type("billboard");
egg_group->set_group_type(EggGroup::GT_instance); egg_group->set_group_type(EggGroup::GT_instance);
egg_group->set_billboard_type(EggGroup::BT_axis); egg_group->set_billboard_type(EggGroup::BT_axis);
} else if (egg_group->has_object_type("billboard-point")) {
egg_group->remove_object_type("billboard-point");
egg_group->set_group_type(EggGroup::GT_instance);
egg_group->set_billboard_type(EggGroup::BT_point_camera_relative);
}
// We also treat the object type "dcs" and "model" as a special
// case, so we can test for these flags later.
if (egg_group->has_object_type("dcs")) {
egg_group->remove_object_type("dcs");
egg_group->set_dcs_flag(true);
}
if (egg_group->has_object_type("model")) {
egg_group->remove_object_type("model");
egg_group->set_model_flag(true);
} }
} }
@ -1861,3 +1904,24 @@ reparent_decals(EggGroupNode *egg_parent) {
return okflag; return okflag;
} }
////////////////////////////////////////////////////////////////////
// Function: MayaShader::string_transform_type
// Access: Public, Static
// Description: Returns the TransformType value corresponding to the
// indicated string, or TT_invalid.
////////////////////////////////////////////////////////////////////
MayaToEggConverter::TransformType MayaToEggConverter::
string_transform_type(const string &arg) {
if (cmp_nocase(arg, "all") == 0) {
return TT_all;
} else if (cmp_nocase(arg, "model") == 0) {
return TT_model;
} else if (cmp_nocase(arg, "dcs") == 0) {
return TT_dcs;
} else if (cmp_nocase(arg, "none") == 0) {
return TT_none;
} else {
return TT_invalid;
}
}

View File

@ -138,7 +138,17 @@ public:
bool _polygon_output; bool _polygon_output;
double _polygon_tolerance; double _polygon_tolerance;
bool _ignore_transforms;
enum TransformType {
TT_invalid,
TT_all,
TT_model,
TT_dcs,
TT_none,
};
TransformType _transform_type;
static TransformType string_transform_type(const string &arg);
}; };

View File

@ -55,21 +55,21 @@ MayaToEgg() :
&MayaToEgg::dispatch_double, NULL, &_polygon_tolerance); &MayaToEgg::dispatch_double, NULL, &_polygon_tolerance);
add_option add_option
("notrans", "", 0, ("trans", "type", 0,
"Don't convert explicit DAG transformations given in the Maya file. " "Specifies which transforms in the Maya file should be converted to "
"Instead, convert all vertices to world space and write the file as " "transforms in the egg file. The option may be one of all, model, "
"one big transform space. Using this option doesn't change the " "dcs, or none. The default is model, which means only transforms on "
"position of objects in the scene, just the number of explicit " "nodes that have the model flag or the dcs flag are preserved.",
"transforms appearing in the resulting egg file.", &MayaToEgg::dispatch_transform_type, NULL, &_transform_type);
&MayaToEgg::dispatch_none, &_ignore_transforms);
add_option add_option
("v", "", 0, ("v", "", 0,
"Increase verbosity. More v's means more verbose.", "Increase verbosity. More v's means more verbose.",
&MayaToEgg::dispatch_count, NULL, &_verbose); &MayaToEgg::dispatch_count, NULL, &_verbose);
_polygon_tolerance = 0.01;
_verbose = 0; _verbose = 0;
_polygon_tolerance = 0.01;
_transform_type = MayaToEggConverter::TT_model;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -108,7 +108,7 @@ run() {
// Copy in the command-line parameters. // Copy in the command-line parameters.
converter._polygon_output = _polygon_output; converter._polygon_output = _polygon_output;
converter._polygon_tolerance = _polygon_tolerance; converter._polygon_tolerance = _polygon_tolerance;
converter._ignore_transforms = _ignore_transforms; converter._transform_type = _transform_type;
// Copy in the path and animation parameters. // Copy in the path and animation parameters.
apply_parameters(converter); apply_parameters(converter);
@ -139,6 +139,25 @@ run() {
nout << "\n"; nout << "\n";
} }
////////////////////////////////////////////////////////////////////
// Function: MayaToEgg::dispatch_transform_type
// Access: Protected, Static
// Description: Dispatches a parameter that expects a
// MayaToEggConverter::TransformType option.
////////////////////////////////////////////////////////////////////
bool MayaToEgg::
dispatch_transform_type(const string &opt, const string &arg, void *var) {
MayaToEggConverter::TransformType *ip = (MayaToEggConverter::TransformType *)var;
(*ip) = MayaToEggConverter::string_transform_type(arg);
if ((*ip) == MayaToEggConverter::TT_invalid) {
nout << "Invalid type for -" << opt << ": " << arg << "\n"
<< "Valid types are all, model, dcs, and none.\n";
return false;
}
return true;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
MayaToEgg prog; MayaToEgg prog;

View File

@ -21,6 +21,7 @@
#include "pandatoolbase.h" #include "pandatoolbase.h"
#include "somethingToEgg.h" #include "somethingToEgg.h"
#include "mayaToEggConverter.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : MayaToEgg // Class : MayaToEgg
@ -32,10 +33,13 @@ public:
void run(); void run();
protected:
static bool dispatch_transform_type(const string &opt, const string &arg, void *var);
int _verbose; int _verbose;
bool _polygon_output; bool _polygon_output;
double _polygon_tolerance; double _polygon_tolerance;
bool _ignore_transforms; MayaToEggConverter::TransformType _transform_type;
}; };
#endif #endif