From 4c72cd822e8fbaab614361d952a0f25e421bfe80 Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 15:12:20 +0800 Subject: [PATCH 1/6] =?UTF-8?q?[FrontendWebApi]=20=E5=8A=A0=E5=85=A5=20?= =?UTF-8?q?=E6=9F=A5=E8=A9=A2=E7=87=88=E5=85=B7=E8=A8=AD=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/DeviceManageController.cs | 31 +++++++++++++++++++ FrontendWebApi/Models/Device.cs | 8 +++++ 2 files changed, 39 insertions(+) diff --git a/FrontendWebApi/ApiControllers/DeviceManageController.cs b/FrontendWebApi/ApiControllers/DeviceManageController.cs index 7792db6..c934a26 100644 --- a/FrontendWebApi/ApiControllers/DeviceManageController.cs +++ b/FrontendWebApi/ApiControllers/DeviceManageController.cs @@ -711,6 +711,37 @@ namespace FrontendWebApi.ApiControllers return Ok(apiResult); } + [HttpPost] + [Route("api/GetDevNodeForCor")] + public async Task>> GetDevNodeForCor([FromBody] Device p) + { + ApiResult> apiResult = new ApiResult>(); + List device = new List(); + + try + { + apiResult.Code = "0001"; + if (p != null ) + { + if (p.device_system_tag == "LT" && p.device_name_tag == "L1") + { + var d = await backendRepository.GetAllAsync($@"select device_guid,priority,device_node_coordinate_3d,forge_dbid from device_node where deleted = 0"); + + apiResult.Data = d; + apiResult.Code = "0000"; + } + } + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + return Ok(apiResult); + } + return Ok(apiResult); + } + /// /// 燈控排程列表 /// diff --git a/FrontendWebApi/Models/Device.cs b/FrontendWebApi/Models/Device.cs index 0fda044..c8db861 100644 --- a/FrontendWebApi/Models/Device.cs +++ b/FrontendWebApi/Models/Device.cs @@ -133,4 +133,12 @@ namespace FrontendWebApi.Models public string device_coordinate_3d { get; set; } public int? forge_dbid { get; set; } } + + public class DevNodeForCor + { + public string device_guid { get; set; } + public int priority { get; set; } + public string device_node_coordinate_3d { get; set; } + public int? forge_dbid { get; set; } + } } From 5cce208d6e047338f128d81d4bcdbace23017eff Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 15:15:15 +0800 Subject: [PATCH 2/6] =?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; From 3c192e87deee4a8c3d5f03b8a5e034c18d3f0805 Mon Sep 17 00:00:00 2001 From: wanli Date: Wed, 4 Jan 2023 15:15:53 +0800 Subject: [PATCH 3/6] =?UTF-8?q?[Backend]=20=E6=9B=B4=E6=8F=9Bforge?= =?UTF-8?q?=E6=B8=AC=E8=A9=A6=E7=9A=84=E6=A8=A1=E5=9E=8Burn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/wwwroot/forgeDemo.html | 82 ++-------------------------------- 1 file changed, 3 insertions(+), 79 deletions(-) diff --git a/Backend/wwwroot/forgeDemo.html b/Backend/wwwroot/forgeDemo.html index 0e8b9fc..6bbdccb 100644 --- a/Backend/wwwroot/forgeDemo.html +++ b/Backend/wwwroot/forgeDemo.html @@ -184,7 +184,6 @@ \ No newline at end of file diff --git a/Frontend/index.html b/Frontend/index.html index c61e9df..4fd61ae 100644 --- a/Frontend/index.html +++ b/Frontend/index.html @@ -136,7 +136,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li