使用 C++ 和 DirectX 渲染 3D Delaunay
Rendering 3D Delaunay using C++ and DirectX
我尝试了下面的代码,但我的索引不正确。我正在尝试使用 CGAL 和 3D Delaunay 渲染线条,但我得到了正确的索引。很难获得3D Delaunay的索引。我不知道哪个部分是错误的,我尝试使用 4 个顶点,它看起来是正确的,但是超过 5 个索引时我得到错误的三角形......
std::vector<int> triangles;
std::map<Delaunay3::Vertex_handle, int> index_of_vertex;
int j = 0;
for (Delaunay3::Finite_vertices_iterator it = dt.finite_vertices_begin();
it != dt.finite_vertices_end(); ++it, ++j) {
index_of_vertex[it.base()] = j;
}
for (Delaunay3::Finite_facets_iterator itFacet = dt.finite_facets_begin();
itFacet != dt.finite_facets_end(); itFacet++) {
triangles.push_back(index_of_vertex[itFacet->first->vertex(0)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(1)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(0)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(3)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(1)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
triangles.push_back(index_of_vertex[itFacet->first->vertex(3)]);
}
std::vector<WORD> lineIndex;
lineIndex.resize(triangles.size() * sizeof(int) * 4);
int l, t;
for (l = 0, t = 0; t < triangles.size(); t += 4) {
// Each triangle has 3 lines, so D3D_PRIMITIVE_TOPOLOGY_LINELIST needs 6 vertices
// Each vertex has to be listed twice
lineIndex[l] = triangles[t];
l++;
lineIndex[l] = triangles[t + 1];
l++;
lineIndex[l] = triangles[t + 1];
l++;
lineIndex[l] = triangles[t + 2];
l++;
lineIndex[l] = triangles[t + 2];
l++;
lineIndex[l] = triangles[t];
l++;
}
// Fill in a buffer description for drawing only the triangle outlines
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = numTriangleVertices * 3 * sizeof(int); // <---- from the function
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
ZeroMemory(&InitData, sizeof(InitData));
InitData.pSysMem = static_cast<void*>(lineIndex.data());
pd3dDevice->CreateBuffer(&bd, &InitData, &g_pTriOutlineIndexBuffer);
让我用只有 4 个非共面顶点的三角测量来解释它。
然后你有 4 个有限面。它们中的每一个都表示为一个std::pair<Delaunay3::Cell_handle, int> pair;
,其中pair. first
是入射到小平面的像元,pair.second
是顶点的索引,与小平面中的小平面相对。
如果pair.second == 0
,则1,2,3
面顶点的索引;如果pair.second == 1
,则2,3,0
面顶点的索引;等。
也就是说,一般来说,pair.second == i
,小平面顶点的索引是(i+1)%4, (i+2)%4, (i+3)%4
还有一个帮助类,它是三角测量的基类https://doc.cgal.org/latest/TDS_3/classCGAL_1_1Triangulation__utils__3.html
它允许您编写Delaunay_3::vertex_triple_index(i,j)
。
我同意这根本没有很好的记录,我们将改进这一点。
相关文章:
- 无法将结构注册为增强几何体3D点
- OpenGL大的3D纹理(>2GB)非常慢
- 是什么导致了Unity 3D中的"错误线程异常"?
- 如何声明一个可以在整个程序中使用的全局 2d 3d 4d .. 数组(堆版本)变量?
- CPU 瓶颈;处理具有许多非静态对象的 3D 场景渲染的简单方法
- 如何使用Qt 3D库加载和显示搅拌机.obj源文件场景
- 如何从 3D 曲面网格中删除自相交三角形?
- CUDA 使用共享内存平铺 3D 卷积实现
- 检查框内的 3D 点
- 如何在 3D OpenGL 场景上绘制 SDL 2D 矩形?
- Frank Luna 在他的书"使用 DirectX12 进行 3D 游戏编程"的介绍中盒子示例的问题
- 使用 C++在 OpenGL 中对 3D 多边形进行纹理处理
- 使用 C++在 OpenGL 中移动自动旋转的 3D 多边形
- 是否可以使用 DirectX 3D 11 绘制由三角形组成的圆?
- 如何使用条件计算 3D 网格中从一个点到另一个点的所有路径
- 在 OpenGL 中使用键盘移动 3D 形状,C++
- 是否可以制作没有内部分割的cgal 3d多多马因网格?
- 我想通过OpenGL创建3D金字塔
- 使用 C++ 和 DirectX 渲染 3D Delaunay
- 如何通过CGAL通过一些3D共面顶点生成Delaunay