Assimp  v3.1.1 (June 2014)
AssimpView::SceneAnimator Class Reference

Calculates the animated node transformations for a given scene and timestamp. More...

Public Member Functions

void Calculate (double pTime)
 Calculates the node transformations for the scene. More...
 
aiAnimationCurrentAnim () const
 Get the current animation or NULL. More...
 
size_t CurrentAnimIndex () const
 Get the current animation index. More...
 
const std::vector< aiMatrix4x4 > & GetBoneMatrices (const aiNode *pNode, size_t pMeshIndex=0)
 Calculates the bone matrices for the given mesh. More...
 
const aiMatrix4x4GetGlobalTransform (const aiNode *node) const
 Retrieves the most recent global transformation matrix for the given node. More...
 
const aiMatrix4x4GetLocalTransform (const aiNode *node) const
 Retrieves the most recent local transformation matrix for the given node. More...
 
 SceneAnimator (const aiScene *pScene, size_t pAnimIndex=0)
 Constructor for a given scene. More...
 
void SetAnimIndex (size_t pAnimIndex)
 Sets the animation to use for playback. More...
 
 ~SceneAnimator ()
 Destructor. More...
 

Protected Types

typedef std::map< const char *, const aiNode * > BoneMap
 Name to node map to quickly find nodes for given bones by their name. More...
 
typedef std::map< const aiNode *, SceneAnimNode * > NodeMap
 Name to node map to quickly find nodes by their name. More...
 

Protected Member Functions

void CalculateGlobalTransform (SceneAnimNode *pInternalNode)
 Calculates the global transformation matrix for the given internal node. More...
 
SceneAnimNodeCreateNodeTree (aiNode *pNode, SceneAnimNode *pParent)
 Recursively creates an internal node structure matching the current scene and animation. More...
 
void UpdateTransforms (SceneAnimNode *pNode, const std::vector< aiMatrix4x4 > &pTransforms)
 Recursively updates the internal node transformations from the given matrix array. More...
 

Protected Attributes

AnimEvaluatormAnimEvaluator
 The AnimEvaluator we use to calculate the current pose for the current animation. More...
 
BoneMap mBoneNodesByName
 
size_t mCurrentAnimIndex
 Current animation index. More...
 
aiMatrix4x4 mIdentityMatrix
 Identity matrix to return a reference to in case of error. More...
 
NodeMap mNodesByName
 
SceneAnimNodemRootNode
 Root node of the internal scene structure. More...
 
const aiScenemScene
 The scene we're operating on. More...
 
std::vector< aiMatrix4x4mTransforms
 Array to return transformations results inside. More...
 

Detailed Description

Calculates the animated node transformations for a given scene and timestamp.

Create an instance for a aiScene you want to animate and set the current animation to play. You can then have the instance calculate the current pose for all nodes by calling Calculate() for a given timestamp. After this you can retrieve the present transformation for a given node by calling GetLocalTransform() or GetGlobalTransform(). A full set of bone matrices can be retrieved by GetBoneMatrices() for a given mesh.

Member Typedef Documentation

§ BoneMap

typedef std::map<const char*, const aiNode*> AssimpView::SceneAnimator::BoneMap
protected

Name to node map to quickly find nodes for given bones by their name.

§ NodeMap

typedef std::map<const aiNode*, SceneAnimNode*> AssimpView::SceneAnimator::NodeMap
protected

Name to node map to quickly find nodes by their name.

Constructor & Destructor Documentation

§ SceneAnimator()

SceneAnimator::SceneAnimator ( const aiScene pScene,
size_t  pAnimIndex = 0 
)

Constructor for a given scene.

The object keeps a reference to the scene during its lifetime, but ownership stays at the caller.

Parameters
pSceneThe scene to animate.
pAnimIndex[optional] Index of the animation to play. Assumed to be 0 if not given.

§ ~SceneAnimator()

SceneAnimator::~SceneAnimator ( )

Destructor.

Member Function Documentation

§ Calculate()

void SceneAnimator::Calculate ( double  pTime)

Calculates the node transformations for the scene.

Call this to get uptodate results before calling one of the getters.

Parameters
pTimeCurrent time. Can be an arbitrary range.

§ CalculateGlobalTransform()

