1 |
– |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Convert MGF (Materials and Geometry Format) to Radiance |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <stdlib.h> |
10 |
|
#include <math.h> |
11 |
|
#include <string.h> |
12 |
|
#include "mgflib/parser.h" |
21 |
|
|
22 |
|
double emult = 1.; /* emitter multiplier */ |
23 |
|
|
24 |
< |
FILE *matfp = stdout; /* material output file */ |
24 |
> |
FILE *matfp; /* material output file */ |
25 |
|
|
26 |
|
int r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph(); |
27 |
|
char *material(), *object(), *addarg(); |
32 |
|
char *argv[]; |
33 |
|
{ |
34 |
|
int i; |
35 |
+ |
|
36 |
+ |
matfp = stdout; |
37 |
|
/* print out parser version */ |
38 |
|
printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); |
39 |
|
/* initialize dispatch table */ |
296 |
|
char **av; |
297 |
|
{ |
298 |
|
static int nfaces; |
299 |
+ |
int myi = invert; |
300 |
|
char *mat; |
301 |
|
register int i; |
302 |
|
register C_VERTEX *cv; |
315 |
|
if (is0vect(cva[i-1]->n)) |
316 |
|
break; |
317 |
|
} |
318 |
< |
if (i == ac) { |
318 |
> |
if (i < ac) |
319 |
> |
i = ISFLAT; |
320 |
> |
else |
321 |
|
i = flat_tri(cva[0]->p, cva[1]->p, cva[2]->p, |
322 |
|
cva[0]->n, cva[1]->n, cva[2]->n); |
323 |
< |
if (i < 0) |
324 |
< |
return(MG_OK); /* degenerate (error?) */ |
323 |
> |
if (i == DEGEN) |
324 |
> |
return(MG_OK); /* degenerate (error?) */ |
325 |
> |
if (i == RVBENT) { |
326 |
> |
myi = !myi; |
327 |
> |
i = ISBENT; |
328 |
> |
} else if (i == RVFLAT) { |
329 |
> |
myi = !myi; |
330 |
> |
i = ISFLAT; |
331 |
|
} |
332 |
< |
if (!i) { /* smoothed triangles */ |
333 |
< |
do_tri(mat, cva[0], cva[1], cva[2]); |
332 |
> |
if (i == ISBENT) { /* smoothed triangles */ |
333 |
> |
do_tri(mat, cva[0], cva[1], cva[2], myi); |
334 |
|
if (ac == 5) |
335 |
< |
do_tri(mat, cva[2], cva[3], cva[0]); |
335 |
> |
do_tri(mat, cva[2], cva[3], cva[0], myi); |
336 |
|
return(MG_OK); |
337 |
|
} |
338 |
|
} |
340 |
|
printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces); |
341 |
|
printf("0\n0\n%d\n", 3*(ac-1)); |
342 |
|
for (i = 1; i < ac; i++) { /* get, transform, print each vertex */ |
343 |
< |
if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL) |
343 |
> |
if ((cv = c_getvert(av[myi ? ac-i : i])) == NULL) |
344 |
|
return(MG_EUNDEF); |
345 |
|
xf_xfmpoint(v, cv->p); |
346 |
|
putv(v); |
414 |
|
} |
415 |
|
|
416 |
|
|
417 |
< |
do_tri(mat, cv1, cv2, cv3) /* put out smoothed triangle */ |
417 |
> |
do_tri(mat, cv1, cv2, cv3, iv) /* put out smoothed triangle */ |
418 |
|
char *mat; |
419 |
|
C_VERTEX *cv1, *cv2, *cv3; |
420 |
+ |
int iv; |
421 |
|
{ |
422 |
|
static int ntris; |
423 |
|
BARYCCM bvecs; |
424 |
< |
FLOAT bcoor[3][3]; |
424 |
> |
RREAL bcoor[3][3]; |
425 |
|
C_VERTEX *cvt; |
426 |
|
FVECT v1, v2, v3; |
427 |
|
FVECT n1, n2, n3; |
428 |
|
register int i; |
429 |
|
|
430 |
< |
if (invert) { /* swap vertex order if inverted */ |
430 |
> |
if (iv) { /* swap vertex order if inverted */ |
431 |
|
cvt = cv1; |
432 |
|
cv1 = cv3; |
433 |
|
cv3 = cvt; |