Re: [osg-users] StateSet UpdateCallback on a camera

2012-07-09 Thread Robert Osfield
Hi Christian,

I have just checked the Viewer::updateTraversal() and associated
UpdateVisitor::handle_callbacks() code and it looks to me like a
StateSet with callbacks attached to a Viewer camera should have it's
callbacks called.  I haven't tested the code though, too many other
tasks to get through I'm afraid.  Perhaps the issue is related to
using an older version of the OSG than the svn/trunk I've just looked
at.

Robert.

On 6 July 2012 14:30, Christian Schulte  wrote:
> Thanks Tim for your response,
>
> I will try your solution with an empty UpdateCallBack for the camera.
> Concerning multiples views in my application, I didn't post my whole code,
> but we are in a class derived from osgViewer::CompositeViewer.
> I understand that Fog and Light are not SceneGraphNodes, but in my case I
> associated my osg::Light to an osg::LightSource whihc is a node, and it is
> this lightSource that I tried to cull, in order to have a view without any
> light.
>
> Thanks,
>
> Christian
>
> Le 06/07/2012 11:46, Tim Moore a écrit :
>
>> Salut,
>>
>> On Fri, Jul 6, 2012 at 10:13 AM, Christian Schulte
>>  wrote:
>>>
>>> Hi everyone,
>>>
>>> I'm facing a problem in our flight simulation environment, where we want
>>> to
>>> make the fog camera dependent ( in order to have cameras without fog for
>>> simulation control). I tried to follow the 2009 thread "[osg-users] Set
>>> fog
>>> in the canera StateSet" and succeded to implement a non variyng fog. But
>>> in
>>> our case we have a statesetcallback for changing the parameter of the fog
>>> and one for activating disactivating the fog.
>>>
>> ...
>>>
>>> But, adding the fog to our different views, neither the
>>> vesaFogUpdateCallback nor the vesaFogEnableUpdateCallback are accessed
>>> anymore... This is the code I tryed to implement :
>>>
>>>  BOOST_FOREACH(propTreeNode & v,
>>> arbreUtile->getOptionalChildProperties("graphic.windows.views"))
>>>  {
>>>  propTreeHolder pView(&v.second);
>>>  if(pView.empty() || v.first.compare("msgFile")==0 ||
>>> v.first.compare("activeView")==0)
>>>  continue;
>>>
>>>  std::string name = v.first;
>>>  osgViewer::View* view = new osgViewer::View;
>>
>> I don't know if this is pseudo-code or not, but generally you don't
>> create more than one Viewer per application; instead you use
>> CompositeViewer or slave cameras in one Viewer. However, if this is
>> working for you, who am I to say different :)
>>>
>>>  view->setName(name);
>>>  addView(view);
>>>  view->setSceneData(root);
>>>  view->getCamera()->setName(name);
>>>  view->getCamera()->setClearColor(fog->getColor());
>>
>> ...
>>>
>>> view->getCamera()->getOrCreateStateSet()->setAttributeAndModes(fog,
>>> osg::StateAttribute::ON);
>>>  fog->setUpdateCallback(new vesaFogUpdateCallback);
>>>
>>> view->getCamera()->getOrCreateStateSet()->setUpdateCallback(new
>>> vesaFogEnableUpdateCallback);
>>>  }
>>>  }
>>>
>>> The solution I found is to create an UpdateCallback for each camera which
>>> implements the code present in both my old Fog callbacks.
>>>
>>> Does anyone have an idea of why the UpdateCallBack of the stateset does
>>> not
>>> work when associated to a camera ? What am I doing wrong ?
>>
>> Viewer only runs an UpdateVisitor on a camera if it has an update
>> callback. This may be a small bug, as you have discovered, as it
>> ignores the possibility that the camera's state set could have update
>> callbacks. I believe you will find that your state set update callback
>> will get run even if you install an empty callback on the camera node.
>>
>> Tim
>>>
>>> Moreover, I initially tried to activate desactivate the osf::Fog, the
>>> osg::Light and the osgParticle::PrecipitationEffect using a
>>> NodeMask/CullMask logic for each camera. It works for the
>>> PrecipitationEffect, but doesn't for the Fog and the Light. Is it a
>>> normal
>>> behaviour or is there something wrong in my code (in which case I would
>>> show
>>> you the code).
>>
>> I'm not sure what you mean, as Fog and Light aren't scene graph nodes.
>> Be sure that any StateAttribute objects have their data variance set
>> to DYNAMIC.
>>
>> Tim
>>>
>>> Thankyou for your help,
>>>
>>> SCHULTE Christian
>>> Research  Engineer
>>> in charge of the Simulation Laboratory
>>> System Control and Flight Dynamics Department
>>> Simulation and Flight Testing Unit
>>> ONERA - The French Aerospace Lab
>>> Ecole de l'Air - BA 701
>>> 13661 SALON cedex AIR
>>> FRANCE
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___

