Re: [osg-users] osgmanipulator and osgUtil::Optimizer

2008-10-06 Thread Robert Osfield
Hi J-S,

This bug suggests that either the osg::Material's are updated
dynamically and the osg::Material aren't set to be DYNAMIC, or that
the relevant part of the osgUtil::Optimizer is not recognizing these
Material's as being independent.

As a separate issue running osgmanipulator with no arguments comes up
with an empty screen save for the text instructions...

I'm currently working on another bug right now so I'd appreciate it
others could dive in a work out what these problems stem from ;-)

Robert.

On Mon, Oct 6, 2008 at 2:20 PM, Jean-Sébastien Guay
[EMAIL PROTECTED] wrote:
 Hi all,

 I just noticed something that made me laugh. It seems like the
 osgUtil::Optimizer is very effective in combining similar statesets...

 If you start the osgmanipulator example with no arguments, it creates a
 default scene with a bunch of objects with manipulators on them. If you then
 press Tab and start using the manipulators, you'll notice that when you
 click on anything that's red (an X axis translation arrow, or the red
 rotation circle, etc.), *all* the red manipulator handles light up! (turn
 yellow) It seems that the optimizer has merged all red materials into a
 single material referenced by all objects. Same for the green and blue
 materials.

 Setting OSG_OPTIMIZER=OFF solves the issue. Perhaps the optimizer should be
 run on the loaded objects but not the manipulators? Or perhaps it should
 just not be used in that example?

 Anyways, as I said, I just found it funny.

 J-S
 --
 __
 Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
 ___
 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] osgmanipulator and osgUtil::Optimizer

2008-10-06 Thread Jean-Sébastien Guay

Hi Robert,


This bug suggests that either the osg::Material's are updated
dynamically and the osg::Material aren't set to be DYNAMIC, or that
the relevant part of the osgUtil::Optimizer is not recognizing these
Material's as being independent.


I'll try flagging the materials as DYNAMIC.


As a separate issue running osgmanipulator with no arguments comes up
with an empty screen save for the text instructions...


On my side it comes up fine, i.e. with some test models (cylinders, 
cones, cubes) with various manipulators on them... Not sure why it would 
behave differently on your side.



I'm currently working on another bug right now so I'd appreciate it
others could dive in a work out what these problems stem from ;-)


I can take a hint :-) I'll get back to you on the DYNAMIC setting.

J-S
--
__
Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgmanipulator and osgUtil::Optimizer

2008-10-06 Thread Jean-Sébastien Guay

Hi Robert,


I'll try flagging the materials as DYNAMIC.


Well, flagging the osgManipulator::Dragger's stateSet as DYNAMIC did the 
trick. Will send the fixed file to osg-submissions.


As for you not seeing anything when you start osgmanipulator without any 
arguments, I have no idea what's wrong there, I see the test objects fine...


J-S
--
__
Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgmanipulator and osgUtil::Optimizer

2008-10-06 Thread Jean-Sébastien Guay

Hi Robert,

Well, flagging the osgManipulator::Dragger's stateSet as DYNAMIC did the 
trick. Will send the fixed file to osg-submissions.


As promised on osg-users. The modification is in the base class so it 
applies to all draggers.


J-S
--
__
Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.

#include osgManipulator/Dragger
#include osg/Material

using namespace osgManipulator;

PointerInfo::PointerInfo():
_nearPoint(osg::Vec3()),
_farPoint(osg::Vec3()),
_eyeDir(osg::Vec3(0,0,1))
{
_hitIter = _hitList.begin();
}

bool PointerInfo::contains(const osg::Node* node) const
{
if (node  _hitIter!=_hitList.end()) return 
std::find((*_hitIter).first.begin(), (*_hitIter).first.end(), node) != 
(*_hitIter).first.end();
else return false;
}

bool PointerInfo::projectWindowXYIntoObject(const osg::Vec2 windowCoord, 
osg::Vec3 nearPoint, osg::Vec3 farPoint) const
{
nearPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),0.0f)*_inverseMVPW;
farPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),1.0f)*_inverseMVPW;

return true;
}

Dragger::Dragger() : _commandManager(0)
{
_parentDragger = this;
this-getOrCreateStateSet()-setDataVariance(osg::Object::DYNAMIC);
}

Dragger::~Dragger()
{
}


bool CompositeDragger::handle(const PointerInfo pi, const 
osgGA::GUIEventAdapter ea, osgGA::GUIActionAdapter aa)
{
// Check if the dragger node is in the nodepath.
if (!pi.contains(this))
return false;

for (DraggerList::iterator itr=_draggerList.begin(); 
itr!=_draggerList.end(); ++itr)
{
if ((*itr)-handle(pi, ea, aa))
return true;
}
return false;
}

bool CompositeDragger::containsDragger( const Dragger* dragger ) const
{
for (DraggerList::const_iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
{
if (itr-get() == dragger) return true;
}
return false;
}

CompositeDragger::DraggerList::iterator CompositeDragger::findDragger( const 
Dragger* dragger )
{
for (DraggerList::iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
{
if (itr-get() == dragger) return itr;
}
return _draggerList.end();
}

bool CompositeDragger::addDragger(Dragger *dragger)
{
if (dragger  !containsDragger(dragger))
{
_draggerList.push_back(dragger);
return true;
}
else return false;

}

bool CompositeDragger::removeDragger(Dragger *dragger)
{
DraggerList::iterator itr = findDragger(dragger);
if (itr != _draggerList.end())
{
_draggerList.erase(itr);
return true;
}
else return false;

}
void CompositeDragger::setCommandManager(CommandManager* cm)
{
for (DraggerList::iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
{
(*itr)-setCommandManager(cm);
}
Dragger::setCommandManager(cm);
}

void CompositeDragger::setParentDragger(Dragger* dragger)
{
for (DraggerList::iterator itr = _draggerList.begin(); itr != 
_draggerList.end(); ++itr)
{
(*itr)-setParentDragger(dragger);
}
Dragger::setParentDragger(dragger);
}

class ForceCullCallback : public osg::Drawable::CullCallback
{
public:
virtual bool cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const
{
return true;
}
};

void osgManipulator::setDrawableToAlwaysCull(osg::Drawable drawable)
{
ForceCullCallback* cullCB = new ForceCullCallback;
drawable.setCullCallback (cullCB);
}

void osgManipulator::setMaterialColor(const osg::Vec4 color, osg::Node node)
{
osg::Material* mat = 
dynamic_castosg::Material*(node.getOrCreateStateSet()-getAttribute(osg::StateAttribute::MATERIAL));
if (! mat)
{
mat = new osg::Material;
node.getOrCreateStateSet()-setAttribute(mat);
}
mat-setDiffuse(osg::Material::FRONT_AND_BACK, color);
}
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgmanipulator and osgUtil::Optimizer

2008-10-06 Thread Jean-Sébastien Guay

Oops, sorry folks, wrong list.

Jean-Sébastien Guay wrote:

Hi Robert,

Well, flagging the osgManipulator::Dragger's stateSet as DYNAMIC did 
the trick. Will send the fixed file to osg-submissions.


As promised on osg-users. The modification is in the base class so it 
applies to all draggers.


J-S




--
__
Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org