Browse Source

combine sibling CollisionNodes

David Rose 24 years ago
parent
commit
2b115621e3

+ 33 - 0
panda/src/collide/collisionNode.cxx

@@ -124,6 +124,39 @@ xform(const LMatrix4f &mat) {
   mark_bound_stale();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionNode::combine_with
+//       Access: Public, Virtual
+//  Description: Collapses this node with the other node, if possible,
+//               and returns a pointer to the combined node, or NULL
+//               if the two nodes cannot safely be combined.
+//
+//               The return value may be this, other, or a new node
+//               altogether.
+//
+//               This function is called from GraphReducer::flatten(),
+//               and need not deal with children; its job is just to
+//               decide whether to collapse the two nodes and what the
+//               collapsed node should look like.
+////////////////////////////////////////////////////////////////////
+Node *CollisionNode::
+combine_with(Node *other) {
+  if (is_exact_type(get_class_type()) &&
+      other->is_exact_type(get_class_type())) {
+    // Two CollisionNodes can combine, but only if they have the same
+    // name.
+    CollisionNode *cother = DCAST(CollisionNode, other);
+    if (get_name() == cother->get_name()) {
+      const PT(CollisionSolid) *solids_begin = &cother->_solids[0];
+      const PT(CollisionSolid) *solids_end = solids_begin + cother->_solids.size();
+      _solids.insert(_solids.end(), solids_begin, solids_end);
+      return this;
+    }
+  }
+
+  return (Node *)NULL;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionNode::preserve_name
 //       Access: Public, Virtual

+ 1 - 0
panda/src/collide/collisionNode.h

@@ -44,6 +44,7 @@ public:
   virtual ~CollisionNode();
   virtual Node *make_copy() const;
   virtual void xform(const LMatrix4f &mat);
+  virtual Node *combine_with(Node *other); 
   virtual bool preserve_name() const;
 
 PUBLISHED:

+ 6 - 0
panda/src/graph/graphReducer.cxx

@@ -290,6 +290,11 @@ consider_siblings(Node *, NodeRelation *arc1, NodeRelation *arc2) {
 
   // We can't collapse siblings with arcs that contain sub_render
   // transitions.  That could be bad.
+
+  // On the other hand, maybe we can; why not?  The only one that
+  // could cause grief is the DecalTransition, which we'll
+  // special-case in SceneGraphReducer.
+  /*
   if (arc1->has_sub_render_trans()) {
     if (graph_cat.is_debug()) {
       graph_cat.debug()
@@ -298,6 +303,7 @@ consider_siblings(Node *, NodeRelation *arc1, NodeRelation *arc2) {
     }
     return false;
   }
+  */
 
   return true;
 }

+ 20 - 0
panda/src/sgraphutil/sceneGraphReducer.cxx

@@ -23,6 +23,7 @@
 #include <geom.h>
 #include <indent.h>
 #include <billboardTransition.h>
+#include <decalTransition.h>
 
 
 ////////////////////////////////////////////////////////////////////
@@ -285,6 +286,25 @@ r_apply_transitions(NodeRelation *arc, int transition_types,
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: SceneGraphReducer::consider_siblings
+//       Access: Protected, Virtual
+//  Description: Decides whether or not the indicated sibling nodes
+//               (and their associated arcs) should be collapsed into
+//               a single node or not.  Returns true if the arcs may
+//               be collapsed, false if they should be kept distinct.
+////////////////////////////////////////////////////////////////////
+bool SceneGraphReducer::
+consider_siblings(Node *parent, NodeRelation *arc1, NodeRelation *arc2) {
+  // We can't collapse siblings with arcs that contain the
+  // DecalTransition; however, other transitions are OK.
+  if (arc1->has_transition(DecalTransition::get_class_type())) {
+    return false;
+  }
+
+  return GraphReducer::consider_siblings(parent, arc1, arc2);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: SceneGraphReducer::collapse_nodes
 //       Access: Protected, Virtual

+ 3 - 0
panda/src/sgraphutil/sceneGraphReducer.h

@@ -70,6 +70,9 @@ protected:
                            AccumulatedTransitions trans,
                            bool duplicate);
 
+  virtual bool consider_siblings(Node *parent,
+                                 NodeRelation *arc1, NodeRelation *arc2);
+
   virtual Node *collapse_nodes(Node *node1, Node *node2, bool siblings);
 
 private: