最终效果录屏

所有开关和推拉门动画.mp4

概述

多个开关与门的联动实现需要将每个开关与对应的门进行绑定。

代码实现

在每一个开关的json中添加一个对象”glassDoor”,根据研究院室内实际情况,抽象出开关与门的关系:一个开关对应着两扇门,一扇门有两个路径动画(开门路径动画、关门路径动画),每一个关门动画都有自己的定时器。
将每扇门按照左右位置和开关index编号。
将每个路径动画按照左右位置、开关动作和开关index编号。
在门的json中使用以上编号标记每一扇门和每一个路径动画。

switchJson.js

  1. /*
  2. * "glassDoor": [
  3. {
  4. "doorRef": "leftDoor0",
  5. "pathRef": ["leftOpen0", "leftClose0"],
  6. "closeTimer": null
  7. },
  8. {
  9. "doorRef": "rightDoor0",
  10. "pathRef": ["rightOpen0", "rightClose0"],
  11. "closeTimer": null
  12. }
  13. ],
  14. */
  15. const switchJson = [
  16. {
  17. "ref": "switch0",
  18. "glassDoor": [
  19. {
  20. "doorRef": "leftDoor0", // 将每扇门按照左右位置和开关index编号
  21. "pathRef": ["leftOpen0", "leftClose0"], // 将每个路径动画按照左右位置、开关动作和开关index编号
  22. "closeTimer": null
  23. },
  24. {
  25. "doorRef": "rightDoor0",
  26. "pathRef": ["rightOpen0", "rightClose0"],
  27. "closeTimer": null
  28. }
  29. ],
  30. "czmObject": {
  31. "xbsjType": "Tileset",
  32. "xbsjGuid": "b7a4c6d4-23f3-474e-a828-f34264e40416",
  33. "name": "前台-开关",
  34. "url": "...", // 模型地址
  35. "xbsjPosition": [
  36. 2.0444499593823284,
  37. 0.6398407227372647,
  38. 184.3798550556327
  39. ],
  40. "xbsjRotation": [
  41. -0.3959951084942439,
  42. -0.08726646259971647,
  43. 0
  44. ],
  45. "xbsjScale": [
  46. 0.05,
  47. 0.04,
  48. 0.048
  49. ],
  50. "xbsjUseOriginTransform": false,
  51. "xbsjClippingPlanes": {},
  52. "xbsjCustomShader": {}
  53. }
  54. },
  55. {
  56. "ref": "switch1",
  57. "glassDoor": [
  58. {
  59. "doorRef": "leftDoor1",
  60. "pathRef": ["leftOpen1", "leftClose1"],
  61. "closeTimer": null
  62. },
  63. {
  64. "doorRef": "rightDoor1",
  65. "pathRef": ["rightOpen1", "rightClose1"],
  66. "closeTimer": null
  67. }
  68. ],
  69. "czmObject": {
  70. "xbsjType": "Tileset",
  71. "xbsjGuid": "f1e7c69f-dc49-4ae1-a7f4-e06de262b81a",
  72. "name": "东走廊-北开关",
  73. "url": "...", // 模型地址
  74. "xbsjPosition": [
  75. 2.0444524982375794,
  76. 0.6398415783390702,
  77. 184.60063585634657
  78. ],
  79. "xbsjRotation": [
  80. -0.3959951084942439,
  81. 0.08726646259971647,
  82. 0
  83. ],
  84. "xbsjScale": [
  85. 0.05,
  86. 0.04,
  87. 0.048
  88. ],
  89. "xbsjUseOriginTransform": false,
  90. "xbsjClippingPlanes": {},
  91. "xbsjCustomShader": {}
  92. }
  93. },
  94. {
  95. "ref": "switch2",
  96. "glassDoor": [
  97. {
  98. "doorRef": "leftDoor2",
  99. "pathRef": ["leftOpen2", "leftClose2"],
  100. "closeTimer": null
  101. },
  102. {
  103. "doorRef": "rightDoor2",
  104. "pathRef": ["rightOpen2", "rightClose2"],
  105. "closeTimer": null
  106. }
  107. ],
  108. "czmObject": {
  109. "xbsjType": "Tileset",
  110. "xbsjGuid": "a9ff6500-db41-4ac4-b625-ee1d230ca368",
  111. "name": "东走廊-南开关",
  112. "url": "...", // 模型地址
  113. "xbsjPosition": [
  114. 2.044453599997902,
  115. 0.6398394609856203,
  116. 184.641940963229
  117. ],
  118. "xbsjRotation": [
  119. -0.3959951084942439,
  120. 0.08726646259971647,
  121. 0
  122. ],
  123. "xbsjScale": [
  124. 0.05,
  125. 0.04,
  126. 0.048
  127. ],
  128. "xbsjUseOriginTransform": false,
  129. "xbsjClippingPlanes": {},
  130. "xbsjCustomShader": {}
  131. }
  132. },
  133. {
  134. "ref": "switch3",
  135. "glassDoor": [
  136. {
  137. "doorRef": "leftDoor3",
  138. "pathRef": ["leftOpen3", "leftClose3"],
  139. "closeTimer": null
  140. },
  141. {
  142. "doorRef": "rightDoor3",
  143. "pathRef": ["rightOpen3", "rightClose3"],
  144. "closeTimer": null
  145. }
  146. ],
  147. "czmObject": {
  148. "xbsjType": "Tileset",
  149. "xbsjGuid": "788772f1-7700-44fe-b88a-727125fb9574",
  150. "name": "展厅-开关",
  151. "url": "...", // 模型地址
  152. "xbsjPosition": [
  153. 2.044452536861528,
  154. 0.6398421616480751,
  155. 184.6179881832191
  156. ],
  157. "xbsjRotation": [
  158. -0.3959951084942439,
  159. 0.08726646259971647,
  160. 0
  161. ],
  162. "xbsjScale": [
  163. 0.05,
  164. 0.04,
  165. 0.048
  166. ],
  167. "xbsjUseOriginTransform": false,
  168. "xbsjClippingPlanes": {},
  169. "xbsjCustomShader": {}
  170. }
  171. }
  172. ];
  173. export default switchJson;

