Advertisement

Multi-Mesh Models from .obj and .mtl - C++ Model Factory

Started by February 23, 2014 05:50 PM
-1 comments, last by mynameisnafe 10 years, 9 months ago

Hi all,

I'm looking for some advice regarding .obj and .mtl files.

I have .obj and .mtl file loaders - they load a .obj model as one mesh and a vector of materials from the .mtl.
Each mesh can be assigned a material.

I'd like to split up the faces that I pull in from the .obj loader into meshes, so each mesh can be used with the material in the .mtl file that it's assigned to, i.e., so I can use the material data as GL Uniform Data (colours, tex ids).

This way I can build build up a Model of Meshes, with each mesh having it's own material. I can add Model to a scenegraph and it can Render its Meshes. So far so so.


Mesh
{
  Vec3 *v, *n, *c, *uv, *indices; Material *material;
};

GLMesh
{
  VAO*, Shader*, Mesh*
};

The question is, how best to do this for .obj files?

I'd do it in the loader, of course, and assign the right material to the right mesh.

But how do you decide what is a mesh (when a mesh starts and ends) in .obj?
1) Each 'usemtl ', find a mesh with that material name or create a mesh, and add to those vertices, indices, etc, find the material in the vector of Materials later and copy it to the Mesh ?

2) Each 'g ', start a new mesh, and use the last 'usemtl ' as that meshes material name, find the material in the vector of Materials later and copy it over to the Mesh?

Any .obj vets?

Thanks in advance

This topic is closed to new replies.

Advertisement