YZProjectCloud/yanzhu-bigscreen/src/views/bim/bimTools.js

112 lines
3.0 KiB
JavaScript
Raw Normal View History

2025-07-26 15:21:53 +08:00
function initBimCfg(that) {
if (!that.bimCfg) {
that.bimCfg = {}
}
if (!that.hideParts) {
that.hideParts = [];
}
let config = that.$tryToJson(that.selProject?.bimConfig, {})
that.bimCfg.background = config.background || ''
that.bimCfg.showGis = config.showGis || false
that.bimCfg.clientApi = config.clientApi || false
}
function initBimGis(that, api) {
if (that.bimCfg.showGis) {
api.Public.setGisState(true);
api.Public.setTerrainState(false, "http://113.201.2.107:9304/layer.json", false)
api.Public.setGisState(true);
} else if (that.bimCfg.background) {
api.Public.setGisState(false, that.bimCfg.background);
}
}
function initLoadModel(that, api) {
let fnInit = () => {
if (api.m_model.size > 0) {
setTimeout(() => {
initModelPosition(that, api)
}, 1000)
} else {
setTimeout(fnInit, 1000);
}
}
fnInit();
}
function initModelPosition(that, api) {
that.models.forEach(modelInfo => {
if (modelInfo) {
let modelId = modelInfo.lightweightName
let cfg = that.$tryToJson(modelInfo.bimConfig, {});
let x = cfg?.x || 0;
let y = cfg?.y || 0;
let z = cfg?.z || 0;
let rotateZ = cfg?.rotateZ || 0;
if (x * 1 + y * 1 + z * 1 != 0) {
console.log("移动模型", modelId, x, y, z)
api.Model.moveToPosition([x, y, z], 0, modelId)
}
if (rotateZ * 1 != 0) {
api.Model.rotate(0, 0, rotateZ, modelId)
}
if (cfg && cfg.hideParts) {
cfg.hideParts.forEach(it => {
that.hideParts.push(it);
})
}
setTimeout(() => {
api.Model.location(modelId);
setTimeout(() => {
that.resetScene();
}, 1000);
}, 1000);
}
initHideParts(that, api)
});
}
function initHideParts(that, api) {
let hideCnt = 0;
let hideFn = () => {
hideCnt++;
if (hideCnt > 30) {
return;
}
setTimeout(() => {
let featureIds = (that.hideParts || []).map(it => it.featureId);
if (featureIds.length > 0) {
api.Feature.setVisible(featureIds.join("#"), false);
}
hideFn();
}, 100)
};
hideFn();
}
2025-07-29 17:42:49 +08:00
function resetScene(that, api) {
that.selectedViewpoint = null;
that.selectedRoam = null;
api.Camera.stopImmersiveRoam();
api.Model.location(api.m_model.keys().toArray()[0]);
if (!that.isClient()) {
api.Plugin.deleteMiniMap();
}
if (that.viewPoint) {
if (that.viewPoint.world) {
if (!that.isClient()) {
api.Camera.setViewPort(that.viewPoint);
}
}
}
}
2025-07-26 15:21:53 +08:00
export default {
initBimCfg,
initBimGis,
initLoadModel,
initModelPosition,
2025-07-29 17:42:49 +08:00
initHideParts,
resetScene
2025-07-26 15:21:53 +08:00
}