]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/model.hxx
Add preliminary spot light animation
[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 namespace simgear
27 {
28 class SGReaderWriterOptions;
29 }
30
31 osg::Texture2D*
32 SGLoadTexture2D(bool staticTexture, const std::string& path,
33                 const osgDB::Options* options = 0,
34                 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1);
35
36 inline osg::Texture2D*
37 SGLoadTexture2D(const std::string& path,
38                 const osgDB::Options* options = 0,
39                 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1)
40 {
41     return SGLoadTexture2D(true, path, options, wrapu, wrapv, mipmaplevels);
42 }
43
44 inline osg::Texture2D*
45 SGLoadTexture2D(const SGPath& path,
46                 const osgDB::Options* options = 0,
47                 bool wrapu = true, bool wrapv = true,
48                 int mipmaplevels = -1)
49 {
50     return SGLoadTexture2D(true, path.str(), options, wrapu, wrapv,
51                            mipmaplevels);
52 }
53
54 inline osg::Texture2D*
55 SGLoadTexture2D(bool staticTexture, const SGPath& path,
56                 const osgDB::Options* options = 0,
57                 bool wrapu = true, bool wrapv = true,
58                 int mipmaplevels = -1)
59 {
60     return SGLoadTexture2D(staticTexture, path.str(), options, wrapu, wrapv,
61                            mipmaplevels);
62 }
63
64 namespace simgear
65 {
66 osg::Node* copyModel(osg::Node* model);
67
68 // Change the StateSets of a model to hold different textures based on
69 // a livery path.
70
71 class TextureUpdateVisitor : public NodeAndDrawableVisitor
72 {
73 public:
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
78 protected:
79     osg::Texture2D* textureReplace(int unit, const osg::StateAttribute* attr);
80     osg::StateSet* cloneStateSet(const osg::StateSet* stateSet);
81 private:
82     osgDB::FilePathList _pathList;
83 };
84
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
89 {
90 public:
91     UserDataCopyVisitor();
92     virtual void apply(osg::Node& node);
93 };
94
95 /**
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.
99  *
100  * returns a copy if any nodes are changed
101  */
102 osg::ref_ptr<osg::Node>
103 instantiateEffects(osg::Node* model,
104                    PropertyList& effectProps,
105                    const SGReaderWriterOptions* options);
106
107 /**
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.
112  *
113  * returns a copy if any nodes are changed
114  */
115
116 inline osg::ref_ptr<osg::Node>
117 instantiateEffects(osg::Node* model,
118                    const SGReaderWriterOptions* options)
119 {
120     PropertyList effectProps;
121     return instantiateEffects(model, effectProps, options);
122 }
123 }
124 #endif // __MODEL_HXX