void SceneAnimator::CalculateGlobalTransform ( SceneAnimNode pInternalNode)
protected

Calculates the global transformation matrix for the given internal node.

§ CreateNodeTree()

SceneAnimNode * SceneAnimator::CreateNodeTree ( aiNode pNode,
SceneAnimNode pParent 
)
protected

Recursively creates an internal node structure matching the current scene and animation.

§ CurrentAnim()

aiAnimation* AssimpView::SceneAnimator::CurrentAnim ( ) const
inline

Get the current animation or NULL.

§ CurrentAnimIndex()

size_t AssimpView::SceneAnimator::CurrentAnimIndex ( ) const
inline

Get the current animation index.

§ GetBoneMatrices()

const std::vector< aiMatrix4x4 > & SceneAnimator::GetBoneMatrices ( const aiNode pNode,
size_t  pMeshIndex = 0 
)

Calculates the bone matrices for the given mesh.

Each bone matrix transforms from mesh space in bind pose to mesh space in skinned pose, it does not contain the mesh's world matrix. Thus the usual matrix chain for using in the vertex shader is

boneMatrix * worldMatrix * viewMatrix * projMatrix
Parameters
pNodeThe node carrying the mesh.
pMeshIndexIndex of the mesh in the node's mesh array. The NODE's mesh array, not the scene's mesh array! Leave out to use the first mesh of the node, which is usually also the only one.
Returns
A reference to a vector of bone matrices. Stays stable till the next call to GetBoneMatrices();

§ GetGlobalTransform()

const aiMatrix4x4 & SceneAnimator::GetGlobalTransform ( const aiNode node) const

Retrieves the most recent global transformation matrix for the given node.

The returned matrix is in world space, which is the same coordinate space as the transformation of the scene's root node. If the node is not animated, the node's original transformation is returned so that you can safely use or assign it to the node itsself. If there is no node with the given name, the identity matrix is returned. All transformations are updated whenever Calculate() is called.

Parameters
pNodeNameName of the node
Returns
A reference to the node's most recently calculated global transformation matrix.

§ GetLocalTransform()

const aiMatrix4x4 & SceneAnimator::GetLocalTransform ( const aiNode node) const

Retrieves the most recent local transformation matrix for the given node.

The returned matrix is in the node's parent's local space, just like the original node's transformation matrix. If the node is not animated, the node's original transformation is returned so that you can safely use or assign it to the node itsself. If there is no node with the given name, the identity matrix is returned. All transformations are updated whenever Calculate() is called.

Parameters
pNodeNameName of the node
Returns
A reference to the node's most recently calculated local transformation matrix.

§ SetAnimIndex()

void SceneAnimator::SetAnimIndex ( size_t  pAnimIndex)

Sets the animation to use for playback.

This also recreates the internal mapping structures, which might take a few cycles.

Parameters
pAnimIndexIndex of the animation in the scene's animation array

§ UpdateTransforms()

void SceneAnimator::UpdateTransforms ( SceneAnimNode pNode,
const std::vector< aiMatrix4x4 > &  pTransforms 
)
protected

Recursively updates the internal node transformations from the given matrix array.

Member Data Documentation

§ mAnimEvaluator

AnimEvaluator* AssimpView::SceneAnimator::mAnimEvaluator
protected

The AnimEvaluator we use to calculate the current pose for the current animation.

§ mBoneNodesByName

BoneMap AssimpView::SceneAnimator::mBoneNodesByName
protected

§ mCurrentAnimIndex

size_t AssimpView::SceneAnimator::mCurrentAnimIndex
protected

Current animation index.

§ mIdentityMatrix

aiMatrix4x4 AssimpView::SceneAnimator::mIdentityMatrix
protected

Identity matrix to return a reference to in case of error.

§ mNodesByName

NodeMap AssimpView::SceneAnimator::mNodesByName
protected

§ mRootNode

SceneAnimNode* AssimpView::SceneAnimator::mRootNode
protected

Root node of the internal scene structure.

§ mScene

const aiScene* AssimpView::SceneAnimator::mScene
protected

The scene we're operating on.

§ mTransforms

std::vector<aiMatrix4x4> AssimpView::SceneAnimator::mTransforms
protected

Array to return transformations results inside.


The documentation for this class was generated from the following files: