ThreeJS triangulateShape返回null

时间:2018-04-28 10:01:53

标签: three.js triangulation

我正在尝试使用ThreeJS triangulateShape创建自定义形状。

例如:如果点是:["-1 0 1", "-1 0 -1", "1 0 -1", "1 0 1"]一个简单的正方形,它应该自动创建由三角形组成的面:["0 1 2", "0 2 3"]

我正在尝试使用shapeUtils.triangulateShape函数但它失败了。代码如下所示:

var geometry = new THREE.Geometry();
var points = data.vertices.map(function (vertex) {
    return vertex.split(' ').map(function(x){return parseFloat(x);});
});
for(var i =0; i < points.length; i++) {
  geometry.vertices.push(new THREE.Vector3(points[i][0], points[i][1], points[i][2]));
}
var holes =[];
var triangles = THREE.ShapeUtils.triangulateShape( geometry.vertices, holes );

它创建一个空数组。我认为将params传递给triangulateShape有些不对劲但是无法弄明白。感谢

1 个答案:

答案 0 :(得分:0)

ShapeUtils.triangulateShape仅接受2D轮廓作为第一个参数。您正在应用3D数据。