From Carlo Camporesi, add support for text into .ive plugin, tweak by
Robert Osfield to allow font names to be exported correctly with extension
This commit is contained in:
@@ -368,6 +368,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\TexMat.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Text.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Texture.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -680,6 +684,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\TexMat.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Text.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Texture.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
* HISTORY: Created 11.03.2003
|
||||
* Updated for texture1D by Don Burns, 27.1.2004
|
||||
* Updated for light model - Stan Blinov at 25 august 7512 from World Creation (7.09.2004)
|
||||
* Updated for light model - Stan Blinov at 25 august 7512 from World Creation (7.09.2004)
|
||||
*
|
||||
*
|
||||
* Copyright 2003 VR-C
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "CullFace.h"
|
||||
#include "ClipPlane.h"
|
||||
#include "PolygonOffset.h"
|
||||
//#include "PolygonMode.h"
|
||||
#include "ShadeModel.h"
|
||||
#include "Point.h"
|
||||
#include "LineWidth.h"
|
||||
@@ -68,6 +69,8 @@
|
||||
#include "ShapeDrawable.h"
|
||||
#include "Shape.h"
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
#include <osg/Endian>
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
@@ -92,7 +95,7 @@ DataInputStream::DataInputStream(std::istream* istream)
|
||||
{
|
||||
unsigned int endianType ;
|
||||
|
||||
_loadExternalReferenceFiles = false;
|
||||
_loadExternalReferenceFiles = false;
|
||||
|
||||
_verboseOutput = false;
|
||||
|
||||
@@ -630,7 +633,7 @@ osg::Image* DataInputStream::readImage(std::string filename)
|
||||
{
|
||||
// If image is already read and in list
|
||||
// then just return pointer to this.
|
||||
ImageMap::iterator mitr=_imageMap.find(filename);
|
||||
ImageMap::iterator mitr=_imageMap.find(filename);
|
||||
if (mitr!=_imageMap.end()) return mitr->second.get();
|
||||
|
||||
// Image is not in list.
|
||||
@@ -708,6 +711,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
|
||||
attribute = new osg::PolygonOffset();
|
||||
((ive::PolygonOffset*)(attribute))->read(this);
|
||||
}
|
||||
/* else if(attributeID == IVEPOLYGONMODE){
|
||||
attribute = new osg::PolygonMode();
|
||||
((ive::PolygonMode*)(attribute))->read(this);
|
||||
}*/
|
||||
else if(attributeID == IVESHADEMODEL){
|
||||
attribute = new osg::ShadeModel();
|
||||
((ive::ShadeModel*)(attribute))->read(this);
|
||||
@@ -764,7 +771,7 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
|
||||
attribute = new osg::LightModel();
|
||||
((ive::LightModel*)(attribute))->read(this);
|
||||
}
|
||||
else if(attributeID == IVEFRONTFACE){
|
||||
else if(attributeID == IVEFRONTFACE){
|
||||
attribute = new osg::FrontFace();
|
||||
((ive::FrontFace*)(attribute))->read(this);
|
||||
}
|
||||
@@ -804,6 +811,10 @@ osg::Drawable* DataInputStream::readDrawable()
|
||||
drawable = new osg::ShapeDrawable();
|
||||
((ShapeDrawable*)(drawable))->read(this);
|
||||
}
|
||||
else if(drawableTypeID == IVETEXT){
|
||||
drawable = new osgText::Text();
|
||||
((Text*)(drawable))->read(this);
|
||||
}
|
||||
else
|
||||
throw Exception("Unknown drawable drawableTypeIDentification in Geode::read()");
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define IVE_DATAINPUTSTREAM 1
|
||||
|
||||
|
||||
#include <iostream> // for ifstream
|
||||
#include <iostream> // for ifstream
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <osg/Quat>
|
||||
#include <osg/Array>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Image>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/ref_ptr>
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include "IveVersion.h"
|
||||
#include "DataTypeSize.h"
|
||||
#include "DataTypeSize.h"
|
||||
#include "Exception.h"
|
||||
|
||||
|
||||
@@ -33,83 +33,83 @@ namespace ive{
|
||||
class DataInputStream{
|
||||
|
||||
public:
|
||||
DataInputStream(std::istream* istream);
|
||||
~DataInputStream();
|
||||
DataInputStream(std::istream* istream);
|
||||
~DataInputStream();
|
||||
|
||||
void setOptions(const osgDB::ReaderWriter::Options* options);
|
||||
const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); }
|
||||
|
||||
unsigned int getVersion();
|
||||
bool readBool();
|
||||
char readChar();
|
||||
unsigned char readUChar();
|
||||
unsigned short readUShort();
|
||||
unsigned int readUInt();
|
||||
int readInt();
|
||||
int peekInt();
|
||||
float readFloat();
|
||||
long readLong();
|
||||
unsigned long readULong();
|
||||
double readDouble();
|
||||
std::string readString();
|
||||
void readCharArray(char* data, int size);
|
||||
unsigned int getVersion();
|
||||
bool readBool();
|
||||
char readChar();
|
||||
unsigned char readUChar();
|
||||
unsigned short readUShort();
|
||||
unsigned int readUInt();
|
||||
int readInt();
|
||||
int peekInt();
|
||||
float readFloat();
|
||||
long readLong();
|
||||
unsigned long readULong();
|
||||
double readDouble();
|
||||
std::string readString();
|
||||
void readCharArray(char* data, int size);
|
||||
|
||||
osg::Vec2 readVec2();
|
||||
osg::Vec3 readVec3();
|
||||
osg::Vec4 readVec4();
|
||||
osg::Vec2d readVec2d();
|
||||
osg::Vec3d readVec3d();
|
||||
osg::Vec4d readVec4d();
|
||||
osg::Plane readPlane();
|
||||
osg::UByte4 readUByte4();
|
||||
osg::Quat readQuat();
|
||||
osg::Matrix readMatrix();
|
||||
osg::Geometry::AttributeBinding readBinding();
|
||||
osg::Array* readArray();
|
||||
osg::IntArray* readIntArray();
|
||||
osg::UByteArray* readUByteArray();
|
||||
osg::UShortArray* readUShortArray();
|
||||
osg::UIntArray* readUIntArray();
|
||||
osg::UByte4Array* readUByte4Array();
|
||||
osg::FloatArray* readFloatArray();
|
||||
osg::Vec2Array* readVec2Array();
|
||||
osg::Vec3Array* readVec3Array();
|
||||
osg::Vec4Array* readVec4Array();
|
||||
osg::Vec2 readVec2();
|
||||
osg::Vec3 readVec3();
|
||||
osg::Vec4 readVec4();
|
||||
osg::Vec2d readVec2d();
|
||||
osg::Vec3d readVec3d();
|
||||
osg::Vec4d readVec4d();
|
||||
osg::Plane readPlane();
|
||||
osg::UByte4 readUByte4();
|
||||
osg::Quat readQuat();
|
||||
osg::Matrix readMatrix();
|
||||
osg::Geometry::AttributeBinding readBinding();
|
||||
osg::Array* readArray();
|
||||
osg::IntArray* readIntArray();
|
||||
osg::UByteArray* readUByteArray();
|
||||
osg::UShortArray* readUShortArray();
|
||||
osg::UIntArray* readUIntArray();
|
||||
osg::UByte4Array* readUByte4Array();
|
||||
osg::FloatArray* readFloatArray();
|
||||
osg::Vec2Array* readVec2Array();
|
||||
osg::Vec3Array* readVec3Array();
|
||||
osg::Vec4Array* readVec4Array();
|
||||
|
||||
osg::Image* readImage(std::string s);
|
||||
osg::StateSet* readStateSet();
|
||||
osg::StateAttribute* readStateAttribute();
|
||||
osg::Drawable* readDrawable();
|
||||
osg::Shape* readShape();
|
||||
osg::Node* readNode();
|
||||
osg::Image* readImage(std::string s);
|
||||
osg::StateSet* readStateSet();
|
||||
osg::StateAttribute* readStateAttribute();
|
||||
osg::Drawable* readDrawable();
|
||||
osg::Shape* readShape();
|
||||
osg::Node* readNode();
|
||||
|
||||
// Set and get if must be generated external reference ive files
|
||||
void setLoadExternalReferenceFiles(bool b) {_loadExternalReferenceFiles=b;};
|
||||
bool getLoadExternalReferenceFiles() {return _loadExternalReferenceFiles;};
|
||||
// Set and get if must be generated external reference ive files
|
||||
void setLoadExternalReferenceFiles(bool b) {_loadExternalReferenceFiles=b;};
|
||||
bool getLoadExternalReferenceFiles() {return _loadExternalReferenceFiles;};
|
||||
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::Image> > ImageMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::StateSet> > StateSetMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::StateAttribute> > StateAttributeMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Drawable> > DrawableMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Shape> > ShapeMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Node> > NodeMap;
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::Image> > ImageMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::StateSet> > StateSetMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::StateAttribute> > StateAttributeMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Drawable> > DrawableMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Shape> > ShapeMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Node> > NodeMap;
|
||||
|
||||
bool _verboseOutput;
|
||||
std::istream* _istream;
|
||||
std::istream* _istream;
|
||||
int _byteswap;
|
||||
|
||||
private:
|
||||
int _version;
|
||||
bool _peeking;
|
||||
int _peekValue;
|
||||
ImageMap _imageMap;
|
||||
StateSetMap _statesetMap;
|
||||
StateAttributeMap _stateAttributeMap;
|
||||
DrawableMap _drawableMap;
|
||||
ShapeMap _shapeMap;
|
||||
NodeMap _nodeMap;
|
||||
int _version;
|
||||
bool _peeking;
|
||||
int _peekValue;
|
||||
ImageMap _imageMap;
|
||||
StateSetMap _statesetMap;
|
||||
StateAttributeMap _stateAttributeMap;
|
||||
DrawableMap _drawableMap;
|
||||
ShapeMap _shapeMap;
|
||||
NodeMap _nodeMap;
|
||||
|
||||
bool _loadExternalReferenceFiles;
|
||||
bool _loadExternalReferenceFiles;
|
||||
|
||||
osg::ref_ptr<const osgDB::ReaderWriter::Options> _options;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "CullFace.h"
|
||||
#include "ClipPlane.h"
|
||||
#include "PolygonOffset.h"
|
||||
//#include "PolygonMode.h"
|
||||
#include "ShadeModel.h"
|
||||
#include "Point.h"
|
||||
#include "LineWidth.h"
|
||||
@@ -70,6 +71,8 @@
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
|
||||
@@ -103,8 +106,8 @@ DataOutputStream::DataOutputStream(std::ostream * ostream)
|
||||
_includeImageData= true;
|
||||
|
||||
_includeExternalReferences = false;
|
||||
_writeExternalReferenceFiles = true;
|
||||
_useOriginalExternalReferences = false;
|
||||
_writeExternalReferenceFiles = false;
|
||||
_useOriginalExternalReferences = true;
|
||||
|
||||
|
||||
_ostream = ostream;
|
||||
@@ -510,6 +513,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
|
||||
else if(dynamic_cast<const osg::PolygonOffset*>(attribute)){
|
||||
((ive::PolygonOffset*)(attribute))->write(this);
|
||||
}
|
||||
/* // This is a PolygonMode
|
||||
else if(dynamic_cast<const osg::PolygonMode*>(attribute)){
|
||||
((ive::PolygonMode*)(attribute))->write(this);
|
||||
}*/
|
||||
else if(dynamic_cast<const osg::ShadeModel*>(attribute)){
|
||||
((ive::ShadeModel*)(attribute))->write(this);
|
||||
}
|
||||
@@ -566,8 +573,8 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
|
||||
else if(dynamic_cast<const osg::LightModel*>(attribute)){
|
||||
((ive::LightModel*)(attribute))->write(this);
|
||||
}
|
||||
// This is a FrontFace
|
||||
else if(dynamic_cast<const osg::FrontFace*>(attribute)){
|
||||
// This is a FrontFace
|
||||
else if(dynamic_cast<const osg::FrontFace*>(attribute)){
|
||||
((ive::FrontFace*)(attribute))->write(this);
|
||||
}
|
||||
|
||||
@@ -604,6 +611,8 @@ void DataOutputStream::writeDrawable(const osg::Drawable* drawable)
|
||||
((ive::Geometry*)(drawable))->write(this);
|
||||
else if(dynamic_cast<const osg::ShapeDrawable*>(drawable))
|
||||
((ive::ShapeDrawable*)(drawable))->write(this);
|
||||
else if(dynamic_cast<const osgText::Text*>(drawable))
|
||||
((ive::Text*)(drawable))->write(this);
|
||||
else
|
||||
{
|
||||
throw Exception("Unknown drawable in DataOutputStream::writeDrawable()");
|
||||
|
||||
@@ -74,6 +74,7 @@ CXXFILES =\
|
||||
Texture2D.cpp\
|
||||
Texture3D.cpp\
|
||||
Texture.cpp\
|
||||
Text.cpp\
|
||||
TextureCubeMap.cpp\
|
||||
Transform.cpp\
|
||||
VertexProgram.cpp\
|
||||
|
||||
@@ -102,7 +102,10 @@ namespace ive {
|
||||
#define IVEDIRECTIONALSECTOR 0x0010000A
|
||||
|
||||
// osgFX classes
|
||||
#define IVEMULTITEXTURECONTROL 0x01000001
|
||||
#define IVEMULTITEXTURECONTROL 0x01000001
|
||||
|
||||
//osgText classes
|
||||
#define IVETEXT 0x10000001
|
||||
|
||||
|
||||
class ReadWrite{
|
||||
|
||||
187
src/osgPlugins/ive/Text.cpp
Normal file
187
src/osgPlugins/ive/Text.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* FILE: Text.cpp
|
||||
*
|
||||
* DESCRIPTION: Read/Write osgText::Text 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 "Text.h"
|
||||
#include "Drawable.h"
|
||||
#include "Object.h"
|
||||
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace ive;
|
||||
|
||||
void Text::write(DataOutputStream* out){
|
||||
// Write Text's identification.
|
||||
out->writeInt(IVETEXT);
|
||||
// If the osg class is inherited by any other class we should also write this to file.
|
||||
osg::Object* obj = dynamic_cast<osg::Object*>(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->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());
|
||||
|
||||
// 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<osg::UByteArray> strarr = new osg::UByteArray(textstring.size());
|
||||
|
||||
for(itr=textstring.begin();
|
||||
itr!=textstring.end();
|
||||
++itr)
|
||||
{
|
||||
strarr->push_back((char)(*itr));
|
||||
}
|
||||
|
||||
out->writeBool(false);
|
||||
out->writeUByteArray(strarr.get());
|
||||
}
|
||||
}
|
||||
|
||||
void Text::read(DataInputStream* in){
|
||||
// Peek on Text's identification.
|
||||
int id = in->peekInt();
|
||||
if(id == IVETEXT){
|
||||
// Read Text'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<osg::Object*>(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(height,aspectRatio);
|
||||
|
||||
setCharacterSizeMode((osgText::Text::CharacterSizeMode) in->readUInt());
|
||||
|
||||
setMaximumWidth(in->readFloat());
|
||||
setMaximumHeight(in->readFloat());
|
||||
|
||||
setAlignment((osgText::Text::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());
|
||||
|
||||
if(in->readBool())
|
||||
setText(in->readString());
|
||||
else
|
||||
{
|
||||
std::string textstr;
|
||||
|
||||
osg::ref_ptr<osg::UByteArray> arr = in->readUByteArray();
|
||||
|
||||
for(unsigned int i = 0; i < arr->getNumElements(); i++)
|
||||
{
|
||||
textstr += (char) arr->at(i);
|
||||
}
|
||||
|
||||
setText(textstr);
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
throw Exception("ShadeModel::read(): Expected ShadeModel identification.");
|
||||
}
|
||||
}
|
||||
15
src/osgPlugins/ive/Text.h
Normal file
15
src/osgPlugins/ive/Text.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef IVE_TEXT
|
||||
#define IVE_TEXT 1
|
||||
|
||||
#include <osgText/Text>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class Text : public osgText::Text, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -87,7 +87,7 @@ bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
float height;
|
||||
if (fr[1].getFloat(height))
|
||||
{
|
||||
text.setMaximumWidth(height);
|
||||
text.setMaximumHeight(height);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user