diff options
| author | sikor666 <[email protected]> | 2020-05-08 20:27:10 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-08 20:27:10 +0200 |
| commit | db4a618c6f165c90f8d4aaa470f84705fe62b6b5 (patch) | |
| tree | 901743871331a8f335a3e3c192fa72a93da260d7 /src/models.c | |
| parent | df5c522049ddd82fba048a6bd069338999729d6a (diff) | |
| download | raylib-db4a618c6f165c90f8d4aaa470f84705fe62b6b5.tar.gz raylib-db4a618c6f165c90f8d4aaa470f84705fe62b6b5.zip | |
Fix materials loading for IQM models (#1227)
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/models.c b/src/models.c index 00d3b516..482c647b 100644 --- a/src/models.c +++ b/src/models.c @@ -3050,6 +3050,7 @@ static Model LoadIQM(const char *fileName) #define BONE_NAME_LENGTH 32 // BoneInfo name string length #define MESH_NAME_LENGTH 32 // Mesh name string length + #define MATERIAL_NAME_LENGTH 32 // Material name string length // IQM file structs //----------------------------------------------------------------------------------- @@ -3182,12 +3183,25 @@ static Model LoadIQM(const char *fileName) model.meshCount = iqm.num_meshes; model.meshes = RL_CALLOC(model.meshCount, sizeof(Mesh)); + model.materialCount = model.meshCount; + model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material)); + model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int)); + char name[MESH_NAME_LENGTH] = { 0 }; + char material[MATERIAL_NAME_LENGTH] = { 0 }; for (int i = 0; i < model.meshCount; i++) { fseek(iqmFile, iqm.ofs_text + imesh[i].name, SEEK_SET); - fread(name, sizeof(char)*MESH_NAME_LENGTH, 1, iqmFile); // Mesh name not used... + fread(name, sizeof(char)*MESH_NAME_LENGTH, 1, iqmFile); + + fseek(iqmFile, iqm.ofs_text + imesh[i].material, SEEK_SET); + fread(material, sizeof(char)*MATERIAL_NAME_LENGTH, 1, iqmFile); + + model.materials[i] = LoadMaterialDefault(); + + TRACELOG(LOG_DEBUG, "MODEL: [%s] mesh name (%s), material (%s)", fileName, name, material); + model.meshes[i].vertexCount = imesh[i].num_vertexes; model.meshes[i].vertices = RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float)); // Default vertex positions |
