index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <div class="full animate__animated animate__faster" :class="menuIndex == 0 ? 'animate__bounceInLeft' : 'animate__bounceOutLeft'" style="overflow: hidden;" >
  3. <!-- 背景--3D场景 -->
  4. <scene3-d ref="scene" style="z-index: 9;" :camera-option="cameraOptions" :controls-option="controlsOption"
  5. @loadingFinish="initScene">
  6. </scene3-d>
  7. <!-- 数据面板 -->
  8. <main-scene @openDialog="openDialog" @playVideo="playVideo" @showInfoBox="showInfoBox" ref="data-panel"
  9. style="z-index: 9;"> </main-scene>
  10. <!-- 工具栏 -->
  11. <tools-bar :option="toolsOption"></tools-bar>
  12. <!-- 园区事件 -->
  13. <mp-dialog ref="mpDialog" title="园区事件">
  14. <div slot="detail" style="color: #FFFFFF;padding: 1.25rem;">
  15. {{dialogDetail.detail}}
  16. </div>
  17. </mp-dialog>
  18. <!-- 视频播放 -->
  19. <devicePlayer ref="devicePlayer"></devicePlayer>
  20. </div>
  21. </template>
  22. <script>
  23. import {
  24. mapGetters
  25. } from "vuex";
  26. import devicePlayer from "@/components/scene/wvp/devicePlayer.vue";
  27. import mpDialog from "../../components/mp-dialog.vue"
  28. import TopBar from "../../components/3DScene/top-bar/top-bar";
  29. import Scene3D from "../../components/3DScene/3DScene";
  30. import MainScene from "../../components/scene/mainScene";
  31. import ToolsBar from "../../components/3DScene/tools-bar/tools-bar";
  32. import * as Three from "three";
  33. import {
  34. getBox1,
  35. getCameraBox
  36. } from "../../components/3DScene/infoBox";
  37. import {
  38. CSS2DObject
  39. } from "three/examples/jsm/renderers/CSS2DRenderer";
  40. import {
  41. fullscreenToggel
  42. } from "../../util/util";
  43. export default {
  44. name: "index",
  45. components: {
  46. devicePlayer,
  47. mpDialog,
  48. MainScene,
  49. Scene3D,
  50. TopBar,
  51. ToolsBar,
  52. },
  53. computed: {
  54. ...mapGetters(["menuIndex"])
  55. },
  56. data() {
  57. return {
  58. dialogDetail: {},
  59. mesh: {},
  60. searchText: "",
  61. searchCameraType: "",
  62. searchType: "building",
  63. searchIndex: 0,
  64. isReady: false,
  65. handlePanelShow: false,
  66. toolsPanelType: "building",
  67. toolsOption: [{
  68. icon: '/img/tools/361.png',
  69. name: '旋转',
  70. event: this.round
  71. },
  72. {
  73. icon: '/img/tools/reset.png',
  74. name: '复位',
  75. event: this.reset
  76. },
  77. {
  78. icon: '/img/tools/loudong.png',
  79. name: '建筑信息',
  80. event: () => {
  81. this.showBox(this.buildingObj, "building")
  82. }
  83. },
  84. {
  85. icon: '/img/tools/video.png',
  86. name: '摄像头',
  87. event: () => {
  88. this.showBox(this.cameraObj, "camera")
  89. }
  90. },
  91. {
  92. icon: '/img/tools/full.png',
  93. name: '信息框',
  94. event: () => {
  95. this.$refs['data-panel'].infoBoxShow()
  96. }
  97. },
  98. ],
  99. finishNum: 0,
  100. loadingSchedule: 0,
  101. buildingsRes: [],
  102. cameraRes: [],
  103. objs: [],
  104. gltf: [
  105. '/gltf/7_8/20H.gltf',
  106. '/gltf/5H/5H.gltf',
  107. '/gltf/3H/3H.gltf',
  108. '/gltf/7H/7H.gltf',
  109. '/gltf/13H/13H.gltf',
  110. '/gltf/14H/14H.gltf',
  111. '/gltf/17H/17H.gltf',
  112. '/gltf/1H/1H.gltf',
  113. '/gltf/DX2/DX2.gltf',
  114. '/gltf/TiKuai/TiKuai.gltf',
  115. '/gltf/SKY/Sky.gltf',
  116. '/gltf/Tree_Car/Tree_Car.gltf',
  117. ],
  118. controlsOption: {
  119. minDistance: 100,
  120. maxDistance: 500,
  121. autoRotate: false,
  122. autoRotateSpeed: 1,
  123. keyPanSpeed: 3,
  124. target: new Three.Vector3(0, 0, 0),
  125. enableDamping: true,
  126. },
  127. cameraOptions: {
  128. position: [5000, 5000, 1000],
  129. near: 0.01,
  130. far: 50000,
  131. lookAt: [1300, 0, 1300],
  132. },
  133. obj: [{
  134. mtlUrl: '/obj/CAR.mtl',
  135. objUrl: '/obj/CAR.obj'
  136. },
  137. {
  138. mtlUrl: '/obj/DX.mtl',
  139. objUrl: '/obj/DX.obj'
  140. },
  141. {
  142. mtlUrl: '/test/Tree.mtl',
  143. objUrl: '/test/Tree.obj'
  144. },
  145. {
  146. mtlUrl: '/obj/TiKuai.mtl',
  147. objUrl: '/obj/TiKuai.obj'
  148. },
  149. {
  150. mtlUrl: '/obj/XiaoPin.mtl',
  151. objUrl: '/obj/XiaoPin.obj'
  152. },
  153. {
  154. mtlUrl: '/test/Building_A.mtl',
  155. objUrl: '/test/Building_A.obj'
  156. },
  157. {
  158. mtlUrl: '/test/BuildingB.mtl',
  159. objUrl: '/test/BuildingB.obj'
  160. },
  161. {
  162. mtlUrl: '/test/BuildingC.mtl',
  163. objUrl: '/test/BuildingC.obj'
  164. },
  165. {
  166. mtlUrl: '/obj/building/3H.mtl',
  167. objUrl: '/obj/building/3H.obj'
  168. },
  169. {
  170. mtlUrl: '/obj/building/5H.mtl',
  171. objUrl: '/obj/building/5H.obj'
  172. },
  173. {
  174. mtlUrl: '/obj/building/13H.mtl',
  175. objUrl: '/obj/building/13H.obj'
  176. },
  177. {
  178. mtlUrl: '/obj/building/14H.mtl',
  179. objUrl: '/obj/building/14.obj'
  180. },
  181. {
  182. mtlUrl: '/obj/building/17.mtl',
  183. objUrl: '/obj/building/17.obj'
  184. },
  185. {
  186. mtlUrl: '/obj/building/20.mtl',
  187. objUrl: '/obj/building/20.obj'
  188. },
  189. ],
  190. buildings: [{
  191. text: '软件园主楼',
  192. position: [100, 115, 100]
  193. },
  194. {
  195. text: '软件园副楼',
  196. position: [170, 50, 50]
  197. },
  198. {
  199. text: '软件园A栋',
  200. position: [0, 105, 110]
  201. },
  202. {
  203. text: '软件园B栋',
  204. position: [-70, 105, 110]
  205. },
  206. {
  207. text: '软件园C栋',
  208. position: [-120, 105, 55]
  209. },
  210. {
  211. text: '软件园D栋',
  212. position: [-120, 105, -20]
  213. },
  214. ],
  215. cameraList: [{
  216. number: 'HK-nm51658186',
  217. position: [50, 0, 70],
  218. src: '/video/video2.mp4',
  219. name: "设备2",
  220. type: "枪机"
  221. },
  222. {
  223. number: 'HK-nm51658186',
  224. position: [-100, 0, 100],
  225. src: '/video/video3.mp4',
  226. name: "设备3",
  227. type: "枪机"
  228. },
  229. {
  230. number: 'HK-nm51658186',
  231. position: [100, 0, 20],
  232. src: '/video/video4.mp4',
  233. name: "设备4",
  234. type: "枪机"
  235. },
  236. {
  237. number: 'HK-nm51658186',
  238. position: [200, 0, 50],
  239. src: '/video/video4.mp4',
  240. name: "设备4",
  241. type: "球机"
  242. },
  243. {
  244. number: 'HK-nm51658186',
  245. position: [75, 0, 10],
  246. src: '/video/video4.mp4',
  247. name: "设备4",
  248. type: "球机"
  249. },
  250. ],
  251. cameraObj: {},
  252. buildingObj: {},
  253. }
  254. },
  255. provide() {
  256. return {
  257. "index": this
  258. }
  259. },
  260. mounted() {
  261. this.buildingsRes = this.buildings;
  262. this.cameraRes = this.cameraList;
  263. },
  264. watch: {
  265. searchCameraType() {
  266. this.cameraRes = this.searchCameraType == "全部" ? this.cameraList : this.cameraList.filter(item => item.type ==
  267. this.searchCameraType)
  268. }
  269. },
  270. methods: {
  271. showInfoBox() {
  272. this.toolsOption.forEach(item => {
  273. if (item.name == '信息框') {
  274. if (item.icon == '/img/tools/full.png') {
  275. item.icon = '/img/tools/full-out.png'
  276. } else {
  277. item.icon = '/img/tools/full.png'
  278. }
  279. console.log(item, "123");
  280. this.$forceUpdate()
  281. }
  282. })
  283. },
  284. openDialog(item) {
  285. this.dialogDetail = item
  286. this.$refs.mpDialog.open(item.time)
  287. },
  288. playVideo(item) {
  289. const {
  290. deviceId
  291. } = item
  292. const {
  293. channelId
  294. } = item
  295. const {
  296. info
  297. } = item
  298. this.$refs.devicePlayer.openDialog("media", deviceId, channelId, info);
  299. },
  300. reset() {
  301. this.$refs['scene'].camera.position.z = this.cameraOptions.position[0];
  302. this.$refs['scene'].camera.position.x = this.cameraOptions.position[1];
  303. this.$refs['scene'].camera.position.y = this.cameraOptions.position[2];
  304. this.$refs['scene'].camera.lookAt(...this.cameraOptions.lookAt);
  305. this.$refs['scene'].controls.target.set(0, 0, 0);
  306. this.$refs['data-panel'].infoBoxShow(true);
  307. },
  308. handleNext(num, list) {
  309. this.searchIndex = (this.searchIndex + num) % list.children.length;
  310. if (this.searchIndex < 0) {
  311. this.searchIndex = list.children.length + this.searchIndex;
  312. }
  313. list.children.forEach((item, index) => {
  314. console.log(this.searchIndex, index);
  315. if (index == this.searchIndex) {
  316. this.$refs['scene'].flyto(item.position);
  317. item.visible = true;
  318. } else {
  319. item.visible = false;
  320. }
  321. })
  322. },
  323. async initScene() {
  324. this.$refs['scene'].scene.fog = new Three.Fog(this.$refs['scene'].scene.background, 1, 5000);
  325. //添加天空盒
  326. // this.$refs['scene'].addSkyBox(
  327. // [
  328. // '/sky/HDR_r.jpg',
  329. // '/sky/HDR_l.jpg',
  330. // '/sky/HDR_u.jpg',
  331. // '/sky/HDR_d.jpg',
  332. // '/sky/HDR_f.jpg',
  333. // '/sky/HDR_b.jpg',
  334. // ]
  335. // );
  336. // 添加模型
  337. // await this.addObj();
  338. await this.addGltf();
  339. this.addDirectionalLight();
  340. this.initBoxInfo();
  341. this.isReady = true;
  342. //自旋转
  343. // this.$refs['scene'].controls.autoRotate = true;
  344. },
  345. toBuilding(objIndex, list) {
  346. list.children.forEach((item, index) => {
  347. if (objIndex == index) {
  348. this.searchIndex = index;
  349. this.$refs['scene'].flyto(item.position);
  350. item.visible = true;
  351. } else {
  352. item.visible = false;
  353. }
  354. })
  355. },
  356. quitToolPanel() {
  357. this.handlePanelShow = false;
  358. this.buildingObj.children.forEach(item => {
  359. item.visible = false;
  360. })
  361. this.cameraObj.children.forEach(item => {
  362. item.visible = false;
  363. })
  364. this.reset();
  365. },
  366. async addGltf() {
  367. this.gltf.forEach(item => {
  368. this.$refs['scene'].addGltf(item,
  369. (gltf) => {
  370. this.$refs['scene'].scene.add(gltf.scene)
  371. gltf.scene.traverse(function(child) {
  372. child.castShadow = true;
  373. child.receiveShadow = true;
  374. if (child.isMesh) {
  375. console.log(child, 546546);
  376. child.material.color = new Three.Color("rgb(200,200,200)");
  377. child.material.side = Three.DoubleSide;
  378. child.material.emissive = child.material.color;
  379. child.material.emissiveMap = child.material.map;
  380. if (child.material.name == 'JZ_LanGan_GeZi' || child.material.name == 'JZ_14_LanGan' ||
  381. child.name.indexOf("Tree") > -1) {
  382. console.log(child.name, 456789)
  383. child.material.transparent = true;
  384. }
  385. }
  386. });
  387. this.finishNum++;
  388. this.loadingSchedule = ((this.finishNum * 100) / (this.gltf.length * 100)) * 100
  389. },
  390. (xhr) => {
  391. if (xhr.total == xhr.loaded) {
  392. // this.finishNum++;
  393. }
  394. });
  395. })
  396. },
  397. initBoxInfo() {
  398. this.buildingObj = new Three.Object3D();
  399. this.buildings.forEach(item => {
  400. let element = getBox1(item.text, this);
  401. let label = new CSS2DObject(element);
  402. label.position.x = item.position[0];
  403. label.position.y = item.position[1];
  404. label.position.z = item.position[2];
  405. label.visible = false;
  406. this.buildingObj.add(label);
  407. })
  408. this.$refs['scene'].scene.add(this.buildingObj);
  409. this.cameraObj = new Three.Object3D();
  410. this.cameraList.forEach(item => {
  411. let element = getCameraBox(item, this);
  412. let label = new CSS2DObject(element);
  413. label.position.x = item.position[0];
  414. label.position.y = item.position[1];
  415. label.position.z = item.position[2];
  416. label.visible = false;
  417. this.cameraObj.add(label);
  418. })
  419. this.$refs['scene'].scene.add(this.cameraObj);
  420. },
  421. //添加平行光
  422. addDirectionalLight() {
  423. //添加光源
  424. let dirLight = new Three.DirectionalLight("#bebebe", 1)
  425. dirLight.position.set(1, 1, 1);
  426. dirLight.shadow.mapSize.width = 512; // default
  427. dirLight.shadow.mapSize.height = 512; // default
  428. dirLight.shadow.camera.near = 1; // default
  429. dirLight.shadow.camera.far = 100;
  430. dirLight.castShadow = true;
  431. this.$refs['scene'].scene.add(dirLight);
  432. },
  433. showBox(list, type) {
  434. this.$refs['scene'].controls.autoRotate = false;
  435. this.toolsPanelType = type;
  436. this.handlePanelShow = true;
  437. this.searchIndex = 0;
  438. if (list.children.length > 0) {
  439. list.children[0].visible = true;
  440. this.$refs['data-panel'].infoBoxShow(false)
  441. this.$refs['scene'].flyto(list.children[0].position)
  442. }
  443. },
  444. showCamera() {
  445. const list = this.cameraObj;
  446. list.children.forEach((item, index) => {
  447. item.visible = !item.visible;
  448. })
  449. },
  450. handleFull() {
  451. fullscreenToggel();
  452. },
  453. round() {
  454. this.$refs['scene'].controls.autoRotate = !this.$refs['scene'].controls.autoRotate;
  455. },
  456. handleSearch() {
  457. this.buildingsRes = this.buildings.filter(item => item.text.indexOf(this.searchText) > -1)
  458. },
  459. }
  460. }
  461. </script>
  462. <style scoped>
  463. .handle-panel-1 {
  464. width: 20%;
  465. height: 430px;
  466. /* background: rgba(230, 160, 9, 0.5); */
  467. position: absolute;
  468. top: 200px;
  469. left: 3%;
  470. }
  471. .handle-panel-2 {
  472. width: 20%;
  473. height: 510px;
  474. /* background: rgba(230, 160, 9, 0.5); */
  475. position: absolute;
  476. top: 200px;
  477. left: 3%;
  478. }
  479. .search-body {
  480. overflow-y: scroll;
  481. width: 100%;
  482. height: 300px;
  483. }
  484. .search-footer {
  485. width: 100%;
  486. height: 60px;
  487. background: rgba(0, 0, 0, 0.5);
  488. color: whitesmoke;
  489. font-size: 18px;
  490. }
  491. .search-item {
  492. width: 95%;
  493. margin: auto;
  494. height: 45px;
  495. border-bottom: 1px solid #525252;
  496. }
  497. .click:hover {
  498. cursor: pointer;
  499. transform: translate(1px, 1px);
  500. }
  501. .click:active {
  502. cursor: pointer;
  503. transform: translate(2px, 2px);
  504. }
  505. .building-click:hover {
  506. cursor: pointer;
  507. text-shadow: 2px 2px 2px #ccffb4;
  508. }
  509. </style>