40 |
|
|
41 |
|
int smooth = 0; /* apply smoothing? */ |
42 |
|
int objout = 0; /* output .OBJ format? */ |
43 |
+ |
int rev = 0; /* invert normal directions? */ |
44 |
|
|
45 |
|
char *modname, *surfname; |
46 |
|
|
55 |
|
} datarec; /* our recorded data */ |
56 |
|
|
57 |
|
/* XXX this is redundant with rt/noise3.c, should go to a library */ |
58 |
< |
double l_hermite(), l_bezier(), l_bspline(), l_dataval(); |
58 |
> |
double l_hermite(char *), l_bezier(char *), |
59 |
> |
l_bspline(char *), l_dataval(char *); |
60 |
|
|
61 |
|
typedef struct { |
62 |
|
int valid; /* point is valid (vertex number) */ |
63 |
< |
int nvalid; /* normal is valid */ |
63 |
> |
int nvalid; /* normal is valid (normal number) */ |
64 |
|
FVECT p; /* vertex position */ |
65 |
|
FVECT n; /* average normal */ |
66 |
|
RREAL uv[2]; /* (u,v) position */ |
111 |
|
smooth++; |
112 |
|
else if (!strcmp(argv[i], "-o")) |
113 |
|
objout++; |
114 |
+ |
else if (!strcmp(argv[i], "-i")) |
115 |
+ |
rev = 1; |
116 |
|
else |
117 |
|
goto userror; |
118 |
|
|
154 |
|
/* print header */ |
155 |
|
fputs("# ", stdout); |
156 |
|
printargs(argc, argv, stdout); |
157 |
< |
eclock = 0; |
157 |
> |
doptimize(1); |
158 |
> |
eclock++; |
159 |
|
/* initialize */ |
160 |
|
comprow(-1.0/m, row0, n); |
161 |
|
comprow(0.0, row1, n); |
313 |
|
int n |
314 |
|
) |
315 |
|
{ |
316 |
+ |
static FVECT prevNorm; |
317 |
+ |
|
318 |
|
for ( ; n-- >= 0; rp++) { |
319 |
|
if (!rp->valid) |
320 |
|
continue; |
321 |
|
fputs("v ", stdout); |
322 |
|
pvect(rp->p); |
323 |
< |
if (smooth && !ZEROVECT(rp->n)) { |
323 |
> |
rp->valid = ++nverts; |
324 |
> |
printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); |
325 |
> |
if (!smooth || ZEROVECT(rp->n)) |
326 |
> |
rp->nvalid = 0; |
327 |
> |
else if (VABSEQ(rp->n, prevNorm)) |
328 |
> |
rp->nvalid = nnorms; |
329 |
> |
else { |
330 |
|
printf("\tvn %.9g %.9g %.9g\n", |
331 |
|
rp->n[0], rp->n[1], rp->n[2]); |
332 |
|
rp->nvalid = ++nnorms; |
333 |
< |
} else |
334 |
< |
rp->nvalid = 0; |
322 |
< |
printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); |
323 |
< |
rp->valid = ++nverts; |
333 |
> |
VCOPY(prevNorm, rp->n); |
334 |
> |
} |
335 |
|
} |
336 |
|
} |
337 |
|
|
361 |
|
int axis; |
362 |
|
FVECT v1, v2, vc1, vc2; |
363 |
|
int ok1, ok2; |
364 |
+ |
|
365 |
+ |
if (rev) { /* reverse normals? */ |
366 |
+ |
POINT *pt = p1; p1 = p2; p2 = pt; |
367 |
+ |
} |
368 |
|
/* compute exact normals */ |
369 |
|
ok1 = (p0->valid && p1->valid && p2->valid); |
370 |
|
if (ok1) { |
545 |
|
fvsum(v2, r1[0].p, r1[-1].p, -1.0); |
546 |
|
else |
547 |
|
fvsum(v2, r1[1].p, r1[-1].p, -1.0); |
548 |
< |
fcross(r1[0].n, v1, v2); |
548 |
> |
if (rev) |
549 |
> |
fcross(r1[0].n, v2, v1); |
550 |
> |
else |
551 |
> |
fcross(r1[0].n, v1, v2); |
552 |
|
normalize(r1[0].n); |
553 |
|
skip: |
554 |
|
r0++; r1++; r2++; |