| | |
| | | |
| | | const help = false; |
| | | const debugCamera = { |
| | | x: 100, |
| | | y: 300, |
| | | x: 200, |
| | | y: 200, |
| | | z: 200 |
| | | } |
| | | |
| | |
| | | |
| | | constructor(dom) { |
| | | const { current: container } = dom; |
| | | console.log(container); |
| | | this.scene = initScene(); |
| | | this.camera = initCamera(this.scene); |
| | | this.renderer = initRenderer(container); |
| | |
| | | const 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)); |
| | | } |
| | |
| | | // this.renderer.toneMapping = THREE.ReinhardToneMapping; |
| | | renderer.toneMapping = THREE.ACESFilmicToneMapping; |
| | | renderer.setPixelRatio(window.devicePixelRatio); |
| | | renderer.setSize(window.innerWidth, window.innerHeight); |
| | | renderer.setSize(300, 500); |
| | | container.appendChild(renderer.domElement); |
| | | return renderer; |
| | | } |
| | |
| | | controls.rotateSpeed = 0.6; // 视角移动速度减慢 |
| | | // controls.autoRotate = true; // 自动旋转 |
| | | |
| | | controls.target = new THREE.Vector3(debugCamera.x, 0, debugCamera.z) // 平替 camera的lookAt |
| | | controls.target = new THREE.Vector3(0, 0, 0) // 平替 camera的lookAt |
| | | return controls; |
| | | } |
| | | |
| | |
| | | window.addEventListener('resize', function () { |
| | | camera.aspect = window.innerWidth / window.innerHeight; |
| | | camera.updateProjectionMatrix(); |
| | | renderer.setSize(window.innerWidth, window.innerHeight); |
| | | renderer.setSize(100, 500); |
| | | }, false); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | const buildFloor = (scene) => { |
| | | // const size = 10000; |
| | | // const divisions = 100; |
| | | // const helper = new THREE.GridHelper(size, divisions); |
| | | // helper.position.x = size / 2; |
| | | // helper.position.z = size / 2; |
| | | // helper.material.opacity = 0.25; |
| | | // helper.material.transparent = true; |
| | | // scene.add(helper); |
| | | // return helper; |
| | | const boxGeometry = new THREE.BoxGeometry(100, 100, 100); // 216为长度,10为宽度,10为高度 |
| | | const boxMaterial = new THREE.MeshBasicMaterial({ color: 0x40739e }); |
| | | const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial); |
| | | boxMesh.position.set(0, 0, 0); // 根据你的需求设置位置 |
| | | scene.add(boxMesh) |
| | | return boxMesh; |
| | | |
| | | const width = 3500; |
| | | const length = 7500; |
| | | const floorGeometry = new THREE.BoxGeometry(width, 1, length); // 216为长度,10为宽度,10为高度 |
| | | const floorMaterial = new THREE.MeshBasicMaterial({ |
| | | color: 0xffffff, |
| | | transparent: true, |
| | | opacity: 0.1, |
| | | }); |
| | | const floorMesh = new THREE.Mesh(floorGeometry, floorMaterial); |
| | | floorMesh.position.set(width / 2, -1, length / 2); // 根据你的需求设置位置 |
| | | floorMesh.name = 'floor'; |
| | | scene.add(floorMesh); |
| | | return floorMesh; |
| | | const size = 100; |
| | | const divisions = 100; |
| | | const helper = new THREE.GridHelper(size, divisions); |
| | | helper.position.x = size / 2; |
| | | helper.position.z = size / 2; |
| | | helper.material.opacity = 0.25; |
| | | helper.material.transparent = true; |
| | | scene.add(helper); |
| | | return helper; |
| | | } |