更新樓層顯示

This commit is contained in:
JouChun 2024-10-24 13:22:00 -04:00
parent 7f570fc366
commit fdac1a2fb3
4 changed files with 111 additions and 65 deletions

View File

@ -33,7 +33,7 @@ const updateHeatBarIsShow = (isShow) => {
heat_bar_isShow.value = isShow; heat_bar_isShow.value = isShow;
}; };
const { updateDataVisualization, createSprites, hideAllObjects, forgeClickListener, clear } = useForgeSprite() const { updateDataVisualization, createSprites, showSubSystemObjects, forgeClickListener, clear } = useForgeSprite()
const forgeDom = ref(null); const forgeDom = ref(null);
@ -163,7 +163,7 @@ const initForge = async () => {
viewer.isLoadDone() viewer.isLoadDone()
); );
hideAllObjects(); showSubSystemObjects();
createSprites(); createSprites();
forgeClickListener(); forgeClickListener();
}) })

View File

@ -1,70 +1,107 @@
import useSelectedFloor from "@/hooks/useSelectedFloor";
import { watch, ref, inject } from "vue";
import { useRoute } from "vue-router";
function useForgeFloor() { function useForgeFloor() {
const findLevels = (viewer) => { const route = useRoute();
return new Promise((resolve, reject) => { const levelList = ref([]);
viewer.model.search( const { selectedFloor } = useSelectedFloor();
"layer", const { subscribeData } = inject("system_deviceList");
(nodeIds) => {
let levels = []; const forgeViewer = ref(null);
const tree = viewer.model.getInstanceTree(); const dataVizExtn = ref(null);
for (let i = 0; i < nodeIds.length; i++) { const updateViewerFloor = (viewer, dataVisualization) => {
const dbId = nodeIds[i]; forgeViewer.value = viewer;
const name = tree.getNodeName(dbId); dataVizExtn.value = dataVisualization;
if (!name || name.includes("<沒有層級>")) continue;
levels.push({
guid: dbId,
name,
dbId,
extension: {
buildingStory: true,
structure: false,
computationHeight: 0,
groundPlane: false,
hasAssociatedViewPlans: false,
},
});
}
levels = levels.sort((a, b) => b.elevation - a.elevation);
resolve(levels);
},
(e) => {
reject(e);
}
);
});
}; };
// function getCutPlaneParam(idx, n, viewer, levels) { const findLevels = () => {
// if (idx < 0 || !n) return; forgeViewer.value.model.search(
"layer",
(nodeIds) => {
let levels = [];
const tree = forgeViewer.value.model.getInstanceTree();
for (let i = 0; i < nodeIds.length; i++) {
const dbId = nodeIds[i];
const name = tree.getNodeName(dbId);
if (!name || name.includes("<沒有層級>")) continue;
levels.push({
guid: dbId,
name,
dbId,
extension: {
buildingStory: true,
structure: false,
computationHeight: 0,
groundPlane: false,
hasAssociatedViewPlans: false,
},
});
}
levels = levels.sort((a, b) => b.elevation - a.elevation);
console.log(levels);
levelList.value = levels;
},
(e) => {
console.log(e);
}
);
};
// const level = levels[idx]; watch(forgeViewer, () => {
// if (!level) return; findLevels();
});
// const model = viewer.model; const hideDbIdFn = () => {
// const globalOffset = model.getData().globalOffset; const tree = forgeViewer.value.model.getInstanceTree();
// const units = model.getUnitString(); const allDbIdsStr = Object.keys(tree.nodeAccess.dbIdToIndex);
// const elevRaw = Autodesk.Viewing.Private.convertUnits( for (var i = 0; i < allDbIdsStr.length; i++) {
// "ft", forgeViewer.value.hide(parseInt(allDbIdsStr[i]));
// units, }
// 1, };
// level.elevation const showDbIdFn = () => {
// ); hideAllObjects();
// let d = elevRaw - globalOffset.z - 0.5; subscribeData.value.forEach((value, index) => {
// if (n == 1) d = -1 * d; forgeViewer.value.show(value.forge_dbid);
});
// return new THREE.Vector4(0, 0, n, d); forgeViewer.value.impl.invalidate(true);
// } };
// function profile(viewer, levels) { const showLevels = () => {
// //const upperIdx = 6; const currentFloorName = selectedFloor.value.title.replaceAll(/U/gi, "");
// const upperCutPlaneParam = getCutPlaneParam(2, 1, viewer, levels);
// //const lowerIdx = 7;
// const lowerCutPlaneParam = getCutPlaneParam(3, -1, viewer, levels);
// viewer.setCutPlanes([upperCutPlaneParam, lowerCutPlaneParam]);
// }
const level = levelList.value.find(({ name }) =>
name.includes(currentFloorName)
);
console.log(currentFloorName, level);
if (!level) {
forgeViewer.value.impl.toggleGhosting(true);
showDbIdFn();
} else {
hideDbIdFn();
// forgeViewer.value.clearSelection();
// forgeViewer.value.model.setAllVisibility(0);
forgeViewer.value.impl.toggleGhosting(false);
// forgeViewer.value.impl.toggleGroundShadow(false);
forgeViewer.value.show(level.dbId);
forgeViewer.value.impl.invalidate(true);
}
};
return { findLevels, profile }; watch(
() => route,
(newValue) => {
console.log(newValue);
newValue && showLevels();
},
{
deep: true,
}
);
return { findLevels, showLevels, updateViewerFloor };
} }
export default useForgeFloor; export default useForgeFloor;

