Re: [osg-users] getting RGB of texture in *.ive file

2012-10-02 Thread Joe Doob
Thanks for the advice!

I'm getting closer but not quite there yet. 

I found that my drawable in this test case has exactly one parent, and his 
parent has a state set. I am able to get the image attached to the texture on 
this state set without running across any null pointers, and write the image to 
a file for verification...


Code:

if(drawable->getParent(0)->getStateSet())
{
state_set = drawable->getParent(0)->getStateSet();
osg::Texture * texture = state_set->getTextureAttribute(0, 
osg::StateAttribute::TEXTURE)->asTexture();
if(texture->getImage(osg::Material::FRONT))
{
textureImage = texture->getImage(osg::Material::FRONT);
osgDB::writeImageFile(*textureImage, "image.bmp");
}




Unfortunately, the image produced is pure noise. Also, I've found that using 
the getColor method on the image always returns a Vec4 with values (1, 1, 1, 
1)... so something is clearly wrong.

I should have no problem accessing the textures of an *.ive file directly in 
this way, right?

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





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


Re: [osg-users] getting RGB of texture in *.ive file

2012-10-01 Thread Thrall, Bryan
Joe Doob wrote on 2012-10-01: 
> This snippet produces a valid drawable, however the drawable returns a
> NULL stateset and so I can't obtain the texture object.
> 
> How can I obtain the osg::Image to get RGB in this case? Or, is there
a
> better method?

The texture for the Drawable must be set in a parent node (the Geode
that contains it, or possibly some Node higher in the scene graph).

You can use osg::Drawable::getParents() to work your way up the scene
graph until you find the StateSet that sets the texture. Note that OSG
combines StateSets, so even if you find a StateSet it might not specify
the texture; it all depends on how the model is structured. Also, that
part of the scene graph could occur multiple times in the scene graph if
it is instanced (which is why getParents() returns a list: there  could
be more than one parent).

Hope this helps,
--
Bryan Thrall
Principal Software Engineer
FlightSafety International
bryan.thr...@flightsafety.com


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


[osg-users] getting RGB of texture in *.ive file

2012-10-01 Thread Joe Doob
Hello,

I have a large terrain map which I load from an *.osg file containing a list of 
ProxyNode objects containing *.ive files, using osgDB::readNodeFile.

My end goal is to get RGB of points on the texture map found through a line 
segment intersection.

I have read through the mousePosition function in the InteractiveImageHandler 
class which shows how I would get the texture coordinates of the point 
intersected. 

>From there, I attempted to get the RGB value this way:


Code:

osg::Drawable * drawable = intersection.drawable.get();
if(drawable->getStateSet())
{
state_set = drawable->getStateSet();
osg::Texture * texture =
dynamic_cast(state_set->getTextureAttribute
(0, osg::StateAttribute::TEXTURE));

if(texture)
{
textureImage = texture->getImage(osg::Material::FRONT);
return textureImage->getColor(textureCoordinates);
}
}




This snippet produces a valid drawable, however the drawable returns a NULL 
stateset and so I can't obtain the texture object.

How can I obtain the osg::Image to get RGB in this case? Or, is there a better 
method?

Thanks-

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





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