glassDoorJson.js

  1. // 前台接待处
  2. const reception = [
  3. {
  4. "ref": "leftDoor0",
  5. "czmObject": {
  6. "xbsjType": "Tileset",
  7. "xbsjGuid": "73ed68f3-1dc4-40e7-bddb-50a3e7be4bed",
  8. "name": "前台-左侧门",
  9. "url": "...", // 模型地址
  10. "xbsjPosition": [
  11. 2.044449816295,
  12. 0.6398410391053218,
  13. 181.25
  14. ],
  15. "xbsjRotation": [
  16. -0.3969407967416281,
  17. 0.014846137946110005,
  18. 0
  19. ],
  20. "xbsjScale": [
  21. 0.85,
  22. 0.88,
  23. 1
  24. ],
  25. "xbsjUseOriginTransform": false,
  26. "xbsjClippingPlanes": {},
  27. "xbsjCustomShader": {}
  28. }
  29. },{
  30. "ref": "leftOpen0",
  31. "czmObject": {
  32. "xbsjType": "Path",
  33. "xbsjGuid": "514fa82b-97c2-4c81-b87d-9a01d953ec3e",
  34. "name": "前台-左侧门-路径动画",
  35. "positions": [
  36. [
  37. 2.044449816295,
  38. 0.6398410391053218,
  39. 181.25
  40. ],
  41. [
  42. 2.0444497639740824,
  43. 0.6398411440696372,
  44. 181.25
  45. ]
  46. ],
  47. "rotations": [
  48. [
  49. 0,
  50. 0,
  51. 0
  52. ],
  53. [
  54. 0,
  55. 0,
  56. 0
  57. ]
  58. ],
  59. "currentSpeed": 1,
  60. "playing": false
  61. }
  62. },{
  63. "ref": "leftClose0",
  64. "czmObject": {
  65. "xbsjType": "Path",
  66. "xbsjGuid": "0a1e9f7e-18fb-4996-bd1a-1303a2fcc6cc",
  67. "name": "前台-左侧门-路径动画",
  68. "positions": [
  69. [
  70. 2.0444497639740824,
  71. 0.6398411440696372,
  72. 181.25
  73. ],
  74. [
  75. 2.044449816295,
  76. 0.6398410391053218,
  77. 181.25
  78. ]
  79. ],
  80. "rotations": [
  81. [
  82. 0,
  83. 0,
  84. 0
  85. ],
  86. [
  87. 0,
  88. 0,
  89. 0
  90. ]
  91. ],
  92. "currentSpeed": 1,
  93. "playing": false
  94. }
  95. },
  96. {
  97. "ref": "rightDoor0",
  98. "czmObject": {
  99. "xbsjType": "Tileset",
  100. "xbsjGuid": "293745c2-4160-488f-b785-549763654784",
  101. "name": "前台-右侧门",
  102. "url": "...", // 模型地址
  103. "xbsjPosition": [
  104. 2.044449875336235,
  105. 0.639840927184629,
  106. 181.25
  107. ],
  108. "xbsjRotation": [
  109. -0.39542618159920906,
  110. 0.015707963267948967,
  111. 0
  112. ],
  113. "xbsjScale": [
  114. 0.85,
  115. 0.88,
  116. 1
  117. ],
  118. "xbsjUseOriginTransform": false,
  119. "xbsjClippingPlanes": {},
  120. "xbsjCustomShader": {}
  121. }
  122. },{
  123. "ref": "rightOpen0",
  124. "czmObject": {
  125. "xbsjType": "Path",
  126. "xbsjGuid": "791ba4ac-a022-4f04-8e36-66dff64aa24d",
  127. "name": "前台-右侧门-路径动画",
  128. "positions": [
  129. [
  130. 2.044449875336235,
  131. 0.639840927184629,
  132. 181.25
  133. ],
  134. [
  135. 2.044449927731744,
  136. 0.639840822289407,
  137. 181.25
  138. ]
  139. ],
  140. "rotations": [
  141. [
  142. 0,
  143. 0,
  144. 0
  145. ],
  146. [
  147. 0,
  148. 0,
  149. 0
  150. ]
  151. ],
  152. "currentSpeed": 1,
  153. "playing": false
  154. }
  155. },{
  156. "ref": "rightClose0",
  157. "czmObject": {
  158. "xbsjType": "Path",
  159. "xbsjGuid": "feb278ee-7aea-448d-adf8-95078157a232",
  160. "name": "路径动画",
  161. "positions": [
  162. [
  163. 2.044449927731744,
  164. 0.639840822289407,
  165. 181.25
  166. ],
  167. [
  168. 2.044449875336235,
  169. 0.639840927184629,
  170. 181.25
  171. ]
  172. ],
  173. "rotations": [
  174. [
  175. 0,
  176. 0,
  177. 0
  178. ],
  179. [
  180. 0,
  181. 0,
  182. 0
  183. ]
  184. ],
  185. "currentSpeed": 1,
  186. "playing": false
  187. }
  188. }
  189. ];
  190. // 走廊北
  191. const corridor_north = [
  192. {
  193. "ref": "leftDoor1",
  194. "czmObject": {
  195. "xbsjType": "Tileset",
  196. "xbsjGuid": "86b8b0f7-903c-43b0-97f8-658f813b1721",
  197. "name": "东走廊北-左侧门",
  198. "url": "...", // 模型地址
  199. "xbsjPosition": [
  200. 2.0444523934162557,
  201. 0.6398417755615563,
  202. 181.46
  203. ],
  204. "xbsjRotation": [
  205. -0.3957096034349785,
  206. 0.015707963267948967,
  207. 0
  208. ],
  209. "xbsjScale": [
  210. 0.85,
  211. 0.87,
  212. 1
  213. ],
  214. "xbsjUseOriginTransform": false,
  215. "xbsjClippingPlanes": {},
  216. "xbsjCustomShader": {}
  217. }
  218. },
  219. {
  220. "ref": "leftOpen1",
  221. "czmObject": {
  222. "xbsjType": "Path",
  223. "xbsjGuid": "c8ebc7df-47d2-4370-ba7b-7d496ed08ab9",
  224. "name": "东走廊北-左侧门-路径动画",
  225. "positions": [
  226. [
  227. 2.0444523934162557,
  228. 0.6398417755615563,
  229. 181.46
  230. ],
  231. [
  232. 2.04445245106097,
  233. 0.6398416725678746,
  234. 181.46
  235. ]
  236. ],
  237. "rotations": [
  238. [
  239. 0,
  240. 0,
  241. 0
  242. ],
  243. [
  244. 0,
  245. 0,
  246. 0
  247. ]
  248. ],
  249. "currentSpeed": 1,
  250. "playing": false
  251. }
  252. },
  253. {
  254. "ref": "leftClose1",
  255. "czmObject": {
  256. "xbsjType": "Path",
  257. "xbsjGuid": "c8ebc7df-47d2-4370-ba7b-7d496ed08ab9",
  258. "name": "东走廊北-左侧门-路径动画",
  259. "positions": [
  260. [
  261. 2.04445245106097,
  262. 0.6398416725678746,
  263. 181.46
  264. ],
  265. [
  266. 2.0444523934162557,
  267. 0.6398417755615563,
  268. 181.46
  269. ]
  270. ],
  271. "rotations": [
  272. [
  273. 0,
  274. 0,
  275. 0
  276. ],
  277. [
  278. 0,
  279. 0,
  280. 0
  281. ]
  282. ],
  283. "currentSpeed": 1,
  284. "playing": false
  285. }
  286. },
  287. {
  288. "ref": "rightDoor1",
  289. "czmObject": {
  290. "xbsjType": "Tileset",
  291. "xbsjGuid": "13c9e958-d197-47dd-a205-0b8fe1e5bc5a",
  292. "name": "东走廊北-右侧门",
  293. "url": "...", // 模型地址
  294. "xbsjPosition": [
  295. 2.044452336345083,
  296. 0.6398418863587736,
  297. 181.46
  298. ],
  299. "xbsjRotation": [
  300. -0.3968314720420576,
  301. 0.015707963267948967,
  302. 0
  303. ],
  304. "xbsjScale": [
  305. 0.85,
  306. 0.87,
  307. 1
  308. ],
  309. "xbsjUseOriginTransform": false,
  310. "xbsjClippingPlanes": {},
  311. "xbsjCustomShader": {}
  312. }
  313. },
  314. {
  315. "ref": "rightOpen1",
  316. "czmObject": {
  317. "xbsjType": "Path",
  318. "xbsjGuid": "e20b70e4-3e61-4a54-a26f-ab15c3eae867",
  319. "name": "东走廊北-右侧门-路径动画",
  320. "positions": [
  321. [
  322. 2.044452336345083,
  323. 0.6398418863587736,
  324. 181.46
  325. ],
  326. [
  327. 2.044452284412869,
  328. 0.6398419926270578,
  329. 181.46
  330. ]
  331. ],
  332. "rotations": [
  333. [
  334. 0,
  335. 0,
  336. 0
  337. ],
  338. [
  339. 0,
  340. 0,
  341. 0
  342. ]
  343. ],
  344. "currentSpeed": 1,
  345. "playing": false
  346. }
  347. },
  348. {
  349. "ref": "rightClose1",
  350. "czmObject": {
  351. "xbsjType": "Path",
  352. "xbsjGuid": "e20b70e4-3e61-4a54-a26f-ab15c3eae867",
  353. "name": "东走廊北-右侧门-路径动画",
  354. "positions": [
  355. [
  356. 2.044452284412869,
  357. 0.6398419926270578,
  358. 181.46
  359. ],
  360. [
  361. 2.044452336345083,
  362. 0.6398418863587736,
  363. 181.46
  364. ]
  365. ],
  366. "rotations": [
  367. [
  368. 0,
  369. 0,
  370. 0
  371. ],
  372. [
  373. 0,
  374. 0,
  375. 0
  376. ]
  377. ],
  378. "currentSpeed": 1,
  379. "playing": false
  380. }
  381. }
  382. ];
  383. // 走廊南
  384. const corridor_south = [
  385. {
  386. "ref": "leftDoor2",
  387. "czmObject": {
  388. "xbsjType": "Tileset",
  389. "xbsjGuid": "bac20974-3f5f-4adb-b67c-5a5f820da2ee",
  390. "name": "东走廊南-左侧门",
  391. "url": "...", // 模型地址
  392. "xbsjPosition": [
  393. 2.044453497691577,
  394. 0.6398396591887818,
  395. 181.5
  396. ],
  397. "xbsjRotation": [
  398. -0.3949680776541822,
  399. 0.015707963267948967,
  400. 0
  401. ],
  402. "xbsjScale": [
  403. 0.85,
  404. 0.87,
  405. 1
  406. ],
  407. "xbsjUseOriginTransform": false,
  408. "xbsjClippingPlanes": {},
  409. "xbsjCustomShader": {}
  410. }
  411. },
  412. {
  413. "ref": "leftOpen2",
  414. "czmObject": {
  415. "xbsjType": "Path",
  416. "xbsjGuid": "8cc71244-4abb-4be3-8964-31c0f48dacf6",
  417. "name": "东走廊南-左侧门-路径动画",
  418. "positions": [
  419. [
  420. 2.044453497691577,
  421. 0.6398396591887818,
  422. 181.5
  423. ],
  424. [
  425. 2.044453551574043,
  426. 0.6398395546758482,
  427. 181.5
  428. ]
  429. ],
  430. "rotations": [
  431. [
  432. 0,
  433. 0,
  434. 0
  435. ],
  436. [
  437. 0,
  438. 0,
  439. 0
  440. ]
  441. ],
  442. "currentSpeed": 1,
  443. "playing": false
  444. }
  445. },
  446. {
  447. "ref": "leftClose2",
  448. "czmObject": {
  449. "xbsjType": "Path",
  450. "xbsjGuid": "8cc71244-4abb-4be3-8964-31c0f48dacf5",
  451. "name": "东走廊南-左侧门-路径动画",
  452. "positions": [
  453. [
  454. 2.044453551574043,
  455. 0.6398395546758482,
  456. 181.5
  457. ],
  458. [
  459. 2.044453497691577,
  460. 0.6398396591887818,
  461. 181.5
  462. ]
  463. ],
  464. "rotations": [
  465. [
  466. 0,
  467. 0,
  468. 0
  469. ],
  470. [
  471. 0,
  472. 0,
  473. 0
  474. ]
  475. ],
  476. "currentSpeed": 1,
  477. "playing": false
  478. }
  479. },
  480. {
  481. "ref": "rightDoor2",
  482. "czmObject": {
  483. "xbsjType": "Tileset",
  484. "xbsjGuid": "4463f2e9-d4a8-4ce2-b8fd-e27385ec90e7",
  485. "name": "东走廊南-右侧门",
  486. "url": "...", // 模型地址
  487. "xbsjPosition": [
  488. 2.0444534406343626,
  489. 0.6398397703102854,
  490. 181.5
  491. ],
  492. "xbsjRotation": [
  493. -0.39681226428802496,
  494. 0.015707963267948967,
  495. 0
  496. ],
  497. "xbsjScale": [
  498. 0.85,
  499. 0.87,
  500. 1
  501. ],
  502. "xbsjUseOriginTransform": false,
  503. "xbsjClippingPlanes": {},
  504. "xbsjCustomShader": {}
  505. }
  506. },
  507. {
  508. "ref": "rightOpen2",
  509. "czmObject": {
  510. "xbsjType": "Path",
  511. "xbsjGuid": "411b4964-1997-4106-a8fc-6d9e4c25040d",
  512. "name": "东走廊南-右侧门-路径动画",
  513. "positions": [
  514. [
  515. 2.0444534406343626,
  516. 0.6398397703102854,
  517. 181.5
  518. ],
  519. [
  520. 2.044453386062222,
  521. 0.6398398751956313,
  522. 181.5
  523. ]
  524. ],
  525. "rotations": [
  526. [
  527. 0,
  528. 0,
  529. 0
  530. ],
  531. [
  532. 0,
  533. 0,
  534. 0
  535. ]
  536. ],
  537. "currentSpeed": 1,
  538. "playing": false
  539. }
  540. },
  541. {
  542. "ref": "rightClose2",
  543. "czmObject": {
  544. "xbsjType": "Path",
  545. "xbsjGuid": "411b4964-1997-4106-a8fc-6d9e4c25040v",
  546. "name": "东走廊南-右侧门-路径动画",
  547. "positions": [
  548. [
  549. 2.044453386062222,
  550. 0.6398398751956313,
  551. 181.5
  552. ],
  553. [
  554. 2.0444534406343626,
  555. 0.6398397703102854,
  556. 181.5
  557. ]
  558. ],
  559. "rotations": [
  560. [
  561. 0,
  562. 0,
  563. 0
  564. ],
  565. [
  566. 0,
  567. 0,
  568. 0
  569. ]
  570. ],
  571. "currentSpeed": 1,
  572. "playing": false
  573. }
  574. }
  575. ];
  576. // 展厅
  577. const showroom = [
  578. {
  579. "ref": "leftDoor3",
  580. "czmObject": {
  581. "xbsjType": "Tileset",
  582. "xbsjGuid": "dcead727-1fa2-4cdf-8914-e85e633a60a1",
  583. "name": "展厅-左侧门",
  584. "url": "...", // 模型地址
  585. "xbsjPosition": [
  586. 2.04445265845087,
  587. 0.639841866217198,
  588. 181.51049512039936
  589. ],
  590. "xbsjRotation": [
  591. -0.3967670706393829,
  592. 0.015707963267948967,
  593. 0
  594. ],
  595. "xbsjScale": [
  596. 0.85,
  597. 0.87,
  598. 1
  599. ],
  600. "xbsjUseOriginTransform": false,
  601. "xbsjClippingPlanes": {},
  602. "xbsjCustomShader": {}
  603. }
  604. },
  605. {
  606. "ref": "leftOpen3",
  607. "czmObject": {
  608. "xbsjType": "Path",
  609. "xbsjGuid": "b5352dab-5d4b-41a8-b2fd-304eb936291b",
  610. "name": "展厅-左侧门-路径动画",
  611. "positions": [
  612. [
  613. 2.04445265845087,
  614. 0.639841866217198,
  615. 181.51049512039936
  616. ],
  617. [
  618. 2.0444527145178744,
  619. 0.6398417611322228,
  620. 181.51049512039936
  621. ]
  622. ],
  623. "rotations": [
  624. [
  625. 0,
  626. 0,
  627. 0
  628. ],
  629. [
  630. 0,
  631. 0,
  632. 0
  633. ]
  634. ],
  635. "currentSpeed": 1,
  636. "playing": false
  637. }
  638. },
  639. {
  640. "ref": "leftClose3",
  641. "czmObject": {
  642. "xbsjType": "Path",
  643. "xbsjGuid": "b5352dab-5d4b-41a8-b2fd-304eb936291a",
  644. "name": "展厅-左侧门-路径动画",
  645. "positions": [
  646. [
  647. 2.0444527145178744,
  648. 0.6398417611322228,
  649. 181.51049512039936
  650. ],
  651. [
  652. 2.04445265845087,
  653. 0.639841866217198,
  654. 181.51049512039936
  655. ]
  656. ],
  657. "rotations": [
  658. [
  659. 0,
  660. 0,
  661. 0
  662. ],
  663. [
  664. 0,
  665. 0,
  666. 0
  667. ]
  668. ],
  669. "currentSpeed": 1,
  670. "playing": false
  671. }
  672. },
  673. {
  674. "ref": "rightDoor3",
  675. "czmObject": {
  676. "xbsjType": "Tileset",
  677. "xbsjGuid": "7254984f-eef8-4b32-ab0b-6b1d20b678a8",
  678. "name": "展厅-右侧门",
  679. "url": "...", // 模型地址
  680. "xbsjPosition": [
  681. 2.0444526011030795,
  682. 0.6398419770744627,
  683. 181.51200448185625
  684. ],
  685. "xbsjRotation": [
  686. -0.3960921777795168,
  687. 0.015707963267948967,
  688. 0
  689. ],
  690. "xbsjScale": [
  691. 0.85,
  692. 0.87,
  693. 1
  694. ],
  695. "xbsjUseOriginTransform": false,
  696. "xbsjClippingPlanes": {},
  697. "xbsjCustomShader": {}
  698. }
  699. },
  700. {
  701. "ref": "rightOpen3",
  702. "czmObject": {
  703. "xbsjType": "Path",
  704. "xbsjGuid": "ec90227e-0b62-4867-8f0a-7a888fdb78f3",
  705. "name": "展厅-右侧门-路径动画",
  706. "positions": [
  707. [
  708. 2.0444526011030795,
  709. 0.6398419770744627,
  710. 181.51200448185625
  711. ],
  712. [
  713. 2.0444525492357384,
  714. 0.6398420829344057,
  715. 181.51200448185625
  716. ]
  717. ],
  718. "rotations": [
  719. [
  720. 0,
  721. 0,
  722. 0
  723. ],
  724. [
  725. 0,
  726. 0,
  727. 0
  728. ]
  729. ],
  730. "currentSpeed": 1,
  731. "playing": false
  732. }
  733. },
  734. {
  735. "ref": "rightClose3",
  736. "czmObject": {
  737. "xbsjType": "Path",
  738. "xbsjGuid": "ec90227e-0b62-4867-8f0a-7a888fdb78f5",
  739. "name": "展厅-右侧门-路径动画",
  740. "positions": [
  741. [
  742. 2.0444525492357384,
  743. 0.6398420829344057,
  744. 181.51200448185625
  745. ],
  746. [
  747. 2.0444526011030795,
  748. 0.6398419770744627,
  749. 181.51200448185625
  750. ]
  751. ],
  752. "rotations": [
  753. [
  754. 0,
  755. 0,
  756. 0
  757. ],
  758. [
  759. 0,
  760. 0,
  761. 0
  762. ]
  763. ],
  764. "currentSpeed": 1,
  765. "playing": false
  766. }
  767. }
  768. ];
  769. const glassDoorJson = [
  770. ...reception,
  771. ...corridor_north,
  772. ...corridor_south,
  773. ...showroom
  774. ];
  775. export default glassDoorJson;

