Skip to main content
GameDev.net gamedev.net
🔒 Locked

Working with the DirectX .X File Format and Animation in DirectX 9.0

Started by Myopic Rhino Mar 30, 2004 at 5:08 PM 47 replies 25.6k views
dirtbag
dirtbag
Hey Jason,nice article

Just 1 quick question though...
(Copied from my previous post about it)





Is there a certain way in creating animation-set''s in a package
like 3D Studio Max,for the .X Format,or does the direct x exporter(depending on which one)handle seperating them automatically.

E.G,you have a character in 3DStudio that has 130 frames of animation.

0-29 has an idle anim,30-59 has a walk...run etc.

How do you actually seperate them,into something like set1: idle
set2: walk set3: run set4:die etc etc??

Is it animation package specific or DirectX exporter specific?




DirectXXX Member since: 9/24/2002 From: Pakistan
Posted - 1 April 2004 10:37:13 AM
directx supports animation set if you are a programmer you have to modify example exporter of max to save .x animation sets. But if you are not a programmer just save individual .x files of each set and use MeshView utility that comes with DXSDK to combine them into 1 .x file.



dirtbag Member since: 3/30/2004 From:
Posted - 1 April 2004 11:16:33 AM
What i really want to have is several anim sets in only 1 file.
Btw,i''m a programmer

Iv''e actually just read the new article on the .X format(here on the news page).If i''m unsuccessful in this thread,i''ll post there.

So,i gather the (easiest)solution would be to say..animate an idle animation,then export to .x format.Animate my other sets,exporting as seperate files.
Then finally,open then up,and copy and paste the sets from all the differnt files,into 1 .xfile.

Yes? No?





dirtbag Member since: 3/30/2004 From:
Posted - 1 April 2004 11:26:44 AM
One more thing..
Iv''e opened an .xfile with notepad.
which sections need to be copy + pasted to the 1 file?

The section at the bottom after:
}
and at the start of the word..
AnimationSet{

etc...etc..
}

end of the file?



Appreciate your help jason.

Why would anyone in a right state of mind attempt to get blood out of a stone?? don''t they know its made of stone..doh.
__Daedalus__
__Daedalus__
If you look within an X file that has animations (e.g tiny.x) you''ll see that there are templates called "AnimationSet" amongst all the others. They take the form of

AnimationSet {
.
.
Data and sub-templates etc
.
.
}

An "AnimationSet" encapsulates any one animation. There are typically many "Animation" templates within an "AnimationSet" - as many "Animation" templates as there are bones in your model. If you export to text format you can easily give the single animation a name like this

AnimationSet WalkAnim {
.
.
Data and sub-templates etc
.
.
}

which you can reference in your game engine (or see in the MeshView utility). So essentially and to answer you question, you can export your animations from MAX one at a time in to individual X files. With the model being the same you can just copy the entire AnimationSet templates from each X file and paste them one after the other in a single file. Just give each AnimationSet a unique name.




jasonjurecka
jasonjurecka
Sorry about the late reply.


the exporter that I used just used the Maya time scale to deside what is an animation set.

If I wanted to put multiple animations into one model I would have to export out the seperate animation data and then copy/paste it into the model.

I know this is kinda getto but I did not write the exporter. the models that I used in the article are included in the MS SDK examples if you would like to take a look at them.

I hope this answers your question. if not feel free to email me.

___________________________

Jason Jurecka
www.jurecka.us
jason@jurecka.us
www.tsbgames.com

"Everything is a game."

[edited by - jasonjurecka on April 4, 2004 5:42:59 AM]
_________Jason Jureckawww.jurecka.usjason@jurecka.uswww.tsbgames.com"Everything is a game."
Roquqkie
Roquqkie
Hi Jason

Thanks for a great article...!

I''ve implemented the code into my own project, but if I use lighting the model is all black!?

Do you have any idea what to do?

Best regards
Roquqkie
mikkel.hempel@tele2adsl.dk
Trip99
Trip99
You can load models with different animation sets into the MeshView utility (comes with SDK) and combine them together into one .x file
------------------------See my games programming site at: www.toymaker.info
jasonjurecka
jasonjurecka
it is good to hear people are using it.

The model is black because the model does not have vert normals.

there is an DX9 SDK example which goes through adding them in. I dont remember off hand which one it was but i do remember that the test app had a skull for the .x file that was used. If you have the sdk look at the sample browser.





___________________________

