diff --git a/panda/src/collide/collisionNode.cxx b/panda/src/collide/collisionNode.cxx index 2ae1ec370d..8b5d8dbc95 100644 --- a/panda/src/collide/collisionNode.cxx +++ b/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 diff --git a/panda/src/collide/collisionNode.h b/panda/src/collide/collisionNode.h index 50c333b860..fee2070c86 100644 --- a/panda/src/collide/collisionNode.h +++ b/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: diff --git a/panda/src/graph/graphReducer.cxx b/panda/src/graph/graphReducer.cxx index 2160ae38de..726329b706 100644 --- a/panda/src/graph/graphReducer.cxx +++ b/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; } diff --git a/panda/src/sgraphutil/sceneGraphReducer.cxx b/panda/src/sgraphutil/sceneGraphReducer.cxx index a3cef9982a..894286b058 100644 --- a/panda/src/sgraphutil/sceneGraphReducer.cxx +++ b/panda/src/sgraphutil/sceneGraphReducer.cxx @@ -23,6 +23,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////////////// @@ -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 diff --git a/panda/src/sgraphutil/sceneGraphReducer.h b/panda/src/sgraphutil/sceneGraphReducer.h index 6e3389d475..a28206571f 100644 --- a/panda/src/sgraphutil/sceneGraphReducer.h +++ b/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: