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;
_polygon_output = false;
_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;
}
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;
}
@ -850,15 +868,24 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
}
MMatrix mat = matrix.asMatrix();
MMatrix ident_mat;
ident_mat.setToIdentity();
LMatrix4d m4d(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]);
if (!mat.isEquivalent(ident_mat, 0.0001)) {
egg_group->set_transform
(LMatrix4d(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]));
// Now convert the matrix to the local frame.
mat = dag_path.inclusiveMatrix(&status);
if (!status) {
status.perror("Can't get coordinate space for matrix");
return;
}
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->set_group_type(EggGroup::GT_instance);
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;
}
////////////////////////////////////////////////////////////////////
// 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;
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);
add_option
("notrans", "", 0,
"Don't convert explicit DAG transformations given in the Maya file. "
"Instead, convert all vertices to world space and write the file as "
"one big transform space. Using this option doesn't change the "
"position of objects in the scene, just the number of explicit "
"transforms appearing in the resulting egg file.",
&MayaToEgg::dispatch_none, &_ignore_transforms);
("trans", "type", 0,
"Specifies which transforms in the Maya file should be converted to "
"transforms in the egg file. The option may be one of all, model, "
"dcs, or none. The default is model, which means only transforms on "
"nodes that have the model flag or the dcs flag are preserved.",
&MayaToEgg::dispatch_transform_type, NULL, &_transform_type);
add_option
("v", "", 0,
"Increase verbosity. More v's means more verbose.",
&MayaToEgg::dispatch_count, NULL, &_verbose);
_polygon_tolerance = 0.01;
_verbose = 0;
_polygon_tolerance = 0.01;
_transform_type = MayaToEggConverter::TT_model;
}
////////////////////////////////////////////////////////////////////
@ -108,7 +108,7 @@ run() {
// Copy in the command-line parameters.
converter._polygon_output = _polygon_output;
converter._polygon_tolerance = _polygon_tolerance;
converter._ignore_transforms = _ignore_transforms;
converter._transform_type = _transform_type;
// Copy in the path and animation parameters.
apply_parameters(converter);
@ -139,6 +139,25 @@ run() {
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[]) {
MayaToEgg prog;

View File

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