PR Feedback
This commit is contained in:
parent
164de4860d
commit
24095a0c97
|
|
@ -4106,6 +4106,12 @@ static Model LoadOBJ(const char* fileName)
|
||||||
unsigned int flags = TINYOBJ_FLAG_TRIANGULATE;
|
unsigned int flags = TINYOBJ_FLAG_TRIANGULATE;
|
||||||
int ret = tinyobj_parse_obj(&objAttributes, &objShapes, &objShapeCount, &objMaterials, &objMaterialCount, fileText, dataSize, flags);
|
int ret = tinyobj_parse_obj(&objAttributes, &objShapes, &objShapeCount, &objMaterials, &objMaterialCount, fileText, dataSize, flags);
|
||||||
|
|
||||||
|
if (ret != TINYOBJ_SUCCESS)
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_ERROR, "MODEL Unable to read obj data %s", fileName);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
UnloadFileText(fileText);
|
UnloadFileText(fileText);
|
||||||
|
|
||||||
unsigned int faceVertIndex = 0;
|
unsigned int faceVertIndex = 0;
|
||||||
|
|
@ -4144,10 +4150,16 @@ static Model LoadOBJ(const char* fileName)
|
||||||
model.meshCount = meshIndex + 1;
|
model.meshCount = meshIndex + 1;
|
||||||
model.meshes = (Mesh*)MemAlloc(sizeof(Mesh) * model.meshCount);
|
model.meshes = (Mesh*)MemAlloc(sizeof(Mesh) * model.meshCount);
|
||||||
|
|
||||||
if (objMaterialCount == 0) objMaterialCount = 1;
|
if (objMaterialCount > 0)
|
||||||
|
{
|
||||||
model.materialCount = objMaterialCount;
|
model.materialCount = objMaterialCount;
|
||||||
model.materials = (Material*)MemAlloc(sizeof(Material) * objMaterialCount);
|
model.materials = (Material*)MemAlloc(sizeof(Material) * objMaterialCount);
|
||||||
|
}
|
||||||
|
else // we must allocate at least one material
|
||||||
|
{
|
||||||
|
model.materialCount = 1;
|
||||||
|
model.materials = (Material*)MemAlloc(sizeof(Material) * 1);
|
||||||
|
}
|
||||||
|
|
||||||
model.meshMaterial = (int*)MemAlloc(sizeof(int) * model.meshCount);
|
model.meshMaterial = (int*)MemAlloc(sizeof(int) * model.meshCount);
|
||||||
|
|
||||||
|
|
@ -4249,7 +4261,7 @@ static Model LoadOBJ(const char* fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
int matId = 0;
|
int matId = 0;
|
||||||
if (lastMaterial >= 0 && lastMaterial < objMaterialCount)
|
if (lastMaterial >= 0 && lastMaterial < (int)objMaterialCount)
|
||||||
matId = lastMaterial;
|
matId = lastMaterial;
|
||||||
|
|
||||||
model.meshMaterial[meshIndex] = matId;
|
model.meshMaterial[meshIndex] = matId;
|
||||||
|
|
@ -4260,10 +4272,6 @@ static Model LoadOBJ(const char* fileName)
|
||||||
int normalIndex = objAttributes.faces[faceVertIndex].vn_idx;
|
int normalIndex = objAttributes.faces[faceVertIndex].vn_idx;
|
||||||
int texcordIndex = objAttributes.faces[faceVertIndex].vt_idx;
|
int texcordIndex = objAttributes.faces[faceVertIndex].vt_idx;
|
||||||
|
|
||||||
Vector3 vert = { objAttributes.vertices[vertIndex * 3], objAttributes.vertices[vertIndex * 3 + 1] , objAttributes.vertices[vertIndex * 3 + 2] };
|
|
||||||
Vector3 normal = { objAttributes.normals[normalIndex * 3], objAttributes.normals[normalIndex * 3 + 1] , objAttributes.normals[normalIndex * 3 + 2] };
|
|
||||||
Vector2 uv = { objAttributes.texcoords[texcordIndex * 2], objAttributes.texcoords[texcordIndex * 2 + 1] };
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
model.meshes[meshIndex].vertices[localMeshVertexCount * 3 + i] = objAttributes.vertices[vertIndex * 3 + i];
|
model.meshes[meshIndex].vertices[localMeshVertexCount * 3 + i] = objAttributes.vertices[vertIndex * 3 + i];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user