6 int dump(struct cmesh *cm);
8 int main(int argc, char **argv)
13 for(i=1; i<argc; i++) {
14 if(!(cm = cmesh_alloc())) {
15 perror("failed to allocate mesh");
18 if(cmesh_load(cm, argv[i]) == -1) {
19 fprintf(stderr, "failed to load: %s\n", argv[i]);
30 static int nverts, nidx, voffs;
31 static const float *varr, *narr, *tarr;
32 static unsigned int *iarr;
34 static int zcmp(const void *a, const void *b)
36 unsigned int *aidx = (unsigned int*)a;
37 unsigned int *bidx = (unsigned int*)b;
39 float az = varr[aidx[0] * 3 + 2] + varr[aidx[1] * 3 + 2] + varr[aidx[2] * 3 + 2];
40 float bz = varr[bidx[0] * 3 + 2] + varr[bidx[1] * 3 + 2] + varr[bidx[2] * 3 + 2];
45 int dump(struct cmesh *cm)
49 varr = cmesh_attrib_ro(cm, CMESH_ATTR_VERTEX);
50 narr = cmesh_attrib_ro(cm, CMESH_ATTR_NORMAL);
51 tarr = cmesh_attrib_ro(cm, CMESH_ATTR_TEXCOORD);
52 iarr = cmesh_index(cm);
53 nverts = cmesh_attrib_count(cm, CMESH_ATTR_VERTEX);
54 nidx = cmesh_index_count(cm);
56 qsort(iarr, nidx / 3, sizeof *iarr * 3, zcmp);
58 printf("static struct xvertex mesh[] = {\n");
59 for(i=0; i<nidx; i++) {
61 printf("\t{%7d, %7d, %7d,", (int)(varr[voffs] * 65536.0f),
62 (int)(varr[voffs + 1] * 65536.0f), -(int)(varr[voffs + 2] * 65536.0f));
63 printf(" %7d, %7d, %7d,", (int)(narr[voffs] * 65536.0f),
64 (int)(narr[voffs + 1] * 65536.0f), -(int)(narr[voffs + 2] * 65536.0f));
65 printf(" %7d, %7d,", (int)(tarr[voffs] * 65536.0f), (int)(tarr[voffs] * 65536.0f));
66 printf(" 0xff}%c\n", i < nidx - 1 ? ',' : '\n');