问题描述
我将开放的场景图形从3.4更新到3.6.5,有一部分给我带来了麻烦。我们有一个代表点云的类,经过几次插补后,向该点添加点的测试失败。
以下是创建适当节点的部分:
osg::Geode* geode = new osg::Geode();
m_geometry = new osg::Geometry();
m_vertexData = new osg::Vec3Array;
m_vertexData->setDataVariance(osg::Object::DYNAMIC);
m_geometry->setVertexArray(m_vertexData);
setColor(m_color);
// At this stage there are no vertices in there
m_drawArrays = new osg::DrawArrays(osg::PrimitiveSet::POINTS,m_vertexData->size());
m_drawArrays->setDataVariance(osg::Object::DYNAMIC);
m_geometry->addPrimitiveSet(m_drawArrays);
m_geometry->setUsedisplayList(false);
m_geometry->setDataVariance(osg::Object::DYNAMIC);
m_geometry->getorCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
m_point = new osg::Point(1.0f);
m_geometry->getorCreateStateSet()->setAttribute(m_point,osg::StateAttribute::ON);
geode->addDrawable(m_geometry);
m_transform->addChild(geode);
所有成员变量都保存为osg::ref_ptr<>
更新部分看起来像这样,它在对viewer->frame()
的调用之间被调用,并且每个上下文的线程被设置为一个(我们目前仅使用一个)。 vertexData
是我们自己的结构,可能已被修改。
auto& vertices = vertexData.getVertices();
size_t count = vertices.size();
// Check for size change in number of vertices
auto vertexArray = static_cast<osg::Vec3Array*>(m_geometry->getVertexArray());
if (count != static_cast<size_t>(vertexArray->size()))
{
vertexArray->resize(count);
m_drawArrays->setCount(count);
m_drawArrays->dirty();
}
// #performance
// Calculate the bounding Box while iterating over the vertices,this will save osg time in the update traversal
for (size_t i = 0; i < count; ++i)
{
const auto& vertex = vertices[i];
(*vertexArray)[i][0] = static_cast<float>(vertex.position[0]);
(*vertexArray)[i][1] = static_cast<float>(vertex.position[1]);
(*vertexArray)[i][2] = static_cast<float>(vertex.position[2]);
}
m_geometry->dirtyBound();
m_geometry->dirtydisplayList();
这是更新顶点数量的正确方法吗?换成新的osg:Vec3Array
可以但会影响性能。
尝试执行PrimitiveSet
时,崩溃发生在glDrawArrays(_mode,_first,_count);
感谢您的帮助,谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)