@threlte/xr 1.5.5 → 1.6.1

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.
Files changed (69) hide show
  1. package/dist/components/Controller.svelte +59 -60
  2. package/dist/components/Hand.svelte +21 -29
  3. package/dist/components/XR.svelte +146 -16
  4. package/dist/components/XR.svelte.d.ts +20 -0
  5. package/dist/components/XROrigin.svelte +82 -0
  6. package/dist/components/XROrigin.svelte.d.ts +33 -0
  7. package/dist/components/internal/TeleportRay.svelte +15 -3
  8. package/dist/hooks/currentReadable.svelte.d.ts +28 -1
  9. package/dist/hooks/currentReadable.svelte.js +36 -9
  10. package/dist/hooks/useController.svelte.d.ts +3 -3
  11. package/dist/hooks/useController.svelte.js +30 -7
  12. package/dist/hooks/useHand.svelte.d.ts +2 -2
  13. package/dist/hooks/useHand.svelte.js +26 -5
  14. package/dist/hooks/useHandJoint.svelte.js +6 -5
  15. package/dist/hooks/useHitTest.svelte.js +56 -12
  16. package/dist/hooks/useTeleport.d.ts +11 -9
  17. package/dist/hooks/useTeleport.js +62 -14
  18. package/dist/hooks/useXR.js +5 -5
  19. package/dist/hooks/useXROrigin.svelte.d.ts +10 -0
  20. package/dist/hooks/useXROrigin.svelte.js +11 -0
  21. package/dist/index.d.ts +4 -0
  22. package/dist/index.js +3 -0
  23. package/dist/internal/inputSources.svelte.d.ts +84 -0
  24. package/dist/internal/inputSources.svelte.js +91 -0
  25. package/dist/internal/setupHeadset.svelte.js +18 -6
  26. package/dist/internal/setupInputSources.d.ts +4 -0
  27. package/dist/internal/setupInputSources.js +319 -0
  28. package/dist/internal/state.svelte.d.ts +10 -12
  29. package/dist/internal/state.svelte.js +9 -3
  30. package/dist/lib/getXRSessionOptions.d.ts +1 -1
  31. package/dist/lib/getXRSessionOptions.js +8 -7
  32. package/dist/lib/toggleXRSession.d.ts +1 -1
  33. package/dist/lib/toggleXRSession.js +20 -5
  34. package/dist/plugins/pointerControls/compute.js +14 -9
  35. package/dist/plugins/pointerControls/context.d.ts +3 -3
  36. package/dist/plugins/pointerControls/context.js +12 -6
  37. package/dist/plugins/pointerControls/index.d.ts +4 -3
  38. package/dist/plugins/pointerControls/index.js +63 -29
  39. package/dist/plugins/pointerControls/setup.svelte.js +64 -44
  40. package/dist/plugins/pointerControls/types.d.ts +14 -3
  41. package/dist/plugins/teleportControls/compute.d.ts +1 -1
  42. package/dist/plugins/teleportControls/compute.js +11 -8
  43. package/dist/plugins/teleportControls/context.d.ts +4 -4
  44. package/dist/plugins/teleportControls/context.js +1 -4
  45. package/dist/plugins/teleportControls/index.js +7 -4
  46. package/dist/plugins/teleportControls/plugin.svelte.js +12 -51
  47. package/dist/plugins/teleportControls/setup.svelte.js +10 -9
  48. package/dist/plugins/touchControls/compute.d.ts +3 -0
  49. package/dist/plugins/touchControls/compute.js +13 -0
  50. package/dist/plugins/touchControls/context.d.ts +12 -0
  51. package/dist/plugins/touchControls/context.js +27 -0
  52. package/dist/plugins/touchControls/hook.d.ts +5 -0
  53. package/dist/plugins/touchControls/hook.js +26 -0
  54. package/dist/plugins/touchControls/index.d.ts +33 -0
  55. package/dist/plugins/touchControls/index.js +41 -0
  56. package/dist/plugins/touchControls/plugin.svelte.d.ts +1 -0
  57. package/dist/plugins/touchControls/plugin.svelte.js +24 -0
  58. package/dist/plugins/touchControls/setup.svelte.d.ts +2 -0
  59. package/dist/plugins/touchControls/setup.svelte.js +247 -0
  60. package/dist/plugins/touchControls/types.d.ts +62 -0
  61. package/dist/plugins/touchControls/types.js +11 -0
  62. package/dist/types.d.ts +1 -1
  63. package/package.json +3 -3
  64. package/dist/internal/setupControllers.d.ts +0 -2
  65. package/dist/internal/setupControllers.js +0 -73
  66. package/dist/internal/setupHands.d.ts +0 -2
  67. package/dist/internal/setupHands.js +0 -67
  68. package/dist/internal/useHandTrackingState.d.ts +0 -5
  69. package/dist/internal/useHandTrackingState.js +0 -20
