我正在尝试在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
);