Panorama.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Codes from "./enum/Codes.js"
  2. import {eventsManager} from "./EventsManager.js"
  3. import util from "./util.js"
  4. import Logger from "./Logger.js"
  5. const logger = new Logger('panorama')
  6. export default class Panorama {
  7. constructor(e) {
  8. E(this, "_actived", !1);
  9. E(this, "handleReceivePanorama", async(e,t)=>{
  10. logger.warn("handle panorama", e.uuid, e.pos, e.finished);
  11. const r = {
  12. data: e.data,
  13. pose: {
  14. position: e.pos
  15. }
  16. }
  17. , n = this.room.sceneManager;
  18. if (this.room.networkController.rtcp.workers.changePanoMode(!0),
  19. await n.materialComponent.changePanoImg(0, r),
  20. !!e.finished)
  21. if (await n.changePanoShaderForLowModel(0),
  22. this.room.isPano = !0,
  23. this._actived = !0,
  24. t)
  25. this.room.sceneManager.cameraComponent.changeToFirstPersonView({
  26. position: t.position,
  27. rotation: t.angle
  28. });
  29. else {
  30. const {skinId: o, pathName: a} = this.room.currentState;
  31. if (!o || !a)
  32. return;
  33. const s = await this.room.modelManager.findRoute(o, a)
  34. , {camera: l} = util.getRandomItem(s.birthPointList) || {};
  35. l && this.room.sceneManager.cameraComponent.changeToFirstPersonView(le(oe({}, l), {
  36. rotation: l.angle
  37. }))
  38. }
  39. }
  40. );
  41. this.room = e
  42. }
  43. get actived() {
  44. return this._actived
  45. }
  46. bindListener(e) {
  47. this.room.networkController.rtcp.workers.registerFunction("panorama", r=>{
  48. logger.warn("receive panorama", r.uuid, r.pos),
  49. r.uuid && eventsManager.remove(r.uuid, Codes.Success, r, !0),
  50. this.room.isFirstDataUsed || (this.room.isFirstDataUsed = !0,
  51. this.handleReceivePanorama(r, this.room.options.camera).then(e))
  52. }
  53. )
  54. }
  55. access(e, t, r) {
  56. const {camera: n, player: o, attitude: a, areaName: s, pathName: l, tag: u} = e;
  57. return this.room.actionsHandler.requestPanorama({
  58. camera: n,
  59. player: o,
  60. attitude: a,
  61. areaName: s,
  62. pathName: l,
  63. tag: u
  64. }, t, r).then(c=>this.handleReceivePanorama(c, o))
  65. }
  66. exit(e) {
  67. const {camera: t, player: r, attitude: n, areaName: o, pathName: a} = e;
  68. return this.room.networkController.rtcp.workers.changePanoMode(!1),
  69. this.room.actionsHandler.changeRotationRenderType({
  70. renderType: RenderType.RotationVideo,
  71. player: r,
  72. camera: t,
  73. attitude: n,
  74. areaName: o,
  75. pathName: a
  76. }).then(()=>this.handleExitPanorama()).catch(s=>(this.room.networkController.rtcp.workers.changePanoMode(!0),
  77. Promise.reject(s)))
  78. }
  79. handleExitPanorama() {
  80. var e, t, r, n, o, a;
  81. this.room.isPano = !1,
  82. this._actived = !1,
  83. (n = (e = this.room.sceneManager) == null ? void 0 : e.cameraComponent) == null || n.forceChangeSavedCameraPose({
  84. position: (t = this.room._currentClickingState) == null ? void 0 : t.camera.position,
  85. rotation: (r = this.room._currentClickingState) == null ? void 0 : r.camera.angle
  86. }),
  87. this.room.sceneManager.changeVideoShaderForLowModel(),
  88. (a = (o = this.room.sceneManager) == null ? void 0 : o.cameraComponent) == null || a.changeToThirdPersonView()
  89. }
  90. }