@realsee/vreo 0.2.0-alpha.16 → 0.2.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/docs/assets/highlight.css +1 -1
  3. package/docs/assets/main.js +2 -2
  4. package/docs/assets/search.js +1 -1
  5. package/docs/assets/style.css +28 -2
  6. package/docs/classes/Player.AudioLike.html +7 -7
  7. package/docs/classes/Player.Controller.html +8 -8
  8. package/docs/classes/Player.Player-1.html +6 -6
  9. package/docs/classes/Player.VideoAgentMesh.html +52 -52
  10. package/docs/classes/Player.VideoAgentScene.html +1 -1
  11. package/docs/demo/assets/AppReact.10c53460.js +1 -0
  12. package/docs/demo/assets/AppReact.3778df98.js +1 -0
  13. package/docs/demo/assets/default.03c59a9e.js +3952 -0
  14. package/docs/demo/assets/default.19fbc6cf.js +3952 -0
  15. package/docs/demo/assets/default.55c3f308.css +1 -0
  16. package/docs/demo/assets/default.ba6e9412.css +1 -0
  17. package/docs/demo/assets/dynamic.63886cda.js +1 -0
  18. package/docs/demo/assets/dynamic.74fff6a1.js +1 -0
  19. package/docs/demo/assets/{examples.4104efd4.js → examples.960e21f5.js} +2 -2
  20. package/docs/demo/assets/examples.b031a050.js +25 -0
  21. package/docs/demo/assets/examples.b3de04c9.js +25 -0
  22. package/docs/demo/assets/index.c8252302.js +1 -0
  23. package/docs/demo/assets/index.d79aab1a.js +1 -0
  24. package/docs/demo/assets/main.4104126d.js +1 -0
  25. package/docs/demo/assets/main.46c544c8.js +1 -0
  26. package/docs/demo/assets/{react.98c8f46f.js → react.465bd89e.js} +2 -2
  27. package/docs/demo/assets/react.53ec05f2.js +25 -0
  28. package/docs/demo/assets/react.855b3d23.css +1 -0
  29. package/docs/demo/examples.html +3 -4
  30. package/docs/demo/index-react-dynamic.html +5 -6
  31. package/docs/demo/index-react.html +6 -7
  32. package/docs/demo/index.html +4 -5
  33. package/docs/enums/Player.InfoPanelStyleEnum.html +1 -1
  34. package/docs/enums/Player.InfoPanelTypeEnum.html +2 -2
  35. package/docs/enums/Player.PanoEffectEnum.html +2 -2
  36. package/docs/enums/Player.PanoTagEnum.html +2 -2
  37. package/docs/enums/Player.PanoTagStyleEnum.html +3 -3
  38. package/docs/enums/Player.VreoKeyframeEnum.html +12 -12
  39. package/docs/enums/fivePlugins.CameraMovementEffect.html +1 -1
  40. package/docs/enums/fivePlugins.Rotation.html +1 -1
  41. package/docs/index.html +1 -1
  42. package/docs/interfaces/Player.CustomVreoKeyframeProps.html +1 -1
  43. package/docs/interfaces/Player.PlayerConfigs.html +2 -2
  44. package/docs/interfaces/Player.Vertex.html +2 -2
  45. package/docs/interfaces/Player.VideoAgentMeshOptions.html +5 -5
  46. package/docs/interfaces/Player.VreoKeyframe.html +2 -2
  47. package/docs/interfaces/Player.VreoUnit.html +2 -2
  48. package/docs/interfaces/Player.VreoVideo.html +2 -2
  49. package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +2 -2
  50. package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +1 -1
  51. package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +2 -2
  52. package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +1 -1
  53. package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +1 -1
  54. package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +1 -1
  55. package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +1 -1
  56. package/docs/interfaces/fivePlugins.Vector3Position.html +2 -2
  57. package/docs/interfaces/react.VreoActionCallbacks.html +7 -7
  58. package/docs/interfaces/react.VreoProviderProps.html +1 -1
  59. package/docs/modules/Player.html +16 -16
  60. package/docs/modules/custom.html +1 -1
  61. package/docs/modules/fivePlugins.html +3 -3
  62. package/docs/modules/react.html +1 -1
  63. package/docs/modules.html +1 -1
  64. package/lib/PlayController/index.js +3 -3
  65. package/lib/Player/App.js +1 -1
  66. package/lib/Player/Controller.d.ts +2 -0
  67. package/lib/Player/Controller.js +24 -5
  68. package/lib/Player/custom/SpatialScenePanel/index.js +1 -1
  69. package/lib/Player/index.d.ts +1 -0
  70. package/lib/Player/index.js +44 -9
  71. package/lib/Player/modules/Drawer/index.js +1 -1
  72. package/lib/Player/modules/PopUp/index.js +1 -1
  73. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +2 -2
  74. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +16 -8
  75. package/lib/Player/modules/VideoAgent/VideoAgentScene.js +7 -3
  76. package/lib/Player/modules/VideoAgent/index.js +1 -1
  77. package/lib/Player/modules/keyframes/BgMusic/index.js +1 -1
  78. package/lib/Player/modules/keyframes/CameraMovement/index.js +1 -1
  79. package/lib/Player/modules/keyframes/InfoPanel/index.js +1 -1
  80. package/lib/Player/modules/keyframes/ModelVideo/index.js +1 -1
  81. package/lib/Player/modules/keyframes/PanoEffect/index.js +1 -1
  82. package/lib/Player/modules/keyframes/PanoEffect/lineAnime.js +1 -1
  83. package/lib/Player/modules/keyframes/PanoTag/index.js +1 -1
  84. package/lib/Player/modules/keyframes/PanoTextLabel/index.js +1 -1
  85. package/lib/Player/modules/keyframes/Prompter/index.js +1 -1
  86. package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +1 -1
  87. package/lib/Player/modules/keyframes/VideoEffect/index.js +1 -1
  88. package/lib/fivePlugins/CSS3DRenderPlugin/index.js +1 -1
  89. package/lib/fivePlugins/ModelTVVideoPlugin/index.js +1 -1
  90. package/lib/react/index.js +1 -1
  91. package/lib/shared-utils/AduioLike.js +3 -3
  92. package/lib/shared-utils/animationFrame/BetterTween.js +7 -3
  93. package/lib/shared-utils/animationFrame/tween.js +1 -1
  94. package/lib/shared-utils/createTransMatrix.js +1 -1
  95. package/lib/typings/VreoUnit.d.ts +1 -0
  96. package/package.json +3 -2
  97. package/resources/Player/Controller.ts +149 -129
  98. package/resources/Player/index.tsx +169 -153
  99. package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +10 -4
  100. package/resources/typings/VreoUnit.ts +2 -0
  101. package/stylesheets/default.css +8 -3
  102. package/docs/demo/assets/AppReact.2978a2aa.js +0 -1
  103. package/docs/demo/assets/default.0c3b245d.js +0 -64
  104. package/docs/demo/assets/default.70243c83.css +0 -1
  105. package/docs/demo/assets/dynamic.37c058ac.js +0 -1
  106. package/docs/demo/assets/index.863d264e.js +0 -1
  107. package/docs/demo/assets/main.f8c52f62.js +0 -1
  108. package/docs/demo/assets/react.aa3cf7f7.css +0 -1
  109. package/docs/demo/assets/vendor.f4c5cb32.js +0 -3902
@@ -11,158 +11,178 @@ import { PlayerConfigs } from './typings'
11
11
  */
12
12
  export class Controller extends Subscribe<VreoKeyframeEvent> {
13
13
 
14
- $five?: Five
15
- configs?: PlayerConfigs
16
- videoAgentScene?: VideoAgentScene
17
- vreoUnit?: VreoUnit
18
- stopInterval?: () => void
19
- playing = false
14
+ $five?: Five
15
+ configs?: PlayerConfigs
16
+ videoAgentScene?: VideoAgentScene
17
+ vreoUnit?: VreoUnit
18
+ stopInterval?: () => void
19
+ playing = false
20
+ ended = false
21
+
22
+ visible = false
23
+
24
+ get isAudio() {
25
+ return !this.videoAgentScene?.videoAgentMesh.videoUrl?.endsWith('.mp4')
26
+ }
20
27
 
21
- visible = false
28
+ popUp: string | JSX.Element | null = null
22
29
 
23
- get isAudio() {
24
- return !this.videoAgentScene?.videoAgentMesh.videoUrl?.endsWith('.mp4')
25
- }
30
+ openPopUp(popUp: string | JSX.Element | false) {
31
+ if (!popUp) {
32
+ this.popUp = null
33
+ return
34
+ }
35
+ this.popUp = popUp
36
+ }
26
37
 
27
- popUp: string | JSX.Element | null = null
38
+ drawerConfig: {
39
+ content: string | JSX.Element
40
+ height?: number | string
41
+ } | null = null
28
42
 
29
- openPopUp(popUp: string | JSX.Element | false) {
30
- if (!popUp) {
31
- this.popUp = null
32
- return
33
- }
34
- this.popUp = popUp
35
- }
36
-
37
- drawerConfig: {
38
- content: string | JSX.Element
39
- height?: number | string
40
- } | null = null
41
-
42
- setVisible(v: boolean) {
43
- this.visible = v
44
- }
45
-
46
- setPlaying(playing: boolean) {
47
- this.playing = playing
48
- }
49
-
50
- openDrawer(drawerConfig?: false | { content: string | JSX.Element; height?: number | string }) {
51
- if (!drawerConfig) {
52
- this.drawerConfig = {
53
- content: '',
54
- height: this.drawerConfig?.height
55
- }
56
- return
43
+ setVisible(v: boolean) {
44
+ this.visible = v
57
45
  }
58
46
 
59
- this.drawerConfig = drawerConfig
60
- }
61
-
62
- constructor() {
63
- super()
64
-
65
- makeObservable(this, {
66
- visible: observable,
67
- setVisible: action,
68
- playing: observable,
69
- setPlaying: action,
70
- popUp: observable.ref,
71
- openPopUp: action,
72
- drawerConfig: observable.ref,
73
- openDrawer: action,
74
- })
75
-
76
- // 监听播放情况:抛出触发时机
77
- reaction(
78
- () => this.playing,
79
- (playing) => {
80
- this.emit(playing ? 'playing' : 'paused')
81
- }
82
- )
83
- }
84
-
85
- get ready() {
86
- return !!this.videoAgentScene
87
- }
88
-
89
- get currentTime() {
90
- return this.videoAgentScene?.videoAgentMesh.currentTime || 0
91
- }
92
-
93
- get currentKeyframes() {
94
- if (!this.vreoUnit) return []
95
- const keyframes = this.vreoUnit.keyframes
96
- // 没有被解析过且开始时间低于当前时间戳 100ms
97
- return keyframes.filter((keyframe: VreoKeyframe) => {
98
- if (keyframe.parsed) return false
99
- const dur = this.currentTime - keyframe.start
100
- return dur <= 100 && dur >= 0
101
- })
102
- }
103
-
104
- get videoInstance() {
105
- return this.videoAgentScene?.videoAgentMesh.videoInstance
106
- }
107
-
108
- /**
109
- * 逐帧任务
110
- */
111
- requestAnimationFrameLoop(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
112
- if (this.videoInstance?.ended) {
113
- this.setPlaying(false)
114
- this.videoInstance.pause()
115
- return
47
+ setPlaying(playing: boolean) {
48
+ this.playing = playing
116
49
  }
117
50
 
118
- if (!this.playing) {
119
- if (!this.videoInstance?.paused) {
120
- this.videoInstance?.pause()
121
- }
122
- return
51
+ setEnded(ended: boolean) {
52
+ this.ended = ended
123
53
  }
124
54
 
125
- if (this.videoInstance?.paused && this.playing) {
126
- this.videoInstance.play()
55
+ openDrawer(drawerConfig?: false | { content: string | JSX.Element; height?: number | string }) {
56
+ if (!drawerConfig) {
57
+ this.drawerConfig = {
58
+ content: '',
59
+ height: this.drawerConfig?.height
60
+ }
61
+ return
62
+ }
63
+
64
+ this.drawerConfig = drawerConfig
127
65
  }
128
66
 
129
- const currentKeyframes = this.currentKeyframes
67
+ constructor() {
68
+ super()
69
+
70
+ makeObservable(this, {
71
+ visible: observable,
72
+ setVisible: action,
73
+ playing: observable,
74
+ setPlaying: action,
75
+ popUp: observable.ref,
76
+ openPopUp: action,
77
+ drawerConfig: observable.ref,
78
+ openDrawer: action,
79
+ ended: observable,
80
+ setEnded: action
81
+ })
82
+
83
+ // 监听播放情况:抛出触发时机
84
+ reaction(
85
+ () => this.ended,
86
+ (ended) => {
87
+ if (ended) {
88
+ this.emit('paused', true)
89
+ }
90
+ }
91
+ )
92
+
93
+ reaction(
94
+ () => this.playing,
95
+ (playing) => {
96
+ if (!this.ended) {
97
+ this.emit(playing ? 'playing' : 'paused')
98
+ }
99
+ }
100
+ )
130
101
 
131
- currentKeyframes.forEach((keyframe) => {
132
- if (keyframe.parsed) return
133
- keyframe.parsed = true
134
- this.emit(keyframe.type, keyframe)
135
- if (callback) {
136
- callback(keyframe.type, keyframe)
137
- }
138
- })
139
- }
102
+ }
140
103
 
141
- run(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
142
- if (this.stopInterval) return
143
- this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop(callback))
144
- }
104
+ get ready() {
105
+ return !!this.videoAgentScene
106
+ }
145
107
 
146
- dispose() {
147
- this.setPlaying(false)
108
+ get currentTime() {
109
+ return this.videoAgentScene?.videoAgentMesh.currentTime || 0
110
+ }
111
+
112
+ get currentKeyframes() {
113
+ if (!this.vreoUnit) return []
114
+ const keyframes = this.vreoUnit.keyframes
115
+ // 没有被解析过且开始时间低于当前时间戳 100ms
116
+ return keyframes.filter((keyframe: VreoKeyframe) => {
117
+ if (keyframe.parsed) return false
118
+ const dur = this.currentTime - keyframe.start
119
+ return dur <= 100 && dur >= 0
120
+ })
121
+ }
148
122
 
149
- if (this.currentKeyframes) {
150
- this.currentKeyframes.forEach((keyframe) => (keyframe.parsed = false))
123
+ get videoInstance() {
124
+ return this.videoAgentScene?.videoAgentMesh.videoInstance
151
125
  }
152
126
 
153
127
  /**
154
- * 清理掉数据
128
+ * 逐帧任务
155
129
  */
156
- this.vreoUnit = undefined
157
- if (this.videoInstance) {
158
- this.videoInstance.currentTime = 0
130
+ requestAnimationFrameLoop(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
131
+ if (this.videoInstance?.ended) {
132
+ this.setEnded(true)
133
+ this.setPlaying(false)
134
+ this.videoInstance.pause()
135
+ return
136
+ }
137
+
138
+ if (!this.playing) {
139
+ if (!this.videoInstance?.paused) {
140
+ this.videoInstance?.pause()
141
+ }
142
+ return
143
+ }
144
+
145
+ if (this.videoInstance?.paused && this.playing) {
146
+ this.videoInstance.play()
147
+ }
148
+
149
+ const currentKeyframes = this.currentKeyframes
150
+
151
+ currentKeyframes.forEach((keyframe) => {
152
+ if (keyframe.parsed) return
153
+ keyframe.parsed = true
154
+ this.emit(keyframe.type, keyframe)
155
+ if (callback) {
156
+ callback(keyframe.type, keyframe)
157
+ }
158
+ })
159
+ }
160
+
161
+ run(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
162
+ if (this.stopInterval) return
163
+ this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop(callback))
159
164
  }
160
165
 
161
- if (this.stopInterval) {
162
- this.stopInterval()
163
- this.stopInterval = undefined
166
+ dispose() {
167
+ this.setPlaying(false)
168
+
169
+ if (this.currentKeyframes) {
170
+ this.currentKeyframes.forEach((keyframe) => (keyframe.parsed = false))
171
+ }
172
+
173
+ /**
174
+ * 清理掉数据
175
+ */
176
+ this.vreoUnit = undefined
177
+ if (this.videoInstance) {
178
+ this.videoInstance.currentTime = 0
179
+ }
180
+
181
+ if (this.stopInterval) {
182
+ this.stopInterval()
183
+ this.stopInterval = undefined
184
+ }
164
185
  }
165
- }
166
186
  }
167
187
 
168
188
  export const ControllerContext = React.createContext<Controller | null>(null)
@@ -11,175 +11,191 @@ import { PlayerConfigs } from './typings'
11
11
  import { PopUp } from './modules/PopUp'
12
12
 
13
13
  export class Player extends Subscribe<VreoKeyframeEvent> {
14
- $five: Five
15
- private controller: Controller
16
- configs: Readonly<PlayerConfigs>
17
-
18
- constructor(five: Five, configs: Partial<PlayerConfigs> = {}) {
19
- super()
20
- this.controller = new Controller()
21
- this.$five = this.controller.$five = five
22
-
23
- if (!configs.containter) {
24
- const containter = document.querySelector('#vreo-app') || document.createElement('div')
25
- ReactDOM.unmountComponentAtNode(containter)
26
- containter.setAttribute('id', 'vreo-app')
27
- configs.containter = containter
28
- document.body.append(containter)
14
+ $five: Five
15
+ private controller: Controller
16
+ configs: Readonly<PlayerConfigs>
17
+
18
+ constructor(five: Five, configs: Partial<PlayerConfigs> = {}) {
19
+ super()
20
+ this.controller = new Controller()
21
+ this.$five = this.controller.$five = five
22
+
23
+ if (!configs.containter) {
24
+ const containter = document.getElementById('vreo-app') || document.createElement('div')
25
+ ReactDOM.unmountComponentAtNode(containter)
26
+ containter.setAttribute('id', 'vreo-app')
27
+ configs.containter = containter
28
+ const fiveCanvasDomParent = five.getElement()?.parentNode
29
+ if (fiveCanvasDomParent) {
30
+ fiveCanvasDomParent.append(containter)
31
+ } else {
32
+ document.body.append(containter)
33
+ }
34
+ // document.body.append(containter)
35
+ }
36
+
37
+ this.configs = Object.freeze(
38
+ Object.assign(
39
+ {
40
+ keyframeMap: {},
41
+ },
42
+ configs
43
+ )
44
+ )
45
+
46
+ this.controller.configs = this.configs
47
+
48
+ ReactDOM.render(
49
+ <ControllerContext.Provider value={this.controller}>
50
+ <App />
51
+ <Drawer />
52
+ <PopUp />
53
+ {this.configs.customKeyframes &&
54
+ this.configs.customKeyframes.map((CustomCmpt, key) => (
55
+ <CustomCmpt
56
+ key={key}
57
+ subscribe={{
58
+ on: (name, callback) => this.on(name, callback),
59
+ once: (name, callback) => this.once(name, callback),
60
+ off: (name, callback) => this.off(name, callback),
61
+ }}
62
+ five={five}
63
+ />
64
+ ))}
65
+ </ControllerContext.Provider>,
66
+ configs.containter
67
+ )
68
+
69
+ // 监听播放情况:抛出触发时机
70
+ reaction(
71
+ () => [this.controller.playing, this.controller.ended],
72
+ ([playing, ended]) => {
73
+ if (ended) {
74
+ this.emit('paused', true)
75
+ } else {
76
+ this.emit(playing ? 'playing' : 'paused')
77
+ }
78
+ }
79
+ )
29
80
  }
30
81
 
31
- this.configs = Object.freeze(
32
- Object.assign(
33
- {
34
- keyframeMap: {},
35
- },
36
- configs
37
- )
38
- )
39
-
40
- this.controller.configs = this.configs
41
-
42
- ReactDOM.render(
43
- <ControllerContext.Provider value={this.controller}>
44
- <App />
45
- <Drawer />
46
- <PopUp />
47
- {this.configs.customKeyframes &&
48
- this.configs.customKeyframes.map((CustomCmpt, key) => (
49
- <CustomCmpt
50
- key={key}
51
- subscribe={{
52
- on: (name, callback) => this.on(name, callback),
53
- once: (name, callback) => this.once(name, callback),
54
- off: (name, callback) => this.off(name, callback),
55
- }}
56
- five={five}
57
- />
58
- ))}
59
- </ControllerContext.Provider>,
60
- configs.containter
61
- )
62
-
63
- // 监听播放情况:抛出触发时机
64
- reaction(
65
- () => this.controller.playing,
66
- (playing) => {
67
- this.emit(playing ? 'playing' : 'paused')
68
- }
69
- )
70
- }
71
-
72
- async load(vreoUnit: VreoUnit, currentTime = 0, preload = false, force = false) {
73
- if (force) {
74
- vreoUnit = JSON.parse(JSON.stringify(vreoUnit))
75
- }
76
- if (!this.controller.visible) {
77
- this.controller.setVisible(true)
78
- // 延迟 500ms 规避跟 DOM 动画冲突
79
- await new Promise((resolve) => {
80
- setTimeout(() => resolve(true), 500)
81
- })
82
+ async load(vreoUnit: VreoUnit, currentTime = 0, preload = false, force = false) {
83
+ if (force) {
84
+ vreoUnit = JSON.parse(JSON.stringify(vreoUnit))
85
+ }
86
+ if (!this.controller.visible) {
87
+ this.controller.setVisible(true)
88
+ // 延迟 500ms 规避跟 DOM 动画冲突
89
+ await new Promise((resolve) => {
90
+ setTimeout(() => resolve(true), 500)
91
+ })
92
+ }
93
+
94
+ if (this.controller.stopInterval) {
95
+ this.controller.stopInterval()
96
+ this.controller.stopInterval = undefined
97
+ }
98
+
99
+ this.controller.vreoUnit = vreoUnit
100
+ this.controller.videoInstance?.pause()
101
+
102
+ // 预载逻辑
103
+ // 是否降低图片分辨率
104
+ if (
105
+ this.$five.imageOptions.size &&
106
+ this.configs.imageOptions?.size &&
107
+ this.$five.imageOptions.size > this.configs.imageOptions.size
108
+ ) {
109
+ this.$five.imageOptions.size = this.configs.imageOptions.size
110
+ }
111
+
112
+ // 预载数据中的点位
113
+ if (preload || (preload === undefined && this.configs.autoPreload)) {
114
+ const panoIndexMap = vreoUnit.keyframes
115
+ .filter((vreoKeyframe) => {
116
+ if (vreoKeyframe.type !== VreoKeyframeEnum.CameraMovement) {
117
+ return false
118
+ }
119
+
120
+ const data = vreoKeyframe.data as CameraMovementData
121
+ if (data.panoIndex === undefined) {
122
+ return false
123
+ }
124
+ return true
125
+ })
126
+ .reduce((accu: Record<number, boolean>, curr) => {
127
+ const panoIndex = curr.data.panoIndex as number
128
+ if (!accu[panoIndex]) {
129
+ accu[panoIndex] = true
130
+ }
131
+ return accu
132
+ }, {})
133
+
134
+ const panoIndexs = Object.keys(panoIndexMap)
135
+ for (let i = 0; i < panoIndexs.length; i++) {
136
+ await this.$five.preloadPano(Number(panoIndexs[i]))
137
+ }
138
+ }
139
+
140
+ // 新数据载入就绪
141
+ this.emit('loaded', vreoUnit)
142
+ this.controller.emit('loaded', vreoUnit)
143
+
144
+ if (this.controller.videoAgentScene?.videoAgentMesh.videoInstance) {
145
+ this.controller.videoAgentScene.videoAgentMesh.videoInstance.currentTime = currentTime / 1000
146
+ }
147
+ await this.controller.videoAgentScene?.videoAgentMesh.play(
148
+ vreoUnit.video.url,
149
+ currentTime / 1000,
150
+ vreoUnit.video.duration
151
+ )
152
+
153
+ this.controller.setEnded(false)
154
+ this.play()
155
+
156
+ this.controller.run((type, keyframe) => this.emit(type, keyframe))
157
+ return true
82
158
  }
83
159
 
84
- if (this.controller.stopInterval) {
85
- this.controller.stopInterval()
86
- this.controller.stopInterval = undefined
160
+ get paused() {
161
+ return !this.controller.playing
87
162
  }
88
163
 
89
- this.controller.vreoUnit = vreoUnit
90
- this.controller.videoInstance?.pause()
91
-
92
- // 预载逻辑
93
- // 是否降低图片分辨率
94
- if (
95
- this.$five.imageOptions.size &&
96
- this.configs.imageOptions?.size &&
97
- this.$five.imageOptions.size > this.configs.imageOptions.size
98
- ) {
99
- this.$five.imageOptions.size = this.configs.imageOptions.size
100
- }
164
+ play(currentTime?: number) {
165
+ if (this.controller.playing) return true
166
+ if (currentTime && this.controller.videoInstance) {
167
+ this.controller.videoInstance.currentTime = currentTime / 1000
168
+ }
169
+ Object.assign(window, { $vreoController: this.controller })
101
170
 
102
- // 预载数据中的点位
103
- if (preload || (preload === undefined && this.configs.autoPreload)) {
104
- const panoIndexMap = vreoUnit.keyframes
105
- .filter((vreoKeyframe) => {
106
- if (vreoKeyframe.type !== VreoKeyframeEnum.CameraMovement) {
107
- return false
108
- }
109
-
110
- const data = vreoKeyframe.data as CameraMovementData
111
- if (data.panoIndex === undefined) {
112
- return false
113
- }
114
- return true
115
- })
116
- .reduce((accu: Record<number, boolean>, curr) => {
117
- const panoIndex = curr.data.panoIndex as number
118
- if (!accu[panoIndex]) {
119
- accu[panoIndex] = true
120
- }
121
- return accu
122
- }, {})
123
-
124
- const panoIndexs = Object.keys(panoIndexMap)
125
- for (let i = 0; i < panoIndexs.length; i++) {
126
- await this.$five.preloadPano(Number(panoIndexs[i]))
127
- }
171
+ this.controller.setPlaying(true)
172
+ return true
128
173
  }
129
174
 
130
- // 新数据载入就绪
131
- this.emit('loaded', vreoUnit)
132
- this.controller.emit('loaded', vreoUnit)
133
-
134
- if (this.controller.videoAgentScene?.videoAgentMesh.videoInstance) {
135
- this.controller.videoAgentScene.videoAgentMesh.videoInstance.currentTime = currentTime / 1000
136
- }
137
- await this.controller.videoAgentScene?.videoAgentMesh.play(
138
- vreoUnit.video.url,
139
- currentTime / 1000,
140
- vreoUnit.video.duration
141
- )
142
- this.play()
143
-
144
- this.controller.run((type, keyframe) => this.emit(type, keyframe))
145
- return true
146
- }
147
-
148
- get paused() {
149
- return !this.controller.playing
150
- }
151
-
152
- play(currentTime?: number) {
153
- if (this.controller.playing) return true
154
- if (currentTime && this.controller.videoInstance) {
155
- this.controller.videoInstance.currentTime = currentTime / 1000
175
+ pause() {
176
+ this.controller.setPlaying(false)
156
177
  }
157
- Object.assign(window, {$vreoController: this.controller})
158
178
 
159
- this.controller.setPlaying(true)
160
- return true
161
- }
162
-
163
- pause() {
164
- this.controller.setPlaying(false)
165
- }
179
+ show() {
180
+ this.controller.setVisible(true)
181
+ }
166
182
 
167
- show() {
168
- this.controller.setVisible(true)
169
- }
183
+ hide() {
184
+ this.controller.setVisible(false)
185
+ }
170
186
 
171
- hide() {
172
- this.controller.setVisible(false)
173
- }
187
+ getCurrentTime() {
188
+ return this.controller.currentTime
189
+ }
174
190
 
175
- dispose() {
176
- this.pause()
177
- this.controller.dispose()
191
+ dispose() {
192
+ this.pause()
193
+ this.controller.dispose()
178
194
 
179
- if (this.configs.containter) {
180
- ReactDOM.unmountComponentAtNode(this.configs.containter as Element)
195
+ if (this.configs.containter) {
196
+ ReactDOM.unmountComponentAtNode(this.configs.containter as Element)
197
+ }
181
198
  }
182
- }
183
199
  }
184
200
 
185
201
  console.log(`