Path Tracer
anim.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2020, assimp team
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
13 
14 * Redistributions of source code must retain the above
15  copyright notice, this list of conditions and the
16  following disclaimer.
17 
18 * Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the
20  following disclaimer in the documentation and/or other
21  materials provided with the distribution.
22 
23 * Neither the name of the assimp team, nor the names of its
24  contributors may be used to endorse or promote products
25  derived from this software without specific prior
26  written permission of the assimp team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
41 
47 #pragma once
48 #ifndef AI_ANIM_H_INC
49 #define AI_ANIM_H_INC
50 
51 #ifdef __GNUC__
52 #pragma GCC system_header
53 #endif
54 
55 #include <assimp/quaternion.h>
56 #include <assimp/types.h>
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 // ---------------------------------------------------------------------------
64 struct aiVectorKey {
66  double mTime;
67 
69  C_STRUCT aiVector3D mValue;
70 
71 #ifdef __cplusplus
72 
74  aiVectorKey() AI_NO_EXCEPT
75  : mTime(0.0),
76  mValue() {
77  // empty
78  }
79 
81 
82  aiVectorKey(double time, const aiVector3D &value) :
83  mTime(time), mValue(value) {
84  // empty
85  }
86 
87  typedef aiVector3D elem_type;
88 
89  // Comparison operators. For use with std::find();
90  bool operator==(const aiVectorKey &rhs) const {
91  return rhs.mValue == this->mValue;
92  }
93  bool operator!=(const aiVectorKey &rhs) const {
94  return rhs.mValue != this->mValue;
95  }
96 
97  // Relational operators. For use with std::sort();
98  bool operator<(const aiVectorKey &rhs) const {
99  return mTime < rhs.mTime;
100  }
101  bool operator>(const aiVectorKey &rhs) const {
102  return mTime > rhs.mTime;
103  }
104 #endif // __cplusplus
105 };
106 
107 // ---------------------------------------------------------------------------
110 struct aiQuatKey {
112  double mTime;
113 
116 
117 #ifdef __cplusplus
118  aiQuatKey() AI_NO_EXCEPT
119  : mTime(0.0),
120  mValue() {
121  // empty
122  }
123 
125  aiQuatKey(double time, const aiQuaternion &value) :
126  mTime(time), mValue(value) {}
127 
128  typedef aiQuaternion elem_type;
129 
130  // Comparison operators. For use with std::find();
131  bool operator==(const aiQuatKey &rhs) const {
132  return rhs.mValue == this->mValue;
133  }
134  bool operator!=(const aiQuatKey &rhs) const {
135  return rhs.mValue != this->mValue;
136  }
137 
138  // Relational operators. For use with std::sort();
139  bool operator<(const aiQuatKey &rhs) const {
140  return mTime < rhs.mTime;
141  }
142  bool operator>(const aiQuatKey &rhs) const {
143  return mTime > rhs.mTime;
144  }
145 #endif
146 };
147 
148 // ---------------------------------------------------------------------------
150 struct aiMeshKey {
152  double mTime;
153 
158  unsigned int mValue;
159 
160 #ifdef __cplusplus
161 
162  aiMeshKey() AI_NO_EXCEPT
163  : mTime(0.0),
164  mValue(0) {
165  }
166 
168  aiMeshKey(double time, const unsigned int value) :
169  mTime(time), mValue(value) {}
170 
171  typedef unsigned int elem_type;
172 
173  // Comparison operators. For use with std::find();
174  bool operator==(const aiMeshKey &o) const {
175  return o.mValue == this->mValue;
176  }
177  bool operator!=(const aiMeshKey &o) const {
178  return o.mValue != this->mValue;
179  }
180 
181  // Relational operators. For use with std::sort();
182  bool operator<(const aiMeshKey &o) const {
183  return mTime < o.mTime;
184  }
185  bool operator>(const aiMeshKey &o) const {
186  return mTime > o.mTime;
187  }
188 
189 #endif
190 };
191 
192 // ---------------------------------------------------------------------------
196  double mTime;
197 
199  unsigned int *mValues;
200  double *mWeights;
201 
203  unsigned int mNumValuesAndWeights;
204 #ifdef __cplusplus
205  aiMeshMorphKey() AI_NO_EXCEPT
206  : mTime(0.0),
207  mValues(nullptr),
208  mWeights(nullptr),
210  }
211 
212  ~aiMeshMorphKey() {
213  if (mNumValuesAndWeights && mValues && mWeights) {
214  delete[] mValues;
215  delete[] mWeights;
216  }
217  }
218 #endif
219 };
220 
221 // ---------------------------------------------------------------------------
228 
231 
235 
241 
244 #ifndef SWIG
246 #endif
247 };
248 
249 // ---------------------------------------------------------------------------
264 struct aiNodeAnim {
267  C_STRUCT aiString mNodeName;
268 
270  unsigned int mNumPositionKeys;
271 
278 
280  unsigned int mNumRotationKeys;
281 
289 
291  unsigned int mNumScalingKeys;
292 
299 
306 
313 
314 #ifdef __cplusplus
315  aiNodeAnim() AI_NO_EXCEPT
316  : mNumPositionKeys(0),
317  mPositionKeys(nullptr),
318  mNumRotationKeys(0),
319  mRotationKeys(nullptr),
320  mNumScalingKeys(0),
321  mScalingKeys(nullptr),
324  // empty
325  }
326 
327  ~aiNodeAnim() {
328  delete[] mPositionKeys;
329  delete[] mRotationKeys;
330  delete[] mScalingKeys;
331  }
332 #endif // __cplusplus
333 };
334 
335 // ---------------------------------------------------------------------------
341 struct aiMeshAnim {
346  C_STRUCT aiString mName;
347 
349  unsigned int mNumKeys;
350 
352  C_STRUCT aiMeshKey *mKeys;
353 
354 #ifdef __cplusplus
355 
356  aiMeshAnim() AI_NO_EXCEPT
357  : mNumKeys(),
358  mKeys() {}
359 
360  ~aiMeshAnim() {
361  delete[] mKeys;
362  }
363 
364 #endif
365 };
366 
367 // ---------------------------------------------------------------------------
374  C_STRUCT aiString mName;
375 
377  unsigned int mNumKeys;
378 
381 
382 #ifdef __cplusplus
383 
384  aiMeshMorphAnim() AI_NO_EXCEPT
385  : mNumKeys(),
386  mKeys() {}
387 
388  ~aiMeshMorphAnim() {
389  delete[] mKeys;
390  }
391 
392 #endif
393 };
394 
395 // ---------------------------------------------------------------------------
398 struct aiAnimation {
402  C_STRUCT aiString mName;
403 
405  double mDuration;
406 
409 
412  unsigned int mNumChannels;
413 
416  C_STRUCT aiNodeAnim **mChannels;
417 
420  unsigned int mNumMeshChannels;
421 
425 
428  unsigned int mNumMorphMeshChannels;
429 
433 
434 #ifdef __cplusplus
435  aiAnimation() AI_NO_EXCEPT
436  : mDuration(-1.),
437  mTicksPerSecond(0.),
438  mNumChannels(0),
439  mChannels(nullptr),
440  mNumMeshChannels(0),
441  mMeshChannels(nullptr),
443  mMorphMeshChannels(nullptr) {
444  // empty
445  }
446 
447  ~aiAnimation() {
448  // DO NOT REMOVE THIS ADDITIONAL CHECK
449  if (mNumChannels && mChannels) {
450  for (unsigned int a = 0; a < mNumChannels; a++) {
451  delete mChannels[a];
452  }
453 
454  delete[] mChannels;
455  }
457  for (unsigned int a = 0; a < mNumMeshChannels; a++) {
458  delete mMeshChannels[a];
459  }
460 
461  delete[] mMeshChannels;
462  }
464  for (unsigned int a = 0; a < mNumMorphMeshChannels; a++) {
465  delete mMorphMeshChannels[a];
466  }
467 
468  delete[] mMorphMeshChannels;
469  }
470  }
471 #endif // __cplusplus
472 };
473 
474 #ifdef __cplusplus
475 }
476 
478 namespace Assimp {
479 
480 // ---------------------------------------------------------------------------
487 template <typename T>
488 struct Interpolator {
489  // ------------------------------------------------------------------
495  void operator()(T &anim_out, const T &a, const T &b, ai_real d) const {
496  anim_out = a + (b - a) * d;
497  }
498 }; // ! Interpolator <T>
499 
501 
502 template <>
503 struct Interpolator<aiQuaternion> {
504  void operator()(aiQuaternion &out, const aiQuaternion &a,
505  const aiQuaternion &b, ai_real d) const {
506  aiQuaternion::Interpolate(out, a, b, d);
507  }
508 }; // ! Interpolator <aiQuaternion>
509 
510 template <>
511 struct Interpolator<unsigned int> {
512  void operator()(unsigned int &out, unsigned int a,
513  unsigned int b, ai_real d) const {
514  out = d > 0.5f ? b : a;
515  }
516 }; // ! Interpolator <aiQuaternion>
517 
518 template <>
519 struct Interpolator<aiVectorKey> {
520  void operator()(aiVector3D &out, const aiVectorKey &a,
521  const aiVectorKey &b, ai_real d) const {
522  Interpolator<aiVector3D> ipl;
523  ipl(out, a.mValue, b.mValue, d);
524  }
525 }; // ! Interpolator <aiVectorKey>
526 
527 template <>
528 struct Interpolator<aiQuatKey> {
529  void operator()(aiQuaternion &out, const aiQuatKey &a,
530  const aiQuatKey &b, ai_real d) const {
531  Interpolator<aiQuaternion> ipl;
532  ipl(out, a.mValue, b.mValue, d);
533  }
534 }; // ! Interpolator <aiQuatKey>
535 
536 template <>
537 struct Interpolator<aiMeshKey> {
538  void operator()(unsigned int &out, const aiMeshKey &a,
539  const aiMeshKey &b, ai_real d) const {
540  Interpolator<unsigned int> ipl;
541  ipl(out, a.mValue, b.mValue, d);
542  }
543 }; // ! Interpolator <aiQuatKey>
544 
546 
547 } // namespace Assimp
548 
549 #endif // __cplusplus
550 
551 #endif // AI_ANIM_H_INC
aiNodeAnim::mPositionKeys
C_STRUCT aiVectorKey * mPositionKeys
Definition: anim.h:277
aiQuatKey::mValue
C_STRUCT aiQuaternion mValue
Definition: anim.h:115
aiNodeAnim::mRotationKeys
C_STRUCT aiQuatKey * mRotationKeys
Definition: anim.h:288
aiNodeAnim::mNodeName
C_STRUCT aiString mNodeName
Definition: anim.h:267
aiVector3D
Definition: vector3.h:136
types.h
aiAnimBehaviour_REPEAT
@ aiAnimBehaviour_REPEAT
Definition: anim.h:240
aiMeshMorphAnim::mKeys
C_STRUCT aiMeshMorphKey * mKeys
Definition: anim.h:380
aiNodeAnim::mPreState
C_ENUM aiAnimBehaviour mPreState
Definition: anim.h:305
aiNodeAnim::mNumPositionKeys
unsigned int mNumPositionKeys
Definition: anim.h:270
aiAnimBehaviour_DEFAULT
@ aiAnimBehaviour_DEFAULT
Definition: anim.h:227
aiAnimation::mNumMorphMeshChannels
unsigned int mNumMorphMeshChannels
Definition: anim.h:428
aiAnimation::mDuration
double mDuration
Definition: anim.h:405
quaternion.h
Quaternion structure, including operators when compiling in C++.
aiVectorKey
Definition: anim.h:64
aiMeshMorphKey
Definition: anim.h:194
aiNodeAnim::mNumRotationKeys
unsigned int mNumRotationKeys
Definition: anim.h:280
aiMeshKey::mTime
double mTime
Definition: anim.h:152
aiAnimBehaviour_CONSTANT
@ aiAnimBehaviour_CONSTANT
Definition: anim.h:230
aiMeshKey
Definition: anim.h:150
aiMeshAnim::mNumKeys
unsigned int mNumKeys
Definition: anim.h:349
aiNodeAnim::mScalingKeys
C_STRUCT aiVectorKey * mScalingKeys
Definition: anim.h:298
aiVectorKey::mValue
C_STRUCT aiVector3D mValue
Definition: anim.h:69
aiQuaternion
Definition: quaternion.h:128
aiMeshAnim
Definition: anim.h:341
_aiAnimBehaviour_Force32Bit
@ _aiAnimBehaviour_Force32Bit
Definition: anim.h:245
aiMeshKey::mValue
unsigned int mValue
Definition: anim.h:158
aiAnimBehaviour_LINEAR
@ aiAnimBehaviour_LINEAR
Definition: anim.h:234
aiNodeAnim::mNumScalingKeys
unsigned int mNumScalingKeys
Definition: anim.h:291
aiAnimation::mMorphMeshChannels
C_STRUCT aiMeshMorphAnim ** mMorphMeshChannels
Definition: anim.h:432
aiMeshMorphAnim
Definition: anim.h:369
aiAnimation::mNumChannels
unsigned int mNumChannels
Definition: anim.h:412
aiMeshAnim::mName
C_STRUCT aiString mName
Definition: anim.h:346
aiMeshMorphKey::mValues
unsigned int * mValues
Definition: anim.h:199
aiAnimation::mChannels
C_STRUCT aiNodeAnim ** mChannels
Definition: anim.h:416
aiString
Definition: types.h:266
aiNodeAnim
Definition: anim.h:264
aiMeshMorphAnim::mName
C_STRUCT aiString mName
Definition: anim.h:374
aiAnimation
Definition: anim.h:398
aiAnimBehaviour
aiAnimBehaviour
Definition: anim.h:225
aiNodeAnim::mPostState
C_ENUM aiAnimBehaviour mPostState
Definition: anim.h:312
aiQuatKey
Definition: anim.h:110
aiAnimation::mName
C_STRUCT aiString mName
Definition: anim.h:402
aiMeshMorphKey::mNumValuesAndWeights
unsigned int mNumValuesAndWeights
Definition: anim.h:203
aiMeshMorphAnim::mNumKeys
unsigned int mNumKeys
Definition: anim.h:377
aiQuatKey::mTime
double mTime
Definition: anim.h:112
aiAnimation::mNumMeshChannels
unsigned int mNumMeshChannels
Definition: anim.h:420
aiMeshMorphKey::mTime
double mTime
Definition: anim.h:196
Assimp
Definition: ai_assert.h:50
aiAnimation::mMeshChannels
C_STRUCT aiMeshAnim ** mMeshChannels
Definition: anim.h:424
aiMeshAnim::mKeys
C_STRUCT aiMeshKey * mKeys
Definition: anim.h:352
aiAnimation::mTicksPerSecond
double mTicksPerSecond
Definition: anim.h:408
aiVectorKey::mTime
double mTime
Definition: anim.h:66