don't flatten GeomNodes within a Character

This commit is contained in:
David Rose 2004-09-22 20:45:14 +00:00
parent aa80a45ed2
commit 1704f805ba
4 changed files with 64 additions and 49 deletions

View File

@ -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

View File

@ -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);

View File

@ -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 {

View File

@ -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);
}
}
}