Hi,
I am using an API that depends on osg 2.8.1, and have been asked to finally
attempt to upgrade to the latest development release (3.1.1).
The SDK currently makes a few customization to osg, mainly adding user data to
osgPlugins::osg::Node. The following 2 functions are changed in the file:
$OSG/src/osgPlugins/osg/Node.cpp
Code:
#include "osg/AcousticPropertyData.h"
bool Node_readLocalData(Object& obj, Input& fr)
{
...
// change user data to read in acoustic properties
if (fr.matchSequence("user_data {"))
{
int entry = fr[0].getNoNestedBrackets();
fr += 2;
while (!fr.eof() && fr[0].getNoNestedBrackets() > entry)
{
std::string str = fr[0].getStr();
if (str.length()>0)
{
std::string type = str.substr(0,
str.find_first_of(' '));
const char *cStr = str.c_str();
if (type == "RoomData")
{
RoomData* roomData = new RoomData();
char type[256];
int isActive;
sscanf(cStr, "%s %lf %lf %lf %lf %d %ld
%ld %lf %s",
&(type),
&(roomData->m_WetMix),
&(roomData->m_Diffusion),
&(roomData->m_T60Low),
&(roomData->m_T60High),
&(isActive),
&(roomData->m_DefaultPartitionId),
&(roomData->m_DefaultReflectorId),
&(roomData->m_DefaultFlankingBoost),
&(roomData->m_RoomID));
roomData->m_IsActive = (isActive != 0);
node.setUserData(roomData);
}
else if (type == "SurfaceData")
{
SurfaceData* surfaceData = new
SurfaceData();
char type[256];
int isActive;
sscanf(cStr, "%s %lf %lf %lf %lf %d",
&(type),
&(surfaceData->m_ReflectorId),
&(surfaceData->m_PartitionId),
&(surfaceData->m_FlankingBoost),
&(isActive));
surfaceData->m_IsActive = (isActive !=
0);
node.setUserData(surfaceData);
}
++fr;
}
}
iteratorAdvanced = true;
}
...
}
bool Node_writeLocalData(const Object& obj, Output& fw)
{
...
// change user data to become acoustic property
if (!strcmp(node.className(), "Geode") || !strcmp(node.className(),
"Group"))
{
const Referenced* _userData = NULL;
_userData = node.getUserData();
if (_userData)
{
AcousticPropertyData* object = NULL;
object =
dynamic_cast<AcousticPropertyData*>(const_cast< Referenced* >(_userData));
if (object)
{
fw.indent() << "user_data {"<< std::endl;
fw.moveIn();
char tempCStr[2048];
if (object->m_AcousticDataType == kRoomData)
{
RoomData* roomData =
dynamic_cast<RoomData*>(object);
strncpy(roomData->m_RoomID,
node.getName().c_str(), sizeof(roomData->m_RoomID));
sprintf(tempCStr, "%s %lf %lf %lf %lf
%d %d %d %lf %s",
"RoomData",
roomData->m_WetMix,
roomData->m_Diffusion,
roomData->m_T60Low,
roomData->m_T60High,
(roomData->m_IsActive ? 1 : 0),
roomData->m_DefaultPartitionId,
roomData->m_DefaultReflectorId,
roomData->m_DefaultFlankingBoost,
roomData->m_RoomID);
}
else if (object->m_AcousticDataType ==
kSurfaceData)
{
SurfaceData* surfaceData =
dynamic_cast<SurfaceData*>(object);
sprintf(tempCStr, "%s %ld %ld %lf %d",
"SurfaceData",
surfaceData->m_PartitionId,
surfaceData->m_ReflectorId,
surfaceData->m_FlankingBoost,
(surfaceData->m_IsActive ? 1 :
0));
}
std::string str;
str.assign(tempCStr);
fw.indent() << fw.wrapString(str) << std::endl;
fw.moveOut();
fw.indent() << "}"<< std::endl;
}
}
}
...
}
I attached "AccousticPropertyData.h" which basically contains definitions of
the classes "RoomData" and "SurfaceData".
The problem is that in 3.1.1 osgPlugins osg has been deprecated. So using the
above code wouldn't be possible without using deprecated code, which I would
rather not do.
My question is, how can I add user data to osg node? Preferably without making
any changes to osg, but rather through my app/sdk. Any sample that does that?
Thank you!
Cheers,
Tamer
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48855#48855
Attachments:
http://forum.openscenegraph.org//files/acousticpropertydata_209.h
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org