@viamrobotics/motion-tools 0.5.6 → 0.6.1

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/color.d.ts CHANGED
@@ -7,18 +7,23 @@ import { Color, type ColorRepresentation } from 'three';
7
7
  */
8
8
  export declare const darkenColor: (value: ColorRepresentation, percent: number) => Color;
9
9
  export declare const colors: {
10
- readonly selected: string;
11
10
  readonly default: string;
12
- readonly arm: {
13
- readonly selected: string;
14
- readonly default: string;
15
- };
16
- readonly camera: {
17
- readonly selected: string;
18
- readonly default: string;
19
- };
20
- readonly gripper: {
21
- readonly selected: string;
22
- readonly default: string;
23
- };
11
+ };
12
+ export declare const resourceColors: {
13
+ readonly arm: string;
14
+ readonly camera: string;
15
+ readonly base: string;
16
+ readonly board: string;
17
+ readonly button: string;
18
+ readonly encoder: string;
19
+ readonly gantry: string;
20
+ readonly gripper: string;
21
+ readonly motor: string;
22
+ readonly movement_sensor: string;
23
+ readonly pose_tracker: string;
24
+ readonly power_sensor: string;
25
+ readonly sensor: string;
26
+ readonly servo: string;
27
+ readonly switch: string;
28
+ readonly webcam: string;
24
29
  };
package/dist/color.js CHANGED
@@ -51,19 +51,25 @@ export const darkenColor = (value, percent) => {
51
51
  hsl.l = Math.max(0, hsl.l * (1 - percent / 100));
52
52
  return new Color().setHSL(hsl.h, hsl.s, hsl.l);
53
53
  };
54
+ const darkness = '600';
54
55
  export const colors = {
55
- selected: oklchToHex(twColors.red['900']),
56
- default: oklchToHex(twColors.red['500']),
57
- arm: {
58
- selected: oklchToHex(twColors.amber['900']),
59
- default: oklchToHex(twColors.amber['500']),
60
- },
61
- camera: {
62
- selected: oklchToHex(twColors.blue['900']),
63
- default: oklchToHex(twColors.blue['500']),
64
- },
65
- gripper: {
66
- selected: oklchToHex(twColors.cyan['900']),
67
- default: oklchToHex(twColors.cyan['500']),
68
- },
56
+ default: oklchToHex(twColors.red[darkness]),
57
+ };
58
+ export const resourceColors = {
59
+ arm: oklchToHex(twColors.amber[darkness]),
60
+ camera: oklchToHex(twColors.blue[darkness]),
61
+ base: oklchToHex(twColors.slate[darkness]),
62
+ board: oklchToHex(twColors.emerald[darkness]),
63
+ button: oklchToHex(twColors.gray[darkness]),
64
+ encoder: oklchToHex(twColors.lime[darkness]),
65
+ gantry: oklchToHex(twColors.purple[darkness]),
66
+ gripper: oklchToHex(twColors.cyan[darkness]),
67
+ motor: oklchToHex(twColors.orange[darkness]),
68
+ movement_sensor: oklchToHex(twColors.indigo[darkness]),
69
+ pose_tracker: oklchToHex(twColors.rose[darkness]),
70
+ power_sensor: oklchToHex(twColors.violet[darkness]),
71
+ sensor: oklchToHex(twColors.teal[darkness]),
72
+ servo: oklchToHex(twColors.yellow[darkness]),
73
+ switch: oklchToHex(twColors.stone[darkness]),
74
+ webcam: oklchToHex(twColors.sky[darkness]),
69
75
  };
@@ -1,6 +1,11 @@
1
+ <script module>
2
+ import { Color, type Object3D } from 'three'
3
+
4
+ const colorUtil = new Color()
5
+ </script>
6
+
1
7
  <script lang="ts">
2
8
  import type { Snippet } from 'svelte'
3
- import type { Object3D } from 'three'
4
9
  import type { WorldObject } from '../WorldObject'
5
10
  import { useObjectEvents } from '../hooks/useObjectEvents.svelte'
6
11
  import Geometry from './Geometry.svelte'
@@ -20,13 +25,15 @@
20
25
 
