From 1704f805baf818d9a5031616a5c3c302b59915f0 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 22 Sep 2004 20:45:14 +0000 Subject: [PATCH] don't flatten GeomNodes within a Character --- panda/src/char/character.cxx | 12 ++++ panda/src/char/character.h | 1 + panda/src/pgraph/pandaNode.cxx | 4 +- panda/src/pgraph/sceneGraphReducer.cxx | 96 +++++++++++++------------- 4 files changed, 64 insertions(+), 49 deletions(-) diff --git a/panda/src/char/character.cxx b/panda/src/char/character.cxx index df07dda133..3d492bf4d6 100644 --- a/panda/src/char/character.cxx +++ b/panda/src/char/character.cxx @@ -108,6 +108,18 @@ safe_to_transform() const { return false; } +//////////////////////////////////////////////////////////////////// +// Function: Character::safe_to_flatten_below +// Access: Public, Virtual +// Description: Returns true if a flatten operation may safely +// continue past this node, or false if nodes below this +// node may not be molested. +//////////////////////////////////////////////////////////////////// +bool Character:: +safe_to_flatten_below() const { + return false; +} + //////////////////////////////////////////////////////////////////// // Function: Character::has_cull_callback // Access: Public, Virtual diff --git a/panda/src/char/character.h b/panda/src/char/character.h index 700046fc5c..8954a0749f 100644 --- a/panda/src/char/character.h +++ b/panda/src/char/character.h @@ -48,6 +48,7 @@ public: virtual PandaNode *make_copy() const; virtual bool safe_to_transform() const; + virtual bool safe_to_flatten_below() const; virtual bool has_cull_callback() const; virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data); diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 63d2cb2d1d..df6402e3f9 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -475,8 +475,8 @@ safe_to_combine() const { // Function: PandaNode::safe_to_flatten_below // Access: Public, Virtual // Description: Returns true if a flatten operation may safely -// continue past this node, or false if it should drop -// all attributes here and stop. +// continue past this node, or false if nodes below this +// node may not be molested. //////////////////////////////////////////////////////////////////// bool PandaNode:: safe_to_flatten_below() const { diff --git a/panda/src/pgraph/sceneGraphReducer.cxx b/panda/src/pgraph/sceneGraphReducer.cxx index 18f48b5721..21fcc5b029 100644 --- a/panda/src/pgraph/sceneGraphReducer.cxx +++ b/panda/src/pgraph/sceneGraphReducer.cxx @@ -220,56 +220,58 @@ r_flatten(PandaNode *grandparent_node, PandaNode *parent_node, int combine_siblings_bits) { int num_nodes = 0; - // First, recurse on each of the children. - { - PandaNode::ChildrenCopy cr = parent_node->get_children_copy(); - int num_children = cr.get_num_children(); - for (int i = 0; i < num_children; i++) { - PandaNode *child_node = cr.get_child(i); - num_nodes += r_flatten(parent_node, child_node, combine_siblings_bits); - } - } - - // Now that the above loop has removed some children, the child list - // saved above is no longer accurate, so hereafter we must ask the - // node for its real child list. - - // If we have CS_recurse set, then we flatten siblings before trying - // to flatten children. Otherwise, we flatten children 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); - } - } - - if (parent_node->get_num_children() == 1) { - // If we now have exactly one child, consider flattening the node - // out. - PT(PandaNode) child_node = parent_node->get_child(0); - int child_sort = parent_node->get_child_sort(0); - - if (consider_child(grandparent_node, parent_node, child_node)) { - // Ok, do it. - parent_node->remove_child(0); - - if (do_flatten_child(grandparent_node, parent_node, child_node)) { - // Done! - num_nodes++; - } else { - // Chicken out. - parent_node->add_child(child_node, child_sort); + if (parent_node->safe_to_flatten_below()) { + // First, recurse on each of the children. + { + PandaNode::ChildrenCopy cr = parent_node->get_children_copy(); + int num_children = cr.get_num_children(); + for (int i = 0; i < num_children; i++) { + PandaNode *child_node = cr.get_child(i); + num_nodes += r_flatten(parent_node, child_node, combine_siblings_bits); + } + } + + // Now that the above loop has removed some children, the child + // list saved above is no longer accurate, so hereafter we must + // ask the node for its real child list. + + // If we have CS_recurse set, then we flatten siblings before + // trying to flatten children. Otherwise, we flatten children + // 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); } } - } - 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); + if (parent_node->get_num_children() == 1) { + // If we now have exactly one child, consider flattening the node + // out. + PT(PandaNode) child_node = parent_node->get_child(0); + int child_sort = parent_node->get_child_sort(0); + + if (consider_child(grandparent_node, parent_node, child_node)) { + // Ok, do it. + parent_node->remove_child(0); + + if (do_flatten_child(grandparent_node, parent_node, child_node)) { + // Done! + num_nodes++; + } else { + // Chicken out. + parent_node->add_child(child_node, child_sort); + } + } + } + + 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); + } } }