summaryrefslogtreecommitdiffhomepage
path: root/src/models.c
diff options
context:
space:
mode:
authorTristan Schulz <[email protected]>2021-09-09 18:14:15 +0200
committerGitHub <[email protected]>2021-09-09 18:14:15 +0200
commit7bf31dd46897f4fd590b9db275caeb42992ccd47 (patch)
treef5542aa624443573e294fb24f18775f2ead7476b /src/models.c
parent1a6adc5f74b73bae38bf994e07692993072e7ca0 (diff)
downloadraylib-7bf31dd46897f4fd590b9db275caeb42992ccd47.tar.gz
raylib-7bf31dd46897f4fd590b9db275caeb42992ccd47.zip
Fixed loading obj models with no materials (#1984)
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/models.c b/src/models.c
index 045cd16a..ab3d0dd0 100644
--- a/src/models.c
+++ b/src/models.c
@@ -3560,13 +3560,22 @@ static Model LoadOBJ(const char *fileName)
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
// Count the faces for each material
- int *matFaces = RL_CALLOC(materialCount, sizeof(int));
+ int *matFaces = RL_CALLOC(model.meshCount, sizeof(int));
- for (int fi = 0; fi< attrib.num_faces; fi++)
+ // iff no materials are present use all faces on one mesh
+ if (materialCount > 0)
+ {
+ 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]++;
+ }
+
+ }
+ else
{
- //tinyobj_vertex_index_t face = attrib.faces[fi];
- int idx = attrib.material_ids[fi];
- matFaces[idx]++;
+ matFaces[0] = attrib.num_faces;
}
//--------------------------------------
@@ -5606,4 +5615,4 @@ static Model LoadVOX(const char *fileName)
return model;
}
-#endif \ No newline at end of file
+#endif