From 94e3b5a34511cd501789f5a9608e1d3cf1e35377 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 29 Jan 2010 11:35:09 +0000 Subject: [PATCH] From Wang Rui, osgText serializers and support for PagedLOD+ProxyNode --- src/osgWrappers/serializers/CMakeLists.txt | 2 +- src/osgWrappers/serializers/osg/PagedLOD.cpp | 45 ++++ src/osgWrappers/serializers/osg/ProxyNode.cpp | 44 ++++ .../serializers/osgText/CMakeLists.txt | 7 + .../serializers/osgText/FadeText.cpp | 12 + src/osgWrappers/serializers/osgText/Text.cpp | 114 ++++++++++ .../serializers/osgText/Text3D.cpp | 37 +++ .../serializers/osgText/TextBase.cpp | 213 ++++++++++++++++++ 8 files changed, 473 insertions(+), 1 deletion(-) create mode 100644 src/osgWrappers/serializers/osgText/CMakeLists.txt create mode 100644 src/osgWrappers/serializers/osgText/FadeText.cpp create mode 100644 src/osgWrappers/serializers/osgText/Text.cpp create mode 100644 src/osgWrappers/serializers/osgText/Text3D.cpp create mode 100644 src/osgWrappers/serializers/osgText/TextBase.cpp diff --git a/src/osgWrappers/serializers/CMakeLists.txt b/src/osgWrappers/serializers/CMakeLists.txt index 2d928a3db..ded54824c 100644 --- a/src/osgWrappers/serializers/CMakeLists.txt +++ b/src/osgWrappers/serializers/CMakeLists.txt @@ -34,4 +34,4 @@ SET(TARGET_COMMON_LIBRARIES ADD_SUBDIRECTORY(osg) ADD_SUBDIRECTORY(osgParticle) - +ADD_SUBDIRECTORY(osgText) diff --git a/src/osgWrappers/serializers/osg/PagedLOD.cpp b/src/osgWrappers/serializers/osg/PagedLOD.cpp index 6e286ec29..98260b747 100644 --- a/src/osgWrappers/serializers/osg/PagedLOD.cpp +++ b/src/osgWrappers/serializers/osg/PagedLOD.cpp @@ -3,6 +3,7 @@ #include #include +// _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( 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; i0 ) + { + os << osgDB::BEGIN_BRACKET << std::endl; + for ( unsigned int i=0; i0; +} + +static bool readChildren( osgDB::InputStream& is, osg::ProxyNode& node ) +{ + unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + for ( unsigned int i=0; i( 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; i0 ) + { + os << osgDB::BEGIN_BRACKET << std::endl; + for ( unsigned int i=0; i +#include +#include +#include + +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 +} diff --git a/src/osgWrappers/serializers/osgText/Text.cpp b/src/osgWrappers/serializers/osgText/Text.cpp new file mode 100644 index 000000000..96fc15d42 --- /dev/null +++ b/src/osgWrappers/serializers/osgText/Text.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include + +// _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 +} diff --git a/src/osgWrappers/serializers/osgText/Text3D.cpp b/src/osgWrappers/serializers/osgText/Text3D.cpp new file mode 100644 index 000000000..e0e21b3a6 --- /dev/null +++ b/src/osgWrappers/serializers/osgText/Text3D.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +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 +} diff --git a/src/osgWrappers/serializers/osgText/TextBase.cpp b/src/osgWrappers/serializers/osgText/TextBase.cpp new file mode 100644 index 000000000..8c827776d --- /dev/null +++ b/src/osgWrappers/serializers/osgText/TextBase.cpp @@ -0,0 +1,213 @@ +#include +#include +#include +#include + +// _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( 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 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