View File

@ -5,8 +5,6 @@ export default function useForgeHeatmap() {
const route = useRoute(); const route = useRoute();
const { subscribeData, realtimeData } = inject("system_deviceList"); const { subscribeData, realtimeData } = inject("system_deviceList");
// const data = computed(()=>)
const forgeViewer = ref(null); const forgeViewer = ref(null);
const dataVizExtn = ref(null); const dataVizExtn = ref(null);
const updateViewExtension = (viewer, dataVisualization) => { const updateViewExtension = (viewer, dataVisualization) => {
@ -28,7 +26,8 @@ export default function useForgeHeatmap() {
watch( watch(
() => realtimeData, () => realtimeData,
() => { () => {
Object.keys(dataVizExtn.value?.surfaceShading).length && dataVizExtn.value &&
Object.keys(dataVizExtn.value?.surfaceShading)?.length &&
dataVizExtn.value.updateSurfaceShading(getSensorValue); dataVizExtn.value.updateSurfaceShading(getSensorValue);
}, },
{ {
@ -37,6 +36,7 @@ export default function useForgeHeatmap() {
); );
const createHeatMap = async () => { const createHeatMap = async () => {
if (!dataVizExtn.value) return;
const heatMapName = `iot_heatmap_${route.query?.gas}`; const heatMapName = `iot_heatmap_${route.query?.gas}`;
console.log("createHeatMap", heatMapName); console.log("createHeatMap", heatMapName);
const { const {
@ -89,7 +89,7 @@ export default function useForgeHeatmap() {
() => route.query, () => route.query,
(newValue, oldValue) => { (newValue, oldValue) => {
if (newValue.gas !== oldValue.gas) { if (newValue.gas !== oldValue.gas) {
createHeatMap(newValue.gas); // createHeatMap(newValue.gas);
} else if (!newValue.gas) { } else if (!newValue.gas) {
dataVizExtn.value?.removeSurfaceShading(); dataVizExtn.value?.removeSurfaceShading();
} }

View File

@ -3,6 +3,7 @@ import useAlarmStore from "@/stores/useAlarmStore";
import hexToRgb from "@/util/hexToRgb"; import hexToRgb from "@/util/hexToRgb";
import useSelectedFloor from "@/hooks/useSelectedFloor"; import useSelectedFloor from "@/hooks/useSelectedFloor";
import useForgeHeatmap from "./useForgeHeatmap"; import useForgeHeatmap from "./useForgeHeatmap";
import useForgeFloor from "./useForgeFloor";
export default function useForgeSprite() { export default function useForgeSprite() {
const store = useAlarmStore(); const store = useAlarmStore();
@ -14,6 +15,7 @@ export default function useForgeSprite() {
const dataVizExtn = ref(null); const dataVizExtn = ref(null);
const { createHeatMap, updateViewExtension } = useForgeHeatmap(); const { createHeatMap, updateViewExtension } = useForgeHeatmap();
const { updateViewerFloor } = useForgeFloor();
const updateDataVisualization = async (viewer) => { const updateDataVisualization = async (viewer) => {
if (!forgeViewer.value) { if (!forgeViewer.value) {
@ -25,6 +27,7 @@ export default function useForgeSprite() {
); );
dataVizExtn.value = markRaw(dataVisualization); dataVizExtn.value = markRaw(dataVisualization);
updateViewExtension(markRaw(viewer), markRaw(dataVisualization)); updateViewExtension(markRaw(viewer), markRaw(dataVisualization));
updateViewerFloor(markRaw(viewer), markRaw(dataVisualization))
}; };
function onSpriteClicked(event) { function onSpriteClicked(event) {
@ -104,7 +107,10 @@ export default function useForgeSprite() {
watch( watch(
() => showData, () => showData,
() => { () => {
forgeViewer.value?.isLoadDone() && createSprites(); if (forgeViewer.value?.isLoadDone()) {
createSprites();
hideAllObjects();
}
}, },
{ {
deep: true, deep: true,
@ -150,7 +156,10 @@ export default function useForgeSprite() {
for (var i = 0; i < allDbIdsStr.length; i++) { for (var i = 0; i < allDbIdsStr.length; i++) {
forgeViewer.value.hide(parseInt(allDbIdsStr[i])); forgeViewer.value.hide(parseInt(allDbIdsStr[i]));
} }
};
const showSubSystemObjects = () => {
hideAllObjects();
subscribeData.value.forEach((value, index) => { subscribeData.value.forEach((value, index) => {
forgeViewer.value.show(value.forge_dbid); forgeViewer.value.show(value.forge_dbid);
}); });
@ -173,7 +182,7 @@ export default function useForgeSprite() {
return { return {
createSprites, createSprites,
updateDataVisualization, updateDataVisualization,
hideAllObjects, showSubSystemObjects,
forgeClickListener, forgeClickListener,
clear, clear,
}; };