7#include <osg/Texture2D>
9#include <osg/NodeVisitor>
10#include <osg/StateSet>
12#include <simgear/canvas/CanvasObjectPlacement.hxx>
13#include <simgear/scene/material/EffectGeode.hxx>
27 osg::ref_ptr<osg::Geode>
node;
42 osg::Texture2D* new_texture ):
43 osg::NodeVisitor(
osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
50 osg::Texture2D* new_texture,
51 osg::NodeCallback* cull_callback = 0,
52 const simgear::canvas::CanvasWeakPtr&
canvas =
53 simgear::canvas::CanvasWeakPtr() ):
54 osg::NodeVisitor(
osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
55 _tex_name( placement->getStringValue(
"texture") ),
56 _node_name( placement->getStringValue(
"node") ),
70 "No filter criterion for replacing texture. "
71 " Every texture will be replaced!"
84 virtual void apply(osg::Geode& node)
86 simgear::EffectGeode* effectGeode =
dynamic_cast<simgear::EffectGeode*
>(&node);
89 simgear::Effect* eff = effectGeode->getEffect();
95 osg::Group *parent = node.getParent(0);
103 const osg::NodePath& np = getNodePath();
105 for(
int i =
static_cast<int>(np.size()) - 2;
i >= 0; --
i )
107 const osg::Node* path_segment = np[
i];
108 const osg::Node* path_parent = path_segment->getParent(0);
112 if( path_parent && path_parent->getName().empty() )
132 unsigned int unit = 0;
134 else if (
_tex_name ==
"normalmap") unit = 1;
136 else if (
_tex_name ==
"emissive") unit = 3;
138 SG_LOG(SG_GL, SG_DEV_ALERT,
"Unknown texture '" <<
_tex_name
139 <<
"'. Using base-color by default");
156 group->setName(
"canvas texture group");
157 group->addChild(g.node);
158 g.parent->removeChild(g.node);
159 g.parent->addChild(group);
164 group->getOrCreateStateSet()->setTextureAttributeAndModes(
167 osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
169 _placements.push_back(simgear::canvas::PlacementPtr(
170 new simgear::canvas::ObjectPlacement(
_node, group,
_canvas)
178 <<
" for object '" << g.parent->getName() <<
"'"
205 if( !node.getName().empty() )
206 return node.getName();
211 osg::Group
const* parent = node.getParent(0);
212 if( parent->getName() ==
"pick render group" )
213 return parent->getParent(0)->getName();
215 return node.getName();
220simgear::canvas::Placements
223 osg::Texture2D* new_texture )
226 branch->accept(visitor);
232simgear::canvas::Placements
234 osg::Texture2D* new_texture )
238 globals->get_scenery()->get_aircraft_branch(),
245simgear::canvas::Placements
247 SGPropertyNode* placement,
248 osg::Texture2D* new_texture,
249 osg::NodeCallback* cull_callback,
250 const simgear::canvas::CanvasWeakPtr&
canvas )
256 branch->accept(visitor);
262simgear::canvas::Placements
264 osg::Texture2D* new_texture,
265 osg::NodeCallback* cull_callback,
266 const simgear::canvas::CanvasWeakPtr&
canvas )
270 globals->get_scenery()->get_aircraft_branch(),
Replace a texture in the airplane model with another.
GroupList groups_to_modify
simgear::canvas::CanvasWeakPtr _canvas
osg::Texture2D * _new_texture
ReplaceStaticTextureVisitor(const char *name, osg::Texture2D *new_texture)
osg::ref_ptr< osg::Material > MaterialPtr
std::string _node_name
! Only replace if node name matches
ReplaceStaticTextureVisitor(SGPropertyNode *placement, osg::Texture2D *new_texture, osg::NodeCallback *cull_callback=0, const simgear::canvas::CanvasWeakPtr &canvas=simgear::canvas::CanvasWeakPtr())
simgear::canvas::Placements _placements
osg::NodeCallback * _cull_callback
std::string _parent_name
!
std::vector< GroupListItem > GroupList
simgear::canvas::Placements & getPlacements()
Get a list of groups which have been inserted into the scene graph to replace the given texture.
osg::ref_ptr< osg::Group > GroupPtr
virtual void apply(osg::Geode &node)
const std::string & getNodeName(const osg::Node &node) const
simgear::canvas::Placements set_texture(osg::Node *branch, const char *name, osg::Texture2D *new_texture)
Replace an opengl texture name inside a given branch of the scene graph.
simgear::canvas::Placements set_aircraft_texture(const char *name, osg::Texture2D *new_texture)
Replace an opengl texture name inside the aircraft scene graph.
osg::ref_ptr< osg::Group > parent
osg::ref_ptr< osg::Geode > node