@threlte/xr 0.0.5 → 0.0.7
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 +2 -1
- package/dist/components/Hand.svelte +2 -4
- package/dist/components/Headset.svelte +6 -35
- package/dist/components/XR.svelte +2 -0
- package/dist/hooks/useHeadset.d.ts +1 -0
- package/dist/hooks/useHeadset.js +4 -0
- package/dist/internal/headset.d.ts +3 -0
- package/dist/internal/headset.js +34 -0
- package/package.json +2 -2
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
mode='immersive-ar'
|
|
19
19
|
sessionInit={{
|
|
20
20
|
domOverlay: typeof document !== 'undefined' ? { root: document.body } : undefined,
|
|
21
|
-
|
|
21
|
+
requiredFeatures: ['plane-detection'],
|
|
22
|
+
optionalFeatures: ['hit-test', 'light-estimation', 'dom-overlay', 'dom-overlay-for-handheld-ar']
|
|
22
23
|
}}
|
|
23
24
|
on:click
|
|
24
25
|
on:error
|
|
@@ -65,8 +65,6 @@ $:
|
|
|
65
65
|
}
|
|
66
66
|
$:
|
|
67
67
|
store = stores[handedness];
|
|
68
|
-
$:
|
|
69
|
-
hand = $store?.hand;
|
|
70
68
|
$:
|
|
71
69
|
inputSource = $store?.inputSource;
|
|
72
70
|
$:
|
|
@@ -91,9 +89,9 @@ onDestroy(() => {
|
|
|
91
89
|
});
|
|
92
90
|
</script>
|
|
93
91
|
|
|
94
|
-
{#if hand}
|
|
92
|
+
{#if $store?.hand}
|
|
95
93
|
<T
|
|
96
|
-
is={hand}
|
|
94
|
+
is={$store.hand}
|
|
97
95
|
name='XR hand {handedness}'
|
|
98
96
|
>
|
|
99
97
|
{#if $$slots.default === undefined}
|
|
@@ -1,44 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
const {
|
|
5
|
-
const
|
|
6
|
-
const { xr } = renderer;
|
|
7
|
-
const group = new Group();
|
|
8
|
-
const immersiveFrame = useFrame(() => {
|
|
9
|
-
const space = xr.getReferenceSpace();
|
|
10
|
-
if (space === null)
|
|
11
|
-
return;
|
|
12
|
-
const pose = xr.getFrame().getViewerPose(space);
|
|
13
|
-
if (pose === void 0)
|
|
14
|
-
return;
|
|
15
|
-
const { position, orientation } = pose.transform;
|
|
16
|
-
group.position.set(position.x, position.y, position.z);
|
|
17
|
-
group.quaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);
|
|
18
|
-
}, { autostart: false });
|
|
19
|
-
$:
|
|
20
|
-
if ($isPresenting) {
|
|
21
|
-
immersiveFrame.start();
|
|
22
|
-
} else {
|
|
23
|
-
immersiveFrame.stop();
|
|
24
|
-
}
|
|
25
|
-
const nonImmersiveFrame = useFrame(() => {
|
|
26
|
-
group.position.copy(camera.current.position);
|
|
27
|
-
group.quaternion.copy(camera.current.quaternion);
|
|
28
|
-
}, { autostart: false });
|
|
29
|
-
$:
|
|
30
|
-
if ($isPresenting === false) {
|
|
31
|
-
nonImmersiveFrame.start();
|
|
32
|
-
} else {
|
|
33
|
-
nonImmersiveFrame.stop();
|
|
34
|
-
}
|
|
1
|
+
|
|
2
|
+
<script>import { T, HierarchicalObject, useThrelte } from "@threlte/core";
|
|
3
|
+
import { useHeadset } from "../hooks/useHeadset";
|
|
4
|
+
const { scene } = useThrelte();
|
|
5
|
+
const headset = useHeadset();
|
|
35
6
|
</script>
|
|
36
7
|
|
|
37
8
|
<HierarchicalObject
|
|
38
9
|
onChildMount={(child) => { scene.add(child) }}
|
|
39
10
|
onChildDestroy={(child) => { scene.remove(child) }}
|
|
40
11
|
>
|
|
41
|
-
<T is={
|
|
12
|
+
<T is={headset}>
|
|
42
13
|
<slot />
|
|
43
14
|
</T>
|
|
44
15
|
</HierarchicalObject>
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
session,
|
|
28
28
|
xr as xrStore
|
|
29
29
|
} from "../internal/stores";
|
|
30
|
+
import { useUpdateHeadset } from "../internal/headset";
|
|
30
31
|
export let foveation = 1;
|
|
31
32
|
export let frameRate = void 0;
|
|
32
33
|
export let referenceSpace = "local-floor";
|
|
@@ -82,6 +83,7 @@ $xrStore = xr;
|
|
|
82
83
|
xr.enabled = true;
|
|
83
84
|
xr.addEventListener("sessionstart", handleSessionStart);
|
|
84
85
|
xr.addEventListener("sessionend", handleSessionEnd);
|
|
86
|
+
useUpdateHeadset();
|
|
85
87
|
onDestroy(() => {
|
|
86
88
|
$initialized = false;
|
|
87
89
|
$xrStore = void 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useHeadset: () => Readonly<THREE.Group>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Group } from 'three';
|
|
2
|
+
import { useThrelte, useFrame, watch } from '@threlte/core';
|
|
3
|
+
import { useXR } from '../hooks';
|
|
4
|
+
export const headset = new Group();
|
|
5
|
+
export const useUpdateHeadset = () => {
|
|
6
|
+
const { renderer, camera } = useThrelte();
|
|
7
|
+
const xrState = useXR();
|
|
8
|
+
const { xr } = renderer;
|
|
9
|
+
const immersiveFrame = useFrame(() => {
|
|
10
|
+
const space = xr.getReferenceSpace();
|
|
11
|
+
if (space === null)
|
|
12
|
+
return;
|
|
13
|
+
const pose = xr.getFrame().getViewerPose(space);
|
|
14
|
+
if (pose === undefined)
|
|
15
|
+
return;
|
|
16
|
+
const { position, orientation } = pose.transform;
|
|
17
|
+
headset.position.set(position.x, position.y, position.z);
|
|
18
|
+
headset.quaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);
|
|
19
|
+
}, { autostart: false, invalidate: false });
|
|
20
|
+
const nonImmersiveFrame = useFrame(() => {
|
|
21
|
+
headset.position.copy(camera.current.position);
|
|
22
|
+
headset.quaternion.copy(camera.current.quaternion);
|
|
23
|
+
}, { autostart: false, invalidate: false });
|
|
24
|
+
watch(xrState.isPresenting, (isPresenting) => {
|
|
25
|
+
if (isPresenting) {
|
|
26
|
+
immersiveFrame.start();
|
|
27
|
+
nonImmersiveFrame.stop();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
immersiveFrame.stop();
|
|
31
|
+
nonImmersiveFrame.start();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/xr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"author": "Micheal Parks <michealparks1989@gmail.com> (https://parks.lol)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"devDependencies": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"typescript": "^5.1.6",
|
|
19
19
|
"vite": "^4.4.6",
|
|
20
20
|
"vite-plugin-mkcert": "^1.16.0",
|
|
21
|
-
"@threlte/core": "6.0.
|
|
21
|
+
"@threlte/core": "6.0.9"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"svelte": ">=4",
|