1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
33 |
|
int argc; |
34 |
|
char *argv[]; |
35 |
|
{ |
36 |
< |
int i, rv; |
36 |
> |
int i; |
37 |
> |
/* print out parser version */ |
38 |
> |
printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); |
39 |
|
/* initialize dispatch table */ |
40 |
|
mg_ehand[MG_E_COMMENT] = r_comment; /* we pass comments */ |
41 |
|
mg_ehand[MG_E_COLOR] = c_hcolor; /* they get color */ |
94 |
|
} |
95 |
|
putchar('\n'); |
96 |
|
if (i == argc) { /* convert stdin */ |
97 |
< |
if ((rv = mg_load(NULL)) != MG_OK) |
97 |
> |
if (mg_load(NULL) != MG_OK) |
98 |
|
exit(1); |
99 |
|
if (mg_nunknown) |
100 |
|
printf("## %s: %u unknown entities\n", |
103 |
|
for ( ; i < argc; i++) { |
104 |
|
printf("## %s %s ##############################\n", |
105 |
|
argv[0], argv[i]); |
106 |
< |
if ((rv = mg_load(argv[i])) != MG_OK) |
106 |
> |
if (mg_load(argv[i]) != MG_OK) |
107 |
|
exit(1); |
108 |
|
if (mg_nunknown) { |
109 |
|
printf("## %s %s: %u unknown entities\n", |
307 |
|
if ((mat = material()) == NULL) /* get material */ |
308 |
|
return(MG_EBADMAT); |
309 |
|
if (ac <= 5) { /* check for smoothing */ |
310 |
+ |
C_VERTEX *cva[5]; |
311 |
|
for (i = 1; i < ac; i++) { |
312 |
< |
if ((cv = c_getvert(av[i])) == NULL) |
312 |
> |
if ((cva[i-1] = c_getvert(av[i])) == NULL) |
313 |
|
return(MG_EUNDEF); |
314 |
< |
if (is0vect(cv->n)) |
314 |
> |
if (is0vect(cva[i-1]->n)) |
315 |
|
break; |
316 |
|
} |
317 |
< |
if (i == ac) { /* break into triangles */ |
318 |
< |
do_tri(mat, av[1], av[2], av[3]); |
317 |
> |
if (i == ac) { |
318 |
> |
i = flat_tri(cva[0]->p, cva[1]->p, cva[2]->p, |
319 |
> |
cva[0]->n, cva[1]->n, cva[2]->n); |
320 |
> |
if (i < 0) |
321 |
> |
return(MG_OK); /* degenerate (error?) */ |
322 |
> |
} |
323 |
> |
if (!i) { /* smoothed triangles */ |
324 |
> |
do_tri(mat, cva[0], cva[1], cva[2]); |
325 |
|
if (ac == 5) |
326 |
< |
do_tri(mat, av[3], av[4], av[1]); |
326 |
> |
do_tri(mat, cva[2], cva[3], cva[0]); |
327 |
|
return(MG_OK); |
328 |
|
} |
329 |
|
} |
355 |
|
if (ac < 2) |
356 |
|
return(MG_EARGC); |
357 |
|
/* construct output file name */ |
358 |
< |
if ((op = strrchr(av[1], '/')) == NULL) |
358 |
> |
if ((op = strrchr(av[1], '/')) != NULL) |
359 |
> |
op++; |
360 |
> |
else |
361 |
|
op = av[1]; |
362 |
|
(void)strcpy(fname, op); |
363 |
|
if ((op = strrchr(fname, '.')) == NULL) |
405 |
|
} |
406 |
|
|
407 |
|
|
408 |
< |
do_tri(mat, vn1, vn2, vn3) /* put out smoothed triangle */ |
409 |
< |
char *mat, *vn1, *vn2, *vn3; |
408 |
> |
do_tri(mat, cv1, cv2, cv3) /* put out smoothed triangle */ |
409 |
> |
char *mat; |
410 |
> |
C_VERTEX *cv1, *cv2, *cv3; |
411 |
|
{ |
412 |
|
static int ntris; |
413 |
|
BARYCCM bvecs; |
414 |
|
FLOAT bcoor[3][3]; |
415 |
< |
C_VERTEX *cv1, *cv2, *cv3; |
415 |
> |
C_VERTEX *cvt; |
416 |
|
FVECT v1, v2, v3; |
417 |
|
FVECT n1, n2, n3; |
418 |
|
register int i; |
419 |
< |
/* the following is repeat code, so assume it's OK */ |
420 |
< |
cv2 = c_getvert(vn2); |
421 |
< |
if (invert) { |
422 |
< |
cv3 = c_getvert(vn1); |
423 |
< |
cv1 = c_getvert(vn3); |
412 |
< |
} else { |
413 |
< |
cv1 = c_getvert(vn1); |
414 |
< |
cv3 = c_getvert(vn3); |
419 |
> |
|
420 |
> |
if (invert) { /* swap vertex order if inverted */ |
421 |
> |
cvt = cv1; |
422 |
> |
cv1 = cv3; |
423 |
> |
cv3 = cvt; |
424 |
|
} |
425 |
|
xf_xfmpoint(v1, cv1->p); |
426 |
|
xf_xfmpoint(v2, cv2->p); |
546 |
|
return(mname); |
547 |
|
} |
548 |
|
/* check for plastic */ |
549 |
< |
if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 || |
541 |
< |
c_isgrey(&c_cmaterial->rs_c))) { |
549 |
> |
if (c_cmaterial->rs < .1) { |
550 |
|
cvtcolor(radrgb, &c_cmaterial->rd_c, |
551 |
|
c_cmaterial->rd/(1.-c_cmaterial->rs)); |
552 |
|
fprintf(matfp, "\nvoid plastic %s\n0\n0\n", mname); |