From 46f9ca1642adb734f80fcf81a898a07acb47482c Mon Sep 17 00:00:00 2001 From: wanli Date: Mon, 9 Jan 2023 16:32:28 +0800 Subject: [PATCH] =?UTF-8?q?[Frontend]=20=E5=87=BD=E5=BC=8F=E8=BC=B8?= =?UTF-8?q?=E5=85=A5=E6=9B=B4=E6=94=B9=E7=82=BAdevice=5Fguid:=20=E7=87=88?= =?UTF-8?q?=E5=85=89=E9=97=9C=E7=87=88=E3=80=81=E7=87=88=E5=85=89=E6=94=B9?= =?UTF-8?q?=E8=AE=8A=E9=A1=8F=E8=89=B2=E5=92=8C=E5=BC=B7=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/_sysMonAll.html | 39 +++++++++++++ Frontend/js/forge/forgemodel.js | 99 +++++++++++++-------------------- 2 files changed, 79 insertions(+), 59 deletions(-) diff --git a/Frontend/_sysMonAll.html b/Frontend/_sysMonAll.html index 72defa2..2dd6031 100644 --- a/Frontend/_sysMonAll.html +++ b/Frontend/_sysMonAll.html @@ -48,6 +48,7 @@ setLightColor(); } if (arr.indexOf(3) != -1) { + getLightPoint(); getHotspotPoint(() => { show3DModel(data.urn_3D); }); @@ -447,11 +448,49 @@ } + async function getLightPoint(callback = null) { + let url = baseApiUrl + "/api/GetDevNodeForCor"; + let sendData = { + "device_area_tag": pageAct.AreaTag, + "device_building_tag": pageAct.buiTag, + "device_system_tag": pageAct.sysMainTag, + "device_name_tag": pageAct.sysSubTag, + }; + objSendData.Data = sendData; + ytAjax = new YourTeam.Ajax(url, objSendData, function (res) { + if (!res || res.code != "0000" || !res.data) { + + } else { + + let myDataList = []; + $.each(res.data, (idx, data) => { + let item = {}; + item.position = {}; + if (data.device_node_coordinate_3d != null && isJSON(data.device_node_coordinate_3d)) { + item.position = JSON.parse(data.device_node_coordinate_3d); + } + $.extend(item, data); + myDataList.push(item); + }) + + console.log("2", myDataList) + setLightPoint(myDataList); + callback ? callback() : ""; + } + }, null, "POST").send(); + + } + function setHotspotPoint(myDataList = []) { console.log(myDataList) getHopspotPoint(myDataList); } + async function setLightPoint(myDataList = []) { + console.log(myDataList) + getLightData(myDataList); + } + var parentEle = ""; onEvent("autodesk:click:sprite", "[name=forgeViewer]", function (e, obj) { forgeUnFocusAll(); diff --git a/Frontend/js/forge/forgemodel.js b/Frontend/js/forge/forgemodel.js index a021bc5..cffbc8d 100644 --- a/Frontend/js/forge/forgemodel.js +++ b/Frontend/js/forge/forgemodel.js @@ -330,15 +330,6 @@ class elevator3D { } function onDocumentLoadSuccess(doc, eleOption) { - //取得燈光清單 - if (lightDataList != undefined && lightDataList != null && lightDataList.length > 0) { - lightDataList.forEach((myData, index) => { - //if (myData.priority == 5) { - const position = JSON.parse(myData.device_node_coordinate_3d); - lightList.push({ dbid: myData.forge_dbid, spotLight: newLight(position) }); - //} - }); - } var viewables = doc.getRoot().getDefaultGeometry(); viewer.loadDocumentNode(doc, viewables).then(i => { @@ -727,15 +718,26 @@ function hideColor(nodeId) {//顏色改成透明 } -//------------------ 紀錄熱點座標 --------------- -function getHopspotPoint(data) { - //var av = Autodesk.Viewing; - myDataList = data; - //viewer.addEventListener(av.GEOMETRY_LOADED_EVENT, addHotPoint, { - // once: true, - //}); +//紀錄燈具座標 +async function getLightData(data) { + lightDataList = data; +} + +async function testNewLight(dataList) { + dataList.forEach((myData, index) => { + const position = JSON.parse(myData.device_node_coordinate_3d); + lightList.push({ dbid: myData.forge_dbid, device_guid: myData.device_guid, lightObject: new THREE.SpotLight(0xff0000, 200, 20, 0.6, 0.5, 10) }); + + lightList[index].lightObject.position.set(position.x, position.y, position.z); + lightList[index].lightObject.castShadow = true; + lightList[index].lightObject.visible = true; + lightList[index].lightObject.target.position.set(position.x, position.y, position.z - 20); + viewer.scene.add(lightList[index].lightObject.target); + viewer.scene.add(lightList[index].lightObject); + viewer.impl.sceneUpdated(true); + + }); } -//-------------------- end ---------------------- //------------------- 加入熱點 ----------------- async function addHotPoint(data) { @@ -753,13 +755,10 @@ async function addHotPoint(data) { const style = new DataVizCore.ViewableStyle(viewableType, spriteColor, spriteIcon); - //取得燈光清單 - //if (lightDataList != undefined && lightDataList != null && lightDataList.length > 0) { - // lightDataList.forEach((myData, index) => { - // const position = JSON.parse(myData.device_node_coordinate_3d); - // lightList.push({ dbid: myData.forge_dbid, spotLight: newLight(position) }); - // }); - //} + if (lightDataList != undefined && lightDataList != null && lightDataList.length > 0) { + testNewLight(lightDataList); + } + //熱點 點擊事件註冊 viewer.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClicked);// SPRITE_SELECTED @@ -790,12 +789,16 @@ async function addHotPoint(data) { if (event != undefined && event != null) { if (event.dbId >= dbIdStart) {//event.dbId > 0 && event.dbId < 19 console.log(`Sprite clicked: ${event.dbId}`); - openHotspotModal(); + for (let i = dbIdStart; i <= myDataList.length + 10; i++) { changeColorForHotspot(i); changeScaleForHotspot(i, false); } let myData = myDataList.filter(x => x._dbId == event.dbId)[0]; + if (lightList != undefined && lightList != null && lightList.length > 0) { + //setLightOpenOrClose(false, myData.device_guid);//關燈測試 + //setLightValues(myData.device_guid, 20, 0x00ff00);//更改燈光顏色和強度的測試 + } $(selector).trigger("autodesk:click:sprite", { event, myData }); } else { $(selector).trigger("autodesk:clickOut:sprite", { event }); @@ -817,7 +820,6 @@ async function addHotPoint(data) { // if (dbIds.length > 0) { // // 處理已選取元件的邏輯 // $(selector).trigger("autodesk:click:sprite", event); - // //openHotspotModal(); // console.log(`------ name: ${viewer.model.getInstanceTree().getNodeName(dbIds)} , dbId: ${dbIds}`);//, id: ${event.clickInfo.object.id}, position.x: ${event.clickInfo.point.x}, y: ${event.clickInfo.point.y}, z: ${event.clickInfo.point.z} // } else { // // 處理沒有選取元件的邏輯 @@ -864,22 +866,7 @@ async function changeScaleForHotspot(dbId, type = true) { //------------------- end -------------- -//----------------- 開關熱點小視窗 ---------------------- -function openHotspotModal() { - //var modal = document.getElementById("hotspotModal"); - //modal.style.display = "block"; - //$("#pills-register-tab").removeClass("active"); - //$("#pills-alarm-tab").removeClass("active"); - //$("#pills-operation-tab").removeClass("active"); - //$("#pills-login-tab").tab("show"); -} -function closeHotspotModal() { - //var modal = document.getElementById("hotspotModal"); - //modal.style.display = "none"; - -} -//------------------ end -------------------------------- //------------------ 熱圖 ------------------------------- async function loadHeatmaps(model) { @@ -1118,25 +1105,24 @@ async function newLight(lightPosition) { } //調整燈光 強度、顏色 -async function setLightValues(dbid, intensity, color) { - for (var i = 0; i < lightList.length; i++) { - if (lightList[i].dbid == dbid) { - lightList[i].spotLight.intensity = intensity; - +async function setLightValues(deviceGuid, intensity, color) { + for (var i = 0; i < lightList.length; i++) { + if (lightList[i].device_guid == deviceGuid) { + lightList[i].lightObject.intensity = intensity; + var tempcolor = new THREE.Color().setHex(color); - lightList[i].spotLight.color = tempcolor; - viewer.impl.sceneUpdated(true); + lightList[i].lightObject.color = tempcolor; } } + viewer.impl.sceneUpdated(true); } //燈光開關 -function setLightOpenOrClose(value, light) { - if (value) { - light.visible = true; - } - else { - light.visible = false; +async function setLightOpenOrClose(value, deviceGuid) { + for (var i = 0; i < lightList.length; i++) { + if (lightList[i].device_guid == deviceGuid) { + lightList[i].lightObject.visible = value; + } } viewer.impl.sceneUpdated(true); } @@ -1173,11 +1159,6 @@ function getHopspotPoint(data) { myDataList = data; } -//紀錄燈具座標 -async function getLightData(data) { - lightDataList = data; -} - //呼叫載入熱圖 async function toLoadHeatmap(roomArr) { const model = viewer.model;