X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrtris;a=blobdiff_plain;f=src%2Fcmesh.c;h=e40e4f461c1d5f093aa603514ed3a0a768976c4a;hp=993fa2cc0d8554a06deb6771c3332da445e8ac86;hb=e50e34cb3791268a6665e3970ed76d2ad0d7aed2;hpb=a6bd42c022f3b1c12a54444e5e469215f2ecbe27 diff --git a/src/cmesh.c b/src/cmesh.c index 993fa2c..e40e4f4 100644 --- a/src/cmesh.c +++ b/src/cmesh.c @@ -1296,9 +1296,14 @@ int cmesh_dump_obj(struct cmesh *cm, const char *fname) return -1; } +#define HAS_VN 1 +#define HAS_VT 2 + int cmesh_dump_obj_file(struct cmesh *cm, FILE *fp, int voffs) { + static const char *fmtstr[] = {" %u", " %u//%u", " %u/%u", " %u/%u/%u"}; int i, j, num, nelem; + unsigned int aflags = 0; if(!cmesh_has_attrib(cm, CMESH_ATTR_VERTEX)) { return -1; @@ -1315,6 +1320,7 @@ int cmesh_dump_obj_file(struct cmesh *cm, FILE *fp, int voffs) } if(cmesh_has_attrib(cm, CMESH_ATTR_NORMAL)) { + aflags |= HAS_VN; nelem = cm->vattr[CMESH_ATTR_NORMAL].nelem; if((num = dynarr_size(cm->vattr[CMESH_ATTR_NORMAL].data)) != cm->nverts * nelem) { warning_log("normal array size (%d) != nverts (%d)\n", num, cm->nverts); @@ -1326,6 +1332,7 @@ int cmesh_dump_obj_file(struct cmesh *cm, FILE *fp, int voffs) } if(cmesh_has_attrib(cm, CMESH_ATTR_TEXCOORD)) { + aflags |= HAS_VT; nelem = cm->vattr[CMESH_ATTR_TEXCOORD].nelem; if((num = dynarr_size(cm->vattr[CMESH_ATTR_TEXCOORD].data)) != cm->nverts * nelem) { warning_log("texcoord array size (%d) != nverts (%d)\n", num, cm->nverts); @@ -1346,7 +1353,7 @@ int cmesh_dump_obj_file(struct cmesh *cm, FILE *fp, int voffs) fputc('f', fp); for(j=0; j<3; j++) { unsigned int idx = *idxptr++ + 1 + voffs; - fprintf(fp, " %u/%u/%u", idx, idx, idx); + fprintf(fp, fmtstr[aflags], idx, idx, idx); } fputc('\n', fp); } @@ -1356,7 +1363,7 @@ int cmesh_dump_obj_file(struct cmesh *cm, FILE *fp, int voffs) for(i=0; i