From 66b31cef54c4ebdcf34ae2724d3749c12f31656b Mon Sep 17 00:00:00 2001 From: JouChun Date: Tue, 15 Oct 2024 22:33:01 -0400 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B3=BB=E7=B5=B1=E6=A8=A3?= =?UTF-8?q?=E5=BC=8F=20=EF=BD=9C=E4=BD=BF=E7=94=A8local=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/forge/ForgeForSystem.vue | 172 +++++++++++++++--------- src/views/system/System.vue | 42 +++--- 2 files changed, 128 insertions(+), 86 deletions(-) diff --git a/src/components/forge/ForgeForSystem.vue b/src/components/forge/ForgeForSystem.vue index 153c8a0..4e8d7ce 100644 --- a/src/components/forge/ForgeForSystem.vue +++ b/src/components/forge/ForgeForSystem.vue @@ -39,80 +39,120 @@ const forgeDom = ref(null); const initViewer = (container) => { return new Promise(function (resolve, reject) { - Autodesk.Viewing.Initializer({ getAccessToken }, function () { - const config = { - extensions: ["Autodesk.DataVisualization", "Autodesk.DocumentBrowser"], - }; - let viewer = new Autodesk.Viewing.GuiViewer3D(container, config); - Autodesk.Viewing.Private.InitParametersSetting.alpha = true; - viewer.start(); - resolve(viewer); - }); - }); -}; + // Autodesk.Viewing.Initializer({ getAccessToken }, function () { + // const config = { + // extensions: ["Autodesk.DataVisualization", "Autodesk.DocumentBrowser"], + // }; + // let viewer = new Autodesk.Viewing.GuiViewer3D(container, config); + // Autodesk.Viewing.Private.InitParametersSetting.alpha = true; + // viewer.start(); + // resolve(viewer); + // }); -const loadModel = (viewer, urn) => { - return new Promise(function (resolve, reject) { - async function onDocumentLoadSuccess(doc) { - viewer.setGroundShadow(false); - viewer.impl.renderer().setClearAlpha(0); //clear alpha channel - viewer.impl.glrenderer().setClearColor(0xffffff, 0); //set transparent background, color code does not matter - viewer.impl.invalidate(true); //trigger rendering - - const documentNode = await viewer.loadDocumentNode( - doc, - doc.getRoot().getDefaultGeometry() - ); - updateDataVisualization(viewer) - resolve(documentNode); - } - function onDocumentLoadFailure(code, message, errors) { - reject({ code, message, errors }); - } - Autodesk.Viewing.Document.load( - "urn:" + urn, - onDocumentLoadSuccess, - onDocumentLoadFailure + Autodesk.Viewing.Initializer( + { + env: "Local", + language: "en", + }, + function () { + const config = { + extensions: [ + "Autodesk.DataVisualization", + "Autodesk.DocumentBrowser", + ], + }; + let viewer = new Autodesk.Viewing.GuiViewer3D(container, config); + Autodesk.Viewing.Private.InitParametersSetting.alpha = true; + viewer.start(); + resolve(viewer); + } ); }); }; -const initForge = () => { - getUrn().then((res) => { - if (!res.isSuccess) return; - - initViewer(forgeDom.value).then((viewer) => { - loadModel(viewer, res.data[0].urn_3D).then(() => { - viewer.addEventListener( - Autodesk.Viewing.GEOMETRY_LOADED_EVENT, - async function () { - console.log( - "Autodesk.Viewing.GEOMETRY_LOADED_EVENT", - viewer.isLoadDone() - ); - // updateForgeViewer(viewer); - createSprites() - hideAllObjects(); - } - ); - viewer.addEventListener( - Autodesk.Viewing.CAMERA_CHANGE_EVENT, - function (e) { - // viewer.isLoadDone() && - // updateDbidPosition(this, subscribeData.value); - console.log( - "camera position changed: ", - NOP_VIEWER.navigation.getTarget(), - e.camera.position - ); - } - ); - - }); - }); +// 使用本地 .svf 文件加載模型 +const loadModel = (viewer, filePath) => { + return new Promise((resolve, reject) => { + viewer.loadModel( + filePath, + {}, + (model) => { + viewer.impl.invalidate(true); + viewer.fitToView(); + resolve(model); + console.log("模型加載完成"); + }, + reject + ); }); }; +// const loadModel = (viewer, urn) => { +// return new Promise(function (resolve, reject) { +// async function onDocumentLoadSuccess(doc) { +// viewer.setGroundShadow(false); +// viewer.impl.renderer().setClearAlpha(0); //clear alpha channel +// viewer.impl.glrenderer().setClearColor(0xffffff, 0); //set transparent background, color code does not matter +// viewer.impl.invalidate(true); //trigger rendering + +// const documentNode = await viewer.loadDocumentNode( +// doc, +// doc.getRoot().getDefaultGeometry() +// ); +// updateDataVisualization(viewer) +// resolve(documentNode); +// } +// function onDocumentLoadFailure(code, message, errors) { +// reject({ code, message, errors }); +// } +// Autodesk.Viewing.Document.load( +// "urn:" + urn, +// onDocumentLoadSuccess, +// onDocumentLoadFailure +// ); +// }); +// }; + +const initForge = async () => { + // getUrn().then((res) => { + // if (!res.isSuccess) return; + + // initViewer(forgeDom.value).then((viewer) => { + // loadModel(viewer, res.data[0].urn_3D).then(() => { + // viewer.addEventListener( + // Autodesk.Viewing.GEOMETRY_LOADED_EVENT, + // async function () { + // console.log( + // "Autodesk.Viewing.GEOMETRY_LOADED_EVENT", + // viewer.isLoadDone() + // ); + // // updateForgeViewer(viewer); + // createSprites() + // hideAllObjects(); + // } + // ); + // viewer.addEventListener( + // Autodesk.Viewing.CAMERA_CHANGE_EVENT, + // function (e) { + // // viewer.isLoadDone() && + // // updateDbidPosition(this, subscribeData.value); + // console.log( + // "camera position changed: ", + // NOP_VIEWER.navigation.getTarget(), + // e.camera.position + // ); + // } + // ); + + // }); + // }); + // }); + const FILE_BASEURL = import.meta.env.VITE_FILE_API_BASEURL; + const viewer = await initViewer(forgeDom.value) + const filePath = `${FILE_BASEURL}/upload/forge/0.svf`; + await loadModel(viewer, filePath) +}; + onMounted(() => { console.log("Forge 加載"); initForge(); diff --git a/src/views/system/System.vue b/src/views/system/System.vue index 5dfe30e..56f617b 100644 --- a/src/views/system/System.vue +++ b/src/views/system/System.vue @@ -116,27 +116,29 @@ provide("system_deviceList", { data, subscribeData, currentFloor, updateCurrentF