beam: add zoom speed control
This commit is contained in:
+50
-3
@@ -7,6 +7,7 @@ import { createTemplatesMenu } from "./src/ui/templatesMenu.js";
|
||||
import { createSettingsMenu } from "./src/ui/settingsMenu.js";
|
||||
import { createMeasurementModal } from "./src/ui/measurementModal.js";
|
||||
import { createGlassSelect } from "./src/ui/glassSelect.js";
|
||||
import { createSliderControl } from "./src/ui/controls/slider.js";
|
||||
import "./theme.js";
|
||||
import { TransformGizmo } from "./transformGizmo.js";
|
||||
import { createObjectModal } from "./src/ui/objectModal.js";
|
||||
@@ -42,6 +43,7 @@ const lightingModeControl = document.getElementById("lightingModeControl");
|
||||
const lightingModeSelectHost = document.getElementById("lightingModeSelect");
|
||||
const navigationAxisControl = document.getElementById("navigationAxisControl");
|
||||
const navigationAxisSelectHost = document.getElementById("navigationAxisSelect");
|
||||
const zoomSpeedControl = document.getElementById("zoomSpeedControl");
|
||||
const logList = document.getElementById("logList");
|
||||
const loaderEl = document.getElementById("loader");
|
||||
const navCubeCanvas = document.getElementById("navCube");
|
||||
@@ -216,9 +218,11 @@ const sceneModels = {}; // modelId -> SceneModel
|
||||
let activeDisplayMode = "source";
|
||||
let activeLightingMode = "ambient";
|
||||
let activeNavigationAxis = "auto";
|
||||
let activeZoomSpeed = 20;
|
||||
let displayModeSelect = null;
|
||||
let lightingModeSelect = null;
|
||||
let navigationAxisSelect = null;
|
||||
let zoomSpeedSlider = null;
|
||||
let defaultCameraWorldAxis = null;
|
||||
let defaultCameraUp = null;
|
||||
let currentSelection = null; // { modelId, objectId }
|
||||
@@ -244,27 +248,42 @@ const treeModelIds = new Set();
|
||||
|
||||
const CAMERA_CONTROL_SETTINGS = {
|
||||
keyboardDollyRate: 45,
|
||||
mouseWheelDollyRate: 20,
|
||||
dollyInertia: 0,
|
||||
dollyMinSpeed: 0.008,
|
||||
dollyProximityThreshold: 90,
|
||||
};
|
||||
|
||||
const normalizeZoomSpeed = (value) => {
|
||||
const numeric = Number(value);
|
||||
if (!Number.isFinite(numeric)) return 20;
|
||||
return Math.min(100, Math.max(5, Math.round(numeric)));
|
||||
};
|
||||
|
||||
const configureCameraControl = () => {
|
||||
const control = viewer?.cameraControl;
|
||||
if (!control) return;
|
||||
activeZoomSpeed = normalizeZoomSpeed(activeZoomSpeed);
|
||||
control.panRightClick = false;
|
||||
control.followPointer = true;
|
||||
control.doublePickFlyTo = false;
|
||||
control.smartPivot = true;
|
||||
control.zoomOnMouseWheel = true;
|
||||
control.keyboardDollyRate = CAMERA_CONTROL_SETTINGS.keyboardDollyRate;
|
||||
control.mouseWheelDollyRate = CAMERA_CONTROL_SETTINGS.mouseWheelDollyRate;
|
||||
control.mouseWheelDollyRate = activeZoomSpeed;
|
||||
control.dollyInertia = CAMERA_CONTROL_SETTINGS.dollyInertia;
|
||||
control.dollyMinSpeed = CAMERA_CONTROL_SETTINGS.dollyMinSpeed;
|
||||
control.dollyProximityThreshold = CAMERA_CONTROL_SETTINGS.dollyProximityThreshold;
|
||||
};
|
||||
|
||||
const setZoomSpeed = (value, { announce = false } = {}) => {
|
||||
activeZoomSpeed = normalizeZoomSpeed(value);
|
||||
zoomSpeedSlider?.setValue?.(activeZoomSpeed);
|
||||
configureCameraControl();
|
||||
if (announce) {
|
||||
setStatus(`Скорость зума: ${activeZoomSpeed}%`);
|
||||
}
|
||||
};
|
||||
|
||||
const ensureCameraControlActive = () => {
|
||||
if (!viewer || !viewer.cameraControl) return;
|
||||
configureCameraControl();
|
||||
@@ -2205,6 +2224,7 @@ const buildProjectSnapshot = async (name) => {
|
||||
displayMode: activeDisplayMode,
|
||||
lightingMode: activeLightingMode,
|
||||
navigationAxis: activeNavigationAxis,
|
||||
zoomSpeed: activeZoomSpeed,
|
||||
selection: {
|
||||
ids: lastSelection.ids || [],
|
||||
modelId: lastSelection.modelId || null,
|
||||
@@ -2267,7 +2287,8 @@ const buildModelViewerSettings = () => ({
|
||||
edges: !!toggleEdges?.checked,
|
||||
displayMode: activeDisplayMode,
|
||||
lightingMode: activeLightingMode,
|
||||
navigationAxis: activeNavigationAxis
|
||||
navigationAxis: activeNavigationAxis,
|
||||
zoomSpeed: activeZoomSpeed
|
||||
} : {},
|
||||
design: settingsMenu?.getState ? settingsMenu.getState() : {}
|
||||
});
|
||||
@@ -2307,6 +2328,9 @@ const applyModelViewerSettings = (settings, { applyCamera = true, applyDesign =
|
||||
activeNavigationAxis = viewerState.navigationAxis;
|
||||
applyNavigationAxis({ resetAuto: false });
|
||||
}
|
||||
if (viewerState.zoomSpeed !== undefined) {
|
||||
setZoomSpeed(viewerState.zoomSpeed);
|
||||
}
|
||||
if (applyCamera) {
|
||||
applyCameraSnapshot(viewerState.camera);
|
||||
}
|
||||
@@ -2391,6 +2415,9 @@ const applyViewerState = (state) => {
|
||||
activeNavigationAxis = state.navigationAxis;
|
||||
applyNavigationAxis({ resetAuto: false });
|
||||
}
|
||||
if (state.zoomSpeed !== undefined) {
|
||||
setZoomSpeed(state.zoomSpeed);
|
||||
}
|
||||
if (state.transforms && typeof state.transforms === "object") {
|
||||
Object.keys(transformStore).forEach((k) => delete transformStore[k]);
|
||||
Object.assign(transformStore, safeClone(state.transforms));
|
||||
@@ -2971,6 +2998,9 @@ const initViewer = async () => {
|
||||
activeNavigationAxis = params.get("navigationAxis") || params.get("axis") || "auto";
|
||||
applyNavigationAxis({ resetAuto: false });
|
||||
}
|
||||
if (params.has("zoomSpeed")) {
|
||||
setZoomSpeed(params.get("zoomSpeed"));
|
||||
}
|
||||
|
||||
if (modelSettings?.viewerState) {
|
||||
modelSettings = {
|
||||
@@ -2980,6 +3010,7 @@ const initViewer = async () => {
|
||||
displayMode: activeDisplayMode,
|
||||
lightingMode: activeLightingMode,
|
||||
navigationAxis: activeNavigationAxis,
|
||||
zoomSpeed: activeZoomSpeed,
|
||||
edges: params.has("edges") ? params.get("edges") !== "false" : modelSettings.viewerState.edges
|
||||
}
|
||||
};
|
||||
@@ -3327,6 +3358,22 @@ const loadProjectSnapshot = async (project) => {
|
||||
});
|
||||
setNavigationAxisControlState();
|
||||
}
|
||||
if (zoomSpeedControl) {
|
||||
zoomSpeedSlider = createSliderControl({
|
||||
label: "Скорость зума",
|
||||
value: activeZoomSpeed,
|
||||
min: 5,
|
||||
max: 100,
|
||||
step: 1,
|
||||
className: "inspector-slider",
|
||||
showValue: true,
|
||||
formatValue: (value) => `${Math.round(value)}%`,
|
||||
onChange: (value) => {
|
||||
setZoomSpeed(value);
|
||||
},
|
||||
});
|
||||
zoomSpeedControl.replaceChildren(zoomSpeedSlider);
|
||||
}
|
||||
loadProjectsList().catch(() => {
|
||||
templatesMenu?.setData({ templates: templateFallbacks, projects: [], error: "API недоступно" });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user