| 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; |
| 179 |
|
eputs(s) /* put string to stderr */ |
| 180 |
|
register char *s; |
| 181 |
|
{ |
| 182 |
< |
static int inline = 0; |
| 182 |
> |
static int inln = 0; |
| 183 |
|
|
| 184 |
< |
if (!inline++) { |
| 184 |
> |
if (!inln++) { |
| 185 |
|
fputs(progname, stderr); |
| 186 |
|
fputs(": ", stderr); |
| 187 |
|
} |
| 188 |
|
fputs(s, stderr); |
| 189 |
|
if (*s && s[strlen(s)-1] == '\n') |
| 190 |
< |
inline = 0; |
| 190 |
> |
inln = 0; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 195 |
|
register CUBE *cu; |
| 196 |
|
OBJECT obj; |
| 197 |
|
{ |
| 198 |
+ |
#define nexti(n) ((ndx += cnt*cnt++)%(n)) |
| 199 |
+ |
static unsigned long ndx; |
| 200 |
+ |
static unsigned int cnt; |
| 201 |
|
CUBE cukid; |
| 202 |
|
OCTREE ot; |
| 203 |
|
OBJECT oset[MAXSET+1]; |
| 204 |
< |
int in; |
| 204 |
> |
int in, k; |
| 205 |
|
register int i, j; |
| 206 |
|
|
| 207 |
|
in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu); |
| 208 |
|
|
| 209 |
< |
if (!in) |
| 209 |
> |
if (in == O_MISS) |
| 210 |
|
return; /* no intersection */ |
| 211 |
|
|
| 212 |
|
if (istree(cu->cutree)) { |
| 233 |
|
objset(oset, cu->cutree); |
| 234 |
|
cukid.cusize = cu->cusize * 0.5; |
| 235 |
|
|
| 236 |
< |
if (in == 2 || oset[0] < objlim || cukid.cusize < mincusize) { |
| 236 |
> |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
| 237 |
|
/* add to set */ |
| 238 |
|
if (oset[0] >= MAXSET) { |
| 239 |
|
sprintf(errmsg, |
| 255 |
|
if ((1<<j) & i) |
| 256 |
|
cukid.cuorg[j] += cukid.cusize; |
| 257 |
|
} |
| 258 |
+ |
/* surfaces first */ |
| 259 |
|
for (j = 1; j <= oset[0]; j++) |
| 260 |
< |
addobject(&cukid, oset[j]); |
| 260 |
> |
if (!isvolume(objptr(oset[j])->otype)) |
| 261 |
> |
addobject(&cukid, oset[j]); |
| 262 |
> |
/* then this object */ |
| 263 |
|
addobject(&cukid, obj); |
| 264 |
+ |
/* volumes last */ |
| 265 |
+ |
k = nexti(oset[0]); /* random start */ |
| 266 |
+ |
for (j = k+1; j <= oset[0]; j++) |
| 267 |
+ |
if (isvolume(objptr(oset[j])->otype)) |
| 268 |
+ |
addobject(&cukid, oset[j]); |
| 269 |
+ |
for (j = 1; j <= k; j++) |
| 270 |
+ |
if (isvolume(objptr(oset[j])->otype)) |
| 271 |
+ |
addobject(&cukid, oset[j]); |
| 272 |
|
octkid(ot, i) = cukid.cutree; |
| 273 |
|
} |
| 274 |
|
cu->cutree = ot; |
| 275 |
|
} |
| 276 |
|
} |
| 277 |
+ |
#undef nexti |
| 278 |
|
} |