| 19 |  | int | 
| 20 |  | findName(const char *nm, const char **nmlist, int n) | 
| 21 |  | { | 
| 22 | < | 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); | 
| 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; | 
| 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; | 
| 573 |  | while (sc->ndescr > 0) | 
| 574 |  | freeqstr(sc->descr[--sc->ndescr]); | 
| 575 |  | efree((char *)sc->descr); | 
| 576 | + | sc->descr = NULL; | 
| 577 |  | sc->ndescr = 0; | 
| 578 |  | } | 
| 579 |  |  | 
| 605 |  | fp->v[j].fnext = f;                     /* append new face */ | 
| 606 |  | } | 
| 607 |  |  | 
| 603 | – | /* Allocate an empty scene */ | 
| 604 | – | Scene * | 
| 605 | – | newScene(void) | 
| 606 | – | { | 
| 607 | – | Scene   *sc = (Scene *)ecalloc(1, sizeof(Scene)); | 
| 608 | – | /* default group & material */ | 
| 609 | – | sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps); | 
| 610 | – | sc->grpname[sc->ngrps++] = savqstr("DEFAULT_GROUP"); | 
| 611 | – | sc->matname = chunk_alloc(char *, sc->matname, sc->nmats); | 
| 612 | – | sc->matname[sc->nmats++] = savqstr("DEFAULT_MATERIAL"); | 
| 613 | – |  | 
| 614 | – | return(sc); | 
| 615 | – | } | 
| 616 | – |  | 
| 608 |  | /* Add a vertex to a scene */ | 
| 609 |  | int | 
| 610 |  | addVertex(Scene *sc, double x, double y, double z) | 
| 631 |  | int | 
| 632 |  | addNormal(Scene *sc, double xn, double yn, double zn) | 
| 633 |  | { | 
| 634 | < | FVECT   nrm; | 
| 634 | > | FVECT   nrm; | 
| 635 |  |  | 
| 636 |  | nrm[0] = xn; nrm[1] = yn; nrm[2] = zn; | 
| 637 |  | if (normalize(nrm) == .0) | 
| 645 |  | void | 
| 646 |  | setGroup(Scene *sc, const char *nm) | 
| 647 |  | { | 
| 648 | < | sc->lastgrp = findName(nm, (const char **)sc->grpname, sc->ngrps); | 
| 648 | > | sc->lastgrp = getGroupID(sc, nm); | 
| 649 |  | if (sc->lastgrp >= 0) | 
| 650 |  | return; | 
| 651 |  | sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps); | 
| 656 |  | void | 
| 657 |  | setMaterial(Scene *sc, const char *nm) | 
| 658 |  | { | 
| 659 | < | sc->lastmat = findName(nm, (const char **)sc->matname, sc->nmats); | 
| 659 | > | sc->lastmat = getMaterialID(sc, nm); | 
| 660 |  | if (sc->lastmat >= 0) | 
| 661 |  | return; | 
| 662 |  | sc->matname = chunk_alloc(char *, sc->matname, sc->nmats); | 
| 667 |  | Face * | 
| 668 |  | addFace(Scene *sc, VNDX vid[], int nv) | 
| 669 |  | { | 
| 670 | < | Face    *f; | 
| 671 | < | int     i; | 
| 670 | > | Face    *f; | 
| 671 | > | int     i; | 
| 672 |  |  | 
| 673 |  | if (nv < 3) | 
| 674 |  | return(NULL); | 
| 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((char *)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) | 
| 790 | + | { | 
| 791 | + | Scene   *sc = (Scene *)ecalloc(1, sizeof(Scene)); | 
| 792 | + | /* default group & material */ | 
| 793 | + | sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps); | 
| 794 | + | sc->grpname[sc->ngrps++] = savqstr("DEFAULT_GROUP"); | 
| 795 | + | sc->matname = chunk_alloc(char *, sc->matname, sc->nmats); | 
| 796 | + | sc->matname[sc->nmats++] = savqstr("DEFAULT_MATERIAL"); | 
| 797 | + |  | 
| 798 | + | return(sc); | 
| 799 | + | } | 
| 800 | + |  | 
| 801 |  | /* Duplicate a scene, optionally selecting faces */ | 
| 802 |  | Scene * | 
| 803 |  | dupScene(const Scene *osc, int flreq, int flexc) | 
| 813 |  | sc = newScene(); | 
| 814 |  | for (i = 0; i < osc->ndescr; i++) | 
| 815 |  | addComment(sc, osc->descr[i]); | 
| 816 | < | if (osc->ngrps) { | 
| 817 | < | sc->grpname = (char **)emalloc(sizeof(char *) * | 
| 818 | < | (osc->ngrps+(CHUNKSIZ-1))); | 
| 819 | < | for (i = 0; i < osc->ngrps; i++) | 
| 816 | > | if (osc->ngrps > 1) { | 
| 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) { | 
| 824 | < | sc->matname = (char **)emalloc(sizeof(char *) * | 
| 825 | < | (osc->nmats+(CHUNKSIZ-1))); | 
| 826 | < | for (i = 0; i < osc->nmats; i++) | 
| 823 | > | if (osc->nmats > 1) { | 
| 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]); | 
| 828 |  | sc->nmats = osc->nmats; | 
| 829 |  | } | 
| 830 |  | if (osc->nverts) { | 
| 831 |  | sc->vert = (Vertex *)emalloc(sizeof(Vertex) * | 
| 832 |  | (osc->nverts+(CHUNKSIZ-1))); | 
| 833 | < | memcpy((void *)sc->vert, (const void *)osc->vert, | 
| 746 | < | sizeof(Vertex)*osc->nverts); | 
| 833 | > | memcpy(sc->vert, osc->vert, sizeof(Vertex)*osc->nverts); | 
| 834 |  | sc->nverts = osc->nverts; | 
| 835 |  | for (i = 0; i < sc->nverts; i++) | 
| 836 |  | sc->vert[i].vflist = NULL; | 
| 838 |  | if (osc->ntex) { | 
| 839 |  | sc->tex = (TexCoord *)emalloc(sizeof(TexCoord) * | 
| 840 |  | (osc->ntex+(CHUNKSIZ-1))); | 
| 841 | < | memcpy((void *)sc->tex, (const void *)osc->tex, | 
| 755 | < | sizeof(TexCoord)*osc->ntex); | 
| 841 | > | memcpy(sc->tex, osc->tex, sizeof(TexCoord)*osc->ntex); | 
| 842 |  | sc->ntex = osc->ntex; | 
| 843 |  | } | 
| 844 |  | if (osc->nnorms) { | 
| 845 |  | sc->norm = (Normal *)emalloc(sizeof(Normal) * | 
| 846 |  | (osc->nnorms+CHUNKSIZ)); | 
| 847 | < | memcpy((void *)sc->norm, (const void *)osc->norm, | 
| 762 | < | sizeof(Normal)*osc->nnorms); | 
| 847 | > | memcpy(sc->norm, osc->norm, sizeof(Normal)*osc->nnorms); | 
| 848 |  | sc->nnorms = osc->nnorms; | 
| 849 |  | } | 
| 850 |  | for (fo = osc->flist; fo != NULL; fo = fo->next) { | 
| 851 |  | if ((fo->flags & fltest) != flreq) | 
| 852 |  | continue; | 
| 853 | < | f = (Face *)emalloc(sizeof(Face) + | 
| 854 | < | sizeof(VertEnt)*(fo->nv-3)); | 
| 770 | < | memcpy((void *)f, (const void *)fo, sizeof(Face) + | 
| 771 | < | sizeof(VertEnt)*(fo->nv-3)); | 
| 853 | > | f = (Face *)emalloc(sizeof(Face) + sizeof(VertEnt)*(fo->nv-3)); | 
| 854 | > | memcpy(f, fo, sizeof(Face) + sizeof(VertEnt)*(fo->nv-3)); | 
| 855 |  | for (i = 0; i < f->nv; i++) | 
| 856 |  | add2facelist(sc, f, i); | 
| 857 |  | f->next = sc->flist; | 
| 862 |  | return(sc); | 
| 863 |  | } | 
| 864 |  |  | 
| 865 | + | /* Add one scene to another, not checking for redundancies */ | 
| 866 | + | int | 
| 867 | + | addScene(Scene *scdst, const Scene *scsrc) | 
| 868 | + | { | 
| 869 | + | VNDX            my_vlist[4]; | 
| 870 | + | int             *vert_map = NULL; | 
| 871 | + | int             tex_off = 0; | 
| 872 | + | int             norm_off = 0; | 
| 873 | + | VNDX            *vlist = my_vlist; | 
| 874 | + | int             vllen = sizeof(my_vlist)/sizeof(VNDX); | 
| 875 | + | int             cur_mat = 0; | 
| 876 | + | int             cur_grp = 0; | 
| 877 | + | int             fcnt = 0; | 
| 878 | + | const Face      *f; | 
| 879 | + | int             i; | 
| 880 | + |  | 
| 881 | + | if ((scdst == NULL) | (scsrc == NULL)) | 
| 882 | + | return(-1); | 
| 883 | + | if (scsrc->nfaces <= 0) | 
| 884 | + | return(0); | 
| 885 | + | /* map vertices */ | 
| 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) { | 
| 890 | + | vert_map[i] = -1; | 
| 891 | + | continue; | 
| 892 | + | } | 
| 893 | + | vert_map[i] = addVertex(scdst, v->p[0], v->p[1], v->p[2]); | 
| 894 | + | } | 
| 895 | + | tex_off = scdst->ntex;          /* append texture coords */ | 
| 896 | + | if (scsrc->ntex > 0) { | 
| 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(scdst->norm, | 
| 905 | + | sizeof(Normal)*(norm_off+scsrc->nnorms+(CHUNKSIZ-1))); | 
| 906 | + | memcpy(scdst->norm+norm_off, scsrc->norm, | 
| 907 | + | sizeof(Normal)*scsrc->nnorms); | 
| 908 | + | } | 
| 909 | + | /* add faces */ | 
| 910 | + | scdst->lastgrp = scdst->lastmat = 0; | 
| 911 | + | for (f = scsrc->flist; f != NULL; f = f->next) { | 
| 912 | + | if (f->grp != cur_grp) | 
| 913 | + | setGroup(scdst, scsrc->grpname[cur_grp = f->grp]); | 
| 914 | + | if (f->mat != cur_mat) | 
| 915 | + | setMaterial(scdst, scsrc->matname[cur_mat = f->mat]); | 
| 916 | + | if (f->nv > vllen) { | 
| 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; ) { | 
| 924 | + | if (f->v[i].vid >= 0) | 
| 925 | + | vlist[i][0] = vert_map[f->v[i].vid]; | 
| 926 | + | if (f->v[i].tid >= 0) | 
| 927 | + | vlist[i][1] = f->v[i].tid + tex_off; | 
| 928 | + | if (f->v[i].nid >= 0) | 
| 929 | + | vlist[i][2] = f->v[i].nid + norm_off; | 
| 930 | + | } | 
| 931 | + | fcnt += (addFace(scdst, vlist, f->nv) != NULL); | 
| 932 | + | } | 
| 933 | + | /* clean up */ | 
| 934 | + | if (vlist != my_vlist) efree(vlist); | 
| 935 | + | efree(vert_map); | 
| 936 | + | return(fcnt); | 
| 937 | + | } | 
| 938 | + |  | 
| 939 |  | #define MAXAC   100 | 
| 940 |  |  | 
| 941 |  | /* Transform entire scene */ | 
| 992 |  | if (!*xfm) | 
| 993 |  | return(0); | 
| 994 |  | /* parse string into words */ | 
| 995 | < | xav[0] = strcpy((char *)malloc(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 | < | free(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) | 
| 1089 |  | if (!vmap[i]) | 
| 1090 |  | continue; | 
| 1091 |  | if (nused != i) | 
| 1092 | < | memcpy((void *)sc->norm[nused], | 
| 936 | < | (void *)sc->norm[i], | 
| 937 | < | sizeof(Normal)); | 
| 1092 | > | memcpy(sc->norm[nused], sc->norm[i], sizeof(Normal)); | 
| 1093 |  | vmap[i] = nused++; | 
| 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 |  | } |