X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrlugburz;a=blobdiff_plain;f=src%2Fscenefile.c;fp=src%2Fscenefile.c;h=398ce96bf5faa908d86896da6bfa3eefb55d0e3f;hp=39d9b92b70a1636000bf5283b0c0fd0feb3ec8b7;hb=5c66bff3dc3b2fdf8b57908de4ebcfc6da6e3597;hpb=f3d32774e0c196175d8143c21313097bcc8ff3a2 diff --git a/src/scenefile.c b/src/scenefile.c index 39d9b92..398ce96 100644 --- a/src/scenefile.c +++ b/src/scenefile.c @@ -339,14 +339,18 @@ static int load_mtllib(struct scenefile *scn, const char *path_prefix, const cha if(memcmp(line, "newmtl", 6) == 0) { if(mtl) { + conv_mtl(mtl, &om, path_prefix); mtl->next = scn->mtllist; scn->mtllist = mtl; } - if((mtl = calloc(1, sizeof *mtl))) { - if((line = cleanline(line + 6))) { - mtl->name = strdup(line); - } + mtl = calloc(1, sizeof *mtl); + + memset(&om, 0, sizeof om); + + if((line = cleanline(line + 6))) { + om.name = strdup(line); } + } else if(memcmp(line, "Kd", 2) == 0) { sscanf(line + 3, "%f %f %f", &om.kd.x, &om.kd.y, &om.kd.z); } else if(memcmp(line, "Ks", 2) == 0) { @@ -370,10 +374,10 @@ static int load_mtllib(struct scenefile *scn, const char *path_prefix, const cha om.map_alpha = strdup(line); } } - conv_mtl(mtl, &om, path_prefix); } if(mtl) { + conv_mtl(mtl, &om, path_prefix); mtl->next = scn->mtllist; scn->mtllist = mtl; } @@ -397,7 +401,7 @@ static void conv_mtl(struct material *mm, struct objmtl *om, const char *path_pr int len, prefix_len, maxlen = 0; memset(mm, 0, sizeof *mm); - mm->name = strdup(om->name); + mm->name = om->name; mm->color = om->kd; mm->spec = om->ks; mm->shininess = om->shin;