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 

How to access the view parameters from which the Cull Visitor came?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Miguel
Guest





PostPosted: Fri Sep 22, 2017 5:31 pm    Post subject:
How to access the view parameters from which the Cull Visitor came?
Reply with quote

Hi!

I have a multi-view app (using CompositeViewer) in which some nodes should look differently in different views. For example, some label positions should be recalculated depending on the view's camera parameters and some annotations (rectangular area with a border some text) should be visible or hidden depending on the view scale.

I am trying to override

void GraticuleNode::traverse(osg::NodeVisitor& nv)

and check if the visitor is osg::NodeVisitor::CULL_VISITOR

if it is, I change child required parameters of child nodes, and make them visible or not with

setNodeMask(visible ? 0x2 : 0);

I am new to OSG and I am not sure I am doing everything correctly and its not clear for me, how to access View parameters here ( in traverse(...) ). In particular, I need:

1) to access view width and height in pixels (Viewport in pixels) and pass them to a specific node shader as uniforms,

2) Check some View attributes depending on which I show or hide the child nodes. I set the View attributes when I create the osgViewer::View, for example, there is an attribute determining if the View is Primary (Main) or Secondary (Zoom).

Vasiliy.


------------------
Post generated by Mail2Forum
Back to top
scrawl
Appreciator


Joined: 14 Dec 2014
Posts: 175

PostPosted: Mon Oct 02, 2017 8:51 pm    Post subject:
Reply with quote

Hi Miguel,

Overriding traverse() is possible, it's also possible to add a callback via node->addCullCallback(myCallback) which is essentially the same just via a callback object that can be reused for multiple nodes (of possibly different types). I would usually go with callbacks as they are a little more flexible but both methods are fine. From there if it's a cull visitor you can just cast it:

Code:

osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv)

and get all the info you need from the CullVisitor, its Camera, etc.

It should be noted that OSG can (but does not by default) run culling for multiple cameras simultaneously, with the CullThreadPerCamera threading mode. If this is the case, making modifications to a subgraph like setNodeMask(), changing uniform's etc. is going to create race conditions. This can be worked around by not modifying the scene graph with your changes, but instead push them onto the active CullVisitor only (e.g. by pushing a StateSet with new state, or push a new ModelViewMatrix - have a look at the CullVisitor's push/popStateSet and push/PopModelViewMatrix). I would argue this is the cleaner way in any case, as the act of viewing a scene should not fundamentally change it (unless we're talking about quantum mechanics Wink ).

Quote:

1) to access view width and height in pixels (Viewport in pixels) and pass them to a specific node shader as uniforms,

This part is easy - the CullVisitor has the Camera and the Camera has a Viewport.

Quote:

2) Check some View attributes depending on which I show or hide the child nodes. I set the View attributes when I create the osgViewer::View, for example, there is an attribute determining if the View is Primary (Main) or Secondary (Zoom).

As far as I remember, the osgViewer::View isn't directly exposed from the CullVisitor or the Camera because the core OSG is not dependent on the osgViewer component. You might be able to use dynamic_cast's to get at the View regardless, but I'd suggest try using masks instead to differentiate views (e.g. the Camera's CullMask).

Hope this helps,

Cheers,
Jannik
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 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 Do not cull inactive culling drawables Mathieu Submission 0 Fri Dec 01, 2017 3:50 pm View latest post
No new posts When gets the view matrix of a camera... wernerM General 2 Sat Nov 18, 2017 4:08 pm View latest post
No new posts Access to gl context psquare General 2 Fri Nov 10, 2017 1:32 pm View latest post
No new posts How to set field of view of second sl... kefaline General [forum] 2 Wed Oct 04, 2017 1:29 pm View latest post
No new posts access to viewer instances in plugins Ralf Habacker General 2 Wed Aug 16, 2017 7:32 am 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