let moveSpeed, movePlane, moveLine, moveStartVector, moveEndVector; //初始化平移切面参数 function initMoveClipPlaneArgs() { moveSpeed = 5; movePlane = new THREE.Plane(); moveLine = new THREE.Line3(); moveStartVector = new THREE.Vector3(); moveEndVector = new THREE.Vector3(); } //平移切面 function moveClipPlane(currentMouse, lastMouse) { let distance = getMoveDistance(currentMouse, lastMouse); if (distance == undefined || !canMoveForward(distance)) { return; } let newConstant = ClipPlaneManager.activeMeshInfo.Mesh.Plane.constant + distance; movePlane.set(ClipPlaneManager.activeMeshInfo.Mesh.Plane.normal, newConstant); refreshClipMesh(movePlane, ClipPlaneManager.activeMeshInfo.Mesh.Object, ClipPlaneManager.activeMeshInfo.Mesh.ImageName, function () { if (ClipPlaneManager.activeMeshInfo != undefined) { ClipPlaneManager.activeMeshInfo.Mesh.Plane.set(movePlane.normal, newConstant); addRotateInfo(); } EventCenter.emit("updateLastMousePos", currentMouse); }); } //计算平移距离 function getMoveDistance(currentMouse, lastMouse) { setMouseVector(OSHelper.clientX(currentMouse), OSHelper.clientY(currentMouse), moveEndVector); setMouseVector(lastMouse.x, lastMouse.y, moveStartVector); moveLine.set(moveStartVector, moveEndVector); let distance = moveLine.distance() * moveSpeed; if (distance <= 2) { return undefined; } if (moveEndVector.clone().sub(moveStartVector).dot(ClipPlaneManager.activeMeshInfo.Mesh.Plane.normal) > 0) { distance = -distance; } return distance; } //判断切面是否移动到了最远点 function canMoveForward(moveDistance) { if (ClipPlaneManager.activeMeshInfo.Mesh != undefined) { if (moveDistance > 0 || ClipPlaneManager.activeMeshInfo.Mesh.Plane.constant + moveDistance > ClipPlaneManager.activeMeshInfo.MaxForwardDistance) { return true; } } return false; } //平面鼠标坐标转三维坐标 function setMouseVector(mouseX,mouseY, MouseVector) { MouseVector.set((mouseX / window.innerWidth) * 2 - 1, 1 - (mouseY / window.innerHeight) * 2, 0.5); MouseVector.unproject(camera); }