@realsee/vreo 0.2.0-alpha.2 → 0.2.0-alpha.21-beta
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.
- package/CHANGELOG.md +8 -0
- package/README.md +80 -5
- package/docs/assets/custom.css +2 -2
- package/docs/assets/highlight.css +1 -1
- package/docs/assets/main.js +2 -2
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +28 -2
- package/docs/classes/Player.AudioLike.html +52 -0
- package/docs/classes/Player.Controller.html +13 -13
- package/docs/classes/Player.Player-1.html +11 -11
- package/docs/classes/Player.VideoAgentMesh.html +53 -53
- package/docs/classes/Player.VideoAgentScene.html +1 -1
- package/docs/demo/assets/AppReact.043b1cd2.js +1 -0
- package/docs/demo/assets/default.55c3f308.css +1 -0
- package/docs/demo/assets/default.9a6a32fc.js +3952 -0
- package/docs/demo/assets/dynamic.bdbbbafa.js +1 -0
- package/docs/demo/assets/examples.2aaa85e1.js +25 -0
- package/docs/demo/assets/examples.dac4a6fe.css +1 -0
- package/docs/demo/assets/index.9b5c1a3f.js +1 -0
- package/docs/demo/assets/index.a7bafdff.css +1 -0
- package/docs/demo/assets/main.0895bebe.js +1 -0
- package/docs/demo/assets/react.855b3d23.css +1 -0
- package/docs/demo/assets/react.959cff42.js +25 -0
- package/docs/demo/assets/znRoyv06SZQeqA7m.0057e8ae.js +1 -0
- package/docs/demo/examples.html +17 -0
- package/docs/demo/index-react-dynamic.html +20 -0
- package/docs/demo/index-react.html +20 -0
- package/docs/demo/index.html +19 -0
- package/docs/enums/Player.InfoPanelStyleEnum.html +1 -0
- package/docs/enums/Player.InfoPanelTypeEnum.html +2 -2
- package/docs/enums/Player.PanoEffectEnum.html +2 -2
- package/docs/enums/Player.PanoTagEnum.html +2 -2
- package/docs/enums/Player.PanoTagStyleEnum.html +7 -0
- package/docs/enums/Player.VreoKeyframeEnum.html +12 -12
- package/docs/enums/fivePlugins.CameraMovementEffect.html +1 -1
- package/docs/enums/fivePlugins.Rotation.html +1 -1
- package/docs/index.html +37 -6
- package/docs/interfaces/Player.CustomVreoKeyframeProps.html +1 -1
- package/docs/interfaces/Player.PlayerConfigs.html +3 -3
- package/docs/interfaces/Player.Vertex.html +2 -2
- package/docs/interfaces/Player.VideoAgentMeshOptions.html +8 -1
- package/docs/interfaces/Player.VreoKeyframe.html +2 -2
- package/docs/interfaces/Player.VreoUnit.html +2 -2
- package/docs/interfaces/Player.VreoVideo.html +2 -2
- package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +4 -0
- package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +1 -1
- package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +2 -2
- package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +1 -1
- package/docs/interfaces/fivePlugins.Vector3Position.html +3 -0
- package/docs/interfaces/react.VreoActionCallbacks.html +15 -7
- package/docs/interfaces/react.VreoProviderProps.html +1 -1
- package/docs/modules/Player.html +21 -15
- package/docs/modules/custom.html +1 -1
- package/docs/modules/fivePlugins.html +5 -2
- package/docs/modules/react.html +1 -1
- package/docs/modules.html +1 -1
- package/lib/PlayController/createHTMLAudioElement.d.ts +1 -0
- package/lib/PlayController/createHTMLAudioElement.js +47 -0
- package/lib/PlayController/index.d.ts +38 -0
- package/lib/PlayController/index.js +300 -0
- package/lib/Player/App.js +5 -4
- package/lib/Player/Controller.d.ts +5 -1
- package/lib/Player/Controller.js +38 -5
- package/lib/Player/custom/SpatialScenePanel/index.d.ts +2 -2
- package/lib/Player/custom/SpatialScenePanel/index.js +98 -26
- package/lib/Player/index.d.ts +3 -2
- package/lib/Player/index.js +116 -24
- package/lib/Player/modules/Drawer/index.js +1 -1
- package/lib/Player/modules/PopUp/index.d.ts +2 -0
- package/lib/Player/modules/PopUp/index.js +43 -0
- package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +17 -2
- package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +113 -37
- package/lib/Player/modules/VideoAgent/VideoAgentScene.d.ts +5 -1
- package/lib/Player/modules/VideoAgent/VideoAgentScene.js +9 -4
- package/lib/Player/modules/VideoAgent/index.d.ts +2 -0
- package/lib/Player/modules/VideoAgent/index.js +2 -2
- package/lib/Player/modules/keyframes/BgMusic/index.js +1 -1
- package/lib/Player/modules/keyframes/CameraMovement/index.js +42 -6
- package/lib/Player/modules/keyframes/InfoPanel/index.js +74 -36
- package/lib/Player/modules/keyframes/ModelVideo/index.js +46 -9
- package/lib/Player/modules/keyframes/PanoEffect/index.js +1 -1
- package/lib/Player/modules/keyframes/PanoEffect/lineAnime.js +1 -1
- package/lib/Player/modules/keyframes/PanoTag/index.js +20 -7
- package/lib/Player/modules/keyframes/PanoTextLabel/index.d.ts +3 -0
- package/lib/Player/modules/keyframes/PanoTextLabel/index.js +96 -51
- package/lib/Player/modules/keyframes/Prompter/index.js +5 -19
- package/lib/Player/modules/keyframes/UpdateVRPanorama/index.js +31 -19
- package/lib/Player/modules/keyframes/VideoEffect/index.js +1 -1
- package/lib/Player/typings.d.ts +6 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.d.ts +2 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.js +12 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.d.ts +7 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.js +32 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.d.ts +3 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.js +11 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/index.d.ts +56 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/index.js +275 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.d.ts +7 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.js +18 -0
- package/lib/fivePlugins/CameraMovementPlugin/index.js +109 -94
- package/lib/fivePlugins/CameraMovementPlugin/typings.d.ts +1 -0
- package/lib/fivePlugins/ModelTVVideoPlugin/index.js +1 -1
- package/lib/react/index.d.ts +7 -3
- package/lib/react/index.js +3 -3
- package/lib/shared-utils/AduioLike.d.ts +37 -0
- package/lib/shared-utils/AduioLike.js +165 -0
- package/lib/shared-utils/animationFrame/BetterTween.js +7 -3
- package/lib/shared-utils/animationFrame/tween.js +1 -1
- package/lib/shared-utils/createTransMatrix.d.ts +1 -0
- package/lib/shared-utils/createTransMatrix.js +43 -0
- package/lib/typings/VreoUnit.d.ts +42 -5
- package/lib/typings/VreoUnit.js +26 -6
- package/package.json +8 -8
- package/resources/PlayController/createHTMLAudioElement.ts +53 -0
- package/resources/PlayController/index.ts +167 -0
- package/resources/Player/App.tsx +2 -0
- package/resources/Player/Controller.ts +155 -121
- package/resources/Player/custom/SpatialScenePanel/index.tsx +148 -45
- package/resources/Player/index.tsx +186 -110
- package/resources/Player/modules/PopUp/index.tsx +26 -0
- package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +67 -14
- package/resources/Player/modules/VideoAgent/VideoAgentScene.ts +3 -3
- package/resources/Player/modules/VideoAgent/index.tsx +3 -2
- package/resources/Player/modules/keyframes/CameraMovement/index.tsx +7 -3
- package/resources/Player/modules/keyframes/InfoPanel/index.tsx +79 -34
- package/resources/Player/modules/keyframes/ModelVideo/index.tsx +36 -3
- package/resources/Player/modules/keyframes/PanoTag/index.tsx +31 -12
- package/resources/Player/modules/keyframes/PanoTextLabel/index.tsx +87 -34
- package/resources/Player/modules/keyframes/Prompter/index.tsx +5 -15
- package/resources/Player/modules/keyframes/UpdateVRPanorama/index.tsx +25 -16
- package/resources/Player/typings.ts +5 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/centerPoint.ts +5 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/createResizeObserver.ts +17 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/evenNumber.ts +4 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/index.ts +254 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.ts +5 -0
- package/resources/fivePlugins/CameraMovementPlugin/index.ts +66 -52
- package/resources/fivePlugins/CameraMovementPlugin/typings.ts +2 -1
- package/resources/react/index.tsx +7 -3
- package/resources/shared-utils/AduioLike.ts +108 -0
- package/resources/shared-utils/createTransMatrix.ts +12 -0
- package/resources/typings/VreoUnit.ts +46 -5
- package/stylesheets/custom/SpatialScenePanel.css +14 -8
- package/stylesheets/default.css +116 -12
|
@@ -1,21 +1,66 @@
|
|
|
1
|
-
import classNames from 'classnames'
|
|
2
1
|
import * as React from 'react'
|
|
3
|
-
import
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import ReactDOM from 'react-dom'
|
|
4
|
+
import { Vector3, Quaternion } from 'three'
|
|
5
|
+
|
|
6
|
+
import { useController, useFiveInstance } from '../../../hooks'
|
|
7
|
+
import { CSS3DRenderPlugin } from '../../../../fivePlugins/CSS3DRenderPlugin'
|
|
4
8
|
import { PanoTextLabelData, VreoKeyframe, VreoKeyframeEnum } from '../../../../typings/VreoUnit'
|
|
5
|
-
import { useController, useFiveProject2d } from '../../../hooks'
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 通过传入中心点确定矩形框架容器的四个点:
|
|
12
|
+
* 1. 已知矩形长宽和中心点
|
|
13
|
+
* 2. 借助planeGeometry生成垂直相机视角的平面上的四个点
|
|
14
|
+
* 3. 通过向量相加,平行四边形法则获取到移动position后的面上四个点
|
|
15
|
+
*/
|
|
16
|
+
const calcPoints = (
|
|
17
|
+
centerPoint: Vector3,
|
|
18
|
+
normal: THREE.Vector3 | undefined,
|
|
19
|
+
wrapperLength: number,
|
|
20
|
+
wrapperWidth: number
|
|
21
|
+
) => {
|
|
22
|
+
// 375px 对应 1m
|
|
23
|
+
const length = wrapperLength / 375
|
|
24
|
+
const width = wrapperWidth / 375
|
|
25
|
+
|
|
26
|
+
const geometry = new THREE.PlaneGeometry(length, width)
|
|
27
|
+
if (normal) {
|
|
28
|
+
const lookPoint = new THREE.Vector3(normal.x + centerPoint.x, normal.y + centerPoint.y, normal.z + centerPoint.z)
|
|
29
|
+
geometry.lookAt(lookPoint)
|
|
30
|
+
}
|
|
31
|
+
// const pointgeometry = new THREE.Geometry()
|
|
32
|
+
// pointgeometry.vertices.push(cameraPosition)
|
|
33
|
+
// const pointmaterial = new THREE.PointsMaterial({
|
|
34
|
+
// color: 0xffffff,
|
|
35
|
+
// size: 0.4,
|
|
36
|
+
// })
|
|
37
|
+
// _point = new THREE.Points(pointgeometry, pointmaterial)
|
|
38
|
+
// console.log(cameraPosition)
|
|
39
|
+
|
|
40
|
+
const material = new THREE.MeshBasicMaterial({ color: 0xffff00, side: THREE.DoubleSide })
|
|
41
|
+
const plane = new THREE.Mesh(geometry, material)
|
|
42
|
+
const v0 = centerPoint.clone()
|
|
43
|
+
plane.position.copy(v0)
|
|
44
|
+
|
|
45
|
+
// 计算传入的四个点的坐标
|
|
46
|
+
const [v1, v2, v3, v4] = plane.geometry.vertices
|
|
47
|
+
const downLeft = v0.clone().add(v4)
|
|
48
|
+
const downRight = v0.clone().add(v3)
|
|
49
|
+
const upLeft = v0.clone().add(v2)
|
|
50
|
+
const upRight = v0.clone().add(v1)
|
|
51
|
+
|
|
52
|
+
// 插件使用要求:矩形四个点位数据,顺序为**必须**为左下、右下、右上、左上
|
|
53
|
+
return [downLeft, downRight, upRight, upLeft]
|
|
12
54
|
}
|
|
13
55
|
|
|
56
|
+
/**
|
|
57
|
+
* 空间文本标签。
|
|
58
|
+
*/
|
|
14
59
|
export function PanoTextLabel() {
|
|
15
|
-
const [state, setState] = React.useState<PanoTextLabelState | null>(null)
|
|
16
60
|
const timeoutRef = React.useRef<NodeJS.Timeout | null>()
|
|
17
61
|
const controller = useController()
|
|
18
|
-
const
|
|
62
|
+
const five = useFiveInstance()
|
|
63
|
+
const ref = React.useRef<ReturnType<typeof CSS3DRenderPlugin>>()
|
|
19
64
|
|
|
20
65
|
React.useEffect(() => {
|
|
21
66
|
if (controller.configs?.keyframeMap.PanoTextLabel === false) {
|
|
@@ -24,19 +69,43 @@ export function PanoTextLabel() {
|
|
|
24
69
|
const callback = (keyframe: VreoKeyframe) => {
|
|
25
70
|
const { start, end, data } = keyframe
|
|
26
71
|
const panoTextLabelData = data as PanoTextLabelData
|
|
72
|
+
// 增加无文本情况的判断
|
|
73
|
+
if (data.text === '') return
|
|
74
|
+
|
|
27
75
|
const { x, y, z } = panoTextLabelData.vertex
|
|
76
|
+
const centerPoint = new Vector3(x, y, z)
|
|
77
|
+
const normal = new Vector3(panoTextLabelData.normal?.x, panoTextLabelData.normal?.y, panoTextLabelData.normal?.z)
|
|
78
|
+
// 生成传入的四个点,将文本框最大宽度定在200px,最高高度在30px
|
|
79
|
+
const wrapperLength = 200
|
|
80
|
+
const wrapperWidth = 30
|
|
81
|
+
const points = calcPoints(centerPoint, panoTextLabelData.normal && normal, wrapperLength, wrapperWidth)
|
|
28
82
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
83
|
+
if (!ref.current) ref.current = CSS3DRenderPlugin(five)
|
|
84
|
+
const container = ref.current.create3DDomContainer(points)
|
|
85
|
+
const css3DObject = container?.css3DObject
|
|
86
|
+
// 将获取的mesh进行旋转操作,根据欧拉角去进行mesh的变换
|
|
87
|
+
if (data.quaternion) {
|
|
88
|
+
const quaternion = new Quaternion(data.quaternion.x, data.quaternion.y, data.quaternion.z, data.quaternion.w)
|
|
89
|
+
css3DObject?.quaternion.copy(quaternion)
|
|
90
|
+
}
|
|
91
|
+
if (container?.container)
|
|
92
|
+
ReactDOM.render(
|
|
93
|
+
<div className="PanoTextLabel PanoTextLabel--notHidden">
|
|
94
|
+
<div className="PanoTextLabel-wrapper">
|
|
95
|
+
<div style={{ fontSize: `${data.fontSize || 16}px` }} className="PanoText-innerText">
|
|
96
|
+
{data.text || ''}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</div>,
|
|
100
|
+
container?.container
|
|
101
|
+
)
|
|
32
102
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
103
|
+
timeoutRef.current = setTimeout(() => {
|
|
104
|
+
ref.current?.disposeAll()
|
|
105
|
+
}, end - start)
|
|
36
106
|
}
|
|
37
107
|
controller.on(VreoKeyframeEnum.PanoTextLabel, callback)
|
|
38
108
|
|
|
39
|
-
Object.assign(window, { $panoTextLabel: { setState } })
|
|
40
109
|
return () => {
|
|
41
110
|
controller.off(VreoKeyframeEnum.PanoTextLabel, callback)
|
|
42
111
|
if (timeoutRef.current) {
|
|
@@ -45,21 +114,5 @@ export function PanoTextLabel() {
|
|
|
45
114
|
}
|
|
46
115
|
}, [controller])
|
|
47
116
|
|
|
48
|
-
return
|
|
49
|
-
<div
|
|
50
|
-
className={classNames('PanoTextLabel', {
|
|
51
|
-
'PanoTextLabel--notHidden': state,
|
|
52
|
-
})}
|
|
53
|
-
style={{
|
|
54
|
-
left: (state?.left || 0) + 'px',
|
|
55
|
-
top: (state?.top || 0) + 'px',
|
|
56
|
-
}}
|
|
57
|
-
>
|
|
58
|
-
<div className="PanoTextLabel-wrapper">
|
|
59
|
-
<div style={{ fontSize: `${state?.fontSize || 16}px` }} className="PanoText-innerText">
|
|
60
|
-
{state?.text || ''}
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
)
|
|
117
|
+
return <></>
|
|
65
118
|
}
|
|
@@ -2,7 +2,6 @@ import * as React from 'react'
|
|
|
2
2
|
import classNames from 'classnames'
|
|
3
3
|
import { useController } from '../../../hooks'
|
|
4
4
|
|
|
5
|
-
import { CSSTransition, TransitionGroup } from 'react-transition-group'
|
|
6
5
|
import { VreoKeyframe, VreoKeyframeEnum } from '../../../../typings/VreoUnit'
|
|
7
6
|
|
|
8
7
|
export function Prompter() {
|
|
@@ -27,7 +26,8 @@ export function Prompter() {
|
|
|
27
26
|
|
|
28
27
|
ref.current = setTimeout(() => {
|
|
29
28
|
setHidden(true)
|
|
30
|
-
|
|
29
|
+
setText('')
|
|
30
|
+
// setTimeout(() => setText(''), 500)
|
|
31
31
|
|
|
32
32
|
if (ref.current) clearTimeout(ref.current)
|
|
33
33
|
ref.current = null
|
|
@@ -48,19 +48,9 @@ export function Prompter() {
|
|
|
48
48
|
'vreo-prompter--audio': controller.isAudio,
|
|
49
49
|
})}
|
|
50
50
|
>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<CSSTransition
|
|
55
|
-
key={text}
|
|
56
|
-
classNames="vreo-prompter-text-transition"
|
|
57
|
-
timeout={500}
|
|
58
|
-
addEndListener={(node, done) => node.addEventListener('transitionend', done, false)}
|
|
59
|
-
>
|
|
60
|
-
<div className="vreo-prompter-innerText">{text}</div>
|
|
61
|
-
</CSSTransition>
|
|
62
|
-
</TransitionGroup>
|
|
63
|
-
) : undefined}
|
|
51
|
+
<div className="vreo-prompter-text">
|
|
52
|
+
<div className="vreo-prompter-innerText">{text}</div>
|
|
53
|
+
</div>
|
|
64
54
|
</div>
|
|
65
55
|
)
|
|
66
56
|
}
|
|
@@ -6,49 +6,56 @@ import { UpdateVRPanoramaData, VreoKeyframe, VreoKeyframeEnum } from '../../../.
|
|
|
6
6
|
export function UpdateVRPanorama() {
|
|
7
7
|
const controller = useController()
|
|
8
8
|
const five = useFiveInstance()
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const deafultWorkRef = React.useRef<string[] | null>(null)
|
|
10
|
+
const updateWorkRef = React.useRef<Work | null>(null)
|
|
11
11
|
|
|
12
|
+
// 恢复默认 VR
|
|
12
13
|
const restoreCallback = React.useCallback(() => {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
// 先清理掉 之前的 VR 数据备份
|
|
15
|
+
updateWorkRef.current = null
|
|
16
|
+
|
|
17
|
+
if (deafultWorkRef.current) {
|
|
18
|
+
const work = parseWork(deafultWorkRef.current)
|
|
15
19
|
five.load(work)
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
workRef.current = null
|
|
19
22
|
}, [])
|
|
20
23
|
|
|
24
|
+
// 暂停时: 恢复默认 VR
|
|
21
25
|
const pausedCallback = React.useCallback(() => {
|
|
22
|
-
if (
|
|
23
|
-
const work = parseWork(
|
|
26
|
+
if (deafultWorkRef.current) {
|
|
27
|
+
const work = parseWork(deafultWorkRef.current)
|
|
28
|
+
Object.assign(window, {$rawWork: work})
|
|
24
29
|
five.load(work)
|
|
25
30
|
}
|
|
26
31
|
}, [])
|
|
27
32
|
|
|
33
|
+
// 播放时:如果暂停前有更新 VR 需要还原
|
|
28
34
|
const playingCallback = React.useCallback(() => {
|
|
29
|
-
if (!
|
|
35
|
+
if (!updateWorkRef.current) {
|
|
30
36
|
return
|
|
31
37
|
}
|
|
32
|
-
five.load(
|
|
38
|
+
five.load(updateWorkRef.current)
|
|
33
39
|
}, [])
|
|
34
40
|
|
|
35
41
|
React.useEffect(() => {
|
|
36
42
|
const callback = (keyframe: VreoKeyframe) => {
|
|
37
|
-
if (!
|
|
38
|
-
|
|
43
|
+
if (!deafultWorkRef.current) {
|
|
44
|
+
deafultWorkRef.current = five.work.raw.works
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
const data = keyframe.data as UpdateVRPanoramaData
|
|
42
48
|
|
|
43
49
|
// 如果数据中有新 work 数据,则直接载入
|
|
44
50
|
if (data.work) {
|
|
45
|
-
|
|
46
|
-
five.load(
|
|
51
|
+
updateWorkRef.current = parseWork(data.work)
|
|
52
|
+
five.load(updateWorkRef.current)
|
|
47
53
|
return
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
const lastRawWork = five.work?.raw.works[0]
|
|
51
57
|
|
|
58
|
+
|
|
52
59
|
// 动态场景:不提供完成的签名数据,需重新整理
|
|
53
60
|
if (data.dynamic_scene && !data.panorama) {
|
|
54
61
|
const lastWork = JSON.parse(lastRawWork)
|
|
@@ -59,8 +66,10 @@ export function UpdateVRPanorama() {
|
|
|
59
66
|
delete data.dynamic_scene
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
Object.assign(window, {$work1: JSON.parse(lastRawWork), $work2: data, parseWork: parseWork})
|
|
70
|
+
|
|
71
|
+
updateWorkRef.current = parseWork([lastRawWork, data])
|
|
72
|
+
five.load(updateWorkRef.current)
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
controller.on(VreoKeyframeEnum.UpdateVRPanorama, callback)
|
|
@@ -84,7 +93,7 @@ export function UpdateVRPanorama() {
|
|
|
84
93
|
controller.off('paused', pausedCallback)
|
|
85
94
|
controller.off('playing', playingCallback)
|
|
86
95
|
}
|
|
87
|
-
}, [
|
|
96
|
+
}, [])
|
|
88
97
|
|
|
89
98
|
return <></>
|
|
90
99
|
}
|
|
@@ -2,6 +2,7 @@ import React, { ReactNode } from 'react';
|
|
|
2
2
|
import { Subscribe, Five } from '@realsee/five';
|
|
3
3
|
|
|
4
4
|
import { VreoKeyframeConfigMap, VreoKeyframeEvent } from '../typings/VreoUnit'
|
|
5
|
+
import { VideoAgentMeshOptions } from './modules/VideoAgent/VideoAgentMesh';
|
|
5
6
|
|
|
6
7
|
export interface PlayerConfigs {
|
|
7
8
|
containter?: ReactDOM.Container
|
|
@@ -15,11 +16,15 @@ export interface PlayerConfigs {
|
|
|
15
16
|
videoEffect?: HTMLVideoElement
|
|
16
17
|
modelTVVideo?: HTMLVideoElement
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
videoAgentMeshOptions?: VideoAgentMeshOptions
|
|
18
21
|
/**
|
|
19
22
|
* 如果需要在 底部面板添加自定义内容,可以传递个 React 组件。
|
|
20
23
|
*/
|
|
21
24
|
customPanelChildren?: ReactNode
|
|
22
25
|
customKeyframes?: React.FC<CustomVreoKeyframeProps>[]
|
|
26
|
+
imageOptions?: { size: number }
|
|
27
|
+
autoPreload?: boolean
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export type VreoSubscribe = Pick<Subscribe<VreoKeyframeEvent>, 'on' | 'once' | 'off'>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description: 简陋的 ResizeObserver polyfill
|
|
3
|
+
*/
|
|
4
|
+
export default function createResizeObserver(func: () => any, element?: HTMLElement) {
|
|
5
|
+
if (!element || typeof ResizeObserver === 'undefined') {
|
|
6
|
+
return {
|
|
7
|
+
observe: () => window.addEventListener('resize', func),
|
|
8
|
+
unobserve: () => window.removeEventListener('resize', func),
|
|
9
|
+
}
|
|
10
|
+
} else {
|
|
11
|
+
const observer = new ResizeObserver(func)
|
|
12
|
+
return {
|
|
13
|
+
observe: () => observer.observe(element),
|
|
14
|
+
unobserve: () => observer.unobserve(element),
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { FivePlugin } from '@realsee/five'
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import { Scene, Vector3 } from 'three'
|
|
4
|
+
import { CSS3DObject, CSS3DRenderer } from 'three/examples/jsm/renderers/CSS3DRenderer'
|
|
5
|
+
import evenNumber from './evenNumber'
|
|
6
|
+
import centerPoint from './centerPoint'
|
|
7
|
+
import transformPositionToVector3 from './transformPositionToVector3'
|
|
8
|
+
import createResizeObserver from './createResizeObserver'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 三维向量
|
|
12
|
+
*/
|
|
13
|
+
export interface Vector3Position {
|
|
14
|
+
x: number
|
|
15
|
+
y: number
|
|
16
|
+
z: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CSS3DRenderPluginParameterType = undefined
|
|
20
|
+
export interface CSS3DRenderPluginExportType {
|
|
21
|
+
/**
|
|
22
|
+
* @description: 根据传入的四个点位创建一个3d dom容器,可以通过ReactDom.render()的方式将react组件放到容器中
|
|
23
|
+
* @param {Five} five
|
|
24
|
+
* @param {Vector3[] | Vector3Position[]} points: 矩形四个点坐标
|
|
25
|
+
* @param {number} config.ratio: 1px对应多少米,默认为 0.002,即1px对应2mm
|
|
26
|
+
* @param {number} config.dpr: dpr, 默认为1
|
|
27
|
+
* @param {HTMLElement} config.container: HTMLElement
|
|
28
|
+
* @param {number} config.autoRender: 默认为true,如果需要手动render则传false
|
|
29
|
+
* @param {'front' | 'behind'} config.mode: 两种模式
|
|
30
|
+
* @param {HTMLElement} config.behindFiveContainer: 如果config.mode为'behind',需要传入容器,并确保此容器位five下方,且中间没有其他dom元素遮挡
|
|
31
|
+
* @return {{ container: HTMLElement; dispose: () => void }}: container: dom容器, dispose: 清理函数
|
|
32
|
+
*/
|
|
33
|
+
create3DDomContainer: (
|
|
34
|
+
points: Vector3[] | Vector3Position[],
|
|
35
|
+
config?: { ratio?: number; dpr?: number; autoRender?: boolean; container?: HTMLElement; [key: string]: any } & (
|
|
36
|
+
| { mode?: 'front' }
|
|
37
|
+
| { mode: 'behind'; behindFiveContainer: HTMLElement }
|
|
38
|
+
),
|
|
39
|
+
) => { container: HTMLElement; dispose: () => void; css3DObject: CSS3DObject; render?: () => void } | void
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @description: 销毁所有的渲染内容
|
|
43
|
+
* @return {void}
|
|
44
|
+
*/
|
|
45
|
+
disposeAll: () => void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Create3DDomContainerInterface = CSS3DRenderPluginExportType['create3DDomContainer']
|
|
49
|
+
type Create3DDomContainerConfigInterface = NonNullable<Parameters<Create3DDomContainerInterface>[1]>
|
|
50
|
+
interface CSS3DRenderPluginState {
|
|
51
|
+
disposeCallbacks: (() => boolean)[]
|
|
52
|
+
frontMode?: {
|
|
53
|
+
scene: Scene
|
|
54
|
+
css3DRenderer: CSS3DRenderer
|
|
55
|
+
}
|
|
56
|
+
behindMode?: {
|
|
57
|
+
scene: Scene
|
|
58
|
+
css3DRenderer: CSS3DRenderer
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* **CSS3DRenderPlugin** 提供矩形区域(三维空间四个坐标点),你可以在此矩形区域中渲染 DOM 内容。
|
|
64
|
+
* 实现原理参考[CSS3DRenderer](https://threejs.org/docs/index.html?q=CSS3D#examples/en/renderers/CSS3DRenderer)。
|
|
65
|
+
*
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
export const CSS3DRenderPlugin: FivePlugin<CSS3DRenderPluginParameterType, CSS3DRenderPluginExportType> = (five) => {
|
|
69
|
+
const state: CSS3DRenderPluginState = { disposeCallbacks: [] }
|
|
70
|
+
const create3DDomContainer = (
|
|
71
|
+
...params: Parameters<Create3DDomContainerInterface>
|
|
72
|
+
): ReturnType<Create3DDomContainerInterface> => {
|
|
73
|
+
const points = params[0].map((point) => (point instanceof Vector3 ? point : transformPositionToVector3(point)))
|
|
74
|
+
const config = params[1]
|
|
75
|
+
if (points?.length < 4) return console.error('points must be equal or greater than than 4')
|
|
76
|
+
if (!five?.model?.loaded) return console.error('five.model.loaded is: ', five?.model?.loaded)
|
|
77
|
+
const fiveElement = five.getElement()
|
|
78
|
+
if (!fiveElement) return console.error('five.getElement() is ' + fiveElement)
|
|
79
|
+
|
|
80
|
+
const disposers: any[] = []
|
|
81
|
+
const ratio = config?.ratio || 0.00216
|
|
82
|
+
if (ratio <= 0.00215) console.warn('if you need click css3DElement on safari, ratio must be greater than 0.00215')
|
|
83
|
+
const dpr = config?.dpr || 1
|
|
84
|
+
const mode = config?.mode || 'front'
|
|
85
|
+
const autoRender = config?.autoRender ?? true
|
|
86
|
+
const behindFiveContainer = config?.behindFiveContainer || fiveElement.parentElement || document.body
|
|
87
|
+
const container = config?.container || document.createElement('div')
|
|
88
|
+
container.classList.add('__Dnalogel-plugin--CSS3DRenderPlugin')
|
|
89
|
+
|
|
90
|
+
// 获取css3DObject, 如果mode为behind的话,一起获取mesh
|
|
91
|
+
const { css3DObject, mesh } = createObject(points, { ratio, dpr, container, mode })
|
|
92
|
+
|
|
93
|
+
// ======= INIT START =======
|
|
94
|
+
let resizeObserver:
|
|
95
|
+
| {
|
|
96
|
+
observe?: () => void
|
|
97
|
+
unobserve?: () => void
|
|
98
|
+
}
|
|
99
|
+
| undefined
|
|
100
|
+
const frontModeUnInited = mode === 'front' && !state.frontMode
|
|
101
|
+
const behindModeUnInited = mode === 'behind' && !state.behindMode
|
|
102
|
+
const inited = !(frontModeUnInited || behindModeUnInited)
|
|
103
|
+
let stopRenderFlag = false
|
|
104
|
+
let requestAnimationFrameId: number | null = null
|
|
105
|
+
|
|
106
|
+
if (behindModeUnInited) {
|
|
107
|
+
state.behindMode = { scene: new Scene(), css3DRenderer: new CSS3DRenderer() }
|
|
108
|
+
}
|
|
109
|
+
if (frontModeUnInited) {
|
|
110
|
+
state.frontMode = { scene: new Scene(), css3DRenderer: new CSS3DRenderer() }
|
|
111
|
+
}
|
|
112
|
+
const { scene, css3DRenderer } = mode === 'behind' ? state.behindMode! : state.frontMode!
|
|
113
|
+
|
|
114
|
+
const render = (() => {
|
|
115
|
+
if (!inited) {
|
|
116
|
+
const css3DRendererSetSize = () => {
|
|
117
|
+
// 这里evenNumber策略是遇到奇数会加1,不知道为啥会触发滚动条显示,导致fiveElement变小,fiveElement变小又触发了这里的resize,宽高变小,滚动条消失,然后又触发resize。。。无限循环
|
|
118
|
+
// 为了规避上面这种情况,evenNumber设置了一个参数,遇到奇数可选择减一
|
|
119
|
+
const rendererWidth = evenNumber(fiveElement.clientWidth, { smaller: true })
|
|
120
|
+
const rendererHeight = evenNumber(fiveElement.clientHeight, { smaller: true })
|
|
121
|
+
css3DRenderer.setSize(rendererWidth, rendererHeight)
|
|
122
|
+
}
|
|
123
|
+
css3DRendererSetSize()
|
|
124
|
+
resizeObserver = createResizeObserver(css3DRendererSetSize, fiveElement)
|
|
125
|
+
css3DRenderer.domElement.style.position = 'absolute'
|
|
126
|
+
css3DRenderer.domElement.style.top = '0'
|
|
127
|
+
css3DRenderer.domElement.style.userSelect = 'none'
|
|
128
|
+
css3DRenderer.domElement.style.pointerEvents = 'none'
|
|
129
|
+
|
|
130
|
+
const renderEveryFrame = () => {
|
|
131
|
+
if (stopRenderFlag) return
|
|
132
|
+
requestAnimationFrameId = requestAnimationFrame(renderEveryFrame)
|
|
133
|
+
css3DRenderer.render(scene!, five.camera)
|
|
134
|
+
}
|
|
135
|
+
return () => {
|
|
136
|
+
scene.add(css3DObject)
|
|
137
|
+
resizeObserver?.observe?.()
|
|
138
|
+
renderEveryFrame()
|
|
139
|
+
if (mode === 'behind' && mesh) {
|
|
140
|
+
five.scene.add(mesh)
|
|
141
|
+
disposers.push(() => mesh && five.scene.remove(mesh))
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
return () => {
|
|
146
|
+
scene.add(css3DObject)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
})()
|
|
150
|
+
if (frontModeUnInited) {
|
|
151
|
+
const wrapper = fiveElement.parentElement || document.body
|
|
152
|
+
wrapper.appendChild(css3DRenderer.domElement)
|
|
153
|
+
}
|
|
154
|
+
if (behindModeUnInited) {
|
|
155
|
+
const wrapper = behindFiveContainer
|
|
156
|
+
wrapper.appendChild(css3DRenderer.domElement)
|
|
157
|
+
}
|
|
158
|
+
// ======= INIT END =======
|
|
159
|
+
|
|
160
|
+
const dispose = () => {
|
|
161
|
+
stopRenderFlag = true
|
|
162
|
+
disposers.forEach((d) => d?.())
|
|
163
|
+
scene.remove(css3DObject)
|
|
164
|
+
if (typeof requestAnimationFrameId === 'number') cancelAnimationFrame(requestAnimationFrameId)
|
|
165
|
+
if (scene.children.length === 0) {
|
|
166
|
+
css3DRenderer.domElement.remove()
|
|
167
|
+
if (mode === 'front') state.frontMode = undefined
|
|
168
|
+
if (mode === 'behind') state.behindMode = undefined
|
|
169
|
+
if (!state.behindMode && !state.frontMode) {
|
|
170
|
+
resizeObserver?.unobserve?.()
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return true
|
|
174
|
+
}
|
|
175
|
+
const idx = state.disposeCallbacks.findIndex((item) => item === dispose)
|
|
176
|
+
if (idx !== -1) {
|
|
177
|
+
state.disposeCallbacks.splice(idx, 1)
|
|
178
|
+
} else {
|
|
179
|
+
state.disposeCallbacks.push(dispose)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (autoRender) render()
|
|
183
|
+
return { container, dispose, css3DObject, render: autoRender ? undefined : render }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const createObject = (
|
|
187
|
+
points: Vector3[],
|
|
188
|
+
config: Required<Pick<Create3DDomContainerConfigInterface, 'ratio' | 'dpr' | 'container'>> &
|
|
189
|
+
Pick<Create3DDomContainerConfigInterface, 'mode'>,
|
|
190
|
+
) => {
|
|
191
|
+
const { ratio, dpr, container: element, mode } = config
|
|
192
|
+
const planeWidth = points[0].distanceTo(points[1])
|
|
193
|
+
const planeHeight = points[1].distanceTo(points[2])
|
|
194
|
+
const domWidthPx = evenNumber((planeWidth / ratio) * dpr)
|
|
195
|
+
const domHeightPx = evenNumber((planeHeight / ratio) * dpr)
|
|
196
|
+
|
|
197
|
+
const css3DObject = new CSS3DObject(element)
|
|
198
|
+
css3DObject.scale.set(ratio, ratio, ratio)
|
|
199
|
+
element.style.width = domWidthPx + 'px'
|
|
200
|
+
element.style.height = domHeightPx + 'px'
|
|
201
|
+
element.style.pointerEvents = 'none'
|
|
202
|
+
|
|
203
|
+
const centerPosition = centerPoint(points[0], points[2])
|
|
204
|
+
|
|
205
|
+
const vector01 = points[1].clone().sub(points[0]) // 点0 -> 点1 的向量
|
|
206
|
+
const vector12 = points[2].clone().sub(points[1]) // 点1 -> 点2 的向量
|
|
207
|
+
|
|
208
|
+
// 旋转
|
|
209
|
+
const rotateXAngle = new Vector3(0, 1, 0).angleTo(new Vector3(0, vector12.y, vector12.z))
|
|
210
|
+
const rotateYAngle = new Vector3(1, 0, 0).angleTo(new Vector3(vector01.x, 0, vector01.z))
|
|
211
|
+
const rotateZAngle = vector01.angleTo(new Vector3(vector01.x, 0, vector01.z))
|
|
212
|
+
/**
|
|
213
|
+
* [0,1,0] => [0,0,1] 为rolate Worldx正方向
|
|
214
|
+
* [0,0,1] => [0,1,0] 为rolate Worldy正方向
|
|
215
|
+
* [0,1,1] => [-1,0,0] 为rolate Worldz正方向
|
|
216
|
+
*/
|
|
217
|
+
const rotateX = (vector12.z > 0 ? -1 : 1) * rotateXAngle
|
|
218
|
+
const rotateY = (vector01.z < 0 ? 1 : -1) * rotateYAngle
|
|
219
|
+
const rotateZ = ((vector01.x > 0 && vector01.y < 0) || (vector01.x < 0 && vector01.y > 0) ? -1 : 1) * rotateZAngle
|
|
220
|
+
|
|
221
|
+
css3DObject.rotateOnWorldAxis(new Vector3(1, 0, 0), rotateX) // x
|
|
222
|
+
css3DObject.rotateOnWorldAxis(new Vector3(0, 1, 0), rotateY) // y
|
|
223
|
+
css3DObject.rotateOnWorldAxis(new Vector3(0, 0, 1), rotateZ) // z
|
|
224
|
+
|
|
225
|
+
css3DObject.position.set(centerPosition.x, centerPosition.y, centerPosition.z)
|
|
226
|
+
|
|
227
|
+
let mesh: THREE.Mesh<THREE.PlaneGeometry, THREE.MeshBasicMaterial> | undefined
|
|
228
|
+
if (mode === 'behind') {
|
|
229
|
+
const material = new THREE.MeshBasicMaterial({
|
|
230
|
+
opacity: 0,
|
|
231
|
+
transparent: false,
|
|
232
|
+
side: THREE.DoubleSide,
|
|
233
|
+
})
|
|
234
|
+
const geometry = new THREE.PlaneGeometry(domWidthPx, domHeightPx)
|
|
235
|
+
mesh = new THREE.Mesh(geometry, material)
|
|
236
|
+
mesh.name = 'CSS3DRenderPlugin-mesh'
|
|
237
|
+
mesh.position.copy(css3DObject.position)
|
|
238
|
+
mesh.rotation.copy(css3DObject.rotation)
|
|
239
|
+
mesh.scale.copy(css3DObject.scale)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return { css3DObject, mesh }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
create3DDomContainer,
|
|
247
|
+
disposeAll: () => {
|
|
248
|
+
state.disposeCallbacks.forEach((d) => d?.())
|
|
249
|
+
state.disposeCallbacks = []
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export default CSS3DRenderPlugin
|