From Wang Rui, "Changes:

1. Rewrite the reading/writing exception handlers to work like the ive
plugin exceptions.
2. Write a header writing/checking function in ReaderWriterOSG2.cpp,
which may help decide if the stream is ascii or binary. The
readInputIterator() function will return null pointer if the input
file is nither osgb nor osgt format, which indicates that the old .osg
format could be used here, in case we've merged the two plugins
together.
3. Add a new ForceReadingImage option in the InputStream, which will
allocate an empty image object with the filename if specifed external
image file is missed. It may be useful for format converting in some
cases.
4. Add new osgParticle wrappers, as well as some modification to the
osgParticle headers, for instance, change isEnabled() to getEnabled().
5. Some fixes to the osg serialization wrappers."
This commit is contained in:
Robert Osfield 2010-01-27 17:09:05 +00:00
parent 00c17c6cff
commit 0a9263d50e
19 changed files with 434 additions and 306 deletions

View File

@ -31,11 +31,17 @@
namespace osgDB
{
class InputException
class InputException : public osg::Referenced
{
public:
InputException( const std::string& field, const std::string& err )
: _field(field), _error(err) {}
InputException( const std::vector<std::string>& fields, const std::string& err ) : _error(err)
{
for ( unsigned int i=0; i<fields.size(); ++i )
{
_field += fields[i];
_field += " ";
}
}
const std::string& getField() const { return _field; }
const std::string& getError() const { return _error; }
@ -65,25 +71,25 @@ public:
bool getUseFloatMatrix() const { return _useFloatMatrix; }
// Serialization related functions
InputStream& operator>>( bool& b ) { _in->readBool(b); return *this; }
InputStream& operator>>( char& c ) { _in->readChar(c); return *this; }
InputStream& operator>>( signed char& c ) { _in->readSChar(c); return *this; }
InputStream& operator>>( unsigned char& c ) { _in->readUChar(c); return *this; }
InputStream& operator>>( short& s ) { _in->readShort(s); return *this; }
InputStream& operator>>( unsigned short& s ) { _in->readUShort(s); return *this; }
InputStream& operator>>( int& i ) { _in->readInt(i); return *this; }
InputStream& operator>>( unsigned int& i ) { _in->readUInt(i); return *this; }
InputStream& operator>>( long& l ) { _in->readLong(l); return *this; }
InputStream& operator>>( unsigned long& l ) { _in->readULong(l); return *this; }
InputStream& operator>>( float& f ) { _in->readFloat(f); return *this; }
InputStream& operator>>( double& d ) { _in->readDouble(d); return *this; }
InputStream& operator>>( std::string& s ) { _in->readString(s); return *this; }
InputStream& operator>>( std::istream& (*fn)(std::istream&) ) { _in->readStream(fn); return *this; }
InputStream& operator>>( std::ios_base& (*fn)(std::ios_base&) ) { _in->readBase(fn); return *this; }
InputStream& operator>>( bool& b ) { _in->readBool(b); checkStream(); return *this; }
InputStream& operator>>( char& c ) { _in->readChar(c); checkStream(); return *this; }
InputStream& operator>>( signed char& c ) { _in->readSChar(c); checkStream(); return *this; }
InputStream& operator>>( unsigned char& c ) { _in->readUChar(c); checkStream(); return *this; }
InputStream& operator>>( short& s ) { _in->readShort(s); checkStream(); return *this; }
InputStream& operator>>( unsigned short& s ) { _in->readUShort(s); checkStream(); return *this; }
InputStream& operator>>( int& i ) { _in->readInt(i); checkStream(); return *this; }
InputStream& operator>>( unsigned int& i ) { _in->readUInt(i); checkStream(); return *this; }
InputStream& operator>>( long& l ) { _in->readLong(l); checkStream(); return *this; }
InputStream& operator>>( unsigned long& l ) { _in->readULong(l); checkStream(); return *this; }
InputStream& operator>>( float& f ) { _in->readFloat(f); checkStream(); return *this; }
InputStream& operator>>( double& d ) { _in->readDouble(d); checkStream(); return *this; }
InputStream& operator>>( std::string& s ) { _in->readString(s); checkStream(); return *this; }
InputStream& operator>>( std::istream& (*fn)(std::istream&) ) { _in->readStream(fn); checkStream(); return *this; }
InputStream& operator>>( std::ios_base& (*fn)(std::ios_base&) ) { _in->readBase(fn); checkStream(); return *this; }
InputStream& operator>>( ObjectGLenum& value ) { _in->readGLenum(value); return *this; }
InputStream& operator>>( ObjectProperty& prop ) { _in->readProperty(prop); return *this; }
InputStream& operator>>( ObjectMark& mark ) { _in->readMark(mark); return *this; }
InputStream& operator>>( ObjectGLenum& value ) { _in->readGLenum(value); checkStream(); return *this; }
InputStream& operator>>( ObjectProperty& prop ) { _in->readProperty(prop); checkStream(); return *this; }
InputStream& operator>>( ObjectMark& mark ) { _in->readMark(mark); checkStream(); return *this; }
InputStream& operator>>( osg::Vec2b& v );
InputStream& operator>>( osg::Vec3b& v );
@ -116,9 +122,9 @@ public:
{ ptr = static_cast<T*>(readObject()); return *this; }
// Convenient methods for reading
inline bool matchString( const std::string& str );
inline void advanceToCurrentEndBracket();
inline void readWrappedString( std::string& str );
bool matchString( const std::string& str );
void advanceToCurrentEndBracket();
void readWrappedString( std::string& str );
void readCharArray( char* s, unsigned int size ) { _in->readCharArray(s, size); }
// Global reading functions
@ -134,8 +140,12 @@ public:
void readSchema( std::istream& fin );
void resetSchema();
// Exception handlers
inline void throwException( const std::string& msg );
const InputException* getException() const { return _exception.get(); }
protected:
inline void checkStream() const;
inline void checkStream();
void setWrapperSchema( const std::string& name, const std::string& properties );
template<typename T>
@ -146,68 +156,22 @@ protected:
int _byteSwap;
bool _useFloatMatrix;
std::string _currentField;
InputIterator* _in;
bool _forceReadingImage;
std::vector<std::string> _fields;
osg::ref_ptr<InputIterator> _in;
osg::ref_ptr<InputException> _exception;
};
bool InputStream::matchString( const std::string& str )
void InputStream::throwException( const std::string& msg )
{
if ( !isBinary() )
{
std::string s; *this >> s;
if ( s==str ) return true;
else _in->getStream()->seekg( -(int)(s.length()), std::ios::cur );
}
return false;
_exception = new InputException(_fields, msg);
}
void InputStream::advanceToCurrentEndBracket()
{
if ( isBinary() )
return;
std::string passString;
unsigned int blocks = 0;
while ( !_in->getStream()->eof() )
{
passString.clear();
*this >> passString;
if ( passString=="}" )
{
if ( blocks<=0 ) return;
else blocks--;
}
else if ( passString=="{" )
blocks++;
}
}
void InputStream::readWrappedString( std::string& str )
{
*this >> str;
if ( !isBinary() )
{
if ( str[0]=='\"' )
{
if ( str.size()==1 || (*str.rbegin())!='\"' )
{
char ch;
do
{
_in->getStream()->get( ch ); checkStream();
str.append( 1, ch );
} while ( ch!='\"' );
}
str = str.substr(1, str.size()-2);
}
}
}
void InputStream::checkStream() const
void InputStream::checkStream()
{
_in->checkStream();
if ( _in->isFailed() )
throw InputException(_currentField, "InputStream: Failed to read from stream.");
throwException( "InputStream: Failed to read from stream." );
}
}

