ThreeJS:网格消失,如果我改变它的位置


var orientation = {dim1: 100, dim2: 100, dim3: 100}
geom = new THREE.BoxGeometry(orientation.dim1, orientation.dim2, orientation.dim3);
//geom.translate(orientation.dim1 / 2, orientation.dim2 / 2, orientation.dim3 / 2);
box_material = new THREE.MeshPhongMaterial({
color: 0xffffff,
transparent: false,
opacity: 0.5,
alphaTest: 0.5
});
box_material.depthWrite  = true;
var vertices = [];
vertices.push( 0, 0, 0 );           
geom.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 )) ;
var mesh = new THREE.Mesh(geom, box_material)
//mesh.frustumCulled = false;
scene.add(mesh);

这是应该创建框的代码。如果我不设置属性&;position&;它出现了,但当我试图设定它的位置时,它就消失了。如果我尝试从控制台手动移动它的位置,它仍然卡住。

有什么问题吗?

谢谢!

如果你只是想改变框的位置,只需使用:

mesh.position.set(x, y, z);

不要碰geom.setAttribute('position')方法,因为那会破坏它的顶点,这可能不是你想要的。

最新更新