0
\$\begingroup\$

Currently, I have a model loader heavily inspired by the one made in LearnOpenGL, which works fine when loading regular models. I made a simple cube in Blender, exported it as an OBJ and I'm able to load the cube with Assimp just fine. The problem is that I want to be able to render this same cube model with different textures. When I load the model with Assimp::Importer::ReadFile I can't change the material used for each mesh, so I'm only able to render the cube with one texture (I could use a material for each mesh, but that's not what I need). I want to know what would be the best way to adapt this model loader to support specifying a texture when loading the model and also keep the current behavior if I need to load a more complex model. These are the options I have considered:

  1. Add an option to ignore the materials from the scene and handle textures manually, which I don't think would mix well with the current code
  2. Duplicate the models and create new materials for each model (doable for now, but not really feasible if when there are too many possible combinations)
  3. Load an OBJ file into a buffer in memory with a placeholder material name after usemtl, change that name to the material I want and pass the buffer to Assimp::Importer::ReadFileFromMemory. This seems like my the best option so far but still feels kinda weird

I'm not stuck to OBJ, so I could switch to another format if it's necessary. What could I do here?

\$\endgroup\$
2
  • \$\begingroup\$ Option 4 - stich all textures into one atlas and thus have one texture. \$\endgroup\$
    – Kromster
    Apr 1 at 16:37
  • \$\begingroup\$ This doesn't seem very flexible if I want to load a model I downloaded, for example. \$\endgroup\$
    – KleberPF
    Apr 2 at 2:22

0

You must log in to answer this question.

Browse other questions tagged .