Angus Henderson (angus++at++death.reading.sgi.com)
Mon, 11 Mar 1996 09:12:22 +0000
ANGus
#include <Performer/pf.h>
#include <Performer/prmath.h>
#include "pfutil.h"
#include "pfflt.h"
#include "pfsgi.h"
#include "generic.h"
#include "perfly.h"
#include "gui.h"
#include "keybd.h"
static long getNumVerts(pfGeoSet *);
static void getVerts(pfGeode*, short, short);
void
makeVertList(pfNode *node, short q, short copy)
{
long type, i, j;
type = pfGetType(node);
if(type == PFTYPE_GEODE)
{
getVerts((pfGeode*)node, q, copy);
}
else if(type & PFCLASS_GROUP)
{
long nc;
/*
* Recurse on children. Act on return value.
*/
for(i = 0; i < (nc = pfGetNumChildren(node)); i++)
{
pfNode *child = pfGetChild(node, i);
makeVertList(child, q, copy);
}
}
}
static void
getVerts(pfGeode * geode, short q, short copy)
{
long i, j, ng;
pfGeoSet *gset;
long nverts;
void *coords;
ushort *indices;
ng = pfGetNumGSets( geode);
printf("found a geode with %d gsets\n",ng);
if(ng > 0)
{
for(i = 0; i < ng; i++)
{
gset = pfGetGSet( geode, i);
nverts = getNumVerts(gset);
pfGetGSetAttrLists( gset, PFGS_COORD3, &coords, &indices);
if(indices)
printf("- INDEXED\n");
else
printf("- NON-INDEXED\n");
if(sharkAnimation[q][copy].vertList == NULL)
{
sharkAnimation[q][copy].vertList = (float**)pfMalloc(
nverts * sizeof( float* ) ,pfGetSharedArena() );
sharkAnimation[q][copy].numVerts = 0;
}
else
sharkAnimation[q][copy].vertList = (float**)pfRealloc(
(void*)sharkAnimation[q][copy].vertList, (nverts +
sharkAnimation[q][copy].numVerts) * sizeof(float*));
for(j = 0; j < nverts; j++)
{
*(sharkAnimation[q][copy].vertList +
sharkAnimation[q][copy].numVerts + j) = (float*)coords + j*3;
}
sharkAnimation[q][copy].numVerts += nverts;
printf("Verts in this GSet: %d Total vertices: %d\n", nverts,
sharkAnimation[q][copy].numVerts);
}
}
}
long
getNumVerts(pfGeoSet *gset)
{
long i, nprims, nverts;
long *lengths;
long sumLengths = 0;
nprims = pfGetGSetNumPrims( gset );
lengths = pfGetGSetPrimLengths( gset );
if(lengths)
{
for(i = 0; i<nprims; i++)
{
sumLengths += *(lengths + i);
}
}
switch (pfGetGSetPrimType( gset ) )
{
case PFGS_POINTS:
printf("PFGS_POINTS");
nverts = nprims;
break;
case PFGS_LINES:
printf("PFGS_LINES");
nverts = nprims * 2;
break;
case PFGS_LINESTRIPS:
printf("PFGS_LINESTRIPS");
nverts = sumLengths;
break;
case PFGS_FLAT_LINESTRIPS:
printf("PFGS_FLAT_LINESTRIPS");
nverts = sumLengths;
break;
case PFGS_TRIS:
printf("PFGS_TRIS");
nverts = nprims * 3;
break;
case PFGS_QUADS:
printf("PFGS_QUADS");
nverts = nprims * 4;
break;
case PFGS_TRISTRIPS:
printf("PFGS_TRISTRIPS");
nverts = sumLengths;
break;
case PFGS_FLAT_TRISTRIPS:
printf("PFGS_FLAT_TRISTRIPS");
nverts = sumLengths;
break;
default:
printf("Primitive type Unknown: %d ", pfGetGSetPrimType( gset ));
nverts = 0;
}
return nverts;
}
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:32 PDT