From 99a294ebae6a45751733929270f0eab2f90165f8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 1 Sep 2008 12:40:33 +0000 Subject: [PATCH] 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 --- src/osgPlugins/ive/CMakeLists.txt | 2 ++ src/osgPlugins/ive/DataInputStream.cpp | 33 +++++++++++++++++ src/osgPlugins/ive/DataInputStream.h | 2 ++ src/osgPlugins/ive/DataOutputStream.cpp | 47 +++++++++++++++++++++++++ src/osgPlugins/ive/DataOutputStream.h | 3 +- src/osgPlugins/ive/IveVersion.h | 3 +- src/osgPlugins/ive/Object.cpp | 24 +++++++++++++ src/osgPlugins/ive/ReadWrite.h | 3 +- 8 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 6f959e3b4..86af63468 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -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 diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index a9ae0f18f..dc2173652 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -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; +} + + diff --git a/src/osgPlugins/ive/DataInputStream.h b/src/osgPlugins/ive/DataInputStream.h index bb8015300..628f1edd3 100644 --- a/src/osgPlugins/ive/DataInputStream.h +++ b/src/osgPlugins/ive/DataInputStream.h @@ -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;}; diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index cd97deca7..d835048f6 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -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(object); + if (node) + { + writeInt(IVENODE); + writeNode(node); + return; + } + + const osg::StateSet* stateset = dynamic_cast(object); + if (stateset) + { + writeInt(IVESTATESET); + writeStateSet(stateset); + return; + } + + const osg::StateAttribute* sa = dynamic_cast(object); + if (sa) + { + writeInt(IVESTATEATTRIBUTE); + writeStateAttribute(sa); + return; + } + + const osg::Drawable* drawable = dynamic_cast(object); + if (drawable) + { + writeInt(IVEDRAWABLE); + writeDrawable(drawable); + return; + } + + const osgSim::ShapeAttributeList* sal = dynamic_cast(object); + if (sal) + { + writeInt(IVESHAPEATTRIBUTELIST); + ((ive::ShapeAttributeList*)sal)->write(this); + return; + } + + // fallback, osg::Object type not supported, so can't write out + writeInt(-1); +} diff --git a/src/osgPlugins/ive/DataOutputStream.h b/src/osgPlugins/ive/DataOutputStream.h index 08139a259..6797282f9 100644 --- a/src/osgPlugins/ive/DataOutputStream.h +++ b/src/osgPlugins/ive/DataOutputStream.h @@ -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; } diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index d643d5164..f71481955 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -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 diff --git a/src/osgPlugins/ive/Object.cpp b/src/osgPlugins/ive/Object.cpp index e28cf182b..fec76cf40 100644 --- a/src/osgPlugins/ive/Object.cpp +++ b/src/osgPlugins/ive/Object.cpp @@ -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(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"); diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 773f6299a..799afe06d 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -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