ingowald / optix7course

Apache License 2.0
452 stars 80 forks source link

A bug in example07 when import models #37

Closed Puluomiyuhun closed 1 year ago

Puluomiyuhun commented 1 year ago

Hello! Thank you very much for the optix7 course you provided, which enabled us to successfully complete our own renderer.

There is a small bug in the function ‘’Model* loadOBJ(const std::string& objFile, material_kind mat_kind)‘’ in lesson 7. Your code is: for (auto faceMatID : shape.mesh.material_ids) { materialIDs.insert(faceMatID); } std::map<tinyobj::index_t, int> knownVertices; for (int materialID : materialIDs) { ......

However, writing this way can lead to many incorrect faces after importing many models. I think it should be: for (auto faceMatID : shape.mesh.material_ids) { materialIDs.insert(faceMatID); } for (int materialID : materialIDs) { std::map<tinyobj::index_t, int> knownVertices; ......

Because every time we create a material, we need to split a separate Triangle Mesh, so that 'knownVerticals' should be placed within a loop that traverses the materials.

ingowald commented 1 year ago

That sounds about right; I thought I had already fixed this, but maybe that was in the OWL-copy of this sample. If you already have a solutoin please send a PR, I'd be happy to merge it!

ingowald commented 1 year ago

Just fixed as suggested; also in all other examples that used the same importer code.