From 3ffcce2cc2b5c83425c18dc1fe9461987f67d89d Mon Sep 17 00:00:00 2001 From: Wizzerinus Date: Thu, 25 Apr 2024 14:55:30 +0300 Subject: [PATCH] add getPlayMode() for actor and anim interface --- direct/src/actor/Actor.py | 12 ++++++++++-- panda/src/putil/animInterface.I | 15 +++++++++++++++ panda/src/putil/animInterface.h | 17 ++++++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/direct/src/actor/Actor.py b/direct/src/actor/Actor.py index 263ac8803a..cc81d525ca 100644 --- a/direct/src/actor/Actor.py +++ b/direct/src/actor/Actor.py @@ -737,6 +737,13 @@ class Actor(DirectObject, NodePath): else: return None + def getPlayMode(self, animName=None, partName=None): + if self.__animControlDict: + controls = self.getAnimControls(animName, partName, onlyPlaying=False) + if controls: + return controls[0].getPlayMode() + return None + def hasLOD(self): """ Return 1 if the actor has LODs, 0 otherwise @@ -1762,7 +1769,7 @@ class Actor(DirectObject, NodePath): return None def getAnimControls(self, animName=None, partName=None, lodName=None, - allowAsyncBind = True): + allowAsyncBind = True, onlyPlaying = True): """getAnimControls(self, string, string=None, string=None) Returns a list of the AnimControls that represent the given @@ -1840,7 +1847,7 @@ class Actor(DirectObject, NodePath): # get all playing animations for thisPart, animDict in animDictItems: for anim in animDict.values(): - if anim.animControl and anim.animControl.isPlaying(): + if anim.animControl and (not onlyPlaying or anim.animControl.isPlaying()): controls.append(anim.animControl) else: # get the named animation(s) only. @@ -2660,3 +2667,4 @@ class Actor(DirectObject, NodePath): get_base_frame_rate = getBaseFrameRate remove_anim_control_dict = removeAnimControlDict load_anims_on_all_lods = loadAnimsOnAllLODs + get_play_mode = getPlayMode diff --git a/panda/src/putil/animInterface.I b/panda/src/putil/animInterface.I index 3d09f34a00..17f8494654 100644 --- a/panda/src/putil/animInterface.I +++ b/panda/src/putil/animInterface.I @@ -231,6 +231,16 @@ is_playing() const { return cdata->is_playing(); } +/** + * Returns the current play mode of the animation; whether the animation is + * playing normally, looping, posing, or in ping-pong mode. + */ +INLINE AnimInterface::PlayMode AnimInterface:: +get_play_mode() const { + CDReader cdata(_cycler); + return cdata->get_play_mode(); +} + /** * Should be called by a derived class to specify the native frame rate of the * animation. It is legal to call this after the animation has already @@ -266,6 +276,11 @@ get_frac() const { return get_full_fframe() - (double)get_full_frame(0); } +INLINE AnimInterface::PlayMode AnimInterface::CData:: +get_play_mode() const { + return _play_mode; +} + INLINE std::ostream & operator << (std::ostream &out, const AnimInterface &ai) { ai.output(out); diff --git a/panda/src/putil/animInterface.h b/panda/src/putil/animInterface.h index 80f2a3da9d..5e29ed3140 100644 --- a/panda/src/putil/animInterface.h +++ b/panda/src/putil/animInterface.h @@ -38,6 +38,13 @@ protected: AnimInterface(const AnimInterface ©); PUBLISHED: + enum PlayMode { + PM_pose, + PM_play, + PM_loop, + PM_pingpong, + }; + virtual ~AnimInterface(); INLINE void play(); INLINE void play(double from, double to); @@ -59,6 +66,7 @@ PUBLISHED: INLINE int get_full_frame() const; INLINE double get_full_fframe() const; INLINE bool is_playing() const; + INLINE PlayMode get_play_mode() const; virtual void output(std::ostream &out) const; @@ -73,6 +81,7 @@ PUBLISHED: MAKE_PROPERTY(full_frame, get_full_frame); MAKE_PROPERTY(full_fframe, get_full_fframe); MAKE_PROPERTY(playing, is_playing); + MAKE_PROPERTY(play_mode, get_play_mode); protected: INLINE void set_frame_rate(double frame_rate); @@ -80,13 +89,6 @@ protected: virtual void animation_activated(); private: - enum PlayMode { - PM_pose, - PM_play, - PM_loop, - PM_pingpong, - }; - // This data is not cycled, because it is a semi-permanent part of the // interface. Also, some derivatives of AnimInterface don't even use it. int _num_frames; @@ -112,6 +114,7 @@ private: int get_full_frame(int increment) const; double get_full_fframe() const; bool is_playing() const; + INLINE PlayMode get_play_mode() const; virtual void output(std::ostream &out) const;