View File

@ -30,11 +30,17 @@
namespace osgDB
{
class OutputException
class OutputException : public osg::Referenced
{
public:
OutputException( const std::string& field, const std::string& err )
: _field(field), _error(err) {}
OutputException( const std::vector<std::string>& fields, const std::string& err ) : _error(err)
{
for ( unsigned int i=0; i<fields.size(); ++i )
{
_field += fields[i];
_field += " ";
}
}
const std::string& getField() const { return _field; }
const std::string& getError() const { return _error; }
@ -70,6 +76,7 @@ public:
virtual ~OutputStream();
bool isBinary() const { return _out->isBinary(); }
const std::string& getSchemaName() const { return _schemaName; }
void setWriteImageHint( WriteImageHint hint ) { _writeImageHint = hint; }
WriteImageHint getWriteImageHint() const { return _writeImageHint; }
@ -125,7 +132,7 @@ public:
{ writeObject(ptr.get()); return *this; }
// Convenient methods for writing
inline void writeWrappedString( const std::string& str );
void writeWrappedString( const std::string& str );
void writeCharArray( const char* s, unsigned int size ) { _out->writeCharArray(s, size); }
// Global writing functions
@ -140,6 +147,10 @@ public:
// Schema handlers
void writeSchema( std::ostream& fout );
// Exception handlers
inline void throwException( const std::string& msg );
const OutputException* getException() const { return _exception.get(); }
protected:
template<typename T>
void writeArrayImplementation( const T*, int writeSize, unsigned int numInRow=1 );
@ -151,21 +162,17 @@ protected:
ObjectMap _objectMap;
WriteImageHint _writeImageHint;
std::string _currentField;
std::vector<std::string> _fields;
std::string _schemaName;
std::string _compressorName;
std::stringstream _compressSource;
OutputIterator* _out;
osg::ref_ptr<OutputIterator> _out;
osg::ref_ptr<OutputException> _exception;
};
void OutputStream::writeWrappedString( const std::string& str )
void OutputStream::throwException( const std::string& msg )
{
if ( !isBinary() )
{
std::string wrappedStr = std::string("\"") + str + std::string("\"");
*this << wrappedStr;
}
else
*this << str;
_exception = new OutputException(_fields, msg);
}
}

View File

@ -137,18 +137,32 @@ public:
virtual bool read( InputStream& is, osg::Object& obj )
{
C& object = OBJECT_CAST<C&>(obj);
if ( !is.isBinary() && !is.matchString(_name) )
return true;
if ( is.isBinary() )
{
bool ok = false; is >> ok;
if ( !ok ) return true;
}
else
{
if ( !is.matchString(_name) )
return true;
}
return (*_reader)(is, object);
}
virtual bool write( OutputStream& os, const osg::Object& obj )
{
const C& object = OBJECT_CAST<const C&>(obj);
if ( !os.isBinary() )
bool ok = (*_checker)(object);
if ( os.isBinary() )
{
if ( !(*_checker)(object) ) return true;
os << _name;
os << ok;
if ( !ok ) return true;
}
else
{
if ( !ok ) return true;
os << PROPERTY(_name.c_str());
}
return (*_writer)(os, object);
}
@ -158,6 +172,8 @@ public:
protected:
std::string _name;
Checker _checker;
public:
Reader _reader;
Writer _writer;
};
@ -219,7 +235,7 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name;
os << PROPERTY((ParentType::_name).c_str());
if ( _useHex ) os << std::hex;
os << (object.*_getter)();
if ( _useHex ) os << std::dec;
@ -228,9 +244,11 @@ public:
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
protected:
bool _useHex;
};
@ -274,12 +292,12 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name << (object.*_getter)() << std::endl;
os << PROPERTY((ParentType::_name).c_str()) << (object.*_getter)() << std::endl;
}
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
};
@ -323,7 +341,7 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name << (object.*_getter)() << std::endl;
os << PROPERTY((ParentType::_name).c_str()) << (object.*_getter)() << std::endl;
}
return true;
}
@ -343,6 +361,7 @@ protected:
}
}
public:
Getter _getter;
Setter _setter;
};
@ -385,12 +404,12 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name << GLENUM((object.*_getter)()) << std::endl;
os << PROPERTY((ParentType::_name).c_str()) << GLENUM((object.*_getter)()) << std::endl;
}
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
};
@ -435,14 +454,14 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name;
os << PROPERTY((ParentType::_name).c_str());
os.writeWrappedString( (object.*_getter)() );
os << std::endl;
}
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
};
@ -498,7 +517,7 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name << hasObject;
os << PROPERTY((ParentType::_name).c_str()) << hasObject;
if ( hasObject )
{
os << BEGIN_BRACKET << std::endl;
@ -510,7 +529,7 @@ public:
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
};
@ -566,7 +585,7 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name << hasObject;
os << PROPERTY((ParentType::_name).c_str()) << hasObject;
if ( hasObject )
{
os << BEGIN_BRACKET << std::endl;
@ -578,7 +597,7 @@ public:
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
};
@ -631,14 +650,16 @@ public:
}
else if ( ParentType::_defaultValue!=(object.*_getter)() )
{
os << ParentType::_name << getString((object.*_getter)()) << std::endl;
os << PROPERTY((ParentType::_name).c_str()) << getString((object.*_getter)()) << std::endl;
}
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
protected:
IntLookup _lookup;
};
@ -706,7 +727,7 @@ public:
}
else if ( size>0 )
{
os << ParentType::_name << size << BEGIN_BRACKET << std::endl;
os << PROPERTY((ParentType::_name).c_str()) << size << BEGIN_BRACKET << std::endl;
for ( ConstIterator itr=list.begin();
itr!=list.end(); ++itr )
{
@ -717,7 +738,7 @@ public:
return true;
}
protected:
public:
Getter _getter;
Setter _setter;
};
@ -845,7 +866,7 @@ protected:
serializer->add(#VALUE, MyClass::VALUE)
#define END_ENUM_SERIALIZER() \
wrapper->addSerializer(serializer.get()); }
wrapper->addSerializer(serializer); }
}

