Archived

This topic is now archived and is closed to further replies.

How to use a mesh?

This topic is 5177 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

I need to use a IDirect3DMesh9 just to use calculate normals function on it. So how the vertices are "transfered" to it? There is a LockVertexBuffer method, but how do you set how many vertex will be in the mesh? [edited by - The C modest god on October 9, 2003 4:59:19 PM]

Share this post


Link to post
Share on other sites
What is it you want to do, just calculate normals for a mesh? No reason to bother loading it into a IDirect3DMesh9 if you''ve already got it present via your own structure.

I punched "calculating normals" into Google and here''s the first thing I got. I''m sure a little more searching could find you more examples.

---
http://www.gapingwolf.com

Share this post


Link to post
Share on other sites
quote:
Original post by FenrirWolf
What is it you want to do, just calculate normals for a mesh? No reason to bother loading it into a IDirect3DMesh9 if you''ve already got it present via your own structure.

I punched "calculating normals" into Google and here''s the first thing I got. I''m sure a little more searching could find you more examples.

---
http://www.gapingwolf.com


The normals are of the vertices themself not the triangle.
It would be easier to create a mesh and use the function instead.

Share this post


Link to post
Share on other sites
If you have the verticies you just put them into an array, lock the buffer, then memcpy the array into the buffer and unlock it. I''ve only done it directly with vertex buffers, not models, so there might be some other things you need to do like setting the attribute table (face count, vertex count)

I take it you mean an ID3DXMesh interface rather than IDirect3DMesh9, because according to the DirectX 9 SDK there''s no such thing as an IDirect3DMesh9.

Share this post


Link to post
Share on other sites
quote:
Original post by The C modest god
The normals are of the vertices themself not the triangle.
It would be easier to create a mesh and use the function instead.

Many times, the normals of a triangles' vertices are the same as the face normal. Lemme try some ascii art Let's say you're looking at a triangle edge on. The face normal points straight up:


/| |
|
|
|
|
-------------------------------


This is the same normal you would store at your vertices. It would look like this:

/|\ /| | |
| |
| |
| |
| |
-------------------------------------

A real artist would be able to manually adjust normals from inside a modeling package, but this is how you do it when you compute them in code.

If you want to make the normals look a little more realistic, you have to take into account the face normals of adjacent triangles. This is a little more difficult but not impossible. The D3DX allows you to do this by accepting adjacency information into the D3DXComputeNormals function.

If you still want to use the ID3DXMesh interface, here's what you do. Call D3DXCreateMesh or D3DXCreateMeshFVF to create a mesh object with the proper amount of faces and vertices. It will return a pointer to an ID3DXMesh. You can then call ID3DXMesh::LockVertexBuffer and ID3DXMesh::LockIndexBuffer and memcpy all your vertices and indices into the mesh because you created the mesh to be exactly the right size to hold your data. Remember that an object of ID3DXMesh expects it's index buffer to be set up as a triangle list, not a triangle strip or fan.

You should then call ID3DXMesh::GenerateAdjacency so that the mesh looks at all the vertex and index info and creates a list of triangles that are adjacent to eachother. With all of this done, you can call D3DXComputeNormals and pass it the adjacency information. Since you already have the data loaded into the model, you might as well take advantage of the optimization routines it gives you. You can use ID3DXMesh::OptimizeInPlace to help performance.

You can then either call ID3DXMesh::DrawSubset to render your model or access the vertex and index bufferes directly and draw the model yourself using IDirect3DDevice9::DrawIndexedPrimitve.

Hope this helps,
neneboricua

[edited by - neneboricua19 on October 10, 2003 11:28:33 AM]

Share this post


Link to post
Share on other sites