@realsee/vreo 0.2.0-alpha.2 → 0.2.0-alpha.20

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 (147) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +80 -5
  3. package/docs/assets/custom.css +2 -2
  4. package/docs/assets/highlight.css +1 -1
  5. package/docs/assets/main.js +2 -2
  6. package/docs/assets/search.js +1 -1
  7. package/docs/assets/style.css +28 -2
  8. package/docs/classes/Player.AudioLike.html +52 -0
  9. package/docs/classes/Player.Controller.html +13 -13
  10. package/docs/classes/Player.Player-1.html +11 -11
  11. package/docs/classes/Player.VideoAgentMesh.html +53 -53
  12. package/docs/classes/Player.VideoAgentScene.html +1 -1
  13. package/docs/demo/assets/AppReact.ec0a6e82.js +1 -0
  14. package/docs/demo/assets/default.55c3f308.css +1 -0
  15. package/docs/demo/assets/default.a5d6dd99.js +3952 -0
  16. package/docs/demo/assets/dynamic.8c30b7ae.js +1 -0
  17. package/docs/demo/assets/examples.dac4a6fe.css +1 -0
  18. package/docs/demo/assets/examples.ddb41c97.js +25 -0
  19. package/docs/demo/assets/index.a7bafdff.css +1 -0
  20. package/docs/demo/assets/index.fc42be2b.js +1 -0
  21. package/docs/demo/assets/main.d119ebf7.js +1 -0
  22. package/docs/demo/assets/react.2d403aee.js +25 -0
  23. package/docs/demo/assets/react.855b3d23.css +1 -0
  24. package/docs/demo/assets/znRoyv06SZQeqA7m.0057e8ae.js +1 -0
  25. package/docs/demo/examples.html +17 -0
  26. package/docs/demo/index-react-dynamic.html +20 -0
  27. package/docs/demo/index-react.html +20 -0
  28. package/docs/demo/index.html +19 -0
  29. package/docs/enums/Player.InfoPanelStyleEnum.html +1 -0
  30. package/docs/enums/Player.InfoPanelTypeEnum.html +2 -2
  31. package/docs/enums/Player.PanoEffectEnum.html +2 -2
  32. package/docs/enums/Player.PanoTagEnum.html +2 -2
  33. package/docs/enums/Player.PanoTagStyleEnum.html +7 -0
  34. package/docs/enums/Player.VreoKeyframeEnum.html +12 -12
  35. package/docs/enums/fivePlugins.CameraMovementEffect.html +1 -1
  36. package/docs/enums/fivePlugins.Rotation.html +1 -1
  37. package/docs/index.html +37 -6
  38. package/docs/interfaces/Player.CustomVreoKeyframeProps.html +1 -1
  39. package/docs/interfaces/Player.PlayerConfigs.html +3 -3
  40. package/docs/interfaces/Player.Vertex.html +2 -2
  41. package/docs/interfaces/Player.VideoAgentMeshOptions.html +8 -1
  42. package/docs/interfaces/Player.VreoKeyframe.html +2 -2
  43. package/docs/interfaces/Player.VreoUnit.html +2 -2
  44. package/docs/interfaces/Player.VreoVideo.html +2 -2
  45. package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +4 -0
  46. package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +1 -1
  47. package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +2 -2
  48. package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +1 -1
  49. package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +1 -1
  50. package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +1 -1
  51. package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +1 -1
  52. package/docs/interfaces/fivePlugins.Vector3Position.html +3 -0
  53. package/docs/interfaces/react.VreoActionCallbacks.html +15 -7
  54. package/docs/interfaces/react.VreoProviderProps.html +1 -1
  55. package/docs/modules/Player.html +21 -15
  56. package/docs/modules/custom.html +1 -1
  57. package/docs/modules/fivePlugins.html +5 -2
  58. package/docs/modules/react.html +1 -1
  59. package/docs/modules.html +1 -1
  60. package/lib/PlayController/createHTMLAudioElement.d.ts +1 -0
  61. package/lib/PlayController/createHTMLAudioElement.js +47 -0
  62. package/lib/PlayController/index.d.ts +38 -0
  63. package/lib/PlayController/index.js +300 -0
  64. package/lib/Player/App.js +5 -4
  65. package/lib/Player/Controller.d.ts +5 -1
  66. package/lib/Player/Controller.js +38 -5
  67. package/lib/Player/custom/SpatialScenePanel/index.d.ts +2 -2
  68. package/lib/Player/custom/SpatialScenePanel/index.js +98 -26
  69. package/lib/Player/index.d.ts +3 -2
  70. package/lib/Player/index.js +116 -24
  71. package/lib/Player/modules/Drawer/index.js +1 -1
  72. package/lib/Player/modules/PopUp/index.d.ts +2 -0
  73. package/lib/Player/modules/PopUp/index.js +43 -0
  74. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +17 -2
  75. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +113 -37
  76. package/lib/Player/modules/VideoAgent/VideoAgentScene.d.ts +5 -1
  77. package/lib/Player/modules/VideoAgent/VideoAgentScene.js +9 -4
  78. package/lib/Player/modules/VideoAgent/index.d.ts +2 -0
  79. package/lib/Player/modules/VideoAgent/index.js +2 -2
  80. package/lib/Player/modules/keyframes/BgMusic/index.js +1 -1
  81. package/lib/Player/modules/keyframes/CameraMovement/index.js +42 -6
  82. package/lib/Player/modules/keyframes/InfoPanel/index.js +74 -36
  83. package/lib/Player/modules/keyframes/ModelVideo/index.js +46 -9
  84. package/lib/Player/modules/keyframes/PanoEffect/index.js +1 -1
  85. package/lib/Player/modules/keyframes/PanoEffect/lineAnime.js +1 -1
  86. package/lib/Player/modules/keyframes/PanoTag/index.js +20 -7
  87. package/lib/Player/modules/keyframes/PanoTextLabel/index.d.ts +3 -0
  88. package/lib/Player/modules/keyframes/PanoTextLabel/index.js +96 -51
  89. package/lib/Player/modules/keyframes/Prompter/index.js +5 -19
  90. package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +31 -19
  91. package/lib/Player/modules/keyframes/VideoEffect/index.js +1 -1
  92. package/lib/Player/typings.d.ts +6 -0
  93. package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.d.ts +2 -0
  94. package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.js +12 -0
  95. package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.d.ts +7 -0
  96. package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.js +32 -0
  97. package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.d.ts +3 -0
  98. package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.js +11 -0
  99. package/lib/fivePlugins/CSS3DRenderPlugin/index.d.ts +56 -0
  100. package/lib/fivePlugins/CSS3DRenderPlugin/index.js +275 -0
  101. package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.d.ts +7 -0
  102. package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.js +18 -0
  103. package/lib/fivePlugins/CameraMovementPlugin/index.js +104 -90
  104. package/lib/fivePlugins/CameraMovementPlugin/typings.d.ts +1 -0
  105. package/lib/fivePlugins/ModelTVVideoPlugin/index.js +1 -1
  106. package/lib/react/index.d.ts +7 -3
  107. package/lib/react/index.js +3 -3
  108. package/lib/shared-utils/AduioLike.d.ts +37 -0
  109. package/lib/shared-utils/AduioLike.js +165 -0
  110. package/lib/shared-utils/animationFrame/BetterTween.js +7 -3
  111. package/lib/shared-utils/animationFrame/tween.js +1 -1
  112. package/lib/shared-utils/createTransMatrix.d.ts +1 -0
  113. package/lib/shared-utils/createTransMatrix.js +43 -0
  114. package/lib/typings/VreoUnit.d.ts +42 -5
  115. package/lib/typings/VreoUnit.js +26 -6
  116. package/package.json +8 -8
  117. package/resources/PlayController/createHTMLAudioElement.ts +53 -0
  118. package/resources/PlayController/index.ts +167 -0
  119. package/resources/Player/App.tsx +2 -0
  120. package/resources/Player/Controller.ts +155 -121
  121. package/resources/Player/custom/SpatialScenePanel/index.tsx +148 -45
  122. package/resources/Player/index.tsx +186 -110
  123. package/resources/Player/modules/PopUp/index.tsx +26 -0
  124. package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +66 -14
  125. package/resources/Player/modules/VideoAgent/VideoAgentScene.ts +3 -3
  126. package/resources/Player/modules/VideoAgent/index.tsx +3 -2
  127. package/resources/Player/modules/keyframes/CameraMovement/index.tsx +7 -3
  128. package/resources/Player/modules/keyframes/InfoPanel/index.tsx +79 -34
  129. package/resources/Player/modules/keyframes/ModelVideo/index.tsx +36 -3
  130. package/resources/Player/modules/keyframes/PanoTag/index.tsx +31 -12
  131. package/resources/Player/modules/keyframes/PanoTextLabel/index.tsx +87 -34
  132. package/resources/Player/modules/keyframes/Prompter/index.tsx +5 -15
  133. package/resources/Player/modules/keyframes/UpdateVRPanorama/index.tsx +25 -16
  134. package/resources/Player/typings.ts +5 -0
  135. package/resources/fivePlugins/CSS3DRenderPlugin/centerPoint.ts +5 -0
  136. package/resources/fivePlugins/CSS3DRenderPlugin/createResizeObserver.ts +17 -0
  137. package/resources/fivePlugins/CSS3DRenderPlugin/evenNumber.ts +4 -0
  138. package/resources/fivePlugins/CSS3DRenderPlugin/index.ts +254 -0
  139. package/resources/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.ts +5 -0
  140. package/resources/fivePlugins/CameraMovementPlugin/index.ts +59 -48
  141. package/resources/fivePlugins/CameraMovementPlugin/typings.ts +2 -1
  142. package/resources/react/index.tsx +7 -3
  143. package/resources/shared-utils/AduioLike.ts +108 -0
  144. package/resources/shared-utils/createTransMatrix.ts +12 -0
  145. package/resources/typings/VreoUnit.ts +46 -5
  146. package/stylesheets/custom/SpatialScenePanel.css +14 -8
  147. package/stylesheets/default.css +116 -12
@@ -0,0 +1,167 @@
1
+ import { Subscribe } from '@realsee/five'
2
+ import { requestAnimationFrameInterval } from '../shared-utils/animationFrame'
3
+ import { VreoKeyframe, VreoKeyframeEvent, VreoUnit } from '../typings/VreoUnit'
4
+ import { createHTMLAudioElement } from './createHTMLAudioElement'
5
+
6
+ export interface PlayControllerConfig {
7
+ audio?: HTMLAudioElement
8
+ }
9
+
10
+ const closures: Record<string, any> = {}
11
+
12
+ export class PlayController extends Subscribe<VreoKeyframeEvent> {
13
+
14
+ vreoUnit?: VreoUnit
15
+
16
+ config: PlayControllerConfig = {}
17
+ stopInterval: () => void
18
+
19
+ get paused() {
20
+ return this.audioInstance.paused
21
+ }
22
+
23
+ get audioInstance() {
24
+ return this.config.audio!
25
+ }
26
+
27
+ get currentTime() {
28
+ return this.audioInstance.currentTime * 1000
29
+ }
30
+
31
+ get currentKeyframes() {
32
+ if (!this.vreoUnit) return []
33
+ const keyframes = this.vreoUnit.keyframes
34
+ // 没有被解析过且开始时间低于当前时间戳 100ms
35
+ return keyframes.filter((keyframe: VreoKeyframe) => {
36
+ if (keyframe.parsed) return false
37
+ const dur = this.currentTime - keyframe.start
38
+ return dur <= 100 && dur >= 0
39
+ })
40
+ }
41
+
42
+ /**
43
+ * 音频时长 不一定能获取得到,建议以 VreoUnit 配置的时长为准。
44
+ */
45
+ get duration() {
46
+ return this.audioInstance.duration * 1000
47
+ }
48
+
49
+ constructor(config: PlayControllerConfig = {}) {
50
+ super()
51
+
52
+ if (!config.audio) {
53
+ config.audio = createHTMLAudioElement()
54
+ }
55
+
56
+ this.config = Object.assign(this.config, config)
57
+
58
+ closures.onPlaying = () => this.emit('playing')
59
+ closures.onPaused = () => this.emit('paused')
60
+ closures.onEnded = () => this.emit('paused', true)
61
+
62
+ this.audioInstance.addEventListener('play', closures.onPlaying)
63
+ this.audioInstance.addEventListener('pause', closures.onPaused)
64
+ this.audioInstance.addEventListener('ended', closures.onEnded)
65
+
66
+ this.stopInterval = requestAnimationFrameInterval(() => {
67
+ if (this.audioInstance.paused) {
68
+ return
69
+ }
70
+
71
+ if (!this.vreoUnit) {
72
+ return
73
+ }
74
+
75
+ const keyframes = this.vreoUnit.keyframes
76
+ const currentTime = this.currentTime
77
+ // 没有被解析过且开始时间低于当前时间戳 100ms
78
+ const currentKeyframes = keyframes.filter((keyframe: VreoKeyframe) => {
79
+ if (keyframe.parsed) return false
80
+
81
+ const dur = currentTime - keyframe.start
82
+ return dur <= 60 && dur >= 0
83
+ })
84
+
85
+ currentKeyframes.forEach((keyframe) => {
86
+ if (keyframe.parsed) return
87
+ keyframe.parsed = true
88
+ this.emit(keyframe.type, keyframe)
89
+ })
90
+ })
91
+
92
+ }
93
+
94
+
95
+
96
+ /**
97
+ * 载入数据
98
+ */
99
+ async load(vreoUnit: VreoUnit): Promise<boolean> {
100
+ this.vreoUnit = vreoUnit
101
+
102
+ await this.pause()
103
+ return await new Promise((resolve, reject) => {
104
+ if (vreoUnit.video.url === this.audioInstance.src) {
105
+ return resolve(true)
106
+ }
107
+
108
+ this.audioInstance.src = vreoUnit.video.url
109
+ const canplaythrough = () => {
110
+ resolve(true)
111
+ this.audioInstance.removeEventListener('canplaythrough', canplaythrough)
112
+ }
113
+ const error = (err: any) => {
114
+ reject(err)
115
+ this.audioInstance.removeEventListener('error', error)
116
+ }
117
+ this.audioInstance.addEventListener('canplaythrough', canplaythrough)
118
+ this.audioInstance.addEventListener('error', error)
119
+ })
120
+ }
121
+
122
+ /**
123
+ * 播放
124
+ */
125
+ async play() {
126
+ closures.playPromise = this.audioInstance.play()
127
+ }
128
+
129
+ /**
130
+ * 暂停
131
+ */
132
+ async pause() {
133
+ if (closures.playPromise) {
134
+ await closures.playPromise
135
+ }
136
+ this.audioInstance.pause()
137
+ }
138
+
139
+ /**
140
+ * 销毁资源
141
+ * @notice 一旦销毁,创建的实例将不可用:需重新创建实例。
142
+ *
143
+ * @deprecated **慎重执行**
144
+ */
145
+ dispose() {
146
+ // 清理事件监听
147
+ this.audioInstance.removeEventListener('play', closures.onPlaying)
148
+ this.audioInstance.removeEventListener('pasue', closures.onPaused)
149
+ this.audioInstance.removeEventListener('ended', closures.onEnded)
150
+ if (this.stopInterval) {
151
+ this.stopInterval()
152
+ }
153
+ }
154
+ }
155
+
156
+ console.log(`
157
+
158
+ ┏━━━┓━━━━━━━━━┏┓━━━━━━━━━━━━━
159
+ ┃┏━┓┃━━━━━━━━━┃┃━━━━━━━━━━━━━
160
+ ┃┗━┛┃┏━━┓┏━━┓━┃┃━┏━━┓┏━━┓┏━━┓
161
+ ┃┏┓┏┛┃┏┓┃┗━┓┃━┃┃━┃━━┫┃┏┓┃┃┏┓┃
162
+ ┃┃┃┗┓┃┃━┫┃┗┛┗┓┃┗┓┣━━┃┃┃━┫┃┃━┫
163
+ ┗┛┗━┛┗━━┛┗━━━┛┗━┛┗━━┛┗━━┛┗━━┛
164
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
165
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
166
+
167
+ `)
@@ -16,6 +16,7 @@ import { VideoAgent } from './modules/VideoAgent'
16
16
  import { BgMusic } from './modules/keyframes/BgMusic'
17
17
 
18
18
  const AppView = observer(({ controller }: { controller: Controller }) => {
19
+
19
20
  return (
20
21
  <div
21
22
  className={classNames('vreo-panel', {
@@ -34,6 +35,7 @@ const AppView = observer(({ controller }: { controller: Controller }) => {
34
35
  controller.setPlaying(true)
35
36
  }
36
37
  }}
38
+ options={controller.configs?.videoAgentMeshOptions || {}}
37
39
  />
38
40
  <Prompter />
39
41
  {controller.configs?.customPanelChildren}
@@ -11,144 +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
20
-
21
- visible = false
22
-
23
- get isAudio() {
24
- return !this.videoAgentScene?.videoAgentMesh.videoUrl?.endsWith('.mp4')
25
- }
26
-
27
- drawerConfig: {
28
- content: string | JSX.Element
29
- height?: number | string
30
- } | null = null
31
-
32
- setVisible(v: boolean) {
33
- this.visible = v
34
- }
35
-
36
- setPlaying(playing: boolean) {
37
- this.playing = playing
38
- }
39
-
40
- openDrawer(drawerConfig?: false | { content: string | JSX.Element; height?: number | string }) {
41
- if (!drawerConfig) {
42
- this.drawerConfig = {
43
- content: '',
44
- height: this.drawerConfig?.height
45
- }
46
- return
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')
47
26
  }
48
27
 
49
- this.drawerConfig = drawerConfig
50
- }
51
-
52
- constructor() {
53
- super()
54
-
55
- makeObservable(this, {
56
- visible: observable,
57
- setVisible: action,
58
- playing: observable,
59
- setPlaying: action,
60
- drawerConfig: observable.ref,
61
- openDrawer: action,
62
- })
63
-
64
- // 监听播放情况:抛出触发时机
65
- reaction(
66
- () => this.playing,
67
- (playing) => {
68
- this.emit(playing ? 'playing' : 'paused')
69
- }
70
- )
71
- }
72
-
73
- get ready() {
74
- return !!this.videoAgentScene
75
- }
76
-
77
- get currentTime() {
78
- return this.videoAgentScene?.videoAgentMesh.currentTime || 0
79
- }
80
-
81
- get currentKeyframes() {
82
- if (!this.vreoUnit) return []
83
- const keyframes = this.vreoUnit.keyframes
84
- // 没有被解析过且开始时间低于当前时间戳 100ms
85
- return keyframes.filter((keyframe: VreoKeyframe) => {
86
- if (keyframe.parsed) return false
87
- const dur = this.currentTime - keyframe.start
88
- return dur <= 100 && dur >= 0
89
- })
90
- }
91
-
92
- get videoInstance() {
93
- return this.videoAgentScene?.videoAgentMesh.videoInstance
94
- }
95
-
96
- /**
97
- * 逐帧任务
98
- */
99
- requestAnimationFrameLoop(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
100
- if (this.videoInstance?.ended) {
101
- this.setPlaying(false)
102
- this.videoInstance.pause()
103
- return
28
+ popUp: string | JSX.Element | null = null
29
+
30
+ openPopUp(popUp: string | JSX.Element | false) {
31
+ if (!popUp) {
32
+ this.popUp = null
33
+ return
34
+ }
35
+ this.popUp = popUp
36
+ }
37
+
38
+ drawerConfig: {
39
+ content: string | JSX.Element
40
+ height?: number | string
41
+ } | null = null
42
+
43
+ setVisible(v: boolean) {
44
+ this.visible = v
104
45
  }
105
- if (!this.playing) {
106
- if (!this.videoInstance?.paused) {
107
- this.videoInstance?.pause()
108
- }
109
- return
46
+
47
+ setPlaying(playing: boolean) {
48
+ this.playing = playing
49
+ }
50
+
51
+ setEnded(ended: boolean) {
52
+ this.ended = ended
110
53
  }
111
- if (this.videoInstance?.paused && this.playing) {
112
- this.videoInstance.play()
54
+
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
113
65
  }
114
66
 
115
- 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
+ )
101
+
102
+ }
116
103
 
117
- currentKeyframes.forEach((keyframe) => {
118
- if (keyframe.parsed) return
119
- keyframe.parsed = true
120
- this.emit(keyframe.type, keyframe)
121
- if (callback) {
122
- callback(keyframe.type, keyframe)
123
- }
124
- })
125
- }
104
+ get ready() {
105
+ return !!this.videoAgentScene
106
+ }
126
107
 
127
- run(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
128
- if (this.stopInterval) return
129
- this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop(callback))
130
- }
108
+ get currentTime() {
109
+ return this.videoAgentScene?.videoAgentMesh.currentTime || 0
110
+ }
131
111
 
132
- dispose() {
133
- this.setPlaying(false)
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
+ }
134
122
 
135
- if (this.currentKeyframes) {
136
- this.currentKeyframes.forEach((keyframe) => (keyframe.parsed = false))
123
+ get videoInstance() {
124
+ return this.videoAgentScene?.videoAgentMesh.videoInstance
137
125
  }
138
126
 
139
127
  /**
140
- * 清理掉数据
128
+ * 逐帧任务
141
129
  */
142
- this.vreoUnit = undefined
143
- if (this.videoInstance) {
144
- 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))
145
164
  }
146
165
 
147
- if (this.stopInterval) {
148
- this.stopInterval()
149
- 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
+ }
150
185
  }
151
- }
152
186
  }
153
187
 
154
188
  export const ControllerContext = React.createContext<Controller | null>(null)