| | |
| | | controls.minPolarAngle = 0; // 最小俯仰角度(向下看) |
| | | controls.maxPolarAngle = Math.PI / 2.1; // 最大俯仰角度(向上看) |
| | | controls.rotateSpeed = 0.6; // 视角移动速度减慢 |
| | | controls.autoRotate = true; // 自动旋转 |
| | | controls.autoRotate = false; // 自动旋转 |
| | | |
| | | controls.target = new THREE.Vector3(0, 250, 0) // 屏幕中心点 平替 camera的lookAt |
| | | return controls; |
| | |
| | | let that = this; |
| | | const raycaster = new THREE.Raycaster(); |
| | | const mouse = new THREE.Vector2(); |
| | | |
| | | this.dom.addEventListener("dblclick", (event) => { |
| | | }) |
| | | this.dom.addEventListener("click", (event) => { |
| | |
| | | x = event.clientX; |
| | | y = event.clientY; |
| | | } |
| | | let rect = this.dom.getBoundingClientRect(); |
| | | mouse.x = ((x - rect.left) / rect.width) * 2 - 1; |
| | | mouse.y = -((y - rect.top) / rect.height) * 2 + 1; |
| | | event.preventDefault(); |
| | | // mouse.x = (x / this.getFullWidth()) * 2 - 1; |
| | | // mouse.y = -(y / this.getFullHeight()) * 2 + 1; |
| | | mouse.x = (x / window.innerWidth) * 2 - 1; |
| | | mouse.y = -(y / window.innerHeight) * 2 + 1; |
| | | raycaster.setFromCamera(mouse, that.camera); |
| | | let intersects = raycaster.intersectObjects(that.objects, true); |
| | | console.log(intersects); |
| | | if (intersects.length === 0) { |
| | | return; |
| | | } |
| | | let objName = intersects[0].object.name; |
| | | if (objName.startsWith("locNo")) { |
| | | if (this.handleClick) { |
| | | this.handleClick(objName, x, y); |
| | | } |
| | | if (objName && this.handleClick) { |
| | | this.handleClick(objName, x, y); |
| | | } |
| | | }, false); |
| | | } |