From dba344febae41906b963d9e377cfc8f59ff3522b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 1 Jul 2008 18:37:13 +0000 Subject: [PATCH] From Lilin Xiong, "I change ive plugin a little for osgText inout, so the ive plugin supports backdrop setting, and Text3D, FadeText inout : 1. in DataInputStream.cpp, add 1286--1293 lines; 2. in Text.cpp, add some code for text's Backdrop setting; 3. in IveVersion.h, add line 39, increase the VERSION to VERSION_028(line 41) 4. in ReadWrite.h, add line 146,147 5. add file FadeText.h, FadeText.cpp, Text3D.h, Text3D.cpp." --- src/osgPlugins/ive/CMakeLists.txt | 4 + src/osgPlugins/ive/DataInputStream.cpp | 13 +- src/osgPlugins/ive/FadeText.cpp | 61 +++++++ src/osgPlugins/ive/FadeText.h | 15 ++ src/osgPlugins/ive/IveVersion.h | 3 +- src/osgPlugins/ive/ReadWrite.h | 3 + src/osgPlugins/ive/Text.cpp | 44 ++++- src/osgPlugins/ive/Text3D.cpp | 217 +++++++++++++++++++++++++ src/osgPlugins/ive/Text3D.h | 15 ++ 9 files changed, 370 insertions(+), 5 deletions(-) create mode 100644 src/osgPlugins/ive/FadeText.cpp create mode 100644 src/osgPlugins/ive/FadeText.h create mode 100644 src/osgPlugins/ive/Text3D.cpp create mode 100644 src/osgPlugins/ive/Text3D.h diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 1ad7cc2dd..8d80c0e15 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -93,6 +93,8 @@ SET(TARGET_SRC TexGenNode.cpp TexMat.cpp Text.cpp + FadeText.cpp + Text3D.cpp Texture1D.cpp Texture2D.cpp Texture3D.cpp @@ -198,6 +200,8 @@ SET(TARGET_H TexGenNode.h TexMat.h Text.h + FadeText.h + Text3D.h Texture1D.h Texture2D.h Texture3D.h diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 1749cfb47..ed92bbc69 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -97,6 +97,9 @@ #include "HeightFieldLayer.h" #include "CompositeLayer.h" +#include "FadeText.h" +#include "Text3D.h" + #include #include #include @@ -1279,7 +1282,15 @@ osg::Drawable* DataInputStream::readDrawable() else if(drawableTypeID == IVETEXT){ drawable = new osgText::Text(); ((Text*)(drawable))->read(this); - } + } + else if(drawableTypeID == IVEFADETEXT){ + drawable = new osgText::FadeText(); + ((FadeText*)(drawable))->read(this); + } + else if(drawableTypeID == IVETEXT3D){ + drawable = new osgText::Text3D(); + ((Text3D*)(drawable))->read(this); + } else throw Exception("Unknown drawable drawableTypeIDentification in Geode::read()"); diff --git a/src/osgPlugins/ive/FadeText.cpp b/src/osgPlugins/ive/FadeText.cpp new file mode 100644 index 000000000..be228b2c8 --- /dev/null +++ b/src/osgPlugins/ive/FadeText.cpp @@ -0,0 +1,61 @@ +/********************************************************************** + * + * FILE: FadeText.cpp + * + * DESCRIPTION: Read/Write osgText::FadeText in binary format to disk. + * + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. + * + * HISTORY: Created 27.3.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "FadeText.h" +#include "Text.h" +#include "Drawable.h" +#include "Object.h" + +#include +#include +#include + +using namespace ive; + +void FadeText::write(DataOutputStream* out){ + // Write FadeText's identification. + out->writeInt(IVEFADETEXT); + // If the osg class is inherited by any other class we should also write this to file. + osgText::Text* text = dynamic_cast(this); + if(text){ + ((ive::Text*)(text))->write(out); + } + else + throw Exception("FadeText::write(): Could not cast this osgText::FadeText to an osgText::Tex."); + + // Write FadeText's properties. + out->writeFloat(getFadeSpeed()); +} + +void FadeText::read(DataInputStream* in){ + // Read FadeText's identification. + int id = in->peekInt(); + if(id == IVEFADETEXT){ + + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osgText::Text* text = dynamic_cast(this); + if(text){ + ((ive::Text*)(text))->read(in); + } + else + throw Exception("FadeText::read(): Could not cast this osgText::FadeText to an osgText::Text."); + + setFadeSpeed(in->readFloat()); + } + else{ + throw Exception("FadeText::read(): Expected FadeText identification."); + } +} diff --git a/src/osgPlugins/ive/FadeText.h b/src/osgPlugins/ive/FadeText.h new file mode 100644 index 000000000..255c7c2f8 --- /dev/null +++ b/src/osgPlugins/ive/FadeText.h @@ -0,0 +1,15 @@ +#ifndef IVE_FADETEXT +#define IVE_FADETEXT 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class FadeText : public osgText::FadeText, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index 667a6a278..805779b0a 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -36,8 +36,9 @@ #define VERSION_0025 25 #define VERSION_0026 26 #define VERSION_0027 27 +#define VERSION_0028 28 -#define VERSION VERSION_0027 +#define VERSION VERSION_0028 /* The BYTE_SEX tag is used to check the endian of the IVE file being read in. The IVE format diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 97303b8a0..2c026fa4b 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -143,6 +143,9 @@ namespace ive { //osgText classes #define IVETEXT 0x10000001 +#define IVETEXT3D 0x10000002 +#define IVEFADETEXT 0x10000003 + class ReadWrite{ public: diff --git a/src/osgPlugins/ive/Text.cpp b/src/osgPlugins/ive/Text.cpp index 66de59743..cc001ad87 100644 --- a/src/osgPlugins/ive/Text.cpp +++ b/src/osgPlugins/ive/Text.cpp @@ -75,6 +75,23 @@ void Text::write(DataOutputStream* out){ out->writeVec4(getColor()); out->writeUInt(getDrawMode()); + if ( out->getVersion() >= VERSION_0028 ) + { + out->writeUInt(getBackdropType()); + + out->writeFloat(getBackdropHorizontalOffset()); + out->writeFloat(getBackdropVerticalOffset()); + + out->writeVec4(getBackdropColor()); + out->writeUInt(getBackdropImplementation()); + + out->writeUInt(getColorGradientMode()); + out->writeVec4(getColorGradientTopLeft()); + out->writeVec4(getColorGradientBottomLeft()); + out->writeVec4(getColorGradientBottomRight()); + out->writeVec4(getColorGradientTopRight()); + } + // text :: Modified from osgPlugins::osg const osgText::String& textstring = getText(); bool isACString = true; @@ -149,7 +166,7 @@ void Text::read(DataInputStream* in){ setCharacterSize(c_height,aspectRatio); - setCharacterSizeMode((osgText::Text::CharacterSizeMode) in->readUInt()); + setCharacterSizeMode((osgText::TextBase::CharacterSizeMode) in->readUInt()); setMaximumWidth(in->readFloat()); setMaximumHeight(in->readFloat()); @@ -159,7 +176,7 @@ void Text::read(DataInputStream* in){ setLineSpacing(in->readFloat()); } - setAlignment((osgText::Text::AlignmentType) in->readUInt()); + setAlignment((osgText::TextBase::AlignmentType) in->readUInt()); //Nothing to do... //setAxisAlignment((osgText::Text::AxisAlignment) in->readUint()); @@ -172,6 +189,27 @@ void Text::read(DataInputStream* in){ setColor(in->readVec4()); setDrawMode(in->readUInt()); + if ( in->getVersion() >= VERSION_0028 ) + { + setBackdropType((osgText::Text::BackdropType) in->readUInt()); + + float horizontalOffset,verticalOffset; + horizontalOffset = in->readFloat(); + verticalOffset = in->readFloat(); + setBackdropOffset(horizontalOffset,verticalOffset); + + setBackdropColor(in->readVec4()); + setBackdropImplementation((osgText::Text::BackdropImplementation) in->readUInt()); + setColorGradientMode((osgText::Text::ColorGradientMode) in->readUInt()); + + osg::Vec4 colorGradientTopLeft,colorGradientBottomLeft,colorGradientBottomRight,colorGradientTopRight; + colorGradientTopLeft = in->readVec4(); + colorGradientBottomLeft = in->readVec4(); + colorGradientBottomRight = in->readVec4(); + colorGradientTopRight = in->readVec4(); + setColorGradientCorners(colorGradientTopLeft,colorGradientBottomLeft,colorGradientBottomRight,colorGradientTopRight); + } + if(in->readBool()) setText(in->readString()); else @@ -203,6 +241,6 @@ void Text::read(DataInputStream* in){ } else{ - throw Exception("ShadeModel::read(): Expected ShadeModel identification."); + throw Exception("Text::read(): Expected Text identification."); } } diff --git a/src/osgPlugins/ive/Text3D.cpp b/src/osgPlugins/ive/Text3D.cpp new file mode 100644 index 000000000..592afc240 --- /dev/null +++ b/src/osgPlugins/ive/Text3D.cpp @@ -0,0 +1,217 @@ +/********************************************************************** + * + * FILE: Text3D.cpp + * + * DESCRIPTION: Read/Write osgText::Text3D in binary format to disk. + * + * CREATED BY: Auto generated by iveGenerator + * and later modified by Rune Schmidt Jensen. + * + * HISTORY: Created 27.3.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "Text3D.h" +#include "Text.h" +#include "Drawable.h" +#include "Object.h" + +#include +#include +#include + +using namespace ive; + +void Text3D::write(DataOutputStream* out){ + // Write Text's identification. + out->writeInt(IVETEXT3D); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Drawable*)(obj))->write(out); + } + else + throw Exception("Text::write(): Could not cast this osgText::Text to an osg::Drawable."); + // Write Text's properties. + if( getFont() ) + { + std::string fname = getFont()->getFileName(); + + if(!fname.empty()) + { + if(out->getUseOriginalExternalReferences()) + { + out->writeString(fname); //Saving file name with local directory + } + else + { + out->writeString(osgDB::getSimpleFileName(fname)); //Saving original file name + } + } + else + out->writeString(""); //Blank string + } + else + out->writeString(""); //Blank string + + out->writeUInt(getFontWidth()); + out->writeUInt(getFontHeight()); + out->writeFloat(getCharacterHeight()); + out->writeFloat(getCharacterAspectRatio()); + out->writeUInt(getCharacterSizeMode()); + out->writeFloat(getMaximumWidth()); + out->writeFloat(getMaximumHeight()); + + out->writeFloat(getLineSpacing()); + + out->writeUInt(getAlignment()); + + out->writeQuat(getRotation()); //FIXME: controllare che ci sia + + out->writeBool(getAutoRotateToScreen()); + out->writeUInt(getLayout()); + out->writeVec3(getPosition()); +// out->writeVec4(getColor()); + out->writeUInt(getDrawMode()); + + //for text3d's property + out->writeFloat(getCharacterDepth()); + out->writeUInt(getRenderMode()); + + // text :: Modified from osgPlugins::osg + const osgText::String& textstring = getText(); + bool isACString = true; + osgText::String::const_iterator itr; + for(itr=textstring.begin(); + itr!=textstring.end() && isACString; + ++itr) + { + if (*itr==0 || *itr>256) isACString=false; + } + + if (isACString) + { + std::string str; + + for(itr=textstring.begin(); + itr!=textstring.end(); + ++itr) + { + str += (char)(*itr); + } + + //std::copy(textstring.begin(),textstring.end(),std::back_inserter(str)); + + out->writeBool(true); + out->writeString(str); + } + else + { + // do it the hardway...output each character as an int + osg::ref_ptr strarr = new osg::UIntArray(textstring.size()); + + for(itr=textstring.begin(); + itr!=textstring.end(); + ++itr) + { + strarr->push_back((*itr)); + } + + out->writeBool(false); + out->writeUIntArray(strarr.get()); + } +} + +void Text3D::read(DataInputStream* in){ + // Peek on Text3D's identification. + int id = in->peekInt(); + if(id == IVETEXT3D){ + // Read Text3D's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Drawable*)(obj))->read(in); + } + else + throw Exception("Text::read(): Could not cast this osgText::Text to an osg::Drawable."); + // Read Text's properties + + unsigned int width, height; + float c_height, aspectRatio; + + setFont(in->readString()); + + width = in->readUInt(); + height = in->readUInt(); + + setFontResolution(width,height); + + c_height = in->readFloat(); + aspectRatio = in->readFloat(); + + setCharacterSize(c_height,aspectRatio); + + setCharacterSizeMode((osgText::TextBase::CharacterSizeMode) in->readUInt()); + + setMaximumWidth(in->readFloat()); + setMaximumHeight(in->readFloat()); + + if ( in->getVersion() >= VERSION_0020 ) + { + setLineSpacing(in->readFloat()); + } + + setAlignment((osgText::TextBase::AlignmentType) in->readUInt()); + + //Nothing to do... + //setAxisAlignment((osgText::Text::AxisAlignment) in->readUint()); + + setRotation(in->readQuat()); + setAutoRotateToScreen(in->readBool()); + setLayout((osgText::Text::Layout) in->readUInt()); + + setPosition(in->readVec3()); +// setColor(in->readVec4()); + setDrawMode(in->readUInt()); + + //for text3d's property + setCharacterDepth(in->readFloat()); + setRenderMode((osgText::Text3D::RenderMode) in->readUInt()); + + if(in->readBool()) + setText(in->readString()); + else + { + if ( in->getVersion() >= VERSION_0018 ) + { + osgText::String textstr; + osg::ref_ptr arr = in->readUIntArray(); + for(unsigned int i = 0; i < arr->getNumElements(); i++) + { + textstr.push_back( arr->at(i) ); + } + + setText(textstr); + } + else + { + // buggy original path, should have used a UIntArray originally, now fixed above. + std::string textstr; + osg::ref_ptr arr = in->readUByteArray(); + for(unsigned int i = 0; i < arr->getNumElements(); i++) + { + textstr += (char) arr->at(i); + } + + setText(textstr); + } + } + + } + else{ + throw Exception("Text3D::read(): Expected ShadeModel identification."); + } +} diff --git a/src/osgPlugins/ive/Text3D.h b/src/osgPlugins/ive/Text3D.h new file mode 100644 index 000000000..405c949b9 --- /dev/null +++ b/src/osgPlugins/ive/Text3D.h @@ -0,0 +1,15 @@ +#ifndef IVE_TEXT3D +#define IVE_TEXT3D 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Text3D : public osgText::Text3D, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif