Sign in to follow this  
leandro81

Retrieving Mesh geometry

Recommended Posts

Hi Folks, I'm using C# with DirectX 9. When I try to retrieve a simple mesh (a table) geometry to input Newton Library (for collision detection), using index and vertex buffer, this is what happens: Free Image Hosting at www.ImageShack.us The blue lines are drawn for debugging purposes using this code:
           GraphicsStream indexList = objectMesh.LockIndexBuffer(LockFlags.ReadOnly);  //objectMesh.IndexBuffer.Lock(0, 0, LockFlags.None);                        
           short[] indices = new short[objectMesh.NumberFaces * 3];           
           for (int i = 0; i < objectMesh.NumberFaces * 3; i++)
           {
               indices[i] = (short)indexList.Read(typeof(short));
           }
           objectMesh.UnlockIndexBuffer(); // objectMesh.IndexBuffer.Unlock();

           GraphicsStream stm = objectMesh.LockVertexBuffer(LockFlags.ReadOnly); //objectMesh.VertexBuffer.Lock(0, 0, LockFlags.None);
           Vector3[] vertices = new Vector3[objectMesh.NumberVertices];
           for (int i = 0; i < objectMesh.NumberVertices; i++)
           {

               vertices[i] = (Vector3)stm.Read(typeof(Vector3));

           }
           objectMesh.UnlockVertexBuffer(); //objectMesh.VertexBuffer.Unlock();
            
           for (int i = 0; i < objectMesh.NumberFaces; i++)
           {
               CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[3];
               verts[0].Position = new Vector3(vertices[indices[(i * 3) + 0]].X, vertices[indices[(i * 3) + 0]].Y, vertices[indices[(i * 3) + 0]].Z);
               verts[0].Color = System.Drawing.Color.Blue.ToArgb();
               verts[1].Position = new Vector3(vertices[indices[(i * 3) + 1]].X, vertices[indices[(i * 3) + 1]].Y, vertices[indices[(i * 3) + 1]].Z);
               verts[1].Color = System.Drawing.Color.Blue.ToArgb();
               verts[2].Position = new Vector3(vertices[indices[(i * 3) + 2]].X, vertices[indices[(i * 3) + 2]].Y, vertices[indices[(i * 3) + 2]].Z);
               verts[2].Color = System.Drawing.Color.Blue.ToArgb();

               device.Transform.World = Matrix.Identity;
               device.VertexFormat = CustomVertex.PositionColored.Format;
               device.DrawUserPrimitives(PrimitiveType.LineList, 1, verts);
           }

I am having really a hard time to retrieve this geometry correctly (the table gets rendered correctly, but look at those crazy blue lines that I get when I read it from its buffers). So, any suggestions on this subject would be really appreciated. Thanks in advance, Leandro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this