vrshoot

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