Przeglądaj źródła

move joints to end of list on output

David Rose 22 lat temu
rodzic
commit
3c1914b19a

+ 14 - 0
panda/src/egg/eggGroup.cxx

@@ -294,6 +294,20 @@ write(ostream &out, int indent_level) const {
   indent(out, indent_level) << "}\n";
   indent(out, indent_level) << "}\n";
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggGroup::is_joint
+//       Access: Public, Virtual
+//  Description: Returns true if this particular node represents a
+//               <Joint> entry or not.  This is a handy thing to know
+//               since Joints are sorted to the end of their sibling
+//               list when writing an egg file.  See
+//               EggGroupNode::write().
+////////////////////////////////////////////////////////////////////
+bool EggGroup::
+is_joint() const {
+  return (get_group_type() == GT_joint);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: EggGroup::determine_alpha_mode
 //     Function: EggGroup::determine_alpha_mode
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 2 - 0
panda/src/egg/eggGroup.h

@@ -99,6 +99,8 @@ public:
 
 
   virtual void write(ostream &out, int indent_level) const;
   virtual void write(ostream &out, int indent_level) const;
 
 
+  virtual bool is_joint() const;
+
   virtual EggRenderMode *determine_alpha_mode();
   virtual EggRenderMode *determine_alpha_mode();
   virtual EggRenderMode *determine_depth_write_mode();
   virtual EggRenderMode *determine_depth_write_mode();
   virtual EggRenderMode *determine_depth_test_mode();
   virtual EggRenderMode *determine_depth_test_mode();

+ 18 - 1
panda/src/egg/eggGroupNode.cxx

@@ -86,8 +86,25 @@ EggGroupNode::
 void EggGroupNode::
 void EggGroupNode::
 write(ostream &out, int indent_level) const {
 write(ostream &out, int indent_level) const {
   iterator i;
   iterator i;
+
+  // Since joints tend to reference vertex pools, which sometimes
+  // appear later in the file, and since generally non-joints don't
+  // reference joints, we try to maximize our chance of writing out a
+  // one-pass readable egg file by writing joints at the end of the
+  // list of children of a particular node.
+
   for (i = begin(); i != end(); ++i) {
   for (i = begin(); i != end(); ++i) {
-    (*i)->write(out, indent_level);
+    PT(EggNode) child = (*i);
+    if (!child->is_joint()) {
+      child->write(out, indent_level);
+    }
+  }
+
+  for (i = begin(); i != end(); ++i) {
+    PT(EggNode) child = (*i);
+    if (child->is_joint()) {
+      child->write(out, indent_level);
+    }
   }
   }
 }
 }
 
 

+ 14 - 0
panda/src/egg/eggNode.cxx

@@ -44,6 +44,20 @@ apply_texmats() {
   r_apply_texmats(textures);
   r_apply_texmats(textures);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggNode::is_joint
+//       Access: Public, Virtual
+//  Description: Returns true if this particular node represents a
+//               <Joint> entry or not.  This is a handy thing to know
+//               since Joints are sorted to the end of their sibling
+//               list when writing an egg file.  See
+//               EggGroupNode::write().
+////////////////////////////////////////////////////////////////////
+bool EggNode::
+is_joint() const {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: EggNode::determine_alpha_mode
 //     Function: EggNode::determine_alpha_mode
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 2 - 0
panda/src/egg/eggNode.h

@@ -63,6 +63,8 @@ public:
   INLINE void flatten_transforms();
   INLINE void flatten_transforms();
   void apply_texmats();
   void apply_texmats();
 
 
+  virtual bool is_joint() const;
+
   virtual EggRenderMode *determine_alpha_mode();
   virtual EggRenderMode *determine_alpha_mode();
   virtual EggRenderMode *determine_depth_write_mode();
   virtual EggRenderMode *determine_depth_write_mode();
   virtual EggRenderMode *determine_depth_test_mode();
   virtual EggRenderMode *determine_depth_test_mode();