Browse Source

define flatten-collision-nodes

David Rose 18 years ago
parent
commit
cb1c87d58c

+ 20 - 18
panda/src/collide/collisionNode.cxx

@@ -145,27 +145,29 @@ xform(const LMatrix4f &mat) {
 ////////////////////////////////////////////////////////////////////
 PandaNode *CollisionNode::
 combine_with(PandaNode *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, because the name is often meaningful, and only if they
-    // have the same collide masks.
-    CollisionNode *cother = DCAST(CollisionNode, other);
-    if (get_name() == cother->get_name() &&
-        get_from_collide_mask() == cother->get_from_collide_mask() &&
-        get_into_collide_mask() == cother->get_into_collide_mask()) {
-      const COWPT(CollisionSolid) *solids_begin = &cother->_solids[0];
-      const COWPT(CollisionSolid) *solids_end = solids_begin + cother->_solids.size();
-      _solids.insert(_solids.end(), solids_begin, solids_end);
-      mark_internal_bounds_stale();
-      return this;
+  if (flatten_collision_nodes) {
+    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, because the name is often meaningful, and only if they
+      // have the same collide masks.
+      CollisionNode *cother = DCAST(CollisionNode, other);
+      if (get_name() == cother->get_name() &&
+          get_from_collide_mask() == cother->get_from_collide_mask() &&
+          get_into_collide_mask() == cother->get_into_collide_mask()) {
+        const COWPT(CollisionSolid) *solids_begin = &cother->_solids[0];
+        const COWPT(CollisionSolid) *solids_end = solids_begin + cother->_solids.size();
+        _solids.insert(_solids.end(), solids_begin, solids_end);
+        mark_internal_bounds_stale();
+        return this;
+      }
+      
+      // Two CollisionNodes with different names or different collide
+      // masks can't combine.
     }
-
-    // Two CollisionNodes with different names can't combine.
-    return (PandaNode *)NULL;
   }
 
-  return PandaNode::combine_with(other);
+  return NULL;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 11 - 0
panda/src/collide/config_collide.cxx

@@ -73,6 +73,17 @@ ConfigVariableBool allow_collider_multiple
           "false, a one-word BitMask is always used instead, which is faster "
           "per pass, but may require more passes."));
 
+ConfigVariableBool flatten_collision_nodes
+("flatten-collision-nodes", false,
+ PRC_DESC("Set this true to allow NodePath::flatten_medium() and "
+          "flatten_strong() to combine multiple CollisionNodes "
+          "into a single CollisionNode--but only if they share the "
+          "same name and collide masks.  When false, CollisionNodes "
+          "are never combined.  This is false by default, since "
+          "collision tests rely heavily on bounding volume tests "
+          "to be efficient, and combining CollisionNodes is likely "
+          "to merge bounding volumes inappropriately."));
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: init_libcollide

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

@@ -28,6 +28,7 @@ NotifyCategoryDecl(collide, EXPCL_PANDA, EXPTP_PANDA);
 extern EXPCL_PANDA ConfigVariableBool respect_prev_transform;
 extern EXPCL_PANDA ConfigVariableBool respect_effective_normal;
 extern EXPCL_PANDA ConfigVariableBool allow_collider_multiple;
+extern EXPCL_PANDA ConfigVariableBool flatten_collision_nodes;
 
 extern EXPCL_PANDA void init_libcollide();