Public Member Functions | Protected Member Functions

sp::scene::AnimationSkeleton Class Reference
[Animation System]

#include <spAnimationSkeleton.hpp>

List of all members.

Public Member Functions

 AnimationSkeleton ()
virtual ~AnimationSkeleton ()
AnimationJointcreateJoint (const Transformation &OriginTransform, const io::stringc &Name="", AnimationJoint *Parent=0)
void deleteJoint (AnimationJoint *Joint)
 Deletes the specified joint from the list.
AnimationJointfindJoint (const io::stringc &Name)
 Returns a pointer to the first joint with the specified name.
void setJointParent (AnimationJoint *Joint, AnimationJoint *Parent)
void updateSkeleton ()
void transformVertices (Mesh *MeshObj) const
void fillJointTransformations (std::vector< dim::matrix4f > &JointMatrices, bool KeepJointOrder=true) const
bool setupVertexBufferAttributes (Mesh *MeshObj, const std::vector< video::SVertexAttribute > &IndexAttributes, const std::vector< video::SVertexAttribute > &WeightAttributes) const
virtual void render (const dim::matrix4f &BaseMatrix, const video::color &Color=video::color(255, 255, 0))
const std::list
< AnimationJoint * > & 
getJointList () const
 Returns the list of all animation joints.
u32 getJointCount () const
 Returns the count of animation joints.
const std::vector
< AnimationJoint * > & 
getRootJointList () const
 Returns the list of all animation root joints. Root joints have no parent.
u32 getRootJointCount () const
 Returns the count of animation root joints.

Protected Member Functions

virtual void drawJointConnections (AnimationJoint *Joint, dim::matrix4f BaseMatrix, const video::color &Color)
virtual void drawJointConnector (const dim::matrix4f &Matrix, const video::color &Color)

Detailed Description

Animation skeletons are constructed out of animation joints. It forms the foundation of a skeletal animation.


Constructor & Destructor Documentation

sp::scene::AnimationSkeleton::AnimationSkeleton (  ) 
sp::scene::AnimationSkeleton::~AnimationSkeleton (  )  [virtual]

Member Function Documentation

AnimationJoint * sp::scene::AnimationSkeleton::createJoint ( const Transformation OriginTransform,
const io::stringc Name = "",
AnimationJoint Parent = 0 
)

Creates a new AnimationJoint object and adds it into the skeleton graph.

Parameters:
OriginTransform,: Specifies the origin transformation.
Name,: Specifies the joint's name.
Parent,: Specifies the joint parent.
Returns:
Pointer to the new AnimationJoint object.
void sp::scene::AnimationSkeleton::deleteJoint ( AnimationJoint Joint  ) 

Deletes the specified joint from the list.

void sp::scene::AnimationSkeleton::drawJointConnections ( AnimationJoint Joint,
dim::matrix4f  BaseMatrix,
const video::color Color 
) [protected, virtual]
void sp::scene::AnimationSkeleton::drawJointConnector ( const dim::matrix4f Matrix,
const video::color Color 
) [protected, virtual]
void sp::scene::AnimationSkeleton::fillJointTransformations ( std::vector< dim::matrix4f > &  JointMatrices,
bool  KeepJointOrder = true 
) const

Fills all joint transformations into the given matrix list.

Parameters:
[in,out] JointMatrices Specifies the container which is to be filled with the joint transformations.
[in] KeepJointOrder Specifies whether the joint order is to be kept or not. If true each joint matrix is stored at the same index as the joint has been created for the skeleton. Use this when you need the transformations for hardware accelerated animation. If false the transformations can be computed a little faster but the order is arbitrary. By default true.
Note:
This will not resize the container! Initialize the container with the maximum size, e.g. count of joints.
AnimationJoint * sp::scene::AnimationSkeleton::findJoint ( const io::stringc Name  ) 

Returns a pointer to the first joint with the specified name.

u32 sp::scene::AnimationSkeleton::getJointCount (  )  const [inline]

Returns the count of animation joints.

const std::list<AnimationJoint*>& sp::scene::AnimationSkeleton::getJointList (  )  const [inline]

Returns the list of all animation joints.

u32 sp::scene::AnimationSkeleton::getRootJointCount (  )  const [inline]

