LaserBim.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <header>
  3. <div v-if="project">项目 - {{ project.name }}</div>
  4. </header>
  5. <article>
  6. <main>
  7. <div class="split" v-if="source">
  8. <iframe ref="sourceFrame" :src="`smart-laser.html?m=${source.num}&dev`" frameborder="0" @load="onLoadSource"></iframe>
  9. <div class="tools">
  10. <div class="item-mode">
  11. <div class="iconfont icon-show_roaming_normal" :class="{ active: mode == 0 }" @click="onModeChange(0)"></div>
  12. <div class="iconfont icon-show_more" :class="{ active: mode == 1 }" @click="onModeChange(1)"></div>
  13. </div>
  14. <div class="item-date" v-if="target">
  15. <span class="prev" @click="onPrevDate('source')"><i class="iconfont icon-show_back"></i></span>
  16. <span @click="onPickDate('source')">{{ source.date }}</span>
  17. <span class="next" @click="onNextDate('source')"><i class="iconfont icon-show_back"></i></span>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="split" v-if="target">
  22. <iframe ref="targetFrame" :src="`smart-bim.html?m=${target.num}`" frameborder="0" @load="onLoadTarget"></iframe>
  23. </div>
  24. <div class="tools" v-if="source">
  25. <div class="item-date" v-if="!target">
  26. <span class="prev" @click="onPrevDate()"><i class="iconfont icon-show_back"></i></span>
  27. <span @click="onPickDate('all')">{{ source.date }}</span>
  28. <span class="next" @click="onNextDate()"><i class="iconfont icon-show_back"></i></span>
  29. </div>
  30. <div class="item-split" @click="onCompare">
  31. <i class="iconfont icon-size-o"></i>
  32. </div>
  33. </div>
  34. <div class="popup" v-if="source && datepickName">
  35. <div>
  36. <span @click="onPickClose"><i class="iconfont icon-close"></i></span>
  37. <datepicker :inline="true" :value="datepickValue" :highlighted="highlighted" @selected="onSelected"></datepicker>
  38. </div>
  39. </div>
  40. </main>
  41. </article>
  42. </template>
  43. <script setup>
  44. import Datepicker from 'vuejs3-datepicker'
  45. import { ref, onActivated, onDeactivated, reactive, onMounted, computed } from 'vue'
  46. import ConvertViews from '@/utils/ConvertViews'
  47. let sourceApp = null, sourceSceneName
  48. let targetApp = null
  49. const views = new ConvertViews()
  50. const datepickName = ref(null)
  51. const datepickValue = ref(null)
  52. const sourceFrame = ref(null)
  53. const targetFrame = ref(null)
  54. const mode = ref(0)
  55. const source = ref(null)
  56. const target = ref(null)
  57. const project = ref(null)
  58. const projects = reactive([{ pid: '001', name: '五楼办公区', num: 'SS-t-bFMqa1dqUU', date: '2022-09-01' }])
  59. const scenes = reactive([
  60. { pid: '001', num: 'SS-t-bFMqa1dqUU', date: '2022-09-01' },
  61. { pid: '001', num: 'SS-t-xp9BDKfzhR', date: '2022-09-03' },
  62. { pid: '001', num: 'SS-t-lc5OWhZPaC', date: '2022-09-05' },
  63. { pid: '001', num: 'SS-t-Y6gLRFwxE5', date: '2022-09-10' },
  64. ])
  65. const highlighted = computed(() => {
  66. let dates = []
  67. if (datepickName.value) {
  68. dates = scenes.map(item => item.date.toDate())
  69. }
  70. return {
  71. dates: dates,
  72. }
  73. })
  74. const getView = ()=>{
  75. let camera = sourceApp.viewer.mainViewport.camera
  76. return {
  77. position : camera.position,
  78. quaternion : camera.quaternion,
  79. fov : camera.fov
  80. }
  81. }
  82. const initConvertView = (noNeedBindEvent) => {
  83. if(sourceApp && targetApp ){
  84. views.init(sourceApp, targetApp , sourceApp.viewer.inputHandler.domElement, 'laser', getView(),
  85. sourceApp.viewer.images360.panos.slice(0,2).map(e=>e.position), )
  86. }
  87. }
  88. const onLoadSource = () => {
  89. if(views.loaded){
  90. views.clear({dontClearTarget:true})
  91. }
  92. sourceApp = sourceFrame.value.contentWindow
  93. sourceApp.loaded.then(sdk => {
  94. if (mode.value != 0) {
  95. sdk.scene.changeMode(mode.value)
  96. }
  97. window.viewer1 = sourceApp.viewer
  98. viewer1.mainViewport.view.minPitch+=0.01//防止bim垂直视角上的闪烁(似乎是因 up 要乘以某矩阵导致微小偏差所致)
  99. viewer1.mainViewport.view.minPitch-=0.01
  100. initConvertView()
  101. sourceSceneName = sourceApp.Potree.settings.number
  102. sourceApp.viewer.addEventListener('camera_changed', e => {
  103. targetApp && views.receive( getView() )
  104. })
  105. })
  106. sourceApp.canChangePos = ()=>{
  107. return sourceApp.Potree.settings.displayMode != 'showPanos'
  108. }
  109. }
  110. const onLoadTarget = () => {
  111. targetApp = targetFrame.value.contentWindow
  112. targetApp.loaded.then(viewer=>{
  113. //console.log(viewer.getViewer().camera)
  114. window.viewer2 = targetApp.viewer
  115. initConvertView()
  116. })
  117. // targetApp.Scene.on('loaded', () => {
  118. // targetApp.Camera.setCompassDisplay(false)
  119. // targetApp.Connect.sync.start()
  120. // targetApp.VRScreenSYNC = false
  121. // console.log('targetApp.Scene loaded')
  122. // views.bind({ targetApp })
  123. // sourceApp && sourceApp.Connect.sync.sync()
  124. // })
  125. // targetApp.Connect.sync.on('data', data => {
  126. // if (sourceApp) {
  127. // views.applyDiff(sourceApp, data)
  128. // sourceApp.Connect.sync.receive(data)
  129. // }
  130. // })
  131. }
  132. views.addEventListener('sendCameraData',(e)=>{ //同步右侧数据
  133. sourceApp.viewer.mainViewport.view.position.copy(e.data.position)
  134. sourceApp.viewer.mainViewport.view.lookAt(e.data.target)
  135. })
  136. const onModeChange = targetMode => {
  137. if (sourceApp) {
  138. sourceApp.loaded.then(sdk => sdk.scene.changeMode(targetMode))
  139. mode.value = targetMode
  140. }
  141. }
  142. const onPickDate = name => {
  143. if (name == 'target') {
  144. datepickValue.value = target.value.date.toDate()
  145. } else {
  146. datepickValue.value = source.value.date.toDate()
  147. }
  148. datepickName.value = name
  149. }
  150. const onPickClose = () => {
  151. datepickName.value = null
  152. datepickValue.value = null
  153. }
  154. const onSelected = payload => {
  155. if (!payload) {
  156. return
  157. }
  158. var date = payload.format('YYYY-mm-dd')
  159. var dates = highlighted.value.dates.map(item => item.format('YYYY-mm-dd'))
  160. if (dates.indexOf(date) != -1) {
  161. var find = scenes.find(c => c.date == date)
  162. if (find) {
  163. if (datepickName.value) {
  164. if (datepickName.value == 'all' || datepickName.value == 'source') {
  165. if (find.num != source.value.num) {
  166. source.value = find
  167. }
  168. } else if (datepickName.value == 'target') {
  169. if (find.num != target.value.num) {
  170. target.value = find
  171. }
  172. }
  173. } else {
  174. if (find.num != source.value.num) {
  175. source.value = find
  176. }
  177. }
  178. }
  179. }
  180. datepickName.value = null
  181. }
  182. const onCompare = () => {
  183. if (target.value) {
  184. target.value = null
  185. targetApp = null
  186. views.clear()
  187. return
  188. }
  189. let index = scenes.findIndex(item => item.num == source.value.num)
  190. if (index == -1) {
  191. return
  192. }
  193. if (++index > scenes.length - 1) {
  194. index = 0
  195. }
  196. target.value = scenes[index]
  197. }
  198. const onPrevDate = name => {
  199. let scene = null
  200. if (!name || name == 'source') {
  201. scene = source
  202. } else {
  203. scene = target
  204. }
  205. let index = scenes.findIndex(item => item.num == scene.value.num)
  206. if (index == -1) {
  207. return
  208. }
  209. if (--index == -1) {
  210. index = scenes.length - 1
  211. }
  212. // if (name) {
  213. // if (name == 'source') {
  214. // if (scenes[index].num == target.value.num) {
  215. // index--
  216. // }
  217. // } else {
  218. // if (scenes[index].num == source.value.num) {
  219. // index--
  220. // }
  221. // }
  222. // }
  223. // if (index == -1) {
  224. // index = scenes.length - 1
  225. // }
  226. scene.value = scenes[index]
  227. }
  228. const onNextDate = name => {
  229. let scene = null
  230. if (!name || name == 'source') {
  231. scene = source
  232. } else {
  233. scene = target
  234. }
  235. let index = scenes.findIndex(item => item.num == scene.value.num)
  236. if (index == -1) {
  237. return
  238. }
  239. if (++index > scenes.length - 1) {
  240. index = 0
  241. }
  242. // if (name) {
  243. // if (name == 'source') {
  244. // if (scenes[index].num == target.value.num) {
  245. // index++
  246. // }
  247. // } else {
  248. // if (scenes[index].num == source.value.num) {
  249. // index++
  250. // }
  251. // }
  252. // }
  253. // if (index > scenes.length - 1) {
  254. // index = 0
  255. // }
  256. scene.value = scenes[index]
  257. }
  258. onMounted(() => {
  259. project.value = projects[0]
  260. if (project.value) {
  261. source.value = scenes[2] //scenes.find(item => item.num == project.value.num)
  262. }
  263. })
  264. </script>
  265. <style lang="scss" scoped>
  266. header {
  267. height: 60px;
  268. background-color: rgba(0, 0, 0, 0.8);
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. font-size: 18px;
  273. }
  274. article {
  275. display: flex;
  276. width: 100%;
  277. height: 100%;
  278. overflow: hidden;
  279. }
  280. aside {
  281. width: 160px;
  282. height: 100%;
  283. background-color: rgba(0, 0, 0, 0.8);
  284. h4 {
  285. font-size: 16px;
  286. text-align: center;
  287. }
  288. ul {
  289. margin-top: 20px;
  290. }
  291. li {
  292. margin: 0;
  293. padding: 0;
  294. font-size: 16px;
  295. margin-left: 20px;
  296. cursor: pointer;
  297. &:hover,
  298. &.active {
  299. color: #00c8af;
  300. }
  301. }
  302. }
  303. main {
  304. flex: 1;
  305. width: 100%;
  306. height: 100%;
  307. position: relative;
  308. display: flex;
  309. &.full {
  310. .split {
  311. width: 50%;
  312. }
  313. }
  314. iframe {
  315. position: absolute;
  316. left: 0;
  317. top: 0;
  318. z-index: 1000;
  319. width: 100%;
  320. height: 100%;
  321. }
  322. .split {
  323. width: 100%;
  324. height: 100%;
  325. overflow: hidden;
  326. position: relative;
  327. .tools {
  328. width: 100%;
  329. padding-left: 20px;
  330. padding-right: 20px;
  331. justify-content: space-between;
  332. left: 0;
  333. transform: none;
  334. .item-mode {
  335. display: flex;
  336. align-items: center;
  337. justify-content: space-around;
  338. height: 34px;
  339. border-radius: 17px;
  340. background-color: rgba(0, 0, 0, 0.3);
  341. > div {
  342. position: relative;
  343. margin-left: 20px;
  344. margin-right: 20px;
  345. cursor: pointer;
  346. &.active {
  347. color: #00c8af;
  348. }
  349. }
  350. i {
  351. font-size: 18px;
  352. }
  353. }
  354. }
  355. }
  356. .tools {
  357. position: absolute;
  358. left: 50%;
  359. transform: translateX(-50%);
  360. bottom: 10px;
  361. z-index: 1000;
  362. display: flex;
  363. justify-content: center;
  364. align-items: center;
  365. color: #fff;
  366. i {
  367. font-size: 18px;
  368. }
  369. .item-date {
  370. position: relative;
  371. height: 34px;
  372. border-radius: 17px;
  373. background-color: rgba(0, 0, 0, 0.3);
  374. padding: 0 30px;
  375. display: flex;
  376. justify-content: center;
  377. align-items: center;
  378. margin-left: 10px;
  379. margin-right: 10px;
  380. span {
  381. cursor: pointer;
  382. }
  383. .prev,
  384. .next {
  385. position: absolute;
  386. left: 5px;
  387. }
  388. .next {
  389. left: auto;
  390. right: 5px;
  391. transform: rotate(180deg);
  392. }
  393. }
  394. .item-split {
  395. display: flex;
  396. justify-content: center;
  397. align-items: center;
  398. width: 34px;
  399. height: 34px;
  400. border-radius: 50%;
  401. background-color: rgba(0, 0, 0, 0.3);
  402. cursor: pointer;
  403. }
  404. }
  405. .popup {
  406. position: absolute;
  407. left: 0;
  408. top: 0;
  409. width: 100%;
  410. height: 100%;
  411. z-index: 1000;
  412. display: flex;
  413. align-items: center;
  414. justify-content: center;
  415. > div {
  416. position: relative;
  417. color: #444;
  418. span {
  419. position: absolute;
  420. right: -20px;
  421. top: -20px;
  422. cursor: pointer;
  423. background-color: rgba(0, 0, 0, 0.3);
  424. width: 24px;
  425. height: 24px;
  426. border-radius: 50%;
  427. z-index: 1000;
  428. display: flex;
  429. justify-content: center;
  430. align-items: center;
  431. color: #fff;
  432. }
  433. i {
  434. font-size: 12px;
  435. }
  436. }
  437. }
  438. }
  439. </style>
  440. <style lang="scss">
  441. #app {
  442. background-color: rgba(0, 0, 0, 0.8);
  443. display: flex;
  444. flex-direction: column;
  445. }
  446. .vuejs3-datepicker__calendar-topbar {
  447. display: none !important;
  448. }
  449. .highlighted {
  450. background: #4ebde1 !important;
  451. }
  452. .selected {
  453. background: #00c8af !important;
  454. }
  455. </style>