View File

@ -8,7 +8,7 @@
namespace osgDB
{
class OSGDB_EXPORT OutputIterator
class OSGDB_EXPORT OutputIterator : public osg::Referenced
{
public:
OutputIterator() : _out(0) {}
@ -44,7 +44,7 @@ protected:
std::ostream* _out;
};
class OSGDB_EXPORT InputIterator
class OSGDB_EXPORT InputIterator : public osg::Referenced
{
public:
InputIterator() : _in(0), _failed(false) {}
@ -54,7 +54,9 @@ public:
std::istream* getStream() { return _in; }
const std::istream* getStream() const { return _in; }
void checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; }
bool isFailed() const { return _failed; }
virtual bool isBinary() const = 0;
virtual void readBool( bool& b ) = 0;
@ -79,9 +81,6 @@ public:
virtual void readCharArray( char* s, unsigned int size ) = 0;
protected:
void checkStream() const
{ if (_in->rdstate()&_in->failbit) _failed = true; }
std::istream* _in;
mutable bool _failed;
};

View File

@ -58,6 +58,7 @@ namespace osgParticle
inline void setReferenceFrame(ReferenceFrame rf);
/// Get whether this processor is enabled or not.
bool getEnabled() const { return _enabled; }
inline bool isEnabled() const;
/// Set whether this processor is enabled or not.
@ -76,6 +77,7 @@ namespace osgParticle
inline void setEndless(bool type);
/// Check whether this processor is endless.
bool getEndless() const { return _endless; }
inline bool isEndless() const;
/// Set the lifetime of this processor.

View File

