| 506 |
|
} |
| 507 |
|
} |
| 508 |
|
f->next = ftst->next; /* remove from scene list */ |
| 509 |
< |
efree((char *)ftst); |
| 509 |
> |
efree(ftst); |
| 510 |
|
sc->nfaces--; |
| 511 |
|
} else |
| 512 |
|
f = f->next; |
| 572 |
|
{ |
| 573 |
|
while (sc->ndescr > 0) |
| 574 |
|
freeqstr(sc->descr[--sc->ndescr]); |
| 575 |
< |
efree((char *)sc->descr); |
| 575 |
> |
efree(sc->descr); |
| 576 |
> |
sc->descr = NULL; |
| 577 |
|
sc->ndescr = 0; |
| 578 |
|
} |
| 579 |
|
|
| 701 |
|
return(f); |
| 702 |
|
} |
| 703 |
|
|
| 704 |
+ |
/* Get neighbor vertices: malloc array with valence in index[0] */ |
| 705 |
+ |
int * |
| 706 |
+ |
getVertexNeighbors(Scene *sc, int vid) |
| 707 |
+ |
{ |
| 708 |
+ |
int *varr; |
| 709 |
+ |
Face *f; |
| 710 |
+ |
int j=0; |
| 711 |
+ |
|
| 712 |
+ |
if (sc == NULL || (vid < 0) | (vid >= sc->nverts) || |
| 713 |
+ |
(f = sc->vert[vid].vflist) == NULL) |
| 714 |
+ |
return(NULL); |
| 715 |
+ |
|
| 716 |
+ |
varr = (int *)emalloc(sizeof(int)*CHUNKSIZ); |
| 717 |
+ |
varr[0] = 0; /* add unique neighbors */ |
| 718 |
+ |
for ( ; f != NULL; f = f->v[j].fnext) { |
| 719 |
+ |
int i, cvi; |
| 720 |
+ |
for (j = f->nv; j--; ) /* find ourself in poly */ |
| 721 |
+ |
if (f->v[j].vid == vid) |
| 722 |
+ |
break; |
| 723 |
+ |
if (j < 0) /* this is an error */ |
| 724 |
+ |
break; |
| 725 |
+ |
if (f->nv < 3) /* also never happens */ |
| 726 |
+ |
continue; |
| 727 |
+ |
/* check previous neighbor */ |
| 728 |
+ |
cvi = f->v[ (j > 0) ? j-1 : f->nv-1 ].vid; |
| 729 |
+ |
for (i = varr[0]+1; --i; ) /* making sure not in list */ |
| 730 |
+ |
if (varr[i] == cvi) |
| 731 |
+ |
break; |
| 732 |
+ |
if (!i) { /* new neighbor? */ |
| 733 |
+ |
varr = chunk_alloc(int, varr, varr[0]+1); |
| 734 |
+ |
varr[++varr[0]] = cvi; |
| 735 |
+ |
} |
| 736 |
+ |
/* check next neighbor */ |
| 737 |
+ |
cvi = f->v[ (j < f->nv-1) ? j+1 : 0 ].vid; |
| 738 |
+ |
for (i = varr[0]+1; --i; ) |
| 739 |
+ |
if (varr[i] == cvi) |
| 740 |
+ |
break; |
| 741 |
+ |
if (!i) { |
| 742 |
+ |
varr = chunk_alloc(int, varr, varr[0]+1); |
| 743 |
+ |
varr[++varr[0]] = cvi; |
| 744 |
+ |
} |
| 745 |
+ |
} |
| 746 |
+ |
if (!varr[0]) { |
| 747 |
+ |
efree(varr); /* something went awry */ |
| 748 |
+ |
return(NULL); |
| 749 |
+ |
} |
| 750 |
+ |
/* tighten array & return */ |
| 751 |
+ |
return((int *)erealloc(varr, sizeof(int)*(varr[0]+1))); |
| 752 |
+ |
} |
| 753 |
+ |
|
| 754 |
+ |
/* Callback for growBoundingBox() */ |
| 755 |
+ |
static int |
| 756 |
+ |
addBBox(Scene *sc, Face *f, void *p) |
| 757 |
+ |
{ |
| 758 |
+ |
double (*bbox)[3] = (double (*)[3])p; |
| 759 |
+ |
int i, j; |
| 760 |
+ |
|
| 761 |
+ |
for (i = f->nv; i-- > 0; ) { |
| 762 |
+ |
double *p3 = sc->vert[f->v[i].vid].p; |
| 763 |
+ |
for (j = 3; j--; ) { |
| 764 |
+ |
if (p3[j] < bbox[0][j]) |
| 765 |
+ |
bbox[0][j] = p3[j]; |
| 766 |
+ |
if (p3[j] > bbox[1][j]) |
| 767 |
+ |
bbox[1][j] = p3[j]; |
| 768 |
+ |
} |
| 769 |
+ |
} |
| 770 |
+ |
return(1); |
| 771 |
+ |
} |
| 772 |
+ |
|
| 773 |
+ |
/* Expand bounding box min & max (initialize bbox to all zeroes) */ |
| 774 |
+ |
int |
| 775 |
+ |
growBoundingBox(Scene *sc, double bbox[2][3], int flreq, int flexc) |
| 776 |
+ |
{ |
| 777 |
+ |
if (sc == NULL || sc->nfaces <= 0 || bbox == NULL) |
| 778 |
+ |
return(0); |
| 779 |
+ |
|
| 780 |
+ |
if (VABSEQ(bbox[0], bbox[1])) { /* first run */ |
| 781 |
+ |
bbox[0][0] = bbox[0][1] = bbox[0][2] = FHUGE; |
| 782 |
+ |
bbox[1][0] = bbox[1][1] = bbox[1][2] = -FHUGE; |
| 783 |
+ |
} |
| 784 |
+ |
return(foreachFace(sc, addBBox, flreq, flexc, bbox)); |
| 785 |
+ |
} |
| 786 |
+ |
|
| 787 |
|
/* Allocate an empty scene */ |
| 788 |
|
Scene * |
| 789 |
|
newScene(void) |
| 814 |
|
for (i = 0; i < osc->ndescr; i++) |
| 815 |
|
addComment(sc, osc->descr[i]); |
| 816 |
|
if (osc->ngrps > 1) { |
| 817 |
< |
sc->grpname = (char **)erealloc((char *)sc->grpname, |
| 817 |
> |
sc->grpname = (char **)erealloc(sc->grpname, |
| 818 |
|
sizeof(char *) * (osc->ngrps+(CHUNKSIZ-1))); |
| 819 |
|
for (i = 1; i < osc->ngrps; i++) |
| 820 |
|
sc->grpname[i] = savqstr(osc->grpname[i]); |
| 821 |
|
sc->ngrps = osc->ngrps; |
| 822 |
|
} |
| 823 |
|
if (osc->nmats > 1) { |
| 824 |
< |
sc->matname = (char **)erealloc((char *)sc->matname, |
| 824 |
> |
sc->matname = (char **)erealloc(sc->matname, |
| 825 |
|
sizeof(char *) * (osc->nmats+(CHUNKSIZ-1))); |
| 826 |
|
for (i = 1; i < osc->nmats; i++) |
| 827 |
|
sc->matname[i] = savqstr(osc->matname[i]); |
| 883 |
|
if (scsrc->nfaces <= 0) |
| 884 |
|
return(0); |
| 885 |
|
/* map vertices */ |
| 886 |
< |
vert_map = (int *)emalloc(sizeof(int *)*scsrc->nverts); |
| 886 |
> |
vert_map = (int *)emalloc(sizeof(int)*scsrc->nverts); |
| 887 |
|
for (i = 0; i < scsrc->nverts; i++) { |
| 888 |
|
const Vertex *v = scsrc->vert + i; |
| 889 |
|
if (v->vflist == NULL) { |
| 894 |
|
} |
| 895 |
|
tex_off = scdst->ntex; /* append texture coords */ |
| 896 |
|
if (scsrc->ntex > 0) { |
| 897 |
< |
scdst->tex = (TexCoord *)erealloc((char *)scdst->tex, |
| 897 |
> |
scdst->tex = (TexCoord *)erealloc(scdst->tex, |
| 898 |
|
sizeof(TexCoord)*(tex_off+scsrc->ntex+(CHUNKSIZ-1))); |
| 899 |
|
memcpy(scdst->tex+tex_off, scsrc->tex, |
| 900 |
|
sizeof(TexCoord)*scsrc->ntex); |
| 901 |
|
} |
| 902 |
|
norm_off = scdst->nnorms; /* append normals */ |
| 903 |
|
if (scsrc->nnorms > 0) { |
| 904 |
< |
scdst->norm = (Normal *)erealloc((char *)scdst->norm, |
| 904 |
> |
scdst->norm = (Normal *)erealloc(scdst->norm, |
| 905 |
|
sizeof(Normal)*(norm_off+scsrc->nnorms+(CHUNKSIZ-1))); |
| 906 |
|
memcpy(scdst->norm+norm_off, scsrc->norm, |
| 907 |
|
sizeof(Normal)*scsrc->nnorms); |
| 914 |
|
if (f->mat != cur_mat) |
| 915 |
|
setMaterial(scdst, scsrc->matname[cur_mat = f->mat]); |
| 916 |
|
if (f->nv > vllen) { |
| 917 |
< |
if (vlist == my_vlist) |
| 918 |
< |
vlist = (VNDX *)emalloc( |
| 919 |
< |
sizeof(VNDX)*(vllen = f->nv)); |
| 920 |
< |
else |
| 837 |
< |
vlist = (VNDX *)erealloc((char *)vlist, |
| 838 |
< |
sizeof(VNDX)*(vllen = f->nv)); |
| 917 |
> |
vlist = (VNDX *)( vlist == my_vlist ? |
| 918 |
> |
emalloc(sizeof(VNDX)*f->nv) : |
| 919 |
> |
erealloc(vlist, sizeof(VNDX)*f->nv) ); |
| 920 |
> |
vllen = f->nv; |
| 921 |
|
} |
| 922 |
|
memset(vlist, 0xff, sizeof(VNDX)*f->nv); |
| 923 |
|
for (i = f->nv; i-- > 0; ) { |
| 931 |
|
fcnt += (addFace(scdst, vlist, f->nv) != NULL); |
| 932 |
|
} |
| 933 |
|
/* clean up */ |
| 934 |
< |
if (vlist != my_vlist) efree((char *)vlist); |
| 935 |
< |
efree((char *)vert_map); |
| 934 |
> |
if (vlist != my_vlist) efree(vlist); |
| 935 |
> |
efree(vert_map); |
| 936 |
|
return(fcnt); |
| 937 |
|
} |
| 938 |
|
|
| 992 |
|
if (!*xfm) |
| 993 |
|
return(0); |
| 994 |
|
/* parse string into words */ |
| 995 |
< |
xav[0] = strcpy((char *)emalloc(strlen(xfm)+1), xfm); |
| 995 |
> |
xav[0] = savqstr((char *)xfm); |
| 996 |
|
xac = 1; i = 0; |
| 997 |
|
for ( ; ; ) { |
| 998 |
|
while (!isspace(xfm[++i])) |
| 1003 |
|
if (!xfm[i]) |
| 1004 |
|
break; |
| 1005 |
|
if (xac >= MAXAC-1) { |
| 1006 |
< |
free(xav[0]); |
| 1006 |
> |
freeqstr(xav[0]); |
| 1007 |
|
return(0); |
| 1008 |
|
} |
| 1009 |
|
xav[xac++] = xav[0] + i; |
| 1010 |
|
} |
| 1011 |
|
xav[xac] = NULL; |
| 1012 |
|
i = xfScene(sc, xac, xav); |
| 1013 |
< |
efree((char *)xav[0]); |
| 1013 |
> |
freeqstr(xav[0]); |
| 1014 |
|
return(i); |
| 1015 |
|
} |
| 1016 |
|
#undef MAXAC |
| 1043 |
|
} |
| 1044 |
|
if (nused == sc->nverts) |
| 1045 |
|
goto skip_pos; |
| 1046 |
< |
sc->vert = (Vertex *)erealloc((char *)sc->vert, |
| 1046 |
> |
sc->vert = (Vertex *)erealloc(sc->vert, |
| 1047 |
|
sizeof(Vertex)*(nused+(CHUNKSIZ-1))); |
| 1048 |
|
sc->nverts = nused; |
| 1049 |
|
for (f = sc->flist; f != NULL; f = f->next) |
| 1069 |
|
} |
| 1070 |
|
if (nused == sc->ntex) |
| 1071 |
|
goto skip_tex; |
| 1072 |
< |
sc->tex = (TexCoord *)erealloc((char *)sc->tex, |
| 1072 |
> |
sc->tex = (TexCoord *)erealloc(sc->tex, |
| 1073 |
|
sizeof(TexCoord)*(nused+(CHUNKSIZ-1))); |
| 1074 |
|
sc->ntex = nused; |
| 1075 |
|
for (f = sc->flist; f != NULL; f = f->next) |
| 1094 |
|
} |
| 1095 |
|
if (nused == sc->nnorms) |
| 1096 |
|
goto skip_norms; |
| 1097 |
< |
sc->norm = (Normal *)erealloc((char *)sc->norm, |
| 1097 |
> |
sc->norm = (Normal *)erealloc(sc->norm, |
| 1098 |
|
sizeof(Normal)*(nused+(CHUNKSIZ-1))); |
| 1099 |
|
sc->nnorms = nused; |
| 1100 |
|
for (f = sc->flist; f != NULL; f = f->next) |
| 1103 |
|
f->v[i].nid = vmap[f->v[i].nid]; |
| 1104 |
|
skip_norms: |
| 1105 |
|
/* clean up */ |
| 1106 |
< |
efree((char *)vmap); |
| 1106 |
> |
efree(vmap); |
| 1107 |
|
} |
| 1108 |
|
|
| 1109 |
|
/* Free a scene */ |
| 1118 |
|
clearComments(sc); |
| 1119 |
|
for (i = sc->ngrps; i-- > 0; ) |
| 1120 |
|
freeqstr(sc->grpname[i]); |
| 1121 |
< |
efree((char *)sc->grpname); |
| 1121 |
> |
efree(sc->grpname); |
| 1122 |
|
for (i = sc->nmats; i-- > 0; ) |
| 1123 |
|
freeqstr(sc->matname[i]); |
| 1124 |
< |
efree((char *)sc->matname); |
| 1125 |
< |
efree((char *)sc->vert); |
| 1126 |
< |
efree((char *)sc->tex); |
| 1127 |
< |
efree((char *)sc->norm); |
| 1124 |
> |
efree(sc->matname); |
| 1125 |
> |
efree(sc->vert); |
| 1126 |
> |
efree(sc->tex); |
| 1127 |
> |
efree(sc->norm); |
| 1128 |
|
while ((f = sc->flist) != NULL) { |
| 1129 |
|
sc->flist = f->next; |
| 1130 |
< |
efree((char *)f); |
| 1130 |
> |
efree(f); |
| 1131 |
|
} |
| 1132 |
< |
efree((char *)sc); |
| 1132 |
> |
efree(sc); |
| 1133 |
|
} |