From c3611c5875ce1d0825f504e3ec6acf6ec6eeda86 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Dec 2008 16:26:02 +0000 Subject: [PATCH] Added mechanism for registering proxy objects in the .osg plugin in a way that is compatible with static linking. --- examples/osgstaticviewer/osgstaticviewer.cpp | 1 + include/osgDB/Registry | 9 + src/osgPlugins/osg/AlphaFunc.cpp | 2 +- src/osgPlugins/osg/AnimationPath.cpp | 2 +- src/osgPlugins/osg/AutoTransform.cpp | 2 +- src/osgPlugins/osg/Billboard.cpp | 2 +- src/osgPlugins/osg/BlendColor.cpp | 2 +- src/osgPlugins/osg/BlendEquation.cpp | 2 +- src/osgPlugins/osg/BlendFunc.cpp | 4 +- src/osgPlugins/osg/Box.cpp | 81 ++ src/osgPlugins/osg/CMakeLists.txt | 166 ++-- src/osgPlugins/osg/Camera.cpp | 4 +- src/osgPlugins/osg/CameraView.cpp | 2 +- src/osgPlugins/osg/Capsule.cpp | 91 +++ src/osgPlugins/osg/ClearNode.cpp | 4 +- src/osgPlugins/osg/ClipNode.cpp | 2 +- src/osgPlugins/osg/ClipPlane.cpp | 2 +- src/osgPlugins/osg/ClusterCullingCallback.cpp | 2 +- src/osgPlugins/osg/ColorMask.cpp | 2 +- src/osgPlugins/osg/ColorMatrix.cpp | 2 +- src/osgPlugins/osg/CompositeShape.cpp | 75 ++ src/osgPlugins/osg/Cone.cpp | 89 +++ src/osgPlugins/osg/ConvexPlanarOccluder.cpp | 2 +- src/osgPlugins/osg/CoordinateSystemNode.cpp | 2 +- src/osgPlugins/osg/CullFace.cpp | 2 +- src/osgPlugins/osg/Cylinder.cpp | 89 +++ src/osgPlugins/osg/Depth.cpp | 2 +- src/osgPlugins/osg/Drawable.cpp | 5 +- src/osgPlugins/osg/EllipsoidModel.cpp | 2 +- src/osgPlugins/osg/Fog.cpp | 2 +- src/osgPlugins/osg/FragmentProgram.cpp | 2 +- src/osgPlugins/osg/FrontFace.cpp | 2 +- src/osgPlugins/osg/Geode.cpp | 2 +- src/osgPlugins/osg/Geometry.cpp | 2 +- src/osgPlugins/osg/Group.cpp | 2 +- src/osgPlugins/osg/HeightField.cpp | 183 +++++ src/osgPlugins/osg/Image.cpp | 2 +- src/osgPlugins/osg/ImageSequence.cpp | 2 +- src/osgPlugins/osg/LOD.cpp | 2 +- src/osgPlugins/osg/Light.cpp | 2 +- src/osgPlugins/osg/LightModel.cpp | 2 +- src/osgPlugins/osg/LightSource.cpp | 2 +- src/osgPlugins/osg/LineStipple.cpp | 2 +- src/osgPlugins/osg/LineWidth.cpp | 2 +- src/osgPlugins/osg/Material.cpp | 2 +- src/osgPlugins/osg/MatrixTransform.cpp | 4 +- src/osgPlugins/osg/Node.cpp | 3 +- src/osgPlugins/osg/NodeCallback.cpp | 2 +- src/osgPlugins/osg/Object.cpp | 2 +- src/osgPlugins/osg/OccluderNode.cpp | 2 +- src/osgPlugins/osg/OcclusionQueryNode.cpp | 2 +- src/osgPlugins/osg/PagedLOD.cpp | 2 +- src/osgPlugins/osg/Point.cpp | 2 +- src/osgPlugins/osg/PointSprite.cpp | 2 +- src/osgPlugins/osg/PolygonMode.cpp | 2 +- src/osgPlugins/osg/PolygonOffset.cpp | 2 +- .../osg/PositionAttitudeTransform.cpp | 2 +- src/osgPlugins/osg/Program.cpp | 2 +- src/osgPlugins/osg/Projection.cpp | 2 +- src/osgPlugins/osg/ProxyNode.cpp | 2 +- src/osgPlugins/osg/ReaderWriterOSG.cpp | 88 ++- src/osgPlugins/osg/Scissor.cpp | 2 +- src/osgPlugins/osg/Sequence.cpp | 2 +- src/osgPlugins/osg/ShadeModel.cpp | 2 +- src/osgPlugins/osg/Shader.cpp | 2 +- src/osgPlugins/osg/Shape.cpp | 717 ------------------ src/osgPlugins/osg/ShapeDrawable.cpp | 2 +- src/osgPlugins/osg/Sphere.cpp | 69 ++ src/osgPlugins/osg/StateAttribute.cpp | 2 +- src/osgPlugins/osg/StateSet.cpp | 4 +- src/osgPlugins/osg/Stencil.cpp | 2 +- src/osgPlugins/osg/Switch.cpp | 2 +- src/osgPlugins/osg/TessellationHints.cpp | 2 +- src/osgPlugins/osg/TexEnv.cpp | 2 +- src/osgPlugins/osg/TexEnvCombine.cpp | 2 +- src/osgPlugins/osg/TexEnvFilter.cpp | 2 +- src/osgPlugins/osg/TexGen.cpp | 2 +- src/osgPlugins/osg/TexGenNode.cpp | 2 +- src/osgPlugins/osg/TexMat.cpp | 2 +- src/osgPlugins/osg/Texture.cpp | 2 +- src/osgPlugins/osg/Texture1D.cpp | 2 +- src/osgPlugins/osg/Texture2D.cpp | 4 +- src/osgPlugins/osg/Texture3D.cpp | 2 +- src/osgPlugins/osg/TextureCubeMap.cpp | 2 +- src/osgPlugins/osg/TextureRectangle.cpp | 2 +- src/osgPlugins/osg/Transform.cpp | 2 +- src/osgPlugins/osg/Uniform.cpp | 2 +- src/osgPlugins/osg/VertexProgram.cpp | 2 +- src/osgPlugins/osg/Viewport.cpp | 2 +- 89 files changed, 945 insertions(+), 883 deletions(-) create mode 100644 src/osgPlugins/osg/Box.cpp create mode 100644 src/osgPlugins/osg/Capsule.cpp create mode 100644 src/osgPlugins/osg/CompositeShape.cpp create mode 100644 src/osgPlugins/osg/Cone.cpp create mode 100644 src/osgPlugins/osg/Cylinder.cpp create mode 100644 src/osgPlugins/osg/HeightField.cpp delete mode 100644 src/osgPlugins/osg/Shape.cpp create mode 100644 src/osgPlugins/osg/Sphere.cpp diff --git a/examples/osgstaticviewer/osgstaticviewer.cpp b/examples/osgstaticviewer/osgstaticviewer.cpp index f2cbd24ab..623a2a01e 100644 --- a/examples/osgstaticviewer/osgstaticviewer.cpp +++ b/examples/osgstaticviewer/osgstaticviewer.cpp @@ -40,6 +40,7 @@ USE_OSGPLUGIN(ive); USE_OSGPLUGIN(freetype); USE_OSGPLUGIN(osg); +USE_OSGPLUGIN(rgb); USE_OSGPLUGIN(OpenFlight); // include the platform specific GraphicsWindow implementation. diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 586f0372a..e79a727ee 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -697,6 +697,15 @@ struct PluginFunctionProxy extern "C" void osgdb_##ext(void) {} \ static osgDB::RegisterReaderWriterProxy g_proxy_##classname; + +#define USE_DOTOSGWRAPPER(classname) \ + extern "C" void dotosgwrapper_##classname(void); \ + static osgDB::PluginFunctionProxy proxy_dotosgwrapper_##classname(dotosgwrapper_##classname); + +#define REGISTER_DOTOSGWRAPPER(classname) \ + extern "C" void dotosgwrapper_##classname(void) {} \ + static osgDB::RegisterDotOsgWrapperProxy dotosgwrapper_proxy_##classname + } #endif diff --git a/src/osgPlugins/osg/AlphaFunc.cpp b/src/osgPlugins/osg/AlphaFunc.cpp index 05fd236e4..cc97659f7 100644 --- a/src/osgPlugins/osg/AlphaFunc.cpp +++ b/src/osgPlugins/osg/AlphaFunc.cpp @@ -14,7 +14,7 @@ bool AlphaFunc_matchFuncStr(const char* str,AlphaFunc::ComparisonFunction& func) const char* AlphaFunc_getFuncStr(AlphaFunc::ComparisonFunction func); // register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_AlphaFuncProxy +REGISTER_DOTOSGWRAPPER(AlphaFunc) ( new osg::AlphaFunc, "AlphaFunc", diff --git a/src/osgPlugins/osg/AnimationPath.cpp b/src/osgPlugins/osg/AnimationPath.cpp index 767103f29..5af82eaba 100644 --- a/src/osgPlugins/osg/AnimationPath.cpp +++ b/src/osgPlugins/osg/AnimationPath.cpp @@ -17,7 +17,7 @@ bool AnimationPath_writeLocalData(const osg::Object &obj, osgDB::Output &fw); // register the read and write functions with the osgDB::Registry. -osgDB::RegisterDotOsgWrapperProxy AnimationPath_Proxy +REGISTER_DOTOSGWRAPPER(AnimationPath) ( new osg::AnimationPath, "AnimationPath", diff --git a/src/osgPlugins/osg/AutoTransform.cpp b/src/osgPlugins/osg/AutoTransform.cpp index f37cb663c..0270bc1fb 100644 --- a/src/osgPlugins/osg/AutoTransform.cpp +++ b/src/osgPlugins/osg/AutoTransform.cpp @@ -13,7 +13,7 @@ bool AutoTransform_readLocalData(Object& obj, Input& fr); bool AutoTransform_writeLocalData(const Object& obj, Output& fw); // register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_AutoTransformProxy +REGISTER_DOTOSGWRAPPER(AutoTransform) ( new osg::AutoTransform, "AutoTransform", diff --git a/src/osgPlugins/osg/Billboard.cpp b/src/osgPlugins/osg/Billboard.cpp index 82fbb226e..d5be5396e 100644 --- a/src/osgPlugins/osg/Billboard.cpp +++ b/src/osgPlugins/osg/Billboard.cpp @@ -12,7 +12,7 @@ bool Billboard_readLocalData(Object& obj, Input& fr); bool Billboard_writeLocalData(const Object& obj, Output& fw); // register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_BillboardProxy +REGISTER_DOTOSGWRAPPER(Billboard) ( new osg::Billboard, "Billboard", diff --git a/src/osgPlugins/osg/BlendColor.cpp b/src/osgPlugins/osg/BlendColor.cpp index 8ec443198..4158de86c 100644 --- a/src/osgPlugins/osg/BlendColor.cpp +++ b/src/osgPlugins/osg/BlendColor.cpp @@ -14,7 +14,7 @@ bool BlendColor_writeLocalData(const Object& obj, Output& fw); // register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_BlendColorProxy +REGISTER_DOTOSGWRAPPER(BlendColor) ( new osg::BlendColor, "BlendColor", diff --git a/src/osgPlugins/osg/BlendEquation.cpp b/src/osgPlugins/osg/BlendEquation.cpp index 7cde67972..8d889850c 100644 --- a/src/osgPlugins/osg/BlendEquation.cpp +++ b/src/osgPlugins/osg/BlendEquation.cpp @@ -15,7 +15,7 @@ bool BlendEquation_matchModeStr(const char* str,int& mode); const char* BlendEquation_getModeStr(int value); // register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_BlendEquationProxy +REGISTER_DOTOSGWRAPPER(BlendEquation) ( new osg::BlendEquation, "BlendEquation", diff --git a/src/osgPlugins/osg/BlendFunc.cpp b/src/osgPlugins/osg/BlendFunc.cpp index 1e90ef190..d6af1f7d3 100644 --- a/src/osgPlugins/osg/BlendFunc.cpp +++ b/src/osgPlugins/osg/BlendFunc.cpp @@ -16,7 +16,7 @@ const char* BlendFunc_getModeStr(int value); // register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_TransparencyProxy +REGISTER_DOTOSGWRAPPER(Transparency) ( new osg::BlendFunc, "Transparency", @@ -25,7 +25,7 @@ RegisterDotOsgWrapperProxy g_TransparencyProxy &BlendFunc_writeLocalData ); -RegisterDotOsgWrapperProxy g_BlendFuncProxy +REGISTER_DOTOSGWRAPPER(BlendFunc) ( new osg::BlendFunc, "BlendFunc", diff --git a/src/osgPlugins/osg/Box.cpp b/src/osgPlugins/osg/Box.cpp new file mode 100644 index 000000000..870977814 --- /dev/null +++ b/src/osgPlugins/osg/Box.cpp @@ -0,0 +1,81 @@ +#include +#include +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + + +////////////////////////////////////////////////////////////////////////////// +// forward declare functions to use later. +bool Box_readLocalData(Object& obj, Input& fr); +bool Box_writeLocalData(const Object& obj, Output& fw); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(Box) +( + new osg::Box, + "Box", + "Object Box", + &Box_readLocalData, + &Box_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool Box_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + Box& box = static_cast(obj); + + if (fr.matchSequence("Center %f %f %f")) + { + osg::Vec3 center; + fr[1].getFloat(center.x()); + fr[2].getFloat(center.y()); + fr[3].getFloat(center.z()); + box.setCenter(center); + fr+=4; + iteratorAdvanced = true; + } + + if (fr.matchSequence("HalfLengths %f %f %f")) + { + osg::Vec3 lenghts; + fr[1].getFloat(lenghts.x()); + fr[2].getFloat(lenghts.y()); + fr[3].getFloat(lenghts.z()); + box.setHalfLengths(lenghts); + fr+=4; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Rotation %f %f %f %f")) + { + osg::Quat rotation; + fr[1].getFloat(rotation.x()); + fr[2].getFloat(rotation.y()); + fr[3].getFloat(rotation.z()); + fr[4].getFloat(rotation.w()); + box.setRotation(rotation); + fr+=5; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool Box_writeLocalData(const Object& obj, Output& fw) +{ + const Box& box = static_cast(obj); + + fw.indent()<<"Center "< +#include +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + + +////////////////////////////////////////////////////////////////////////////// +// forward declare functions to use later. +bool Capsule_readLocalData(Object& obj, Input& fr); +bool Capsule_writeLocalData(const Object& obj, Output& fw); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(Capsule) +( + new osg::Capsule, + "Capsule", + "Object Capsule", + &Capsule_readLocalData, + &Capsule_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool Capsule_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + Capsule& capsule = static_cast(obj); + + if (fr.matchSequence("Center %f %f %f")) + { + osg::Vec3 center; + fr[1].getFloat(center.x()); + fr[2].getFloat(center.y()); + fr[3].getFloat(center.z()); + capsule.setCenter(center); + fr+=4; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Radius %f")) + { + float radius; + fr[1].getFloat(radius); + capsule.setRadius(radius); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Height %f")) + { + float height; + fr[1].getFloat(height); + capsule.setHeight(height); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Rotation %f %f %f %f")) + { + osg::Quat rotation; + fr[1].getFloat(rotation.x()); + fr[2].getFloat(rotation.y()); + fr[3].getFloat(rotation.z()); + fr[4].getFloat(rotation.w()); + capsule.setRotation(rotation); + fr+=5; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool Capsule_writeLocalData(const Object& obj, Output& fw) +{ + const Capsule& capsule = static_cast(obj); + + fw.indent()<<"Center "< +#include +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + + +////////////////////////////////////////////////////////////////////////////// +// forward declare functions to use later. +bool CompositeShape_readLocalData(Object& obj, Input& fr); +bool CompositeShape_writeLocalData(const Object& obj, Output& fw); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(CompositeShape) +( + new osg::CompositeShape, + "CompositeShape", + "Object CompositeShape", + &CompositeShape_readLocalData, + &CompositeShape_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool CompositeShape_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + CompositeShape& composite = static_cast(obj); + + ref_ptr readObject; + if (fr[0].matchWord("Shape")) + { + readObject = fr.readObject(); + if (readObject.valid()) + { + osg::Shape* shape = dynamic_cast(readObject.get()); + if (shape) composite.setShape(shape); + else notify(WARN)<<"Warning:: "<className()<<" loaded but cannot not be attached to Drawable."<())).valid()) + { + osg::Shape* shape = static_cast(readObject.get()); + composite.addChild(shape); + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool CompositeShape_writeLocalData(const Object& obj, Output& fw) +{ + const CompositeShape& composite = static_cast(obj); + + if (composite.getShape()) + { + fw.indent() << "Shape "; + fw.writeObject(*composite.getShape()); + } + + for(unsigned int i=0;i +#include +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + + +////////////////////////////////////////////////////////////////////////////// +// forward declare functions to use later. +bool Cone_readLocalData(Object& obj, Input& fr); +bool Cone_writeLocalData(const Object& obj, Output& fw); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(Cone) +( + new osg::Cone, + "Cone", + "Object Cone", + &Cone_readLocalData, + &Cone_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool Cone_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + Cone& cone = static_cast(obj); + + if (fr.matchSequence("Center %f %f %f")) + { + osg::Vec3 center; + fr[1].getFloat(center.x()); + fr[2].getFloat(center.y()); + fr[3].getFloat(center.z()); + cone.setCenter(center); + fr+=4; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Radius %f")) + { + float radius; + fr[1].getFloat(radius); + cone.setRadius(radius); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Height %f")) + { + float height; + fr[1].getFloat(height); + cone.setHeight(height); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Rotation %f %f %f %f")) + { + osg::Quat rotation; + fr[1].getFloat(rotation.x()); + fr[2].getFloat(rotation.y()); + fr[3].getFloat(rotation.z()); + fr[4].getFloat(rotation.w()); + cone.setRotation(rotation); + fr+=5; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool Cone_writeLocalData(const Object& obj, Output& fw) +{ + const Cone& cone = static_cast(obj); + + fw.indent()<<"Center "< +#include +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + + +////////////////////////////////////////////////////////////////////////////// +// forward declare functions to use later. +bool Cylinder_readLocalData(Object& obj, Input& fr); +bool Cylinder_writeLocalData(const Object& obj, Output& fw); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(Cylinder) +( + new osg::Cylinder, + "Cylinder", + "Object Cylinder", + &Cylinder_readLocalData, + &Cylinder_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool Cylinder_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + Cylinder& cylinder = static_cast(obj); + + if (fr.matchSequence("Center %f %f %f")) + { + osg::Vec3 center; + fr[1].getFloat(center.x()); + fr[2].getFloat(center.y()); + fr[3].getFloat(center.z()); + cylinder.setCenter(center); + fr+=4; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Radius %f")) + { + float radius; + fr[1].getFloat(radius); + cylinder.setRadius(radius); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Height %f")) + { + float height; + fr[1].getFloat(height); + cylinder.setHeight(height); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Rotation %f %f %f %f")) + { + osg::Quat rotation; + fr[1].getFloat(rotation.x()); + fr[2].getFloat(rotation.y()); + fr[3].getFloat(rotation.z()); + fr[4].getFloat(rotation.w()); + cylinder.setRotation(rotation); + fr+=5; + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool Cylinder_writeLocalData(const Object& obj, Output& fw) +{ + const Cylinder& cylinder = static_cast(obj); + + fw.indent()<<"Center "< +#include +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + + +////////////////////////////////////////////////////////////////////////////// +// forward declare functions to use later. +bool HeightField_readLocalData(Object& obj, Input& fr); +bool HeightField_writeLocalData(const Object& obj, Output& fw); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(HeightField) +( + new osg::HeightField, + "HeightField", + "Object HeightField", + &HeightField_readLocalData, + &HeightField_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(Grid) +( + new osg::HeightField, + "Grid", + "Object HeightField", + 0, + 0, + DotOsgWrapper::READ_AND_WRITE +); + +bool HeightField_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + HeightField& heightfield = static_cast(obj); + + if (fr.matchSequence("Origin %f %f %f")) + { + osg::Vec3 origin; + fr[1].getFloat(origin.x()); + fr[2].getFloat(origin.y()); + fr[3].getFloat(origin.z()); + heightfield.setOrigin(origin); + fr+=4; + } + + if (fr.matchSequence("XInterval %f")) + { + float interval; + fr[1].getFloat(interval); + heightfield.setXInterval(interval); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("YInterval %f")) + { + float interval; + fr[1].getFloat(interval); + heightfield.setYInterval(interval); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("SkirtHeight %f")) + { + float height; + fr[1].getFloat(height); + heightfield.setSkirtHeight(height); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("BorderWidth %i")) + { + unsigned int width; + fr[1].getUInt(width); + heightfield.setBorderWidth(width); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Rotation %f %f %f %f")) + { + osg::Quat rotation; + fr[1].getFloat(rotation.x()); + fr[2].getFloat(rotation.y()); + fr[3].getFloat(rotation.z()); + fr[4].getFloat(rotation.w()); + heightfield.setRotation(rotation); + fr+=5; + iteratorAdvanced = true; + } + + if (fr.matchSequence("NumColumnsAndRows %i %i")) + { + int numcolumns,numrows; + fr[1].getInt(numcolumns); + fr[2].getInt(numrows); + heightfield.allocate(numcolumns,numrows); + fr+=3; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Heights {")) + { + + int entry = fr[0].getNoNestedBrackets(); + + fr += 2; + + float height; + unsigned int row = 0; + unsigned int column = 0; + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + if (fr.readSequence(height)) + { + heightfield.setHeight(column,row,height); + ++column; + if (column>=heightfield.getNumColumns()) + { + column = 0; + ++row; + } + } + else + { + ++fr; + } + } + + iteratorAdvanced = true; + ++fr; + + } + + return iteratorAdvanced; +} + +bool HeightField_writeLocalData(const Object& obj, Output& fw) +{ + const HeightField& heightfield = static_cast(obj); + + int prec = fw.precision(); + fw.precision(15); + fw.indent()<<"Origin "< -#include -#include - -#include -#include -#include - -using namespace osg; -using namespace osgDB; - - -////////////////////////////////////////////////////////////////////////////// - -// forward declare functions to use later. -bool Sphere_readLocalData(Object& obj, Input& fr); -bool Sphere_writeLocalData(const Object& obj, Output& fw); - -//register the read and write functions with the osgDB::Registry. -RegisterDotOsgWrapperProxy g_SphereFuncProxy -( - new osg::Sphere, - "Sphere", - "Object Sphere", - &Sphere_readLocalData, - &Sphere_writeLocalData, - DotOsgWrapper::READ_AND_WRITE -); - -bool Sphere_readLocalData(Object& obj, Input& fr) -{ - bool iteratorAdvanced = false; - - Sphere& sphere = static_cast(obj); - - if (fr.matchSequence("Center %f %f %f")) - { - osg::Vec3 center; - fr[1].getFloat(center.x()); - fr[2].getFloat(center.y()); - fr[3].getFloat(center.z()); - sphere.setCenter(center); - fr+=4; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Radius %f")) - { - float radius; - fr[1].getFloat(radius); - sphere.setRadius(radius); - fr+=2; - iteratorAdvanced = true; - } - - - return iteratorAdvanced; -} - -bool Sphere_writeLocalData(const Object& obj, Output& fw) -{ - const Sphere& sphere = static_cast(obj); - - fw.indent()<<"Center "<(obj); - - if (fr.matchSequence("Center %f %f %f")) - { - osg::Vec3 center; - fr[1].getFloat(center.x()); - fr[2].getFloat(center.y()); - fr[3].getFloat(center.z()); - box.setCenter(center); - fr+=4; - iteratorAdvanced = true; - } - - if (fr.matchSequence("HalfLengths %f %f %f")) - { - osg::Vec3 lenghts; - fr[1].getFloat(lenghts.x()); - fr[2].getFloat(lenghts.y()); - fr[3].getFloat(lenghts.z()); - box.setHalfLengths(lenghts); - fr+=4; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Rotation %f %f %f %f")) - { - osg::Quat rotation; - fr[1].getFloat(rotation.x()); - fr[2].getFloat(rotation.y()); - fr[3].getFloat(rotation.z()); - fr[4].getFloat(rotation.w()); - box.setRotation(rotation); - fr+=5; - iteratorAdvanced = true; - } - - return iteratorAdvanced; -} - -bool Box_writeLocalData(const Object& obj, Output& fw) -{ - const Box& box = static_cast(obj); - - fw.indent()<<"Center "<(obj); - - if (fr.matchSequence("Center %f %f %f")) - { - osg::Vec3 center; - fr[1].getFloat(center.x()); - fr[2].getFloat(center.y()); - fr[3].getFloat(center.z()); - cone.setCenter(center); - fr+=4; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Radius %f")) - { - float radius; - fr[1].getFloat(radius); - cone.setRadius(radius); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Height %f")) - { - float height; - fr[1].getFloat(height); - cone.setHeight(height); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Rotation %f %f %f %f")) - { - osg::Quat rotation; - fr[1].getFloat(rotation.x()); - fr[2].getFloat(rotation.y()); - fr[3].getFloat(rotation.z()); - fr[4].getFloat(rotation.w()); - cone.setRotation(rotation); - fr+=5; - iteratorAdvanced = true; - } - - return iteratorAdvanced; -} - -bool Cone_writeLocalData(const Object& obj, Output& fw) -{ - const Cone& cone = static_cast(obj); - - fw.indent()<<"Center "<(obj); - - if (fr.matchSequence("Center %f %f %f")) - { - osg::Vec3 center; - fr[1].getFloat(center.x()); - fr[2].getFloat(center.y()); - fr[3].getFloat(center.z()); - cylinder.setCenter(center); - fr+=4; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Radius %f")) - { - float radius; - fr[1].getFloat(radius); - cylinder.setRadius(radius); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Height %f")) - { - float height; - fr[1].getFloat(height); - cylinder.setHeight(height); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Rotation %f %f %f %f")) - { - osg::Quat rotation; - fr[1].getFloat(rotation.x()); - fr[2].getFloat(rotation.y()); - fr[3].getFloat(rotation.z()); - fr[4].getFloat(rotation.w()); - cylinder.setRotation(rotation); - fr+=5; - iteratorAdvanced = true; - } - - return iteratorAdvanced; -} - -bool Cylinder_writeLocalData(const Object& obj, Output& fw) -{ - const Cylinder& cylinder = static_cast(obj); - - fw.indent()<<"Center "<(obj); - - if (fr.matchSequence("Center %f %f %f")) - { - osg::Vec3 center; - fr[1].getFloat(center.x()); - fr[2].getFloat(center.y()); - fr[3].getFloat(center.z()); - capsule.setCenter(center); - fr+=4; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Radius %f")) - { - float radius; - fr[1].getFloat(radius); - capsule.setRadius(radius); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Height %f")) - { - float height; - fr[1].getFloat(height); - capsule.setHeight(height); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Rotation %f %f %f %f")) - { - osg::Quat rotation; - fr[1].getFloat(rotation.x()); - fr[2].getFloat(rotation.y()); - fr[3].getFloat(rotation.z()); - fr[4].getFloat(rotation.w()); - capsule.setRotation(rotation); - fr+=5; - iteratorAdvanced = true; - } - - return iteratorAdvanced; -} - -bool Capsule_writeLocalData(const Object& obj, Output& fw) -{ - const Capsule& capsule = static_cast(obj); - - fw.indent()<<"Center "<(obj); - - if (fr.matchSequence("Origin %f %f %f")) - { - osg::Vec3 origin; - fr[1].getFloat(origin.x()); - fr[2].getFloat(origin.y()); - fr[3].getFloat(origin.z()); - heightfield.setOrigin(origin); - fr+=4; - } - - if (fr.matchSequence("XInterval %f")) - { - float interval; - fr[1].getFloat(interval); - heightfield.setXInterval(interval); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("YInterval %f")) - { - float interval; - fr[1].getFloat(interval); - heightfield.setYInterval(interval); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("SkirtHeight %f")) - { - float height; - fr[1].getFloat(height); - heightfield.setSkirtHeight(height); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("BorderWidth %i")) - { - unsigned int width; - fr[1].getUInt(width); - heightfield.setBorderWidth(width); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Rotation %f %f %f %f")) - { - osg::Quat rotation; - fr[1].getFloat(rotation.x()); - fr[2].getFloat(rotation.y()); - fr[3].getFloat(rotation.z()); - fr[4].getFloat(rotation.w()); - heightfield.setRotation(rotation); - fr+=5; - iteratorAdvanced = true; - } - - if (fr.matchSequence("NumColumnsAndRows %i %i")) - { - int numcolumns,numrows; - fr[1].getInt(numcolumns); - fr[2].getInt(numrows); - heightfield.allocate(numcolumns,numrows); - fr+=3; - iteratorAdvanced = true; - } - - if (fr.matchSequence("Heights {")) - { - - int entry = fr[0].getNoNestedBrackets(); - - fr += 2; - - float height; - unsigned int row = 0; - unsigned int column = 0; - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - if (fr.readSequence(height)) - { - heightfield.setHeight(column,row,height); - ++column; - if (column>=heightfield.getNumColumns()) - { - column = 0; - ++row; - } - } - else - { - ++fr; - } - } - - iteratorAdvanced = true; - ++fr; - - } - - return iteratorAdvanced; -} - -bool HeightField_writeLocalData(const Object& obj, Output& fw) -{ - const HeightField& heightfield = static_cast(obj); - - int prec = fw.precision(); - fw.precision(15); - fw.indent()<<"Origin "<(obj); - - ref_ptr readObject; - if (fr[0].matchWord("Shape")) - { - readObject = fr.readObject(); - if (readObject.valid()) - { - osg::Shape* shape = dynamic_cast(readObject.get()); - if (shape) composite.setShape(shape); - else notify(WARN)<<"Warning:: "<className()<<" loaded but cannot not be attached to Drawable."<())).valid()) - { - osg::Shape* shape = static_cast(readObject.get()); - composite.addChild(shape); - iteratorAdvanced = true; - } - - return iteratorAdvanced; -} - -bool CompositeShape_writeLocalData(const Object& obj, Output& fw) -{ - const CompositeShape& composite = static_cast(obj); - - if (composite.getShape()) - { - fw.indent() << "Shape "; - fw.writeObject(*composite.getShape()); - } - - for(unsigned int i=0;i(obj); -// -// return iteratorAdvanced; -// } -// -// bool InfinitePlane_writeLocalData(const Object& obj, Output& fw) -// { -// //const InfinitePlane& infplane = static_cast(obj); -// -// return true; -// } -// -// -// ////////////////////////////////////////////////////////////////////////////// -// -// // forward declare functions to use later. -// bool TriangleMesh_readLocalData(Object& obj, Input& fr); -// bool TriangleMesh_writeLocalData(const Object& obj, Output& fw); -// -// //register the read and write functions with the osgDB::Registry. -// RegisterDotOsgWrapperProxy g_TriangleMeshFuncProxy -// ( -// new osg::TriangleMesh, -// "TriangleMesh", -// "Object ", -// &TriangleMesh_readLocalData, -// &TriangleMesh_writeLocalData, -// DotOsgWrapper::READ_AND_WRITE -// ); -// -// bool TriangleMesh_readLocalData(Object& obj, Input& fr) -// { -// bool iteratorAdvanced = false; -// -// // TriangleMesh& mesh = static_cast(obj); -// -// return iteratorAdvanced; -// } -// -// bool TriangleMesh_writeLocalData(const Object& obj, Output& fw) -// { -// // const TriangleMesh& mesh = static_cast(obj); -// -// return true; -// } -// -// -// ////////////////////////////////////////////////////////////////////////////// -// // forward declare functions to use later. -// bool ConvexHull_readLocalData(Object& obj, Input& fr); -// bool ConvexHull_writeLocalData(const Object& obj, Output& fw); -// -// //register the read and write functions with the osgDB::Registry. -// RegisterDotOsgWrapperProxy g_ConvexHullFuncProxy -// ( -// new osg::ConvexHull, -// "ConvexHull", -// "Object ", -// &ConvexHull_readLocalData, -// &ConvexHull_writeLocalData, -// DotOsgWrapper::READ_AND_WRITE -// ); -// -// bool ConvexHull_readLocalData(Object& obj, Input& fr) -// { -// bool iteratorAdvanced = false; -// -// // ConvexHull& geom = static_cast(obj); -// -// return iteratorAdvanced; -// } -// -// bool ConvexHull_writeLocalData(const Object& obj, Output& fw) -// { -// // const ConvexHull& geom = static_cast(obj); -// -// return true; -// } -// -// - diff --git a/src/osgPlugins/osg/ShapeDrawable.cpp b/src/osgPlugins/osg/ShapeDrawable.cpp index 23f7ff90d..252827a34 100644 --- a/src/osgPlugins/osg/ShapeDrawable.cpp +++ b/src/osgPlugins/osg/ShapeDrawable.cpp @@ -13,7 +13,7 @@ using namespace osgDB; bool ShapeDrawable_readLocalData(Object& obj, Input& fr); bool ShapeDrawable_writeLocalData(const Object& obj, Output& fw); -RegisterDotOsgWrapperProxy g_ShapeDrawableFuncProxy +REGISTER_DOTOSGWRAPPER(ShapeDrawable) ( new osg::ShapeDrawable, "ShapeDrawable", diff --git a/src/osgPlugins/osg/Sphere.cpp b/src/osgPlugins/osg/Sphere.cpp new file mode 100644 index 000000000..0a2b98b93 --- /dev/null +++ b/src/osgPlugins/osg/Sphere.cpp @@ -0,0 +1,69 @@ +#include +#include +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + + +////////////////////////////////////////////////////////////////////////////// + +// forward declare functions to use later. +bool Sphere_readLocalData(Object& obj, Input& fr); +bool Sphere_writeLocalData(const Object& obj, Output& fw); + +//register the read and write functions with the osgDB::Registry. +REGISTER_DOTOSGWRAPPER(Sphere) +( + new osg::Sphere, + "Sphere", + "Object Sphere", + &Sphere_readLocalData, + &Sphere_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool Sphere_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + Sphere& sphere = static_cast(obj); + + if (fr.matchSequence("Center %f %f %f")) + { + osg::Vec3 center; + fr[1].getFloat(center.x()); + fr[2].getFloat(center.y()); + fr[3].getFloat(center.z()); + sphere.setCenter(center); + fr+=4; + iteratorAdvanced = true; + } + + if (fr.matchSequence("Radius %f")) + { + float radius; + fr[1].getFloat(radius); + sphere.setRadius(radius); + fr+=2; + iteratorAdvanced = true; + } + + + return iteratorAdvanced; +} + +bool Sphere_writeLocalData(const Object& obj, Output& fw) +{ + const Sphere& sphere = static_cast(obj); + + fw.indent()<<"Center "<