]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/modellib.hxx
model paging patch from Till Busch
[simgear.git] / simgear / scene / model / modellib.hxx
1 // Copyright (C) 2008 Till Busch buti@bux.at
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 //
17
18 #ifndef _SG_MODEL_LIB_HXX
19 #define _SG_MODEL_LIB_HXX 1
20
21 #ifndef __cplusplus
22 # error This library requires C++
23 #endif
24
25 #include <simgear/compiler.h>   // for SG_USING_STD
26
27 #include STL_STRING
28
29 #include <osg/Node>
30
31 #include <simgear/props/props.hxx>
32
33 SG_USING_STD(map);
34 SG_USING_STD(string);
35
36 namespace simgear {
37
38 class SGModelData; // defined below
39
40 /**
41  * Class for loading and managing models with XML wrappers.
42  */
43 class SGModelLib
44 {
45 public:
46     typedef osg::Node *(*panel_func)(SGPropertyNode *);
47
48     static void init(const string &root_dir);
49
50     // Load a 3D model (any format)
51     // data->modelLoaded() will be called after the model is loaded
52     static osg::Node* loadModel(const string &path,
53                                 SGPropertyNode *prop_root,
54                                 SGModelData *data=0);
55
56     // Load a 3D model (any format)
57     // with a panel_func to load a panel
58     static osg::Node* loadModel(const string &path,
59                                 SGPropertyNode *prop_root,
60                                 panel_func pf);
61
62     // Load a 3D model (any format) through the DatabasePager.
63     // Most models should be loaded using this function!
64     // This function will initially return an SGPagedLOD node.
65     // data->modelLoaded() will be called after the model is loaded and
66     // connected to the scene graph. See AIModelData on how to use this.
67     // NOTE: AIModelData uses observer_ptr to avoid circular references.
68     static osg::Node* loadPagedModel(const string &path,
69                                      SGPropertyNode *prop_root,
70                                      SGModelData *data=0);
71
72 protected:
73     SGModelLib();
74     ~SGModelLib ();
75 };
76
77
78 /**
79  * Abstract class for adding data to the scene graph.  modelLoaded() is
80  * called after the model was loaded, and the destructor when the branch
81  * is removed from the scene graph.
82  */
83 class SGModelData : public osg::Referenced {
84 public:
85     virtual ~SGModelData() {}
86     virtual void modelLoaded( const string& path, SGPropertyNode *prop,
87                               osg::Node*branch) = 0;
88
89     virtual void setProps(SGPropertyNode *p)
90         { _props = p; }
91
92     SGPropertyNode *getProperties()
93         { return _props; }
94 protected:
95     SGPropertyNode_ptr _props;
96 };
97
98 }
99
100 #endif // _SG_MODEL_LIB_HXX