![]() |
|
|||
File indexing completed on 2025-02-21 09:30:07
0001 /* 0002 --------------------------------------------------------------------------- 0003 Open Asset Import Library (assimp) 0004 --------------------------------------------------------------------------- 0005 0006 Copyright (c) 2006-2024, assimp team 0007 0008 All rights reserved. 0009 0010 Redistribution and use of this software in source and binary forms, 0011 with or without modification, are permitted provided that the following 0012 conditions are met: 0013 0014 * Redistributions of source code must retain the above 0015 copyright notice, this list of conditions and the 0016 following disclaimer. 0017 0018 * Redistributions in binary form must reproduce the above 0019 copyright notice, this list of conditions and the 0020 following disclaimer in the documentation and/or other 0021 materials provided with the distribution. 0022 0023 * Neither the name of the assimp team, nor the names of its 0024 contributors may be used to endorse or promote products 0025 derived from this software without specific prior 0026 written permission of the assimp team. 0027 0028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0029 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0030 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0031 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0032 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0033 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0034 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0035 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0036 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0037 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0038 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0039 --------------------------------------------------------------------------- 0040 */ 0041 0042 /** 0043 * @file anim.h 0044 * @brief Defines the data structures in which the imported animations 0045 * are returned. 0046 */ 0047 #pragma once 0048 #ifndef AI_ANIM_H_INC 0049 #define AI_ANIM_H_INC 0050 0051 #ifdef __GNUC__ 0052 #pragma GCC system_header 0053 #endif 0054 0055 #include <assimp/quaternion.h> 0056 #include <assimp/types.h> 0057 0058 #ifdef __cplusplus 0059 extern "C" { 0060 #endif 0061 0062 // --------------------------------------------------------------------------- 0063 /** 0064 */ 0065 enum aiAnimInterpolation { 0066 /** */ 0067 aiAnimInterpolation_Step, 0068 0069 /** */ 0070 aiAnimInterpolation_Linear, 0071 0072 /** */ 0073 aiAnimInterpolation_Spherical_Linear, 0074 0075 /** */ 0076 aiAnimInterpolation_Cubic_Spline, 0077 0078 /** */ 0079 #ifndef SWIG 0080 _aiAnimInterpolation_Force32Bit = INT_MAX 0081 #endif 0082 }; 0083 0084 // --------------------------------------------------------------------------- 0085 /** A time-value pair specifying a certain 3D vector for the given time. */ 0086 struct aiVectorKey { 0087 /** The time of this key */ 0088 double mTime; 0089 0090 /** The value of this key */ 0091 C_STRUCT aiVector3D mValue; 0092 0093 /** The interpolation setting of this key */ 0094 C_ENUM aiAnimInterpolation mInterpolation; 0095 0096 #ifdef __cplusplus 0097 0098 /// @brief The default constructor. 0099 aiVectorKey() AI_NO_EXCEPT 0100 : mTime(0.0), mValue(), mInterpolation(aiAnimInterpolation_Linear) {} 0101 0102 /// @brief Construction from a given time and key value. 0103 aiVectorKey(double time, const aiVector3D &value) : 0104 mTime(time), mValue(value), mInterpolation(aiAnimInterpolation_Linear){} 0105 0106 typedef aiVector3D elem_type; 0107 0108 // Comparison operators. For use with std::find(); 0109 bool operator==(const aiVectorKey &rhs) const { 0110 return rhs.mValue == this->mValue; 0111 } 0112 0113 bool operator!=(const aiVectorKey &rhs) const { 0114 return rhs.mValue != this->mValue; 0115 } 0116 0117 // Relational operators. For use with std::sort(); 0118 bool operator<(const aiVectorKey &rhs) const { 0119 return mTime < rhs.mTime; 0120 } 0121 0122 bool operator>(const aiVectorKey &rhs) const { 0123 return mTime > rhs.mTime; 0124 } 0125 #endif // __cplusplus 0126 }; 0127 0128 // --------------------------------------------------------------------------- 0129 /** A time-value pair specifying a rotation for the given time. 0130 * Rotations are expressed with quaternions. */ 0131 struct aiQuatKey { 0132 /** The time of this key */ 0133 double mTime; 0134 0135 /** The value of this key */ 0136 C_STRUCT aiQuaternion mValue; 0137 0138 /** The interpolation setting of this key */ 0139 C_ENUM aiAnimInterpolation mInterpolation; 0140 0141 #ifdef __cplusplus 0142 aiQuatKey() AI_NO_EXCEPT 0143 : mTime(0.0), mValue(), mInterpolation(aiAnimInterpolation_Linear) {} 0144 0145 /** Construction from a given time and key value */ 0146 aiQuatKey(double time, const aiQuaternion &value) : 0147 mTime(time), mValue(value), mInterpolation(aiAnimInterpolation_Linear) {} 0148 0149 typedef aiQuaternion elem_type; 0150 0151 // Comparison operators. For use with std::find(); 0152 bool operator==(const aiQuatKey &rhs) const { 0153 return rhs.mValue == this->mValue; 0154 } 0155 0156 bool operator!=(const aiQuatKey &rhs) const { 0157 return rhs.mValue != this->mValue; 0158 } 0159 0160 // Relational operators. For use with std::sort(); 0161 bool operator<(const aiQuatKey &rhs) const { 0162 return mTime < rhs.mTime; 0163 } 0164 0165 bool operator>(const aiQuatKey &rhs) const { 0166 return mTime > rhs.mTime; 0167 } 0168 #endif 0169 }; 0170 0171 // --------------------------------------------------------------------------- 0172 /** Binds a anim-mesh to a specific point in time. */ 0173 struct aiMeshKey { 0174 /** The time of this key */ 0175 double mTime; 0176 0177 /** Index into the aiMesh::mAnimMeshes array of the 0178 * mesh corresponding to the #aiMeshAnim hosting this 0179 * key frame. The referenced anim mesh is evaluated 0180 * according to the rules defined in the docs for #aiAnimMesh.*/ 0181 unsigned int mValue; 0182 0183 #ifdef __cplusplus 0184 0185 aiMeshKey() AI_NO_EXCEPT 0186 : mTime(0.0), 0187 mValue(0) { 0188 } 0189 0190 /** Construction from a given time and key value */ 0191 aiMeshKey(double time, const unsigned int value) : 0192 mTime(time), mValue(value) {} 0193 0194 typedef unsigned int elem_type; 0195 0196 // Comparison operators. For use with std::find(); 0197 bool operator==(const aiMeshKey &o) const { 0198 return o.mValue == this->mValue; 0199 } 0200 bool operator!=(const aiMeshKey &o) const { 0201 return o.mValue != this->mValue; 0202 } 0203 0204 // Relational operators. For use with std::sort(); 0205 bool operator<(const aiMeshKey &o) const { 0206 return mTime < o.mTime; 0207 } 0208 bool operator>(const aiMeshKey &o) const { 0209 return mTime > o.mTime; 0210 } 0211 0212 #endif 0213 }; 0214 0215 // --------------------------------------------------------------------------- 0216 /** Binds a morph anim mesh to a specific point in time. */ 0217 struct aiMeshMorphKey { 0218 /** The time of this key */ 0219 double mTime; 0220 0221 /** The values and weights at the time of this key 0222 * - mValues: index of attachment mesh to apply weight at the same position in mWeights 0223 * - mWeights: weight to apply to the blend shape index at the same position in mValues 0224 */ 0225 unsigned int *mValues; 0226 double *mWeights; 0227 0228 /** The number of values and weights */ 0229 unsigned int mNumValuesAndWeights; 0230 #ifdef __cplusplus 0231 aiMeshMorphKey() AI_NO_EXCEPT 0232 : mTime(0.0), 0233 mValues(nullptr), 0234 mWeights(nullptr), 0235 mNumValuesAndWeights(0) { 0236 } 0237 0238 ~aiMeshMorphKey() { 0239 if (mNumValuesAndWeights && mValues && mWeights) { 0240 delete[] mValues; 0241 delete[] mWeights; 0242 } 0243 } 0244 #endif 0245 }; 0246 0247 // --------------------------------------------------------------------------- 0248 /** Defines how an animation channel behaves outside the defined time 0249 * range. This corresponds to aiNodeAnim::mPreState and 0250 * aiNodeAnim::mPostState.*/ 0251 enum aiAnimBehaviour { 0252 /** The value from the default node transformation is taken*/ 0253 aiAnimBehaviour_DEFAULT = 0x0, 0254 0255 /** The nearest key value is used without interpolation */ 0256 aiAnimBehaviour_CONSTANT = 0x1, 0257 0258 /** The value of the nearest two keys is linearly 0259 * extrapolated for the current time value.*/ 0260 aiAnimBehaviour_LINEAR = 0x2, 0261 0262 /** The animation is repeated. 0263 * 0264 * If the animation key go from n to m and the current 0265 * time is t, use the value at (t-n) % (|m-n|).*/ 0266 aiAnimBehaviour_REPEAT = 0x3, 0267 0268 /** This value is not used, it is just here to force the 0269 * the compiler to map this enum to a 32 Bit integer */ 0270 #ifndef SWIG 0271 _aiAnimBehaviour_Force32Bit = INT_MAX 0272 #endif 0273 }; 0274 0275 // --------------------------------------------------------------------------- 0276 /** Describes the animation of a single node. The name specifies the 0277 * bone/node which is affected by this animation channel. The keyframes 0278 * are given in three separate series of values, one each for position, 0279 * rotation and scaling. The transformation matrix computed from these 0280 * values replaces the node's original transformation matrix at a 0281 * specific time. 0282 * This means all keys are absolute and not relative to the bone default pose. 0283 * The order in which the transformations are applied is 0284 * - as usual - scaling, rotation, translation. 0285 * 0286 * @note All keys are returned in their correct, chronological order. 0287 * Duplicate keys don't pass the validation step. Most likely there 0288 * will be no negative time values, but they are not forbidden also ( so 0289 * implementations need to cope with them! ) */ 0290 struct aiNodeAnim { 0291 /** The name of the node affected by this animation. The node 0292 * must exist and it must be unique.*/ 0293 C_STRUCT aiString mNodeName; 0294 0295 /** The number of position keys */ 0296 unsigned int mNumPositionKeys; 0297 0298 /** The position keys of this animation channel. Positions are 0299 * specified as 3D vector. The array is mNumPositionKeys in size. 0300 * 0301 * If there are position keys, there will also be at least one 0302 * scaling and one rotation key.*/ 0303 C_STRUCT aiVectorKey *mPositionKeys; 0304 0305 /** The number of rotation keys */ 0306 unsigned int mNumRotationKeys; 0307 0308 /** The rotation keys of this animation channel. Rotations are 0309 * given as quaternions, which are 4D vectors. The array is 0310 * mNumRotationKeys in size. 0311 * 0312 * If there are rotation keys, there will also be at least one 0313 * scaling and one position key. */ 0314 C_STRUCT aiQuatKey *mRotationKeys; 0315 0316 /** The number of scaling keys */ 0317 unsigned int mNumScalingKeys; 0318 0319 /** The scaling keys of this animation channel. Scalings are 0320 * specified as 3D vector. The array is mNumScalingKeys in size. 0321 * 0322 * If there are scaling keys, there will also be at least one 0323 * position and one rotation key.*/ 0324 C_STRUCT aiVectorKey *mScalingKeys; 0325 0326 /** Defines how the animation behaves before the first 0327 * key is encountered. 0328 * 0329 * The default value is aiAnimBehaviour_DEFAULT (the original 0330 * transformation matrix of the affected node is used).*/ 0331 C_ENUM aiAnimBehaviour mPreState; 0332 0333 /** Defines how the animation behaves after the last 0334 * key was processed. 0335 * 0336 * The default value is aiAnimBehaviour_DEFAULT (the original 0337 * transformation matrix of the affected node is taken).*/ 0338 C_ENUM aiAnimBehaviour mPostState; 0339 0340 #ifdef __cplusplus 0341 aiNodeAnim() AI_NO_EXCEPT 0342 : mNumPositionKeys(0), 0343 mPositionKeys(nullptr), 0344 mNumRotationKeys(0), 0345 mRotationKeys(nullptr), 0346 mNumScalingKeys(0), 0347 mScalingKeys(nullptr), 0348 mPreState(aiAnimBehaviour_DEFAULT), 0349 mPostState(aiAnimBehaviour_DEFAULT) { 0350 // empty 0351 } 0352 0353 ~aiNodeAnim() { 0354 delete[] mPositionKeys; 0355 delete[] mRotationKeys; 0356 delete[] mScalingKeys; 0357 } 0358 #endif // __cplusplus 0359 }; 0360 0361 // --------------------------------------------------------------------------- 0362 /** Describes vertex-based animations for a single mesh or a group of 0363 * meshes. Meshes carry the animation data for each frame in their 0364 * aiMesh::mAnimMeshes array. The purpose of aiMeshAnim is to 0365 * define keyframes linking each mesh attachment to a particular 0366 * point in time. */ 0367 struct aiMeshAnim { 0368 /** Name of the mesh to be animated. An empty string is not allowed, 0369 * animated meshes need to be named (not necessarily uniquely, 0370 * the name can basically serve as wild-card to select a group 0371 * of meshes with similar animation setup)*/ 0372 C_STRUCT aiString mName; 0373 0374 /** Size of the #mKeys array. Must be 1, at least. */ 0375 unsigned int mNumKeys; 0376 0377 /** Key frames of the animation. May not be nullptr. */ 0378 C_STRUCT aiMeshKey *mKeys; 0379 0380 #ifdef __cplusplus 0381 0382 aiMeshAnim() AI_NO_EXCEPT 0383 : mNumKeys(), 0384 mKeys() {} 0385 0386 ~aiMeshAnim() { 0387 delete[] mKeys; 0388 } 0389 0390 #endif 0391 }; 0392 0393 // --------------------------------------------------------------------------- 0394 /** Describes a morphing animation of a given mesh. */ 0395 struct aiMeshMorphAnim { 0396 /** Name of the mesh to be animated. An empty string is not allowed, 0397 * animated meshes need to be named (not necessarily uniquely, 0398 * the name can basically serve as wildcard to select a group 0399 * of meshes with similar animation setup)*/ 0400 C_STRUCT aiString mName; 0401 0402 /** Size of the #mKeys array. Must be 1, at least. */ 0403 unsigned int mNumKeys; 0404 0405 /** Key frames of the animation. May not be nullptr. */ 0406 C_STRUCT aiMeshMorphKey *mKeys; 0407 0408 #ifdef __cplusplus 0409 0410 aiMeshMorphAnim() AI_NO_EXCEPT 0411 : mNumKeys(), 0412 mKeys() {} 0413 0414 ~aiMeshMorphAnim() { 0415 delete[] mKeys; 0416 } 0417 0418 #endif 0419 }; 0420 0421 // --------------------------------------------------------------------------- 0422 /** An animation consists of key-frame data for a number of nodes. For 0423 * each node affected by the animation a separate series of data is given.*/ 0424 struct aiAnimation { 0425 /** The name of the animation. If the modeling package this data was 0426 * exported from does support only a single animation channel, this 0427 * name is usually empty (length is zero). */ 0428 C_STRUCT aiString mName; 0429 0430 /** Duration of the animation in ticks. */ 0431 double mDuration; 0432 0433 /** Ticks per second. 0 if not specified in the imported file */ 0434 double mTicksPerSecond; 0435 0436 /** The number of bone animation channels. Each channel affects 0437 * a single node. */ 0438 unsigned int mNumChannels; 0439 0440 /** The node animation channels. Each channel affects a single node. 0441 * The array is mNumChannels in size. */ 0442 C_STRUCT aiNodeAnim **mChannels; 0443 0444 /** The number of mesh animation channels. Each channel affects 0445 * a single mesh and defines vertex-based animation. */ 0446 unsigned int mNumMeshChannels; 0447 0448 /** The mesh animation channels. Each channel affects a single mesh. 0449 * The array is mNumMeshChannels in size. */ 0450 C_STRUCT aiMeshAnim **mMeshChannels; 0451 0452 /** The number of mesh animation channels. Each channel affects 0453 * a single mesh and defines morphing animation. */ 0454 unsigned int mNumMorphMeshChannels; 0455 0456 /** The morph mesh animation channels. Each channel affects a single mesh. 0457 * The array is mNumMorphMeshChannels in size. */ 0458 C_STRUCT aiMeshMorphAnim **mMorphMeshChannels; 0459 0460 #ifdef __cplusplus 0461 aiAnimation() AI_NO_EXCEPT 0462 : mDuration(-1.), 0463 mTicksPerSecond(0.), 0464 mNumChannels(0), 0465 mChannels(nullptr), 0466 mNumMeshChannels(0), 0467 mMeshChannels(nullptr), 0468 mNumMorphMeshChannels(0), 0469 mMorphMeshChannels(nullptr) { 0470 // empty 0471 } 0472 0473 ~aiAnimation() { 0474 // DO NOT REMOVE THIS ADDITIONAL CHECK 0475 if (mNumChannels && mChannels) { 0476 for (unsigned int a = 0; a < mNumChannels; a++) { 0477 delete mChannels[a]; 0478 } 0479 0480 delete[] mChannels; 0481 } 0482 if (mNumMeshChannels && mMeshChannels) { 0483 for (unsigned int a = 0; a < mNumMeshChannels; a++) { 0484 delete mMeshChannels[a]; 0485 } 0486 0487 delete[] mMeshChannels; 0488 } 0489 if (mNumMorphMeshChannels && mMorphMeshChannels) { 0490 for (unsigned int a = 0; a < mNumMorphMeshChannels; a++) { 0491 delete mMorphMeshChannels[a]; 0492 } 0493 0494 delete[] mMorphMeshChannels; 0495 } 0496 } 0497 #endif // __cplusplus 0498 }; 0499 0500 #ifdef __cplusplus 0501 } 0502 0503 /// @brief Some C++ utilities for inter- and extrapolation 0504 namespace Assimp { 0505 0506 // --------------------------------------------------------------------------- 0507 /** 0508 * @brief CPP-API: Utility class to simplify interpolations of various data types. 0509 * 0510 * The type of interpolation is chosen automatically depending on the 0511 * types of the arguments. 0512 */ 0513 template <typename T> 0514 struct Interpolator { 0515 // ------------------------------------------------------------------ 0516 /** @brief Get the result of the interpolation between a,b. 0517 * 0518 * The interpolation algorithm depends on the type of the operands. 0519 * aiQuaternion's and aiQuatKey's SLERP, the rest does a simple 0520 * linear interpolation. */ 0521 void operator()(T &anim_out, const T &a, const T &b, ai_real d) const { 0522 anim_out = a + (b - a) * d; 0523 } 0524 }; // ! Interpolator <T> 0525 0526 //! @cond Never 0527 0528 template <> 0529 struct Interpolator<aiQuaternion> { 0530 void operator()(aiQuaternion &out, const aiQuaternion &a, 0531 const aiQuaternion &b, ai_real d) const { 0532 aiQuaternion::Interpolate(out, a, b, d); 0533 } 0534 }; // ! Interpolator <aiQuaternion> 0535 0536 template <> 0537 struct Interpolator<unsigned int> { 0538 void operator()(unsigned int &out, unsigned int a, 0539 unsigned int b, ai_real d) const { 0540 out = d > 0.5f ? b : a; 0541 } 0542 }; // ! Interpolator <aiQuaternion> 0543 0544 template <> 0545 struct Interpolator<aiVectorKey> { 0546 void operator()(aiVector3D &out, const aiVectorKey &a, 0547 const aiVectorKey &b, ai_real d) const { 0548 Interpolator<aiVector3D> ipl; 0549 ipl(out, a.mValue, b.mValue, d); 0550 } 0551 }; // ! Interpolator <aiVectorKey> 0552 0553 template <> 0554 struct Interpolator<aiQuatKey> { 0555 void operator()(aiQuaternion &out, const aiQuatKey &a, 0556 const aiQuatKey &b, ai_real d) const { 0557 Interpolator<aiQuaternion> ipl; 0558 ipl(out, a.mValue, b.mValue, d); 0559 } 0560 }; // ! Interpolator <aiQuatKey> 0561 0562 template <> 0563 struct Interpolator<aiMeshKey> { 0564 void operator()(unsigned int &out, const aiMeshKey &a, 0565 const aiMeshKey &b, ai_real d) const { 0566 Interpolator<unsigned int> ipl; 0567 ipl(out, a.mValue, b.mValue, d); 0568 } 0569 }; // ! Interpolator <aiQuatKey> 0570 0571 //! @endcond 0572 0573 } // namespace Assimp 0574 0575 #endif // __cplusplus 0576 0577 #endif // AI_ANIM_H_INC
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |