ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/objutil.c
(Generate patch)

Comparing ray/src/common/objutil.c (file contents):
Revision 2.14 by greg, Wed Apr 7 03:02:00 2021 UTC vs.
Revision 2.15 by greg, Wed Apr 7 14:37:57 2021 UTC

# Line 604 | Line 604 | add2facelist(Scene *sc, Face *f, int i)
604          fp->v[j].fnext = f;                     /* append new face */
605   }
606  
607 /* Allocate an empty scene */
608 Scene *
609 newScene(void)
610 {
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");
615        sc->matname = chunk_alloc(char *, sc->matname, sc->nmats);
616        sc->matname[sc->nmats++] = savqstr("DEFAULT_MATERIAL");
617
618        return(sc);
619 }
620
607   /* Add a vertex to a scene */
608   int
609   addVertex(Scene *sc, double x, double y, double z)
# Line 714 | Line 700 | addFace(Scene *sc, VNDX vid[], int nv)
700          return(f);
701   }
702  
703 + /* Allocate an empty scene */
704 + Scene *
705 + newScene(void)
706 + {
707 +        Scene   *sc = (Scene *)ecalloc(1, sizeof(Scene));
708 +                                                /* default group & material */
709 +        sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps);
710 +        sc->grpname[sc->ngrps++] = savqstr("DEFAULT_GROUP");
711 +        sc->matname = chunk_alloc(char *, sc->matname, sc->nmats);
712 +        sc->matname[sc->nmats++] = savqstr("DEFAULT_MATERIAL");
713 +
714 +        return(sc);
715 + }
716 +
717   /* Duplicate a scene, optionally selecting faces */
718   Scene *
719   dupScene(const Scene *osc, int flreq, int flexc)
# Line 729 | Line 729 | dupScene(const Scene *osc, int flreq, int flexc)
729          sc = newScene();
730          for (i = 0; i < osc->ndescr; i++)
731                  addComment(sc, osc->descr[i]);
732 <        if (osc->ngrps) {
733 <                sc->grpname = (char **)emalloc(sizeof(char *) *
734 <                                                (osc->ngrps+(CHUNKSIZ-1)));
735 <                for (i = 0; i < osc->ngrps; i++)
732 >        if (osc->ngrps > 1) {
733 >                sc->grpname = (char **)erealloc((char *)sc->grpname,
734 >                                sizeof(char *) * (osc->ngrps+(CHUNKSIZ-1)));
735 >                for (i = 1; i < osc->ngrps; i++)
736                          sc->grpname[i] = savqstr(osc->grpname[i]);
737                  sc->ngrps = osc->ngrps;
738          }
739 <        if (osc->nmats) {
740 <                sc->matname = (char **)emalloc(sizeof(char *) *
741 <                                                (osc->nmats+(CHUNKSIZ-1)));
742 <                for (i = 0; i < osc->nmats; i++)
739 >        if (osc->nmats > 1) {
740 >                sc->matname = (char **)erealloc((char *)sc->matname,
741 >                                sizeof(char *) * (osc->nmats+(CHUNKSIZ-1)));
742 >                for (i = 1; i < osc->nmats; i++)
743                          sc->matname[i] = savqstr(osc->matname[i]);
744                  sc->nmats = osc->nmats;
745          }
746          if (osc->nverts) {
747                  sc->vert = (Vertex *)emalloc(sizeof(Vertex) *
748                                                  (osc->nverts+(CHUNKSIZ-1)));
749 <                memcpy((void *)sc->vert, (const void *)osc->vert,
750 <                                sizeof(Vertex)*osc->nverts);
749 >                memcpy(sc->vert, osc->vert, sizeof(Vertex)*osc->nverts);
750                  sc->nverts = osc->nverts;
751                  for (i = 0; i < sc->nverts; i++)
752                          sc->vert[i].vflist = NULL;
# Line 755 | Line 754 | dupScene(const Scene *osc, int flreq, int flexc)
754          if (osc->ntex) {
755                  sc->tex = (TexCoord *)emalloc(sizeof(TexCoord) *
756                                                  (osc->ntex+(CHUNKSIZ-1)));
757 <                memcpy((void *)sc->tex, (const void *)osc->tex,
759 <                                sizeof(TexCoord)*osc->ntex);
757 >                memcpy(sc->tex, osc->tex, sizeof(TexCoord)*osc->ntex);
758                  sc->ntex = osc->ntex;
759          }
760          if (osc->nnorms) {
761                  sc->norm = (Normal *)emalloc(sizeof(Normal) *
762                                                  (osc->nnorms+CHUNKSIZ));
763 <                memcpy((void *)sc->norm, (const void *)osc->norm,
766 <                                sizeof(Normal)*osc->nnorms);
763 >                memcpy(sc->norm, osc->norm, sizeof(Normal)*osc->nnorms);
764                  sc->nnorms = osc->nnorms;
765          }
766          for (fo = osc->flist; fo != NULL; fo = fo->next) {
767                  if ((fo->flags & fltest) != flreq)
768                          continue;
769 <                f = (Face *)emalloc(sizeof(Face) +
770 <                                sizeof(VertEnt)*(fo->nv-3));
774 <                memcpy((void *)f, (const void *)fo, sizeof(Face) +
775 <                                sizeof(VertEnt)*(fo->nv-3));
769 >                f = (Face *)emalloc(sizeof(Face) + sizeof(VertEnt)*(fo->nv-3));
770 >                memcpy(f, fo, sizeof(Face) + sizeof(VertEnt)*(fo->nv-3));
771                  for (i = 0; i < f->nv; i++)
772                          add2facelist(sc, f, i);
773                  f->next = sc->flist;
# Line 1012 | Line 1007 | skip_tex:
1007                  if (!vmap[i])
1008                          continue;
1009                  if (nused != i)
1010 <                        memcpy((void *)sc->norm[nused],
1016 <                                        (void *)sc->norm[i],
1017 <                                        sizeof(Normal));
1010 >                        memcpy(sc->norm[nused], sc->norm[i], sizeof(Normal));
1011                  vmap[i] = nused++;
1012          }
1013          if (nused == sc->nnorms)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines