@threlte/xr 1.0.4 → 1.0.6

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.
@@ -18,7 +18,7 @@ This should be placed within a Threlte `<Canvas />`.
18
18
 
19
19
  -->
20
20
  <script lang="ts">
21
- import { onMount, type Snippet } from 'svelte'
21
+ import { onDestroy, onMount, type Snippet } from 'svelte'
22
22
  import { useThrelte, watch } from '@threlte/core'
23
23
  import type { XRSessionEvent } from '../types'
24
24
  import {
@@ -168,6 +168,12 @@ This should be placed within a Threlte `<Canvas />`.
168
168
  xr.removeEventListener('sessionend', handleSessionEnd)
169
169
  }
170
170
  })
171
+ onDestroy(() => {
172
+ // if unmounted while presenting (e.g. due to sveltekit navigation), end the session
173
+ if (session.current) {
174
+ session.current.end()
175
+ }
176
+ })
171
177
 
172
178
  $effect.pre(() => updateTargetFrameRate(frameRate))
173
179
  $effect.pre(() => xr.setFoveation(foveation))
@@ -169,29 +169,43 @@ export const setupPointerControls = (context, handContext, fixedStep = 1 / 40) =
169
169
  fixedStep,
170
170
  autoStart: false
171
171
  });
172
- watch(controller, (input) => {
172
+ watch([controller, handContext.enabled], ([input, enabled]) => {
173
173
  if (input === undefined)
174
174
  return;
175
- input.targetRay.addEventListener('selectstart', handlePointerDown);
176
- input.targetRay.addEventListener('selectend', handlePointerUp);
177
- input.targetRay.addEventListener('select', handleClick);
178
- return () => {
175
+ const removeHandlers = () => {
179
176
  input.targetRay.removeEventListener('selectstart', handlePointerDown);
180
177
  input.targetRay.removeEventListener('selectend', handlePointerUp);
181
178
  input.targetRay.removeEventListener('select', handleClick);
182
179
  };
180
+ if (enabled) {
181
+ input.targetRay.addEventListener('selectstart', handlePointerDown);
182
+ input.targetRay.addEventListener('selectend', handlePointerUp);
183
+ input.targetRay.addEventListener('select', handleClick);
184
+ return removeHandlers;
185
+ }
186
+ else {
187
+ removeHandlers();
188
+ return;
189
+ }
183
190
  });
184
- watch(hand, (input) => {
191
+ watch([hand, handContext.enabled], ([input, enabled]) => {
185
192
  if (input === undefined)
186
193
  return;
187
- input.hand.addEventListener('pinchstart', handlePointerDown);
188
- input.hand.addEventListener('pinchend', handlePointerUp);
189
- input.hand.addEventListener('pinchend', handleClick);
190
- return () => {
194
+ const removeHandlers = () => {
191
195
  input.hand.removeEventListener('pinchstart', handlePointerDown);
192
196
  input.hand.removeEventListener('pinchend', handlePointerUp);
193
197
  input.hand.removeEventListener('pinchend', handleClick);
194
198
  };
199
+ if (enabled) {
200
+ input.hand.addEventListener('pinchstart', handlePointerDown);
201
+ input.hand.addEventListener('pinchend', handlePointerUp);
202
+ input.hand.addEventListener('pinchend', handleClick);
203
+ return removeHandlers;
204
+ }
205
+ else {
206
+ removeHandlers();
207
+ return;
208
+ }
195
209
  });
196
210
  watch([useXR().isPresenting, handContext.enabled], ([isPresenting, enabled]) => {
197
211
  if (isPresenting && enabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/xr",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",