[Resolved][MDX]Small problem, updating vertexbuffer of a mesh created by Mesh.Sphere

This topic is 4254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey everyone, I've got one small problem with the D3DX mesh class. I usually use my own mesh formats, but for the occlusion culling of lights, I am using meshes. My code is
    Public CullMesh As Direct3D.Mesh
CullMesh = Mesh.Sphere(D3DDevice, cLightRadius, 32, 32)

Dim ranks(0) As Integer
ranks(0) = CullMesh.NumberVertices

Dim arr() As CustomVertex.PositionColored = CullMesh.VertexBuffer.Lock(0, GetType(CustomVertex.PositionColored), LockFlags.None, ranks)

Dim I As Integer = 0
For I = 0 To CullMesh.NumberVertices - 1
Dim cV As CustomVertex.PositionColored = arr(I)
cV.Color = Color.Red.ToArgb
arr(I) = cV
Next

CullMesh.VertexBuffer.Unlock()


If I change any parameter of cV, the mesh messes up (vertices dissappear, etc) and yet the color does still not change. If I do not change any parameter of cV, the mesh is unlocked with the same data it originally had. I'm fairly sure I'm missing something small here. Any ideas? Thanks. :) [Edited by - CadeF on May 30, 2006 4:16:35 AM]

Share on other sites

It looks like you're trying to lock the vertex buffer with a flag of "LockFlags.None"

According to the documentation this means "use no locks." Although I'm not as familiar with MDX, with regular DirectX you would typically use the D3DLOCK_DISCARD flag, which maps to the LockFlags.Discard managed enumeration. Of course, this flag can only be used with buffers created with the "Dynamic" flag.

Try this call instead, and see how it works:

Dim arr() As CustomVertex.PositionColored = CullMesh.VertexBuffer.Lock(0, GetType(CustomVertex.PositionColored), LockFlags.Discard, ranks)

Also, you shouldnt need to call SetData, as that "locks" the vertex buffer, but you've already got it locked with the call to "Lock"...If you want to use SetData, then remove the initial lock.

Cheers!

Share on other sites
Thanks, tried that. Changed creation to dynamic, locking flag to discard and removed the unlock flag. But I still have the same problem.

Share on other sites
If I recall correctly, the meshes returned from Mesh.Sphere() and other Mesh creation methods don't use the PositionColored vertexformat. I believe they use PositionColoredTextured, but you can check out the Mesh.VertexFormat or Mesh.VertexDeclaration properties to find out which format to use exactly.

Do you have a specific reason to change the color on the vertices themselves btw? You might be better off using the device.Material property to set the color for the mesh. It's easier and more efficient, so if you can use it, I'd go with that.

Share on other sites
Thanks, that worked. I was going to try deformed spheres for occlusion culling of static point lights with dynamic shadow casters. To do that, I need to adjust the vertex positions of the mesh. I tried changing the color to make sure I had everything working correctly.

Edit: And my sphere deforming technique works too now.

Higly tessellated occlusion query mesh for a point light.