Add BIM section plane tool
This commit is contained in:
+196
-1
@@ -39,6 +39,9 @@ const measureButton = document.querySelector('[data-action="measure"]');
|
||||
const settingsButton = document.querySelector('[data-action="settings"]');
|
||||
const templatesButton = document.querySelector('[data-action="templates"]');
|
||||
const shareButton = document.querySelector('[data-action="share"]');
|
||||
const sectionButton = document.querySelector('[data-action="section"]');
|
||||
const sectionToolbar = document.getElementById("sectionToolbar");
|
||||
const sectionOverviewCanvas = document.getElementById("sectionPlanesOverview");
|
||||
const projectionToggle = document.querySelector('[data-action="projection"]');
|
||||
const treeContainer = document.getElementById("treeContainer");
|
||||
const displayModeControl = document.getElementById("displayModeControl");
|
||||
@@ -250,6 +253,11 @@ let measurePlugin = null;
|
||||
let measureControl = null;
|
||||
let measureActive = false;
|
||||
let activeMeasurementId = null;
|
||||
let sectionPlanesPlugin = null;
|
||||
let activeSectionPlaneId = null;
|
||||
let sectionPlaneCounter = 0;
|
||||
let sectionModeActive = false;
|
||||
let activeSectionAxis = null;
|
||||
let objectContextModal = null;
|
||||
let mathUtil = null;
|
||||
let selectionState = null; // { ids, modelId, pivotCenter, baseTransforms: Map, transform }
|
||||
@@ -454,6 +462,9 @@ const applyRuntimeMode = () => {
|
||||
if (dropZone) {
|
||||
dropZone.style.pointerEvents = isGuestMode() ? "none" : "";
|
||||
}
|
||||
if (sectionToolbar && isGuestMode()) {
|
||||
sectionToolbar.classList.add("hidden");
|
||||
}
|
||||
};
|
||||
|
||||
const initializeRuntimeMode = async () => {
|
||||
@@ -1171,6 +1182,155 @@ const clearMeasurements = () => {
|
||||
closeMeasurementModal();
|
||||
};
|
||||
|
||||
const getSectionPlaneIds = () => Object.keys(sectionPlanesPlugin?.sectionPlanes || {});
|
||||
|
||||
const getActiveSectionPlane = () => {
|
||||
if (!sectionPlanesPlugin) return null;
|
||||
if (activeSectionPlaneId && sectionPlanesPlugin.sectionPlanes?.[activeSectionPlaneId]) {
|
||||
return sectionPlanesPlugin.sectionPlanes[activeSectionPlaneId];
|
||||
}
|
||||
const firstId = getSectionPlaneIds()[0] || null;
|
||||
activeSectionPlaneId = firstId;
|
||||
return firstId ? sectionPlanesPlugin.sectionPlanes[firstId] : null;
|
||||
};
|
||||
|
||||
const setAllSectionPlanesActive = (active) => {
|
||||
getSectionPlaneIds().forEach((id) => {
|
||||
const sectionPlane = sectionPlanesPlugin?.sectionPlanes?.[id];
|
||||
if (sectionPlane) {
|
||||
sectionPlane.active = !!active;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const getSectionCenter = () => {
|
||||
const sceneAABB = viewer?.scene?.aabb;
|
||||
const aabb = Array.isArray(sceneAABB) || ArrayBuffer.isView(sceneAABB)
|
||||
? Array.from(sceneAABB)
|
||||
: null;
|
||||
const center = centerFromAABB(aabb);
|
||||
return center.every((value) => Number.isFinite(value)) ? center : [0, 0, 0];
|
||||
};
|
||||
|
||||
const getCameraSectionDir = () => {
|
||||
const eye = snapshotVec(viewer?.camera?.eye) || [0, 0, 1];
|
||||
const look = snapshotVec(viewer?.camera?.look) || [0, 0, 0];
|
||||
return normalizeVec3([
|
||||
look[0] - eye[0],
|
||||
look[1] - eye[1],
|
||||
look[2] - eye[2],
|
||||
], [0, 0, -1]);
|
||||
};
|
||||
|
||||
const setSectionAxisActive = (axis) => {
|
||||
activeSectionAxis = axis || null;
|
||||
sectionToolbar?.querySelectorAll("[data-section-action]").forEach((btn) => {
|
||||
btn.classList.toggle("active", !!axis && btn.dataset.sectionAction === axis);
|
||||
});
|
||||
};
|
||||
|
||||
const setSectionModeActive = (active) => {
|
||||
sectionModeActive = !!active && !!sectionPlanesPlugin && getSectionPlaneIds().length > 0 && !isGuestMode();
|
||||
sectionButton?.classList.toggle("active", sectionModeActive);
|
||||
sectionToolbar?.classList.toggle("hidden", !sectionModeActive);
|
||||
document.body.dataset.sectionMode = sectionModeActive ? "active" : "";
|
||||
sectionPlanesPlugin?.setOverviewVisible?.(sectionModeActive);
|
||||
if (!sectionModeActive) {
|
||||
setSectionAxisActive(null);
|
||||
sectionPlanesPlugin?.hideControl?.();
|
||||
}
|
||||
};
|
||||
|
||||
const updateSectionControls = () => {
|
||||
const available = !!sectionPlanesPlugin && !isGuestMode() && activeModels.length > 0;
|
||||
if (sectionButton) {
|
||||
sectionButton.disabled = !available;
|
||||
sectionButton.classList.toggle("disabled", !available);
|
||||
sectionButton.classList.toggle("active", available && sectionModeActive);
|
||||
}
|
||||
if (!available) {
|
||||
sectionToolbar?.classList.add("hidden");
|
||||
document.body.dataset.sectionMode = "";
|
||||
sectionPlanesPlugin?.setOverviewVisible?.(false);
|
||||
}
|
||||
};
|
||||
|
||||
const createOrUpdateSectionPlane = (axis = "camera") => {
|
||||
if (!sectionPlanesPlugin) {
|
||||
showError("Разрез недоступен в текущей сборке SDK");
|
||||
return null;
|
||||
}
|
||||
if (!activeModels.length) {
|
||||
showError("Сначала загрузите модель");
|
||||
return null;
|
||||
}
|
||||
|
||||
setMeasureActive(false);
|
||||
const dirs = {
|
||||
camera: getCameraSectionDir(),
|
||||
x: [1, 0, 0],
|
||||
y: [0, 1, 0],
|
||||
z: [0, 0, 1],
|
||||
};
|
||||
const dir = dirs[axis] || dirs.camera;
|
||||
const pos = getSectionCenter();
|
||||
let sectionPlane = getActiveSectionPlane();
|
||||
|
||||
if (!sectionPlane) {
|
||||
const id = `sectionPlane-${++sectionPlaneCounter}`;
|
||||
sectionPlane = sectionPlanesPlugin.createSectionPlane({ id, pos, dir });
|
||||
activeSectionPlaneId = sectionPlane.id || id;
|
||||
} else {
|
||||
sectionPlane.pos = pos;
|
||||
sectionPlane.dir = dir;
|
||||
sectionPlane.active = true;
|
||||
activeSectionPlaneId = sectionPlane.id || activeSectionPlaneId;
|
||||
}
|
||||
|
||||
sectionPlanesPlugin.showControl(activeSectionPlaneId);
|
||||
setSectionModeActive(true);
|
||||
setSectionAxisActive(axis);
|
||||
setStatus("Разрез включён");
|
||||
rearmCameraControl();
|
||||
return sectionPlane;
|
||||
};
|
||||
|
||||
const clearSectionPlanes = () => {
|
||||
sectionPlanesPlugin?.clear?.();
|
||||
activeSectionPlaneId = null;
|
||||
setSectionModeActive(false);
|
||||
};
|
||||
|
||||
const flipSectionPlanes = () => {
|
||||
if (!getActiveSectionPlane()) {
|
||||
createOrUpdateSectionPlane("camera");
|
||||
return;
|
||||
}
|
||||
setAllSectionPlanesActive(true);
|
||||
sectionPlanesPlugin?.flipSectionPlanes?.();
|
||||
sectionPlanesPlugin?.showControl?.(activeSectionPlaneId);
|
||||
setSectionModeActive(true);
|
||||
setStatus("Разрез инвертирован");
|
||||
};
|
||||
|
||||
const toggleSectionPlanes = () => {
|
||||
if (sectionModeActive) {
|
||||
setAllSectionPlanesActive(false);
|
||||
setSectionModeActive(false);
|
||||
setStatus("Разрез выключен");
|
||||
return;
|
||||
}
|
||||
if (getSectionPlaneIds().length > 0) {
|
||||
setAllSectionPlanesActive(true);
|
||||
activeSectionPlaneId = activeSectionPlaneId || getSectionPlaneIds()[0];
|
||||
sectionPlanesPlugin?.showControl?.(activeSectionPlaneId);
|
||||
setSectionModeActive(true);
|
||||
setStatus("Разрез включён");
|
||||
return;
|
||||
}
|
||||
createOrUpdateSectionPlane("camera");
|
||||
};
|
||||
|
||||
const rebuildNavCube = (sdk) => {
|
||||
if (!navCubeCanvas || !viewer) return;
|
||||
const cubeColor = cssValue("--cube-base", "#7b3fff");
|
||||
@@ -1257,6 +1417,7 @@ const updatePanelsVisibility = () => {
|
||||
projectNameInput.value = "";
|
||||
}
|
||||
}
|
||||
updateSectionControls();
|
||||
applyRuntimeMode();
|
||||
};
|
||||
|
||||
@@ -1990,6 +2151,7 @@ const destroyAllModels = ({ preserveMeta = false } = {}) => {
|
||||
gizmo?.clearTarget();
|
||||
treeView?.unShowNode?.();
|
||||
clearMeasurements();
|
||||
clearSectionPlanes();
|
||||
selectionState = null;
|
||||
lastSelection = { ids: [], modelId: null };
|
||||
activeTransformTarget = null;
|
||||
@@ -2852,7 +3014,7 @@ const initViewer = async () => {
|
||||
|
||||
const sdk = await import(SDK_URL);
|
||||
sdkRef = sdk;
|
||||
const { Viewer, NavCubePlugin, DistanceMeasurementsPlugin, DistanceMeasurementsMouseControl } = sdk;
|
||||
const { Viewer, NavCubePlugin, DistanceMeasurementsPlugin, DistanceMeasurementsMouseControl, SectionPlanesPlugin } = sdk;
|
||||
mathUtil = sdk.math;
|
||||
if (headerEl && homeButton && !homeButton.querySelector(".ue-logo")) {
|
||||
const logoEl = createLogo();
|
||||
@@ -2931,6 +3093,22 @@ const initViewer = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
if (SectionPlanesPlugin && sectionOverviewCanvas) {
|
||||
sectionPlanesPlugin = new SectionPlanesPlugin(viewer, {
|
||||
overviewCanvasId: "sectionPlanesOverview",
|
||||
overviewVisible: false,
|
||||
});
|
||||
sectionPlanesPlugin.setOverviewVisible(false);
|
||||
setSectionModeActive(false);
|
||||
} else {
|
||||
console.warn("SectionPlanesPlugin is not available in the loaded SDK build");
|
||||
if (sectionButton) {
|
||||
sectionButton.classList.add("disabled");
|
||||
sectionButton.disabled = true;
|
||||
sectionButton.title = "Разрез недоступен";
|
||||
}
|
||||
}
|
||||
|
||||
if (DistanceMeasurementsPlugin && DistanceMeasurementsMouseControl) {
|
||||
measurePlugin = new DistanceMeasurementsPlugin(viewer, {
|
||||
defaultAxisVisible: false,
|
||||
@@ -4308,6 +4486,8 @@ const loadProjectSnapshot = async (project) => {
|
||||
} else if (action === "measure") {
|
||||
if (!measurePlugin || !measureControl) return;
|
||||
setMeasureActive(!measureActive);
|
||||
} else if (action === "section") {
|
||||
toggleSectionPlanes();
|
||||
} else if (action === "projection") {
|
||||
toggleProjection();
|
||||
} else if (action === "share") {
|
||||
@@ -4318,6 +4498,21 @@ const loadProjectSnapshot = async (project) => {
|
||||
});
|
||||
}
|
||||
|
||||
sectionToolbar?.addEventListener("click", (e) => {
|
||||
if (isGuestMode()) return;
|
||||
const btn = e.target.closest("[data-section-action]");
|
||||
if (!btn) return;
|
||||
const action = btn.dataset.sectionAction;
|
||||
if (action === "camera" || action === "x" || action === "y" || action === "z") {
|
||||
createOrUpdateSectionPlane(action);
|
||||
} else if (action === "flip") {
|
||||
flipSectionPlanes();
|
||||
} else if (action === "clear") {
|
||||
clearSectionPlanes();
|
||||
setStatus("Разрез выключен");
|
||||
}
|
||||
});
|
||||
|
||||
function updateTransformInputs(transform) {
|
||||
const empty = {
|
||||
position: ["", "", ""],
|
||||
|
||||
Reference in New Issue
Block a user