@threlte/xr 1.3.0 → 1.5.0

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.
@@ -72,7 +72,7 @@
72
72
 
73
73
  const { scene } = useThrelte()
74
74
 
75
- const handedness = $derived<'left' | 'right'>(left ? 'left' : right ? 'right' : hand ?? 'left')
75
+ const handedness = $derived<'left' | 'right'>(left ? 'left' : right ? 'right' : (hand ?? 'left'))
76
76
 
77
77
  $effect.pre(() => {
78
78
  controllerEvents[handedness] = {
@@ -47,7 +47,7 @@
47
47
 
48
48
  const { scene, renderer, scheduler, renderStage } = useThrelte()
49
49
 
50
- const handedness = $derived<'left' | 'right'>(left ? 'left' : right ? 'right' : hand ?? 'left')
50
+ const handedness = $derived<'left' | 'right'>(left ? 'left' : right ? 'right' : (hand ?? 'left'))
51
51
 
52
52
  $effect.pre(() => {
53
53
  handEvents[handedness] = {
@@ -19,6 +19,8 @@ This should be placed within a Threlte `<Canvas />`.
19
19
  -->
20
20
  <script lang="ts">
21
21
  import type { EventListener, WebXRManager, Event as ThreeEvent } from 'three'
22
+ import type { XRHandModelFactory } from 'three/examples/jsm/webxr/XRHandModelFactory.js'
23
+ import type { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js'
22
24
  import type { Snippet } from 'svelte'
23
25
  import { useThrelte } from '@threlte/core'
24
26
  import {
@@ -65,6 +67,12 @@ This should be placed within a Threlte `<Canvas />`.
65
67
  /** Called after an XRSession is ended */
66
68
  onsessionend?: (event: XRSessionEvent) => void
67
69
 
70
+ /** Optionally provide custom XRHandModelFactory */
71
+ handFactory?: XRHandModelFactory
72
+
73
+ /** Optionally provide custom XRControllerModelFactory */
74
+ controllerFactory?: XRControllerModelFactory
75
+
68
76
  /** Called when an XRSession is hidden or unfocused. */
69
77
  onvisibilitychange?: (event: XRSessionEvent) => void
70
78
 
@@ -81,7 +89,9 @@ This should be placed within a Threlte `<Canvas />`.
81
89
  onvisibilitychange,
82
90
  oninputsourceschange,
83
91
  fallback,
84
- children
92
+ children,
93
+ handFactory,
94
+ controllerFactory
85
95
  }: Props = $props()
86
96
 
87
97
  const { renderer, renderMode } = useThrelte()
@@ -90,8 +100,8 @@ This should be placed within a Threlte `<Canvas />`.
90
100
 
91
101
  setupRaf()
92
102
  setupHeadset()
93
- setupControllers()
94
- setupHands()
103
+ setupControllers(controllerFactory)
104
+ setupHands(handFactory)
95
105
 
96
106
  const handleSessionStart: EventListener<object, 'sessionstart', WebXRManager> = (event) => {
97
107
  isPresenting.current = true
@@ -1,4 +1,6 @@
1
1
  import type { WebXRManager, Event as ThreeEvent } from 'three';
2
+ import type { XRHandModelFactory } from 'three/examples/jsm/webxr/XRHandModelFactory.js';
3
+ import type { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
2
4
  import type { Snippet } from 'svelte';
3
5
  interface Props {
4
6
  /**
@@ -26,6 +28,10 @@ interface Props {
26
28
  onsessionstart?: (event: ThreeEvent<'sessionstart', WebXRManager>) => void;
27
29
  /** Called after an XRSession is ended */
28
30
  onsessionend?: (event: XRSessionEvent) => void;
31
+ /** Optionally provide custom XRHandModelFactory */
32
+ handFactory?: XRHandModelFactory;
33
+ /** Optionally provide custom XRControllerModelFactory */
34
+ controllerFactory?: XRControllerModelFactory;
29
35
  /** Called when an XRSession is hidden or unfocused. */
30
36
  onvisibilitychange?: (event: XRSessionEvent) => void;
31
37
  /** Called when available inputsources change */
@@ -1 +1,2 @@
1
- export declare const setupControllers: () => void;
1
+ import { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
2
+ export declare const setupControllers: (factory?: XRControllerModelFactory) => void;
@@ -4,17 +4,17 @@ import { onMount } from 'svelte';
4
4
  import { useHandTrackingState } from './useHandTrackingState.js';
5
5
  import { controllers } from '../hooks/useController.svelte.js';
6
6
  import { controllerEvents } from './state.svelte.js';
7
- export const setupControllers = () => {
8
- const factory = new XRControllerModelFactory();
7
+ export const setupControllers = (factory) => {
9
8
  const { xr } = useThrelte().renderer;
10
9
  const hasHands = useHandTrackingState();
11
10
  const targetRaySpaces = [xr.getController(0), xr.getController(1)];
12
11
  const indexMap = new Map();
13
12
  targetRaySpaces.forEach((targetRay, index) => {
13
+ const model = (factory ?? new XRControllerModelFactory()).createControllerModel(targetRay);
14
14
  indexMap.set(targetRay, {
15
15
  targetRay,
16
16
  grip: xr.getControllerGrip(index),
17
- model: factory.createControllerModel(targetRay)
17
+ model
18
18
  });
19
19
  });
20
20
  onMount(() => {
@@ -1 +1,2 @@
1
- export declare const setupHands: () => void;
1
+ import { XRHandModelFactory } from 'three/examples/jsm/webxr/XRHandModelFactory.js';
2
+ export declare const setupHands: (factory?: XRHandModelFactory) => void;
@@ -4,17 +4,17 @@ import { onMount } from 'svelte';
4
4
  import { hands } from '../hooks/useHand.svelte.js';
5
5
  import { useHandTrackingState } from './useHandTrackingState.js';
6
6
  import { handEvents } from './state.svelte.js';
7
- export const setupHands = () => {
8
- const factory = new XRHandModelFactory();
7
+ export const setupHands = (factory) => {
9
8
  const { xr } = useThrelte().renderer;
10
9
  const hasHands = useHandTrackingState();
11
10
  const handSpaces = [xr.getHand(0), xr.getHand(1)];
12
11
  const map = new Map();
13
12
  handSpaces.forEach((handSpace, index) => {
13
+ const model = (factory ?? new XRHandModelFactory()).createHandModel(handSpace, 'mesh');
14
14
  map.set(handSpace, {
15
15
  hand: handSpace,
16
16
  targetRay: xr.getController(index),
17
- model: factory.createHandModel(handSpace, 'mesh')
17
+ model
18
18
  });
19
19
  });
20
20
  onMount(() => {
@@ -1,5 +1,5 @@
1
1
  import { Raycaster, Vector3 } from 'three';
2
- import { currentWritable, watch } from '@threlte/core';
2
+ import { currentWritable, observe } from '@threlte/core';
3
3
  import { defaultComputeFunction } from './compute.js';
4
4
  import { injectPointerControlsPlugin } from './plugin.svelte.js';
5
5
  import { setupPointerControls } from './setup.svelte.js';
@@ -34,11 +34,11 @@ export const pointerControls = (handedness, options) => {
34
34
  setupPointerControls(context, ctx, options?.fixedStep);
35
35
  }
36
36
  const handContext = getHandContext(handedness);
37
- watch(handContext.enabled, (enabled) => {
37
+ observe.pre(() => [handContext.enabled], ([enabled]) => {
38
38
  controlsCounter += enabled ? 1 : -1;
39
39
  pointerState[handedness].enabled = controlsCounter > 0;
40
40
  });
41
- watch(handContext.pointerOverTarget, (hovering) => {
41
+ observe.pre(() => [handContext.pointerOverTarget], ([hovering]) => {
42
42
  pointerState[handedness].hovering = hovering;
43
43
  });
44
44
  return {
@@ -1,5 +1,5 @@
1
1
  import { Vector3 } from 'three';
2
- import { observe, watch } from '@threlte/core';
2
+ import { observe } from '@threlte/core';
3
3
  import { getInternalContext } from './context.js';
4
4
  import { controllers } from '../../hooks/useController.svelte.js';
5
5
  import { useHand } from '../../hooks/useHand.svelte.js';
@@ -187,7 +187,7 @@ export const setupPointerControls = (context, handContext, fixedStep = 1 / 40) =
187
187
  return;
188
188
  }
189
189
  });
190
- watch([hand, handContext.enabled], ([input, enabled]) => {
190
+ observe.pre(() => [hand, handContext.enabled], ([input, enabled]) => {
191
191
  if (input === undefined)
192
192
  return;
193
193
  const removeHandlers = () => {
@@ -1,4 +1,4 @@
1
- import { currentWritable, watch } from '@threlte/core';
1
+ import { currentWritable, observe } from '@threlte/core';
2
2
  import { createTeleportContext, useTeleportControls, getHandContext } from './context.js';
3
3
  import { injectTeleportControlsPlugin } from './plugin.svelte.js';
4
4
  import { setHandContext } from './context.js';
@@ -24,11 +24,11 @@ export const teleportControls = (handedness, options) => {
24
24
  setupTeleportControls(context, ctx, options?.fixedStep);
25
25
  }
26
26
  const handContext = getHandContext(handedness);
27
- watch(handContext.enabled, (enabled) => {
27
+ observe.pre(() => [handContext.enabled], ([enabled]) => {
28
28
  controlsCounter += enabled ? 1 : -1;
29
29
  teleportState[handedness].enabled = controlsCounter > 0;
30
30
  });
31
- watch(handContext.active, (hovering) => {
31
+ observe.pre(() => [handContext.active], ([hovering]) => {
32
32
  teleportState[handedness].hovering = hovering;
33
33
  });
34
34
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/xr",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "author": "Micheal Parks <michealparks1989@gmail.com> (https://parks.lol)",
5
5
  "license": "MIT",
6
6
  "description": "Tools to more easily create VR and AR experiences with Threlte",
@@ -17,8 +17,10 @@
17
17
  "eslint-plugin-svelte": "^3.5.1",
18
18
  "globals": "^16.1.0",
19
19
  "postcss": "^8.4.38",
20
+ "prettier": "^3.8.1",
21
+ "prettier-plugin-svelte": "^3.5.1",
20
22
  "publint": "^0.2.7",
21
- "svelte": "5.26.2",
23
+ "svelte": "5.53.6",
22
24
  "svelte-check": "^4.3.1",
23
25
  "three": "^0.175.0",
24
26
  "tslib": "^2.6.2",
@@ -26,7 +28,7 @@
26
28
  "typescript-eslint": "^8.32.0",
27
29
  "vite": "^7.1.4",
28
30
  "vite-plugin-mkcert": "^1.17.5",
29
- "@threlte/core": "8.4.0"
31
+ "@threlte/core": "8.5.2"
30
32
  },
31
33
  "peerDependencies": {
32
34
  "svelte": ">=5",
@@ -46,7 +48,7 @@
46
48
  "homepage": "https://threlte.xyz",
47
49
  "repository": {
48
50
  "type": "git",
49
- "url": "https://github.com/threlte/threlte.git",
51
+ "url": "https://github.com/threlte/threlte",
50
52
  "directory": "packages/xr"
51
53
  },
52
54
  "bugs": {