1
1
import { Canvas , useThree } from '@react-three/fiber'
2
2
import { createXRStore , useHover , XR , XRLayer } from '@react-three/xr'
3
+ import { Text } from '@react-three/drei'
3
4
import { useEffect , useMemo , useRef } from 'react'
4
- import { Mesh } from 'three'
5
+ import { Mesh , SRGBColorSpace , VideoTexture } from 'three'
5
6
import { forwardHtmlEvents } from '@pmndrs/pointer-events'
6
7
7
8
const store = createXRStore ( {
@@ -10,11 +11,16 @@ const store = createXRStore({
10
11
11
12
export function App ( ) {
12
13
// eslint-disable-next-line react-hooks/rules-of-hooks
13
- const image = useMemo ( ( ) => {
14
+ const video = useMemo ( ( ) => {
14
15
const result = document . createElement ( 'video' )
15
16
result . src = 'test.mp4'
16
17
return result
17
18
} , [ ] )
19
+ const videoTexture = useMemo ( ( ) => {
20
+ const texture = new VideoTexture ( video )
21
+ texture . colorSpace = SRGBColorSpace
22
+ return texture
23
+ } , [ video ] )
18
24
return (
19
25
< >
20
26
< button onClick = { ( ) => store . enterAR ( ) } > Enter AR</ button >
@@ -25,23 +31,18 @@ export function App() {
25
31
>
26
32
< SwitchToXRPointerEvents />
27
33
< XR store = { store } >
28
- { image != null && (
29
- < XRLayer
30
- position = { [ 0 , 1.5 , - 0.5 ] }
31
- onClick = { ( ) => image . play ( ) }
32
- scale = { 0.5 }
33
- shape = "quad"
34
- pixelHeight = { 1024 }
35
- pixelWidth = { 1024 }
36
- centralAngle = { Math . PI }
37
- centralHorizontalAngle = { Math . PI }
38
- lowerVerticalAngle = { - Math . PI / 2 }
39
- upperVerticalAngle = { Math . PI / 2 }
40
- src = { image }
41
- >
42
- < Inner />
43
- </ XRLayer >
44
- ) }
34
+ < Text scale = { 0.03 } color = "black" position = { [ - 0.3 , 1.78 , - 0.5 ] } >
35
+ With XRLayer
36
+ </ Text >
37
+ < XRLayer position = { [ - 0.3 , 1.5 , - 0.5 ] } onClick = { ( ) => video . play ( ) } scale = { 0.5 } shape = "quad" src = { video } />
38
+
39
+ < Text scale = { 0.03 } color = "black" position = { [ 0.3 , 1.78 , - 0.5 ] } >
40
+ Without XRLayer
41
+ </ Text >
42
+ < mesh position = { [ 0.3 , 1.5 , - 0.5 ] } scale = { 0.5 } >
43
+ < planeGeometry />
44
+ < meshBasicMaterial map = { videoTexture } toneMapped = { false } />
45
+ </ mesh >
45
46
</ XR >
46
47
</ Canvas >
47
48
</ >
0 commit comments