69 |
|
|
70 |
|
|
71 |
|
int |
72 |
< |
cvpoly(n, vp, vn, vc) /* convert a polygon to extended triangles */ |
72 |
> |
cvpoly(mo, n, vp, vn, vc) /* convert a polygon to extended triangles */ |
73 |
> |
OBJECT mo; |
74 |
|
int n; |
75 |
|
FVECT *vp; |
76 |
|
FVECT *vn; |
98 |
|
tc[0] = tc[1] = tc[2] = NULL; |
99 |
|
} |
100 |
|
if (n == 3) /* output single triangle */ |
101 |
< |
return(cvtri(vp[0], vp[1], vp[2], |
101 |
> |
return(cvtri(mo, vp[0], vp[1], vp[2], |
102 |
|
tn[0], tn[1], tn[2], |
103 |
|
tc[0], tc[1], tc[2])); |
104 |
|
|
115 |
|
if (flags & MT_UV) |
116 |
|
for (i = 3; i--; ) |
117 |
|
tc[i] = vc[ord[i]]; |
118 |
< |
i = cvtri(vp[ord[0]], vp[ord[1]], vp[ord[2]], |
118 |
> |
tcnt += cvtri(mo, vp[ord[0]], vp[ord[1]], vp[ord[2]], |
119 |
|
tn[0], tn[1], tn[2], |
120 |
|
tc[0], tc[1], tc[2]); |
120 |
– |
if (i < 0) |
121 |
– |
return(i); |
122 |
– |
tcnt += i; |
121 |
|
/* remove vertex and rotate */ |
122 |
|
n--; |
123 |
|
j = ord[0]; |
155 |
|
|
156 |
|
|
157 |
|
int /* create an extended triangle */ |
158 |
< |
cvtri(vp1, vp2, vp3, vn1, vn2, vn3, vc1, vc2, vc3) |
158 |
> |
cvtri(mo, vp1, vp2, vp3, vn1, vn2, vn3, vc1, vc2, vc3) |
159 |
> |
OBJECT mo; |
160 |
|
FVECT vp1, vp2, vp3; |
161 |
|
FVECT vn1, vn2, vn3; |
162 |
|
FLOAT vc1[2], vc2[2], vc3[2]; |
163 |
|
{ |
164 |
< |
char buf[32]; |
165 |
< |
int flags; |
166 |
< |
TRIDATA *ts; |
167 |
< |
OBJECT fobj; |
168 |
< |
FACE *f; |
169 |
< |
OBJREC *fop; |
170 |
< |
int j; |
164 |
> |
static OBJECT fobj = OVOID; |
165 |
> |
char buf[32]; |
166 |
> |
int flags; |
167 |
> |
TRIDATA *ts; |
168 |
> |
FACE *f; |
169 |
> |
OBJREC *fop; |
170 |
> |
int j; |
171 |
|
|
172 |
|
flags = MT_V; |
173 |
|
if (vn1 != NULL && vn2 != NULL && vn3 != NULL) |
174 |
|
flags |= MT_N; |
175 |
|
if (vc1 != NULL && vc2 != NULL && vc3 != NULL) |
176 |
|
flags |= MT_UV; |
177 |
< |
/* create extended triangle */ |
178 |
< |
fobj = newobject(); |
179 |
< |
if (fobj == OVOID) |
180 |
< |
return(-1); |
181 |
< |
fop = objptr(fobj); |
182 |
< |
fop->omod = OVOID; |
183 |
< |
fop->otype = OBJ_FACE; |
184 |
< |
sprintf(buf, "t%d", fobj); |
185 |
< |
fop->oname = savqstr(buf); |
186 |
< |
fop->oargs.nfargs = 9; |
187 |
< |
fop->oargs.farg = (FLOAT *)malloc(9*sizeof(FLOAT)); |
188 |
< |
if (fop->oargs.farg == NULL) |
189 |
< |
goto nomem; |
177 |
> |
if (fobj == OVOID) { /* create new triangle object */ |
178 |
> |
fobj = newobject(); |
179 |
> |
if (fobj == OVOID) |
180 |
> |
goto nomem; |
181 |
> |
fop = objptr(fobj); |
182 |
> |
fop->omod = mo; |
183 |
> |
fop->otype = OBJ_FACE; |
184 |
> |
sprintf(buf, "t%d", fobj); |
185 |
> |
fop->oname = savqstr(buf); |
186 |
> |
fop->oargs.nfargs = 9; |
187 |
> |
fop->oargs.farg = (FLOAT *)malloc(9*sizeof(FLOAT)); |
188 |
> |
if (fop->oargs.farg == NULL) |
189 |
> |
goto nomem; |
190 |
> |
} else { /* else reuse failed one */ |
191 |
> |
fop = objptr(fobj); |
192 |
> |
if (fop->otype != OBJ_FACE || fop->oargs.nfargs != 9) |
193 |
> |
error(CONSISTENCY, "code error 1 in cvtri"); |
194 |
> |
} |
195 |
|
for (j = 3; j--; ) { |
196 |
|
fop->oargs.farg[j] = vp1[j]; |
197 |
|
fop->oargs.farg[3+j] = vp2[j]; |
198 |
|
fop->oargs.farg[6+j] = vp3[j]; |
199 |
|
} |
200 |
|
/* create face record */ |
201 |
< |
if ((f = getface(fop)) == NULL || f->area == 0.) { |
202 |
< |
freeobjects(fobj, 1); |
201 |
> |
f = getface(fop); |
202 |
> |
if (f->area == 0.) { |
203 |
> |
free_os(fop); |
204 |
|
return(0); |
205 |
|
} |
206 |
|
if (fop->os != (char *)f) |
207 |
< |
error(CONSISTENCY, "code error in cvtri"); |
207 |
> |
error(CONSISTENCY, "code error 2 in cvtri"); |
208 |
|
/* follow with auxliary data */ |
209 |
|
f = (FACE *)realloc((void *)f, sizeof(FACE)+tdsize(flags)); |
210 |
|
if (f == NULL) |
231 |
|
add2bounds(vp1, vc1); |
232 |
|
add2bounds(vp2, vc2); |
233 |
|
add2bounds(vp3, vc3); |
234 |
+ |
fobj = OVOID; /* we used this one */ |
235 |
|
return(1); |
236 |
|
nomem: |
237 |
|
error(SYSTEM, "out of memory in cvtri"); |
269 |
|
for (i = 3; i--; ) |
270 |
|
for (j = 2; j--; ) |
271 |
|
vert[i].uv[j] = ts->vc[i][j]; |
272 |
< |
ts->obj = addmeshtri(ourmesh, vert); |
272 |
> |
ts->obj = addmeshtri(ourmesh, vert, o->omod); |
273 |
|
if (ts->obj == OVOID) |
274 |
|
error(INTERNAL, "addmeshtri failed"); |
275 |
|
return(ts->obj); |