1 / 33

Skinned Meshes

Skinned Meshes. Viacheslav Filonenko Michael McKenna Tang Ke. Skeletal Animation. Animating Skinned Meshes. So far we only worked with Static Meshes. Skinned Meshes have flexible Vertices – position of each vertex can be changed in real time.

jana
Télécharger la présentation

Skinned Meshes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Skinned Meshes Viacheslav Filonenko Michael McKenna Tang Ke

  2. Skeletal Animation

  3. Animating Skinned Meshes So far we only worked with Static Meshes. Skinned Meshes have flexible Vertices – position of each vertex can be changed in real time. Not very useful if that has to be done manually. Animating complicated meshes of living beings manually can be very challenging and the results will be far from convincing (actually may turn out scary). Skeletal Animation can help a lot.

  4. Skeleton structure • All bones are connected • Bones are arranged in a hierarchy. • Moving one node will move all the children nodes attached to it but won’t affect other nodes. • The coordinates of every bone is given relative to its parent’s local space - rotating the forearm will cause the palm and the finger to be moved and rotated as well.

  5. Sample Hierarchy

  6. Calculating Mesh coordinates Every part of mesh is attached to a certain bone. For example vertices that make up foot will be attached to foot bone. When a bone moves, attached vertices move together with it. FingerWorldMat = FingerMat * PalmMat * ForearmMat * ... * BodyMat This way is not used anymore as having every vertex to be attached only to one bone will cause gaps (cracks) in the mesh.

  7. Vertex Blending • Skin meshes have the same bone hierarchies, but a single part of a skin mesh can be transformed by more than one bone. • Linear interpolation formula is used to calculate how a vertex is affected by multiple bones. • Requires that each vertex have a blending weight so that the vertex shader can determine how the bones affect the vertex. • For example, if we have a vertex that's to be affected by two bones, the following formula will give the world's coordinate of the vertex as affected by the two bones: Vw = Vm * M1 * w + Vm * M2 * (1-w) Where Vw is the vertex position in world coordinate. Vm is the vertex position relative to the model's local space. M1 and M2 are the transformation matrices of the two bones. w is the blending weight.

  8. Uses for Skeletal Animation Skeletal animation is useful because it allows the animator to control just those characteristics of the model that are independently moveable. A character cannot move the bottom part of their skin independent of the top part. Typically a visual model for the skin will have lots of elements, that the animator would otherwise have to coordinate. Using a skeleton allows the animator to ignore such issues and focus on the large scale motion. Animation is therefore made much simpler: an animation can be defined by simple movements of the bones, instead of vertex by vertex.

  9. Disadvantage? The weakness of the skeletal approach is that it doesn't by itself provide realistic muscle movement. A character flexing an arm will have both large scale bone movement and local skin motion caused by the change in muscle shape under the skin. It is common in animation for the movie industry and increasingly in computer games to have special muscle controllers attached to the bones that mimic this effect. Next step – Virtual Anatomy Simulation?

  10. DirectX .X File Formatand Skinned Meshes

  11. What are X Files? • X files are file formats using templates for storing meshes, textures, animations, user-defined objects and other 3D Geometry. • History: • X files were introduced with DirectX 2.0. • A binary version was released with DirectX 3.0. • Interfaces and Methods that allow reading and writing of X files was introduced with DirectX 6.0.

  12. X File Contents - Header • X files need to identify themselves when they are being loaded by a program. Each file starts with a small header which in our version is: xof 0302txt 0032 • xof is known as the Magic Number. This signifies that the file is an x file. • The 0302txt informs the program that the file is using the DirectX .x file version 3.2 formats and is stored as text instead of binary (bin). • The 0032 signifies how many bits are to reserved for floating points 32-bit or 64-bit.

  13. X File Contents - Data • All the remaining data in X files are either templates or data objects. • The templates look similar to C structure definitions while the data objects are instances of them. You can tell the difference between them as templates start with the word template.

  14. X File Contents - Templates. • Templates are used to define any information that data objects can contain in an X file. These templates can contain any combination of data types from the template data type list: • WORD 16-bit value WORD numWords; • DWORD 32-bit value (int/long) DWORD numDWords; • FLOAT Float value FLOAT numFloats; • DOUBLE 64-bit floating-point value DOUBLE numDoubles; • CHAR 8-bit signed value CHAR imChar;

  15. X File Contents – Templates (Cont). • UCHAR 8-bit unsigned value UCHAR imUChar; • BYTE 8-bit unsigned value BYTE byte; • STRING A NULL termination String STRING sentence; • Array An array of one of the above types array DWORD data[nDWords];

  16. X File Contents – Template Types • Templates are defined by assigning a unique class name preceded by the keyword template. Templates also require a unique Identification Number GUID. • There are three types of templates that can be constructed for an X file. The types are determined by their restrictions: • Open • Closed • Restricted • These restrictions determine which data types can appear in the hierarchy of a data object defined by the template.

  17. Open Templates • Open Templates have no restrictions on which data types can be implemented in a data object. This means that when data is being added new variables can be added. template Mesh { <3D82AB44-62DA-11cf-AB39-0020AF71E433> DWORD nVertices; array Vector vertices[nVertices]; DWORD nFaces; array MeshFace faces[nFaces]; [ ... ] // An open template }

  18. Closed Templates • Closed Templates reject all data types that have not been defined in the template. It follows the template definition exactly. template Vector { <3D82AB5E-62DA-11cf-AB39-0020AF71E433> FLOAT x; FLOAT y; FLOAT z; } // A closed template

  19. Restricted Templates • These templates are a combination of the both Open and Closed. Every variable in a closed template must be defined in a data object. Restricted Templates allow a number of additional templates or data types to be added later on. template FileSystem { <UUID>STRING name; [ Directory <UUID>, File <UUID> ] // A restricted template }

  20. What use are these templates? • What use are these templates if they are not universally used. • These template structures can be used for personal programs and storage however the DirectX SDK provides a number of templates that are used for mesh related data. • These are often referred to as standard templates. Each has their own GUID and unique template name.

  21. Standard Templates • From research I have seen 32 different templates but not all of these are used for Skinned Animated Meshes. Frame - A frame of reference template that defines a hierarchy. FrameTransformationMatrix - Holds the transformation Matrix for a parent Frame template. Mesh - Contains a single mesh’s data. MeshNormals - Holds the normals used by mesh data. MeshTextrueCoords - Holds Texture wrapping for mesh faces. MeshMaterialList - Contains the materials for face mapping values. Material - Contains material colour values. VertexDuplicationIndeices - Informs which vertices are duplicates of other vertices.

  22. Standard Templates SkinWeights - Contains an array of weight values mapped to a mesh’s vertices. Used specifically in Skinned Meshes. AnimationSet - Contains a collection of animation templates. Animation - Defines animation data for a single frame. AnimationKey - Defines a single key frame for the parent animation templates. XSkinMeshHeader - Used by skinned meshes to define the number of bones contained in a mesh. TextureFilenameContains - the texture filename to use as a material

  23. Data Objects • Creating Data objects is similar to instantiating a class or a structure. It is important that each variable contained in the template is included in the data object and is defined in the same order as the template. • Some templates do not define any data types but may reference other templates which create a hierarchy of data objects. This hierarchy of objects makes the skeletal structure of meshes a lot easier to define. • The data objects are declared in the same manner as any class: StructureName InstanceName{ }

  24. Loading and Animating

  25. Model Used • Working with the DirectX .X File Format and Animation in DirectX 9.0 By Jason Jurecka • http://www.gamedev.net/reference/articles/article2079.asp

  26. Classes • CAllocateHierarchy • This class is used with the D3DXLoadMeshHierarchyFromX function. • It handles the Creation and Deletion of Frames and Mesh Containers.

  27. Classes • //1. The name of the frame • //2. The output new frame • HRESULT CAllocateHierarchy::CreateFrame(LPCTSTR Name, LPD3DXFRAME *ppNewFrame) • HRESULT CAllocateHierarchy::CreateMeshContainer( • LPCSTR Name, //1. Name of the Mesh • CONST D3DXMESHDATA *pMeshData, //2. The mesh Data • CONST D3DXMATERIAL *pMaterials, //3. that materials of the mesh • CONST D3DXEFFECTINSTANCE *pEffectInstances, //4. the effects on the mesh • DWORD NumMaterials, //5. the number of meterials in the mesh • CONST DWORD *pAdjacency, //6. the adjacency array for the mesh • LPD3DXSKININFO pSkinInfo, //7. the skin information for the mesh • LPD3DXMESHCONTAINER *ppNewMeshContainer //8. the output mesh container );

  28. Classes • SkinnedMeshWrapper • Wrapper class that handles loading, drawing and animation of the skinned mesh. • void SetCurrentAnimation(DWORD dwAnimationFlag); • void SetupBoneMatrices(LPFRAME pFrame, LPD3DXMATRIX pParentMatrix, IDirect3DDevice9* device); • void UpdateFrameMatrices(LPFRAME pFrame, LPD3DXMATRIX pParentMatrix);

  29. Classes • D3DXLoadMeshHierarchyFromX(_meshName, // File load • D3DXMESH_MANAGED, // Load Options • device, // D3D Device • &Alloc, // Hierarchy allocation class • NULL, // NO Effects • &m_pFrameRoot, // Frame hierarchy • &m_pAnimController))) // Animation Controller

  30. Classes • AnimatedCharacter / Dalek extends Character • StaticMeshWrapper / SkinnedMeshWrapper extends MeshWrapper • ((SkinnedMeshWrapper * )(_meshWrapper))->SetCurrentAnimation(_animationState); • _meshWrapper->update(timeDelta); • _meshWrapper = AssetLoader::instance()->getSkinnedMeshWrapper("tiny_4anim.x", device); • _meshWrapper = AssetLoader::instance()->getStaticMeshWrapper("assets/dalek.x", device);

  31. Problems Encountered • Scaling • D3DXMATRIX mScale, mRot, T; • D3DXMatrixScaling(&mScale, 0.05, 0.05, 0.05); • D3DXMatrixRotationX(&mRot, -90.0); • T = mScale * mRot; • _worldTransform=T*_worldTransform; • device->SetTransform(D3DTS_WORLD, &_worldTransform);

  32. Problems Encountered • Cannot Load Daleks and Tinys together • .h files confliction AnimatedCharacter * dalek= new AnimatedCharacter(); Dalek * dalek= new Dalek();

  33. Future Work • Play different animations • Load new form of meshes

More Related