From: Larry E. Ramey (hydrax++at++mindspring.com)
Date: 11/16/2000 21:17:16
Hey all,
I have a stupid little program that is supposed to replace the Materials
in an invetor file with my material. (and save it as a pfb file) But it
fails a "pfDirtCheck".
I don't understand what this is, or why is fails said test.
Here is the code. (as you can see I ripped of fog.C)
Larry E. Ramey
VRCO Software Engineer (from home, hence the funny e-mail)
#include <stdlib.h>
#include <Performer/pf/pfChannel.h>
#include <Performer/pf/pfLightSource.h>
#include <Performer/pf/pfNode.h>
#include <Performer/pf/pfScene.h>
#include <Performer/pr/pfFog.h>
#include <Performer/pr/pfLinMath.h>
#include <Performer/pr/pfMaterial.h>
#include <Performer/pf/pfGeode.h>
#include <Performer/pr/pfGeoState.h>
#include <Performer/pf/pfGroup.h>
#include <fstream.h>
#include <string>
#include <Performer/pfdu.h>
using std::string;
static void OpenPipeWin (pfPipeWindow *pw);
static void DrawChannel (pfChannel *chan, void *data);
static void adjustMaterial(pfGroup*,pfMaterial*,pfMaterial*);
pfSphere *bsphere;
//
// Usage() -- print usage advice and exit. This
// procedure is executed in the application process.
//
static void
Usage (void)
{
pfNotify(PFNFY_FATAL, PFNFY_USAGE, "Usage: fog file.ext ...\n");
exit(1);
}
int
main (int argc, char *argv[])
{
float t = 0.0f;
if (argc < 2)
Usage();
// Initialize Performer
pfInit();
// Use default multiprocessing mode based on number of
// processors.
//
pfMultiprocess( PFMP_APPCULLDRAW );
bsphere = (pfSphere*) pfMalloc (sizeof(pfSphere),
pfGetSharedArena());
// Load all loader DSO's before pfConfig() forks
pfdInitConverter(argv[1]);
// Configure multiprocessing mode and start parallel
// processes.
//
pfConfig();
// Append standard data directories to PFPATH
pfFilePath(".:/usr/share/Performer/data");
// Read a single file, of any known type
pfNode *root = pfdLoadFile(argv[1]);
if (root == NULL)
{
pfExit();
exit(-1);
}
pfMaterial* frontMat;
pfMaterial* backMat;
// Attach loaded file to a new pfScene
pfScene *scene = new pfScene;
frontMat = (pfMaterial*)
pfMalloc(sizeof(pfMaterial),pfGetSharedArena());
backMat = (pfMaterial*)
pfMalloc(sizeof(pfMaterial),pfGetSharedArena());
assert(frontMat);
assert(backMat);
ifstream in("matProps.txt");
float buff[3];
in>>buff[0]>>buff[1]>>buff[2];
frontMat->setColor(PFMTL_AMBIENT,buff[0],buff[1],buff[2]);
in>>buff[0]>>buff[1]>>buff[2];
frontMat->setColor(PFMTL_DIFFUSE,buff[0],buff[1],buff[2]);
in>>buff[0]>>buff[1]>>buff[2];
frontMat->setColor(PFMTL_EMISSION,buff[0],buff[1],buff[2]);
in>>buff[0]>>buff[1]>>buff[2];
frontMat->setColor(PFMTL_SPECULAR,buff[0],buff[1],buff[2]);
in>>buff[0];
frontMat->setAlpha(buff[0]);
in>>buff[0];
frontMat->setShininess(buff[0]);
frontMat->setSide(PFMTL_FRONT);
string type;
in>>type;
if(type == "PFMTL_CMODE_AMBIENT_AND_DIFFUSE")
frontMat->setColorMode(PFMTL_FRONT,PFMTL_CMODE_AMBIENT_AND_DIFFUSE);
else if(type == "PFMTL_CMODE_AMBIENT")
frontMat->setColorMode(PFMTL_FRONT,PFMTL_CMODE_AMBIENT);
else if(type == "PFMTL_CMODE_DIFFUSE")
frontMat->setColorMode(PFMTL_FRONT,PFMTL_CMODE_DIFFUSE);
else if(type == "PFMTL_CMODE_EMISSION")
frontMat->setColorMode(PFMTL_FRONT,PFMTL_CMODE_EMISSION);
else if(type == "PFMTL_CMODE_SPECULAR")
frontMat->setColorMode(PFMTL_FRONT,PFMTL_CMODE_SPECULAR);
else if(type == "PFMTL_CMODE_OFF")
frontMat->setColorMode(PFMTL_FRONT,PFMTL_CMODE_OFF);
in>>buff[0]>>buff[1]>>buff[2];
backMat->setColor(PFMTL_AMBIENT,buff[0],buff[1],buff[2]);
in>>buff[0]>>buff[1]>>buff[2];
backMat->setColor(PFMTL_DIFFUSE,buff[0],buff[1],buff[2]);
in>>buff[0]>>buff[1]>>buff[2];
backMat->setColor(PFMTL_EMISSION,buff[0],buff[1],buff[2]);
in>>buff[0]>>buff[1]>>buff[2];
backMat->setColor(PFMTL_SPECULAR,buff[0],buff[1],buff[2]);
in>>buff[0];
backMat->setAlpha(buff[0]);
in>>buff[0];
backMat->setShininess(buff[0]);
backMat->setSide(PFMTL_BACK);
/* in>>type;
if(type == "PFMTL_CMODE_AMBIENT_AND_DIFFUSE")
backMat->setColorMode(PFMTL_BACK,PFMTL_CMODE_AMBIENT_AND_DIFFUSE);
else if(type == "PFMTL_CMODE_AMBIENT")
backMat->setColorMode(PFMTL_BACK,PFMTL_CMODE_AMBIENT);
else if(type == "PFMTL_CMODE_DIFFUSE")
backMat->setColorMode(PFMTL_BACK,PFMTL_CMODE_DIFFUSE);
else if(type == "PFMTL_CMODE_EMISSION")
backMat->setColorMode(PFMTL_BACK,PFMTL_CMODE_EMISSION);
else if(type == "PFMTL_CMODE_SPECULAR")
backMat->setColorMode(PFMTL_BACK,PFMTL_CMODE_SPECULAR);
else if(type == "PFMTL_CMODE_OFF")
backMat->setColorMode(PFMTL_BACK,PFMTL_CMODE_OFF);
*/
assert(in.good());
//if(t>10.0 && once){
if(root->isOfType(pfGroup::getClassType()))
adjustMaterial((pfGroup*)root,frontMat,backMat);
// once=false;
//}
scene->addChild((pfGroup*)root);
// determine extent of scene's geometry
scene->getBound(bsphere);
// Create a pfLightSource and attach it to scene
scene->addChild(new pfLightSource);
// Configure and open GL window
pfPipe *p = pfGetPipe(0);
pfPipeWindow *pw = new pfPipeWindow(p);
pw->setName(argv[0]);
pw->setOriginSize(0,0,500,500);
pw->setConfigFunc(OpenPipeWin);
pw->config();
// Create and configure a pfChannel.
pfChannel *chan = new pfChannel(p);
chan->setScene(scene);
chan->setNearFar(1.0f, 10.0f * bsphere->radius);
chan->setFOV(45.0f, 0.0f);
chan->setTravFunc(PFTRAV_DRAW,DrawChannel);
bool once=true;
// Simulate for twenty seconds.
while (t < 20.0f)
{
float s, c;
pfCoord view;
// Go to sleep until next frame time.
pfSync();
// Compute new view position.
t = pfGetTime();
pfSinCos(45.0f*t, &s, &c);
view.hpr.set(45.0f*t, -10.0f, 0);
view.xyz.set(2.0f * bsphere->radius * s,
-2.0f * bsphere->radius *c,
0.5f * bsphere->radius);
chan->setView(view.xyz, view.hpr);
// Initiate cull/draw for this frame.
pfFrame();
}
// Terminate parallel processes and exit.
pfExit();
return 0;
}
//
// OpenPipeWin() -- create a GL window: set up the
// window system, IRIS GL, and IRIS Performer. This
// procedure is executed in the draw process (when
// there is a separate draw process).
//
static void
OpenPipeWin (pfPipeWindow *pw)
{
// Open graphics window.
pw->open();
}
// Draw process callback
static void DrawChannel (pfChannel *chan, void *)
{
chan->clear();
pfDraw();
}
static void adjustMaterial(pfGroup* grp,pfMaterial* f,pfMaterial* b)
{
for(int j =0; j<grp->getNumChildren();++j){
pfNode* cur = grp->getChild(j);
if (cur->isOfType(pfGeode::getClassType())){
pfGeode* geode = (pfGeode*) cur;
for(int i=0;i<geode->getNumGSets();++i){
pfGeoSet* gSet = geode->getGSet(i);
pfGeoState* gState = gSet->getGState();
if(!gState) gState = (pfGeoState*) pfMalloc(sizeof(
pfGeoState),pfGetSharedArena());
gState->setAttr(PFSTATE_FRONTMTL,f);
gState->setAttr(PFSTATE_BACKMTL,b);
}
}
else if( cur->isOfType(pfGroup::getClassType()))
adjustMaterial((pfGroup*)grp->getChild(j),f,b);
}
}
This archive was generated by hypermail 2b29 : Thu Nov 16 2000 - 21:18:49 PST