diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index 1c29dc937..dffc9aa88 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -258,6 +258,14 @@ SOURCE=..\..\..\src\osgPlugins\ive\ShadeModel.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Shape.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\ive\ShapeDrawable.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\PrimitiveSet.cpp # End Source File # Begin Source File @@ -518,6 +526,14 @@ SOURCE=..\..\..\src\osgPlugins\ive\ShadeModel.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Shape.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\ive\ShapeDrawable.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\ReadWrite.h # End Source File # Begin Source File diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 01dcf2e77..3ddf05af8 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -53,6 +53,8 @@ #include "VisibilityGroup.h" #include "Geometry.h" +#include "ShapeDrawable.h" +#include "Shape.h" #include #include @@ -699,10 +701,16 @@ osg::Drawable* DataInputStream::readDrawable() int drawableTypeID = peekInt(); osg::Drawable* drawable; - if(drawableTypeID == IVEGEOMETRY){ + if(drawableTypeID == IVEGEOMETRY) + { drawable = new osg::Geometry(); ((Geometry*)(drawable))->read(this); } + else if(drawableTypeID == IVESHAPEDRAWABLE) + { + drawable = new osg::ShapeDrawable(); + ((ShapeDrawable*)(drawable))->read(this); + } else throw Exception("Unknown drawable drawableTypeIDentification in Geode::read()"); @@ -716,6 +724,62 @@ osg::Drawable* DataInputStream::readDrawable() return drawable; } +osg::Shape* DataInputStream::readShape() +{ + // Read stateattributes unique ID. + int id = readInt(); + // See if stateattribute is already in the list. + ShapeMap::iterator itr= _shapeMap.find(id); + if (itr!=_shapeMap.end()) return itr->second.get(); + + // stateattribute is not in list. + // Create a new stateattribute, + + int shapeTypeID = peekInt(); + osg::Shape* shape; + if(shapeTypeID == IVESPHERE) + { + shape = new osg::Sphere(); + ((Sphere*)(shape))->read(this); + } + else if(shapeTypeID == IVEBOX) + { + shape = new osg::Box(); + ((Box*)(shape))->read(this); + } + else if(shapeTypeID == IVECONE) + { + shape = new osg::Cone(); + ((Cone*)(shape))->read(this); + } + else if(shapeTypeID == IVECYLINDER) + { + shape = new osg::Cylinder(); + ((Cylinder*)(shape))->read(this); + } + else if(shapeTypeID == IVECAPSULE) + { + shape = new osg::Capsule(); + ((Capsule*)(shape))->read(this); + } + else if(shapeTypeID == IVEHEIGHTFIELD) + { + shape = new osg::HeightField(); + ((HeightField*)(shape))->read(this); + } + else + throw Exception("Unknown shape shapeTypeIDentification in Shape::read()"); + + + // and add it to the stateattribute map, + _shapeMap[id] = shape; + + + if (_verboseOutput) std::cout<<"read/writeShape() ["< > ImageMap; typedef std::map > StateSetMap; typedef std::map > StateAttributeMap; typedef std::map > DrawableMap; + typedef std::map > ShapeMap; typedef std::map > NodeMap; bool _verboseOutput; @@ -84,9 +87,10 @@ private: StateSetMap _statesetMap; StateAttributeMap _stateAttributeMap; DrawableMap _drawableMap; + ShapeMap _shapeMap; NodeMap _nodeMap; - int _byteswap ; + int _byteswap ; }; } diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index d95dc660d..b92d9cd80 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -55,6 +55,9 @@ #include "VisibilityGroup.h" #include "Geometry.h" +#include "ShapeDrawable.h" + +#include "Shape.h" using namespace ive; @@ -507,13 +510,57 @@ void DataOutputStream::writeDrawable(const osg::Drawable* drawable) if(dynamic_cast(drawable)) ((ive::Geometry*)(drawable))->write(this); - else{ + else if(dynamic_cast(drawable)) + ((ive::ShapeDrawable*)(drawable))->write(this); + else + { throw Exception("Unknown drawable in DataOutputStream::writeDrawable()"); } if (_verboseOutput) std::cout<<"read/writeDrawable() ["<second); + + if (_verboseOutput) std::cout<<"read/writeShape() ["<second<<"]"<(shape)) + ((ive::Sphere*)(shape))->write(this); + else if(dynamic_cast(shape)) + ((ive::Box*)(shape))->write(this); + else if(dynamic_cast(shape)) + ((ive::Cone*)(shape))->write(this); + else if(dynamic_cast(shape)) + ((ive::Cylinder*)(shape))->write(this); + else if(dynamic_cast(shape)) + ((ive::Capsule*)(shape))->write(this); + else if(dynamic_cast(shape)) + ((ive::HeightField*)(shape))->write(this); + else + { + throw Exception("Unknown shape in DataOutputStream::writeShape()"); + } + if (_verboseOutput) std::cout<<"read/writeShape() ["< #include #include +#include #include "IveVersion.h" #include "DataTypeSize.h" @@ -60,6 +61,7 @@ public: void writeStateSet(const osg::StateSet* stateset); void writeStateAttribute(const osg::StateAttribute* sa); void writeDrawable(const osg::Drawable* sa); + void writeShape(const osg::Shape* sa); void writeNode(const osg::Node* sa); // Set and get include image data in stream @@ -75,11 +77,13 @@ private: typedef std::map StateSetMap; typedef std::map StateAttributeMap; typedef std::map DrawableMap; + typedef std::map ShapeMap; typedef std::map NodeMap; StateSetMap _stateSetMap; StateAttributeMap _stateAttributeMap; DrawableMap _drawableMap; + ShapeMap _shapeMap; NodeMap _nodeMap; bool _includeImageData; diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index b952e19a6..cb6e52813 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -43,6 +43,8 @@ CXXFILES =\ PrimitiveSet.cpp\ Sequence.cpp\ ShadeModel.cpp\ + Shape.cpp\ + ShapeDrawable.cpp\ Switch.cpp\ StateSet.cpp\ TexEnv.cpp\ diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 064b75414..a0552c316 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -58,8 +58,18 @@ namespace ive { #define IVEVERTEXPROGRAM 0x0000012F // Drawables -#define IVEDRAWABLE 0x00001000 -#define IVEGEOMETRY 0x00001001 +#define IVEDRAWABLE 0x00001000 +#define IVEGEOMETRY 0x00001001 +#define IVESHAPEDRAWABLE 0x00001002 + +// Shapes +#define IVESHAPE 0x00002000 +#define IVESPHERE 0x00002001 +#define IVEBOX 0x00002002 +#define IVECONE 0x00002004 +#define IVECYLINDER 0x00002005 +#define IVECAPSULE 0x00002006 +#define IVEHEIGHTFIELD 0x00002007 // Primitive set #define IVEPRIMITIVESET 0x00010000 diff --git a/src/osgPlugins/ive/Shape.cpp b/src/osgPlugins/ive/Shape.cpp new file mode 100644 index 000000000..0346c7776 --- /dev/null +++ b/src/osgPlugins/ive/Shape.cpp @@ -0,0 +1,314 @@ +/********************************************************************** + * + * FILE: HeightField.cpp + * + * DESCRIPTION: Read/Write osg::HeightField 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 "Shape.h" +#include "Object.h" + +using namespace ive; + + +//////////////////////////////////////////////////////////////////////////////// +// +// Sphere +// +void Sphere::write(DataOutputStream* out) +{ + // Write CullFace's identification. + out->writeInt(IVESPHERE); + // 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::Object*)(obj))->write(out); + } + else + throw Exception("Sphere::write(): Could not cast this osg::Sphere to an osg::Object."); + + // Write Sphere's properties. + //out->writeVec4(getColor()); +} + +void Sphere::read(DataInputStream* in) +{ + // Peek on Sphere's identification. + int id = in->peekInt(); + if(id == IVESPHERE) + { + // Read Sphere'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::Object*)(obj))->read(in); + } + else + throw Exception("Sphere::read(): Could not cast this osg::Sphere to an osg::Object."); + + // Read Sphere's properties + //setColor(in->readVec4()); + + } + else + { + throw Exception("Sphere::read(): Expected Sphere identification."); + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// +// Box +// +void Box::write(DataOutputStream* out) +{ + // Write CullFace's identification. + out->writeInt(IVEBOX); + // 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::Object*)(obj))->write(out); + } + else + throw Exception("Box::write(): Could not cast this osg::Box to an osg::Object."); + + // Write Box's properties. + //out->writeVec4(getColor()); +} + +void Box::read(DataInputStream* in) +{ + // Peek on Box's identification. + int id = in->peekInt(); + if(id == IVEBOX) + { + // Read Box'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::Object*)(obj))->read(in); + } + else + throw Exception("Box::read(): Could not cast this osg::Box to an osg::Object."); + + // Read Box's properties + //setColor(in->readVec4()); + + } + else + { + throw Exception("Box::read(): Expected Box identification."); + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// +// Cone +// +void Cone::write(DataOutputStream* out) +{ + // Write CullFace's identification. + out->writeInt(IVECONE); + // 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::Object*)(obj))->write(out); + } + else + throw Exception("Cone::write(): Could not cast this osg::Cone to an osg::Object."); + + // Write Cone's properties. + //out->writeVec4(getColor()); +} + +void Cone::read(DataInputStream* in) +{ + // Peek on Cone's identification. + int id = in->peekInt(); + if(id == IVECONE) + { + // Read Cone'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::Object*)(obj))->read(in); + } + else + throw Exception("Cone::read(): Could not cast this osg::Cone to an osg::Object."); + + // Read Cone's properties + //setColor(in->readVec4()); + + } + else + { + throw Exception("Cone::read(): Expected Cone identification."); + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// +// Cylinder +// +void Cylinder::write(DataOutputStream* out) +{ + // Write CullFace's identification. + out->writeInt(IVECYLINDER); + // 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::Object*)(obj))->write(out); + } + else + throw Exception("Cylinder::write(): Could not cast this osg::Cylinder to an osg::Object."); + + // Write Cylinder's properties. + //out->writeVec4(getColor()); +} + +void Cylinder::read(DataInputStream* in) +{ + // Peek on Cylinder's identification. + int id = in->peekInt(); + if(id == IVECYLINDER) + { + // Read Cylinder'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::Object*)(obj))->read(in); + } + else + throw Exception("Cylinder::read(): Could not cast this osg::Cylinder to an osg::Object."); + + // Read Cylinder's properties + //setColor(in->readVec4()); + + } + else + { + throw Exception("Cylinder::read(): Expected Cylinder identification."); + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// +// Capsule +// +void Capsule::write(DataOutputStream* out) +{ + // Write CullFace's identification. + out->writeInt(IVECAPSULE); + // 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::Object*)(obj))->write(out); + } + else + throw Exception("Capsule::write(): Could not cast this osg::Capsule to an osg::Object."); + + // Write Capsule's properties. + //out->writeVec4(getColor()); +} + +void Capsule::read(DataInputStream* in) +{ + // Peek on Capsule's identification. + int id = in->peekInt(); + if(id == IVECAPSULE) + { + // Read Capsule'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::Object*)(obj))->read(in); + } + else + throw Exception("Capsule::read(): Could not cast this osg::Capsule to an osg::Object."); + + // Read Capsule's properties + //setColor(in->readVec4()); + + } + else + { + throw Exception("Capsule::read(): Expected Capsule identification."); + } +} + + +//////////////////////////////////////////////////////////////////////////////// +// +// HeightField +// +void HeightField::write(DataOutputStream* out) +{ + // Write CullFace's identification. + out->writeInt(IVEHEIGHTFIELD); + // 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::Object*)(obj))->write(out); + } + else + throw Exception("HeightField::write(): Could not cast this osg::HeightField to an osg::Object."); + + // Write HeightField's properties. + //out->writeVec4(getColor()); +} + +void HeightField::read(DataInputStream* in) +{ + // Peek on HeightField's identification. + int id = in->peekInt(); + if(id == IVEHEIGHTFIELD) + { + // Read HeightField'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::Object*)(obj))->read(in); + } + else + throw Exception("HeightField::read(): Could not cast this osg::HeightField to an osg::Object."); + + // Read HeightField's properties + //setColor(in->readVec4()); + + } + else + { + throw Exception("HeightField::read(): Expected HeightField identification."); + } +} + diff --git a/src/osgPlugins/ive/Shape.h b/src/osgPlugins/ive/Shape.h new file mode 100644 index 000000000..0f453d67b --- /dev/null +++ b/src/osgPlugins/ive/Shape.h @@ -0,0 +1,47 @@ +#ifndef IVE_HIEGHTFIELD +#define IVE_HIEGHTFIELD 1 + +#include +#include "ReadWrite.h" + +namespace ive{ + +class Sphere : public osg::Sphere, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +class Box : public osg::Box, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +class Cone : public osg::Cone, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +class Cylinder : public osg::Cylinder, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +class Capsule : public osg::Capsule, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +class HeightField : public osg::HeightField, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +} + +#endif diff --git a/src/osgPlugins/ive/ShapeDrawable.cpp b/src/osgPlugins/ive/ShapeDrawable.cpp new file mode 100644 index 000000000..6f11fcb86 --- /dev/null +++ b/src/osgPlugins/ive/ShapeDrawable.cpp @@ -0,0 +1,78 @@ +/********************************************************************** + * + * FILE: ShapeDrawable.cpp + * + * DESCRIPTION: Read/Write osg::ShapeDrawable 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 "ShapeDrawable.h" +#include "Object.h" + +using namespace ive; + +void ShapeDrawable::write(DataOutputStream* out) +{ + // Write CullFace's identification. + out->writeInt(IVESHAPEDRAWABLE); + // 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::Object*)(obj))->write(out); + } + else + throw Exception("ShapeDrawable::write(): Could not cast this osg::ShapeDrawable to an osg::Object."); + + // Write ShapeDrawable's properties. + out->writeVec4(getColor()); + + if (getShape()) + { + out->writeBool(true); + out->writeShape(getShape()); + } + else + { + out->writeBool(false); + } +} + +void ShapeDrawable::read(DataInputStream* in) +{ + // Peek on ShapeDrawable's identification. + int id = in->peekInt(); + if(id == IVESHAPEDRAWABLE) + { + // Read ShapeDrawable'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::Object*)(obj))->read(in); + } + else + throw Exception("ShapeDrawable::read(): Could not cast this osg::ShapeDrawable to an osg::Object."); + + // Read ShapeDrawable's properties + setColor(in->readVec4()); + + if (in->readBool()) + { + setShape(in->readShape()); + } + + } + else + { + throw Exception("ShapeDrawable::read(): Expected ShapeDrawable identification."); + } +} diff --git a/src/osgPlugins/ive/ShapeDrawable.h b/src/osgPlugins/ive/ShapeDrawable.h new file mode 100644 index 000000000..8e0645d9f --- /dev/null +++ b/src/osgPlugins/ive/ShapeDrawable.h @@ -0,0 +1,15 @@ +#ifndef IVE_SHAPEDRAWABLE +#define IVE_SHAPEDRAWABLE 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class ShapeDrawable : public osg::ShapeDrawable, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif