I have some trouble using a MultipassMaterial together with ClipPlaneChunks. I tried it with OpenSG 1.8. I am not sure if I understood right how to use the MultipassMaterial. The code is at the end of this mail.
So what I want to do is (as an example) cut a quarter out of a torus. As I can describe only convex regions with cutting planes I tried to do it by using a SimpleMaterial with an attached ClipPlaneChunk that cuts away half of the torus in the first Pass in MultiPassMaterial. Then in the second Pass I use another Material that cuts away the half of the torus already rendered and half of the remaining half (und so should render a quarter torus).
Using the two materials I created for the two passes as standalone result in the rendering I expected and show either half of the torus or a quarter of the torus. However, attaching both materials to a MultiPassMaterial seems to ignore the second Pass (and draws only half of the torus). If I exchange the order in the MultiPassMaterial it draws the other half .... ?????
Is the way I have choosen right and feasible? Does somebody have an idea?
Kind regards,
Bjoern
The code (in addition I attached the .cpp file):
------------------------------------------------------------------------------------------
NodePtr torusNode = makeTorus(.5, 2, 16, 16);
GeometryPtr torusGeo = GeometryPtr::dcast(torusNode->getCore());
//Renders the "right" side part of the torusSimpleMaterialPtr pass1 = SimpleMaterial::create();
ClipPlaneChunkPtr xClip = ClipPlaneChunk::create();
beginEditCP(xClip);{
xClip->setEquation(Vec4f(1,0,0,0));
xClip->setEnable(
true);xClip->setBeacon(torusNode);
};endEditCP(xClip);
beginEditCP(pass1);{
pass1->setDiffuse(Color3f(1.0, 1.0, 1.0));
pass1->setAmbient(Color3f(0.1, 0.1, 0.1));
pass1->addChunk(xClip);
};endEditCP(pass1);
//Renders the "upper left" quarter of the torusSimpleMaterialPtr pass2 = SimpleMaterial::create();
ClipPlaneChunkPtr xInvClip = ClipPlaneChunk::create();
beginEditCP(xInvClip);{
xInvClip->setEquation(Vec4f(-1,0,0,0));
xInvClip->setEnable(
true);xInvClip->setBeacon(torusNode);
};endEditCP(xInvClip);
ClipPlaneChunkPtr yClip = ClipPlaneChunk::create();
beginEditCP(yClip);{
yClip->setEquation(Vec4f(0,1,0,0));
yClip->setEnable(
true);yClip->setBeacon(torusNode);
};endEditCP(yClip);
beginEditCP(pass2);{
pass2->setDiffuse(Color3f(1.0, 1.0, 1.0));
pass2->setAmbient(Color3f(0.1, 0.1, 0.1));
pass2->addChunk(xInvClip);
pass2->addChunk(yClip);
};endEditCP(pass2);
//this works: (renders the "right" half of the torus // //beginEditCP(torusGeo);{ // torusGeo->setMaterial(pass1); //};endEditCP(torusGeo); //this works: (renders the "upper left" quarter of the torus // //beginEditCP(torusGeo);{ // torusGeo->setMaterial(pass2); //};endEditCP(torusGeo); //this failsMultiPassMaterialPtr mPassMat = MultiPassMaterial::create();
beginEditCP(mPassMat);{
mPassMat->addMaterial(pass1);
mPassMat->addMaterial(pass2);
};endEditCP(mPassMat);
beginEditCP(torusGeo);{
torusGeo->setMaterial(mPassMat);
};endEditCP(torusGeo);
-------------------------------------------------------------------------
Dr. Bjoern Zehner
UFZ Centre for Environmental Research Leipzig-Halle
Permoserstrasse 15
04318 Leipzig
Germany
http://www.ufz.de/index.php?en=5673
Tel: ++49 (341) 235 3979
Fax: ++49 (341) 235 3939
// Headers #include <OpenSG/OSGGLUT.h> #include <OpenSG/OSGConfig.h> #include <OpenSG/OSGSimpleGeometry.h> #include <OpenSG/OSGGLUTWindow.h> #include <OpenSG/OSGSimpleSceneManager.h> #include <OpenSG/OSGAction.h> #include <OpenSG/OSGTime.h> #include <OpenSG/OSGGeometry.h>
#include <OpenSG/OSGChunkMaterial.h>
#include <OpenSG/OSGClipPlaneChunk.h>
#include <OpenSG/OSGGroup.h>
#include <OpenSG/OSGMaterialGroup.h>
#include <OpenSG/OSGMultiPassMaterial.h>
// Activate the OpenSG namespace
OSG_USING_NAMESPACE
// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;
// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );
// helper class to find a named node
// names are handled as simple attachments, get the header for that
#include <OpenSG/OSGSimpleAttachments.h>
NodePtr root;
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
GroupPtr group;
root = makeCoredNode<Group>(&group);
NodePtr torusNode = makeTorus(.5, 2, 16, 16);
GeometryPtr torusGeo = GeometryPtr::dcast(torusNode->getCore());
//Renders the "right" side part of the torus
SimpleMaterialPtr pass1 = SimpleMaterial::create();
ClipPlaneChunkPtr xClip = ClipPlaneChunk::create();
beginEditCP(xClip);{
xClip->setEquation(Vec4f(1,0,0,0));
xClip->setEnable(true);
xClip->setBeacon(torusNode);
};endEditCP(xClip);
beginEditCP(pass1);{
pass1->setDiffuse(Color3f(1.0, 1.0, 1.0));
pass1->setAmbient(Color3f(0.1, 0.1, 0.1));
pass1->addChunk(xClip);
};endEditCP(pass1);
//Renders the "upper left" quarter of the torus
SimpleMaterialPtr pass2 = SimpleMaterial::create();
ClipPlaneChunkPtr xInvClip = ClipPlaneChunk::create();
beginEditCP(xInvClip);{
xInvClip->setEquation(Vec4f(-1,0,0,0));
xInvClip->setEnable(true);
xInvClip->setBeacon(torusNode);
};endEditCP(xInvClip);
ClipPlaneChunkPtr yClip = ClipPlaneChunk::create();
beginEditCP(yClip);{
yClip->setEquation(Vec4f(0,1,0,0));
yClip->setEnable(true);
yClip->setBeacon(torusNode);
};endEditCP(yClip);
beginEditCP(pass2);{
pass2->setDiffuse(Color3f(1.0, 1.0, 1.0));
pass2->setAmbient(Color3f(0.1, 0.1, 0.1));
pass2->addChunk(xInvClip);
pass2->addChunk(yClip);
};endEditCP(pass2);
//this works: (renders the "right" half of the torus
//
//beginEditCP(torusGeo);{
// torusGeo->setMaterial(pass1);
//};endEditCP(torusGeo);
//this works: (renders the "upper left" quarter of the torus
//
//beginEditCP(torusGeo);{
// torusGeo->setMaterial(pass2);
//};endEditCP(torusGeo);
//this fails
MultiPassMaterialPtr mPassMat = MultiPassMaterial::create();
beginEditCP(mPassMat);{
mPassMat->addMaterial(pass1);
mPassMat->addMaterial(pass2);
};endEditCP(mPassMat);
beginEditCP(torusGeo);{
torusGeo->setMaterial(mPassMat);
};endEditCP(torusGeo);
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (torusNode);
// show the whole scene
mgr->showAll();
// GLUT main loop
glutMainLoop();
return 0;
}
//
// GLUT callback functions
//
// redraw the window
void display(void)
{
mgr->idle();
mgr->redraw();
}
void update(void)
{
glutPostRedisplay();
}
// react to size changes
void reshape(int w, int h)
{
mgr->resize(w, h);
glutPostRedisplay();
}
// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
if (state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
glutPostRedisplay();
}
// react to mouse motions with pressed buttons
void motion(int x, int y)
{
mgr->mouseMove(x, y);
glutPostRedisplay();
}
// react to keys
void keyboard(unsigned char k, int , int )
{
switch(k)
{
case 27:
{
OSG::osgExit();
exit(0);
}
break;
case 'f':
{
mgr->setNavigationMode(Navigator::FLY);
}
break;
case 't':
{
mgr->setNavigationMode(Navigator::TRACKBALL);
}
break;
}
}
// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(update);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
return winid;
}
------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________ Opensg-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensg-users
