[Frontend] [監控系統][照明系統] 加入燈光;新增函式: 燈光開關、燈光的強度和顏色更改、物件設定顏色和顏色的透明度、物件透明度設定

This commit is contained in:
wanli 2023-01-04 15:15:15 +08:00
parent 4c72cd822e
commit 5cce208d6e
2 changed files with 93 additions and 34 deletions

View File

@ -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();

View File

@ -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;