X file and skeleton Animation

Source: Internet
Author: User

. X file format
Frame Scene_Root {// scenario Framework matrix
Matrix
Frame body {// main Frame Matrix
Matrix
Frame unknown {// subframe matrix under the main framework
Matrix
Mesh {grid local coordinates
MeshNormals {...} // Normal Vector Data
MeshTextureCoords {...} // texture coordinate
MeshMaterialList {Material {TextureFIleName {...} // Material list
XSkinMeshHeader {...} // skeleton Information
SkinWeights {...} // vertex skin and bone link information (weight)
.........
}
}
}

// Skeleton parent-child relationship Transformation Matrix
Frame Bip01_Pelvis {Bone Matrix
Frame Bip01_Spine {matrix of spinal cord 1
FrameBip01_Spine1 {spine 2 matrix
................
}
}
}

AnimationSet {animation set
Animation {skeleton action
Animation key {...}
{Bip01_Pelvis} // The skeleton that implements the action
}
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
Relationship between bones
An = Skeleton Matrix A of the nth bone
Xn = coordinate Xn of the skin vertex of the nth bone in the nth bone Coordinate System
X (F) = Coordinate System of the parent skeleton
X (C) = coordinate system of child bones
A (Fr) = transformation matrix from child to Father
X (W) = the parent Coordinate System of the root skeleton is the world coordinate of the vertex
X (l) = local coordinates of vertices

X (F) = X (C) A (Fr)
X (W) = X1 (C) A1 (Fr) = X2 (C) A2 (Fr) A1 (Fr) = X3 (C) A3 (Fr) A2 (Fr) a1 (Fr) = .......... X (L) A (m) m-1 ).... a2 (Fr) A1 (Fr ).
X (L) = X (m + 1) A (m + 1) = X (m + 2) A (m + 2) A (m + 1) = .... X (n) A (n-1 )..... A (m + 2) A (m + 1 ).
Xn = X (L) (A (n) A (n-1)... A (m + 2) A (m + 1) ^-1.
(A (n) A (n-1)... A (m + 2) A (m + 1) ^-1 is the weight matrix.

* The transformed vertex world coordinates are equal to the product of the local coordinates, the weight matrix, and the world transformation matrix of the skeleton. Considering that the vertex is affected by multiple bones, the coordinates after the vertex motion must be multiplied by the weight value of the vertex!

//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
D3DAPI usage
D3DXFRAME Skeleton Structure
D3DXMESHCONAINER Grid container

D3DXFRAME
PFringSibling points to the sibling Frame at the same level,
PFrameFirstChild points to the sub-Frame,
PMeshContainer points to the Mesh data of the framework.
TranformationMatrix is a transformation matrix that stores the coordinate system relative to the parent frame.

D3DXMESHCONTINER
PNextMeshContainer next mesh container pointer
Storage space and processing functions of MeshData grid data
PSkinInfo interface for storing grid skin information, providing functions and data for processing skeleton skin

Use the header pointer to traverse the binary tree, locate any Frame position using the Frame name, and accumulate and calculate the local coordinate transformation matrix and weight matrix of the skeleton!

You can expand D3DXFRAME and D3DXMESHCONTINER to easily store the transformation matrix used in the animation process, the weight matrix of the skeleton, and the texture used for rendering!
Struct D3DXFRAME_DERIVED: public D3DXFRAME
{
D3DXMATRIXA16 CombinedTransformationMatrix; Action Transformation Matrix
};

Struct D3DXMESHCONTAINER_DERIVED: public D3DXMESHCONTAINER
{
LPDIRECT3DTEXTURE9 * ppTextures; texture Array
LPD3DXMESH pOrigMesh; original mesh
LPD3DXATTRIBUTERANGE pAttributeTable; Attribute Table
DWORD NumAttributeGroups; number of attribute groups
DWORD NumInfl;
LPD3DXBUFFER pBoneCombinationBuf; skeleton
D3DXMATRIX ** ppBoneMatrixPtrs; Skeleton Matrix
D3DXMATRIX * pBoneOffsetMatrices; bone weight matrix
DWORD NumPaletteEntries;
};

ID3DXAllocateHierarchy interface to load the frame data of the. x file into the above two struct
CreateFrame
CreateMeshContainer create a Grid container
DestroyFrame release
DestroyMeshContatiner

The following code extends the ID3DXAllocateHierarchy interface:
Class CAllocateHierarchy: public ID3DXAllocateHierarchy
{
Public:
STDMETHOD (CreateFrame) (THIS _ LPCTSTR Name, LPD3DXFRAME * ppNewFrame );
STDMETHOD (CreateMeshContainer) (THIS _
LPCSTR Name,
CONST D3DXMESHDATA * pMeshData,
CONST D3DXMATERIAL * pMaterials,
CONST D3DXEFFECTINSTANCE * pEffectInstances,
DWORD NumMaterials,
Const dword * pAdjacency,
LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER * ppNewMeshContainer );
STDMETHOD (DestroyFrame) (THIS _ LPD3DXFRAME pFrameToFree );
STDMETHOD (DestroyMeshContainer) (THIS _ LPD3DXMESHCONTAINER pMeshContainerBase );
CAllocateHierarchy (CSkinMesh * pSkinMesh): m_pSkinMesh (pSkinMesh ){}

Public:
CSkinMesh * m_pSkinMesh; // to call the method for generating skeleton skin data
};

D3DXLoadMeshHierarchyFromX loads the. x file and returns a pointer to the root frame and an interface object used to control the animation.
The ConvertToIndexedBlendedMesh function in the ID3dXSKinInfo interface generates a new skin mesh that contains vertex index, weight, and skeleton combination attributes, so that each subset of the mesh can be rendered one by one!
ConvertToIndexedBlendedMesh Parameters
Original grid imported by pMesh
Options NULL
PaletteSize Skeleton Matrix call
PAdjacencyIn's adjacent triangle Information
PAdjacecyOut NULL
PFaceRemap NULL
PpVertexRemap NULL
PMaxVertexInfl maximum number of bones affected by a vertex
Number of bones in the pNumBoneCombinations skeleton combination Attribute Table
PpBoneCombinationTable skeleton combination Attribute Table
PpMesh

The ppBoneCombinationTable points to the skeleton composite Attribute Table (array). The element of this table is a D3DXBONECOMBINATION structure, which stores the subset property ID, the subset triangle surface and vertex, and the internal skeleton ID information.
The data in the skin mesh and skeleton composite attribute table can be used to calculate the new coordinates of the vertices of the grid subset of the role at any animation time point! Call DrawSubset to render each subset!

//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////
Steps:
1. Call the D3DXLoadMeshHierarchyFromX function. This function calls the CreateMeshContainer function of the CAllocateHierarchy class interface, fills the data in the D3DXMESHCONTAINER_DERIVED struct, and generates skin data!
2. Start from the root, store the skin data (matrix) into pMeshContainer-> ppBoneMatrixPtrs based on the total number of bones and recursion.
3. Update the world transformation matrix of the skeleton, traverse all child bones from the root, and calculate the surround box.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.