From 7d1236924a76b9690891af4bdcf5127875c6f08f Mon Sep 17 00:00:00 2001 From: "Gregory J. Ward" Date: Thu, 1 Apr 2021 14:52:55 +0000 Subject: [PATCH] perf(gensurf): .OBJ output now re-uses identical subsequent normal IDs --- src/gen/gensurf.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/gen/gensurf.c b/src/gen/gensurf.c index a564f3c58..4bdb0a746 100644 --- a/src/gen/gensurf.c +++ b/src/gen/gensurf.c @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: gensurf.c,v 2.28 2020/11/14 00:29:51 greg Exp $"; +static const char RCSid[] = "$Id: gensurf.c,v 2.29 2021/04/01 14:52:55 greg Exp $"; #endif /* * gensurf.c - program to generate functional surfaces @@ -58,7 +58,7 @@ double l_hermite(), l_bezier(), l_bspline(), l_dataval(); typedef struct { int valid; /* point is valid (vertex number) */ - int nvalid; /* normal is valid */ + int nvalid; /* normal is valid (normal number) */ FVECT p; /* vertex position */ FVECT n; /* average normal */ RREAL uv[2]; /* (u,v) position */ @@ -308,19 +308,25 @@ putobjrow( /* output vertex row to .OBJ */ int n ) { + static FVECT prevNorm; + for ( ; n-- >= 0; rp++) { if (!rp->valid) continue; fputs("v ", stdout); pvect(rp->p); - if (smooth && !ZEROVECT(rp->n)) { + rp->valid = ++nverts; + printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); + if (!smooth || ZEROVECT(rp->n)) + rp->nvalid = 0; + else if (VABSEQ(rp->n, prevNorm)) + rp->nvalid = nnorms; + else { printf("\tvn %.9g %.9g %.9g\n", rp->n[0], rp->n[1], rp->n[2]); rp->nvalid = ++nnorms; - } else - rp->nvalid = 0; - printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); - rp->valid = ++nverts; + VCOPY(prevNorm, rp->n); + } } }