23 |
|
|
24 |
|
double emult = 1.; /* emitter multiplier */ |
25 |
|
|
26 |
< |
FILE *matfp = stdout; /* material output file */ |
26 |
> |
FILE *matfp; /* material output file */ |
27 |
|
|
28 |
|
int r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph(); |
29 |
|
char *material(), *object(), *addarg(); |
34 |
|
char *argv[]; |
35 |
|
{ |
36 |
|
int i; |
37 |
+ |
|
38 |
+ |
matfp = stdout; |
39 |
|
/* print out parser version */ |
40 |
|
printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); |
41 |
|
/* initialize dispatch table */ |
309 |
|
if ((mat = material()) == NULL) /* get material */ |
310 |
|
return(MG_EBADMAT); |
311 |
|
if (ac <= 5) { /* check for smoothing */ |
312 |
+ |
C_VERTEX *cva[5]; |
313 |
|
for (i = 1; i < ac; i++) { |
314 |
< |
if ((cv = c_getvert(av[i])) == NULL) |
314 |
> |
if ((cva[i-1] = c_getvert(av[i])) == NULL) |
315 |
|
return(MG_EUNDEF); |
316 |
< |
if (is0vect(cv->n)) |
316 |
> |
if (is0vect(cva[i-1]->n)) |
317 |
|
break; |
318 |
|
} |
319 |
< |
if (i == ac) { /* break into triangles */ |
320 |
< |
do_tri(mat, av[1], av[2], av[3]); |
319 |
> |
if (i == ac) { |
320 |
> |
i = flat_tri(cva[0]->p, cva[1]->p, cva[2]->p, |
321 |
> |
cva[0]->n, cva[1]->n, cva[2]->n); |
322 |
> |
if (i < 0) |
323 |
> |
return(MG_OK); /* degenerate (error?) */ |
324 |
> |
} |
325 |
> |
if (!i) { /* smoothed triangles */ |
326 |
> |
do_tri(mat, cva[0], cva[1], cva[2]); |
327 |
|
if (ac == 5) |
328 |
< |
do_tri(mat, av[3], av[4], av[1]); |
328 |
> |
do_tri(mat, cva[2], cva[3], cva[0]); |
329 |
|
return(MG_OK); |
330 |
|
} |
331 |
|
} |
357 |
|
if (ac < 2) |
358 |
|
return(MG_EARGC); |
359 |
|
/* construct output file name */ |
360 |
< |
if ((op = strrchr(av[1], '/')) == NULL) |
360 |
> |
if ((op = strrchr(av[1], '/')) != NULL) |
361 |
> |
op++; |
362 |
> |
else |
363 |
|
op = av[1]; |
364 |
|
(void)strcpy(fname, op); |
365 |
|
if ((op = strrchr(fname, '.')) == NULL) |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
< |
do_tri(mat, vn1, vn2, vn3) /* put out smoothed triangle */ |
411 |
< |
char *mat, *vn1, *vn2, *vn3; |
410 |
> |
do_tri(mat, cv1, cv2, cv3) /* put out smoothed triangle */ |
411 |
> |
char *mat; |
412 |
> |
C_VERTEX *cv1, *cv2, *cv3; |
413 |
|
{ |
414 |
|
static int ntris; |
415 |
|
BARYCCM bvecs; |
416 |
|
FLOAT bcoor[3][3]; |
417 |
< |
C_VERTEX *cv1, *cv2, *cv3; |
417 |
> |
C_VERTEX *cvt; |
418 |
|
FVECT v1, v2, v3; |
419 |
|
FVECT n1, n2, n3; |
420 |
|
register int i; |
421 |
< |
/* the following is repeat code, so assume it's OK */ |
422 |
< |
cv2 = c_getvert(vn2); |
423 |
< |
if (invert) { |
424 |
< |
cv3 = c_getvert(vn1); |
425 |
< |
cv1 = c_getvert(vn3); |
414 |
< |
} else { |
415 |
< |
cv1 = c_getvert(vn1); |
416 |
< |
cv3 = c_getvert(vn3); |
421 |
> |
|
422 |
> |
if (invert) { /* swap vertex order if inverted */ |
423 |
> |
cvt = cv1; |
424 |
> |
cv1 = cv3; |
425 |
> |
cv3 = cvt; |
426 |
|
} |
427 |
|
xf_xfmpoint(v1, cv1->p); |
428 |
|
xf_xfmpoint(v2, cv2->p); |