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

Comparing ray/src/common/readmesh.c (file contents):
Revision 2.1 by greg, Tue Mar 11 17:08:55 2003 UTC vs.
Revision 2.12 by greg, Thu Apr 29 14:36:49 2004 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   *  Routines for reading a compiled mesh from a file
6   */
7  
8 + #include  <time.h>
9 +
10 + #include  "platform.h"
11   #include  "standard.h"
12   #include  "octree.h"
13   #include  "object.h"
14   #include  "mesh.h"
15 + #include  "resolu.h"
16  
17 + #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
18 + #define getc    getc_unlocked
19 + #endif
20 +
21   static char     *meshfn;        /* input file name */
22   static FILE     *meshfp;        /* mesh file pointer */
23   static int      objsize;        /* sizeof(OBJECT) from writer */
# Line 73 | Line 81 | gettree()                              /* get a pre-ordered octree */
81          register int  i;
82          
83          switch (getc(meshfp)) {
84 <        case OT_EMPTY:
85 <                return(EMPTY);
86 <        case OT_FULL:
87 <                return(getfullnode());
88 <        case OT_TREE:
89 <                if ((ot = octalloc()) == EMPTY)
90 <                        mesherror(SYSTEM, "out of tree space in readmesh");
91 <                for (i = 0; i < 8; i++)
92 <                        octkid(ot, i) = gettree();
93 <                return(ot);
94 <        case EOF:
95 <                mesherror(USER, "truncated mesh octree");
96 <        default:
97 <                mesherror(USER, "damaged mesh octree");
84 >                case OT_EMPTY:
85 >                        return(EMPTY);
86 >                case OT_FULL:
87 >                        return(getfullnode());
88 >                case OT_TREE:
89 >                        if ((ot = octalloc()) == EMPTY)
90 >                                mesherror(SYSTEM, "out of tree space in readmesh");
91 >                        for (i = 0; i < 8; i++)
92 >                                octkid(ot, i) = gettree();
93 >                        return(ot);
94 >                case EOF:
95 >                        mesherror(USER, "truncated mesh octree");
96 >                default:
97 >                        mesherror(USER, "damaged mesh octree");
98          }
99 +        return (OCTREE)NULL; /* pro forma return */
100   }
101  
102  
# Line 130 | Line 139 | register MESHPATCH     *pp;
139          pp->nverts = mgetint(2);
140          if (pp->nverts <= 0 || pp->nverts > 256)
141                  mesherror(USER, "bad number of patch vertices");
142 <        pp->xyz = (uint4 (*)[3])malloc(pp->nverts*3*sizeof(uint4));
142 >        pp->xyz = (uint32 (*)[3])malloc(pp->nverts*3*sizeof(uint32));
143          if (pp->xyz == NULL)
144                  goto nomem;
145          if (flags & MT_N) {
146 <                pp->norm = (int4 *)calloc(pp->nverts, sizeof(int4));
146 >                pp->norm = (int32 *)calloc(pp->nverts, sizeof(int32));
147                  if (pp->norm == NULL)
148                          goto nomem;
149          } else
150                  pp->norm = NULL;
151          if (flags & MT_UV) {
152 <                pp->uv = (uint4 (*)[2])calloc(pp->nverts, 2*sizeof(uint4));
152 >                pp->uv = (uint32 (*)[2])calloc(pp->nverts, 2*sizeof(uint32));
153                  if (pp->uv == NULL)
154                          goto nomem;
155          } else
# Line 174 | Line 183 | register MESHPATCH     *pp;
183                  }
184          } else
185                  pp->tri = NULL;
186 +                                        /* local triangle material(s) */
187 +        if (mgetint(2) > 1) {
188 +                pp->trimat = (int16 *)malloc(pp->ntris*sizeof(int16));
189 +                if (pp->trimat == NULL)
190 +                        goto nomem;
191 +                for (i = 0; i < pp->ntris; i++)
192 +                        pp->trimat[i] = mgetint(2);
193 +        } else {
194 +                pp->solemat = mgetint(2);
195 +                pp->trimat = NULL;
196 +        }
197                                          /* joiner triangles */
198          pp->nj1tris = mgetint(2);
199          if (pp->nj1tris < 0 || pp->nj1tris > 512)
# Line 187 | Line 207 | register MESHPATCH     *pp;
207                          pp->j1tri[i].v1j = mgetint(4);
208                          pp->j1tri[i].v2 = mgetint(1);
209                          pp->j1tri[i].v3 = mgetint(1);
210 +                        pp->j1tri[i].mat = mgetint(2);
211                  }
212          } else
213                  pp->j1tri = NULL;
# Line 203 | Line 224 | register MESHPATCH     *pp;
224                          pp->j2tri[i].v1j = mgetint(4);
225                          pp->j2tri[i].v2j = mgetint(4);
226                          pp->j2tri[i].v3 = mgetint(1);
227 +                        pp->j2tri[i].mat = mgetint(2);
228                  }
229          } else
230                  pp->j2tri = NULL;
# Line 218 | Line 240 | MESH   *mp;
240   char    *path;
241   int     flags;
242   {
243 +        char    *err;
244          char    sbuf[64];
245          int     i;
246                                          /* check what's loaded */
# Line 230 | Line 253 | int    flags;
253                  sprintf(errmsg, "cannot open mesh file \"%s\"", path);
254                  error(SYSTEM, errmsg);
255          }
256 < #ifdef MSDOS
234 <        setmode(fileno(meshfp), O_BINARY);
235 < #endif
256 >        SET_FILE_BINARY(meshfp);
257                                          /* read header */
258          checkheader(meshfp, MESHFMT, flags&IO_INFO ? stdout : (FILE *)NULL);
259                                          /* read format number */
# Line 259 | Line 280 | int    flags;
280                  mp->mcube.cutree = gettree();
281          else if (flags & IO_SCENE)
282                  skiptree();
283 <                                        /* read the patches */
283 >                                        /* read materials and patches */
284          if (flags & IO_SCENE) {
285 +                mp->mat0 = nobjects;
286 +                readscene(meshfp, objsize);
287 +                mp->nmats = nobjects - mp->mat0;
288                  mp->npatches = mgetint(4);
289                  mp->patch = (MESHPATCH *)calloc(mp->npatches,
290                                          sizeof(MESHPATCH));
# Line 272 | Line 296 | int    flags;
296                                          /* clean up */
297          fclose(meshfp);
298          mp->ldflags |= flags;
299 +                                        /* verify data */
300 +        if ((err = checkmesh(mp)) != NULL)
301 +                mesherror(USER, err);
302   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines