1 #include <bias_config.h>
2 #include <Gui/biasgl.h>
4 #include "SceneOpenSceneGraph.hh"
5 #include <GLviewer/OpenSceneGraphHelper.hh>
7 #include <GLviewer/GLProjectionParametersInterface.hh>
8 #include <Base/Common/FileHandling.hh>
9 #include <Base/Debug/Debug.hh>
10 #include <osg/CameraNode>
12 #include <osg/Geometry>
13 #include <osg/BlendEquation>
14 #include <osg/CullFace>
15 #include <osg/FrontFace>
16 #include <osg/LightSource>
18 #include <osg/Stencil>
19 #include <osg/MatrixTransform>
20 #include <osg/BlendFunc>
21 #include <osgShadow/ShadowedScene>
22 #include <osgShadow/ShadowMap>
23 #include <osg/Version>
29 #include <osg/AlphaFunc>
31 #include <osg/Geometry>
34 #include <osg/ClipNode>
35 #include <osg/AnimationPath>
36 #include <osgDB/ReadFile>
37 #include <osgDB/WriteFile>
38 #include <osgUtil/Optimizer>
39 #include <osgViewer/Viewer>
42 #include <osgParticle/Particle>
43 #include <osgParticle/ParticleSystem>
44 #include <osgParticle/ParticleSystemUpdater>
45 #include <osgParticle/ModularEmitter>
46 #include <osgParticle/MultiSegmentPlacer>
47 #include <osgParticle/ModularProgram>
48 #include <osgParticle/AccelOperator>
49 #include <osgParticle/FluidFrictionOperator>
52 #include <osgFX/Registry>
53 #include <osgFX/Effect>
54 #include <osgFX/BumpMapping>
56 #include <GLviewer/Scenes/NodeInfoOpenSGVisitor.hh>
57 #include <osgDB/WriteFile>
74 SceneOpenSceneGraph(
bool redirect) :
SceneBase(), timer_(), startTick_()
95 clearMask_ =GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT;
116 BIASERR(
"Init on SceneOpenSceneGraph should only be called "
124 osg::setNotifyLevel(osg::ALWAYS);
142 sceneView_->getCamera()->setClearColor(osg::Vec4(255.0f, 255.0f, 255.0f, 1.0f));
144 sceneView_->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
145 sceneView_->setLightingMode(osg::View::HEADLIGHT);
151 light_->setAmbient( osg::Vec4( .3f, .3f, .3f, 1.0f ));
153 light_->setDiffuse( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ));
154 light_->setSpecular( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ));
161 rootTree_ ->setName(SOSG_ROOT_NODE_NAME);
166 osg::StateSet* state =
rootTree_->getOrCreateStateSet();
167 state->setMode(GL_LIGHTING, osg::StateAttribute::ON);
168 state->setMode(GL_LIGHT0, osg::StateAttribute::ON);
170 state->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
188 lightSource->setReferenceFrame(osg::LightSource::ABSOLUTE_RF);
189 lightSource->setLight(
light_.get());
190 lightSource->setName(SOSG_LIGHT_SOURCE_NAME);
201 osg::ShapeDrawable *lightRepresentation =
new osg::ShapeDrawable(
202 new osg::Sphere(
osg::Vec3(0., 0., 0.), 20.0));
203 lightRepresentation->setColor(osg::Vec4(1., 1., 0., 1.));
221 class disableZwriteNodeVisitor :
public osg::NodeVisitor
226 disableZwriteNodeVisitor()
227 : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
230 virtual void apply(osg::Geode &node)
232 unsigned num_drawables = node.getNumDrawables();
233 for (
unsigned int i=0; i<num_drawables; i++)
235 osg::Drawable* dr = node.getDrawable(i);
238 osg::StateSet* sts = dr->getStateSet();
241 if(sts->getMode(GL_BLEND)==osg::StateAttribute::ON)
243 osg::Depth* pDepth =
new osg::Depth();
244 pDepth->setWriteMask(
false);
245 sts->setAttributeAndModes(pDepth, osg::StateAttribute::OVERRIDE |
246 osg::StateAttribute::ON);
247 sts->setMode(GL_CULL_FACE, osg::StateAttribute::ON |
248 osg::StateAttribute::OVERRIDE );
249 osg::CullFace *cullFace =
new osg::CullFace(osg::CullFace::BACK);
250 sts->setAttribute(cullFace);
251 osg::BlendFunc* pBlendFunc =
new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,
252 osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
253 sts->setAttributeAndModes(pBlendFunc, osg::StateAttribute::OVERRIDE |
254 osg::StateAttribute::ON);
255 sts->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
261 virtual void apply(osg::ClearNode &node)
264 node.setClearMask(0);
273 disableZwriteNodeVisitor vis;
302 if ((node->getName()).empty()) {
303 sw->setName(SOSG_SWITCH_PREFIX+(
string)
"Whatever");
305 sw->setName(SOSG_SWITCH_PREFIX+node->getName());
308 sw->addChild(node.get());
312 sw->setAllChildrenOn();
314 osg::StateSet *stateset = (node.get())->getOrCreateStateSet();
315 stateset->setRenderBinDetails( 10,
"RenderBin");
332 string path, base, suffix;
336 char currentdir[255];
338 _getcwd(currentdir,255);
339 int res = _chdir(path.c_str());
340 if (res<0)
return -1;
342 node = osgDB::readNodeFile((base+suffix).c_str());
344 node = osgDB::readNodeFile(fileName.c_str());
354 BIASWARN(
"Could not read 3d-model-file "<<fileName<<endl);
358 string name = ((node->getName()).empty()) ? (base) : (node->getName());
362 sw->setName(SOSG_SWITCH_PREFIX+name);
367 std::transform(suffix.begin(), suffix.end(), suffix.begin(), (int
368 (*)(int)) std::tolower);
369 BCDOUT(D_SCENEOSG_MatrixTransform,
"suffix: "<<suffix<< endl);
370 if (suffix ==
".wrl"){
371 BCDOUT(D_SCENEOSG_MatrixTransform,
"found wrl file\n");
374 osg::MatrixTransform *mt =
375 dynamic_cast<osg::MatrixTransform *
> (node.get());
376 if (mt && mt->getNumChildren() == 1){
377 osg::Node *child = mt->getChild(0);
378 BCDOUT(D_SCENEOSG_MatrixTransform,
"dropping matrix transform node\n");
398 if(!dynamic_cast<osg::MatrixTransform *>(node.get())){
399 osg::MatrixTransform *mt =
new osg::MatrixTransform();
400 mt->addChild(node.get());
404 sw->addChild(node.get());
407 osg::StateSet *stateset = (node.get())->getOrCreateStateSet();
408 stateset->setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON );
409 stateset->setRenderBinDetails( 10,
"RenderBin");
430 node->accept(finder);
431 if (finder.
_am.valid()) {
434 osgAnimation::AnimationList animlst = finder.
_am->getAnimationList();
436 std::cout <<
"Animation Duration: " << animation->getDuration() <<
", Starttime: " << animation->getStartTime() << std::endl;
440 animation->setPlaymode(osgAnimation::Animation::ONCE);
442 animation->setPlayMode(osgAnimation::Animation::ONCE);
446 std::cout <<
"found animation" << std::endl;
450 sw->setAllChildrenOn();
467 const double& width_mm,
470 if ( !imageNode.valid() )
return -1;
474 mt->addChild(imageNode);
478 if (fileName.empty()) {
479 sw->setName(SOSG_SWITCH_PREFIX+(
string)
"Image");
480 mt->setName((
string)
"Image");
501 oss << setprecision(7) << width_mm ;
505 sw->setAllChildrenOn();
507 osg::StateSet *stateset = (mt.get())->getOrCreateStateSet();
508 stateset->setRenderBinDetails( 10,
"RenderBin");
512 imageNode = sw.get();
539 osg::Node::ParentList parlist = Node->getParents();
540 osg::Node* actnode = Node;
541 if (parlist.size() != 0)
543 osg::Group* pargoup = parlist[0];
547 parlist = actnode->getParents();BIASASSERT(parlist.size()!=0);
548 pargoup = parlist[0];
563 childNode->accept(erasevisitor);
565 if (!
rootTree_->removeChild(childNode.get())){
566 BIASERR(
"not a valid child node "<<childNode.get());
579 osg::Node *myNode = node;
581 string path, base, suffix;
584 std::transform(suffix.begin(), suffix.end(), suffix.begin(), (int
585 (*)(int)) std::tolower);
586 BCDOUT(D_SCENEOSG_MatrixTransform,
"saving suffix: "<<suffix<< endl);
588 if (suffix ==
".wrl")
590 BCDOUT(D_SCENEOSG_MatrixTransform,
"found wrl file, adding matrix "
591 <<
"transform for compensation\n");
594 mt =
new osg::MatrixTransform(
osg::Matrix(1, 0, 0, 0, 0, 0, 1, 0, 0, -1,
597 mt->setName(node->getName());
601 osgDB::writeNodeFile(*myNode, fileName);
674 childNode->accept(erasevisitor);
678 BIASERR(
"not a valid child node "<<childNode);
687 std::map<osg::Node*, NodeInfo>::iterator it;
690 osg::Node* node = (*it).first;
693 BIASWARN(
"Null pointer in nodeinfo list");
699 (*it).second.Name = node->getName();
700 node->setName((*it).second.Id);
712 string ivename = dir + base +
".ive";
715 if (!osgDB::writeNodeFile(*
rootTree_, ivename))
722 osg::Node* node = (*it).first;
725 BIASWARN(
"Null pointer in nodeinfo list");
728 node->setName((*it).second.Name);
744 string modelfilename = dir + base +
".ive";
746 tempNode = osgDB::readNodeFile(modelfilename);
750 tempGroup = tempNode->asGroup();
753 BIASWARN(
"not a valid scene tree file");
759 string xmlpath = dir + base +
".xml";
760 if (tempMap.
XMLRead(xmlpath) != 0)
762 BIASWARN(xmlpath<<
" not found");
771 tempGroup->accept(namerestorevisitor);
794 light_->setAmbient( osg::Vec4( .0f, .0f, .0f, .0f ));
795 light_->setDiffuse( osg::Vec4( .0f, .0f, .0f, .0f ));
796 light_->setSpecular( osg::Vec4( .0f, .0f, .0f, .0f ));
799 light_->setAmbient( osg::Vec4( .3f, .3f, .3f, 1.0f ));
801 light_->setDiffuse( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ));
802 light_->setSpecular( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ));
807 m.makeTranslate(
osg::Vec3(posPointLight[0], posPointLight[1],
832 osg::Timer_t t1 = osg::Timer::instance()->tick();
833 double time = osg::Timer::instance()->delta_s(
startTick_, t1);
846 class transparentColourValueVisitor :
public osg::ValueVisitor
849 transparentColourValueVisitor() :
850 osg::ValueVisitor(), transparency_(0.5)
854 transparentColourValueVisitor(
const double transparency) :
855 osg::ValueVisitor(), transparency_(transparency)
862 v[3] = 1.0 - transparency_;
865 virtual void apply(osg::Vec4ub &v)
866 { v[3] = (
unsigned char)(255.0*(1.0-transparency_)); }
869 double transparency_;
872 class transparentColourArrayVisitor :
public osg::ArrayVisitor
875 transparentColourArrayVisitor() :
876 osg::ArrayVisitor(), transparency_(0.5)
880 transparentColourArrayVisitor(
const double transparency) :
881 osg::ArrayVisitor(), transparency_(transparency)
886 apply(osg::Vec4Array &va)
888 transparentColourValueVisitor tcvv(transparency_);
889 const unsigned num = va.getNumElements();
890 for (
unsigned i = 0; i < num; i++)
896 virtual void apply(osg::Vec4ubArray &va)
898 transparentColourValueVisitor tcvv(transparency_);
899 const unsigned num = va.getNumElements();
900 for (
unsigned i=0; i<num; i++){
906 double transparency_;
909 class makeTransparentNodeVisitor :
public osg::NodeVisitor
915 makeTransparentNodeVisitor() :
916 osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), transparency_(0.5)
923 makeTransparentNodeVisitor(
const double transparency) :
924 osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), transparency_(transparency)
926 BIASASSERT(transparency>=0.0 && transparency<=1.0);
930 apply(osg::Geode &node)
932 unsigned num_drawables = node.getNumDrawables();
933 for (
unsigned int i = 0; i < num_drawables; i++)
935 osg::Geometry *geom = node.getDrawable(i)->asGeometry();
939 osg::Array *col = geom->getColorArray();
943 transparentColourArrayVisitor tcav(transparency_);
955 apply(osg::ClearNode &node)
958 node.setClearMask(0);
963 setTransparency(
const double transparency)
965 BIASASSERT(transparency>=0.0 && transparency<=1.0);
966 transparency_ = transparency;
970 double transparency_;
977 BIASASSERT(transparency>=0.0 && transparency<=1.0);
979 osg::StateSet *stateset =
rootTree_->getOrCreateStateSet();
981 stateset->setMode(GL_BLEND, osg::StateAttribute::ON
982 | osg::StateAttribute::OVERRIDE);
984 osg::BlendEquation* blendEquation =
new osg::BlendEquation(
985 osg::BlendEquation::FUNC_ADD);
986 osg::BlendFunc* pBlendFunc =
new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,
987 osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
988 stateset->setAttributeAndModes(pBlendFunc, osg::StateAttribute::OVERRIDE |
989 osg::StateAttribute::ON);
991 stateset->setAttributeAndModes(blendEquation, osg::StateAttribute::OVERRIDE
992 | osg::StateAttribute::ON);
994 stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON
995 | osg::StateAttribute::OVERRIDE);
998 osg::CullFace *cullFace =
new osg::CullFace(osg::CullFace::BACK);
1001 stateset->setAttribute(cullFace);
1008 stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
1010 makeTransparentNodeVisitor tnv(transparency);
1021 BEXCEPTION(
"you can't animate automatically and set time manually");
1036 osg::Timer_t t1 = osg::Timer::instance()->tick();
1037 double time = osg::Timer::instance()->delta_s(
startTick_, t1);
1045 glPushAttrib( GL_VIEWPORT_BIT );
1046 glMatrixMode(GL_PROJECTION);
1048 glMatrixMode(GL_TEXTURE);
1050 glMatrixMode(GL_MODELVIEW);
1053 GLint viewParams[4];
1054 glGetIntegerv( GL_VIEWPORT, viewParams );
1055 sceneView_->getCamera()->setViewport(viewParams[0], viewParams[1],
1056 viewParams[2], viewParams[3]);
1059 osg::Matrixf osgMat;
1061 glGetFloatv( GL_PROJECTION_MATRIX, glMat );
1062 osgMat.set( glMat );
1063 sceneView_->getCamera()->setProjectionMatrix( osgMat );
1071 glGetFloatv( GL_MODELVIEW_MATRIX, glMat );
1079 osgMat.set( glMat );
1082 osg::Vec3d eye, center, up;
1083 float lookDistance=1.0;
1084 osgMat.getLookAt (eye, center, up, lookDistance);
1086 m.makeTranslate(eye);
1089 sceneView_->getCamera()->getViewMatrix().set( osgMat );
1091 GLbitfield mask =
sceneView_->getCamera()->getClearMask();
1102 glGetIntegerv(GL_DRAW_BUFFER,&drawenum);
1112 glMatrixMode(GL_MODELVIEW);
1114 glMatrixMode(GL_TEXTURE);
1116 glMatrixMode(GL_PROJECTION);
1126 const osg::BoundingSphere& bs =
rootTree_->getBound();
1129 (double) bs.center()[1], (double) bs.center()[2]);
1137 const osg::BoundingSphere& bs =
rootTree_->getBound();
1139 Vector3<double> center((
double) bs.center()[0], (double) bs.center()[1],
1140 (double) bs.center()[2]);
1142 double radius = (double) bs.radius();
1145 min = center - diag;
1146 max = center + diag;
1155 double depth = camera->
GetDepth(x, y);
1160 UnProjectToPoint(thepoint, depth);
1161 cout <<
"viewing ray intersects scene at " << intersection << endl;
1169 return (osg::dynamic_pointer_cast<osg::Node>(
rootTree_));
1190 const string vis = (visible)?(
"TRUE"):(
"FALSE");
1209 const string occ = (state)?(
"TRUE"):(
"FALSE");
1212 osg::StateSet *stateset = node->getOrCreateStateSet();
1213 BIASASSERT(stateset);
1214 osg::ColorMask *colmask =
new osg::ColorMask(!state, !state, !state, !state);
1215 stateset->setAttribute(colmask);
1216 osg::Stencil *stencil =
new osg::Stencil();
1220 stateset->setRenderBinDetails( 1,
"RenderBin");
1223 stencil->setFunction( osg::Stencil::GREATER, 1, ~(
unsigned int)0);
1227 stencil->setOperation(osg::Stencil::KEEP,osg::Stencil::KEEP,
1228 osg::Stencil::REPLACE);
1233 stateset->setRenderBinDetails( 10,
"RenderBin");
1236 stencil->setFunction( osg::Stencil::NOTEQUAL, 2, ~(
unsigned int)0);
1241 stencil->setOperation(osg::Stencil::KEEP,osg::Stencil::KEEP,
1242 osg::Stencil::ZERO);
1245 #if (OPENSCENEGRAPH_MAJOR_VERSION>=2) && (OPENSCENEGRAPH_MINOR_VERSION>=8)
1246 stateset->setNestRenderBins(
false);
1248 stateset->setAttributeAndModes(stencil);
1258 t = node->asTransform();
1261 osg::MatrixTransform * tm;
1262 tm = t->asMatrixTransform();
1270 BIASASSERT( (
NodeInfoMap_[node].IsEditable && (val==
"TRUE") ) ||
1272 return (val==
"TRUE");
1295 rootTree_ =
new osgShadow::ShadowedScene(st.get());
1296 rootTree_->setName(
"_sceneRootShadowed");
1298 for (
unsigned int n = 0; n < (temproot->getNumChildren()); n++)
1300 rootTree_->addChild(temproot->getChild(n));
1304 osg::dynamic_pointer_cast<osgShadow::ShadowedScene>(
rootTree_);
1305 dynamic_cast<osgShadow::ShadowMap*
> (shadowedScene->getShadowTechnique()) ->setLight(
1320 const string &mirrortexture,
bool cutUpperHalf)
1323 osg::Geometry* geom =
new osg::Geometry;
1325 osg::Vec3Array* coords =
new osg::Vec3Array(4);
1326 (*coords)[0].set(ll[0], ll[1], ll[2]);
1327 (*coords)[1].set(ul[0], ul[1], ul[2]);
1328 (*coords)[2].set(ur[0], ur[1], ur[2]);
1329 (*coords)[3].set(lr[0], lr[1], lr[2]);
1336 geom->setVertexArray(coords);
1338 osg::Vec3Array* norms =
new osg::Vec3Array(1);
1348 (*norms)[0].set(-center2[0], -center2[1], -center2[2]);
1349 geom->setNormalArray(norms);
1350 geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
1352 osg::Vec2Array* tcoords =
new osg::Vec2Array(4);
1357 (*tcoords)[0].set(0.0f, 1.0f);
1358 (*tcoords)[1].set(0.0f, 0.0f);
1359 (*tcoords)[2].set(1.0f, 0.0f);
1360 (*tcoords)[3].set(1.0f, 1.0f);
1361 geom->setTexCoordArray(0, tcoords);
1362 geom->setTexCoordArray(1, tcoords);
1364 osg::Vec4Array* colours =
new osg::Vec4Array(1);
1366 (*colours)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
1367 geom->setColorArray(colours);
1368 geom->setColorBinding(osg::Geometry::BIND_OVERALL);
1370 geom->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4));
1373 osg::Drawable* mirror = geom;
1375 osg::MatrixTransform* rootNode =
new osg::MatrixTransform;
1379 osg::ColorMask* rootColorMask =
new osg::ColorMask;
1380 rootColorMask->setMask(
true,
true,
true,
true);
1384 osg::Depth* rootDepth =
new osg::Depth;
1385 rootDepth->setFunction(osg::Depth::LESS);
1386 rootDepth->setRange(0.0, 1.0);
1388 osg::StateSet* rootStateSet =
new osg::StateSet();
1389 rootStateSet->setAttribute(rootColorMask);
1390 rootStateSet->setAttribute(rootDepth);
1392 rootNode->setStateSet(rootStateSet);
1399 osg::Stencil* stencil =
new osg::Stencil;
1400 stencil->setFunction(osg::Stencil::ALWAYS, 1, ~0u);
1401 stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
1402 osg::Stencil::REPLACE);
1405 osg::ColorMask* colorMask =
new osg::ColorMask;
1406 colorMask->setMask(
false,
false,
false,
false);
1408 osg::StateSet* statesetBin1 =
new osg::StateSet();
1409 statesetBin1->setRenderBinDetails(1,
"RenderBin");
1410 statesetBin1->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
1411 statesetBin1->setAttributeAndModes(stencil, osg::StateAttribute::ON);
1412 statesetBin1->setAttribute(colorMask);
1415 osg::Geode* geode =
new osg::Geode;
1416 geode->addDrawable(mirror);
1417 geode->setStateSet(statesetBin1);
1418 rootNode->addChild(geode);
1426 osg::Stencil* stencil =
new osg::Stencil;
1427 stencil->setFunction(osg::Stencil::ALWAYS, 0, ~0u);
1428 stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
1429 osg::Stencil::REPLACE);
1431 osg::StateSet* statesetBin2 =
new osg::StateSet();
1432 statesetBin2->setRenderBinDetails(2,
"RenderBin");
1433 statesetBin2->setAttributeAndModes(stencil, osg::StateAttribute::ON);
1435 osg::Group* groupBin2 =
new osg::Group();
1436 groupBin2->setStateSet(statesetBin2);
1437 groupBin2->addChild(model);
1441 rootNode->addChild(groupBin2);
1448 osg::Stencil* stencil =
new osg::Stencil;
1449 stencil->setFunction(osg::Stencil::EQUAL, 1, ~0u);
1450 stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
1451 osg::Stencil::KEEP);
1454 osg::ColorMask* colorMask =
new osg::ColorMask;
1455 colorMask->setMask(
false,
false,
false,
false);
1458 osg::Depth* depth =
new osg::Depth;
1459 depth->setFunction(osg::Depth::ALWAYS);
1460 depth->setRange(1.0, 1.0);
1462 osg::StateSet* statesetBin3 =
new osg::StateSet();
1463 statesetBin3->setRenderBinDetails(3,
"RenderBin");
1464 statesetBin3->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
1465 statesetBin3->setAttributeAndModes(stencil, osg::StateAttribute::ON);
1466 statesetBin3->setAttribute(colorMask);
1467 statesetBin3->setAttribute(depth);
1470 osg::Geode* geode =
new osg::Geode;
1471 geode->addDrawable(mirror);
1472 geode->setStateSet(statesetBin3);
1474 rootNode->addChild(geode);
1494 osg::ClipPlane* clipplane =
new osg::ClipPlane;
1498 osg::Vec3 onormal(-normal[0], -normal[1], -normal[2]);
1501 osg::Plane theclipplane(onormal,
osg::Vec3(center[0], center[1],
1503 cout <<
"clipplane is " << theclipplane[0] <<
" " << theclipplane[1]
1504 <<
" " << theclipplane[2] <<
" " << theclipplane[3] <<
" " << endl;
1505 clipplane->setClipPlane(theclipplane);
1506 clipplane->setClipPlaneNum(0);
1508 osg::ClipNode* clipNode =
new osg::ClipNode;
1509 clipNode->addClipPlane(clipplane);
1511 osg::StateSet* dstate = clipNode->getOrCreateStateSet();
1512 dstate->setRenderBinDetails(4,
"RenderBin");
1513 dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE
1514 | osg::StateAttribute::OFF);
1516 osg::Stencil* stencil =
new osg::Stencil;
1517 stencil->setFunction(osg::Stencil::EQUAL, 1, ~0u);
1518 stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
1519 osg::Stencil::KEEP);
1520 dstate->setAttributeAndModes(stencil, osg::StateAttribute::ON);
1522 osg::MatrixTransform* reverseMatrix =
new osg::MatrixTransform;
1523 reverseMatrix->setStateSet(dstate);
1526 rot.makeRotate(
osg::Vec3(0, 0, 1), onormal);
1529 reverseMatrix->preMult(osg::Matrix::translate(-center[0], -center[1],
1530 -center[2]) * rott * osg::Matrix::scale(1.0f, 1.0f, -1.0f) * rot
1531 * osg::Matrix::translate(center[0], center[1], center[2]));
1533 reverseMatrix->addChild(model);
1534 clipNode->addChild(reverseMatrix);
1535 rootNode->addChild(clipNode);
1542 osg::Depth* depth =
new osg::Depth;
1543 depth->setFunction(osg::Depth::ALWAYS);
1545 osg::Stencil* stencil =
new osg::Stencil;
1546 stencil->setFunction(osg::Stencil::EQUAL, 1, ~0u);
1548 stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP,
1549 osg::Stencil::ZERO);
1552 osg::BlendFunc* trans =
new osg::BlendFunc;
1554 trans->setFunction(osg::BlendFunc::SRC_ALPHA,
1555 osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
1557 osg::AlphaFunc* alpha =
new osg::AlphaFunc;
1558 alpha->setFunction(osg::AlphaFunc::ALWAYS);
1560 osg::StateSet* statesetBin5 =
new osg::StateSet;
1562 statesetBin5->setMode(GL_CULL_FACE,osg::StateAttribute::OFF
1563 | osg::StateAttribute::PROTECTED);
1566 osg::Image* image = osgDB::readImageFile(mirrortexture.c_str());
1569 osg::Texture2D* texture =
new osg::Texture2D;
1570 texture->setImage(image);
1573 statesetBin5->setTextureAttributeAndModes(0, texture,
1574 osg::StateAttribute::ON | osg::StateAttribute::PROTECTED);
1578 BIASERR(
"could not load texture "<<mirrortexture);
1581 statesetBin5->setRenderBinDetails(5,
"RenderBin");
1582 statesetBin5->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
1583 statesetBin5->setAttributeAndModes(stencil, osg::StateAttribute::ON);
1584 statesetBin5->setAttributeAndModes(trans, osg::StateAttribute::ON);
1585 statesetBin5->setAttributeAndModes(alpha, osg::StateAttribute::ON);
1586 statesetBin5->setAttribute(depth);
1589 osg::Geode* geode =
new osg::Geode;
1590 geode->addDrawable(mirror);
1591 geode->setStateSet(statesetBin5);
1656 rootNode->addChild(geode);
1661 rootNode->setName(model->getName() +
"_mirrored");
1669 const string& mirrortexture,
bool cutUpperHalf)
1672 cout <<
"SceneOpenSceneGraph has " <<
rootTree_->getNumChildren()
1673 <<
" children..." << endl;
1674 for (
unsigned int i = 0; i <
rootTree_->getNumChildren(); i++)
1676 osg::Node *node =
rootTree_->getChild(i);
1677 cout <<
"creating reflection for subtree " << i <<
" with name "
1678 << node->getName() << endl;
1684 mirrortexture, cutUpperHalf);
1696 osgParticle::ParticleSystem *dustParticleSystem =
1697 new osgParticle::ParticleSystem;
1700 dustParticleSystem->setDefaultAttributes(
"/home/koeser/test.png",
false,
1705 osg::Geode *geode =
new osg::Geode;
1706 osg::Group* rootNode =
new osg::Group;
1707 rootNode->addChild(geode);
1708 geode->addDrawable(dustParticleSystem);
1711 osgParticle::ParticleSystemUpdater *dustSystemUpdater =
1712 new osgParticle::ParticleSystemUpdater;
1714 dustSystemUpdater->addParticleSystem(dustParticleSystem);
1716 rootNode->addChild(dustSystemUpdater);
1720 osgParticle::Particle smokeParticle;
1721 smokeParticle.setSizeRange(osgParticle::rangef(0.01, 20.0));
1722 smokeParticle.setLifeTime(4);
1723 smokeParticle.setMass(0.01);
1725 dustParticleSystem->setDefaultParticleTemplate(smokeParticle);
1728 osgParticle::ModularEmitter *emitter =
new osgParticle::ModularEmitter;
1730 emitter->setParticleSystem(dustParticleSystem);
1734 osgParticle::RandomRateCounter *dustRate =
1735 static_cast<osgParticle::RandomRateCounter *
> (emitter->getCounter());
1736 dustRate->setRateRange(5, 10);
1739 osgParticle::MultiSegmentPlacer* lineSegment =
1740 new osgParticle::MultiSegmentPlacer();
1744 lineSegment->addVertex(0, 0, -2);
1745 lineSegment->addVertex(0, -2, -2);
1746 lineSegment->addVertex(0, -16, 0);
1748 emitter->setPlacer(lineSegment);
1751 osgParticle::RadialShooter* smokeShooter =
new osgParticle::RadialShooter();
1753 smokeShooter->setThetaRange(0.0, 3.14159 / 2);
1754 smokeShooter->setInitialSpeedRange(50, 100);
1756 emitter->setShooter(smokeShooter);
1761 osgParticle::ModularProgram *moveDustInAir =
new osgParticle::ModularProgram;
1762 moveDustInAir->setParticleSystem(dustParticleSystem);
1765 osgParticle::AccelOperator *accelUp =
new osgParticle::AccelOperator;
1766 accelUp->setToGravity(-1);
1767 moveDustInAir->addOperator(accelUp);
1770 osgParticle::FluidFrictionOperator *airFriction =
1771 new osgParticle::FluidFrictionOperator;
1772 airFriction->setFluidToAir();
1774 moveDustInAir->addOperator(airFriction);
1777 rootNode->addChild(moveDustInAir);
osg::ref_ptr< osg::Group > rootTree_
NodeInfoMap * pNodeInfoMap
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
void AddDebugLevel(const long int lv)
int XMLRead(const std::string &Filename)
derived classes must implement the function XMLIn which is called by this function XMLRead to read ev...
void DisableZWriteForTransparentNodes_()
osg::Node * createMirroredScene(osg::Node *model, const BIAS::Vector3< double > &ul, const BIAS::Vector3< double > &ur, const BIAS::Vector3< double > &ll, const BIAS::Vector3< double > &lr, const std::string &mirrortexture, bool cutUpperHalf)
helper function for mirror effects, called for all subscenes
double lastPauseTime_
Time when the animation was paused for the last time.
bool NodeHasNodeInfo(osg::Node *node) const
container for scene root and ptr to nodeinfomap
void SetAnimate(const bool animate)
virtual BIAS::ProjectionParametersBase * GetMyselfAsProjectionParametersBase() const =0
void AppendSubTree(osg::ref_ptr< osg::Node > &childNode)
Append an OSG subtree to the constructed root tree.
void RemoveSubTree(osg::ref_ptr< osg::Node > &childNode)
BIAS::Vector3< double > GetBoundingBoxCenter()
Returns center of bounding box around the whole scene.
int AppendSubTreeFromImageFile(const std::string &fileName, const double &width_mm, osg::ref_ptr< osg::Node > &imageNode)
Loads contents from 2D image file into scene graph.
bool IsEditableNode(osg::Node *node)
osg::ref_ptr< osgViewer::Viewer > sceneView_
void AddMirror(const BIAS::Vector3< double > &ul, const BIAS::Vector3< double > &ur, const BIAS::Vector3< double > &ll, const BIAS::Vector3< double > &lr, const std::string &mirrortexture, bool cutUpperHalf=false)
adds a rectangular mirror surface into the scene
bool Save(std::string filename)
Abstract interface class to handle changes in rendering parameters by controllers and in rendering co...
visitor for traversing the scene graph and applying some operation to the related nodeinfomap ...
void MakeTransparent(const double transparency)
bool hasOpenSceneGraphAnimation_
static std::string Basename(const std::string &fullname)
Get file base name without path from given path and filename.
void Reset()
deletes internal pointers
int XMLWrite(const std::string &Filename, int CompressionLevel=0, bool AutoAddCompressionSuffix=true, std::string encoding="UTF-8") const
call this to add the class to a new xml tree and write it to the file Filename.
double timeOffset_
Time offset because of time "pauses".
virtual ~SceneOpenSceneGraph()
static void SplitName(const std::string &fullname, std::string &dir, std::string &base, std::string &suffix)
Split full path into:
void SetAnimationTime(const double current_time, bool CallDraw=true)
setanimationtime() calls draw.
void SetNodeOccluder(osg::Node *node, const bool state)
long int NewDebugLevel(const std::string &name)
creates a new debuglevel
MyBasicAnimationManager animationManager_
osg::ref_ptr< osg::Node > RootNode
bool lightRepresentationVisible_
virtual GLProjectionParametersInterface * GetGLProjectionParametersInterface()
Get the camera as projectionparametersinterface, can be of type GLProjection of of any from GLProject...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
bool Load(std::string filename)
int Init()
Initializes OpenSG tree for scene appendance.
int AppendSubTreeSwitch(osg::ref_ptr< osg::Node > &switchNode, eNodeType NodeType=eNT_Default)
Append an OSG subtree to the constructed root tree with switch node.
osg::ref_ptr< osg::Node > GetSceneRoot()
returns ref_ptr to root of tree
virtual void Draw()
To do anything usefull, overload this method, assume context is ready and draw.
osg::ref_ptr< osgAnimation::BasicAnimationManager > _am
osg::ref_ptr< osg::Light > light_
static bool AddOrSetInfo(osg::ref_ptr< osg::Node > node, const std::string &key, const std::string &value)
Adds or sets information to the node.
void SetNodeMarkerID(osg::Node *node, const unsigned long long &id)
bool RightMouseDoubleClicked(int x, int y)
static std::string Suffix(const std::string &fullname)
Get file suffix (including dot!) from given path and filename.
Base class for all scenes.
int AppendSubTreeFromFile(const std::string &fileName, osg::ref_ptr< osg::Node > &childNode, bool optimize=false)
Loads contents from file into scene graph.
void HeadlightSwitch(bool on=true)
Toggles the headlight.
osg::ref_ptr< osg::MatrixTransform > lightTransform_
void SetFixedPointLight(bool on, BIAS::Vector3< double > posPointLight)
Removes the camera as a beacon for the lights and sets a fixed position for Point Light or fixed dire...
void MakeRootShadowNode(osg::ref_ptr< osg::LightSource > lightSource)
osg::observer_ptr< osgViewer::GraphicsWindow > embedWindow_
bool SaveSubTree(osg::Node *node, const std::string &fileName)
Saves contents beginning at node into a file.
virtual double GetDepth(const unsigned int x, const unsigned int y)=0
osg::ref_ptr< osg::Switch > lightRepresentationSwitch_
void SetFixedDirectionalLight(bool on, BIAS::Vector3< double > dirDirectionalLight)
std::string NodePtr2IDString_(osg::Node *node)
void SetNodeVisible(osg::Node *node, const bool visible)
sets node visbility in guis like treectrlopensgwx this changes only the nodeinfomap and has no effec...
virtual void GetBoundingBox(BIAS::Vector3< double > &min, BIAS::Vector3< double > &max)
Returns bounding box around the whole scene.
osg::ref_ptr< osg::FrameStamp > frameStamp_
void CreateStandardNodes_()
osg::ref_ptr< osg::Geode > lightRepresentationGeode_
std::string NodeType2String(const enum eNodeType &t)
Vector3< T > & Normalize()
normalize this vector to length 1
void RemoveSubTreeAndParents(osg::Node *Node)
removes the subtree and the parents except the globalroot of a given node
void UpdateLightRepresentation_()
static bool HasInfo(const osg::ref_ptr< osg::Node > node, const std::string &key, std::string &value)
Checks if the node contains additional information in form of a key value pair.