osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 #include <osgEarth/ModelSource> 00020 #include <osg/Notify> 00021 #include <osgDB/ReadFile> 00022 #include <OpenThreads/ScopedLock> 00023 00024 using namespace osgEarth; 00025 using namespace OpenThreads; 00026 00027 /****************************************************************/ 00028 00029 void 00030 ModelSourceOptions::fromConfig( const Config& conf ) 00031 { 00032 conf.getIfSet<float>( "min_range", _minRange ); 00033 conf.getIfSet<float>( "max_range", _maxRange ); 00034 conf.getIfSet<int>( "render_order", _renderOrder ); 00035 conf.getIfSet<bool>( "depth_test_enabled", _depthTestEnabled ); 00036 } 00037 00038 void 00039 ModelSourceOptions::mergeConfig( const Config& conf ) 00040 { 00041 DriverConfigOptions::mergeConfig( conf ); 00042 fromConfig( conf ); 00043 } 00044 00045 Config 00046 ModelSourceOptions::getConfig() const 00047 { 00048 Config conf = DriverConfigOptions::getConfig(); 00049 conf.updateIfSet( "min_range", _minRange ); 00050 conf.updateIfSet( "max_range", _maxRange ); 00051 conf.updateIfSet( "render_order", _renderOrder ); 00052 conf.updateIfSet( "depth_test_enabled", _depthTestEnabled ); 00053 return conf; 00054 } 00055 00056 //------------------------------------------------------------------------ 00057 00058 ModelSource::ModelSource( const ModelSourceOptions& options ) : 00059 _options( options ) 00060 { 00061 //TODO: is this really necessary? 00062 this->setThreadSafeRefUnref( true ); 00063 } 00064 00065 //------------------------------------------------------------------------ 00066 00067 #undef LC 00068 #define LC "[ModelSourceFactory] " 00069 #define MODEL_SOURCE_OPTIONS_TAG "__osgEarth::ModelSourceOptions" 00070 00071 ModelSource* 00072 ModelSourceFactory::create( const ModelSourceOptions& options ) 00073 { 00074 ModelSource* modelSource = 0L; 00075 00076 if ( !options.getDriver().empty() ) 00077 { 00078 std::string driverExt = std::string(".osgearth_model_") + options.getDriver(); 00079 00080 osg::ref_ptr<osgDB::ReaderWriter::Options> rwopts = new osgDB::ReaderWriter::Options(); 00081 rwopts->setPluginData( MODEL_SOURCE_OPTIONS_TAG, (void*)&options ); 00082 00083 modelSource = dynamic_cast<ModelSource*>( osgDB::readObjectFile( driverExt, rwopts.get() ) ); 00084 if ( modelSource ) 00085 { 00086 //modelSource->setName( options.getName() ); 00087 OE_INFO << "Loaded ModelSource driver \"" << options.getDriver() << "\" OK" << std::endl; 00088 } 00089 else 00090 { 00091 OE_WARN << "FAIL, unable to load model source driver for \"" << options.getDriver() << "\"" << std::endl; 00092 } 00093 } 00094 else 00095 { 00096 OE_WARN << LC << "FAIL, illegal null driver specification" << std::endl; 00097 } 00098 00099 return modelSource; 00100 } 00101 00102 //------------------------------------------------------------------------ 00103 00104 const ModelSourceOptions& 00105 ModelSourceDriver::getModelSourceOptions( const osgDB::ReaderWriter::Options* options ) const 00106 { 00107 return *static_cast<const ModelSourceOptions*>( options->getPluginData( MODEL_SOURCE_OPTIONS_TAG ) ); 00108 }