@threlte/xr 0.0.9 → 0.0.11
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.
- package/dist/components/ARButton.svelte +3 -2
- package/dist/components/ARButton.svelte.d.ts +7 -0
- package/dist/components/VRButton.svelte +2 -2
- package/dist/components/VRButton.svelte.d.ts +1 -0
- package/dist/components/XR.svelte +2 -0
- package/dist/components/XRButton.svelte +6 -3
- package/dist/components/XRButton.svelte.d.ts +1 -0
- package/dist/internal/headset.js +3 -1
- package/dist/internal/updateRaf.d.ts +1 -0
- package/dist/internal/updateRaf.js +21 -0
- package/package.json +1 -1
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
16
|
<XRButton
|
|
17
|
-
{...$$restProps}
|
|
18
|
-
mode='immersive-ar'
|
|
19
17
|
sessionInit={{
|
|
20
18
|
domOverlay: typeof document !== 'undefined' ? { root: document.body } : undefined,
|
|
21
19
|
requiredFeatures: ['plane-detection'],
|
|
22
20
|
optionalFeatures: ['hit-test', 'light-estimation', 'dom-overlay', 'dom-overlay-for-handheld-ar']
|
|
23
21
|
}}
|
|
22
|
+
{...$$restProps}
|
|
23
|
+
mode='immersive-ar'
|
|
24
|
+
|
|
24
25
|
on:click
|
|
25
26
|
on:error
|
|
26
27
|
/>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="webxr" />
|
|
1
2
|
import { SvelteComponent } from "svelte";
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
@@ -221,10 +222,16 @@ declare const __propDef: {
|
|
|
221
222
|
'on:close'?: import("svelte/elements").EventHandler<Event, HTMLButtonElement> | null | undefined;
|
|
222
223
|
'on:fullscreenchange'?: import("svelte/elements").EventHandler<Event, HTMLButtonElement> | null | undefined;
|
|
223
224
|
'on:fullscreenerror'?: import("svelte/elements").EventHandler<Event, HTMLButtonElement> | null | undefined;
|
|
225
|
+
sessionInit?: XRSessionInit & {
|
|
226
|
+
domOverlay?: {
|
|
227
|
+
root: HTMLElement;
|
|
228
|
+
} | undefined;
|
|
229
|
+
};
|
|
224
230
|
};
|
|
225
231
|
events: {
|
|
226
232
|
click: CustomEvent<{
|
|
227
233
|
state: "unsupported" | "insecure" | "blocked" | "supported";
|
|
234
|
+
nativeEvent: MouseEvent;
|
|
228
235
|
}>;
|
|
229
236
|
error: CustomEvent<Error>;
|
|
230
237
|
} & {
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
16
|
<XRButton
|
|
17
|
-
{...$$restProps}
|
|
18
|
-
mode='immersive-vr'
|
|
19
17
|
sessionInit={{
|
|
20
18
|
optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers']
|
|
21
19
|
}}
|
|
20
|
+
{...$$restProps}
|
|
21
|
+
mode='immersive-vr'
|
|
22
22
|
on:click
|
|
23
23
|
on:error
|
|
24
24
|
/>
|
|
@@ -27,11 +27,13 @@ import {
|
|
|
27
27
|
session,
|
|
28
28
|
xr as xrStore
|
|
29
29
|
} from "../internal/stores";
|
|
30
|
+
import { updateRaf } from "../internal/updateRaf";
|
|
30
31
|
import { useUpdateHeadset } from "../internal/headset";
|
|
31
32
|
export let foveation = 1;
|
|
32
33
|
export let frameRate = void 0;
|
|
33
34
|
export let referenceSpace = "local-floor";
|
|
34
35
|
const dispatch = createRawEventDispatcher();
|
|
36
|
+
updateRaf();
|
|
35
37
|
const { renderer, frameloop } = useThrelte();
|
|
36
38
|
const { xr } = renderer;
|
|
37
39
|
const handleSessionStart = (event) => {
|
|
@@ -27,11 +27,11 @@ export let sessionInit = void 0;
|
|
|
27
27
|
export let force = void 0;
|
|
28
28
|
export let styled = true;
|
|
29
29
|
const dispatch = createEventDispatcher();
|
|
30
|
-
const handleButtonClick = async (state) => {
|
|
30
|
+
const handleButtonClick = async (nativeEvent, state) => {
|
|
31
31
|
if (!$initialized) {
|
|
32
32
|
throw new Error("The <XR> component was not created. This is required to start an XR session.");
|
|
33
33
|
}
|
|
34
|
-
dispatch("click", { state });
|
|
34
|
+
dispatch("click", { state, nativeEvent });
|
|
35
35
|
if (state !== "supported")
|
|
36
36
|
return;
|
|
37
37
|
try {
|
|
@@ -65,7 +65,10 @@ $:
|
|
|
65
65
|
</script>
|
|
66
66
|
|
|
67
67
|
{#await getXRSupportState(mode) then state}
|
|
68
|
-
<button
|
|
68
|
+
<button
|
|
69
|
+
{...$$restProps}
|
|
70
|
+
on:click={(event) => handleButtonClick(event, state)}
|
|
71
|
+
>
|
|
69
72
|
{#if state === 'unsupported'}
|
|
70
73
|
{modeText} unsupported
|
|
71
74
|
{:else if state === 'insecure'}
|
package/dist/internal/headset.js
CHANGED
|
@@ -11,7 +11,9 @@ export const useUpdateHeadset = () => {
|
|
|
11
11
|
if (space === null)
|
|
12
12
|
return;
|
|
13
13
|
const pose = xr.getFrame().getViewerPose(space);
|
|
14
|
-
|
|
14
|
+
// Although pose is only typed as possibly undefined,
|
|
15
|
+
// It can be null on android chrome when using phone AR.
|
|
16
|
+
if (pose === undefined || pose === null)
|
|
15
17
|
return;
|
|
16
18
|
const { position, orientation } = pose.transform;
|
|
17
19
|
headset.position.set(position.x, position.y, position.z);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const updateRaf: () => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @ts-expect-error svelte/internal is untyped.
|
|
2
|
+
import { set_raf } from 'svelte/internal';
|
|
3
|
+
import { onDestroy } from 'svelte';
|
|
4
|
+
import { watch } from '@threlte/core';
|
|
5
|
+
import { session } from './stores';
|
|
6
|
+
export const updateRaf = () => {
|
|
7
|
+
if (typeof window === 'undefined')
|
|
8
|
+
return;
|
|
9
|
+
const browserRaf = (fn) => requestAnimationFrame(fn);
|
|
10
|
+
const currentRaf = { fn: browserRaf };
|
|
11
|
+
set_raf((fn) => currentRaf.fn(fn));
|
|
12
|
+
watch(session, (session) => {
|
|
13
|
+
if (session) {
|
|
14
|
+
currentRaf.fn = (fn) => (session.requestAnimationFrame(fn));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
currentRaf.fn = browserRaf;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
onDestroy(() => (currentRaf.fn = browserRaf));
|
|
21
|
+
};
|