Refine BIM section controls and styling
This commit is contained in:
+82
-2
@@ -1,10 +1,10 @@
|
||||
const SDK_VERSION = "2.6.78"; // соответствует package.json
|
||||
const SDK_URL = "./lib/dc-camera-context.es.js";
|
||||
const SDK_URL = "./lib/dc-camera-context.es.js?v=2";
|
||||
|
||||
import { createLogo } from "./src/ui/logo.js";
|
||||
import { toolbarConfig, applyToolbarVars } from "./src/ui/toolbar.js";
|
||||
import { createTemplatesMenu } from "./src/ui/templatesMenu.js?v=2";
|
||||
import { createSettingsMenu } from "./src/ui/settingsMenu.js?v=5";
|
||||
import { createSettingsMenu } from "./src/ui/settingsMenu.js?v=6";
|
||||
import { createMeasurementModal } from "./src/ui/measurementModal.js";
|
||||
import { createGlassSelect } from "./src/ui/glassSelect.js";
|
||||
import { createSliderControl } from "./src/ui/controls/slider.js";
|
||||
@@ -943,6 +943,12 @@ const cssValue = (name, fallback = "") => {
|
||||
return (v && v.trim()) || fallback;
|
||||
};
|
||||
|
||||
const clampNumber = (value, min, max, fallback) => {
|
||||
const num = Number(value);
|
||||
if (!Number.isFinite(num)) return fallback;
|
||||
return Math.max(min, Math.min(max, num));
|
||||
};
|
||||
|
||||
const hexToRgb01 = (hex) => {
|
||||
if (!hex) return [1, 1, 1];
|
||||
const clean = hex.trim();
|
||||
@@ -998,6 +1004,56 @@ const applyMeasureTheme = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const sectionPlaneThemeFromCSS = () => ({
|
||||
axes: {
|
||||
x: hexToRgb01(cssValue("--section-axis-x", "#ff2b2b")),
|
||||
y: hexToRgb01(cssValue("--section-axis-y", "#35ff4f")),
|
||||
z: hexToRgb01(cssValue("--section-axis-z", "#285bff")),
|
||||
},
|
||||
gizmoDiameter: clampNumber(parseFloat(cssValue("--section-gizmo-diameter", "1")), 0.5, 1.8, 1),
|
||||
planeFillColor: hexToRgb01(cssValue("--section-plane-fill", "#606060")),
|
||||
planeFillAlpha: clampNumber(parseFloat(cssValue("--section-plane-alpha", "0.32")), 0, 1, 0.32),
|
||||
planeEdgeColor: hexToRgb01(cssValue("--section-plane-edge", "#0d0d0d")),
|
||||
planeEdgeAlpha: clampNumber(parseFloat(cssValue("--section-plane-edge-alpha", "0.8")), 0, 1, 0.8),
|
||||
});
|
||||
|
||||
const applySectionPlaneTheme = () => {
|
||||
if (!sectionPlanesPlugin) return;
|
||||
const theme = sectionPlaneThemeFromCSS();
|
||||
Object.values(sectionPlanesPlugin._controls || {}).forEach((control) => {
|
||||
control?.setStyle?.(theme);
|
||||
});
|
||||
Object.values(sectionPlanesPlugin._overview?._planes || {}).forEach((plane) => {
|
||||
const mesh = plane?._mesh;
|
||||
if (!mesh) return;
|
||||
if (mesh.material) {
|
||||
mesh.material.diffuse = theme.planeFillColor;
|
||||
mesh.material.emissive = theme.planeFillColor;
|
||||
mesh.material.alpha = theme.planeFillAlpha;
|
||||
mesh.material.alphaMode = theme.planeFillAlpha < 1 ? "blend" : "opaque";
|
||||
}
|
||||
if (mesh.edgeMaterial) {
|
||||
mesh.edgeMaterial.edgeColor = theme.planeEdgeColor;
|
||||
mesh.edgeMaterial.edgeAlpha = theme.planeEdgeAlpha;
|
||||
}
|
||||
if (mesh.highlightMaterial) {
|
||||
mesh.highlightMaterial.fillColor = theme.planeFillColor;
|
||||
mesh.highlightMaterial.fillAlpha = theme.planeFillAlpha;
|
||||
mesh.highlightMaterial.edgeColor = theme.planeEdgeColor;
|
||||
mesh.highlightMaterial.edgeAlpha = theme.planeEdgeAlpha;
|
||||
}
|
||||
if (mesh.selectedMaterial) {
|
||||
mesh.selectedMaterial.fillColor = theme.planeFillColor;
|
||||
mesh.selectedMaterial.fillAlpha = theme.planeFillAlpha;
|
||||
mesh.selectedMaterial.edgeColor = theme.planeEdgeColor;
|
||||
mesh.selectedMaterial.edgeAlpha = theme.planeEdgeAlpha;
|
||||
}
|
||||
mesh.opacity = theme.planeFillAlpha;
|
||||
});
|
||||
viewer?.scene?.glRedraw?.();
|
||||
sectionPlanesPlugin._overview?._scene?.glRedraw?.();
|
||||
};
|
||||
|
||||
const applyHighlightTheme = () => {
|
||||
if (!viewer?.scene?.highlightMaterial) return;
|
||||
const hexToRGB = (hex) => {
|
||||
@@ -1229,8 +1285,21 @@ const setSectionAxisActive = (axis) => {
|
||||
});
|
||||
};
|
||||
|
||||
const positionSectionToolbar = () => {
|
||||
if (!sectionButton || !sectionToolbar) return;
|
||||
const rect = sectionButton.getBoundingClientRect();
|
||||
if (!rect.width || !rect.height) return;
|
||||
const gap = parseFloat(cssValue("--tb-gap", "10")) || 10;
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty("--section-toolbar-left", `${Math.round(rect.right + gap)}px`);
|
||||
root.style.setProperty("--section-toolbar-bottom", `${Math.round(Math.max(8, window.innerHeight - rect.bottom))}px`);
|
||||
};
|
||||
|
||||
const setSectionModeActive = (active) => {
|
||||
sectionModeActive = !!active && !!sectionPlanesPlugin && getSectionPlaneIds().length > 0 && !isGuestMode();
|
||||
if (sectionModeActive) {
|
||||
positionSectionToolbar();
|
||||
}
|
||||
sectionButton?.classList.toggle("active", sectionModeActive);
|
||||
sectionToolbar?.classList.toggle("hidden", !sectionModeActive);
|
||||
document.body.dataset.sectionMode = sectionModeActive ? "active" : "";
|
||||
@@ -1287,6 +1356,7 @@ const createOrUpdateSectionPlane = (axis = "camera") => {
|
||||
activeSectionPlaneId = sectionPlane.id || activeSectionPlaneId;
|
||||
}
|
||||
|
||||
applySectionPlaneTheme();
|
||||
sectionPlanesPlugin.showControl(activeSectionPlaneId);
|
||||
setSectionModeActive(true);
|
||||
setSectionAxisActive(axis);
|
||||
@@ -1569,6 +1639,11 @@ window.addEventListener("pointerup", scheduleCameraRearm, true);
|
||||
window.addEventListener("mouseup", scheduleCameraRearm, true);
|
||||
window.addEventListener("touchend", scheduleCameraRearm, true);
|
||||
window.addEventListener("touchcancel", scheduleCameraRearm, true);
|
||||
window.addEventListener("resize", () => {
|
||||
if (sectionModeActive) {
|
||||
positionSectionToolbar();
|
||||
}
|
||||
});
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (!document.hidden) {
|
||||
scheduleCameraRearm();
|
||||
@@ -3099,6 +3174,7 @@ const initViewer = async () => {
|
||||
overviewVisible: false,
|
||||
});
|
||||
sectionPlanesPlugin.setOverviewVisible(false);
|
||||
applySectionPlaneTheme();
|
||||
setSectionModeActive(false);
|
||||
} else {
|
||||
console.warn("SectionPlanesPlugin is not available in the loaded SDK build");
|
||||
@@ -3971,6 +4047,9 @@ const loadProjectSnapshot = async (project) => {
|
||||
if (key && key.startsWith("measure")) {
|
||||
applyMeasureTheme();
|
||||
}
|
||||
if (key && key.startsWith("section")) {
|
||||
applySectionPlaneTheme();
|
||||
}
|
||||
focusCanvasAndControls();
|
||||
},
|
||||
onShow: () => {
|
||||
@@ -3986,6 +4065,7 @@ const loadProjectSnapshot = async (project) => {
|
||||
rebuildNavCube(sdk);
|
||||
applyHighlightTheme();
|
||||
applyMeasureTheme();
|
||||
applySectionPlaneTheme();
|
||||
if (displayModeControl && displayModeSelectHost) {
|
||||
displayModeSelect = createGlassSelect({
|
||||
host: displayModeSelectHost,
|
||||
|
||||
Reference in New Issue
Block a user