pi-bimface-web
Version:
基本BIMFACE的功能封装工具库,主要为了解决BIMFACE执行流程的代码赘余,集成常见的基础功能,包含构件绘色、构件定位、模型缩放等等,最大化提高BIMFACE的开发效率 # 基于BIMFACE的底层API封装
1,601 lines (1,374 loc) • 48 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function isLoadBim() {
if (!window.Glodon) {
return false;
}
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
/**
*
* @param op Viewer3D对象
* @param mod Model3D对象
*
* 功能API说明
* setRoomsColorById ---- 根据房间ID修改房间颜色
* setRoomsFrameColorById ---- 根据房间ID修改房间线框颜色
* @returns
*/
function mixinRoom(op, mod) {
/**
* 房间类: 专门用来操作BIMFACE房间API
*/
var Room = /*#__PURE__*/function () {
function Room() {
_classCallCheck(this, Room);
}
_createClass(Room, [{
key: "setRoomsColorById",
value:
/**
* 根据房间ID修改房间颜色
* @param op
* @param roomIds
* @param option
*/
function setRoomsColorById(roomIds, option) {
op.setRoomsColorById(roomIds, new Glodon.Web.Graphics.Color(option.color, option.transparency));
}
/**
* 根据房间ID修改房间线框颜色
* @param op
* @param roomIds
* @param option
*/
}, {
key: "setRoomsFrameColorById",
value: function setRoomsFrameColorById(roomIds, option) {
op.setRoomsFrameColorById(roomIds, new Glodon.Web.Graphics.Color(option.color, option.transparency));
}
/**
* 获取房间属性
* @param roomId
* @param callback
*/
}, {
key: "getRoomProperty",
value: function getRoomProperty(roomId, callback) {
mod.getRoomProperty(roomId, callback);
}
/**
* 房间标签
* @param cofing
* @param callback
*/
}, {
key: "createRoomItem",
value: function createRoomItem(config) {
var drawableConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
drawableConfig.viewer = op; //容器
var drawableContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableConfig);
var customItem = new Glodon.Bimface.Plugins.Drawable.CustomItem(config); // 添加自定义标签
drawableContainer.addItem(customItem);
}
}]);
return Room;
}();
return new Room();
}
/**
* 构件类:用于构件操作API集合
* @param op Viewer3D对象
* @param mod Model3D对象
*
* 功能API说明
* setColor ---- 构件着色
* clearColor ---- 清除构件着色
* conditionColor ---- 构件根据条件绘色
* clearConditionArtifactColor ---- 清除构件条件绘色
* freeze ---- 冻结构件
* clearFreeze ---- 清除构件冻结效果
* hide ---- 隐藏构件
* show ---- 显示隐藏的构件
* hideAllComponents ---- 隐藏全部构件
* transparent ---- 构件半透明
* transparentCondition ---- 给指定模型的所有构件着色
* opaque ---- 构件透明还原
* isolate ---- 构件隔离
* resetIsolate ---- 取消隔离效果
* zoomToSelect ---- 构件定位
* getProperty ---- 获取构件属性
* getComponentsByConditions ---- 根据筛选条件获取构件信息
* deactivateComponentsById ---- 将构件设置未激活状态,当构件被设置为未激活的状态后,构件无法被选择、修改颜色与材质、控制可见性(显示、隐藏)、设置隔离效果,用户可以穿透该构件选择其后方的构件、三维标签
* deactivateComponentsByObjectData ---- 根据筛选条件设置构件未激活状态
*/
function mixinArtifacts(op, mod) {
var Artifacts = /*#__PURE__*/function () {
function Artifacts() {
_classCallCheck(this, Artifacts);
}
_createClass(Artifacts, [{
key: "setColor",
value:
/**
* 构件着色
* @param id 构件ID
* @param option
*/
function setColor(id, option) {
var color = new Glodon.Web.Graphics.Color(option.color, option.transparency);
mod.overrideComponentsColorById(id, color);
}
/**
* 清除构件着色
* @param id 构件ID
*/
}, {
key: "clearColor",
value: function clearColor(id) {
mod.restoreComponentsColorById(id);
}
/**
* 构件根据条件绘色
* @param conditions 条件数组
* @param option
*/
}, {
key: "conditionColor",
value: function conditionColor(conditions, option) {
var color = new Glodon.Web.Graphics.Color(option.color, option.transparency);
mod.overrideComponentsColorByObjectData(conditions, color);
}
/**
* 清除构件条件绘色
* @param conditions
*/
}, {
key: "clearConditionArtifactColor",
value: function clearConditionArtifactColor(conditions) {
mod.restoreComponentsColorByObjectData(conditions);
}
/**
* 冻结构件
* @param id 构件ID
* @param color
*/
}, {
key: "freeze",
value: function freeze(id, color) {
var freezeColor = new Glodon.Web.Graphics.Color('#c4c7ce', 0.8);
if (color) {
freezeColor = new Glodon.Web.Graphics.Color(color, 0.8);
}
mod.overrideComponentsColorById(id, freezeColor);
mod.deactivateComponentsById(id);
}
/**
* 清除构件冻结
*/
}, {
key: "clearFreeze",
value: function clearFreeze() {
mod.activateAllComponents();
mod.clearOverrideColorComponents();
}
/**
* 隐藏构件
* @param id 构件ID
*/
}, {
key: "hide",
value: function hide(id) {
mod.hideComponentsById(id);
}
/**
* 隐藏全部构件
*/
}, {
key: "hideAllComponents",
value: function hideAllComponents() {
mod.hideAllComponents();
}
/**
* 显示隐藏的构件
* @param id 构件ID
*/
}, {
key: "show",
value: function show(id) {
mod.showComponentsById(id);
}
/**
* 构件半透明
* @param id 构件ID
*/
}, {
key: "transparent",
value: function transparent(id) {
mod.transparentComponentsById(id);
}
/**
* 给指定模型的所有构件着色
* @param colorOption
*/
}, {
key: "transparentCondition",
value: function transparentCondition(colorOption) {
var color = new Glodon.Web.Graphics.Color(colorOption.color, colorOption.transparency);
mod.overrideAllComponentsColor(color);
}
/**
* 构件透明还原
* @param id 构件ID
*/
}, {
key: "opaque",
value: function opaque(id) {
mod.opaqueComponentsById(id);
}
/**
* 构件隔离
* @param id 构件ID
*/
}, {
key: "isolate",
value: function isolate(id, option) {
var makeOthersTranslucent = Glodon.Bimface.Viewer.IsolateOption.MakeOthersTranslucent;
mod.isolateComponentsById(id, makeOthersTranslucent); // 设置隔离下的构件颜色
if (option) {
mod.setIsolatedComponentColor(new Glodon.Web.Graphics.Color(option.color, option.transparency));
}
}
/**
* 取消隔离
* @param id
*/
}, {
key: "resetIsolate",
value: function resetIsolate() {
mod.clearIsolation();
}
/**
* @param id 构件定位
*/
}, {
key: "zoomToSelect",
value: function zoomToSelect(id) {
// 清除构件选中状态
// mod.clearSelectedComponents()
// 选中构件
mod.setSelectedComponentsById(id); // 定位到选中的构件
mod.zoomToSelectedComponents();
}
/**
* 获取构件属性
* @param id
* @param successCallback
*/
}, {
key: "getProperty",
value: function getProperty(id, successCallback) {
mod.getComponentProperty(id, successCallback);
}
/**
* 根据筛选条件获取构件信息
* @param conditions
* @param successCallback
* @param failureCallback
*/
}, {
key: "getComponentsByConditions",
value: function getComponentsByConditions(conditions, successCallback, failureCallback) {
mod.getComponentsByConditions(conditions, successCallback, failureCallback);
}
/**
* 将构件设置未激活状态,当构件被设置为未激活的状态后,构件无法被选择、修改颜色与材质、控制可见性(显示、隐藏)、设置隔离效果,用户可以穿透该构件选择其后方的构件、三维标签
* @param id
*/
}, {
key: "deactivateComponentsById",
value: function deactivateComponentsById(id) {
mod.deactivateComponentsById(id);
}
/**
* 根据筛选条件设置构件未激活状态
* @param conditions
*/
}, {
key: "deactivateComponentsByObjectData",
value: function deactivateComponentsByObjectData(conditions) {
mod.deactivateComponentsByObjectData(conditions);
}
/**
* 集成模型中根据文件ID获取子模型的楼层信息
* @param fileId
* @param callback
*/
}, {
key: "getFloorsbyFileId",
value: function getFloorsbyFileId(fileId, callback) {
op.getFloorsbyFileId(fileId, callback);
}
/**
* 根据筛选条件显示构件,其余全部隐藏
* @param conditions
* @param progressCallback
* @param successCallback
*/
}, {
key: "showExclusiveComponentsByObjectData",
value: function showExclusiveComponentsByObjectData(conditions, progressCallback, successCallback) {
op.showExclusiveComponentsByObjectData(conditions, progressCallback, successCallback);
}
}]);
return Artifacts;
}();
return new Artifacts();
}
/**
*
* @param op Viewer3D对象
* @param mod Model3D对象
*
* 功能API说明
* setRoomsColorById ---- 根据房间ID修改房间颜色
* setRoomsFrameColorById ---- 根据房间ID修改房间线框颜色
* @returns
*/
function mixinModel(mod) {
/**
* 模型类: 专门用来操作BIMFACE模型API
*/
var Model = /*#__PURE__*/function () {
function Model() {
_classCallCheck(this, Model);
}
_createClass(Model, [{
key: "move",
value:
/**
* 模型移动
* @param ob
* @param position 通用坐标配置
*/
function move(position) {
mod.setModelTranslation(position);
}
/**
* 模型缩放
* @param ob
* @param multiple 缩放倍数
* @param position 模型位置中心点坐标
* @returns
*/
}, {
key: "scale",
value: function scale(multiple, position) {
if (position) {
mod.setModelScale(position, multiple);
return;
}
mod.setModelScale({
x: 0,
y: 0,
z: 0
}, multiple);
}
/**
* 横截面3D展示
*/
}, {
key: "view3DCross",
value: function view3DCross() {
// 获取模型视图状态
mod.get3DViewStates(function (data) {
mod.setState(data.views[1].state);
});
}
/**
* 竖截面3D展示
*/
}, {
key: "view3DVertical",
value: function view3DVertical() {
// 获取模型视图状态
mod.get3DViewStates(function (data) {
mod.setState(data.views[2].state);
});
}
}]);
return Model;
}();
return new Model();
}
// 热力图对象
var heatMap2D;
var heatMap3D; // 水流动画对象
var flowEffect; // 水流动画材质
var material; // 环形扫描对象
var ringScanEffect; // 扇形扫描对象
var fanScanEffect; // 平面扫描对象
// let planeScanEffect: Glodon.Bimface.Plugins.Animation.PlaneScanEffect
// // 构造外部构件管理器
// let extObjMng: Glodon.Bimface.Plugins.ExternalObject.ExternalObjectManager
// // 曲线构成对象
// let splineCurve: Glodon.Bimface.Plugins.Geometry.SplineCurve
// // 曲线动画配置项
// let curveAnimationConfig: Glodon.Bimface.Plugins.Animation.CurveAnimationConfig
// // 曲线动画对象
// let curveAnimation: Glodon.Bimface.Plugins.Animation.CurveAnimation
// // 外部构件载入id
// let splineCurveId: void
// // 辉光对象
// let bloomEffect: Glodon.Bimface.Plugins.Effect.BloomEffect
/**
*
* @param op Viewer3D对象
* @param mod Model3D对象
*
* 特效动画API
* create2DHeatMap ---- 创建二维热力图
* clear2DHeatMap ---- 清除2D热力图
* create3DHeatMap ---- 创建3D热力图
* clear3DHeatMap ---- 清除3D热力图
* @returns
*/
function mixinAnimation(op, mod) {
/**
* 模型类: 专门用来操作BIMFACE模型API
*/
var Animation = /*#__PURE__*/function () {
function Animation() {
_classCallCheck(this, Animation);
}
_createClass(Animation, [{
key: "create2DHeatMap",
value:
/**
* 创建二维热力图
* @param id 构件id
* @param position
*/
function create2DHeatMap(position, id, heatMapData) {
var heatMap2DConfig = new Glodon.Bimface.Plugins.Heatmap.Heatmap2DConfig();
heatMap2DConfig.enableColorLegend = true;
heatMap2DConfig.viewer = op;
heatMap2DConfig.boundary = position;
heatMap2DConfig.max = 100; // 构造二维热力图对象
heatMap2D = new Glodon.Bimface.Plugins.Heatmap.Heatmap2D(heatMap2DConfig); // const arr = [
// {
// x: -5488.956433395811,
// y: -2312.137857225113,
// z: 7052.798895332921,
// value: 60
// }
// ]
heatMap2D.setData(heatMapData);
heatMap2D.setRadius(600);
heatMap2D.update();
heatMap2D.show();
op.getModel().transparentComponentsById(id);
}
/**
* 清除2D热力图
* @param id
*/
}, {
key: "clear2DHeatMap",
value: function clear2DHeatMap(id) {
heatMap2D.dispose();
op.getModel().opaqueComponentsById(id);
}
/**
* 创建3D热力图
* @param position 三维坐标
* @param id 构件ID
*/
}, {
key: "create3DHeatMap",
value: function create3DHeatMap(position, id, heatMapData, heatMapBaseConfig) {
var heatMap3DConfig = new Glodon.Bimface.Plugins.Heatmap.Heatmap3DConfig();
heatMap3DConfig.enableColorLegend = true;
heatMap3DConfig.viewer = op;
heatMap3DConfig.radius = heatMapBaseConfig.radius;
heatMap3DConfig.boundary = position;
heatMap3DConfig.boundaryHeight = heatMapBaseConfig.boundaryHeight; // 构造三维热力图对象
heatMap3D = new Glodon.Bimface.Plugins.Heatmap.Heatmap3D(heatMap3DConfig);
heatMap3D.setData(heatMapData);
heatMap3D.setDataMax(100);
heatMap3D.update();
heatMap3D.show();
op.getModel().transparentComponentsById(id, 0.0);
}
/**
* 清除3D热力图
* @param id
*/
}, {
key: "clear3DHeatMap",
value: function clear3DHeatMap(id) {
heatMap3D.dispose();
op.getModel().opaqueComponentsById(id);
} // /**
// * 环形动效扫描效果
// */
// ringScan(position: position, color: colorOption) {
// let ringScanEffectConfig = new Glodon.Bimface.Plugins.Animation.RingScanEffectConfig()
// // 配置Viewer对象、颜色、持续时间、位置、半径、衰减力度等参数
// ringScanEffectConfig.viewer = op
// ringScanEffectConfig.color = new Glodon.Web.Graphics.Color(color.color, color.transparency)
// ringScanEffectConfig.duration = 2000
// ringScanEffectConfig.originPosition = position
// ringScanEffectConfig.radius = 20000
// ringScanEffectConfig.progressive = 1
// // 构造环状扫描效果对象
// ringScanEffect = new Glodon.Bimface.Plugins.Animation.RingScanEffect(ringScanEffectConfig)
// ringScanEffect.show()
// }
/**
* 构件整体发光
*/
}, {
key: "glowEffect",
value: function glowEffect(id, glowEffectConfig) {
// 开启物体发光效果
op.enableGlowEffect(true); // 根据ID设置整体发光效果,"body"为整体发光,"outline"为轮廓线发光
mod.setGlowEffectById(id, {
type: glowEffectConfig.type,
color: new Glodon.Web.Graphics.Color(glowEffectConfig.color.color, glowEffectConfig.color.transparency),
intensity: glowEffectConfig.intensity,
spread: glowEffectConfig.spread
});
}
/**
* 平面扫描
* @param url 材质路径
* @param boundary 扫描范围包围盒
* @param duration 扫描时间
* @param direction 扫描过程
* @param colorOption 颜色
* @param blendingRatio 材质合成度
*/
// planeScanEffect(
// url: string,
// boundary: position[],
// duration: number,
// direction: position,
// colorOption: specialColor,
// blendingRatio: number
// ) {
// // 初始化材质
// let materialConfig = new Glodon.Bimface.Plugins.Material.MaterialConfig();
// materialConfig.viewer = op;
// materialConfig.src = '../../dev/1.png';
// let material = new Glodon.Bimface.Plugins.Material.Material(materialConfig);
// // 构造平面扫描效果配置项
// // let planeScanEffectConfig = new Glodon.Bimface.Plugins.Animation.PlaneScanEffectConfig();
// // // 配置Viewer对象、方向、持续时间、边界
// // planeScanEffectConfig.viewer = op;
// // planeScanEffectConfig.direction = direction;
// // planeScanEffectConfig.duration = duration;
// // planeScanEffectConfig.boundary = boundary;
// // // 设置水平扫描颜色
// // planeScanEffectConfig.color = new Glodon.Web.Graphics.Color(50, 211, 166, 1.0);
// // // 设置水平扫描材质
// // planeScanEffectConfig.material = material;
// // // 设置材质与颜色的混合参数
// // planeScanEffectConfig.blendingRatio = 0.3;
// // // 构造水平扫描效果对象
// // planeScanEffect = new Glodon.Bimface.Plugins.Animation.PlaneScanEffect(planeScanEffectConfig)
// let planeScanEffectConfig = new Glodon.Bimface.Plugins.Animation.PlaneScanEffectConfig();
// // 配置Viewer对象、方向、持续时间、边界
// planeScanEffectConfig.viewer = op;
// planeScanEffectConfig.direction = { x: 0.6, y: 0.8, z: 0 };
// planeScanEffectConfig.duration = 2000;
// planeScanEffectConfig.boundary = [
// { x: 13023609.960575795, y: 25777457.255968206, z: 50.61713809092208 },
// { x: 13122365.995315686, y: 25839575.569788456, z: 50.61713809194653 },
// { x: 13315590.835127937, y: 25970551.36890273, z: 50.61713809410652 },
// { x: 13276959.063045746, y: 26028989.384943567, z: 50.61713809507025 },
// { x: 13155465.068261532, y: 26169861.95716057, z: 50.61713809737892 },
// { x: 13136429.412665904, y: 26212368.128522705, z: 50.61713809809444 },
// { x: 13134071.918206926, y: 26226598.456635598, z: 50.61713809832914 },
// { x: 12839819.545762224, y: 26093815.956026126, z: 50.617138096139335 },
// { x: 12950723.349436384, y: 25912849.28590552, z: 50.61713809314037 },
// { x: 13023609.960575795, y: 25777457.255968206, z: 50.61713809092208 }
// ];
// // 设置水平扫描颜色
// planeScanEffectConfig.color = new Glodon.Web.Graphics.Color(50, 211, 166, 1.0);
// // 设置水平扫描材质
// planeScanEffectConfig.material = material;
// // 设置材质与颜色的混合参数
// planeScanEffectConfig.blendingRatio = 0.3;
// // 构造水平扫描效果对象
// planeScanEffect = new Glodon.Bimface.Plugins.Animation.PlaneScanEffect(planeScanEffectConfig)
// }
// clearPlaneScanEffect() {
// // 清除水平扫描效果
// planeScanEffect.destroy();
// }
/**
* 清除构件发光效果
*/
}, {
key: "clearGlowEffect",
value: function clearGlowEffect(id) {
mod.removeGlowEffectById(id);
}
/**
* 构件水流动画
* @param src
* @param id
*/
}, {
key: "setFlowEffect",
value: function setFlowEffect(src, id) {
var offset = [0, 0]; // 构造材质容器
var materialContainer = new Glodon.Bimface.Plugins.Material.MaterialContainer(); // 构造材质配置
var materialConfig = new Glodon.Bimface.Plugins.Material.MaterialConfig();
materialConfig.viewer = op;
materialConfig.src = src;
materialConfig.rotation = 90;
materialConfig.offset = offset;
materialConfig.scale = [0.1524, 0.1524];
material = new Glodon.Bimface.Plugins.Material.Material(materialConfig);
materialContainer.addMaterial(material); // 将材质附着至构件
material.overrideComponentsMaterialById(id); // 水流动画
var flowEffectConfig = new Glodon.Bimface.Plugins.Animation.FlowEffectConfig(); // 构造水流动画对象 flowEffect1
flowEffectConfig.material = material;
flowEffectConfig.speed = [0.5, 0];
flowEffectConfig.viewer = op;
flowEffect = new Glodon.Bimface.Plugins.Animation.FlowEffect(flowEffectConfig); // 渲染三维模型,加载图片资源需要时间,此处设定了200ms的延迟
setTimeout(function () {
op.render();
flowEffect.play();
}, 200);
}
/**
* 清除水流动画
*/
}, {
key: "clearSetFlowEffect",
value: function clearSetFlowEffect() {
if (flowEffect) {
flowEffect.stop();
material.clearOverrideComponentsMaterial();
}
}
/**
* 环形扫描动画
*/
}, {
key: "setScanEffect",
value: function setScanEffect(position, color, scanOption) {
// if (ringScanEffect) return
// 构造环状扫描效果配置项
var ringScanEffectConfig = new Glodon.Bimface.Plugins.Animation.RingScanEffectConfig(); // 配置Viewer对象、颜色、持续时间、位置、半径、衰减力度等参数
ringScanEffectConfig.viewer = op;
ringScanEffectConfig.color = new Glodon.Web.Graphics.Color(color.r, color.g, color.b, color.a);
ringScanEffectConfig.duration = (scanOption === null || scanOption === void 0 ? void 0 : scanOption.duration) || 2000;
ringScanEffectConfig.originPosition = position;
ringScanEffectConfig.radius = (scanOption === null || scanOption === void 0 ? void 0 : scanOption.radius) || 200000;
ringScanEffectConfig.progressive = scanOption.progressive; // 构造环状扫描效果对象
ringScanEffect = new Glodon.Bimface.Plugins.Animation.RingScanEffect(ringScanEffectConfig);
ringScanEffect.show();
op.render();
}
/**
* 清除环形扫描动画
*/
}, {
key: "clearScanEffect",
value: function clearScanEffect() {
// 清除环状扫描效果
ringScanEffect.destroy();
ringScanEffect = null;
}
/**
* 扇形扫描动画
* @param bgColor 扇形扫描效果的背景颜色
* @param color 扇形扫描效果的颜色
* @param position 扇形扫描效果的中心点坐标
*/
}, {
key: "setFanScanEffect",
value: function setFanScanEffect(bgColor, color, position) {
if (fanScanEffect) return;
var fanScanEffectConfig = new Glodon.Bimface.Plugins.Animation.FanScanEffectConfig(); // 配置Viewer对象、背景颜色、扫描颜色、持续时间、扇形角度、位置、扫描半径等参数
fanScanEffectConfig.viewer = op;
fanScanEffectConfig.backgroundColor = new Glodon.Web.Graphics.Color(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
fanScanEffectConfig.color = new Glodon.Web.Graphics.Color(color.r, color.g, color.b, color.a);
fanScanEffectConfig.duration = 2000;
fanScanEffectConfig.fanAngle = Math.PI;
fanScanEffectConfig.originPosition = position;
fanScanEffectConfig.radius = 200000; // 构造扇形扫描效果对象
fanScanEffect = new Glodon.Bimface.Plugins.Animation.FanScanEffect(fanScanEffectConfig);
op.render();
}
/**
* 清除扇形扫描动画
*/
}, {
key: "clearSetFanScanEffect",
value: function clearSetFanScanEffect() {
// 清除扇形扫描效果
fanScanEffect.destroy();
fanScanEffect = null;
}
/**
* 构造曲线动画
* @param url 贴图地址
* @param points 路径坐标
* @param colors
*/
}, {
key: "setCurveAnimation",
value: function setCurveAnimation(url, points, colors, name, anOption) {
var color = new Glodon.Web.Graphics.Color(colors.r, colors.g, colors.b, colors.a);
var width = anOption.width;
var style = {
"lineType": "Continuous",
"lineStyle": null
}; // 构造曲线
var splineCurve = new Glodon.Bimface.Plugins.Geometry.SplineCurve(points, color, width, style); // 曲线贴图
splineCurve.setMap({
src: url,
// 允许颜色覆盖
enableColorOverride: false
}, function () {
var extObjMng = new Glodon.Bimface.Plugins.ExternalObject.ExternalObjectManager(op); // 将曲线作为外部构件载入场景
extObjMng.loadObject({
name: name,
object: splineCurve
});
var splineCurveId = extObjMng.getObjectIdByName(name); // 构造辉光效果的配置项
var bloomEffectConfig = new Glodon.Bimface.Plugins.Effect.BloomEffectConfig(); // 设置构件ID数组、强度、扩散程度、viewer参数
bloomEffectConfig.ids = [{
"objectIds": [splineCurveId]
}];
bloomEffectConfig.intensity = anOption.intensity;
bloomEffectConfig.spread = anOption.spread;
bloomEffectConfig.viewer = op; // 构造辉光效果
new Glodon.Bimface.Plugins.Effect.BloomEffect(bloomEffectConfig);
}); // 构造曲线动画的配置项
var curveAnimationConfig = new Glodon.Bimface.Plugins.Animation.CurveAnimationConfig(); // 配置Viewer对象、曲线对象、动画时间、动画循环、动画类型等参数
curveAnimationConfig.viewer = op;
curveAnimationConfig.curves = [splineCurve];
curveAnimationConfig.time = anOption.time;
curveAnimationConfig.loop = anOption.loop;
curveAnimationConfig.type = anOption.type; // 构造曲线动画对象
var curveAnimation = new Glodon.Bimface.Plugins.Animation.CurveAnimation(curveAnimationConfig);
curveAnimation.play();
}
}]);
return Animation;
}();
return new Animation();
}
/**
* BIMFACE基础类
*/
var BimBase = /*#__PURE__*/function () {
// 是否成功加载3D模型
// 离线配置
// Viewer3D对象
// model对象
// Web3D对象
// DOM
// // dom结构绑定ID
// _id: string
// 房间类
// 构件类
// 模型类
// 动效类
function BimBase(viewToken, dom, option) {
_classCallCheck(this, BimBase);
_defineProperty(this, "isAdd3DModel", false);
_defineProperty(this, "_viewToken", void 0);
_defineProperty(this, "_options", void 0);
_defineProperty(this, "_viewer3D", void 0);
_defineProperty(this, "_model3D", void 0);
_defineProperty(this, "_app", void 0);
_defineProperty(this, "_dom", void 0);
_defineProperty(this, "room", void 0);
_defineProperty(this, "artifacts", void 0);
_defineProperty(this, "model", void 0);
_defineProperty(this, "animation", void 0);
this._viewToken = viewToken;
this._options = option;
this._dom = dom;
}
_createClass(BimBase, [{
key: "_load",
value: function _load(successCallback, failureCallback) {
var _this$_options;
var that = this;
/**
* 3D模型加载成功回调
* @param viewMetaData
*/
function localSuccessCallBack(viewMetaData) {
var config = new Glodon.Bimface.Application.WebApplication3DConfig();
config.domElement = that._dom; // 隐藏工具栏和构件树
config.Toolbars = []; // 设置模型爆炸配置项`
config.enableExplosion = true; // 背景颜色设置
config.backgroundColor = [{
color: new Glodon.Web.Graphics.Color(16, 32, 61, 0)
}];
var app = new Glodon.Bimface.Application.WebApplication3D(config);
var view3D = app.getViewer();
view3D.addModel(viewMetaData);
that._viewer3D = app.getViewer();
that._app = app; // 监听添加view完成的事件
view3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewAdded, function () {
that.isAdd3DModel = true; //自适应屏幕大小
window.onresize = function () {
view3D.resize(document.documentElement.clientWidth, document.documentElement.clientHeight - 40);
};
var model3D = view3D.getModel();
that._model3D = view3D.getModel();
that.room = mixinRoom(view3D, model3D);
that.artifacts = mixinArtifacts(view3D, model3D);
that.model = mixinModel(model3D);
that.animation = mixinAnimation(view3D, model3D); // 视图加载完成后执行业务回调
successCallback(viewMetaData); // 渲染3D模型
view3D.render();
});
}
/**
* 3D模型加载失败回调
* @param error
*/
function failureView3DCallback(error) {
failureCallback(error);
}
var options = new BimfaceSDKLoaderConfig();
if ((_this$_options = this._options) !== null && _this$_options !== void 0 && _this$_options.path) {
options.path = this._options.path;
options.dataEnvType = BimfaceEnvOption.Local;
options.sdkPath = this._options.sdkPath;
} else {
options.viewToken = this._viewToken;
}
BimfaceSDKLoader.load(options, localSuccessCallBack, failureView3DCallback);
}
/**
* 模型初始化加载
*/
}, {
key: "_renderModel",
value: function _renderModel() {
this._viewer3D.render();
}
/**
* 获取模型3D对象
* @param modelId 模型id
*
* @returns
*/
}, {
key: "_getModel",
value: function _getModel(modelId) {
return this._viewer3D.getModel(modelId);
}
}, {
key: "getViewer3D",
value: function getViewer3D() {
return this._viewer3D;
}
/**
* 初始化执行
* @param successCallback
* @param failureCallback
* @returns
*/
}, {
key: "render",
value: function render(successCallback, failureCallback) {
return this._load(successCallback, failureCallback);
}
}]);
return BimBase;
}();
var sectionRegion;
var cunstomItemContainer;
/**
* BIMFACE封装主类
*/
var Bim = /*#__PURE__*/function (_BimBase) {
_inherits(Bim, _BimBase);
var _super = _createSuper(Bim);
function Bim() {
_classCallCheck(this, Bim);
return _super.apply(this, arguments);
}
_createClass(Bim, [{
key: "getModelTree",
value:
/**
* 获取目录树信息
* @param callback
*/
function getModelTree(callback) {
var model3D = this._viewer3D.getModel();
model3D === null || model3D === void 0 ? void 0 : model3D.getModelTree(callback);
}
/**
* 设置背景色
* @param colorOption
*/
}, {
key: "setBackgroundColor",
value: function setBackgroundColor(colorOption) {
// 设置单色景色
var monochrome = new Glodon.Web.Graphics.Color(colorOption.color, colorOption.transparency);
this._viewer3D.setBackgroundColor(monochrome);
this._renderModel();
}
/**
* 根据构件ID获取ObjectData,用于作为筛选条件
* @param id
* @returns
*/
}, {
key: "getObjectDataById",
value: function getObjectDataById(id) {
var model3D = this._viewer3D.getModel();
return model3D.getObjectDataById(id);
}
/**
* 获取当前模型层级数据
* @param callback
*/
}, {
key: "getFloors",
value: function getFloors(callback) {
var model3D = this._viewer3D.getModel();
model3D.getFloors(callback);
}
/**
* 获取当前相机位置信息,用于设置相机位置参数参照
* @returns
*/
}, {
key: "getCameraStatus",
value: function getCameraStatus() {
return this._viewer3D.getCameraStatus();
}
/**
* 根据位置设置当前视觉点
* @param camera 相机状态,getCameraStatus()返回的对象
* @param callback
* @returns
*/
}, {
key: "setCameraStatus",
value: function setCameraStatus(camera, callback) {
this._viewer3D.setCameraStatus(camera, callback);
}
/**
* 根据构件、外部构件、房间ID获取其包围盒信息
* @param id
*/
}, {
key: "getBoundingBoxById",
value: function getBoundingBoxById(id) {
var model3D = this._viewer3D.getModel();
return model3D.getBoundingBoxById(id);
}
/**
* 获取空间
* @param successCallback
* @param failureCallback
*/
}, {
key: "getAreas",
value: function getAreas(successCallback, failureCallback) {
var model3D = this._viewer3D.getModel(); // 回调后操作
model3D.getAreas(successCallback, failureCallback);
}
/**
* 获取楼层下的构件ID
* @param floorId
* @param callback
*/
}, {
key: "getFloorBoundingBoxById",
value: function getFloorBoundingBoxById(floorId, callback) {
var model3D = this._viewer3D.getModel();
model3D.getFloorBoundingBoxById(floorId, callback);
}
/**
* 创建房间
* @param roomHeight 房间高度
*/
}, {
key: "createRooms",
value: function createRooms(boundary, roomHeight, roomId) {
var viewer3D = this._viewer3D;
viewer3D.createRoom(boundary, roomHeight, roomId);
this._renderModel();
}
/**
* 环形扫描动效
* @param position
* @param color
*/
}, {
key: "setRingScan",
value: function setRingScan(position, color) {
this.animation.ringScan(position, color);
this._renderModel();
}
/**
* 构件整体发光动效
* @param id
* @param glowEffectConfig
*/
}, {
key: "setGlowEffect",
value: function setGlowEffect(id, glowEffectConfig) {
this.animation.glowEffect(id, glowEffectConfig);
this._renderModel();
}
/**
* 设置标签
* @param position
* @param dom
* @param cb 回调函数
* @param type 点击事件标识
*/
}, {
key: "set2DItems",
value: function set2DItems(position, dom, cb, type) {
var drawableContainerConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig(); // 设置容器配置匹配的对象
drawableContainerConfig.viewer = this._viewer3D; // 创建标签容器
cunstomItemContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableContainerConfig);
var config = new Glodon.Bimface.Plugins.Drawable.CustomItemConfig();
config.content = dom;
config.viewer = this._viewer3D;
config.worldPosition = position;
config.id = type;
var customItem = new Glodon.Bimface.Plugins.Drawable.CustomItem(config); // 点击事件
customItem.onClick(cb);
cunstomItemContainer.addItem(customItem); //设置Tip的样式
customItem.setTooltipStyle({
border: '1px',
top: '-33px'
});
}
/**
* 清除标签
*/
}, {
key: "clearSet2DItems",
value: function clearSet2DItems() {
if (cunstomItemContainer) {
cunstomItemContainer.clear();
}
}
/**
* 恢复所有默认显示,包括着色、选择、隔离、半透明、空间等
*/
}, {
key: "restoreAllDefault",
value: function restoreAllDefault() {
var model3D = this._viewer3D.getModel();
model3D.restoreAllDefault();
}
/**楼层剖切 */
}, {
key: "setFloorBox",
value: function setFloorBox(id, roomId) {
var _this = this;
if (sectionRegion) {
sectionRegion.exit();
}
var model3D = this._viewer3D.getModel();
model3D.getFloorBoundingBoxById(id, function (row) {
var boundary = [{
x: row.min.x,
y: row.max.y,
z: row.min.z
}, {
x: row.min.x,
y: row.min.y,
z: row.min.z
}, {
x: row.max.x,
y: row.min.y,
z: row.min.z
}, {
x: row.max.x,
y: row.max.y,
z: row.min.z
}];
var config = new Glodon.Bimface.Plugins.Section.SectionRegionConfig(); // 配置剖切区域边界、高度、Viewer对象等参数
config.boundary = boundary;
model3D.getRoomProperty(roomId, function (ow) {
config.height = ow.bboxMax.z - ow.bboxMin.z;
config.viewer = _this._viewer3D; // 构造剖切区域
sectionRegion = new Glodon.Bimface.Plugins.Section.SectionRegion(config); // 变更剖切方向
sectionRegion.changeClipDirection();
sectionRegion.hide();
});
});
}
/**
* 右键监听事件
* @param callback
*/
}, {
key: "rightEventListener",
value: function rightEventListener(callback) {
this._viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ContextMenu, callback);
}
/**
* 模型设置阻尼效果
*/
}, {
key: "setDampingAnimation",
value: function setDampingAnimation() {
this._viewer3D.enableDamping(true);
}
/**
* 模型绕点旋转
* @param position 旋转中心,{x: 0, y: 0, z: 0},缺省值为场景中心
* @param speed 速率,正负表示方向,数值表示速度
*/
}, {
key: "rotateModelPosition",
value: function rotateModelPosition(position, speed) {
this._viewer3D.startAutoRotate(speed, position);
}
/**
* 停止模型旋转
*/
}, {
key: "stopRotateModel",
value: function stopRotateModel() {
this._viewer3D.stopAutoRotate();
}
/**
* 设置天空盒效果
* @param type
*/
}, {
key: "setBackground",
value: function setBackground(type) {
var _iblManager, _iblManager2, _iblManager3;
var that = this;
var iblManager = null; // 初始化天空盒
function initIBL() {
if (iblManager) {
return;
} // 构造天空盒管理器配置项,并指定Viewer、Option参数
var skyBoxManagerConfig = new Glodon.Bimface.Plugins.SkyBox.SkyBoxManagerConfig();
skyBoxManagerConfig.viewer = that._viewer3D; // 设置自定义天空盒的图片资源
skyBoxManagerConfig.customizedImage = {
front: "https://static.bimface.com/attach/0d178c31584d432f93b3df90832d6ba1_EnvMap_posz.jpg",
back: "https://static.bimface.com/attach/c02b7114af6d4966b3f1fd7d483fcdd9_EnvMap_negz.jpg",
left: "https://static.bimface.com/attach/6c2f5045467b4c51a4e506524e74a65c_EnvMap_negx.jpg",
right: "https://static.bimface.com/attach/ec541f626f194a979d49ec5f52ca32bb_EnvMap_posx.jpg",
top: "https://static.bimface.com/attach/01700a9a6f7542af8df76bc923b065b9_EnvMap_posy.jpg",
bottom: "https://static.bimface.com/attach/031a2a1a51374fc88fe8acf1d490b7c0_EnvMap_negy.jpg"
};
skyBoxManagerConfig.style = Glodon.Bimface.Plugins.SkyBox.SkyBoxStyle.CloudySky; // 构造天空盒管理器,构造完成后,场景背景即发生变化
iblManager = new Glodon.Bimface.Plugins.SkyBox.SkyBoxManager(skyBoxManagerConfig);
}
switch (type) {
// 蓝天白云
case 1:
initIBL(); // 将天空盒效果设置为蓝天
iblManager.setStyle(Glodon.Bimface.Plugins.SkyBox.SkyBoxStyle.BlueSky);
iblManager.enableSkyBox(true);
break;
// 开启城市夜景的IBL效果
case 2:
initIBL();
(_iblManager = iblManager) === null || _iblManager === void 0 ? void 0 : _iblManager.setStyle(Glodon.Bimface.Plugins.IBL.IBLStyle.CityNightView);
iblManager.enableSkyBox(true);
break;
// 开启空旷园区的IBL效果
case 3:
initIBL();
(_iblManager2 = iblManager) === null || _iblManager2 === void 0 ? void 0 : _iblManager2.setStyle(Glodon.Bimface.Plugins.IBL.IBLStyle.OpenField);
iblManager.enableSkyBox(true);
break;
// 开启草坪效果的IBL效果
case 4:
initIBL();
(_iblManager3 = iblManager) === null || _iblManager3 === void 0 ? void 0 : _iblManager3.setStyle(Glodon.Bimface.Plugins.IBL.IBLStyle.LawnScene);
iblManager.enableSkyBox(true);
break;
}
}
}, {
key: "setBackgroundBoxNigh",
value: function setBackgroundBoxNigh() {
// 构造天空盒管理器配置项,并指定Viewer、Option参数
var skyBoxManagerConfig = new Glodon.Bimface.Plugins.SkyBox.SkyBoxManagerConfig();
skyBoxManagerConfig.viewer = this._viewer3D;
skyBoxManagerConfig.style = Glodon.Bimface.Plugins.SkyBox.SkyBoxStyle.DarkNight; // 构造天空盒管理器,构造完成后,场景背景即发生变化
new Glodon.Bimface.Plugins.SkyBox.SkyBoxManager(skyBoxManagerConfig);
}
/**
* 自定义构件线框描边
*/
}, {
key: "onWallStoke",
value: function onWallStoke(conditions, colorOption) {
var model3D = this._viewer3D.getModel();
var colorGreen = new Glodon.Web.Graphics.Color(colorOption.r, colorOption.g, colorOption.b, colorOption.a);
model3D.overrideComponentsFrameColorByObjectData(conditions, colorGreen);
this._renderModel();
}
/**
* 模型强调效果:构件、房间、外部构件
*/
}, {
key: "blinkModel",
value: function blinkModel(ids, colorOption) {
// 构件闪烁
this._viewer3D.addBlinkComponentsById(ids);
this._viewer3D.setBlinkColor(new Glodon.Web.Graphics.Color(colorOption.color, colorOption.transparency));
this._viewer3D.enableBlinkComponents(true);
this._viewer3D.setBlinkIntervalTime(500);
this._viewer3D.render();
}
/**
* 清除闪烁
*/
}, {
key: "clearBlinkModel",
value: function clearBlinkModel() {
// 取消闪烁
this._viewer3D.clearAllBlinkComponents();
this._viewer3D.render();
}
}]);
return Bim;
}(BimBase);
function init(viewToken, dom, option) {
if (!viewToken && !(option !== null && option !== void 0 && option.path)) {
throw new Error('Initialize failed: invalid viewToken.');
}
if (!dom) {
throw new Error('Initialize failed: invalid dom.');
}
var bim = new Bim(viewToken, dom, option);
return bim;
}
var isBim = isLoadBim();
var PIBIM = {
init: function init$1() {
if (isBim) {
console.error('请引入BIMFACE JSSDK!');
}
return init;
}
};
var index = PIBIM.init();
exports.PIBIM = index;