6 |
|
*/ |
7 |
|
|
8 |
|
#include "copyright.h" |
9 |
+ |
#include "paths.h" |
10 |
+ |
#include "platform.h" |
11 |
|
#include "standard.h" |
12 |
+ |
#include "resolu.h" |
13 |
|
#include "cvmesh.h" |
14 |
|
#include "otypes.h" |
15 |
|
|
16 |
< |
extern int o_face(); |
16 |
> |
extern int o_face(); /* XXX should go to a header file */ |
17 |
|
|
18 |
|
int o_default() { return(O_MISS); } |
19 |
|
|
23 |
|
|
24 |
|
int nowarn = 0; /* supress warnings? */ |
25 |
|
|
26 |
< |
int objlim = 15; /* # of objects before split */ |
26 |
> |
int objlim = 9; /* # of objects before split */ |
27 |
|
|
28 |
|
int resolu = 16384; /* octree resolution limit */ |
29 |
|
|
30 |
|
double mincusize; /* minimum cube size from resolu */ |
31 |
|
|
32 |
+ |
static void addface(CUBE *cu, OBJECT obj); |
33 |
+ |
static void add2full(CUBE *cu, OBJECT obj); |
34 |
|
|
35 |
< |
main(argc, argv) /* compile a .OBJ file into a mesh */ |
36 |
< |
int argc; |
37 |
< |
char *argv[]; |
35 |
> |
|
36 |
> |
int |
37 |
> |
main( /* compile a .OBJ file into a mesh */ |
38 |
> |
int argc, |
39 |
> |
char *argv[] |
40 |
> |
) |
41 |
|
{ |
42 |
< |
int i; |
42 |
> |
int verbose = 0; |
43 |
> |
char *cp; |
44 |
> |
int i, j; |
45 |
|
|
46 |
|
progname = argv[0]; |
47 |
|
ofun[OBJ_FACE].funp = o_face; |
54 |
|
case 'r': /* resolution limit */ |
55 |
|
resolu = atoi(argv[++i]); |
56 |
|
break; |
57 |
+ |
case 'a': /* material file */ |
58 |
+ |
readobj(argv[++i]); |
59 |
+ |
break; |
60 |
+ |
case 'l': /* library material */ |
61 |
+ |
cp = getpath(argv[++i], getrlibpath(), R_OK); |
62 |
+ |
if (cp == NULL) { |
63 |
+ |
sprintf(errmsg, |
64 |
+ |
"cannot find library material: '%s'", |
65 |
+ |
argv[i]); |
66 |
+ |
error(SYSTEM, errmsg); |
67 |
+ |
} |
68 |
+ |
readobj(cp); |
69 |
+ |
break; |
70 |
|
case 'w': /* supress warnings */ |
71 |
|
nowarn = 1; |
72 |
|
break; |
73 |
+ |
case 'v': /* print mesh stats */ |
74 |
+ |
verbose = 1; |
75 |
+ |
break; |
76 |
|
default: |
77 |
|
sprintf(errmsg, "unknown option: '%s'", argv[i]); |
78 |
|
error(USER, errmsg); |
79 |
|
break; |
80 |
|
} |
81 |
+ |
|
82 |
+ |
if (i < argc-2) |
83 |
+ |
error(USER, "too many file arguments"); |
84 |
|
/* initialize mesh */ |
85 |
|
cvinit(i==argc-2 ? argv[i+1] : "<stdout>"); |
86 |
< |
|
87 |
< |
if (i == argc) /* read .OBJ file into triangles */ |
86 |
> |
/* read .OBJ file into triangles */ |
87 |
> |
if (i == argc) |
88 |
|
wfreadobj(NULL); |
89 |
|
else |
90 |
|
wfreadobj(argv[i]); |
94 |
|
if (i == argc-2) /* open output file */ |
95 |
|
if (freopen(argv[i+1], "w", stdout) == NULL) |
96 |
|
error(SYSTEM, "cannot open output file"); |
97 |
< |
#ifdef MSDOS |
69 |
< |
setmode(fileno(stdout), O_BINARY); |
70 |
< |
#endif |
97 |
> |
SET_FILE_BINARY(stdout); |
98 |
|
newheader("RADIANCE", stdout); /* new binary file header */ |
99 |
|
printargs(i<argc ? i+1 : argc, argv, stdout); |
100 |
|
fputformat(MESHFMT, stdout); |
103 |
|
mincusize = ourmesh->mcube.cusize / resolu - FTINY; |
104 |
|
|
105 |
|
for (i = 0; i < nobjects; i++) /* add triangles to octree */ |
106 |
< |
addface(&ourmesh->mcube, i); |
106 |
> |
if (objptr(i)->otype == OBJ_FACE) |
107 |
> |
addface(&ourmesh->mcube, i); |
108 |
|
|
109 |
|
/* optimize octree */ |
110 |
|
ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree); |
116 |
|
|
117 |
|
writemesh(ourmesh, stdout); /* write mesh to output */ |
118 |
|
|
119 |
< |
printmeshstats(ourmesh, stderr); |
119 |
> |
if (verbose) |
120 |
> |
printmeshstats(ourmesh, stderr); |
121 |
|
|
122 |
|
quit(0); |
123 |
+ |
return 0; /* pro forma return */ |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
void |
128 |
< |
quit(code) /* exit program */ |
129 |
< |
int code; |
128 |
> |
quit( /* exit program */ |
129 |
> |
int code |
130 |
> |
) |
131 |
|
{ |
132 |
|
exit(code); |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
void |
137 |
< |
cputs() /* interactive error */ |
137 |
> |
cputs(void) /* interactive error */ |
138 |
|
{ |
139 |
|
/* referenced, but not used */ |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
void |
144 |
< |
wputs(s) /* warning message */ |
145 |
< |
char *s; |
144 |
> |
wputs( /* warning message */ |
145 |
> |
char *s |
146 |
> |
) |
147 |
|
{ |
148 |
|
if (!nowarn) |
149 |
|
eputs(s); |
151 |
|
|
152 |
|
|
153 |
|
void |
154 |
< |
eputs(s) /* put string to stderr */ |
155 |
< |
register char *s; |
154 |
> |
eputs( /* put string to stderr */ |
155 |
> |
register char *s |
156 |
> |
) |
157 |
|
{ |
158 |
|
static int inln = 0; |
159 |
|
|
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
< |
addface(cu, obj) /* add a face to a cube */ |
171 |
< |
register CUBE *cu; |
172 |
< |
OBJECT obj; |
170 |
> |
static void |
171 |
> |
addface( /* add a face to a cube */ |
172 |
> |
register CUBE *cu, |
173 |
> |
OBJECT obj |
174 |
> |
) |
175 |
|
{ |
141 |
– |
CUBE cukid; |
142 |
– |
OCTREE ot; |
143 |
– |
OBJECT oset[MAXSET+1]; |
144 |
– |
register int i, j; |
176 |
|
|
177 |
|
if (o_face(objptr(obj), cu) == O_MISS) |
178 |
|
return; |
179 |
|
|
180 |
|
if (istree(cu->cutree)) { |
181 |
< |
/* do children */ |
181 |
> |
CUBE cukid; /* do children */ |
182 |
> |
int i, j; |
183 |
|
cukid.cusize = cu->cusize * 0.5; |
184 |
|
for (i = 0; i < 8; i++) { |
185 |
|
cukid.cutree = octkid(cu->cutree, i); |
194 |
|
return; |
195 |
|
} |
196 |
|
if (isempty(cu->cutree)) { |
197 |
< |
/* singular set */ |
197 |
> |
OBJECT oset[2]; /* singular set */ |
198 |
|
oset[0] = 1; oset[1] = obj; |
199 |
|
cu->cutree = fullnode(oset); |
200 |
|
return; |
201 |
|
} |
202 |
|
/* add to full node */ |
203 |
+ |
add2full(cu, obj); |
204 |
+ |
} |
205 |
+ |
|
206 |
+ |
|
207 |
+ |
static void |
208 |
+ |
add2full( /* add object to full node */ |
209 |
+ |
register CUBE *cu, |
210 |
+ |
OBJECT obj |
211 |
+ |
) |
212 |
+ |
{ |
213 |
+ |
OCTREE ot; |
214 |
+ |
OBJECT oset[MAXSET+1]; |
215 |
+ |
CUBE cukid; |
216 |
+ |
register int i, j; |
217 |
+ |
|
218 |
|
objset(oset, cu->cutree); |
219 |
|
cukid.cusize = cu->cusize * 0.5; |
220 |
|
|
221 |
< |
if (oset[0] < objlim || cukid.cusize < mincusize) { |
221 |
> |
if (oset[0] < objlim || cukid.cusize < |
222 |
> |
(oset[0] < MAXSET ? mincusize : mincusize/256.0)) { |
223 |
|
/* add to set */ |
224 |
|
if (oset[0] >= MAXSET) { |
225 |
< |
sprintf(errmsg, "set overflow in addface (%s)", |
225 |
> |
sprintf(errmsg, "set overflow in addobject (%s)", |
226 |
|
objptr(obj)->oname); |
227 |
|
error(INTERNAL, errmsg); |
228 |
|
} |