Re: [osg-users] StateSet UpdateCallback on a camera

2012-07-06 Thread Christian Schulte

Thanks Tim for your response,

I will try your solution with an empty UpdateCallBack for the camera.
Concerning multiples views in my application, I didn't post my whole 
code, but we are in a class derived from osgViewer::CompositeViewer.
I understand that Fog and Light are not SceneGraphNodes, but in my case 
I associated my osg::Light to an osg::LightSource whihc is a node, and 
it is this lightSource that I tried to cull, in order to have a view 
without any light.


Thanks,

Christian

Le 06/07/2012 11:46, Tim Moore a écrit :

Salut,

On Fri, Jul 6, 2012 at 10:13 AM, Christian Schulte
 wrote:

Hi everyone,

I'm facing a problem in our flight simulation environment, where we want to
make the fog camera dependent ( in order to have cameras without fog for
simulation control). I tried to follow the 2009 thread "[osg-users] Set fog
in the canera StateSet" and succeded to implement a non variyng fog. But in
our case we have a statesetcallback for changing the parameter of the fog
and one for activating disactivating the fog.


...

But, adding the fog to our different views, neither the
vesaFogUpdateCallback nor the vesaFogEnableUpdateCallback are accessed
anymore... This is the code I tryed to implement :

 BOOST_FOREACH(propTreeNode & v,
arbreUtile->getOptionalChildProperties("graphic.windows.views"))
 {
 propTreeHolder pView(&v.second);
 if(pView.empty() || v.first.compare("msgFile")==0 ||
v.first.compare("activeView")==0)
 continue;

 std::string name = v.first;
 osgViewer::View* view = new osgViewer::View;

I don't know if this is pseudo-code or not, but generally you don't
create more than one Viewer per application; instead you use
CompositeViewer or slave cameras in one Viewer. However, if this is
working for you, who am I to say different :)

 view->setName(name);
 addView(view);
 view->setSceneData(root);
 view->getCamera()->setName(name);
 view->getCamera()->setClearColor(fog->getColor());

...

view->getCamera()->getOrCreateStateSet()->setAttributeAndModes(fog,
osg::StateAttribute::ON);
 fog->setUpdateCallback(new vesaFogUpdateCallback);

view->getCamera()->getOrCreateStateSet()->setUpdateCallback(new
vesaFogEnableUpdateCallback);
 }
 }

The solution I found is to create an UpdateCallback for each camera which
implements the code present in both my old Fog callbacks.

Does anyone have an idea of why the UpdateCallBack of the stateset does not
work when associated to a camera ? What am I doing wrong ?

Viewer only runs an UpdateVisitor on a camera if it has an update
callback. This may be a small bug, as you have discovered, as it
ignores the possibility that the camera's state set could have update
callbacks. I believe you will find that your state set update callback
will get run even if you install an empty callback on the camera node.

Tim

Moreover, I initially tried to activate desactivate the osf::Fog, the
osg::Light and the osgParticle::PrecipitationEffect using a
NodeMask/CullMask logic for each camera. It works for the
PrecipitationEffect, but doesn't for the Fog and the Light. Is it a normal
behaviour or is there something wrong in my code (in which case I would show
you the code).

