2 #ifndef KJY_ANIM_ENGINE_COMPONENTS_POSE_KEYFRAME_ANIMATION_HPP_     3 #define KJY_ANIM_ENGINE_COMPONENTS_POSE_KEYFRAME_ANIMATION_HPP_     7 #include <util/common.h>     9 #include "AttachableComponent.hpp"    10 #include <util/UUID.hpp>    14 typedef size_t key_time_t;
    16 key_time_t seconds_to_key_time(
double seconds);
    17 double key_time_to_seconds(key_time_t time);
    20 enum class InterpolationType{interp_step, interp_linear, interp_cubicspline}; 
    26     KeyframeTemplate<T>(
const T& t, 
const T& aInTangent, 
const T& aOutTangent) : mKeyValue(t), mInTangent(aInTangent), mOutTangent(aOutTangent) {}
    30     T mInTangent, mOutTangent; 
    31     InterpolationType mInterpolationType = InterpolationType::interp_linear;
    33     virtual const T& getKeyValue()
 const {
return(mKeyValue);}
    34     virtual void setKeyValue(
const T& value){mKeyValue = value;}
    36     T interpolate_with_other(
const KeyframeTemplate& other, 
double parameter) 
const = 
delete;
    41     ChannelNoKeyframeException(
const std::string& find_hint, 
size_t time_ms) : _whatstr(
"No keyframe exists to be returned when calling " + find_hint + 
"with timecode " + std::to_string(time_ms)){}
    42     const char* what() 
const noexcept {
    43         return(_whatstr.c_str());
    47     const std::string _whatstr;
    50 template<
typename keyframe_t>
    54     using property_t = 
typename keyframe_t::property_t;
    56     inline const keyframe_t& at_index(
size_t index)
 const {
    57         assert(this->size() > index);
    58         return(std::next(this->begin(), index)->second);
    60     inline keyframe_t& at_index(
size_t index) {
    61         assert(this->size() > index);
    62         return(std::next(this->begin(), index)->second);
    65     inline key_time_t getLength()
 const {
return(this->size() == 0 ? 0 : this->rbegin()->first);}
    66     std::pair<key_time_t, const keyframe_t&> getNearestKey(key_time_t time_ms) 
const;
    67     std::pair<key_time_t, const keyframe_t&> getNearestKeyBefore(key_time_t time_ms) 
const;
    68     std::pair<key_time_t, const keyframe_t&> getNearestKeyAfter(key_time_t time_ms) 
const;
    70     property_t sample(key_time_t time_ms) 
const;
    73     property_t _mFallbackValue;
    79     using keyframe_template::keyframe_template;
    80     using property_t = keyframe_template::property_t; 
    82     property_t interpolate_with_other(
const Vec3Keyframe& other, 
double parameter) 
const;
    87     using keyframe_template::keyframe_template;
    88     using property_t = keyframe_template::property_t; 
    90     property_t interpolate_with_other(
const QuatKeyframe& other, 
double parameter) 
const;
    96     virtual key_time_t getLength() 
const = 0;
    97     virtual property_t sample(key_time_t time_ms) 
const = 0;
    98     virtual void sampleInPlace(key_time_t time, P& target_prop) 
const = 0;
   101 template<
typename P, 
typename K>
   103     using property_t = P;
   105     virtual key_time_t getLength() 
const = 0;
   106     virtual property_t sample(K key, key_time_t time_ms) 
const = 0;
   107     virtual void sampleInPlace(K key, key_time_t time, P& target_prop) 
const = 0;
   113 template<
typename Sequence, 
typename K>
   116     using inherited_map = std::map<K, Sequence>;
   117     using inherited_map::inherited_map;
   118     using sequence_selection = 
typename inherited_map::iterator;
   119     using const_sequence_selection = 
typename inherited_map::const_iterator;
   120     key_time_t getLength()
 const{
   122         for(
auto pair_iter = this->begin(); pair_iter != this->end(); pair_iter++){
   123             key_time_t seq_len = pair_iter->second.getLength();
   124             max = max < seq_len ? seq_len : max;
   132     virtual key_time_t getCurrentTime() 
const = 0;
   133     virtual void setCurrentTime(key_time_t time) = 0;
   134     virtual std::string getAnimatorName() 
const = 0;
   135     virtual void setAnimatorName(
const std::string& name) = 0;
   136     virtual bool isEnabled() 
const = 0;
   137     virtual void enable() = 0;
   138     virtual void disable() = 0;
   139     virtual bool willLoop() 
const = 0;
   140     virtual void enableLoop() = 0;
   141     virtual void disableLoop() = 0;
   143     virtual void overrideLoopTime(key_time_t time) = 0;
   145     virtual void resetLoopTime() = 0;
   148     virtual key_time_t getLength() 
const = 0;
   151 typedef std::vector<Animator*> AnimatorCollection;
   161         void keyPose(key_time_t time, 
const Pose& pose);
   163         inline key_time_t getLength()
 const {
return(MAX(translation.getLength(), MAX(scale.getLength(), orientation.getLength())));}
   174     inline key_time_t getLength()
 const {
return(keyframes.getLength());}
   175     inline void setUnderlyingPose(
const Pose& pose) {_underlying_pose_ = pose;}
   176     Pose sample(key_time_t time_ms) 
const;
   177     void sampleInPlace(key_time_t time_ms, 
Pose& target) 
const;
   178     Pose sample(key_time_t time_ms, 
const Pose& initial_state) 
const;
   181    Pose _underlying_pose_;
   193     virtual key_time_t getCurrentTime() 
const override;
   194     virtual void setCurrentTime(key_time_t time) 
override;
   195     virtual std::string getAnimatorName() 
const override;
   196     virtual void setAnimatorName(
const std::string& name) 
override;
   197     virtual void setFallbackPose(
const Pose& fallback) {_fallback_pose_ = fallback;}
   198     virtual key_time_t getLength() 
const override ;
   200     virtual bool isEnabled()
 const override {
return(_enabled);}
   201     virtual void enable()
 override {_enabled = 
true;}
   202     virtual void disable()
 override {_enabled = 
false;}
   204     virtual bool willLoop()
 const override {
return(_loops);}
   205     virtual void enableLoop()
 override {_loops = 
true;};
   206     virtual void disableLoop()
 override {_loops = 
false;}
   208     virtual void overrideLoopTime(key_time_t time)
 override {_loop_time = time;}
   210     virtual void resetLoopTime()
 override {_loop_time = 0;}
   213     std::string _animation_name;
   214     key_time_t _current_time;
   216     bool _enabled = 
true;
   218     key_time_t _loop_time = 0;
   222     Pose _fallback_pose_;
 Definition: KeyframeAnimation.hpp:51
Definition: KeyframeAnimation.hpp:39
Definition: KeyframeAnimation.hpp:114
Definition: KeyframeAnimation.hpp:77
Definition: KeyframeAnimation.hpp:23
Definition: KeyframeAnimation.hpp:155
Definition: KeyframeAnimation.hpp:94
Definition: KeyframeAnimation.hpp:102
Definition: AttachableComponent.hpp:5
Definition: KeyframeAnimation.hpp:184
Definition: KeyframeAnimation.hpp:85
Definition: KeyframeAnimation.hpp:153
Definition: KeyframeAnimation.hpp:130