当我尝试使用FirstPersonControls时,它只会给我这个错误:
未捕获的TypeError:targetPosition.setFromSphericalCoords不是 功能 在THREE.FirstPersonControls.update(FirstPersonControls.js:276) 在动画(main.js:143)
const scene = new THREE.Scene()
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild( renderer.domElement)
const camera = new
THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight, 0.1,
1000 )
camera.position.set( 0, 10, 100)
camera.rotation.x = -0.5
const starsGeometry = new THREE.Geometry();
for ( let i = 0; i < 10000; i ++ ) {
const star = new THREE.Vector3()
star.x = THREE.Math.randFloatSpread(2000)
star.y = THREE.Math.randFloatSpread(2000)
star.z = THREE.Math.randFloatSpread(2000)
starsGeometry.vertices.push( star )
}
const starsMaterial = new THREE.PointsMaterial( { color: 0x888888 } )
const starField = new THREE.Points( starsGeometry, starsMaterial )
scene.add( starField )
controls = new THREE.FirstPersonControls( camera, renderer.domElement )
controls.lookSpeed = 0.1
controls.movementSpeed = 100
const clock = new THREE.Clock( true )
function animate() {
requestAnimationFrame( animate )
renderer.render( scene, camera )
controls.update( clock.getDelta() )
}
animate()
我所需要做的就是能够用鼠标环顾四周,并使指针仍然可见,但是我不知道该怎么做。