2
* This library is open source and may be redistributed and/or modified under
3
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or (at
4
* your option) any later version. The full license is in the LICENSE file
5
* included with this distribution, and on the openscenegraph.org website.
7
* This library is distributed in the hope that it will be useful, but
8
* WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* OpenSceneGraph Public License for more details.
14
// Copyright(c) 2008 Skew Matrix Software LLC.
18
#include <osg/ProxyNode>
20
#include <osgDB/FileNameUtils>
21
#include <osgDB/FileUtils>
22
#include <osgDB/Registry>
23
#include <osgDB/ReadFile>
25
#include "ExportOptions.h"
35
/** @name Valid Option Strings
36
* This plugin supports the following \c Option string values.
40
* Specifies the version of the output OpenFlight file. Supported values
41
* include 15.7, 15.8, and 16.1. Default is 16.1. Example:
44
std::string ExportOptions::_versionOption( "version" );
46
* Specifies the contents of the \c Units field of the OpenFliht header record.
47
* Valid values include INCHES, FEET, METERS, KILOMETERS, and NATICAL_MILES.
48
* Default is METERS. Example: "units=METERS".
50
std::string ExportOptions::_unitsOption( "units" );
51
/** Value: "validate".
52
* If present in the Options string, the plugin does not write an OpenFlight file.
53
* Instead, it returns an indication of the scene graph's suitability for
56
std::string ExportOptions::_validateOption( "validate" );
58
* Specifies the directory to use for creation of temporary files. If not
59
* specified, the directory is taken from the file name. If the file doesn't
60
* contain a path, the current working directory is used. Applications should
61
* set this to the name of their app-specific temp directory. If the path
62
* contains spaces, use double quotes to ensure correct parsing. Examples:
64
* "tempDir=\"C:\\My Temp Dir\"".
66
std::string ExportOptions::_tempDirOption( "tempDir" );
67
/** Value: "lighting".
68
* Specifies a default enable/disable state for lighting, for Nodes in the
69
* exported scene graph that don't set it explicitly. By default, the
70
* exporter assumes lighting is enabled (GL_LIGHTING ON). Set this to
71
* either ON or OFF. Example:
74
std::string ExportOptions::_lightingOption( "lighting" );
75
/** Value: "stripTextureFilePath".
76
* If present in the Options string, the exporter strips the path from
77
* texture file names, and writes only the texure file name to the FLT
78
* Texture Palette. By default, the exporter doesn't strip the path,
79
* and the name written to the Texture Palette is taken directly from
80
* the osg::Image object referenced by the osg::Texture2D StateAttribute.
82
std::string ExportOptions::_stripTextureFilePathOption( "stripTextureFilePath" );
86
using namespace osgDB;
89
const int ExportOptions::VERSION_15_7( 1570 );
90
const int ExportOptions::VERSION_15_8( 1580 );
91
const int ExportOptions::VERSION_16_1( 1610 );
95
ExportOptions::ExportOptions()
96
: _version( VERSION_16_1 ),
99
_lightingDefault( true ),
100
_stripTextureFilePath( false )
104
ExportOptions::ExportOptions( const osgDB::ReaderWriter::Options* opt )
105
: _version( VERSION_16_1 ),
108
_lightingDefault( true )
112
const ExportOptions* fltOpt = dynamic_cast<const ExportOptions*>( opt );
115
_version = fltOpt->_version;
116
_units = fltOpt->_units;
117
_validate = fltOpt->_validate;
118
_tempDir = fltOpt->_tempDir;
119
_lightingDefault = fltOpt->_lightingDefault;
121
setOptionString( opt->getOptionString() );
126
ExportOptions::parseOptionsString()
128
// Parse out the option string and store values directly in
129
// ExportOptions member variables.
131
const std::string& str = getOptionString();
135
std::string::size_type pos( 0 );
136
while (pos != str.npos)
138
// Skip leading spaces.
139
while ( (pos < str.length()) &&
143
// Get the next token
144
std::string::size_type count = str.substr( pos ).find_first_of( " =" );
145
std::string token = str.substr( pos, count );
146
if (count == str.npos)
151
// See if it's a Boolen/toggle
152
if ( token == _validateOption )
154
osg::notify( osg::INFO ) << "fltexp: Found: " << token << std::endl;
155
setValidateOnly( true );
158
if ( token == _stripTextureFilePathOption )
160
osg::notify( osg::INFO ) << "fltexp: Found: " << token << std::endl;
161
setStripTextureFilePath( true );
165
// Not a Boolean/toggle. Must have a value.
166
// Get the value of the token, which could be double-quoted.
167
if( str[pos] == '"' )
170
count = str.substr( pos ).find_first_of( '"' );
173
count = str.substr( pos ).find_first_of( ' ' );
174
std::string value = str.substr( pos, count );
175
if (count == str.npos)
180
if (token == _versionOption)
182
osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
183
int version( VERSION_16_1 );
184
if( value == std::string( "15.7" ) )
185
version = VERSION_15_7;
186
else if( value == std::string( "15.8" ) )
187
version = VERSION_15_8;
188
else if( value != std::string( "16.1" ) )
189
osg::notify( osg::WARN ) << "fltexp: Unsupported version: " << value << ". Defaulting to 16.1." << std::endl;
190
setFlightFileVersionNumber( version );
192
else if (token == _unitsOption)
194
osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
195
FlightUnits units( METERS );
196
if( value == std::string( "KILOMETERS" ) )
198
else if( value == std::string( "FEET" ) )
200
else if( value == std::string( "INCHES" ) )
202
else if( value == std::string( "NAUTICAL_MILES" ) )
203
units = NAUTICAL_MILES;
204
else if( value != std::string( "METERS" ) )
205
osg::notify( osg::WARN ) << "fltexp: Unsupported units: " << value << ". Defaulting to METERS." << std::endl;
206
setFlightUnits( units );
208
else if (token == _tempDirOption)
210
osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
213
else if (token == _lightingOption)
215
osg::notify( osg::INFO ) << "fltexp: Token: " << token << ", Value: " << value << std::endl;
216
bool lighting( true );
217
if (value == std::string( "OFF" ) )
219
else if (value != std::string( "ON" ) )
220
osg::notify( osg::WARN ) << "fltexp: Unsupported lighting value: " << value << ". Defaulting to ON." << std::endl;
221
setLightingDefault( lighting );
224
osg::notify( osg::WARN ) << "fltexp: Bogus OptionString: " << token << std::endl;