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.4 by schorsch, Sat Jun 7 12:50:20 2003 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9   #include  "octree.h"
10   #include  "object.h"
11   #include  "mesh.h"
12 + #include  "resolu.h"
13  
14   static char     *meshfn;        /* input file name */
15   static FILE     *meshfp;        /* mesh file pointer */
# Line 73 | Line 74 | gettree()                              /* get a pre-ordered octree */
74          register int  i;
75          
76          switch (getc(meshfp)) {
77 <        case OT_EMPTY:
78 <                return(EMPTY);
79 <        case OT_FULL:
80 <                return(getfullnode());
81 <        case OT_TREE:
82 <                if ((ot = octalloc()) == EMPTY)
83 <                        mesherror(SYSTEM, "out of tree space in readmesh");
84 <                for (i = 0; i < 8; i++)
85 <                        octkid(ot, i) = gettree();
86 <                return(ot);
87 <        case EOF:
88 <                mesherror(USER, "truncated mesh octree");
89 <        default:
90 <                mesherror(USER, "damaged mesh octree");
77 >                case OT_EMPTY:
78 >                        return(EMPTY);
79 >                case OT_FULL:
80 >                        return(getfullnode());
81 >                case OT_TREE:
82 >                        if ((ot = octalloc()) == EMPTY)
83 >                                mesherror(SYSTEM, "out of tree space in readmesh");
84 >                        for (i = 0; i < 8; i++)
85 >                                octkid(ot, i) = gettree();
86 >                        return(ot);
87 >                case EOF:
88 >                        mesherror(USER, "truncated mesh octree");
89 >                default:
90 >                        mesherror(USER, "damaged mesh octree");
91          }
92 +        return NULL; /* pro forma return */
93   }
94  
95  
# Line 174 | Line 176 | register MESHPATCH     *pp;
176                  }
177          } else
178                  pp->tri = NULL;
179 +                                        /* local triangle material(s) */
180 +        if (mgetint(2) > 1) {
181 +                pp->trimat = (int2 *)malloc(pp->ntris*sizeof(int2));
182 +                if (pp->trimat == NULL)
183 +                        goto nomem;
184 +                for (i = 0; i < pp->ntris; i++)
185 +                        pp->trimat[i] = mgetint(2);
186 +        } else {
187 +                pp->solemat = mgetint(2);
188 +                pp->trimat = NULL;
189 +        }
190                                          /* joiner triangles */
191          pp->nj1tris = mgetint(2);
192          if (pp->nj1tris < 0 || pp->nj1tris > 512)
# Line 187 | Line 200 | register MESHPATCH     *pp;
200                          pp->j1tri[i].v1j = mgetint(4);
201                          pp->j1tri[i].v2 = mgetint(1);
202                          pp->j1tri[i].v3 = mgetint(1);
203 +                        pp->j1tri[i].mat = mgetint(2);
204                  }
205          } else
206                  pp->j1tri = NULL;
# Line 203 | Line 217 | register MESHPATCH     *pp;
217                          pp->j2tri[i].v1j = mgetint(4);
218                          pp->j2tri[i].v2j = mgetint(4);
219                          pp->j2tri[i].v3 = mgetint(1);
220 +                        pp->j2tri[i].mat = mgetint(2);
221                  }
222          } else
223                  pp->j2tri = NULL;
# Line 218 | Line 233 | MESH   *mp;
233   char    *path;
234   int     flags;
235   {
236 +        char    *err;
237          char    sbuf[64];
238          int     i;
239                                          /* check what's loaded */
# Line 230 | Line 246 | int    flags;
246                  sprintf(errmsg, "cannot open mesh file \"%s\"", path);
247                  error(SYSTEM, errmsg);
248          }
249 < #ifdef MSDOS
234 <        setmode(fileno(meshfp), O_BINARY);
235 < #endif
249 >        SET_FILE_BINARY(meshfp);
250                                          /* read header */
251          checkheader(meshfp, MESHFMT, flags&IO_INFO ? stdout : (FILE *)NULL);
252                                          /* read format number */
# Line 259 | Line 273 | int    flags;
273                  mp->mcube.cutree = gettree();
274          else if (flags & IO_SCENE)
275                  skiptree();
276 <                                        /* read the patches */
276 >                                        /* read materials and patches */
277          if (flags & IO_SCENE) {
278 +                mp->mat0 = nobjects;
279 +                readscene(meshfp, objsize);
280 +                mp->nmats = nobjects - mp->mat0;
281                  mp->npatches = mgetint(4);
282                  mp->patch = (MESHPATCH *)calloc(mp->npatches,
283                                          sizeof(MESHPATCH));
# Line 272 | Line 289 | int    flags;
289                                          /* clean up */
290          fclose(meshfp);
291          mp->ldflags |= flags;
292 +                                        /* verify data */
293 +        if ((err = checkmesh(mp)) != NULL)
294 +                mesherror(USER, err);
295   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines