#include <osg/Camera>
#include <osg/Geode>
#include <osg/NodeVisitor>
-#include <osg/Material>
#include <osg/Matrix>
#include <osg/PolygonMode>
#include <osg/ShadeModel>
#include <osgDB/FileNameUtils>
+#include <simgear/canvas/CanvasObjectPlacement.hxx>
#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/util/RenderConstants.hxx>
-#include <Canvas/FGCanvasSystemAdapter.hxx>
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
#include "od_gauge.hxx"
#include <cassert>
-static simgear::canvas::SystemAdapterPtr system_adapter(
- new canvas::FGCanvasSystemAdapter
-);
-
//------------------------------------------------------------------------------
FGODGauge::FGODGauge()
{
- setSystemAdapter(system_adapter);
+
}
//------------------------------------------------------------------------------
osg::Texture2D* new_texture ):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_tex_name( osgDB::getSimpleFileName(name) ),
- _new_texture(new_texture)
+ _new_texture(new_texture),
+ _cull_callback(0)
{}
ReplaceStaticTextureVisitor( SGPropertyNode* placement,
osg::Texture2D* new_texture,
- osg::NodeCallback* cull_callback = 0 ):
+ osg::NodeCallback* cull_callback = 0,
+ const simgear::canvas::CanvasWeakPtr& canvas =
+ simgear::canvas::CanvasWeakPtr() ):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_tex_name( osgDB::getSimpleFileName(
placement->getStringValue("texture"))
_parent_name( placement->getStringValue("parent") ),
_node(placement),
_new_texture(new_texture),
- _cull_callback(cull_callback)
+ _cull_callback(cull_callback),
+ _canvas(canvas)
{
if( _tex_name.empty()
&& _node_name.empty()
return;
osg::Group *parent = node.getParent(0);
- if( !_node_name.empty() && parent->getName() != _node_name )
+ if( !_node_name.empty() && getNodeName(*parent) != _node_name )
return;
if( !_parent_name.empty() )
osg::StateAttribute::ON );
_placements.push_back( simgear::canvas::PlacementPtr(
- new ObjectPlacement(_node, group)
+ new simgear::canvas::ObjectPlacement(_node, group, _canvas)
));
SG_LOG
protected:
- class ObjectPlacement:
- public simgear::canvas::Placement
- {
- public:
-
- ObjectPlacement( SGPropertyNode* node,
- GroupPtr group ):
- Placement(node),
- _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
- */
- virtual ~ObjectPlacement()
- {
- assert( _group->getNumChildren() == 1 );
- osg::Node *child = _group->getChild(0);
-
- if( _group->getNumParents() )
- {
- osg::Group *parent = _group->getParent(0);
- parent->addChild(child);
- parent->removeChild(_group);
- }
-
- _group->removeChild(child);
- }
-
- private:
- GroupPtr _group;
- MaterialPtr _material;
- };
-
std::string _tex_name, ///<! Name of texture to be replaced
_node_name, ///<! Only replace if node name matches
_parent_name; ///<! Only replace if any parent node matches
osg::Texture2D *_new_texture;
osg::NodeCallback *_cull_callback;
- simgear::canvas::Placements _placements;
+ simgear::canvas::CanvasWeakPtr _canvas;
+ simgear::canvas::Placements _placements;
+
+ const std::string& getNodeName(const osg::Node& node) const
+ {
+ if( !node.getName().empty() )
+ return node.getName();
+
+ // Special handling for pick animation which clears the name of the object
+ // and instead sets the name of a parent group with one or two groups
+ // attached (one for normal rendering and one for the picking highlight).
+ osg::Group const* parent = node.getParent(0);
+ if( parent->getName() == "pick render group" )
+ return parent->getParent(0)->getName();
+
+ return node.getName();
+ }
};
//------------------------------------------------------------------------------
simgear::canvas::Placements
-FGODGauge::set_texture( const char* name,
+FGODGauge::set_texture( osg::Node* branch,
+ const char * name,
osg::Texture2D* new_texture )
{
- osg::Group* root = globals->get_scenery()->get_aircraft_branch();
ReplaceStaticTextureVisitor visitor(name, new_texture);
- root->accept(visitor);
+ branch->accept(visitor);
return visitor.getPlacements();
}
//------------------------------------------------------------------------------
simgear::canvas::Placements
-FGODGauge::set_texture( SGPropertyNode* placement,
+FGODGauge::set_aircraft_texture( const char* name,
+ osg::Texture2D* new_texture )
+{
+ return set_texture
+ (
+ globals->get_scenery()->get_aircraft_branch(),
+ name,
+ new_texture
+ );
+}
+
+//------------------------------------------------------------------------------
+simgear::canvas::Placements
+FGODGauge::set_texture( osg::Node* branch,
+ SGPropertyNode* placement,
osg::Texture2D* new_texture,
- osg::NodeCallback* cull_callback )
+ osg::NodeCallback* cull_callback,
+ const simgear::canvas::CanvasWeakPtr& canvas )
{
- osg::Group* root = globals->get_scenery()->get_aircraft_branch();
- ReplaceStaticTextureVisitor visitor(placement, new_texture, cull_callback);
- root->accept(visitor);
+ ReplaceStaticTextureVisitor visitor( placement,
+ new_texture,
+ cull_callback,
+ canvas );
+ branch->accept(visitor);
return visitor.getPlacements();
}
+
+//------------------------------------------------------------------------------
+simgear::canvas::Placements
+FGODGauge::set_aircraft_texture( SGPropertyNode* placement,
+ osg::Texture2D* new_texture,
+ osg::NodeCallback* cull_callback,
+ const simgear::canvas::CanvasWeakPtr& canvas )
+{
+ return set_texture
+ (
+ globals->get_scenery()->get_aircraft_branch(),
+ placement,
+ new_texture,
+ cull_callback,
+ canvas
+ );
+}