diff --git a/panda/src/chan/animControl.I b/panda/src/chan/animControl.I index 0d04cf4cdd..63df29f07f 100644 --- a/panda/src/chan/animControl.I +++ b/panda/src/chan/animControl.I @@ -116,8 +116,15 @@ get_anim() const { //////////////////////////////////////////////////////////////////// // Function: AnimControl::get_channel_index -// Access: Public -// Description: +// Access: Published +// Description: Returns the particular channel index associated with +// this AnimControl. This channel index is the slot on +// which each AnimGroup is bound to its associated +// PartGroup, for each joint in the animation. +// +// It will be true that +// get_part()->find_child("n")->get_bound(get_channel_index()) +// == get_anim()->find_child("n"), for each joint "n". //////////////////////////////////////////////////////////////////// INLINE int AnimControl:: get_channel_index() const { diff --git a/panda/src/chan/animControl.h b/panda/src/chan/animControl.h index 49f3fed179..125de0e2fa 100644 --- a/panda/src/chan/animControl.h +++ b/panda/src/chan/animControl.h @@ -73,6 +73,7 @@ PUBLISHED: PartBundle *get_part() const; INLINE AnimBundle *get_anim() const; + INLINE int get_channel_index() const; void output(ostream &out) const; @@ -86,8 +87,6 @@ public: bool channel_has_changed(AnimChannelBase *channel) const; void mark_channels(); - INLINE int get_channel_index() const; - private: enum ActionType { diff --git a/panda/src/chan/movingPartBase.I b/panda/src/chan/movingPartBase.I index 808c5bed44..229a22b35b 100644 --- a/panda/src/chan/movingPartBase.I +++ b/panda/src/chan/movingPartBase.I @@ -29,3 +29,37 @@ MovingPartBase(const MovingPartBase ©) : { // We don't copy the bound channels. } + +//////////////////////////////////////////////////////////////////// +// Function: MovingPartBase::get_max_bound +// Access: Published +// Description: Returns the number of channels that might be bound to +// this PartGroup. This might not be the actual number +// of channels, since there might be holes in the list; +// it is one more than the index number of the highest +// bound channel. Thus, it is called get_max_bound() +// instead of get_num_bound(). +//////////////////////////////////////////////////////////////////// +INLINE int MovingPartBase:: +get_max_bound() const { + return _channels.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: MovingPartBase::get_bound +// Access: Published +// Description: Returns the nth bound channel on this PartGroup. n +// can be determined by iterating from 0 to one less +// than get_max_bound(); or n might be +// AnimControl::get_channel_index(). +// +// This will return NULL if there is no channel bound on +// the indicated index. It is an error to call this if +// n is less than zero or greater than or equal to +// get_max_bound(). +//////////////////////////////////////////////////////////////////// +INLINE AnimChannelBase *MovingPartBase:: +get_bound(int n) const { + nassertr(n >= 0 && n < (int)_channels.size(), NULL); + return _channels[n]; +} diff --git a/panda/src/chan/movingPartBase.cxx b/panda/src/chan/movingPartBase.cxx index 42b986f461..18e14ddb08 100644 --- a/panda/src/chan/movingPartBase.cxx +++ b/panda/src/chan/movingPartBase.cxx @@ -208,6 +208,10 @@ pick_channel_index(plist &holes, int &next) const { //////////////////////////////////////////////////////////////////// void MovingPartBase:: bind_hierarchy(AnimGroup *anim, int channel_index) { + if (chan_cat.is_debug()) { + chan_cat.debug() + << "binding " << *this << " to " << *anim << "\n"; + } while ((int)_channels.size() <= channel_index) { _channels.push_back((AnimChannelBase*)0L); } diff --git a/panda/src/chan/movingPartBase.h b/panda/src/chan/movingPartBase.h index 5ce05383a5..6ac1cbd98a 100644 --- a/panda/src/chan/movingPartBase.h +++ b/panda/src/chan/movingPartBase.h @@ -42,6 +42,11 @@ protected: public: MovingPartBase(PartGroup *parent, const string &name); +PUBLISHED: + INLINE int get_max_bound() const; + INLINE AnimChannelBase *get_bound(int n) const; + +public: virtual TypeHandle get_value_type() const=0; virtual AnimChannelBase *make_initial_channel() const=0; virtual void write(ostream &out, int indent_level) const; diff --git a/panda/src/chan/partGroup.cxx b/panda/src/chan/partGroup.cxx index 0d015c14f0..67fb72c735 100644 --- a/panda/src/chan/partGroup.cxx +++ b/panda/src/chan/partGroup.cxx @@ -168,7 +168,7 @@ public: //////////////////////////////////////////////////////////////////// void PartGroup:: sort_descendants() { - sort(_children.begin(), _children.end(), PartGroupAlphabeticalOrder()); + stable_sort(_children.begin(), _children.end(), PartGroupAlphabeticalOrder()); Children::iterator ci; for (ci = _children.begin(); ci != _children.end(); ++ci) {