Discussion:
[osg-users] CompositeViewer with multiple view, and scene management
Julien Achard
2018-08-28 13:15:22 UTC
Permalink
Hi All,

I'm struggling with the composite viewer and closing views.

What i need to do :
I have an application that simulate moving planes. I need to allow user to open window(s) on one or more selected plane(s), on demand. The views are camera at the plane position to display the pilot point of view.
So basically, i need a unique scene, with multiple cameras to render differents point of view on this scene in separate windows.
Add / Remove view on the fly.
Update of the scene node position on the fly (planes positions managed by the application).

What i tried :
Creation of a composite viewer, and two views, each one with the same sceneData.
Added the two views to the compositeViewer.
In the run function of a thread class (to avoid blocking my main application), i made a loop to first update my nodes, and then call frame on the composite viewer.

My problem is when i clic on close of one of the view, it is not closed, the refresh in it stops, then i need to clic again to close it. Sometimes i need to clic 3 times.
(on the first clic on close of the last view remaining, the compositeViewer considers he is done, and my thread leave the run loop even if the last view is not totally closed)

Is this the proper way to update the scene nodes during runtime ?

I use OSG 3.6.2 build from source, VS2013, Windows 7.


Code:

MyThread::MyThread() : ost::Thread(),
m_pCompositeViewer(new osgViewer::CompositeViewer()),
m_pRootNode(new osg::Group())
{
//...
//Some node creation in the m_pRootNode
//...

// view one
{
osgViewer::View* view = new osgViewer::View;
view->setName("View one");
m_pCompositeViewer->addView(view);

view->setUpViewInWindow(0, 100, 800, 600);
view->setSceneData(m_pRootNode);
}

// view two
{
osgViewer::View* view = new osgViewer::View;
view->setName("View two");
m_pCompositeViewer->addView(view);

view->setUpViewInWindow(1000, 100, 800, 600);
view->setSceneData(m_pRootNode);
}
}

void MyThread::run()
{
m_pCompositeViewer->realize();
while (!m_pCompositeViewer->done())
{
// ...
// Some update on the nodes of my scene
// ...
m_pCompositeViewer->frame();
}
}



...

Thank you!

Cheers,
Julien

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74613#74613
Julien Achard
2018-08-28 14:48:28 UTC
Permalink
Hi again,

I have reduced the involved code to the minimum.
I put in attachement the sample.

It's a really simple application, and you will see that attemp to call run() (or frame() in a loop) in the run() of the thread will fail.

However, the same code will work outside of the run().

I need to thread this to avoid blocking my main application !

...

Thank you!

Cheers,
Julien

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74615#74615
Robert Osfield
2018-09-03 11:48:43 UTC
Permalink
Hi Jilien,
Post by Julien Achard
I have reduced the involved code to the minimum.
I put in attachement the sample.
It's a really simple application, and you will see that attemp to call run() (or frame() in a loop) in the run() of the thread will fail.
However, the same code will work outside of the run().
I need to thread this to avoid blocking my main application !
Your sample didn't come through. Could you try posting it again, or
posting it online somwhere.

Thanks,
Robert.
Julien Achard
2018-09-03 12:19:52 UTC
Permalink
Hi Robert,

thanks for your time, i forgot the attachement :-*.
I edited my previous post.

...

Thank you!

Cheers,
Julien

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

Loading...