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>
28 class SGReaderWriterXMLOptions;
32 SGLoadTexture2D(bool staticTexture, const std::string& path,
33 const osgDB::ReaderWriter::Options* options = 0,
34 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1);
36 inline osg::Texture2D*
37 SGLoadTexture2D(const std::string& path,
38 const osgDB::ReaderWriter::Options* options = 0,
39 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1)
41 return SGLoadTexture2D(true, path, options, wrapu, wrapv, mipmaplevels);
44 inline osg::Texture2D*
45 SGLoadTexture2D(const SGPath& path,
46 const osgDB::ReaderWriter::Options* options = 0,
47 bool wrapu = true, bool wrapv = true,
48 int mipmaplevels = -1)
50 return SGLoadTexture2D(true, path.str(), options, wrapu, wrapv,
54 inline osg::Texture2D*
55 SGLoadTexture2D(bool staticTexture, const SGPath& path,
56 const osgDB::ReaderWriter::Options* options = 0,
57 bool wrapu = true, bool wrapv = true,
58 int mipmaplevels = -1)
60 return SGLoadTexture2D(staticTexture, path.str(), options, wrapu, wrapv,
66 osg::Node* copyModel(osg::Node* model);
68 // Change the StateSets of a model to hold different textures based on
71 class TextureUpdateVisitor : public NodeAndDrawableVisitor
74 TextureUpdateVisitor(const osgDB::FilePathList& pathList);
75 virtual void apply(osg::Node& node);
76 virtual void apply(osg::Drawable& drawable);
77 // Copied from Mathias' earlier SGTextureUpdateVisitor
79 osg::Texture2D* textureReplace(int unit, const osg::StateAttribute* attr);
80 osg::StateSet* cloneStateSet(const osg::StateSet* stateSet);
82 osgDB::FilePathList _pathList;
85 // Create new userdata structs in a copied model.
86 // The BVH trees are shared with the original model, but the velocity fields
87 // should usually be distinct fields for distinct models.
88 class UserDataCopyVisitor : public osg::NodeVisitor
91 UserDataCopyVisitor();
92 virtual void apply(osg::Node& node);
96 * Transform an OSG subgraph by substituting Effects and EffectGeodes
97 * for osg::Geodes with osg::StateSets. This is only guaranteed to
98 * work for models prouced by the .ac loader.
100 * returns a copy if any nodes are changed
102 osg::ref_ptr<osg::Node>
103 instantiateEffects(osg::Node* model,
104 PropertyList& effectProps,
105 const SGReaderWriterXMLOptions* options);
108 * Transform an OSG subgraph by substituting the Effects and
109 * EffectGeodes for osg::Geodes with osg::StateSets, inheriting from
110 * the default model effect. This is only guaranteed to work for
111 * models prouced by the .ac loader.
113 * returns a copy if any nodes are changed
116 inline osg::ref_ptr<osg::Node>
117 instantiateEffects(osg::Node* model,
118 const SGReaderWriterXMLOptions* options)
120 PropertyList effectProps;
121 return instantiateEffects(model, effectProps, options);
124 #endif // __MODEL_HXX