Browse Source

allow flatten_strong() to combine the children of a ModelNode

David Rose 19 years ago
parent
commit
64d4d729fc

+ 18 - 4
panda/src/pgraph/lodNode.cxx

@@ -59,16 +59,30 @@ make_copy() const {
 //       Access: Public, Virtual
 //  Description: Returns true if it is generally safe to combine this
 //               particular kind of PandaNode with other kinds of
-//               PandaNodes, adding children or whatever.  For
-//               instance, an LODNode should not be combined with any
-//               other PandaNode, because its set of children is
-//               meaningful.
+//               PandaNodes of compatible type, adding children or
+//               whatever.  For instance, an LODNode should not be
+//               combined with any other PandaNode, because its set of
+//               children is meaningful.
 ////////////////////////////////////////////////////////////////////
 bool LODNode::
 safe_to_combine() const {
   return false;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: LODNode::safe_to_combine_children
+//       Access: Public, Virtual
+//  Description: Returns true if it is generally safe to combine the
+//               children of this PandaNode with each other.  For
+//               instance, an LODNode's children should not be
+//               combined with each other, because the set of children
+//               is meaningful.
+////////////////////////////////////////////////////////////////////
+bool LODNode::
+safe_to_combine_children() const {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LODNode::xform
 //       Access: Public, Virtual

+ 1 - 0
panda/src/pgraph/lodNode.h

@@ -41,6 +41,7 @@ protected:
 public:
   virtual PandaNode *make_copy() const;
   virtual bool safe_to_combine() const;
+  virtual bool safe_to_combine_children() const;
   virtual void xform(const LMatrix4f &mat);
   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
 

+ 4 - 4
panda/src/pgraph/modelNode.cxx

@@ -87,10 +87,10 @@ safe_to_modify_transform() const {
 //       Access: Public, Virtual
 //  Description: Returns true if it is generally safe to combine this
 //               particular kind of PandaNode with other kinds of
-//               PandaNodes, adding children or whatever.  For
-//               instance, an LODNode should not be combined with any
-//               other PandaNode, because its set of children is
-//               meaningful.
+//               PandaNodes of compatible type, adding children or
+//               whatever.  For instance, an LODNode should not be
+//               combined with any other PandaNode, because its set of
+//               children is meaningful.
 ////////////////////////////////////////////////////////////////////
 bool ModelNode::
 safe_to_combine() const {

+ 18 - 4
panda/src/pgraph/pandaNode.cxx

@@ -243,16 +243,30 @@ safe_to_modify_transform() const {
 //       Access: Public, Virtual
 //  Description: Returns true if it is generally safe to combine this
 //               particular kind of PandaNode with other kinds of
-//               PandaNodes, adding children or whatever.  For
-//               instance, an LODNode should not be combined with any
-//               other PandaNode, because its set of children is
-//               meaningful.
+//               PandaNodes of compatible type, adding children or
+//               whatever.  For instance, an LODNode should not be
+//               combined with any other PandaNode, because its set of
+//               children is meaningful.
 ////////////////////////////////////////////////////////////////////
 bool PandaNode::
 safe_to_combine() const {
   return true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PandaNode::safe_to_combine_children
+//       Access: Public, Virtual
+//  Description: Returns true if it is generally safe to combine the
+//               children of this PandaNode with each other.  For
+//               instance, an LODNode's children should not be
+//               combined with each other, because the set of children
+//               is meaningful.
+////////////////////////////////////////////////////////////////////
+bool PandaNode::
+safe_to_combine_children() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PandaNode::safe_to_flatten_below
 //       Access: Public, Virtual

+ 1 - 0
panda/src/pgraph/pandaNode.h

@@ -88,6 +88,7 @@ public:
   virtual bool safe_to_transform() const;
   virtual bool safe_to_modify_transform() const;
   virtual bool safe_to_combine() const;
+  virtual bool safe_to_combine_children() const;
   virtual bool safe_to_flatten_below() const;
   virtual bool preserve_name() const;
   virtual int get_unsafe_to_apply_attribs() const;

+ 14 - 9
panda/src/pgraph/sceneGraphReducer.cxx

@@ -231,7 +231,14 @@ r_flatten(PandaNode *grandparent_node, PandaNode *parent_node,
   }
   int num_nodes = 0;
 
-  if (parent_node->safe_to_flatten_below()) {
+  if (!parent_node->safe_to_flatten_below()) {
+    if (pgraph_cat.is_spam()) {
+      pgraph_cat.spam()
+        << "Not traversing farther; " << *parent_node
+        << " doesn't allow flattening below itself.\n";
+    }
+    
+  } else {
     if ((combine_siblings_bits & CS_within_radius) != 0) {
       CPT(BoundingVolume) bv = parent_node->get_bounds();
       if (bv->is_of_type(BoundingSphere::get_class_type())) {
@@ -274,10 +281,9 @@ r_flatten(PandaNode *grandparent_node, PandaNode *parent_node,
     // 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);
-      }
+        parent_node->get_num_children() >= 2 &&
+        parent_node->safe_to_combine_children()) {
+      num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
     }
 
     if (parent_node->get_num_children() == 1) {
@@ -302,10 +308,9 @@ r_flatten(PandaNode *grandparent_node, PandaNode *parent_node,
 
     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);
-      }
+        parent_node->get_num_children() >= 2 &&
+        parent_node->safe_to_combine_children()) {
+      num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
     }
 
     // Finally, if any of our remaining children are plain PandaNodes

+ 18 - 4
panda/src/pgraph/sequenceNode.cxx

@@ -54,16 +54,30 @@ get_num_frames() const {
 //       Access: Public, Virtual
 //  Description: Returns true if it is generally safe to combine this
 //               particular kind of PandaNode with other kinds of
-//               PandaNodes, adding children or whatever.  For
-//               instance, an LODNode should not be combined with any
-//               other PandaNode, because its set of children is
-//               meaningful.
+//               PandaNodes of compatible type, adding children or
+//               whatever.  For instance, an LODNode should not be
+//               combined with any other PandaNode, because its set of
+//               children is meaningful.
 ////////////////////////////////////////////////////////////////////
 bool SequenceNode::
 safe_to_combine() const {
   return false;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: SequenceNode::safe_to_combine_children
+//       Access: Public, Virtual
+//  Description: Returns true if it is generally safe to combine the
+//               children of this PandaNode with each other.  For
+//               instance, an LODNode's children should not be
+//               combined with each other, because the set of children
+//               is meaningful.
+////////////////////////////////////////////////////////////////////
+bool SequenceNode::
+safe_to_combine_children() const {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: SequenceNode::make_copy
 //       Access: Public, Virtual

+ 1 - 0
panda/src/pgraph/sequenceNode.h

@@ -44,6 +44,7 @@ PUBLISHED:
 public:
   virtual PandaNode *make_copy() const;
   virtual bool safe_to_combine() const;
+  virtual bool safe_to_combine_children() const;
 
   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
   virtual bool has_single_child_visibility() const;

+ 18 - 4
panda/src/pgraph/switchNode.cxx

@@ -37,16 +37,30 @@ make_copy() const {
 //       Access: Public, Virtual
 //  Description: Returns true if it is generally safe to combine this
 //               particular kind of PandaNode with other kinds of
-//               PandaNodes, adding children or whatever.  For
-//               instance, an LODNode should not be combined with any
-//               other PandaNode, because its set of children is
-//               meaningful.
+//               PandaNodes of compatible type, adding children or
+//               whatever.  For instance, an LODNode should not be
+//               combined with any other PandaNode, because its set of
+//               children is meaningful.
 ////////////////////////////////////////////////////////////////////
 bool SwitchNode::
 safe_to_combine() const {
   return false;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: SwitchNode::safe_to_combine_children
+//       Access: Public, Virtual
+//  Description: Returns true if it is generally safe to combine the
+//               children of this PandaNode with each other.  For
+//               instance, an LODNode's children should not be
+//               combined with each other, because the set of children
+//               is meaningful.
+////////////////////////////////////////////////////////////////////
+bool SwitchNode::
+safe_to_combine_children() const {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: SwitchNode::CData::write_datagram
 //       Access: Public, Virtual

+ 1 - 0
panda/src/pgraph/switchNode.h

@@ -37,6 +37,7 @@ public:
 
   virtual PandaNode *make_copy() const;
   virtual bool safe_to_combine() const;
+  virtual bool safe_to_combine_children() const;
 
   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
   virtual bool has_single_child_visibility() const;