@threlte/xr 1.0.0-next.10 → 1.0.0-next.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.
@@ -1,7 +1,7 @@
1
1
  import { Raycaster, Vector3 } from 'three';
2
2
  import { currentWritable, watch } from '@threlte/core';
3
3
  import { defaultComputeFunction } from './compute';
4
- import { injectPointerControlsPlugin } from './plugin';
4
+ import { injectPointerControlsPlugin } from './plugin.svelte';
5
5
  import { setupPointerControls } from './setup';
6
6
  import { getControlsContext, getHandContext, setControlsContext, setHandContext, setInternalContext } from './context';
7
7
  import { pointerState } from '../../internal/stores';
@@ -0,0 +1,22 @@
1
+ import { injectPlugin, isInstanceOf, observe } from '@threlte/core';
2
+ import { usePointerControls } from './hook';
3
+ import { events } from './types';
4
+ export const injectPointerControlsPlugin = () => {
5
+ injectPlugin('threlte-pointer-controls', (args) => {
6
+ if (!isInstanceOf(args.ref, 'Object3D'))
7
+ return;
8
+ const hasEventHandlers = Object.entries(args.props).some(([key, value]) => {
9
+ return value !== undefined && events.includes(key);
10
+ });
11
+ if (!hasEventHandlers)
12
+ return;
13
+ const { addInteractiveObject, removeInteractiveObject } = usePointerControls();
14
+ observe.pre(() => [args.ref], ([ref]) => {
15
+ addInteractiveObject(ref, args.props);
16
+ return () => removeInteractiveObject(ref);
17
+ });
18
+ return {
19
+ pluginProps: events
20
+ };
21
+ });
22
+ };
@@ -1,6 +1,6 @@
1
1
  import { currentWritable, watch } from '@threlte/core';
2
2
  import { createTeleportContext, useTeleportControls, getHandContext } from './context';
3
- import { injectTeleportControlsPlugin } from './plugin';
3
+ import { injectTeleportControlsPlugin } from './plugin.svelte';
4
4
  import { setHandContext } from './context';
5
5
  import { setupTeleportControls } from './setup';
6
6
  import { teleportState } from '../../internal/stores';
