我试图在网格物体上使用three.js lookAt()方法(来自CylinderBufferGeometry),以便它朝向一个点,但是当我使用.lookAt()方法时,它会导致网格物体从视野中消失
如果我注释掉.lookAt()方法,则圆柱体显示正常。我使用的是THREE.PerspectiveCamera和THREE.WebGLRenderer,可能与此问题有关。
// Build cylinder
var cylinderRadius = 0.15
var cylinderHeight = 20
var geometry = new THREE.CylinderBufferGeometry(cylinderRadius, cylinderRadius, cylinderHeight);
var material = new THREE.MeshBasicMaterial({color: 0xffffff});
var cylinder = new THREE.Mesh(geometry, material);
// Point the cylinder up
cylinder.geometry.rotateX( Math.PI / 2);
cylinder.geometry.translate(0,0, cylinderHeight/2 );
// Move cylinder to position
cylinder.position.x = 10;
cylinder.position.y = 10;
// Look at point
cylinder.lookAt(0,0,15); // <-- ISSUE OCCURS HERE
scene.add(cylinder);
render();
答案 0 :(得分:1)
使用cylinder.lookAt(new THREE.Vector3(0,0,15));而不是cylinder.lookAt(0,0,15);