Sign in to follow this  

D3DXCreateMeshFVF vs D3DXLoadMeshFromX

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

Hello. You guys are great. Up til now all of my meshes were loaded from X files using D3DXLoadMeshFromX, which takes as arguements the number of materials in the mesh and pointers to the materials and Texture buffers. I'm trying to use D3DXCreateMeshFVF, which doesn't take any arguements regarding materials or textures. So how do I associate the texture buffer with the mesh? I.e., to render the mesh with DrawSubset(attrib), how does the mesh know how many subsets to draw? Also, after creating the mesh, how would I load it? Hope this makes sense. Thanks again.

Share this post


Link to post
Share on other sites
I used D3DXCreateMeshFVF() in one of my tools to convert terrain heightmaps in to X file meshes. One of the main parameters you supply to D3DXCreateMeshFVF() is a variable of type ID3DXMesh* along with the pre-calculated number of vertices and indices that will be in the mesh.

After you have used the above function you are left with a prepared ID3DXMesh* variable that you supplied to it. You need to lock the vertex buffer and the index buffer of this mesh interface individually and fill it up manually with your vertex and index data. So, in the case of vertices, you may instance an array of a defined vertex structure, iterate through this array and fill it up with position, normal, texture coordinate data for each vertex etc and then copy it in to ID3DXMesh*'s vertex buffer. You would do the same with the indices if you are creating an indexed primitive.

To assign the triangles to a subset for rendering you need to lock the ID3DXMesh's attribute buffer and fill it with numbers. Each number is the subset that the corresponding face, made up from the vertex and index buffers, belongs to. It is sequential from start to end.

Once you have done that you can call Mesh->OptimizeInplace() to reorder the data in your mesh buffers for more efficient rendering.

You would not need to load the mesh after having done this because you have filled it with data yourself. You can render it as you would any other ID3DXMesh*. You can of course save it to an .X file using D3DXSaveMeshToX() and load it with D3DXLoadMeshFromX() the next time.

As you can imagine, it is quite hard to fill the necessary buffers algorithmically. As far as I can gauge, you would only do this if you're creating some procedural geometry like trees and shit. If you can use a 3D modeler you would be much better off sticking with that!

Share this post


Link to post
Share on other sites

This topic is 4838 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.

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