From Wang Rui, osgText serializers and support for PagedLOD+ProxyNode

This commit is contained in:
Robert Osfield
2010-01-29 11:35:09 +00:00
parent 4ae1c275f2
commit 94e3b5a345
8 changed files with 473 additions and 1 deletions

View File

@@ -34,4 +34,4 @@ SET(TARGET_COMMON_LIBRARIES
ADD_SUBDIRECTORY(osg)
ADD_SUBDIRECTORY(osgParticle)
ADD_SUBDIRECTORY(osgText)

View File

@@ -3,6 +3,7 @@
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
// _perRangeDataList
static bool checkRangeDataList( const osg::PagedLOD& node )
{
return node.getNumFileNames()>0;
@@ -43,6 +44,49 @@ static bool writeRangeDataList( osgDB::OutputStream& os, const osg::PagedLOD& no
return true;
}
// _children
static bool checkChildren( const osg::PagedLOD& node )
{
return node.getNumChildren()>0;
}
static bool readChildren( osgDB::InputStream& is, osg::PagedLOD& node )
{
unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Node* child = dynamic_cast<osg::Node*>( is.readObject() );
if ( child ) node.addChild( child );
}
is >> osgDB::END_BRACKET;
return true;
}
static bool writeChildren( osgDB::OutputStream& os, const osg::PagedLOD& node )
{
unsigned int size=node.getNumFileNames(), dynamicLoadedSize=0;
for ( unsigned int i=0; i<size; ++i )
{
if ( !node.getFileName(i).empty() )
dynamicLoadedSize++;
}
unsigned int realSize = size-dynamicLoadedSize; os << realSize;
if ( realSize>0 )
{
os << osgDB::BEGIN_BRACKET << std::endl;
for ( unsigned int i=0; i<size; ++i )
{
if ( !node.getFileName(i).empty() ) continue;
if ( i<node.getNumChildren() )
os << node.getChild(i);
}
os << osgDB::END_BRACKET;
}
os << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( PagedLOD,
new osg::PagedLOD,
osg::PagedLOD,
@@ -55,4 +99,5 @@ REGISTER_OBJECT_WRAPPER( PagedLOD,
ADD_UINT_SERIALIZER( NumChildrenThatCannotBeExpired, 0 ); // _numChildrenThatCannotBeExpired
ADD_BOOL_SERIALIZER( DisableExternalChildrenPaging, false ); // _disableExternalChildrenPaging
ADD_USER_SERIALIZER( RangeDataList ); // _perRangeDataList
ADD_USER_SERIALIZER( Children ); // _children (which are not loaded from external)
}

View File

@@ -34,6 +34,49 @@ static bool writeFileNames( osgDB::OutputStream& os, const osg::ProxyNode& node
return true;
}
// _children
static bool checkChildren( const osg::ProxyNode& node )
{
return node.getNumChildren()>0;
}
static bool readChildren( osgDB::InputStream& is, osg::ProxyNode& node )
{
unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::Node* child = dynamic_cast<osg::Node*>( is.readObject() );
if ( child ) node.addChild( child );
}
is >> osgDB::END_BRACKET;
return true;
}
static bool writeChildren( osgDB::OutputStream& os, const osg::ProxyNode& node )
{
unsigned int size=node.getNumFileNames(), dynamicLoadedSize=0;
for ( unsigned int i=0; i<size; ++i )
{
if ( !node.getFileName(i).empty() )
dynamicLoadedSize++;
}
unsigned int realSize = size-dynamicLoadedSize; os << realSize;
if ( realSize>0 )
{
os << osgDB::BEGIN_BRACKET << std::endl;
for ( unsigned int i=0; i<size; ++i )
{
if ( !node.getFileName(i).empty() ) continue;
if ( i<node.getNumChildren() )
os << node.getChild(i);
}
os << osgDB::END_BRACKET;
}
os << std::endl;
return true;
}
// _userDefinedCenter, _radius
static bool checkUserCenter( const osg::ProxyNode& node )
{
@@ -62,6 +105,7 @@ REGISTER_OBJECT_WRAPPER( ProxyNode,
// Note: osg::Group is not in the list to prevent recording dynamic loaded children
ADD_USER_SERIALIZER( FileNames ); // _filenameList
ADD_USER_SERIALIZER( Children ); // _children (which are not loaded from external)
ADD_STRING_SERIALIZER( DatabasePath, "" ); // _databasePath
BEGIN_ENUM_SERIALIZER( LoadingExternalReferenceMode, LOAD_IMMEDIATELY );

View File

@@ -0,0 +1,7 @@
FILE(GLOB TARGET_SRC *.cpp)
FILE(GLOB TARGET_H *.h)
SET(TARGET_ADDED_LIBRARIES osgText )
#### end var setup ###
SETUP_PLUGIN(osgtext)

View File

@@ -0,0 +1,12 @@
#include <osgText/FadeText>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgText_FadeText,
new osgText::FadeText,
osgText::FadeText,
"osg::Object osg::Drawable osgText::TextBase osgText::Text osgText::FadeText" )
{
ADD_FLOAT_SERIALIZER( FadeSpeed, 0.0f ); // _fadeSpeed
}

View File

@@ -0,0 +1,114 @@
#include <osgText/Text>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
// _font
static bool checkFont( const osgText::Text& text )
{
return text.getFont()!=NULL;
}
static bool readFont( osgDB::InputStream& is, osgText::Text& text )
{
std::string fontName; is.readWrappedString( fontName );
text.setFont( osgText::readFontFile(fontName) );
return true;
}
static bool writeFont( osgDB::OutputStream& os, const osgText::Text& text )
{
os.writeWrappedString( text.getFont()->getFileName() );
os << std::endl;
return true;
}
// _backdropHorizontalOffset, _backdropVerticalOffset
static bool checkBackdropOffset( const osgText::Text& text )
{
return true;
}
static bool readBackdropOffset( osgDB::InputStream& is, osgText::Text& text )
{
float horizontal, vertical; is >> horizontal >> vertical;
text.setBackdropOffset( horizontal, vertical );
return true;
}
static bool writeBackdropOffset( osgDB::OutputStream& os, const osgText::Text& text )
{
os << text.getBackdropHorizontalOffset()
<< text.getBackdropVerticalOffset() << std::endl;
return true;
}
// _colorGradientTopLeft .. _colorGradientBottomRight
static bool checkColorGradientCorners( const osgText::Text& text )
{
return true;
}
static bool readColorGradientCorners( osgDB::InputStream& is, osgText::Text& text )
{
osg::Vec4d lt, lb, rb, rt;
is >> osgDB::BEGIN_BRACKET;
is >> osgDB::PROPERTY("TopLeft") >> lt;
is >> osgDB::PROPERTY("BottomLeft") >> lb;
is >> osgDB::PROPERTY("BottomRight") >> rb;
is >> osgDB::PROPERTY("TopRight") >> rt;
is >> osgDB::END_BRACKET;
text.setColorGradientCorners( lt, lb, rb, rt );
return true;
}
static bool writeColorGradientCorners( osgDB::OutputStream& os, const osgText::Text& text )
{
os << osgDB::BEGIN_BRACKET << std::endl;
os << osgDB::PROPERTY("TopLeft") << osg::Vec4d(text.getColorGradientTopLeft()) << std::endl;
os << osgDB::PROPERTY("BottomLeft") << osg::Vec4d(text.getColorGradientBottomLeft()) << std::endl;
os << osgDB::PROPERTY("BottomRight") << osg::Vec4d(text.getColorGradientBottomRight()) << std::endl;
os << osgDB::PROPERTY("TopRight") << osg::Vec4d(text.getColorGradientTopRight()) << std::endl;
os << osgDB::END_BRACKET << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( osgText_Text,
new osgText::Text,
osgText::Text,
"osg::Object osg::Drawable osgText::TextBase osgText::Text" )
{
ADD_USER_SERIALIZER( Font ); // _font
ADD_VEC4_SERIALIZER( Color, osg::Vec4() ); // _color
BEGIN_ENUM_SERIALIZER( BackdropType, NONE );
ADD_ENUM_VALUE( DROP_SHADOW_BOTTOM_RIGHT );
ADD_ENUM_VALUE( DROP_SHADOW_CENTER_RIGHT );
ADD_ENUM_VALUE( DROP_SHADOW_TOP_RIGHT );
ADD_ENUM_VALUE( DROP_SHADOW_BOTTOM_CENTER );
ADD_ENUM_VALUE( DROP_SHADOW_TOP_CENTER );
ADD_ENUM_VALUE( DROP_SHADOW_BOTTOM_LEFT );
ADD_ENUM_VALUE( DROP_SHADOW_CENTER_LEFT );
ADD_ENUM_VALUE( DROP_SHADOW_TOP_LEFT );
ADD_ENUM_VALUE( OUTLINE );
ADD_ENUM_VALUE( NONE );
END_ENUM_SERIALIZER(); // _backdropType
BEGIN_ENUM_SERIALIZER( BackdropImplementation, DEPTH_RANGE );
ADD_ENUM_VALUE( POLYGON_OFFSET );
ADD_ENUM_VALUE( NO_DEPTH_BUFFER );
ADD_ENUM_VALUE( DEPTH_RANGE );
ADD_ENUM_VALUE( STENCIL_BUFFER );
END_ENUM_SERIALIZER(); // _backdropImplementation
ADD_USER_SERIALIZER( BackdropOffset ); // _backdropHorizontalOffset, _backdropVerticalOffset
ADD_VEC4_SERIALIZER( BackdropColor, osg::Vec4() ); // _backdropColor
BEGIN_ENUM_SERIALIZER( ColorGradientMode, SOLID );
ADD_ENUM_VALUE( SOLID );
ADD_ENUM_VALUE( PER_CHARACTER );
ADD_ENUM_VALUE( OVERALL );
END_ENUM_SERIALIZER(); // _colorGradientMode
ADD_USER_SERIALIZER( ColorGradientCorners ); // _colorGradientTopLeft .. _colorGradientBottomRight
}

View File

@@ -0,0 +1,37 @@
#include <osgText/Text3D>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
static bool checkFont( const osgText::Text3D& text )
{
return text.getFont()!=NULL;
}
static bool readFont( osgDB::InputStream& is, osgText::Text3D& text )
{
std::string fontName; is.readWrappedString( fontName );
text.setFont( osgText::readFont3DFile(fontName) );
return true;
}
static bool writeFont( osgDB::OutputStream& os, const osgText::Text3D& text )
{
os.writeWrappedString( text.getFont()->getFileName() );
os << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( osgText_Text3D,
new osgText::Text3D,
osgText::Text3D,
"osg::Object osg::Drawable osgText::TextBase osgText::Text3D" )
{
ADD_FLOAT_SERIALIZER( CharacterDepth, 1.0f ); // _characterDepth
ADD_USER_SERIALIZER( Font ); // _font
BEGIN_ENUM_SERIALIZER( RenderMode, PER_GLYPH );
ADD_ENUM_VALUE( PER_FACE );
ADD_ENUM_VALUE( PER_GLYPH );
END_ENUM_SERIALIZER(); // _renderMode
}

View File

@@ -0,0 +1,213 @@
#include <osgText/TextBase>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
// _fontSize
static bool checkFontSize( const osgText::TextBase& text )
{
return true;
}
static bool readFontSize( osgDB::InputStream& is, osgText::TextBase& text )
{
unsigned int width, height; is >> width >> height;
text.setFontResolution( width, height );
return true;
}
static bool writeFontSize( osgDB::OutputStream& os, const osgText::TextBase& text )
{
os << text.getFontWidth() << text.getFontHeight() << std::endl;
return true;
}
// _characterHeight, _characterAspectRatio
static bool checkCharacterSize( const osgText::TextBase& text )
{
return true;
}
static bool readCharacterSize( osgDB::InputStream& is, osgText::TextBase& text )
{
float height, aspectRatio; is >> height >> aspectRatio;
text.setCharacterSize( height, aspectRatio );
return true;
}
static bool writeCharacterSize( osgDB::OutputStream& os, const osgText::TextBase& text )
{
os << text.getCharacterHeight() << text.getCharacterAspectRatio() << std::endl;
return true;
}
// _text
static bool checkText( const osgText::TextBase& text )
{
return text.getText().size()>0;
}
static bool readText( osgDB::InputStream& is, osgText::TextBase& text )
{
bool isACString; is >> isACString;
if ( isACString )
{
std::string acString; is.readWrappedString( acString );
text.setText( acString );
}
else
{
osg::UIntArray* array = dynamic_cast<osg::UIntArray*>( is.readArray() );
if ( array )
{
osgText::String string; string;
for ( osg::UIntArray::iterator itr=array->begin(); itr!=array->end(); ++itr )
{
string.push_back( *itr );
}
text.setText( string );
}
}
return true;
}
static bool writeText( osgDB::OutputStream& os, const osgText::TextBase& text )
{
bool isACString = true;
const osgText::String& string = text.getText();
for ( osgText::String::const_iterator itr=string.begin(); itr!=string.end(); ++itr )
{
if ( *itr==0 || *itr>256 )
{
isACString = false;
break;
}
}
os << isACString;
if ( isACString )
{
std::string acString;
for ( osgText::String::const_iterator itr=string.begin(); itr!=string.end(); ++itr )
{
acString += (char)(*itr);
}
os.writeWrappedString( acString );
os << std::endl;
}
else
{
osg::ref_ptr<osg::UIntArray> array = new osg::UIntArray( string.begin(), string.end() );
os << array.get();
}
return true;
}
// _drawMode
static bool checkDrawMode( const osgText::TextBase& text )
{
return text.getDrawMode()!=osgText::TextBase::TEXT;
}
static bool readDrawMode( osgDB::InputStream& is, osgText::TextBase& text )
{
unsigned int mask = osgText::TextBase::TEXT;
if ( is.isBinary() )
is >> mask;
else
{
std::string maskSetString; is >> maskSetString;
osgDB::StringList maskList; osgDB::split( maskSetString, maskList, '|' );
for ( unsigned int i=0; i<maskList.size(); ++i )
{
const std::string& maskValue = maskList[i];
if ( maskValue=="TEXT" ) mask |= osgText::TextBase::TEXT;
else if ( maskValue=="BOUND" ) mask |= osgText::TextBase::BOUNDINGBOX;
else if ( maskValue=="FILLED" ) mask |= osgText::TextBase::FILLEDBOUNDINGBOX;
else if ( maskValue=="ALIGNMENT" ) mask |= osgText::TextBase::ALIGNMENT;
}
}
text.setDrawMode( mask );
return true;
}
static bool writeDrawMode( osgDB::OutputStream& os, const osgText::TextBase& text )
{
unsigned int mask = text.getDrawMode();
if ( os.isBinary() )
os << mask;
else
{
std::string maskString;
if ( mask==osgText::TextBase::TEXT ) maskString += std::string("TEXT|");
if ( mask==osgText::TextBase::BOUNDINGBOX ) maskString += std::string("BOUND|");
if ( mask==osgText::TextBase::FILLEDBOUNDINGBOX ) maskString += std::string("FILLED|");
if ( mask==osgText::TextBase::ALIGNMENT ) maskString += std::string("ALIGNMENT|");
if ( !maskString.size() ) maskString = std::string("NONE|");
os << maskString.substr(0, maskString.size()-1) << std::endl;
}
return true;
}
REGISTER_OBJECT_WRAPPER( osgText_TextBase,
/*new osgText::TextBase*/NULL,
osgText::TextBase,
"osg::Object osg::Drawable osgText::TextBase" )
{
ADD_USER_SERIALIZER( FontSize ); // _fontSize
ADD_USER_SERIALIZER( CharacterSize ); // _characterHeight, _characterAspectRatio
BEGIN_ENUM_SERIALIZER( CharacterSizeMode, OBJECT_COORDS );
ADD_ENUM_VALUE( OBJECT_COORDS );
ADD_ENUM_VALUE( SCREEN_COORDS );
ADD_ENUM_VALUE( OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT );
END_ENUM_SERIALIZER(); // _characterSizeMode
ADD_FLOAT_SERIALIZER( MaximumWidth, 0.0f ); // _maximumWidth
ADD_FLOAT_SERIALIZER( MaximumHeight, 0.0f ); // _maximumHeight
ADD_FLOAT_SERIALIZER( LineSpacing, 0.0f ); // _lineSpacing
ADD_USER_SERIALIZER( Text ); // _text
ADD_VEC3_SERIALIZER( Position, osg::Vec3() ); // _position
BEGIN_ENUM_SERIALIZER2( Alignment, osgText::TextBase::AlignmentType, LEFT_BASE_LINE );
ADD_ENUM_VALUE( LEFT_TOP );
ADD_ENUM_VALUE( LEFT_CENTER );
ADD_ENUM_VALUE( LEFT_BOTTOM );
ADD_ENUM_VALUE( CENTER_TOP );
ADD_ENUM_VALUE( CENTER_CENTER );
ADD_ENUM_VALUE( CENTER_BOTTOM );
ADD_ENUM_VALUE( RIGHT_TOP );
ADD_ENUM_VALUE( RIGHT_CENTER );
ADD_ENUM_VALUE( RIGHT_BOTTOM );
ADD_ENUM_VALUE( LEFT_BASE_LINE );
ADD_ENUM_VALUE( CENTER_BASE_LINE );
ADD_ENUM_VALUE( RIGHT_BASE_LINE );
ADD_ENUM_VALUE( LEFT_BOTTOM_BASE_LINE );
ADD_ENUM_VALUE( CENTER_BOTTOM_BASE_LINE );
ADD_ENUM_VALUE( RIGHT_BOTTOM_BASE_LINE );
END_ENUM_SERIALIZER(); // _alignment
BEGIN_ENUM_SERIALIZER( AxisAlignment, XY_PLANE );
ADD_ENUM_VALUE( XY_PLANE );
ADD_ENUM_VALUE( REVERSED_XY_PLANE );
ADD_ENUM_VALUE( XZ_PLANE );
ADD_ENUM_VALUE( REVERSED_XZ_PLANE );
ADD_ENUM_VALUE( YZ_PLANE );
ADD_ENUM_VALUE( REVERSED_YZ_PLANE );
ADD_ENUM_VALUE( SCREEN );
ADD_ENUM_VALUE( USER_DEFINED_ROTATION );
END_ENUM_SERIALIZER(); // _axisAlignment
ADD_QUAT_SERIALIZER( Rotation, osg::Quat() ); // _rotation
ADD_BOOL_SERIALIZER( AutoRotateToScreen, false ); // _autoRotateToScreen
BEGIN_ENUM_SERIALIZER( Layout, LEFT_TO_RIGHT );
ADD_ENUM_VALUE( LEFT_TO_RIGHT );
ADD_ENUM_VALUE( RIGHT_TO_LEFT );
ADD_ENUM_VALUE( VERTICAL );
END_ENUM_SERIALIZER(); // _layout
ADD_USER_SERIALIZER( DrawMode ); // _drawMode
ADD_FLOAT_SERIALIZER( BoundingBoxMargin, 0.0f ); // _textBBMargin
ADD_VEC4_SERIALIZER( BoundingBoxColor, osg::Vec4() ); // _textBBColor
}