Skip to content

Commit 9bda2c4

Browse files
docs(examples): implemented example of an object that is linked to camera (#288)
1 parent 7ae5476 commit 9bda2c4

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Box } from '@react-three/drei'
2+
import { Canvas, createPortal, useThree } from '@react-three/fiber'
3+
import { VRButton, XR } from '@react-three/xr'
4+
import { ComponentProps } from 'react'
5+
6+
function Object(props: ComponentProps<typeof Box>) {
7+
return (
8+
<Box {...props} args={[0.4, 0.1, 0.1]}>
9+
<meshStandardMaterial color="blue" />
10+
</Box>
11+
)
12+
}
13+
14+
function CameraLinkedObject() {
15+
const camera = useThree((state) => state.camera)
16+
return createPortal(<Object position={[0, 0.6, -1]} />, camera)
17+
}
18+
19+
export default function () {
20+
return (
21+
<>
22+
<VRButton />
23+
<Canvas>
24+
<XR>
25+
<ambientLight intensity={0.5} />
26+
<pointLight position={[5, 5, 5]} />
27+
<CameraLinkedObject />
28+
</XR>
29+
</Canvas>
30+
</>
31+
)
32+
}

examples/src/demos/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ const Player = { Component: lazy(() => import('./Player')) }
66
const Text = { Component: lazy(() => import('./Text')) }
77
const Hands = { Component: lazy(() => import('./Hands')) }
88
const Teleport = { Component: lazy(() => import('./Teleport')) }
9+
const CameraLinkedObject = { Component: lazy(() => import('./CameraLinkedObject')) }
910

10-
export { Interactive, HitTest, Player, Text, Hands, Teleport }
11+
export { Interactive, HitTest, Player, Text, Hands, Teleport, CameraLinkedObject }

0 commit comments

Comments
 (0)