Re: [osg-users] Selecting objects

2014-05-25 Thread Alexpux

23 мая 2014 г., в 22:54, Trajce Nikolov NICK  
написал(а):

> Hi Alexey
> 
> I guess this is the problem, the material you are setting to the previous 
> selected model. Maybe you record the state before selection and set it back 
> when you select a new node
> 

I’m try:

if (m_SelectedNode){
m_SelectedNode->setStateSet(clonedStateSet);
}
…..
if (node){
m_SelectedNode = node;
osg::Material* material = new osg::Material;
osg::StateSet* state = node->getOrCreateStateSet();
// save OSG-State
clonedStateSet = 
reinterpret_cast(state->clone(osg::CopyOp::DEEP_COPY_ALL));
….
}

But have the same result as before.
> Nick
> 
> 
> On Fri, May 23, 2014 at 6:51 PM, Alexpux  wrote:
> Hi all!
> 
> I’m new in OpenSceneGraph. I have big models exported from 3dmax and 
> materials from VRay (about 50 000 objects).
> I want highlight object on scene when clicking on it. Example with showing 
> bounding box work for me ok but I need
> to highlight object with, for example, green color and transparency.
> 
> I modify handle function as:
> 
> bool PickHandler::handle( const osgGA::GUIEventAdapter& ea,
>   osgGA::GUIActionAdapter& aa )
> {
> if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
>  ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
>  !(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL) )
> return false;
> 
> osgViewer::View* viewer = dynamic_cast(&aa);
> if (viewer)
> {
> osg::ref_ptr ray =
> new osgUtil::LineSegmentIntersector(
> osgUtil::Intersector::WINDOW, ea.getX(), ea.getY()
> );
> osgUtil::IntersectionVisitor iv(ray.get());
> iv.setTraversalMask( ~0x1 );
> viewer->getCamera()->accept(iv);
> if (ray->containsIntersections())
> {
> osgUtil::LineSegmentIntersector::Intersection resInt = 
> *(ray->getIntersections().begin());
> osg::BoundingBox bb = resInt.drawable->getBound();
> osg::Vec3 worldCenter = bb.center() * 
> osg::computeLocalToWorld(resInt.nodePath);
> m_selectionBox->setMatrix(
> osg::Matrix::scale(bb.xMax()-bb.xMin(),
>   bb.yMax()-bb.yMin(),
>   bb.zMax()-bb.zMin()) *
> osg::Matrix::translate(worldCenter) );
> 
> ///
> 
> if (m_SelectedNode){
> osg::Material* rev_material = new osg::Material;
> osg::StateSet* rev_state = 
> m_SelectedNode->getOrCreateStateSet();
> rev_state->setMode(GL_BLEND,osg::StateAttribute::ON | 
> osg::StateAttribute::OVERRIDE);
> rev_material->setAlpha(osg::Material::FRONT_AND_BACK, 1);
> 
> rev_state->setAttributeAndModes(rev_material,osg::StateAttribute::ON | 
> osg::StateAttribute::OVERRIDE);
> osg::BlendFunc* bf = new osg::BlendFunc( 
> osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA );
> rev_state->setAttributeAndModes(bf);
> 
> m_SelectedNode->setStateSet(rev_state);
> m_SelectedNode=NULL;
> }
> osg::NodePath& nodePath = resInt.nodePath;
> osg::Node* node = 
> (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
> osg::Group* parent = 
> (nodePath.size()>=2)?dynamic_cast(nodePath[nodePath.size()-2]):0;
> 
> if (node) {
> m_SelectedNode = node;
> osg::Material* material = new osg::Material;
> osg::StateSet* state = node->getOrCreateStateSet();
> 
> state->setMode(GL_BLEND,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
> material->setAlpha(osg::Material::FRONT_AND_BACK, 0.6);
> state->setAttribute(material,osg::StateAttribute::ON | 
> osg::StateAttribute::OVERRIDE);
> osg::BlendFunc* bf = new osg::BlendFunc( 
> osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA );
> state->setAttribute(bf);
> state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
> state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
> 
> node->setStateSet(state);
> }
> 
> ///
> }
> }
> return false;
> }
> 
> When select object I have transparency on it. But when I select another 
> object I see that previous object lost it color and become grey.
> How I can restore previous state of object material?
> 
> Regards,
> Alexey.
> 
> 
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
> 
> 
> -- 
> trajce nikolov nick
> 

Re: [osg-users] Selecting objects

2014-05-23 Thread Trajce Nikolov NICK
Hi Alexey

I guess this is the problem, the material you are setting to the previous
selected model. Maybe you record the state before selection and set it back
when you select a new node

Nick


On Fri, May 23, 2014 at 6:51 PM, Alexpux  wrote:

> Hi all!
>
> I'm new in OpenSceneGraph. I have big models exported from 3dmax and
> materials from VRay (about 50 000 objects).
> I want highlight object on scene when clicking on it. Example with showing
> bounding box work for me ok but I need
> to highlight object with, for example, green color and transparency.
>
> I modify handle function as:
>
> bool PickHandler::handle( const osgGA::GUIEventAdapter& ea,
>   osgGA::GUIActionAdapter& aa )
> {
> if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
>  ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
>  !(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL) )
> return false;
>
> osgViewer::View* viewer = dynamic_cast(&aa);
> if (viewer)
> {
> osg::ref_ptr ray =
> new osgUtil::LineSegmentIntersector(
> osgUtil::Intersector::WINDOW, ea.getX(), ea.getY()
> );
> osgUtil::IntersectionVisitor iv(ray.get());
> iv.setTraversalMask( ~0x1 );
> viewer->getCamera()->accept(iv);
> if (ray->containsIntersections())
> {
> osgUtil::LineSegmentIntersector::Intersection resInt =
> *(ray->getIntersections().begin());
> osg::BoundingBox bb = resInt.drawable->getBound();
> osg::Vec3 worldCenter = bb.center() *
> osg::computeLocalToWorld(resInt.nodePath);
> m_selectionBox->setMatrix(
> osg::Matrix::scale(bb.xMax()-bb.xMin(),
>   bb.yMax()-bb.yMin(),
>   bb.zMax()-bb.zMin()) *
> osg::Matrix::translate(worldCenter) );
>
> ///
>
> if (m_SelectedNode){
> osg::Material* rev_material = new osg::Material;
> osg::StateSet* rev_state =
> m_SelectedNode->getOrCreateStateSet();
> rev_state->setMode(GL_BLEND,osg::StateAttribute::ON |
> osg::StateAttribute::OVERRIDE);
> rev_material->setAlpha(osg::Material::FRONT_AND_BACK, 1);
>
> rev_state->setAttributeAndModes(rev_material,osg::StateAttribute::ON |
> osg::StateAttribute::OVERRIDE);
> osg::BlendFunc* bf = new osg::BlendFunc(
> osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA );
> rev_state->setAttributeAndModes(bf);
>
> m_SelectedNode->setStateSet(rev_state);
> m_SelectedNode=NULL;
> }
> osg::NodePath& nodePath = resInt.nodePath;
> osg::Node* node =
> (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
> osg::Group* parent =
> (nodePath.size()>=2)?dynamic_cast(nodePath[nodePath.size()-2]):0;
>
> if (node) {
> m_SelectedNode = node;
> osg::Material* material = new osg::Material;
> osg::StateSet* state = node->getOrCreateStateSet();
>
> state->setMode(GL_BLEND,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
> material->setAlpha(osg::Material::FRONT_AND_BACK, 0.6);
> state->setAttribute(material,osg::StateAttribute::ON |
> osg::StateAttribute::OVERRIDE);
> osg::BlendFunc* bf = new osg::BlendFunc(
> osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA );
> state->setAttribute(bf);
> state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
> state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
>
> node->setStateSet(state);
> }
>
> ///
> }
> }
> return false;
> }
>
> When select object I have transparency on it. But when I select another
> object I see that previous object lost it color and become grey.
> How I can restore previous state of object material?
>
> Regards,
> Alexey.
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



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


[osg-users] Selecting objects

2014-05-23 Thread Alexpux
Hi all!

I’m new in OpenSceneGraph. I have big models exported from 3dmax and materials 
from VRay (about 50 000 objects).
I want highlight object on scene when clicking on it. Example with showing 
bounding box work for me ok but I need
to highlight object with, for example, green color and transparency.

I modify handle function as:

bool PickHandler::handle( const osgGA::GUIEventAdapter& ea,
  osgGA::GUIActionAdapter& aa )
{
if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
 ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
 !(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL) )
return false;

osgViewer::View* viewer = dynamic_cast(&aa);
if (viewer)
{
osg::ref_ptr ray =
new osgUtil::LineSegmentIntersector(
osgUtil::Intersector::WINDOW, ea.getX(), ea.getY()
);
osgUtil::IntersectionVisitor iv(ray.get());
iv.setTraversalMask( ~0x1 );
viewer->getCamera()->accept(iv);
if (ray->containsIntersections())
{
osgUtil::LineSegmentIntersector::Intersection resInt = 
*(ray->getIntersections().begin());
osg::BoundingBox bb = resInt.drawable->getBound();
osg::Vec3 worldCenter = bb.center() * 
osg::computeLocalToWorld(resInt.nodePath);
m_selectionBox->setMatrix(
osg::Matrix::scale(bb.xMax()-bb.xMin(),
  bb.yMax()-bb.yMin(),
  bb.zMax()-bb.zMin()) *
osg::Matrix::translate(worldCenter) );

///

if (m_SelectedNode){
osg::Material* rev_material = new osg::Material;
osg::StateSet* rev_state = 
m_SelectedNode->getOrCreateStateSet();
rev_state->setMode(GL_BLEND,osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE);
rev_material->setAlpha(osg::Material::FRONT_AND_BACK, 1);

rev_state->setAttributeAndModes(rev_material,osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE);
osg::BlendFunc* bf = new osg::BlendFunc( 
osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA );
rev_state->setAttributeAndModes(bf);

m_SelectedNode->setStateSet(rev_state);
m_SelectedNode=NULL;
}
osg::NodePath& nodePath = resInt.nodePath;
osg::Node* node = 
(nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
osg::Group* parent = 
(nodePath.size()>=2)?dynamic_cast(nodePath[nodePath.size()-2]):0;

if (node) {
m_SelectedNode = node;
osg::Material* material = new osg::Material;
osg::StateSet* state = node->getOrCreateStateSet();

state->setMode(GL_BLEND,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
material->setAlpha(osg::Material::FRONT_AND_BACK, 0.6);
state->setAttribute(material,osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE);
osg::BlendFunc* bf = new osg::BlendFunc( 
osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA );
state->setAttribute(bf);
state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);

node->setStateSet(state);
}

///
}
}
return false;
}

When select object I have transparency on it. But when I select another object 
I see that previous object lost it color and become grey.
How I can restore previous state of object material?

Regards,
Alexey.


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