From 87a2a282be5463edd7f0b4dbd9370a65858f4dae Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 16 Aug 2004 13:54:40 +0000 Subject: [PATCH] From Michael Gronager, addition of NodeCallback support in .osg format. --- VisualStudio/osgPlugins/osg/dot_osg.dsp | 4 ++ src/osgPlugins/osg/GNUmakefile | 1 + src/osgPlugins/osg/NodeCallback.cpp | 56 +++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/osgPlugins/osg/NodeCallback.cpp diff --git a/VisualStudio/osgPlugins/osg/dot_osg.dsp b/VisualStudio/osgPlugins/osg/dot_osg.dsp index c2784b4ae..7dad7ac30 100755 --- a/VisualStudio/osgPlugins/osg/dot_osg.dsp +++ b/VisualStudio/osgPlugins/osg/dot_osg.dsp @@ -232,6 +232,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\Node.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\osg\NodeCallback.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\osg\Object.cpp # End Source File # Begin Source File diff --git a/src/osgPlugins/osg/GNUmakefile b/src/osgPlugins/osg/GNUmakefile index 5675e2415..18c44d67d 100644 --- a/src/osgPlugins/osg/GNUmakefile +++ b/src/osgPlugins/osg/GNUmakefile @@ -35,6 +35,7 @@ CXXFILES =\ Matrix.cpp\ MatrixTransform.cpp\ Node.cpp\ + NodeCallback.cpp\ Object.cpp\ OccluderNode.cpp\ PagedLOD.cpp\ diff --git a/src/osgPlugins/osg/NodeCallback.cpp b/src/osgPlugins/osg/NodeCallback.cpp new file mode 100644 index 000000000..c01d98781 --- /dev/null +++ b/src/osgPlugins/osg/NodeCallback.cpp @@ -0,0 +1,56 @@ +#include + +#include + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + +bool NodeCallback_readLocalData(osg::Object &obj, osgDB::Input &fr); +bool NodeCallback_writeLocalData(const osg::Object &obj, osgDB::Output &fw); // register the read and write functions with the osgDB::Registry. + +osgDB::RegisterDotOsgWrapperProxy NodeCallback_Proxy +( + new NodeCallback, + "NodeCallback", + "Object NodeCallback", + &NodeCallback_readLocalData, + &NodeCallback_writeLocalData +); + +bool NodeCallback_readLocalData(osg::Object &obj, osgDB::Input &fr) +{ + NodeCallback& nc = dynamic_cast(obj); + if (!(&nc)) return false; + + bool itrAdvanced = false; + + static osg::ref_ptr s_nc = new NodeCallback; + osg::ref_ptr object = fr.readObjectOfType(*s_nc); + if (object.valid()) + { + NodeCallback* ncc = dynamic_cast(object.get()); + if (ncc) nc.setNestedCallback(ncc); + itrAdvanced = true; + } + + return itrAdvanced; +} + +bool NodeCallback_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + const NodeCallback* nc = dynamic_cast(&obj); + if (!nc) return false; + + NodeCallback* nnc = (NodeCallback*) nc; + + if (nnc->getNestedCallback()) + { + fw.writeObject(*(nnc->getNestedCallback())); + } + + return true; +}