Jason Jurecka
www.jurecka.us
jason@jurecka.us
www.tsbgames.com

"Everything is a game."

[edited by - jasonjurecka on April 6, 2004 5:15:24 PM]
_________Jason Jureckawww.jurecka.usjason@jurecka.uswww.tsbgames.com"Everything is a game."
Roquqkie
Roquqkie
Hi Jason

Yes I kindda figured that out, so I computed its normals using the DX Mesh viewer, which is included in the SDK-tools.
In the mesh-viewer I can see it with lighting...
But! It's still black! :|

Best regards
Roquqkie

[edited by - Roquqkie on April 7, 2004 8:45:05 AM]
jasonjurecka
jasonjurecka
Ok well check and make sure you have the texture in the right directory.

In the tutorial the texture that is used is assumed to be local to the location of the .x file.



___________________________

Jason Jurecka
www.jurecka.us
jason@jurecka.us
www.tsbgames.com

"Everything is a game."
_________Jason Jureckawww.jurecka.usjason@jurecka.uswww.tsbgames.com"Everything is a game."
Roquqkie
Roquqkie
The texture is working... When I turn off lighting I can see the texture...

Best regards
Roquqkie
jasonjurecka
jasonjurecka
Make sure the light is being inited or setup.

___________________________

Jason Jurecka
www.jurecka.us
jason@jurecka.us
www.tsbgames.com

"Everything is a game."
_________Jason Jureckawww.jurecka.usjason@jurecka.uswww.tsbgames.com"Everything is a game."
jasonjurecka
jasonjurecka
for all of you that are haveing these errors:

C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CModel.cpp(45) : error C2259: 'CAllocateHierarchy' : cannot instantiate abstract class due to following members:
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CAllocateHierarchy.h(24) : see declaration of 'CAllocateHierarchy'
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CModel.cpp(45) : warning C4259: 'long __stdcall ID3DXAllocateHierarchy::CreateMeshContainer(const char *,const struct _D3DXMESHDATA *,const struct _D3DXMATERIAL *,const struct _D3DXEFFECTINS
TANCE *,unsigned long,const unsigned long *,struct ID3DXSkinInfo *,struct _D3DXMESHCONTAINER ** )' : pure virtual function was not defined
C:\DX90SDK\INCLUDE\d3dx9anim.h(168) : see declaration of 'CreateMeshContainer'
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CModel.cpp(45) : error C2259: 'CAllocateHierarchy' : cannot instantiate abstract class due to following members:
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CAllocateHierarchy.h(24) : see declaration of 'CAllocateHierarchy'
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CModel.cpp(45) : warning C4259: 'long __stdcall ID3DXAllocateHierarchy::CreateMeshContainer(const char *,const struct _D3DXMESHDATA *,const struct _D3DXMATERIAL *,const struct _D3DXEFFECTINS
TANCE *,unsigned long,const unsigned long *,struct ID3DXSkinInfo *,struct _D3DXMESHCONTAINER ** )' : pure virtual function was not defined
C:\DX90SDK\INCLUDE\d3dx9anim.h(168) : see declaration of 'CreateMeshContainer'
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CModel.cpp(64) : error C2259: 'CAllocateHierarchy' : cannot instantiate abstract class due to following members:
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CAllocateHierarchy.h(24) : see declaration of 'CAllocateHierarchy'
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CModel.cpp(64) : warning C4259: 'long __stdcall ID3DXAllocateHierarchy::CreateMeshContainer(const char *,const struct _D3DXMESHDATA *,const struct _D3DXMATERIAL *,const struct _D3DXEFFECTINS
TANCE *,unsigned long,const unsigned long *,struct ID3DXSkinInfo *,struct _D3DXMESHCONTAINER ** )' : pure virtual function was not defined
C:\DX90SDK\INCLUDE\d3dx9anim.h(168) : see declaration of 'CreateMeshContainer'
C:\Documents and Settings\Stu\Desktop\TestApp-2079\TestApp\CModel.cpp(227) : error C2039: 'SetTime' : is not a member of 'ID3DXAnimationController'
C:\DX90SDK\INCLUDE\d3dx9anim.h(671) : see declaration of 'ID3DXAnimationController'
Error executing cl.exe.

TestApp.exe - 4 error(s), 3 warning(s)


You have DX9.0 with the summer update right?

Those errors are caused by you having the summer update for DX9.

open the file d3dx9anim.h
search the file for "ID3DXAnimationController"
when you find the actual interface there will be added parameters to the
CreateMeshContainer function.