deepblue_ani.js

由于角度加减多少度,需要在CesiumLab中尝试将模型移动、旋转后总结规律得出, 如果想所有的开关模型都使用这个方法计算角度,那么在模型制作时,必须保证模型的尺寸一致,缩放一致

  1. import switchJson from '@/constant/switchJson';
  2. let openDoor = false;
  3. let switchTimer = null;
  4. // 室内模型-玻璃门 开门 动画
  5. export function openDoorAnimation (earth, modelArr) {
  6. modelArr.forEach((item)=>{
  7. const model = earth.sceneTree.$refs[item.doorRef].czmObject;
  8. const path = earth.sceneTree.$refs[item.pathRef[0]].czmObject;
  9. if (model.xbsjPosition[1] !== path.positions[1][1] && openDoor) {
  10. path.playing = true;
  11. XE.MVVM.watch(path, 'currentPosition', position => {
  12. model.xbsjPosition = [...position];
  13. });
  14. }
  15. });
  16. }
  17. // 室内模型-玻璃门 关门 动画
  18. export function closeDoorAnimation (earth, modelArr) {
  19. modelArr.forEach((item)=>{
  20. const model = earth.sceneTree.$refs[item.doorRef].czmObject;
  21. const path = earth.sceneTree.$refs[item.pathRef[1]].czmObject;
  22. if(item.closeTimer) {
  23. clearTimeout(item.closeTimer)
  24. }
  25. if (model.xbsjPosition[1] !== path.positions[1][1] && !openDoor) {
  26. item.closeTimer = setTimeout(()=>{
  27. path.playing = true;
  28. XE.MVVM.watch(path, 'currentPosition', position => {
  29. model.xbsjPosition = [...position];
  30. })
  31. }, 5000)
  32. }
  33. });
  34. }
  35. // 室内模型-开关 按下动画
  36. export function switchAnimation (earth) {
  37. const switchObj = [];
  38. let switchRef = "";
  39. switchJson.forEach((item,index)=>{
  40. switchRef = `switch${index}`;
  41. switchObj.push({
  42. switch: earth.sceneTree.$refs[switchRef].czmObject,
  43. door: item.glassDoor
  44. });
  45. });
  46. switchObj.forEach((item)=>{
  47. /*
  48. * 将开关模型变化之前的rotation和position拷贝一份,
  49. * 需要将开关模型恢复原位时赋值即可
  50. * 使用...解构赋值是因为...是浅拷贝,不受原值变化的影响
  51. */
  52. const oldRotation = [...item.switch.xbsjRotation];
  53. const oldPosition = [...item.switch.xbsjPosition];
  54. // 弧度转角度
  55. item.xdegree = Number((oldPosition[0] / Math.PI * 180).toFixed(7));
  56. item.ydegree = Number((oldPosition[1] / Math.PI * 180).toFixed(8));
  57. item.switch.onclick = () => {
  58. if (switchTimer) {
  59. clearTimeout(switchTimer)
  60. }
  61. openDoor = true;
  62. item.switch.xbsjRotation[1] = -item.switch.xbsjRotation[1];
  63. // 角度加减多少度,需要在CesiumLab中尝试将模型移动、旋转后总结规律得出
  64. // 如果想所有的开关模型都使用这个方法计算角度,那么在模型制作时,必须保证模型的尺寸一致,缩放一致
  65. if (item.switch.xbsjRotation[1] < 0) {
  66. item.xdegree -= 0.0000002;
  67. item.ydegree -= 0.00000006;
  68. } else {
  69. item.xdegree += 0.0000002;
  70. item.ydegree += 0.00000007;
  71. }
  72. // 角度转弧度
  73. item.switch.xbsjPosition[0] = item.xdegree / 180 * Math.PI;
  74. item.switch.xbsjPosition[1] = item.ydegree / 180 * Math.PI;
  75. openDoorAnimation(earth, item.door);
  76. switchTimer = setTimeout(()=>{
  77. // 开关模型恢复原位时,需要将所有变化的值赋值为初始值
  78. item.switch.xbsjRotation = oldRotation;
  79. item.switch.xbsjPosition = oldPosition;
  80. item.xdegree = Number((oldPosition[0] / Math.PI * 180).toFixed(7));
  81. item.ydegree = Number((oldPosition[1] / Math.PI * 180).toFixed(8));
  82. openDoor = false;
  83. closeDoorAnimation(earth, item.door);
  84. }, 500);
  85. }
  86. });
  87. }

