2
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3
* Copyright 2008-2010 Pelican Mapping
6
* osgEarth is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>
20
#ifndef OSGEARTH_MODEL_LAYER_H
21
#define OSGEARTH_MODEL_LAYER_H 1
23
#include <osgEarth/Common>
24
#include <osgEarth/Layer>
25
#include <osgEarth/Config>
26
#include <osgEarth/ModelSource>
35
* Configuration options for a ModelLayer.
37
class OSGEARTH_EXPORT ModelLayerOptions : public ConfigOptions
40
ModelLayerOptions( const ConfigOptions& options =ConfigOptions() );
42
ModelLayerOptions( const std::string& name, const ModelSourceOptions& driverOptions =ModelSourceOptions() );
45
* The readable name of the layer.
47
optional<std::string>& name() { return _name; }
48
const optional<std::string>& name() const { return _name; }
51
* Options for the underlying model source driver.
53
optional<ModelSourceOptions>& driver() { return _driver; }
54
const optional<ModelSourceOptions>& driver() const { return _driver; }
57
* Whether to enable OpenGL lighting on the model node.
59
optional<bool>& lightingEnabled() { return _lighting; }
60
const optional<bool>& lightingEnabled() const { return _lighting; }
63
* Whether this layer will be drawn.
65
optional<bool>& enabled() { return _enabled; }
66
const optional<bool>& enabled() const { return _enabled; }
69
* Whether to drape the model geometry over the terrain as a projected overlay.
72
optional<bool>& overlay() { return _overlay; }
73
const optional<bool>& overlay() const { return _overlay; }
76
virtual Config getConfig() const;
77
virtual void mergeConfig( const Config& conf );
80
void fromConfig( const Config& conf );
83
optional<std::string> _name;
84
optional<bool> _overlay;
85
optional<ModelSourceOptions> _driver;
86
optional<bool> _enabled;
87
optional<bool> _lighting;
91
* Callback for receiving notification of property changes on a ModelLayer.
93
struct ModelLayerCallback : public osg::Referenced
95
virtual void onOverlayChanged( class ModelLayer* layer ) { }
98
typedef void (ModelLayerCallback::*ModelLayerCallbackMethodPtr)(ModelLayer* layer);
100
typedef std::list< osg::ref_ptr<ModelLayerCallback> > ModelLayerCallbackList;
103
class OSGEARTH_EXPORT ModelLayer : public Layer
107
* Constructs a new model layer.
109
ModelLayer( const ModelLayerOptions& options );
112
* Constructs a new model layer with a user-provided driver options.
114
ModelLayer( const std::string& name, const ModelSourceOptions& options );
117
* Constructs a new model layer with a user-provided model source.
119
ModelLayer(const ModelLayerOptions& options, ModelSource* source );
122
* Constructs a new model layer with a user provided name and an existing node
124
ModelLayer(const std::string& name, osg::Node* node);
128
* Gets the name of this model layer
130
const std::string& getName() const { return _options.name().value(); }
133
* Gets the initialization options for this layer.
135
const ModelLayerOptions& getModelLayerOptions() const { return _options; }
138
* Gets the reference URI (for resolving relative paths)
140
const std::string& getReferenceURI() const { return _referenceURI; }
143
* Access the underlying model source.
145
ModelSource* getModelSource() const { return _modelSource.get(); }
149
osg::Node* getOrCreateNode( ProgressCallback* progress =0L );
151
public: // properties
153
/** Whether this layer is rendered. */
154
bool getEnabled() const;
155
void setEnabled(bool enabled);
157
/** Whether this layer is drawn as normal geometry or as a draped overlay. */
158
bool getOverlay() const;
159
void setOverlay( bool overlay );
161
// whether to apply lighting to the model layer's root node
162
void setLightingEnabled( bool value );
163
const optional<bool>& lightingEnabled() const { return _enabled; }
167
/** Adds a property notification callback to this layer */
168
void addCallback( ModelLayerCallback* cb );
170
/** Removes a property notification callback from this layer */
171
void removeCallback( ModelLayerCallback* cb );
176
void initialize( const std::string& referenceURI, const Map* map );
179
std::string _referenceURI;
180
osg::ref_ptr<ModelSource> _modelSource;
181
const ModelLayerOptions _options;
183
osg::ref_ptr< osg::Node > _node;
185
optional<bool> _enabled;
186
optional<bool> _lighting;
187
optional<bool> _overlay;
189
Revision _modelSourceRev;
191
ModelLayerCallbackList _callbacks;
192
virtual void fireCallback( ModelLayerCallbackMethodPtr method );
196
typedef std::vector< osg::ref_ptr<ModelLayer> > ModelLayerVector;
199
#endif // OSGEARTH_MODEL_LAYER_H