Skip to content

Commit

Permalink
perf(gensurf): .OBJ output now re-uses identical subsequent normal IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Apr 1, 2021
1 parent 269550c commit 7d12369
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/gen/gensurf.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 7d12369

Please sign in to comment.