diff options
| author | Tristan Schulz <[email protected]> | 2021-09-01 21:29:20 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-01 21:29:20 +0200 |
| commit | e8fa7ceb79613188c495b80a332875a1afdab8cf (patch) | |
| tree | 593aa9540dec9d77457ba04644a300103b33ae70 /src/models.c | |
| parent | 68bcfa119243e716eaf00ffe521d0358c084b74f (diff) | |
| download | raylib-e8fa7ceb79613188c495b80a332875a1afdab8cf.tar.gz raylib-e8fa7ceb79613188c495b80a332875a1afdab8cf.zip | |
[models] Fixed counting loop for face amount per material (#1967)
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/models.c b/src/models.c index a464c9fd..b175dd94 100644 --- a/src/models.c +++ b/src/models.c @@ -3491,6 +3491,11 @@ RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Ve //---------------------------------------------------------------------------------- #if defined(SUPPORT_FILEFORMAT_OBJ) // Load OBJ mesh data +// +// Keep the following information in mind when reading this +// - A mesh is created for every material present in the obj file +// - the model.meshCount is therefore the materialCount returned from tinyobj +// - the mesh is automatically triangulated by tinyobj static Model LoadOBJ(const char *fileName) { Model model = { 0 }; @@ -3542,15 +3547,12 @@ static Model LoadOBJ(const char *fileName) // Count the faces for each material int *matFaces = RL_CALLOC(materialCount, sizeof(int)); - for (unsigned int mi = 0; mi < meshCount; mi++) - { - for (unsigned int fi = 0; fi < meshes[mi].length; fi++) - { - int idx = attrib.material_ids[meshes[mi].face_offset + fi]; - if (idx == -1) idx = 0; // for no material face (which could be the whole model) - matFaces[idx]++; - } + for(int fi = 0; fi< attrib.num_faces; fi++){ + tinyobj_vertex_index_t face = attrib.faces[fi]; + int idx = attrib.material_ids[fi]; + matFaces[idx]++; } + //-------------------------------------- // Create the material meshes |
