| | |
| | | initLight(this.scene); |
| | | |
| | | this.animate(); |
| | | this.build(); |
| | | } |
| | | |
| | | animate = () => { |
| | |
| | | initScene = () => { |
| | | const scene = new THREE.Scene(); |
| | | // scene.background = new THREE.Color(0xf0f0f0); |
| | | scene.background = new THREE.Color(0x333333); |
| | | // scene.background = new THREE.Color(0x333333); |
| | | if (help) { |
| | | scene.add(new THREE.AxesHelper(1000)); |
| | | } |
| | |
| | | |
| | | initCamera = () => { |
| | | const camera = new THREE.PerspectiveCamera(70, this.getFullWidth() / this.getFullHeight(), 1, 60000); |
| | | camera.position.set(-300, 300, 300); |
| | | camera.position.set(-400, 400, 400); |
| | | this.scene.add(camera); |
| | | return camera; |
| | | } |
| | |
| | | controls.rotateSpeed = 0.6; // 视角移动速度减慢 |
| | | controls.autoRotate = true; // 自动旋转 |
| | | |
| | | controls.target = new THREE.Vector3(0, 0, 0) // 平替 camera的lookAt |
| | | controls.target = new THREE.Vector3(0, 250, 0) // 屏幕中心点 平替 camera的lookAt |
| | | return controls; |
| | | } |
| | | |
| | |
| | | }, false); |
| | | } |
| | | |
| | | build = () => { |
| | | buildDemo(this.scene); |
| | | generateMesh = (fn) => { |
| | | fn(this.scene); |
| | | } |
| | | |
| | | handleClick = () => { |
| | |
| | | scene.add(ambientLight); |
| | | |
| | | const spotLight = new THREE.SpotLight(0xffffff, 8); |
| | | spotLight.position.set(-300, 300, 0); |
| | | spotLight.position.set(-300, 1000, 0); |
| | | spotLight.angle = Math.PI / 4; // 角度 |
| | | spotLight.distance = 800; // 距离 |
| | | spotLight.decay = 0; // 光衰 |
| | |
| | | if (help) { |
| | | scene.add(new THREE.SpotLightHelper(spotLight)); |
| | | } |
| | | } |
| | | |
| | | const buildDemo = (scene) => { |
| | | const boxGeometry = new THREE.BoxGeometry(100, 100, 100); |
| | | const boxMaterial = new THREE.MeshStandardMaterial({ |
| | | color: '#222f3e', |
| | | }); |
| | | const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial); |
| | | boxMesh.position.set(0, 0, 0); |
| | | scene.add(boxMesh) |
| | | return boxMesh; |
| | | } |