diff --git a/pandatool/src/eggcharbase/eggJointData.I b/pandatool/src/eggcharbase/eggJointData.I index 2e3aa8b793..f34d27594e 100644 --- a/pandatool/src/eggcharbase/eggJointData.I +++ b/pandatool/src/eggcharbase/eggJointData.I @@ -48,6 +48,21 @@ get_child(int n) const { return _children[n]; } +//////////////////////////////////////////////////////////////////// +// Function: EggJointData::find_joint +// Access: Public +// Description: Returns the first descendent joint found with the +// indicated name, or NULL if no joint has that name. +//////////////////////////////////////////////////////////////////// +INLINE EggJointData *EggJointData:: +find_joint(const string &name) { + EggJointData *joint = find_joint_exact(name); + if (joint == (EggJointData *)NULL) { + joint = find_joint_matches(name); + } + return joint; +} + //////////////////////////////////////////////////////////////////// // Function: EggJointData::has_rest_frame // Access: Public diff --git a/pandatool/src/eggcharbase/eggJointData.cxx b/pandatool/src/eggcharbase/eggJointData.cxx index 8eeef98d43..39d40a06b0 100644 --- a/pandatool/src/eggcharbase/eggJointData.cxx +++ b/pandatool/src/eggcharbase/eggJointData.cxx @@ -44,29 +44,6 @@ EggJointData(EggCharacterCollection *collection, _rest_frames_differ = false; } -//////////////////////////////////////////////////////////////////// -// Function: EggJointData::find_joint -// Access: Public -// Description: Returns the first descendent joint found with the -// indicated name, or NULL if no joint has that name. -//////////////////////////////////////////////////////////////////// -EggJointData *EggJointData:: -find_joint(const string &name) { - Children::const_iterator ci; - for (ci = _children.begin(); ci != _children.end(); ++ci) { - EggJointData *child = (*ci); - if (child->get_name() == name) { - return child; - } - EggJointData *result = child->find_joint(name); - if (result != (EggJointData *)NULL) { - return result; - } - } - - return (EggJointData *)NULL; -} - //////////////////////////////////////////////////////////////////// // Function: EggJointData::get_frame // Access: Public @@ -438,6 +415,53 @@ do_finish_reparent() { return all_ok; } +//////////////////////////////////////////////////////////////////// +// Function: EggJointData::find_joint_exact +// Access: Private +// Description: The recursive implementation of find_joint, this +// flavor searches recursively for an exact match of the +// preferred joint name. +//////////////////////////////////////////////////////////////////// +EggJointData *EggJointData:: +find_joint_exact(const string &name) { + Children::const_iterator ci; + for (ci = _children.begin(); ci != _children.end(); ++ci) { + EggJointData *child = (*ci); + if (child->get_name() == name) { + return child; + } + EggJointData *result = child->find_joint_exact(name); + if (result != (EggJointData *)NULL) { + return result; + } + } + + return (EggJointData *)NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggJointData::find_joint_matches +// Access: Private +// Description: The recursive implementation of find_joint, this +// flavor searches recursively for any acceptable match. +//////////////////////////////////////////////////////////////////// +EggJointData *EggJointData:: +find_joint_matches(const string &name) { + Children::const_iterator ci; + for (ci = _children.begin(); ci != _children.end(); ++ci) { + EggJointData *child = (*ci); + if (child->matches_name(name)) { + return child; + } + EggJointData *result = child->find_joint_matches(name); + if (result != (EggJointData *)NULL) { + return result; + } + } + + return (EggJointData *)NULL; +} + //////////////////////////////////////////////////////////////////// // Function: EggJointData::get_new_net_frame // Access: Private diff --git a/pandatool/src/eggcharbase/eggJointData.h b/pandatool/src/eggcharbase/eggJointData.h index 3c4d368888..5f1778153d 100644 --- a/pandatool/src/eggcharbase/eggJointData.h +++ b/pandatool/src/eggcharbase/eggJointData.h @@ -41,7 +41,7 @@ public: INLINE EggJointData *get_parent() const; INLINE int get_num_children() const; INLINE EggJointData *get_child(int n) const; - EggJointData *find_joint(const string &name); + INLINE EggJointData *find_joint(const string &name); LMatrix4d get_frame(int model_index, int n) const; LMatrix4d get_net_frame(int model_index, int n) const; @@ -69,6 +69,9 @@ protected: bool do_finish_reparent(); private: + EggJointData *find_joint_exact(const string &name); + EggJointData *find_joint_matches(const string &name); + const LMatrix4d &get_new_net_frame(int model_index, int n); const LMatrix4d &get_new_net_frame_inv(int model_index, int n); LMatrix4d get_new_frame(int model_index, int n);