Larry Ramey (ramey++at++ccpo.odu.edu)
Tue, 30 Mar 1999 12:08:24 -0500
If anyone has a solution please CC me as well as the list, as I get
info-performer in digest mode, and would like to resolve this today if
possible.
I have looked everywhere for a solution, /usr/share/Performer,
info-performer archive, even the modestly named www.dorbie.com <g>. I am
not adverse to being sent code to read and puzzle this out on my own,
what I wouldn't do for a good performer book.
On to the problem:
Given a GeoSet of the general shape:
1g 2g
-----------
| |
| |
| |
-----------
3g 4g
I want to map a texture onto it.
1t 2t
_______
| |
| |
| |
-------
3t 4t
Obviously the texture is a different size than the GeoSet. The simple
solution is to distort the texture such that 1g lines up with 1t and 2g
lines up with 2t, ect,ect. This will cause the texture to stretch or
compress. This is very easy to do in OpenGL (in fact I have done this in
the OpenGL version of our code) But how do I make Performer do this?
Performer want to repeat or clip the texture as needed, yielding an
undistorted texture, but one that doesn't fit the Geode.
Here is the relevant code:
void sgManager::textureNode(char* name,char* filename,int nodeNumber){
// -1 means texture this node, 0 means texture 0th child
// 1 means texture 1st child,2 means texture 2nd child ect
//This is a hack because ->find() doesn't work on pfNode unless it
inherits from pfGroup.
// So I cheated and textured something I "knew" was a Geode. Will have
to fix later.
pfNode* thisNode = scene->find(name,pfGeode::getClassType());
if(thisNode==NULL){
cout<<" Node named "<<name<<" not found. sgManager::textureNode\n";
return;
}
pfTexture* texture = new pfTexture;
pfTexEnv* tev = new pfTexEnv;
if (texture == NULL || tev == NULL){
pfDelete(texture);
pfDelete(tev);
cout<<"Out of performer memory in sgManager::textureNode\n";
return;
}
if(!texture->loadFile(filename)){
cout<<"File load failed, "<<filename<<" in sgManager::textureNode\n";
pfDelete(texture);
return;
}
pfGeode* textureNode=NULL;
if (nodeNumber == -1) textureNode = (pfGeode*)thisNode;
else {
pfGroup* thisGroup = (pfGroup*) thisNode;
textureNode = (pfGeode*) thisGroup->getChild(nodeNumber);
}
if(!textureNode){
cout<<"Can't find Child # "<<nodeNumber<<" of Node "<<name<<"\n";
pfDelete(texture);
return;
}
tev->setMode(PFTE_DECAL);
pfEnable(PFEN_TEXGEN);
pfGeoSet* gSet=NULL;
// C5D makes an assumtion here that we should texture the first GeoSet.
// This may need to change later. LER
gSet=textureNode->getGSet(0);
pfGeoState* gState=NULL;
gState = gSet->getGState();
if (!gState) gState = new pfGeoState;
gState->setAttr(PFSTATE_TEXTURE,texture);
gState->setMode(PFSTATE_ENTEXTURE,PF_ON);
gState->setAttr(PFSTATE_TEXENV, tev);
pfTexGen* texGen = new pfTexGen;
gState->setMode(PFSTATE_ENTEXGEN,PF_ON);
gState->setAttr(PFSTATE_TEXGEN,texGen);
texGen->setMode(PF_S, PFTG_OBJECT_LINEAR);
texGen->setMode(PF_T, PFTG_OBJECT_LINEAR);
texGen->setMode(PF_R, PFTG_OFF);
texGen->setMode(PF_Q, PFTG_OFF);
gSet->setGState(gState);
}
---------------------------------------------------------------
Larry E. Ramey ramey++at++ccpo.odu.edu
757-683-6276(office) 757-683-5335 (CAVE)
"Count the heads man." - Zaphod Bebblebrox
"Won't weigh you down, with good intentions" -Sarah McLachlan
This archive was generated by hypermail 2.0b2 on Tue Mar 30 1999 - 09:04:34 PST