]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/modellib.hxx
Make return type from loadPagedModel explicit.
[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 <string>
28
29 #include <osg/Node>
30 #include <osgDB/ReaderWriter>
31
32 #include <simgear/props/props.hxx>
33 #include <simgear/misc/sg_path.hxx>
34
35 namespace osg {
36     class PagedLOD;
37 }
38
39 namespace simgear {
40
41 class SGModelData; // defined below
42
43 /**
44  * Class for loading and managing models with XML wrappers.
45  */
46 class SGModelLib
47 {
48 public:
49     typedef osg::Node *(*panel_func)(SGPropertyNode *);
50
51     static void init(const std::string &root_dir, SGPropertyNode* root);
52
53     static void resetPropertyRoot();
54     
55     static void setPanelFunc(panel_func pf);
56     
57     // Load a 3D model (any format)
58     // data->modelLoaded() will be called after the model is loaded
59     static osg::Node* loadModel(const std::string &path,
60                                 SGPropertyNode *prop_root = NULL,
61                                 SGModelData *data=0, bool load2DPanels=false);
62
63     // Load a 3D model (any format) through the DatabasePager.
64     // This function initially just returns a proxy node that refers to
65     // the model file. Once the viewer steps onto that node the
66     // model will be loaded.
67     static osg::Node* loadDeferredModel(const std::string &path,
68                                         SGPropertyNode *prop_root = NULL,
69                                         SGModelData *data=0);
70     // Load a 3D model (any format) through the DatabasePager.
71     // This function initially just returns a PagedLOD node that refers to
72     // the model file. Once the viewer steps onto that node the
73     // model will be loaded. When the viewer does no longer reference this
74     // node for a long time the node is unloaded again.
75     static osg::PagedLOD* loadPagedModel(const std::string &path,
76                                      SGPropertyNode *prop_root = NULL,
77                                      SGModelData *data=0);
78
79     static std::string findDataFile(const std::string& file, 
80       const osgDB::Options* opts = NULL,
81       SGPath currentDir = SGPath()); 
82 protected:
83     SGModelLib();
84     ~SGModelLib ();
85     
86 private:
87   static SGPropertyNode_ptr static_propRoot;
88   static panel_func static_panelFunc;
89 };
90
91
92 /**
93  * Abstract class for adding data to the scene graph.  modelLoaded() is
94  * called after the model was loaded, and the destructor when the branch
95  * is removed from the scene graph.
96  */
97 class SGModelData : public osg::Referenced {
98 public:
99     virtual ~SGModelData() {}
100     virtual void modelLoaded(const std::string& path, SGPropertyNode *prop,
101                              osg::Node* branch) = 0;
102     virtual SGModelData* clone() const = 0;
103 };
104
105 }
106
107 #endif // _SG_MODEL_LIB_HXX