[Frontend] 函式輸入更改為device_guid: 燈光關燈、燈光改變顏色和強度
This commit is contained in:
parent
f4e837212d
commit
46f9ca1642
@ -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();
|
||||
|
@ -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) {
|
||||
async function setLightValues(deviceGuid, intensity, color) {
|
||||
for (var i = 0; i < lightList.length; i++) {
|
||||
if (lightList[i].dbid == dbid) {
|
||||
lightList[i].spotLight.intensity = intensity;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user