added a subroot option to maya2egg and a omittex option to mayacopy

This commit is contained in:
Asad M. Zaman 2006-07-06 21:02:53 +00:00
parent 70fef33162
commit 29fcabab5c
7 changed files with 91 additions and 5 deletions

View File

@ -370,7 +370,9 @@ check_pseudo_joints(bool joint_above) {
if (all_joints) {
// Finally, if all children are joints, then we are too.
if (_joint_type == JT_joint_parent) {
_joint_type = JT_pseudo_joint;
if (!get_name().empty()) { // make sure parent of root is not a joint
_joint_type = JT_pseudo_joint;
}
}
}
}

View File

@ -71,12 +71,13 @@ build_node(const MDagPath &dag_path) {
////////////////////////////////////////////////////////////////////
// Function: MayaNodeTree::build_hierarchy
// Access: Public
// Description: Walks through the complete Maya hierarchy and builds
// Description: Walks through the complete Maya hierarchy if subroot
// is empty() else walks from the subroot down and builds
// up the corresponding tree, but does not tag any nodes
// for conversion.
////////////////////////////////////////////////////////////////////
bool MayaNodeTree::
build_hierarchy() {
build_hierarchy(const string &subroot) {
MStatus status;
MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status);
@ -85,6 +86,33 @@ build_hierarchy() {
return false;
}
// if a subtree is specified ignore other nodes until the subtree
if (!subroot.empty()){
mayaegg_cat.info() << "subroot name: " << subroot << endl;
while (!dag_iterator.isDone()) {
string node_name;
string path = dag_iterator.fullPathName(&status).asChar();
if (!status) {
status.perror("MItDag::getPath");
} else {
size_t bar = path.rfind("|");
if (bar != string::npos) {
node_name = path.substr(bar + 1);
if (node_name == subroot) {
mayaegg_cat.info() << "node name: " << node_name << endl;
status = dag_iterator.reset(dag_iterator.item(),MItDag::kDepthFirst, MFn::kTransform);
if (!status) {
status.perror("MItDag constructor");
return false;
}
break;
}
}
}
dag_iterator.next();
}
}
// Get the entire Maya scene.
// This while loop walks through the entire Maya hierarchy, one
@ -588,12 +616,16 @@ r_build_node(const string &path) {
string parent_path, local_name;
if (bar != string::npos) {
parent_path = path.substr(0, bar);
//mayaegg_cat.info() << "parent_path: " << parent_path << endl;
local_name = path.substr(bar + 1);
} else {
local_name = path;
}
//mayaegg_cat.info() << "local_name: " << local_name << endl;
MayaNodeDesc *parent_node_desc = r_build_node(parent_path);
if (parent_node_desc == (MayaNodeDesc *)NULL)
mayaegg_cat.info() << "empty parent: " << local_name << endl;
node_desc = new MayaNodeDesc(this, parent_node_desc, local_name);
_nodes.push_back(node_desc);
}

View File

@ -44,7 +44,7 @@ class MayaNodeTree {
public:
MayaNodeTree(MayaToEggConverter *converter);
MayaNodeDesc *build_node(const MDagPath &dag_path);
bool build_hierarchy();
bool build_hierarchy(const string &subroot);
void tag_all();
bool tag_selected();

View File

@ -111,6 +111,7 @@ MayaToEggConverter(const MayaToEggConverter &copy) :
_subsets(copy._subsets),
_ignore_sliders(copy._ignore_sliders),
_force_joints(copy._force_joints),
_subroot(copy._subroot),
_tree(this),
_maya(copy._maya),
_polygon_output(copy._polygon_output),
@ -213,6 +214,19 @@ convert_file(const Filename &filename) {
return convert_maya();
}
////////////////////////////////////////////////////////////////////
// Function: MayaToEggConverter::set_subroot
// Access: Public
// Description: Sets a name pattern to the subroot node. If
// the subroot node is not empty, then only the
// subroot node in the maya file will be
// converted.
////////////////////////////////////////////////////////////////////
void MayaToEggConverter::
set_subroot(const string &subroot) {
_subroot = subroot;
}
////////////////////////////////////////////////////////////////////
// Function: MayaToEggConverter::clear_subsets
// Access: Public
@ -414,7 +428,7 @@ convert_maya() {
frame_inc = frame_inc * input_frame_rate / output_frame_rate;
bool all_ok = _tree.build_hierarchy();
bool all_ok = _tree.build_hierarchy(_subroot);
if (all_ok) {
if (_from_selection) {
@ -907,6 +921,28 @@ process_model_node(MayaNodeDesc *node_desc) {
get_transform(node_desc, dag_path, egg_group);
make_locator(dag_path, dag_node, egg_group);
}
} else if (dag_path.hasFn(MFn::kCamera)) {
MFnCamera camera (dag_path, &status);
if ( !status ) {
status.perror("MFnCamera constructor");
mayaegg_cat.error() << "camera extraction failed" << endl;
return false;
}
// Extract some interesting Camera data
mayaegg_cat.info() << " eyePoint: "
<< camera.eyePoint(MSpace::kWorld) << endl;
mayaegg_cat.info() << " upDirection: "
<< camera.upDirection(MSpace::kWorld) << endl;
mayaegg_cat.info() << " viewDirection: "
<< camera.viewDirection(MSpace::kWorld) << endl;
mayaegg_cat.info() << " aspectRatio: " << camera.aspectRatio() << endl;
mayaegg_cat.info() << " horizontalFilmAperture: "
<< camera.horizontalFilmAperture() << endl;
mayaegg_cat.info() << " verticalFilmAperture: "
<< camera.verticalFilmAperture() << endl;
} else {
// Just a generic node.
if (_animation_convert == AC_none) {

View File

@ -80,6 +80,8 @@ public:
virtual bool convert_file(const Filename &filename);
virtual DistanceUnit get_input_units();
void set_subroot(const string &subroot);
void clear_subsets();
void add_subset(const GlobPattern &glob);
@ -160,6 +162,7 @@ private:
vector_string _tex_names;
bool _from_selection;
string _subroot;
typedef pvector<GlobPattern> Globs;
Globs _subsets;
Globs _ignore_sliders;

View File

@ -84,6 +84,16 @@ MayaToEgg() :
"nodes that have the model flag or the dcs flag are preserved.",
&MayaToEgg::dispatch_transform_type, NULL, &_transform_type);
add_option
("subroot", "name", 0,
"Specifies that only a subroot of the hierarchy in the Maya file should "
"be converted; specifically, the animation under the node or nodes whose "
"name matches the parameter (which may include globbing characters "
"like * or ?). This parameter may not be repeated multiple times to name "
"multiple roots. If it is omitted altogether, the entire file is "
"converted.",
&MayaToEgg::dispatch_string, NULL, &_subroot);
add_option
("subset", "name", 0,
"Specifies that only a subset of the geometry in the Maya file should "
@ -166,6 +176,8 @@ run() {
converter._always_show_vertex_color = !_suppress_vertex_color;
converter._transform_type = _transform_type;
converter.set_subroot(_subroot);
vector_string::const_iterator si;
if (!_subsets.empty()) {
converter.clear_subsets();

View File

@ -42,6 +42,7 @@ protected:
bool _respect_maya_double_sided;
bool _suppress_vertex_color;
MayaToEggConverter::TransformType _transform_type;
string _subroot;
vector_string _subsets;
vector_string _ignore_sliders;
vector_string _force_joints;