OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

add/remove nodes when rendering


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum]
View previous topic :: View next topic  
Author Message
SophieAude
Newbie


Joined: 08 Mar 2015
Posts: 7

PostPosted: Tue Apr 14, 2015 7:56 am    Post subject:
add/remove nodes when rendering
Reply with quote

Hi,

I work on a project for witch I need to remove/add nodes while OpenSceneGraph is rendering.
I created a rendering window with OpenScenegraph and then I would like to be able to load/unload objects in it.
I make the calls for OSG frame() function inside a draw function and I use a singleton to manage the creation of the viewer. That way I managed to have a single viewer and then load my OpenSceneGraph objects inside that same viewer.
It seems fine but the problem is that I have to set camera and viewer parameters each time I call frame(). If I don't nothing is displayed, except OSG font colour.
Ideally I would like to set the viewer parameters only when I load an OSG object for the first time.

Currently when I load an OSG object I use my singleton to find the viewer and to add the loaded node to the root associated to my viewer.
instance()->find_or_create_viewer(); //creates a viewer if none have been created yet
instance()->addChild(loadedNode);
viewer_ = instance()->viewer(); // return a pointer to the unique osgViewer::Viewer

In my draw function I have to do the following :
viewer_->setUpViewerAsEmbeddedInWindow(viewParams[0],viewParams[1],viewParams[2] ,viewParams[3]);
viewer_->getCamera()->setProjectionMatrix( osg::Matrix(glMat_projection) );
viewer_->getCamera()->setViewMatrix( osg::Matrix(glMat_modelview) );
viewer_->frame();

I have read that for dynamical rendering there was something to do about object's variance so I tried a few things but I didn't find how to solve my problem.

Thank you!

Cheers,
Sophie
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10781

PostPosted: Tue Apr 14, 2015 8:36 am    Post subject:
add/remove nodes when rendering
Reply with quote

Hi Sophie,


Are you simply looking to load databases in a background thread whilst the main thread and rendering threads get on with update, culling and rendering the scene?


The OSG has an database paging class call osgDB::DatabasePager that is built into the osgViewer::Viewer/CompositeViewer that will automatically load databases and merge them with the main scene graph during the update traversal.  This is built around the osg::PagedLOD class, but you can also use the osg::ProxyNode.


Robert.





On 14 April 2015 at 08:57, Sophie Audonneau < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi,

I work on a project for witch I need to remove/add nodes while OpenSceneGraph is rendering.
I created a rendering window with OpenScenegraph and then I would like to be able to load/unload objects in it.
I make the calls for OSG frame() function inside a draw function and I use a singleton to manage the creation of the viewer. That way I managed to have a single viewer and then load my OpenSceneGraph objects inside that same viewer.
It seems fine but the problem is that I have to set camera and viewer parameters each time I call frame(). If I don't nothing is displayed, except OSG font colour.
Ideally I would like to set the viewer parameters only when I load an OSG object for the first time.

Currently when I load an OSG object I use my singleton to find the viewer and to add the loaded node to the root associated to my viewer.
instance()->find_or_create_viewer(); //creates a viewer if none have been created yet
instance()->addChild(loadedNode);
viewer_ = instance()->viewer(); // return a pointer to the unique osgViewer::Viewer

In my draw function I have to do the following :
viewer_->setUpViewerAsEmbeddedInWindow(viewParams[0],viewParams[1],viewParams[2] ,viewParams[3]);
viewer_->getCamera()->setProjectionMatrix( osg::Matrix(glMat_projection) );
viewer_->getCamera()->setViewMatrix( osg::Matrix(glMat_modelview) );
viewer_->frame();

I have read that for dynamical rendering there was something to do about object's variance so I tried a few things but I didn't find how to solve my problem.

Thank you!

Cheers,
Sophie

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





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Jan Ciger
Guest





PostPosted: Tue Apr 14, 2015 9:00 am    Post subject:
add/remove nodes when rendering
Reply with quote

Hello,


On Tue, Apr 14, 2015 at 9:57 AM, Sophie Audonneau < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
In my draw function I have to do the following :
viewer_->setUpViewerAsEmbeddedInWindow(viewParams[0],viewParams[1],viewParams[2] ,viewParams[3]);
viewer_->getCamera()->setProjectionMatrix( osg::Matrix(glMat_projection) );
viewer_->getCamera()->setViewMatrix( osg::Matrix(glMat_modelview) );
viewer_->frame();



You are not supposed to do this on every frame, unless you are changing them all time. Are you doing some sort of augmented reality where they are provided by the tracking system? In a typical OSG application the matrices are typically set only once (or not at all - use the default!), the view matrix is often driven using a camera manipulator. The only thing you should do periodically is viewer_->frame().


I think your problem is that you are calling setUpViewerAsEmbeddedInWindow() on every frame - this sets the viewer up from scratch each time. There is no need to do that - you do it only once when you are creating the window.

Please, have a look at the examples that ship with OSG. They show how to use OSG and how to integrate it with other libraries (which is what I assume you are doing, since you are calling setUpViewerAsEmbeddedInWindow() yourself).


Re adding/removing nodes - that is perfectly fine, just do it before or after running the viewer_->frame() call, not in some sort of callback or separate thread.


J.

------------------
Post generated by Mail2Forum
Back to top
SophieAude
Newbie


Joined: 08 Mar 2015
Posts: 7

PostPosted: Tue Apr 14, 2015 2:15 pm    Post subject:
Reply with quote

Thank you both for your answers !

Robert :

Having databases in the background could be a good solution, I had not thought about it. However I have looked at the functioning of osgDB::DatabasePager but as I'm not very familiar with its use I can't see clearly how it could be incorporated in my application.
I currently ask the user to specify which files he wants to load (through a file browser) and then use readNodeFile to get the osg::Nodes associated to each file. From what I saw, in the DatabasePager, readNode is called internally from the filecache and I don't really see how it can be integrated. To remove/hide specified data from the scenegraph is it necessary to specify an expiryTime or is it possible to point out the node that must be remove (as in removeChild(osg::Node*)) ? I didn't find a lot of examples of use of the DatabasePager, do you think of one I could use to gain a better understanding of that tool ?


Jan :

OpenSceneGraph is actually included in another application, which have its own openGl parameters that's why I get back some view parameters and matrices.
At first I called setUpViewerAsEmbeddedInWindow and getCamera inside the singleton when I created the viewer as it seemed logical but it didn't work. I tried several configurations and surprisingly realised that with those calls at each frame() it seemed to work properly (at least I can load several files and display them in my viewer) but I don't understand why it works that way and it is obviously not very efficient.


Thanks,

Sophie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Polygon Rendering bhanu406 General 1 Thu Mar 16, 2017 9:18 am View latest post
No new posts About separate rendering of a slave c... wernerM General 0 Tue Mar 07, 2017 3:14 pm View latest post
No new posts Slow down with shared nodes Andre Normann General 18 Tue Mar 07, 2017 8:24 am View latest post
No new posts How to handle cameras in the scene gr... wernerM General 7 Fri Feb 24, 2017 4:47 pm View latest post
No new posts Multi thread Rendering robertosfield General 1 Thu Jan 19, 2017 1:19 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP