3

我有一个可能很愚蠢的问题。我试图遍历平面的顶点。为什么这行不通。我收到“未捕获的类型错误:无法设置未定义的属性‘x’”错误。

plane = new THREE.Mesh(new THREE.PlaneGeometry(100,100, 10, 10), planeMat);

//Set up heightmap for plane
var vertices = plane.geometry.vertices;
var l = vertices.length;
for ( var i = 0;i < l;i++){
    vertices[i].position.x = Math.random()*50;
}

scene.add(plane);

呈现http://jsfiddle.net/sJESN/的整个代码取消注释上述循环中的注释行以获取错误。

感谢您的帮助,我已经为此发疯了 3 天!对不起任何菜鸟的错误。

4

1 回答 1

8

作为所有几何对象的一部分的顶点数组没有位置成员。位置变量是 Object3D 的成员,它是一个 THREE.Vector3。顶点数组实际上本身就是一个 THREE.Vector3 数组,因此您只需更改此行

vertices[i].position.x = Math.random() * 50;

到...

vertices[i].x = Math.random() * 50;
于 2012-07-12T19:46:03.867 回答