just add them in and the code will compile.

you need not change anything else in the code but the function header and
definition.

there is no functionallity that is changed in the app.

___________________________

Jason Jurecka
www.jurecka.us
jason@jurecka.us
www.tsbgames.com

"Everything is a game."

[edited by - jasonjurecka on May 5, 2004 7:39:03 PM]
_________Jason Jureckawww.jurecka.usjason@jurecka.uswww.tsbgames.com"Everything is a game."
Uriel
Uriel
Hm.. I get those errors:


error C2039: 'SetTime' : is not a member of 'ID3DXAnimationController'

error C2259: 'CAllocateHierarchy' : cannot instantiate abstract class

error C2259: 'CAllocateHierarchy' : cannot instantiate abstract class


I have summer update, thats true.


But could you name those functions i have to overload in 'ID3DXAnimationController'. Before i found your post here i was looking for not overloaded funcs in ID3DXAllocateHierarchy, since that is the class from CAllocateHierarchy is derrived?

Its rainy today and im sleepy (out of coffee) but no functions from 'ID3DXAnimationController' are overloaded in this sample and there are over 20 of them.

All funcs from ID3DXAllocateHierarchy are overloaded properly.

Also there is no such func like SetTime(..) in ID3DXAnimationController. It seems that SetTime was made obsolete by AdvanceTime... but i may be wrong.

[edited by - Uriel on April 25, 2004 11:18:44 AM]
Uriel
Uriel
STDMETHOD(CreateMeshContainer)(THIS_
LPCSTR Name,
CONST D3DXMESHDATA *pMeshData,
CONST D3DXMATERIAL *pMaterials,
CONST D3DXEFFECTINSTANCE *pEffectInstances,
DWORD NumMaterials,
CONST DWORD *pAdjacency,
LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER *ppNewMeshContainer);


This was the only func that needed to be overloaded.
Uriel
Uriel
Ok, i made animations work with my resources managers.

The problem is: i have the same problem as Roquqkie.
When i turn on lights - ambient to be precise, all meshes turn black. I switch lights off - i see textures. Normals are OK, because 5 h ago my game was running nice with same meshes, lights and textures on. I experimented with materials, but even when i use tiny.x from sample as reference model, she is black without textures.

Any help?
jasonjurecka
jasonjurecka
Make sure that the light is not inside the model.

if it is inside the model then there would be no light on the outside for it to use so the model is black.



___________________________

Jason Jurecka
www.jurecka.us
jason@jurecka.us
www.tsbgames.com

"Everything is a game."
_________Jason Jureckawww.jurecka.usjason@jurecka.uswww.tsbgames.com"Everything is a game."
Uriel
Uriel
Well, im using only ambient light so its not important where it is located.
This code and meshes worked perfectly with lights , until i implemented animations. Then all went black. I suspect problem with materials, but that doesnt explain why tiny.x also renders black.

Edit:

Of course it was just stupid mistake - TextureStage was leaved in incorrect state by particle manager.
It became problem when i stopped using standard LPD3DXMESH and its DrawSubset.

"Clean After Yourself, Fool!"
*smacks himself with hammer*

Sorry for bothering you, and nice tutorial ;-)

[edited by - Uriel on April 26, 2004 3:39:41 PM]
Zawinul
Zawinul
Nice job on this tutorial/sample, very nice layout and clean design.

Altho I see the problem people are having.. you''re creating the array of materials and not populating it. You''re only populating the textures themselves. You need to set each material9 entry to "Materials.MatD3D" (the actual material inside the d3dxmaterial structure.) You can do that right in the same loop you''re loading textures.

-Z

- Zawinul
jasonjurecka
jasonjurecka
Well thank you i am just happy that people are finding it useful.

i think the materials are mem copied in there somewhere.

___________________________

Jason Jurecka
www.jurecka.us
jason@jurecka.us
www.tsbgames.com

"Everything is a game."

[edited by - JasonJurecka on May 20, 2004 5:11:53 PM]
_________Jason Jureckawww.jurecka.usjason@jurecka.uswww.tsbgames.com"Everything is a game."
commy2005
commy2005
I updated to the december 2004 version of SDK.

I followed the instructions went to the d3dx9anim.h but can't find any CreateMeshContainer function in the D3DXAnimationController,did I follow the wrong step or something was wrong?

I can't fix the compilation error,althought I checked everything is overloaded properly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.