]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/model.hxx
db7f663806d48a006f21aba6d4167cb922c7b159
[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 SG_USING_STD(vector);
19 SG_USING_STD(set);
20
21 #include <osg/Node>
22 #include <osg/Texture2D>
23 #include <osgDB/ReaderWriter>
24
25 #include <simgear/misc/sg_path.hxx>
26 #include <simgear/props/props.hxx>
27
28
29 // Has anyone done anything *really* stupid, like making min and max macros?
30 #ifdef min
31 #undef min
32 #endif
33 #ifdef max
34 #undef max
35 #endif
36
37
38 /**
39  * Abstract class for adding data to the scene graph.  modelLoaded() is
40  * called by sgLoad3DModel() after the model was loaded, and the destructor
41  * when the branch is removed from the graph.
42  */
43 class SGModelData : public osg::Referenced {
44 public:
45     virtual ~SGModelData() {}
46     virtual void modelLoaded( const string& path, SGPropertyNode *prop,
47                               osg::Node*branch) = 0;
48 };
49
50
51 /**
52  * Load a 3D model with or without XML wrapper.  Note, this version
53  * Does not know about or load the panel/cockpit information.  Use the
54  * "model_panel.hxx" version if you want to load an aircraft
55  * (i.e. ownship) with a panel.
56  *
57  * If the path ends in ".xml", then it will be used as a property-
58  * list wrapper to add animations to the model.
59  *
60  * Subsystems should not normally invoke this function directly;
61  * instead, they should use the FGModelLoader declared in loader.hxx.
62  */
63 osg::Node*
64 sgLoad3DModel( const string& fg_root, const string &path,
65                SGPropertyNode *prop_root, double sim_time_sec,
66                osg::Node *(*load_panel)(SGPropertyNode *) = 0,
67                SGModelData *data = 0,
68                const SGPath& texturePath = SGPath() );
69
70
71 /**
72  * Make the animation
73  */
74 void
75 sgMakeAnimation( osg::Node* model,
76                  const char * name,
77                  vector<SGPropertyNode_ptr> &name_nodes,
78                  SGPropertyNode *prop_root,
79                  SGPropertyNode_ptr node,
80                  double sim_time_sec,
81                  SGPath &texture_path,
82                  set<osg::Node*> &ignore_branches );
83
84 osg::Texture2D*
85 SGLoadTexture2D(bool staticTexture, const std::string& path,
86                 const osgDB::ReaderWriter::Options* options = 0,
87                 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1);
88
89 inline osg::Texture2D*
90 SGLoadTexture2D(const std::string& path,
91                 const osgDB::ReaderWriter::Options* options = 0,
92                 bool wrapu = true, bool wrapv = true, int mipmaplevels = -1)
93 {
94     return SGLoadTexture2D(true, path, options, wrapu, wrapv, mipmaplevels);
95 }
96
97 inline osg::Texture2D*
98 SGLoadTexture2D(const SGPath& path,
99                 const osgDB::ReaderWriter::Options* options = 0,
100                 bool wrapu = true, bool wrapv = true,
101                 int mipmaplevels = -1)
102 {
103     return SGLoadTexture2D(true, path.str(), options, wrapu, wrapv,
104                            mipmaplevels);
105 }
106
107 inline osg::Texture2D*
108 SGLoadTexture2D(bool staticTexture, const SGPath& path,
109                 const osgDB::ReaderWriter::Options* options = 0,
110                 bool wrapu = true, bool wrapv = true,
111                 int mipmaplevels = -1)
112 {
113     return SGLoadTexture2D(staticTexture, path.str(), options, wrapu, wrapv,
114                            mipmaplevels);
115 }
116
117 #endif // __MODEL_HXX