Archived

This topic is now archived and is closed to further replies.

DX8 trouble with mesh animation. PLEASE!!

This topic is 5804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i].MatD3D; // Set the ambient color for the material (D3DX does not do this) g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse= g_pMeshMaterials[i].Specular; // Create the texture if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, d3dxMaterials[i].pTextureFilename, &g_pMeshTextures[i] ) ) ) { g_pMeshTextures[i] = NULL; } } // Done with the material buffer pD3DXMtrlBuffer->Release(); return S_OK; } i render it with this: for( j=0; jSetMaterial( &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.

Share this post


Link to post
Share on other sites
<< 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
*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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Yeah.
in fact i''m working on it. Just i don''t know why there is a .x that FUSES all the 3 .x dolphins in different poses.

at the end it would be fun if there was a mesh structure in wich import the ANIMATED mesh (allowed by the x format) and then animate it on a delay-between-frames basis.

I can''t see how to use the animation info stored in the .x files, and i wonder if it''s possible without skinned meshes.

ANOTHER THING!

i''ve tried to see if the skinned mesh uses that animation info i''ve told: answer, NO!
i''ve made a simple animation in 3ds, exported to .x and passed (renaming it) to the skinnedmesh example: it visualized correctly the mesh, but no animation at all, just first frame.
So the ''bones'' don''t come (imo) from the .x...

let me know!


bye

Share this post


Link to post
Share on other sites
Check in the exported .X file for a template type of Animation or AnimationSet. If those are not in the .X file, then it did not export them correctly. Also, if you''re using bones, the exporter will include a couple addition headers in there, namely XSkinMeshHeader. If that''s not at the top somewhere, then the bone information wasn''t exported.

I can''t help you much on the 3ds exporting, as I do not have it at this point, but if you''re using Milkshape 3D, then you should be in luck soon - my .X file exporter for Milkshape 3D is nearly complete - you can download the current version that exports simple meshes at this point (no animations of skin data yet). Those functions are nearly complete, but at times I get slowed down working on my book, but don''t dispair - it''ll be done in time for the book release as well.



Jim


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I don''t know much about C/C++. Im a VB user! But i know 100% that you can use built in animation controlls with DirectX.. there''s a sample that comes with VB SDK that uses keyframes from an X file...

Share this post


Link to post
Share on other sites
The VB skinnedmesh sample isn''t any better. You are FAR better off designing your own animation system. Besides, if MS was trying to tell you to use VB, there would be an FPS counter, and a menu in the VB samples...

As for that Dolphin, each dolphin pose is a different Subset in the mesh, so you can render either from the one mesh.

Z.

Share this post


Link to post
Share on other sites
Message: "we are S-T-U-P-I-D people"
i had some consideration after trying Dx8 and Vc++ 6, but soon decreased.
Easy things are explained deeply and with abundance of detail
Difficult ones are ''described'' with little or no code, and submerged in uneuseful other code...

Share this post


Link to post
Share on other sites
Zaei,
I wasn''t talking about the skinnedMesh VB sample.
Check out the VB AnimKeys sample. Now THATs what I call stupid
as there is NO AnimKeys sample made for C++. :-D
--Mohotmoz

Share this post


Link to post
Share on other sites
That AnimKeys thing would be wonderful for my current project, if only it were in C++. Maybe i can wade through the VB code to figure it out =(. MS probably figured that the model and animations were so bad there was no point in doing a C++ version of it =P.

Z.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The thing that bothers me the most is THERE ARE PEOPLE OUT THERE WHO KNOW EXACTLY WHAT DO DO WITH SKINNED MESHES (and perhaps the AnimKeys, but this might be pushing my luck) but those people either
a) arn''t on this forum so can''t help us
b) ARE on this forum BUT WON''T HELP US because one day most likely they will make $$$ out of their knowledge of skinned meshes! (a game, a book, a class they''re teaching, etc.)
we need more people who are:
a) the people who work @ microsoft and wrote the "tutorial" on skinned meshes (hah, some tutorial i''d be better off reading it in some ancient heiroglyphics or something)
b) the people who understand Microsoftish (what a thought) and are willing to interpret Micro$oft''$ "code" for the free world

