Jump to content
  • Advertisement
Sign in to follow this  

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

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

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.

  Vec3 *v, *n, *c, *uv, *indices; Material *material;

  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

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!