@@ -0,0 +1,31 @@
1
+ import { injectPlugin, isInstanceOf, observe } from '@threlte/core';
2
+ import { useTeleportControls } from './context';
3
+ /**
4
+ * Registers T components with "teleportSurface" or "teleportBlocker" attributes.
5
+ */
6
+ export const injectTeleportControlsPlugin = () => {
7
+ injectPlugin('threlte-teleport-controls', (args) => {
8
+ if (!isInstanceOf(args.ref, 'Mesh'))
9
+ return;
10
+ const isSurface = $derived('teleportSurface' in args.props && !!args.props.teleportSurface);
11
+ const isBlocker = $derived('teleportBlocker' in args.props && !!args.props.teleportBlocker);
12
+ const surfaceRef = $derived(isSurface ? args.ref : undefined);
13
+ const blockerRef = $derived(isBlocker ? args.ref : undefined);
14
+ if (!isSurface && !isBlocker)
15
+ return;
16
+ const { addBlocker, addSurface, removeBlocker, removeSurface } = useTeleportControls();
17
+ observe.pre(() => [surfaceRef, blockerRef], ([surfaceRef, blockerRef]) => {
18
+ if (surfaceRef) {
19
+ addSurface(surfaceRef, args.props);
20
+ return removeSurface(surfaceRef);
21
+ }
22
+ else if (blockerRef) {
23
+ addBlocker(blockerRef);
24
+ return removeBlocker(blockerRef);
25
+ }
26
+ });
27
+ return {
28
+ pluginProps: ['teleportSurface', 'teleportBlocker']
29
+ };
30
+ });
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/xr",
3
- "version": "1.0.0-next.10",
3
+ "version": "1.0.0-next.11",
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",
@@ -9,22 +9,22 @@
9
9
  "@sveltejs/kit": "^2.7.2",
10
10
  "@sveltejs/package": "^2.3.1",
11
11
  "@sveltejs/vite-plugin-svelte": "^3.1.0",
12
+ "@types/three": "^0.169.0",
12
13
  "@typescript-eslint/eslint-plugin": "^7.6.0",
13
14
  "@typescript-eslint/parser": "^7.6.0",
15
+ "autoprefixer": "^10.4.19",
14
16
  "eslint": "^9.0.0",
15
17
  "eslint-plugin-svelte": "^2.36.0",
16
- "svelte-check": "^3.6.9",
17
- "typescript": "^5.4.5",
18
- "@types/three": "^0.169.0",
19
- "autoprefixer": "^10.4.19",
20
18
  "postcss": "^8.4.38",
21
19
  "publint": "^0.2.7",
22
20
  "svelte": "^5.0.5",
21
+ "svelte-check": "^3.6.9",
23
22
  "three": "^0.169.0",
24
23
  "tslib": "^2.6.2",
24
+ "typescript": "^5.4.5",
25
25
  "vite": "^5.2.8",
26
26
  "vite-plugin-mkcert": "^1.17.5",
27
- "@threlte/core": "8.0.0-next.21"
27
+ "@threlte/core": "8.0.0-next.22"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "svelte": ">=5",
@@ -1,26 +0,0 @@
1
- import { injectPlugin, watch } from '@threlte/core';
2
- import { writable } from 'svelte/store';
3
- import { usePointerControls } from './hook';
4
- import { events } from './types';
5
- export const injectPointerControlsPlugin = () => {
6
- injectPlugin('threlte-pointer-controls', ({ ref, props }) => {
7
- if (!ref.isObject3D)
8
- return;
9
- const { addInteractiveObject, removeInteractiveObject } = usePointerControls();
10
- const refStore = writable(ref);
11
- watch(refStore, ($refStore) => {
12
- const hasEventHandlers = Object.entries(props).some(([key, value]) => {
13
- return value !== undefined && events.includes(key);
14
- });
15
- if (!hasEventHandlers)
16
- return;
17
- addInteractiveObject($refStore, props);
18
- return () => removeInteractiveObject($refStore);
19
- });
20
- return {
21
- onRefChange(ref) {
22
- refStore.set(ref);
23
- }
24
- };
25
- });
26
- };
@@ -1,54 +0,0 @@
1
- import { writable } from 'svelte/store';
2
- import { isInstanceOf, watch } from '@threlte/core';
3
- import { injectPlugin } from '@threlte/core';
4
- import { useTeleportControls } from './context';
5
- /**
6
- * Registers T components with "teleportSurface" or "teleportBlocker" attributes.
7
- */
8
- export const injectTeleportControlsPlugin = () => {
9
- const noop = () => { };
10
- injectPlugin('threlte-teleport-controls', ({ ref, props }) => {
11
- if (!isInstanceOf(ref, 'Mesh'))
12
- return;
13
- const isSurface = 'teleportSurface' in props;
14
- const isBlocker = 'teleportBlocker' in props;
15
- if (!isSurface && !isBlocker)
16
- return;
17
- const { addBlocker, addSurface, removeBlocker, removeSurface } = useTeleportControls();
18
- const refStore = writable(ref);
19
- const propsStore = writable(props);
20
- watch([refStore, propsStore], ([$refStore, $propsStore]) => {
21
- if (isSurface) {
22
- if ($propsStore.teleportSurface === false) {
23
- removeSurface($refStore);
24
- return noop;
25
- }
26
- else {
27
- addSurface($refStore, props);
28
- return () => removeSurface($refStore);
29
- }
30
- }
31
- else if (isBlocker) {
32
- if (props.teleportBlocker === false) {
33
- removeBlocker($refStore);
34
- return noop;
35
- }
36
- else {
37
- addBlocker($refStore);
38
- return () => removeBlocker($refStore);
39
- }
40
- }
41
- else {
42
- return noop;
43
- }
44
- });
45
- return {
46
- onRefChange(ref) {
47
- refStore.set(ref);
48
- },
49
- onPropsChange(props) {
50
- propsStore.set(props);
51
- }
52
- };
53
- });
54
- };