Skip to content

Commit

Permalink
feat: add teleport
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Oct 5, 2024
1 parent c7063a5 commit cb5bcee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { OrbitControls } from '@react-three/drei'
import { Canvas } from '@react-three/fiber'
import { createXRStore, IfInSessionMode, XR, XROrigin } from '@react-three/xr'
import { createXRStore, IfInSessionMode, XR } from '@react-three/xr'
import { Leva } from 'leva'

import { Model } from './components/model'
import { Perf } from './components/perf'
import { Stage } from './components/stage'
import { Toolbar } from './components/toolbar'
import { Origin } from './components/xr/origin'

export const App = () => {
const store = createXRStore({
Expand All @@ -25,9 +26,7 @@ export const App = () => {
<Leva />
<Canvas camera={{ position: [0, 0, 2] }} shadows style={{ flexGrow: 1, width: '100%' }}>
<XR store={store}>
<group position={[0, 0, 2]}>
<XROrigin />
</group>
<Origin />
<IfInSessionMode deny={['immersive-ar', 'immersive-vr']}>
<Perf />
<Toolbar />
Expand Down
28 changes: 28 additions & 0 deletions src/components/xr/origin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { TeleportTarget, XROrigin } from '@react-three/xr'
import { useState } from 'react'
import { Vector3 } from 'three'

export const Origin = () => {
const [position, setPosition] = useState(new Vector3(0, 0, 2))

/** @see {@link https://pmndrs.github.io/xr/docs/tutorials/teleport} */
return (
<>
<XROrigin position={position} />
<TeleportTarget onTeleport={setPosition}>
<mesh position={[0, 0, 0]} scale={[0.5, 0.001, 0.5]}>
<sphereGeometry />
<meshPhysicalMaterial
color="white"
ior={1.5}
opacity={0.15}
specularColor="white"
specularIntensity={1}
transmission={1}
transparent
/>
</mesh>
</TeleportTarget>
</>
)
}

0 comments on commit cb5bcee

Please sign in to comment.