19 |
|
int |
20 |
|
findName(const char *nm, const char **nmlist, int n) |
21 |
|
{ |
22 |
< |
register int i; |
22 |
> |
int i; |
23 |
|
|
24 |
|
for (i = n; i-- > 0; ) |
25 |
|
if (!strcmp(nmlist[i], nm)) |
31 |
|
void |
32 |
|
clearSelection(Scene *sc, int set) |
33 |
|
{ |
34 |
< |
Face *f; |
34 |
> |
Face *f; |
35 |
|
|
36 |
|
for (f = sc->flist; f != NULL; f = f->next) |
37 |
|
if (set) |
44 |
|
void |
45 |
|
selectGroup(Scene *sc, const char *gname, int invert) |
46 |
|
{ |
47 |
< |
int gid = findName(gname, (const char **)sc->grpname, sc->ngrps); |
48 |
< |
Face *f; |
47 |
> |
int gid = getGroupID(sc, gname); |
48 |
> |
Face *f; |
49 |
|
|
50 |
|
if (gid < 0) |
51 |
|
return; |
62 |
|
void |
63 |
|
selectMaterial(Scene *sc, const char *mname, int invert) |
64 |
|
{ |
65 |
< |
int mid = findName(mname, (const char **)sc->matname, sc->nmats); |
66 |
< |
Face *f; |
65 |
> |
int mid = getMaterialID(sc, mname); |
66 |
> |
Face *f; |
67 |
|
|
68 |
|
if (mid < 0) |
69 |
|
return; |
80 |
|
void |
81 |
|
invertSelection(Scene *sc) |
82 |
|
{ |
83 |
< |
Face *f; |
83 |
> |
Face *f; |
84 |
|
|
85 |
|
for (f = sc->flist; f != NULL; f = f->next) |
86 |
|
f->flags ^= FACE_SELECTED; |
90 |
|
int |
91 |
|
numberSelected(Scene *sc) |
92 |
|
{ |
93 |
< |
int nsel = 0; |
94 |
< |
Face *f; |
93 |
> |
int nsel = 0; |
94 |
> |
Face *f; |
95 |
|
|
96 |
|
for (f = sc->flist; f != NULL; f = f->next) |
97 |
|
nsel += ((f->flags & FACE_SELECTED) != 0); |
103 |
|
foreachFace(Scene *sc, int (*cb)(Scene *, Face *, void *), |
104 |
|
int flreq, int flexc, void *c_data) |
105 |
|
{ |
106 |
< |
int fltest = flreq | flexc; |
107 |
< |
int sum = 0; |
108 |
< |
Face *f; |
106 |
> |
const int fltest = flreq | flexc; |
107 |
> |
int sum = 0; |
108 |
> |
Face *f; |
109 |
|
|
110 |
|
if ((sc == NULL) | (cb == NULL)) |
111 |
|
return(0); |
123 |
|
static int |
124 |
|
remFaceTexture(Scene *sc, Face *f, void *dummy) |
125 |
|
{ |
126 |
< |
int hadTexture = 0; |
127 |
< |
int i; |
126 |
> |
int hadTexture = 0; |
127 |
> |
int i; |
128 |
|
|
129 |
|
for (i = f->nv; i-- > 0; ) { |
130 |
|
if (f->v[i].tid < 0) |
146 |
|
static int |
147 |
|
remFaceNormal(Scene *sc, Face *f, void *dummy) |
148 |
|
{ |
149 |
< |
int hadNormal = 0; |
150 |
< |
int i; |
149 |
> |
int hadNormal = 0; |
150 |
> |
int i; |
151 |
|
|
152 |
|
for (i = f->nv; i-- > 0; ) { |
153 |
|
if (f->v[i].nid < 0) |
169 |
|
static int |
170 |
|
chngFaceGroup(Scene *sc, Face *f, void *ptr) |
171 |
|
{ |
172 |
< |
int grp = *(int *)ptr; |
172 |
> |
int grp = *(int *)ptr; |
173 |
> |
|
174 |
|
if (f->grp == grp) |
175 |
|
return(0); |
176 |
|
f->grp = grp; |
181 |
|
int |
182 |
|
changeGroup(Scene *sc, const char *gname, int flreq, int flexc) |
183 |
|
{ |
184 |
< |
int grp = findName(gname, (const char **)sc->grpname, sc->ngrps); |
184 |
> |
int grp = getGroupID(sc, gname); |
185 |
> |
|
186 |
|
if (grp < 0) { |
187 |
|
sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps); |
188 |
|
sc->grpname[grp=sc->ngrps++] = savqstr((char *)gname); |
194 |
|
static int |
195 |
|
chngFaceMaterial(Scene *sc, Face *f, void *ptr) |
196 |
|
{ |
197 |
< |
int mat = *(int *)ptr; |
197 |
> |
int mat = *(int *)ptr; |
198 |
> |
|
199 |
|
if (f->mat == mat) |
200 |
|
return(0); |
201 |
|
f->mat = mat; |
206 |
|
int |
207 |
|
changeMaterial(Scene *sc, const char *mname, int flreq, int flexc) |
208 |
|
{ |
209 |
< |
int mat = findName(mname, (const char **)sc->matname, sc->nmats); |
209 |
> |
int mat = getMaterialID(sc, mname); |
210 |
> |
|
211 |
|
if (mat < 0) { |
212 |
|
sc->matname = chunk_alloc(char *, sc->matname, sc->nmats); |
213 |
|
sc->matname[mat=sc->nmats++] = savqstr((char *)mname); |
252 |
|
static int |
253 |
|
replace_vertex(Scene *sc, int prev, int repl, double eps) |
254 |
|
{ |
255 |
< |
int repl_tex[10]; |
256 |
< |
int repl_norm[10]; |
257 |
< |
Face *f, *flast=NULL; |
258 |
< |
int i, j=0; |
255 |
> |
int repl_tex[10]; |
256 |
> |
int repl_norm[10]; |
257 |
> |
Face *f, *flast=NULL; |
258 |
> |
int i, j=0; |
259 |
|
/* check to see if it's even used */ |
260 |
|
if (sc->vert[prev].vflist == NULL) |
261 |
|
return(0); |
263 |
|
repl_tex[0] = -1; |
264 |
|
for (f = sc->vert[repl].vflist; f != NULL; f = f->v[j].fnext) { |
265 |
|
/* make sure prev isn't in there */ |
266 |
< |
for (j = 0; j < f->nv; j++) |
266 |
> |
for (j = f->nv; j-- > 0; ) |
267 |
|
if (f->v[j].vid == prev) |
268 |
|
return(0); |
269 |
< |
for (j = 0; j < f->nv; j++) |
269 |
> |
for (j = f->nv; j-- > 0; ) |
270 |
|
if (f->v[j].vid == repl) |
271 |
|
break; |
272 |
< |
if (j >= f->nv) |
272 |
> |
if (j < 0) |
273 |
|
goto linkerr; |
274 |
|
if (f->v[j].tid < 0) |
275 |
|
continue; |
294 |
|
/* get replacement normals */ |
295 |
|
repl_norm[0] = -1; |
296 |
|
for (f = sc->vert[repl].vflist; f != NULL; f = f->v[j].fnext) { |
297 |
< |
for (j = 0; j < f->nv; j++) |
297 |
> |
for (j = f->nv; j-- > 0; ) |
298 |
|
if (f->v[j].vid == repl) |
299 |
|
break; |
300 |
|
if (f->v[j].nid < 0) |
319 |
|
} |
320 |
|
/* replace occurrences of vertex */ |
321 |
|
for (f = sc->vert[prev].vflist; f != NULL; f = f->v[j].fnext) { |
322 |
< |
for (j = 0; j < f->nv; j++) |
322 |
> |
for (j = f->nv; j-- > 0; ) |
323 |
|
if (f->v[j].vid == prev) |
324 |
|
break; |
325 |
< |
if (j >= f->nv) |
325 |
> |
if (j < 0) |
326 |
|
goto linkerr; |
327 |
|
/* XXX doesn't allow for multiple references to prev in face */ |
328 |
|
f->v[j].vid = repl; /* replace vertex itself */ |
329 |
< |
if (faceArea(sc, f, NULL) <= FTINY) |
329 |
> |
if (faceArea(sc, f, NULL) <= FTINY*FTINY) |
330 |
|
f->flags |= FACE_DEGENERATE; |
331 |
|
if (f->v[j].tid >= 0) /* replace texture if appropriate */ |
332 |
|
for (i = 0; repl_tex[i] >= 0; i++) { |
364 |
|
int |
365 |
|
coalesceVertices(Scene *sc, double eps) |
366 |
|
{ |
367 |
< |
int nelim = 0; |
368 |
< |
LUTAB myLookup; |
369 |
< |
LUENT *le; |
370 |
< |
char vertfmt[32], vertbuf[64]; |
371 |
< |
double d; |
372 |
< |
int i; |
367 |
> |
int nelim = 0; |
368 |
> |
LUTAB myLookup; |
369 |
> |
LUENT *le; |
370 |
> |
char vertfmt[32], vertbuf[64]; |
371 |
> |
double d; |
372 |
> |
int i; |
373 |
|
|
374 |
|
if (eps >= 1.) |
375 |
|
return(0); |
416 |
|
int |
417 |
|
findDuplicateFaces(Scene *sc) |
418 |
|
{ |
419 |
< |
int nchecked = 0; |
420 |
< |
int nfound = 0; |
421 |
< |
Face *f, *f1; |
422 |
< |
int vid; |
423 |
< |
int i, j; |
419 |
> |
int nchecked = 0; |
420 |
> |
int nfound = 0; |
421 |
> |
Face *f, *f1; |
422 |
> |
int vid; |
423 |
> |
int i, j; |
424 |
|
/* start fresh */ |
425 |
|
for (f = sc->flist; f != NULL; f = f->next) |
426 |
|
f->flags &= ~FACE_DUPLICATE; |
436 |
|
/* look for duplicates */ |
437 |
|
for (f1 = sc->vert[vid].vflist; f1 != NULL; |
438 |
|
f1 = f1->v[j].fnext) { |
439 |
< |
for (j = 0; j < f1->nv; j++) |
439 |
> |
for (j = f1->nv; j-- > 0; ) |
440 |
|
if (f1->v[j].vid == vid) |
441 |
|
break; |
442 |
< |
if (j >= f1->nv) |
442 |
> |
if (j < 0) |
443 |
|
break; /* missing link! */ |
444 |
|
if (f1 == f) |
445 |
|
continue; /* shouldn't happen */ |
464 |
|
++nfound; |
465 |
|
} |
466 |
|
} |
467 |
+ |
if (verbose) |
468 |
+ |
fprintf(stderr, "Found %d duplicate faces\n", nfound); |
469 |
|
return(nfound); |
470 |
|
} |
471 |
|
|
473 |
|
int |
474 |
|
deleteFaces(Scene *sc, int flreq, int flexc) |
475 |
|
{ |
476 |
< |
int fltest = flreq | flexc; |
477 |
< |
int orig_nfaces = sc->nfaces; |
478 |
< |
Face fhead; |
479 |
< |
Face *f, *ftst; |
476 |
> |
const int fltest = flreq | flexc; |
477 |
> |
int orig_nfaces = sc->nfaces; |
478 |
> |
Face fhead; |
479 |
> |
Face *f, *ftst; |
480 |
|
|
481 |
|
fhead.next = sc->flist; |
482 |
|
f = &fhead; |
492 |
|
continue; |
493 |
|
} |
494 |
|
while (vf != NULL) { |
495 |
< |
for (j = 0; j < vf->nv; j++) |
495 |
> |
for (j = vf->nv; j-- > 0; ) |
496 |
|
if (vf->v[j].vid == vid) |
497 |
|
break; |
498 |
< |
if (j >= vf->nv) |
498 |
> |
if (j < 0) |
499 |
|
break; /* error */ |
500 |
|
if (vf->v[j].fnext == ftst) { |
501 |
|
vf->v[j].fnext = |
553 |
|
sc->descr[sc->ndescr++] = savqstr((char *)comment); |
554 |
|
} |
555 |
|
|
556 |
+ |
/* Find index for comment containing the given string (starting from n) */ |
557 |
+ |
int |
558 |
+ |
findComment(Scene *sc, const char *match, int n) |
559 |
+ |
{ |
560 |
+ |
if (n >= sc->ndescr) |
561 |
+ |
return(-1); |
562 |
+ |
n *= (n > 0); |
563 |
+ |
while (n < sc->ndescr) |
564 |
+ |
if (strstr(sc->descr[n], match) != NULL) |
565 |
+ |
return(n); |
566 |
+ |
return(-1); |
567 |
+ |
} |
568 |
+ |
|
569 |
|
/* Clear comments */ |
570 |
|
void |
571 |
|
clearComments(Scene *sc) |
592 |
|
for ( ; ; ) { /* else find position */ |
593 |
|
if (fp == f) |
594 |
|
return; /* already in list */ |
595 |
< |
for (j = 0; j < fp->nv; j++) |
595 |
> |
for (j = fp->nv; j-- > 0; ) |
596 |
|
if (fp->v[j].vid == vid) |
597 |
|
break; |
598 |
< |
if (j >= fp->nv) |
598 |
> |
if (j < 0) |
599 |
|
error(CONSISTENCY, "Link error in add2facelist()"); |
600 |
|
if (fp->v[j].fnext == NULL) |
601 |
|
break; /* reached the end */ |
608 |
|
Scene * |
609 |
|
newScene(void) |
610 |
|
{ |
611 |
< |
Scene *sc = (Scene *)ecalloc(1, sizeof(Scene)); |
611 |
> |
Scene *sc = (Scene *)ecalloc(1, sizeof(Scene)); |
612 |
|
/* default group & material */ |
613 |
|
sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps); |
614 |
|
sc->grpname[sc->ngrps++] = savqstr("DEFAULT_GROUP"); |
644 |
|
int |
645 |
|
addNormal(Scene *sc, double xn, double yn, double zn) |
646 |
|
{ |
647 |
< |
FVECT nrm; |
647 |
> |
FVECT nrm; |
648 |
|
|
649 |
|
nrm[0] = xn; nrm[1] = yn; nrm[2] = zn; |
650 |
|
if (normalize(nrm) == .0) |
658 |
|
void |
659 |
|
setGroup(Scene *sc, const char *nm) |
660 |
|
{ |
661 |
< |
sc->lastgrp = findName(nm, (const char **)sc->grpname, sc->ngrps); |
661 |
> |
sc->lastgrp = getGroupID(sc, nm); |
662 |
|
if (sc->lastgrp >= 0) |
663 |
|
return; |
664 |
|
sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps); |
669 |
|
void |
670 |
|
setMaterial(Scene *sc, const char *nm) |
671 |
|
{ |
672 |
< |
sc->lastmat = findName(nm, (const char **)sc->matname, sc->nmats); |
672 |
> |
sc->lastmat = getMaterialID(sc, nm); |
673 |
|
if (sc->lastmat >= 0) |
674 |
|
return; |
675 |
|
sc->matname = chunk_alloc(char *, sc->matname, sc->nmats); |
680 |
|
Face * |
681 |
|
addFace(Scene *sc, VNDX vid[], int nv) |
682 |
|
{ |
683 |
< |
Face *f; |
684 |
< |
int i; |
683 |
> |
Face *f; |
684 |
> |
int i; |
685 |
|
|
686 |
|
if (nv < 3) |
687 |
|
return(NULL); |
709 |
|
sc->flist = f; |
710 |
|
sc->nfaces++; |
711 |
|
/* check face area */ |
712 |
< |
if (!(f->flags & FACE_DEGENERATE) && faceArea(sc, f, NULL) <= FTINY) |
712 |
> |
if (!(f->flags & FACE_DEGENERATE) && faceArea(sc, f, NULL) <= FTINY*FTINY) |
713 |
|
f->flags |= FACE_DEGENERATE; |
714 |
|
return(f); |
715 |
|
} |
716 |
|
|
717 |
< |
/* Duplicate a scene */ |
717 |
> |
/* Duplicate a scene, optionally selecting faces */ |
718 |
|
Scene * |
719 |
< |
dupScene(const Scene *osc) |
719 |
> |
dupScene(const Scene *osc, int flreq, int flexc) |
720 |
|
{ |
721 |
+ |
int fltest = flreq | flexc; |
722 |
|
Scene *sc; |
723 |
|
const Face *fo; |
724 |
|
Face *f; |
767 |
|
sc->nnorms = osc->nnorms; |
768 |
|
} |
769 |
|
for (fo = osc->flist; fo != NULL; fo = fo->next) { |
770 |
+ |
if ((fo->flags & fltest) != flreq) |
771 |
+ |
continue; |
772 |
|
f = (Face *)emalloc(sizeof(Face) + |
773 |
|
sizeof(VertEnt)*(fo->nv-3)); |
774 |
|
memcpy((void *)f, (const void *)fo, sizeof(Face) + |
779 |
|
sc->flist = f; |
780 |
|
sc->nfaces++; |
781 |
|
} |
782 |
+ |
deleteUnreferenced(sc); /* jetsam */ |
783 |
|
return(sc); |
784 |
|
} |
785 |
|
|
786 |
+ |
/* Add one scene to another, not checking for redundancies */ |
787 |
+ |
int |
788 |
+ |
addScene(Scene *scdst, const Scene *scsrc) |
789 |
+ |
{ |
790 |
+ |
VNDX my_vlist[4]; |
791 |
+ |
int *vert_map = NULL; |
792 |
+ |
int *norm_map = NULL; |
793 |
+ |
int *tex_map = NULL; |
794 |
+ |
VNDX *vlist = my_vlist; |
795 |
+ |
int vllen = sizeof(my_vlist)/sizeof(VNDX); |
796 |
+ |
int cur_mat = 0; |
797 |
+ |
int cur_grp = 0; |
798 |
+ |
int fcnt = 0; |
799 |
+ |
const Face *f; |
800 |
+ |
int i; |
801 |
+ |
|
802 |
+ |
if ((scdst == NULL) | (scsrc == NULL)) |
803 |
+ |
return(-1); |
804 |
+ |
if (scsrc->nfaces <= 0) |
805 |
+ |
return(0); |
806 |
+ |
/* map vertices */ |
807 |
+ |
vert_map = (int *)emalloc(sizeof(int *)*scsrc->nverts); |
808 |
+ |
for (i = 0; i < scsrc->nverts; i++) { |
809 |
+ |
const Vertex *v = scsrc->vert + i; |
810 |
+ |
if (v->vflist == NULL) { |
811 |
+ |
vert_map[i] = -1; |
812 |
+ |
continue; |
813 |
+ |
} |
814 |
+ |
vert_map[i] = addVertex(scdst, v->p[0], v->p[1], v->p[2]); |
815 |
+ |
} |
816 |
+ |
if (scsrc->ntex > 0) /* map texture coords */ |
817 |
+ |
tex_map = (int *)emalloc(sizeof(int *)*scsrc->ntex); |
818 |
+ |
for (i = 0; i < scsrc->ntex; i++) { |
819 |
+ |
const TexCoord *t = scsrc->tex + i; |
820 |
+ |
tex_map[i] = addTexture(scdst, t->u, t->v); |
821 |
+ |
} |
822 |
+ |
if (scsrc->nnorms > 0) /* map normals */ |
823 |
+ |
norm_map = (int *)emalloc(sizeof(int *)*scsrc->nnorms); |
824 |
+ |
for (i = 0; i < scsrc->nnorms; i++) { |
825 |
+ |
const float *n = scsrc->norm[i]; |
826 |
+ |
norm_map[i] = addNormal(scdst, n[0], n[1], n[2]); |
827 |
+ |
} |
828 |
+ |
/* add faces */ |
829 |
+ |
scdst->lastgrp = scdst->lastmat = 0; |
830 |
+ |
for (f = scsrc->flist; f != NULL; f = f->next) { |
831 |
+ |
if (f->grp != cur_grp) |
832 |
+ |
setGroup(scdst, scsrc->grpname[cur_grp = f->grp]); |
833 |
+ |
if (f->mat != cur_mat) |
834 |
+ |
setMaterial(scdst, scsrc->matname[cur_mat = f->mat]); |
835 |
+ |
if (f->nv > vllen) { |
836 |
+ |
if (vlist == my_vlist) |
837 |
+ |
vlist = (VNDX *)emalloc( |
838 |
+ |
sizeof(VNDX)*(vllen = f->nv)); |
839 |
+ |
else |
840 |
+ |
vlist = (VNDX *)erealloc((char *)vlist, |
841 |
+ |
sizeof(VNDX)*(vllen = f->nv)); |
842 |
+ |
} |
843 |
+ |
memset(vlist, 0xff, sizeof(VNDX)*f->nv); |
844 |
+ |
for (i = f->nv; i-- > 0; ) { |
845 |
+ |
if (f->v[i].vid >= 0) |
846 |
+ |
vlist[i][0] = vert_map[f->v[i].vid]; |
847 |
+ |
if (f->v[i].tid >= 0) |
848 |
+ |
vlist[i][1] = tex_map[f->v[i].tid]; |
849 |
+ |
if (f->v[i].nid >= 0) |
850 |
+ |
vlist[i][2] = norm_map[f->v[i].nid]; |
851 |
+ |
} |
852 |
+ |
fcnt += (addFace(scdst, vlist, f->nv) != NULL); |
853 |
+ |
} |
854 |
+ |
/* clean up */ |
855 |
+ |
if (vlist != my_vlist) efree((char *)vlist); |
856 |
+ |
if (norm_map != NULL) efree((char *)norm_map); |
857 |
+ |
if (tex_map != NULL) efree((char *)tex_map); |
858 |
+ |
efree((char *)vert_map); |
859 |
+ |
return(fcnt); |
860 |
+ |
} |
861 |
+ |
|
862 |
+ |
#define MAXAC 100 |
863 |
+ |
|
864 |
|
/* Transform entire scene */ |
865 |
|
int |
866 |
|
xfScene(Scene *sc, int xac, char *xav[]) |
867 |
|
{ |
868 |
+ |
char comm[24+MAXAC*8]; |
869 |
+ |
char *cp; |
870 |
|
XF myxf; |
871 |
|
FVECT vec; |
872 |
|
int i; |
889 |
|
vec[0] /= myxf.sca; vec[1] /= myxf.sca; vec[2] /= myxf.sca; |
890 |
|
VCOPY(sc->norm[i], vec); |
891 |
|
} |
892 |
+ |
/* add comment */ |
893 |
+ |
cp = strcpy(comm, "Transformed by:"); |
894 |
+ |
for (i = 0; i < xac; i++) { |
895 |
+ |
while (*cp) cp++; |
896 |
+ |
*cp++ = ' '; |
897 |
+ |
strcpy(cp, xav[i]); |
898 |
+ |
} |
899 |
+ |
addComment(sc, comm); |
900 |
|
return(xac); /* all done */ |
901 |
|
} |
902 |
|
|
903 |
|
/* Ditto, using transform string rather than pre-parsed words */ |
793 |
– |
#define MAXAC 100 |
904 |
|
int |
905 |
|
xfmScene(Scene *sc, const char *xfm) |
906 |
|
{ |
915 |
|
if (!*xfm) |
916 |
|
return(0); |
917 |
|
/* parse string into words */ |
918 |
< |
xav[0] = strcpy((char *)malloc(strlen(xfm)+1), xfm); |
918 |
> |
xav[0] = strcpy((char *)emalloc(strlen(xfm)+1), xfm); |
919 |
|
xac = 1; i = 0; |
920 |
|
for ( ; ; ) { |
921 |
|
while (!isspace(xfm[++i])) |
933 |
|
} |
934 |
|
xav[xac] = NULL; |
935 |
|
i = xfScene(sc, xac, xav); |
936 |
< |
free(xav[0]); |
936 |
> |
efree((char *)xav[0]); |
937 |
|
return(i); |
938 |
|
} |
939 |
|
#undef MAXAC |
940 |
+ |
|
941 |
+ |
/* Delete unreferenced vertices, normals, texture coords */ |
942 |
+ |
void |
943 |
+ |
deleteUnreferenced(Scene *sc) |
944 |
+ |
{ |
945 |
+ |
int *vmap; |
946 |
+ |
Face *f; |
947 |
+ |
int nused, i; |
948 |
+ |
/* allocate index map */ |
949 |
+ |
if (!sc->nverts) |
950 |
+ |
return; |
951 |
+ |
i = sc->nverts; |
952 |
+ |
if (sc->ntex > i) |
953 |
+ |
i = sc->ntex; |
954 |
+ |
if (sc->nnorms > i) |
955 |
+ |
i = sc->nnorms; |
956 |
+ |
vmap = (int *)emalloc(sizeof(int)*i); |
957 |
+ |
/* remap positions */ |
958 |
+ |
for (i = nused = 0; i < sc->nverts; i++) { |
959 |
+ |
if (sc->vert[i].vflist == NULL) { |
960 |
+ |
vmap[i] = -1; |
961 |
+ |
continue; |
962 |
+ |
} |
963 |
+ |
if (nused != i) |
964 |
+ |
sc->vert[nused] = sc->vert[i]; |
965 |
+ |
vmap[i] = nused++; |
966 |
+ |
} |
967 |
+ |
if (nused == sc->nverts) |
968 |
+ |
goto skip_pos; |
969 |
+ |
sc->vert = (Vertex *)erealloc((char *)sc->vert, |
970 |
+ |
sizeof(Vertex)*(nused+(CHUNKSIZ-1))); |
971 |
+ |
sc->nverts = nused; |
972 |
+ |
for (f = sc->flist; f != NULL; f = f->next) |
973 |
+ |
for (i = f->nv; i--; ) |
974 |
+ |
if ((f->v[i].vid = vmap[f->v[i].vid]) < 0) |
975 |
+ |
error(CONSISTENCY, |
976 |
+ |
"Link error in del_unref_verts()"); |
977 |
+ |
skip_pos: |
978 |
+ |
/* remap texture coord's */ |
979 |
+ |
if (!sc->ntex) |
980 |
+ |
goto skip_tex; |
981 |
+ |
memset((void *)vmap, 0, sizeof(int)*sc->ntex); |
982 |
+ |
for (f = sc->flist; f != NULL; f = f->next) |
983 |
+ |
for (i = f->nv; i--; ) |
984 |
+ |
if (f->v[i].tid >= 0) |
985 |
+ |
vmap[f->v[i].tid] = 1; |
986 |
+ |
for (i = nused = 0; i < sc->ntex; i++) { |
987 |
+ |
if (!vmap[i]) |
988 |
+ |
continue; |
989 |
+ |
if (nused != i) |
990 |
+ |
sc->tex[nused] = sc->tex[i]; |
991 |
+ |
vmap[i] = nused++; |
992 |
+ |
} |
993 |
+ |
if (nused == sc->ntex) |
994 |
+ |
goto skip_tex; |
995 |
+ |
sc->tex = (TexCoord *)erealloc((char *)sc->tex, |
996 |
+ |
sizeof(TexCoord)*(nused+(CHUNKSIZ-1))); |
997 |
+ |
sc->ntex = nused; |
998 |
+ |
for (f = sc->flist; f != NULL; f = f->next) |
999 |
+ |
for (i = f->nv; i--; ) |
1000 |
+ |
if (f->v[i].tid >= 0) |
1001 |
+ |
f->v[i].tid = vmap[f->v[i].tid]; |
1002 |
+ |
skip_tex: |
1003 |
+ |
/* remap normals */ |
1004 |
+ |
if (!sc->nnorms) |
1005 |
+ |
goto skip_norms; |
1006 |
+ |
memset((void *)vmap, 0, sizeof(int)*sc->nnorms); |
1007 |
+ |
for (f = sc->flist; f != NULL; f = f->next) |
1008 |
+ |
for (i = f->nv; i--; ) |
1009 |
+ |
if (f->v[i].nid >= 0) |
1010 |
+ |
vmap[f->v[i].nid] = 1; |
1011 |
+ |
for (i = nused = 0; i < sc->nnorms; i++) { |
1012 |
+ |
if (!vmap[i]) |
1013 |
+ |
continue; |
1014 |
+ |
if (nused != i) |
1015 |
+ |
memcpy((void *)sc->norm[nused], |
1016 |
+ |
(void *)sc->norm[i], |
1017 |
+ |
sizeof(Normal)); |
1018 |
+ |
vmap[i] = nused++; |
1019 |
+ |
} |
1020 |
+ |
if (nused == sc->nnorms) |
1021 |
+ |
goto skip_norms; |
1022 |
+ |
sc->norm = (Normal *)erealloc((char *)sc->norm, |
1023 |
+ |
sizeof(Normal)*(nused+(CHUNKSIZ-1))); |
1024 |
+ |
sc->nnorms = nused; |
1025 |
+ |
for (f = sc->flist; f != NULL; f = f->next) |
1026 |
+ |
for (i = f->nv; i--; ) |
1027 |
+ |
if (f->v[i].nid >= 0) |
1028 |
+ |
f->v[i].nid = vmap[f->v[i].nid]; |
1029 |
+ |
skip_norms: |
1030 |
+ |
/* clean up */ |
1031 |
+ |
efree((char *)vmap); |
1032 |
+ |
} |
1033 |
|
|
1034 |
|
/* Free a scene */ |
1035 |
|
void |