37 |
|
|
38 |
|
FVECT meshbounds[2]; /* mesh bounding box */ |
39 |
|
|
40 |
+ |
static void add2bounds(FVECT vp, RREAL vc[2]); |
41 |
+ |
static OBJECT cvmeshtri(OBJECT obj); |
42 |
+ |
static OCTREE cvmeshoct(OCTREE ot); |
43 |
|
|
44 |
+ |
|
45 |
+ |
|
46 |
|
MESH * |
47 |
< |
cvinit(nm) /* initialize empty mesh */ |
48 |
< |
char *nm; |
47 |
> |
cvinit( /* initialize empty mesh */ |
48 |
> |
char *nm |
49 |
> |
) |
50 |
|
{ |
51 |
|
/* free old mesh, first */ |
52 |
|
if (ourmesh != NULL) { |
75 |
|
} |
76 |
|
|
77 |
|
|
72 |
– |
int |
73 |
– |
cvpoly(mo, n, vp, vn, vc) /* convert a polygon to extended triangles */ |
74 |
– |
OBJECT mo; |
75 |
– |
int n; |
76 |
– |
FVECT *vp; |
77 |
– |
FVECT *vn; |
78 |
– |
RREAL (*vc)[2]; |
79 |
– |
{ |
80 |
– |
int tcnt = 0; |
81 |
– |
int flags; |
82 |
– |
RREAL *tn[3], *tc[3]; |
83 |
– |
int *ord; |
84 |
– |
int i, j; |
85 |
– |
|
86 |
– |
if (n < 3) /* degenerate face */ |
87 |
– |
return(0); |
88 |
– |
flags = MT_V; |
89 |
– |
if (vn != NULL) { |
90 |
– |
tn[0] = vn[0]; tn[1] = vn[1]; tn[2] = vn[2]; |
91 |
– |
flags |= MT_N; |
92 |
– |
} else { |
93 |
– |
tn[0] = tn[1] = tn[2] = NULL; |
94 |
– |
} |
95 |
– |
if (vc != NULL) { |
96 |
– |
tc[0] = vc[0]; tc[1] = vc[1]; tc[2] = vc[2]; |
97 |
– |
flags |= MT_UV; |
98 |
– |
} else { |
99 |
– |
tc[0] = tc[1] = tc[2] = NULL; |
100 |
– |
} |
101 |
– |
if (n == 3) /* output single triangle */ |
102 |
– |
return(cvtri(mo, vp[0], vp[1], vp[2], |
103 |
– |
tn[0], tn[1], tn[2], |
104 |
– |
tc[0], tc[1], tc[2])); |
105 |
– |
|
106 |
– |
/* decimate polygon (assumes convex) */ |
107 |
– |
ord = (int *)malloc(n*sizeof(int)); |
108 |
– |
if (ord == NULL) |
109 |
– |
error(SYSTEM, "out of memory in cvpoly"); |
110 |
– |
for (i = n; i--; ) |
111 |
– |
ord[i] = i; |
112 |
– |
while (n >= 3) { |
113 |
– |
if (flags & MT_N) |
114 |
– |
for (i = 3; i--; ) |
115 |
– |
tn[i] = vn[ord[i]]; |
116 |
– |
if (flags & MT_UV) |
117 |
– |
for (i = 3; i--; ) |
118 |
– |
tc[i] = vc[ord[i]]; |
119 |
– |
tcnt += cvtri(mo, vp[ord[0]], vp[ord[1]], vp[ord[2]], |
120 |
– |
tn[0], tn[1], tn[2], |
121 |
– |
tc[0], tc[1], tc[2]); |
122 |
– |
/* remove vertex and rotate */ |
123 |
– |
n--; |
124 |
– |
j = ord[0]; |
125 |
– |
for (i = 0; i < n-1; i++) |
126 |
– |
ord[i] = ord[i+2]; |
127 |
– |
ord[i] = j; |
128 |
– |
} |
129 |
– |
free((void *)ord); |
130 |
– |
return(tcnt); |
131 |
– |
} |
132 |
– |
|
133 |
– |
|
78 |
|
static void |
79 |
< |
add2bounds(vp, vc) /* add point and uv coordinate to bounds */ |
80 |
< |
FVECT vp; |
81 |
< |
RREAL vc[2]; |
79 |
> |
add2bounds( /* add point and uv coordinate to bounds */ |
80 |
> |
FVECT vp, |
81 |
> |
RREAL vc[2] |
82 |
> |
) |
83 |
|
{ |
84 |
|
register int j; |
85 |
|
|
101 |
|
|
102 |
|
|
103 |
|
int /* create an extended triangle */ |
104 |
< |
cvtri(mo, vp1, vp2, vp3, vn1, vn2, vn3, vc1, vc2, vc3) |
105 |
< |
OBJECT mo; |
106 |
< |
FVECT vp1, vp2, vp3; |
107 |
< |
FVECT vn1, vn2, vn3; |
108 |
< |
RREAL vc1[2], vc2[2], vc3[2]; |
104 |
> |
cvtri( |
105 |
> |
OBJECT mo, |
106 |
> |
FVECT vp1, |
107 |
> |
FVECT vp2, |
108 |
> |
FVECT vp3, |
109 |
> |
FVECT vn1, |
110 |
> |
FVECT vn2, |
111 |
> |
FVECT vn3, |
112 |
> |
RREAL vc1[2], |
113 |
> |
RREAL vc2[2], |
114 |
> |
RREAL vc3[2] |
115 |
> |
) |
116 |
|
{ |
117 |
|
static OBJECT fobj = OVOID; |
118 |
|
char buf[32]; |
155 |
|
fop = objptr(fobj); |
156 |
|
fop->omod = mo; |
157 |
|
fop->otype = OBJ_FACE; |
158 |
< |
sprintf(buf, "t%d", fobj); |
158 |
> |
sprintf(buf, "t%ld", (long)fobj); |
159 |
|
fop->oname = savqstr(buf); |
160 |
|
fop->oargs.nfargs = 9; |
161 |
|
fop->oargs.farg = (RREAL *)malloc(9*sizeof(RREAL)); |
214 |
|
|
215 |
|
|
216 |
|
static OBJECT |
217 |
< |
cvmeshtri(obj) /* add an extended triangle to our mesh */ |
218 |
< |
OBJECT obj; |
217 |
> |
cvmeshtri( /* add an extended triangle to our mesh */ |
218 |
> |
OBJECT obj |
219 |
> |
) |
220 |
|
{ |
221 |
|
OBJREC *o = objptr(obj); |
222 |
|
TRIDATA *ts; |
252 |
|
|
253 |
|
|
254 |
|
void |
255 |
< |
cvmeshbounds() /* set mesh boundaries */ |
255 |
> |
cvmeshbounds(void) /* set mesh boundaries */ |
256 |
|
{ |
257 |
|
int i; |
258 |
|
|
279 |
|
double marg; /* expand past endpoints */ |
280 |
|
marg = (2./(1L<<(8*sizeof(uint16)))) * |
281 |
|
(ourmesh->uvlim[1][i] - |
282 |
< |
ourmesh->uvlim[0][i]); |
282 |
> |
ourmesh->uvlim[0][i]) + FTINY; |
283 |
|
ourmesh->uvlim[0][i] -= marg; |
284 |
|
ourmesh->uvlim[1][i] += marg; |
285 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
static OCTREE |
292 |
< |
cvmeshoct(ot) /* convert triangles in subtree */ |
293 |
< |
OCTREE ot; |
292 |
> |
cvmeshoct( /* convert triangles in subtree */ |
293 |
> |
OCTREE ot |
294 |
> |
) |
295 |
|
{ |
296 |
|
int i; |
297 |
|
|
315 |
|
|
316 |
|
|
317 |
|
MESH * |
318 |
< |
cvmesh() /* convert mesh and octree leaf nodes */ |
318 |
> |
cvmesh(void) /* convert mesh and octree leaf nodes */ |
319 |
|
{ |
320 |
|
if (ourmesh == NULL) |
321 |
|
return(NULL); |