diff --git a/panda/src/pgraph/lodNode.cxx b/panda/src/pgraph/lodNode.cxx index 91b4aac0ab..faa2e767d9 100644 --- a/panda/src/pgraph/lodNode.cxx +++ b/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 diff --git a/panda/src/pgraph/lodNode.h b/panda/src/pgraph/lodNode.h index f0a2c2757b..27e5ae758b 100644 --- a/panda/src/pgraph/lodNode.h +++ b/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); diff --git a/panda/src/pgraph/modelNode.cxx b/panda/src/pgraph/modelNode.cxx index f3d822c6fc..03317ce4bd 100644 --- a/panda/src/pgraph/modelNode.cxx +++ b/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 { diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index fde7513016..debcfce807 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/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 diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index 1e858d9bfb..7352af5985 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/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; diff --git a/panda/src/pgraph/sceneGraphReducer.cxx b/panda/src/pgraph/sceneGraphReducer.cxx index 4409bd7150..e9a664515c 100644 --- a/panda/src/pgraph/sceneGraphReducer.cxx +++ b/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 diff --git a/panda/src/pgraph/sequenceNode.cxx b/panda/src/pgraph/sequenceNode.cxx index 4108b7e321..fe6bc1f7cb 100644 --- a/panda/src/pgraph/sequenceNode.cxx +++ b/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 diff --git a/panda/src/pgraph/sequenceNode.h b/panda/src/pgraph/sequenceNode.h index 81d4ea3797..581249f539 100644 --- a/panda/src/pgraph/sequenceNode.h +++ b/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; diff --git a/panda/src/pgraph/switchNode.cxx b/panda/src/pgraph/switchNode.cxx index 37255e4ff6..253a2cde1e 100644 --- a/panda/src/pgraph/switchNode.cxx +++ b/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 diff --git a/panda/src/pgraph/switchNode.h b/panda/src/pgraph/switchNode.h index cc38e910cd..756676c1d7 100644 --- a/panda/src/pgraph/switchNode.h +++ b/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;