diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c86299da8ce..1b67bf2d89fab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Fixed memory leaks from dart::gui::osg::Viewer: [#1349](https://github.com/dartsim/dart/pull/1349) * Added point rendering mode to PointCloudShape: [#1351](https://github.com/dartsim/dart/pull/1351), [#1355](https://github.com/dartsim/dart/pull/1355) * Updated ImGui to 1.71: [#1362](https://github.com/dartsim/dart/pull/1362) + * Fixed refresh of LineSegmentShapeNode: [#1381](https://github.com/dartsim/dart/pull/1381) * dartpy diff --git a/dart/gui/osg/render/LineSegmentShapeNode.cpp b/dart/gui/osg/render/LineSegmentShapeNode.cpp index 3daf6f578a3db..63dd2d181f64a 100644 --- a/dart/gui/osg/render/LineSegmentShapeNode.cpp +++ b/dart/gui/osg/render/LineSegmentShapeNode.cpp @@ -84,6 +84,7 @@ class LineSegmentShapeDrawable : public ::osg::Geometry ::osg::ref_ptr<::osg::Vec3Array> mVertices; ::osg::ref_ptr<::osg::Vec4Array> mColors; + ::osg::ref_ptr<::osg::DrawElementsUInt> mElements; }; //============================================================================== @@ -187,8 +188,10 @@ LineSegmentShapeDrawable::LineSegmentShapeDrawable( : mLineSegmentShape(shape), mVisualAspect(visualAspect), mVertices(new ::osg::Vec3Array), - mColors(new ::osg::Vec4Array) + mColors(new ::osg::Vec4Array), + mElements(new ::osg::DrawElementsUInt(::osg::PrimitiveSet::LINES)) { + addPrimitiveSet(mElements); refresh(true); } @@ -207,18 +210,17 @@ void LineSegmentShapeDrawable::refresh(bool firstTime) const common::aligned_vector& connections = mLineSegmentShape->getConnections(); - ::osg::ref_ptr<::osg::DrawElementsUInt> elements - = new ::osg::DrawElementsUInt(::osg::PrimitiveSet::LINES); - elements->reserve(2 * connections.size()); + mElements->clear(); + mElements->reserve(2 * connections.size()); for (std::size_t i = 0; i < connections.size(); ++i) { const Eigen::Vector2i& c = connections[i]; - elements->push_back(c[0]); - elements->push_back(c[1]); + mElements->push_back(static_cast(c[0])); + mElements->push_back(static_cast(c[1])); } - addPrimitiveSet(elements); + setPrimitiveSet(0, mElements); } if (mLineSegmentShape->checkDataVariance(