Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

Can anybody help me with animating a mesh? The stupid DX9 SDK has kicked out the SkinnedMesh for VB and added none for C#.

 

Could you also tell me how I can specify to only play a specific range of frames (eg. 25 - 35)?

 

Thx.

  • 5 weeks later...
Posted

So far ..

 

all the advice ive got has been to look at the dolphin sample, which i found too hard to follow,.. if anyone could help us out with a better sample or explain animating meshes to us that would be great....

Posted (edited)

You can manually interpolate meshes, http://www.directx4vb.com shows how to animate meshes simply, I haven't started using animated X files yet, so I can only recommend a net search, http://www.gamedev.net or http://www.flipcode.com may have something, albeit probably in unmanaged C++ which most likely won't help

 

There is a structure in Direct3DX called SkinMesh, it has a FromX function and has a property returning SkinInformation and a Mesh object, the SkinInformation can be altered to animate the mesh and then you call ConvertToBlendedMesh to get a mesh with specified animation applied apparently but I've never used it so can't be sure how it works.

Edited by AndreRyan
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

Directx4vb.com was helpfull

 

But its in dx8 with vb 6, i couldnt figure out how to get the verticie data from the meshs so i could manually interpolate. Thanks very much though hopefully i can do it with the skinned mesh

Posted

ANIMATION TYPES

 

There are 2 main types of animation shown in the SDK, TWEEN used in the Dolphin and BONE HIERARCY like in the tiny.x model.

 

The standard for serious animation is to use BONE animation ... If you've never creatred a model, it works like this.

 

you create a mesh shape.

Add a outer texture UVW Map of a bitmap for example to create the clothes, face, etc.

put a skeleton inside, that has a relationship to all the other bones, usually haing the hip as the main starting point.

Then you skin the model, which is a proccess to assign which VERTICES/FACES ( little triangle faces that move when the bones do ) are associated to what bones.

 

You move the bones around over a time line creating key fame points in animation.

 

The total animation is then merged and named. Multipul animations can also be added.

 

This information is saved in the text of the \DX90SDK\Samples\C++\Direct3D\MultiAnimation\tiny_4anim.x file in the SDK.

 

Try loading it into the mesh viewer and choose between animations.

 

Creating an Instance of tiny_4anim.x is no so easy.

 

There is an Animation Controller to change between animations, a frame controller for the animation, a mesh blending index controller and a bones object to address.

Posted

ok,.. dont really understand C++ all that well,

 

IM a vb programer,.. and ive been working on tweening cause it doesnt seem so hard, big deception, i still cant find a way to extract the verticies from the meshs.. ive tried copieing the dolphin example and it doesnt work for me!

Posted
To get the verticies out, use MeshObject.LockVertexBuffer, it returns a graphicstream which you'll have to parse manually into a vertex format, I'm not sure which format it is
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

Well Tweening is getting Closer

 

Ive finnaly figured out how to get the vertex's out of the mesh now i have to put the new ones back in,... Any advice? By the Way im creating an annimated mesh class once i figure this out so ill post it here thanks for all the help so far and yet too come.

Posted (edited)

Finnally

 

Finnally have working mesh,... Heres My Class, the .anm file contains the number of keyframes and the addresses of each mesh,.....

