]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/model.hxx
Effects for models
[simgear.git] / simgear / scene / model / model.hxx
1 // model.hxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifndef __MODEL_HXX
7 #define __MODEL_HXX 1
8
9 #ifndef __cplusplus
10 # error This library requires C++
11 #endif
12
13 #include <simgear/compiler.h>
14
15 #include <vector>
16 #include <set>
17
18 #include <osg/Node>
19 #include <osg/Texture2D>
20 #include <osgDB/ReaderWriter>
21
22 #include <simgear/misc/sg_path.hxx>
23 #include <simgear/props/props.hxx>
24 #include <simgear/scene/util/NodeAndDrawableVisitor.hxx>
25
26 osg::Texture2D*
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);
30
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)
35 {
36     return SGLoadTexture2D(true, path, options, wrapu, wrapv, mipmaplevels);
37 }
38
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)
44 {
45     return SGLoadTexture2D(true, path.str(), options, wrapu, wrapv,
46                            mipmaplevels);
47 }
48
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)
54 {
55     return SGLoadTexture2D(staticTexture, path.str(), options, wrapu, wrapv,
56                            mipmaplevels);
57 }
58
59 namespace simgear
60 {
61 osg::Node* copyModel(osg::Node* model);
62
63 // Change the StateSets of a model to hold different textures based on
64 // a livery path.
65
66 class TextureUpdateVisitor : public NodeAndDrawableVisitor
67 {
68 public:
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
73 protected:
74     osg::Texture2D* textureReplace(int unit, const osg::StateAttribute* attr);
75     osg::StateSet* cloneStateSet(const osg::StateSet* stateSet);
76 private:
77     osgDB::FilePathList _pathList;
78 };
79
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
84 {
85 public:
86     UserDataCopyVisitor();
87     virtual void apply(osg::Node& node);
88 };
89
90 /**
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.
94  *
95  * returns a copy if any nodes are changed
96  */
97 osg::ref_ptr<osg::Node>
98 instantiateEffects(osg::Node* model,
99                    PropertyList& effectProps,
100                    const osgDB::ReaderWriter::Options* options);
101
102 /**
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.
107  *
108  * returns a copy if any nodes are changed
109  */
110
111 inline osg::ref_ptr<osg::Node>
112 instantiateEffects(osg::Node* model,
113                    const osgDB::ReaderWriter::Options* options)
114 {
115     PropertyList effectProps;
116     return instantiateEffects(model, effectProps, options);
117 }
118 }
119 #endif // __MODEL_HXX