diff --git a/pandatool/src/mayaegg/mayaNodeDesc.cxx b/pandatool/src/mayaegg/mayaNodeDesc.cxx index 5dffa09725..72d6ca0c8d 100755 --- a/pandatool/src/mayaegg/mayaNodeDesc.cxx +++ b/pandatool/src/mayaegg/mayaNodeDesc.cxx @@ -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; + } } } } diff --git a/pandatool/src/mayaegg/mayaNodeTree.cxx b/pandatool/src/mayaegg/mayaNodeTree.cxx index 5c1ebcc0c2..a51142102a 100755 --- a/pandatool/src/mayaegg/mayaNodeTree.cxx +++ b/pandatool/src/mayaegg/mayaNodeTree.cxx @@ -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); } diff --git a/pandatool/src/mayaegg/mayaNodeTree.h b/pandatool/src/mayaegg/mayaNodeTree.h index d07e541866..77973db803 100755 --- a/pandatool/src/mayaegg/mayaNodeTree.h +++ b/pandatool/src/mayaegg/mayaNodeTree.h @@ -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(); diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 3981dbdbda..bcf5991d57 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -111,6 +111,7 @@ MayaToEggConverter(const MayaToEggConverter ©) : _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) { diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index e141c2e5e8..62f75e134c 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -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 Globs; Globs _subsets; Globs _ignore_sliders; diff --git a/pandatool/src/mayaprogs/mayaToEgg.cxx b/pandatool/src/mayaprogs/mayaToEgg.cxx index 95c9833d76..ed752dfa2e 100644 --- a/pandatool/src/mayaprogs/mayaToEgg.cxx +++ b/pandatool/src/mayaprogs/mayaToEgg.cxx @@ -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(); diff --git a/pandatool/src/mayaprogs/mayaToEgg.h b/pandatool/src/mayaprogs/mayaToEgg.h index 50a83971bc..990970011d 100644 --- a/pandatool/src/mayaprogs/mayaToEgg.h +++ b/pandatool/src/mayaprogs/mayaToEgg.h @@ -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;