2022-11-18 21:27:54 +08:00
|
|
|
|
var viewer;
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
2022-11-24 00:20:37 +08:00
|
|
|
|
let fragProxy;
|
|
|
|
|
var targetFloorZ;
|
|
|
|
|
var elevatorSpeed;
|
2022-12-23 16:17:22 +08:00
|
|
|
|
var selector = "#forgeViewer";
|
2023-01-04 01:18:46 +08:00
|
|
|
|
var myDataList;
|
2023-01-04 15:15:15 +08:00
|
|
|
|
var lightDataList;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
var lightList = []; //燈光清單
|
|
|
|
|
var levels; //剖面用
|
|
|
|
|
var lowerIdx = 0; //剖面的下方樓層
|
|
|
|
|
var upperIdx = 0; //剖面的上方樓層
|
2022-11-18 21:27:54 +08:00
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
function launchViewer(urn, callback, failCallback, _selector = "#forgeViewer") {
|
2022-12-27 15:17:52 +08:00
|
|
|
|
selector = _selector;
|
2022-11-18 21:27:54 +08:00
|
|
|
|
var options = {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
env: "AutodeskProduction",
|
2023-01-05 18:37:12 +08:00
|
|
|
|
getAccessToken: getForgeToken,
|
|
|
|
|
settings: {
|
|
|
|
|
ambientShadows: false,
|
2023-04-24 11:55:46 +08:00
|
|
|
|
groundShadows: false,
|
|
|
|
|
},
|
2022-11-18 21:27:54 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Autodesk.Viewing.Initializer(options, () => {
|
2022-12-23 16:17:22 +08:00
|
|
|
|
viewer = new Autodesk.Viewing.GuiViewer3D($(selector)[0]);
|
2022-11-29 12:46:19 +08:00
|
|
|
|
//viewer = new Autodesk.Viewing.Viewer3D(document.getElementById('forgeViewer'));
|
2022-11-18 21:27:54 +08:00
|
|
|
|
viewer.start();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
var documentId = "urn:" + urn;
|
2022-12-01 19:32:32 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
Autodesk.Viewing.Document.load(
|
|
|
|
|
documentId,
|
|
|
|
|
onDocumentLoadSuccess,
|
|
|
|
|
onDocumentLoadFailure
|
|
|
|
|
);
|
2023-01-05 18:37:12 +08:00
|
|
|
|
setShadowShow();
|
2022-11-18 21:27:54 +08:00
|
|
|
|
|
2022-12-27 15:17:52 +08:00
|
|
|
|
$(selector).on("autodesk:loaded", function (e, nodeIds) {
|
2022-12-07 18:59:53 +08:00
|
|
|
|
callback ? callback(viewer, nodeIds) : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-01-04 18:49:37 +08:00
|
|
|
|
$(selector).on("autodesk:loaded:fail", function (e) {
|
|
|
|
|
failCallback ? failCallback(viewer) : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
//test
|
2022-12-31 18:03:16 +08:00
|
|
|
|
// for (let i = 0; i < urn.length; i++) {
|
|
|
|
|
// Autodesk.Viewing.Document.load(urn[i]["urn"], async (doc) => {
|
|
|
|
|
// let viewables = doc.getRoot().getDefaultGeometry();
|
|
|
|
|
// let model = await viewer.loadDocumentNode(doc, viewables, {
|
|
|
|
|
// preserveView: false,
|
|
|
|
|
// keepCurrentModels: true,
|
|
|
|
|
// placementTransform: (new THREE.Matrix4()).setPosition(urn[i]["xform"]),
|
|
|
|
|
// keepCurrentModels: true,
|
|
|
|
|
// globalOffset: {
|
|
|
|
|
// x: 0,
|
|
|
|
|
// y: 0,
|
|
|
|
|
// z: 0
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// await viewer.waitForLoadDone(); //!<<< Wait for loading materials, properties and geometries for this model (URN)
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//loadHeatmaps(viewer.getAllModels()[0]); //!<<< equals to viewer.model
|
2022-11-18 21:27:54 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function launchViewerForHotspot(
|
|
|
|
|
urn,
|
|
|
|
|
callback,
|
|
|
|
|
failCallback,
|
|
|
|
|
_selector = "#forgeViewer"
|
|
|
|
|
) {
|
2022-12-27 15:17:52 +08:00
|
|
|
|
selector = _selector;
|
2022-12-26 18:20:32 +08:00
|
|
|
|
var av = Autodesk.Viewing;
|
|
|
|
|
var options = {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
env: "AutodeskProduction",
|
2023-01-05 18:37:12 +08:00
|
|
|
|
getAccessToken: getForgeToken,
|
|
|
|
|
settings: {
|
|
|
|
|
ambientShadows: false,
|
2023-04-24 11:55:46 +08:00
|
|
|
|
groundShadows: false,
|
|
|
|
|
},
|
2022-12-26 18:20:32 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Autodesk.Viewing.Initializer(options, () => {
|
|
|
|
|
viewer = new Autodesk.Viewing.GuiViewer3D($(selector)[0]);
|
|
|
|
|
viewer.start();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
var documentId = "urn:" + urn;
|
2022-12-26 18:20:32 +08:00
|
|
|
|
|
|
|
|
|
viewer.addEventListener(av.GEOMETRY_LOADED_EVENT, addHotPoint, {
|
|
|
|
|
once: true,
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
Autodesk.Viewing.Document.load(
|
|
|
|
|
documentId,
|
|
|
|
|
onDocumentLoadSuccess,
|
|
|
|
|
onDocumentLoadFailure
|
|
|
|
|
);
|
2023-01-05 18:37:12 +08:00
|
|
|
|
setShadowShow();
|
2022-12-26 18:20:32 +08:00
|
|
|
|
$(selector).on("autodesk:loaded", function (e, nodeIds) {
|
|
|
|
|
callback ? callback(viewer, nodeIds) : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-01-04 18:49:37 +08:00
|
|
|
|
|
|
|
|
|
$(selector).on("autodesk:loaded:fail", function (e) {
|
|
|
|
|
failCallback ? failCallback(viewer) : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-26 18:20:32 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function launchViewerNoTools(
|
|
|
|
|
urn,
|
|
|
|
|
callback,
|
|
|
|
|
failCallback,
|
|
|
|
|
_selector = "#forgeViewer"
|
|
|
|
|
) {
|
2023-01-04 17:31:34 +08:00
|
|
|
|
selector = _selector;
|
2022-12-09 18:20:41 +08:00
|
|
|
|
var options = {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
env: "AutodeskProduction",
|
2023-01-05 18:37:12 +08:00
|
|
|
|
getAccessToken: getForgeToken,
|
|
|
|
|
settings: {
|
|
|
|
|
ambientShadows: false,
|
2023-04-24 11:55:46 +08:00
|
|
|
|
groundShadows: false,
|
|
|
|
|
},
|
2022-12-09 18:20:41 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Autodesk.Viewing.Initializer(options, () => {
|
|
|
|
|
//viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer'));
|
2022-12-26 18:32:21 +08:00
|
|
|
|
viewer = new Autodesk.Viewing.Viewer3D($(selector)[0]);
|
2022-12-09 18:20:41 +08:00
|
|
|
|
viewer.start();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
var documentId = "urn:" + urn;
|
2022-12-09 18:20:41 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
Autodesk.Viewing.Document.load(
|
|
|
|
|
documentId,
|
|
|
|
|
onDocumentLoadSuccess,
|
|
|
|
|
onDocumentLoadFailure
|
|
|
|
|
);
|
2023-01-05 18:37:12 +08:00
|
|
|
|
setShadowShow();
|
2022-12-23 16:17:22 +08:00
|
|
|
|
$(selector).on("autodesk:loaded", function (e, nodeIds) {
|
2022-12-09 18:20:41 +08:00
|
|
|
|
callback ? callback(viewer, nodeIds) : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-01-04 18:49:37 +08:00
|
|
|
|
|
|
|
|
|
$(selector).on("autodesk:loaded:fail", function (e) {
|
|
|
|
|
failCallback ? failCallback(viewer) : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-09 18:20:41 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 00:20:37 +08:00
|
|
|
|
function getAllLeafComponents(viewer, callback) {
|
|
|
|
|
var cbCount = 0;
|
|
|
|
|
var tree;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
var jsData = [];
|
2022-11-24 00:20:37 +08:00
|
|
|
|
|
|
|
|
|
function getLeafComponentsRec(current, parent) {
|
|
|
|
|
cbCount++;
|
|
|
|
|
if (tree.getChildCount(current) != 0) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
tree.enumNodeChildren(
|
|
|
|
|
current,
|
|
|
|
|
function (children) {
|
|
|
|
|
getLeafComponentsRec(children, current);
|
|
|
|
|
},
|
|
|
|
|
false
|
|
|
|
|
);
|
2022-11-24 00:20:37 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
var nodeName = viewer.model.getInstanceTree().getNodeName(current);
|
|
|
|
|
jsData.push({ id: current, parent: parent, text: nodeName });
|
2022-11-24 00:20:37 +08:00
|
|
|
|
|
|
|
|
|
if (--cbCount == 0) callback(jsData);
|
|
|
|
|
}
|
|
|
|
|
viewer.getObjectTree(function (objectTree) {
|
|
|
|
|
tree = objectTree;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
var rootId = tree.getRootId();
|
|
|
|
|
var nodeName = viewer.model.getInstanceTree().getNodeName(rootId);
|
|
|
|
|
jsData.push({ id: rootId, parent: "#", text: nodeName });
|
|
|
|
|
var allLeafComponents = getLeafComponentsRec(rootId, "#");
|
2022-11-24 00:20:37 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 18:37:07 +08:00
|
|
|
|
class elevator3D {
|
|
|
|
|
constructor(option = {}) {
|
|
|
|
|
this.ele = option.element;
|
|
|
|
|
this.viewer = option.viewer;
|
|
|
|
|
this.nodeId = option.nodeId;
|
2023-05-23 10:58:08 +08:00
|
|
|
|
this.speed = option.speed ?? 0.18;
|
2023-01-03 16:47:23 +08:00
|
|
|
|
this.tagValue = option.tagValue ?? "";
|
2022-11-30 18:37:07 +08:00
|
|
|
|
this.fragProxys = [];
|
|
|
|
|
this.fragProxy = null;
|
|
|
|
|
this.initCallback = option.inited ?? null;
|
|
|
|
|
this.movStatus = 0;
|
|
|
|
|
this.targetFloorZ = 0;
|
|
|
|
|
this.floorHeight = option.floorHeight ?? [{}];
|
2023-02-14 15:16:11 +08:00
|
|
|
|
this.sensorObjs = option.sensorObjs ?? null;
|
2022-11-30 18:37:07 +08:00
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 定義遍歷模型中所有片段的異步函數
|
|
|
|
|
enumFragments = function (nodeId) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// 定義結果陣列
|
|
|
|
|
let result = [];
|
|
|
|
|
// 使用 InstanceTree.enumNodeFragments 遍歷模型中的所有片段
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.viewer?.model?.getData().instanceTree.enumNodeFragments(
|
|
|
|
|
nodeId,
|
|
|
|
|
(fragId) => {
|
|
|
|
|
// 將遍歷到的片段 ID 添加到結果陣列中
|
|
|
|
|
result.push(fragId);
|
|
|
|
|
},
|
|
|
|
|
(nodeId) => {
|
|
|
|
|
// 如果遍歷到的節點是葉節點,则返回 true,表示繼續遍歷該節點的片段
|
|
|
|
|
return model.getData().instanceTree.isLeaf(nodeId);
|
|
|
|
|
}
|
|
|
|
|
);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 将结果陣列作為参数调用 resolve 函数
|
|
|
|
|
resolve(result);
|
|
|
|
|
});
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
// 設置樹狀結構中片段
|
|
|
|
|
setTreeFrag = async function (callback) {
|
2022-12-08 18:12:40 +08:00
|
|
|
|
let tree = this.viewer?.model?.getData().instanceTree;
|
|
|
|
|
if (!tree) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 18:37:07 +08:00
|
|
|
|
let nodeId = this.nodeId;
|
2022-12-27 15:17:52 +08:00
|
|
|
|
|
2022-12-01 19:32:32 +08:00
|
|
|
|
if (nodeId) {
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 刪除 fragmentProxys 中與當前 nodeId 相同的項目
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.fragProxys
|
|
|
|
|
.filter((x) => x.nodeId == nodeId)
|
|
|
|
|
.forEach((x) => {
|
|
|
|
|
let idx = this.fragProxys.indexOf(x);
|
|
|
|
|
this.fragProxys.splice(idx, 1);
|
|
|
|
|
});
|
2022-12-01 19:32:32 +08:00
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 遍歷當前 nodeId 中的所有片段
|
|
|
|
|
let fragments = await this.enumFragments(nodeId);
|
2022-12-01 19:32:32 +08:00
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
fragments.forEach((frag) => {
|
|
|
|
|
// 取得當前片段的 FragmentProxy 物件
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let fragProxy = this.viewer.impl.getFragmentProxy(
|
|
|
|
|
this.viewer.model,
|
|
|
|
|
frag
|
|
|
|
|
);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 將當前片段的信息添加到 fragProxys 陣列中
|
|
|
|
|
this.fragProxys.push({ nodeId: nodeId, fragId: frag, frag: fragProxy });
|
|
|
|
|
// 取得當前片段的動畫變換矩陣
|
2022-12-01 19:32:32 +08:00
|
|
|
|
fragProxy.getAnimTransform();
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 定義當前片段的位置向量
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let fragPosition = new THREE.Vector3(0, 0, 0); // 一樓0 二樓15 三樓 26
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 設置當前片段的位置
|
2022-12-01 19:32:32 +08:00
|
|
|
|
fragProxy.position = fragPosition;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 更新當前片段的動畫變換矩陣
|
2022-12-01 19:32:32 +08:00
|
|
|
|
fragProxy.updateAnimTransform();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-01 19:32:32 +08:00
|
|
|
|
}
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 通知檢視器更新場景
|
2022-11-30 18:37:07 +08:00
|
|
|
|
this.viewer.impl.sceneUpdated(true);
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
2023-01-13 16:49:55 +08:00
|
|
|
|
if (!$(this.ele)[0]) {
|
|
|
|
|
callback ? callback() : "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-01 19:32:32 +08:00
|
|
|
|
if (typeof $(this.ele)[0]._elevator3D == "undefined") {
|
2022-11-30 18:37:07 +08:00
|
|
|
|
$(this.ele)[0]._elevator3D = [];
|
|
|
|
|
}
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
2022-11-30 18:37:07 +08:00
|
|
|
|
$(this.ele)[0]._elevator3D.push({ nodeId: nodeId, obj: this });
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
this.initCallback ? this.initCallback() : "";
|
|
|
|
|
callback ? callback() : "";
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-30 18:37:07 +08:00
|
|
|
|
|
2022-12-01 19:32:32 +08:00
|
|
|
|
init = function (callback = null) {
|
|
|
|
|
this.setTreeFrag(callback);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-30 18:37:07 +08:00
|
|
|
|
|
|
|
|
|
setElevatorFloor = function (floor) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.targetFloorZ =
|
|
|
|
|
this.floorHeight.filter((x) => x.floor == floor)[0]?.height ?? 0;
|
|
|
|
|
};
|
2022-11-30 18:37:07 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
setElevatorSpeed = function (speed) {
|
|
|
|
|
//0.01 ~ 1
|
2022-11-30 18:37:07 +08:00
|
|
|
|
this.speed = speed;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-30 18:37:07 +08:00
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 電梯移動
|
|
|
|
|
movElevator = async function () {
|
2022-11-30 18:37:07 +08:00
|
|
|
|
let nodeId = this.nodeId;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let fragProxyZ = 0; // 定義 fragProxyZ 變量,用於存儲當前片段的 z 坐標
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
|
|
|
|
// 取得當前 nodeId 的片段代理對象
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let fragProxy = this.fragProxys.filter((x) => x.nodeId == nodeId)[0]?.frag;
|
2022-12-01 19:32:32 +08:00
|
|
|
|
if (!fragProxy) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
2022-12-07 18:59:53 +08:00
|
|
|
|
changeColor(nodeId);
|
2022-12-27 15:17:52 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (
|
|
|
|
|
(this.movStatus == 2 &&
|
|
|
|
|
fragProxy.position.z.roundDecimal(2) <
|
|
|
|
|
this.targetFloorZ.roundDecimal(2)) ||
|
|
|
|
|
(this.movStatus == 1 &&
|
|
|
|
|
fragProxy.position.z.roundDecimal(2) >
|
|
|
|
|
this.targetFloorZ.roundDecimal(2)) ||
|
|
|
|
|
fragProxy.position.z.roundDecimal(2) == this.targetFloorZ.roundDecimal(2)
|
|
|
|
|
) {
|
2022-12-08 17:27:32 +08:00
|
|
|
|
stoped(this);
|
|
|
|
|
}
|
2022-12-07 18:59:53 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (
|
|
|
|
|
fragProxy.position.z.roundDecimal(2) > this.targetFloorZ.roundDecimal(2)
|
|
|
|
|
) {
|
2022-12-07 18:59:53 +08:00
|
|
|
|
this.movStatus = 2;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else if (
|
|
|
|
|
fragProxy.position.z.roundDecimal(2) < this.targetFloorZ.roundDecimal(2)
|
|
|
|
|
) {
|
2022-12-07 18:59:53 +08:00
|
|
|
|
this.movStatus = 1;
|
2022-11-30 18:37:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
// 遍歷當前 nodeId 中的所有片段
|
|
|
|
|
let fragments = await this.enumFragments(nodeId);
|
|
|
|
|
|
|
|
|
|
fragments.forEach((frag) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let fragProxy = this.viewer.impl.getFragmentProxy(
|
|
|
|
|
this.viewer.model,
|
|
|
|
|
frag
|
|
|
|
|
);
|
2022-12-01 19:32:32 +08:00
|
|
|
|
fragProxy.getAnimTransform();
|
2023-01-03 16:47:23 +08:00
|
|
|
|
|
2022-12-08 17:27:32 +08:00
|
|
|
|
if (this.movStatus == 2) {
|
2022-12-01 19:32:32 +08:00
|
|
|
|
fragProxy.position.z -= this.speed;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else if (this.movStatus == 1) {
|
2022-12-01 19:32:32 +08:00
|
|
|
|
fragProxy.position.z += this.speed;
|
2022-11-30 18:37:07 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let tarFrag = this.fragProxys.filter(
|
|
|
|
|
(x) => x.nodeId == nodeId && x.fragId == frag
|
|
|
|
|
)[0];
|
2023-02-14 15:16:11 +08:00
|
|
|
|
if (tarFrag) {
|
2023-01-03 16:47:23 +08:00
|
|
|
|
tarFrag.frag.position.z = fragProxy.position.z;
|
|
|
|
|
}
|
2022-12-01 19:32:32 +08:00
|
|
|
|
fragProxyZ = fragProxy.position.z;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
|
2023-02-24 16:03:17 +08:00
|
|
|
|
// 改變感測器熱點位置
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.sensorObjs && this.sensorObjs[0]?.changePos(nodeId + 2, fragProxyZ);
|
2023-02-24 16:03:17 +08:00
|
|
|
|
// if(nodeId === 15200) {
|
|
|
|
|
// }
|
2023-04-24 11:55:46 +08:00
|
|
|
|
fragProxy.updateAnimTransform();
|
|
|
|
|
});
|
2022-11-30 18:37:07 +08:00
|
|
|
|
|
|
|
|
|
this.viewer.impl.sceneUpdated(true);
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let movElevator = $(this.ele)[0]
|
|
|
|
|
._elevator3D.filter((x) => x.nodeId == this.nodeId)[0]
|
|
|
|
|
?.obj.movElevator.bind(this);
|
2022-12-07 18:59:53 +08:00
|
|
|
|
|
2022-12-08 17:27:32 +08:00
|
|
|
|
if (this.movStatus == 2) {
|
2022-11-30 18:37:07 +08:00
|
|
|
|
if (fragProxyZ >= this.targetFloorZ) {
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
movElevator();
|
|
|
|
|
});
|
2022-12-07 18:59:53 +08:00
|
|
|
|
} else {
|
2022-12-08 17:27:32 +08:00
|
|
|
|
stoped(this);
|
2022-11-30 18:37:07 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else if (this.movStatus == 1) {
|
2022-11-30 18:37:07 +08:00
|
|
|
|
if (fragProxyZ <= this.targetFloorZ) {
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
movElevator();
|
|
|
|
|
});
|
2022-12-07 18:59:53 +08:00
|
|
|
|
} else {
|
2022-12-08 17:27:32 +08:00
|
|
|
|
stoped(this);
|
2022-11-30 18:37:07 +08:00
|
|
|
|
}
|
2022-12-08 17:27:32 +08:00
|
|
|
|
} else {
|
|
|
|
|
stoped(this);
|
2022-11-30 18:37:07 +08:00
|
|
|
|
}
|
2022-12-27 15:17:52 +08:00
|
|
|
|
|
2022-12-08 17:27:32 +08:00
|
|
|
|
function stoped(obj) {
|
|
|
|
|
obj.movStatus = 0;
|
|
|
|
|
hideColor(nodeId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-11-30 18:37:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-01 19:32:32 +08:00
|
|
|
|
function onDocumentLoadSuccess(doc, eleOption) {
|
2022-11-18 21:27:54 +08:00
|
|
|
|
var viewables = doc.getRoot().getDefaultGeometry();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
viewer.loadDocumentNode(doc, viewables).then((i) => {
|
2022-11-18 21:27:54 +08:00
|
|
|
|
// documented loaded, any action?
|
|
|
|
|
});
|
2022-12-31 18:03:16 +08:00
|
|
|
|
// viewer.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, (args) => {
|
|
|
|
|
// var currSelection = viewer.getSelection();
|
|
|
|
|
// var domElem = document.getElementById('id_printer');
|
|
|
|
|
// domElem.innerText = currSelection[0];
|
|
|
|
|
// });
|
|
|
|
|
|
2022-11-30 18:37:07 +08:00
|
|
|
|
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
|
2023-01-16 18:35:01 +08:00
|
|
|
|
let instanceTree = viewer.model?.getData().instanceTree;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// console.log(instanceTree.nodeAccess)
|
2022-12-07 18:59:53 +08:00
|
|
|
|
allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex);
|
2023-01-04 17:31:34 +08:00
|
|
|
|
/*getNodeIdByDbIds("【電梯】", (nodeIds) => {*/
|
|
|
|
|
$(selector).trigger("autodesk:loaded");
|
|
|
|
|
/*});*/
|
2022-11-30 18:37:07 +08:00
|
|
|
|
});
|
2022-11-24 00:20:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 19:03:31 +08:00
|
|
|
|
// 輔助函數,使用 Promise 封裝 viewer.getProperties 函數
|
2023-02-14 15:16:11 +08:00
|
|
|
|
function viewerGetProperties(dbIds, attributeName = null) {
|
2022-12-30 19:03:31 +08:00
|
|
|
|
// 在這裡,我們使用 viewer.getProperties 函數的成功回調函數作為 resolve 函數,
|
|
|
|
|
// 並使用 viewer.getProperties 函數的失敗回調函數作為 resolve 函數的參數
|
|
|
|
|
// 這樣,當 viewer.getProperties 函數成功時,Promise 會傳回 properties 物件;
|
|
|
|
|
// 當 viewer.getProperties 函數失敗時,Promise 會傳回 null。
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let option = {};
|
|
|
|
|
if (attributeName != null) {
|
|
|
|
|
option.propFilter = [attributeName]; // 限制只返回指定的屬性
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
viewer.model.getBulkProperties2(
|
|
|
|
|
dbIds,
|
|
|
|
|
option, // 取得指定元素的屬性信息
|
2023-02-14 15:16:11 +08:00
|
|
|
|
function (elements) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
resolve(elements); // 成功時傳回 elements 物件
|
|
|
|
|
}
|
|
|
|
|
);
|
2022-12-30 19:03:31 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2022-12-27 15:17:52 +08:00
|
|
|
|
|
2022-12-30 19:03:31 +08:00
|
|
|
|
// 輔助函數,使用 Promise 封裝 viewer.search 函數
|
|
|
|
|
async function getNodeIdBySearch(text) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
viewer.search(
|
|
|
|
|
text,
|
|
|
|
|
(e) => {
|
|
|
|
|
// 在 3D 模型中搜索具有指定文本的元素
|
|
|
|
|
resolve(e); // 成功時傳回搜索結果
|
|
|
|
|
},
|
|
|
|
|
(e) => {
|
|
|
|
|
resolve(null); // 失敗時傳回 null
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
2022-12-30 19:03:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// 主函數 - 透過 model 全部 node 取得特定 nodeId
|
2023-01-03 16:47:23 +08:00
|
|
|
|
async function getNodeIdByDbIds(checkValue = [], callback = null) {
|
2022-12-30 19:03:31 +08:00
|
|
|
|
let evelMap = new Map();
|
|
|
|
|
let hasElement = false; // 設置是否有 【tag_id】的node
|
2023-01-03 16:47:23 +08:00
|
|
|
|
let targetNodeIds = await getNodeIdBySearch(checkValue);
|
2023-02-14 15:16:11 +08:00
|
|
|
|
let elements = await viewerGetProperties(targetNodeIds, "【tag_id】");
|
2022-12-30 19:03:31 +08:00
|
|
|
|
|
|
|
|
|
// 從 elements 中篩選出包含 【tag_id】 屬性的元素
|
2023-04-24 11:55:46 +08:00
|
|
|
|
elements = elements.filter(
|
|
|
|
|
(x) =>
|
|
|
|
|
x.properties.findIndex(
|
|
|
|
|
(y) =>
|
|
|
|
|
y.displayName == "【tag_id】" &&
|
|
|
|
|
checkValue.indexOf(y.displayValue) != -1
|
|
|
|
|
) != -1
|
|
|
|
|
);
|
2022-12-30 19:03:31 +08:00
|
|
|
|
|
|
|
|
|
if (elements) {
|
|
|
|
|
hasElement = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var e of elements) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let name = e.properties[0].displayValue; // 獲取元素的 【tag_id】 屬性
|
2022-12-30 19:03:31 +08:00
|
|
|
|
let chiElements = null;
|
|
|
|
|
|
|
|
|
|
// 獲取 node 元素的子元素信息
|
|
|
|
|
targetNodeIds = await viewerGetProperties([e.dbId], "child");
|
|
|
|
|
// 二次篩選
|
2023-04-24 11:55:46 +08:00
|
|
|
|
chiElements = targetNodeIds.filter(
|
|
|
|
|
(x) => x.properties.findIndex((y) => y.displayName == "child") != -1
|
|
|
|
|
);
|
2022-12-30 19:03:31 +08:00
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// 獲取子元素的 nodeId
|
2023-04-24 11:55:46 +08:00
|
|
|
|
targetNodeIds = chiElements.map((x) => x.properties[0].displayValue);
|
2022-12-30 19:03:31 +08:00
|
|
|
|
// 獲取子元素的屬性信息
|
|
|
|
|
chiElements = await viewerGetProperties(targetNodeIds);
|
|
|
|
|
|
|
|
|
|
// 將 node 元素的 【tag_id】 屬性和子元素的 nodeId 加入 Map 中
|
|
|
|
|
evelMap.set(name, chiElements[0]?.dbId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasElement) {
|
|
|
|
|
callback ? callback([]) : "";
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback ? callback(evelMap) : "";
|
2022-12-07 18:59:53 +08:00
|
|
|
|
return evelMap;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 00:20:37 +08:00
|
|
|
|
function setElevatorFloor(floor) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (floor == 0) targetFloorZ = 0;
|
|
|
|
|
else if (floor == 1) targetFloorZ = 15;
|
|
|
|
|
else if (floor == 2) targetFloorZ = 26;
|
2022-11-24 00:20:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function setElevatorSpeed(speed) {
|
|
|
|
|
//0.01 ~ 1
|
2022-11-24 00:20:37 +08:00
|
|
|
|
elevatorSpeed = speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function movElevator() {
|
2023-01-16 18:35:01 +08:00
|
|
|
|
let tree = viewer.model?.getData().instanceTree;
|
2022-11-24 00:20:37 +08:00
|
|
|
|
let nodeId = 10952;
|
|
|
|
|
let fragProxyZ = 0;
|
|
|
|
|
var movStatus = 0; // 0=no 1=up 2=down
|
|
|
|
|
|
|
|
|
|
if (fragProxy.position.z > targetFloorZ) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
movStatus = 2;
|
|
|
|
|
} else if (fragProxy.position.z < targetFloorZ) {
|
|
|
|
|
movStatus = 1;
|
2022-11-24 00:20:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (movStatus == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tree.enumNodeFragments(nodeId, function (frag) {
|
|
|
|
|
fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag);
|
|
|
|
|
fragProxy.getAnimTransform();
|
2022-12-31 18:03:16 +08:00
|
|
|
|
//let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26
|
2022-11-24 00:20:37 +08:00
|
|
|
|
if (movStatus == 2) {
|
|
|
|
|
fragProxy.position.z -= elevatorSpeed;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else if (movStatus == 1) {
|
2022-11-24 00:20:37 +08:00
|
|
|
|
fragProxy.position.z += elevatorSpeed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fragProxyZ = fragProxy.position.z;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
fragProxy.updateAnimTransform();
|
2022-11-24 00:20:37 +08:00
|
|
|
|
});
|
|
|
|
|
viewer.impl.sceneUpdated(true);
|
|
|
|
|
|
|
|
|
|
if (movStatus == 2) {
|
|
|
|
|
if (fragProxyZ >= targetFloorZ) {
|
|
|
|
|
requestAnimationFrame(movElevator);
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else if (movStatus == 1) {
|
2022-11-24 00:20:37 +08:00
|
|
|
|
if (fragProxyZ <= targetFloorZ) {
|
|
|
|
|
requestAnimationFrame(movElevator);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
|
|
|
|
//let fragPosition = new THREE.Vector3(position);// 一樓0 二樓15 三樓 26
|
|
|
|
|
|
|
|
|
|
//fragProxy.position = fragPosition;
|
|
|
|
|
|
|
|
|
|
//fragProxy.updateAnimTransform();
|
|
|
|
|
|
|
|
|
|
//viewer.impl.sceneUpdated(true);
|
2022-11-24 00:20:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getAllDbIds(viewer) {
|
2023-01-16 18:35:01 +08:00
|
|
|
|
var instanceTree = viewer.model?.getData().instanceTree;
|
2022-11-24 00:20:37 +08:00
|
|
|
|
|
|
|
|
|
var allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex);
|
2022-11-18 21:27:54 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
return allDbIdsStr.map(function (id) {
|
|
|
|
|
return parseInt(id);
|
|
|
|
|
});
|
2022-11-18 21:27:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Autodesk.Viewing.Document.load() failuire callback.
|
|
|
|
|
*/
|
|
|
|
|
function onDocumentLoadFailure(viewerErrorCode) {
|
2023-01-04 18:49:37 +08:00
|
|
|
|
$(selector).trigger("autodesk:loaded:fail");
|
2022-11-18 21:27:54 +08:00
|
|
|
|
console.error("onDocumentLoadFailure() - errorCode:" + viewerErrorCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getForgeToken(callback) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
fetch(forgeTokenBase.url).then((res) => {
|
|
|
|
|
res.json().then((data) => {
|
2022-12-27 15:17:52 +08:00
|
|
|
|
let limitResType = ["object", "undefined"];
|
|
|
|
|
let access_token = data;
|
|
|
|
|
$.each(forgeTokenBase.res_access_token, (idx, dict) => {
|
|
|
|
|
access_token = access_token[dict];
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-27 15:17:52 +08:00
|
|
|
|
|
|
|
|
|
let expires_in = data;
|
|
|
|
|
$.each(forgeTokenBase.res_expires_in, (idx, dict) => {
|
|
|
|
|
expires_in = expires_in[dict];
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-27 15:17:52 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (
|
|
|
|
|
limitResType.includes(typeof access_token) ||
|
|
|
|
|
limitResType.includes(typeof expires_in)
|
|
|
|
|
) {
|
|
|
|
|
(access_token = ""), (expires_in = "");
|
2022-12-27 15:17:52 +08:00
|
|
|
|
throw "access_token or expires_in on the ForgeTokenBase object for getting forge token by URL is not the correct path.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(access_token, expires_in);
|
2022-11-18 21:27:54 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
//callback("eyJhbGciOiJSUzI1NiIsImtpZCI6IlU3c0dGRldUTzlBekNhSzBqZURRM2dQZXBURVdWN2VhIn0.eyJzY29wZSI6WyJkYXRhOndyaXRlIiwiZGF0YTpyZWFkIiwiYnVja2V0OnJlYWQiLCJidWNrZXQ6dXBkYXRlIiwiYnVja2V0OmNyZWF0ZSJdLCJjbGllbnRfaWQiOiJUQTNocXNGZnpRYk5PVVhLcGxkS1VLU2V3NFNKMjF3NSIsImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9hand0ZXhwNjAiLCJqdGkiOiJiemxzWE5qWElvZ2R1UjUzTUJkdlhrTTNTT01qeVB1bHJrMmdTVWJudGNTeDg1b01kRG1xejg3Z05jenJkRzhpIiwiZXhwIjoxNjY4MTgzMDM2fQ.VU3qLwTJ9nlXnomKCdk4y5UcgszGEO_zlvE7w5mWWajeBMwKLo-zw7LJEqUEajRksvssppR9SbVsjLSx-vDVc3DRhCo3jYTWKPT1T3wQrlkOSqLeIrAdnKdBDNBWKgrGJt_xcmXc3dZ3XNKf9L_F6Ex808rUlo6cem1mcPpKl1jCBDqKu1mAX7aDtZ65TTQZbGGhbG4HdnET-d1i5w4LunGN11UAHhDUW3n0SWWIBL27PiiUQONZttajhD5st6IngYLcjr93BYVyJmDF7-wm4WZlHSw2OnXIfbJcFXEd83uVv_Rej4UXjzZ0e6kHwzc2nvGvKSIFu3Nt7CabdR8CkA", 3599);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-29 18:44:09 +08:00
|
|
|
|
//------------------ 熱圖 -------------------------------
|
|
|
|
|
class ADHeatMaps {
|
|
|
|
|
constructor(option = {}) {
|
2022-12-30 19:03:31 +08:00
|
|
|
|
this.devices = option.devices ?? [];
|
|
|
|
|
this.checkNodeString = "【ROOM】";
|
2022-12-31 18:03:16 +08:00
|
|
|
|
this.tempVals = [];
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.roomDbIds = []; //房間 dbId
|
2022-12-29 18:44:09 +08:00
|
|
|
|
this.model = null;
|
|
|
|
|
this.dataVizExtn = null;
|
2023-03-13 12:00:31 +08:00
|
|
|
|
this.shadingData = null;
|
2022-12-29 18:44:09 +08:00
|
|
|
|
this.onComplete = option.onComplete ?? null;
|
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init = async function () {
|
|
|
|
|
// 載入 Autodesk Viewer 的資料視覺化擴充功能
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const dataVizExtn = await viewer.loadExtension(
|
|
|
|
|
"Autodesk.DataVisualization"
|
|
|
|
|
);
|
2023-02-14 15:16:11 +08:00
|
|
|
|
this.dataVizExtn = dataVizExtn;
|
2022-12-29 18:44:09 +08:00
|
|
|
|
// 儲存 Viewer 的模型
|
|
|
|
|
this.model = viewer.model;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.addHeatMaps();
|
|
|
|
|
};
|
2023-03-13 12:00:31 +08:00
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
async addHeatMaps() {
|
2022-12-29 18:44:09 +08:00
|
|
|
|
const {
|
|
|
|
|
SurfaceShadingData,
|
|
|
|
|
SurfaceShadingPoint,
|
|
|
|
|
SurfaceShadingNode,
|
2023-04-24 11:55:46 +08:00
|
|
|
|
SurfaceShadingGroup,
|
2022-12-29 18:44:09 +08:00
|
|
|
|
} = Autodesk.DataVisualization.Core;
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// test
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const shadingGroup = new SurfaceShadingGroup("iot-heatmap");
|
2023-03-13 12:00:31 +08:00
|
|
|
|
const rooms = new Map();
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
console.log(this.devices);
|
2023-03-13 12:00:31 +08:00
|
|
|
|
for (const { id, roomDbId, position, sensorTypes } of this.devices) {
|
|
|
|
|
if (!id || roomDbId == -1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
|
2023-03-13 12:00:31 +08:00
|
|
|
|
if (!rooms.has(roomDbId)) {
|
|
|
|
|
const room = new SurfaceShadingNode(id, roomDbId);
|
|
|
|
|
shadingGroup.addChild(room);
|
|
|
|
|
rooms.set(roomDbId, room);
|
|
|
|
|
}
|
|
|
|
|
const room = rooms.get(roomDbId);
|
|
|
|
|
room.addPoint(new SurfaceShadingPoint(id, position, sensorTypes));
|
|
|
|
|
}
|
|
|
|
|
this.shadingData = new SurfaceShadingData();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.shadingData.addChild(shadingGroup);
|
2023-03-13 12:00:31 +08:00
|
|
|
|
this.shadingData.initialize(this.model);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
|
|
|
|
|
if (pageAct.sysSubTag == "L1") {
|
|
|
|
|
await this.dataVizExtn.setupSurfaceShading(this.model, this.shadingData, {
|
|
|
|
|
type: "PlanarHeatmap",
|
|
|
|
|
placementPosition: 0.7,
|
|
|
|
|
confidence: 240.0,
|
|
|
|
|
});
|
|
|
|
|
this.dataVizExtn.registerSurfaceShadingColors(
|
|
|
|
|
"temperature",
|
|
|
|
|
[0x000000, 0xffd524]
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
await this.dataVizExtn.setupSurfaceShading(this.model, this.shadingData);
|
|
|
|
|
this.dataVizExtn.registerSurfaceShadingColors(
|
|
|
|
|
"temperature",
|
|
|
|
|
[0x0000ff, 0x00ff00, 0xffff00, 0xff0000]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
this.dataVizExtn.renderSurfaceShading(
|
|
|
|
|
"iot-heatmap",
|
|
|
|
|
"temperature",
|
|
|
|
|
this.getSensorValue.bind(this)
|
|
|
|
|
);
|
2022-12-29 18:44:09 +08:00
|
|
|
|
|
2023-01-03 16:47:23 +08:00
|
|
|
|
//let nodeIds = await getNodeIdByDbIds(this.checkNodeString);
|
|
|
|
|
//nodeIds = Array.from(nodeIds);
|
|
|
|
|
//nodeIds = nodeIds.map(x => { return { room: x[0] , nodeId: x[1]} });
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// this.roomDbIds = this.devices.filter(x => x.roomDbId != -1).map(x => x.roomDbId).Distinct();
|
|
|
|
|
|
|
|
|
|
// // 建立一個 SurfaceShadingData 物件,並將 SurfaceShadingNode 加入到該物件中
|
|
|
|
|
// const heatmapData = new SurfaceShadingData();
|
|
|
|
|
|
|
|
|
|
// $.each(this.roomDbIds, (idx, rDbid) => {
|
|
|
|
|
// // 建立一個名為 "Room Panel" 的 SurfaceShadingNode 物件,並將房間的模型給傳入,只在該房間呈現溫度
|
|
|
|
|
// const shadingNode = new SurfaceShadingNode("RoomPanel" + rDbid, rDbid);
|
|
|
|
|
|
|
|
|
|
// // 遍歷每個設備,建立一個 SurfaceShadingPoint 物件並加入到 SurfaceShadingNode 中,透過這些設備渲染溫度
|
|
|
|
|
// this.devices.filter(x => x.roomDbId == rDbid).forEach((device) => {
|
|
|
|
|
// const shadingPoint = new SurfaceShadingPoint(
|
|
|
|
|
// device.id,
|
|
|
|
|
// undefined,
|
|
|
|
|
// device.sensorTypes
|
|
|
|
|
// );
|
|
|
|
|
// shadingPoint.positionFromDBId(this.model, device.roomDbId)
|
|
|
|
|
// shadingNode.addPoint(shadingPoint);
|
|
|
|
|
// // device.temp = 0;
|
|
|
|
|
// });
|
2022-12-30 19:03:31 +08:00
|
|
|
|
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// heatmapData.addChild(shadingNode);
|
|
|
|
|
// })
|
2022-12-30 19:03:31 +08:00
|
|
|
|
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// // 將資料初始化並顯示在模型上
|
|
|
|
|
// heatmapData.initialize(this.model);
|
2022-12-29 18:44:09 +08:00
|
|
|
|
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// // 對模型做表面顏色的渲染
|
|
|
|
|
// await this.dataVizExtn.setupSurfaceShading(this.model, heatmapData);
|
2022-12-29 16:03:58 +08:00
|
|
|
|
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// // 對 "temperature" 的溫度設定兩種顏色:紅色和藍色
|
|
|
|
|
// this.dataVizExtn.registerSurfaceShadingColors("temperature", [0x0000ff, 0x00ff00, 0xffff00, 0xff0000]);
|
2022-12-29 18:44:09 +08:00
|
|
|
|
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// $.each(this.roomDbIds, (idx, rDbid) => {
|
|
|
|
|
// this.dataVizExtn.renderSurfaceShading("RoomPanel" + rDbid, "temperature", this.getSensorValue.bind(this));
|
|
|
|
|
// })
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
2023-03-13 12:00:31 +08:00
|
|
|
|
// /*this.changeTemp(this.tempVal);*/
|
2022-12-30 19:03:31 +08:00
|
|
|
|
this.onComplete ? this.onComplete() : "";
|
2022-12-29 18:44:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 15:16:11 +08:00
|
|
|
|
getSensorValue = function (device, sensorType) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let dev = this.devices.filter((x) => x.id == device.id)[0];
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// shadingPoint.positionFromDBId(this.model, device.roomDbId)
|
2022-12-31 18:03:16 +08:00
|
|
|
|
return dev.temp / 40;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
2022-12-29 18:44:09 +08:00
|
|
|
|
// 改變溫度
|
2023-03-13 12:00:31 +08:00
|
|
|
|
changeTemp = async function (devId, temp) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
// console.log("changeTemp",devId, temp)
|
2022-12-30 19:03:31 +08:00
|
|
|
|
this.tempVal = temp;
|
|
|
|
|
// 透過 device id 取得 roomDbId
|
2022-12-31 18:03:16 +08:00
|
|
|
|
this.devices.forEach((dev) => {
|
|
|
|
|
if (devId == dev.id) {
|
|
|
|
|
dev.temp = temp;
|
2022-12-30 19:03:31 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2023-03-13 12:00:31 +08:00
|
|
|
|
|
|
|
|
|
if (!this.shadingData) {
|
|
|
|
|
await this.addHeatMaps();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
this.dataVizExtn.renderSurfaceShading(
|
|
|
|
|
"iot-heatmap",
|
|
|
|
|
"temperature",
|
|
|
|
|
this.getSensorValue.bind(this)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2023-03-13 12:00:31 +08:00
|
|
|
|
this.dataVizExtn.updateSurfaceShading(this.getSensorValue.bind(this));
|
|
|
|
|
}
|
|
|
|
|
// $.each(this.roomDbIds, async (idx, rDbid) => {
|
|
|
|
|
// this.dataVizExtn.renderSurfaceShading("RoomPanel" + rDbid, "temperature", this.getSensorValue.bind(this));
|
|
|
|
|
// })
|
|
|
|
|
|
2022-12-31 18:03:16 +08:00
|
|
|
|
//if (rDbid != null) {
|
|
|
|
|
// // 取得新的溫度值
|
|
|
|
|
// let getSensorValue = (device, sensorType) => {
|
|
|
|
|
// return this.tempVal / 40;
|
|
|
|
|
// }
|
|
|
|
|
// // 對 "Room Panel" 做表面顏色的渲染,並使用新的溫度值
|
|
|
|
|
// this.dataVizExtn.renderSurfaceShading("RoomPanel" + rDbid, "temperature", getSensorValue);
|
|
|
|
|
//}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
};
|
2022-12-30 19:03:31 +08:00
|
|
|
|
}
|
2022-12-29 18:44:09 +08:00
|
|
|
|
|
2023-01-04 15:15:15 +08:00
|
|
|
|
//全部物件 透明度: 輸入0:透明;輸入1:不透明
|
2023-01-05 18:37:12 +08:00
|
|
|
|
function setTransparentBuilding(transparent, filDbids = []) {
|
|
|
|
|
for (var i = 0; i < allDbIdsStr.length; i++) {
|
|
|
|
|
setTransparency(parseInt(allDbIdsStr[i]), transparent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < filDbids.length; i++) {
|
|
|
|
|
setTransparency(parseInt(filDbids[i]), transparent == 0 ? 1 : 0);
|
|
|
|
|
}
|
2022-12-07 18:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//設定模型 透明度
|
|
|
|
|
function setTransparency(nodeId, opacity) {
|
|
|
|
|
var model = viewer.model;
|
|
|
|
|
var fragList = viewer.model.getFragmentList();
|
2023-01-04 15:15:15 +08:00
|
|
|
|
var fragIds = [];
|
2022-12-07 18:59:53 +08:00
|
|
|
|
|
|
|
|
|
model.getData().instanceTree.enumNodeFragments(
|
2023-04-24 11:55:46 +08:00
|
|
|
|
nodeId,
|
|
|
|
|
(fragId) => {
|
2023-01-05 18:37:12 +08:00
|
|
|
|
// 將遍歷到的片段 ID 添加到結果陣列中
|
2023-04-24 11:55:46 +08:00
|
|
|
|
fragIds.push(fragId);
|
|
|
|
|
},
|
|
|
|
|
(nodeId) => {
|
2023-01-05 18:37:12 +08:00
|
|
|
|
// 如果遍歷到的節點是葉節點,则返回 true,表示繼續遍歷該節點的片段
|
|
|
|
|
return model.getData().instanceTree.isLeaf(nodeId);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
2022-12-07 18:59:53 +08:00
|
|
|
|
|
|
|
|
|
fragIds.forEach((fragId) => {
|
|
|
|
|
//获取材质
|
|
|
|
|
var material = fragList.getMaterial(fragId);
|
|
|
|
|
|
|
|
|
|
if (material) {
|
|
|
|
|
//设置透明度
|
2023-04-24 11:55:46 +08:00
|
|
|
|
material.opacity = opacity; //0.5;
|
2022-12-07 18:59:53 +08:00
|
|
|
|
material.transparent = true;
|
|
|
|
|
//标记更新
|
|
|
|
|
material.needsUpdate = true;
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
});
|
2022-12-07 18:59:53 +08:00
|
|
|
|
|
|
|
|
|
//更新viewer
|
|
|
|
|
viewer.impl.invalidate(true, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function changeColor(nodeId, color = [0, 255, 0, 1]) {
|
|
|
|
|
//電梯變綠色
|
2023-01-05 18:37:12 +08:00
|
|
|
|
let model = viewer.model;
|
|
|
|
|
let fragList = viewer.model.getFragmentList();
|
2023-01-16 18:35:01 +08:00
|
|
|
|
let instanceTree = viewer.model?.getData().instanceTree;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
color = color.map((x, i) => (i < 3 ? x / 255 : x));
|
2023-01-05 18:37:12 +08:00
|
|
|
|
color = new THREE.Vector4().fromArray(color);
|
|
|
|
|
model.getData().instanceTree.enumNodeFragments(
|
2023-04-24 11:55:46 +08:00
|
|
|
|
nodeId,
|
|
|
|
|
(fragId) => {
|
2023-01-05 18:37:12 +08:00
|
|
|
|
// 將遍歷到的片段 ID 添加到結果陣列中
|
|
|
|
|
let material = fragList.getMaterial(fragId);
|
|
|
|
|
|
|
|
|
|
if (material) {
|
|
|
|
|
//设置透明度
|
2023-04-24 11:55:46 +08:00
|
|
|
|
material.opacity = 1; //0.5;
|
2023-01-05 18:37:12 +08:00
|
|
|
|
material.transparent = true;
|
|
|
|
|
//标记更新
|
|
|
|
|
material.needsUpdate = true;
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
},
|
|
|
|
|
(nodeId) => {
|
2023-01-05 18:37:12 +08:00
|
|
|
|
// 如果遍歷到的節點是葉節點,则返回 true,表示繼續遍歷該節點的片段
|
|
|
|
|
return model.getData().instanceTree.isLeaf(nodeId);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
instanceTree.enumNodeChildren(
|
|
|
|
|
nodeId,
|
|
|
|
|
function (chiNodeId) {
|
|
|
|
|
viewer.setThemingColor(chiNodeId, color);
|
|
|
|
|
},
|
|
|
|
|
(chiNodeId) => {
|
|
|
|
|
// 如果遍歷到的節點是葉節點,则返回 true,表示繼續遍歷該節點的片段
|
|
|
|
|
return model.getData().instanceTree.isLeaf(chiNodeId);
|
|
|
|
|
}
|
|
|
|
|
);
|
2022-12-07 18:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function hideColor(nodeId) {
|
|
|
|
|
//顏色改成透明
|
2023-01-16 18:35:01 +08:00
|
|
|
|
let instanceTree = viewer.model?.getData().instanceTree;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
instanceTree.enumNodeChildren(
|
|
|
|
|
nodeId,
|
|
|
|
|
function (chiNodeId) {
|
|
|
|
|
var color = new THREE.Vector4(0, 1, 0, 0);
|
|
|
|
|
viewer.setThemingColor(chiNodeId, color);
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
);
|
2022-12-26 18:20:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 16:32:28 +08:00
|
|
|
|
//紀錄燈具座標
|
|
|
|
|
async function getLightData(data) {
|
2023-01-10 18:39:07 +08:00
|
|
|
|
lightList = [];
|
2023-01-09 16:32:28 +08:00
|
|
|
|
lightDataList = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function testNewLight(dataList) {
|
|
|
|
|
dataList.forEach((myData, index) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const position = myData.position;
|
|
|
|
|
if (lightList.findIndex((x) => x.device_guid == myData.device_guid) == -1) {
|
|
|
|
|
lightList.push({
|
|
|
|
|
dbid: myData.forge_dbid,
|
|
|
|
|
device_guid: myData.device_guid,
|
|
|
|
|
lightObject: new THREE.SpotLight(0xe1cf18, 10, 200, 1, 1, 2),
|
|
|
|
|
});
|
|
|
|
|
} else if (
|
|
|
|
|
lightList.findIndex((x) => x.device_guid == myData.device_node_guid) == -1
|
|
|
|
|
) {
|
|
|
|
|
lightList.push({
|
|
|
|
|
dbid: myData.forge_dbid,
|
|
|
|
|
device_guid: myData.device_node_guid,
|
|
|
|
|
lightObject: new THREE.SpotLight(0xe1cf18, 10, 200, 1, 1, 2),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (position && position.x && position.y && position.z) {
|
|
|
|
|
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 - 100
|
|
|
|
|
);
|
|
|
|
|
viewer.scene.add(lightList[index].lightObject.target);
|
|
|
|
|
viewer.scene.add(lightList[index].lightObject);
|
2023-01-10 18:39:07 +08:00
|
|
|
|
}
|
2023-01-11 18:37:58 +08:00
|
|
|
|
|
|
|
|
|
//let spotLightHelper = new THREE.SpotLightHelper(lightList[index].lightObject);
|
|
|
|
|
//viewer.scene.add(spotLightHelper);
|
2023-01-09 16:32:28 +08:00
|
|
|
|
});
|
2023-01-11 18:37:58 +08:00
|
|
|
|
viewer.impl.sceneUpdated(true);
|
2023-01-04 17:31:34 +08:00
|
|
|
|
}
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
2022-12-26 18:20:32 +08:00
|
|
|
|
//------------------- 加入熱點 -----------------
|
|
|
|
|
async function addHotPoint(data) {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
var viewer = data.target ? data.target : data;
|
2022-12-26 18:20:32 +08:00
|
|
|
|
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
|
|
|
|
|
const DataVizCore = Autodesk.DataVisualization.Core;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const viewableType = Autodesk.DataVisualization.Core.ViewableType.SPRITE; //DataVizCore.ViewableType.SPRITE;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
let spriteColor = null;
|
|
|
|
|
let spriteIcon = "";
|
2022-12-29 16:03:58 +08:00
|
|
|
|
const dbIdStart = 10;
|
|
|
|
|
const dbIdEnd = 19;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (pageAct.sysSubTag === "M12") {
|
|
|
|
|
return;
|
2023-02-14 15:16:11 +08:00
|
|
|
|
} else {
|
|
|
|
|
spriteColor = new THREE.Color(0xffffff);
|
2023-05-30 16:01:26 +08:00
|
|
|
|
spriteIcon = "/file/img/forge/sensor_circle.svg";
|
2023-02-14 15:16:11 +08:00
|
|
|
|
if (location.href.indexOf("localhost:5966") != -1) {
|
2023-05-30 16:01:26 +08:00
|
|
|
|
spriteIcon = "/img/forge/sensor_circle.svg";
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
2022-12-28 18:47:09 +08:00
|
|
|
|
}
|
2022-12-26 18:20:32 +08:00
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const style = new DataVizCore.ViewableStyle(
|
|
|
|
|
viewableType,
|
|
|
|
|
spriteColor,
|
|
|
|
|
spriteIcon
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
lightDataList != undefined &&
|
|
|
|
|
lightDataList != null &&
|
|
|
|
|
lightDataList.length > 0
|
|
|
|
|
) {
|
2023-01-09 16:32:28 +08:00
|
|
|
|
testNewLight(lightDataList);
|
|
|
|
|
}
|
2023-02-14 15:16:11 +08:00
|
|
|
|
|
2022-12-26 18:20:32 +08:00
|
|
|
|
//熱點 點擊事件註冊
|
2023-04-24 11:55:46 +08:00
|
|
|
|
viewer.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClicked); // SPRITE_SELECTED
|
2023-02-18 21:00:48 +08:00
|
|
|
|
// viewer.addEventListener(DataVizCore.MOUSE_CLICK, onSpriteClickedOut);
|
2022-12-28 18:47:09 +08:00
|
|
|
|
//viewer.addEventListener(
|
|
|
|
|
// Autodesk.Viewing.SELECTION_CHANGED_EVENT,
|
|
|
|
|
// onSelectionChange
|
|
|
|
|
//);
|
2022-12-26 18:20:32 +08:00
|
|
|
|
|
|
|
|
|
const viewableData = new DataVizCore.ViewableData();
|
|
|
|
|
viewableData.spriteSize = 24; // Sprites as points of size 24 x 24 pixels
|
|
|
|
|
myDataList.forEach((myData, index) => {
|
|
|
|
|
const dbId = 10 + index;
|
2023-01-04 17:31:34 +08:00
|
|
|
|
const myPosition = myData.position;
|
2022-12-26 18:20:32 +08:00
|
|
|
|
const viewable = new DataVizCore.SpriteViewable(myPosition, style, dbId);
|
2022-12-28 13:12:08 +08:00
|
|
|
|
myData._dbId = dbId;
|
2022-12-26 18:20:32 +08:00
|
|
|
|
viewableData.addViewable(viewable);
|
|
|
|
|
});
|
|
|
|
|
await viewableData.finish();
|
|
|
|
|
dataVizExtn.addViewables(viewableData);
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// console.log(dataVizExtn)
|
2022-12-28 18:47:09 +08:00
|
|
|
|
$(selector).trigger("autodesk:complete:sprite", { myDataList });
|
2022-12-26 18:20:32 +08:00
|
|
|
|
|
|
|
|
|
//---------------- 熱點點擊事件 --------------------
|
|
|
|
|
function onSpriteClicked(event) {
|
2022-12-29 16:03:58 +08:00
|
|
|
|
event.hasStopped = true;
|
2022-12-26 18:20:32 +08:00
|
|
|
|
if (event != undefined && event != null) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (event.dbId >= dbIdStart) {
|
|
|
|
|
//event.dbId > 0 && event.dbId < 19
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// console.log(`Sprite clicked: ${event.dbId}`);
|
|
|
|
|
|
2023-01-05 18:37:12 +08:00
|
|
|
|
for (let i = dbIdStart; i <= myDataList.length + 10; i++) {
|
2023-05-30 16:01:26 +08:00
|
|
|
|
!alarmDbIdList.some(({ spriteDbid }) => spriteDbid == i) &&
|
2023-04-24 11:55:46 +08:00
|
|
|
|
pageAct.sysSubTag !== "L1" &&
|
|
|
|
|
changeColorForHotspot(i);
|
2023-02-18 21:00:48 +08:00
|
|
|
|
changeScaleForHotspot(i, true);
|
2022-12-29 16:03:58 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let myData = myDataList.filter((x) => x._dbId == event.dbId)[0];
|
|
|
|
|
if (
|
|
|
|
|
lightList != undefined &&
|
|
|
|
|
lightList != null &&
|
|
|
|
|
lightList.length > 0
|
|
|
|
|
) {
|
2023-01-09 16:32:28 +08:00
|
|
|
|
//setLightOpenOrClose(false, myData.device_guid);//關燈測試
|
|
|
|
|
//setLightValues(myData.device_guid, 20, 0x00ff00);//更改燈光顏色和強度的測試
|
2023-04-24 11:55:46 +08:00
|
|
|
|
moveViewToDevice(myData.forge_dbid); //移動視角至該設備
|
2023-01-09 16:32:28 +08:00
|
|
|
|
}
|
2022-12-28 18:47:09 +08:00
|
|
|
|
$(selector).trigger("autodesk:click:sprite", { event, myData });
|
2022-12-29 16:03:58 +08:00
|
|
|
|
} else {
|
2023-05-30 16:01:26 +08:00
|
|
|
|
!alarmDbIdList.some(({ spriteDbid }) => spriteDbid == event.dbId) &&
|
2023-04-24 11:55:46 +08:00
|
|
|
|
pageAct.sysSubTag !== "L1" &&
|
|
|
|
|
changeColorForHotspot(event.dbId, null);
|
2023-02-18 21:00:48 +08:00
|
|
|
|
changeScaleForHotspot(event.dbId, false);
|
2022-12-29 16:03:58 +08:00
|
|
|
|
$(selector).trigger("autodesk:clickOut:sprite", { event });
|
2022-12-26 18:20:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.clickInfo != null) {
|
|
|
|
|
//document.getElementById('deviceName').innerHTML = viewer.model.getInstanceTree().getNodeName(event.clickInfo.dbId);
|
|
|
|
|
//document.getElementById('deviceDbid').innerHTML = event.clickInfo.dbId;
|
|
|
|
|
//document.getElementById('devicePosition').innerHTML = "(" + (event.clickInfo.point.x).toFixed(2) + ", " + (event.clickInfo.point.y).toFixed(2) + ", " + (event.clickInfo.point.z).toFixed(2) + ")";
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// console.log(`event>> dbId: ${event.clickInfo.dbId}, id: ${event.clickInfo.object.id}, position.x: ${event.clickInfo.point.x}, y: ${event.clickInfo.point.y}, z: ${event.clickInfo.point.z}, name: ${viewer.model.getInstanceTree().getNodeName(event.clickInfo.dbId)}`);
|
2022-12-26 18:20:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 21:00:48 +08:00
|
|
|
|
// function onSpriteClickedOut(event){
|
|
|
|
|
// event.hasStopped = true;
|
|
|
|
|
// if (event != undefined && event != null) {
|
|
|
|
|
// if (event.dbId >= dbIdStart) {
|
|
|
|
|
// for (let i = dbIdStart; i <= myDataList.length + 10; i++) {
|
|
|
|
|
// changeColorForHotspot(event.dbId);
|
|
|
|
|
// changeScaleForHotspot(event.dbId, false);
|
|
|
|
|
// }
|
|
|
|
|
// let myData = myDataList.filter(x => x._dbId == event.dbId)[0];
|
|
|
|
|
// debugger
|
|
|
|
|
// $(selector).trigger("autodesk:clickOut:sprite", { event });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2022-12-28 18:47:09 +08:00
|
|
|
|
//function onSelectionChange(event) {
|
|
|
|
|
// if (event != undefined && event != null) {
|
|
|
|
|
// const dbIds = event.dbIdArray;
|
|
|
|
|
|
|
|
|
|
// if (dbIds.length > 0) {
|
|
|
|
|
// // 處理已選取元件的邏輯
|
|
|
|
|
// $(selector).trigger("autodesk:click:sprite", event);
|
|
|
|
|
// 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 {
|
|
|
|
|
// // 處理沒有選取元件的邏輯
|
|
|
|
|
// $(selector).trigger("autodesk:click:sprite", event);
|
|
|
|
|
// console.log("no item");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
}
|
2022-12-26 18:20:32 +08:00
|
|
|
|
|
2023-05-30 16:01:26 +08:00
|
|
|
|
//hex -> rgbsensor_circle
|
|
|
|
|
function hexToRgb(hex) {
|
|
|
|
|
return (
|
|
|
|
|
"rgb(" +
|
|
|
|
|
parseInt("0x" + hex.slice(1, 3)) +
|
|
|
|
|
"," +
|
|
|
|
|
parseInt("0x" + hex.slice(3, 5)) +
|
|
|
|
|
"," +
|
|
|
|
|
parseInt("0x" + hex.slice(5, 7)) +
|
|
|
|
|
")"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-28 18:47:09 +08:00
|
|
|
|
// 熱點 更換顏色
|
2023-05-30 16:01:26 +08:00
|
|
|
|
async function changeColorForHotspot(dbId, type = null, OnOff = false) {
|
2022-12-28 18:47:09 +08:00
|
|
|
|
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
|
2023-02-22 10:33:35 +08:00
|
|
|
|
let spriteColorFocus = new THREE.Color(0xffffff);
|
2023-05-30 16:01:26 +08:00
|
|
|
|
|
|
|
|
|
spriteColorFocus = OnOff
|
|
|
|
|
? pageAct.sysSubObj.device_normal_color
|
|
|
|
|
? new THREE.Color(hexToRgb(pageAct.sysSubObj.device_normal_color))
|
|
|
|
|
: new THREE.Color(0xffffff)
|
|
|
|
|
: pageAct.sysSubObj.device_close_color
|
|
|
|
|
? new THREE.Color(hexToRgb(pageAct.sysSubObj.device_close_color))
|
|
|
|
|
: new THREE.Color(0xffffff);
|
|
|
|
|
|
|
|
|
|
if (type == "focus") {
|
2023-01-05 18:37:12 +08:00
|
|
|
|
spriteColorFocus = new THREE.Color(0x00ffe1);
|
|
|
|
|
} else if (type == "error") {
|
2023-05-30 16:01:26 +08:00
|
|
|
|
spriteColorFocus = new THREE.Color(
|
|
|
|
|
hexToRgb(pageAct.sysSubObj.device_error_color)
|
|
|
|
|
);
|
|
|
|
|
spriteErrIcon = baseForgeApiUrl + "/file/img/forge/sensor_circle.svg";
|
|
|
|
|
if (location.href.indexOf("localhost:5966") != -1) {
|
|
|
|
|
spriteErrIcon = baseForgeApiUrl + "/img/forge/sensor_circle.svg";
|
|
|
|
|
}
|
2023-02-14 15:16:11 +08:00
|
|
|
|
}
|
2022-12-28 18:47:09 +08:00
|
|
|
|
const viewablesToUpdate = dbId;
|
|
|
|
|
dataVizExtn.invalidateViewables(viewablesToUpdate, (viewable) => {
|
|
|
|
|
return {
|
2023-05-30 16:01:26 +08:00
|
|
|
|
url: "/file/img/forge/sensor_circle.svg",
|
2022-12-28 18:47:09 +08:00
|
|
|
|
color: spriteColorFocus,
|
|
|
|
|
};
|
|
|
|
|
});
|
2022-12-26 18:20:32 +08:00
|
|
|
|
}
|
2022-12-28 18:47:09 +08:00
|
|
|
|
|
2022-12-29 16:03:58 +08:00
|
|
|
|
// 熱點 更換大小
|
2022-12-30 19:03:31 +08:00
|
|
|
|
async function changeScaleForHotspot(dbId, type = true) {
|
2022-12-29 16:03:58 +08:00
|
|
|
|
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
|
|
|
|
|
let scale = 1;
|
2022-12-30 19:03:31 +08:00
|
|
|
|
if (type) {
|
2022-12-29 16:03:58 +08:00
|
|
|
|
scale = 1.2;
|
|
|
|
|
}
|
|
|
|
|
const viewablesToUpdate = dbId;
|
|
|
|
|
dataVizExtn.invalidateViewables(viewablesToUpdate, (viewable) => {
|
|
|
|
|
return {
|
|
|
|
|
scale: scale, // Restore the viewable size
|
|
|
|
|
//url: "https://.../circle.svg",
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-12-28 18:47:09 +08:00
|
|
|
|
|
2022-12-31 18:03:16 +08:00
|
|
|
|
//------------------- end --------------
|
|
|
|
|
|
2023-01-04 17:31:34 +08:00
|
|
|
|
//------------------ 熱圖 -------------------------------
|
|
|
|
|
async function loadHeatmaps(model) {
|
2023-03-13 12:00:31 +08:00
|
|
|
|
//console.log("熱圖 loadHeat")
|
2022-12-29 18:19:22 +08:00
|
|
|
|
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
|
|
|
|
|
|
2023-01-04 17:31:34 +08:00
|
|
|
|
//取三個空調設備的位置打點
|
|
|
|
|
const devices = [
|
|
|
|
|
{
|
|
|
|
|
id: "Oficina 5",
|
|
|
|
|
//name: "Oficina-",
|
2023-04-24 11:55:46 +08:00
|
|
|
|
position: { x: 6.98, y: -19.0, z: 16.86 }, // x: 0, y: 25, z: -2.5 (-4.93, -20.61, 16.86)
|
|
|
|
|
sensorTypes: ["temperature", "humidity"],
|
2023-01-04 17:31:34 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Oficina 4",
|
|
|
|
|
//name: "Oficina-",
|
|
|
|
|
position: { x: 35.85, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (23.94, -3.85, 16.86)
|
2023-04-24 11:55:46 +08:00
|
|
|
|
sensorTypes: ["temperature", "humidity"],
|
2023-01-04 17:31:34 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Oficina 3",
|
|
|
|
|
//name: "Oficina-",
|
|
|
|
|
position: { x: 6.98, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (-4.93, -3.85, 16.86)
|
2023-04-24 11:55:46 +08:00
|
|
|
|
sensorTypes: ["temperature", "humidity"],
|
|
|
|
|
},
|
2023-01-04 17:31:34 +08:00
|
|
|
|
];
|
|
|
|
|
//冷氣N5: (-4.93, -20.61, 16.86), N4: (23.94, -3.85, 16.86), N3: (-4.93, -3.85, 16.86)
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
|
|
|
|
// Initialize sensor values
|
|
|
|
|
let sensorVals = [];
|
|
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
|
sensorVals[i] = Math.random();
|
2022-12-31 15:24:02 +08:00
|
|
|
|
}
|
2022-12-29 18:19:22 +08:00
|
|
|
|
|
2022-12-31 18:03:16 +08:00
|
|
|
|
const roomDbIds = [];
|
2023-01-04 17:31:34 +08:00
|
|
|
|
roomDbIds.push(7567);
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const { SurfaceShadingData, SurfaceShadingPoint, SurfaceShadingNode } =
|
|
|
|
|
Autodesk.DataVisualization.Core;
|
2023-01-04 17:31:34 +08:00
|
|
|
|
|
|
|
|
|
const shadingNode = new SurfaceShadingNode("Room Panel", roomDbIds);
|
|
|
|
|
|
|
|
|
|
devices.forEach((device) => {
|
|
|
|
|
const shadingPoint = new SurfaceShadingPoint(
|
|
|
|
|
device.id,
|
|
|
|
|
device.position,
|
|
|
|
|
device.sensorTypes
|
|
|
|
|
);
|
|
|
|
|
shadingNode.addPoint(shadingPoint);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const heatmapData = new SurfaceShadingData();
|
|
|
|
|
heatmapData.addChild(shadingNode);
|
|
|
|
|
heatmapData.initialize(model);
|
|
|
|
|
|
|
|
|
|
// Setup surface shading
|
|
|
|
|
await dataVizExtn.setupSurfaceShading(model, heatmapData);
|
2023-01-10 18:39:07 +08:00
|
|
|
|
|
|
|
|
|
dataVizExtn.registerSurfaceShadingColors("temperature", [0xff0000, 0x0000ff]);
|
2023-01-04 17:31:34 +08:00
|
|
|
|
|
|
|
|
|
function getSensorValue(device, sensorType) {
|
|
|
|
|
return sensorVals[parseInt(device.id.slice(-1)) - 1];
|
2023-01-04 01:18:46 +08:00
|
|
|
|
}
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
2023-01-04 17:31:34 +08:00
|
|
|
|
dataVizExtn.renderSurfaceShading("Room Panel", "temperature", getSensorValue);
|
|
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
// Modify sensor values.
|
|
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
|
sensorVals[i] = Math.random();
|
|
|
|
|
}
|
|
|
|
|
dataVizExtn.updateSurfaceShading(getSensorValue);
|
|
|
|
|
}, 2000);
|
|
|
|
|
}
|
|
|
|
|
//------------------ end --------------------------------
|
|
|
|
|
async function loadHeatmapsForFloor(model) {
|
|
|
|
|
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
|
|
|
|
|
|
|
|
|
|
//x: -17.33, y: 51.03, z: -2.52
|
|
|
|
|
const devices = [
|
|
|
|
|
{
|
|
|
|
|
id: "Oficina 5",
|
|
|
|
|
//name: "Oficina-",
|
2023-04-24 11:55:46 +08:00
|
|
|
|
position: { x: 6.98, y: -19.0, z: 16.86 }, // x: 0, y: 25, z: -2.5 (-4.93, -20.61, 16.86)
|
|
|
|
|
sensorTypes: ["temperature", "humidity"],
|
2023-01-04 17:31:34 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Oficina 4",
|
|
|
|
|
//name: "Oficina-",
|
|
|
|
|
position: { x: 35.85, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (23.94, -3.85, 16.86)
|
2023-04-24 11:55:46 +08:00
|
|
|
|
sensorTypes: ["temperature", "humidity"],
|
2023-01-04 17:31:34 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Oficina 3",
|
|
|
|
|
//name: "Oficina-",
|
|
|
|
|
position: { x: 6.98, y: -2.24, z: 16.86 }, // x: 0, y: 25.03, z: -2.52 (-4.93, -3.85, 16.86)
|
2023-04-24 11:55:46 +08:00
|
|
|
|
sensorTypes: ["temperature", "humidity"],
|
|
|
|
|
},
|
2023-01-04 17:31:34 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Initialize sensor values
|
|
|
|
|
let sensorVals = [];
|
|
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
|
sensorVals[i] = Math.random();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const roomDbIds = [];
|
|
|
|
|
|
|
|
|
|
roomDbIds.push(7567);
|
|
|
|
|
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const { SurfaceShadingData, SurfaceShadingPoint, SurfaceShadingNode } =
|
|
|
|
|
Autodesk.DataVisualization.Core;
|
2022-12-29 18:19:22 +08:00
|
|
|
|
|
|
|
|
|
const shadingNode = new SurfaceShadingNode("Room Panel", roomDbIds);
|
|
|
|
|
|
|
|
|
|
devices.forEach((device) => {
|
|
|
|
|
const shadingPoint = new SurfaceShadingPoint(
|
|
|
|
|
device.id,
|
|
|
|
|
device.position,
|
|
|
|
|
device.sensorTypes
|
|
|
|
|
);
|
|
|
|
|
shadingNode.addPoint(shadingPoint);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const heatmapData = new SurfaceShadingData();
|
|
|
|
|
heatmapData.addChild(shadingNode);
|
|
|
|
|
heatmapData.initialize(model);
|
|
|
|
|
|
|
|
|
|
// Setup surface shading
|
|
|
|
|
await dataVizExtn.setupSurfaceShading(model, heatmapData);
|
2023-01-04 17:31:34 +08:00
|
|
|
|
|
|
|
|
|
//dataVizExtn.registerSurfaceShadingColors("co2", [0x00ff00, 0xff0000]);
|
2022-12-29 18:19:22 +08:00
|
|
|
|
dataVizExtn.registerSurfaceShadingColors("temperature", [0xff0000, 0x0000ff]);
|
|
|
|
|
|
|
|
|
|
function getSensorValue(device, sensorType) {
|
2023-01-04 17:31:34 +08:00
|
|
|
|
return sensorVals[parseInt(device.id.slice(-1)) - 1];
|
2022-12-29 18:19:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dataVizExtn.renderSurfaceShading("Room Panel", "temperature", getSensorValue);
|
|
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
// Modify sensor values.
|
|
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
|
sensorVals[i] = Math.random();
|
|
|
|
|
}
|
|
|
|
|
dataVizExtn.updateSurfaceShading(getSensorValue);
|
|
|
|
|
}, 2000);
|
|
|
|
|
}
|
2023-01-04 17:31:34 +08:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
async function loadHeatmap() {
|
|
|
|
|
const model = viewer.model;
|
|
|
|
|
loadHeatmaps(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadHeatmapForFloor() {
|
|
|
|
|
const model = viewer.model;
|
|
|
|
|
loadHeatmapsForFloor(model);
|
|
|
|
|
}
|
2022-12-31 18:03:16 +08:00
|
|
|
|
|
|
|
|
|
//------------ 剖面 ----------------------
|
2023-03-13 12:00:31 +08:00
|
|
|
|
|
|
|
|
|
function findLevels(model) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
model.search(
|
|
|
|
|
"layer",
|
|
|
|
|
(nodeIds) => {
|
|
|
|
|
let levels = [];
|
|
|
|
|
const tree = viewer.model.getInstanceTree();
|
|
|
|
|
for (let i = 0; i < nodeIds.length; i++) {
|
|
|
|
|
const dbId = nodeIds[i];
|
|
|
|
|
const name = tree.getNodeName(dbId);
|
|
|
|
|
if (!name || name.includes("<沒有層級>")) continue;
|
|
|
|
|
levels.push({
|
|
|
|
|
guid: dbId,
|
|
|
|
|
name,
|
|
|
|
|
dbId,
|
|
|
|
|
extension: {
|
|
|
|
|
buildingStory: true,
|
|
|
|
|
structure: false,
|
|
|
|
|
computationHeight: 0,
|
|
|
|
|
groundPlane: false,
|
|
|
|
|
hasAssociatedViewPlans: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
resolve(levels);
|
|
|
|
|
},
|
|
|
|
|
(e) => {
|
|
|
|
|
reject(e);
|
2023-03-13 12:00:31 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
);
|
2023-03-13 12:00:31 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-29 18:19:22 +08:00
|
|
|
|
async function getRemoteLevels() {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let aecData = await Autodesk.Viewing.Document.getAecModelData(
|
|
|
|
|
this.viewer.model.getDocumentNode()
|
|
|
|
|
);
|
2023-03-13 12:00:31 +08:00
|
|
|
|
|
|
|
|
|
let levels;
|
|
|
|
|
if (!aecData || !aecData.levels) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const levelExt = await viewer.loadExtension("Autodesk.AEC.LevelsExtension");
|
2023-03-13 12:00:31 +08:00
|
|
|
|
levelExt.setAecModelData(undefined, viewer.model); //!<<< Clear before reset
|
2023-04-24 11:55:46 +08:00
|
|
|
|
levels = await findLevels(viewer.model);
|
2023-03-13 12:00:31 +08:00
|
|
|
|
aecdata = Autodesk.AEC.AecModelData.computeLevels(levels, viewer.model); //!<<< Rebuild aec model data
|
|
|
|
|
} else {
|
|
|
|
|
levels = aecData.levels;
|
|
|
|
|
}
|
|
|
|
|
levels.sort((a, b) => b.elevation - a.elevation);
|
|
|
|
|
return levels;
|
2022-12-29 18:19:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 18:49:37 +08:00
|
|
|
|
async function getLevelsData(lowerFloor, upperFloor, callback = null) {
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// 樓層正規化 取得樓層
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const floorRegex = /[\d|\w]+F/gim;
|
|
|
|
|
const floorRegex2 = /^FL[\d|\w]+/gim;
|
2022-12-31 18:03:16 +08:00
|
|
|
|
const data = await this.getRemoteLevels();
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let name =
|
|
|
|
|
data[i].name?.match(floorRegex) || data[i].name?.match(floorRegex2);
|
|
|
|
|
if (
|
|
|
|
|
name &&
|
|
|
|
|
(name[0] == lowerFloor || name[0].split("L")[1] + "F" == lowerFloor)
|
|
|
|
|
) {
|
2022-12-31 18:03:16 +08:00
|
|
|
|
lowerIdx = i;
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (
|
|
|
|
|
name &&
|
|
|
|
|
(name[0] == upperFloor || name[0].split("L")[1] + "F" == upperFloor)
|
|
|
|
|
) {
|
2023-03-13 12:00:31 +08:00
|
|
|
|
if (i > upperIdx && lowerFloor == upperFloor) {
|
|
|
|
|
} else {
|
|
|
|
|
upperIdx = i;
|
|
|
|
|
}
|
2022-12-31 18:03:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-13 12:00:31 +08:00
|
|
|
|
|
2022-12-31 18:03:16 +08:00
|
|
|
|
this.levels = data;
|
2023-01-04 18:49:37 +08:00
|
|
|
|
profile(callback);
|
2022-12-31 18:03:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-29 18:19:22 +08:00
|
|
|
|
function getCutPlaneParam(idx, n) {
|
|
|
|
|
if (idx < 0 || !n) return;
|
|
|
|
|
|
|
|
|
|
const level = this.levels[idx];
|
|
|
|
|
if (!level) return;
|
|
|
|
|
|
|
|
|
|
const model = this.viewer.model;
|
|
|
|
|
const globalOffset = model.getData().globalOffset;
|
|
|
|
|
const units = model.getUnitString();
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const elevRaw = Autodesk.Viewing.Private.convertUnits(
|
|
|
|
|
"ft",
|
|
|
|
|
units,
|
|
|
|
|
1,
|
|
|
|
|
level.elevation
|
|
|
|
|
);
|
2022-12-29 18:19:22 +08:00
|
|
|
|
let d = elevRaw - globalOffset.z - 0.5;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
if (n == 1) d = -1 * d;
|
2022-12-29 18:19:22 +08:00
|
|
|
|
|
|
|
|
|
return new THREE.Vector4(0, 0, n, d);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 18:49:37 +08:00
|
|
|
|
function profile(callback = null) {
|
2022-12-31 18:03:16 +08:00
|
|
|
|
//const upperIdx = 6;
|
2022-12-29 18:19:22 +08:00
|
|
|
|
const upperCutPlaneParam = this.getCutPlaneParam(upperIdx, 1);
|
2022-12-31 18:03:16 +08:00
|
|
|
|
//const lowerIdx = 7;
|
2022-12-29 18:19:22 +08:00
|
|
|
|
const lowerCutPlaneParam = this.getCutPlaneParam(lowerIdx, -1);
|
|
|
|
|
this.viewer.setCutPlanes([upperCutPlaneParam, lowerCutPlaneParam]);
|
2023-01-04 18:49:37 +08:00
|
|
|
|
callback ? callback() : "";
|
2022-12-29 18:19:22 +08:00
|
|
|
|
}
|
2023-01-04 01:18:46 +08:00
|
|
|
|
//----------------- end -----------------------------------------------
|
|
|
|
|
//新增燈光
|
|
|
|
|
async function newLight(lightPosition) {
|
|
|
|
|
//聚光燈
|
2023-02-22 10:33:35 +08:00
|
|
|
|
var spotLight = new THREE.SpotLight(0xe1cf18, 0, 20, 0.6, 0.5, 10);
|
2023-01-04 01:18:46 +08:00
|
|
|
|
spotLight.position.set(lightPosition.x, lightPosition.y, lightPosition.z);
|
2023-02-14 15:16:11 +08:00
|
|
|
|
// console.log(lightPosition.x, lightPosition.y, lightPosition.z)
|
2023-01-04 01:18:46 +08:00
|
|
|
|
spotLight.castShadow = false;
|
|
|
|
|
spotLight.visible = true;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
spotLight.target.position.set(
|
|
|
|
|
lightPosition.x,
|
|
|
|
|
lightPosition.y,
|
|
|
|
|
lightPosition.z - 20
|
|
|
|
|
);
|
2023-01-04 01:18:46 +08:00
|
|
|
|
viewer.scene.add(spotLight.target);
|
|
|
|
|
viewer.scene.add(spotLight);
|
|
|
|
|
viewer.impl.sceneUpdated(true);
|
|
|
|
|
|
|
|
|
|
return spotLight;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 15:15:15 +08:00
|
|
|
|
//調整燈光 強度、顏色
|
2023-01-09 16:32:28 +08:00
|
|
|
|
async function setLightValues(deviceGuid, intensity, color) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const light = lightList.find(({ device_guid }) => device_guid === deviceGuid);
|
|
|
|
|
if (light) {
|
|
|
|
|
console.log(light, intensity, color);
|
|
|
|
|
light.lightObject.intensity = intensity;
|
|
|
|
|
var tempcolor = new THREE.Color().setHex(color);
|
|
|
|
|
light.lightObject.color = tempcolor;
|
2023-01-04 01:18:46 +08:00
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
// 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].lightObject.color = tempcolor;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2023-01-09 16:32:28 +08:00
|
|
|
|
viewer.impl.sceneUpdated(true);
|
2023-01-04 01:18:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 15:15:15 +08:00
|
|
|
|
//燈光開關
|
2023-01-09 16:32:28 +08:00
|
|
|
|
async function setLightOpenOrClose(value, deviceGuid) {
|
|
|
|
|
for (var i = 0; i < lightList.length; i++) {
|
|
|
|
|
if (lightList[i].device_guid == deviceGuid) {
|
|
|
|
|
lightList[i].lightObject.visible = value;
|
|
|
|
|
}
|
2023-01-04 15:15:15 +08:00
|
|
|
|
}
|
|
|
|
|
viewer.impl.sceneUpdated(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//透過nodeId,更改物件顏色或顯示與否;color請填寫THREE.Vector4
|
2023-04-24 11:55:46 +08:00
|
|
|
|
function changeColorTransparency(nodeId, color) {
|
|
|
|
|
//變綠色
|
2023-01-04 15:15:15 +08:00
|
|
|
|
//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);
|
|
|
|
|
}
|
2023-01-04 01:18:46 +08:00
|
|
|
|
|
2023-01-05 18:37:12 +08:00
|
|
|
|
//隱藏全物件
|
2023-01-04 18:49:37 +08:00
|
|
|
|
function hideAllObjects(filDbids = []) {
|
2023-01-04 17:23:30 +08:00
|
|
|
|
//viewer.hide(4);//只針對一個物件(dbid為4)做隱藏
|
|
|
|
|
for (var i = 0; i < allDbIdsStr.length; i++) {
|
|
|
|
|
viewer.hide(parseInt(allDbIdsStr[i]));
|
|
|
|
|
}
|
2023-01-04 18:49:37 +08:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < filDbids.length; i++) {
|
|
|
|
|
viewer.show(parseInt(filDbids[i]), viewer.model);
|
|
|
|
|
}
|
2023-01-04 17:23:30 +08:00
|
|
|
|
}
|
|
|
|
|
//顯示全物件
|
|
|
|
|
function showAllObjects() {
|
|
|
|
|
//viewer.show(4); //只針對一個物件(dbid為4)做顯示
|
|
|
|
|
for (var i = 0; i < allDbIdsStr.length; i++) {
|
|
|
|
|
viewer.show(parseInt(allDbIdsStr[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 19:15:27 +08:00
|
|
|
|
function showHeat(selector) {
|
|
|
|
|
const labels = [
|
|
|
|
|
`${(10).toFixed(2)}${"°C"}`,
|
|
|
|
|
`${(40 / 2).toFixed(2)}${"°C"}`,
|
2023-04-24 11:55:46 +08:00
|
|
|
|
`${(30).toFixed(2)}${"°C"}`,
|
2023-01-09 19:15:27 +08:00
|
|
|
|
];
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const colorStops = ["blue", "green", "yellow", "red"];
|
2023-01-09 19:15:27 +08:00
|
|
|
|
createHeatmapRect(labels, colorStops, selector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createHeatmapRect(labels, colorStops, selector) {
|
|
|
|
|
if (!$(selector)[0]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
const context = $(selector)[0].getContext("2d");
|
2023-01-09 19:15:27 +08:00
|
|
|
|
let i, len;
|
2023-01-10 18:39:07 +08:00
|
|
|
|
context.clearRect(0, 0, 200, 50);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
context.fillStyle = "back"; //white
|
2023-01-09 19:15:27 +08:00
|
|
|
|
for (i = 0, len = labels.length; i < len; i++) {
|
2023-04-24 11:55:46 +08:00
|
|
|
|
let x = 10 + (180 * i) / (len - 1);
|
2023-01-09 19:15:27 +08:00
|
|
|
|
if (i === len - 1) {
|
|
|
|
|
x -= context.measureText(labels[i]).width;
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else if (i > 0) {
|
2023-01-09 19:15:27 +08:00
|
|
|
|
x -= 0.5 * context.measureText(labels[i]).width;
|
|
|
|
|
}
|
|
|
|
|
context.fillText(labels[i], x, 10);
|
|
|
|
|
}
|
2023-01-10 18:39:07 +08:00
|
|
|
|
const gradient = context.createLinearGradient(0, 0, 200, 0);
|
2023-01-09 19:15:27 +08:00
|
|
|
|
for (i = 0, len = colorStops.length; i < len; i++) {
|
|
|
|
|
gradient.addColorStop(i / (len - 1), colorStops[i]);
|
|
|
|
|
}
|
|
|
|
|
context.fillStyle = gradient;
|
2023-01-10 18:39:07 +08:00
|
|
|
|
context.fillRect(10, 20, 200, 25);
|
2023-01-09 19:15:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 01:18:46 +08:00
|
|
|
|
//======================== 外部呼叫function ===========================
|
|
|
|
|
//紀錄熱點座標
|
|
|
|
|
function getHopspotPoint(data) {
|
|
|
|
|
myDataList = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//呼叫載入熱圖
|
|
|
|
|
async function toLoadHeatmap(roomArr) {
|
|
|
|
|
const model = viewer.model;
|
|
|
|
|
loadHeatmaps(model, roomArr);
|
|
|
|
|
}
|
2023-01-05 18:37:12 +08:00
|
|
|
|
|
|
|
|
|
function setShadowShow(type = false) {
|
|
|
|
|
viewer.setGroundShadow(type);
|
|
|
|
|
viewer.impl.sceneUpdated(true);
|
|
|
|
|
}
|
2023-01-09 17:09:44 +08:00
|
|
|
|
//============================= end ===================================
|
|
|
|
|
|
|
|
|
|
function moveViewToDevice(letter) {
|
|
|
|
|
if (letter != "") {
|
|
|
|
|
viewer.clearSelection();
|
|
|
|
|
viewer.select(letter);
|
|
|
|
|
viewer.fitToView([letter]);
|
2023-04-24 11:55:46 +08:00
|
|
|
|
} else {
|
2023-01-09 17:09:44 +08:00
|
|
|
|
viewer.clearSelection();
|
|
|
|
|
}
|
2023-04-24 11:55:46 +08:00
|
|
|
|
}
|