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.2 by greg, Wed Mar 12 04:59:04 2003 UTC vs.
Revision 2.26 by greg, Tue Nov 6 17:12:35 2012 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 <        uint4           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 27 | Line 32 | static MESH    *mlist = NULL;          /* list of loaded meshes *
32  
33  
34   static unsigned long
35 < cvhash(cvp)                             /* hash an encoded vertex */
31 < MCVERT  *cvp;
35 > cvhash(const char *p)                   /* hash an encoded vertex */
36   {
37 +        const MCVERT    *cvp = (const MCVERT *)p;
38          unsigned long   hval;
39          
40          if (!(cvp->fl & MT_V))
# Line 44 | Line 49 | MCVERT *cvp;
49  
50  
51   static int
52 < cvcmp(v1, v2)                           /* compare encoded vertices */
48 < register MCVERT *v1, *v2;
52 > cvcmp(const char *vv1, const char *vv2)         /* compare encoded vertices */
53   {
54 +        const MCVERT    *v1 = (const MCVERT *)vv1, *v2 = (const MCVERT *)vv2;
55          if (v1->fl != v2->fl)
56                  return(1);
57          if (v1->xyz[0] != v2->xyz[0])
# Line 68 | Line 73 | register MCVERT        *v1, *v2;
73  
74  
75   MESH *
76 < getmesh(mname, flags)                   /* get mesh data */
77 < char    *mname;
78 < int     flags;
76 > getmesh(                                /* get new mesh data reference */
77 >        char    *mname,
78 >        int     flags
79 > )
80   {
81          char  *pathname;
82 <        register MESH  *ms;
82 >        MESH  *ms;
83  
84          flags &= IO_LEGAL;
85          for (ms = mlist; ms != NULL; ms = ms->next)
86                  if (!strcmp(mname, ms->name)) {
87 <                        if ((ms->ldflags & flags) == flags) {
88 <                                ms->nref++;
83 <                                return(ms);             /* loaded */
84 <                        }
85 <                        break;                  /* load the rest */
87 >                        ms->nref++;     /* increase reference count */
88 >                        break;
89                  }
90 <        if (ms == NULL) {
90 >        if (ms == NULL) {               /* load first time */
91                  ms = (MESH *)calloc(1, sizeof(MESH));
92                  if (ms == NULL)
93                          error(SYSTEM, "out of memory in getmesh");
# Line 94 | Line 97 | int    flags;
97                  ms->next = mlist;
98                  mlist = ms;
99          }
100 <        if ((pathname = getpath(mname, getlibpath(), R_OK)) == NULL) {
100 >        if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) {
101                  sprintf(errmsg, "cannot find mesh file \"%s\"", mname);
102                  error(USER, errmsg);
103          }
# Line 106 | Line 109 | int    flags;
109  
110  
111   MESHINST *
112 < getmeshinst(o, flags)                   /* create mesh instance */
113 < OBJREC  *o;
114 < int     flags;
112 > getmeshinst(                            /* create mesh instance */
113 >        OBJREC  *o,
114 >        int     flags
115 > )
116   {
117 <        register MESHINST  *ins;
117 >        MESHINST  *ins;
118  
119          flags &= IO_LEGAL;
120          if ((ins = (MESHINST *)o->os) == NULL) {
# Line 128 | Line 132 | int    flags;
132                  ins->msh = NULL;
133                  o->os = (char *)ins;
134          }
135 <        if (ins->msh == NULL || (ins->msh->ldflags & flags) != flags)
135 >        if (ins->msh == NULL)
136                  ins->msh = getmesh(o->oargs.sarg[0], flags);
137 +        else if ((flags &= ~ins->msh->ldflags))
138 +                readmesh(ins->msh,
139 +                        getpath(o->oargs.sarg[0], getrlibpath(), R_OK),
140 +                                flags);
141          return(ins);
142   }
143  
144  
145   int
146 < getmeshtrivid(tvid, mp, ti)             /* get triangle vertex ID's */
147 < int4            tvid[3];
148 < register MESH   *mp;
149 < OBJECT          ti;
146 > nextmeshtri(                            /* get next triangle ID */
147 >        OBJECT *tip,
148 >        MESH *mp
149 > )
150   {
151 +        int             pn;
152 +        MESHPATCH       *pp;
153 +
154 +        pn = ++(*tip) >> 10;                    /* next triangle (OVOID init) */
155 +        while (pn < mp->npatches) {
156 +                pp = &mp->patch[pn];
157 +                if (!(*tip & 0x200)) {          /* local triangle? */
158 +                        if ((*tip & 0x1ff) < pp->ntris)
159 +                                return(1);
160 +                        *tip &= ~0x1ff;         /* move on to single-joiners */
161 +                        *tip |= 0x200;
162 +                }
163 +                if (!(*tip & 0x100)) {          /* single joiner? */
164 +                        if ((*tip & 0xff) < pp->nj1tris)
165 +                                return(1);
166 +                        *tip &= ~0xff;          /* move on to double-joiners */
167 +                        *tip |= 0x100;
168 +                }
169 +                if ((*tip & 0xff) < pp->nj2tris)
170 +                        return(1);
171 +                *tip = ++pn << 10;              /* first in next patch */
172 +        }
173 +        return(0);                              /* out of patches */
174 + }
175 +
176 + int
177 + getmeshtrivid(                          /* get triangle vertex ID's */
178 +        int32   tvid[3],
179 +        OBJECT  *mo,
180 +        MESH    *mp,
181 +        OBJECT  ti
182 + )
183 + {
184          int             pn = ti >> 10;
185 +        MESHPATCH       *pp;
186  
187          if (pn >= mp->npatches)
188                  return(0);
189 +        pp = &mp->patch[pn];
190          ti &= 0x3ff;
191          if (!(ti & 0x200)) {            /* local triangle */
192                  struct PTri     *tp;
193 <                if (ti >= mp->patch[pn].ntris)
193 >                if (ti >= pp->ntris)
194                          return(0);
195 <                tp = &mp->patch[pn].tri[ti];
195 >                tp = &pp->tri[ti];
196                  tvid[0] = tvid[1] = tvid[2] = pn << 8;
197                  tvid[0] |= tp->v1;
198                  tvid[1] |= tp->v2;
199                  tvid[2] |= tp->v3;
200 +                if (pp->trimat != NULL)
201 +                        *mo = pp->trimat[ti];
202 +                else
203 +                        *mo = pp->solemat;
204 +                if (*mo != OVOID)
205 +                        *mo += mp->mat0;
206                  return(1);
207          }
208          ti &= ~0x200;
209          if (!(ti & 0x100)) {            /* single link vertex */
210                  struct PJoin1   *tp1;
211 <                if (ti >= mp->patch[pn].nj1tris)
211 >                if (ti >= pp->nj1tris)
212                          return(0);
213 <                tp1 = &mp->patch[pn].j1tri[ti];
213 >                tp1 = &pp->j1tri[ti];
214                  tvid[0] = tp1->v1j;
215                  tvid[1] = tvid[2] = pn << 8;
216                  tvid[1] |= tp1->v2;
217                  tvid[2] |= tp1->v3;
218 +                if ((*mo = tp1->mat) != OVOID)
219 +                        *mo += mp->mat0;
220                  return(1);
221          }
222          ti &= ~0x100;
223          {                               /* double link vertex */
224                  struct PJoin2   *tp2;
225 <                if (ti >= mp->patch[pn].nj2tris)
225 >                if (ti >= pp->nj2tris)
226                          return(0);
227 <                tp2 = &mp->patch[pn].j2tri[ti];
227 >                tp2 = &pp->j2tri[ti];
228                  tvid[0] = tp2->v1j;
229                  tvid[1] = tp2->v2j;
230                  tvid[2] = pn << 8 | tp2->v3;
231 +                if ((*mo = tp2->mat) != OVOID)
232 +                        *mo += mp->mat0;
233          }
234          return(1);
235   }
236  
237  
238   int
239 < getmeshvert(vp, mp, vid, what)  /* get triangle vertex from ID */
240 < MESHVERT        *vp;
241 < register MESH   *mp;
242 < int4            vid;
243 < int             what;
239 > getmeshvert(                            /* get triangle vertex from ID */
240 >        MESHVERT        *vp,
241 >        MESH            *mp,
242 >        int32           vid,
243 >        int             what
244 > )
245   {
246          int             pn = vid >> 8;
247          MESHPATCH       *pp;
248          double          vres;
249 <        register int    i;
249 >        int     i;
250          
251          vp->fl = 0;
252          if (pn >= mp->npatches)
# Line 226 | Line 280 | int            what;
280   }
281  
282  
283 + OBJREC *
284 + getmeshpseudo(                  /* get mesh pseudo object for material */
285 +        MESH    *mp,
286 +        OBJECT  mo
287 + )
288 + {
289 +        if (mo < mp->mat0 || mo >= mp->mat0 + mp->nmats)
290 +                error(INTERNAL, "modifier out of range in getmeshpseudo");
291 +        if (mp->pseudo == NULL) {
292 +                int     i;
293 +                mp->pseudo = (OBJREC *)calloc(mp->nmats, sizeof(OBJREC));
294 +                if (mp->pseudo == NULL)
295 +                        error(SYSTEM, "out of memory in getmeshpseudo");
296 +                for (i = mp->nmats; i--; ) {
297 +                        mp->pseudo[i].omod = mp->mat0 + i;
298 +                        mp->pseudo[i].otype = OBJ_FACE;
299 +                        mp->pseudo[i].oname = "M-Tri";
300 +                }
301 +        }
302 +        return(&mp->pseudo[mo - mp->mat0]);
303 + }
304 +
305 +
306   int
307 < getmeshtri(tv, mp, ti, what)    /* get triangle vertices */
308 < MESHVERT        tv[3];
309 < MESH            *mp;
310 < OBJECT          ti;
311 < int             what;
307 > getmeshtri(                     /* get triangle vertices */
308 >        MESHVERT        tv[3],
309 >        OBJECT          *mo,
310 >        MESH            *mp,
311 >        OBJECT          ti,
312 >        int             wha
313 > )
314   {
315 <        int4    tvid[3];
315 >        int32   tvid[3];
316  
317 <        if (!getmeshtrivid(tvid, mp, ti))
317 >        if (!getmeshtrivid(tvid, mo, mp, ti))
318                  return(0);
319  
320 <        getmeshvert(&tv[0], mp, tvid[0], what);
321 <        getmeshvert(&tv[1], mp, tvid[1], what);
322 <        getmeshvert(&tv[2], mp, tvid[2], what);
320 >        getmeshvert(&tv[0], mp, tvid[0], wha);
321 >        getmeshvert(&tv[1], mp, tvid[1], wha);
322 >        getmeshvert(&tv[2], mp, tvid[2], wha);
323  
324          return(tv[0].fl & tv[1].fl & tv[2].fl);
325   }
326  
327  
328 < int4
329 < addmeshvert(mp, vp)             /* find/add a mesh vertex */
330 < register MESH   *mp;
331 < MESHVERT        *vp;
328 > int32
329 > addmeshvert(                    /* find/add a mesh vertex */
330 >        MESH    *mp,
331 >        MESHVERT        *vp
332 > )
333   {
254        LUTAB           *ltp;
334          LUENT           *lvp;
335          MCVERT          cv;
336 <        register int    i;
336 >        int     i;
337  
338          if (!(vp->fl & MT_V))
339                  return(-1);
# Line 264 | Line 343 | MESHVERT       *vp;
343                          return(-1);
344                  if (vp->v[i] >= mp->mcube.cuorg[i] + mp->mcube.cusize)
345                          return(-1);
346 <                cv.xyz[i] = (uint4)(4294967296. *
346 >                cv.xyz[i] = (uint32)(4294967296. *
347                                  (vp->v[i] - mp->mcube.cuorg[i]) /
348                                  mp->mcube.cusize);
349          }
350 <        if (vp->fl & MT_N)
350 >        if (vp->fl & MT_N)              /* assumes normalized! */
351                  cv.norm = encodedir(vp->n);
352          if (vp->fl & MT_UV)
353                  for (i = 0; i < 2; i++) {
# Line 276 | Line 355 | MESHVERT       *vp;
355                                  return(-1);
356                          if (vp->uv[i] >= mp->uvlim[1][i])
357                                  return(-1);
358 <                        cv.uv[i] = (uint4)(4294967296. *
358 >                        cv.uv[i] = (uint32)(4294967296. *
359                                          (vp->uv[i] - mp->uvlim[0][i]) /
360                                          (mp->uvlim[1][i] - mp->uvlim[0][i]));
361                  }
362          cv.fl = vp->fl;
363 <        ltp = (LUTAB *)mp->cdata;       /* get lookup table */
364 <        if (ltp == NULL) {
365 <                ltp = (LUTAB *)calloc(1, sizeof(LUTAB));
366 <                if (ltp == NULL)
363 >        if (mp->lut.tsiz == 0) {
364 >                mp->lut.hashf = cvhash;
365 >                mp->lut.keycmp = cvcmp;
366 >                mp->lut.freek = free;
367 >                if (!lu_init(&mp->lut, 50000))
368                          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;
369          }
370                                          /* find entry */
371 <        lvp = lu_find(ltp, (char *)&cv);
371 >        lvp = lu_find(&mp->lut, (char *)&cv);
372          if (lvp == NULL)
373                  goto nomem;
374          if (lvp->key == NULL) {
375 <                lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int4));
376 <                bcopy((void *)&cv, (void *)lvp->key, sizeof(MCVERT));
375 >                lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int32));
376 >                memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT));
377          }
378          if (lvp->data == NULL) {        /* new vertex */
379 <                register MESHPATCH      *pp;
379 >                MESHPATCH       *pp;
380                  if (mp->npatches <= 0) {
381                          mp->patch = (MESHPATCH *)calloc(MPATCHBLKSIZ,
382                                          sizeof(MESHPATCH));
# Line 315 | Line 389 | MESHVERT       *vp;
389                                                  (void *)mp->patch,
390                                          (mp->npatches + MPATCHBLKSIZ)*
391                                                  sizeof(MESHPATCH));
392 <                                bzero((void *)(mp->patch + mp->npatches),
392 >                                memset((void *)(mp->patch + mp->npatches), '\0',
393                                          MPATCHBLKSIZ*sizeof(MESHPATCH));
394                          }
395                          if (mp->npatches++ >= 1L<<22)
# Line 323 | Line 397 | MESHVERT       *vp;
397                  }
398                  pp = &mp->patch[mp->npatches-1];
399                  if (pp->xyz == NULL) {
400 <                        pp->xyz = (uint4 (*)[3])calloc(256, 3*sizeof(int4));
400 >                        pp->xyz = (uint32 (*)[3])calloc(256, 3*sizeof(int32));
401                          if (pp->xyz == NULL)
402                                  goto nomem;
403                  }
# Line 331 | Line 405 | MESHVERT       *vp;
405                          pp->xyz[pp->nverts][i] = cv.xyz[i];
406                  if (cv.fl & MT_N) {
407                          if (pp->norm == NULL) {
408 <                                pp->norm = (int4 *)calloc(256, sizeof(int4));
408 >                                pp->norm = (int32 *)calloc(256, sizeof(int32));
409                                  if (pp->norm == NULL)
410                                          goto nomem;
411                          }
# Line 339 | Line 413 | MESHVERT       *vp;
413                  }
414                  if (cv.fl & MT_UV) {
415                          if (pp->uv == NULL) {
416 <                                pp->uv = (uint4 (*)[2])calloc(256,
417 <                                                2*sizeof(uint4));
416 >                                pp->uv = (uint32 (*)[2])calloc(256,
417 >                                                2*sizeof(uint32));
418                                  if (pp->uv == NULL)
419                                          goto nomem;
420                          }
# Line 349 | Line 423 | MESHVERT       *vp;
423                  }
424                  pp->nverts++;
425                  lvp->data = lvp->key + sizeof(MCVERT);
426 <                *(int4 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1);
426 >                *(int32 *)lvp->data = (mp->npatches-1) << 8 | (pp->nverts-1);
427          }
428 <        return(*(int4 *)lvp->data);
428 >        return(*(int32 *)lvp->data);
429   nomem:
430          error(SYSTEM, "out of memory in addmeshvert");
431          return(-1);
# Line 359 | Line 433 | nomem:
433  
434  
435   OBJECT
436 < addmeshtri(mp, tv)              /* add a new mesh triangle */
437 < MESH            *mp;
438 < MESHVERT        tv[3];
436 > addmeshtri(                     /* add a new mesh triangle */
437 >        MESH            *mp,
438 >        MESHVERT        tv[3],
439 >        OBJECT          mo
440 > )
441   {
442 <        int4                    vid[3], t;
442 >        int32                   vid[3], t;
443          int                     pn[3], i;
444 <        register MESHPATCH      *pp;
444 >        MESHPATCH       *pp;
445  
446          if (!(tv[0].fl & tv[1].fl & tv[2].fl & MT_V))
447                  return(OVOID);
# Line 375 | Line 451 | MESHVERT       tv[3];
451                          return(OVOID);
452                  pn[i] = vid[i] >> 8;
453          }
454 +                                /* normalize material index */
455 +        if (mo != OVOID) {
456 +                if ((mo -= mp->mat0) >= mp->nmats)
457 +                        mp->nmats = mo+1;
458 +                else if (mo < 0)
459 +                        error(INTERNAL, "modifier range error in addmeshtri");
460 +        }
461                                  /* assign triangle */
462          if (pn[0] == pn[1] && pn[1] == pn[2]) { /* local case */
463                  pp = &mp->patch[pn[0]];
# Line 388 | Line 471 | MESHVERT       tv[3];
471                          pp->tri[pp->ntris].v1 = vid[0] & 0xff;
472                          pp->tri[pp->ntris].v2 = vid[1] & 0xff;
473                          pp->tri[pp->ntris].v3 = vid[2] & 0xff;
474 +                        if (pp->ntris == 0)
475 +                                pp->solemat = mo;
476 +                        else if (pp->trimat == NULL && mo != pp->solemat) {
477 +                                pp->trimat = (int16 *)malloc(
478 +                                                512*sizeof(int16));
479 +                                if (pp->trimat == NULL)
480 +                                        goto nomem;
481 +                                for (i = pp->ntris; i--; )
482 +                                        pp->trimat[i] = pp->solemat;
483 +                        }
484 +                        if (pp->trimat != NULL)
485 +                                pp->trimat[pp->ntris] = mo;
486                          return(pn[0] << 10 | pp->ntris++);
487                  }
488          }
# Line 410 | Line 505 | MESHVERT       tv[3];
505                          pp->j1tri[pp->nj1tris].v1j = vid[0];
506                          pp->j1tri[pp->nj1tris].v2 = vid[1] & 0xff;
507                          pp->j1tri[pp->nj1tris].v3 = vid[2] & 0xff;
508 +                        pp->j1tri[pp->nj1tris].mat = mo;
509                          return(pn[1] << 10 | 0x200 | pp->nj1tris++);
510                  }
511          }
# Line 426 | Line 522 | MESHVERT       tv[3];
522          pp->j2tri[pp->nj2tris].v1j = vid[0];
523          pp->j2tri[pp->nj2tris].v2j = vid[1];
524          pp->j2tri[pp->nj2tris].v3 = vid[2] & 0xff;
525 +        pp->j2tri[pp->nj2tris].mat = mo;
526          return(pn[2] << 10 | 0x300 | pp->nj2tris++);
527   nomem:
528          error(SYSTEM, "out of memory in addmeshtri");
# Line 433 | Line 530 | nomem:
530   }
531  
532  
533 + char *
534 + checkmesh(MESH *mp)                     /* validate mesh data */
535 + {
536 +        static char     embuf[128];
537 +        int             nouvbounds = 1;
538 +        int     i;
539 +                                        /* basic checks */
540 +        if (mp == NULL)
541 +                return("NULL mesh pointer");
542 +        if (!mp->ldflags)
543 +                return("unassigned mesh");
544 +        if (mp->name == NULL)
545 +                return("missing mesh name");
546 +        if (mp->nref <= 0)
547 +                return("unreferenced mesh");
548 +                                        /* check boundaries */
549 +        if (mp->ldflags & IO_BOUNDS) {
550 +                if (mp->mcube.cusize <= FTINY)
551 +                        return("illegal octree bounds in mesh");
552 +                nouvbounds = (mp->uvlim[1][0] - mp->uvlim[0][0] <= FTINY ||
553 +                                mp->uvlim[1][1] - mp->uvlim[0][1] <= FTINY);
554 +        }
555 +                                        /* check octree */
556 +        if (mp->ldflags & IO_TREE) {
557 +                if (isempty(mp->mcube.cutree))
558 +                        error(WARNING, "empty mesh octree");
559 +        }
560 +                                        /* check scene data */
561 +        if (mp->ldflags & IO_SCENE) {
562 +                if (!(mp->ldflags & IO_BOUNDS))
563 +                        return("unbounded scene in mesh");
564 +                if (mp->mat0 < 0 || mp->mat0+mp->nmats > nobjects)
565 +                        return("bad mesh modifier range");
566 +                for (i = mp->mat0+mp->nmats; i-- > mp->mat0; ) {
567 +                        int     otyp = objptr(i)->otype;
568 +                        if (!ismodifier(otyp)) {
569 +                                sprintf(embuf,
570 +                                        "non-modifier in mesh (%s \"%s\")",
571 +                                        ofun[otyp].funame, objptr(i)->oname);
572 +                                return(embuf);
573 +                        }
574 +                }
575 +                if (mp->npatches <= 0)
576 +                        error(WARNING, "no patches in mesh");
577 +                for (i = 0; i < mp->npatches; i++) {
578 +                        MESHPATCH       *pp = &mp->patch[i];
579 +                        if (pp->nverts <= 0)
580 +                                error(WARNING, "no vertices in patch");
581 +                        else {
582 +                                if (pp->xyz == NULL)
583 +                                        return("missing patch vertex list");
584 +                                if (nouvbounds && pp->uv != NULL)
585 +                                        return("unreferenced uv coordinates");
586 +                        }
587 +                        if (pp->ntris > 0 && pp->tri == NULL)
588 +                                return("missing patch triangle list");
589 +                        if (pp->nj1tris > 0 && pp->j1tri == NULL)
590 +                                return("missing patch joiner triangle list");
591 +                        if (pp->nj2tris > 0 && pp->j2tri == NULL)
592 +                                return("missing patch double-joiner list");
593 +                }
594 +        }
595 +        return(NULL);                   /* seems OK */
596 + }
597 +
598 +
599   static void
600 < tallyoctree(ot, ecp, lcp, ocp)  /* tally octree size */
601 < OCTREE  ot;
602 < int     *ecp, *lcp, *ocp;
600 > tallyoctree(                    /* tally octree size */
601 >        OCTREE  ot,
602 >        int     *ecp,
603 >        int     *lcp,
604 >        int     *ocp
605 > )
606   {
607          int     i;
608  
# Line 457 | Line 623 | int    *ecp, *lcp, *ocp;
623  
624  
625   void
626 < printmeshstats(ms, fp)          /* print out mesh statistics */
627 < MESH    *ms;
628 < FILE    *fp;
626 > printmeshstats(                 /* print out mesh statistics */
627 >        MESH    *ms,
628 >        FILE    *fp
629 > )
630   {
631          int     lfcnt=0, lecnt=0, locnt=0;
632          int     vcnt=0, ncnt=0, uvcnt=0;
# Line 469 | Line 636 | FILE   *fp;
636          
637          tallyoctree(ms->mcube.cutree, &lecnt, &lfcnt, &locnt);
638          for (i = 0; i < ms->npatches; i++) {
639 <                register MESHPATCH      *pp = &ms->patch[i];
639 >                MESHPATCH       *pp = &ms->patch[i];
640                  vcnt += pp->nverts;
641                  if (pp->norm != NULL) {
642                          for (j = pp->nverts; j--; )
# Line 488 | Line 655 | FILE   *fp;
655                  t2cnt += pp->nj2tris;
656          }
657          fprintf(fp, "Mesh statistics:\n");
658 +        fprintf(fp, "\t%ld materials\n", (long)ms->nmats);
659          fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches,
660                          (ms->npatches*sizeof(MESHPATCH) +
661 <                        vcnt*3*sizeof(uint4) +
662 <                        nscnt*sizeof(int4) +
663 <                        uvscnt*2*sizeof(uint4) +
661 >                        vcnt*3*sizeof(uint32) +
662 >                        nscnt*sizeof(int32) +
663 >                        uvscnt*2*sizeof(uint32) +
664                          tcnt*sizeof(struct PTri) +
665                          t1cnt*sizeof(struct PJoin1) +
666                          t2cnt*sizeof(struct PJoin2))/(1024.*1024.));
# Line 510 | Line 678 | FILE   *fp;
678  
679  
680   void
681 < freemesh(ms)                    /* free mesh data */
514 < MESH    *ms;
681 > freemesh(MESH *ms)              /* free mesh data */
682   {
683          MESH    mhead;
684          MESH    *msp;
# Line 537 | Line 704 | MESH   *ms;
704                                  /* free mesh data */
705          freestr(ms->name);
706          octfree(ms->mcube.cutree);
707 <        if (ms->cdata != NULL)
541 <                lu_done((LUTAB *)ms->cdata);
707 >        lu_done(&ms->lut);
708          if (ms->npatches > 0) {
709 <                register MESHPATCH      *pp = ms->patch + ms->npatches;
709 >                MESHPATCH       *pp = ms->patch + ms->npatches;
710                  while (pp-- > ms->patch) {
711                          if (pp->j2tri != NULL)
712                                  free((void *)pp->j2tri);
# Line 557 | Line 723 | MESH   *ms;
723                  }
724                  free((void *)ms->patch);
725          }
726 +        if (ms->pseudo != NULL)
727 +                free((void *)ms->pseudo);
728          free((void *)ms);
729   }
730  
731  
732   void
733 < freemeshinst(o)                 /* free mesh instance */
566 < OBJREC  *o;
733 > freemeshinst(OBJREC *o)         /* free mesh instance */
734   {
735          if (o->os == NULL)
736                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines