--- ray/src/common/instance.c 1989/02/02 10:34:35 1.1 +++ ray/src/common/instance.c 1993/02/02 13:24:50 2.3 @@ -1,4 +1,4 @@ -/* Copyright (c) 1988 Regents of the University of California */ +/* Copyright (c) 1990 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -16,6 +16,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "instance.h" +#define IO_ILLEGAL (IO_FILES|IO_INFO) + static SCENE *slist = NULL; /* list of loaded octrees */ @@ -28,7 +30,7 @@ int flags; char *pathname; register SCENE *sc; - flags &= ~IO_FILES; /* not allowed */ + flags &= ~IO_ILLEGAL; /* not allowed */ for (sc = slist; sc != NULL; sc = sc->next) if (!strcmp(sname, sc->name)) { if ((sc->ldflags & flags) == flags) @@ -41,14 +43,24 @@ int flags; error(SYSTEM, "out of memory in getscene"); sc->name = savestr(sname); sc->ldflags = 0; + sc->scube.cutree = EMPTY; + sc->scube.cuorg[0] = sc->scube.cuorg[1] = + sc->scube.cuorg[2] = 0.; + sc->scube.cusize = 0.; + sc->firstobj = sc->nobjs = 0; sc->next = slist; slist = sc; } - if ((pathname = getpath(sname, libpath)) == NULL) { + if ((pathname = getpath(sname, libpath, R_OK)) == NULL) { sprintf(errmsg, "cannot find octree file \"%s\"", sname); error(USER, errmsg); } - readoct(pathname, flags & ~sc->ldflags, &sc->scube, NULL); + flags &= ~sc->ldflags; /* skip what's already loaded */ + if (flags & IO_SCENE) + sc->firstobj = nobjects; + readoct(pathname, flags, &sc->scube, NULL); + if (flags & IO_SCENE) + sc->nobjs = nobjects - sc->firstobj; sc->ldflags |= flags; return(sc); } @@ -61,27 +73,33 @@ int flags; { register INSTANCE *in; + flags &= ~IO_ILLEGAL; /* not allowed */ if ((in = (INSTANCE *)o->os) == NULL) { if ((in = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL) error(SYSTEM, "out of memory in getinstance"); if (o->oargs.nsargs < 1) objerror(o, USER, "bad # of arguments"); - in->f.sca = 1.0; - setident4(in->f.xfm); - if (xf(in->f.xfm, &in->f.sca, o->oargs.nsargs-1, + if (fullxf(&in->x, o->oargs.nsargs-1, o->oargs.sarg+1) != o->oargs.nsargs-1) objerror(o, USER, "bad transform"); - if (in->f.sca < 0.0) - in->f.sca = -in->f.sca; - in->b.sca = 1.0; - setident4(in->b.xfm); - invxf(in->b.xfm, &in->b.sca,o->oargs.nsargs-1,o->oargs.sarg+1); - if (in->b.sca < 0.0) - in->b.sca = -in->b.sca; + if (in->x.f.sca < 0.0) + in->x.f.sca = -in->x.f.sca; + if (in->x.b.sca < 0.0) + in->x.b.sca = -in->x.b.sca; in->obj = NULL; - (INSTANCE *)o->os = in; + o->os = (char *)in; } if (in->obj == NULL || (in->obj->ldflags & flags) != flags) in->obj = getscene(o->oargs.sarg[0], flags); return(in); +} + + +freeinstance(o) /* free memory associated with instance */ +OBJREC *o; +{ + if (o->os == NULL) + return; + free(o->os); + o->os = NULL; }