fix(earth-controls): zoom-aware drag sensitivity and bump version to 0.22.13

This commit is contained in:
linkong
2026-04-07 09:29:27 +08:00
parent 1a3abf73bb
commit 5b9ef0223d
7 changed files with 42 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "planet-frontend",
"version": "0.22.12",
"version": "0.22.13",
"private": true,
"dependencies": {
"@ant-design/icons": "^5.2.6",

View File

@@ -7,6 +7,9 @@ export const CONFIG = {
maxZoom: 5.0,
earthRadius: 100,
rotationSpeed: 0.0005,
dragRotationFactorBase: 0.005,
dragRotationScaleMin: 0.28,
dragRotationScaleMax: 2.0,
};
// Earth coordinate constants

View File

@@ -108,6 +108,7 @@ import {
getShowTerrain,
setAutoRotate,
resetView,
getZoomLevel,
teardownControls,
} from "./controls.js";
import {
@@ -170,7 +171,6 @@ const scratchBGPDirection = new THREE.Vector3();
const scratchBGPWorldPosition = new THREE.Vector3();
const cleanupFns = [];
const DRAG_ROTATION_FACTOR = 0.005;
const DRAG_SMOOTHING_FACTOR = 0.18;
const INERTIA_DAMPING = 0.92;
const INERTIA_MIN_VELOCITY = 0.00008;
@@ -201,6 +201,16 @@ function isEventOnHud(event) {
return HUD_INTERACTIVE_SELECTORS.some((selector) => target.closest(selector));
}
function getDragRotationFactor() {
const zoom = Math.max(getZoomLevel(), 0.01);
const scale = THREE.MathUtils.clamp(
1 / zoom,
CONFIG.dragRotationScaleMin,
CONFIG.dragRotationScaleMax,
);
return CONFIG.dragRotationFactorBase * scale;
}
function disposeMaterial(material) {
if (!material) return;
if (Array.isArray(material)) {
@@ -1142,8 +1152,9 @@ function onMouseMove(event) {
const deltaX = event.clientX - previousMousePosition.x;
const deltaY = event.clientY - previousMousePosition.y;
const rotationDeltaY = deltaX * DRAG_ROTATION_FACTOR;
const rotationDeltaX = deltaY * DRAG_ROTATION_FACTOR;
const dragRotationFactor = getDragRotationFactor();
const rotationDeltaY = deltaX * dragRotationFactor;
const rotationDeltaX = deltaY * dragRotationFactor;
targetRotation.y += rotationDeltaY;
targetRotation.x += rotationDeltaX;