From 28c36d615b55f2282b02bc1c64f2a48a08509b5c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 21 May 2014 09:07:25 +0000 Subject: [PATCH] Added osg::runNamedCallbackObjects(..) convinience method for run all named osg::CallbackObjects attached to an osg::Object --- include/osg/ScriptEngine | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/osg/ScriptEngine b/include/osg/ScriptEngine index 85e5b97f5..3fa81a954 100644 --- a/include/osg/ScriptEngine +++ b/include/osg/ScriptEngine @@ -84,6 +84,27 @@ inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& return udc ? dynamic_cast(udc->getUserObject(name)) : 0; } +/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/ +inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters) +{ + bool result = false; + osg::UserDataContainer* udc = object->getUserDataContainer(); + if (udc) + { + for(unsigned int i = 0; igetNumUserObjects(); ++i) + { + osg::Object* obj = udc->getUserObject(i); + if (obj && obj->getName()==name) + { + osg::CallbackObject* co = dynamic_cast(obj); + if (co) result = co->run(object, inputParameters, outputParameters) | result; + } + } + } + + return result; +} + /** NodeCallback for attaching a script to a NodeCallback so that it can be called as an update or event callback.*/ class OSG_EXPORT ScriptNodeCallback : public osg::NodeCallback {