Hi Per,
I've quite a bit of head scratching about what was going on a couple
of things dawned on me:
1) The way to implement localization of small feature culling is to
disable it globally and then just enable it for
the subgraphs that need it. This avoid problems with subgraphs
being culled from higher up in the scene graph
due to small feature culling that you haven't disabled yet.
2) One should only enable the culling against the view frustum sides,
unless you explicitly require near/far culling based
on a fixed control of near/far planes.
3) One only needs to modify the mask of the CullingSet, mode of
CullSettings is just a distraction.
I've applied these changes to your example osgscribe.cpp, and now it
works I believe you intended - although the I'm now enabling culling
for the right hand subgarph, rather than disabling it for the right
hand subgraph, you can get your original effect by just swapping which
subgraphs has the callback on.
As the modified example demonstrates that you can enable small feature
culling selectively on subgraphs without any modifications to the core
OSG I'm closing this "bug report"/"bug fix".
Cheers,
Robert.
/* OpenSceneGraph example, osgscribe.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <osg/Geode>
#include <osg/Group>
#include <osg/Notify>
#include <osg/Material>
#include <osg/PolygonOffset>
#include <osg/PolygonMode>
#include <osg/LineStipple>
#include <osg/PositionAttitudeTransform>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgViewer/Viewer>
#include <osgUtil/Optimizer>
class MyCullingCallback : public osg::NodeCallback
{
public:
MyCullingCallback() : osg::NodeCallback()
{}
virtual void operator() (osg::Node *node, osg::NodeVisitor *nv)
{
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if(cv){
osg::CullingSet &cs = cv->getCurrentCullingSet();
osg::CullingSet::Mask previousMask = cs.getCullingMask();
cs.setCullingMask(previousMask | osg::CullSettings::SMALL_FEATURE_CULLING);
traverse(node,nv);
cs.setCullingMask(previousMask);
}else
traverse(node,nv);
}
};
int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
// construct the viewer.
osgViewer::Viewer viewer;
osg::Camera *cam = viewer.getCamera();
if(cam){
// note just enable view furstum culling sides, leave it to subgraphs to enable
// small feature culling where required.
cam->setCullingMode(osgUtil::CullVisitor::VIEW_FRUSTUM_SIDES_CULLING);
cam->setSmallFeatureCullingPixelSize(200);
}
// load the nodes from the commandline arguments.
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
// if not loaded assume no arguments passed in, try use default mode instead.
if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osg");
if (!loadedModel)
{
osg::notify(osg::NOTICE)<<"Please specifiy a model filename on the command line."<<std::endl;
return 1;
}
osg::Group* rootnode = new osg::Group;
rootnode->addChild(loadedModel);
osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform;
pat->setPosition(osg::Vec3d(20, 0, 0));
osg::Group *tmp = new osg::Group;
// enable small feature culling for subgraph.
tmp->setCullCallback(new MyCullingCallback);
tmp->addChild(pat);
rootnode->addChild(tmp);
pat->addChild(loadedModel);
// add a viewport to the viewer and attach the scene graph.
viewer.setSceneData( rootnode );
return viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org