#include #include #include #include #include #include static bool checkDrawables( const osg::Geode& node ) { return node.getNumDrawables()>0; } static bool readDrawables( osgDB::InputStream& is, osg::Geode& node ) { unsigned int size = 0; is >> size >> is.BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); if ( drawable ) { node.addDrawable( drawable ); } } is >> is.END_BRACKET; return true; } static bool writeDrawables( osgDB::OutputStream& os, const osg::Geode& node ) { unsigned int size = node.getNumDrawables(); os << size << os.BEGIN_BRACKET << std::endl; for ( unsigned int i=0; i(objectPtr); outputParameters.push_back(new osg::UIntValueObject("return", geode->getNumDrawables())); return true; } }; struct GeodeGetDrawable : public osgDB::MethodObject { virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const { if (inputParameters.empty()) return false; osg::Object* indexObject = inputParameters[0].get(); osg::UIntValueObject* uivo = dynamic_cast(indexObject); if (!uivo) return false; osg::Geode* geode = reinterpret_cast(objectPtr); outputParameters.push_back(geode->getDrawable(uivo->getValue())); return true; } }; struct GeodeAddDrawable : public osgDB::MethodObject { virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const { if (inputParameters.empty()) return false; osg::Drawable* child = dynamic_cast(inputParameters[0].get()); if (!child) return false; osg::Geode* geode = reinterpret_cast(objectPtr); geode->addDrawable(child); return true; } }; struct GeodeRemoveDrawable : public osgDB::MethodObject { virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const { if (inputParameters.empty()) return false; osg::Drawable* child = dynamic_cast(inputParameters[0].get()); if (!child) return false; osg::Geode* geode = reinterpret_cast(objectPtr); geode->removeDrawable(child); return true; } }; REGISTER_OBJECT_WRAPPER( Geode, new osg::Geode, osg::Geode, "osg::Object osg::Node osg::Geode" ) { ADD_USER_SERIALIZER( Drawables ); // _drawables ADD_METHOD_OBJECT( "getNumDrawables", GeodeGetNumDrawables ); ADD_METHOD_OBJECT( "getDrawable", GeodeGetDrawable ); ADD_METHOD_OBJECT( "addDrawable", GeodeAddDrawable ); ADD_METHOD_OBJECT( "removeDrawable", GeodeRemoveDrawable ); }