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.5 by schorsch, Sun Jun 8 12:03:09 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines