From 3c1914b19a266f831b5bfa7c4ee91e79b0edb7bb Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 5 Jun 2003 23:47:53 +0000 Subject: [PATCH] move joints to end of list on output --- panda/src/egg/eggGroup.cxx | 14 ++++++++++++++ panda/src/egg/eggGroup.h | 2 ++ panda/src/egg/eggGroupNode.cxx | 19 ++++++++++++++++++- panda/src/egg/eggNode.cxx | 14 ++++++++++++++ panda/src/egg/eggNode.h | 2 ++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/panda/src/egg/eggGroup.cxx b/panda/src/egg/eggGroup.cxx index c5a0f2187a..396655297a 100644 --- a/panda/src/egg/eggGroup.cxx +++ b/panda/src/egg/eggGroup.cxx @@ -294,6 +294,20 @@ write(ostream &out, int indent_level) const { indent(out, indent_level) << "}\n"; } +//////////////////////////////////////////////////////////////////// +// Function: EggGroup::is_joint +// Access: Public, Virtual +// Description: Returns true if this particular node represents a +// 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 // Access: Public, Virtual diff --git a/panda/src/egg/eggGroup.h b/panda/src/egg/eggGroup.h index 0df92c0e46..5d98893d55 100644 --- a/panda/src/egg/eggGroup.h +++ b/panda/src/egg/eggGroup.h @@ -99,6 +99,8 @@ public: virtual void write(ostream &out, int indent_level) const; + virtual bool is_joint() const; + virtual EggRenderMode *determine_alpha_mode(); virtual EggRenderMode *determine_depth_write_mode(); virtual EggRenderMode *determine_depth_test_mode(); diff --git a/panda/src/egg/eggGroupNode.cxx b/panda/src/egg/eggGroupNode.cxx index 44d8049e92..bfed304d74 100644 --- a/panda/src/egg/eggGroupNode.cxx +++ b/panda/src/egg/eggGroupNode.cxx @@ -86,8 +86,25 @@ EggGroupNode:: void EggGroupNode:: write(ostream &out, int indent_level) const { 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) { - (*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); + } } } diff --git a/panda/src/egg/eggNode.cxx b/panda/src/egg/eggNode.cxx index 038bbb0f00..7b0ed5cb99 100644 --- a/panda/src/egg/eggNode.cxx +++ b/panda/src/egg/eggNode.cxx @@ -44,6 +44,20 @@ apply_texmats() { r_apply_texmats(textures); } +//////////////////////////////////////////////////////////////////// +// Function: EggNode::is_joint +// Access: Public, Virtual +// Description: Returns true if this particular node represents a +// 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 // Access: Public, Virtual diff --git a/panda/src/egg/eggNode.h b/panda/src/egg/eggNode.h index 85834d6e00..01879bd02b 100644 --- a/panda/src/egg/eggNode.h +++ b/panda/src/egg/eggNode.h @@ -63,6 +63,8 @@ public: INLINE void flatten_transforms(); void apply_texmats(); + virtual bool is_joint() const; + virtual EggRenderMode *determine_alpha_mode(); virtual EggRenderMode *determine_depth_write_mode(); virtual EggRenderMode *determine_depth_test_mode();