@viamrobotics/motion-tools 0.5.2 → 0.5.4

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.
Files changed (33) hide show
  1. package/README.md +0 -25
  2. package/dist/WorldObject.d.ts +3 -2
  3. package/dist/color.js +1 -1
  4. package/dist/components/App.svelte +3 -3
  5. package/dist/components/Details.svelte +0 -1
  6. package/dist/components/Focus.svelte +3 -1
  7. package/dist/components/Geometry.svelte +2 -1
  8. package/dist/components/KeyboardControls.svelte +13 -3
  9. package/dist/components/KeyboardControls.svelte.d.ts +2 -2
  10. package/dist/components/Pointcloud.svelte +13 -10
  11. package/dist/components/Scene.svelte +17 -4
  12. package/dist/components/SceneProviders.svelte +2 -1
  13. package/dist/components/dashboard/Button.svelte +5 -4
  14. package/dist/components/portal/PortalTarget.svelte +4 -4
  15. package/dist/components/xr/Controllers.svelte +38 -50
  16. package/dist/components/xr/Controllers.svelte.d.ts +17 -2
  17. package/dist/components/xr/Hands.svelte +1 -0
  18. package/dist/components/xr/OriginMarker.svelte +70 -30
  19. package/dist/components/xr/XR.svelte +9 -2
  20. package/dist/components/xr/useAnchors.svelte.d.ts +2 -0
  21. package/dist/components/xr/useAnchors.svelte.js +55 -0
  22. package/dist/components/xr/useOrigin.svelte.d.ts +9 -0
  23. package/dist/components/xr/useOrigin.svelte.js +27 -0
  24. package/dist/hooks/useFrames.svelte.js +3 -3
  25. package/dist/hooks/useSelection.svelte.d.ts +7 -8
  26. package/dist/hooks/useShapes.svelte.js +119 -32
  27. package/dist/lib.d.ts +0 -2
  28. package/dist/lib.js +0 -2
  29. package/dist/three/BatchedArrow.d.ts +2 -2
  30. package/dist/three/BatchedArrow.js +2 -1
  31. package/package.json +61 -60
  32. package/dist/components/CameraControls.svelte +0 -81
  33. package/dist/components/CameraControls.svelte.d.ts +0 -12
package/README.md CHANGED
@@ -9,31 +9,6 @@ To visit the visualizer, go to `http://localhost:5173/`
9
9
 
10
10
  Open the machine config page (bottom right) and enter in connection details to visualize a specific machine.
11
11
 
12
- ## Todo
13
-
14
- ----- hard -----
15
-
16
- - animated sequence of motion plan
17
- - Give better fetching / connection state info
18
- - configure frames in app
19
- - embed in teleop
20
-
21
- ----- medium -----
22
-
23
- - remote IP access when custom drawing, to draw on remote computers
24
- - geometries need to be parented to parent
25
- - color pallet for resource to color
26
- - measurement tool
27
-
28
- ----- easy ------
29
-
30
- - double click to set trackball center in object view
31
- - Set default pointcloud color in settings
32
- - points are not sized right in ortho cam view
33
- - bounding boxes should include just the thing and not children
34
-
35
- --- action items ----
36
-
37
12
  ## Env files
38
13
 
39
14
  To add a list of connection configs in an `.env.local` file, use the following format:
@@ -1,5 +1,5 @@
1
1
  import type { Geometry, Pose } from '@viamrobotics/sdk';
2
- import { BatchedMesh, Box3, Object3D, Vector3 } from 'three';
2
+ import { BatchedMesh, Box3, Object3D, Vector3, type ColorRepresentation } from 'three';
3
3
  export type PointsGeometry = {
4
4
  case: 'points';
5
5
  value: Float32Array<ArrayBuffer>;
@@ -11,11 +11,12 @@ export type LinesGeometry = {
11
11
  export type Geometries = Geometry['geometryType'] | PointsGeometry | LinesGeometry;
12
12
  export type Metadata = {
13
13
  colors?: Float32Array;
14
- color?: string;
14
+ color?: ColorRepresentation;
15
15
  gltf?: {
16
16
  scene: Object3D;
17
17
  };
18
18
  points?: Vector3[];
19
+ pointSize?: number;
19
20
  batched?: {
20
21
  id: number;
21
22
  object: BatchedMesh;
package/dist/color.js CHANGED
@@ -14,7 +14,7 @@ const toHex = (x) => {
14
14
  const oklchToHex = (raw) => {
15
15
  const match = raw.match(/oklch\(\s*([\d.]+)%\s+([\d.]+)\s+([\d.]+)\s*\)/);
16
16
  if (!match) {
17
- return '#000000';
17
+ return raw;
18
18
  }
19
19
  const l = parseFloat(match[1]) / 100;
20
20
  const c = parseFloat(match[2]);
@@ -20,7 +20,7 @@
20
20
 
21
21
  createPartIDContext(() => partID)
22
22
 
23
- let root = $state<HTMLElement>()
23
+ let root = $state.raw<HTMLElement>()
24
24
  </script>
25
25
 
26
26
  <div
@@ -33,10 +33,10 @@
33
33
  {#snippet children({ focus })}
34
34
  <Scene>
35
35
  {@render appChildren?.()}
36
-
37
- <XR />
38
36
  </Scene>
39
37
 
38
+ <XR />
39
+
40
40
  <DomPortal element={root}>
41
41
  <Dashboard />
42
42
  <Details />
@@ -21,7 +21,6 @@
21
21
 
22
22
  const object = $derived(focusedObject.current ?? selectedObject.current)
23
23
  const object3d = $derived(focusedObject3d.current ?? selectedObject3d.current)
24
-
25
24
  const worldPosition = $derived(object3d?.getWorldPosition(new Vector3()))
26
25
  const worldQuaternion = $derived(object3d?.getWorldQuaternion(new Quaternion()))
27
26
  const worldOrientation = $derived(
@@ -12,16 +12,18 @@
12
12
  const vec = new Vector3()
13
13
 
14
14
  let center = $state.raw<[number, number, number]>([0, 0, 0])
15
+ let size = $state.raw<[number, number, number]>([0, 0, 0])
15
16
 
16
17
  $effect(() => {
17
18
  if (object3d) {
18
19
  box.setFromObject(object3d)
20
+ size = box.getSize(vec).toArray()
19
21
  center = box.getCenter(vec).toArray()
20
22
  }
21
23
  })
22
24
  </script>
23
25
 
24
- <Camera position={[2, 0, 0]}>
26
+ <Camera position={[size[0], 0, 0]}>
25
27
  <TrackballControls target={center}>
26
28
  <Gizmo />
27
29
  </TrackballControls>
@@ -64,7 +64,8 @@
64
64
  {...rest}
65
65
  >
66
66
  {#if geometry?.case === 'mesh'}
67
- {@const meshGeometry = plyLoader.parse(atob(geometry.value.mesh as unknown as string))}
67
+ {@const mesh = geometry.value.mesh as Uint8Array<ArrayBuffer>}
68
+ {@const meshGeometry = plyLoader.parse(typeof mesh === 'string' ? atob(mesh) : mesh.buffer)}
68
69
  <T
69
70
  is={meshGeometry}
70
71
  {oncreate}
@@ -1,13 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { MathUtils } from 'three'
3
3
  import { useTask } from '@threlte/core'
4
- import type CameraController from 'camera-controls'
4
+ import type { CameraControlsRef } from '@threlte/extras'
5
5
  import { PressedKeys } from 'runed'
6
6
  import { useFocused } from '../hooks/useSelection.svelte'
7
7
  import { useSettings } from '../hooks/useSettings.svelte'
8
8
 
9
9
  interface Props {
10
- cameraControls: CameraController
10
+ cameraControls: CameraControlsRef
11
11
  }
12
12
 
13
13
  let { cameraControls }: Props = $props()
@@ -20,11 +20,13 @@
20
20
  const s = $derived(keys.has('s'))
21
21
  const a = $derived(keys.has('a'))
22
22
  const d = $derived(keys.has('d'))
23
+ const r = $derived(keys.has('r'))
24
+ const f = $derived(keys.has('f'))
23
25
  const up = $derived(keys.has('arrowup'))
24
26
  const left = $derived(keys.has('arrowleft'))
25
27
  const down = $derived(keys.has('arrowdown'))
26
28
  const right = $derived(keys.has('arrowright'))
27
- const any = $derived(w || s || a || d || up || left || down || right)
29
+ const any = $derived(w || s || a || d || r || f || up || left || down || right)
28
30
 
29
31
  const { start, stop } = useTask(
30
32
  (delta) => {
@@ -46,6 +48,14 @@
46
48
  cameraControls.forward(-0.01 * dt, true)
47
49
  }
48
50
 
51
+ if (r) {
52
+ cameraControls.dolly(0.01 * dt, true)
53
+ }
54
+
55
+ if (f) {
56
+ cameraControls.dolly(-0.01 * dt, true)
57
+ }
58
+
49
59
  if (left) {
50
60
  cameraControls.rotate(-0.1 * MathUtils.DEG2RAD * dt, 0, true)
51
61
  }
@@ -1,6 +1,6 @@
1
- import type CameraController from 'camera-controls';
1
+ import type { CameraControlsRef } from '@threlte/extras';
2
2
  interface Props {
3
- cameraControls: CameraController;
3
+ cameraControls: CameraControlsRef;
4
4
  }
5
5
  declare const KeyboardControls: import("svelte").Component<Props, {}, "">;
6
6
  type KeyboardControls = ReturnType<typeof KeyboardControls>;
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
+ import { Points, BufferAttribute, BufferGeometry, PointsMaterial } from 'three'
3
+
2
4
  import { T } from '@threlte/core'
3
- import { Points, BufferAttribute, BufferGeometry, Color, PointsMaterial } from 'three'
4
5
  import type { WorldObject } from '../WorldObject'
5
6
  import { useObjectEvents } from '../hooks/useObjectEvents.svelte'
6
7
  import { meshBounds } from '@threlte/extras'
@@ -12,18 +13,15 @@
12
13
 
13
14
  let { object }: Props = $props()
14
15
 
15
- const points = new Points()
16
- const geometry = new BufferGeometry()
17
- const material = new PointsMaterial({
18
- size: 0.01,
19
- color: new Color('#888888'),
20
- })
21
-
22
16
  const colors = $derived(object.metadata.colors)
23
17
  const positions = $derived(object.geometry?.value ?? new Float32Array())
24
18
 
25
- $effect(() => {
26
- material.vertexColors = colors !== undefined
19
+ const points = new Points()
20
+ const geometry = new BufferGeometry()
21
+ const material = new PointsMaterial()
22
+
23
+ $effect.pre(() => {
24
+ material.size = object.metadata.pointSize ?? 0.01
27
25
  })
28
26
 
29
27
  $effect.pre(() => {
@@ -31,8 +29,13 @@
31
29
  })
32
30
 
33
31
  $effect.pre(() => {
32
+ material.vertexColors = colors !== undefined
33
+ material.color.set(colors ? 0xffffff : (object.metadata.color ?? '#888888'))
34
+
35
+ material.toneMapped = false
34
36
  if (colors) {
35
37
  geometry.setAttribute('color', new BufferAttribute(colors, 3))
38
+ geometry.attributes.color.needsUpdate = true
36
39
  }
37
40
  })
38
41
 
@@ -1,11 +1,16 @@
1
1
  <script lang="ts">
2
2
  import { Color, Vector3 } from 'three'
3
3
  import { T } from '@threlte/core'
4
- import { Gizmo, Grid, interactivity } from '@threlte/extras'
4
+ import {
5
+ CameraControls,
6
+ type CameraControlsRef,
7
+ Gizmo,
8
+ Grid,
9
+ interactivity,
10
+ } from '@threlte/extras'
5
11
  import { PortalTarget } from './portal'
6
12
  import Frames from './Frames.svelte'
7
13
  import Pointclouds from './Pointclouds.svelte'
8
- import CameraControls from './CameraControls.svelte'
9
14
  import Selected from './Selected.svelte'
10
15
  import Focus from './Focus.svelte'
11
16
  import StaticGeometries from './StaticGeometries.svelte'
@@ -16,6 +21,7 @@
16
21
  import { useXR } from '@threlte/xr'
17
22
  import { useTransformControls } from '../hooks/useControls.svelte'
18
23
  import KeyboardControls from './KeyboardControls.svelte'
24
+ import { useOrigin } from './xr/useOrigin.svelte'
19
25
 
20
26
  interface Props {
21
27
  children?: Snippet
@@ -35,6 +41,7 @@
35
41
 
36
42
  const focused = useFocused()
37
43
  const transformControls = useTransformControls()
44
+ const origin = useOrigin()
38
45
 
39
46
  const { isPresenting } = useXR()
40
47
  </script>
@@ -44,12 +51,16 @@
44
51
  args={[new Color('white')]}
45
52
  />
46
53
 
47
- <T.Group rotation.x={$isPresenting ? -Math.PI / 2 : 0}>
54
+ <T.Group
55
+ position={origin.position}
56
+ rotation.x={$isPresenting ? -Math.PI / 2 : 0}
57
+ rotation.z={origin.rotation}
58
+ >
48
59
  {#if focused.current === undefined}
49
60
  {#if !$isPresenting}
50
61
  <Camera position={[3, 3, 3]}>
51
62
  <CameraControls enabled={!transformControls.active}>
52
- {#snippet children({ ref })}
63
+ {#snippet children({ ref }: { ref: CameraControlsRef })}
53
64
  <KeyboardControls cameraControls={ref} />
54
65
  <Gizmo />
55
66
  {/snippet}
@@ -71,6 +82,8 @@
71
82
  plane="xy"
72
83
  sectionColor="#333"
73
84
  infiniteGrid
85
+ cellSize={0.5}
86
+ sectionSize={10}
74
87
  fadeOrigin={new Vector3()}
75
88
  fadeDistance={25}
76
89
  />
@@ -14,6 +14,7 @@
14
14
  import { provideMotionClient } from '../hooks/useMotionClient.svelte'
15
15
  import { provideLogs } from '../hooks/useLogs.svelte'
16
16
  import { provideSettings } from '../hooks/useSettings.svelte'
17
+ import { provideOrigin } from './xr/useOrigin.svelte'
17
18
 
18
19
  interface Props {
19
20
  children: Snippet<[{ focus: boolean }]>
@@ -29,6 +30,7 @@
29
30
  provideRefreshRates()
30
31
  provideLogs()
31
32
 
33
+ provideOrigin()
32
34
  provideStaticGeometries()
33
35
  provideShapes()
34
36
 
@@ -37,7 +39,6 @@
37
39
  providePointclouds(() => partID.current)
38
40
  provideMotionClient(() => partID.current)
39
41
  provideObjects()
40
-
41
42
  const { focus } = provideSelection()
42
43
  </script>
43
44
 
@@ -18,9 +18,6 @@
18
18
  class: className = '',
19
19
  onclick,
20
20
  }: Props = $props()
21
-
22
- const activeClasses = 'z-10 border-gray-5 bg-white text-gray-8'
23
- const inactiveClasses = 'bg-light border-medium text-disabled'
24
21
  </script>
25
22
 
26
23
  <Tooltip
@@ -28,7 +25,11 @@
28
25
  location="bottom"
29
26
  >
30
27
  <label
31
- class={[className, 'relative block border', active ? activeClasses : inactiveClasses]}
28
+ class={[
29
+ className,
30
+ 'relative block border',
31
+ active ? 'border-gray-5 text-gray-8 z-10 bg-white' : 'bg-light border-medium text-disabled',
32
+ ]}
32
33
  aria-describedby={tooltipID}
33
34
  >
34
35
  <button
@@ -8,11 +8,11 @@
8
8
  let { id = 'default' }: Props = $props()
9
9
 
10
10
  const portals = usePortalContext()
11
- const childArray = $derived(portals.get(id))
11
+ const childrenArray = $derived(portals.get(id))
12
12
  </script>
13
13
 
14
- {#if childArray}
15
- {#each childArray as children (children)}
16
- {@render children?.()}
14
+ {#if childrenArray !== undefined}
15
+ {#each childrenArray as children (children)}
16
+ {@render children()}
17
17
  {/each}
18
18
  {/if}
@@ -1,56 +1,48 @@
1
1
  <script lang="ts">
2
2
  import { Controller } from '@threlte/xr'
3
- import { useGamepad } from '@threlte/extras'
3
+ // import { useGamepad } from '@threlte/extras'
4
4
 
5
- import { BaseClient } from '@viamrobotics/sdk'
5
+ // import { BaseClient } from '@viamrobotics/sdk'
6
6
 
7
7
  import { RigidBody } from '@threlte/rapier'
8
8
  import HandCollider from './HandCollider.svelte'
9
- import { usePartID } from '../../hooks/usePartID.svelte'
10
- import { useResourceNames, useRobotClient } from '@viamrobotics/svelte-sdk'
11
-
12
- const gamepadLeft = useGamepad({ xr: true, hand: 'left' })
13
-
14
- const partID = usePartID()
15
- const resources = useResourceNames(() => partID.current)
16
- const robotClient = useRobotClient(() => partID.current)
17
- const resource = $derived(resources.current.find((r) => r.subtype === 'base'))
18
- const baseClient = $derived(
19
- robotClient.current && resource ? new BaseClient(robotClient.current, resource.name) : undefined
20
- )
21
-
22
- const linear = { x: 0, y: 0, z: 0 }
23
- const angular = { x: 0, y: 0, z: 0 }
24
-
25
- gamepadLeft.squeeze.on('change', (event) => {
26
- linear.y = -event.value
27
- baseClient?.setPower(linear, angular)
28
- })
29
-
30
- gamepadLeft.trigger.on('change', (event) => {
31
- if (typeof event.value === 'number') {
32
- linear.y = event.value
33
- baseClient?.setPower(linear, angular)
34
- }
35
- })
36
-
37
- gamepadLeft.thumbstick.on('change', (event) => {
38
- if (typeof event.value === 'object') {
39
- angular.z = event.value.x
40
- baseClient?.setPower(linear, angular)
41
- }
42
- })
43
-
44
- const onselectstart = () => {}
45
-
46
- const onselectend = () => {}
9
+ // import { usePartID } from '../../hooks/usePartID.svelte'
10
+ // import { useResourceNames, useRobotClient } from '@viamrobotics/svelte-sdk'
11
+
12
+ // const gamepadLeft = useGamepad({ xr: true, hand: 'left' })
13
+
14
+ // const partID = usePartID()
15
+ // const resources = useResourceNames(() => partID.current)
16
+ // const robotClient = useRobotClient(() => partID.current)
17
+ // const resource = $derived(resources.current.find((r) => r.subtype === 'base'))
18
+ // const baseClient = $derived(
19
+ // robotClient.current && resource ? new BaseClient(robotClient.current, resource.name) : undefined
20
+ // )
21
+
22
+ // const linear = { x: 0, y: 0, z: 0 }
23
+ // const angular = { x: 0, y: 0, z: 0 }
24
+
25
+ // gamepadLeft.squeeze.on('change', (event) => {
26
+ // linear.y = -event.value
27
+ // baseClient?.setPower(linear, angular)
28
+ // })
29
+
30
+ // gamepadLeft.trigger.on('change', (event) => {
31
+ // if (typeof event.value === 'number') {
32
+ // linear.y = event.value
33
+ // baseClient?.setPower(linear, angular)
34
+ // }
35
+ // })
36
+
37
+ // gamepadLeft.thumbstick.on('change', (event) => {
38
+ // if (typeof event.value === 'object') {
39
+ // angular.z = event.value.x
40
+ // baseClient?.setPower(linear, angular)
41
+ // }
42
+ // })
47
43
  </script>
48
44
 
49
- <Controller
50
- left
51
- {onselectstart}
52
- {onselectend}
53
- >
45
+ <Controller left>
54
46
  {#snippet grip()}
55
47
  <RigidBody type="kinematicPosition">
56
48
  <HandCollider />
@@ -58,11 +50,7 @@
58
50
  {/snippet}
59
51
  </Controller>
60
52
 
61
- <Controller
62
- right
63
- {onselectstart}
64
- {onselectend}
65
- >
53
+ <Controller right>
66
54
  {#snippet grip()}
67
55
  <RigidBody type="kinematicPosition">
68
56
  <HandCollider />
@@ -1,3 +1,18 @@
1
- declare const Controllers: import("svelte").Component<Record<string, never>, {}, "">;
2
- type Controllers = ReturnType<typeof Controllers>;
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const Controllers: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type Controllers = InstanceType<typeof Controllers>;
3
18
  export default Controllers;
@@ -2,6 +2,7 @@
2
2
  import { Hand } from '@threlte/xr'
3
3
 
4
4
  console.log('hands')
5
+
5
6
  const onpinchstart = () => {
6
7
  console.log('start')
7
8
  }
@@ -4,62 +4,112 @@
4
4
  import { Collider, RigidBody } from '@threlte/rapier'
5
5
  import { RigidBody as RigidBodyType } from '@dimforge/rapier3d-compat'
6
6
  import { useController } from '@threlte/xr'
7
- import { Group, Mesh, Quaternion, Vector3 } from 'three'
7
+ import { Euler, Group, Quaternion, Vector3 } from 'three'
8
+ import { useOrigin } from './useOrigin.svelte'
9
+
10
+ const origin = useOrigin()
8
11
 
9
12
  const height = 0.1
10
13
  const radius = 0.05
11
14
 
12
15
  const group = new Group()
13
- const mesh = new Mesh()
16
+ const innerGroup = new Group()
14
17
 
15
18
  const vec3 = new Vector3()
19
+
16
20
  const quaternion = new Quaternion()
21
+ const euler = new Euler()
17
22
 
18
23
  const offset = new Vector3()
24
+
19
25
  const position = new Vector3()
20
26
 
21
- let hovering = $state(false)
22
27
  let dragging = $state(false)
23
28
  let rotating = $state(false)
24
29
 
25
- let rigidBody: RigidBodyType | undefined = $state()
30
+ let currentDistance = 0
31
+ const rotateDown = new Vector3()
32
+
33
+ let rigidBody = $state<RigidBodyType>()
26
34
 
27
35
  const left = useController('left')
36
+ const right = useController('right')
37
+
28
38
  const leftPad = useGamepad({ xr: true, hand: 'left' })
39
+ const rightPad = useGamepad({ xr: true, hand: 'right' })
29
40
 
30
41
  leftPad.trigger.on('down', () => {
42
+ const grip = $left?.grip
43
+
44
+ if (!grip) {
45
+ return
46
+ }
47
+
31
48
  dragging = true
32
- mesh.getWorldPosition(vec3)
49
+ innerGroup.getWorldPosition(vec3)
33
50
  offset.copy($left!.grip.position).sub(vec3)
34
51
  })
35
52
  leftPad.trigger.on('up', () => (dragging = false))
36
53
 
37
- leftPad.squeeze.on('down', () => {
54
+ rightPad.trigger.on('down', () => {
55
+ const grip = $right?.grip
56
+
57
+ if (!grip) {
58
+ return
59
+ }
60
+
38
61
  rotating = true
39
- mesh.getWorldQuaternion(quaternion)
62
+ rotateDown.copy($right?.grip.position)
63
+ currentDistance = euler.z
40
64
  })
41
- leftPad.squeeze.on('up', () => (rotating = false))
42
-
43
- const onsensorenter = () => (hovering = true)
44
- const onsensorexit = () => (hovering = false)
65
+ rightPad.trigger.on('up', () => (rotating = false))
45
66
 
46
- const { start, stop } = useTask(
67
+ const dragTask = useTask(
47
68
  () => {
48
69
  if (!$left || !rigidBody) return
49
70
 
50
71
  position.copy($left.grip.position).sub(offset)
51
72
 
73
+ origin.set(position)
74
+
52
75
  rigidBody.setNextKinematicTranslation({ x: position.x, y: position.y, z: position.z })
53
76
  },
54
77
  { autoStart: false }
55
78
  )
56
79
 
57
- $effect(() => (hovering && dragging ? start() : stop()))
58
- </script>
80
+ const rotateTask = useTask(
81
+ () => {
82
+ if (!$right || !rigidBody) return
59
83
 
60
- {#if rotating}
61
- <!-- TODO -->
62
- {/if}
84
+ const distance = rotateDown.distanceToSquared($right.grip.position)
85
+
86
+ const rotation = rigidBody.rotation()
87
+ quaternion.copy(rotation)
88
+ euler.setFromQuaternion(quaternion)
89
+ euler.z = distance + currentDistance
90
+ origin.set(undefined, euler.z)
91
+
92
+ rigidBody.setNextKinematicRotation(quaternion.setFromEuler(euler))
93
+ },
94
+ { autoStart: false }
95
+ )
96
+
97
+ $effect.pre(() => {
98
+ if (dragging) {
99
+ dragTask.start()
100
+ } else {
101
+ dragTask.stop()
102
+ }
103
+ })
104
+
105
+ $effect.pre(() => {
106
+ if (rotating) {
107
+ rotateTask.start()
108
+ } else {
109
+ rotateTask.stop()
110
+ }
111
+ })
112
+ </script>
63
113
 
64
114
  <T
65
115
  is={group}
@@ -73,23 +123,13 @@
73
123
  sensor
74
124
  shape="cone"
75
125
  args={[height / 2, radius]}
76
- {onsensorenter}
77
- {onsensorexit}
78
126
  >
79
- <T is={mesh}>
80
- <T.ConeGeometry
81
- args={[radius, height]}
82
- oncreate={(ref) => {
83
- ref.rotateX(-Math.PI / 2)
84
- ref.translate(0, 0, height / 2)
85
- }}
86
- />
87
- <T.MeshStandardMaterial color={hovering ? 'hotpink' : 'red'} />
88
-
127
+ <T is={innerGroup}>
89
128
  <Grid
90
129
  plane="xy"
91
130
  position.y={0.05}
92
- fadeDistance={1}
131
+ fadeDistance={5}
132
+ fadeOrigin={new Vector3()}
93
133
  cellSize={0.1}
94
134
  cellColor="#fff"
95
135
  sectionColor="#fff"
@@ -1,16 +1,23 @@
1
1
  <script lang="ts">
2
- import { XR, XRButton } from '@threlte/xr'
2
+ import { T } from '@threlte/core'
3
+ import { useXR, XR, XRButton } from '@threlte/xr'
3
4
  import OriginMarker from './OriginMarker.svelte'
4
5
  import DomPortal from '../DomPortal.svelte'
5
6
  import { useSettings } from '../../hooks/useSettings.svelte'
7
+ import Controllers from './Controllers.svelte'
6
8
 
9
+ const { isPresenting } = useXR()
7
10
  const settings = useSettings()
8
11
  const enableXR = $derived(settings.current.enableXR)
9
12
  </script>
10
13
 
11
14
  {#if enableXR}
12
15
  <XR>
13
- <OriginMarker />
16
+ <T.Group rotation.x={$isPresenting ? -Math.PI / 2 : 0}>
17
+ <OriginMarker />
18
+ </T.Group>
19
+
20
+ <Controllers />
14
21
  </XR>
15
22
 
16
23
  <DomPortal>