char *name;
unsigned int nverts, nfaces;
- struct submesh *sublist;
+ struct submesh *sublist, *subtail;
int subcount;
/* current value for each attribute for the immediate mode interface */
}
cmdest->sublist = head;
+ cmdest->subtail = tail;
cmdest->subcount = cmsrc->subcount;
}
free(sm);
}
cm->subcount = 0;
+ cm->subtail = 0;
}
int cmesh_submesh(struct cmesh *cm, const char *name, int fstart, int fcount)
sm->vcount = fcount * 3;
}
- sm->next = cm->sublist;
- cm->sublist = sm;
+ sm->next = 0;
+ if(cm->sublist) {
+ cm->subtail->next = sm;
+ cm->subtail = sm;
+ } else {
+ cm->sublist = cm->subtail = sm;
+ }
cm->subcount++;
return 0;
}
free(sm->name);
free(sm);
+ if(cm->subtail == sm) {
+ cm->subtail = prev;
+ }
+
cm->subcount--;
assert(cm->subcount >= 0);
- cm->sublist = dummy.next;
+ if(!dummy.next) {
+ cm->sublist = cm->subtail = 0;
+ } else {
+ cm->sublist = dummy.next;
+ }
return 0;
}
static const char *fmtstr[] = {" %u", " %u//%u", " %u/%u", " %u/%u/%u"};
int i, j, num, nelem;
unsigned int aflags = 0;
+ const struct submesh *sub = cm->sublist;
if(!cmesh_has_attrib(cm, CMESH_ATTR_VERTEX)) {
return -1;
assert(numidx % 3 == 0);
for(i=0; i<numtri; i++) {
+ if(sub && sub->istart <= *idxptr) {
+ fprintf(fp, "o %s\n", sub->name);
+ sub = sub->next;
+ }
+
fputc('f', fp);
for(j=0; j<3; j++) {
unsigned int idx = *idxptr++ + 1 + voffs;
int numtri = cm->nverts / 3;
unsigned int idx = 1 + voffs;
for(i=0; i<numtri; i++) {
+ if(sub && sub->vstart == idx - 1) {
+ fprintf(fp, "o %s\n", sub->name);
+ sub = sub->next;
+ }
+
fputc('f', fp);
for(j=0; j<3; j++) {
fprintf(fp, fmtstr[aflags], idx, idx, idx);
struct cmesh;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* global state */
void cmesh_set_attrib_sdrloc(int attr, int loc);
int cmesh_get_attrib_sdrloc(int attr);
int cmesh_dump_obj(const struct cmesh *cm, const char *fname);
int cmesh_dump_obj_file(const struct cmesh *cm, FILE *fp, int voffs);
+#ifdef __cplusplus
+}
+#endif
#endif /* CMESH_H_ */