osgEarth 2.1.1
|
00001 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00002 * Copyright 2008-2009 Pelican Ventures, Inc. 00003 * http://osgearth.org 00004 * 00005 * osgEarth is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/> 00017 */ 00018 #include <osg/Notify> 00019 00020 #include <osgDB/FileNameUtils> 00021 #include <osgDB/FileUtils> 00022 #include <osgDB/Registry> 00023 #include <osgEarth/Profile> 00024 00025 #include "PatchGroup" 00026 #include "PatchSet" 00027 #include "SeamlessEngineNode" 00028 00029 #include <string> 00030 #include <iostream> 00031 00032 namespace seamless 00033 { 00034 using namespace osg; 00035 using namespace osgEarth; 00036 00037 class SeamlessPlugin : public osgDB::ReaderWriter 00038 { 00039 public: 00040 SeamlessPlugin() 00041 { 00042 supportsExtension("osgearth_engine_seamless", 00043 "osgEarth seamless engine plugin"); 00044 supportsExtension("osgearth_engine_seamless_patch", 00045 "seamless engine patch pseudo loader"); 00046 } 00047 00048 virtual const char* className() 00049 { 00050 return "OSG Earth Seamless Engine"; 00051 } 00052 00053 virtual ReadResult readObject(const std::string& uri, const Options* options) const 00054 { 00055 if ("osgearth_engine_seamless" == osgDB::getFileExtension(uri)) 00056 { 00057 if ("earth" 00058 == osgDB::getNameLessExtension(osgDB::getFileExtension(uri))) 00059 return readNode(uri, options); 00060 else 00061 return ReadResult(new SeamlessEngineNode); 00062 } 00063 else 00064 return ReadResult::FILE_NOT_HANDLED; 00065 } 00066 00067 virtual ReadResult 00068 readNode(const std::string& uri, const Options* options) const 00069 { 00070 if ("osgearth_engine_seamless_patch" == osgDB::getFileExtension(uri)) 00071 { 00072 Vec2d lowerLeft(0.0, 1.0); 00073 Vec2d upperRight(1.0, 1.0); 00074 const PatchOptions* poptions 00075 = dynamic_cast<const PatchOptions*>(options); 00076 if (!poptions) 00077 { 00078 OE_FATAL 00079 << "PatchGroup reader: Options object is not PatchOptions\n"; 00080 return osgDB::ReaderWriter::ReadResult::ERROR_IN_READING_FILE; 00081 } 00082 PatchSet* pset = poptions->getPatchSet(); 00083 Group* result = new Group; 00084 for (int i = 0; i < 4; ++i) 00085 result->addChild(pset->createChild(poptions, i)); 00086 return result; 00087 00088 } 00089 else 00090 { 00091 // The pseudo-loader form for engines isn't supported anymore. 00092 return ReadResult::FILE_NOT_FOUND; 00093 } 00094 } 00095 }; 00096 00097 REGISTER_OSGPLUGIN(osgearth_engine_seamless, SeamlessPlugin) 00098 }