diff --git a/include/osg/CullSettings b/include/osg/CullSettings index 95bf9f108..87de0e63d 100644 --- a/include/osg/CullSettings +++ b/include/osg/CullSettings @@ -86,10 +86,10 @@ class OSG_EXPORT CullSettings void setCullSettings(const CullSettings& settings) { inheritCullSettings(settings, ALL_VARIABLES); } /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ - void inheritCullSettings(const CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); } + virtual void inheritCullSettings(const CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); } /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ - void inheritCullSettings(const CullSettings& settings, unsigned int inheritanceMask); + virtual void inheritCullSettings(const CullSettings& settings, unsigned int inheritanceMask); /** read the environmental variables.*/ void readEnvironmentalVariables(); diff --git a/include/osg/View b/include/osg/View index 769c728b9..797716410 100644 --- a/include/osg/View +++ b/include/osg/View @@ -15,6 +15,7 @@ #define OSG_VIEW 1 #include +#include #include @@ -43,6 +44,29 @@ class OSG_EXPORT View : public osg::Object /** Get the const Stats object.*/ const osg::Stats* getStats() const { return _stats.get(); } + /** Options for controlling the global lighting used for the view.*/ + enum LightingMode + { + NO_LIGHT, + HEADLIGHT, + SKY_LIGHT + }; + + /** Set the global lighting to use for this view. + * Defaults to headlight. */ + void setLightingMode(LightingMode lightingMode); + + /** Get the global lighting used for this view.*/ + LightingMode getLightingMode() const { return _lightingMode; } + + /** Get the global light.*/ + void setLight(osg::Light* light) { _light = light; } + + /** Get the global lighting if assigned.*/ + osg::Light* getLight() { return _light.get(); } + + /** Get the const global lighting if assigned.*/ + const osg::Light* getLight() const { return _light.get(); } /** Set the master camera of the view. */ void setCamera(osg::Camera* camera); @@ -109,10 +133,13 @@ class OSG_EXPORT View : public osg::Object osg::ref_ptr _stats; + LightingMode _lightingMode; + osg::ref_ptr _light; + osg::ref_ptr _camera; - typedef std::vector Slaves; - Slaves _slaves; + typedef std::vector Slaves; + Slaves _slaves; }; } diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index 25e98d5cc..2293831f9 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -422,6 +422,12 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings virtual osg::Matrixd computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const; virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view) const; + /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ + void inheritCullSettings(const CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); } + + /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ + virtual void inheritCullSettings(const osg::CullSettings& settings, unsigned int inheritanceMask); + /** Do init traversal of attached scene graph using Init NodeVisitor. * The init traversal is called once for each SceneView, and should diff --git a/src/osg/View.cpp b/src/osg/View.cpp index 16296e7c7..ef5fe107b 100644 --- a/src/osg/View.cpp +++ b/src/osg/View.cpp @@ -20,6 +20,8 @@ View::View() { // osg::notify(osg::NOTICE)<<"Constructing osg::View"<setProjectionMatrixAsFrustum(-0.325, 0.325, -0.26, 0.26, 1.0f,10000.0f); @@ -31,6 +33,8 @@ View::View() View::View(const osg::View& view, const osg::CopyOp& copyop): Object(view,copyop), + _lightingMode(view._lightingMode), + _light(view._light), _camera(view._camera), _slaves(view._slaves) { @@ -60,6 +64,19 @@ View::~View() osg::notify(osg::INFO)<<"Done destructing osg::View"<setLightNum(0); + _light->setAmbient(Vec4(0.00f,0.0f,0.00f,1.0f)); + _light->setDiffuse(Vec4(0.8f,0.8f,0.8f,1.0f)); + _light->setSpecular(Vec4(1.0f,1.0f,1.0f,1.0f)); + } +} + void View::setCamera(osg::Camera* camera) { diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 04965b0ff..bd9d7dbc4 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -496,6 +496,24 @@ osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& vi -es,0.0,0.0,1.0); } +void SceneView::inheritCullSettings(const osg::CullSettings& settings, unsigned int inheritanceMask) +{ + if (_camera.valid() && _camera->getView()) + { + switch(_camera->getView()->getLightingMode()) + { + case(osg::View::NO_LIGHT): setLightingMode(NO_SCENEVIEW_LIGHT); break; + case(osg::View::HEADLIGHT): setLightingMode(HEADLIGHT); break; + case(osg::View::SKY_LIGHT): setLightingMode(SKY_LIGHT); break; + } + + setLight(_camera->getView()->getLight()); + } + + osg::CullSettings::inheritCullSettings(settings, inheritanceMask); +} + + void SceneView::cull() { _dynamicObjectCount = 0; diff --git a/src/osgWrappers/osg/CullSettings.cpp b/src/osgWrappers/osg/CullSettings.cpp index 37f6ed3cc..e203fa8ae 100644 --- a/src/osgWrappers/osg/CullSettings.cpp +++ b/src/osgWrappers/osg/CullSettings.cpp @@ -99,12 +99,12 @@ BEGIN_VALUE_REFLECTOR(osg::CullSettings) "Set the local cull settings values from specified CullSettings object. ", ""); I_Method1(void, inheritCullSettings, IN, const osg::CullSettings &, settings, - Properties::NON_VIRTUAL, + Properties::VIRTUAL, __void__inheritCullSettings__C5_CullSettings_R1, "Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask. ", ""); I_Method2(void, inheritCullSettings, IN, const osg::CullSettings &, settings, IN, unsigned int, inheritanceMask, - Properties::NON_VIRTUAL, + Properties::VIRTUAL, __void__inheritCullSettings__C5_CullSettings_R1__unsigned_int, "Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask. ", ""); diff --git a/src/osgWrappers/osg/View.cpp b/src/osgWrappers/osg/View.cpp index b6cbfcd32..550ce43af 100644 --- a/src/osgWrappers/osg/View.cpp +++ b/src/osgWrappers/osg/View.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,12 @@ #undef OUT #endif +BEGIN_ENUM_REFLECTOR(osg::View::LightingMode) + I_EnumLabel(osg::View::NO_LIGHT); + I_EnumLabel(osg::View::HEADLIGHT); + I_EnumLabel(osg::View::SKY_LIGHT); +END_REFLECTOR + BEGIN_OBJECT_REFLECTOR(osg::View) I_BaseType(osg::Object); I_Constructor0(____View, @@ -75,6 +82,31 @@ BEGIN_OBJECT_REFLECTOR(osg::View) __C5_osg_Stats_P1__getStats, "Get the const Stats object. ", ""); + I_Method1(void, setLightingMode, IN, osg::View::LightingMode, lightingMode, + Properties::NON_VIRTUAL, + __void__setLightingMode__LightingMode, + "Set the global lighting to use for this view. ", + "Defaults to headlight. "); + I_Method0(osg::View::LightingMode, getLightingMode, + Properties::NON_VIRTUAL, + __LightingMode__getLightingMode, + "Get the global lighting used for this view. ", + ""); + I_Method1(void, setLight, IN, osg::Light *, light, + Properties::NON_VIRTUAL, + __void__setLight__osg_Light_P1, + "Get the global light. ", + ""); + I_Method0(osg::Light *, getLight, + Properties::NON_VIRTUAL, + __osg_Light_P1__getLight, + "Get the global lighting if assigned. ", + ""); + I_Method0(const osg::Light *, getLight, + Properties::NON_VIRTUAL, + __C5_osg_Light_P1__getLight, + "Get the const global lighting if assigned. ", + ""); I_Method1(void, setCamera, IN, osg::Camera *, camera, Properties::NON_VIRTUAL, __void__setCamera__osg_Camera_P1, @@ -138,6 +170,12 @@ BEGIN_OBJECT_REFLECTOR(osg::View) I_SimpleProperty(osg::Camera *, Camera, __osg_Camera_P1__getCamera, __void__setCamera__osg_Camera_P1); + I_SimpleProperty(osg::Light *, Light, + __osg_Light_P1__getLight, + __void__setLight__osg_Light_P1); + I_SimpleProperty(osg::View::LightingMode, LightingMode, + __LightingMode__getLightingMode, + __void__setLightingMode__LightingMode); I_ArrayProperty(osg::View::Slave &, Slave, __Slave_R1__getSlave__unsigned_int, 0, diff --git a/src/osgWrappers/osgUtil/SceneView.cpp b/src/osgWrappers/osgUtil/SceneView.cpp index 8f3423da0..cfdd4ffc1 100644 --- a/src/osgWrappers/osgUtil/SceneView.cpp +++ b/src/osgWrappers/osgUtil/SceneView.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -696,6 +697,16 @@ BEGIN_OBJECT_REFLECTOR(osgUtil::SceneView) __osg_Matrixd__computeRightEyeViewImplementation__C5_osg_Matrixd_R1, "", ""); + I_Method1(void, inheritCullSettings, IN, const osg::CullSettings &, settings, + Properties::NON_VIRTUAL, + __void__inheritCullSettings__C5_CullSettings_R1, + "Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask. ", + ""); + I_Method2(void, inheritCullSettings, IN, const osg::CullSettings &, settings, IN, unsigned int, inheritanceMask, + Properties::VIRTUAL, + __void__inheritCullSettings__C5_osg_CullSettings_R1__unsigned_int, + "Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask. ", + ""); I_Method0(void, init, Properties::VIRTUAL, __void__init,