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

Comparing ray/src/common/mesh.c (file contents):
Revision 2.1 by greg, Tue Mar 11 17:08:55 2003 UTC vs.
Revision 2.20 by greg, Tue May 25 22:04:13 2004 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   * Mesh support routines
6   */
7  
8 < #include "standard.h"
8 > #include <string.h>
9 >
10 > #include "rtio.h"
11 > #include "rtmath.h"
12 > #include "rterror.h"
13 > #include "paths.h"
14   #include "octree.h"
15   #include "object.h"
16 + #include "otypes.h"
17   #include "mesh.h"
12 #include "lookup.h"
18  
19   /* An encoded mesh vertex */
20   typedef struct {
21          int             fl;
22 <        uint4           xyz[3];
23 <        int4            norm;
24 <        int4            uv[2];
22 >        uint32          xyz[3];
23 >        int32           norm;
24 >        uint32          uv[2];
25   } MCVERT;
26  
27   #define  MPATCHBLKSIZ   128             /* patch allocation block size */
# Line 25 | Line 30 | typedef struct {
30  
31   static MESH     *mlist = NULL;          /* list of loaded meshes */
32  
33 + static lut_keycmpf_t cvcmp;
34 + static lut_hashf_t cvhash;
35  
36 +
37   static unsigned long
38 < cvhash(cvp)                             /* hash an encoded vertex */
39 < MCVERT  *cvp;
38 > cvhash(p)                               /* hash an encoded vertex */
39 > //MCVERT        *cvp;
40 > const void      *p;
41   {
42 +        const MCVERT    *cvp = (const MCVERT *)p;
43          unsigned long   hval;
44          
45          if (!(cvp->fl & MT_V))
# Line 44 | Line 54 | MCVERT *cvp;
54  
55  
56   static int
57 < cvcmp(v1, v2)                           /* compare encoded vertices */
58 < register MCVERT *v1, *v2;
57 > cvcmp(vv1, vv2)                         /* compare encoded vertices */
58 > //register MCVERT       *v1, *v2;
59 > const void      *vv1, *vv2;
60   {
61 +        const MCVERT    *v1 = vv1, *v2 = vv2;
62          if (v1->fl != v2->fl)
63                  return(1);
64          if (v1->xyz[0] != v2->xyz[0])
# Line 68 | Line 80 | register MCVERT        *v1, *v2;
80  
81  
82   MESH *
83 < getmesh(mname, flags)                   /* get mesh data */
83 > getmesh(mname, flags)                   /* get new mesh data reference */
84   char    *mname;
85   int     flags;
86   {
# Line 78 | Line 90 | int    flags;
90          flags &= IO_LEGAL;
91          for (ms = mlist; ms != NULL; ms = ms->next)
92                  if (!strcmp(mname, ms->name)) {
93 <                        if ((ms->ldflags & flags) == flags) {
94 <                                ms->nref++;
83 <                                return(ms);             /* loaded */
84 <                        }
85 <                        break;                  /* load the rest */
93 >                        ms->nref++;     /* increase reference count */
94 >                        break;
95                  }
96 <        if (ms == NULL) {
96 >        if (ms == NULL) {               /* load first time */
97                  ms = (MESH *)calloc(1, sizeof(MESH));
98                  if (ms == NULL)
99                          error(SYSTEM, "out of memory in getmesh");
# Line 94 | Line 103 | int    flags;
103                  ms->next = mlist;
104                  mlist = ms;
105          }
106 <        if ((pathname = getpath(mname, getlibpath(), R_OK)) == NULL) {
106 >        if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) {
107                  sprintf(errmsg, "cannot find mesh file \"%s\"", mname);
108                  error(USER, errmsg);
109          }
# Line 128 | Line 137 | int    flags;
137                  ins->msh = NULL;
138                  o->os = (char *)ins;
139          }
140 <        if (ins->msh == NULL || (ins->msh->ldflags & flags) != flags)
140 >        if (ins->msh == NULL)
141                  ins->msh = getmesh(o->oargs.sarg[0], flags);
142 +        else if ((flags &= ~ins->msh->ldflags))
143 +                readmesh(ins->msh,
144 +                        getpath(o->oargs.sarg[0], getrlibpath(), R_OK),
145 +                                flags);
146          return(ins);
147   }
148  
149  
150   int
151 < getmeshtrivid(tvid, mp, ti)             /* get triangle vertex ID's */
152 < int4            tvid[3];
153 < register MESH   *mp;
154 < OBJECT          ti;
151 > getmeshtrivid(tvid, mo, mp, ti)         /* get triangle vertex ID's */
152 > int32   tvid[3];
153 > OBJECT  *mo;
154 > MESH    *mp;
155 > OBJECT  ti;
156   {
157          int             pn = ti >> 10;
158 +        MESHPATCH       *pp;
159  
160          if (pn >= mp->npatches)
161                  return(0);
162 +        pp = &mp->patch[pn];
163          ti &= 0x3ff;
164          if (!(ti & 0x200)) {            /* local triangle */
165                  struct PTri     *tp;
166 <                if (ti >= mp->patch[pn].ntris)
166 >                if (ti >= pp->ntris)
167                          return(0);
168 <                tp = &mp->patch[pn].tri[ti];
168 >                tp = &pp->tri[ti];
169                  tvid[0] = tvid[1] = tvid[2] = pn << 8;
170                  tvid[0] |= tp->v1;
171                  tvid[1] |= tp->v2;
172                  tvid[2] |= tp->v3;
173 +                if (pp->trimat != NULL)
174 +                        *mo = pp->trimat[ti];
175 +                else
176 +                        *mo = pp->solemat;
177 +                if (*mo != OVOID)
178 +                        *mo += mp->mat0;
179                  return(1);
180          }
181          ti &= ~0x200;
182          if (!(ti & 0x100)) {            /* single link vertex */
183                  struct PJoin1   *tp1;
184 <                if (ti >= mp->patch[pn].nj1tris)
184 >                if (ti >= pp->nj1tris)
185                          return(0);
186 <                tp1 = &mp->patch[pn].j1tri[ti];
186 >                tp1 = &pp->j1tri[ti];
187                  tvid[0] = tp1->v1j;
188                  tvid[1] = tvid[2] = pn << 8;
189                  tvid[1] |= tp1->v2;
190                  tvid[2] |= tp1->v3;
191 +                if ((*mo = tp1->mat) != OVOID)
192 +                        *mo += mp->mat0;
193                  return(1);
194          }
195          ti &= ~0x100;
196          {                               /* double link vertex */
197                  struct PJoin2   *tp2;
198 <                if (ti >= mp->patch[pn].nj2tris)
198 >                if (ti >= pp->nj2tris)
199                          return(0);
200 <                tp2 = &mp->patch[pn].j2tri[ti];
200 >                tp2 = &pp->j2tri[ti];
201                  tvid[0] = tp2->v1j;
202                  tvid[1] = tp2->v2j;
203                  tvid[2] = pn << 8 | tp2->v3;
204 +                if ((*mo = tp2->mat) != OVOID)
205 +                        *mo += mp->mat0;
206          }
207          return(1);
208   }
# Line 185 | Line 211 | OBJECT         ti;
211   int
212   getmeshvert(vp, mp, vid, what)  /* get triangle vertex from ID */
213   MESHVERT        *vp;
214 < register MESH   *mp;
215 < int4            vid;
214 > MESH            *mp;
215 > int32           vid;
216   int             what;
217   {
218          int             pn = vid >> 8;
# Line 217 | Line 243 | int            what;
243                                          /* get (u,v) */
244          if (what & MT_UV && pp->uv != NULL && pp->uv[vid][0]) {
245                  for (i = 0; i < 2; i++)
246 <                        vp->uv[i] = mp->uvlim[i][0] +
247 <                                (mp->uvlim[i][1] - mp->uvlim[i][0])*
246 >                        vp->uv[i] = mp->uvlim[0][i] +
247 >                                (mp->uvlim[1][i] - mp->uvlim[0][i])*
248                                  (pp->uv[vid][i] + .5)*(1./4294967296.);
249                  vp->fl |= MT_UV;
250          }
# Line 226 | Line 252 | int            what;
252   }
253  
254  
255 + OBJREC *
256 + getmeshpseudo(mp, mo)           /* get mesh pseudo object for material */
257 + MESH    *mp;
258 + OBJECT  mo;
259 + {
260 +        if (mo < mp->mat0 || mo >= mp->mat0 + mp->nmats)
261 +                error(INTERNAL, "modifier out of range in getmeshpseudo");
262 +        if (mp->pseudo == NULL) {
263 +                register int    i;
264 +                mp->pseudo = (OBJREC *)calloc(mp->nmats, sizeof(OBJREC));
265 +                if (mp->pseudo == NULL)
266 +                        error(SYSTEM, "out of memory in getmeshpseudo");
267 +                for (i = mp->nmats; i--; ) {
268 +                        mp->pseudo[i].omod = mp->mat0 + i;
269 +                        mp->pseudo[i].otype = OBJ_FACE;
270 +                        mp->pseudo[i].oname = "M-Tri";
271 +                }
272 +        }
273 +        return(&mp->pseudo[mo - mp->mat0]);
274 + }
275 +
276 +
277   int
278 < getmeshtri(tv, mp, ti, what)    /* get triangle vertices */
278 > getmeshtri(tv, mo, mp, ti, wha) /* get triangle vertices */
279   MESHVERT        tv[3];
280 + OBJECT          *mo;
281   MESH            *mp;
282   OBJECT          ti;
283 < int             what;
283 > int             wha;
284   {
285 <        int4    tvid[3];
285 >        int32   tvid[3];
286  
287 <        if (!getmeshtrivid(tvid, mp, ti))
287 >        if (!getmeshtrivid(tvid, mo, mp, ti))
288                  return(0);
289  
290 <        getmeshvert(&tv[0], mp, tvid[0], what);
291 <        getmeshvert(&tv[1], mp, tvid[1], what);
292 <        getmeshvert(&tv[2], mp, tvid[2], what);
290 >        getmeshvert(&tv[0], mp, tvid[0], wha);
291 >        getmeshvert(&tv[1], mp, tvid[1], wha);
292 >        getmeshvert(&tv[2], mp, tvid[2], wha);
293  
294          return(tv[0].fl & tv[1].fl & tv[2].fl);
295   }
296  
297  
298 < int4
298 > int32
299   addmeshvert(mp, vp)             /* find/add a mesh vertex */
300   register MESH   *mp;
301   MESHVERT        *vp;
302   {
254        LUTAB           *ltp;
303          LUENT           *lvp;
304          MCVERT          cv;
305          register int    i;
# Line 264 | Line 312 | MESHVERT       *vp;
312                          return(-1);
313                  if (vp->v[i] >= mp->mcube.cuorg[i] + mp->mcube.cusize)
314                          return(-1);
315 <                cv.xyz[i] = (uint4)(4294967296. *
315 >                cv.xyz[i] = (uint32)(4294967296. *
316                                  (vp->v[i] - mp->mcube.cuorg[i]) /
317                                  mp->mcube.cusize);
318          }
319 <        if (vp->fl & MT_N)
319 >        if (vp->fl & MT_N)              /* assumes normalized! */
320                  cv.norm = encodedir(vp->n);
321          if (vp->fl & MT_UV)
322                  for (i = 0; i < 2; i++) {
323 <                        if (vp->uv[i] <= mp->uvlim[i][0])
323 >                        if (vp->uv[i] <= mp->uvlim[0][i])
324                                  return(-1);
325 <                        if (vp->uv[i] >= mp->uvlim[i][1])
325 >                        if (vp->uv[i] >= mp->uvlim[1][i])
326                                  return(-1);
327 <                        cv.uv[i] = (uint4)(4294967296. *
328 <                                        (vp->uv[i] - mp->uvlim[i][0]) /
329 <                                        (mp->uvlim[i][1] - mp->uvlim[i][0]));
327 >                        cv.uv[i] = (uint32)(4294967296. *
328 >                                        (vp->uv[i] - mp->uvlim[0][i]) /
329 >                                        (mp->uvlim[1][i] - mp->uvlim[0][i]));
330                  }
331          cv.fl = vp->fl;
332 <        ltp = (LUTAB *)mp->cdata;       /* get lookup table */
333 <        if (ltp == NULL) {
334 <                ltp = (LUTAB *)calloc(1, sizeof(LUTAB));
335 <                if (ltp == NULL)
332 >        if (mp->lut.tsiz == 0) {
333 >                mp->lut.hashf = cvhash;
334 >                mp->lut.keycmp = cvcmp;
335 >                mp->lut.freek = free;
336 >                if (!lu_init(&mp->lut, 50000))
337                          goto nomem;
289                ltp->hashf = cvhash;
290                ltp->keycmp = cvcmp;
291                ltp->freek = free;
292                if (!lu_init(ltp, 50000))
293                        goto nomem;
294                mp->cdata = (char *)ltp;
338          }
339                                          /* find entry */
340 <        lvp = lu_find(ltp, (char *)&cv);
340 >        lvp = lu_find(&mp->lut, (char *)&cv);
341          if (lvp == NULL)
342                  goto nomem;
343          if (lvp->key == NULL) {
344 <                lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int4));
345 <                bcopy((void *)&cv, (void *)lvp->key, sizeof(MCVERT));
344 >                lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int32));
345 >                memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT));
346          }
347          if (lvp->data == NULL) {        /* new vertex */
348                  register MESHPATCH      *pp;
# Line 315 | Line 358 | MESHVERT       *vp;
358                                                  (void *)mp->patch,
359                                          (mp->npatches + MPATCHBLKSIZ)*
360                                                  sizeof(MESHPATCH));
361 <                                bzero((void *)(mp->patch + mp->npatches),
361 >                                memset((void *)(mp->patch + mp->npatches), '\0',
362                                          MPATCHBLKSIZ*sizeof(MESHPATCH));
363                          }
364 <                        if (mp->npatches++ >= 1<<20)
364 >                        if (mp->npatches++ >= 1L<<22)
365                                  error(INTERNAL, "too many mesh patches");
366                  }
367                  pp = &mp->patch[mp->npatches-1];
368                  if (pp->xyz == NULL) {
369 <                        pp->xyz = (uint4 (*)[3])calloc(256, 3*sizeof(int4));
369 >                        pp->xyz = (uint32 (*)[3])calloc(256, 3*sizeof(int32));
370                          if (pp->xyz == NULL)
371                                  goto nomem;
372                  }
# Line 331 | Line 374 | MESHVERT       *vp;
374                          pp->xyz[pp->nverts][i] = cv.xyz[i];
375                  if (cv.fl & MT_N) {
376                          if (pp->norm == NULL) {
377 <                                pp->norm = (int4 *)calloc(256, sizeof(int4));
377 >                                pp->norm = (int32 *)calloc(256, sizeof(int32));
378                                  if (pp->norm == NULL)
379                                          goto nomem;
380                          }
# Line 339 | Line 382 | MESHVERT       *vp;
382                  }
383                  if (cv.fl & MT_UV) {
384                          if (pp->uv == NULL) {
385 <                                pp->uv = (uint4 (*)[2])calloc(256,
386 <                                                2*sizeof(uint4));
385 >                                pp->uv = (uint32 (*)[2])calloc(256,
386 >                                                2*sizeof(uint32));
387                                  if (pp->uv == NULL)
388                                          goto nomem;
389                          }
# Line 349 | Line 392 | MESHVERT       *vp;
392                  }
393                  pp->nverts++;
394                  lvp->data = lvp->key + sizeof(MCVERT);
395 <                *(int4 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1);
395 >                *(int32 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1);
396          }
397 <        return(*(int4 *)lvp->data);
397 >        return(*(int32 *)lvp->data);
398   nomem:
399          error(SYSTEM, "out of memory in addmeshvert");
400          return(-1);
# Line 359 | Line 402 | nomem:
402  
403  
404   OBJECT
405 < addmeshtri(mp, tv)              /* add a new mesh triangle */
405 > addmeshtri(mp, tv, mo)          /* add a new mesh triangle */
406   MESH            *mp;
407   MESHVERT        tv[3];
408 + OBJECT          mo;
409   {
410 <        int4                    vid[3], t;
410 >        int32                   vid[3], t;
411          int                     pn[3], i;
412          register MESHPATCH      *pp;
413  
# Line 375 | Line 419 | MESHVERT       tv[3];
419                          return(OVOID);
420                  pn[i] = vid[i] >> 8;
421          }
422 +                                /* normalize material index */
423 +        if (mo != OVOID) {
424 +                if ((mo -= mp->mat0) >= mp->nmats)
425 +                        mp->nmats = mo+1;
426 +                else if (mo < 0)
427 +                        error(INTERNAL, "modifier range error in addmeshtri");
428 +        }
429                                  /* assign triangle */
430          if (pn[0] == pn[1] && pn[1] == pn[2]) { /* local case */
431                  pp = &mp->patch[pn[0]];
# Line 384 | Line 435 | MESHVERT       tv[3];
435                          if (pp->tri == NULL)
436                                  goto nomem;
437                  }
438 <                if (pp->ntris >= 512)
439 <                        goto toomany;
440 <                pp->tri[pp->ntris].v1 = vid[0] & 0xff;
441 <                pp->tri[pp->ntris].v2 = vid[1] & 0xff;
442 <                pp->tri[pp->ntris].v3 = vid[2] & 0xff;
443 <
444 <                return(pn[0] << 10 | pp->ntris++);
438 >                if (pp->ntris < 512) {
439 >                        pp->tri[pp->ntris].v1 = vid[0] & 0xff;
440 >                        pp->tri[pp->ntris].v2 = vid[1] & 0xff;
441 >                        pp->tri[pp->ntris].v3 = vid[2] & 0xff;
442 >                        if (pp->ntris == 0)
443 >                                pp->solemat = mo;
444 >                        else if (pp->trimat == NULL && mo != pp->solemat) {
445 >                                pp->trimat = (int16 *)malloc(
446 >                                                512*sizeof(int16));
447 >                                if (pp->trimat == NULL)
448 >                                        goto nomem;
449 >                                for (i = pp->ntris; i--; )
450 >                                        pp->trimat[i] = pp->solemat;
451 >                        }
452 >                        if (pp->trimat != NULL)
453 >                                pp->trimat[pp->ntris] = mo;
454 >                        return(pn[0] << 10 | pp->ntris++);
455 >                }
456          }
457          if (pn[0] == pn[1]) {
458 <                t = vid[2]; vid[2] = vid[0]; vid[0] = t;
459 <                i = pn[2]; pn[2] = pn[0]; pn[0] = i;
458 >                t = vid[2]; vid[2] = vid[1]; vid[1] = vid[0]; vid[0] = t;
459 >                i = pn[2]; pn[2] = pn[1]; pn[1] = pn[0]; pn[0] = i;
460          } else if (pn[0] == pn[2]) {
461 <                t = vid[0]; vid[0] = vid[1]; vid[1] = t;
462 <                i = pn[0]; pn[0] = pn[1]; pn[1] = i;
461 >                t = vid[0]; vid[0] = vid[1]; vid[1] = vid[2]; vid[2] = t;
462 >                i = pn[0]; pn[0] = pn[1]; pn[1] = pn[2]; pn[2] = i;
463          }
464          if (pn[1] == pn[2]) {                   /* single link */
465                  pp = &mp->patch[pn[1]];
# Line 407 | Line 469 | MESHVERT       tv[3];
469                          if (pp->j1tri == NULL)
470                                  goto nomem;
471                  }
472 <                if (pp->nj1tris >= 256)
473 <                        goto toomany;
474 <                pp->j1tri[pp->nj1tris].v1j = pn[0] << 8 | (vid[0] & 0xff);
475 <                pp->j1tri[pp->nj1tris].v2 = vid[1] & 0xff;
476 <                pp->j1tri[pp->nj1tris].v3 = vid[2] & 0xff;
477 <                
478 <                return(pn[1] << 10 | 0x200 | pp->nj1tris++);
472 >                if (pp->nj1tris < 256) {
473 >                        pp->j1tri[pp->nj1tris].v1j = vid[0];
474 >                        pp->j1tri[pp->nj1tris].v2 = vid[1] & 0xff;
475 >                        pp->j1tri[pp->nj1tris].v3 = vid[2] & 0xff;
476 >                        pp->j1tri[pp->nj1tris].mat = mo;
477 >                        return(pn[1] << 10 | 0x200 | pp->nj1tris++);
478 >                }
479          }
480                                                  /* double link */
481          pp = &mp->patch[pn[2]];
# Line 424 | Line 486 | MESHVERT       tv[3];
486                          goto nomem;
487          }
488          if (pp->nj2tris >= 256)
489 <                goto toomany;
490 <        pp->j2tri[pp->nj2tris].v1j = pn[0] << 8 | (vid[0] & 0xff);
491 <        pp->j2tri[pp->nj2tris].v2j = pn[1] << 8 | (vid[1] & 0xff);
489 >                error(INTERNAL, "too many patch triangles in addmeshtri");
490 >        pp->j2tri[pp->nj2tris].v1j = vid[0];
491 >        pp->j2tri[pp->nj2tris].v2j = vid[1];
492          pp->j2tri[pp->nj2tris].v3 = vid[2] & 0xff;
493 <        
493 >        pp->j2tri[pp->nj2tris].mat = mo;
494          return(pn[2] << 10 | 0x300 | pp->nj2tris++);
495   nomem:
496          error(SYSTEM, "out of memory in addmeshtri");
497          return(OVOID);
436 toomany:
437        error(CONSISTENCY, "too many patch triangles in addmeshtri");
438        return(OVOID);
498   }
499  
500  
501 + char *
502 + checkmesh(mp)                           /* validate mesh data */
503 + register MESH   *mp;
504 + {
505 +        static char     embuf[128];
506 +        int             nouvbounds = 1;
507 +        register int    i;
508 +                                        /* basic checks */
509 +        if (mp == NULL)
510 +                return("NULL mesh pointer");
511 +        if (!mp->ldflags)
512 +                return("unassigned mesh");
513 +        if (mp->name == NULL)
514 +                return("missing mesh name");
515 +        if (mp->nref <= 0)
516 +                return("unreferenced mesh");
517 +                                        /* check boundaries */
518 +        if (mp->ldflags & IO_BOUNDS) {
519 +                if (mp->mcube.cusize <= FTINY)
520 +                        return("illegal octree bounds in mesh");
521 +                nouvbounds = (mp->uvlim[1][0] - mp->uvlim[0][0] <= FTINY ||
522 +                                mp->uvlim[1][1] - mp->uvlim[0][1] <= FTINY);
523 +        }
524 +                                        /* check octree */
525 +        if (mp->ldflags & IO_TREE) {
526 +                if (isempty(mp->mcube.cutree))
527 +                        error(WARNING, "empty mesh octree");
528 +        }
529 +                                        /* check scene data */
530 +        if (mp->ldflags & IO_SCENE) {
531 +                if (!(mp->ldflags & IO_BOUNDS))
532 +                        return("unbounded scene in mesh");
533 +                if (mp->mat0 < 0 || mp->mat0+mp->nmats > nobjects)
534 +                        return("bad mesh modifier range");
535 +                for (i = mp->mat0+mp->nmats; i-- > mp->mat0; ) {
536 +                        int     otyp = objptr(i)->otype;
537 +                        if (!ismodifier(otyp)) {
538 +                                sprintf(embuf,
539 +                                        "non-modifier in mesh (%s \"%s\")",
540 +                                        ofun[otyp].funame, objptr(i)->oname);
541 +                                return(embuf);
542 +                        }
543 +                }
544 +                if (mp->npatches <= 0)
545 +                        error(WARNING, "no patches in mesh");
546 +                for (i = 0; i < mp->npatches; i++) {
547 +                        register MESHPATCH      *pp = &mp->patch[i];
548 +                        if (pp->nverts <= 0)
549 +                                error(WARNING, "no vertices in patch");
550 +                        else {
551 +                                if (pp->xyz == NULL)
552 +                                        return("missing patch vertex list");
553 +                                if (nouvbounds && pp->uv != NULL)
554 +                                        return("unreferenced uv coordinates");
555 +                        }
556 +                        if (pp->ntris > 0 && pp->tri == NULL)
557 +                                return("missing patch triangle list");
558 +                        if (pp->nj1tris > 0 && pp->j1tri == NULL)
559 +                                return("missing patch joiner triangle list");
560 +                        if (pp->nj2tris > 0 && pp->j2tri == NULL)
561 +                                return("missing patch double-joiner list");
562 +                }
563 +        }
564 +        return(NULL);                   /* seems OK */
565 + }
566 +
567 +
568   static void
569   tallyoctree(ot, ecp, lcp, ocp)  /* tally octree size */
570   OCTREE  ot;
# Line 494 | Line 620 | FILE   *fp;
620                  t2cnt += pp->nj2tris;
621          }
622          fprintf(fp, "Mesh statistics:\n");
623 +        fprintf(fp, "\t%ld materials\n", ms->nmats);
624          fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches,
625                          (ms->npatches*sizeof(MESHPATCH) +
626 <                        vcnt*3*sizeof(uint4) +
627 <                        nscnt*sizeof(int4) +
628 <                        uvscnt*2*sizeof(uint4) +
626 >                        vcnt*3*sizeof(uint32) +
627 >                        nscnt*sizeof(int32) +
628 >                        uvscnt*2*sizeof(uint32) +
629                          tcnt*sizeof(struct PTri) +
630                          t1cnt*sizeof(struct PJoin1) +
631                          t2cnt*sizeof(struct PJoin2))/(1024.*1024.));
# Line 517 | Line 644 | FILE   *fp;
644  
645   void
646   freemesh(ms)                    /* free mesh data */
647 < MESH    *ms;
647 > register MESH   *ms;
648   {
649          MESH    mhead;
650          MESH    *msp;
# Line 543 | Line 670 | MESH   *ms;
670                                  /* free mesh data */
671          freestr(ms->name);
672          octfree(ms->mcube.cutree);
673 <        if (ms->cdata != NULL)
547 <                lu_done((LUTAB *)ms->cdata);
673 >        lu_done(&ms->lut);
674          if (ms->npatches > 0) {
675                  register MESHPATCH      *pp = ms->patch + ms->npatches;
676                  while (pp-- > ms->patch) {
# Line 563 | Line 689 | MESH   *ms;
689                  }
690                  free((void *)ms->patch);
691          }
692 +        if (ms->pseudo != NULL)
693 +                free((void *)ms->pseudo);
694          free((void *)ms);
695   }
696  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines