1

我正在尝试在three.js 中创建一个大地形,我使用physi.js 作为物理引擎。

到目前为止,从高度图生成几何图形没有问题。但是,当我尝试将其添加为 aTHREE.Mesh时,它运行良好,当我尝试将其添加为 a 时,Physijs.HeightfieldMesh我收到以下错误:

TypeError: geometry.vertices[(a + (((this._physijs.ypts - b) - 1) * this._physijs.ypts))] is undefined

几何图形生成为平面,然后根据高度图修改每个顶点的 Z 位置。

var geometry = new THREE.PlaneGeometry( img.naturalWidth, img.naturalHeight,img.naturalWidth -1, img.naturalHeight -1 );
var material = new THREE.MeshLambertMaterial( { color : 0x0F0F0F } );

//set height of vertices
for ( var i = 0; i<plane.geometry.vertices.length; i++ ) {
    plane.geometry.vertices[i].z = data[i];//let's just assume the data is correct since it works as a THREE.Mesh
}

var terrain = new THREE.Mesh(geometry, material); // works

//does not work
var terrain = new Physijs.heightfieldMesh(
    geometry, 
    material,
    0
);
4

1 回答 1

1

我认为您的问题是您在循环中使用“plane.geometry”而不是“geometry”来设置顶点高度。
也许应该是:

//set height of vertices
for ( var i = 0; i < geometry.vertices.length; i++ ) {
    geometry.vertices[i].z = data[i];//let's just assume the data is correct since it works as a THREE.Mesh
}

我创建的这个小提琴似乎工作正常。

于 2014-11-16T06:58:33.763 回答