@ -123,6 +123,7 @@ namespace osgParticle
inline void setDoublePassRendering(bool v);
/// Return true if the particle system is frozen.
bool getFrozen() const { return _frozen; }
inline bool isFrozen() const;
/** Set or reset the <I>frozen</I> state.

View File

@ -47,7 +47,7 @@ namespace osgParticle
void snow(float intensity);
void setMaximumParticleDensity(float density) { if (_maximumParticleDensity==density) return; _maximumParticleDensity = density; _dirty = true;}
float setMaximumParticleDensity() const { return _maximumParticleDensity; }
float getMaximumParticleDensity() const { return _maximumParticleDensity; }
void setWind(const osg::Vec3& wind) { _wind = wind; }
const osg::Vec3& getWind() const { return _wind; }

View File

@ -24,8 +24,7 @@ using namespace osgDB;
static std::string s_lastSchema;
InputStream::InputStream( const osgDB::Options* options )
: _byteSwap(0), _useFloatMatrix(false),
_in(0)
: _byteSwap(0), _useFloatMatrix(false), _forceReadingImage(false)
{
if ( !options ) return;
@ -39,6 +38,10 @@ InputStream::InputStream( const osgDB::Options* options )
{
// Omit this
}
else if ( option=="ForceReadingImage" )
{
_forceReadingImage = true;
}
else
{
StringList keyAndValues;
@ -157,6 +160,77 @@ InputStream& InputStream::operator>>( osg::Matrixd& mat )
return *this;
}
bool InputStream::matchString( const std::string& str )
{
if ( !isBinary() )
{
std::string s; *this >> s;
if ( s==str ) return true;
else _in->getStream()->seekg( -(int)(s.length()), std::ios::cur );
}
return false;
}
void InputStream::advanceToCurrentEndBracket()
{
if ( isBinary() )
return;
std::string passString;
unsigned int blocks = 0;
while ( !_in->getStream()->eof() )
{
passString.clear();
*this >> passString;
if ( passString=="}" )
{
if ( blocks<=0 ) return;
else blocks--;
}
else if ( passString=="{" )
blocks++;
}
}
void InputStream::readWrappedString( std::string& str )
{
*this >> str;
if ( !isBinary() )
{
if ( str[0]=='\"' )
{
if ( str.size()==1 || (*str.rbegin())!='\"' )
{
char ch;
do
{
_in->getStream()->get( ch ); checkStream();
if ( ch=='\\' )
{
_in->getStream()->get( ch ); checkStream();
if ( ch=='\"' )
{
str += ch; ch = 0;
}
else if ( ch=='\\' )
{
str += ch;
}
else
{
str += '\\'; str += ch;
}
}
else
str += ch;
} while ( ch!='\"' );
}
str = str.substr(1, str.size()-2);
}
}
}
osg::Array* InputStream::readArray()
{
osg::ref_ptr<osg::Array> array = NULL;
@ -319,9 +393,10 @@ osg::Array* InputStream::readArray()
}
break;
default:
throw InputException(_currentField, "InputStream::readArray(): Unsupported array type.");
throwException( "InputStream::readArray(): Unsupported array type." );
}
if ( getException() ) return NULL;
_arrayMap[id] = array;
return array.release();
}
@ -401,8 +476,10 @@ osg::PrimitiveSet* InputStream::readPrimitiveSet()
}
break;
default:
throw InputException(_currentField, "InputStream::readPrimitiveSet(): Unsupported array type.");
throwException( "InputStream::readPrimitiveSet(): Unsupported array type." );
}
if ( getException() ) return NULL;
return primitive.release();
}
@ -412,6 +489,7 @@ osg::Image* InputStream::readImage()
int writeHint, decision = IMAGE_EXTERNAL;
*this >> PROPERTY("FileName"); readWrappedString(name);
*this >> PROPERTY("WriteHint") >> writeHint >> decision;
if ( getException() ) return NULL;
osg::ref_ptr<osg::Image> image = NULL;
bool readFromExternal = true;
@ -436,7 +514,9 @@ osg::Image* InputStream::readImage()
{
char* data = new char[size];
if ( !data )
throw InputException(_currentField, "InputStream::readImage() Out of memory.");
throwException( "InputStream::readImage() Out of memory." );
if ( getException() ) return NULL;
readCharArray( data, size );
image->setOrigin( (osg::Image::Origin)origin );
image->setImage( s, t, r, internalFormat, pixelFormat, dataType,
@ -463,7 +543,8 @@ osg::Image* InputStream::readImage()
{
char* data = new char[size];
if ( !data )
throw InputException(_currentField, "InputStream::readImage(): Out of memory.");
throwException( "InputStream::readImage(): Out of memory." );
if ( getException() ) return NULL;
readCharArray( data, size );
std::string ext = osgDB::getFileExtension( name );
@ -500,7 +581,10 @@ osg::Image* InputStream::readImage()
}
if ( readFromExternal )
{
image = osgDB::readImageFile( name );
if ( !image && _forceReadingImage ) image = new osg::Image;
}
if ( image.valid() )
{
image->setFileName( name );
@ -516,6 +600,7 @@ osg::Object* InputStream::readObject( osg::Object* existingObj )
std::string className;
unsigned int id = 0;
*this >> className >> BEGIN_BRACKET >> PROPERTY("UniqueID") >> id;
if ( getException() ) return NULL;
IdentifierMap::iterator itr = _identifierMap.find( id );
if ( itr!=_identifierMap.end() )
@ -532,6 +617,8 @@ osg::Object* InputStream::readObject( osg::Object* existingObj )
advanceToCurrentEndBracket();
return NULL;
}
_fields.push_back( className );
osg::ref_ptr<osg::Object> obj = existingObj ? existingObj : wrapper->getProto()->cloneType();
if ( obj.valid() )
{
@ -547,12 +634,16 @@ osg::Object* InputStream::readObject( osg::Object* existingObj )
<< *itr << std::endl;
continue;
}
_fields.push_back( assocWrapper->getName() );
_currentField = assocWrapper->getName();
assocWrapper->read( *this, *obj );
if ( getException() ) return NULL;
_fields.pop_back();
}
}
advanceToCurrentEndBracket();
_fields.pop_back();
return obj.release();
}
@ -575,11 +666,14 @@ void InputStream::readSchema( std::istream& fin )
InputStream::ReadType InputStream::start( InputIterator* inIterator )
{
_fields.clear();
_fields.push_back( "Start" );
ReadType type = READ_UNKNOWN;
_currentField = "Header";
_in = inIterator;
if ( !_in )
throw InputException(_currentField, "InputStream: Null stream specified.");
throwException( "InputStream: Null stream specified." );
if ( getException() ) return type;
// Check OSG header information
unsigned int version = 0;
@ -595,9 +689,6 @@ InputStream::ReadType InputStream::start( InputIterator* inIterator )
}
if ( !isBinary() )
{
DEF_PROPERTY("#Ascii", header); *this >> header;
if ( header._name!="#Ascii" ) return READ_UNKNOWN;
std::string typeString; *this >> typeString;
if ( typeString=="Scene" ) type = READ_SCENE;
else if ( typeString=="Image" ) type = READ_IMAGE;
@ -614,12 +705,14 @@ InputStream::ReadType InputStream::start( InputIterator* inIterator )
<< " may be incompatible with current reader version "
<< PLUGIN_VERSION << std::endl;
}
_fields.pop_back();
return type;
}
void InputStream::decompress()
{
_currentField = "Decompression";
_fields.clear();
_fields.push_back( "Decompression" );
if ( !isBinary() ) return;
std::string compressorName; *this >> compressorName;
@ -634,8 +727,11 @@ void InputStream::decompress()
std::string data;
if ( !compressor->decompress(*(_in->getStream()), data) )
throw InputException(_currentField, "InputStream: Failed to decompress stream.");
throwException( "InputStream: Failed to decompress stream." );
if ( getException() ) return;
_in->setStream( new std::stringstream(data) );
_fields.pop_back();
}
// PROTECTED METHODS

View File

@ -448,7 +448,11 @@ ObjectWrapper* ObjectWrapperManager::findWrapper( const std::string& name )
if ( osgDB::Registry::instance()->loadLibrary(nodeKitLib)==osgDB::Registry::LOADED )
return findWrapper(name);
std::string pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(libName);
std::string pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(std::string("serializers_")+libName);
if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
return findWrapper(name);
pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(libName);
if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
return findWrapper(name);
}
@ -491,7 +495,11 @@ BaseCompressor* ObjectWrapperManager::findCompressor( const std::string& name )
if ( osgDB::Registry::instance()->loadLibrary(nodeKitLib)==osgDB::Registry::LOADED )
return findCompressor(name);
std::string pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(libName);
std::string pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(std::string("compressor_")+libName);
if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
return findCompressor(name);
pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(libName);
if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
return findCompressor(name);
}

View File

@ -22,8 +22,7 @@
using namespace osgDB;
OutputStream::OutputStream( const osgDB::Options* options )
: _writeImageHint(WRITE_USE_IMAGE_HINT),
_out(0)
: _writeImageHint(WRITE_USE_IMAGE_HINT)
{
if ( !options ) return;
@ -43,11 +42,7 @@ OutputStream::OutputStream( const osgDB::Options* options )
if ( keyAndValues.size()<2 ) continue;
if ( keyAndValues[0]=="SchemaFile" )
{
osgDB::ofstream schemaStream( keyAndValues[1].c_str(), std::ios::out );
if ( !schemaStream.fail() ) writeSchema( schemaStream );
schemaStream.close();
}
_schemaName = keyAndValues[1];
else if ( keyAndValues[0]=="Compressor" )
_compressorName = keyAndValues[1];
else if ( keyAndValues[0]=="WriteImageHint" )
@ -136,6 +131,28 @@ OutputStream& OutputStream::operator<<( const osg::Matrixd& mat )
return *this;
}
void OutputStream::writeWrappedString( const std::string& str )
{
if ( !isBinary() )
{
std::string wrappedStr;
unsigned int size = str.size();
for ( unsigned int i=0; i<size; ++i )
{
char ch = str[i];
if ( ch=='\"' ) wrappedStr += '\\';
else if ( ch=='\\' ) wrappedStr += '\\';
wrappedStr += ch;
}
wrappedStr.insert( 0, 1, '\"' );
wrappedStr += '\"';
*this << wrappedStr;
}
else
*this << str;
}
void OutputStream::writeArray( const osg::Array* a )
{
if ( !a ) return;
@ -235,7 +252,7 @@ void OutputStream::writeArray( const osg::Array* a )
writeArrayImplementation( static_cast<const osg::Vec4dArray*>(a), a->getNumElements() );
break;
default:
throw OutputException(_currentField, "OutputStream::writeArray(): Unsupported array type.");
throwException( "OutputStream::writeArray(): Unsupported array type." );
}
}
@ -286,7 +303,7 @@ void OutputStream::writePrimitiveSet( const osg::PrimitiveSet* p )
}
break;
default:
throw OutputException(_currentField, "OutputStream::writePrimitiveSet(): Unsupported primitive type.");
throwException( "OutputStream::writePrimitiveSet(): Unsupported primitive type." );
}
}
@ -296,6 +313,7 @@ void OutputStream::writeImage( const osg::Image* img )
*this << PROPERTY("FileName"); writeWrappedString(img->getFileName()); *this << std::endl;
*this << PROPERTY("WriteHint") << (int)img->getWriteHint();
if ( getException() ) return;
int decision = IMAGE_EXTERNAL;
switch ( _writeImageHint )
@ -367,7 +385,9 @@ void OutputStream::writeImage( const osg::Image* img )
{
char* data = new char[size];
if ( !data )
throw OutputException(_currentField, "OutputStream::writeImage(): Out of memory.");
throwException( "OutputStream::writeImage(): Out of memory." );
if ( getException() ) return;
infile.seekg( 0, std::ios::beg );
infile.read( data, size );
writeCharArray( data, size );
@ -388,7 +408,6 @@ void OutputStream::writeImage( const osg::Image* img )
default:
break;
}
writeObject( img );
}
@ -402,6 +421,7 @@ void OutputStream::writeObject( const osg::Object* obj )
*this << name << BEGIN_BRACKET << std::endl; // Write object name
*this << PROPERTY("UniqueID") << id << std::endl; // Write object ID
if ( getException() ) return;
// Check whether this is a shared object or not
if ( id>=_objectMap.size() )
@ -414,6 +434,7 @@ void OutputStream::writeObject( const osg::Object* obj )
*this << END_BRACKET << std::endl;
return;
}
_fields.push_back( name );
const StringList& associates = wrapper->getAssociates();
for ( StringList::const_iterator itr=associates.begin(); itr!=associates.end(); ++itr )
@ -425,25 +446,31 @@ void OutputStream::writeObject( const osg::Object* obj )
<< *itr << std::endl;
continue;
}
_fields.push_back( assocWrapper->getName() );
_currentField = assocWrapper->getName();
assocWrapper->write( *this, *obj );
if ( getException() ) return;
_fields.pop_back();
}
_fields.pop_back();
}
*this << END_BRACKET << std::endl;
}
void OutputStream::start( OutputIterator* outIterator, OutputStream::WriteType type )
{
_currentField = "Header";
_fields.clear();
_fields.push_back( "Start" );
_out = outIterator;
if ( !_out )
throw OutputException(_currentField, "OutputStream: Null stream specified.");
throwException( "OutputStream: Null stream specified." );
if ( getException() ) return;
if ( isBinary() )
{
*this << (unsigned int)OSG_HEADER_LOW << (unsigned int)OSG_HEADER_HIGH
<< (unsigned int)type << (unsigned int)PLUGIN_VERSION;
*this << (unsigned int)type << (unsigned int)PLUGIN_VERSION;
if ( sizeof(osg::Matrix::value_type)==FLOAT_SIZE ) *this << (unsigned int)0;
else *this << (unsigned int)1; // Record matrix value type of current built OSG
@ -476,28 +503,29 @@ void OutputStream::start( OutputIterator* outIterator, OutputStream::WriteType t
default: break;
}
*this << PROPERTY("#Ascii") << typeString << std::endl;
*this << typeString << std::endl;
*this << PROPERTY("#Version") << (unsigned int)PLUGIN_VERSION << std::endl;
*this << PROPERTY("#Generator") << std::string("OpenSceneGraph")
<< std::string(osgGetVersion()) << std::endl;
*this << std::endl;
}
_fields.pop_back();
}
void OutputStream::compress( std::ostream* ostream )
{
_currentField = "Compression";
_fields.clear();
_fields.push_back( "Compression" );
if ( _compressorName.empty() || !isBinary() ) return;
BaseCompressor* compressor = Registry::instance()->getObjectWrapperManager()->findCompressor(_compressorName);
if ( !compressor || !ostream ) return;
if ( !compressor->compress(*ostream, _compressSource.str()) )
throw OutputException(_currentField, "OutputStream: Failed to compress stream.");
throwException( "OutputStream: Failed to compress stream." );
_fields.pop_back();
}
// PROTECTED METHODS
void OutputStream::writeSchema( std::ostream& fout )
{
// Write to external ascii stream
@ -521,6 +549,8 @@ void OutputStream::writeSchema( std::ostream& fout )
}
}
// PROTECTED METHODS
template<typename T>
void OutputStream::writeArrayImplementation( const T* a, int writeSize, unsigned int numInRow )
{

View File

@ -116,7 +116,7 @@ public:
virtual void readBool( bool& b )
{
std::string boolString;
*_in >> boolString; checkStream();
*_in >> boolString;
if ( boolString=="TRUE" ) b = true;
else b = false;
}
@ -124,50 +124,50 @@ public:
virtual void readChar( char& c )
{
short s = 0;
*_in >> s; checkStream();
*_in >> s;
c = (char)s;
}
virtual void readSChar( signed char& c )
{
short s = 0;
*_in >> s; checkStream();
*_in >> s;
c = (signed char)s;
}
virtual void readUChar( unsigned char& c )
{
short s = 0;
*_in >> s; checkStream();
*_in >> s;
c = (unsigned char)s;
}
virtual void readShort( short& s )
{ *_in >> s; checkStream(); }
{ *_in >> s; }
virtual void readUShort( unsigned short& s )
{ *_in >> s; checkStream(); }
{ *_in >> s; }
virtual void readInt( int& i )
{ *_in >> i; checkStream(); }
{ *_in >> i; }
virtual void readUInt( unsigned int& i )
{ *_in >> i; checkStream(); }
{ *_in >> i; }
virtual void readLong( long& l )
{ *_in >> l; checkStream(); }
{ *_in >> l; }
virtual void readULong( unsigned long& l )
{ *_in >> l; checkStream(); }
{ *_in >> l; }
virtual void readFloat( float& f )
{ *_in >> f; checkStream(); }
{ *_in >> f; }
virtual void readDouble( double& d )
{ *_in >> d; checkStream(); }
{ *_in >> d; }
virtual void readString( std::string& s )
{ *_in >> s; checkStream(); }
{ *_in >> s; }
virtual void readStream( std::istream& (*fn)(std::istream&) )
{ *_in >> fn; }
@ -179,7 +179,7 @@ public:
{
GLenum e = 0;
std::string enumString;
*_in >> enumString; checkStream();
*_in >> enumString;
e = osgDB::Registry::instance()->getObjectWrapperManager()->getValue("GL", enumString);
value.set( e );
}
@ -188,7 +188,7 @@ public:
{
int value = 0;
std::string enumString;
*_in >> enumString; checkStream();
*_in >> enumString;
if ( prop._mapProperty )
{
value = osgDB::Registry::instance()->getObjectWrapperManager()->getValue(prop._name, enumString);
@ -208,7 +208,7 @@ public:
virtual void readMark( osgDB::ObjectMark& mark )
{
std::string markString;
*_in >> markString; checkStream();
*_in >> markString;
}
virtual void readCharArray( char* s, unsigned int size ) {}

View File

@ -78,64 +78,64 @@ public:
virtual void readBool( bool& b )
{
char c = 0;
_in->read( &c, CHAR_SIZE ); checkStream();
_in->read( &c, CHAR_SIZE );
b = (c!=0);
}
virtual void readChar( char& c )
{ _in->read( &c, CHAR_SIZE ); checkStream(); }
{ _in->read( &c, CHAR_SIZE ); }
virtual void readSChar( signed char& c )
{ _in->read( (char*)&c, CHAR_SIZE ); checkStream(); }
{ _in->read( (char*)&c, CHAR_SIZE ); }
virtual void readUChar( unsigned char& c )
{ _in->read( (char*)&c, CHAR_SIZE ); checkStream(); }
{ _in->read( (char*)&c, CHAR_SIZE ); }
virtual void readShort( short& s )
{
_in->read( (char*)&s, SHORT_SIZE ); checkStream();
_in->read( (char*)&s, SHORT_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&s, SHORT_SIZE );
}
virtual void readUShort( unsigned short& s )
{
_in->read( (char*)&s, SHORT_SIZE ); checkStream();
_in->read( (char*)&s, SHORT_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&s, SHORT_SIZE );
}
virtual void readInt( int& i )
{
_in->read( (char*)&i, INT_SIZE ); checkStream();
_in->read( (char*)&i, INT_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&i, INT_SIZE );
}
virtual void readUInt( unsigned int& i )
{
_in->read( (char*)&i, INT_SIZE ); checkStream();
_in->read( (char*)&i, INT_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&i, INT_SIZE );
}
virtual void readLong( long& l )
{
_in->read( (char*)&l, LONG_SIZE ); checkStream();
_in->read( (char*)&l, LONG_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&l, LONG_SIZE );
}
virtual void readULong( unsigned long& l )
{
_in->read( (char*)&l, LONG_SIZE ); checkStream();
_in->read( (char*)&l, LONG_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&l, LONG_SIZE );
}
virtual void readFloat( float& f )
{
_in->read( (char*)&f, FLOAT_SIZE ); checkStream();
_in->read( (char*)&f, FLOAT_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&f, FLOAT_SIZE );
}
virtual void readDouble( double& d )
{
_in->read( (char*)&d, DOUBLE_SIZE ); checkStream();
_in->read( (char*)&d, DOUBLE_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&d, DOUBLE_SIZE );
}
@ -145,7 +145,7 @@ public:
if ( size )
{
s.resize( size );
_in->read( (char*)s.c_str(), size ); checkStream();
_in->read( (char*)s.c_str(), size );
}
}
@ -156,7 +156,7 @@ public:
virtual void readGLenum( osgDB::ObjectGLenum& value )
{
GLenum e = 0;
_in->read( (char*)&e, GLENUM_SIZE ); checkStream();
_in->read( (char*)&e, GLENUM_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&e, GLENUM_SIZE );
value.set( e );
}
@ -166,7 +166,7 @@ public:
int value = 0;
if ( prop._mapProperty )
{
_in->read( (char*)&value, INT_SIZE ); checkStream();
_in->read( (char*)&value, INT_SIZE );
if ( _byteSwap ) osg::swapBytes( (char*)&value, INT_SIZE );
}
prop.set( value );
@ -175,7 +175,7 @@ public:
virtual void readMark( osgDB::ObjectMark& mark ) {}
virtual void readCharArray( char* s, unsigned int size )
{ if ( size>0 ) _in->read( s, size ); checkStream(); }
{ if ( size>0 ) _in->read( s, size ); }
protected:
int _byteSwap;

View File

@ -21,17 +21,49 @@
using namespace osgDB;
bool checkBinary( std::istream* fin )
#define CATCH_EXCEPTION(s) \
if (s.getException()) return (s.getException()->getError() + " At " + s.getException()->getField());
InputIterator* readInputIterator( std::istream& fin, const Options* options )
{
unsigned int headerLow = 0, headerHigh = 0;
fin->read( (char*)&headerLow, INT_SIZE );
fin->read( (char*)&headerHigh, INT_SIZE );
if ( headerLow!=OSG_HEADER_LOW || headerHigh!=OSG_HEADER_HIGH )
bool extensionIsAscii = false;
if ( options && options->getOptionString().find("Ascii")!=std::string::npos )
extensionIsAscii = true;
if ( !extensionIsAscii )
{
fin->seekg( 0, std::ios::beg );
return false;
unsigned int headerLow = 0, headerHigh = 0;
fin.read( (char*)&headerLow, INT_SIZE );
fin.read( (char*)&headerHigh, INT_SIZE );
if ( headerLow==OSG_HEADER_LOW && headerHigh==OSG_HEADER_HIGH )
{
return new BinaryInputIterator(&fin);
}
fin.seekg( 0, std::ios::beg );
}
std::string header; fin >> header;
if ( header=="#Ascii" )
{
return new AsciiInputIterator(&fin);
}
return NULL;
}
OutputIterator* writeInputIterator( std::ostream& fout, const Options* options )
{
if ( options && options->getOptionString().find("Ascii")!=std::string::npos )
{
fout << std::string("#Ascii") << ' ';
return new AsciiOutputIterator(&fout);
}
else
{
unsigned int low = OSG_HEADER_LOW, high = OSG_HEADER_HIGH;
fout.write( (char*)&low, INT_SIZE );
fout.write( (char*)&high, INT_SIZE );
return new BinaryOutputIterator(&fout);
}
return true;
}
class ReaderWriterOSG2 : public osgDB::ReaderWriter
@ -43,7 +75,8 @@ public:
supportsExtension( "osgt", "OpenSceneGraph extendable ascii format" );
supportsExtension( "osgb", "OpenSceneGraph extendable binary format" );
supportsOption( "Ascii", "Import/Export option: Force the writer export ascii file" );
supportsOption( "Ascii", "Import/Export option: Force reading/writing ascii file" );
supportsOption( "ForceReadingImage", "Import option: Load an empty image instead if required file missed" );
supportsOption( "SchemaFile=<file>", "Import/Export option: Use/Record a ascii schema file" );
supportsOption( "Compressor=<name>", "Export option: Use an inbuilt or user-defined compressor" );
supportsOption( "WriteImageHint=<hint>", "Export option: Hint of writing image to stream: "
@ -82,6 +115,7 @@ public:
osg::ref_ptr<Options> local_opt = options ?
static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
if ( ext=="osgt" ) local_opt->setOptionString( local_opt->getOptionString() + " Ascii" );
osgDB::ifstream istream( fileName.c_str(), std::ios::out|std::ios::binary );
return readImage( istream, local_opt.get() );
@ -89,25 +123,18 @@ public:
virtual ReadResult readImage( std::istream& fin, const Options* options ) const
{
try
osg::ref_ptr<InputIterator> ii = readInputIterator(fin, options);
if ( !ii ) return ReadResult::FILE_NOT_HANDLED;
InputStream is( options );
if ( is.start(ii.get())!=InputStream::READ_IMAGE )
{
InputStream is( options );
InputIterator* ii = NULL;
if ( !checkBinary(&fin) )
ii = new AsciiInputIterator(&fin);
else
ii = new BinaryInputIterator(&fin);
if ( is.start(ii)!=InputStream::READ_IMAGE )
return ReadResult::FILE_NOT_HANDLED;
is.decompress();
return is.readImage();
}
catch ( InputException e )
{
return e.getError() + " At " + e.getField();
CATCH_EXCEPTION(is);
return ReadResult::FILE_NOT_HANDLED;
}
is.decompress(); CATCH_EXCEPTION(is);
osg::Image* image = is.readImage(); CATCH_EXCEPTION(is);
return image;
}
virtual ReadResult readNode( const std::string& file, const Options* options ) const
@ -120,6 +147,7 @@ public:
osg::ref_ptr<Options> local_opt = options ?
static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
if ( ext=="osgt" ) local_opt->setOptionString( local_opt->getOptionString() + " Ascii" );
osgDB::ifstream istream( fileName.c_str(), std::ios::out|std::ios::binary );
return readNode( istream, local_opt.get() );
@ -127,25 +155,19 @@ public:
virtual ReadResult readNode( std::istream& fin, const Options* options ) const
{
try
osg::ref_ptr<InputIterator> ii = readInputIterator(fin, options);
if ( !ii ) return ReadResult::FILE_NOT_HANDLED;
InputStream is( options );
if ( is.start(ii.get())!=InputStream::READ_SCENE )
{
InputStream is( options );
InputIterator* ii = NULL;
if ( !checkBinary(&fin) )
ii = new AsciiInputIterator(&fin);
else
ii = new BinaryInputIterator(&fin);
if ( is.start(ii)!=InputStream::READ_SCENE )
return ReadResult::FILE_NOT_HANDLED;
is.decompress();
return dynamic_cast<osg::Node*>( is.readObject() );
}
catch ( InputException e )
{
return e.getError() + " At " + e.getField();
CATCH_EXCEPTION(is);
return ReadResult::FILE_NOT_HANDLED;
}
is.decompress(); CATCH_EXCEPTION(is);
osg::Node* node = dynamic_cast<osg::Node*>(is.readObject()); CATCH_EXCEPTION(is);
return node;
}
virtual WriteResult writeObject( const osg::Object& object, const std::string& fileName, const Options* options ) const
@ -189,29 +211,22 @@ public:
virtual WriteResult writeImage( const osg::Image& image, std::ostream& fout, const Options* options ) const
{
try
osg::ref_ptr<OutputIterator> oi = writeInputIterator(fout, options);
OutputStream os( options );
os.start( oi.get(), OutputStream::WRITE_IMAGE ); CATCH_EXCEPTION(os);
os.writeImage( &image ); CATCH_EXCEPTION(os);
os.compress( &fout ); CATCH_EXCEPTION(os);
if ( !os.getSchemaName().empty() )
{
OutputStream os( options );
osgDB::OutputIterator* oi = NULL;
if ( options && options->getOptionString().find("Ascii")!=std::string::npos )
oi = new AsciiOutputIterator(&fout);
else
oi = new BinaryOutputIterator(&fout);
os.start( oi, OutputStream::WRITE_IMAGE );
os.writeImage( &image );
os.compress( &fout );
if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE;
return WriteResult::FILE_SAVED;
osgDB::ofstream schemaStream( os.getSchemaName().c_str(), std::ios::out );
if ( !schemaStream.fail() ) os.writeSchema( schemaStream );
schemaStream.close();
}
catch ( OutputException e )
{
osg::notify(osg::WARN) << "ReaderWriterOSG2::writeImage(): " << e.getError()
<< " At " << e.getField() << std::endl;
}
return WriteResult::FILE_NOT_HANDLED;
if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE;
return WriteResult::FILE_SAVED;
}
virtual WriteResult writeNode( const osg::Node& node, const std::string& fileName, const Options* options ) const
@ -235,29 +250,22 @@ public:
virtual WriteResult writeNode( const osg::Node& node, std::ostream& fout, const Options* options ) const
{
try
osg::ref_ptr<OutputIterator> oi = writeInputIterator(fout, options);
OutputStream os( options );
os.start( oi.get(), OutputStream::WRITE_SCENE ); CATCH_EXCEPTION(os);
os.writeObject( &node ); CATCH_EXCEPTION(os);
os.compress( &fout ); CATCH_EXCEPTION(os);
if ( !os.getSchemaName().empty() )
{
OutputStream os( options );
osgDB::OutputIterator* oi = NULL;
if ( options && options->getOptionString().find("Ascii")!=std::string::npos )
oi = new AsciiOutputIterator(&fout);
else
oi = new BinaryOutputIterator(&fout);
os.start( oi, OutputStream::WRITE_SCENE );
os.writeObject( &node );
os.compress( &fout );
if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE;
return WriteResult::FILE_SAVED;
osgDB::ofstream schemaStream( os.getSchemaName().c_str(), std::ios::out );
if ( !schemaStream.fail() ) os.writeSchema( schemaStream );
schemaStream.close();
}
catch ( OutputException e )
{
osg::notify(osg::WARN) << "ReaderWriterOSG2::writeNode(): " << e.getError()
<< " At " << e.getField() << std::endl;
}
return WriteResult::FILE_NOT_HANDLED;
if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE;
return WriteResult::FILE_SAVED;
}
};

View File

@ -33,4 +33,5 @@ SET(TARGET_COMMON_LIBRARIES
)
ADD_SUBDIRECTORY(osg)
ADD_SUBDIRECTORY(osgParticle)

View File

@ -8,8 +8,8 @@ REGISTER_OBJECT_WRAPPER( BlendFunc,
osg::BlendFunc,
"osg::Object osg::StateAttribute osg::BlendFunc" )
{
ADD_GLENUM_SERIALIZER( SourceRGB, GLenum, GL_ONE ); // _source_factor
ADD_GLENUM_SERIALIZER( SourceAlpha, GLenum, GL_ONE ); // _source_factor_alpha
ADD_GLENUM_SERIALIZER( DestinationRGB, GLenum, GL_ONE ); // _destination_factor
ADD_GLENUM_SERIALIZER( DestinationAlpha, GLenum, GL_ONE ); // _destination_factor_alpha
ADD_GLENUM_SERIALIZER( SourceRGB, GLenum, GL_NONE ); // _source_factor
ADD_GLENUM_SERIALIZER( SourceAlpha, GLenum, GL_NONE ); // _source_factor_alpha
ADD_GLENUM_SERIALIZER( DestinationRGB, GLenum, GL_NONE ); // _destination_factor
ADD_GLENUM_SERIALIZER( DestinationAlpha, GLenum, GL_NONE ); // _destination_factor_alpha
}

View File

@ -10,28 +10,22 @@ static bool checkInitialBound( const osg::Drawable& drawable )
static bool readInitialBound( osgDB::InputStream& is, osg::Drawable& drawable )
{
bool valid = false; is >> valid;
if ( valid )
{
osg::Vec3d min, max;
is >> osgDB::BEGIN_BRACKET >> osgDB::PROPERTY("Minimum") >> min;
is >> osgDB::PROPERTY("Maximum") >> max >> osgDB::END_BRACKET;
drawable.setInitialBound( osg::BoundingBox(min, max) );
}
osg::Vec3d min, max;
is >> osgDB::BEGIN_BRACKET;
is >> osgDB::PROPERTY("Minimum") >> min;
is >> osgDB::PROPERTY("Maximum") >> max;
is >> osgDB::END_BRACKET;
drawable.setInitialBound( osg::BoundingBox(min, max) );
return true;
}
static bool writeInitialBound( osgDB::OutputStream& os, const osg::Drawable& drawable )
{
const osg::BoundingBox& bb = drawable.getInitialBound();
os << bb.valid();
if ( bb.valid() )
{
os << osgDB::BEGIN_BRACKET << std::endl;
os << osgDB::PROPERTY("Minimum") << osg::Vec3d(bb._min) << std::endl;
os << osgDB::PROPERTY("Maximum") << osg::Vec3d(bb._max) << std::endl;
os << osgDB::END_BRACKET;
}
os << osgDB::BEGIN_BRACKET << std::endl;
os << osgDB::PROPERTY("Minimum") << osg::Vec3d(bb._min) << std::endl;
os << osgDB::PROPERTY("Maximum") << osg::Vec3d(bb._max) << std::endl;
os << osgDB::END_BRACKET;
os << std::endl;
return true;
}

View File

@ -31,9 +31,6 @@ static bool checkHeights( const osg::HeightField& shape )
static bool readHeights( osgDB::InputStream& is, osg::HeightField& shape )
{
bool hasArray; is >> hasArray;
if ( !hasArray ) return true;
osg::FloatArray* array = dynamic_cast<osg::FloatArray*>( is.readArray() );
if ( array )
{
@ -52,7 +49,6 @@ static bool readHeights( osgDB::InputStream& is, osg::HeightField& shape )
static bool writeHeights( osgDB::OutputStream& os, const osg::HeightField& shape )
{
os << (shape.getFloatArray()!=NULL);
os.writeArray( shape.getFloatArray() );
return true;
}

View File

@ -13,10 +13,10 @@ static bool readInitialBound( osgDB::InputStream& is, osg::Node& node )
{
osg::Vec3d center;
double radius;
bool valid;
is >> valid >> osgDB::BEGIN_BRACKET;
is >> osgDB::BEGIN_BRACKET;
is >> osgDB::PROPERTY("Center") >> center;
is >> osgDB::PROPERTY("Radius") >> radius >> osgDB::END_BRACKET;
is >> osgDB::PROPERTY("Radius") >> radius;
is >> osgDB::END_BRACKET;
node.setInitialBound( osg::BoundingSphere(center, radius) );
return true;
}
@ -24,7 +24,7 @@ static bool readInitialBound( osgDB::InputStream& is, osg::Node& node )
static bool writeInitialBound( osgDB::OutputStream& os, const osg::Node& node )
{
const osg::BoundingSphere& bs = node.getInitialBound();
os << bs.valid() << osgDB::BEGIN_BRACKET << std::endl;
os << osgDB::BEGIN_BRACKET << std::endl;
os << osgDB::PROPERTY("Center") << osg::Vec3d(bs.center()) << std::endl;
os << osgDB::PROPERTY("Radius") << double(bs.radius()) << std::endl;
os << osgDB::END_BRACKET << std::endl;

View File

@ -18,8 +18,9 @@
os << (image!=NULL); \
if ( image!=NULL ) { \
os << osgDB::BEGIN_BRACKET << std::endl << image; \
os << osgDB::END_BRACKET << std::endl; \
os << osgDB::END_BRACKET; \
} \
os << std::endl; \
return true; \
}