diff --git a/Frontend/_sysMonAll.html b/Frontend/_sysMonAll.html index 0e2778f..c8ef609 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); }); @@ -462,11 +463,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/forgetTest2.html b/Frontend/forgetTest2.html index 7eda69e..a937a3c 100644 --- a/Frontend/forgetTest2.html +++ b/Frontend/forgetTest2.html @@ -51,6 +51,7 @@ + @@ -244,7 +245,7 @@ //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6LW1pdHN1YmlzaGkvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU5JUExJUFGXzEyMjgubndk'); //12.30 整棟樓 ARC + MEP - launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8xMl8zMC5ud2Q'); + //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8xMl8zMC5ud2Q'); //12.30 整棟樓 ARC + MEP 半透明 //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8lRTUlOEQlOEElRTklODAlOEYlRTYlOTglOEUlRTUlQkIlQkElRTclQUYlODlfMTJfMzAubndk'); @@ -254,8 +255,11 @@ //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwTUVQJUUzJTgwJTkxXzIwMjJfMTJfMTMubndj');//new MEP //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwQVJDJUUzJTgwJTkxJUU1JTg1JUE4JUU2JUEzJTlGXzIwMjJfMTJfMTMubndj');//全棟 ARC - + //01.06 加上room_id(樓層有燈具) + //launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8yMDIzXzAxXzA2Lm53ZA'); + //01.06 樓層刪除燈具 + launchViewer('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6LW1vZGVsX3Rlc3QxMTIxLyVFMyU4MCU5MCVFNSU4RiVCMCVFNSU4QyU5NyVFNCVCOCVBRCVFOCU4RiVCMSVFNSVBNCVBNyVFNiVBOCU5MyVFMyU4MCU5MUFSQyVFOSU5QiU5OSVFNiVBOCVBMSVFNSVCQyU4RitNRVAlRTYlOEIlODYlRTclQjMlQkIlRTclQjUlQjFfJUU1JTg4JUFBJUU3JTg3JTg4JUU1JTg1JUI3XzIwMjNfMDFfMDYubndk'); }); //function move1Floor() { @@ -412,6 +416,10 @@ createHeatmapRect(labels, colorStops); } + function showList() { + consoleList(); + } + function createHeatmapRect(labels, colorStops) { if (!this.canvas) { return; @@ -438,7 +446,7 @@ context.fillRect(10, 20, 280, 20); } - + diff --git a/Frontend/js/forge/forgemodel.js b/Frontend/js/forge/forgemodel.js index bb766d5..dfe8d02 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_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(0xffffff, 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,17 @@ 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);//更改燈光顏色和強度的測試 + moveViewToDevice(myData.forge_dbid);//移動視角至該設備 + } $(selector).trigger("autodesk:click:sprite", { event, myData }); } else { $(selector).trigger("autodesk:clickOut:sprite", { event }); @@ -817,7 +821,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 +867,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 +1106,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); } @@ -1209,11 +1196,6 @@ function getHopspotPoint(data) { myDataList = data; } -//紀錄燈具座標 -async function getLightData(data) { - lightDataList = data; -} - //呼叫載入熱圖 async function toLoadHeatmap(roomArr) { const model = viewer.model; @@ -1225,4 +1207,15 @@ function setShadowShow(type = false) { viewer.impl.sceneUpdated(true); } -//============================= end =================================== \ No newline at end of file +//============================= end =================================== + +function moveViewToDevice(letter) { + if (letter != "") { + viewer.clearSelection(); + viewer.select(letter); + viewer.fitToView([letter]); + } + else { + viewer.clearSelection(); + } +} \ No newline at end of file diff --git a/Frontend/js/forge/modeltest.js b/Frontend/js/forge/modeltest.js index 765fd66..44ae412 100644 --- a/Frontend/js/forge/modeltest.js +++ b/Frontend/js/forge/modeltest.js @@ -5,6 +5,7 @@ var elevatorSpeed; var allDbIdsStr; let bulbLight;//點燈 var spotLight;//聚光燈 +let testLight; var myDataList;//設備清單 var viewableData; var dataVizExtn; @@ -12,7 +13,9 @@ var spriteColorRed; var levels;//剖面用 var light; let pointLightHelper; - +var tagIdDevList = [];//模型設備List: device_number、device_coordinate_3d、forge_dbid +var roomDataList = [];//模型房間List: room_id、room_name + function launchViewer(urn) { var av = Autodesk.Viewing; var options = { @@ -139,12 +142,10 @@ function onDocumentLoadSuccess(doc) { viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () { - var instanceTree = viewer.model.getData().instanceTree; - - var domElem = document.getElementById('all_id'); - allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex); - domElem.innerText = allDbIdsStr; - + var instanceTree = viewer.model.getData().instanceTree; + var domElem = document.getElementById('all_id'); + allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex); + domElem.innerText = allDbIdsStr; //parseInt(allDbIdsStr[i] //for (var i = 0; i < allDbIdsStr.length; i++) { // //setTransparency(parseInt(allDbIdsStr[i]), 0.2); @@ -161,105 +162,152 @@ function onDocumentLoadSuccess(doc) { // }) //} - // ------------------ 取得tag_id底下的nodeId -------------------------------------- - var curDbId = 0; - var tagId = 0; - var _parentId = 0; - var _childId = 0; - var itemName = ''; - var childIdArr = new Array(); - let evelMap = new Map(); + //// ------------------ 取得tag_id底下的nodeId -------------------------------------- + //var curDbId = 0; + ////var tagId = 0; + ////var _parentId = 0; + ////var _childId = 0; + ////var itemName = ''; + ////var childIdArr = new Array(); + ////let evelMap = new Map(); - let tree = viewer.model.getData().instanceTree; - const model = viewer.model; - const fragList = model.getFragmentList(); + //let tree = viewer.model.getData().instanceTree; + //const model = viewer.model; + //const fragList = model.getFragmentList(); - //loadHeatmaps(model); + // //loadHeatmaps(model); + ////allDbIdsStr.forEach((dbId) => { + //// curDbId = parseInt(dbId); + //// viewer.getProperties(curDbId, function (e) { + //// e.properties.forEach(function (item) { + //// if (item.displayName == "tag_id" && e.name == "【電梯】") { + + //// //getFragmentWorldMatrixByNodeId(e.dbId, viewer); + //// //let fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + + //// tree.enumNodeFragments(e.dbId, function (frag) { + + //// let fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + //// let matrix = new THREE.Matrix4(); + //// console.log("proxy: " + fragProxy.position); + + //// fragProxy.getWorldMatrix(matrix); + + //// }); + + + + //// tagId = e.dbId; + //// viewer.getProperties(tagId, function (e2) { + //// e2.properties.forEach(function (item2) { + //// if (item2.displayName == "child") { + //// _parentId = item2.displayValue; + + //// viewer.getProperties(_parentId, function (e3) { + //// let itemMap = new Map(); + //// e3.properties.forEach(function (item3) { + //// if (item3.displayName == "child") { + //// _childId = item3.displayValue; + //// childIdArr.push(_childId); + + //// var n = 0; + //// viewer.getProperties(childIdArr[n], function (e5) { + //// e5.properties.forEach(function (item5) { + //// if (item5.displayName == "Name") { + //// itemName = item5.displayValue; + //// itemMap.set(childIdArr[0], itemName) + //// console.log("childIdArr[0] ", childIdArr[0]) + //// console.log("item name: ", itemName); + //// n += 3; + //// } + //// }); + //// }) + + //// n = 1; + //// viewer.getProperties(childIdArr[n], function (e6) { + //// e6.properties.forEach(function (item6) { + //// if (item6.displayName == "Name") { + //// itemName = item6.displayValue; + //// itemMap.set(childIdArr[1], itemName) + //// console.log("childIdArr[1] ", childIdArr[1]) + //// console.log("item name: ", itemName); + //// n += 3; + //// } + //// }); + //// }) + + //// n = 2; + //// viewer.getProperties(childIdArr[n], function (e7) { + //// e7.properties.forEach(function (item7) { + //// if (item7.displayName == "Name") { + //// itemName = item7.displayValue; + //// itemMap.set(childIdArr[2], itemName) + //// console.log("childIdArr[2] ", childIdArr[2]) + //// console.log("item name: ", itemName); + //// n += 3; + //// } + //// }); + //// }) + + //// } + //// }); + //// evelMap.set(item.displayValue, itemMap) + //// }) + + //// } + //// }); + //// }) + //// } + //// }); + + //// }) + + ////}) + //allDbIdsStr.forEach((dbId) => { // curDbId = parseInt(dbId); // viewer.getProperties(curDbId, function (e) { // e.properties.forEach(function (item) { - // if (item.displayName == "tag_id" && e.name == "【電梯】") { + // if (item.displayName == "【tag_id】") { // Tag_name tag_id 【tag_id】 + // if (item.displayValue != "") { + // if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) {// TPE_B1_ME_M10 + // console.log("--------------------------------------------------"); + // console.log("Tag_name dbid: " + e.dbId); + // console.log("value: " + item.displayValue); + // } + // //var v = getFragmentWorldMatrixByNodeId(e.dbId, viewer); + // //console.log("v: " + v); + + // //tree.enumNodeFragments(e.dbId, function (frag) { + // // fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + // // fragProxy.getAnimTransform(); + // // console.log("postion: " + fragProxy.position + ", fragP: " + fragProxy.fragPosition); + // //}); + + + + // let bounds = new THREE.Box3(); + + // instanceTree.enumNodeFragments(e.dbId, (fragId) => { + // let box = new THREE.Box3(); + // fragList.getWorldBounds(fragId, box); + // bounds.union(box); + // }, true); + // var position = bounds.center(); + // if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) { + // console.log("position: (" + (position.x).toFixed(2) + ", " + (position.y).toFixed(2) + ", " + (position.z).toFixed(2) + ")"); + // console.log("--------------------------------------------------"); + // } + // } // //getFragmentWorldMatrixByNodeId(e.dbId, viewer); // //let fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); - // tree.enumNodeFragments(e.dbId, function (frag) { - // let fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); - // let matrix = new THREE.Matrix4(); - // console.log("proxy: " + fragProxy.position); - - // fragProxy.getWorldMatrix(matrix); - - // }); - - - - // tagId = e.dbId; - // viewer.getProperties(tagId, function (e2) { - // e2.properties.forEach(function (item2) { - // if (item2.displayName == "child") { - // _parentId = item2.displayValue; - - // viewer.getProperties(_parentId, function (e3) { - // let itemMap = new Map(); - // e3.properties.forEach(function (item3) { - // if (item3.displayName == "child") { - // _childId = item3.displayValue; - // childIdArr.push(_childId); - - // var n = 0; - // viewer.getProperties(childIdArr[n], function (e5) { - // e5.properties.forEach(function (item5) { - // if (item5.displayName == "Name") { - // itemName = item5.displayValue; - // itemMap.set(childIdArr[0], itemName) - // console.log("childIdArr[0] ", childIdArr[0]) - // console.log("item name: ", itemName); - // n += 3; - // } - // }); - // }) - - // n = 1; - // viewer.getProperties(childIdArr[n], function (e6) { - // e6.properties.forEach(function (item6) { - // if (item6.displayName == "Name") { - // itemName = item6.displayValue; - // itemMap.set(childIdArr[1], itemName) - // console.log("childIdArr[1] ", childIdArr[1]) - // console.log("item name: ", itemName); - // n += 3; - // } - // }); - // }) - - // n = 2; - // viewer.getProperties(childIdArr[n], function (e7) { - // e7.properties.forEach(function (item7) { - // if (item7.displayName == "Name") { - // itemName = item7.displayValue; - // itemMap.set(childIdArr[2], itemName) - // console.log("childIdArr[2] ", childIdArr[2]) - // console.log("item name: ", itemName); - // n += 3; - // } - // }); - // }) - - // } - // }); - // evelMap.set(item.displayValue, itemMap) - // }) - - // } - // }); - // }) // } // }); @@ -267,54 +315,64 @@ function onDocumentLoadSuccess(doc) { //}) - allDbIdsStr.forEach((dbId) => { - curDbId = parseInt(dbId); - viewer.getProperties(curDbId, function (e) { - e.properties.forEach(function (item) { - if (item.displayName == "【tag_id】") { // Tag_name tag_id 【tag_id】 - if (item.displayValue != "") { - if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) {// TPE_B1_ME_M10 - console.log("--------------------------------------------------"); - console.log("Tag_name dbid: " + e.dbId); - console.log("value: " + item.displayValue); + ////---------------------- end --------------------------------------------------- + + // ------------------ 2023.01.06 取得tag_id、底下的nodeId -------------------------------------- + var curDbId = 0; + + let tree = viewer.model.getData().instanceTree; + const model = viewer.model; + const fragList = model.getFragmentList(); + + + allDbIdsStr.forEach((dbId) => { + curDbId = parseInt(dbId); + viewer.getProperties(curDbId, function (e) { + e.properties.forEach(function (item) { + if (item.displayName == "【tag_id】") { // Tag_name tag_id 【tag_id】 + if (item.displayValue != "") { + ////if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) {// TPE_B1_ME_M10 + //console.log("--------------------------------------------------"); + //console.log("Tag_name dbid: " + e.dbId); + //console.log("value: " + item.displayValue); + ////} + var str = item.displayValue.split('_'); + if (str.length == 2) { //兩段為房間 ex: U7F_01 + roomDataList.push({ room_id: e.dbId, room_name: item.displayValue }); + } + else if (str.length == 8) { //八段為設備 ex: TPE_B1_ME_M10_U7F_NA_FCU_N1 + //取得座標 + let bounds = new THREE.Box3(); + instanceTree.enumNodeFragments(e.dbId, (fragId) => { + let box = new THREE.Box3(); + fragList.getWorldBounds(fragId, box); + bounds.union(box); + }, true); + var position = bounds.center(); + ////if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) { + //console.log("position: (" + (position.x).toFixed(2) + ", " + (position.y).toFixed(2) + ", " + (position.z).toFixed(2) + ")"); + //console.log("--------------------------------------------------"); + ////} + tagIdDevList.push({ device_number: item.displayValue, device_coordinate_3d: '{ "x": ' + (position.x).toFixed(2) + ', "y": ' + (position.y).toFixed(2) + ', "z": ' + (position.z).toFixed(2) + ' }', forge_dbid: e.dbId }); + } + + + + + + + + } - //var v = getFragmentWorldMatrixByNodeId(e.dbId, viewer); - //console.log("v: " + v); - //tree.enumNodeFragments(e.dbId, function (frag) { - // fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); - // fragProxy.getAnimTransform(); - // console.log("postion: " + fragProxy.position + ", fragP: " + fragProxy.fragPosition); - //}); - - - - let bounds = new THREE.Box3(); - - instanceTree.enumNodeFragments(e.dbId, (fragId) => { - let box = new THREE.Box3(); - fragList.getWorldBounds(fragId, box); - bounds.union(box); - }, true); - var position = bounds.center(); - if ((item.displayValue).indexOf('TPE_B1_LT_L1') > -1) { - console.log("position: (" + (position.x).toFixed(2) + ", " + (position.y).toFixed(2) + ", " + (position.z).toFixed(2) + ")"); - console.log("--------------------------------------------------"); - } } - //getFragmentWorldMatrixByNodeId(e.dbId, viewer); - //let fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + }); - - } - }); + }) }) - - }) - - //---------------------- end --------------------------------------------------- + //---------------------- end --------------------------------------------------- @@ -359,116 +417,51 @@ function onDocumentLoadSuccess(doc) { // }) //}) - - //let tree = viewer.model.getData().instanceTree; - let nodeId = 12112;//12104; //749; //10952; - let nodeId2 = 12111;//12105; //750; - let nodeId3 = 12110;//12104; //751; - tree.enumNodeFragments(nodeId, function (frag) { - fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); - fragProxy.getAnimTransform(); - let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 - fragProxy.position = fragPosition + // //let tree = viewer.model.getData().instanceTree; + //let nodeId = 12112;//12104; //749; //10952; + //let nodeId2 = 12111;//12105; //750; + //let nodeId3 = 12110;//12104; //751; - fragProxy.updateAnimTransform() + //tree.enumNodeFragments(nodeId, function (frag) { + // fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + // fragProxy.getAnimTransform(); + // let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 + // fragProxy.position = fragPosition + // fragProxy.updateAnimTransform() + //}); + //viewer.impl.sceneUpdated(true); - }); - viewer.impl.sceneUpdated(true); + ////------------ add ------------- + //tree.enumNodeFragments(nodeId2, function (frag) { + // fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + // fragProxy.getAnimTransform(); + // let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 - //------------ add ------------- - tree.enumNodeFragments(nodeId2, function (frag) { - fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); - fragProxy.getAnimTransform(); - let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 + // fragProxy.position = fragPosition - fragProxy.position = fragPosition + // fragProxy.updateAnimTransform() - fragProxy.updateAnimTransform() + //}); + //viewer.impl.sceneUpdated(true); - }); - viewer.impl.sceneUpdated(true); + //tree.enumNodeFragments(nodeId3, function (frag) { + // fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + // fragProxy.getAnimTransform(); + // let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 - tree.enumNodeFragments(nodeId3, function (frag) { - fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); - fragProxy.getAnimTransform(); - let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 + // fragProxy.position = fragPosition - fragProxy.position = fragPosition + // fragProxy.updateAnimTransform() - fragProxy.updateAnimTransform() - - }); - viewer.impl.sceneUpdated(true); + //}); + //viewer.impl.sceneUpdated(true); }); - - //add toolbar fail - //function ToolbarExtension(viewer, options) { - // Autodesk.Viewing.Extension.call(this, viewer, options); - //} - - //ToolbarExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype); - //ToolbarExtension.prototype.constructor = ToolbarExtension; - - //ToolbarExtension.prototype.load = function () { - // this.viewer.setLightPreset(6); - // this.viewer.setEnvMapBackground(true); - // this.viewer.fitToView(); - // return true; - //}; - - //ToolbarExtension.prototype.unload = function () { - - //}; - //Autodesk.Viewing.theExtensionManager.registerExtension('ToolbarExtension', ToolbarExtension); - - //ToolbarExtension.prototype.onToolbarCreated = function (toolbar) { - // //alert('TODO: customize Viewer toolbar'); - - // var viewer = this.viewer; - // var button1 = new Autodesk.Viewing.UI.Button('show-env-bg-button'); - // button1.onClick = function (e) { - // viewer.setEnvMapBackground(true); - // }; - // button1.addClass('show-env-bg-button'); - // button1.setToolTip('Show Environment'); - - // //SubToolbar - // this.subToolbar = new Autodesk.Viewing.UI.ControlGroup('my-custom-toolbar'); - // this.subToolbar.addControl(button1); - // toolbar.addControl(this.subToolbar); - - //}; - - - //加入點燈光 - //bulbLight = new THREE.PointLight(0xffffff, 1, 1, 2);//0xff0000 - //bulbLight.position.set(-17.33, 51.03, -2.52);//17.880840301513672 - //bulbLight.castShadow = true; - //bulbLight.intensity = 50; - //bulbLight.distance = 1; - //bulbLight.emissiveIntensity = bulbLight.intensity / Math.pow(0.02, 2.0); - //viewer.scene.add(bulbLight); - - //聚光燈 - //spotLight = new THREE.SpotLight(0xffff00, 80, 10);//0xffffff - //spotLight.position.set(-7.58, 18.20, -0.25); //set(-17.33, 51.03, -2.52); - //spotLight.castShadow = true; - //spotLight.visible = true; - //var geom = new THREE.BoxGeometry(); //create 幾何對象 -17.33, 51.03, -4.52 - //var material = new THREE.MeshLambertMaterial({ color: 0xffff00 });//0xff0000 - //var cube = new THREE.Mesh(geom, material); - //cube.position.set(-7.58, 18.20, -1); //set(-17.33, 51.03, -10);//-4.52 - //viewer.scene.add(cube); - //spotLight.target = cube; - //viewer.scene.add(spotLight); - - //light = newLight(); - newLight(); - + //newLight(); + //testLight = new THREE.SpotLight(); } //------------------- 加入熱點 ----------------- @@ -482,7 +475,8 @@ async function addHotPoint(data) { const spriteIcon = "https://d2zqnmauvnpnnm.cloudfront.net/assets-1/images/circle.svg"; //"/img/forge/hotspot.svg"; const style = new DataVizCore.ViewableStyle(viewableType, spriteColor, spriteIcon); - var a = newLight(); + //var a = newLight(); + newLight(); //function onSpriteClicked(event) { // console.log(`Sprite clicked: ${event.dbId}`); //} @@ -521,7 +515,7 @@ async function addHotPoint(data) { event.hasStopped = true; if (event != undefined && event != null) { if (event.dbId >= 10 && event.dbId <= 13) {//event.dbId > 0 && event.dbId < 19 - setLightValues(20, 0x00ff00) + setLightValues(20, 0x00ff00); console.log(`Sprite clicked: ${event.dbId}`); openHotspotModal(); } @@ -1387,26 +1381,26 @@ async function newLight() { //angle - 光從其上界為 Math.PI / 2 的方向散射的最大角度。 //半影 - 由於半影而衰減的聚光燈錐體的百分比。取值介於 0 和 1 之間。默認值為零。 //decay - 光沿光的距離變暗的量。 - //spotLight = new THREE.SpotLight(0xff0000, 200, 20, 0.6, 0.5, 10);//0xffffff 80, 10 //15, 20 , Math.PI / 12 - //spotLight.position.set(43.72, -15.65, -44.96); //set(-17.33, 51.03, -2.52); // -7.58, 18.20, -0.25 -44.96 - //spotLight.castShadow = false; - //spotLight.visible = true; + spotLight = new THREE.SpotLight(0xff0000, 200, 20, 0.6, 0.5, 10);//0xffffff 80, 10 //15, 20 , Math.PI / 12 + spotLight.position.set(43.72, -15.65, -44.96); //set(-17.33, 51.03, -2.52); // -7.58, 18.20, -0.25 -44.96 + spotLight.castShadow = false; + spotLight.visible = true; - //spotLight.target.position.set(43.72, -15.65, -60);// -15.65 -48 - //viewer.scene.add(spotLight.target); + spotLight.target.position.set(43.72, -15.65, -60);// -15.65 -48 + viewer.scene.add(spotLight.target); - //viewer.scene.add(spotLight); + viewer.scene.add(spotLight); - //viewer.impl.sceneUpdated(true); + viewer.impl.sceneUpdated(true); //return spotLight; //加入點燈光 - bulbLight = new THREE.PointLight(0xff0000, 50, 20, 2);//0xff0000 - bulbLight.position.set(43.72, -15.65, -44.96);//17.880840301513672 - bulbLight.castShadow = true; - bulbLight.visible = true; - viewer.scene.add(bulbLight); + //bulbLight = new THREE.PointLight(0xffffff, 50, 20, 2);//0xff0000 + //bulbLight.position.set(43.72, -15.65, -44.96);//17.880840301513672 + //bulbLight.castShadow = true; + //bulbLight.visible = true; + //viewer.scene.add(bulbLight); //pointLightHelper = new THREE.PointLightHelper(pointLight); //viewer.scene.add(pointLightHelper); @@ -1439,13 +1433,15 @@ function setLightValues(intensity, color) {// distance, angle, penumbra, decay, function setLightOpenOrClose(value) {//, light if (value) { //light.visible = true; - //spotLight.visible = true; - bulbLight.visible = true; + spotLight.visible = true; + //bulbLight.visible = true; + //testLight.visible = true; } else { //light.visible = false; - //spotLight.visible = false; - bulbLight.visible = false; + spotLight.visible = false; + //bulbLight.visible = false; + //testLight.visible = false; } viewer.impl.sceneUpdated(true); } @@ -1457,3 +1453,7 @@ function setLightTransparency(value) { } //------------- end ----------------------------------- +function consoleList() { + console.log(tagIdDevList); + console.log(roomDataList); +} \ No newline at end of file