]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/modellib.hxx
simgear/scene/sky/sky.cxx: Include sg_inlines.h with simgear/ prefix as all other...
[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 simgear {
36
37 class SGModelData; // defined below
38
39 /**
40  * Class for loading and managing models with XML wrappers.
41  */
42 class SGModelLib
43 {
44 public:
45     typedef osg::Node *(*panel_func)(SGPropertyNode *);
46
47     static void init(const std::string &root_dir);
48
49     static void setPropRoot(SGPropertyNode* root);
50     
51     static void setPanelFunc(panel_func pf);
52     
53     // Load a 3D model (any format)
54     // data->modelLoaded() will be called after the model is loaded
55     static osg::Node* loadModel(const std::string &path,
56                                 SGPropertyNode *prop_root = NULL,
57                                 SGModelData *data=0, bool load2DPanels=false);
58
59     // Load a 3D model (any format) through the DatabasePager.
60     // Most models should be loaded using this function!
61     // This function will initially return an SGPagedLOD node.
62     // data->modelLoaded() will be called after the model is loaded and
63     // connected to the scene graph. See AIModelData on how to use this.
64     // NOTE: AIModelData uses observer_ptr to avoid circular references.
65     static osg::Node* loadPagedModel(const std::string &path,
66                                      SGPropertyNode *prop_root = NULL,
67                                      SGModelData *data=0);
68
69     static std::string findDataFile(const std::string& file, 
70       const osgDB::ReaderWriter::Options* opts = NULL,
71       SGPath currentDir = SGPath()); 
72 protected:
73     SGModelLib();
74     ~SGModelLib ();
75     
76 private:
77   static SGPropertyNode_ptr static_propRoot;
78   static panel_func static_panelFunc;
79 };
80
81
82 /**
83  * Abstract class for adding data to the scene graph.  modelLoaded() is
84  * called after the model was loaded, and the destructor when the branch
85  * is removed from the scene graph.
86  */
87 class SGModelData : public osg::Referenced {
88 public:
89     virtual ~SGModelData() {}
90     virtual void modelLoaded(const std::string& path, SGPropertyNode *prop,
91                              osg::Node* branch) = 0;
92 };
93
94 }
95
96 #endif // _SG_MODEL_LIB_HXX