浏览代码

fixed the bug with subroot

Asad M. Zaman 19 年之前
父节点
当前提交
9e6fd852e3

+ 79 - 21
pandatool/src/mayaegg/mayaNodeDesc.cxx

@@ -65,6 +65,7 @@ MayaNodeDesc(MayaNodeTree *tree, MayaNodeDesc *parent, const string &name) :
   _joint_type = JT_none;
   _joint_type = JT_none;
   _is_lod = false;
   _is_lod = false;
   _tagged = false;
   _tagged = false;
+  _joint_tagged = false;
 
 
   // Add ourselves to our parent.
   // Add ourselves to our parent.
   if (_parent != (MayaNodeDesc *)NULL) {
   if (_parent != (MayaNodeDesc *)NULL) {
@@ -209,7 +210,8 @@ get_blend_desc(int n) const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool MayaNodeDesc::
 bool MayaNodeDesc::
 is_joint() const {
 is_joint() const {
-  return _joint_type == JT_joint || _joint_type == JT_pseudo_joint;
+  //return _joint_type == JT_joint || _joint_type == JT_pseudo_joint;
+  return _joint_tagged && (_joint_type == JT_joint || _joint_type == JT_pseudo_joint);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -221,6 +223,46 @@ is_joint() const {
 bool MayaNodeDesc::
 bool MayaNodeDesc::
 is_joint_parent() const {
 is_joint_parent() const {
   return _joint_type == JT_joint_parent;
   return _joint_type == JT_joint_parent;
+  //return _joint_tagged && (_joint_type == JT_joint_parent);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeDesc::is_joint_tagged
+//       Access: Public
+//  Description: Returns true if the node has been joint_tagged to be
+//               converted, false otherwise.
+////////////////////////////////////////////////////////////////////
+bool MayaNodeDesc::
+is_joint_tagged() const {
+  return _joint_tagged;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeDesc::tag_joint
+//       Access: Private
+//  Description: Tags this node for conversion, but does not tag child
+//               nodes.
+////////////////////////////////////////////////////////////////////
+void MayaNodeDesc::
+tag_joint() {
+  _joint_tagged = true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeDesc::tag_joint_recursively
+//       Access: Private
+//  Description: Tags this node and all descendant nodes for
+//               conversion.
+////////////////////////////////////////////////////////////////////
+void MayaNodeDesc::
+tag_joint_recursively() {
+  _joint_tagged = true;
+  //mayaegg_cat.info() << "tjr: " << get_name() << endl;
+  Children::const_iterator ci;
+  for (ci = _children.begin(); ci != _children.end(); ++ci) {
+    MayaNodeDesc *child = (*ci);
+    child->tag_joint_recursively();
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -245,6 +287,23 @@ tag() {
   _tagged = true;
   _tagged = true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeDesc::tag_recursively
+//       Access: Private
+//  Description: Tags this node and all descendant nodes for
+//               conversion.
+////////////////////////////////////////////////////////////////////
+void MayaNodeDesc::
+tag_recursively() {
+  _tagged = true;
+
+  Children::const_iterator ci;
+  for (ci = _children.begin(); ci != _children.end(); ++ci) {
+    MayaNodeDesc *child = (*ci);
+    child->tag_recursively();
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeDesc::has_object_type
 //     Function: MayaNodeDesc::has_object_type
 //       Access: Public
 //       Access: Public
@@ -264,24 +323,6 @@ has_object_type(string object_type) const {
   return ret;
   return ret;
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: MayaNodeDesc::tag_recursively
-//       Access: Private
-//  Description: Tags this node and all descendant nodes for
-//               conversion.
-////////////////////////////////////////////////////////////////////
-void MayaNodeDesc::
-tag_recursively() {
-  _tagged = true;
-
-  Children::const_iterator ci;
-  for (ci = _children.begin(); ci != _children.end(); ++ci) {
-    MayaNodeDesc *child = (*ci);
-    child->tag_recursively();
-  }
-}
-
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeDesc::clear_egg
 //     Function: MayaNodeDesc::clear_egg
 //       Access: Private
 //       Access: Private
@@ -327,6 +368,14 @@ mark_joint_parent() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void MayaNodeDesc::
 void MayaNodeDesc::
 check_pseudo_joints(bool joint_above) {
 check_pseudo_joints(bool joint_above) {
+  static uint32 space_count = 0;
+  if (mayaegg_cat.is_spam()) {
+    string space;
+    for (uint32 idx=0; idx<space_count; ++idx) {
+      space.append(" ");
+    }
+    mayaegg_cat.spam() << "cpj:" << space << get_name() << " joint_type: " << _joint_type << endl;
+  }
   if (_joint_type == JT_joint_parent && joint_above) {
   if (_joint_type == JT_joint_parent && joint_above) {
     // This is one such node: it is the parent of a joint
     // This is one such node: it is the parent of a joint
     // (JT_joint_parent is set), and it is the child of a joint
     // (JT_joint_parent is set), and it is the child of a joint
@@ -348,8 +397,12 @@ check_pseudo_joints(bool joint_above) {
     Children::const_iterator ci;
     Children::const_iterator ci;
     for (ci = _children.begin(); ci != _children.end(); ++ci) {
     for (ci = _children.begin(); ci != _children.end(); ++ci) {
       MayaNodeDesc *child = (*ci);
       MayaNodeDesc *child = (*ci);
+      if (mayaegg_cat.is_spam()) {
+        ++space_count;
+      }
       child->check_pseudo_joints(joint_above);
       child->check_pseudo_joints(joint_above);
-      if (child->is_joint()) {
+      //if (child->is_joint()) {
+      if (child->_joint_type == JT_joint || child->_joint_type == JT_pseudo_joint) {
         any_joints = true;
         any_joints = true;
       }
       }
     }
     }
@@ -363,7 +416,8 @@ check_pseudo_joints(bool joint_above) {
         if (child->_joint_type == JT_joint_parent) {
         if (child->_joint_type == JT_joint_parent) {
           child->_joint_type = JT_pseudo_joint;
           child->_joint_type = JT_pseudo_joint;
         } else if (child->_joint_type == JT_none) {
         } else if (child->_joint_type == JT_none) {
-          all_joints = false;
+          if (!child->get_dag_path().hasFn(MFn::kCamera))
+            all_joints = false;
         }
         }
       }
       }
 
 
@@ -377,6 +431,10 @@ check_pseudo_joints(bool joint_above) {
       }
       }
     }
     }
   }
   }
+  if (mayaegg_cat.is_spam()) {
+    if (space_count > 0)
+      --space_count;
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 4 - 1
pandatool/src/mayaegg/mayaNodeDesc.h

@@ -61,6 +61,7 @@ public:
   bool is_joint_parent() const;
   bool is_joint_parent() const;
 
 
   bool is_tagged() const;
   bool is_tagged() const;
+  bool is_joint_tagged() const;
   bool has_object_type(string object_type) const;
   bool has_object_type(string object_type) const;
 
 
   MayaNodeTree *_tree;
   MayaNodeTree *_tree;
@@ -71,6 +72,8 @@ public:
 private:
 private:
   void tag();
   void tag();
   void tag_recursively();
   void tag_recursively();
+  void tag_joint();
+  void tag_joint_recursively();
 
 
   void clear_egg();
   void clear_egg();
   void mark_joint_parent();
   void mark_joint_parent();
@@ -101,7 +104,7 @@ private:
   double _switch_in, _switch_out;
   double _switch_in, _switch_out;
 
 
   bool _tagged;
   bool _tagged;
-
+  bool _joint_tagged;
 
 
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {

+ 70 - 64
pandatool/src/mayaegg/mayaNodeTree.cxx

@@ -71,13 +71,11 @@ build_node(const MDagPath &dag_path) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeTree::build_hierarchy
 //     Function: MayaNodeTree::build_hierarchy
 //       Access: Public
 //       Access: Public
-//  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.
+//  Description: Walks through the complete Maya hierarchy but does 
+//               not tag any nodes for conversion.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool MayaNodeTree::
 bool MayaNodeTree::
-build_hierarchy(const string &subroot) {
+build_hierarchy() {
   MStatus status;
   MStatus status;
 
 
   MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status);
   MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status);
@@ -86,39 +84,10 @@ build_hierarchy(const string &subroot) {
     return false;
     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) {
-            // mark its parent node name
-            //mayaegg_cat.info() << path.substr(0,bar) << endl;
-            size_t new_bar = path.substr(0,bar).rfind("|");
-            if (new_bar != string::npos) {
-              _subroot_parent_name = path.substr(new_bar+1,bar-(new_bar+1));
-              mayaegg_cat.info() << "subroot parent name: " << _subroot_parent_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();
-    }
-  }
-
+  /*
+    // this is how you can reset the traverser to a specific node
+    status = dag_iterator.reset(dag_iterator.item(),MItDag::kDepthFirst, MFn::kTransform);
+  */
   // Get the entire Maya scene.
   // Get the entire Maya scene.
     
     
   // This while loop walks through the entire Maya hierarchy, one
   // This while loop walks through the entire Maya hierarchy, one
@@ -146,6 +115,43 @@ build_hierarchy(const string &subroot) {
   return all_ok;
   return all_ok;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeTree::tag_joint_all
+//       Access: Public
+//  Description: Tags the entire hierarchy for conversion.  This is
+//               the normal behavior.
+////////////////////////////////////////////////////////////////////
+void MayaNodeTree::
+tag_joint_all() {
+  _root->tag_joint_recursively();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeTree::tag_joint_named
+//       Access: Public
+//  Description: Tags nodes matching the indicated glob (and all of
+//               their children) for conversion.  Returns true on
+//               success, false otherwise (e.g. the named node does
+//               not exist).
+////////////////////////////////////////////////////////////////////
+bool MayaNodeTree::
+tag_joint_named(const GlobPattern &glob) {
+  // There might be multiple nodes matching the name; search for all
+  // of them.
+  bool found_any = false;
+
+  Nodes::iterator ni;
+  for (ni = _nodes.begin(); ni != _nodes.end(); ++ni) {
+    MayaNodeDesc *node = (*ni);
+    if (glob.matches(node->get_name())) {
+      node->tag_joint_recursively();
+      found_any = true;
+    }
+  }
+
+  return found_any;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeTree::tag_all
 //     Function: MayaNodeTree::tag_all
 //       Access: Public
 //       Access: Public
@@ -157,6 +163,32 @@ tag_all() {
   _root->tag_recursively();
   _root->tag_recursively();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeTree::tag_named
+//       Access: Public
+//  Description: Tags nodes matching the indicated glob (and all of
+//               their children) for conversion.  Returns true on
+//               success, false otherwise (e.g. the named node does
+//               not exist).
+////////////////////////////////////////////////////////////////////
+bool MayaNodeTree::
+tag_named(const GlobPattern &glob) {
+  // There might be multiple nodes matching the name; search for all
+  // of them.
+  bool found_any = false;
+
+  Nodes::iterator ni;
+  for (ni = _nodes.begin(); ni != _nodes.end(); ++ni) {
+    MayaNodeDesc *node = (*ni);
+    if (glob.matches(node->get_name())) {
+      node->tag_recursively();
+      found_any = true;
+    }
+  }
+
+  return found_any;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeTree::tag_selected
 //     Function: MayaNodeTree::tag_selected
 //       Access: Public
 //       Access: Public
@@ -220,32 +252,6 @@ tag_selected() {
   return all_ok;
   return all_ok;
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: MayaNodeTree::tag_named
-//       Access: Public
-//  Description: Tags nodes matching the indicated glob (and all of
-//               their children) for conversion.  Returns true on
-//               success, false otherwise (e.g. the named node does
-//               not exist).
-////////////////////////////////////////////////////////////////////
-bool MayaNodeTree::
-tag_named(const GlobPattern &glob) {
-  // There might be multiple nodes matching the name; search for all
-  // of them.
-  bool found_any = false;
-
-  Nodes::iterator ni;
-  for (ni = _nodes.begin(); ni != _nodes.end(); ++ni) {
-    MayaNodeDesc *node = (*ni);
-    if (glob.matches(node->get_name())) {
-      node->tag_recursively();
-      found_any = true;
-    }
-  }
-
-  return found_any;
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeTree::get_num_nodes
 //     Function: MayaNodeTree::get_num_nodes
 //       Access: Public
 //       Access: Public

+ 5 - 1
pandatool/src/mayaegg/mayaNodeTree.h

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

+ 59 - 31
pandatool/src/mayaegg/mayaToEggConverter.cxx

@@ -109,9 +109,9 @@ MayaToEggConverter(const MayaToEggConverter &copy) :
   _program_name(copy._program_name),
   _program_name(copy._program_name),
   _from_selection(copy._from_selection),
   _from_selection(copy._from_selection),
   _subsets(copy._subsets),
   _subsets(copy._subsets),
+  _subroots(copy._subroots),
   _ignore_sliders(copy._ignore_sliders),
   _ignore_sliders(copy._ignore_sliders),
   _force_joints(copy._force_joints),
   _force_joints(copy._force_joints),
-  _subroot(copy._subroot),
   _tree(this),
   _tree(this),
   _maya(copy._maya),
   _maya(copy._maya),
   _polygon_output(copy._polygon_output),
   _polygon_output(copy._polygon_output),
@@ -215,16 +215,29 @@ convert_file(const Filename &filename) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: MayaToEggConverter::set_subroot
+//     Function: MayaToEggConverter::clear_subroots
 //       Access: Public
 //       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
+//  Description: Empties the list of subroot nodes added via
+//               add_subroot().  The entire file will once again be
 //               converted.
 //               converted.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void MayaToEggConverter::
 void MayaToEggConverter::
-set_subroot(const string &subroot) {
-  _subroot = subroot;
+clear_subroots() {
+  _subroots.clear();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaToEggConverter::add_subroot
+//       Access: Public
+//  Description: Adds a name pattern to the list of subroot nodes.  If
+//               the list of subroot nodes is not empty, then only a
+//               subroot of the nodes in the maya file will be
+//               converted: those whose names match one of the
+//               patterns given on this list.
+////////////////////////////////////////////////////////////////////
+void MayaToEggConverter::
+add_subroot(const GlobPattern &glob) {
+  _subroots.push_back(glob);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -428,7 +441,22 @@ convert_maya() {
 
 
   frame_inc = frame_inc * input_frame_rate / output_frame_rate;
   frame_inc = frame_inc * input_frame_rate / output_frame_rate;
 
 
-  bool all_ok = _tree.build_hierarchy(_subroot);
+  bool all_ok = _tree.build_hierarchy();
+
+  if (all_ok) {
+    if (!_subroots.empty()) {
+      Globs::const_iterator gi;
+      for (gi = _subroots.begin(); gi != _subroots.end(); ++gi) {
+        if (!_tree.tag_joint_named(*gi)) {
+          mayaegg_cat.info()
+            << "No node matching " << *gi << " found.\n";
+        }
+      }
+
+    } else {
+      _tree.tag_joint_all();
+    }
+  }
 
 
   if (all_ok) {
   if (all_ok) {
     if (_from_selection) {
     if (_from_selection) {
@@ -690,7 +718,7 @@ convert_char_chan(double start_frame, double end_frame, double frame_inc,
       if (node_desc->is_joint()) {
       if (node_desc->is_joint()) {
         if (mayaegg_cat.is_spam()) {
         if (mayaegg_cat.is_spam()) {
           mayaegg_cat.spam()
           mayaegg_cat.spam()
-            << "joint " << node_desc->get_name() << "\n";
+          << "joint " << node_desc->get_name() << "\n";
         }
         }
         get_joint_transform(node_desc->get_dag_path(), tgroup);
         get_joint_transform(node_desc->get_dag_path(), tgroup);
         EggXfmSAnim *anim = _tree.get_egg_anim(node_desc);
         EggXfmSAnim *anim = _tree.get_egg_anim(node_desc);
@@ -823,6 +851,26 @@ process_model_node(MayaNodeDesc *node_desc) {
         << "\n";
         << "\n";
     }
     }
 
 
+    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 if (dag_path.hasFn(MFn::kLight)) {
   } else if (dag_path.hasFn(MFn::kLight)) {
     if (mayaegg_cat.is_debug()) {
     if (mayaegg_cat.is_debug()) {
       mayaegg_cat.debug()
       mayaegg_cat.debug()
@@ -922,27 +970,6 @@ process_model_node(MayaNodeDesc *node_desc) {
       make_locator(dag_path, dag_node, 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 {
   } else {
     // Just a generic node.
     // Just a generic node.
     if (_animation_convert == AC_none) {
     if (_animation_convert == AC_none) {
@@ -970,7 +997,8 @@ get_transform(MayaNodeDesc *node_desc, const MDagPath &dag_path,
     // When we're getting an animated model, we only get transforms
     // When we're getting an animated model, we only get transforms
     // for joints, and they get converted in a special way.
     // for joints, and they get converted in a special way.
 
 
-    if (node_desc->is_joint()) { 
+    if (node_desc->is_joint()) {
+      //mayaegg_cat.info() << "gt: " << node_desc->get_name() << endl;
       get_joint_transform(dag_path, egg_group);
       get_joint_transform(dag_path, egg_group);
     }
     }
     return;
     return;

+ 3 - 1
pandatool/src/mayaegg/mayaToEggConverter.h

@@ -80,7 +80,8 @@ public:
   virtual bool convert_file(const Filename &filename);
   virtual bool convert_file(const Filename &filename);
   virtual DistanceUnit get_input_units();
   virtual DistanceUnit get_input_units();
 
 
-  void set_subroot(const string &subroot);
+  void clear_subroots();
+  void add_subroot(const GlobPattern &glob);
 
 
   void clear_subsets();
   void clear_subsets();
   void add_subset(const GlobPattern &glob);
   void add_subset(const GlobPattern &glob);
@@ -165,6 +166,7 @@ private:
   string _subroot;
   string _subroot;
   typedef pvector<GlobPattern> Globs;
   typedef pvector<GlobPattern> Globs;
   Globs _subsets;
   Globs _subsets;
+  Globs _subroots;
   Globs _ignore_sliders;
   Globs _ignore_sliders;
   Globs _force_joints;
   Globs _force_joints;