Manually Drawing a D3D Mesh

I'm having some trouble trying to render straight from the resources of the D3D Mesh object...for example


[code]
' myMesh is an instance of Direct3D.Mesh using the Direct3D.Mesh.Sphere
' for creating and initializing the mesh
' d3ddev is a valid instance of a direct3d device
' vertex stride size is the size of the vertex, its a positioned normal
'textured vertex type.

' the world translation has already been setup, lighting is good too.

d3ddev.Indices = myMesh.IndexBuffer
d3ddev.SetStreamSource(0, myMesh.VertexBuffer, 0, VertexStrideSize)

' draw normal
d3ddev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, myMesh.NumberFaces)

' draw it indexed
d3ddev.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, myMesh.NumberVertices, 0, myMesh.NumberFaces)

' draw it through mesh
myMesh.drawSubset(0)

[/code]

When drawing using a method other than the drawSubset method, nothing shows up on the screen whatsoever. I need a way to properly render the mesh manually, so i can setup the vertex/index buffer streams to test out some key frame animation(Q2 MDS style) using the mesh data.

ie, I load in a couple of static meshes into Mesh object classes, and im gonna blend them together.



Answer this question

Manually Drawing a D3D Mesh

  • Paul Dettorre

    AFAIK a D3DX Mesh is always defined as an indexed triangle list, so you should be using the DrawIndexedPrimitives method, but with PrimitiveType.TriangleList as the first parameter.

    This will only work for meshes with one single subset though. Most meshes consist of multiple subsets and you'll have to use the Mesh's attribute table to specify the range of vertices and indices to use when rendering the subsets. Here's a C# project that shows how this can be done. We don't have a simpler sample showing this yet, but as it deals with morphing it should be interesting for your tweening as well.



  • Manually Drawing a D3D Mesh