0
\$\begingroup\$

I am using DrawIndexedPrimitives() for drawing a loaded 3D model by drawing each mesh part, but this process makes my application very slow. This is perhaps because of a very large number of vertex/index buffer data created in video memory.

That is why I am looking for a way to use the same method for each model mesh instead. The problem is that I don't know how I will set the textures of that mesh. Can anyone offer me some guidance?

\$\endgroup\$
1
  • \$\begingroup\$ I don't know, what model editor you are using. But for example Maya has ability to generate "texture map", which looks like this: goo.gl/idbxg It can be then used with for example photoshop and you can create one texture for whole model. But if you want to use several textures, I think you have to use mesh parts. \$\endgroup\$
    – zacharmarz
    Commented Nov 1, 2011 at 13:40

2 Answers 2

1
\$\begingroup\$

Make a single texture atlas by combining all your mesh's textures into one, in any image editing program. Then you'll have to go into your 3D modeling program to set the texture atlas to all the parts of your model, and UV re-map. The re-mapping is not as daunting as you might expect- it'll usually just be a matter of rotating, proportional scaling and moving the groups of vertices until they fit with the new texture. Export the mesh with the new texture coordinates.

Combine your mesh parts into a larger one in runtime. When the models are being loaded, read each vertex buffer and index buffer and join them together to create one large vertex buffer and index buffer. This is a non-destructive change, as you still get to keep the individual mesh parts if you want to go back and make any further tweaks in the modeling program. Now with these new buffers, you only need one draw call and one texture change to render each model.

Your program sounds like it's drawing a complex or busy scene, so it may take some time to build the new vertex buffers dynamically. However, you'll just do this once each time they load in the program.

\$\endgroup\$
0
\$\begingroup\$

If the entire model uses only one texture, theoretically you can set that texture and draw the model's vertex buffer and index buffer in one call, since the entire model is stored in a single vertex and index buffer.

Except, when you load the model the indexes for various mesh parts will not be relative the vertex buffer as a whole, but rather the mesh part's vertex offset, making that impossible for no good reason. So to draw the entire model in one draw call you will have to create a new index buffer with corrected indexes.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .