Archived

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

yanuart

Milkshape & X. files

Recommended Posts

yanuart    162
Has anybody uses milkshape to make an animation based on skinnedmesh and export it to an x files ?? If u do, can u tell me about the hierarchy of the animations template (in x files) that it creates. I''m having trouble understanding and load the animation from it.. And most of all how to use it !!!! DirectX sample doesn''t seem to have good documentation on this subject (how animations works)

Share this post


Link to post
Share on other sites
FantasyGuy    122
I don''t know anything about the milkshape you''re talking about. But I know how skinnedmesh works. Actually, the sample that comes with D3D has no documentation at all. I can''t explain everything here but I''ll give you a quick hint. Skinned meshes are based on vertex blending. You can refer to DX documentation for the details of vertex blending. With vertex blending, each vertex is influenced by 4 bones (frames) as maximum. The mesh is loaded with the D3DXLoadSkinMeshFromXof. The skin mesh consists of bone combinations, each bone combination has 4 references to bones (frames) that affect that bone combination. The bone combination also has a reference to the material. So, what you need to do is to load the frames hierarchy, load the mesh and then link each bone combination of that mesh to the specified frame in the hierarchy according to the names (string) supplied with those frames. After you load the mesh, you generate a blended mesh from it using the ConvertToBlendedMesh member function of ID3DXSkinMesh. When you render, you loop over the bone combination and with each combination, you set the transformation matrices using the D3DTS_WORLDMATRIX(n) macro, set the material and then render. Animation is done by changing the transformation matrix of each bone. Each bone has a set of animation keys that specifies how the transformation is changed over time. The animation is not complex at all but you need first to understand the structure of skinned meshes. I prefer that you go and take a look at the SkinnedMesh sample that comes with D3D. I''ve already read that sample so if you have any question about it, just ask.

Share this post


Link to post
Share on other sites
yanuart    162
DO you know how the x files of the skinnedmeshes sample was build ? (I mean what kind of animation tools and exporter it used to create it ??)

Share this post


Link to post
Share on other sites
kmsixpence    134
As far as i know, there isn''t an animation program for xfiles. Maybe there is but with skinned mesh you do all of the animation yourself. If you want to move the head up, i don''t think there''s a program that will program that in. You will probobly have to move the bone

Share this post


Link to post
Share on other sites
FantasyGuy    122
Of course there is a program. How about using 3D Max? You can find a plugin that exports 3D Max meshes to x files. This plugin comes with the DX8 SDK. You can also download it from www.microsoft.com. I have tried this plugin with 3D Max and Character Studio and it worked.

Share this post


Link to post
Share on other sites
yanuart    162
Great !!!
I''ve been using the same programs also (MAX n the exporter from SDK), but can somebody tell me how to understand the animation data from the x file that it made ??
I''m having trouble understand about how the animation key templates works and the data that it brings (time n bones)
thx

ps : FantasyGuy, you''ve been a great help !!! thanks a lot

Share this post


Link to post
Share on other sites
yanuart    162
Sorry to bother u again FantasyGuy, I hope u have enough patience to answer my stoopid questions
Well, I want to know what kind of informations needed to construct a skinned mesh. I look the code from the SDK but I can''t understand it completely, so may be u can fill in the blanks..
So here they are
// Skin info
D3DXATTRIBUTERANGE *m_pAttrTable;
D3DXMATRIX** m_pBoneMatrix;
LPD3DXBUFFER m_pBoneNamesBuf;
LPD3DXBUFFER m_pBoneOffsetBuf;
D3DXMATRIX* m_pBoneOffsetMat;
DWORD* m_rgiAdjacency;
DWORD m_numBoneComb;
DWORD m_maxFaceInfl;
LPD3DXBUFFER m_pBoneCombinationBuf;
METHOD m_Method;
DWORD m_paletteSize;
BOOL m_bUseSW;
these struct is taken form the code btw..
so any explanations will be great as I myself still trying to figure it out ...

Share this post


Link to post
Share on other sites
FantasyGuy    122
As you know, skinned meshes consists of bones (or frames). Each frame has a transformation matrix as you know. The animation keys deal with the transformation matrix of these frames. Because the skinned mesh is connected to the frames, as soon as you change the transformation matrix of the frame, the skinned mesh will animate accordingly.
Animation keys deals with frames, hence, it''s not limited to skinned meshes. Even if the x file contains normal meshes instead of skinned meshes, the animation keys will work on these meshes. Each Animation template contains one reference to a frame which is the frame to be animated. From this reference you can get the frame data and then extract the frame name from this data. After getting the name, you should search your loaded frame hierarchy for a frame with the same name. After you get a pointer to the specified frame, you can store it to be used later by this animation key. The Animation template contains also one or more AnimationKey templates. Each animation key contains values for the transformation along with the relative time. The way these values are stored are specified in the documentation of DX in the section ''X File Templates''. For example, if we have a matrix animation key with 5 matrices at times, say, 100, 200, 300, 400, and 500. Then, at time 100, we should set the first matrix as the transformation matrix of the frame, at time 200 we set the second and so on.

Share this post


Link to post
Share on other sites
FantasyGuy    122
I''ll give you a quick explanation of the variables you mentioned.

m_pAttrTable: The attribute table, it''s actually neglected. I don''t know why did they put it. I removed it and the program continued to work fine.

m_pBoneMatrix: An array of pointers to the frames'' transformation matrices used by this skinned mesh.

m_pBoneNamesBuf: This is where the bone names are stored. This is used at initialization to construct m_pBoneMatrix.

m_pBoneOffsetBuf: This buffer contains the offset matrix. The offset matrix transforms the coordinates into the bone''s local coordinates. It should be multiplied by the bone matrix before being set as the world transformation matrix.

m_pBoneOffsetMat: This is the offset matrices extracted from m_pBoneOffsetBuf.

m_rgiAdjacency: Buffer containing the index of the adjacent polygons of each polygon. It''s needed by the GenerateSkinnedMesh function, which is in turn needed to generate a mesh from which the count of attributes used by this mesh is obtained. This is used only in software vertex blending in which the program generate a blended mesh at each frame.

m_numBoneComb: Number of bone combinations. Bone combinations table specifies which part of the mesh is to be drawn with which materials and to be transformed by which matrices. The render code loops on this table to draw the whole mesh.

m_maxFaceInfl: Specifies the maximum number of bones that influnces part of the mesh. This is used to check whether the hardware can support the number of influnces of this mesh. In case the hardware cannot support the whole mesh, the program splits the mesh into a hardware part and a software part.

m_pBoneCombinationBuf: The buffer that contains the bone combinations. Actually, this is the core of the skinned mesh functionality. The render function loops on every element in this mesh and set the world matrices (bone matrices) and the material and then call the DrawSubset function.

m_Method: The method of vertex blending. The sample enables the user to choose the method of vertex blending from the menu. It''s simply reflected here.

m_paletteSize & m_bUseSW: I don''t know. I Haven''t seen them before.

Share this post


Link to post
Share on other sites
GenericBum    122
BTW. I know there are 2 different exporters for Milkshape that generate X files. I wrote one, and John Thompson wrote the other. You can find Milkshape at:

http://www.swissquake.ch/chumbalum-soft/

Thanks
Generic Bum

Share this post


Link to post
Share on other sites
yanuart    162
Ok, I''ve had enough !!!!
I''ve spent hours reading samples from the net and documentation but still can''t figure it out how it works ..
I mean.. there''s got to be a better ways to learn about this Direct3D right ?? I mean the guy who made the skinnedmesh sample must learn it somewhere n somehow right ?? I just can''t figure it out by myself man... it''s too muchh...
well enough about my sad life..
back to the bussiness
as u can see in the sample code,
the m_pBoneCombinationsBuf and m_pMesh from the structure SmeshContainer was never been set to any value while the program perform the loading of an xfile, yet those 2 variables are very important while coverting to an blendmesh.
I''ve tried to trace and debug by myself and made a code based on that sample, try to fill in those two variables, yet the result is .. of course.. an exception handling aka illegal op. ehheheh
Can somebdoy who have experienced the same thing know the answer ??

ps : thanks FantasyGuy.. having someone who willing to help me really keep my spirit hangin as i struggle
One day when this is over i want to make a page dedicated to d3d an skinnedmesh (not those lame lack of info kinda page) ...lol

Share this post


Link to post
Share on other sites
yanuart    162
What this vertex shader got to do with the code ???
btw, I''m posting a new question for this subject so that anybody can discuss it freely..

Share this post


Link to post
Share on other sites
-=Code=-    122
I exported my model from 3ds max 3.1 with boned animation and not the biped from character studio or any other related plugins. Too poor to buy it.

Anyways, the mesh loads but there is no animation, am I missing something?

Forgot to mention what it loads in...

The sample that comes along with the SDK that loads tiny.


Edited by - -=Code=- on December 21, 2001 1:58:32 AM

Share this post


Link to post
Share on other sites
yanuart    162
You might want to check out the exporter plug in that microsoft provided.. it''s for MAX 3-4 (i guess), I''ve tried it before and I guess it worked just fine.. i mean all of the animation was there

Share this post


Link to post
Share on other sites
FantasyGuy    122
yanuart, the variables m_pMesh and m_pBoneCombinationBuf are being set in the function CMyD3DApplication::GenerateMesh by the call to ID3DXSkinMesh::ConvertToBlendedMesh or ID3DXSkinMesh::ConvertToIndexedBlendedMesh

Share this post


Link to post
Share on other sites
FantasyGuy    122
-=Code=-, I had the same problem as yours with 3D Max. What''s happening actually is that the bones are not connected to the mesh. The bones are actually animating but they''re hidden as you know. I''m not good in 3D Max but I have a friend who is good in 3D Max. It seems that 3D Max is storing the bones as seperate objects from the mesh and it uses something called ''Modifier'' to connect the mesh to the bones. There are many kinds of modifiers as you might know. After reading the x exporter''s documentation, we figured out that the exporter has problems dealing with any modifier other than the so called ''Physique''. We then tried a sample built with ''Physique'' (The sample was in Character Studio) and it worked fine. What I''m not sure of yet is that whether the Physique modifier is specific to character studio or it can be used seperately.

Share this post


Link to post
Share on other sites
yanuart    162
hmm.. ok now i''ve succeded in loading a skinnedmesh and drawing it ( i hope so)
now i want to test if it works, i''ve tried to do a transformation on some bones, but they don''t work (the scene remain the same).
well, I''ve tried using the step-by-step instruction from the sample code,
Can you tell me which variable should i manipulate to make the bones rotate ?
is it the m_pBoneMatrix or the m_pboneoffsetmat (this name taken from the smeshcontainer structure in the sample code). I assume the bones transformation data is in m_pbonematrix ??

Share this post


Link to post
Share on other sites
FantasyGuy    122
No, you should change neither of these two variables. m_pBoneOffsetMat is fixed and should not be changed. Changing it will no doubt screw up your mesh.
m_pBoneMatrix is the bone transformation matrix but this is just a pointer to the real matrix which is SMesh::matCombined. However, even if you change SMesh::matCombined it won''t work because matCombined is being calculted on each frame. matCombined is calculated from SMesh::matRot which is the one you should change in order to rotate your bone.
The reason for calculating matCombined on each frame is that the bones are structured in a hierarchy in which a bone might be a child of another. This means that the transformation matrix of each bone transforms coordinates from the bone''s parent coordinate instead of transforming it from the world''s coordinate. Hence, you''ll need to multiply the transformation matrix of the bone by the transformation matrices of all its parents until you reach the root bone in order to get a transformation matrix that transforms from the world''s coordinates to the bone''s local coordinates. This is done by multiplying matRot by the PARENT''s matCombined and put the result in matCombined. The code for what I''ve mentioned is placed in CMyD3DApplication::UpdateFrames (don''t care for matTrans, it''s set to identity).

Share this post


Link to post
Share on other sites
yanuart    162
My mesh won''t blend .. that''s irritating..
why ?? I''ve succeeded in loading the skinmesh and draw them, but when i tried to animate the bone.. sure it move but the result is it rendered separately or deformed ..
Do I need to set up a vertex shader to do this ??
I know the sample code use it but I dunno what for ??

Share this post


Link to post
Share on other sites
FantasyGuy    122
No, you don''t need to set a vertex shader, ID3DXMesh is doing it internally. Is the SkinnedMesh sample that comes with the SDK working fine? If so, why don''t you compare your code with the sample in order to find out what''s missing in your code. You can check the SFrame::SetTime function to know how are they animating the bones.

Share this post


Link to post
Share on other sites
yanuart    162
Is it true that I can''t use D3DTS_WORLDTRANSFORM to rotate the entire scene if i use vertex blending ??
What can I use to rotate my world ??

Share this post


Link to post
Share on other sites
yanuart    162
Sorry to ask , but what does this boneoffsetmatrix contains ??
I know u have to setransfrom the bonesmat (taken from the frametransformmatrix templates) and multiply it using the the boneoffsetmatrix.
I''ve done the code and try to make an x file from the exporter, but all of them are deformed. It seems that my code is doing OK, I just worried that the data which is the one that makes things screwed up.
How can I tested my x files ??

Share this post


Link to post
Share on other sites
FantasyGuy    122
Good question. The boneoffsetmatrix transforms the vertices from the space of the mesh to the space of the bone. This is needed because the vertices are stored with coordinates relative to the origin of the mesh instead of the bone, i.e. if you neglect the bones and render the skinned mesh as a normal mesh, it''ll be rendered in its original shape not affected by the bones and also not deformed. So, if you want to animate it according to the bones, you''ll need to transform the vertices from the mesh space to the bone space, and then change them back from the bone space to the mesh space but with new orientation for the bones.
I''m not sure which is responsible for screwing up your mesh. Why don''t you try another mesh. The one that comes with the SDK is working fine (tiny.x), why don''t you test your code with it?

Share this post


Link to post
Share on other sites
yanuart    162
Thanks FantasyGuy, after a couple of weeks of direct3d skinnedmesh crash course, now I''m able to do a skinmesh animation..
Now there''s one thing that I''ve to learn.. it''s about how to make your world for ur game.. hehehhee

I guess I owe u for your patient answering my stupid questions..
HEPPYY NEW YEAR !!!

Share this post


Link to post
Share on other sites