miniassimp
diff include/miniassimp/anim.h @ 0:879c81d94345
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Jan 2019 18:19:26 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/include/miniassimp/anim.h Mon Jan 28 18:19:26 2019 +0200 1.3 @@ -0,0 +1,577 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2018, assimp team 1.10 + 1.11 + 1.12 + 1.13 +All rights reserved. 1.14 + 1.15 +Redistribution and use of this software in source and binary forms, 1.16 +with or without modification, are permitted provided that the following 1.17 +conditions are met: 1.18 + 1.19 +* Redistributions of source code must retain the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer. 1.22 + 1.23 +* Redistributions in binary form must reproduce the above 1.24 + copyright notice, this list of conditions and the 1.25 + following disclaimer in the documentation and/or other 1.26 + materials provided with the distribution. 1.27 + 1.28 +* Neither the name of the assimp team, nor the names of its 1.29 + contributors may be used to endorse or promote products 1.30 + derived from this software without specific prior 1.31 + written permission of the assimp team. 1.32 + 1.33 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.34 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.35 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.36 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.37 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.38 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.39 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.40 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.41 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.42 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.43 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.44 +--------------------------------------------------------------------------- 1.45 +*/ 1.46 + 1.47 +/** 1.48 + * @file anim.h 1.49 + * @brief Defines the data structures in which the imported animations 1.50 + * are returned. 1.51 + */ 1.52 +#pragma once 1.53 +#ifndef AI_ANIM_H_INC 1.54 +#define AI_ANIM_H_INC 1.55 + 1.56 +#include <miniassimp/types.h> 1.57 +#include <miniassimp/quaternion.h> 1.58 + 1.59 +#ifdef __cplusplus 1.60 +extern "C" { 1.61 +#endif 1.62 + 1.63 +// --------------------------------------------------------------------------- 1.64 +/** A time-value pair specifying a certain 3D vector for the given time. */ 1.65 +struct aiVectorKey 1.66 +{ 1.67 + /** The time of this key */ 1.68 + double mTime; 1.69 + 1.70 + /** The value of this key */ 1.71 + C_STRUCT aiVector3D mValue; 1.72 + 1.73 +#ifdef __cplusplus 1.74 + 1.75 + /// @brief The default constructor. 1.76 + aiVectorKey() AI_NO_EXCEPT 1.77 + : mTime( 0.0 ) 1.78 + , mValue() { 1.79 + // empty 1.80 + } 1.81 + 1.82 + /// @brief Construction from a given time and key value. 1.83 + 1.84 + aiVectorKey(double time, const aiVector3D& value) 1.85 + : mTime( time ) 1.86 + , mValue( value ) { 1.87 + // empty 1.88 + } 1.89 + 1.90 + typedef aiVector3D elem_type; 1.91 + 1.92 + // Comparison operators. For use with std::find(); 1.93 + bool operator == (const aiVectorKey& rhs) const { 1.94 + return rhs.mValue == this->mValue; 1.95 + } 1.96 + bool operator != (const aiVectorKey& rhs ) const { 1.97 + return rhs.mValue != this->mValue; 1.98 + } 1.99 + 1.100 + // Relational operators. For use with std::sort(); 1.101 + bool operator < (const aiVectorKey& rhs ) const { 1.102 + return mTime < rhs.mTime; 1.103 + } 1.104 + bool operator > (const aiVectorKey& rhs ) const { 1.105 + return mTime > rhs.mTime; 1.106 + } 1.107 +#endif // __cplusplus 1.108 +}; 1.109 + 1.110 +// --------------------------------------------------------------------------- 1.111 +/** A time-value pair specifying a rotation for the given time. 1.112 + * Rotations are expressed with quaternions. */ 1.113 +struct aiQuatKey 1.114 +{ 1.115 + /** The time of this key */ 1.116 + double mTime; 1.117 + 1.118 + /** The value of this key */ 1.119 + C_STRUCT aiQuaternion mValue; 1.120 + 1.121 +#ifdef __cplusplus 1.122 + aiQuatKey() AI_NO_EXCEPT 1.123 + : mTime( 0.0 ) 1.124 + , mValue() { 1.125 + // empty 1.126 + } 1.127 + 1.128 + /** Construction from a given time and key value */ 1.129 + aiQuatKey(double time, const aiQuaternion& value) 1.130 + : mTime (time) 1.131 + , mValue (value) 1.132 + {} 1.133 + 1.134 + typedef aiQuaternion elem_type; 1.135 + 1.136 + // Comparison operators. For use with std::find(); 1.137 + bool operator == (const aiQuatKey& rhs ) const { 1.138 + return rhs.mValue == this->mValue; 1.139 + } 1.140 + bool operator != (const aiQuatKey& rhs ) const { 1.141 + return rhs.mValue != this->mValue; 1.142 + } 1.143 + 1.144 + // Relational operators. For use with std::sort(); 1.145 + bool operator < (const aiQuatKey& rhs ) const { 1.146 + return mTime < rhs.mTime; 1.147 + } 1.148 + bool operator > (const aiQuatKey& rhs ) const { 1.149 + return mTime > rhs.mTime; 1.150 + } 1.151 +#endif 1.152 +}; 1.153 + 1.154 +// --------------------------------------------------------------------------- 1.155 +/** Binds a anim-mesh to a specific point in time. */ 1.156 +struct aiMeshKey 1.157 +{ 1.158 + /** The time of this key */ 1.159 + double mTime; 1.160 + 1.161 + /** Index into the aiMesh::mAnimMeshes array of the 1.162 + * mesh corresponding to the #aiMeshAnim hosting this 1.163 + * key frame. The referenced anim mesh is evaluated 1.164 + * according to the rules defined in the docs for #aiAnimMesh.*/ 1.165 + unsigned int mValue; 1.166 + 1.167 +#ifdef __cplusplus 1.168 + 1.169 + aiMeshKey() AI_NO_EXCEPT 1.170 + : mTime(0.0) 1.171 + , mValue(0) 1.172 + { 1.173 + } 1.174 + 1.175 + /** Construction from a given time and key value */ 1.176 + aiMeshKey(double time, const unsigned int value) 1.177 + : mTime (time) 1.178 + , mValue (value) 1.179 + {} 1.180 + 1.181 + typedef unsigned int elem_type; 1.182 + 1.183 + // Comparison operators. For use with std::find(); 1.184 + bool operator == (const aiMeshKey& o) const { 1.185 + return o.mValue == this->mValue; 1.186 + } 1.187 + bool operator != (const aiMeshKey& o) const { 1.188 + return o.mValue != this->mValue; 1.189 + } 1.190 + 1.191 + // Relational operators. For use with std::sort(); 1.192 + bool operator < (const aiMeshKey& o) const { 1.193 + return mTime < o.mTime; 1.194 + } 1.195 + bool operator > (const aiMeshKey& o) const { 1.196 + return mTime > o.mTime; 1.197 + } 1.198 + 1.199 +#endif 1.200 +}; 1.201 + 1.202 +// --------------------------------------------------------------------------- 1.203 +/** Binds a morph anim mesh to a specific point in time. */ 1.204 +struct aiMeshMorphKey 1.205 +{ 1.206 + /** The time of this key */ 1.207 + double mTime; 1.208 + 1.209 + /** The values and weights at the time of this key */ 1.210 + unsigned int *mValues; 1.211 + double *mWeights; 1.212 + 1.213 + /** The number of values and weights */ 1.214 + unsigned int mNumValuesAndWeights; 1.215 +#ifdef __cplusplus 1.216 + aiMeshMorphKey() AI_NO_EXCEPT 1.217 + : mTime(0.0) 1.218 + , mValues(0) 1.219 + , mWeights(0) 1.220 + , mNumValuesAndWeights(0) 1.221 + { 1.222 + 1.223 + } 1.224 + 1.225 + ~aiMeshMorphKey() 1.226 + { 1.227 + if (mNumValuesAndWeights && mValues && mWeights) { 1.228 + delete [] mValues; 1.229 + delete [] mWeights; 1.230 + } 1.231 + } 1.232 +#endif 1.233 +}; 1.234 + 1.235 +// --------------------------------------------------------------------------- 1.236 +/** Defines how an animation channel behaves outside the defined time 1.237 + * range. This corresponds to aiNodeAnim::mPreState and 1.238 + * aiNodeAnim::mPostState.*/ 1.239 +enum aiAnimBehaviour 1.240 +{ 1.241 + /** The value from the default node transformation is taken*/ 1.242 + aiAnimBehaviour_DEFAULT = 0x0, 1.243 + 1.244 + /** The nearest key value is used without interpolation */ 1.245 + aiAnimBehaviour_CONSTANT = 0x1, 1.246 + 1.247 + /** The value of the nearest two keys is linearly 1.248 + * extrapolated for the current time value.*/ 1.249 + aiAnimBehaviour_LINEAR = 0x2, 1.250 + 1.251 + /** The animation is repeated. 1.252 + * 1.253 + * If the animation key go from n to m and the current 1.254 + * time is t, use the value at (t-n) % (|m-n|).*/ 1.255 + aiAnimBehaviour_REPEAT = 0x3, 1.256 + 1.257 + /** This value is not used, it is just here to force the 1.258 + * the compiler to map this enum to a 32 Bit integer */ 1.259 +#ifndef SWIG 1.260 + _aiAnimBehaviour_Force32Bit = INT_MAX 1.261 +#endif 1.262 +}; 1.263 + 1.264 +// --------------------------------------------------------------------------- 1.265 +/** Describes the animation of a single node. The name specifies the 1.266 + * bone/node which is affected by this animation channel. The keyframes 1.267 + * are given in three separate series of values, one each for position, 1.268 + * rotation and scaling. The transformation matrix computed from these 1.269 + * values replaces the node's original transformation matrix at a 1.270 + * specific time. 1.271 + * This means all keys are absolute and not relative to the bone default pose. 1.272 + * The order in which the transformations are applied is 1.273 + * - as usual - scaling, rotation, translation. 1.274 + * 1.275 + * @note All keys are returned in their correct, chronological order. 1.276 + * Duplicate keys don't pass the validation step. Most likely there 1.277 + * will be no negative time values, but they are not forbidden also ( so 1.278 + * implementations need to cope with them! ) */ 1.279 +struct aiNodeAnim { 1.280 + /** The name of the node affected by this animation. The node 1.281 + * must exist and it must be unique.*/ 1.282 + C_STRUCT aiString mNodeName; 1.283 + 1.284 + /** The number of position keys */ 1.285 + unsigned int mNumPositionKeys; 1.286 + 1.287 + /** The position keys of this animation channel. Positions are 1.288 + * specified as 3D vector. The array is mNumPositionKeys in size. 1.289 + * 1.290 + * If there are position keys, there will also be at least one 1.291 + * scaling and one rotation key.*/ 1.292 + C_STRUCT aiVectorKey* mPositionKeys; 1.293 + 1.294 + /** The number of rotation keys */ 1.295 + unsigned int mNumRotationKeys; 1.296 + 1.297 + /** The rotation keys of this animation channel. Rotations are 1.298 + * given as quaternions, which are 4D vectors. The array is 1.299 + * mNumRotationKeys in size. 1.300 + * 1.301 + * If there are rotation keys, there will also be at least one 1.302 + * scaling and one position key. */ 1.303 + C_STRUCT aiQuatKey* mRotationKeys; 1.304 + 1.305 + /** The number of scaling keys */ 1.306 + unsigned int mNumScalingKeys; 1.307 + 1.308 + /** The scaling keys of this animation channel. Scalings are 1.309 + * specified as 3D vector. The array is mNumScalingKeys in size. 1.310 + * 1.311 + * If there are scaling keys, there will also be at least one 1.312 + * position and one rotation key.*/ 1.313 + C_STRUCT aiVectorKey* mScalingKeys; 1.314 + 1.315 + /** Defines how the animation behaves before the first 1.316 + * key is encountered. 1.317 + * 1.318 + * The default value is aiAnimBehaviour_DEFAULT (the original 1.319 + * transformation matrix of the affected node is used).*/ 1.320 + C_ENUM aiAnimBehaviour mPreState; 1.321 + 1.322 + /** Defines how the animation behaves after the last 1.323 + * key was processed. 1.324 + * 1.325 + * The default value is aiAnimBehaviour_DEFAULT (the original 1.326 + * transformation matrix of the affected node is taken).*/ 1.327 + C_ENUM aiAnimBehaviour mPostState; 1.328 + 1.329 +#ifdef __cplusplus 1.330 + aiNodeAnim() AI_NO_EXCEPT 1.331 + : mNumPositionKeys( 0 ) 1.332 + , mPositionKeys( 0 ) 1.333 + , mNumRotationKeys( 0 ) 1.334 + , mRotationKeys( 0 ) 1.335 + , mNumScalingKeys( 0 ) 1.336 + , mScalingKeys( 0 ) 1.337 + , mPreState( aiAnimBehaviour_DEFAULT ) 1.338 + , mPostState( aiAnimBehaviour_DEFAULT ) { 1.339 + // empty 1.340 + } 1.341 + 1.342 + ~aiNodeAnim() { 1.343 + delete [] mPositionKeys; 1.344 + delete [] mRotationKeys; 1.345 + delete [] mScalingKeys; 1.346 + } 1.347 +#endif // __cplusplus 1.348 +}; 1.349 + 1.350 +// --------------------------------------------------------------------------- 1.351 +/** Describes vertex-based animations for a single mesh or a group of 1.352 + * meshes. Meshes carry the animation data for each frame in their 1.353 + * aiMesh::mAnimMeshes array. The purpose of aiMeshAnim is to 1.354 + * define keyframes linking each mesh attachment to a particular 1.355 + * point in time. */ 1.356 +struct aiMeshAnim 1.357 +{ 1.358 + /** Name of the mesh to be animated. An empty string is not allowed, 1.359 + * animated meshes need to be named (not necessarily uniquely, 1.360 + * the name can basically serve as wild-card to select a group 1.361 + * of meshes with similar animation setup)*/ 1.362 + C_STRUCT aiString mName; 1.363 + 1.364 + /** Size of the #mKeys array. Must be 1, at least. */ 1.365 + unsigned int mNumKeys; 1.366 + 1.367 + /** Key frames of the animation. May not be NULL. */ 1.368 + C_STRUCT aiMeshKey* mKeys; 1.369 + 1.370 +#ifdef __cplusplus 1.371 + 1.372 + aiMeshAnim() AI_NO_EXCEPT 1.373 + : mNumKeys() 1.374 + , mKeys() 1.375 + {} 1.376 + 1.377 + ~aiMeshAnim() 1.378 + { 1.379 + delete[] mKeys; 1.380 + } 1.381 + 1.382 +#endif 1.383 +}; 1.384 + 1.385 +// --------------------------------------------------------------------------- 1.386 +/** Describes a morphing animation of a given mesh. */ 1.387 +struct aiMeshMorphAnim 1.388 +{ 1.389 + /** Name of the mesh to be animated. An empty string is not allowed, 1.390 + * animated meshes need to be named (not necessarily uniquely, 1.391 + * the name can basically serve as wildcard to select a group 1.392 + * of meshes with similar animation setup)*/ 1.393 + C_STRUCT aiString mName; 1.394 + 1.395 + /** Size of the #mKeys array. Must be 1, at least. */ 1.396 + unsigned int mNumKeys; 1.397 + 1.398 + /** Key frames of the animation. May not be NULL. */ 1.399 + C_STRUCT aiMeshMorphKey* mKeys; 1.400 + 1.401 +#ifdef __cplusplus 1.402 + 1.403 + aiMeshMorphAnim() AI_NO_EXCEPT 1.404 + : mNumKeys() 1.405 + , mKeys() 1.406 + {} 1.407 + 1.408 + ~aiMeshMorphAnim() 1.409 + { 1.410 + delete[] mKeys; 1.411 + } 1.412 + 1.413 +#endif 1.414 +}; 1.415 + 1.416 +// --------------------------------------------------------------------------- 1.417 +/** An animation consists of key-frame data for a number of nodes. For 1.418 + * each node affected by the animation a separate series of data is given.*/ 1.419 +struct aiAnimation { 1.420 + /** The name of the animation. If the modeling package this data was 1.421 + * exported from does support only a single animation channel, this 1.422 + * name is usually empty (length is zero). */ 1.423 + C_STRUCT aiString mName; 1.424 + 1.425 + /** Duration of the animation in ticks. */ 1.426 + double mDuration; 1.427 + 1.428 + /** Ticks per second. 0 if not specified in the imported file */ 1.429 + double mTicksPerSecond; 1.430 + 1.431 + /** The number of bone animation channels. Each channel affects 1.432 + * a single node. */ 1.433 + unsigned int mNumChannels; 1.434 + 1.435 + /** The node animation channels. Each channel affects a single node. 1.436 + * The array is mNumChannels in size. */ 1.437 + C_STRUCT aiNodeAnim** mChannels; 1.438 + 1.439 + 1.440 + /** The number of mesh animation channels. Each channel affects 1.441 + * a single mesh and defines vertex-based animation. */ 1.442 + unsigned int mNumMeshChannels; 1.443 + 1.444 + /** The mesh animation channels. Each channel affects a single mesh. 1.445 + * The array is mNumMeshChannels in size. */ 1.446 + C_STRUCT aiMeshAnim** mMeshChannels; 1.447 + 1.448 + /** The number of mesh animation channels. Each channel affects 1.449 + * a single mesh and defines morphing animation. */ 1.450 + unsigned int mNumMorphMeshChannels; 1.451 + 1.452 + /** The morph mesh animation channels. Each channel affects a single mesh. 1.453 + * The array is mNumMorphMeshChannels in size. */ 1.454 + C_STRUCT aiMeshMorphAnim **mMorphMeshChannels; 1.455 + 1.456 +#ifdef __cplusplus 1.457 + aiAnimation() AI_NO_EXCEPT 1.458 + : mDuration(-1.) 1.459 + , mTicksPerSecond(0.) 1.460 + , mNumChannels(0) 1.461 + , mChannels(0) 1.462 + , mNumMeshChannels(0) 1.463 + , mMeshChannels(0) 1.464 + , mNumMorphMeshChannels(0) 1.465 + , mMorphMeshChannels(0) { 1.466 + // empty 1.467 + } 1.468 + 1.469 + ~aiAnimation() { 1.470 + // DO NOT REMOVE THIS ADDITIONAL CHECK 1.471 + if ( mNumChannels && mChannels ) { 1.472 + for( unsigned int a = 0; a < mNumChannels; a++) { 1.473 + delete mChannels[ a ]; 1.474 + } 1.475 + 1.476 + delete [] mChannels; 1.477 + } 1.478 + if (mNumMeshChannels && mMeshChannels) { 1.479 + for( unsigned int a = 0; a < mNumMeshChannels; a++) { 1.480 + delete mMeshChannels[a]; 1.481 + } 1.482 + 1.483 + delete [] mMeshChannels; 1.484 + } 1.485 + if (mNumMorphMeshChannels && mMorphMeshChannels) { 1.486 + for( unsigned int a = 0; a < mNumMorphMeshChannels; a++) { 1.487 + delete mMorphMeshChannels[a]; 1.488 + } 1.489 + 1.490 + delete [] mMorphMeshChannels; 1.491 + } 1.492 + } 1.493 +#endif // __cplusplus 1.494 +}; 1.495 + 1.496 +#ifdef __cplusplus 1.497 + 1.498 +} 1.499 + 1.500 +/// @brief Some C++ utilities for inter- and extrapolation 1.501 +namespace Assimp { 1.502 + 1.503 +// --------------------------------------------------------------------------- 1.504 +/** 1.505 + * @brief CPP-API: Utility class to simplify interpolations of various data types. 1.506 + * 1.507 + * The type of interpolation is chosen automatically depending on the 1.508 + * types of the arguments. 1.509 + */ 1.510 +template <typename T> 1.511 +struct Interpolator 1.512 +{ 1.513 + // ------------------------------------------------------------------ 1.514 + /** @brief Get the result of the interpolation between a,b. 1.515 + * 1.516 + * The interpolation algorithm depends on the type of the operands. 1.517 + * aiQuaternion's and aiQuatKey's SLERP, the rest does a simple 1.518 + * linear interpolation. */ 1.519 + void operator () (T& out,const T& a, const T& b, ai_real d) const { 1.520 + out = a + (b-a)*d; 1.521 + } 1.522 +}; // ! Interpolator <T> 1.523 + 1.524 +//! @cond Never 1.525 + 1.526 +template <> 1.527 +struct Interpolator <aiQuaternion> { 1.528 + void operator () (aiQuaternion& out,const aiQuaternion& a, 1.529 + const aiQuaternion& b, ai_real d) const 1.530 + { 1.531 + aiQuaternion::Interpolate(out,a,b,d); 1.532 + } 1.533 +}; // ! Interpolator <aiQuaternion> 1.534 + 1.535 +template <> 1.536 +struct Interpolator <unsigned int> { 1.537 + void operator () (unsigned int& out,unsigned int a, 1.538 + unsigned int b, ai_real d) const 1.539 + { 1.540 + out = d>0.5f ? b : a; 1.541 + } 1.542 +}; // ! Interpolator <aiQuaternion> 1.543 + 1.544 +template <> 1.545 +struct Interpolator<aiVectorKey> { 1.546 + void operator () (aiVector3D& out,const aiVectorKey& a, 1.547 + const aiVectorKey& b, ai_real d) const 1.548 + { 1.549 + Interpolator<aiVector3D> ipl; 1.550 + ipl(out,a.mValue,b.mValue,d); 1.551 + } 1.552 +}; // ! Interpolator <aiVectorKey> 1.553 + 1.554 +template <> 1.555 +struct Interpolator<aiQuatKey> { 1.556 + void operator () (aiQuaternion& out, const aiQuatKey& a, 1.557 + const aiQuatKey& b, ai_real d) const 1.558 + { 1.559 + Interpolator<aiQuaternion> ipl; 1.560 + ipl(out,a.mValue,b.mValue,d); 1.561 + } 1.562 +}; // ! Interpolator <aiQuatKey> 1.563 + 1.564 +template <> 1.565 +struct Interpolator<aiMeshKey> { 1.566 + void operator () (unsigned int& out, const aiMeshKey& a, 1.567 + const aiMeshKey& b, ai_real d) const 1.568 + { 1.569 + Interpolator<unsigned int> ipl; 1.570 + ipl(out,a.mValue,b.mValue,d); 1.571 + } 1.572 +}; // ! Interpolator <aiQuatKey> 1.573 + 1.574 +//! @endcond 1.575 + 1.576 +} // ! end namespace Assimp 1.577 + 1.578 +#endif // __cplusplus 1.579 + 1.580 +#endif // AI_ANIM_H_INC