Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
fix peer deps, improve xrFrame hook
Browse files Browse the repository at this point in the history
  • Loading branch information
michealparks committed Aug 6, 2023
1 parent 7173ead commit 75fb738
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 55 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ This hook gives you access to the current state configured by `<XR />`.
import { useXR } from 'threlte-xr'

const {
controllers, // Writable<XRController[]>
isPresenting, // CurrentWritable<boolean> - Whether the XR device is presenting in an XR session
isHandTracking, // CurrentWritable<boolean> - Whether hand tracking inputs are active
session, // CurrentWritable<XRSession | undefined> - The active `XRSession`
xrFrame, // CurrentWritable<XRFrame> - The current XRFrame
xrFrame, // { current: XRFrame } - The current XRFrame
} = useXR()
```

Expand Down
62 changes: 29 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "threlte-xr",
"version": "0.0.31",
"version": "0.0.32",
"license": "MIT",
"scripts": {
"start": "vite dev --host",
Expand All @@ -27,17 +27,17 @@
"!dist/**/*.spec.*"
],
"peerDependencies": {
"svelte": "^3.54.0",
"three": "^0.153.0"
"svelte": ">=4",
"three": ">=0.135"
},
"devDependencies": {
"@dimforge/rapier3d-compat": "^0.11.2",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.22.4",
"@sveltejs/package": "^2.2.0",
"@threlte/core": "^6.0.2",
"@threlte/extras": "^5.0.4",
"@threlte/rapier": "^1.0.3",
"@threlte/core": "^6.0.3",
"@threlte/extras": "^5.0.5",
"@threlte/rapier": "^1.0.4",
"@types/three": "^0.155.0",
"autoprefixer": "^10.4.14",
"nice-color-palettes": "^3.0.0",
Expand All @@ -46,7 +46,7 @@
"svelte": "^4.1.2",
"svelte-check": "^3.4.6",
"tailwindcss": "^3.3.3",
"three": "^0.153.0",
"three": "^0.155.0",
"three-inspect": "^0.3.4",
"tslib": "^2.6.1",
"typescript": "^5.1.6",
Expand All @@ -61,8 +61,11 @@
"three.js",
"3d",
"threlte",
"vr",
"ar",
"xr",
"virtual reality",
"augmented reality"
"augmented reality",
"mixed reality"
]
}
10 changes: 2 additions & 8 deletions src/lib/components/xr.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ and interaction. This should be placed within a Threlte `<Canvas />`.
<script lang='ts'>
import { onDestroy } from 'svelte';
import { useThrelte, createRawEventDispatcher, useFrame } from '@threlte/core'
import { useThrelte, createRawEventDispatcher } from '@threlte/core'
import type { XRSessionEvent } from '$lib/types'
import { session, referenceSpaceType, isPresenting, isHandTracking, xrFrame, initialized, xr as xrStore } from '$lib/internal/stores'
import { session, referenceSpaceType, isPresenting, isHandTracking, initialized, xr as xrStore } from '$lib/internal/stores'
/**
* Enables foveated rendering. `Default is `0`
Expand Down Expand Up @@ -57,18 +57,12 @@ type $$Events = {
const dispatch = createRawEventDispatcher<$$Events>()
const { xr } = useThrelte().renderer
const { start, stop } = useFrame(() => {
xrFrame.set(xr.getFrame())
}, { autostart: false })
const handleSessionStart = (event: XRSessionEvent<'sessionstart'>) => {
start()
$isPresenting = true
dispatch('sessionstart', { ...event, target: $session! })
}
const handleSessionEnd = (event: XRSessionEvent<'sessionend'>) => {
stop()
dispatch('sessionend', { ...event, target: $session! })
$isPresenting = false
$session = undefined
Expand Down
10 changes: 7 additions & 3 deletions src/lib/hooks/use-xr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import {
isPresenting,
isHandTracking,
session,
xrFrame,
xr
} from '$lib/internal/stores'

const stores = {
isPresenting,
isHandTracking,
session,
xrFrame,
xrFrame: {
get current() {
return xr.current!.getFrame()
},
},
}

/**
Expand All @@ -20,5 +24,5 @@ export const useXR = (): {
isPresenting: CurrentWritable<boolean>
isHandTracking: CurrentWritable<boolean>
session: CurrentWritable<XRSession | undefined>
xrFrame: CurrentWritable<XRFrame | undefined>
xrFrame: { current: XRFrame }
} => stores
1 change: 0 additions & 1 deletion src/lib/internal/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const initialized = writable(false)
export const isPresenting = currentWritable(false)
export const isHandTracking = currentWritable(false)

export const xrFrame = currentWritable<XRFrame>(null!)
export const session = currentWritable<XRSession | undefined>(undefined)
export const referenceSpaceType = currentWritable<XRReferenceSpaceType | undefined>(undefined)
export const activeTeleportController = currentWritable<THREE.XRTargetRaySpace | undefined>(undefined)
Expand Down
6 changes: 6 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang='ts'>
import { onMount } from 'svelte'
import { base } from '$app/paths'
import * as THREE from 'three'
const demos = [
['Events', 'events'],
Expand All @@ -12,6 +14,10 @@ const demos = [
['Hand Physics', 'hand-physics'],
] as const
onMount(() => {
window.THREE = THREE
})
</script>

<main class='p-4'>
Expand Down

0 comments on commit 75fb738

Please sign in to comment.