vrshoot

view libs/assimp/assimp/anim.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
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:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
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.
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.
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 */
42 /** @file anim.h
43 * @brief Defines the data structures in which the imported animations
44 * are returned.
45 */
46 #ifndef AI_ANIM_H_INC
47 #define AI_ANIM_H_INC
49 #include "types.h"
50 #include "quaternion.h"
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
56 // ---------------------------------------------------------------------------
57 /** A time-value pair specifying a certain 3D vector for the given time. */
58 struct aiVectorKey
59 {
60 /** The time of this key */
61 double mTime;
63 /** The value of this key */
64 C_STRUCT aiVector3D mValue;
66 #ifdef __cplusplus
68 //! Default constructor
69 aiVectorKey(){}
71 //! Construction from a given time and key value
72 aiVectorKey(double time, const aiVector3D& value)
73 : mTime (time)
74 , mValue (value)
75 {}
78 typedef aiVector3D elem_type;
80 // Comparison operators. For use with std::find();
81 bool operator == (const aiVectorKey& o) const {
82 return o.mValue == this->mValue;
83 }
84 bool operator != (const aiVectorKey& o) const {
85 return o.mValue != this->mValue;
86 }
88 // Relational operators. For use with std::sort();
89 bool operator < (const aiVectorKey& o) const {
90 return mTime < o.mTime;
91 }
92 bool operator > (const aiVectorKey& o) const {
93 return mTime > o.mTime;
94 }
95 #endif
96 };
98 // ---------------------------------------------------------------------------
99 /** A time-value pair specifying a rotation for the given time.
100 * Rotations are expressed with quaternions. */
101 struct aiQuatKey
102 {
103 /** The time of this key */
104 double mTime;
106 /** The value of this key */
107 C_STRUCT aiQuaternion mValue;
109 #ifdef __cplusplus
110 aiQuatKey(){
111 }
113 /** Construction from a given time and key value */
114 aiQuatKey(double time, const aiQuaternion& value)
115 : mTime (time)
116 , mValue (value)
117 {}
119 typedef aiQuaternion elem_type;
121 // Comparison operators. For use with std::find();
122 bool operator == (const aiQuatKey& o) const {
123 return o.mValue == this->mValue;
124 }
125 bool operator != (const aiQuatKey& o) const {
126 return o.mValue != this->mValue;
127 }
129 // Relational operators. For use with std::sort();
130 bool operator < (const aiQuatKey& o) const {
131 return mTime < o.mTime;
132 }
133 bool operator > (const aiQuatKey& o) const {
134 return mTime > o.mTime;
135 }
136 #endif
137 };
139 // ---------------------------------------------------------------------------
140 /** Binds a anim mesh to a specific point in time. */
141 struct aiMeshKey
142 {
143 /** The time of this key */
144 double mTime;
146 /** Index into the aiMesh::mAnimMeshes array of the
147 * mesh coresponding to the #aiMeshAnim hosting this
148 * key frame. The referenced anim mesh is evaluated
149 * according to the rules defined in the docs for #aiAnimMesh.*/
150 unsigned int mValue;
152 #ifdef __cplusplus
154 aiMeshKey() {
155 }
157 /** Construction from a given time and key value */
158 aiMeshKey(double time, const unsigned int value)
159 : mTime (time)
160 , mValue (value)
161 {}
163 typedef unsigned int elem_type;
165 // Comparison operators. For use with std::find();
166 bool operator == (const aiMeshKey& o) const {
167 return o.mValue == this->mValue;
168 }
169 bool operator != (const aiMeshKey& o) const {
170 return o.mValue != this->mValue;
171 }
173 // Relational operators. For use with std::sort();
174 bool operator < (const aiMeshKey& o) const {
175 return mTime < o.mTime;
176 }
177 bool operator > (const aiMeshKey& o) const {
178 return mTime > o.mTime;
179 }
181 #endif
182 };
184 // ---------------------------------------------------------------------------
185 /** Defines how an animation channel behaves outside the defined time
186 * range. This corresponds to aiNodeAnim::mPreState and
187 * aiNodeAnim::mPostState.*/
188 enum aiAnimBehaviour
189 {
190 /** The value from the default node transformation is taken*/
191 aiAnimBehaviour_DEFAULT = 0x0,
193 /** The nearest key value is used without interpolation */
194 aiAnimBehaviour_CONSTANT = 0x1,
196 /** The value of the nearest two keys is linearly
197 * extrapolated for the current time value.*/
198 aiAnimBehaviour_LINEAR = 0x2,
200 /** The animation is repeated.
201 *
202 * If the animation key go from n to m and the current
203 * time is t, use the value at (t-n) % (|m-n|).*/
204 aiAnimBehaviour_REPEAT = 0x3,
208 /** This value is not used, it is just here to force the
209 * the compiler to map this enum to a 32 Bit integer */
210 #ifndef SWIG
211 _aiAnimBehaviour_Force32Bit = INT_MAX
212 #endif
213 };
215 // ---------------------------------------------------------------------------
216 /** Describes the animation of a single node. The name specifies the
217 * bone/node which is affected by this animation channel. The keyframes
218 * are given in three separate series of values, one each for position,
219 * rotation and scaling. The transformation matrix computed from these
220 * values replaces the node's original transformation matrix at a
221 * specific time.
222 * This means all keys are absolute and not relative to the bone default pose.
223 * The order in which the transformations are applied is
224 * - as usual - scaling, rotation, translation.
225 *
226 * @note All keys are returned in their correct, chronological order.
227 * Duplicate keys don't pass the validation step. Most likely there
228 * will be no negative time values, but they are not forbidden also ( so
229 * implementations need to cope with them! ) */
230 struct aiNodeAnim
231 {
232 /** The name of the node affected by this animation. The node
233 * must exist and it must be unique.*/
234 C_STRUCT aiString mNodeName;
236 /** The number of position keys */
237 unsigned int mNumPositionKeys;
239 /** The position keys of this animation channel. Positions are
240 * specified as 3D vector. The array is mNumPositionKeys in size.
241 *
242 * If there are position keys, there will also be at least one
243 * scaling and one rotation key.*/
244 C_STRUCT aiVectorKey* mPositionKeys;
246 /** The number of rotation keys */
247 unsigned int mNumRotationKeys;
249 /** The rotation keys of this animation channel. Rotations are
250 * given as quaternions, which are 4D vectors. The array is
251 * mNumRotationKeys in size.
252 *
253 * If there are rotation keys, there will also be at least one
254 * scaling and one position key. */
255 C_STRUCT aiQuatKey* mRotationKeys;
258 /** The number of scaling keys */
259 unsigned int mNumScalingKeys;
261 /** The scaling keys of this animation channel. Scalings are
262 * specified as 3D vector. The array is mNumScalingKeys in size.
263 *
264 * If there are scaling keys, there will also be at least one
265 * position and one rotation key.*/
266 C_STRUCT aiVectorKey* mScalingKeys;
269 /** Defines how the animation behaves before the first
270 * key is encountered.
271 *
272 * The default value is aiAnimBehaviour_DEFAULT (the original
273 * transformation matrix of the affected node is used).*/
274 C_ENUM aiAnimBehaviour mPreState;
276 /** Defines how the animation behaves after the last
277 * key was processed.
278 *
279 * The default value is aiAnimBehaviour_DEFAULT (the original
280 * transformation matrix of the affected node is taken).*/
281 C_ENUM aiAnimBehaviour mPostState;
283 #ifdef __cplusplus
284 aiNodeAnim()
285 {
286 mNumPositionKeys = 0; mPositionKeys = NULL;
287 mNumRotationKeys = 0; mRotationKeys = NULL;
288 mNumScalingKeys = 0; mScalingKeys = NULL;
290 mPreState = mPostState = aiAnimBehaviour_DEFAULT;
291 }
293 ~aiNodeAnim()
294 {
295 delete [] mPositionKeys;
296 delete [] mRotationKeys;
297 delete [] mScalingKeys;
298 }
299 #endif // __cplusplus
300 };
302 // ---------------------------------------------------------------------------
303 /** Describes vertex-based animations for a single mesh or a group of
304 * meshes. Meshes carry the animation data for each frame in their
305 * aiMesh::mAnimMeshes array. The purpose of aiMeshAnim is to
306 * define keyframes linking each mesh attachment to a particular
307 * point in time. */
308 struct aiMeshAnim
309 {
310 /** Name of the mesh to be animated. An empty string is not allowed,
311 * animated meshes need to be named (not necessarily uniquely,
312 * the name can basically serve as wildcard to select a group
313 * of meshes with similar animation setup)*/
314 C_STRUCT aiString mName;
316 /** Size of the #mKeys array. Must be 1, at least. */
317 unsigned int mNumKeys;
319 /** Key frames of the animation. May not be NULL. */
320 C_STRUCT aiMeshKey* mKeys;
322 #ifdef __cplusplus
324 aiMeshAnim()
325 : mNumKeys()
326 , mKeys()
327 {}
329 ~aiMeshAnim()
330 {
331 delete[] mKeys;
332 }
334 #endif
335 };
337 // ---------------------------------------------------------------------------
338 /** An animation consists of keyframe data for a number of nodes. For
339 * each node affected by the animation a separate series of data is given.*/
340 struct aiAnimation
341 {
342 /** The name of the animation. If the modeling package this data was
343 * exported from does support only a single animation channel, this
344 * name is usually empty (length is zero). */
345 C_STRUCT aiString mName;
347 /** Duration of the animation in ticks. */
348 double mDuration;
350 /** Ticks per second. 0 if not specified in the imported file */
351 double mTicksPerSecond;
353 /** The number of bone animation channels. Each channel affects
354 * a single node. */
355 unsigned int mNumChannels;
357 /** The node animation channels. Each channel affects a single node.
358 * The array is mNumChannels in size. */
359 C_STRUCT aiNodeAnim** mChannels;
362 /** The number of mesh animation channels. Each channel affects
363 * a single mesh and defines vertex-based animation. */
364 unsigned int mNumMeshChannels;
366 /** The mesh animation channels. Each channel affects a single mesh.
367 * The array is mNumMeshChannels in size. */
368 C_STRUCT aiMeshAnim** mMeshChannels;
370 #ifdef __cplusplus
371 aiAnimation()
372 : mDuration(-1.)
373 , mTicksPerSecond()
374 , mNumChannels()
375 , mChannels()
376 , mNumMeshChannels()
377 , mMeshChannels()
378 {
379 }
381 ~aiAnimation()
382 {
383 // DO NOT REMOVE THIS ADDITIONAL CHECK
384 if (mNumChannels && mChannels) {
385 for( unsigned int a = 0; a < mNumChannels; a++) {
386 delete mChannels[a];
387 }
389 delete [] mChannels;
390 }
391 if (mNumMeshChannels && mMeshChannels) {
392 for( unsigned int a = 0; a < mNumMeshChannels; a++) {
393 delete mMeshChannels[a];
394 }
396 delete [] mMeshChannels;
397 }
398 }
399 #endif // __cplusplus
400 };
402 #ifdef __cplusplus
403 }
406 // some C++ utilities for inter- and extrapolation
407 namespace Assimp {
409 // ---------------------------------------------------------------------------
410 /** @brief CPP-API: Utility class to simplify interpolations of various data types.
411 *
412 * The type of interpolation is choosen automatically depending on the
413 * types of the arguments. */
414 template <typename T>
415 struct Interpolator
416 {
417 // ------------------------------------------------------------------
418 /** @brief Get the result of the interpolation between a,b.
419 *
420 * The interpolation algorithm depends on the type of the operands.
421 * aiQuaternion's and aiQuatKey's SLERP, the rest does a simple
422 * linear interpolation. */
423 void operator () (T& out,const T& a, const T& b, float d) const {
424 out = a + (b-a)*d;
425 }
426 }; // ! Interpolator <T>
428 //! @cond Never
430 template <>
431 struct Interpolator <aiQuaternion> {
432 void operator () (aiQuaternion& out,const aiQuaternion& a,
433 const aiQuaternion& b, float d) const
434 {
435 aiQuaternion::Interpolate(out,a,b,d);
436 }
437 }; // ! Interpolator <aiQuaternion>
439 template <>
440 struct Interpolator <unsigned int> {
441 void operator () (unsigned int& out,unsigned int a,
442 unsigned int b, float d) const
443 {
444 out = d>0.5f ? b : a;
445 }
446 }; // ! Interpolator <aiQuaternion>
448 template <>
449 struct Interpolator <aiVectorKey> {
450 void operator () (aiVector3D& out,const aiVectorKey& a,
451 const aiVectorKey& b, float d) const
452 {
453 Interpolator<aiVector3D> ipl;
454 ipl(out,a.mValue,b.mValue,d);
455 }
456 }; // ! Interpolator <aiVectorKey>
458 template <>
459 struct Interpolator <aiQuatKey> {
460 void operator () (aiQuaternion& out, const aiQuatKey& a,
461 const aiQuatKey& b, float d) const
462 {
463 Interpolator<aiQuaternion> ipl;
464 ipl(out,a.mValue,b.mValue,d);
465 }
466 }; // ! Interpolator <aiQuatKey>
468 template <>
469 struct Interpolator <aiMeshKey> {
470 void operator () (unsigned int& out, const aiMeshKey& a,
471 const aiMeshKey& b, float d) const
472 {
473 Interpolator<unsigned int> ipl;
474 ipl(out,a.mValue,b.mValue,d);
475 }
476 }; // ! Interpolator <aiQuatKey>
478 //! @endcond
479 } // ! end namespace Assimp
483 #endif // __cplusplus
484 #endif // AI_ANIM_H_INC