controls.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. import $ from 'jquery';
  2. import model from '@/bimAttribute'
  3. import {
  4. Message
  5. } from 'element-ui'
  6. class bimView {
  7. constructor(arg) {
  8. let viewToken, dom, app, viewer3D, model3D, viewerGIS, renderSuccess, index = 0,
  9. click, hover, roomSaved, change, marker3D, roomManager, layerMng, layerId, walk, elementColor, type,
  10. map, background, initHomeViewer, extObjIds = [],
  11. elementObject = {
  12. fileId: '',
  13. objectId: ''
  14. },
  15. extObjMng, roomEditorToolbar, bimIntegrateId, roamAngle, wallEffect;
  16. dom = arg.dom
  17. viewToken = arg.viewToken;
  18. renderSuccess = arg.renderSuccess;
  19. click = arg.click;
  20. change = arg.change;
  21. hover = arg.hover;
  22. roomSaved = arg.roomSaved;
  23. bimIntegrateId = arg.bimIntegrateId;
  24. roamAngle = arg.roamAngle;
  25. type = arg.type;
  26. background = arg.background;
  27. initHomeViewer = arg.initHomeViewer;
  28. this.init = () => {
  29. //初始化
  30. let options = new BimfaceSDKLoaderConfig();
  31. options.viewToken = viewToken;
  32. BimfaceSDKLoader.load(options, (viewMetaData) => {
  33. this.succrssCallback(viewMetaData)
  34. }, () => {
  35. this.failureCallback()
  36. });
  37. }
  38. this.succrssCallback = (viewMetaData) => {
  39. if (viewMetaData.viewType == "3DView") this.View3DRender();
  40. if (viewMetaData.viewType == "gisView") this.gisRender();
  41. }
  42. this.failureCallback = () => {
  43. console.error('加载失败');
  44. }
  45. this.getCamera = () => {
  46. return viewer3D.getCamera();
  47. }
  48. this.toggleContextMenuDisplay = (isEnabled) => {
  49. viewer3D.toggleContextMenuDisplay(isEnabled)
  50. }
  51. this.View3DRender = () => {
  52. let webAppConfig = new Glodon.Bimface.Application.WebApplication3DConfig();
  53. webAppConfig.domElement = dom;
  54. webAppConfig.effectMode = 'fluency';
  55. let bgcolor = !background ? new Glodon.Web.Graphics.Color(30, 36, 48, 1) : new Glodon.Web.Graphics
  56. .Color(20, 26, 36, 1);
  57. webAppConfig.backgroundColor = [{
  58. color: bgcolor,
  59. stop: "100%"
  60. }]
  61. webAppConfig.enableCSMShadow = false;
  62. // 设置全局单位
  63. webAppConfig.globalUnit = Glodon.Bimface.Common.Units.LengthUnits.Millimeter;
  64. // 创建WebApplication
  65. app = new Glodon.Bimface.Application.WebApplication3D(webAppConfig);
  66. // 添加待显示的模型
  67. app.addView(viewToken);
  68. // 从WebApplication获取viewer3D对象
  69. viewer3D = app.getViewer();
  70. viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.MouseClicked, data => {
  71. if (data.eventType == 'Click') { //左击
  72. if (click) click(data);
  73. } else {
  74. if (!elementObject.objectId) return;
  75. setTimeout(() => {
  76. if ($('.bf-menu.bf-menu-right .bf-menu-item')[0]) $(
  77. '.bf-menu.bf-menu-right .bf-menu-item')[0].onclick = this
  78. .bimAttribute;
  79. if ($('.bf-menu.bf-menu-left .bf-menu-item')[0]) $(
  80. '.bf-menu.bf-menu-left .bf-menu-item')[0].onclick = this
  81. .bimAttribute;
  82. }, 0)
  83. }
  84. })
  85. viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.Hover, data => {
  86. if (hover) hover(data);
  87. })
  88. viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ToolbarHomeClick, (e) => {
  89. console.log(initHomeViewer);
  90. if (initHomeViewer) this.setStatus(initHomeViewer);
  91. })
  92. viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.ViewAdded, () => {
  93. model3D = viewer3D.getModel();
  94. viewer3D.enableSSAOEffect(false);
  95. this.setCamera({
  96. isPan: true,
  97. isRotate: true,
  98. isZoom: true
  99. })
  100. app.getToolbar('MainToolbar').hide();
  101. window.CLOUD.MaterialUtil.getDefaultSelectedMaterial = function() {
  102. if (!elementColor) elementColor = new window.CLOUD
  103. .MeshBasicClipMaterial({
  104. color: '#3669b8',
  105. opacity: 0.7,
  106. transparent: !0,
  107. })
  108. return elementColor;
  109. }
  110. if ($('.gld-bf-properties')[0]) $('.gld-bf-properties')[0].onclick = this.bimAttribute;
  111. if ($('.gld-bf-firstperson')[0]) $('.gld-bf-firstperson')[0].onclick = this.walkStatus;
  112. if (renderSuccess) renderSuccess();
  113. })
  114. viewer3D.addEventListener(Glodon.Bimface.Viewer.Viewer3DEvent.SelectionChanged, data => {
  115. if (data.length == 1) {
  116. let elementData = data[0].split('.');
  117. elementObject.fileId = elementData.length == 2 ? elementData[0] : '';
  118. elementObject.objectId = elementData.length == 2 ? elementData[1] : elementData[0];
  119. } else {
  120. elementObject = {
  121. fileId: '',
  122. objectId: ''
  123. }
  124. }
  125. if (change) change(elementObject);
  126. });
  127. }
  128. this.HideOthers = () => {
  129. model3D.showExclusiveComponentsByObjectData([{
  130. levelName: 'A_4F(14.500)'
  131. }])
  132. }
  133. this.walkStatus = () => {
  134. if (roamAngle) this.setStatus(roamAngle)
  135. }
  136. this.enableWireframe = (isTrue) => {
  137. viewer3D.enableWireframe(isTrue);
  138. }
  139. this.hideComponentsByObjectData = (option) => {
  140. model3D.hideComponentsByObjectData(option);
  141. viewer3D.render();
  142. }
  143. this.bimAttribute = () => {
  144. if (type === 'model') return;
  145. $('.bf-close').click();
  146. if (!elementObject.objectId) return Message({
  147. message: '请选择一个构件',
  148. type: 'warning',
  149. duration: 2000
  150. });
  151. model.show({
  152. bimIntegrateId: bimIntegrateId,
  153. fileId: elementObject.fileId,
  154. objectId: elementObject.objectId
  155. });
  156. }
  157. this.setToolbars = (isShow) => {
  158. isShow ? app.getToolbar('MainToolbar').show() : app.getToolbar('MainToolbar').hide();
  159. }
  160. this.gisRender = () => {
  161. // 创建WebApplicationGISConfig
  162. let webAppConfig = new Glodon.Bimface.Application.WebApplicationGISConfig();
  163. // 设置创建WebApplicationGIS的dom对象
  164. webAppConfig.domElement = dom;
  165. // 创建WebApplicationGIS
  166. app = new Glodon.Bimface.Application.WebApplicationGIS(webAppConfig);
  167. // 加载待显示的场景
  168. app.addScene(viewToken);
  169. // 获取ViewerGIS对象
  170. viewerGIS = app.getViewer();
  171. viewerGIS.addEventListener(Glodon.Bimface.Viewer.ViewerGISEvent.SceneAdded, data => {
  172. layerMng = viewerGIS.getLayerManager();
  173. if (renderSuccess) renderSuccess();
  174. });
  175. viewerGIS.addEventListener(Glodon.Bimface.Viewer.ViewerGISEvent.LayerAdded, function(data) {
  176. layerId = data.layerId;
  177. });
  178. viewerGIS.addEventListener(Glodon.Bimface.Viewer.ViewerGISEvent.SelectedObjectsChanged, data => {});
  179. }
  180. this.getComponentProperty = (objectId, callback) => {
  181. viewer3D.getModel().getComponentProperty(objectId, callback)
  182. }
  183. this.returnCamera = () => {
  184. return viewer3D.getCamera()._cloudCamera;
  185. }
  186. this.addDrawable = (option, successCallback) => {
  187. // 初始化DrawableContainer
  188. let drawableConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
  189. drawableConfig.viewer = viewer3D;
  190. let drawableContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableConfig);
  191. // 创建自定义元素,可以是一个dom element,也可以是个字符串
  192. let config = new Glodon.Bimface.Plugins.Drawable.CustomItemConfig();
  193. config.content = option.html;
  194. config.viewer = viewer3D;
  195. config.worldPosition = option.position;
  196. config.opacity = 1;
  197. if (option.offsetY) config.offsetY = option.offsetY;
  198. if (option.offsetX) config.offsetX = option.offsetX;
  199. if (option.id) config.id = option.id;
  200. if (option.visibleDistance) config.visibleDistance = option.visibleDistance;
  201. //生成customItem实例
  202. let customItem = new Glodon.Bimface.Plugins.Drawable.CustomItem(config);
  203. // customItem.hide();
  204. // 添加自定义标签
  205. drawableContainer.addItem(customItem);
  206. // 开启标签的深度检测
  207. // customItem.enableDepthTest(true);
  208. // // 设置标签遮挡状态变化事件
  209. // customItem.onObstructionChanged(function(data) {
  210. // if (data) {
  211. // // 被遮挡时隐藏标签
  212. // customItem.hide();
  213. // } else {
  214. // // 未遮挡时显示标签
  215. // customItem.show();
  216. // }
  217. // });
  218. customItem.onClick(successCallback);
  219. }
  220. this.setNavigationMode = () => {
  221. viewer3D.setNavigationMode(Glodon.Bimface.Viewer.NavigationMode3D.Walk);
  222. }
  223. this.getWalkthroughData = () => {
  224. let config = new Glodon.Bimface.Plugins.Walkthrough.WalkthroughConfig();
  225. config.viewer = viewer3D;
  226. let wt = new Glodon.Bimface.Plugins.Walkthrough.Walkthrough(config);
  227. wt.addKeyFrame();
  228. return wt.getKeyFrames()[0];
  229. }
  230. this.getBoundingBox = (fileId, callback) => {
  231. model3D.getBoundingBox(fileId, callback)
  232. }
  233. this.isolateComponentsByObjectData = fileList => {
  234. model3D.clearIsolation();
  235. model3D.isolateComponentsByObjectData(fileList, Glodon.Bimface.Viewer.IsolateOption
  236. .MakeOthersTranslucent);
  237. viewer3D.render();
  238. }
  239. this.clearIsolation = () => {
  240. model3D.clearIsolation();
  241. viewer3D.render();
  242. }
  243. this.isolateComponentsById = ids => {
  244. model3D.clearIsolation();
  245. model3D.isolateComponentsById(ids, Glodon.Bimface.Viewer.IsolateOption
  246. .MakeOthersTranslucent);
  247. viewer3D.render();
  248. }
  249. this.setMap = (elem, fn) => {
  250. if (map) return;
  251. let mapConfig = Glodon.Bimface.Plugins.Map.MapConfig();
  252. mapConfig.domElement = elem; //页面的dom元素
  253. mapConfig.viewer = viewer3D; //三维模型
  254. map = new Glodon.Bimface.Plugins.Map.Map(mapConfig);
  255. let list = map.getFloorList(); //获取楼层的小地图列表
  256. if (fn) fn(list);
  257. }
  258. this.showMap = (id) => {
  259. map.showFloorById(id);
  260. }
  261. this.addRecPlane = (data) => { //创建二维平面并贴图
  262. //data = {type|image、canvas,obj|图片地址或者canvas,position|位置}
  263. //pt1是位置 pt2是大小
  264. let pt1 = {
  265. x: 0,
  266. y: 0,
  267. z: 0
  268. },
  269. pt2 = {
  270. x: data.offset.width,
  271. y: data.offset.height,
  272. z: 200
  273. };
  274. let extObjId1 = this.createExternalObject(pt1, pt2, data); //正
  275. let extObjId2 = this.createExternalObject(pt1, pt2, data); //反
  276. let extObjId3 = this.createExternalObject(pt1, pt2, data); //正
  277. let extObjId4 = this.createExternalObject(pt1, pt2, data); //反
  278. return [extObjId1, extObjId3, extObjId2, extObjId4]
  279. }
  280. this.createExternalObject = (pt1, pt2, data) => { //创建外部构件
  281. //添加外部构件
  282. if (!extObjMng) extObjMng = new Glodon.Bimface.Plugins.ExternalObject.ExternalObjectManager(
  283. viewer3D);
  284. let recPlane = this.createPlane(pt1, pt2);
  285. index++;
  286. // 将平面对象添加为外部构件,并获取其ID
  287. extObjMng.loadObject({
  288. name: 'recPlane' + index,
  289. object: recPlane
  290. });
  291. let extObjId = extObjMng.getObjectIdByName("recPlane" + index);
  292. extObjIds.push(extObjId);
  293. let position = {
  294. "x": index % 2 == 0 ? (data.position.x - 200) : data.position.x,
  295. "y": index % 2 == 0 ? (data.position.y - data.offset.width) : data.position.y,
  296. "z": data.position.z
  297. }
  298. let rotateY = data.rotateY || Math.PI / 2;
  299. extObjMng.offset(extObjId, position);
  300. extObjMng.rotateX(extObjId, Math.PI / 2);
  301. index % 2 == 0 ? extObjMng.rotateY(extObjId, rotateY) : extObjMng.rotateY(extObjId, -rotateY);
  302. return extObjId;
  303. }
  304. this.createPlane = (pt1, pt2) => { // 构造矩形平面
  305. //pt1是位置 pt2是大小
  306. let rectanglePlane = new Glodon.Bimface.Plugins.Geometry.Plane({
  307. type: 'rectangle',
  308. points: [pt1, pt2]
  309. });
  310. return rectanglePlane;
  311. }
  312. this.clearALlPlane = () => {
  313. if (extObjMng) extObjMng.clear();
  314. }
  315. this.setCanvasMaterial = (ids, data) => {
  316. // 构造材质配置 materialConfig
  317. let showIds = ids.filter((item, index) => data.updateColor ? index % 2 == 0 : index % 2 != 0);
  318. let hideIds = ids.filter((item, index) => data.updateColor ? index % 2 != 0 : index % 2 == 0);
  319. let materialConfig = new Glodon.Bimface.Plugins.Material.MaterialConfig();
  320. materialConfig.transparent = true;
  321. materialConfig.viewer = viewer3D;
  322. if (data.type == 'canvas') {
  323. materialConfig.canvas = data.obj;
  324. } else {
  325. materialConfig.src = data.obj;
  326. }
  327. materialConfig.callback = function() {
  328. extObjMng.show({
  329. ids: showIds
  330. })
  331. extObjMng.hide({
  332. ids: hideIds
  333. })
  334. viewer3D.render();
  335. };
  336. materialConfig.transparent = true;
  337. // 构造材质对象 material
  338. let material = new Glodon.Bimface.Plugins.Material.Material(materialConfig);
  339. // 将外部构件赋予材质
  340. material.overrideComponentsMaterialById(showIds, viewer3D.getModel().id);
  341. }
  342. this.zoomToBoundingBox = (extObjId) => {
  343. let boundingBox = viewer3D.getModel().getBoundingBoxById(extObjId);
  344. viewer3D.zoomToBoundingBox(boundingBox);
  345. }
  346. this.zoomToSelectedComponents = (ids) => {
  347. viewer3D.getModel().clearSelectedComponents();
  348. viewer3D.getModel().setSelectedComponentsById(ids);
  349. viewer3D.getModel().zoomToSelectedComponents();
  350. }
  351. this.walkthrough = () => { //固定路径漫游
  352. let config = new Glodon.Bimface.Plugins.Walkthrough.WalkthroughConfig();
  353. config.viewer = viewer3D;
  354. let wt = new Glodon.Bimface.Plugins.Walkthrough.Walkthrough(config);
  355. return wt;
  356. }
  357. this.insertRooms = (option) => {
  358. if (!roomManager) roomManager = viewer3D.getRoomManager();
  359. let roomConfig = new Glodon.Bimface.Plugins.Rooms.RoomConfig();
  360. roomConfig.viewer = viewer3D;
  361. roomConfig.roomId = option.id;
  362. roomConfig.geometry = {
  363. "type": "extrusion",
  364. "boundary": option.boundary,
  365. "height": option.height
  366. };
  367. if (typeof option.roomColor == 'object') {
  368. roomConfig.roomColor = new Glodon.Web.Graphics.Color(option.roomColor.r, option.roomColor.g,
  369. option.roomColor.b, option.roomColor.a);
  370. } else {
  371. roomConfig.roomColor = new Glodon.Web.Graphics.Color("#EE799F", 0.8);
  372. }
  373. if (typeof option.frameColor == 'object') {
  374. roomConfig.frameColor = new Glodon.Web.Graphics.Color(option.frameColor.r, option.frameColor.g,
  375. option.frameColor.b, option.frameColor.a);
  376. } else {
  377. roomConfig.frameColor = new Glodon.Web.Graphics.Color("#ffffff", 0.8);
  378. }
  379. let room = new Glodon.Bimface.Plugins.Rooms.Room(roomConfig);
  380. roomManager.addRoom(room);
  381. room.enableDepthTest(true);
  382. viewer3D.render();
  383. }
  384. this.colorRoomById = (option) => {
  385. if (!roomManager) return;
  386. let room = roomManager.getRoomById(option.id);
  387. if (typeof option.roomColor == 'object') {
  388. room.setRoomColor(new Glodon.Web.Graphics.Color(option.roomColor.r, option.roomColor.g,
  389. option.roomColor.b, option.roomColor.a));
  390. room.setRoomFrameColor(new Glodon.Web.Graphics.Color("#90EE90", 0.8));
  391. } else {
  392. room.setRoomColor(new Glodon.Web.Graphics.Color("#EE799F", 0.8));
  393. room.setRoomFrameColor(new Glodon.Web.Graphics.Color("#90EE90", 0.8));
  394. }
  395. }
  396. this.clearAllRooms = () => {
  397. if (roomManager) roomManager.clearAllRooms();
  398. }
  399. this.editRoom = option => {
  400. // 创建房间编辑器工具条的配置
  401. if (roomEditorToolbar) return;
  402. let roomEditorToolbarConfig = new Glodon.Bimface.Plugins.Rooms.RoomEditorToolbarConfig();
  403. roomEditorToolbarConfig.viewer = viewer3D;
  404. roomEditorToolbarConfig.roomId = option.roomId;
  405. // 创建房间编辑器工具条
  406. roomEditorToolbar = new Glodon.Bimface.Plugins.Rooms.RoomEditorToolbar(roomEditorToolbarConfig);
  407. // 注册房间编辑器工具条的监听事件
  408. roomEditorToolbar.addEventListener(Glodon.Bimface.Plugins.Rooms.RoomEditorToolbarEvent.Saved,
  409. data => {
  410. if (roomSaved) {
  411. roomSaved(data)
  412. this.exitRoom();
  413. }
  414. });
  415. roomEditorToolbar.addEventListener(Glodon.Bimface.Plugins.Rooms.RoomEditorToolbarEvent.Cancelled,
  416. data => {
  417. this.exitRoom();
  418. });
  419. }
  420. this.exitRoom = () => {
  421. if (roomEditorToolbar) {
  422. roomEditorToolbar.exit();
  423. roomEditorToolbar = null;
  424. }
  425. }
  426. this.add3DMaker = (markerType, position, imageSrc, clickFn, id) => {
  427. if (!marker3D) {
  428. let markerConfig = new Glodon.Bimface.Plugins.Marker3D.Marker3DContainerConfig();
  429. markerConfig.viewer = viewer3D;
  430. marker3D = new Glodon.Bimface.Plugins.Marker3D.Marker3DContainer(markerConfig);
  431. }
  432. let marker3dConfig = new Glodon.Bimface.Plugins.Marker3D.Marker3DConfig();
  433. if (markerType == 'image') {
  434. marker3dConfig.src = imageSrc ||
  435. "http://static.bimface.com/resources/3DMarker/warner/warner_red.png";
  436. } else if (markerType == 'canvas') {};
  437. marker3dConfig.worldPosition = position;
  438. marker3dConfig.size = 60;
  439. if (id) marker3dConfig.id = id;
  440. let marker3d = new Glodon.Bimface.Plugins.Marker3D.Marker3D(marker3dConfig);
  441. if (clickFn) marker3d.onClick(clickFn)
  442. marker3D.addItem(marker3d);
  443. viewer3D.render();
  444. }
  445. this.clear3DMaker = () => {
  446. if (marker3D) marker3D.clear();
  447. }
  448. this.set3DMaker = (imageSrc, position) => {
  449. if (!marker3D) return this.add3DMaker('image', position, imageSrc);
  450. let mark = marker3D.getAllItems()[0];
  451. mark.setSrc(imageSrc || 'http://static.bimface.com/resources/3DMarker/warner/warner_red.png')
  452. viewer3D.render();
  453. }
  454. this.setCamera = option => {
  455. console.log('setCamera');
  456. viewer3D.enableTranslate(option.isPan)
  457. viewer3D.enableOrbit(option.isRotate)
  458. viewer3D.enableScale(option.isZoom)
  459. }
  460. this.colorElementById = (elementIds, option) => {
  461. let color;
  462. if (option) {
  463. color = new Glodon.Web.Graphics.Color(option.r, option.g, option.b, option.a);
  464. } else {
  465. color = new Glodon.Web.Graphics.Color("#EE799F", 1);
  466. }
  467. viewer3D.getModel().overrideComponentsColorById(elementIds, color);
  468. viewer3D.render();
  469. }
  470. this.overrideAllComponentsColor = () => {
  471. let color = new Glodon.Web.Graphics.Color("#9598a9", 0.5);
  472. model3D.overrideAllComponentsColor(color);
  473. viewer3D.render();
  474. }
  475. this.overrideComponentsColorByObjectData = (conditions, color) => {
  476. console.log(color);
  477. let colors = new Glodon.Web.Graphics.Color("#cecece", 1);
  478. model3D.overrideComponentsColorByObjectData(conditions, colors);
  479. viewer3D.render();
  480. }
  481. this.clearColorElementById = (elementIds) => {
  482. viewer3D.getModel().restoreComponentsColorById(elementIds);
  483. viewer3D.render();
  484. }
  485. this.clearOverrideColorComponents = () => {
  486. viewer3D.getModel().clearOverrideColorComponents();
  487. viewer3D.render();
  488. }
  489. this.getAreas = (callback) => {
  490. viewer3D.getAreas(callback)
  491. }
  492. this.setNavigationMode = () => {
  493. viewer3D.setNavigationMode(Glodon.Bimface.Viewer.NavigationMode3D.ThirdPerson);
  494. viewer3D.setFlySpeedRate(3);
  495. }
  496. this.setBlueSky = () => {
  497. let skyBoxManagerConfig = new Glodon.Bimface.Plugins.SkyBox.SkyBoxManagerConfig();
  498. skyBoxManagerConfig.viewer = viewer3D;
  499. skyBoxManagerConfig.style = Glodon.Bimface.Plugins.SkyBox.SkyBoxStyle.CloudySky;
  500. let skyBoxManager = new Glodon.Bimface.Plugins.SkyBox.SkyBoxManager(skyBoxManagerConfig);
  501. skyBoxManager.setStyle(Glodon.Bimface.Plugins.SkyBox.SkyBoxStyle.CloudySky);
  502. skyBoxManager.enableSkyBox(true);
  503. }
  504. this.setGalaxySky = () => {
  505. let skyBoxManagerConfig = new Glodon.Bimface.Plugins.SkyBox.SkyBoxManagerConfig();
  506. skyBoxManagerConfig.viewer = viewer3D;
  507. skyBoxManagerConfig.style = Glodon.Bimface.Plugins.SkyBox.SkyBoxStyle.DarkNight;
  508. let skyBoxManager = new Glodon.Bimface.Plugins.SkyBox.SkyBoxManager(skyBoxManagerConfig);
  509. skyBoxManager.enableSkyBox(true);
  510. viewer3D.render();
  511. }
  512. this.getCameraState = () => {
  513. return viewer3D.getCamera().getStatus();
  514. }
  515. this.setStatus = (value) => {
  516. viewer3D.getCamera().setStatus(value);
  517. }
  518. this.setStatusValue = (val) => {
  519. roamAngle = val;
  520. }
  521. this.setCameraAnimation = (val) => {
  522. viewer3D.setCameraAnimation(val);
  523. }
  524. this.setCameraState = (state) => {
  525. viewer3D.setCameraStatus(state);
  526. }
  527. this.enableHover = (isHover) => {
  528. viewer3D.enableHover(isHover);
  529. }
  530. this.setGlowEffectById = (ids) => {
  531. viewer3D.enableGlowEffect(true);
  532. model3D.setGlowEffectById(ids, {
  533. type: "body",
  534. color: new Glodon.Web.Graphics.Color(255, 229, 89, 1),
  535. intensity: 1,
  536. spread: 3
  537. })
  538. viewer3D.render();
  539. }
  540. this.setGlowEffectByQuery = query => {
  541. //query array
  542. model3D.getComponentsByConditions(query, data => {
  543. this.setGlowEffectById(data);
  544. })
  545. }
  546. this.clearGlowEffect = () => {
  547. model3D.clearGlowEffect();
  548. viewer3D.render();
  549. }
  550. this.showExclusiveComponentsByObjectData = conditions => {
  551. //根据筛选条件显示构件,其余全部隐藏
  552. model3D.showExclusiveComponentsByObjectData(conditions);
  553. viewer3D.render();
  554. }
  555. this.getObjectDataById = objectId => {
  556. return model3D.getObjectDataById(objectId);
  557. }
  558. this.lockAxis = () => {
  559. viewer3D.lockAxis(Glodon.Bimface.Viewer.AxisOption.Z, [Math.PI / 12, Math.PI / 2])
  560. }
  561. this.setRotationCenter = point => {
  562. viewer3D.setRotationCenter(new Glodon.Web.Geometry.Point3d(point.x, point.y, point.z))
  563. }
  564. this.getTreeList = callback => {
  565. model3D.getModelTree(callback);
  566. }
  567. this.setGlowEffect = option => { //gis发光
  568. if (!layerId || !layerMng) return;
  569. viewerGIS.enableGlowEffect(true);
  570. layerMng.getLayer(layerId).getComponentManager().setGlowEffectById(option.ids, option.type);
  571. }
  572. this.convertObject = (name, id) => {
  573. //添加外部构件
  574. if (!extObjMng) extObjMng = new Glodon.Bimface.Plugins.ExternalObject.ExternalObjectManager(
  575. viewer3D);
  576. if (extObjMng.getObjectIdByName(name)) return extObjMng.getObjectIdByName(name);
  577. let obj = extObjMng.convert(id);
  578. extObjMng.loadObject({
  579. name: name,
  580. object: obj
  581. })
  582. viewer3D.render();
  583. return extObjMng.getObjectIdByName(name);
  584. }
  585. this.rotateObject = (extObjId, angle) => {
  586. let animationId;
  587. animate()
  588. function animate() {
  589. animationId = requestAnimationFrame(animate)
  590. extObjMng.rotateOnBasePoint(extObjId, {
  591. x: 46290.56403256581,
  592. y: 35755.300171217226,
  593. z: -7232.165669450452,
  594. }, {
  595. x: 0,
  596. y: 0,
  597. z: 1
  598. }, Math.PI / angle);
  599. viewer3D.render();
  600. }
  601. setTimeout(() => {
  602. if (animationId) cancelAnimationFrame(animationId);
  603. }, 3000)
  604. }
  605. this.hideComponentsById = (ids) => {
  606. model3D.hideComponentsById(ids);
  607. viewer3D.render();
  608. }
  609. this.setRotationCenter = (point) => {
  610. viewer3D.setRotationCenter(point)
  611. }
  612. this.createWallEffect = (option) => {
  613. //创建电子围栏
  614. // 构造电子围墙效果配置项
  615. let wallEffectConfig = new Glodon.Bimface.Plugins.Animation.WallEffectConfig();
  616. // 配置Viewer对象、方向、持续时间、路径、高度
  617. wallEffectConfig.viewer = viewer3D;
  618. wallEffectConfig.direction = {
  619. type: "Tangent", // 运动方式为沿着路径的切线方向
  620. reverse: false // 运动方向默认为逆时针
  621. }
  622. wallEffectConfig.duration = option.duration;
  623. wallEffectConfig.height = option.height;
  624. wallEffectConfig.stretch = true;
  625. wallEffectConfig.path = option.path;
  626. // 电子围墙颜色
  627. wallEffectConfig.color = new Glodon.Web.Graphics.Color(50, 211, 166, 0.8);
  628. // 构造电子围墙扫描效果对象
  629. wallEffect = new Glodon.Bimface.Plugins.Animation.WallEffect(wallEffectConfig);
  630. }
  631. this.setView = (type) => {
  632. viewer3D.setView(Glodon.Bimface.Viewer.ViewOption[type])
  633. viewer3D.render();
  634. }
  635. this.destroy = () => {
  636. console.log('销毁场景');
  637. app.destroy();
  638. }
  639. this.init();
  640. }
  641. }
  642. export default bimView;