diff --git a/simgear/scene/model/SGLight.cxx b/simgear/scene/model/SGLight.cxx index 29602af4..b29f5797 100644 --- a/simgear/scene/model/SGLight.cxx +++ b/simgear/scene/model/SGLight.cxx @@ -27,6 +27,8 @@ #include #include +#include "animation.hxx" + class SGLightDebugListener : public SGPropertyChangeListener { public: SGLightDebugListener(osg::Switch *sw) : _sw(sw) {} @@ -109,6 +111,17 @@ SGLight::appendLight(const SGPropertyNode *configNode, } align->setMatrix(r * t); + const SGPropertyNode *dim_factor = configNode->getChild("dim-factor"); + if (dim_factor) { + const SGExpressiond *expression = + read_value(dim_factor, modelRoot, "", 0, 1); + light->setUpdateCallback( + new SGLight::UpdateCallback(expression, + light->getAmbient(), + light->getDiffuse(), + light->getSpecular())); + } + osg::Shape *debug_shape = nullptr; if (light->getType() == SGLight::Type::POINT) { debug_shape = new osg::Sphere(osg::Vec3(0, 0, 0), light->getRange()); diff --git a/simgear/scene/model/SGLight.hxx b/simgear/scene/model/SGLight.hxx index 2a25413b..a9b07cf2 100644 --- a/simgear/scene/model/SGLight.hxx +++ b/simgear/scene/model/SGLight.hxx @@ -21,6 +21,7 @@ #include #include +#include class SGLight : public osg::Node { public: @@ -29,6 +30,29 @@ public: SPOT }; + class UpdateCallback : public osg::NodeCallback { + public: + UpdateCallback(const SGExpressiond *expression, + osg::Vec4 ambient, osg::Vec4 diffuse, osg::Vec4 specular) : + _expression(expression), + _ambient(ambient), _diffuse(diffuse), _specular(specular) {} + virtual void operator()(osg::Node *node, osg::NodeVisitor *nv) { + double value = _expression->getValue(); + if (value != _prev_value) { + SGLight *light = dynamic_cast(node); + if (light) { + light->setAmbient(_ambient * value); + light->setDiffuse(_diffuse * value); + light->setSpecular(_specular * value); + } + } + } + private: + SGSharedPtr _expression; + osg::Vec4 _ambient, _diffuse, _specular; + double _prev_value = -1.0; + }; + SGLight(); SGLight(const SGLight& l,