Atoms Crowd  7.0.0
AnimationClipLooper.impl.h
1 // ===========================================================================
2 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
3 //
4 // Use of this software is subject to the terms of the Toolchefs license
5 // agreement provided at the time of installation or download, or which
6 // otherwise accompanies this software in either electronic or hard copy form.
7 // ===========================================================================
8 
9 namespace Atoms
10 {
11  /*
12  void AnimationClipLooper::setAnimationClip(const AnimationClip &animationClip)
13  {
14  m_animationClip = &animationClip;
15 
16  m_numBlendFrames = 0;
17  m_loopStart = 0;
18  m_loopEnd = m_animationClip->numFrames();
19  }
20  */
21 
23  {
24  return m_animationClip;
25  }
26 
28  {
29  return m_animationClip.get() != nullptr;
30  }
31 
33  {
34  return m_animationClip->numJoints();
35  }
36 
38  {
39  if (static_cast<int>(value) > (m_animationClip->numFrames() - 1) || (m_loopStart - value) < 0)
40  {
41  Logger::error() << "Blend frame value outside range " << m_loopStart << "-" << m_animationClip->numFrames() - 1;
42  return;
43  }
44 
45  m_numBlendFrames = value;
46  }
47 
49  {
50  return m_numBlendFrames;
51  }
52 
53  void AnimationClipLooper::setLoopStartFrame(unsigned int value)
54  {
55  if (value > m_loopEnd)
56  {
57  Logger::error() << "Loop start value outside range 0-" << m_loopEnd << " : " << value;
58  return;
59  }
60 
61  if (value - m_numBlendFrames < 0)
62  {
63  Logger::error() << "Blend frames value outside range " << value << "-" << m_animationClip->numFrames() - 1 << ". Resetting number of blend frames to 0.";
64  m_numBlendFrames = 0;
65  }
66 
67  m_loopStart = value;
68  }
69 
71  {
72  return m_loopStart;
73  }
74 
75  void AnimationClipLooper::setLoopEndFrame(unsigned int value)
76  {
77  if (value < m_loopStart || static_cast<int>(value) > (m_animationClip->numFrames() - 1))
78  {
79  Logger::error() << "Loop end value outside range " << m_loopStart << "-" << m_animationClip->numFrames() - 1 << " : " << value;
80  m_loopEnd = m_loopStart + m_animationClip->numFrames() - 1;
81  return;
82  }
83  m_loopEnd = value;
84  }
85 
86  unsigned int AnimationClipLooper::loopEndFrame() const
87  {
88  return m_loopEnd;
89  }
90 
91  unsigned int AnimationClipLooper::mapTimeToFrame(const double time, double &reminder, unsigned int &nextFrame, int offset) const
92  {
93  if (!m_animationClip) return -1;
94  unsigned int frame = m_animationClip->mapTimeToFrame(time, reminder);
95  int relative_duration = std::max(1u, m_loopEnd - m_loopStart);
96  int signedFrame = frame + offset;
97  frame = signedFrame < 0 ? m_loopEnd - (std::abs(signedFrame) % relative_duration + m_loopStart): signedFrame;
98  frame = frame % relative_duration + m_loopStart;
99  nextFrame = frame == (relative_duration + m_loopStart) ? m_loopStart : frame + 1;
100  return frame;
101  }
102 
103  unsigned int AnimationClipLooper::mapFrameToFrame(const unsigned frame, unsigned int &nextFrame) const
104  {
105  if (!m_animationClip) return -1;
106  int relative_duration = std::max(1u,m_loopEnd - m_loopStart);
107  unsigned int resFrame = frame % relative_duration + m_loopStart;
108  nextFrame = resFrame == (relative_duration + m_loopStart) ? m_loopStart : resFrame + 1;
109  return resFrame;
110  }
111 
112  inline unsigned int AnimationClipLooper::numFrames() const
113  {
114  return m_loopEnd - m_loopStart;
115  }
116 
117  std::vector<std::string> AnimationClipLooper::metadataNames(const unsigned int jointId) const
118  {
119  if (!m_animationClip) return std::vector<std::string>();
120  return (*m_animationClip)[static_cast<unsigned short>(jointId)].getArrayMetadataNames();
121  }
122 
123  std::vector<std::string> AnimationClipLooper::staticMetadataNames(const unsigned int jointId) const
124  {
125  return (*m_animationClip)[static_cast<unsigned short>(jointId)].getStaticMetadataNames();
126  }
127 
128  AtomsPtr<const AtomsCore::Metadata> AnimationClipLooper::getStaticMetadata(const unsigned int jointId, const std::string &metdataName) const
129  {
130  assert(m_animationClip != nullptr);
131  assert(m_animationClip->numJoints() > jointId);
132  return (*m_animationClip)[static_cast<unsigned short>(jointId)].getStaticMetadata(metdataName);
133  }
134 
135  const AtomsCore::MapMetadata& AnimationClipLooper::staticMetadata(const unsigned int jointId) const
136  {
137  assert(m_animationClip != nullptr);
138  assert(m_animationClip->numJoints() > jointId);
139  const JointClipData& jClipData = (*m_animationClip)[static_cast<unsigned short>(jointId)];
140  return jClipData.staticMetadata();
141  }
142 
143  const std::map<std::string, AtomsPtr<AtomsCore::BaseTypedArrayMetadata>>& AnimationClipLooper::metadata(const unsigned int jointId) const
144  {
145  return (*m_animationClip)[static_cast<unsigned short>(jointId)].metadata();
146  }
147 
148  const std::vector<std::string>& AnimationClipLooper::animatedMetadata(const unsigned int jointId) const
149  {
150  return (*m_animationClip)[static_cast<unsigned short>(jointId)].animatedMetadata();
151  }
152 }
const AtomsCore::MapMetadata & staticMetadata(const unsigned int jointId) const
Gets joint static metadatas.
Definition: AnimationClipLooper.impl.h:135
unsigned int numFrames() const
Gets the number of frames.
Definition: AnimationClipLooper.impl.h:112
std::vector< std::string > staticMetadataNames(const unsigned int jointId) const
Gets joint static metadata names.
Definition: AnimationClipLooper.impl.h:123
unsigned int loopStartFrame() const
Gets the loop start frame.
Definition: AnimationClipLooper.impl.h:70
AtomsPtr< const AtomsCore::Metadata > getStaticMetadata(const unsigned int jointId, const std::string &metadataName) const
Gets joint static metadata value.
Definition: AnimationClipLooper.impl.h:128
unsigned int loopEndFrame() const
Gets the loop end frame.
Definition: AnimationClipLooper.impl.h:86
void setLoopStartFrame(unsigned int value)
Sets the loop start frame.
Definition: AnimationClipLooper.impl.h:53
void setNumberBlendFrames(unsigned int value)
Sets the number of blend frames.
Definition: AnimationClipLooper.impl.h:37
const AnimationClipCPtr animationClip() const
Get the animation clip.
Definition: AnimationClipLooper.impl.h:22
std::vector< std::string > metadataNames(const unsigned int jointId) const
Gets joint metadata names.
Definition: AnimationClipLooper.impl.h:117
void setLoopEndFrame(unsigned int value)
Sets the loop end frame.
Definition: AnimationClipLooper.impl.h:75
bool isValid() const
Check if the looper is valid and has a valid anim clip.
Definition: AnimationClipLooper.impl.h:27
int numJoints() const
Returns the number of joints.
Definition: AnimationClipLooper.impl.h:32
unsigned int numberBlendFrames() const
Returns the number of blend frames.
Definition: AnimationClipLooper.impl.h:48
Joint Clip data.
Definition: AnimationClip.h:38
MapMetadata class.
Definition: MapMetadata.h:24
static LogProxy error()
Get logger proxy error.
Atoms namespace.
Definition: Agent.h:29
AtomsPtr< const AnimationClip > AnimationClipCPtr
animation clip const pointer
Definition: AnimationClip.h:32