diff --git a/panda/src/char/character.cxx b/panda/src/char/character.cxx index 8e9694c932..37284647ba 100644 --- a/panda/src/char/character.cxx +++ b/panda/src/char/character.cxx @@ -806,10 +806,7 @@ r_clear_joint_characters(PartGroup *part) { if (part->is_of_type(CharacterJoint::get_class_type())) { CharacterJoint *joint = DCAST(CharacterJoint, part); - // Whoops! We are not properly assigning the joint->_character - // node when we flatten characters! TODO: fix this. - // nassertv(joint->get_character() == this || joint->get_character() == NULL); - + nassertv(joint->get_character() == this || joint->get_character() == NULL); joint->set_character(NULL); } diff --git a/panda/src/char/characterJoint.h b/panda/src/char/characterJoint.h index 42a4363c70..6e44169383 100644 --- a/panda/src/char/characterJoint.h +++ b/panda/src/char/characterJoint.h @@ -126,6 +126,7 @@ private: static TypeHandle _type_handle; friend class Character; + friend class CharacterJointBundle; friend class JointVertexTransform; }; diff --git a/panda/src/char/characterJointBundle.cxx b/panda/src/char/characterJointBundle.cxx index dc82407ffb..f89f9b8081 100644 --- a/panda/src/char/characterJointBundle.cxx +++ b/panda/src/char/characterJointBundle.cxx @@ -35,7 +35,7 @@ CharacterJointBundle(const string &name) : PartBundle(name) { //////////////////////////////////////////////////////////////////// // Function: CharacterJointBundle::make_copy -// Access: Public, Virtual +// Access: Protected, Virtual // Description: Allocates and returns a new copy of the node. // Children are not copied, but see copy_subgraph(). //////////////////////////////////////////////////////////////////// @@ -44,6 +44,41 @@ make_copy() const { return new CharacterJointBundle(*this); } +//////////////////////////////////////////////////////////////////// +// Function: CharacterJointBundle::set_node +// Access: Protected, Virtual +// Description: Changes the PartBundleNode pointer associated with +// the PartBundle. Normally called only by the +// PartBundleNode itself, for instance when the bundle +// is flattened with another node. +//////////////////////////////////////////////////////////////////// +void CharacterJointBundle:: +set_node(PartBundleNode *node) { + PartBundle::set_node(node); + if (node->is_of_type(Character::get_class_type())) { + Character *character = DCAST(Character, node); + r_set_character(this, character); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: CharacterJointBundle::r_set_character +// Access: Private +// Description: Recursively sets the Character on each joint in the +// hierarchy. +//////////////////////////////////////////////////////////////////// +void CharacterJointBundle:: +r_set_character(PartGroup *group, Character *character) { + if (group->is_of_type(CharacterJoint::get_class_type())) { + DCAST(CharacterJoint, group)->set_character(character); + } + + Children::const_iterator ci; + for (ci = group->_children.begin(); ci != group->_children.end(); ++ci) { + r_set_character((*ci), character); + } +} + //////////////////////////////////////////////////////////////////// // Function: CharacterJointBundle::make_CharacterJointBundle // Access: Protected diff --git a/panda/src/char/characterJointBundle.h b/panda/src/char/characterJointBundle.h index f739d82bfa..ec08035d30 100644 --- a/panda/src/char/characterJointBundle.h +++ b/panda/src/char/characterJointBundle.h @@ -42,9 +42,14 @@ public: PUBLISHED: INLINE Character *get_node() const; -public: +protected: virtual PartGroup *make_copy() const; + virtual void set_node(PartBundleNode *node); +private: + void r_set_character(PartGroup *group, Character *character); + +public: static void register_with_read_factory(); static TypedWritable *make_CharacterJointBundle(const FactoryParams ¶ms);