Public Class AnimatedMesh
   Public cmesh() As CustomMesh
   Public tMesh As CustomMesh
   Public Key1 As Int16
   Public Key2 As Int16
   Public Dtime As Single
   Public Const tChange As Single = 0.05
   Public KOT As Int16
   Public KeyOrder() As Integer
   Public Structure vertexlist
       Public vertexs() As Vertex
   End Structure
   Dim vertexlists() As vertexlist
   Public Function LoadAnimatedMesh(ByVal anmFile As String, ByVal fFolder As String, ByVal device As Direct3D.Device, ByVal Texturefolder As String)
       Try
           Dim icount As Int16
           Dim icount2 As Int16
           Dim keys As Int16
           Dim stemp As String
           Dim Gs As GraphicsStream
           FileOpen(1, fFolder & anmFile, OpenMode.Input)
           Input(1, keys)
           ReDim cmesh(keys)
           ReDim vertexlists(keys)
           Do Until EOF(1)
               Input(1, stemp)
               cmesh(icount) = New CustomMesh
               vertexlists(icount) = New vertexlist
               cmesh(icount).LoadMesh(fFolder, stemp, DX9.D3DDevice, Texturefolder)
               icount += 1
           Loop
           FileClose(1)
           tMesh = cmesh(0)
           For icount = 0 To keys - 1
               ReDim vertexlists(icount).vertexs(cmesh(icount).xMesh.NumberVertices)
               Gs = cmesh(icount).xMesh.LockVertexBuffer(LockFlags.None)
               For icount2 = 0 To cmesh(icount).xMesh.NumberVertices - 1
                   vertexlists(icount).vertexs(icount2).p.X = Gs.Read(GetType(Single))
                   vertexlists(icount).vertexs(icount2).p.Y = Gs.Read(GetType(Single))
                   vertexlists(icount).vertexs(icount2).p.Z = Gs.Read(GetType(Single))
                   vertexlists(icount).vertexs(icount2).n.X = Gs.Read(GetType(Single))
                   vertexlists(icount).vertexs(icount2).n.Y = Gs.Read(GetType(Single))
                   vertexlists(icount).vertexs(icount2).n.Z = Gs.Read(GetType(Single))
                   vertexlists(icount).vertexs(icount2).tu = Gs.Read(GetType(Single))
                   vertexlists(icount).vertexs(icount2).tv = Gs.Read(GetType(Single))
               Next
               cmesh(icount).xMesh.UnlockVertexBuffer()
               Key2 = 1
           Next
       Catch ex As Exception
           Debug.WriteLine("Load Annimated Mesh:" & ex.ToString)
           ExitGame()
       End Try
   End Function
   Public Function DrawAnimatedMesh(ByVal automatic As Boolean, ByVal d3ddevice As Direct3D.Device)
       Dim icount As Int16
       Try
           If automatic Then
               Dtime += tChange
               If Dtime > 1 Then
                   Dtime = tChange
                   KOT += 1
                   If KOT >= KeyOrder.Length Then
                       KOT = 0
                   End If
                   Key1 = Key2
                   Key2 = KeyOrder(KOT)
               End If
           End If
           Dim gs As GraphicsStream
           gs = tMesh.xMesh.LockVertexBuffer(LockFlags.None)
           With vertexlists(Key2)
               For icount = 0 To vertexlists(0).vertexs.Length - 2
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).p.X, .vertexs(icount).p.X, Dtime)))
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).p.Y, .vertexs(icount).p.Y, Dtime)))
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).p.Z, .vertexs(icount).p.Z, Dtime)))
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).n.X, .vertexs(icount).n.X, Dtime)))
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).n.Y, .vertexs(icount).n.Y, Dtime)))
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).n.Z, .vertexs(icount).n.Z, Dtime)))
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).tu, .vertexs(icount).tu, Dtime)))
                   gs.Write((lerp(vertexlists(Key1).vertexs(icount).tv, .vertexs(icount).tv, Dtime)))
               Next
           End With
           tMesh.xMesh.UnlockVertexBuffer()
           tMesh.DrawMesh(DX9.D3DDevice)
       Catch ex As Exception
           Debug.WriteLine(Key1 & " " & Key2 & " " & Dtime & " " & icount & "/" & vertexlists(0).vertexs.Length - 1)
           Debug.WriteLine("Draw Animated Mesh:" & ex.ToString)
           ExitGame()
       End Try
   End Function
   Public Function lerp(ByVal n1 As Single, ByVal n2 As Single, ByVal time As Single) As Single
       Return ((n2 - n1) * time) + n1
   End Function
End Class

Thank you all for the Help you have given me i hope this code helps some of you,...

Edited by rifter1818

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...