21
26
  const selected = useSelected()
22
27
  const events = useObjectEvents(() => uuid)
28
+
29
+ const color = $derived(rest.metadata.color ?? colors.default)
23
30
  </script>
24
31
 
25
32
  <Geometry
26
33
  {uuid}
27
34
  color={selected.current === uuid
28
- ? `#${darkenColor(rest.metadata.color ?? colors.default, 75).getHexString()}`
29
- : undefined}
35
+ ? `#${darkenColor(color, 75).getHexString()}`
36
+ : `#${colorUtil.set(color).getHexString()}`}
30
37
  {...events}
31
38
  {...rest}
32
39
  />
@@ -1,5 +1,5 @@
1
+ import { type Object3D } from 'three';
1
2
  import type { Snippet } from 'svelte';
2
- import type { Object3D } from 'three';
3
3
  import type { WorldObject } from '../WorldObject';
4
4
  interface Props {
5
5
  uuid: string;
@@ -48,7 +48,7 @@
48
48
  poseToObject3d(pose, mesh)
49
49
  })
50
50
 
51
- let geo = $state<BufferGeometry>()
51
+ let geo = $state.raw<BufferGeometry>()
52
52
 
53
53
  const oncreate = (ref: BufferGeometry) => {
54
54
  geo = ref
@@ -22,6 +22,7 @@
22
22
  import { useTransformControls } from '../hooks/useControls.svelte'
23
23
  import KeyboardControls from './KeyboardControls.svelte'
24
24
  import { useOrigin } from './xr/useOrigin.svelte'
25
+ import { useSettings } from '../hooks/useSettings.svelte'
25
26
 
26
27
  interface Props {
27
28
  children?: Snippet
@@ -39,6 +40,7 @@
39
40
  },
40
41
  })
41
42
 
43
+ const settings = useSettings()
42
44
  const focusedObject3d = useFocusedObject3d()
43
45
  const transformControls = useTransformControls()
44
46
  const origin = useOrigin()
@@ -81,15 +83,15 @@
81
83
 
82
84
  <Selected />
83
85
 
84
- {#if !$isPresenting}
86
+ {#if !$isPresenting && settings.current.grid}
85
87
  <Grid
86
88
  plane="xy"
87
89
  sectionColor="#333"
88
90
  infiniteGrid
89
- cellSize={0.5}
90
- sectionSize={10}
91
+ cellSize={settings.current.gridCellSize}
92
+ sectionSize={settings.current.gridSectionSize}
91
93
  fadeOrigin={new Vector3()}
92
- fadeDistance={25}
94
+ fadeDistance={settings.current.gridFadeDistance}
93
95
  />
94
96
  {/if}
95
97
  {/if}
@@ -23,6 +23,12 @@
23
23
 
24
24
  keys.onKeys('=', () => geometries.add())
25
25
  keys.onKeys('-', () => geometries.remove(selected.current ?? ''))
26
+
27
+ $effect(() => {
28
+ settings.current.transforming = geometries.current.some(
29
+ (geometry) => selected.current === geometry.uuid
30
+ )
31
+ })
26
32
  </script>
27
33
 
28
34
  {#each geometries.current as object (object.uuid)}
@@ -39,6 +45,9 @@
39
45
  <TransformControls
40
46
  object={ref}
41
47
  {mode}
48
+ translationSnap={settings.current.snapping ? 0.1 : undefined}
49
+ rotationSnap={settings.current.snapping ? Math.PI / 24 : undefined}
50
+ scaleSnap={settings.current.snapping ? 0.1 : undefined}
42
51
  onmouseDown={() => {
43
52
  transformControls.setActive(true)
44
53
  }}
@@ -1,9 +1,11 @@
1
1
  <script lang="ts">
2
- import { Select } from '@viamrobotics/prime-core'
2
+ import { Select, Switch, Input } from '@viamrobotics/prime-core'
3
3
  import RefreshRate from '../RefreshRate.svelte'
4
4
  import { useMotionClient } from '../../hooks/useMotionClient.svelte'
5
5
  import Drawer from './Drawer.svelte'
6
+ import { useSettings } from '../../hooks/useSettings.svelte'
6
7
 
8
+ const settings = useSettings()
7
9
  const motionClient = useMotionClient()
8
10
  </script>
9
11
 
@@ -11,7 +13,9 @@
11
13
  name="Settings"
12
14
  defaultOpen
13
15
  >
14
- <div class="flex flex-col gap-2 p-3">
16
+ <div class="flex h-100 flex-col gap-2 overflow-scroll p-3">
17
+ <h3 class="text-base"><strong>Refresh rates</strong></h3>
18
+
15
19
  <RefreshRate name="Frames">
16
20
  <option value="0">Do not fetch</option>
17
21
  <option value="1">Fetch on reconfigure</option>
@@ -20,8 +24,10 @@
20
24
  <RefreshRate name="Geometries" />
21
25
  <RefreshRate name="Poses" />
22
26
 
27
+ <h3 class="text-base"><strong>Motion</strong></h3>
28
+
23
29
  <label class="flex flex-col gap-1">
24
- Motion client
30
+ Client
25
31
  <Select
26
32
  onchange={(event: InputEvent) => {
27
33
  if (event.target instanceof HTMLSelectElement) {
@@ -35,5 +41,45 @@
35
41
  {/each}
36
42
  </Select>
37
43
  </label>
44
+
45
+ <h3 class="text-base"><strong>Grid</strong></h3>
46
+ <div class="flex flex-col gap-2.5">
47
+ <label class="flex items-center justify-between gap-2">
48
+ Enabled <Switch bind:on={settings.current.grid} />
49
+ </label>
50
+
51
+ <label class="flex items-center justify-between gap-2">
52
+ Cell size (m)
53
+
54
+ <div class="w-20">
55
+ <Input
56
+ bind:value={settings.current.gridCellSize}
57
+ on:keydown={(event) => event.stopImmediatePropagation()}
58
+ />
59
+ </div>
60
+ </label>
61
+
62
+ <label class="flex items-center justify-between gap-2">
63
+ Section size (m)
64
+
65
+ <div class="w-20">
66
+ <Input
67
+ bind:value={settings.current.gridSectionSize}
68
+ on:keydown={(event) => event.stopImmediatePropagation()}
69
+ />
70
+ </div>
71
+ </label>
72
+
73
+ <label class="flex items-center justify-between gap-2">
74
+ Fade distance (m)
75
+
76
+ <div class="w-20">
77
+ <Input
78
+ bind:value={settings.current.gridFadeDistance}
79
+ on:keydown={(event) => event.stopImmediatePropagation()}
80
+ />
81
+ </div>
82
+ </label>
83
+ </div>
38
84
  </div>
39
85
  </Drawer>
@@ -5,7 +5,7 @@
5
5
  icon: IconName
6
6
  active?: boolean
7
7
  description: string
8
- hotkey: string
8
+ hotkey?: string
9
9
  class?: string
10
10
  onclick?: () => void
11
11
  }
@@ -14,7 +14,7 @@
14
14
  icon,
15
15
  active = false,
16
16
  description,
17
- hotkey,
17
+ hotkey = '',
18
18
  class: className = '',
19
19
  onclick,
20
20
  }: Props = $props()
@@ -3,7 +3,7 @@ interface Props {
3
3
  icon: IconName;
4
4
  active?: boolean;
5
5
  description: string;
6
- hotkey: string;
6
+ hotkey?: string;
7
7
  class?: string;
8
8
  onclick?: () => void;
9
9
  }
@@ -5,44 +5,7 @@
5
5
  const settings = useSettings()
6
6
  </script>
7
7
 
8
- <div class="absolute top-2 flex w-full justify-center">
9
- <!-- transform -->
10
- <!-- <fieldset>
11
- <Button
12
- icon="cursor-move"
13
- active={$transformMode === TransformModes.TRANSLATE}
14
- description="Translate"
15
- hotkey="T"
16
- onclick={() => transformMode.set(TransformModes.TRANSLATE)}
17
- />
18
- <Button
19
- icon="sync"
20
- active={$transformMode === TransformModes.ROTATE}
21
- description="Rotate"
22
- hotkey="R"
23
- class="-my-px"
24
- onclick={() => transformMode.set(TransformModes.ROTATE)}
25
- />
26
- <Button
27
- icon="resize"
28
- active={$transformMode === TransformModes.SCALE}
29
- description="Scale"
30
- hotkey="S"
31
- onclick={() => transformMode.set(TransformModes.SCALE)}
32
- />
33
- </fieldset> -->
34
-
35
- <!-- snapping -->
36
- <!-- <fieldset>
37
- <Button
38
- icon={$snapMode ? 'magnet' : 'magnet-off'}
39
- active={$snapMode === true}
40
- description="Snapping"
41
- hotkey="Spacebar"
42
- onClick={() => snapMode.set(!$snapMode)}
43
- />
44
- </fieldset> -->
45
-
8
+ <div class="absolute top-2 flex w-full justify-center gap-2">
46
9
  <!-- camera view -->
47
10
  <fieldset class="flex">
48
11
  <Button
@@ -65,4 +28,51 @@
65
28
  }}
66
29
  />
67
30
  </fieldset>
31
+
32
+ <!-- transform -->
33
+ {#if settings.current.transforming}
34
+ <fieldset class="flex">
35
+ <Button
36
+ icon="cursor-move"
37
+ active={settings.current.transformMode === 'translate'}
38
+ description="Translate"
39
+ hotkey="1"
40
+ onclick={() => {
41
+ settings.current.transformMode = 'translate'
42
+ }}
43
+ />
44
+ <Button
45
+ icon="sync"
46
+ active={settings.current.transformMode === 'rotate'}
47
+ description="Rotate"
48
+ hotkey="2"
49
+ class="-ml-px"
50
+ onclick={() => {
51
+ settings.current.transformMode = 'rotate'
52
+ }}
53
+ />
54
+ <Button
55
+ icon="resize"
56
+ active={settings.current.transformMode === 'scale'}
57
+ description="Scale"
58
+ hotkey="3"
59
+ class="-ml-px"
60
+ onclick={() => {
61
+ settings.current.transformMode = 'scale'
62
+ }}
63
+ />
64
+ </fieldset>
65
+
66
+ <!-- snapping -->
67
+ <fieldset class="flex">
68
+ <Button
69
+ icon={settings.current.snapping ? 'magnet' : 'magnet-off'}
70
+ active={settings.current.snapping}
71
+ description="Snapping"
72
+ onclick={() => {
73
+ settings.current.snapping = !settings.current.snapping
74
+ }}
75
+ />
76
+ </fieldset>
77
+ {/if}
68
78
  </div>
@@ -1,11 +1,13 @@
1
1
  import { getContext, setContext, untrack } from 'svelte';
2
- import { useRobotClient, createRobotQuery, useMachineStatus } from '@viamrobotics/svelte-sdk';
2
+ import { useRobotClient, createRobotQuery, useMachineStatus, useResourceNames, } from '@viamrobotics/svelte-sdk';
3
3
  import { WorldObject } from '../WorldObject';
4
4
  import { useRefreshRates } from './useRefreshRates.svelte';
5
5
  import { observe } from '@threlte/core';
6
6
  import { useLogs } from './useLogs.svelte';
7
+ import { resourceColors } from '../color';
7
8
  const key = Symbol('frames-context');
8
9
  export const provideFrames = (partID) => {
10
+ const resourceNames = useResourceNames(partID);
9
11
  const client = useRobotClient(partID);
10
12
  const machineStatus = useMachineStatus(partID);
11
13
  const logs = useLogs();
@@ -28,9 +30,15 @@ export const provideFrames = (partID) => {
28
30
  return objects;
29
31
  }
30
32
  for (const { frame } of query.current.data ?? []) {
31
- if (frame) {
32
- objects.push(new WorldObject(frame.referenceFrame ? frame.referenceFrame : 'Unnamed frame', frame.poseInObserverFrame?.pose, frame.poseInObserverFrame?.referenceFrame, frame.physicalObject?.geometryType));
33
+ if (frame === undefined) {
34
+ continue;
33
35
  }
36
+ const resourceName = resourceNames.current.find((item) => item.name === frame.referenceFrame);
37
+ objects.push(new WorldObject(frame.referenceFrame ? frame.referenceFrame : 'Unnamed frame', frame.poseInObserverFrame?.pose, frame.poseInObserverFrame?.referenceFrame, frame.physicalObject?.geometryType, resourceName
38
+ ? {
39
+ color: resourceColors[resourceName.subtype],
40
+ }
41
+ : undefined));
34
42
  }
35
43
  return objects;
36
44
  });
@@ -7,13 +7,15 @@ import { useRefreshRates } from './useRefreshRates.svelte';
7
7
  import { WorldObject } from '../WorldObject';
8
8
  import { usePersistentUUIDs } from './usePersistentUUIDs.svelte';
9
9
  import { useLogs } from './useLogs.svelte';
10
+ import { resourceColors } from '../color';
10
11
  const key = Symbol('geometries-context');
11
12
  export const provideGeometries = (partID) => {
12
- const logs = useLogs();
13
- const refreshRates = useRefreshRates();
13
+ const resourceNames = useResourceNames(partID);
14
14
  const arms = useResourceNames(partID, 'arm');
15
15
  const cameras = useResourceNames(partID, 'camera');
16
16
  const grippers = useResourceNames(partID, 'gripper');
17
+ const logs = useLogs();
18
+ const refreshRates = useRefreshRates();
17
19
  const armClients = $derived(arms.current.map((arm) => createResourceClient(ArmClient, partID, () => arm.name)));
18
20
  const gripperClients = $derived(grippers.current.map((gripper) => createResourceClient(GripperClient, partID, () => gripper.name)));
19
21
  const cameraClients = $derived(cameras.current.map((camera) => createResourceClient(CameraClient, partID, () => camera.name)));
@@ -45,7 +47,10 @@ export const provideGeometries = (partID) => {
45
47
  if (!query.data)
46
48
  continue;
47
49
  for (const { center, label, geometryType } of query.data.geometries) {
48
- results.push(new WorldObject(label ? label : 'Unnamed geometry', center, query.data.name, geometryType));
50
+ const resourceName = resourceNames.current.find((item) => item.name === query.data.name);
51
+ results.push(new WorldObject(label ? label : 'Unnamed geometry', center, query.data.name, geometryType, resourceName
52
+ ? { color: resourceColors[resourceName.subtype] }
53
+ : undefined));
49
54
  }
50
55
  }
51
56
  updateUUIDs(results);
@@ -1,6 +1,12 @@
1
1
  interface Settings {
2
2
  cameraMode: 'orthographic' | 'perspective';
3
+ transforming: boolean;
4
+ snapping: boolean;
3
5
  transformMode: 'translate' | 'rotate' | 'scale';
6
+ grid: boolean;
7
+ gridCellSize: number;
8
+ gridSectionSize: number;
9
+ gridFadeDistance: number;
4
10
  enableXR: boolean;
5
11
  }
6
12
  interface Context {
@@ -3,7 +3,13 @@ import { getContext, setContext } from 'svelte';
3
3
  const key = Symbol('dashboard-context');
4
4
  const defaults = () => ({
5
5
  cameraMode: 'perspective',
6
+ transforming: false,
7
+ snapping: false,
6
8
  transformMode: 'translate',
9
+ grid: true,
10
+ gridCellSize: 0.5,
11
+ gridSectionSize: 10,
12
+ gridFadeDistance: 25,
7
13
  enableXR: false,
8
14
  });
9
15
  export const provideSettings = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "0.5.6",
3
+ "version": "0.6.1",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -11,38 +11,38 @@
11
11
  "@changesets/cli": "2.29.5",
12
12
  "@dimforge/rapier3d-compat": "0.17.3",
13
13
  "@eslint/compat": "1.3.1",
14
- "@eslint/js": "9.30.1",
15
- "@playwright/test": "1.53.2",
16
- "@sentry/sveltekit": "9.35.0",
17
- "@skeletonlabs/skeleton": "3.1.4",
18
- "@skeletonlabs/skeleton-svelte": "1.2.4",
14
+ "@eslint/js": "9.31.0",
15
+ "@playwright/test": "1.54.1",
16
+ "@sentry/sveltekit": "9.39.0",
17
+ "@skeletonlabs/skeleton": "3.1.7",
18
+ "@skeletonlabs/skeleton-svelte": "1.3.0",
19
19
  "@sveltejs/adapter-static": "3.0.8",
20
- "@sveltejs/kit": "2.22.2",
21
- "@sveltejs/package": "2.3.12",
22
- "@sveltejs/vite-plugin-svelte": "5.1.0",
20
+ "@sveltejs/kit": "2.24.0",
21
+ "@sveltejs/package": "2.4.0",
22
+ "@sveltejs/vite-plugin-svelte": "6.1.0",
23
23
  "@tailwindcss/forms": "0.5.10",
24
24
  "@tailwindcss/vite": "4.1.11",
25
- "@tanstack/svelte-query": "5.81.5",
26
- "@tanstack/svelte-query-devtools": "5.81.5",
25
+ "@tanstack/svelte-query": "5.83.0",
26
+ "@tanstack/svelte-query-devtools": "5.83.0",
27
27
  "@testing-library/jest-dom": "6.6.3",
28
28
  "@testing-library/svelte": "5.2.8",
29
- "@threlte/core": "8.1.2",
29
+ "@threlte/core": "8.1.3",
30
30
  "@threlte/extras": "9.4.2",
31
31
  "@threlte/rapier": "3.1.4",
32
32
  "@threlte/xr": "1.0.8",
33
33
  "@types/bun": "1.2.18",
34
34
  "@types/lodash-es": "4.17.12",
35
- "@types/three": "0.178.0",
36
- "@typescript-eslint/eslint-plugin": "8.36.0",
37
- "@typescript-eslint/parser": "8.36.0",
35
+ "@types/three": "0.178.1",
36
+ "@typescript-eslint/eslint-plugin": "8.37.0",
37
+ "@typescript-eslint/parser": "8.37.0",
38
38
  "@viamrobotics/prime-core": "0.1.5",
39
39
  "@viamrobotics/sdk": "0.46.0",
40
- "@viamrobotics/svelte-sdk": "0.4.1",
40
+ "@viamrobotics/svelte-sdk": "0.4.3",
41
41
  "@vitejs/plugin-basic-ssl": "2.1.0",
42
- "@zag-js/svelte": "1.18.2",
43
- "@zag-js/tree-view": "1.18.2",
44
- "camera-controls": "2.10.1",
45
- "eslint": "9.30.1",
42
+ "@zag-js/svelte": "1.18.3",
43
+ "@zag-js/tree-view": "1.18.3",
44
+ "camera-controls": "3.1.0",
45
+ "eslint": "9.31.0",
46
46
  "eslint-config-prettier": "10.1.5",
47
47
  "eslint-plugin-svelte": "3.10.1",
48
48
  "globals": "16.3.0",
@@ -52,10 +52,10 @@
52
52
  "lucide-svelte": "0.525.0",
53
53
  "prettier": "3.6.2",
54
54
  "prettier-plugin-svelte": "3.4.0",
55
- "prettier-plugin-tailwindcss": "0.6.13",
55
+ "prettier-plugin-tailwindcss": "0.6.14",
56
56
  "publint": "0.3.12",
57
- "runed": "0.30.0",
58
- "svelte": "5.35.4",
57
+ "runed": "0.31.0",
58
+ "svelte": "5.36.1",
59
59
  "svelte-check": "4.2.2",
60
60
  "svelte-virtuallists": "1.4.2",
61
61
  "tailwindcss": "4.1.11",
@@ -63,9 +63,9 @@
63
63
  "threlte-uikit": "1.2.0",
64
64
  "tsx": "4.20.3",
65
65
  "typescript": "5.8.3",
66
- "typescript-eslint": "8.36.0",
66
+ "typescript-eslint": "8.37.0",
67
67
  "vite": "6.3.5",
68
- "vite-plugin-devtools-json": "0.2.1",
68
+ "vite-plugin-devtools-json": "0.3.0",
69
69
  "vite-plugin-mkcert": "1.17.8",
70
70
  "vitest": "3.2.4"
71
71
  },