Search code examples
c++assimp

Assimp 4 Loading Missing materials doesn't throw errors


I'm using Assimp 4.1.0 to load OBJ files. Some files might be referencing a missing material file and i wanted to give my own default values to the materials if Assimp doesn't find them properly.

Given the documentation:

aiMaterial* mat = .....
// The generic way
if(AI_SUCCESS != mat->Get(<material-key>,<where-to-store>)) {
   // handle epic failure here
}

It should throw something, but it isn't. It is returning aiReturn_SUCCESS even though the material file wasn't there. Does anyone have any workaround for this ?

Thanks !


Solution

  • When the material in your example is not there it will be a nullptr-type and your application will crash. When no obj-based material were imported (the file with the mtl-extension ) a base material ill be created I guess this material file will be used to get the key which you want to look for.

    First make sure that you are using the right material instance. Then the API will work as descriped in the API-documentation.

    Just ask if there are still some open questions. And you will get faster answers if you are using the project-side directly :-).

    Kim