1 // Copyright (C) 2008 Till Busch buti@bux.at
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.
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.
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.
18 #ifndef _SG_MODEL_LIB_HXX
19 #define _SG_MODEL_LIB_HXX 1
22 # error This library requires C++
25 #include <simgear/compiler.h> // for SG_USING_STD
30 #include <osgDB/ReaderWriter>
32 #include <simgear/props/props.hxx>
33 #include <simgear/misc/sg_path.hxx>
37 class SGModelData; // defined below
40 * Class for loading and managing models with XML wrappers.
45 typedef osg::Node *(*panel_func)(SGPropertyNode *);
47 typedef SGPath (*resolve_func)(const std::string& path);
49 static void init(const std::string &root_dir);
51 static void setPropRoot(SGPropertyNode* root);
53 static void setPanelFunc(panel_func pf);
55 static void setResolveFunc(resolve_func rf);
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);
63 // Load a 3D model (any format) through the DatabasePager.
64 // Most models should be loaded using this function!
65 // This function will initially return an SGPagedLOD node.
66 // data->modelLoaded() will be called after the model is loaded and
67 // connected to the scene graph. See AIModelData on how to use this.
68 // NOTE: AIModelData uses observer_ptr to avoid circular references.
69 static osg::Node* loadPagedModel(const std::string &path,
70 SGPropertyNode *prop_root = NULL,
73 static std::string findDataFile(const std::string& file,
74 const osgDB::ReaderWriter::Options* opts = NULL,
75 SGPath currentDir = SGPath());
81 static SGPropertyNode_ptr static_propRoot;
82 static panel_func static_panelFunc;
83 static resolve_func static_resolver;
88 * Abstract class for adding data to the scene graph. modelLoaded() is
89 * called after the model was loaded, and the destructor when the branch
90 * is removed from the scene graph.
92 class SGModelData : public osg::Referenced {
94 virtual ~SGModelData() {}
95 virtual void modelLoaded(const std::string& path, SGPropertyNode *prop,
96 osg::Node* branch) = 0;
101 #endif // _SG_MODEL_LIB_HXX