| 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" | 
| 73 | 
  | 
 | 
| 74 | 
  | 
 | 
| 75 | 
  | 
MESH * | 
| 76 | 
< | 
getmesh(mname, flags)                   /* get mesh data */ | 
| 76 | 
> | 
getmesh(mname, flags)                   /* get new mesh data reference */ | 
| 77 | 
  | 
char    *mname; | 
| 78 | 
  | 
int     flags; | 
| 79 | 
  | 
{ | 
| 83 | 
  | 
        flags &= IO_LEGAL; | 
| 84 | 
  | 
        for (ms = mlist; ms != NULL; ms = ms->next) | 
| 85 | 
  | 
                if (!strcmp(mname, ms->name)) { | 
| 86 | 
< | 
                        if ((ms->ldflags & flags) == flags) { | 
| 87 | 
< | 
                                ms->nref++; | 
| 83 | 
< | 
                                return(ms);             /* loaded */ | 
| 84 | 
< | 
                        } | 
| 85 | 
< | 
                        break;                  /* load the rest */ | 
| 86 | 
> | 
                        ms->nref++;     /* increase reference count */ | 
| 87 | 
> | 
                        break; | 
| 88 | 
  | 
                } | 
| 89 | 
< | 
        if (ms == NULL) { | 
| 89 | 
> | 
        if (ms == NULL) {               /* load first time */ | 
| 90 | 
  | 
                ms = (MESH *)calloc(1, sizeof(MESH)); | 
| 91 | 
  | 
                if (ms == NULL) | 
| 92 | 
  | 
                        error(SYSTEM, "out of memory in getmesh"); | 
| 130 | 
  | 
                ins->msh = NULL; | 
| 131 | 
  | 
                o->os = (char *)ins; | 
| 132 | 
  | 
        } | 
| 133 | 
< | 
        if (ins->msh == NULL || (ins->msh->ldflags & flags) != flags) | 
| 133 | 
> | 
        if (ins->msh == NULL) | 
| 134 | 
  | 
                ins->msh = getmesh(o->oargs.sarg[0], flags); | 
| 135 | 
+ | 
        else if ((flags &= ~ins->msh->ldflags)) | 
| 136 | 
+ | 
                readmesh(ins->msh, | 
| 137 | 
+ | 
                        getpath(o->oargs.sarg[0], getrlibpath(), R_OK), | 
| 138 | 
+ | 
                                flags); | 
| 139 | 
  | 
        return(ins); | 
| 140 | 
  | 
} | 
| 141 | 
  | 
 | 
| 309 | 
  | 
                                (vp->v[i] - mp->mcube.cuorg[i]) / | 
| 310 | 
  | 
                                mp->mcube.cusize); | 
| 311 | 
  | 
        } | 
| 312 | 
< | 
        if (vp->fl & MT_N) | 
| 312 | 
> | 
        if (vp->fl & MT_N)              /* assumes normalized! */ | 
| 313 | 
  | 
                cv.norm = encodedir(vp->n); | 
| 314 | 
  | 
        if (vp->fl & MT_UV) | 
| 315 | 
  | 
                for (i = 0; i < 2; i++) { | 
| 335 | 
  | 
                goto nomem; | 
| 336 | 
  | 
        if (lvp->key == NULL) { | 
| 337 | 
  | 
                lvp->key = (char *)malloc(sizeof(MCVERT)+sizeof(int32)); | 
| 338 | 
< | 
                bcopy((void *)&cv, (void *)lvp->key, sizeof(MCVERT)); | 
| 338 | 
> | 
                memcpy((void *)lvp->key, (void *)&cv, sizeof(MCVERT)); | 
| 339 | 
  | 
        } | 
| 340 | 
  | 
        if (lvp->data == NULL) {        /* new vertex */ | 
| 341 | 
  | 
                register MESHPATCH      *pp; | 
| 351 | 
  | 
                                                (void *)mp->patch, | 
| 352 | 
  | 
                                        (mp->npatches + MPATCHBLKSIZ)* | 
| 353 | 
  | 
                                                sizeof(MESHPATCH)); | 
| 354 | 
< | 
                                bzero((void *)(mp->patch + mp->npatches), | 
| 354 | 
> | 
                                memset((void *)(mp->patch + mp->npatches), '\0', | 
| 355 | 
  | 
                                        MPATCHBLKSIZ*sizeof(MESHPATCH)); | 
| 356 | 
  | 
                        } | 
| 357 | 
  | 
                        if (mp->npatches++ >= 1L<<22) | 
| 413 | 
  | 
                pn[i] = vid[i] >> 8; | 
| 414 | 
  | 
        } | 
| 415 | 
  | 
                                /* normalize material index */ | 
| 416 | 
< | 
        if (mo != OVOID) | 
| 416 | 
> | 
        if (mo != OVOID) { | 
| 417 | 
  | 
                if ((mo -= mp->mat0) >= mp->nmats) | 
| 418 | 
  | 
                        mp->nmats = mo+1; | 
| 419 | 
  | 
                else if (mo < 0) | 
| 420 | 
  | 
                        error(INTERNAL, "modifier range error in addmeshtri"); | 
| 421 | 
+ | 
        } | 
| 422 | 
  | 
                                /* assign triangle */ | 
| 423 | 
  | 
        if (pn[0] == pn[1] && pn[1] == pn[2]) { /* local case */ | 
| 424 | 
  | 
                pp = &mp->patch[pn[0]]; | 
| 615 | 
  | 
                t2cnt += pp->nj2tris; | 
| 616 | 
  | 
        } | 
| 617 | 
  | 
        fprintf(fp, "Mesh statistics:\n"); | 
| 618 | 
< | 
        fprintf(fp, "\t%d materials\n", ms->nmats); | 
| 618 | 
> | 
        fprintf(fp, "\t%ld materials\n", ms->nmats); | 
| 619 | 
  | 
        fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches, | 
| 620 | 
  | 
                        (ms->npatches*sizeof(MESHPATCH) + | 
| 621 | 
  | 
                        vcnt*3*sizeof(uint32) + |