|
|
@@ -170,7 +170,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
|
|
|
controls.enablePan = false; // 禁用右键平移功能
|
|
|
|
|
|
- controls.enableZoom = false; // 必须禁用轨道控制器的默认缩放[1](@ref)
|
|
|
+ controls.enableZoom = true; // 必须禁用轨道控制器的默认缩放[1](@ref)
|
|
|
|
|
|
controls.enableDamping = true;
|
|
|
controls.dampingFactor = 0.25;
|
|
|
@@ -178,55 +178,55 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
controls.maxPolarAngle = Math.PI / 2;
|
|
|
|
|
|
// 兼容鼠标滚轮与触摸屏双指缩放
|
|
|
- const handleZoom = (delta) => {
|
|
|
- // console.log('--------',delta);
|
|
|
+ // const handleZoom = (delta) => {
|
|
|
+ // // console.log('--------',delta);
|
|
|
|
|
|
- cube.updateMatrixWorld(true);
|
|
|
- // 计算包围盒
|
|
|
- const box = new THREE.Box3().setFromObject(cube);
|
|
|
- const center = new THREE.Vector3();
|
|
|
- box.getCenter(center);
|
|
|
+ // cube.updateMatrixWorld(true);
|
|
|
+ // // 计算包围盒
|
|
|
+ // const box = new THREE.Box3().setFromObject(cube);
|
|
|
+ // const center = new THREE.Vector3();
|
|
|
+ // box.getCenter(center);
|
|
|
|
|
|
- // 居中模型
|
|
|
- cube.position.sub(center);
|
|
|
+ // // 居中模型
|
|
|
+ // cube.position.sub(center);
|
|
|
|
|
|
- cube.scale.multiplyScalar(delta);
|
|
|
- cube.scale.clampScalar(0.5, 4); // 限制缩放范围0.5-3倍[1,6](@ref)
|
|
|
- };
|
|
|
+ // cube.scale.multiplyScalar(delta);
|
|
|
+ // cube.scale.clampScalar(0.5, 4); // 限制缩放范围0.5-3倍[1,6](@ref)
|
|
|
+ // };
|
|
|
|
|
|
// 鼠标滚轮事件
|
|
|
- window.addEventListener(
|
|
|
- "wheel",
|
|
|
- (e) => {
|
|
|
- e.preventDefault();
|
|
|
- const zoomFactor = e.deltaY > 0 ? 0.95 : 1.05;
|
|
|
- handleZoom(zoomFactor);
|
|
|
- },
|
|
|
- { passive: false }
|
|
|
- );
|
|
|
+ // window.addEventListener(
|
|
|
+ // "wheel",
|
|
|
+ // (e) => {
|
|
|
+ // e.preventDefault();
|
|
|
+ // const zoomFactor = e.deltaY > 0 ? 0.95 : 1.05;
|
|
|
+ // handleZoom(zoomFactor);
|
|
|
+ // },
|
|
|
+ // { passive: false }
|
|
|
+ // );
|
|
|
|
|
|
// 触摸屏双指缩放
|
|
|
- let initialDistance = 0;
|
|
|
- window.addEventListener("touchstart", (e) => {
|
|
|
- if (e.touches.length === 2) {
|
|
|
- initialDistance = Math.hypot(
|
|
|
- e.touches[0].pageX - e.touches[1].pageX,
|
|
|
- e.touches[0].pageY - e.touches[1].pageY
|
|
|
- );
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- window.addEventListener("touchmove", (e) => {
|
|
|
- if (e.touches.length === 2) {
|
|
|
- const currentDistance = Math.hypot(
|
|
|
- e.touches[0].pageX - e.touches[1].pageX,
|
|
|
- e.touches[0].pageY - e.touches[1].pageY
|
|
|
- );
|
|
|
- const zoomFactor = currentDistance > initialDistance ? 1.01 : 0.99;
|
|
|
- handleZoom(zoomFactor);
|
|
|
- initialDistance = currentDistance;
|
|
|
- }
|
|
|
- });
|
|
|
+ // let initialDistance = 0;
|
|
|
+ // window.addEventListener("touchstart", (e) => {
|
|
|
+ // if (e.touches.length === 2) {
|
|
|
+ // initialDistance = Math.hypot(
|
|
|
+ // e.touches[0].pageX - e.touches[1].pageX,
|
|
|
+ // e.touches[0].pageY - e.touches[1].pageY
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+
|
|
|
+ // window.addEventListener("touchmove", (e) => {
|
|
|
+ // if (e.touches.length === 2) {
|
|
|
+ // const currentDistance = Math.hypot(
|
|
|
+ // e.touches[0].pageX - e.touches[1].pageX,
|
|
|
+ // e.touches[0].pageY - e.touches[1].pageY
|
|
|
+ // );
|
|
|
+ // const zoomFactor = currentDistance > initialDistance ? 1.01 : 0.99;
|
|
|
+ // handleZoom(zoomFactor);
|
|
|
+ // initialDistance = currentDistance;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
|
|
|
function animate() {
|
|
|
//cube.rotation.x += 0.01;
|