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