|
|
|
@ -274,59 +274,44 @@ namespace SceneUtil
|
|
|
|
|
|
|
|
|
|
if (lights.size())
|
|
|
|
|
{
|
|
|
|
|
// we do the intersections in view space
|
|
|
|
|
osg::BoundingSphere nodeBound = node->getBound();
|
|
|
|
|
osg::Matrixf mat = *cv->getModelViewMatrix();
|
|
|
|
|
transformBoundingSphere(mat, nodeBound);
|
|
|
|
|
|
|
|
|
|
static std::map<osg::Node*, osg::ref_ptr<osg::StateSet> > statesets;
|
|
|
|
|
std::map<osg::Node*, osg::ref_ptr<osg::StateSet> >::iterator found = statesets.find(node);
|
|
|
|
|
osg::ref_ptr<osg::StateSet> stateset;
|
|
|
|
|
if (found != statesets.end())
|
|
|
|
|
std::vector<LightSource*> lightList;
|
|
|
|
|
for (unsigned int i=0; i<lights.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
stateset = found->second;
|
|
|
|
|
const LightManager::LightSourceTransform& l = lights[i];
|
|
|
|
|
if (l.mViewBound.intersects(nodeBound))
|
|
|
|
|
lightList.push_back(l.mLightSource);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
// we do the intersections in view space
|
|
|
|
|
osg::BoundingSphere nodeBound = node->getBound();
|
|
|
|
|
osg::Matrixf mat = *cv->getModelViewMatrix();
|
|
|
|
|
transformBoundingSphere(mat, nodeBound);
|
|
|
|
|
|
|
|
|
|
std::vector<LightSource*> lightList;
|
|
|
|
|
for (unsigned int i=0; i<lights.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
const LightManager::LightSourceTransform& l = lights[i];
|
|
|
|
|
if (l.mViewBound.intersects(nodeBound))
|
|
|
|
|
lightList.push_back(l.mLightSource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lightList.empty())
|
|
|
|
|
{
|
|
|
|
|
statesets[node] = NULL;
|
|
|
|
|
traverse(node, nv);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int maxLights = static_cast<unsigned int> (8 - mLightManager->getStartLight());
|
|
|
|
|
if (lightList.empty())
|
|
|
|
|
{
|
|
|
|
|
traverse(node, nv);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lightList.size() > maxLights)
|
|
|
|
|
{
|
|
|
|
|
//std::cerr << "More than 8 lights!" << std::endl;
|
|
|
|
|
unsigned int maxLights = static_cast<unsigned int> (8 - mLightManager->getStartLight());
|
|
|
|
|
|
|
|
|
|
// TODO: sort lights by certain criteria
|
|
|
|
|
if (lightList.size() > maxLights)
|
|
|
|
|
{
|
|
|
|
|
//std::cerr << "More than 8 lights!" << std::endl;
|
|
|
|
|
|
|
|
|
|
while (lightList.size() > maxLights)
|
|
|
|
|
lightList.pop_back();
|
|
|
|
|
}
|
|
|
|
|
// TODO: sort lights by certain criteria
|
|
|
|
|
|
|
|
|
|
stateset = mLightManager->getLightListStateSet(lightList);
|
|
|
|
|
statesets[node] = stateset;
|
|
|
|
|
while (lightList.size() > maxLights)
|
|
|
|
|
lightList.pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stateset)
|
|
|
|
|
cv->pushStateSet(stateset);
|
|
|
|
|
osg::StateSet* stateset = mLightManager->getLightListStateSet(lightList);
|
|
|
|
|
|
|
|
|
|
cv->pushStateSet(stateset);
|
|
|
|
|
|
|
|
|
|
traverse(node, nv);
|
|
|
|
|
|
|
|
|
|
if (stateset)
|
|
|
|
|
cv->popStateSet();
|
|
|
|
|
cv->popStateSet();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
traverse(node, nv);
|
|
|
|
|