Explorar o código

DCS-flagged nodes shouldn't get their transforms modified by flatten

David Rose %!s(int64=23) %!d(string=hai) anos
pai
achega
78fc774942

+ 17 - 0
panda/src/pgraph/modelNode.cxx

@@ -65,6 +65,23 @@ safe_to_transform() const {
   return !_preserve_transform;
   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
 //     Function: ModelNode::safe_to_combine
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 1 - 0
panda/src/pgraph/modelNode.h

@@ -47,6 +47,7 @@ public:
 
 
   virtual bool safe_to_flatten() const;
   virtual bool safe_to_flatten() const;
   virtual bool safe_to_transform() const;
   virtual bool safe_to_transform() const;
+  virtual bool safe_to_modify_transform() const;
   virtual bool safe_to_combine() const;
   virtual bool safe_to_combine() const;
   virtual bool preserve_name() const;
   virtual bool preserve_name() const;
 
 

+ 17 - 0
panda/src/pgraph/pandaNode.cxx

@@ -470,6 +470,23 @@ safe_to_transform() const {
   return true;
   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
 //     Function: PandaNode::safe_to_combine
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 1 - 0
panda/src/pgraph/pandaNode.h

@@ -69,6 +69,7 @@ public:
 
 
   virtual bool safe_to_flatten() const;
   virtual bool safe_to_flatten() const;
   virtual bool safe_to_transform() const;
   virtual bool safe_to_transform() const;
+  virtual bool safe_to_modify_transform() const;
   virtual bool safe_to_combine() const;
   virtual bool safe_to_combine() const;
   virtual bool preserve_name() const;
   virtual bool preserve_name() const;
   virtual void xform(const LMatrix4f &mat);
   virtual void xform(const LMatrix4f &mat);

+ 22 - 2
panda/src/pgraph/sceneGraphReducer.cxx

@@ -406,6 +406,28 @@ r_apply_attribs(PandaNode *node, int attrib_types,
     apply_types |= TT_transform;
     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,
   // Directly store whatever attributes we must,
   trans.apply_to_node(node, attrib_types & apply_types);
   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?
   // Do we need to copy any children to flatten instances?
   bool resist_copy = false;
   bool resist_copy = false;
-  int num_children = node->get_num_children();
-  int i;
   for (i = 0; i < num_children; i++) {
   for (i = 0; i < num_children; i++) {
     PandaNode *child_node = node->get_child(i);
     PandaNode *child_node = node->get_child(i);