@@ -1,67 +0,0 @@
1
- import { XRHandModelFactory } from 'three/examples/jsm/webxr/XRHandModelFactory.js';
2
- import { useThrelte } from '@threlte/core';
3
- import { onMount } from 'svelte';
4
- import { hands } from '../hooks/useHand.svelte.js';
5
- import { useHandTrackingState } from './useHandTrackingState.js';
6
- import { handEvents } from './state.svelte.js';
7
- export const setupHands = (factory) => {
8
- const { xr } = useThrelte().renderer;
9
- const hasHands = useHandTrackingState();
10
- const handSpaces = [xr.getHand(0), xr.getHand(1)];
11
- const map = new Map();
12
- const modelFactory = factory ?? new XRHandModelFactory();
13
- handSpaces.forEach((handSpace, index) => {
14
- map.set(handSpace, {
15
- hand: handSpace,
16
- targetRay: xr.getController(index),
17
- model: modelFactory.createHandModel(handSpace, 'mesh')
18
- });
19
- });
20
- onMount(() => {
21
- const dispatch = (event) => {
22
- if (!hasHands())
23
- return;
24
- const handEvent = event;
25
- const handedness = 'handedness' in handEvent ? handEvent.handedness : handEvent.data.handedness;
26
- handEvents[handedness]?.[`on${event.type}`]?.(event);
27
- };
28
- function handleConnected(event) {
29
- const { model, targetRay } = map.get(this);
30
- const { data } = event;
31
- const { handedness, hand: inputSource } = data;
32
- if (handedness === 'none' || inputSource === undefined) {
33
- return;
34
- }
35
- hands[handedness] = {
36
- hand: this,
37
- model,
38
- inputSource,
39
- targetRay
40
- };
41
- dispatch(event);
42
- }
43
- const handleDisconnected = (event) => {
44
- dispatch(event);
45
- const { handedness } = event.data;
46
- if (handedness === 'left' || handedness === 'right') {
47
- hands[handedness] = undefined;
48
- }
49
- };
50
- for (const handSpace of handSpaces) {
51
- handSpace.addEventListener('connected', handleConnected);
52
- handSpace.addEventListener('disconnected', handleDisconnected);
53
- handSpace.addEventListener('pinchstart', dispatch);
54
- handSpace.addEventListener('pinchend', dispatch);
55
- }
56
- return () => {
57
- for (const handSpace of handSpaces) {
58
- handSpace.removeEventListener('connected', handleConnected);
59
- handSpace.removeEventListener('disconnected', handleDisconnected);
60
- handSpace.removeEventListener('pinchstart', dispatch);
61
- handSpace.removeEventListener('pinchend', dispatch);
62
- }
63
- hands.left = undefined;
64
- hands.right = undefined;
65
- };
66
- });
67
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * There are some cases where we need to know if hand tracking is now active before an input source
3
- * connection or disconnection event. This is the way to do that.
4
- */
5
- export declare const useHandTrackingState: () => () => boolean;
@@ -1,20 +0,0 @@
1
- import { useThrelte } from '@threlte/core';
2
- /**
3
- * There are some cases where we need to know if hand tracking is now active before an input source
4
- * connection or disconnection event. This is the way to do that.
5
- */
6
- export const useHandTrackingState = () => {
7
- const { renderer } = useThrelte();
8
- return () => {
9
- const sources = renderer.xr.getSession()?.inputSources;
10
- if (sources === undefined) {
11
- return false;
12
- }
13
- for (const source of sources) {
14
- if (source.hand !== undefined) {
15
- return true;
16
- }
17
- }
18
- return false;
19
- };
20
- };