Bläddra i källkod

fix flatten some more

David Rose 24 år sedan
förälder
incheckning
4cb4ba7598

+ 6 - 0
panda/src/graph/graphReducer.cxx

@@ -377,6 +377,12 @@ collapse_siblings(Node *parent, NodeRelation *arc1, NodeRelation *arc2) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 Node *GraphReducer::
 Node *GraphReducer::
 collapse_nodes(Node *node1, Node *node2, bool) {
 collapse_nodes(Node *node1, Node *node2, bool) {
+  if (!node1->safe_to_combine() || !node2->safe_to_combine()) {
+    // One or both nodes cannot be safely combined with another node;
+    // do nothing.
+    return NULL;
+  }
+
   // We get to choose whether to remove node1 or node2.
   // We get to choose whether to remove node1 or node2.
   if (node2->is_exact_type(Node::get_class_type()) ||
   if (node2->is_exact_type(Node::get_class_type()) ||
       node2->is_exact_type(NamedNode::get_class_type())) {
       node2->is_exact_type(NamedNode::get_class_type())) {

+ 14 - 0
panda/src/graph/node.cxx

@@ -159,6 +159,20 @@ safe_to_transform() const {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: Node::safe_to_combine
+//       Access: Public, Virtual
+//  Description: Returns true if it is generally safe to combine
+//               this particular kind of Node with other kinds of
+//               Nodes, adding children or whatever.  For instance, an
+//               LODNode should not be combined with any other node,
+//               because its set of children is meaningful.
+////////////////////////////////////////////////////////////////////
+bool Node::
+safe_to_combine() const {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Node::xform
 //     Function: Node::xform
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 1 - 0
panda/src/graph/node.h

@@ -68,6 +68,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_combine() const;
   virtual void xform(const LMatrix4f &mat);
   virtual void xform(const LMatrix4f &mat);
 
 
   virtual void transform_changed(NodeRelation *arc);
   virtual void transform_changed(NodeRelation *arc);

+ 15 - 0
panda/src/sgraph/switchNode.cxx

@@ -19,3 +19,18 @@
 #include "switchNode.h"
 #include "switchNode.h"
 
 
 TypeHandle SwitchNode::_type_handle;
 TypeHandle SwitchNode::_type_handle;
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: SwitchNode::safe_to_combine
+//       Access: Public, Virtual
+//  Description: Returns true if it is generally safe to combine
+//               this particular kind of Node with other kinds of
+//               Nodes, adding children or whatever.  For instance, an
+//               LODNode should not be combined with any other node,
+//               because its set of children is meaningful.
+////////////////////////////////////////////////////////////////////
+bool SwitchNode::
+safe_to_combine() const {
+  return false;
+}

+ 1 - 0
panda/src/sgraph/switchNode.h

@@ -44,6 +44,7 @@ PUBLISHED:
   INLINE void operator = (const SwitchNode &copy);
   INLINE void operator = (const SwitchNode &copy);
 
 
 public:
 public:
+  virtual bool safe_to_combine() const;
   virtual void compute_switch(RenderTraverser *trav)=0;
   virtual void compute_switch(RenderTraverser *trav)=0;
 
 
   virtual bool is_child_visible(TypeHandle type, int index)=0;
   virtual bool is_child_visible(TypeHandle type, int index)=0;