Sign in to follow this  
Quat

Organizing Mesh Data

Recommended Posts

Quat    568
I am working on a level editor type program in Direct3D11. So I need to be able to adjust as new objects are added/deleted. I'm trying to figure out how to organize my meshes and their vertex/index buffer representations.

1. I have a fixed amount of vertex formats I support. Should I create one VB/IB for each one, and store all mesh data in them. Then each object just stores the start/end offsets? This saves IASetVertexBuffers and IASetIndexBuffer calls, but since objects can be inserted/deleted it requires resizing the buffers, moving data, and updating the offsets. Should I just have each mesh object have its own VB/IB?

2. Currently, we have a generic "fat" Mesh class that contains the mesh geometry. Since this is an editor like program, we also store additional mesh data that is not rendered (like edge lists). A mesh can have different vertex data (position, normal, tex-coords, second set of tex-coords, tangent, bone weights, etc.). What is an elegant way to fill the vertex buffer? Right now we use a type system:

case DefaultVertex:
FillDefault();
break;
case SkinnedVertex:
FillSkinned();
break;
...

the vertex type is known when the mesh is created. Based on the type, it grabs the system memory vertex data and fills the vertex buffer accordingly. This works, but I find it sort of ugly and am wondering if anyone had better ideas.

Do you think making Mesh a base class with virtual FillVertexBuffer is the way to go? The only problem with this is that we may get a lot of Mesh child classes, and possible duplication of code across child classes.

Share this post


Link to post
Share on other sites
JarkkoL    153
I'm creating one vertex & index buffer per mesh. I don't think it's worth the trouble to put multiple objects in a single buffer.

For importing 3D meshes I have generic mesh class as well. There's also platform specific mesh class with virtual init() function which takes the mesh as an argument and builds platform specific vertex and index buffers from it. This platform specific data is stored back to a file and when a game is loaded the data is streamed straight to video memory without any intermediate format.

Cheers, Jarkko

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