[osg-users] Modify Geometry of osg::Node loaded with ReadNodeFile
Dear All, Google search reveals that it's been discussed couple of times in the forum and mailing list, it 's been mentioned to use the NodeVisitor for that purpose. But isn't there more direct method of retriving the geometry data from loaded model? Something like that:osg::ref_ptrosg::Node load_nd = osgDB::readNodeFile(//Wavefront.obj);osg::Geometry* geo = load_nd-asGeode()-getDrawable(0)-asGeometry(); Because even if I use the nodeVisitor I have to know exact location of where geometry is stored in the loader node. Regards, ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Modify Geometry of osg::Node loaded with ReadNodeFile
Hi Sonya, Hard-wired casting of objects like you suggest will only work for scene graphs created by loaders is one very specific way and will fail if there is any variation away from this. I would strongly recommend not hard-wiring applications in this way. The NodeVisitor is designed to make it easy to traverse through the scene graph and apply operations to different types of Nodes. In svn/trunk life is actually a little easier as I've refactored osg::Drawable so it's subclassed from osg::Node so can be directly handled by a NodeVisitor::apply(osg::Geometry) implementation. NodeVisitor is such a useful tool that it really is one of the pieces of the OSG that all users should master, it simplifies so many tasks, you just need to take the initial steps to learn about it and then it'll be your friend for life. In terms of finding a specific node in the scene graph, there are various means for doing this, the most common is naming a node in the modelling programming and then searching for this named node in the scene graph with your custom NodeVisitor. Robert. On 30 August 2014 07:48, Sonya Blade sonyablade2...@hotmail.com wrote: Dear All, Google search reveals that it's been discussed couple of times in the forum and mailing list, it 's been mentioned to use the NodeVisitor for that purpose. But isn't there more direct method of retriving the geometry data from loaded model? Something like that: osg::ref_ptrosg::Node load_nd = osgDB::readNodeFile(//Wavefront.obj); osg::Geometry* geo = load_nd-asGeode()-getDrawable(0)-asGeometry(); Because even if I use the nodeVisitor I have to know exact location of where geometry is stored in the loader node. Regards, ___ 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
[osg-users] Warped scene with two sets of Geodes
I did post this question on StackOverflow ( http://stackoverflow.com/questions/25576762/warped-scene-with-two-sets-of-geodes ), but I assume that this is a more appropriate place for questions. I have a few objects that I want to combine into a scene graph: Street inherits from Geode and has a Geometry child drawable made up of a GL_LINE_STRIP. Pointer inherits from PositionAttitudeTransform and contains a Geode which contains two Geometry polygons. When I add a bunch of Streets to a Group, it looks just fine. When I add only the Pointer to a Group, it also looks fine. But if I somehow have them both in the scene, the second one is screwed up. (This does not happen if I have only two Pointers.) I posted some screenshots on the StackOverflow site, in case you want to see them. Probably I’m making some simple mistake—but I can’t see it! Here is some code that causes the problem (I tried to shorten it a little): // My libraries: #include asl/util/draw.h #include asl/util/color.h using namespace asl; #include straph/point.h #include straph/straph.h using namespace straph; // Standard and OSG libraries: #include utility #include boost/tuple/tuple.hpp // tie using namespace std; #include osg/ref_ptr #include osg/Array #include osg/Geometry #include osg/Group #include osg/LineWidth using namespace osg; #include osgUtil/Optimizer #include osgViewer/Viewer #include osgViewer/ViewerEventHandlers using namespace osgViewer; Geode* createStreet(const straph::Polyline path, double width, const Color color) { ref_ptrGeometry geom (new Geometry); // Set the shape: ref_ptrVec3dArray array (new Vec3dArray(path.size())); for (unsigned i = 0; i path.size(); ++i) { (*array)[i] = toVec3d(path[i]); } geom-setVertexArray(array.get()); geom-addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, array-size())); // Set the normals: ref_ptrVec3Array normals (new Vec3Array(1)); (*normals)[0].set( 0.0f, 0.0f, 1.0f ); geom-setNormalArray( normals.get() ); geom-setNormalBinding( Geometry::BIND_OVERALL ); // Set the colors: ref_ptrVec4Array colors = new Vec4Array(); colors-push_back(color.get()); geom-setColorArray(colors); geom-setColorBinding(osg::Geometry::BIND_OVERALL); Geode* g = new Geode(); g-addDrawable(geom.get()); // Set the line width. ref_ptrLineWidth lwidth (new LineWidth); lwidth-setWidth(width); g-getOrCreateStateSet()-setAttributeAndModes(lwidth, StateAttribute::ON); return g; } Group* load_streets() { unique_ptrStraph graph = read_shapefile(mexico/roads, 6); Group* root = new Group(); boost::graph_traitsstraph::Straph::edge_iterator ei, ee; for (boost::tie(ei, ee) = edges(*graph); ei != ee; ++ei) { const straph::Segment s = (*graph)[*ei]; root-addChild(createStreet(s.polyline, 2.0, TangoColor::Aluminium4)); } return root; } int main(int, char**) { Group* root = load_streets(); Pointer* p = new Pointer(6.0, TangoColor::Scarlet3, TangoColor::Black); root-addChild(p); Viewer viewer; viewer.setSceneData(root); viewer.getCamera()-setClearColor(Color(TangoColor::White).get()); viewer.run(); } Thanks for the help! :-)  –Ben Morgan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Warped scene with two sets of Geodes
HI Ben, The osg-users mailing list/forum is the appropriate place for support. I've read your post, the code you provided and screenshots and don't really know what to make of it all. I'd guess that others will be similarly confused but what might be work and what might not be. I don't understand why you are subclassing from OSG classes for this type of work, for 3rd parties like ourselves not party to the the code in these subclasses and without any knowledge of why felt the need to do this subclassing it really kinda hard to know where you are going with this code. I couldn't spot any obvious errors in your code, but I sure wouldn't write a tool to visualize a road network in the way you have - having lots of separate scene graph objects and state will introduce CPU and GPU overheads that will prevent getting the best performance for your system. You don't mention what hardware/GL driver/OS/OSG version you are using. This is all is important when trying to track down problems. It could be that you have a buggy OpenGL driver and little to do with your own code. There isn't much we can say to help at this point as there is just way too many unknowns about your software, hardware, OS, exactly nature of the problem etc. Robert. On 30 August 2014 12:32, Ben Morgan nee...@gmail.com wrote: I did post this question on StackOverflow ( http://stackoverflow.com/questions/25576762/warped-scene-with-two-sets-of-geodes ), but I assume that this is a more appropriate place for questions. I have a few objects that I want to combine into a scene graph: Street inherits from Geode and has a Geometry child drawable made up of a GL_LINE_STRIP. Pointer inherits from PositionAttitudeTransform and contains a Geode which contains two Geometry polygons. When I add a bunch of Streets to a Group, it looks just fine. When I add only the Pointer to a Group, it also looks fine. But if I somehow have them both in the scene, the second one is screwed up. (This does not happen if I have only two Pointers.) I posted some screenshots on the StackOverflow site, in case you want to see them. Probably I’m making some simple mistake—but I can’t see it! Here is some code that causes the problem (I tried to shorten it a little): // My libraries: #include asl/util/draw.h #include asl/util/color.h using namespace asl; #include straph/point.h #include straph/straph.h using namespace straph; // Standard and OSG libraries: #include utility #include boost/tuple/tuple.hpp // tie using namespace std; #include osg/ref_ptr #include osg/Array #include osg/Geometry #include osg/Group #include osg/LineWidth using namespace osg; #include osgUtil/Optimizer #include osgViewer/Viewer #include osgViewer/ViewerEventHandlers using namespace osgViewer; Geode* createStreet(const straph::Polyline path, double width, const Color color) { ref_ptrGeometry geom (new Geometry); // Set the shape: ref_ptrVec3dArray array (new Vec3dArray(path.size())); for (unsigned i = 0; i path.size(); ++i) { (*array)[i] = toVec3d(path[i]); } geom-setVertexArray(array.get()); geom-addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, array-size())); // Set the normals: ref_ptrVec3Array normals (new Vec3Array(1)); (*normals)[0].set( 0.0f, 0.0f, 1.0f ); geom-setNormalArray( normals.get() ); geom-setNormalBinding( Geometry::BIND_OVERALL ); // Set the colors: ref_ptrVec4Array colors = new Vec4Array(); colors-push_back(color.get()); geom-setColorArray(colors); geom-setColorBinding(osg::Geometry::BIND_OVERALL); Geode* g = new Geode(); g-addDrawable(geom.get()); // Set the line width. ref_ptrLineWidth lwidth (new LineWidth); lwidth-setWidth(width); g-getOrCreateStateSet()-setAttributeAndModes(lwidth, StateAttribute::ON); return g; } Group* load_streets() { unique_ptrStraph graph = read_shapefile(mexico/roads, 6); Group* root = new Group(); boost::graph_traitsstraph::Straph::edge_iterator ei, ee; for (boost::tie(ei, ee) = edges(*graph); ei != ee; ++ei) { const straph::Segment s = (*graph)[*ei]; root-addChild(createStreet(s.polyline, 2.0, TangoColor::Aluminium4)); } return root; } int main(int, char**) { Group* root = load_streets(); Pointer* p = new Pointer(6.0, TangoColor::Scarlet3, TangoColor::Black); root-addChild(p); Viewer viewer; viewer.setSceneData(root); viewer.getCamera()-setClearColor(Color(TangoColor::White).get()); viewer.run(); } Thanks for the help! :-)  –Ben Morgan ___ 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
Re: [osg-users] View on top of view, (picture in picture)
You will need osgViewer::CompositeViewer. Have a look at osgcompositeviewer example Nick On Sat, Aug 30, 2014 at 11:24 PM, Paul aquawic...@hotmail.com wrote: Hi, I've got a scene that renders some models. I would like to put a seperate camera/node viewport on top of that.. like a picture in picture type thing. The scenes are not related, so they don't need to see each other or anything. Where do I start? Thanks :) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60872#60872 ___ 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