Просмотр исходного кода

added the ability to exclude nodes (and their children) with maya2egg

Chris Brunner 17 лет назад
Родитель
Сommit
e5c6aebcef

+ 28 - 0
pandatool/src/mayaegg/mayaNodeDesc.cxx

@@ -283,6 +283,17 @@ tag() {
   _tagged = true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeDesc::untag
+//       Access: Private
+//  Description: Un-tags this node for conversion, but does not tag child
+//               nodes.
+////////////////////////////////////////////////////////////////////
+void MayaNodeDesc::
+untag() {
+  _tagged = false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeDesc::tag_recursively
 //       Access: Private
@@ -300,6 +311,23 @@ tag_recursively() {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeDesc::untag_recursively
+//       Access: Private
+//  Description: Un-tags this node and all descendant nodes for
+//               conversion.
+////////////////////////////////////////////////////////////////////
+void MayaNodeDesc::
+untag_recursively() {
+  _tagged = false;
+
+  Children::const_iterator ci;
+  for (ci = _children.begin(); ci != _children.end(); ++ci) {
+    MayaNodeDesc *child = (*ci);
+    child->untag_recursively();
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeDesc::has_object_type
 //       Access: Public

+ 2 - 0
pandatool/src/mayaegg/mayaNodeDesc.h

@@ -67,7 +67,9 @@ public:
   
 private:
   void tag();
+  void untag();
   void tag_recursively();
+  void untag_recursively();
   void tag_joint();
   void tag_joint_recursively();
 

+ 26 - 0
pandatool/src/mayaegg/mayaNodeTree.cxx

@@ -185,6 +185,32 @@ tag_named(const GlobPattern &glob) {
   return found_any;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaNodeTree::untag_named
+//       Access: Public
+//  Description: Un-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::
+untag_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->untag_recursively();
+      found_any = true;
+    }
+  }
+
+  return found_any;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaNodeTree::tag_selected
 //       Access: Public

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

@@ -49,6 +49,7 @@ public:
   void tag_all();
   bool tag_selected();
   bool tag_named(const GlobPattern &glob);
+  bool untag_named(const GlobPattern &glob);
 
   int get_num_nodes() const;
   MayaNodeDesc *get_node(int n) const;

+ 34 - 1
pandatool/src/mayaegg/mayaToEggConverter.cxx

@@ -109,6 +109,7 @@ MayaToEggConverter(const MayaToEggConverter &copy) :
   _from_selection(copy._from_selection),
   _subsets(copy._subsets),
   _subroots(copy._subroots),
+  _excludes(copy._excludes),
   _ignore_sliders(copy._ignore_sliders),
   _force_joints(copy._force_joints),
   _tree(this),
@@ -267,6 +268,27 @@ add_subset(const GlobPattern &glob) {
   _subsets.push_back(glob);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaToEggConverter::clear_excludes
+//       Access: Public
+//  Description: Empties the list of excluded nodes added via
+//               add_exclude().
+////////////////////////////////////////////////////////////////////
+void MayaToEggConverter::
+clear_excludes() {
+  _excludes.clear();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaToEggConverter::add_exclude
+//       Access: Public
+//  Description: Adds a name pattern to the list of excluded nodes.
+////////////////////////////////////////////////////////////////////
+void MayaToEggConverter::
+add_exclude(const GlobPattern &glob) {
+  _excludes.push_back(glob);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaToEggConverter::clear_ignore_sliders
 //       Access: Public
@@ -465,7 +487,6 @@ convert_maya() {
   if (all_ok) {
     if (_from_selection) {
       all_ok = _tree.tag_selected();
-
     } else if (!_subsets.empty()) {
       Globs::const_iterator gi;
       for (gi = _subsets.begin(); gi != _subsets.end(); ++gi) {
@@ -480,6 +501,18 @@ convert_maya() {
     }
   }
 
+  if (all_ok) {
+    if (!_excludes.empty()) {
+      Globs::const_iterator gi;
+      for (gi = _excludes.begin(); gi != _excludes.end(); ++gi) {
+        if (!_tree.untag_named(*gi)) {
+          mayaegg_cat.info()
+            << "No node matching " << *gi << " found.\n";
+        }
+      }
+    }
+  }
+
   if (all_ok) {
     switch (get_animation_convert()) {
     case AC_pose:

+ 4 - 0
pandatool/src/mayaegg/mayaToEggConverter.h

@@ -83,6 +83,9 @@ public:
   void clear_subsets();
   void add_subset(const GlobPattern &glob);
 
+  void clear_excludes();
+  void add_exclude(const GlobPattern &glob);
+
   void clear_ignore_sliders();
   void add_ignore_slider(const GlobPattern &glob);
   bool ignore_slider(const string &name) const;
@@ -166,6 +169,7 @@ private:
   typedef pvector<GlobPattern> Globs;
   Globs _subsets;
   Globs _subroots;
+  Globs _excludes;
   Globs _ignore_sliders;
   Globs _force_joints;
 

+ 16 - 1
pandatool/src/mayaprogs/mayaToEgg.cxx

@@ -113,6 +113,15 @@ MayaToEgg() :
      "converted.",
      &MayaToEgg::dispatch_vector_string, NULL, &_subsets);
 
+  add_option
+    ("exclude", "name", 0,
+     "Specifies that a subset of the geometry in the Maya file should "
+     "not be converted; specifically, the geometry under the node or nodes whose "
+     "name matches the parameter (which may include globbing characters "
+     "like * or ?).  This parameter may be repeated multiple times to name "
+     "multiple roots.",
+     &MayaToEgg::dispatch_vector_string, NULL, &_excludes);
+
   add_option
     ("ignore-slider", "name", 0,
      "Specifies the name of a slider (blend shape deformer) that maya2egg "
@@ -196,7 +205,6 @@ run() {
     }
   }
 
-  //vector_string::const_iterator si;
   if (!_subsets.empty()) {
     converter.clear_subsets();
     for (si = _subsets.begin(); si != _subsets.end(); ++si) {
@@ -204,6 +212,13 @@ run() {
     }
   }
 
+  if (!_excludes.empty()) {
+    converter.clear_excludes();
+    for (si = _excludes.begin(); si != _excludes.end(); ++si) {
+      converter.add_exclude(GlobPattern(*si));
+    }
+  }
+
   if (!_ignore_sliders.empty()) {
     converter.clear_ignore_sliders();
     for (si = _ignore_sliders.begin(); si != _ignore_sliders.end(); ++si) {

+ 1 - 0
pandatool/src/mayaprogs/mayaToEgg.h

@@ -42,6 +42,7 @@ protected:
   MayaToEggConverter::TransformType _transform_type;
   vector_string _subroots; 
   vector_string _subsets;
+  vector_string _excludes;
   vector_string _ignore_sliders;
   vector_string _force_joints;
 };