1 // model.hxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain, and comes with no warranty.
10 # error This library requires C++
13 #include <simgear/compiler.h>
19 #include <osg/Texture2D>
20 #include <osgDB/ReaderWriter>
22 #include <simgear/misc/sg_path.hxx>
23 #include <simgear/props/props.hxx>
24 #include <simgear/scene/util/NodeAndDrawableVisitor.hxx>
27 SGLoadTexture2D(bool staticTexture, const std::string& path,
28 const osgDB::ReaderWriter::Options* options = 0,
29 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1);
31 inline osg::Texture2D*
32 SGLoadTexture2D(const std::string& path,
33 const osgDB::ReaderWriter::Options* options = 0,
34 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1)
36 return SGLoadTexture2D(true, path, options, wrapu, wrapv, mipmaplevels);
39 inline osg::Texture2D*
40 SGLoadTexture2D(const SGPath& path,
41 const osgDB::ReaderWriter::Options* options = 0,
42 bool wrapu = true, bool wrapv = true,
43 int mipmaplevels = -1)
45 return SGLoadTexture2D(true, path.str(), options, wrapu, wrapv,
49 inline osg::Texture2D*
50 SGLoadTexture2D(bool staticTexture, const SGPath& path,
51 const osgDB::ReaderWriter::Options* options = 0,
52 bool wrapu = true, bool wrapv = true,
53 int mipmaplevels = -1)
55 return SGLoadTexture2D(staticTexture, path.str(), options, wrapu, wrapv,
61 osg::Node* copyModel(osg::Node* model);
63 // Change the StateSets of a model to hold different textures based on
66 class TextureUpdateVisitor : public NodeAndDrawableVisitor
69 TextureUpdateVisitor(const osgDB::FilePathList& pathList);
70 virtual void apply(osg::Node& node);
71 virtual void apply(osg::Drawable& drawable);
72 // Copied from Mathias' earlier SGTextureUpdateVisitor
74 osg::Texture2D* textureReplace(int unit, const osg::StateAttribute* attr);
75 osg::StateSet* cloneStateSet(const osg::StateSet* stateSet);
77 osgDB::FilePathList _pathList;
80 // Create new userdata structs in a copied model.
81 // The BVH trees are shared with the original model, but the velocity fields
82 // should usually be distinct fields for distinct models.
83 class UserDataCopyVisitor : public osg::NodeVisitor
86 UserDataCopyVisitor();
87 virtual void apply(osg::Node& node);
91 * Transform an OSG subgraph by substituting Effects and EffectGeodes
92 * for osg::Geodes with osg::StateSets. This is only guaranteed to
93 * work for models prouced by the .ac loader.
95 * returns a copy if any nodes are changed
97 osg::ref_ptr<osg::Node>
98 instantiateEffects(osg::Node* model,
99 PropertyList& effectProps,
100 const osgDB::ReaderWriter::Options* options);
103 * Transform an OSG subgraph by substituting the Effects and
104 * EffectGeodes for osg::Geodes with osg::StateSets, inheriting from
105 * the default model effect. This is only guaranteed to work for
106 * models prouced by the .ac loader.
108 * returns a copy if any nodes are changed
111 inline osg::ref_ptr<osg::Node>
112 instantiateEffects(osg::Node* model,
113 const osgDB::ReaderWriter::Options* options)
115 PropertyList effectProps;
116 return instantiateEffects(model, effectProps, options);
119 #endif // __MODEL_HXX