I'm not sure what you mean, as Fog and Light aren't scene graph nodes.
Be sure that any StateAttribute objects have their data variance set
to DYNAMIC.

Tim

Thankyou for your help,

SCHULTE Christian
Research  Engineer
in charge of the Simulation Laboratory
System Control and Flight Dynamics Department
Simulation and Flight Testing Unit
ONERA - The French Aerospace Lab
Ecole de l'Air - BA 701
13661 SALON cedex AIR
FRANCE

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




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


Re: [osg-users] StateSet UpdateCallback on a camera

2012-07-06 Thread Tim Moore
Salut,

On Fri, Jul 6, 2012 at 10:13 AM, Christian Schulte
 wrote:
> Hi everyone,
>
> I'm facing a problem in our flight simulation environment, where we want to
> make the fog camera dependent ( in order to have cameras without fog for
> simulation control). I tried to follow the 2009 thread "[osg-users] Set fog
> in the canera StateSet" and succeded to implement a non variyng fog. But in
> our case we have a statesetcallback for changing the parameter of the fog
> and one for activating disactivating the fog.
>
...
> But, adding the fog to our different views, neither the
> vesaFogUpdateCallback nor the vesaFogEnableUpdateCallback are accessed
> anymore... This is the code I tryed to implement :
>
> BOOST_FOREACH(propTreeNode & v,
> arbreUtile->getOptionalChildProperties("graphic.windows.views"))
> {
> propTreeHolder pView(&v.second);
> if(pView.empty() || v.first.compare("msgFile")==0 ||
> v.first.compare("activeView")==0)
> continue;
>
> std::string name = v.first;
> osgViewer::View* view = new osgViewer::View;
I don't know if this is pseudo-code or not, but generally you don't
create more than one Viewer per application; instead you use
CompositeViewer or slave cameras in one Viewer. However, if this is
working for you, who am I to say different :)
> view->setName(name);
> addView(view);
> view->setSceneData(root);
> view->getCamera()->setName(name);
> view->getCamera()->setClearColor(fog->getColor());
...
> view->getCamera()->getOrCreateStateSet()->setAttributeAndModes(fog,
> osg::StateAttribute::ON);
> fog->setUpdateCallback(new vesaFogUpdateCallback);
>
> view->getCamera()->getOrCreateStateSet()->setUpdateCallback(new
> vesaFogEnableUpdateCallback);
> }
> }
>
> The solution I found is to create an UpdateCallback for each camera which
> implements the code present in both my old Fog callbacks.
>
> Does anyone have an idea of why the UpdateCallBack of the stateset does not
> work when associated to a camera ? What am I doing wrong ?
Viewer only runs an UpdateVisitor on a camera if it has an update
callback. This may be a small bug, as you have discovered, as it
ignores the possibility that the camera's state set could have update
callbacks. I believe you will find that your state set update callback
will get run even if you install an empty callback on the camera node.

Tim
>
> Moreover, I initially tried to activate desactivate the osf::Fog, the
> osg::Light and the osgParticle::PrecipitationEffect using a
> NodeMask/CullMask logic for each camera. It works for the
> PrecipitationEffect, but doesn't for the Fog and the Light. Is it a normal
> behaviour or is there something wrong in my code (in which case I would show
> you the code).
I'm not sure what you mean, as Fog and Light aren't scene graph nodes.
Be sure that any StateAttribute objects have their data variance set
to DYNAMIC.

Tim
>
> Thankyou for your help,
>
> SCHULTE Christian
> Research  Engineer
> in charge of the Simulation Laboratory
> System Control and Flight Dynamics Department
> Simulation and Flight Testing Unit
> ONERA - The French Aerospace Lab
> Ecole de l'Air - BA 701
> 13661 SALON cedex AIR
> FRANCE
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] StateSet UpdateCallback on a camera

2012-07-06 Thread Christian Schulte

  
  
Hi everyone,

