Allow setting emission for each canvas placement
This commit is contained in:
parent
563ea69d34
commit
258d387d15
4 changed files with 65 additions and 16 deletions
|
@ -63,8 +63,10 @@ class WindowPlacement:
|
||||||
public simgear::canvas::Placement
|
public simgear::canvas::Placement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowPlacement( canvas::WindowPtr window,
|
WindowPlacement( SGPropertyNode* node,
|
||||||
|
canvas::WindowPtr window,
|
||||||
simgear::canvas::CanvasPtr canvas ):
|
simgear::canvas::CanvasPtr canvas ):
|
||||||
|
Placement(node),
|
||||||
_window(window),
|
_window(window),
|
||||||
_canvas(canvas)
|
_canvas(canvas)
|
||||||
{}
|
{}
|
||||||
|
@ -229,7 +231,7 @@ canvas::WindowPtr GUIMgr::getWindow(size_t i)
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
simgear::canvas::Placements
|
simgear::canvas::Placements
|
||||||
GUIMgr::addPlacement( const SGPropertyNode* node,
|
GUIMgr::addPlacement( SGPropertyNode* node,
|
||||||
simgear::canvas::CanvasPtr canvas )
|
simgear::canvas::CanvasPtr canvas )
|
||||||
{
|
{
|
||||||
int placement_index = node->getIntValue("index", -1);
|
int placement_index = node->getIntValue("index", -1);
|
||||||
|
@ -246,7 +248,7 @@ GUIMgr::addPlacement( const SGPropertyNode* node,
|
||||||
|
|
||||||
window->setCanvas(canvas);
|
window->setCanvas(canvas);
|
||||||
placements.push_back(
|
placements.push_back(
|
||||||
simgear::canvas::PlacementPtr(new WindowPlacement(window, canvas))
|
simgear::canvas::PlacementPtr(new WindowPlacement(node, window, canvas))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return placements;
|
return placements;
|
||||||
|
|
|
@ -61,8 +61,7 @@ class GUIMgr:
|
||||||
|
|
||||||
canvas::WindowPtr getWindow(size_t i);
|
canvas::WindowPtr getWindow(size_t i);
|
||||||
simgear::canvas::Placements
|
simgear::canvas::Placements
|
||||||
addPlacement( const SGPropertyNode*,
|
addPlacement(SGPropertyNode*, simgear::canvas::CanvasPtr canvas );
|
||||||
simgear::canvas::CanvasPtr canvas );
|
|
||||||
|
|
||||||
bool handleMouse(const osgGA::GUIEventAdapter& ea);
|
bool handleMouse(const osgGA::GUIEventAdapter& ea);
|
||||||
void handleResize(int x, int y, int width, int height);
|
void handleResize(int x, int y, int width, int height);
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <osg/Camera>
|
#include <osg/Camera>
|
||||||
#include <osg/Geode>
|
#include <osg/Geode>
|
||||||
#include <osg/NodeVisitor>
|
#include <osg/NodeVisitor>
|
||||||
|
#include <osg/Material>
|
||||||
#include <osg/Matrix>
|
#include <osg/Matrix>
|
||||||
#include <osg/PolygonMode>
|
#include <osg/PolygonMode>
|
||||||
#include <osg/ShadeModel>
|
#include <osg/ShadeModel>
|
||||||
|
@ -78,6 +79,9 @@ class ReplaceStaticTextureVisitor:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef osg::ref_ptr<osg::Group> GroupPtr;
|
||||||
|
typedef osg::ref_ptr<osg::Material> MaterialPtr;
|
||||||
|
|
||||||
ReplaceStaticTextureVisitor( const char* name,
|
ReplaceStaticTextureVisitor( const char* name,
|
||||||
osg::Texture2D* new_texture ):
|
osg::Texture2D* new_texture ):
|
||||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||||
|
@ -85,7 +89,7 @@ class ReplaceStaticTextureVisitor:
|
||||||
_new_texture(new_texture)
|
_new_texture(new_texture)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ReplaceStaticTextureVisitor( const SGPropertyNode* placement,
|
ReplaceStaticTextureVisitor( SGPropertyNode* placement,
|
||||||
osg::Texture2D* new_texture,
|
osg::Texture2D* new_texture,
|
||||||
osg::NodeCallback* cull_callback = 0 ):
|
osg::NodeCallback* cull_callback = 0 ):
|
||||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||||
|
@ -94,6 +98,7 @@ class ReplaceStaticTextureVisitor:
|
||||||
),
|
),
|
||||||
_node_name( placement->getStringValue("node") ),
|
_node_name( placement->getStringValue("node") ),
|
||||||
_parent_name( placement->getStringValue("parent") ),
|
_parent_name( placement->getStringValue("parent") ),
|
||||||
|
_node(placement),
|
||||||
_new_texture(new_texture),
|
_new_texture(new_texture),
|
||||||
_cull_callback(cull_callback)
|
_cull_callback(cull_callback)
|
||||||
{
|
{
|
||||||
|
@ -179,7 +184,7 @@ class ReplaceStaticTextureVisitor:
|
||||||
|
|
||||||
// insert a new group between the geode an it's parent which overrides
|
// insert a new group between the geode an it's parent which overrides
|
||||||
// the texture
|
// the texture
|
||||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
GroupPtr group = new osg::Group;
|
||||||
group->setName("canvas texture group");
|
group->setName("canvas texture group");
|
||||||
group->addChild(eg);
|
group->addChild(eg);
|
||||||
parent->removeChild(eg);
|
parent->removeChild(eg);
|
||||||
|
@ -188,16 +193,16 @@ class ReplaceStaticTextureVisitor:
|
||||||
if( _cull_callback )
|
if( _cull_callback )
|
||||||
group->setCullCallback(_cull_callback);
|
group->setCullCallback(_cull_callback);
|
||||||
|
|
||||||
_placements.push_back(
|
|
||||||
simgear::canvas::PlacementPtr(new ObjectPlacement(group))
|
|
||||||
);
|
|
||||||
|
|
||||||
osg::StateSet* stateSet = group->getOrCreateStateSet();
|
osg::StateSet* stateSet = group->getOrCreateStateSet();
|
||||||
stateSet->setTextureAttribute( unit, _new_texture,
|
stateSet->setTextureAttribute( unit, _new_texture,
|
||||||
osg::StateAttribute::OVERRIDE );
|
osg::StateAttribute::OVERRIDE );
|
||||||
stateSet->setTextureMode( unit, GL_TEXTURE_2D,
|
stateSet->setTextureMode( unit, GL_TEXTURE_2D,
|
||||||
osg::StateAttribute::ON );
|
osg::StateAttribute::ON );
|
||||||
|
|
||||||
|
_placements.push_back( simgear::canvas::PlacementPtr(
|
||||||
|
new ObjectPlacement(_node, group)
|
||||||
|
));
|
||||||
|
|
||||||
SG_LOG
|
SG_LOG
|
||||||
(
|
(
|
||||||
SG_GL,
|
SG_GL,
|
||||||
|
@ -217,9 +222,49 @@ class ReplaceStaticTextureVisitor:
|
||||||
public simgear::canvas::Placement
|
public simgear::canvas::Placement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectPlacement(osg::ref_ptr<osg::Group> group):
|
|
||||||
|
ObjectPlacement( SGPropertyNode* node,
|
||||||
|
GroupPtr group ):
|
||||||
|
Placement(node),
|
||||||
_group(group)
|
_group(group)
|
||||||
{}
|
{
|
||||||
|
// TODO make more generic and extendable for more properties
|
||||||
|
if( node->hasValue("emission") )
|
||||||
|
setEmission( node->getFloatValue("emission") );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool childChanged(SGPropertyNode* node)
|
||||||
|
{
|
||||||
|
if( node->getParent() != _node )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( node->getNameString() == "emission" )
|
||||||
|
setEmission( node->getFloatValue() );
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEmission(float emit)
|
||||||
|
{
|
||||||
|
emit = SGMiscf::clip(emit, 0, 1);
|
||||||
|
|
||||||
|
if( !_material )
|
||||||
|
{
|
||||||
|
_material = new osg::Material;
|
||||||
|
_material->setColorMode(osg::Material::OFF);
|
||||||
|
_material->setDataVariance(osg::Object::DYNAMIC);
|
||||||
|
_group->getOrCreateStateSet()
|
||||||
|
->setAttribute(_material, ( osg::StateAttribute::ON
|
||||||
|
| osg::StateAttribute::OVERRIDE ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
_material->setEmission(
|
||||||
|
osg::Material::FRONT_AND_BACK,
|
||||||
|
osg::Vec4(emit, emit, emit, emit)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove placement from the scene
|
* Remove placement from the scene
|
||||||
|
@ -240,13 +285,16 @@ class ReplaceStaticTextureVisitor:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osg::ref_ptr<osg::Group> _group;
|
GroupPtr _group;
|
||||||
|
MaterialPtr _material;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string _tex_name, ///<! Name of texture to be replaced
|
std::string _tex_name, ///<! Name of texture to be replaced
|
||||||
_node_name, ///<! Only replace if node name matches
|
_node_name, ///<! Only replace if node name matches
|
||||||
_parent_name; ///<! Only replace if any parent node matches
|
_parent_name; ///<! Only replace if any parent node matches
|
||||||
/// given name (all the tree upwards)
|
/// given name (all the tree upwards)
|
||||||
|
|
||||||
|
SGPropertyNode_ptr _node;
|
||||||
osg::Texture2D *_new_texture;
|
osg::Texture2D *_new_texture;
|
||||||
osg::NodeCallback *_cull_callback;
|
osg::NodeCallback *_cull_callback;
|
||||||
|
|
||||||
|
@ -266,7 +314,7 @@ FGODGauge::set_texture( const char* name,
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
simgear::canvas::Placements
|
simgear::canvas::Placements
|
||||||
FGODGauge::set_texture( const SGPropertyNode* placement,
|
FGODGauge::set_texture( SGPropertyNode* placement,
|
||||||
osg::Texture2D* new_texture,
|
osg::Texture2D* new_texture,
|
||||||
osg::NodeCallback* cull_callback )
|
osg::NodeCallback* cull_callback )
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,7 +65,7 @@ class FGODGauge:
|
||||||
*/
|
*/
|
||||||
static
|
static
|
||||||
simgear::canvas::Placements
|
simgear::canvas::Placements
|
||||||
set_texture( const SGPropertyNode* placement,
|
set_texture( SGPropertyNode* placement,
|
||||||
osg::Texture2D* new_texture,
|
osg::Texture2D* new_texture,
|
||||||
osg::NodeCallback* cull_callback = 0 );
|
osg::NodeCallback* cull_callback = 0 );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue