@threlte/xr 0.0.6 → 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.
@@ -1,44 +1,15 @@
1
- <script>import { T, HierarchicalObject, useFrame, useThrelte } from "@threlte/core";
2
- import { Group } from "three";
3
- import { useXR } from "../hooks";
4
- const { isPresenting } = useXR();
5
- const { renderer, scene, camera } = useThrelte();
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={group}>
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,4 @@
1
+ import { headset } from '../internal/headset';
2
+ export const useHeadset = () => {
3
+ return headset;
4
+ };
@@ -0,0 +1,3 @@
1
+ import { Group } from 'three';
2
+ export declare const headset: Group;
3
+ export declare const useUpdateHeadset: () => void;
@@ -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.6",
3
+ "version": "0.0.7",
4
4
  "author": "Micheal Parks <michealparks1989@gmail.com> (https://parks.lol)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {