[osg-users] dynamic scenegraph design help

2010-07-29 Thread Eric Pouliquen
Dear All,

 I would like to use dynamic scenegraph in my app, while having the viewer 
running.

 I've read a lot of threads about that, but I just would like to know something 
:

 - I create a complex object with its local scenegraph
 - I need to add the local root of the object somewhere in the scenegraph 
already used by the viewer (running).
 
 I understand that I need to add this object in the SG during the update 
operation. But my problem is that, if my object got an updateCB, this cb will 
be called only if my object is attached to the SG, so I can't do any 
parent-addChild(this) in my CB...

 So here are my questions :

 * Must I create a special case in an updateCB of the node (in the already used 
SG) which is the future parent of my new object ? And then in this CB do the 
addChild(futureChild) ?

* is there any other way to do this properly ?

* when creating the local SG of my object, and if my object is not yet in the 
global SG, can I use securely addChild calls out of any updateCB scope (theses 
calls are only used to create the local SG)? For the moment I understand that 
modifying the used SG out of the update step is not secure, but I also 
understand that I can do this on any local SG which are not yet attached to the 
visited SG, am I right ?

Hope I'm clear in my questions... not easy to sum up ;)

Thanks 
 

Eric

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30393#30393





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] dynamic scenegraph design help

2010-07-29 Thread Tom Pearce
Hi Eric, 

To answer the last question first: if your new local scenegraph isn't attached 
to the scene that the viewer has, you can safely do whatever you want to it - 
that memory isn't being accessed by the viewer, since the viewer doesn't even 
know it exists.

As for the rest, it depends a bit on how you are setting up your application 
and scene.  How are you deciding where in the viewer's scene to add this new 
subgraph?  If you know where it will be (e.g. you have a pointer to the group 
to which you wish to add your new subgraph, either predefined or by picking), 
it would be pretty straightforward to add the new subgraph - 
dynamic_castosg::Group*(yourPtr)-addChild(newRoot) would work.  You just 
need to make sure your viewer isn't accessing the scenegraph at the time.  What 
I do is have a custom viewer loop like so:


Code:
while(!viewer.done())
{
viewer.frame();
if(modificationIsNecessary)
{
viewer.stopThreading();
//modify the scene graph tree
//groupThatGetsNewScene-addChild(newSceneRoot);
viewer.startThreading();
}
}




I've been running something along these lines without problems - whether it's 
the *right* way to do it, I don't know.  If your viewer is running in single 
threaded mode already, just being between frame()s is enough, and the 
stopThreading/startThreading isn't doing anything.  If you want to have an 
update callback in the existing viewer scene, that could probably work too - in 
that case I'd think you would want to make sure the parent node data variance 
is set to dynamic to be safe.  It looks like you have a good idea of how you'd 
go about making that updateCallback already.

Cheers,
Tom[/code]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30398#30398





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org