Scott McMillan (scott++at++ht.com)
Tue, 30 Sep 1997 17:22:19 -0400 (EDT)
The root of the scene graph that is create by loadfile is returned. Under is
a collection of different types of nodes. You must traverse this graph to
find the nodes (pfGeode, pfGeoSets, pf*) that you are looking for. You kinda
have to know what types of nodes are connected to what other types of nodes.
For instance only pfGeoSets can be connected to pfGeodes, pfGeoStates are
"connected to" pfGeoSets as well as pfScenes, etc, etc, etc....
Here is some simple graph traversal code that you can modify to find the node
types you are looking for. This does an recursive/exhaustive search of the
sub graph rooted by node looking for pfGeodes (note that a pfGroup is a base
class name for many different types of nodes that can contain multiple
children). Once it finds a pfGeode, it gets a handle to all of the
associated pfGeoSets (this is where the coordinates are stored). With the
pfGeoSet pointer, it gets the pfGeoState, and then the pfTexture, and then I
can go to work on what I want to do. You do not need the code from
pfGeoState on, but I hope you find this instructive.
void upgradeTextures(pfNode *node, const int internal_format)
{
if (node->isOfType(pfGroup::getClassType()))
{
// you could do additional queries here to find out what type of
// pfGroup this node actually is.
for (int i=0; i<((pfGroup *) node)->getNumChildren(); i++)
{
upgradeTextures(((pfGroup *) node)->getChild(i), internal_format);
}
}
else if (node->isOfType(pfGeode::getClassType()))
{
pfGeode *gnode = (pfGeode *)node;
for (int i=0; i<gnode->getNumGSets(); i++)
{
pfGeoSet *gset = gnode->getGSet(i);
if (gset)
{
pfGeoState* gstate = gset->getGState();
if (gstate)
{
pfTexture *tex =
(pfTexture *) gstate->getAttr(PFSTATE_TEXTURE);
// do stuff to the pfTexture
if (tex)
{
int old_format = tex->getFormat(PFTEX_INTERNAL_FORMAT);
tex->setFormat(PFTEX_INTERNAL_FORMAT, internal_format);
int new_format = tex->getFormat(PFTEX_INTERNAL_FORMAT);
cerr << "Upgrading texture (addr: " << hex << tex << "): "
<< old_format << "->" << internal_format
<< " got " << new_format << dec << endl;
if (new_format != internal_format)
{
cerr << "Warning: texture upgrade to "
<< internal_format << "failed: got " << new_format
<< "(address: " << hex << tex << ")" << endl;
}
}
}
}
}
}
}
--
Scott McMillan | HT Medical, Inc. | Disclaimers
scott++at++ht.com | http://www.ht.com | available
Ph: 301-984-3706 | 6001 Montrose Rd., #902 | upon re-
Fax: 301-984-2104 | Rockville, MD 20852 | quest.
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
Submissions: info-performer++at++sgi.com
Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:56:01 PDT