allow flatten_strong() to combine the children of a ModelNode

This commit is contained in:
David Rose 2006-10-18 17:18:17 +00:00
parent 5f4ec707e1
commit 64d4d729fc
10 changed files with 94 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -231,7 +231,14 @@ r_flatten(PandaNode *grandparent_node, PandaNode *parent_node,
} }
int num_nodes = 0; 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) { if ((combine_siblings_bits & CS_within_radius) != 0) {
CPT(BoundingVolume) bv = parent_node->get_bounds(); CPT(BoundingVolume) bv = parent_node->get_bounds();
if (bv->is_of_type(BoundingSphere::get_class_type())) { 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 // first, and then flatten siblings, which avoids overly
// enthusiastic flattening. // enthusiastic flattening.
if ((combine_siblings_bits & CS_recurse) != 0 && if ((combine_siblings_bits & CS_recurse) != 0 &&
parent_node->get_num_children() >= 2) { parent_node->get_num_children() >= 2 &&
if (parent_node->safe_to_combine()) { parent_node->safe_to_combine_children()) {
num_nodes += flatten_siblings(parent_node, combine_siblings_bits); num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
}
} }
if (parent_node->get_num_children() == 1) { 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 && if ((combine_siblings_bits & CS_recurse) == 0 &&
(combine_siblings_bits & ~CS_recurse) != 0 && (combine_siblings_bits & ~CS_recurse) != 0 &&
parent_node->get_num_children() >= 2) { parent_node->get_num_children() >= 2 &&
if (parent_node->safe_to_combine()) { parent_node->safe_to_combine_children()) {
num_nodes += flatten_siblings(parent_node, combine_siblings_bits); num_nodes += flatten_siblings(parent_node, combine_siblings_bits);
}
} }
// Finally, if any of our remaining children are plain PandaNodes // Finally, if any of our remaining children are plain PandaNodes

View File

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

View File

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

View File

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

View File

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