1 #include <osg/Switch> 2 #include <osg/ValueObject> 3 #include <osgDB/ObjectWrapper> 4 #include <osgDB/InputStream> 5 #include <osgDB/OutputStream> 6 7 struct SwitchGetValue : public osgDB::MethodObject 8 { runSwitchGetValue9 virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const 10 { 11 if (inputParameters.empty()) return false; 12 13 unsigned int index = 0; 14 osg::ValueObject* indexObject = inputParameters[0]->asValueObject(); 15 if (indexObject) indexObject->getScalarValue(index); 16 17 osg::Switch* sw = reinterpret_cast<osg::Switch*>(objectPtr); 18 outputParameters.push_back(new osg::BoolValueObject("return", sw->getValue(index))); 19 20 return true; 21 } 22 }; 23 24 25 struct SwitchSetValue : public osgDB::MethodObject 26 { runSwitchSetValue27 virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const 28 { 29 if (inputParameters.size()<2) return false; 30 31 unsigned int index = 0; 32 osg::ValueObject* indexObject = inputParameters[0]->asValueObject(); 33 if (indexObject) indexObject->getScalarValue(index); 34 35 bool enabled = false; 36 osg::ValueObject* valueObject = inputParameters[1]->asValueObject(); 37 if (valueObject) valueObject->getScalarValue(enabled); 38 39 osg::Switch* sw = reinterpret_cast<osg::Switch*>(objectPtr); 40 sw->setValue(index, enabled); 41 42 return true; 43 } 44 }; 45 46 REGISTER_OBJECT_WRAPPER( Switch, 47 new osg::Switch, 48 osg::Switch, 49 "osg::Object osg::Node osg::Group osg::Switch" ) 50 { 51 ADD_BOOL_SERIALIZER( NewChildDefaultValue, true ); // _newChildDefaultValue 52 ADD_LIST_SERIALIZER( ValueList, osg::Switch::ValueList ); // _values 53 54 ADD_METHOD_OBJECT( "getValue", SwitchGetValue ); 55 ADD_METHOD_OBJECT( "setValue", SwitchSetValue ); 56 } 57