From 78fc7749420c3813cb3ce58056c4c05ca02887d5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 27 Jun 2002 18:32:10 +0000 Subject: [PATCH] DCS-flagged nodes shouldn't get their transforms modified by flatten --- panda/src/pgraph/modelNode.cxx | 17 +++++++++++++++++ panda/src/pgraph/modelNode.h | 1 + panda/src/pgraph/pandaNode.cxx | 17 +++++++++++++++++ panda/src/pgraph/pandaNode.h | 1 + panda/src/pgraph/sceneGraphReducer.cxx | 24 ++++++++++++++++++++++-- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/panda/src/pgraph/modelNode.cxx b/panda/src/pgraph/modelNode.cxx index 812ee78426..cea656d76f 100644 --- a/panda/src/pgraph/modelNode.cxx +++ b/panda/src/pgraph/modelNode.cxx @@ -65,6 +65,23 @@ safe_to_transform() const { return !_preserve_transform; } +//////////////////////////////////////////////////////////////////// +// Function: ModelNode::safe_to_modify_transform +// Access: Public, Virtual +// Description: Returns true if it is safe to automatically adjust +// the transform on this kind of node. Usually, this is +// only a bad idea if the user expects to find a +// particular transform on the node. +// +// ModelNodes with the preserve_transform flag set are +// presently the only kinds of nodes that should not +// have their transform even adjusted. +//////////////////////////////////////////////////////////////////// +bool ModelNode:: +safe_to_modify_transform() const { + return !_preserve_transform; +} + //////////////////////////////////////////////////////////////////// // Function: ModelNode::safe_to_combine // Access: Public, Virtual diff --git a/panda/src/pgraph/modelNode.h b/panda/src/pgraph/modelNode.h index d5a8d5e55f..d90658b431 100644 --- a/panda/src/pgraph/modelNode.h +++ b/panda/src/pgraph/modelNode.h @@ -47,6 +47,7 @@ public: virtual bool safe_to_flatten() const; virtual bool safe_to_transform() const; + virtual bool safe_to_modify_transform() const; virtual bool safe_to_combine() const; virtual bool preserve_name() const; diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 076fc68180..9fde96e31b 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -470,6 +470,23 @@ safe_to_transform() const { return true; } +//////////////////////////////////////////////////////////////////// +// Function: PandaNode::safe_to_modify_transform +// Access: Public, Virtual +// Description: Returns true if it is safe to automatically adjust +// the transform on this kind of node. Usually, this is +// only a bad idea if the user expects to find a +// particular transform on the node. +// +// ModelNodes with the preserve_transform flag set are +// presently the only kinds of nodes that should not +// have their transform even adjusted. +//////////////////////////////////////////////////////////////////// +bool PandaNode:: +safe_to_modify_transform() const { + return true; +} + //////////////////////////////////////////////////////////////////// // Function: PandaNode::safe_to_combine // Access: Public, Virtual diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index 113e49db59..70544db046 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/panda/src/pgraph/pandaNode.h @@ -69,6 +69,7 @@ public: virtual bool safe_to_flatten() const; virtual bool safe_to_transform() const; + virtual bool safe_to_modify_transform() const; virtual bool safe_to_combine() const; virtual bool preserve_name() const; virtual void xform(const LMatrix4f &mat); diff --git a/panda/src/pgraph/sceneGraphReducer.cxx b/panda/src/pgraph/sceneGraphReducer.cxx index 74d90a741e..33f9fc7242 100644 --- a/panda/src/pgraph/sceneGraphReducer.cxx +++ b/panda/src/pgraph/sceneGraphReducer.cxx @@ -406,6 +406,28 @@ r_apply_attribs(PandaNode *node, int attrib_types, apply_types |= TT_transform; } + // Also, check the children of this node. If any of them indicates + // it is not safe to modify its transform, we must drop our + // transform here. + int num_children = node->get_num_children(); + int i; + if ((apply_types & TT_transform) == 0) { + bool children_transform_friendly = true; + for (i = 0; i < num_children && children_transform_friendly; i++) { + PandaNode *child_node = node->get_child(i); + children_transform_friendly = child_node->safe_to_modify_transform(); + } + + if (!children_transform_friendly) { + if (pgraph_cat.is_debug()) { + pgraph_cat.debug() + << "Node " << *node + << " has a child that cannot modify its transform; leaving transform here.\n"; + } + apply_types |= TT_transform; + } + } + // Directly store whatever attributes we must, trans.apply_to_node(node, attrib_types & apply_types); @@ -414,8 +436,6 @@ r_apply_attribs(PandaNode *node, int attrib_types, // Do we need to copy any children to flatten instances? bool resist_copy = false; - int num_children = node->get_num_children(); - int i; for (i = 0; i < num_children; i++) { PandaNode *child_node = node->get_child(i);