osg.ClusterCullingCallback
osg::ClusterCullingCallback
是OpenSceneGraph中用于集群裁剪的回调函数。它可以与osg::CullSettings
类一起使用,通过对场景进行分组,提高场景渲染性能。
osg::ClusterCullingCallback
需要使用以下步骤:
osg::ClusterCullingCallback
对象。osg::CullSettings
中。osg::CullSettings
设置osg::ClusterCullingCallback
。示例代码:
osg::ref_ptr<osg::Node> node = createSceneGraph();
osg::ref_ptr<osg::CullSettings> cullSettings = new osg::CullSettings;
cullSettings->addCullStage(new osg::CullStage);
cullSettings->getCullStage(0)->setCullingActive(true);
cullSettings->getCullStage(0)->addCulledNode(node);
osg::ref_ptr<osg::ClusterCullingCallback> clusterCallback = new osg::ClusterCullingCallback;
clusterCallback->setNumOfCullingNodes(8);
clusterCallback->setCullingMethod(osg::ClusterCullingCallback::VIEW_FRUSTUM_CULLING);
cullSettings->getCullStage(0)->setCullCallback(clusterCallback.get());
setCullingMethod(const osg::ClusterCullingCallback::CullingMethod& method)
:设置集群裁剪的方法。可选参数为VIEW_FRUSTUM_CULLING
和VISIBLE_SET_CULLING
。setNumOfCullingNodes(unsigned int n)
:设置分割的节点数。setInitialBound(osg::BoundingSphere& bs)
:设置集群的初始边界。默认使用场景图的边界。setMatrixList(osg::MatrixList& matrixList)
: 设置变换矩阵列表。setMatrix(osg::Matrixd& matrix)
: 设置变换矩阵。VIEW_FRUSTUM_CULLING
:使用视椎体裁剪。VISIBLE_SET_CULLING
:使用可见集合裁剪。osg::ClusterCullingCallback
只能与osg::CullSettings
和osg::CullStack
一起使用。osg::ClusterCullingCallback
只能用于节点的分组裁剪,不能用于物体的裁剪。osg::ClusterCullingCallback
可用于多线程优化场景渲染,但需要合理设置分组数。osg::ClusterCullingCallback
将会增加CPU计算量,需要根据场景复杂度合理使用。