Skip to content

Commit

Permalink
Fix #2663 picking of LineDrawable with the ObjectIDPicker is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Nov 27, 2024
1 parent f85ffb3 commit 3b5757f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/osgEarth/ObjectIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Capabilities"
#include "StringUtils"
#include "VirtualProgram"
#include "LineDrawable"

#include <osg/Geometry>

Expand Down Expand Up @@ -149,18 +150,24 @@ ObjectIndex::tagDrawable(osg::Drawable* drawable, ObjectID id) const
if ( drawable == 0L )
return;

osg::Geometry* geom = drawable->asGeometry();
if ( !geom )
return;

// add a new integer attributer to store the feautre ID per vertex.
ObjectIDArray* ids = new ObjectIDArray();
osg::ref_ptr<ObjectIDArray> ids = new ObjectIDArray();
ids->setBinding(osg::Array::BIND_PER_VERTEX);
ids->setNormalize(false);
geom->setVertexAttribArray(_attribLocation, ids);
ids->setPreserveDataType(true);

ids->assign( geom->getVertexArray()->getNumElements(), id );
if (auto* geometry = drawable->asGeometry())
{
// add a new integer attributer to store the feautre ID per vertex.
geometry->setVertexAttribArray(_attribLocation, ids);
ids->assign(geometry->getVertexArray()->getNumElements(), id);
}
else if (auto* line = dynamic_cast<LineDrawable*>(drawable))
{
line->setVertexAttribArray(_attribLocation, ids);
auto size = line->size();
for (int i = 0; i < size; ++i)
line->pushVertexAttrib(ids.get(), id);
}
}

ObjectID
Expand Down

0 comments on commit 3b5757f

Please sign in to comment.