DX8 trouble with mesh animation. PLEASE!!

Started by
43 comments, last by KingSnake 22 years, 2 months ago
I can''t animate the mesh!! Ok. I''ve made a simple animation in 3d studio max 3, i''ve exported it to a mesh (.3ds), i''ve converted it into a .x file with frames and animations (verified it in text mode of .x file), i''ve opened the .x file as a d3d mesh with this code: //----------------------------------------------------------------------------- // Name: InitGeometry() // Desc: Create the textures and vertex buffers //----------------------------------------------------------------------------- HRESULT InitGeometry() { LPD3DXBUFFER pD3DXMtrlBuffer; //new // Load the mesh from the specified file if( FAILED( D3DXLoadMeshFromX( "alucard2.x", D3DXMESH_MANAGED,//DYNAMIC, //SYSTEMMEM, g_pd3dDevice, NULL, &pD3DXMtrlBuffer, &g_dwNumMaterials, &g_pMesh ) ) ) { return E_FAIL; } D3DXComputeNormals(g_pMesh); //calcola in automatico le normali!! // We need to extract the material properties and texture names from the // pD3DXMtrlBuffer D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer(); g_pMeshMaterials = new D3DMATERIAL8[g_dwNumMaterials]; g_pMeshTextures = new LPDIRECT3DTEXTURE8[g_dwNumMaterials]; for( DWORD i=0; i = d3dxMaterials.MatD3D; // Set the ambient color for the material (D3DX does not do this) g_pMeshMaterials.Ambient = g_pMeshMaterials.Diffuse= g_pMeshMaterials.Specular; // Create the texture if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, d3dxMaterials.pTextureFilename, &g_pMeshTextures ) ) ) { g_pMeshTextures = NULL; } } // Done with the material buffer pD3DXMtrlBuffer->Release(); return S_OK; } i render it with this: for( j=0; j<g_dwNumMaterials; j++ ) //rendering mesh opaca { // Set the material and texture for this subset g_pd3dDevice->SetMaterial( &g_pMeshMaterials[j] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures[j] ); //g_pd3dDevice->SetTexture( 1, g_pTexture); // Draw the mesh subset g_pMesh->DrawSubset( j ); } BUT NO ANIMATION AT ALL! just the first key frame… how do i call the other frames? thanks! Michele. </i>
Advertisement
<< If one more person asks how to animate a mesh, Psionic will blow >>

you can just call frames like that. its alot harder than just

D3DXMakeGraphicsLookCool();
D3DXPlayMyAnimation();

you have to use either fixed function geometry blending, use a vertex shader, or setup animation tweening

msdn.microsoft.com/directx has a tutorial. its advanced.
"This is stupid. I can't believe this! Ok, this time, there really IS a bug in the compiler."... 20 mins pass ..."I'M AN IDIOT!!!"
Do you think you are funny?
Do you think you are helpful?
Do you think i am stupid?
If you are SO good, don''t go around in this board.

Thank you.
I haven''t played much with .x files, but to do animation, you have to read the animation data. ID3DXMesh simple is just static mesh data. ID3DXSkinMesh might be what you want, to make skinned animation. The SDK also has a skinmesh example. In this forum there is one topic describing that quite well. I''m writing 3d game engine and will also implement SkinMesh in very near future. Not yet decided file format (maybe MilkShape, don''t have 3DStudio). Sorry, but can''t help more just now, good luck. You just need to learn very much.
A skinned mesh is a static mesh with ''bones'', matrices that transform some regions of it. I don''t want it. (maybe later..)
I want a simple mesh with straightforward animations, those contained in the .x file (possible, there is also the flag in conv3ds to include it..)

how do i do it?


Michele.
What are you talking about ???

I gave you the site that has an article that shows you how to do mesh animation!

Whats eating you ???



Edited by - Psionic on June 11, 2001 4:24:41 PM
"This is stupid. I can't believe this! Ok, this time, there really IS a bug in the compiler."... 20 mins pass ..."I'M AN IDIOT!!!"
I have the same problem and maybe more : to create the .x ( with animation data ) from .3ds it is correct : conv3ds -A -X name.3ds ?
*Takes Deep Breath*

You can''t use D3DXLoadMeshFromX function to load a mesh that contains bones. The only way is to use the IDirectXFile objects to parse the templates of an .X file. Once you find the Mesh template, you need to load it into an ID3DXSkinMesh object via the D3DXLoadSkinMeshFromXOf function. Once done, you''ll have an array of matrices that you use to alter the orientation of the bones. Once the bones are reoriented, call the ID3DSkinMesh::UpdateSkinnedMesh function to generate an ID3DXMesh object used for rendering the mesh in the orientation.

*Exhales little remaining breath*

It really isn''t hard once you see it in working code. My book is going to contain the code to load multiple animations and apply them to meshes, but you''ll have to wait until Nov when the book is published


Jim Adams



Jim Adams
home.att.net/~rpgbook
Programming Role-Playing Games with DirectX 8
BUT!

If i use 3ds to make an animation, it isn''t saved as ''bones'' into the mesh (that so is a skinned one) or i am wrong? In other words, meshes in dx are only static and the only way to make an animation (aparte tweening) is skinning?

let me know, it is such an important and understimated thing...



Michele.



(if you could add some chunks of code....)


Thanks everybody!
You need to use the .X File exporter provided with the DX SDK in order to export bone data. Any other way, you could structure your scene as a series of frames, then animate the frames individually. Unforunatelly, the code is much too large to post anything here. I can describe it however.

Using the same loading mechanism, scan through each template using the IDirectXFile series of objects. When you find a mesh, load it with the appropriate mesh loading function. At that point, set the desired matrix and render each mesh attached to seperate frames.



Jim Adams
home.att.net/~rpgbook
Programming Role-Playing Games with DirectX 8

This topic is closed to new replies.

Advertisement