<div dir="ltr"><div dir="ltr">That's not really how it's done.<div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div><br></div><div>At a glance, this old example shows sort of what I'm talking about, but it may need tweaking to compile with current sources: <a href="http://forum.openscenegraph.org/viewtopic.php?t=10590&view=next">http://forum.openscenegraph.org/viewtopic.php?t=10590&view=next</a></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 19, 2018 at 10:56 AM Diego Mancilla <<a href="mailto:dmancillac@gmail.com">dmancillac@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm a newbie on OpenSceneGraph and 3D development.<br>
<br>
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.<br>
<br>
I'm using the "Quick Start Guide" as reference and modifying an example that I found on the web.<br>
<br>
A code snippet of what I have:<br>
<br>
<br>
Code:<br>
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;<br>
osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;<br>
geom->setColorArray(c.get());<br>
geom->setColorBinding(osg::Geometry::BIND_OVERALL);<br>
c->push_back(osg::Vec4(1.f, 0.f, 0.f, 1.f));<br>
<br>
osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;<br>
geom->setNormalArray(n.get());<br>
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);<br>
n->push_back(osg::Vec3(0.f, -1.f, 0.f));<br>
<br>
osg::Node* lines = osgDB::readNodeFile("lines.dxf");<br>
osg::Geode* geode = new osg::Geode;<br>
<br>
geode->addChild(lines);<br>
geode->addDrawable(geom.get());<br>
<br>
std::cout << "Num Drawables in geode: " << geode->getNumDrawables() << std::endl;<br>
<br>
osg::Camera* camera = new osg::Camera;<br>
camera->setViewport(0, 0, this->width(), this->height());<br>
camera->setClearColor(osg::Vec4(0.9f, 0.9f, 1.f, 1.f));<br>
float aspectRatio = static_cast<float>(this->width()) / static_cast<float>(this->height());<br>
camera->setProjectionMatrixAsPerspective(30.f, aspectRatio, 1.f, 1000.f);<br>
camera->setGraphicsContext(_mGraphicsWindow);<br>
<br>
_mViewer->setCamera(camera);<br>
_mViewer->setSceneData(geode);<br>
osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator;<br>
manipulator->setAllowThrow(false);<br>
this->setMouseTracking(true);<br>
_mViewer->setCameraManipulator(manipulator);<br>
_mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);<br>
_mViewer->realize();<br>
<br>
<br>
<br>
Thank you!<br>
<br>
Cheers.<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=75209#75209" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=75209#75209</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div style="text-align:center">Chris 'Xenon' Hanson, omo sanza lettere. Xenon@AlphaPixel.com <a href="http://www.alphapixel.com/" target="_blank">http://www.alphapixel.com/</a></div><div style="text-align:center">Training • Consulting • Contracting</div><div style="text-align:center">3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 • GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL</div><div style="text-align:center"><span style="font-size:12.8000001907349px">Legal/IP •</span><span style="font-size:12.8000001907349px"> </span><span style="font-size:12.8000001907349px">Forensics •</span><span style="font-size:12.8000001907349px"> </span>Imaging <span style="font-size:12.8px">•</span><span style="font-size:12.8px"> </span><span style="font-size:12.8px">UAVs </span><span style="font-size:12.8px">• GIS • GPS • osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile • iPhone/iPad/iOS • Android</span></div><div style="text-align:center"><a href="https://twitter.com/alphapixel" target="_blank">@alphapixel</a> <a href="http://facebook.com/alphapixel" target="_blank">facebook.com/alphapixel</a> (775) 623-PIXL [7495]<br></div></div></div></div></div></div>