From 38efb23901c2a8d3102f174490c9cec6bed38d05 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 25 Aug 2008 15:57:17 +0000 Subject: [PATCH] From Liang Aibin, added support for : osgFX::Effect osgFX::AnisotropicLighting osgFX::BumpMapping osgFX::Cartoon osgFX::Scribe osgFX::SpecularHighlights. --- src/osgPlugins/ive/AnisotropicLighting.cpp | 57 +++++++++++++++++ src/osgPlugins/ive/AnisotropicLighting.h | 15 +++++ src/osgPlugins/ive/BumpMapping.cpp | 74 ++++++++++++++++++++++ src/osgPlugins/ive/BumpMapping.h | 15 +++++ src/osgPlugins/ive/CMakeLists.txt | 14 +++- src/osgPlugins/ive/Cartoon.cpp | 59 +++++++++++++++++ src/osgPlugins/ive/Cartoon.h | 15 +++++ src/osgPlugins/ive/DataInputStream.cpp | 28 ++++++++ src/osgPlugins/ive/DataOutputStream.cpp | 24 +++++++ src/osgPlugins/ive/Effect.cpp | 59 +++++++++++++++++ src/osgPlugins/ive/Effect.h | 15 +++++ src/osgPlugins/ive/ReadWrite.h | 6 ++ src/osgPlugins/ive/Scribe.cpp | 57 +++++++++++++++++ src/osgPlugins/ive/Scribe.h | 15 +++++ src/osgPlugins/ive/SpecularHighlights.cpp | 61 ++++++++++++++++++ src/osgPlugins/ive/SpecularHighlights.h | 15 +++++ 16 files changed, 528 insertions(+), 1 deletion(-) create mode 100644 src/osgPlugins/ive/AnisotropicLighting.cpp create mode 100644 src/osgPlugins/ive/AnisotropicLighting.h create mode 100644 src/osgPlugins/ive/BumpMapping.cpp create mode 100644 src/osgPlugins/ive/BumpMapping.h create mode 100644 src/osgPlugins/ive/Cartoon.cpp create mode 100644 src/osgPlugins/ive/Cartoon.h create mode 100644 src/osgPlugins/ive/Effect.cpp create mode 100644 src/osgPlugins/ive/Effect.h create mode 100644 src/osgPlugins/ive/Scribe.cpp create mode 100644 src/osgPlugins/ive/Scribe.h create mode 100644 src/osgPlugins/ive/SpecularHighlights.cpp create mode 100644 src/osgPlugins/ive/SpecularHighlights.h diff --git a/src/osgPlugins/ive/AnisotropicLighting.cpp b/src/osgPlugins/ive/AnisotropicLighting.cpp new file mode 100644 index 000000000..087ded215 --- /dev/null +++ b/src/osgPlugins/ive/AnisotropicLighting.cpp @@ -0,0 +1,57 @@ +/********************************************************************** + * + * FILE: AnisotropicLighting.cpp + * + * DESCRIPTION: Read/Write osgFX::AnisotropicLighting in binary format to disk. + * + * CREATED BY: Liang Aibin + * + * HISTORY: Created 23.8.2008 + * + **********************************************************************/ + +#include "Exception.h" +#include "AnisotropicLighting.h" +#include "Effect.h" + +using namespace ive; + +void AnisotropicLighting::write(DataOutputStream* out){ + // Write AnisotropicLighting's identification. + out->writeInt(IVEANISOTROPICLIGHTING); + // If the osg class is inherited by any other class we should also write this to file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->write(out); + } + else + throw Exception("AnisotropicLighting::write(): Could not cast this osgFX::AnisotropicLighting to an osgFX::Effect."); + + // Write AnisotropicLighting's properties. + out->writeImage(getLightingMap()); + out->writeInt(getLightNumber()); +} + +void AnisotropicLighting::read(DataInputStream* in){ + // Peek on AnisotropicLighting's identification. + int id = in->peekInt(); + if(id == IVEANISOTROPICLIGHTING){ + // Read AnisotropicLighting's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->read(in); + } + else + throw Exception("AnisotropicLighting::read(): Could not cast this osgFX::AnisotropicLighting to an osgFX::Effect."); + + // Read AnisotropicLighting's properties + setLightingMap(in->readImage()); + setLightNumber(in->readInt()); + } + else{ + throw Exception("AnisotropicLighting::read(): Expected AnisotropicLighting identification."); + } +} diff --git a/src/osgPlugins/ive/AnisotropicLighting.h b/src/osgPlugins/ive/AnisotropicLighting.h new file mode 100644 index 000000000..a56d19311 --- /dev/null +++ b/src/osgPlugins/ive/AnisotropicLighting.h @@ -0,0 +1,15 @@ +#ifndef IVE_ANISOTROPICLIGHTING +#define IVE_ANISOTROPICLIGHTING 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class AnisotropicLighting : public osgFX::AnisotropicLighting, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/BumpMapping.cpp b/src/osgPlugins/ive/BumpMapping.cpp new file mode 100644 index 000000000..fa24d27c6 --- /dev/null +++ b/src/osgPlugins/ive/BumpMapping.cpp @@ -0,0 +1,74 @@ +/********************************************************************** + * + * FILE: BumpMapping.cpp + * + * DESCRIPTION: Read/Write osgFX::BumpMapping in binary format to disk. + * + * CREATED BY: Liang Aibin + * + * HISTORY: Created 23.8.2008 + * + **********************************************************************/ + +#include "Exception.h" +#include "BumpMapping.h" +#include "Effect.h" +#include "Texture2D.h" + +using namespace ive; + +void BumpMapping::write(DataOutputStream* out){ + // Write BumpMapping's identification. + out->writeInt(IVEBUMPMAPPING); + // If the osg class is inherited by any other class we should also write this to file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->write(out); + } + else + throw Exception("BumpMapping::write(): Could not cast this osgFX::BumpMapping to an osgFX::Effect."); + + // Write BumpMapping's properties. + out->writeInt(getLightNumber()); + out->writeInt(getDiffuseTextureUnit()); + out->writeInt(getNormalMapTextureUnit()); + + osg::Texture2D *tex=getOverrideDiffuseTexture(); + ((ive::Texture2D*)(tex))->write(out); + + tex=getOverrideNormalMapTexture(); + ((ive::Texture2D*)(tex))->write(out); +} + +void BumpMapping::read(DataInputStream* in){ + // Peek on BumpMapping's identification. + int id = in->peekInt(); + if(id == IVEBUMPMAPPING){ + // Read BumpMapping's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->read(in); + } + else + throw Exception("BumpMapping::read(): Could not cast this osgFX::BumpMapping to an osgFX::Effect."); + + // Read BumpMapping's properties + setLightNumber(in->readInt()); + setDiffuseTextureUnit(in->readInt()); + setNormalMapTextureUnit(in->readInt()); + + osg::Texture2D *tex=new osg::Texture2D; + ((ive::Texture2D*)(tex))->read(in); + setOverrideDiffuseTexture(tex); + + tex=new osg::Texture2D; + ((ive::Texture2D*)(tex))->read(in); + setOverrideNormalMapTexture(tex); + } + else{ + throw Exception("BumpMapping::read(): Expected BumpMapping identification."); + } +} diff --git a/src/osgPlugins/ive/BumpMapping.h b/src/osgPlugins/ive/BumpMapping.h new file mode 100644 index 000000000..24560e06a --- /dev/null +++ b/src/osgPlugins/ive/BumpMapping.h @@ -0,0 +1,15 @@ +#ifndef IVE_BUMPMAPPING +#define IVE_BUMPMAPPING 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class BumpMapping : public osgFX::BumpMapping, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 5cda86523..063211542 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -1,4 +1,4 @@ -#this file is automatically generated +#this file is automatically generated SET(TARGET_SRC @@ -108,6 +108,12 @@ SET(TARGET_SRC VertexProgram.cpp Viewport.cpp VisibilityGroup.cpp + Effect.cpp + AnisotropicLighting.cpp + BumpMapping.cpp + Cartoon.cpp + Scribe.cpp + SpecularHighlights.cpp ) SET(TARGET_H AlphaFunc.h @@ -216,6 +222,12 @@ SET(TARGET_H VertexProgram.h Viewport.h VisibilityGroup.h + Effect.h + AnisotropicLighting.h + BumpMapping.h + Cartoon.h + Scribe.h + SpecularHighlights.h ) SET(TARGET_ADDED_LIBRARIES osgSim osgFX osgText osgTerrain) #### end var setup ### diff --git a/src/osgPlugins/ive/Cartoon.cpp b/src/osgPlugins/ive/Cartoon.cpp new file mode 100644 index 000000000..44c946fd4 --- /dev/null +++ b/src/osgPlugins/ive/Cartoon.cpp @@ -0,0 +1,59 @@ +/********************************************************************** + * + * FILE: Cartoon.cpp + * + * DESCRIPTION: Read/Write osgFX::Cartoon in binary format to disk. + * + * CREATED BY: Liang Aibin + * + * HISTORY: Created 23.8.2008 + * + **********************************************************************/ + +#include "Exception.h" +#include "Cartoon.h" +#include "Effect.h" + +using namespace ive; + +void Cartoon::write(DataOutputStream* out){ + // Write Cartoon's identification. + out->writeInt(IVECARTOON); + // If the osg class is inherited by any other class we should also write this to file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->write(out); + } + else + throw Exception("Cartoon::write(): Could not cast this osgFX::Cartoon to an osgFX::Effect."); + + // Write Cartoon's properties. + out->writeVec4(getOutlineColor()); + out->writeFloat(getOutlineLineWidth()); + out->writeInt(getLightNumber()); +} + +void Cartoon::read(DataInputStream* in){ + // Peek on Cartoon's identification. + int id = in->peekInt(); + if(id == IVECARTOON){ + // Read Cartoon's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->read(in); + } + else + throw Exception("Cartoon::read(): Could not cast this osgFX::Cartoon to an osgFX::Effect."); + + // Read Cartoon's properties + setOutlineColor(in->readVec4()); + setOutlineLineWidth(in->readFloat()); + setLightNumber(in->readInt()); + } + else{ + throw Exception("Cartoon::read(): Expected Cartoon identification."); + } +} diff --git a/src/osgPlugins/ive/Cartoon.h b/src/osgPlugins/ive/Cartoon.h new file mode 100644 index 000000000..c5ab8aad7 --- /dev/null +++ b/src/osgPlugins/ive/Cartoon.h @@ -0,0 +1,15 @@ +#ifndef IVE_CARTOON +#define IVE_CARTOON 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Cartoon : public osgFX::Cartoon, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 7a34e5d57..9f1b58848 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -87,6 +87,12 @@ #include "VisibilityGroup.h" #include "MultiTextureControl.h" +#include "Effect.h" +#include "AnisotropicLighting.h" +#include "BumpMapping.h" +#include "Cartoon.h" +#include "Scribe.h" +#include "SpecularHighlights.h" #include "Geometry.h" #include "ShapeDrawable.h" @@ -1514,6 +1520,28 @@ osg::Node* DataInputStream::readNode() node = new osgFX::MultiTextureControl(); ((ive::MultiTextureControl*)(node))->read(this); } + + else if(nodeTypeID== IVEANISOTROPICLIGHTING){ + node = new osgFX::AnisotropicLighting(); + ((ive::AnisotropicLighting*)(node))->read(this); + } + else if(nodeTypeID== IVEBUMPMAPPING){ + node = new osgFX::BumpMapping(); + ((ive::BumpMapping*)(node))->read(this); + } + else if(nodeTypeID== IVECARTOON){ + node = new osgFX::Cartoon(); + ((ive::Cartoon*)(node))->read(this); + } + else if(nodeTypeID== IVESCRIBE){ + node = new osgFX::Scribe(); + ((ive::Scribe*)(node))->read(this); + } + else if(nodeTypeID== IVESPECULARHIGHLIGHTS){ + node = new osgFX::SpecularHighlights(); + ((ive::SpecularHighlights*)(node))->read(this); + } + else if(nodeTypeID== IVETERRAINTILE){ node = new osgTerrain::TerrainTile(); ((ive::TerrainTile*)(node))->read(this); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index e5c84e77a..9facf704b 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -87,6 +87,12 @@ #include "VisibilityGroup.h" #include "MultiTextureControl.h" +#include "Effect.h" +#include "AnisotropicLighting.h" +#include "BumpMapping.h" +#include "Cartoon.h" +#include "Scribe.h" +#include "SpecularHighlights.h" #include "Geometry.h" #include "ShapeDrawable.h" @@ -1077,6 +1083,24 @@ void DataOutputStream::writeNode(const osg::Node* node) else if(dynamic_cast(node)){ ((ive::MultiTextureControl*)(node))->write(this); } + + + else if(dynamic_cast(node)){ + ((ive::AnisotropicLighting*)(node))->write(this); + } + else if(dynamic_cast(node)){ + ((ive::BumpMapping*)(node))->write(this); + } + else if(dynamic_cast(node)){ + ((ive::Cartoon*)(node))->write(this); + } + else if(dynamic_cast(node)){ + ((ive::Scribe*)(node))->write(this); + } + else if(dynamic_cast(node)){ + ((ive::SpecularHighlights*)(node))->write(this); + } + else if(dynamic_cast(node)){ ((ive::TerrainTile*)(node))->write(this); } diff --git a/src/osgPlugins/ive/Effect.cpp b/src/osgPlugins/ive/Effect.cpp new file mode 100644 index 000000000..38e6e7662 --- /dev/null +++ b/src/osgPlugins/ive/Effect.cpp @@ -0,0 +1,59 @@ +/********************************************************************** + * + * FILE: Effect.cpp + * + * DESCRIPTION: Read/Write osgFX::Effect in binary format to disk. + * + * CREATED BY: Liang Aibin + * + * HISTORY: Created 23.8.2008 + * + **********************************************************************/ + +#include "Exception.h" +#include "Effect.h" +#include "Group.h" + +using namespace ive; + +void Effect::write(DataOutputStream* out){ + // Write Effect's identification. + out->writeInt(IVEEFFECT); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->write(out); + } + else + throw Exception("Effect::write(): Could not cast this osgFX::Effect to an osg::Group."); + + // Write Effect's properties. + out->writeBool(getEnabled()); + + out->writeInt(getSelectedTechnique()); +} + +void Effect::read(DataInputStream* in){ + // Peek on Effect's identification. + int id = in->peekInt(); + if(id == IVEEFFECT){ + // Read Effect's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group){ + ((ive::Group*)(group))->read(in); + } + else + throw Exception("Effect::read(): Could not cast this osgFX::Effect to an osg::Group."); + + // Read Effect's properties + setEnabled(in->readBool()); + + selectTechnique(in->readInt()); + } + else{ + throw Exception("Effect::read(): Expected Effect identification."); + } +} diff --git a/src/osgPlugins/ive/Effect.h b/src/osgPlugins/ive/Effect.h new file mode 100644 index 000000000..929abf15e --- /dev/null +++ b/src/osgPlugins/ive/Effect.h @@ -0,0 +1,15 @@ +#ifndef IVE_EFFECT +#define IVE_EFFECT 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Effect : public osgFX::Effect, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index b58ace510..d8cb86d41 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -141,6 +141,12 @@ namespace ive { // osgFX classes #define IVEMULTITEXTURECONTROL 0x01000001 +#define IVEEFFECT 0x01000002 +#define IVEANISOTROPICLIGHTING 0x01000003 +#define IVEBUMPMAPPING 0x01000004 +#define IVECARTOON 0x01000005 +#define IVESCRIBE 0x01000006 +#define IVESPECULARHIGHLIGHTS 0x01000007 //osgText classes #define IVETEXT 0x10000001 diff --git a/src/osgPlugins/ive/Scribe.cpp b/src/osgPlugins/ive/Scribe.cpp new file mode 100644 index 000000000..24a7d8276 --- /dev/null +++ b/src/osgPlugins/ive/Scribe.cpp @@ -0,0 +1,57 @@ +/********************************************************************** + * + * FILE: Scribe.cpp + * + * DESCRIPTION: Read/Write osgFX::Scribe in binary format to disk. + * + * CREATED BY: Liang Aibin + * + * HISTORY: Created 23.8.2008 + * + **********************************************************************/ + +#include "Exception.h" +#include "Scribe.h" +#include "Effect.h" + +using namespace ive; + +void Scribe::write(DataOutputStream* out){ + // Write Scribe's identification. + out->writeInt(IVESCRIBE); + // If the osg class is inherited by any other class we should also write this to file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->write(out); + } + else + throw Exception("Scribe::write(): Could not cast this osgFX::Scribe to an osgFX::Effect."); + + // Write Scribe's properties. + out->writeVec4(getWireframeColor()); + out->writeFloat(getWireframeLineWidth()); +} + +void Scribe::read(DataInputStream* in){ + // Peek on Scribe's identification. + int id = in->peekInt(); + if(id == IVESCRIBE){ + // Read Scribe's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->read(in); + } + else + throw Exception("Scribe::read(): Could not cast this osgFX::Scribe to an osgFX::Effect."); + + // Read Scribe's properties + setWireframeColor(in->readVec4()); + setWireframeLineWidth(in->readFloat()); + } + else{ + throw Exception("Scribe::read(): Expected Scribe identification."); + } +} diff --git a/src/osgPlugins/ive/Scribe.h b/src/osgPlugins/ive/Scribe.h new file mode 100644 index 000000000..6964f3be1 --- /dev/null +++ b/src/osgPlugins/ive/Scribe.h @@ -0,0 +1,15 @@ +#ifndef IVE_SCRIBE +#define IVE_SCRIBE 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Scribe : public osgFX::Scribe, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/SpecularHighlights.cpp b/src/osgPlugins/ive/SpecularHighlights.cpp new file mode 100644 index 000000000..452b3327a --- /dev/null +++ b/src/osgPlugins/ive/SpecularHighlights.cpp @@ -0,0 +1,61 @@ +/********************************************************************** + * + * FILE: SpecularHighlights.cpp + * + * DESCRIPTION: Read/Write osgFX::SpecularHighlights in binary format to disk. + * + * CREATED BY: Liang Aibin + * + * HISTORY: Created 23.8.2008 + * + **********************************************************************/ + +#include "Exception.h" +#include "SpecularHighlights.h" +#include "Effect.h" + +using namespace ive; + +void SpecularHighlights::write(DataOutputStream* out){ + // Write SpecularHighlights's identification. + out->writeInt(IVEANISOTROPICLIGHTING); + // If the osg class is inherited by any other class we should also write this to file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->write(out); + } + else + throw Exception("SpecularHighlights::write(): Could not cast this osgFX::SpecularHighlights to an osgFX::Effect."); + + // Write SpecularHighlights's properties. + out->writeInt(getLightNumber()); + out->writeInt(getTextureUnit()); + out->writeVec4(getSpecularColor()); + out->writeFloat(getSpecularExponent()); +} + +void SpecularHighlights::read(DataInputStream* in){ + // Peek on SpecularHighlights's identification. + int id = in->peekInt(); + if(id == IVEANISOTROPICLIGHTING){ + // Read SpecularHighlights's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osgFX::Effect* effect = dynamic_cast(this); + if(effect){ + ((ive::Effect*)(effect))->read(in); + } + else + throw Exception("SpecularHighlights::read(): Could not cast this osgFX::SpecularHighlights to an osgFX::Effect."); + + // Read SpecularHighlights's properties + setLightNumber(in->readInt()); + setTextureUnit(in->readInt()); + setSpecularColor(in->readVec4()); + setSpecularExponent(in->readFloat()); + } + else{ + throw Exception("SpecularHighlights::read(): Expected SpecularHighlights identification."); + } +} diff --git a/src/osgPlugins/ive/SpecularHighlights.h b/src/osgPlugins/ive/SpecularHighlights.h new file mode 100644 index 000000000..919d9814e --- /dev/null +++ b/src/osgPlugins/ive/SpecularHighlights.h @@ -0,0 +1,15 @@ +#ifndef IVE_SPECULARHIGHLIGHTS +#define IVE_SPECULARHIGHLIGHTS 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class SpecularHighlights : public osgFX::SpecularHighlights, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif