From 5cce208d6e047338f128d81d4bcdbace23017eff Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 15:15:15 +0800 Subject: [PATCH] =?UTF-8?q?[Frontend]=20[=E7=9B=A3=E6=8E=A7=E7=B3=BB?= =?UTF-8?q?=E7=B5=B1][=E7=85=A7=E6=98=8E=E7=B3=BB=E7=B5=B1]=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E7=87=88=E5=85=89=EF=BC=9B=E6=96=B0=E5=A2=9E=E5=87=BD?= =?UTF-8?q?=E5=BC=8F:=20=E7=87=88=E5=85=89=E9=96=8B=E9=97=9C=E3=80=81?= =?UTF-8?q?=E7=87=88=E5=85=89=E7=9A=84=E5=BC=B7=E5=BA=A6=E5=92=8C=E9=A1=8F?= =?UTF-8?q?=E8=89=B2=E6=9B=B4=E6=94=B9=E3=80=81=E7=89=A9=E4=BB=B6=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E9=A1=8F=E8=89=B2=E5=92=8C=E9=A1=8F=E8=89=B2=E7=9A=84?= =?UTF-8?q?=E9=80=8F=E6=98=8E=E5=BA=A6=E3=80=81=E7=89=A9=E4=BB=B6=E9=80=8F?= =?UTF-8?q?=E6=98=8E=E5=BA=A6=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/_sysMonAll.html | 41 ++++++++++++++++ Frontend/js/forge/forgemodel.js | 86 ++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 34 deletions(-) diff --git a/Frontend/_sysMonAll.html b/Frontend/_sysMonAll.html index add0bb0..c7473f0 100644 --- a/Frontend/_sysMonAll.html +++ b/Frontend/_sysMonAll.html @@ -45,7 +45,9 @@ setLightColor(); } if (arr.indexOf(3) != -1) { + getHotspotPoint(() => { + getLightDevice(); show3DModel(data.urn_3D); }); @@ -335,11 +337,50 @@ } + async function getLightDevice() {//callback = null + getLightData(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 myLightList = []; + $.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); + myLightList.push(item); + }) + + console.log("2", myLightList); + setLightList(myLightList); + //callback ? callback() : ""; + } + }, null, "POST").send(); + + } + function setHotspotPoint(myDataList = []) { console.log(myDataList) getHopspotPoint(myDataList); } + async function setLightList(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 76763d1..99d364f 100644 --- a/Frontend/js/forge/forgemodel.js +++ b/Frontend/js/forge/forgemodel.js @@ -5,6 +5,7 @@ var targetFloorZ; var elevatorSpeed; var selector = "#forgeViewer"; var myDataList; +var lightDataList; var lightList = [];//燈光清單 var levels;//剖面用 var lowerIdx;//剖面的下方樓層 @@ -304,6 +305,16 @@ 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 => { // documented loaded, any action? @@ -323,9 +334,10 @@ function onDocumentLoadSuccess(doc, eleOption) { $(selector).trigger("autodesk:loaded", nodeIds); }); + }); - + } // 輔助函數,使用 Promise 封裝 viewer.getProperties 函數 @@ -607,35 +619,18 @@ class ADHeatMaps { } } - -function setTransparentBuilding() { - //allDbIdsStr.forEach((dbId) => { - // setTransparency(dbId, 0.2); - //}) - - for (var i = 0; i < allDbIdsStr.length; i++) { - setTransparency(parseInt(allDbIdsStr[i]), 0.2); - } - +//全部物件 透明度: 輸入0:透明;輸入1:不透明 +function setTransparentBuilding(transparent) { + for (var i = 0; i < allDbIdsStr.length; i++) { + setTransparency(parseInt(allDbIdsStr[i]), transparent); + } } -function recoverTransparentBuilding() { - //allDbIdsStr.forEach((dbId) => { - // setTransparency(dbId, 1); - //}) - - for (var i = 0; i < allDbIdsStr.length; i++) { - setTransparency(parseInt(allDbIdsStr[i]), 1); - } -} //設定模型 透明度 function setTransparency(nodeId, opacity) { var model = viewer.model; - //var nodeId = 1633; - var fragList = viewer.model.getFragmentList(); - - var fragIds = [] + var fragIds = []; model.getData().instanceTree.enumNodeFragments( nodeId, (fragId) => { @@ -694,6 +689,14 @@ 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) }); + // }); + //} + //熱點 點擊事件註冊 viewer.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClicked);// SPRITE_SELECTED @@ -711,9 +714,6 @@ async function addHotPoint(data) { const viewable = new DataVizCore.SpriteViewable(myPosition, style, dbId); myData._dbId = dbId; viewableData.addViewable(viewable); - if (myData.device_number.indexOf("_LT_L1_") > -1) { - lightList.push({ dbid: myData.forge_dbid, name: myData.device_number, spotLight: newLight(myPosition) }); - } }); await viewableData.finish(); @@ -913,7 +913,7 @@ function profile() { //新增燈光 async function newLight(lightPosition) { //聚光燈 - spotLight = new THREE.SpotLight(0xff0000, 200, 20, 0.6, 0.5, 10); + var spotLight = new THREE.SpotLight(0xffffff, 200, 20, 0.6, 0.5, 10); spotLight.position.set(lightPosition.x, lightPosition.y, lightPosition.z); spotLight.castShadow = false; spotLight.visible = true; @@ -925,15 +925,11 @@ async function newLight(lightPosition) { return spotLight; } -//調整燈光參數 setLightValues(13593, 10, 10, 0.1, 0.3, 1, 0xffff00); -async function setLightValues(dbid, intensity, distance, angle, penumbra, decay, color) { +//調整燈光 強度、顏色 +async function setLightValues(dbid, intensity, color) { for (var i = 0; i < lightList.length; i++) { if (lightList[i].dbid == dbid) { lightList[i].spotLight.intensity = intensity; - lightList[i].spotLight.distance = distance; - lightList[i].spotLight.angle = angle; - lightList[i].spotLight.penumbra = penumbra; - lightList[i].spotLight.decay = decay; var tempcolor = new THREE.Color().setHex(color); lightList[i].spotLight.color = tempcolor; @@ -942,6 +938,23 @@ async function setLightValues(dbid, intensity, distance, angle, penumbra, decay, } } +//燈光開關 +function setLightOpenOrClose(value, light) { + if (value) { + light.visible = true; + } + else { + light.visible = false; + } + viewer.impl.sceneUpdated(true); +} + +//透過nodeId,更改物件顏色或顯示與否;color請填寫THREE.Vector4 +function changeColorTransparency(nodeId, color) {//變綠色 + //var color = new THREE.Vector4(0, 1, 0, 1);//綠色;前三個代表r、g、b; 亦可填入255/255 + //var color = new THREE.Vector4(0, 1, 0, 0);//不顯示顏色;最後的參數為透明度 + viewer.setThemingColor(nodeId, color); +} //======================== 外部呼叫function =========================== //紀錄熱點座標 @@ -949,6 +962,11 @@ function getHopspotPoint(data) { myDataList = data; } +//紀錄燈具座標 +async function getLightData(data) { + lightDataList = data; +} + //呼叫載入熱圖 async function toLoadHeatmap(roomArr) { const model = viewer.model;