[ODE] Help using ODE with DirectX

Pancini, Ettore epancini at ferrari.it
Thu Aug 26 15:40:18 MST 2004


it's VB6 and it has italian comments. nonethless it works and it's exactly what i think you need... 


'crea un trimesh in ode a partire da una directx mesh
Public Sub mPhysics_TrimeshFromMesh(mesh As D3DXMesh)

   Dim vb As Direct3DVertexBuffer8
   Dim ib As Direct3DIndexBuffer8
   
   Dim verts() As typeCUSTOMVERTEX_UNLITTEXTURED
   Dim indxs() As Integer

   Dim count As Long
   Dim Size As Long
   Dim i As Long
   
   Dim odeVertices() As Single
   Dim odeIndices() As Long
   
   'prende vertex e index buffer dal mesh
   Set vb = mesh.GetVertexBuffer()
   Set ib = mesh.GetIndexBuffer()

   'determina numero e dimensione dei vertici
   Size = g_oD3DX.GetFVFVertexSize(mesh.GetFVF())
   count = mesh.GetNumVertices()

   'verifica il vertex format
   If mesh.GetFVF() <> CUSTOMFVF_UNLITTEXTURED Then
      'fvf non supportato
      Debug.Assert False
   End If
   
   'carica il vb
   ReDim Preserve verts(count)
   D3DVertexBuffer8GetData vb, 0, Size * count, 0, verts(0)
   
   'scorre il vertexbuffer e crea un array di elementi
   ReDim odeVertices((count * 3) - 1)
   For i = 0 To count - 1
      odeVertices(i * 3 + 0) = verts(i).v.x
      odeVertices(i * 3 + 1) = verts(i).v.y
      odeVertices(i * 3 + 2) = verts(i).v.z
   Next i
   
   
   'determina numero e dimensione degli indici
   Dim ib_desc As D3DINDEXBUFFER_DESC
   Call ib.GetDesc(ib_desc)
   
   'verifica il formato dell'index buffer
   If ib_desc.Format <> D3DFMT_INDEX16 Then
      'index non supportato
      Debug.Assert False
      Stop
   End If
   
   Debug.Print "num indici: " & mesh.GetNumFaces * 3
      
   'carica indexbuffer
   count = (ib_desc.Size / 2) 'visto che size è in byte, e l'indice è 2 byte...
   ReDim Preserve indxs(count)
   D3DIndexBuffer8GetData ib, 0, ib_desc.Size, 0, indxs(0)
   
   'scorre l'index buffer e copia i dati nell'array per ode
   ReDim odeIndices(count - 1)
   For i = 0 To count - 1
      odeIndices(i) = indxs(i)
   Next
   
   
   'finalmente genera il trimesh in ODE
   LandscapeSetVertices odeVertices(0), UBound(odeVertices) + 1
   LandscapeSetIndices odeIndices(0), UBound(odeIndices) + 1
   LandscapeCreateTrimesh
   
End Sub





-----Original Message-----
From: ode-bounces at q12.org [mailto:ode-bounces at q12.org]On Behalf Of
Duncan Frostick
Sent: mercoledì 25 agosto 2004 01:18
To: ode at q12.org
Subject: [ODE] Help using ODE with DirectX


Hi all, I'm trying to take meshes in directx format and add them to ODE 
as trimeshes. The winding order has to be reversed, but that's trivial, 
I'm having trouble copying the data in the vertex and index buffers of 
the direct3d mesh and placing them into an ODE trimesh. To avoid a 
lengthy explaination of my code and pointlessly complex question - my 
question is simple, how did you transfer the vertex and index 
information which is in direct3d FVF format from the mesh and into ODE? 
I'm hoping there's someone on this list that has used DirectX and ODE 
together before!

Cheers, Duncan

P.s. I had a look at Si Browns buggy test code as advised by the wiki, 
but I couldn't see anything that would help me - I'm really bad at 
interpreting other peoples software designs, especially when learning 
this all for new.
_______________________________________________
ODE mailing list
ODE at q12.org
http://q12.org/mailman/listinfo/ode



More information about the ODE mailing list