From 8ae971bdaa5c1b5b5c875b09dafd95e220ba568d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 6 Jan 2014 16:58:07 +0000 Subject: [PATCH] Added Group::setChild(..) and Geode::setDrawable(..) MethodObjects --- src/osgWrappers/serializers/osg/Geode.cpp | 31 +++++++++++++++++++++++ src/osgWrappers/serializers/osg/Group.cpp | 29 +++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/osgWrappers/serializers/osg/Geode.cpp b/src/osgWrappers/serializers/osg/Geode.cpp index 0c7614083..e9f3c3ee9 100644 --- a/src/osgWrappers/serializers/osg/Geode.cpp +++ b/src/osgWrappers/serializers/osg/Geode.cpp @@ -36,6 +36,7 @@ static bool writeDrawables( osgDB::OutputStream& os, const osg::Geode& node ) os << os.END_BRACKET << std::endl; return true; } + struct GeodeGetNumDrawables : public osgDB::MethodObject { virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const @@ -64,6 +65,35 @@ struct GeodeGetDrawable : public osgDB::MethodObject } }; + +struct GeodeSetDrawable : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + { + if (inputParameters.size()<2) return false; + + osg::Object* indexObject = inputParameters[0].get(); + OSG_NOTICE<<"GeodeSetChild "<className()<(indexObject); + if (dvo) index = static_cast(dvo->getValue()); + else + { + osg::UIntValueObject* uivo = dynamic_cast(indexObject); + if (uivo) index = uivo->getValue(); + } + + osg::Drawable* child = dynamic_cast(inputParameters[1].get()); + if (!child) return false; + + osg::Geode* geode = reinterpret_cast(objectPtr); + geode->setDrawable(index, child); + + return true; + } +}; + struct GeodeAddDrawable : public osgDB::MethodObject { virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const @@ -106,6 +136,7 @@ REGISTER_OBJECT_WRAPPER( Geode, ADD_METHOD_OBJECT( "getNumDrawables", GeodeGetNumDrawables ); ADD_METHOD_OBJECT( "getDrawable", GeodeGetDrawable ); + ADD_METHOD_OBJECT( "setDrawable", GeodeSetDrawable ); ADD_METHOD_OBJECT( "addDrawable", GeodeAddDrawable ); ADD_METHOD_OBJECT( "removeDrawable", GeodeRemoveDrawable ); } diff --git a/src/osgWrappers/serializers/osg/Group.cpp b/src/osgWrappers/serializers/osg/Group.cpp index 237db2ed6..e3592ef14 100644 --- a/src/osgWrappers/serializers/osg/Group.cpp +++ b/src/osgWrappers/serializers/osg/Group.cpp @@ -68,6 +68,34 @@ struct GroupGetChild : public osgDB::MethodObject } }; +struct GroupSetChild : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + { + if (inputParameters.size()<2) return false; + + osg::Object* indexObject = inputParameters[0].get(); + OSG_NOTICE<<"GroupSetChild "<className()<(indexObject); + if (dvo) index = static_cast(dvo->getValue()); + else + { + osg::UIntValueObject* uivo = dynamic_cast(indexObject); + if (uivo) index = uivo->getValue(); + } + + osg::Node* child = dynamic_cast(inputParameters[1].get()); + if (!child) return false; + + osg::Group* group = reinterpret_cast(objectPtr); + group->setChild(index, child); + + return true; + } +}; + struct GroupAddChild : public osgDB::MethodObject { virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const @@ -110,6 +138,7 @@ REGISTER_OBJECT_WRAPPER( Group, ADD_METHOD_OBJECT( "getNumChildren", GroupGetNumChildren ); ADD_METHOD_OBJECT( "getChild", GroupGetChild ); + ADD_METHOD_OBJECT( "setChild", GroupSetChild ); ADD_METHOD_OBJECT( "addChild", GroupAddChild ); ADD_METHOD_OBJECT( "removeChild", GroupRemoveChild ); }