index.js

  1. /* index.js */
  2. import deepblueLeafJson from '@/constant/deepblueJson'; // 引入路径可根据实际情况调整
  3. import switchJson from '@/constant/switchJson'; // 引入路径可根据实际情况调整
  4. import glassDoorJson from '@/constant/glassDoorJson'; // 引入路径可根据实际情况调整
  5. import { switchAnimation } from '@/pages/DigitalTwin/deepblue_ani'; // 引入路径可根据实际情况调整
  6. class animationDemo extends Component{
  7. constructor(props) {
  8. super(props);
  9. this.earth = null;
  10. },
  11. componentDidMount() {
  12. XE.ready().then(()=>{
  13. // 加载标绘插件 js
  14. ...
  15. }).then(()=>{
  16. this.startUp();
  17. })
  18. },
  19. startUp = ()=>{
  20. // 创建 Earth实例
  21. this.earth = new XE.Earth("earthContainer");
  22. // 开启拾取(鼠标点击事件)
  23. this.earth.interaction.picking.enabled = true;
  24. // 通过JSON配置创建节点
  25. this.earth.sceneTree.root.children.push(...deepblueLeafJson, ...switchJson, ...glassDoorJson);
  26. switchAnimation(this.earth);
  27. }
  28. return (
  29. <div id="earthContainer"></div>
  30. )
  31. }
  32. export default animationDemo;