| 39 |
|
|
| 40 |
|
double mincusize; /* minimum cube size from resolu */ |
| 41 |
|
|
| 42 |
+ |
int (*addobjnotify[])() = {NULL}; /* new object notifier functions */ |
| 43 |
|
|
| 44 |
+ |
|
| 45 |
|
main(argc, argv) /* convert object files to an octree */ |
| 46 |
|
int argc; |
| 47 |
|
char **argv; |
| 61 |
|
|
| 62 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 63 |
|
switch (argv[i][1]) { |
| 64 |
+ |
case '\0': /* scene from stdin */ |
| 65 |
+ |
goto breakopt; |
| 66 |
|
case 'i': /* input octree */ |
| 67 |
|
infile = argv[++i]; |
| 68 |
|
break; |
| 89 |
|
error(USER, errmsg); |
| 90 |
|
break; |
| 91 |
|
} |
| 92 |
< |
|
| 92 |
> |
breakopt: |
| 93 |
|
if (infile != NULL) { /* get old octree & objects */ |
| 94 |
|
if (thescene.cusize > FTINY) |
| 95 |
|
error(USER, "only one of '-b' or '-i'"); |
| 105 |
|
|
| 106 |
|
startobj = nobjects; /* previous objects already converted */ |
| 107 |
|
|
| 108 |
< |
for ( ; i < argc; i++) { /* read new files */ |
| 109 |
< |
if (nfiles >= MAXOBJFIL) |
| 110 |
< |
error(INTERNAL, "too many scene files"); |
| 111 |
< |
readobj(ofname[nfiles++] = argv[i]); |
| 112 |
< |
} |
| 108 |
> |
for ( ; i < argc; i++) /* read new scene descriptions */ |
| 109 |
> |
if (!strcmp(argv[i], "-")) { /* from stdin */ |
| 110 |
> |
readobj(NULL); |
| 111 |
> |
outflags &= ~IO_FILES; |
| 112 |
> |
} else { /* from file */ |
| 113 |
> |
if (nfiles >= MAXOBJFIL) |
| 114 |
> |
error(INTERNAL, "too many scene files"); |
| 115 |
> |
readobj(ofname[nfiles++] = argv[i]); |
| 116 |
> |
} |
| 117 |
> |
|
| 118 |
|
ofname[nfiles] = NULL; |
| 119 |
|
/* find bounding box */ |
| 120 |
|
bbmin[0] = bbmin[1] = bbmin[2] = FHUGE; |
| 203 |
|
|
| 204 |
|
in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu); |
| 205 |
|
|
| 206 |
< |
if (!in) |
| 206 |
> |
if (in == O_MISS) |
| 207 |
|
return; /* no intersection */ |
| 208 |
|
|
| 209 |
|
if (istree(cu->cutree)) { |
| 230 |
|
objset(oset, cu->cutree); |
| 231 |
|
cukid.cusize = cu->cusize * 0.5; |
| 232 |
|
|
| 233 |
< |
if (in == 2 || oset[0] < objlim || cukid.cusize < mincusize) { |
| 233 |
> |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
| 234 |
|
/* add to set */ |
| 235 |
|
if (oset[0] >= MAXSET) { |
| 236 |
|
sprintf(errmsg, |
| 252 |
|
if ((1<<j) & i) |
| 253 |
|
cukid.cuorg[j] += cukid.cusize; |
| 254 |
|
} |
| 255 |
+ |
/* surfaces first */ |
| 256 |
|
for (j = 1; j <= oset[0]; j++) |
| 257 |
< |
addobject(&cukid, oset[j]); |
| 257 |
> |
if (!isvolume(objptr(oset[j])->otype)) |
| 258 |
> |
addobject(&cukid, oset[j]); |
| 259 |
> |
/* then this object */ |
| 260 |
|
addobject(&cukid, obj); |
| 261 |
+ |
/* volumes last */ |
| 262 |
+ |
for (j = 1; j <= oset[0]; j++) |
| 263 |
+ |
if (isvolume(objptr(oset[j])->otype)) |
| 264 |
+ |
addobject(&cukid, oset[j]); |
| 265 |
|
octkid(ot, i) = cukid.cutree; |
| 266 |
|
} |
| 267 |
|
cu->cutree = ot; |