Jump to content
  • Advertisement
Sign in to follow this  

Importing / Storing Mesh Information

This topic is 3070 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'm using C++ and DirectX currently and have been toying around with importing the mesh data from files.

I just want to know what some opinions are on loading and storing mesh information since that data with have to be available to not only the grahpics engine but the physics, collision and AI parts.

Currently i can create multiple DirectX Mesh objects to draw out but i'm kind of starting from the other end now.

My first thought was the vectors seems the easiest to store in and resize i just have to count Vertex information in sets of 3.

The hardest part is just arranging the data so that it will be available in so many places.

Would it be better to create an array of a custom structure that holds vectors or vector pointers or to add them as public members of a class and create an array of the class type?

Share this post

Link to post
Share on other sites
Depending on your needs, using a custom file format may be the best path. You'll have to consider the needs to create a DX mesh from the info and to create buffers of information needed by the other parts of your application.

Is loading speed a consideration? Can you afford the time to create data buffers for the other parts (collision,etc.) from the loaded mesh? Is rendering speed a consideration? Even if the others parts can use the mesh vertex data as arranged in the vertex buffer, can you afford the time to lock/unlock the vertex buffer? It's a speed vs. memory issue, essentially.

Assuming speed is more important than memory, a custom file format may be easier to use as a compromise (vs. loading meshes from an x-file and then extracting the needed info from the mesh).

I use a custom format file for each (reuseable) object, as the collision data is much simpler than the graphics data. The graphics object may be quite detailed, but the collision data (to keep the speed up) is just an acceptable approximation of the shape of the graphics object, with a lot fewer triangles. In addition, if the collision shape is simple enough, I don't have collision data at all, but use a flag to indicate that the collision engine should use a sphere/capsule/box/etc. for collision purposes. I use ODE and can default to those "built-in" shapes for collision (rather than using triangular mesh data which is much slower).

Multiple instances of the same object share a common set of data, stored in an "object data" class (to which each instance has a pointer/reference), with instance specific data (textures, matrices, etc.) stored in each instance. [for an explanation of that sentence, see "Department of Redundancy Department"]

That type of data separation may be applicable to the other parts of your application.

Just some thoughts.

Share this post

Link to post
Share on other sites
Well currently i am using my own altered format of wavefront obj files.
So for each file that i import as a reusable model i'm wondering what the best way of storing that buffer information would be before i send it to the class to be converted into a ID3DX10Mesh object.

right now it would be
vertex - x, y, z
texture - u, v
face - 1/1/5
and i included a header list which includes the number of each type there is.

Share this post

Link to post
Share on other sites
It's probably best to have one data-loading routine so it's more easily modifiable (rather than having each object load itself).

Because I don't know DX10 (didn't see that until too late), there may be a better way. However, you might consider loading the mesh data directly into an array of vertex structures. I don't know if you know ahead of time how many vertices you'll be processing but (pseudo-code):

MESHVERTEX *mv = new MESHVERTEX[numVerts];
WORD *ib = new WORD[numFaces*3];
WORD idx = 0; // is DX10 DWORD instead of WORD for indices??
for each vertex reading in:
get v = vertex
mv[idx].pos = D3DXVECTOR3(v.x, v.y, v.z);
//... store vertex position in collision or other buffers?
get tc = texcoords
mv[idx].tc = D3DXVECTOR2(tc.u, tc.v);
// need tc's elsewhere? probably not
get face indices i1, i2, i3
ib[idx*3 + 0] = i1
ib[idx*3 + 1] = i2
ib[idx*3 + 2] = i3
// store indices elsewhere?
// read in other data - do you need normals?
end foreach

for each mesh to be created:
meshObject->CreateMesh(device, mv, ib, instance data) // or some suitable object function for creating the mesh from data
// done with data
delete mv;
delete ib;

Alternatively, if you don't know ahead of time how many verts/indices you're going to have, push them back into a std::vector.

I couldn't tell from your description whether the data you listed is serial in the file or whether you have vertices, then all tc's, then all faces, etc. The principle would be the same however.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!