Overte C++ Documentation
AnimClip.h
1 //
2 // AnimClip.h
3 //
4 // Created by Anthony J. Thibault on 9/2/15.
5 // Copyright (c) 2015 High Fidelity, Inc. All rights reserved.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_AnimClip_h
12 #define hifi_AnimClip_h
13 
14 #include <string>
15 #include "AnimationCache.h"
16 #include "AnimNode.h"
17 
18 // Playback a single animation timeline.
19 // url determines the location of the fbx file to use within this clip.
20 // startFrame and endFrame are in frames 1/30th of a second.
21 // timescale can be used to speed-up or slow-down the animation.
22 // loop flag, when true, will loop the animation as it reaches the end frame.
23 
24 class AnimClip : public AnimNode {
25 public:
26  friend class AnimTests;
27 
28  AnimClip(const QString& id, const QString& url, float startFrame, float endFrame, float timeScale, bool loopFlag, bool mirrorFlag,
29  AnimBlendType blendType, const QString& baseURL, float baseFrame);
30  virtual ~AnimClip() override;
31 
32  virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) override;
33 
34  void setStartFrameVar(const QString& startFrameVar) { _startFrameVar = startFrameVar; }
35  void setEndFrameVar(const QString& endFrameVar) { _endFrameVar = endFrameVar; }
36  void setTimeScaleVar(const QString& timeScaleVar) { _timeScaleVar = timeScaleVar; }
37  void setLoopFlagVar(const QString& loopFlagVar) { _loopFlagVar = loopFlagVar; }
38  void setMirrorFlagVar(const QString& mirrorFlagVar) { _mirrorFlagVar = mirrorFlagVar; }
39  void setFrameVar(const QString& frameVar) { _frameVar = frameVar; }
40 
41  float getStartFrame() const { return _startFrame; }
42  void setStartFrame(float startFrame) { _startFrame = startFrame; }
43  float getEndFrame() const { return _endFrame; }
44  void setEndFrame(float endFrame) { _endFrame = endFrame; }
45 
46  void setTimeScale(float timeScale) { _timeScale = timeScale; }
47  float getTimeScale() const { return _timeScale; }
48 
49  bool getLoopFlag() const { return _loopFlag; }
50  void setLoopFlag(bool loopFlag) { _loopFlag = loopFlag; }
51 
52  bool getMirrorFlag() const { return _mirrorFlag; }
53  void setMirrorFlag(bool mirrorFlag) { _mirrorFlag = mirrorFlag; }
54 
55  float getFrame() const { return _frame; }
56  void loadURL(const QString& url);
57 
58  AnimBlendType getBlendType() const { return _blendType; };
59 
60 protected:
61 
62  virtual void setCurrentFrameInternal(float frame) override;
63 
64  void buildMirrorAnim();
65 
66  // for AnimDebugDraw rendering
67  virtual const AnimPoseVec& getPosesInternal() const override;
68 
69  AnimationPointer _networkAnim;
70  AnimationPointer _baseNetworkAnim;
71 
72  AnimPoseVec _poses;
73 
74  // _anim[frame][joint]
75  std::vector<AnimPoseVec> _anim;
76  std::vector<AnimPoseVec> _mirrorAnim;
77 
78  QString _url;
79  float _startFrame;
80  float _endFrame;
81  float _timeScale;
82  bool _loopFlag;
83  bool _mirrorFlag;
84  float _frame;
85  AnimBlendType _blendType;
86  QString _baseURL;
87  float _baseFrame;
88 
89  QString _startFrameVar;
90  QString _endFrameVar;
91  QString _timeScaleVar;
92  QString _loopFlagVar;
93  QString _mirrorFlagVar;
94  QString _frameVar;
95 
96  // no copies
97  AnimClip(const AnimClip&) = delete;
98  AnimClip& operator=(const AnimClip&) = delete;
99 };
100 
101 #endif // hifi_AnimClip_h