Improved support for setting/getting properties via the osg::UserDataContainer.
This commit is contained in:
parent
e3a003a08f
commit
2797e8cb7c
@ -187,6 +187,15 @@ protected:
|
|||||||
ObjectList _objectList;
|
ObjectList _objectList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** Convinience function for getting the User Object associated with specificed name from an Object's UserDataContainer.*/
|
||||||
|
inline Object* getUserObject(osg::Object* object, const std::string& name)
|
||||||
|
{
|
||||||
|
osg::UserDataContainer* udc = object->getUserDataContainer();
|
||||||
|
return udc ? udc->getUserObject(name) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -247,13 +247,38 @@ typedef osg::Object* ObjectPtr;
|
|||||||
template<>
|
template<>
|
||||||
inline bool PropertyInterface::getProperty(const osg::Object* object, const std::string& propertyName, ObjectPtr& value)
|
inline bool PropertyInterface::getProperty(const osg::Object* object, const std::string& propertyName, ObjectPtr& value)
|
||||||
{
|
{
|
||||||
return copyPropertyObjectFromObject(object, propertyName, &value, sizeof(ObjectPtr), getTypeEnum<ObjectPtr>());
|
if (copyPropertyObjectFromObject(object, propertyName, &value, sizeof(ObjectPtr), getTypeEnum<ObjectPtr>())) return true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"PropertyInterface::getProperty("<<propertyName<<", "<<value->className()<<") Checking UserDataContainer for object ptr"<<std::endl;
|
||||||
|
const osg::UserDataContainer* udc = object->getUserDataContainer();
|
||||||
|
if (udc)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<" Checking UserDataContainer for object ptr"<<std::endl;
|
||||||
|
const osg::Object* ptr = udc->getUserObject(propertyName);
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
value = const_cast<ObjectPtr>(ptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline bool PropertyInterface::setProperty(osg::Object* object, const std::string& propertyName, const ObjectPtr& value)
|
inline bool PropertyInterface::setProperty(osg::Object* object, const std::string& propertyName, const ObjectPtr& value)
|
||||||
{
|
{
|
||||||
return copyPropertyObjectToObject(object, propertyName, &value, sizeof(ObjectPtr), getTypeEnum<ObjectPtr>());
|
if (copyPropertyObjectToObject(object, propertyName, &value, sizeof(ObjectPtr), getTypeEnum<ObjectPtr>())) return true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"PropertyInterface::setProperty("<<propertyName<<", "<<value->className()<<") Adding object to UserDataContainer"<<std::endl;
|
||||||
|
// fallback to using user data to store property data
|
||||||
|
osg::UserDataContainer* udc = object->getOrCreateUserDataContainer();
|
||||||
|
value->setName(propertyName);
|
||||||
|
udc->addUserObject(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,18 @@ osgDB::BaseSerializer* PropertyInterface::getSerializer(const osg::Object* objec
|
|||||||
osg::Object* PropertyInterface::createObject(const std::string& compoundClassName) const
|
osg::Object* PropertyInterface::createObject(const std::string& compoundClassName) const
|
||||||
{
|
{
|
||||||
osgDB::ObjectWrapper* ow = osgDB::Registry::instance()->getObjectWrapperManager()->findWrapper(compoundClassName);
|
osgDB::ObjectWrapper* ow = osgDB::Registry::instance()->getObjectWrapperManager()->findWrapper(compoundClassName);
|
||||||
return (ow!=0) ? ow->createInstance() : 0;
|
if (ow)
|
||||||
|
{
|
||||||
|
osg::Object* object = ow->createInstance();
|
||||||
|
OSG_NOTICE<<"PropertyInterface::createObject("<<compoundClassName<<"), wrapper found, created object="<<object<<std::endl;
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"PropertyInterface::createObject("<<compoundClassName<<"), No object wrapper avaiable."<<std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// return (ow!=0) ? ow->createInstance() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PropertyInterface::copyPropertyDataFromObject(const osg::Object* object, const std::string& propertyName, void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType)
|
bool PropertyInterface::copyPropertyDataFromObject(const osg::Object* object, const std::string& propertyName, void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType)
|
||||||
@ -366,7 +377,7 @@ bool PropertyInterface::copyPropertyDataToObject(osg::Object* object, const std:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OSG_INFO<<"PropertyInterface::copyPropertyDataFromObject() no serializer available."<<std::endl;
|
OSG_NOTICE<<"PropertyInterface::copyPropertyDataFromObject() no serializer available."<<std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,7 +400,7 @@ bool PropertyInterface::copyPropertyObjectFromObject(const osg::Object* object,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OSG_INFO<<"PropertyInterface::copyPropertyObjectFromObject() no serializer available."<<std::endl;
|
OSG_NOTICE<<"PropertyInterface::copyPropertyObjectFromObject() no serializer available."<<std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,6 +537,8 @@ public:
|
|||||||
|
|
||||||
int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string& propertyName) const
|
int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string& propertyName) const
|
||||||
{
|
{
|
||||||
|
OSG_NOTICE<<"LuaScriptEngine::pushPropertyToStack("<<object<<", "<<propertyName<<")"<<std::endl;
|
||||||
|
|
||||||
osgDB::BaseSerializer::Type type;
|
osgDB::BaseSerializer::Type type;
|
||||||
if (!_pi.getPropertyType(object, propertyName, type))
|
if (!_pi.getPropertyType(object, propertyName, type))
|
||||||
{
|
{
|
||||||
@ -549,15 +551,20 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string&
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::CallbackObject* co = osg::getCallbackObject(object, propertyName);
|
osg::Object* uo = osg::getUserObject(object, propertyName);
|
||||||
LuaCallbackObject* lco = dynamic_cast<LuaCallbackObject*>(co);
|
LuaCallbackObject* lco = dynamic_cast<LuaCallbackObject*>(uo);
|
||||||
if (lco)
|
if (lco)
|
||||||
{
|
{
|
||||||
lua_rawgeti(_lua, LUA_REGISTRYINDEX, lco->getRef());
|
lua_rawgeti(_lua, LUA_REGISTRYINDEX, lco->getRef());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
else if (uo)
|
||||||
|
{
|
||||||
|
pushObject(uo);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
OSG_INFO<<"LuaScriptEngine::pushPropertyToStack("<<object<<", "<<propertyName<<") no property found."<<std::endl;
|
OSG_NOTICE<<"LuaScriptEngine::pushPropertyToStack("<<object<<", "<<propertyName<<") no property found."<<std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user