Jump to content
  • Advertisement
Sign in to follow this  
leandro81

Retrieving Mesh geometry

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

If you intended to correct an error in the post then please contact us.

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 = (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 = (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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!