[osg-users] Change color of node read from dxf file

Chris Hanson xenon at alphapixel.com
Mon Nov 19 13:54:44 PST 2018


That's not really how it's done.

You can't add the Node you got from ReadNodeFile as a child of a Geode. I
don't even think that should compile because Geode isn't derive from
osg::Group.

What you need to do is create a visitor to travel through the children of
the "lines" Node (that Node is almost 100% certain to be an osg::Group with
many children), finding any osg::Nodes you are interested in and examining
how the color is set up on them (per-vertex, overall, etc) and changing the
color data there.


At a glance, this old example shows sort of what I'm talking about, but it
may need tweaking to compile with current sources:
http://forum.openscenegraph.org/viewtopic.php?t=10590&view=next

On Mon, Nov 19, 2018 at 10:56 AM Diego Mancilla <dmancillac at gmail.com>
wrote:

> I'm a newbie on OpenSceneGraph and 3D development.
>
>  I have a dxf file that contains a bunch of 3DPOLYLINES (with different
> colors). So far I have been able to read and display them on a viewer, but
> I haven been able to change the color of the rendered lines. I believe that
> I'm not understanding properly the graph relationships.
>
>  I'm  using the "Quick Start Guide" as reference and modifying an example
> that I found on the web.
>
>  A code snippet of what I have:
>
>
> Code:
> osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
> osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
> geom->setColorArray(c.get());
> geom->setColorBinding(osg::Geometry::BIND_OVERALL);
> c->push_back(osg::Vec4(1.f, 0.f, 0.f, 1.f));
>
> osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;
> geom->setNormalArray(n.get());
> geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
> n->push_back(osg::Vec3(0.f, -1.f, 0.f));
>
> osg::Node* lines = osgDB::readNodeFile("lines.dxf");
> osg::Geode* geode = new osg::Geode;
>
> geode->addChild(lines);
> geode->addDrawable(geom.get());
>
> std::cout << "Num Drawables in geode: " << geode->getNumDrawables() <<
> std::endl;
>
> osg::Camera* camera = new osg::Camera;
> camera->setViewport(0, 0, this->width(), this->height());
> camera->setClearColor(osg::Vec4(0.9f, 0.9f, 1.f, 1.f));
> float aspectRatio = static_cast<float>(this->width()) /
> static_cast<float>(this->height());
> camera->setProjectionMatrixAsPerspective(30.f, aspectRatio, 1.f, 1000.f);
> camera->setGraphicsContext(_mGraphicsWindow);
>
> _mViewer->setCamera(camera);
> _mViewer->setSceneData(geode);
> osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator;
> manipulator->setAllowThrow(false);
> this->setMouseTracking(true);
> _mViewer->setCameraManipulator(manipulator);
> _mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
> _mViewer->realize();
>
>
>
> Thank you!
>
> Cheers.
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=75209#75209
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
Chris 'Xenon' Hanson, omo sanza lettere. Xenon at AlphaPixel.com
http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 •
GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging • UAVs • GIS • GPS •
osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile •
iPhone/iPad/iOS • Android
@alphapixel <https://twitter.com/alphapixel> facebook.com/alphapixel (775)
623-PIXL [7495]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20181119/d2e84957/attachment.html>


More information about the osg-users mailing list