Re: [osg-users] Problem loading images when migrating to new OSGViewer
Robert, I tried setting the NearFarRatio to a smaller value, and everything rendered as desired. I ended up using: Code: viewer->getCamera()->setNearFarRatio(0.2); This satisfies all my current requirements, so I will keep in mind your good advice about the osgdepthpartition example if I need to render a more complex scene. Thanks for your help! John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32223#32223 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem loading images when migrating to new OSGViewer
Hi John, On Tue, Sep 28, 2010 at 6:36 PM, John Stokes wrote: > When I comment out the updated "setComputeNearFarMode" line of code, my globe > and sky models show up correctly but my plane model disappears. Is there a > correct cull setting that I should be using to get everything to display? > > I tried using the "COMPUTE_NEAR_FAR_USING_PRIMITIVES" and > "COMPUTE_NEAR_FAR_USING_BOUNDING_VALUES" with this call, but I'm not quite > sure what bounding value I should be using or if I should be looking at > another culling method. OK, this is good, you've isolated the issue to one of management of the near/far planes, so now it's a case of finding the appropriate technique for you type of application/models. First up the near/far planes are computed during the cull traversal, using COMPUTE_NEAR_FAR_USING_PRIMITIVES will be more accurate and provide a tighter bound than COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES but it's more expensive to compute. Both techniques still use clamping of the near/far values to avoid the ratio getting too low which will cause z fighting, this clamping by default pushes out the near value to obtain a specified near/far ratio. The CullSetting::setNearFarRatio(double) sets this value, and Camera subclasses from CullSettings so you can do: camera->setNearFarRatio(0.0001); // default value is 0.0005; It may well be that this in OSG-2.x this near/far ratio is set more conservatively than OSG-0.9.9 and is the reason why you are seeing differences. Have a look at the source code to see what the old default value was. -- For scenes which have a very large depth range that tweaking the near/far planes isn't sufficient it can be useful to using depth partioning, where you render the scene two or more times, varying the region that is rendered in each pass. This osgdepthpartion examples shows this in action. This example is a bit out of date and should really be implemented with viewer slave Cameras rather than in scene graph Camera, but the principles are the same. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem loading images when migrating to new OSGViewer
Robert, Thank you for your insight. I did try loading my models with the standalone osgviewer and each of them loaded correctly as did the exported .osg using osgDB::writeNodeFile. I was testing out commenting out different sections, and I noticed that I had this piece of code that I left out in my last post: Code: OsgViewer* viewer = new osgViewer::Viewer(); viewer->getCamera()->setClearColor( osg::Vec4(0.2,0.2,1,1) ); //Replace osgProducer::viewer cull setting with new osgViewer setting //old code: viewer->getCullSettings().setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); viewer->getCamera()->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); When I comment out the updated "setComputeNearFarMode" line of code, my globe and sky models show up correctly but my plane model disappears. Is there a correct cull setting that I should be using to get everything to display? I tried using the "COMPUTE_NEAR_FAR_USING_PRIMITIVES" and "COMPUTE_NEAR_FAR_USING_BOUNDING_VALUES" with this call, but I'm not quite sure what bounding value I should be using or if I should be looking at another culling method. Thanks, John[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32148#32148 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem loading images when migrating to new OSGViewer
Hi John, I don't know the cause of only the airplane showing up, but can suggest a few things to try to explore what might be going wrong. First up try loading each of the models with osgviewer and see if each one loads up OK. Second write out the completed scene graph to a .osg file just before you run the viewer code. Then try to load this scene graph into osgviewer and see what happens. On the osgProducer::Viewer -> osgViewer::Viewer conversion, with osgViewer the Viewer::frame() method does the sync, update and event traversals, and the rendering traversals all together. Have a look at the source code to Viewer::frame() to see what it's doing. You can break your frame loop out to call each traversals individually if you want. Have a look at discussions about this on the mailing lists/forum and the website, and the examples. In your case you can safely comment out the call to viewer->updateTravesal() as viewer->frame() will be doing it for you. Robert. On Tue, Sep 28, 2010 at 4:10 PM, John Stokes wrote: > Hi, > > I've been migrating some code from OSG 0.9.9 to the latest stable release > (2.8.3), and I've run into an issue when migrating from OSGProducer::viewer > to OsgViewer::viewer. I have three models, an airplane.3ds model, a sky.3ds > model, and a globe.osga model. All three models load correctly (the nodes > returned from osgDB::readNodeFile are not NULL), but only the airplane model > shows up when the viewer display is rendered. > > The only functions that I needed to change from osgProducer to osgViewer were > my initialization and update functions. I've made sure to replace osgProducer > calls with equivalent osgViewer calls when I upgraded (see code below), but > is there anything I might have missed? > > > > Code: > > > 3DPlaneViewer::Initialize(){ > osgViewer::Viewer* viewer = new osgViewer::Viewer(); > > //scene root > osg::Group* root = new osg::Group(); > > //load globe and add transform of globe to root group > osg::Node* globeNode = osgDB::readNodeFile("globe.osga"); > osg::MatrixTransform* globeTransform = new osg::MatrixTransform(); > globeTransform->addChild( globeNode ); > > //create group for globe and sky > osg::Group*terrainNodes = new Group(); > terrainNodes->asGroup()->addChild( globeTransform ); > > //load airplane > osg::Node* airplaneNode = osgDB::readNodeFile("airplane.3ds"); > //specify a location for plane on globe with lat, long, altitude > osg::Matrixd airplaneMatrix; > osg::EllipsoidModel* ellipse->computeLocalToWorldTransformFromLatLongHeight( > osg::DegreesToRadians(20.0f),osg::DegreesToRadians(-30.0f), > 15000,airplaneMatrix ); > > //rotate airplane node > airplaneMatrix.preMult( airplaneMatrix.rotate( > osg::Quat(osg::DegreesToRadians(180.0f), osg::Vec3f( 0, 0, 1 ) ))); > > //setup matrix wrapper node > osg::MatrixTransform* airplaneTransform = new osg::MatrixTransform(); > airplaneTransform->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); > airplaneTransform->setMatrix(airplaneMatrix); > airplaneTransform->addChild( airplaneNode ); > terrainNodes->asGroup()->addChild( airplaneTransform ); > > > //load and add the sky model > osg::Node* skyNode = osgDB::readNodeFile("sky.3DS"); > osg::MatrixTransform* skyTransform = new osg::MatrixTransform(); > skyTransform->addChild( skyNode ); > terrainNodes->asGroup()->addChild( skyTransform ); > > root->addChild( terrainNodes ); > > //realize the scene in the viewer > viewer->setSceneData(root); > viewer->realize(); > > } > > 3DPlaneViewer::Update() > { > > //removed calls to osgProducer::sync() > viewer->updateTraversal(); > > //do some other updates on other objects in the scene > viewer->frame(); > } > > > > > > Thanks, > John > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=32136#32136 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Problem loading images when migrating to new OSGViewer
Hi, I've been migrating some code from OSG 0.9.9 to the latest stable release (2.8.3), and I've run into an issue when migrating from OSGProducer::viewer to OsgViewer::viewer. I have three models, an airplane.3ds model, a sky.3ds model, and a globe.osga model. All three models load correctly (the nodes returned from osgDB::readNodeFile are not NULL), but only the airplane model shows up when the viewer display is rendered. The only functions that I needed to change from osgProducer to osgViewer were my initialization and update functions. I've made sure to replace osgProducer calls with equivalent osgViewer calls when I upgraded (see code below), but is there anything I might have missed? Code: 3DPlaneViewer::Initialize(){ osgViewer::Viewer* viewer = new osgViewer::Viewer(); //scene root osg::Group* root = new osg::Group(); //load globe and add transform of globe to root group osg::Node* globeNode = osgDB::readNodeFile("globe.osga"); osg::MatrixTransform* globeTransform = new osg::MatrixTransform(); globeTransform->addChild( globeNode ); //create group for globe and sky osg::Group*terrainNodes = new Group(); terrainNodes->asGroup()->addChild( globeTransform ); //load airplane osg::Node* airplaneNode = osgDB::readNodeFile("airplane.3ds"); //specify a location for plane on globe with lat, long, altitude osg::Matrixd airplaneMatrix; osg::EllipsoidModel* ellipse->computeLocalToWorldTransformFromLatLongHeight( osg::DegreesToRadians(20.0f),osg::DegreesToRadians(-30.0f), 15000,airplaneMatrix ); //rotate airplane node airplaneMatrix.preMult( airplaneMatrix.rotate( osg::Quat(osg::DegreesToRadians(180.0f), osg::Vec3f( 0, 0, 1 ) ))); //setup matrix wrapper node osg::MatrixTransform* airplaneTransform = new osg::MatrixTransform(); airplaneTransform->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); airplaneTransform->setMatrix(airplaneMatrix); airplaneTransform->addChild( airplaneNode ); terrainNodes->asGroup()->addChild( airplaneTransform ); //load and add the sky model osg::Node* skyNode = osgDB::readNodeFile("sky.3DS"); osg::MatrixTransform* skyTransform = new osg::MatrixTransform(); skyTransform->addChild( skyNode ); terrainNodes->asGroup()->addChild( skyTransform ); root->addChild( terrainNodes ); //realize the scene in the viewer viewer->setSceneData(root); viewer->realize(); } 3DPlaneViewer::Update() { //removed calls to osgProducer::sync() viewer->updateTraversal(); //do some other updates on other objects in the scene viewer->frame(); } Thanks, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32136#32136 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org