diff options
-rw-r--r-- | graphics.h | 1 | ||||
-rw-r--r-- | scene.c | 10 |
2 files changed, 10 insertions, 1 deletions
@@ -102,6 +102,7 @@ struct LightSource struct Material { + char *name; Color ambient; Color diffuse; Color specular; @@ -154,6 +154,11 @@ loadobjmodel(Model *m, OBJ *obj) mtl = &m->materials[m->nmaterials-1]; memset(mtl, 0, sizeof *mtl); + if(objmtl->name != nil){ + mtl->name = strdup(objmtl->name); + if(mtl->name == nil) + sysfatal("strdup: %r"); + } mtl->ambient.r = objmtl->Ka.r; mtl->ambient.g = objmtl->Ka.g; mtl->ambient.b = objmtl->Ka.b; @@ -306,8 +311,11 @@ delmodel(Model *m) freememimage(m->tex); if(m->nor != nil) freememimage(m->nor); - if(m->nmaterials > 0) + if(m->nmaterials > 0){ + while(m->nmaterials--) + free(m->materials[m->nmaterials].name); free(m->materials); + } if(m->nprims > 0) free(m->prims); free(m); |