Added prelimary shape support to .ive plugin

This commit is contained in:
Robert Osfield
2004-03-17 16:11:47 +00:00
parent c4deb5510f
commit 2def63605f
11 changed files with 606 additions and 5 deletions

View File

@@ -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

View File

@@ -53,6 +53,8 @@
#include "VisibilityGroup.h"
#include "Geometry.h"
#include "ShapeDrawable.h"
#include "Shape.h"
#include <osg/Endian>
#include <osgDB/ReadFile>
@@ -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() ["<<id<<"]"<<std::endl;
return shape;
}
osg::Node* DataInputStream::readNode()
{
// Read node unique ID.

View File

@@ -43,6 +43,7 @@ public:
double readDouble();
std::string readString();
void readCharArray(char* data, int size);
osg::Vec2 readVec2();
osg::Vec3 readVec3();
osg::Vec4 readVec4();
@@ -65,12 +66,14 @@ public:
osg::StateSet* readStateSet();
osg::StateAttribute* readStateAttribute();
osg::Drawable* readDrawable();
osg::Shape* readShape();
osg::Node* readNode();
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;
@@ -84,9 +87,10 @@ private:
StateSetMap _statesetMap;
StateAttributeMap _stateAttributeMap;
DrawableMap _drawableMap;
ShapeMap _shapeMap;
NodeMap _nodeMap;
int _byteswap ;
int _byteswap ;
};
}

View File

@@ -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<const osg::Geometry*>(drawable))
((ive::Geometry*)(drawable))->write(this);
else{
else if(dynamic_cast<const osg::ShapeDrawable*>(drawable))
((ive::ShapeDrawable*)(drawable))->write(this);
else
{
throw Exception("Unknown drawable in DataOutputStream::writeDrawable()");
}
if (_verboseOutput) std::cout<<"read/writeDrawable() ["<<id<<"]"<<std::endl;
}
}
void DataOutputStream::writeShape(const osg::Shape* shape)
{
ShapeMap::iterator itr = _shapeMap.find(shape);
if (itr!=_shapeMap.end())
{
// Id already exists so just write ID.
writeInt(itr->second);
if (_verboseOutput) std::cout<<"read/writeShape() ["<<itr->second<<"]"<<std::endl;
}
else
{
// id doesn't exist so create a new ID and
// register the stateset.
int id = _shapeMap.size();
_shapeMap[shape] = id;
// write the id.
writeInt(id);
if(dynamic_cast<const osg::Sphere*>(shape))
((ive::Sphere*)(shape))->write(this);
else if(dynamic_cast<const osg::Box*>(shape))
((ive::Box*)(shape))->write(this);
else if(dynamic_cast<const osg::Cone*>(shape))
((ive::Cone*)(shape))->write(this);
else if(dynamic_cast<const osg::Cylinder*>(shape))
((ive::Cylinder*)(shape))->write(this);
else if(dynamic_cast<const osg::Capsule*>(shape))
((ive::Capsule*)(shape))->write(this);
else if(dynamic_cast<const osg::HeightField*>(shape))
((ive::HeightField*)(shape))->write(this);
else
{
throw Exception("Unknown shape in DataOutputStream::writeShape()");
}
if (_verboseOutput) std::cout<<"read/writeShape() ["<<id<<"]"<<std::endl;
}
}
void DataOutputStream::writeNode(const osg::Node* node)
{
NodeMap::iterator itr = _nodeMap.find(node);

View File

@@ -12,6 +12,7 @@
#include <osg/Array>
#include <osg/Matrix>
#include <osg/Geometry>
#include <osg/Shape>
#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<const osg::StateSet*,int> StateSetMap;
typedef std::map<const osg::StateAttribute*,int> StateAttributeMap;
typedef std::map<const osg::Drawable*,int> DrawableMap;
typedef std::map<const osg::Shape*,int> ShapeMap;
typedef std::map<const osg::Node*,int> NodeMap;
StateSetMap _stateSetMap;
StateAttributeMap _stateAttributeMap;
DrawableMap _drawableMap;
ShapeMap _shapeMap;
NodeMap _nodeMap;
bool _includeImageData;

View File

@@ -43,6 +43,8 @@ CXXFILES =\
PrimitiveSet.cpp\
Sequence.cpp\
ShadeModel.cpp\
Shape.cpp\
ShapeDrawable.cpp\
Switch.cpp\
StateSet.cpp\
TexEnv.cpp\

View File

@@ -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

View File

@@ -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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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<osg::Object*>(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.");
}
}

View File

@@ -0,0 +1,47 @@
#ifndef IVE_HIEGHTFIELD
#define IVE_HIEGHTFIELD 1
#include <osg/Shape>
#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

View File

@@ -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<osg::Object*>(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<osg::Object*>(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.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_SHAPEDRAWABLE
#define IVE_SHAPEDRAWABLE 1
#include <osg/ShapeDrawable>
#include "ReadWrite.h"
namespace ive{
class ShapeDrawable : public osg::ShapeDrawable, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif