【发布时间】:2020-10-27 12:58:25
【问题描述】:
我有许多 Esri Grid 文件 (https://en.wikipedia.org/wiki/Esri_grid#ASCII),我想在不损失精度的情况下以 3D 渲染它们,我正在使用 OpenSceneGraph。
问题是这个网格大约是 1000x1000(或更多)点,所以当我提取顶点,然后计算三角形以创建几何图形时,我最终拥有数百万个它们并且与场景的交互是不可能的(帧率降至 0)。
我尝试了几种方法:
-
三角列表
基本上,当我读取文件时,我会用每个三角形 3 个顶点填充一个数组(这会导致重复);
osg::ref_ptr<osg::Geode> l_pGeodeSurface = new osg::Geode;
osg::ref_ptr<osg::Geometry> l_pGeometrySurface = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> l_pvTrianglePoints = osg::Vec3Array;
osg::ref_ptr<osg::Vec3Array> l_pvOriginalPoints = osg::Vec3Array;
... // Read the file and fill l_pvOriginalPoints
for(*triangle inside the file*)
{
... // Compute correct triangle indices (l_iP1, l_iP2, l_iP3)
// Push triangle vertices inside the array
l_pvTrianglePoints->push_back(l_pvOriginalPoints->at(l_iP1));
l_pvTrianglePoints->push_back(l_pvOriginalPoints->at(l_iP2));
l_pvTrianglePoints->push_back(l_pvOriginalPoints->at(l_iP3));
}
l_pGeometrySurface->setVertexArray(l_pvTrianglePoints);
l_pGeometrySurface->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0, 3, l_pvTrianglePoints->size()));
-
索引三角形列表
和以前一样,但是数组只包含每个顶点一次,我创建了第二个索引数组(基本上我告诉 osg 如何构建三角形,没有重复)
osg::ref_ptr<osg::Geode> l_pGeodeSurface = new osg::Geode;
osg::ref_ptr<osg::Geometry> l_pGeometrySurface = new osg::Geometry;
osg::ref_ptr<osg::DrawElementsUInt> l_pIndices = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, *number of indices*);
osg::ref_ptr<osg::Vec3Array> l_pvOriginalPoints = osg::Vec3Array;
... // Read the file and fill l_pvOriginalPoints
for(i = 0; i < *number of indices*; i++)
{
... // Compute correct triangle indices (l_iP1, l_iP2, l_iP3)
// Push vertices indices inside the array
l_pIndices->at(i) = l_iP1;
l_pIndices->at(i+1) = l_iP2;
l_pIndices->at(i+2) = l_iP3;
}
l_pGeometrySurface->setVertexArray(l_pvOriginalPoints );
l_pGeometrySurface->addPrimitiveSet(l_pIndices.get());
-
实例化
这是一个实验,因为我从未使用过着色器,所以我认为我可以实例化一个三角形,然后使用变换矩阵(传递矩阵作为一个统一的数组,一个用于三角形)。我最终得到了太多制服,只有 20x20 的网格。
我使用这些链接作为参考:
以上都没有解决我的问题,我还能尝试什么?我在渲染技术方面是否遗漏了什么?我认为这是一个相当简单的任务,但我有点卡住了。
【问题讨论】:
-
我推荐使用原始类型
GL_TRIANGLE_STRIP -
@Rabbid76 谢谢,但我不能,因为 Esri 网格可以有任意数量的孔。
-
当然可以。见Primitive Restart
标签: c++ opengl 3d rendering openscenegraph