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.11 by greg, Fri Jan 30 00:08:31 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   static char     *meshfn;        /* input file name */
18   static FILE     *meshfp;        /* mesh file pointer */
# Line 73 | Line 77 | gettree()                              /* get a pre-ordered octree */
77          register int  i;
78          
79          switch (getc(meshfp)) {
80 <        case OT_EMPTY:
81 <                return(EMPTY);
82 <        case OT_FULL:
83 <                return(getfullnode());
84 <        case OT_TREE:
85 <                if ((ot = octalloc()) == EMPTY)
86 <                        mesherror(SYSTEM, "out of tree space in readmesh");
87 <                for (i = 0; i < 8; i++)
88 <                        octkid(ot, i) = gettree();
89 <                return(ot);
90 <        case EOF:
91 <                mesherror(USER, "truncated mesh octree");
92 <        default:
93 <                mesherror(USER, "damaged mesh octree");
80 >                case OT_EMPTY:
81 >                        return(EMPTY);
82 >                case OT_FULL:
83 >                        return(getfullnode());
84 >                case OT_TREE:
85 >                        if ((ot = octalloc()) == EMPTY)
86 >                                mesherror(SYSTEM, "out of tree space in readmesh");
87 >                        for (i = 0; i < 8; i++)
88 >                                octkid(ot, i) = gettree();
89 >                        return(ot);
90 >                case EOF:
91 >                        mesherror(USER, "truncated mesh octree");
92 >                default:
93 >                        mesherror(USER, "damaged mesh octree");
94          }
95 +        return (OCTREE)NULL; /* pro forma return */
96   }
97  
98  
# Line 130 | Line 135 | register MESHPATCH     *pp;
135          pp->nverts = mgetint(2);
136          if (pp->nverts <= 0 || pp->nverts > 256)
137                  mesherror(USER, "bad number of patch vertices");
138 <        pp->xyz = (uint4 (*)[3])malloc(pp->nverts*3*sizeof(uint4));
138 >        pp->xyz = (uint32 (*)[3])malloc(pp->nverts*3*sizeof(uint32));
139          if (pp->xyz == NULL)
140                  goto nomem;
141          if (flags & MT_N) {
142 <                pp->norm = (int4 *)calloc(pp->nverts, sizeof(int4));
142 >                pp->norm = (int32 *)calloc(pp->nverts, sizeof(int32));
143                  if (pp->norm == NULL)
144                          goto nomem;
145          } else
146                  pp->norm = NULL;
147          if (flags & MT_UV) {
148 <                pp->uv = (uint4 (*)[2])calloc(pp->nverts, 2*sizeof(uint4));
148 >                pp->uv = (uint32 (*)[2])calloc(pp->nverts, 2*sizeof(uint32));
149                  if (pp->uv == NULL)
150                          goto nomem;
151          } else
# Line 174 | Line 179 | register MESHPATCH     *pp;
179                  }
180          } else
181                  pp->tri = NULL;
182 +                                        /* local triangle material(s) */
183 +        if (mgetint(2) > 1) {
184 +                pp->trimat = (int16 *)malloc(pp->ntris*sizeof(int16));
185 +                if (pp->trimat == NULL)
186 +                        goto nomem;
187 +                for (i = 0; i < pp->ntris; i++)
188 +                        pp->trimat[i] = mgetint(2);
189 +        } else {
190 +                pp->solemat = mgetint(2);
191 +                pp->trimat = NULL;
192 +        }
193                                          /* joiner triangles */
194          pp->nj1tris = mgetint(2);
195          if (pp->nj1tris < 0 || pp->nj1tris > 512)
# Line 187 | Line 203 | register MESHPATCH     *pp;
203                          pp->j1tri[i].v1j = mgetint(4);
204                          pp->j1tri[i].v2 = mgetint(1);
205                          pp->j1tri[i].v3 = mgetint(1);
206 +                        pp->j1tri[i].mat = mgetint(2);
207                  }
208          } else
209                  pp->j1tri = NULL;
# Line 203 | Line 220 | register MESHPATCH     *pp;
220                          pp->j2tri[i].v1j = mgetint(4);
221                          pp->j2tri[i].v2j = mgetint(4);
222                          pp->j2tri[i].v3 = mgetint(1);
223 +                        pp->j2tri[i].mat = mgetint(2);
224                  }
225          } else
226                  pp->j2tri = NULL;
# Line 218 | Line 236 | MESH   *mp;
236   char    *path;
237   int     flags;
238   {
239 +        char    *err;
240          char    sbuf[64];
241          int     i;
242                                          /* check what's loaded */
# Line 230 | Line 249 | int    flags;
249                  sprintf(errmsg, "cannot open mesh file \"%s\"", path);
250                  error(SYSTEM, errmsg);
251          }
252 < #ifdef MSDOS
234 <        setmode(fileno(meshfp), O_BINARY);
235 < #endif
252 >        SET_FILE_BINARY(meshfp);
253                                          /* read header */
254          checkheader(meshfp, MESHFMT, flags&IO_INFO ? stdout : (FILE *)NULL);
255                                          /* read format number */
# Line 259 | Line 276 | int    flags;
276                  mp->mcube.cutree = gettree();
277          else if (flags & IO_SCENE)
278                  skiptree();
279 <                                        /* read the patches */
279 >                                        /* read materials and patches */
280          if (flags & IO_SCENE) {
281 +                mp->mat0 = nobjects;
282 +                readscene(meshfp, objsize);
283 +                mp->nmats = nobjects - mp->mat0;
284                  mp->npatches = mgetint(4);
285                  mp->patch = (MESHPATCH *)calloc(mp->npatches,
286                                          sizeof(MESHPATCH));
# Line 272 | Line 292 | int    flags;
292                                          /* clean up */
293          fclose(meshfp);
294          mp->ldflags |= flags;
295 +                                        /* verify data */
296 +        if ((err = checkmesh(mp)) != NULL)
297 +                mesherror(USER, err);
298   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines