每个面具有K个顶点的三维点的三角剖分 [英] Triangulation of 3D points with K vertices per face
问题描述
我正在使用Three.js。我有一个 3D点(x,y,z)和一组面孔的集合。一张脸由 K点组成。它可以像凹面一样凸出。
我发现在Three.js文档中没有任何可以帮助我的东西。一种解决方案可能是对这些形状进行三角测量,但到目前为止我还没有找到任何简单的3D三角测量算法。
I'm working with Three.js. I have a collection of 3D points (x, y, z) and a collection of faces. One face is composed of K points. It can be as well convex as concave. I found nothing that could help me in the Three.js documentation. One solution could be to triangulate those shapes, but so far I haven't found any simple 3D triangulation algorithm.
另一种解决方案是做类似的事情:
The other solution would be doing something like that :
var pointsGeometry = new THREE.Geometry();
pointsGeometry.vertices.push(new THREE.Vector3(10, 0, 0));
pointsGeometry.vertices.push(new THREE.Vector3(10, 10, 0));
pointsGeometry.vertices.push(new THREE.Vector3(0, 10, 0));
pointsGeometry.vertices.push(new THREE.Vector3(1, 3, 0));
pointsGeometry.vertices.push(new THREE.Vector3(-1, 3, 0));
pointsGeometry.vertices.push(new THREE.Vector3(10, 0, 0));
var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
var mesh = new THREE.Shape/ShapeGeometry/Something(pointsGeometry, material);
group.add(mesh);
scene.add(group);
我有很多这些形状一起构建一个封闭的表面。
I have a lot of these shapes that build together a closed surface.
有任何建议吗?
感谢您的关注。
祝你有愉快的一天。
Thank you for your attention. Have a nice day.
推荐答案
正如你所指出的,有两种方法可以实现这一目标:
As you pointed out, there are 2 ways to achieve that :
- 使用3D三角测量算法(不是由Three.js提供);
- 通常使用2D三角剖分算法用于Three.js
Shape
在几何体的每个面上应用了一些变换的对象。
- use a 3D triangulation algorithm (not provided by Three.js) ;
- use the 2D triangulation algorithm normally used for Three.js
Shape
objects with some transformation applied upon each face of the geometry.
最后一个似乎很酷,但不幸的是,当我尝试时,我意识到这不是那么微不足道。我提出了类似于Paul-Jan所说的内容:
The last one seems cool but unfortunately, as I tried out I realized it's not that trivial. I came up with something similar to what Paul-Jan said :
对于几何体的每个面:
- 计算面部的质心;
- 计算面部法线;
- 计算面部矩阵;
- 将3D点投影到脸部的2D平面上;
- 创建几何体(使用
Shape $ c $进行三角化c>三角剖分算法);
- 将面矩阵应用于新创建的几何体
- 创建
网格
并将其添加到Object3D
(我尝试将所有几何图形合并为1,但它失败并带有ShapeBufferGeometry
)
- Compute the centroid the face ;
- Compute the face normal ;
- Compute the matrix of the face ;
- Project the 3D points onto the 2D plane of the face ;
- Create the geometry (triangulated with the
Shape
triangulation algorithm) ; - Apply the face matrix to the newly created geometry
- Create a
Mesh
and add it to anObject3D
(I tried to merged all the geometries into 1, but it fails with theShapeBufferGeometry
)
检查这个小提琴。
小心顶点的绕线顺序或将 THREE.Material.side
添加到 THREE.DoubleSide
以防止面孔被剔除。
Be careful to the winding order of your vertices or put the THREE.Material.side
to THREE.DoubleSide
to prevent faces from being culled.
这篇关于每个面具有K个顶点的三维点的三角剖分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!