<div dir="ltr">Gianni,<div><br></div><div>you should call geometry->dirtyDisplayList(); at the end of your move function ... Not sure about the rest of the logic of your code now though .... Maybe better idea then these email iterations is to write us what is your goal with this code since I see no smart logic in there (sorry :-) )</div><div><br></div><div><div>void move(osg::Geometry* geometry, unsigned int sourcePrimitiveSetIndex, unsigned int elementIndex, unsigned int destinationPrimitiveIndex)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>osg::DrawElementsUInt* sourcePrimitiveSet = dynamic_cast<osg::DrawElementsUInt*>(geometry->getPrimitiveSet(sourcePrimitiveSetIndex));</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>osg::DrawElementsUInt* destinationPrimitiveSet = dynamic_cast<osg::DrawElementsUInt*>(geometry->getPrimitiveSet(destinationPrimitiveIndex));</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>destinationPrimitiveSet->push_back(sourcePrimitiveSet->at(elementIndex * 3));</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>destinationPrimitiveSet->push_back(sourcePrimitiveSet->at(elementIndex * 3 + 1));</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>destinationPrimitiveSet->push_back(sourcePrimitiveSet->at(elementIndex * 3 + 2));</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>sourcePrimitiveSet->erase(sourcePrimitiveSet->begin() + elementIndex * 3);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>sourcePrimitiveSet->erase(sourcePrimitiveSet->begin() + elementIndex * 3);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>sourcePrimitiveSet->erase(sourcePrimitiveSet->begin() + elementIndex * 3);</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>sourcePrimitiveSet->dirty();</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>destinationPrimitiveSet->dirty();<span class="gmail-Apple-tab-span" style="white-space:pre"> </span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>geometry->dirtyDisplayList();</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>}</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 26, 2016 at 4:03 PM, Sebastian Messerschmidt <span dir="ltr"><<a href="mailto:sebastian.messerschmidt@gmx.de" target="_blank">sebastian.messerschmidt@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Gianni,<br>
<br>
A very simplistic solution using a outline triangle:<br>
<br>
<br>
<code><br>
#include <osg/Geometry><br>
#include <osg/Geode><br>
#include <osg/MatrixTransform><br>
#include <osg/PolygonOffset><br>
<br>
#include <osgViewer/CompositeViewer><br>
#include <osgViewer/ViewerEventHandlers<wbr>><br>
<br>
#include <osgGA/MultiTouchTrackballMani<wbr>pulator><br>
#include <osg/PolygonMode><br>
#include <osg/LineWidth><br>
#include <osgDB/ReadFile><br>
<br>
//#include <osgQt/GraphicsWindowQt><br>
<br>
#include <iostream><span class=""><br>
<br>
const osg::Vec4 selectedColor(1.0f, 1.0f, 1.0f, 0.5f);<br></span><span class="">
const osg::Vec4 color1(1.0f, 0.0f, 0.0f, 1.0f);<br>
const osg::Vec4 color2(0.0f, 1.0f, 0.0f, 1.0f);<br>
const osg::Vec4 color3(0.0f, 0.0f, 1.0f, 1.0f);<br>
const osg::Vec4 color4(1.0f, 0.0f, 1.0f, 1.0f);<br>
<br>
class SelectModelHandler : public osgGA::GUIEventHandler<br>
{<br>
public:<br></span>
SelectModelHandler(osg::ref_pt<wbr>r<osg::Group> group)<br>
: _selector(0), currentPrimitiveSetIndex(0), _root(group)<br>
{}<br>
<br>
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)<br>
{<br>
<br>
if (ea.getEventType() == osgGA::GUIEventAdapter::RELEAS<wbr>E &&<br>
ea.getButton() == osgGA::GUIEventAdapter::LEFT_M<wbr>OUSE_BUTTON &&<br>
ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY<wbr>_CTRL)<br>
{<br>
osgViewer::View* viewer = dynamic_cast<osgViewer::View*><wbr>(&aa);<br>
if (viewer)<br>
{<br>
osg::ref_ptr<osgUtil::LineSegm<wbr>entIntersector> intersector = new osgUtil::LineSegmentIntersecto<wbr>r(osgUtil::Intersector::<wbr>WINDOW, ea.getX(), ea.getY());<br>
osgUtil::IntersectionVisitor iv(intersector.get());<br>
osg::Camera* camera = viewer->getCamera();<br>
camera->accept(iv);<br>
<br>
if (intersector->containsIntersec<wbr>tions())<br>
{<br>
osgUtil::LineSegmentIntersecto<wbr>r::Intersection result = *(intersector->getIntersection<wbr>s().begin());<br>
doUserOperations(result);<br>
}<br>
}<br>
}<br>
<br>
return false;<br>
}<br>
<br>
virtual void doUserOperations(osgUtil::Line<wbr>SegmentIntersector::Intersecti<wbr>on& result)<br>
{<br>
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(r<wbr>esult.drawable.get());<br>
<br>
//first solution: add some outline<br>
if (_root->getNumChildren())<br>
{<br>
_root->removeChildren(0, _root->getNumChildren());<br>
}<br>
else if (result.indexList.size() > 2)<br>
{<br>
osg::DrawElementsUInt* elements = new osg::DrawElementsUInt(osg::Pri<wbr>mitiveSet::TRIANGLES);<br>
osg::Vec3Array* vertices = new osg::Vec3Array;<br>
osg::Vec4Array* colors = new osg::Vec4Array;<br>
colors->push_back(osg::Vec4(1, 0, 0, 1));<br>
const osg::Vec3Array& org_vertices = dynamic_cast<const osg::Vec3Array&>(*geom->getVer<wbr>texArray());<br>
<br>
vertices->push_back(org_vertic<wbr>es[result.indexList[0]]);<br>
vertices->push_back(org_vertic<wbr>es[result.indexList[1]]);<br>
vertices->push_back(org_vertic<wbr>es[result.indexList[2]]);<br>
(*elements).push_back(0);<br>
(*elements).push_back(1);<br>
(*elements).push_back(2);<br>
<br>
osg::Geode* geode = new osg::Geode;<span class=""><br>
osg::Geometry* geometry = new osg::Geometry;<br></span>
geode->addDrawable(geometry);<br>
geometry->setVertexArray(verti<wbr>ces);<br>
geometry->setColorArray(colors<wbr>, osg::Array::BIND_OVERALL);<br>
geometry->addPrimitiveSet(elem<wbr>ents);<br>
geometry->getOrCreateStateSet(<wbr>)->setAttribute(new osg::PolygonMode( osg::PolygonMode::FRONT_AND_BA<wbr>CK, osg::PolygonMode::LINE));<br>
geometry->getOrCreateStateSet(<wbr>)->setAttribute(new osg::LineWidth(3.0));<br>
_root->addChild(geode);<br>
}<br>
<br>
<br>
}<br>
<br>
protected:<br>
osg::ref_ptr<osg::Geometry> _selector;<br>
unsigned int currentPrimitiveSetIndex;<br>
osg::ref_ptr<osg::Group> _root;<br>
};<br>
<br>
osg::Vec3Array* buildVertices() {<br>
osg::Vec3Array* vertices = new osg::Vec3Array;<br>
vertices->push_back(osg::Vec3(<wbr>0, 0, 0));<br>
vertices->push_back(osg::Vec3(<wbr>10, 0, 0));<br>
vertices->push_back(osg::Vec3(<wbr>10, 10, 0));<br>
vertices->push_back(osg::Vec3(<wbr>0, 10, 0));<br>
vertices->push_back(osg::Vec3(<wbr>20, 0, 0));<br>
vertices->push_back(osg::Vec3(<wbr>20, 10, 0));<br>
vertices->push_back(osg::Vec3(<wbr>20, 20, 0));<br>
vertices->push_back(osg::Vec3(<wbr>10, 20, 0));<br>
vertices->push_back(osg::Vec3(<wbr>0, 20, 0));<br>
return vertices;<br>
}<br>
<br>
osg::DrawElementsUInt* buildElements()<br>
{<br>
osg::DrawElementsUInt* element = new osg::DrawElementsUInt(osg::Pri<wbr>mitiveSet::TRIANGLES);<br>
element->push_back(0);<br>
element->push_back(1);<br>
element->push_back(2);<br>
element->push_back(0);<br>
element->push_back(2);<br>
element->push_back(3);<br>
//////////////////////////////<wbr>//////////////////////////////<wbr>//////////////<br>
element->push_back(1);<br>
element->push_back(4);<br>
element->push_back(5);<br>
element->push_back(1);<br>
element->push_back(5);<br>
element->push_back(2);<br>
//////////////////////////////<wbr>//////////////////////////////<wbr>//////////////<br>
element->push_back(2);<br>
element->push_back(5);<br>
element->push_back(6);<br>
element->push_back(2);<br>
element->push_back(6);<br>
element->push_back(7);<br>
//////////////////////////////<wbr>//////////////////////////////<wbr>//////////////<br>
element->push_back(3);<br>
element->push_back(2);<br>
element->push_back(7);<br>
element->push_back(3);<br>
element->push_back(7);<br>
element->push_back(8);<br>
<br>
return element;<br>
}<br>
<br>
<br>
<br>
osg::Vec4Array* buildColors() {<br>
osg::Vec4Array* colors = new osg::Vec4Array(24);<br>
std::fill(std::begin(*colors), std::end(*colors), osg::Vec4f(0.5,0.5,0.5,1.0));<br>
return colors;<span class=""><br>
}<br>
<br>
osg::Geometry* buildGeometry() {<br>
osg::Geometry* geometry = new osg::Geometry;<br></span>
geometry->setDataVariance(osg:<wbr>:Object::DYNAMIC);<br>
geometry->setVertexArray(build<wbr>Vertices());<br>
geometry->setColorArray(buildC<wbr>olors(), osg::Array::BIND_PER_VERTEX);<br>
<br>
geometry->addPrimitiveSet(buil<wbr>dElements());<br>
<br>
return geometry;<br>
}<br>
<br>
osg::Node* createScene() {<br>
osg::Geode* geode = new osg::Geode;<br>
geode->addDrawable(buildGeomet<wbr>ry());<br>
return geode;<br>
}<br>
<br>
int main(int argc, char** argv)<br>
{<br>
osg::ArgumentParser arguments(&argc, argv);<br>
<br>
osgViewer::Viewer viewer(arguments);<br>
viewer.setUpViewInWindow(0, 0, 1000, 1000, 1);<br>
<br>
osg::ref_ptr<osg::Group> root = new osg::Group;<br>
osg::ref_ptr<osg::Group> selection_root = new osg::Group;<br>
root->addChild(createScene());<br>
root->addChild(selection_root)<wbr>;<br>
osg::ref_ptr<SelectModelHandle<wbr>r> selector = new SelectModelHandler(selection_r<wbr>oot);<br>
viewer.setSceneData(root);<br>
viewer.addEventHandler(selecto<wbr>r.get());<br>
viewer.setCameraManipulator(ne<wbr>w osgGA::TrackballManipulator);<br>
<br>
// add the window size toggle handler<br>
viewer.addEventHandler(new osgViewer::WindowSizeHandler);<br>
<br>
viewer.run();<br>
}<br>
</code><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
Am 9/26/2016 um 3:08 PM schrieb Gianni Ambrosio:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
One question,<br>
why should I use a "vertex" shader/attribute when I need to colour a triangle uniformly?<br>
<br>
Regards,<br>
Gianni<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=68753#68753" rel="noreferrer" target="_blank">http://forum.openscenegraph.or<wbr>g/viewtopic.php?p=68753#68753</a><br>
<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph<wbr>.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.or<wbr>g/listinfo.cgi/osg-users-opens<wbr>cenegraph.org</a><br>
</blockquote>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph<wbr>.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.or<wbr>g/listinfo.cgi/osg-users-opens<wbr>cenegraph.org</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</div>