Just a thought.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try looking at the DX8 SkinnedMesh sample in the Direct3D folder.

It loads tiny.x, an exported biped skeletal model with animation keys (1.51 MB)

MLoad.cpp has functions to load the animation (it starts with LoadMeshHierarchy). You could just skip to LoadAnimation(Set) for an idea behind the parsing stuff.

The end result is a person going through a walking cycle.

Share this post


Link to post
Share on other sites
I''ve been (trying) reading through the SkinnedMesh SDK code some more. It seems to me that for every frame (not keyframe) the program creates a new mesh object then just "scrolls" through the mesh objects, choosing which one to display at what time. Am I right? If I am, then this really doesn''t seem efficient and I COULD just make my own thingy to load 50 meshes (one per frame) from files and "scroll" through them. Are the skinned meshes really more efficient than that?

--Mohotmoz

Share this post


Link to post
Share on other sites
quote:

The thing that bothers me the most is THERE ARE PEOPLE OUT THERE WHO KNOW EXACTLY WHAT DO DO WITH SKINNED MESHES (and perhaps the AnimKeys, but this might be pushing my luck) but those people either
a) arn''t on this forum so can''t help us
b) ARE on this forum BUT WON''T HELP US because one day most likely they will make $$$ out of their knowledge of skinned meshes! (a game, a book, a class they''re teaching, etc.)
we need more people who are:
a) the people who work @ microsoft and wrote the "tutorial" on skinned meshes (hah, some tutorial i''d be better off reading it in some ancient heiroglyphics or something)
b) the people who understand Microsoftish (what a thought) and are willing to interpret Micro$oft''$ "code" for the free world



Post your name next time, or are you afraid of something?

This is the arrogance that really bothers me sometimes. Recently we had a discussion about newbies coming in here asking for something advanced - source code and all. Well, if they got that source code, they''re too new to it to even understand what they''re doing.

If you''ve been tracking the posts on skinned meshes (of which there has been a lot), you''d notice that I''ve been posting on how it''s done. Hell no I''m not going to give away my code at this point - the code that I had to create, learning from the DX SDK sample, just like everybody else did in the world. For you to come out and demand I give it to you, especially if you don''t have the time or patience to do what I suggested and read the SDK example, is pure BS. I can imagine seeing your name pasted all over the code calling it your own the day after somebody posts it (after changing a couple lines of code)!

And for your information, I have so far written two articles on parsing X-Files, leading up to how to use skinned meshes - they just haven''t been posted yet on the article section.

And again, your arrogance saying we won''t help - you check the damn postings a lot of people have left (including myself) that help people out. Just because you aren''t getting what you want doesn''t mean you need to throw a sissy fit over it.



Jim Adams


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

Share this post


Link to post
Share on other sites
Thank you Jim =). Hopefully whoever posted that will shut up.

Now, let me know if im on the right track here. All the load code does is open an X file, and loop through, getting data (or a header?), until there isnt any left. When it gets some, it checks to see what kind it is, and recursivly loads any children, saving the data it needs into the correct members of a "Frame" or "Animation" struct, or class. Right?

Z.

Share this post


Link to post
Share on other sites
Exactly correct. Check the SDK docs for the IDirectXFile series of objects, and read the SDK example - it shows how to create the objects for use. Basically you recursively enumerate all templates, finding the ones you want, then do something with them.

Animation keys aren''t that hard, take a look:

  
AnimationSet NameOfAnimationSet {
Animation NameOfAnimation {
{ BoneNameToApplyAnimationTo }
AnimationKey {
0; // Key type (0=rotate, 1=scale, 2=position, 4=matrix)

2; // # of keys to follow

// Key format= Time, # values to follow, values

// Rotation uses Quaternions (w, x, y, z)

0; 4; 1.0, 0.0, 0.0, 0.0;;,
1000; 4; 0.157, 1.0, 0.0, 0.0;;;
}
}
}


The animation set template is a collection of animations, while an animation template defines a series of keys for a single bone. That way, you can provide a position and rotation set of keys for each bone. The animation key template holds the information for one transformation. As you''re parsing an .X file, you read the animation key templates, only storing the key values.

PS - My milkshape exporter is nearly complete (includes animation and boning information).

Jim


Share this post


Link to post
Share on other sites