Re: [osg-users] LOS materail query
OK, Got this working for some cases. For example, I used Lightwave to create a box with a colorbar texture placed on it so I would know for sure that the color returned was correct. The texture I used was a plain jpg. The problem is when using some other .ive , ost, or .osgt files. These have embedded textures of some unknown format. Do I need to somehow use set/getPixelFromat in order to be able to retrieve to right values for the texture color ? I am using this to check the color values for the picked texture: Code: osg::Image *myImage = myTexture-getImage(0); if (myImage) { osg::Vec4 textureColor = myImage-getColor(tc); std::cout textureColor = textureColor.x()*255 , textureColor.y()*255 , textureColor.z()*255 std::endl; } Thank you! Cheers, Mike -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64938#64938 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] LOS materail query
Hi Mike, OK, the next complication is probably that the osg::Texture has the probably unref'd the Image assigned to it after it's download to GL, the method that control it is in include/osg/Texture: /** Sets whether or not the apply() function will unreference the image * data. If enabled, and the image data is only referenced by this * Texture, apply() will delete the image data. */ inline void setUnRefImageDataAfterApply(bool flag) { _unrefImageDataAfterApply = flag; } This is memory optimization, but... if you want to look at the image data after it's been rendered you obviously don't want to use this feature. By default this feature is OFF, but if you run the osgUtil::Optimizer on the scene graph it can switch it on as a memory optimization. You can switch it back on using the osgUtil::Optimizer::TextureVisitor see the include/osgUtil/Optimizer header for the TextureVisitor. Robert. On 26 August 2015 at 20:34, Mike Greene mgre...@hiwaay.net wrote: OK, fixed that - loaded an .ive file and was able to get correct looking texture coordinates. In a .ive file with embedded textures, is there a textureName? Probably not - not really important. But the code does say that there is one image in the texture. But doing the getImage(0) does not return a valid image and thus no color from the texture is returned. Code: osgUtil::LineSegmentIntersector::Intersections intersections; if (viewer-computeIntersections(ea, intersections)) { const osgUtil::LineSegmentIntersector::Intersection hit = *intersections.begin(); //MGREENE std::cout hit = hit.getLocalIntersectPoint().x() , hit.getLocalIntersectPoint().y() , hit.getLocalIntersectPoint().z() std::endl; osg::Vec3 tc(0, 0, 0); osg::Texture* myTexture = hit.getTextureLookUp(tc); std::cout tc = tc.x() , tc.y() , tc.z() std::endl; if (myTexture){ std::string myString = myTexture-getName(); std::cout texturename = myString std::endl; int numImages = myTexture-getNumImages(); std::cout numImages = numImages std::endl; osg::Image *myImage = myTexture-getImage(0); if (myImage) { osg::Vec4 textureColor = myImage-getColor(tc); std::cout textureColor = textureColor.r() , textureColor.b() , textureColor.g() , textureColor.a() std::endl; } } //END MGREENE ... Thank you! Cheers, Mike -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64908#64908 ___ 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] LOS materail query
OK, fixed that - loaded an .ive file and was able to get correct looking texture coordinates. In a .ive file with embedded textures, is there a textureName? Probably not - not really important. But the code does say that there is one image in the texture. But doing the getImage(0) does not return a valid image and thus no color from the texture is returned. Code: osgUtil::LineSegmentIntersector::Intersections intersections; if (viewer-computeIntersections(ea, intersections)) { const osgUtil::LineSegmentIntersector::Intersection hit = *intersections.begin(); //MGREENE std::cout hit = hit.getLocalIntersectPoint().x() , hit.getLocalIntersectPoint().y() , hit.getLocalIntersectPoint().z() std::endl; osg::Vec3 tc(0, 0, 0); osg::Texture* myTexture = hit.getTextureLookUp(tc); std::cout tc = tc.x() , tc.y() , tc.z() std::endl; if (myTexture){ std::string myString = myTexture-getName(); std::cout texturename = myString std::endl; int numImages = myTexture-getNumImages(); std::cout numImages = numImages std::endl; osg::Image *myImage = myTexture-getImage(0); if (myImage) { osg::Vec4 textureColor = myImage-getColor(tc); std::cout textureColor = textureColor.r() , textureColor.b() , textureColor.g() , textureColor.a() std::endl; } } //END MGREENE ... Thank you! Cheers, Mike -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64908#64908 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] LOS materail query
Hi Mike, The osgparticleeffects demo uses a ShapeDrawable for rendering the terrain, this keeps the code straight forward but it does mean there isn't an osg::Geometry for the vertices and tex coords to hang off as all the geometry data is created on the fly and embedded in a display list. Please remember this example is written to demonstrate how to do particle effects, it's not an example for rendering terrain etc. Try using a scene graph that actually use osg::Geometry and you shoudl have better luck. Robert. On 26 August 2015 at 13:24, Mike Greene mgre...@hiwaay.net wrote: Yes, a null texture is the problem. I am using the osgparticleeffects example, as I know the object does have a texture. It is the example where you click on the terrain and at that point an explosion and smoke effect starts. But when printing out the coordinates of hit in the code above, they do show valid locations on the terrain whenever a mouse clicks on the terrain to place a particle effect. Using one of these valid hits, I then use that intersection to try the texture return code. For example, one of the hit outputs that I ran returned an X,Y,Z of 838.203, 840.662, 268.477 (LocalIntersectPoint), but the texture returned is NULL and of course then tc is (0,0,0). Debugging the code for getTextureLookup, the first two lines : Code: osg::Texture* LineSegmentIntersector::Intersection::getTextureLookUp(osg::Vec3 tc) const { osg::Geometry* geometry = drawable.valid() ? drawable-asGeometry() : 0; osg::Vec3Array* vertices = geometry ? dynamic_castosg::Vec3Array*(geometry-getVertexArray()) : 0; show that drawable.valid is true, but then the value of vertices is always all zeroes. ... Thank you! Cheers, Mike[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64903#64903 ___ 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] LOS materail query
Yes, a null texture is the problem. I am using the osgparticleeffects example, as I know the object does have a texture. It is the example where you click on the terrain and at that point an explosion and smoke effect starts. But when printing out the coordinates of hit in the code above, they do show valid locations on the terrain whenever a mouse clicks on the terrain to place a particle effect. Using one of these valid hits, I then use that intersection to try the texture return code. For example, one of the hit outputs that I ran returned an X,Y,Z of 838.203, 840.662, 268.477 (LocalIntersectPoint), but the texture returned is NULL and of course then tc is (0,0,0). Debugging the code for getTextureLookup, the first two lines : Code: osg::Texture* LineSegmentIntersector::Intersection::getTextureLookUp(osg::Vec3 tc) const { osg::Geometry* geometry = drawable.valid() ? drawable-asGeometry() : 0; osg::Vec3Array* vertices = geometry ? dynamic_castosg::Vec3Array*(geometry-getVertexArray()) : 0; show that drawable.valid is true, but then the value of vertices is always all zeroes. ... Thank you! Cheers, Mike[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64903#64903 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] LOS materail query
Hi, using the example, osgparticleeffects.cpp, I added the following lines of code to the pick function (inside the //MGREENE section): Code: void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter ea) { osg::Group* root = dynamic_castosg::Group*(viewer-getSceneData()); if (!root) return; osgUtil::LineSegmentIntersector::Intersections intersections; if (viewer-computeIntersections(ea,intersections)) { const osgUtil::LineSegmentIntersector::Intersection hit = *intersections.begin(); //MGREENE std::cout hit = hit.getWorldIntersectPoint().x() , hit.getWorldIntersectPoint().y() , hit.getWorldIntersectPoint().z() std::endl; osg::Vec3 tc(0,0,0); osg::ref_ptrosg::Texture myTexture = hit.getTextureLookUp(tc); std::cout tc = tc.x() , tc.y() , tc.z() std::endl; //END MGREENE bool handleMovingModels = false; ... but the values of tc are always 0,0,0. Thank you! Cheers, Mike[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64894#64894 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] LOS materail query
Hi, Hi, using the example, osgparticleeffects.cpp, I added the following lines of code to the pick function (inside the //MGREENE section): Code: void pick(osgViewer::Viewer* viewer, const osgGA::GUIEventAdapter ea) { osg::Group* root = dynamic_castosg::Group*(viewer-getSceneData()); if (!root) return; osgUtil::LineSegmentIntersector::Intersections intersections; if (viewer-computeIntersections(ea,intersections)) { const osgUtil::LineSegmentIntersector::Intersection hit = *intersections.begin(); //MGREENE std::cout hit = hit.getWorldIntersectPoint().x() , hit.getWorldIntersectPoint().y() , hit.getWorldIntersectPoint().z() std::endl; osg::Vec3 tc(0,0,0); osg::ref_ptrosg::Texture myTexture = hit.getTextureLookUp(tc); std::cout tc = tc.x() , tc.y() , tc.z() std::endl; //END MGREENE bool handleMovingModels = false; ... but the values of tc are always 0,0,0. Have you checked the return value of the getTextureLookUp call? Documentation states that it will return a nullptr if no texture is available. If this doesn't help, debugging into the function might help ;-) Cheers Sebastian Thank you! Cheers, Mike[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64894#64894 ___ 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] LOS materail query
Thank you guys very much! Cheers, Mike -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64867#64867 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] LOS materail query
Hi Mike Hi, I am wanting to do a dust cloud when an entity (helicopter) lands on a terrain. Ideally, would like the color of the dust cloud to be similar to the material/texture that the entity is on. Is there a way to do a material/texture color query based on an entity position, kind of like an LOS intersector test? Thank you! You can use the osgUtil::LineSegmentIntersector to retrieve intersections. The result will contain the information on the primitives hit, so you can get the stateset containing the material properties from there. As for the textures: you can also retrieve the texel you hit. I've attached some code-snippet out of some test-application of mine. snip if (!mExternalPickPositionHandler.empty() computeIntersections(view, ea, intersections) ) { osg::Vec3d pos = (intersections.begin())-getWorldIntersectPoint(); osg::Vec3d normal = (intersections.begin())-getWorldIntersectNormal(); #ifdef TEST_TEXELS // use the nearest intersection const osgUtil::LineSegmentIntersector::Intersection intersection = *(intersections.begin()); osg::Drawable* drawable = intersection.drawable.get(); osg::Geometry* geometry = drawable ? drawable-asGeometry() : 0; osg::Vec3Array* vertices = geometry ? dynamic_castosg::Vec3Array*(geometry-getVertexArray()) : 0; if (vertices) { // get the vertex indices. const osgUtil::LineSegmentIntersector::Intersection::IndexList indices = intersection.indexList; const osgUtil::LineSegmentIntersector::Intersection::RatioList ratios = intersection.ratioList; if (indices.size()==3 ratios.size()==3) { unsigned int i1 = indices[0]; unsigned int i2 = indices[1]; unsigned int i3 = indices[2]; float r1 = ratios[0]; float r2 = ratios[1]; float r3 = ratios[2]; osg::Array* texcoords = (geometry-getNumTexCoordArrays()0) ? geometry-getTexCoordArray(0) : 0; osg::Vec2Array* texcoords_Vec2Array = dynamic_castosg::Vec2Array*(texcoords); if (texcoords_Vec2Array) { osg::Vec2 tc1 = (*texcoords_Vec2Array)[i1]; osg::Vec2 tc2 = (*texcoords_Vec2Array)[i2]; osg::Vec2 tc3 = (*texcoords_Vec2Array)[i3]; osg::Vec2 tc = tc1*r1 + tc2*r2 + tc3*r3; //normalize, since negative tex-coords are not handled by osg::Image::set/getImage float int_part; if (tc[0] 0) { tc[0] = 1.0 - modf(tc[0], int_part); } if (tc[1] 0) { tc[1] = 1.0 - modf(tc[1], int_part); } osg::Texture* texture = intersection.getTextureLookUp(osg::Vec3(tc,0)); osg::Image* image = nullptr; if (texture (image = texture-getImage(0))) { osg::Vec4 color = image-getColor(osg::Vec3(tc,0)); std::cout SCRed() HIT texture: image-getFileName() at color std::endl; image-setColor(osg::Vec4(color) * 0.9,osg::Vec3(tc,0)); image-dirty(); texture-setDataVariance(osg::Object::DYNAMIC); } } } } /snip Cheers, Mike -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64857#64857 ___ 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] LOS materail query
Hi Mike, In the osgUtil::LineSegmentItersector::Intersection object there is now (in OSG-3.2 onwards) the convenience method: /** Convenience function for mapping the intersection point to any textures assigned to the objects intersected. * Returns the Texture pointer and texture coords of object hit when a texture is available on the object, returns NULL otherwise.*/ osg::Texture* getTextureLookUp(osg::Vec3 tc) const; From the Texture* you can then get the assigned osg::Image, and osg::Image has a convenience method: /** Get the color value for specified texcoord.*/ Vec4 getColor(const Vec3 texcoord) const; Which should give you exactly what you want. It's possible to everything these new methods do on old versions of the OSG than 3.2 but you'll need to replicate what these do internally. Have a look at the source online for these methods for inspiration. Robert. On 20 August 2015 at 20:58, Mike Greene mgre...@hiwaay.net wrote: Hi, I am wanting to do a dust cloud when an entity (helicopter) lands on a terrain. Ideally, would like the color of the dust cloud to be similar to the material/texture that the entity is on. Is there a way to do a material/texture color query based on an entity position, kind of like an LOS intersector test? Thank you! Cheers, Mike -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=64857#64857 ___ 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