Implemented support for ShapeAttributeList, used John Vidar Larring's initial

submission as a base, but implementing the user data functionality in a different
way to facilitate more flexible user data support
This commit is contained in:
Robert Osfield 2008-09-01 12:40:33 +00:00
parent befa2112f8
commit 99a294ebae
8 changed files with 113 additions and 4 deletions

View File

@ -86,6 +86,7 @@ SET(TARGET_SRC
Shader.cpp
Shape.cpp
ShapeDrawable.cpp
ShapeAttributeList.cpp
StateSet.cpp
Stencil.cpp
Switch.cpp
@ -201,6 +202,7 @@ SET(TARGET_H
Shader.h
ShapeDrawable.h
Shape.h
ShapeAttributeList.h
StateSet.h
Stencil.h
Switch.h

View File

@ -87,6 +87,7 @@
#include "VisibilityGroup.h"
#include "MultiTextureControl.h"
#include "ShapeAttributeList.h"
#include "Effect.h"
#include "AnisotropicLighting.h"
#include "BumpMapping.h"
@ -1655,3 +1656,35 @@ osgTerrain::Locator* DataInputStream::readLocator()
return locator;
}
osg::Object* DataInputStream::readObject()
{
int id = readInt();
if (id<0) return 0;
if (id==IVENODE)
{
return readNode();
}
else if (id==IVESTATESET)
{
return readStateSet();
}
else if (id==IVESTATEATTRIBUTE)
{
return readStateAttribute();
}
else if (id==IVEDRAWABLE)
{
return readDrawable();
}
else if (id==IVESHAPEATTRIBUTELIST)
{
osgSim::ShapeAttributeList* sal = new osgSim::ShapeAttributeList;
((ive::ShapeAttributeList*)sal)->read(this);
return sal;
}
return 0;
}

View File

@ -101,6 +101,8 @@ public:
osg::Node* readNode();
osgTerrain::Layer* readLayer();
osgTerrain::Locator* readLocator();
osg::Object* readObject();
// Set and get if must be generated external reference ive files
void setLoadExternalReferenceFiles(bool b) {_loadExternalReferenceFiles=b;};

View File

@ -87,6 +87,7 @@
#include "VisibilityGroup.h"
#include "MultiTextureControl.h"
#include "ShapeAttributeList.h"
#include "Effect.h"
#include "AnisotropicLighting.h"
#include "BumpMapping.h"
@ -1353,3 +1354,49 @@ void DataOutputStream::writeLocator(const osgTerrain::Locator* locator)
}
}
void DataOutputStream::writeObject(const osg::Object* object)
{
const osg::Node* node = dynamic_cast<const osg::Node*>(object);
if (node)
{
writeInt(IVENODE);
writeNode(node);
return;
}
const osg::StateSet* stateset = dynamic_cast<const osg::StateSet*>(object);
if (stateset)
{
writeInt(IVESTATESET);
writeStateSet(stateset);
return;
}
const osg::StateAttribute* sa = dynamic_cast<const osg::StateAttribute*>(object);
if (sa)
{
writeInt(IVESTATEATTRIBUTE);
writeStateAttribute(sa);
return;
}
const osg::Drawable* drawable = dynamic_cast<const osg::Drawable*>(object);
if (drawable)
{
writeInt(IVEDRAWABLE);
writeDrawable(drawable);
return;
}
const osgSim::ShapeAttributeList* sal = dynamic_cast<const osgSim::ShapeAttributeList*>(object);
if (sal)
{
writeInt(IVESHAPEATTRIBUTELIST);
((ive::ShapeAttributeList*)sal)->write(this);
return;
}
// fallback, osg::Object type not supported, so can't write out
writeInt(-1);
}

View File

@ -98,7 +98,8 @@ public:
void writeLayer(const osgTerrain::Layer* layer);
void writeLocator(const osgTerrain::Locator* locator);
void writeObject(const osg::Object* object);
void setWriteDirectory(const std::string& directoryName) { _writeDirectory = directoryName; }
const std::string& getWriteDirectory() const { return _writeDirectory; }

View File

@ -39,8 +39,9 @@
#define VERSION_0028 28
#define VERSION_0029 29
#define VERSION_0030 30
#define VERSION_0031 31
#define VERSION VERSION_0030
#define VERSION VERSION_0031
/* The BYTE_SEX tag is used to check the endian
of the IVE file being read in. The IVE format

View File

@ -35,6 +35,20 @@ void Object::write(DataOutputStream* out)
case(osg::Object::DYNAMIC): out->writeChar((char)1); break;
case(osg::Object::UNSPECIFIED): out->writeChar((char)2); break;
}
if ( out->getVersion() >= VERSION_0031)
{
const osg::Object* object = dynamic_cast<const osg::Object*>(getUserData());
if (object)
{
out->writeBool(true);
out->writeObject(object);
}
else
{
out->writeBool(false);
}
}
}
void Object::read(DataInputStream* in){
@ -58,6 +72,16 @@ void Object::read(DataInputStream* in){
case 1: setDataVariance(osg::Object::DYNAMIC);break;
case 2: setDataVariance(osg::Object::UNSPECIFIED);break;
}
if ( in->getVersion() >= VERSION_0031)
{
bool hasUserData = in->readBool();
if (hasUserData)
{
setUserData(in->readObject());
}
}
}
else{
throw Exception("Object::read(): Expected Object identification");

View File

@ -119,10 +119,9 @@ namespace ive {
#define IVELIGHTPOINT 0x00100006
#define IVELIGHTPOINTNODE 0x00100007
#define IVEMULTISWITCH 0x00100008
#define IVEVISIBILITYGROUP 0x00100009
#define IVEDIRECTIONALSECTOR 0x0010000A
#define IVESHAPEATTRIBUTELIST 0X0010000B
// osgTerrain classes
#define IVETERRAINTILE 0x00200001