denmeister
07-12-2002, 12:12 PM
Okay,
I only come for help when I'm really stumped. And this time I don't even know where to begin.
I use 3ds max 4.2 and Maya 4 Unlimited to create objects and save them in a binary X file format. No problem there. I also include animation data in the X file along with the mesh. No problem there either.
So the problem is, how do I extract the animation data out of the X file. Microsoft has an example with it's SDK but it's poorly documented and I have no idea what kind of programming methodology they were using, making it very difficult to understand the code.
Does anyone have any experience in dealing with skinned meshes? Or know of a good tutorial anywhere?
denmiester
Sfpiano
07-27-2002, 05:24 PM
'Declarations
'## MESH ##
Dim Mesh As D3DXMesh
'## TEXTURES AND MATERIALS ##
Dim MeshMaterials() As D3DMATERIAL8 ' Mesh Material data
Dim MeshTextures() As Direct3DTexture8 ' Mesh Textures
Dim nMaterials As Long 'How may materials/textures we have....
'-----------------------------------------------------
'Initialising
'-----------------------------------------------------
Private Function InitialiseGeometry() As Boolean
On Error GoTo BailOut: '//Setup our Error handler
'// Any variables required
Dim mtrlBuffer As D3DXBuffer '//Holds some useful data for us...
Dim I As Long 'Loop variable
Dim TextureFile As String 'the texture required
'// Get the data from the file
Set Mesh = D3DX.LoadMeshFromX(App.Path & "\lesson08.x", D3DXMESH_MANAGED, D3DDevice, Nothing, mtrlBuffer, nMaterials)
If Mesh Is Nothing Then GoTo BailOut: '//Dont continue if the above call did not work
'// Allocate the space required for the materials and textures used:
ReDim MeshMaterials(nMaterials) As D3DMATERIAL8
ReDim MeshTextures(nMaterials) As Direct3DTexture8
'// Now we fill our arrays with the information required
For I = 0 To nMaterials - 1
'//Get D3DX to copy the data that we loaded from the file into our structure
D3DX.BufferGetMaterial mtrlBuffer, I, MeshMaterials(I)
'//Fill in the missing gaps - the Ambient properties
MeshMaterials(I).Ambient = MeshMaterials(I).diffuse
'//get the name of the texture used for this part of the mesh
TextureFile = D3DX.BufferGetTextureName(mtrlBuffer, I)
'//Now create the texture
If TextureFile <> "" Then 'Dont try to create a texture from an empty string
Set MeshTextures(I) = D3DX.CreateTextureFromFileEx(D3DDevice, App.Path & "\" & TextureFile, 128, 128, D3DX_DEFAULT, _
0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_LINEAR, _
D3DX_FILTER_LINEAR, 0, ByVal 0, ByVal 0)
End If
Next I
InitialiseGeometry = True
Exit Function
BailOut:
Debug.Print "Error occured in InitGeometry() Code"
InitialiseGeometry = False
End Function
'--------------------------------------------
'Rendering
'--------------------------------------------
For I = 0 To nMaterials - 1
'//Setup the renderer for this part of the mesh
D3DDevice.SetMaterial MeshMaterials(I)
D3DDevice.SetTexture 0, MeshTextures(I)
'//Draw the current part of the mesh
Mesh.DrawSubset I
Next I
denmeister
08-30-2002, 09:59 AM
ok... i said Anim Sets... i didn't ask for ripped code
Squirm
08-30-2002, 06:38 PM
Ripped from DirectX4VB I might add. It comes from this tutorial: http://www.exhedra.com/DirectX4VB/Tutorials/DirectX8/GR_Lesson08.asp
ryborg
09-02-2002, 08:33 PM
Just export your keyframes as seperate X files and then interpolate the verticies. Again, http://www.directx4vb.com is your friend.
Teric
10-10-2002, 05:04 AM
Yes, each keyframe could be dumped out as a separate .x file. However, when you've got a complex model, this can take up a lot of disk space, not to mention the time and memory required to load each .x file into your program.
There has GOT to be a good way to load and use .x files with animation sequences built in. Does anybody have any good information, or should I lock myself in a room for the next week or so, trying to get my head around the skinned mesh example from the SDK?
denmeister
10-14-2002, 07:51 AM
Wow... haven't been on for a while. Yes, there is, infact, a good way to do it. But it's the hierarcial structure of x files that is so complex.
As far as exporting to seperate x files and interpolating the intermediate frames, the model i am currently using is right around 3 megs is text form, and 300kb in binary form. Using the assumption that I am using about 30 keyframes per second (making the model walk)... that comes out to around 9 megs for one complete iteration of the walk. I don't know about you, but my PC would suffer from memory withdrawls if I had to load every animation that way.
The DirectX X File specification allows for the use of bones. Instead of having predetermined keyframes, the bone is attached to verticies and the bone in animated with keyframes. The verticies are moved along with the bone. I have had very good success using no more than 8 bones. However, I have had some stunning results from using 25 or so. Allowing for perfect animation of lips and facial expressions.
I'm working on finishing up a complete ActiveX DLL written in VB that will take advantage of these types of x files. When I finish it I'll post it if anyone is interested.
Kind Regard
denmeister
KevinCoyle
08-03-2003, 05:01 PM
has anyone figured out a good way to do this yet. I'm working on my own 3d engine with vb, It's coming along pretty well so far, but I'd like to include skinned meshes of characters that animate in my engine as well. I've tried messing around with the source program that came with the sdk but the code is difficult to understand. Anyone know of any good tutorials?