Преглед изворни кода

don't flatten GeomNodes within a Character

David Rose пре 21 година
родитељ
комит
1704f805ba

+ 12 - 0
panda/src/char/character.cxx

@@ -108,6 +108,18 @@ safe_to_transform() const {
   return false;
   return false;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: Character::safe_to_flatten_below
+//       Access: Public, Virtual
+//  Description: Returns true if a flatten operation may safely
+//               continue past this node, or false if nodes below this
+//               node may not be molested.
+////////////////////////////////////////////////////////////////////
+bool Character::
+safe_to_flatten_below() const {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Character::has_cull_callback
 //     Function: Character::has_cull_callback
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 1 - 0
panda/src/char/character.h

@@ -48,6 +48,7 @@ public:
   virtual PandaNode *make_copy() const;
   virtual PandaNode *make_copy() const;
 
 
   virtual bool safe_to_transform() const;
   virtual bool safe_to_transform() const;
+  virtual bool safe_to_flatten_below() const;
   virtual bool has_cull_callback() const;
   virtual bool has_cull_callback() const;
   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
 
 

+ 2 - 2
panda/src/pgraph/pandaNode.cxx

@@ -475,8 +475,8 @@ safe_to_combine() const {
 //     Function: PandaNode::safe_to_flatten_below
 //     Function: PandaNode::safe_to_flatten_below
 //       Access: Public, Virtual
 //       Access: Public, Virtual
 //  Description: Returns true if a flatten operation may safely
 //  Description: Returns true if a flatten operation may safely
-//               continue past this node, or false if it should drop
-//               all attributes here and stop.
+//               continue past this node, or false if nodes below this
+//               node may not be molested.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool PandaNode::
 bool PandaNode::
 safe_to_flatten_below() const {
 safe_to_flatten_below() const {

+ 46 - 44
panda/src/pgraph/sceneGraphReducer.cxx

@@ -220,56 +220,58 @@ r_flatten(PandaNode *grandparent_node, PandaNode *parent_node,
           int combine_siblings_bits) {
           int combine_siblings_bits) {
   int num_nodes = 0;
   int num_nodes = 0;
 
 
-  // First, recurse on each of the children.
-  {
-    PandaNode::ChildrenCopy cr = parent_node->get_children_copy();
-    int num_children = cr.get_num_children();
-    for (int i = 0; i < num_children; i++) {
-      PandaNode *child_node = cr.get_child(i);
-      num_nodes += r_flatten(parent_node, child_node, combine_siblings_bits);
+  if (parent_node->safe_to_flatten_below()) {
+    // First, recurse on each of the children.
+    {
+      PandaNode::ChildrenCopy cr = parent_node->get_children_copy();
+      int num_children = cr.get_num_children();
+      for (int i = 0; i < num_children; i++) {
+        PandaNode *child_node = cr.get_child(i);
+        num_nodes += r_flatten(parent_node, child_node, combine_siblings_bits);
+      }
     }
     }
-  }
-
-  // Now that the above loop has removed some children, the child list
-  // saved above is no longer accurate, so hereafter we must ask the
-  // node for its real child list.
-
-  // If we have CS_recurse set, then we flatten siblings before trying
-  // to flatten children.  Otherwise, we flatten children first, and
-  // then flatten siblings, which avoids overly enthusiastic
-  // flattening.
-  if ((combine_siblings_bits & CS_recurse) != 0 && 
-      parent_node->get_num_children() >= 2) {
-    if (parent_node->safe_to_combine()) {
-      num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
+    
+    // Now that the above loop has removed some children, the child
+    // list saved above is no longer accurate, so hereafter we must
+    // ask the node for its real child list.
+    
+    // If we have CS_recurse set, then we flatten siblings before
+    // trying to flatten children.  Otherwise, we flatten children
+    // first, and then flatten siblings, which avoids overly
+    // enthusiastic flattening.
+    if ((combine_siblings_bits & CS_recurse) != 0 && 
+        parent_node->get_num_children() >= 2) {
+      if (parent_node->safe_to_combine()) {
+        num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
+      }
     }
     }
-  }
-
-  if (parent_node->get_num_children() == 1) {
-    // If we now have exactly one child, consider flattening the node
-    // out.
-    PT(PandaNode) child_node = parent_node->get_child(0);
-    int child_sort = parent_node->get_child_sort(0);
 
 
-    if (consider_child(grandparent_node, parent_node, child_node)) {
-      // Ok, do it.
-      parent_node->remove_child(0);
-
-      if (do_flatten_child(grandparent_node, parent_node, child_node)) {
-        // Done!
-        num_nodes++;
-      } else {
-        // Chicken out.
-        parent_node->add_child(child_node, child_sort);
+    if (parent_node->get_num_children() == 1) {
+      // If we now have exactly one child, consider flattening the node
+      // out.
+      PT(PandaNode) child_node = parent_node->get_child(0);
+      int child_sort = parent_node->get_child_sort(0);
+      
+      if (consider_child(grandparent_node, parent_node, child_node)) {
+        // Ok, do it.
+        parent_node->remove_child(0);
+        
+        if (do_flatten_child(grandparent_node, parent_node, child_node)) {
+          // Done!
+          num_nodes++;
+        } else {
+          // Chicken out.
+          parent_node->add_child(child_node, child_sort);
+        }
       }
       }
     }
     }
-  }
 
 
-  if ((combine_siblings_bits & CS_recurse) == 0 &&
-      (combine_siblings_bits & ~CS_recurse) != 0 && 
-      parent_node->get_num_children() >= 2) {
-    if (parent_node->safe_to_combine()) {
-      num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
+    if ((combine_siblings_bits & CS_recurse) == 0 &&
+        (combine_siblings_bits & ~CS_recurse) != 0 && 
+        parent_node->get_num_children() >= 2) {
+      if (parent_node->safe_to_combine()) {
+        num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
+      }
     }
     }
   }
   }