I'm facing a problem in our flight simulation environment, where we
want to make the fog camera dependent ( in order to have cameras
without fog for simulation control). I tried to follow the 2009
thread "[osg-users] Set fog in the canera StateSet" and succeded to
implement a non variyng fog. But in our case we have a
statesetcallback for changing the parameter of the fog and one for
activating disactivating the fog. 

This is how was set the fog before (one fog for all views) : 

    /*
     * Fog
     */
    Fog * fog = pe->getFog(); // pe is a
osgParticle::PrecipitationEffect
    root->getOrCreateStateSet()->setAttributeAndModes(fog,
osg::StateAttribute::ON);
    fog->setUpdateCallback(new vesaFogUpdateCallback);
    root->getOrCreateStateSet()->setUpdateCallback(new
vesaFogEnableUpdateCallback);

But, adding the fog to our different views, neither the
vesaFogUpdateCallback nor the vesaFogEnableUpdateCallback are
accessed anymore... This is the code I tryed to implement : 

        BOOST_FOREACH(propTreeNode & v,
arbreUtile->getOptionalChildProperties("graphic.windows.views"))
        {
            propTreeHolder pView(&v.second);
            if(pView.empty() || v.first.compare("msgFile")==0 ||
v.first.compare("activeView")==0)
                continue;

            std::string name = v.first;
            osgViewer::View* view = new osgViewer::View;
            view->setName(name);
            addView(view);
            view->setSceneData(root);
            view->getCamera()->setName(name);
           
view->getCamera()->setClearColor(fog->getColor());

            view->getCamera()->setViewport(
                new osg::Viewport(
                    traits->width *    
pView.getPropValue("xMin",0.0),
                    traits->height *    
pView.getPropValue("yMin",0.0),
                    traits->width *    
pView.getPropValue("sizeX",1.0),
                    traits->height *    
pView.getPropValue("sizeY",1.0)
                )
            );

            view->getCamera()->setGraphicsContext(gc.get());
            view->getCamera()->setCullSettings(cs);
            if
(arbreUtile->getPropValue("graphic.windows.views."+name+
".effects.withFog",true))
            {
                osg::ref_ptr fog = new osg::Fog();
                float             varNear     = 0.0f;
                float             end         = 0.0f;
                float             density     = 0.0f;
                std::string     tmp         = "";
                osg::Fog::Mode    mode;
                osg::Vec4f         color;
                /*
                 * Get values
                 */
                varNear     =
arbreUtile->getPropValue("sim.environement.fog.start",
1.);
                end         =
arbreUtile->getPropValue("sim.environement.fog.end",
2.);
                density     =
arbreUtile->getPropValue("sim.environement.fog.density",
0.1);
                color         =
arbreUtile->getPropValue("sim.environement.fog.color",
osg::Vec4f(0.7,0.7,0.7,1.0));
                if((tmp =
arbreUtile->getPropValue("sim.environement.fog.mode",std::string("exp2")))
== "linear" )
                    mode = osg::Fog::LINEAR;
                else if(tmp == "exp")
                    mode = osg::Fog::EXP;
                else if(tmp == "exp2")
                    mode = osg::Fog::EXP2;
                else
                    mode = osg::Fog::EXP2;
                fog->setMode(mode);
                fog->setStart(varNear);
                fog->setEnd(end);
                fog->setDensity(density);
                fog->setColor(color);
               
view->getCamera()->getOrCreateStateSet()->setAttributeAndModes(fog,
osg::StateAttribute::ON);
            fog->setUpdateCallback(new
vesaFogUpdateCallback);
           
view->getCamera()->getOrCreateStateSet()->setUpdateCallback(new
vesaFogEnableUpdateCallback);
            }
        }

The solution I found is to create an UpdateCallback for each camera
which implements the code present in both my old Fog callbacks.

Does anyone have an idea of why the UpdateCallBack of the stateset
does not work when associated to a camera ? What am I doing wrong ?

Moreover, I initially tried to activate desactivate the osf::Fog,
the osg::Light and the osgParticle::PrecipitationEffect using a
NodeMask/CullMask logic for each camera. It works for the
PrecipitationEffect, but doesn't for the Fog and the Light. Is it a
normal behaviour or is there something wrong in my