Returns the count of animation root joints.

const std::vector<AnimationJoint*>& sp::scene::AnimationSkeleton::getRootJointList (  )  const [inline]

Returns the list of all animation root joints. Root joints have no parent.

void sp::scene::AnimationSkeleton::render ( const dim::matrix4f BaseMatrix,
const video::color Color = video::color(255, 255, 0) 
) [virtual]

Renders the skeleton as a wire mesh. Call this function inside a 'beginDrawing2D' and 'endDrawing2D' block of your render system (RenderSystem object).

Parameters:
BaseMatrix,: Specifies the base matrix transformation. Use the object's global location (SceneNode::getGlobalLcoation()).
Color,: Specifies the color which is to be used to render the skeleton.
void sp::scene::AnimationSkeleton::setJointParent ( AnimationJoint Joint,
AnimationJoint Parent 
)

Sets the new joint parent and automatically updates the children list. You have to call "updateSkeleton" after changing the parent hierarchy!

Parameters:
Joint,: Specifies the joint which will get the new parnet.
Parent,: Specifies the new AnimationJoint parent object. Can also be 0.
bool sp::scene::AnimationSkeleton::setupVertexBufferAttributes ( Mesh MeshObj,
const std::vector< video::SVertexAttribute > &  IndexAttributes,
const std::vector< video::SVertexAttribute > &  WeightAttributes 
) const

Sets up the vertex buffer attributes of the specified mesh to use this skeleton for hardware accelerated animation. The final vertex shader must be written by yourself, but the workaround to setup the indices and joint weights for each vertex can be calculated by this function.

Parameters:
[in] MeshObj Specifies the mesh object whose vertex buffers are to be set up.
[in] IndexAttributes Specifies the list of vertex attributes for the joint indices.
[in] WeightAttributes Specifies the list of vertex attributes for the joint weights.
Returns:
True if the vertex buffers could be set up successful. Otherwise an error has occured.
Note:
'IndexAttributes' and 'WeightAttributes' must have the same count of elements. It's also recommended to use 4-component float vectors for these attributes.
        // Create a universal vertex format.
        video::VertexFormatUniversal* VertFmt = spRenderer->createVertexFormat<video::VertexFormatUniversal>();
        
        // Add the default components.
        VertFmt->addCoord();
        VertFmt->addNormal();
        VertFmt->addTexCoord();
        
        // Add the attribute for the indices. This is a 4 component vector, thus each vertex can be transformed by 4 joints at once.
        VertFmt->addTexCoord(video::DATATYPE_FLOAT, 4);
        // Add the attribute for the weights. Same as above.
        VertFmt->addTexCoord(video::DATATYPE_FLOAT, 4);
        
        // Create your shader.
        video::ShaderClass* AnimShaderClass = spRenderer->createShaderClass(VertFmt);
        //...
        
        // Setup the vertex buffers
        std::vector<video::SVertexAttribute> IndexAttributes, WeightAttributes;
        
        IndexAttributes.push_back(VertFmt->getTexCoord()[1]);
        WeightAttributes.push_back(VertFmt->getTexCoord()[2]);
        
        AnimSkeleton->setupVertexBuffers(AnimMesh, IndexAttributes, WeightAttributes);
        
        // Disable software per-vertex transformation.
        Anim->setFlags(scene::ANIMFLAG_NO_TRANSFORMATION);
See also:
video::VertexFormatUniversal
void sp::scene::AnimationSkeleton::transformVertices ( Mesh MeshObj  )  const

Transforms the vertices (given by the vertex groups surface) by the current skeleton transformation. Each joint has a 'origin transformation' and a 'current transformation'. If these two transformation of each joint are equal the mesh trnsformation has no effect.

Parameters:
[in] MeshObj Specifies the mesh object which is to be transformed. This mesh should have the same count of mesh buffers with the same count of vertices and triangles as the base mesh used when the skeleton was created.

TODO! -> optimize this, sometimes a vertex will be reseted several times!

TODO! -> optmize this!

void sp::scene::AnimationSkeleton::updateSkeleton (  ) 

Stores all surfaces used by the joints in a unique list. This should be called after all joints have been created.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines