@realsee/vreo 0.2.0-alpha.9 → 1.0.0-alpha.2

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 (156) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +16 -5
  3. package/docs/assets/highlight.css +1 -1
  4. package/docs/assets/main.js +2 -2
  5. package/docs/assets/search.js +1 -1
  6. package/docs/assets/style.css +28 -2
  7. package/docs/classes/Player.AudioLike.html +52 -0
  8. package/docs/classes/Player.Controller.html +13 -13
  9. package/docs/classes/Player.Player-1.html +11 -11
  10. package/docs/classes/Player.VideoAgentMesh.html +53 -53
  11. package/docs/classes/Player.VideoAgentScene.html +1 -1
  12. package/docs/demo/assets/AppReact.d0ee843a.js +1 -0
  13. package/docs/demo/assets/default.63925584.js +3984 -0
  14. package/docs/demo/assets/default.f3f3ca8c.css +1 -0
  15. package/docs/demo/assets/dynamic.76506c2c.js +1 -0
  16. package/docs/demo/assets/examples.3d8323db.js +25 -0
  17. package/docs/demo/assets/examples.dac4a6fe.css +1 -0
  18. package/docs/demo/assets/index.7e31122c.js +1 -0
  19. package/docs/demo/assets/index.9331038f.css +1 -0
  20. package/docs/demo/assets/main.79b11b9d.js +1 -0
  21. package/docs/demo/assets/react.2ee8565f.css +1 -0
  22. package/docs/demo/assets/react.c1c07c14.js +25 -0
  23. package/docs/demo/assets/znRoyv06SZQeqA7m.0057e8ae.js +1 -0
  24. package/docs/demo/examples.html +17 -0
  25. package/docs/demo/index-react-dynamic.html +20 -0
  26. package/docs/demo/index-react.html +20 -0
  27. package/docs/demo/index.html +19 -0
  28. package/docs/enums/Player.InfoPanelStyleEnum.html +1 -1
  29. package/docs/enums/Player.InfoPanelTypeEnum.html +2 -2
  30. package/docs/enums/Player.PanoEffectEnum.html +2 -2
  31. package/docs/enums/Player.PanoTagEnum.html +2 -2
  32. package/docs/enums/Player.PanoTagStyleEnum.html +7 -0
  33. package/docs/enums/Player.VreoKeyframeEnum.html +12 -12
  34. package/docs/enums/fivePlugins.CameraMovementEffect.html +1 -1
  35. package/docs/enums/fivePlugins.Rotation.html +1 -1
  36. package/docs/index.html +13 -6
  37. package/docs/interfaces/Player.CustomVreoKeyframeProps.html +1 -1
  38. package/docs/interfaces/Player.PlayerConfigs.html +4 -3
  39. package/docs/interfaces/Player.Vertex.html +2 -2
  40. package/docs/interfaces/Player.VideoAgentMeshOptions.html +8 -1
  41. package/docs/interfaces/Player.VreoKeyframe.html +2 -2
  42. package/docs/interfaces/Player.VreoUnit.html +2 -2
  43. package/docs/interfaces/Player.VreoVideo.html +2 -2
  44. package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +4 -0
  45. package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +1 -1
  46. package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +2 -2
  47. package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +1 -1
  48. package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +1 -1
  49. package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +1 -1
  50. package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +1 -1
  51. package/docs/interfaces/fivePlugins.Vector3Position.html +3 -0
  52. package/docs/interfaces/react.VreoActionCallbacks.html +15 -7
  53. package/docs/interfaces/react.VreoProviderProps.html +1 -1
  54. package/docs/modules/Player.html +21 -15
  55. package/docs/modules/custom.html +1 -1
  56. package/docs/modules/fivePlugins.html +5 -2
  57. package/docs/modules/react.html +1 -1
  58. package/docs/modules.html +1 -1
  59. package/lib/PlayController/index.js +4 -5
  60. package/lib/Player/App.js +9 -7
  61. package/lib/Player/Controller.d.ts +29 -8
  62. package/lib/Player/Controller.js +193 -27
  63. package/lib/Player/custom/SpatialScenePanel/index.js +5 -4
  64. package/lib/Player/hooks.js +2 -2
  65. package/lib/Player/index.d.ts +5 -3
  66. package/lib/Player/index.js +97 -53
  67. package/lib/Player/modules/Drawer/index.js +1 -1
  68. package/lib/Player/modules/PopUp/index.js +1 -1
  69. package/lib/Player/modules/ResizeObserver/index.d.ts +2 -0
  70. package/lib/Player/modules/ResizeObserver/index.js +37 -0
  71. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +16 -2
  72. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +132 -59
  73. package/lib/Player/modules/VideoAgent/VideoAgentScene.d.ts +3 -6
  74. package/lib/Player/modules/VideoAgent/VideoAgentScene.js +31 -36
  75. package/lib/Player/modules/VideoAgent/index.js +53 -12
  76. package/lib/Player/modules/Wave/index.d.ts +5 -0
  77. package/lib/Player/modules/Wave/index.js +51 -0
  78. package/lib/Player/modules/keyframes/BgMusic/index.js +1 -1
  79. package/lib/Player/modules/keyframes/CameraMovement/index.js +1 -1
  80. package/lib/Player/modules/keyframes/InfoPanel/index.js +22 -10
  81. package/lib/Player/modules/keyframes/ModelVideo/index.js +46 -9
  82. package/lib/Player/modules/keyframes/PanoEffect/index.js +1 -1
  83. package/lib/Player/modules/keyframes/PanoEffect/lineAnime.js +1 -1
  84. package/lib/Player/modules/keyframes/PanoTag/index.d.ts +1 -2
  85. package/lib/Player/modules/keyframes/PanoTag/index.js +79 -119
  86. package/lib/Player/modules/keyframes/PanoTextLabel/index.d.ts +3 -0
  87. package/lib/Player/modules/keyframes/PanoTextLabel/index.js +96 -44
  88. package/lib/Player/modules/keyframes/Prompter/index.js +10 -23
  89. package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +10 -6
  90. package/lib/Player/modules/keyframes/VideoEffect/index.js +1 -1
  91. package/lib/Player/typings.d.ts +12 -1
  92. package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.d.ts +2 -0
  93. package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.js +12 -0
  94. package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.d.ts +7 -0
  95. package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.js +32 -0
  96. package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.d.ts +3 -0
  97. package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.js +11 -0
  98. package/lib/fivePlugins/CSS3DRenderPlugin/index.d.ts +56 -0
  99. package/lib/fivePlugins/CSS3DRenderPlugin/index.js +275 -0
  100. package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.d.ts +7 -0
  101. package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.js +18 -0
  102. package/lib/fivePlugins/CameraMovementPlugin/index.js +13 -12
  103. package/lib/fivePlugins/ModelTVVideoPlugin/index.js +1 -1
  104. package/lib/react/index.d.ts +8 -4
  105. package/lib/react/index.js +3 -3
  106. package/lib/shared-utils/AduioLike.d.ts +37 -0
  107. package/lib/shared-utils/AduioLike.js +166 -0
  108. package/lib/shared-utils/addResizeListener.d.ts +4 -0
  109. package/lib/shared-utils/addResizeListener.js +51 -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/shared-utils/getFileExpandedName.d.ts +1 -0
  115. package/lib/shared-utils/getFileExpandedName.js +13 -0
  116. package/lib/shared-utils/getMediaInfo.d.ts +9 -0
  117. package/lib/shared-utils/getMediaInfo.js +75 -0
  118. package/lib/shared-utils/setElementDataset.d.ts +1 -0
  119. package/lib/shared-utils/setElementDataset.js +24 -0
  120. package/lib/typings/VreoUnit.d.ts +37 -2
  121. package/lib/typings/VreoUnit.js +13 -1
  122. package/package.json +10 -10
  123. package/resources/PlayController/index.ts +0 -13
  124. package/resources/Player/App.tsx +5 -4
  125. package/resources/Player/Controller.ts +277 -146
  126. package/resources/Player/custom/SpatialScenePanel/index.tsx +5 -5
  127. package/resources/Player/hooks.ts +3 -5
  128. package/resources/Player/index.tsx +189 -141
  129. package/resources/Player/modules/ResizeObserver/index.tsx +23 -0
  130. package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +87 -31
  131. package/resources/Player/modules/VideoAgent/VideoAgentScene.ts +27 -24
  132. package/resources/Player/modules/VideoAgent/index.tsx +28 -12
  133. package/resources/Player/modules/Wave/index.tsx +18 -0
  134. package/resources/Player/modules/keyframes/InfoPanel/index.tsx +26 -11
  135. package/resources/Player/modules/keyframes/ModelVideo/index.tsx +36 -3
  136. package/resources/Player/modules/keyframes/PanoTag/index.tsx +53 -97
  137. package/resources/Player/modules/keyframes/PanoTextLabel/index.tsx +86 -34
  138. package/resources/Player/modules/keyframes/Prompter/index.tsx +6 -16
  139. package/resources/Player/modules/keyframes/UpdateVRPanorama/index.tsx +6 -2
  140. package/resources/Player/typings.ts +15 -1
  141. package/resources/fivePlugins/CSS3DRenderPlugin/centerPoint.ts +5 -0
  142. package/resources/fivePlugins/CSS3DRenderPlugin/createResizeObserver.ts +17 -0
  143. package/resources/fivePlugins/CSS3DRenderPlugin/evenNumber.ts +4 -0
  144. package/resources/fivePlugins/CSS3DRenderPlugin/index.ts +254 -0
  145. package/resources/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.ts +5 -0
  146. package/resources/fivePlugins/CameraMovementPlugin/index.ts +19 -12
  147. package/resources/react/index.tsx +7 -3
  148. package/resources/shared-utils/AduioLike.ts +109 -0
  149. package/resources/shared-utils/addResizeListener.ts +46 -0
  150. package/resources/shared-utils/createTransMatrix.ts +12 -0
  151. package/resources/shared-utils/getFileExpandedName.ts +6 -0
  152. package/resources/shared-utils/getMediaInfo.ts +52 -0
  153. package/resources/shared-utils/setElementDataset.ts +18 -0
  154. package/resources/typings/VreoUnit.ts +41 -3
  155. package/stylesheets/custom/SpatialScenePanel.css +2 -1
  156. package/stylesheets/default.css +348 -84
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realsee/vreo",
3
- "version": "0.2.0-alpha.9",
3
+ "version": "1.0.0-alpha.2",
4
4
  "description": "Vreo (VR Video 缩写) 是基于如视三维渲染引擎 Five 和 用户界面构建库 React 实现的如视 3D 空间剧本播放器。",
5
5
  "keywords": [
6
6
  "realsee",
@@ -15,19 +15,20 @@
15
15
  "resources",
16
16
  "docs",
17
17
  "stylesheets",
18
- "LICENSE"
18
+ "LICENSE",
19
+ "CHANGELOG.md"
19
20
  ],
20
21
  "scripts": {
21
22
  "dev": "vite --port=3088 --host 0.0.0.0",
22
23
  "build": "tsc && vite build",
23
24
  "preview": "vite preview",
24
- "docs": "npx typedoc",
25
+ "docs": "npx typedoc && yarn run build",
25
26
  "packages": "node ./dev-tools/build-packages.js"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "@realsee/five": "^5.0.0-alpha.103",
29
- "react": "^16.0.0",
30
- "react-dom": "^16.0.0"
30
+ "react": "^17.0.0",
31
+ "react-dom": "^17.0.0"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@babel/cli": "^7.16.0",
@@ -35,8 +36,8 @@
35
36
  "@babel/preset-env": "^7.16.4",
36
37
  "@babel/preset-react": "^7.16.0",
37
38
  "@babel/preset-typescript": "^7.16.0",
38
- "@realsee/dnalogel": "^0.1.7-alpha.10",
39
- "@realsee/five": "^5.0.0-alpha.103",
39
+ "@realsee/dnalogel": "^2.1.0-alpha.17",
40
+ "@realsee/five": "5.0.0-alpha.149",
40
41
  "@types/offscreencanvas": "^2019.6.4",
41
42
  "@types/react": "^17.0.37",
42
43
  "@types/react-dom": "^17.0.11",
@@ -47,14 +48,13 @@
47
48
  "react-dom": "^16.0.0",
48
49
  "three": "^0.117.1",
49
50
  "typedoc": "^0.22.10",
50
- "typescript": "^4.5.2",
51
+ "typescript": "4.7.4",
51
52
  "vite": "^2.6.14"
52
53
  },
53
54
  "dependencies": {
54
55
  "@tweenjs/tween.js": "18.6.4",
55
56
  "classnames": "^2.3.1",
56
57
  "mobx": "^6.3.7",
57
- "mobx-react": "^7.2.1",
58
- "react-transition-group": "^4.4.2"
58
+ "mobx-react": "^7.2.1"
59
59
  }
60
60
  }
@@ -152,16 +152,3 @@ export class PlayController extends Subscribe<VreoKeyframeEvent> {
152
152
  }
153
153
  }
154
154
  }
155
-
156
- console.log(`
157
-
158
- ┏━━━┓━━━━━━━━━┏┓━━━━━━━━━━━━━
159
- ┃┏━┓┃━━━━━━━━━┃┃━━━━━━━━━━━━━
160
- ┃┗━┛┃┏━━┓┏━━┓━┃┃━┏━━┓┏━━┓┏━━┓
161
- ┃┏┓┏┛┃┏┓┃┗━┓┃━┃┃━┃━━┫┃┏┓┃┃┏┓┃
162
- ┃┃┃┗┓┃┃━┫┃┗┛┗┓┃┗┓┣━━┃┃┃━┫┃┃━┫
163
- ┗┛┗━┛┗━━┛┗━━━┛┗━┛┗━━┛┗━━┛┗━━┛
164
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
165
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
166
-
167
- `)
@@ -2,8 +2,9 @@ import * as React from 'react'
2
2
  import classNames from 'classnames'
3
3
  import { observer } from 'mobx-react'
4
4
  import { Controller } from './Controller'
5
- import { useController, useFiveInstance } from './hooks'
5
+ import { useController } from './hooks'
6
6
  import { CameraMovement } from './modules/keyframes/CameraMovement'
7
+ import { ResizeObserver } from './modules/ResizeObserver'
7
8
  import { InfoPanel } from './modules/keyframes/InfoPanel'
8
9
  import { ModelVideo } from './modules/keyframes/ModelVideo'
9
10
  import { PanoEffect } from './modules/keyframes/PanoEffect'
@@ -14,6 +15,7 @@ import { UpdateVRPanorama } from './modules/keyframes/UpdateVRPanorama'
14
15
  import { VideoEffect } from './modules/keyframes/VideoEffect'
15
16
  import { VideoAgent } from './modules/VideoAgent'
16
17
  import { BgMusic } from './modules/keyframes/BgMusic'
18
+ import { Wave } from './modules/Wave'
17
19
 
18
20
  const AppView = observer(({ controller }: { controller: Controller }) => {
19
21
 
@@ -24,11 +26,9 @@ const AppView = observer(({ controller }: { controller: Controller }) => {
24
26
  })}
25
27
  >
26
28
  <div className="vreo-panel-inner">
29
+ {controller.waveAppearance && <Wave appearance={controller.waveAppearance}/>}
27
30
  <VideoAgent
28
31
  onClick={() => {
29
- if (controller.isAudio) {
30
- return
31
- }
32
32
  if (controller.playing) {
33
33
  controller.setPlaying(false)
34
34
  } else {
@@ -49,6 +49,7 @@ export function App() {
49
49
  return (
50
50
  <>
51
51
  <>
52
+ <ResizeObserver />
52
53
  <CameraMovement />
53
54
  <ModelVideo />
54
55
  <UpdateVRPanorama />
@@ -2,165 +2,296 @@ import { Five, Subscribe } from '@realsee/five'
2
2
  import { action, computed, makeObservable, observable, reaction } from 'mobx'
3
3
  import * as React from 'react'
4
4
  import { requestAnimationFrameInterval } from '../shared-utils/animationFrame'
5
- import { VreoKeyframe, VreoKeyframeEnum, VreoKeyframeEvent, VreoUnit } from '../typings/VreoUnit'
5
+ import { VreoKeyframe, VreoKeyframeEnum, VreoKeyframeEvent, VreoUnit, VreoVideo } from '../typings/VreoUnit'
6
6
  import { VideoAgentScene } from './modules/VideoAgent/VideoAgentScene'
7
- import { PlayerConfigs } from './typings'
7
+ import { Appearance, PlayerConfigs, WaveAppearance } from './typings'
8
+ import setElementDataset from '../shared-utils/setElementDataset'
9
+ import { getMediaType } from '../shared-utils/getMediaInfo'
8
10
 
9
11
  /**
10
12
  * 逻辑控制器:内部状态。
11
13
  */
12
14
  export class Controller extends Subscribe<VreoKeyframeEvent> {
13
15
 
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
- popUp: string | JSX.Element | null = null
28
-
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
57
- }
58
-
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
116
- }
117
- if (!this.playing) {
118
- if (!this.videoInstance?.paused) {
119
- this.videoInstance?.pause()
120
- }
121
- return
122
- }
123
- if (this.videoInstance?.paused && this.playing) {
124
- this.videoInstance.play()
125
- }
126
-
127
- const currentKeyframes = this.currentKeyframes
128
-
129
- currentKeyframes.forEach((keyframe) => {
130
- if (keyframe.parsed) return
131
- keyframe.parsed = true
132
- this.emit(keyframe.type, keyframe)
133
- if (callback) {
134
- callback(keyframe.type, keyframe)
135
- }
136
- })
137
- }
138
-
139
- run(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
140
- if (this.stopInterval) return
141
- this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop(callback))
142
- }
143
-
144
- dispose() {
145
- this.setPlaying(false)
146
-
147
- if (this.currentKeyframes) {
148
- this.currentKeyframes.forEach((keyframe) => (keyframe.parsed = false))
16
+ five: Five
17
+ configs: PlayerConfigs
18
+ videoAgentScene?: VideoAgentScene
19
+ vreoUnit?: VreoUnit
20
+ stopInterval?: () => void
21
+ playing = false
22
+ ended = false
23
+ loading: boolean | null = false // null 表示加载失败
24
+ containerSize?: {
25
+ width: number
26
+ height: number
27
+ }
28
+ appSize?: 'S' | 'M' | 'L' | 'XL'
29
+ container: Element
30
+ waveAppearance: WaveAppearance | null = null
31
+ appearance: Appearance = {
32
+ waveStyle: 'solid',
33
+ }
34
+ avatar?: VreoVideo['avatar']
35
+
36
+
37
+ visible = false
38
+
39
+ get agentType() {
40
+ const type = getMediaType(this.videoAgentScene?.videoAgentMesh.videoUrl)
41
+ if (this.avatar?.force) return 'avatar'
42
+ if (type === 'video') return 'video'
43
+ return 'none'
44
+ }
45
+
46
+ popUp: string | JSX.Element | null = null
47
+
48
+ openPopUp(popUp: string | JSX.Element | false) {
49
+ if (!popUp) {
50
+ this.popUp = null
51
+ return
52
+ }
53
+ this.popUp = popUp
54
+ }
55
+
56
+ setLoading(loading: boolean | null) {
57
+ this.loading = loading
58
+ }
59
+
60
+ drawerConfig: {
61
+ content: string | JSX.Element
62
+ height?: number | string
63
+ } | null = null
64
+
65
+ setAvatar(avatar: VreoVideo['avatar']) {
66
+ this.avatar = avatar
67
+ }
68
+
69
+ setContainerSize(width: number, height: number) {
70
+ this.containerSize = { width, height }
71
+ }
72
+
73
+ setVisible(v: boolean) {
74
+ this.visible = v
75
+ }
76
+
77
+ setPlaying(playing: boolean) {
78
+ this.playing = playing
79
+ }
80
+
81
+ setEnded(ended: boolean) {
82
+ this.ended = ended
83
+ }
84
+
85
+ setAppearance(appearance: Appearance) {
86
+ this.appearance = { ...this.appearance, ...appearance }
87
+ }
88
+
89
+ openDrawer(drawerConfig?: false | { content: string | JSX.Element; height?: number | string }) {
90
+ if (!drawerConfig) {
91
+ this.drawerConfig = {
92
+ content: '',
93
+ height: this.drawerConfig?.height
94
+ }
95
+ return
96
+ }
97
+
98
+ this.drawerConfig = drawerConfig
99
+ }
100
+
101
+ constructor({five, container, configs}: { five: Five, container: Element, configs: PlayerConfigs }) {
102
+ super()
103
+
104
+ this.configs = configs
105
+ this.container = container
106
+ this.five = five
107
+ this.appSize = configs.appSize
108
+ this.appearance = { ...this.appearance, ...configs.appearance }
109
+
110
+ makeObservable(this, {
111
+ visible: observable,
112
+ setVisible: action,
113
+ playing: observable,
114
+ setPlaying: action,
115
+ loading: observable,
116
+ setLoading: action,
117
+ popUp: observable.ref,
118
+ openPopUp: action,
119
+ drawerConfig: observable.ref,
120
+ openDrawer: action,
121
+ ended: observable,
122
+ waveAppearance: observable,
123
+ avatar: observable,
124
+ containerSize: observable,
125
+ setContainerSize: action,
126
+ appearance: observable,
127
+ setAppearance: action,
128
+ configs: observable.ref,
129
+ setEnded: action,
130
+ setAvatar: action,
131
+ })
132
+
133
+ reaction<[typeof this.appearance.waveStyle, boolean | null], boolean>(
134
+ () => [this.appearance.waveStyle, this.loading],
135
+ ([waveStyle, loading]) => {
136
+ if (loading === null) {
137
+ this.waveAppearance = null
138
+ return
139
+ }
140
+ if (waveStyle === 'wave') {
141
+ switch (loading) {
142
+ case true:
143
+ this.waveAppearance = 'double'
144
+ break
145
+ case false:
146
+ this.waveAppearance = 'solid'
147
+ break
148
+ }
149
+ } else if (waveStyle === 'solid') {
150
+ switch (loading) {
151
+ case true:
152
+ this.waveAppearance = 'swap'
153
+ break
154
+ case false:
155
+ this.waveAppearance = 'expand'
156
+ break
157
+ }
158
+ }
159
+ },
160
+ { fireImmediately: true }
161
+ )
162
+
163
+ if (!this.appSize) {
164
+ reaction(
165
+ () => this.containerSize,
166
+ (containerSize) => {
167
+ if (!containerSize) return
168
+ const width = containerSize.width
169
+ const height = containerSize.height
170
+ const size = (() => {
171
+ if (width <= 500) return 'S'
172
+ if (width <= 1024) return 'M'
173
+ if (width <= 2048) return 'L'
174
+ return 'XL'
175
+ })()
176
+ const orientation = (() => {
177
+ if (height > width) return 'portrait'
178
+ return 'landscape'
179
+ })()
180
+ setElementDataset(this.container, { size })
181
+ setElementDataset(this.container, { orientation })
182
+ },
183
+ { fireImmediately: true }
184
+ )
185
+ } else {
186
+ setElementDataset(this.container, { size: this.appSize })
187
+ }
188
+
189
+ // 监听播放情况:抛出触发时机
190
+ reaction(
191
+ () => this.ended,
192
+ (ended) => {
193
+ if (ended) {
194
+ this.emit('paused', true)
195
+ }
196
+ }
197
+ )
198
+
199
+ reaction(
200
+ () => this.playing,
201
+ (playing) => {
202
+ if (!this.ended) {
203
+ this.emit(playing ? 'playing' : 'paused')
204
+ }
205
+ }
206
+ )
207
+
208
+ }
209
+
210
+ get ready() {
211
+ return !!this.videoAgentScene
212
+ }
213
+
214
+ get currentTime() {
215
+ return this.videoAgentScene?.videoAgentMesh.currentTime || 0
216
+ }
217
+
218
+ get currentKeyframes() {
219
+ if (!this.vreoUnit) return []
220
+ const keyframes = this.vreoUnit.keyframes
221
+ // 没有被解析过且开始时间低于当前时间戳 100ms
222
+ return keyframes.filter((keyframe: VreoKeyframe) => {
223
+ if (keyframe.parsed) return false
224
+ const dur = this.currentTime - keyframe.start
225
+ return dur <= 100 && dur >= 0
226
+ })
227
+ }
228
+
229
+ get mediaInstance() {
230
+ return this.videoAgentScene?.videoAgentMesh.mediaInstance
149
231
  }
150
232
 
151
233
  /**
152
- * 清理掉数据
234
+ * 逐帧任务
153
235
  */
154
- this.vreoUnit = undefined
155
- if (this.videoInstance) {
156
- this.videoInstance.currentTime = 0
236
+ requestAnimationFrameLoop(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
237
+ if (this.mediaInstance?.ended) {
238
+ this.setEnded(true)
239
+ this.setPlaying(false)
240
+ this.mediaInstance.pause()
241
+ return
242
+ }
243
+
244
+ if (!this.playing) {
245
+ if (!this.mediaInstance?.paused) {
246
+ this.mediaInstance?.pause()
247
+ }
248
+ return
249
+ }
250
+
251
+ if (this.mediaInstance?.paused && this.playing) {
252
+ this.mediaInstance.play()
253
+ }
254
+
255
+ const currentKeyframes = this.currentKeyframes
256
+
257
+ currentKeyframes.forEach((keyframe) => {
258
+ if (keyframe.parsed) return
259
+ keyframe.parsed = true
260
+ this.emit(keyframe.type, keyframe)
261
+ if (callback) {
262
+ callback(keyframe.type, keyframe)
263
+ }
264
+ })
157
265
  }
158
266
 
159
- if (this.stopInterval) {
160
- this.stopInterval()
161
- this.stopInterval = undefined
267
+ run(callback: (type: VreoKeyframeEnum, keyframe: VreoKeyframe) => void) {
268
+ if (this.stopInterval) return
269
+ this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop(callback))
270
+ }
271
+
272
+ dispose() {
273
+ this.setPlaying(false)
274
+
275
+ if (this.currentKeyframes) {
276
+ this.currentKeyframes.forEach((keyframe) => (keyframe.parsed = false))
277
+ }
278
+
279
+ /**
280
+ * 清理掉数据
281
+ */
282
+ this.vreoUnit = undefined
283
+ if (this.mediaInstance) {
284
+ this.mediaInstance.currentTime = 0
285
+ }
286
+
287
+ if (this.stopInterval) {
288
+ this.stopInterval()
289
+ this.stopInterval = undefined
290
+ }
162
291
  }
163
- }
164
292
  }
165
293
 
166
- export const ControllerContext = React.createContext<Controller | null>(null)
294
+ const ControllerContext = React.createContext<Controller | null>(null)
295
+
296
+ export { ControllerContext }
297
+
@@ -1,10 +1,9 @@
1
1
  import * as React from 'react'
2
2
  import ReactDOM from 'react-dom'
3
3
  import { Five } from '@realsee/five'
4
- import * as THREE from 'three'
5
- import { Object3D, Raycaster, Vector3 } from 'three'
6
- import { tweenProgress } from '@realsee/dnalogel/shared-utils/animationFrame/BetterTween'
7
- import { CSS3DRenderPlugin, CSS3DRenderPluginExportType } from '@realsee/dnalogel/plugins/CSS3DRenderPlugin'
4
+ import { Raycaster, Vector3 } from 'three'
5
+ import { tweenProgress } from '../../../shared-utils/animationFrame/BetterTween'
6
+ import { CSS3DRenderPlugin, CSS3DRenderPluginExportType } from '../../../fivePlugins/CSS3DRenderPlugin'
8
7
 
9
8
  import { VreoKeyframe, VreoKeyframeEnum } from '../../../typings/VreoUnit'
10
9
  import { CustomVreoKeyframeProps } from '../../typings'
@@ -33,6 +32,7 @@ import { CustomVreoKeyframeProps } from '../../typings'
33
32
  // "temperature": "27",
34
33
  // "title": "沉浸式回家"
35
34
  // }
35
+
36
36
  export interface SpatialScenePanelData {
37
37
  customType: 'SpatialScenePanel'
38
38
  title: string
@@ -222,7 +222,7 @@ const Panel = React.forwardRef(
222
222
  <div className="SpatialScenePanel-body">
223
223
  {props.data?.stateList?.map((state, index) => (
224
224
  <div key={`scene-${state.text}`} className={`SpatialScenePanel-item index_${index}`}>
225
- <img className="SpatialScenePanel-icon" src={state.icon}></img>
225
+ <img className="SpatialScenePanel-icon" src={state.icon} alt={`${state.text}`}></img>
226
226
  <div className="SpatialScenePanel-text">{state.text}</div>
227
227
  <div className="SpatialScenePanel-dot"></div>
228
228
  </div>
@@ -2,8 +2,6 @@ import React from 'react'
2
2
  import { Vector3 } from 'three'
3
3
  import { ControllerContext } from './Controller'
4
4
 
5
-
6
-
7
5
  export function useController() {
8
6
  const controller = React.useContext(ControllerContext)
9
7
  if (!controller) {
@@ -15,14 +13,14 @@ export function useController() {
15
13
 
16
14
  export function useFiveInstance() {
17
15
  const controller = useController()
18
- if (!controller.$five) {
16
+ if (!controller.five) {
19
17
  throw new Error('没有找到 "five" 实例')
20
18
  }
21
19
 
22
- return controller.$five
20
+ return controller.five
23
21
  }
24
22
 
25
23
  export function useFiveProject2d() {
26
24
  const five = useFiveInstance()
27
25
  return (vector: Vector3) => five.project2d(vector, false)
28
- }
26
+ }