@viamrobotics/motion-tools 1.25.5 → 1.26.0

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
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte'
3
3
 
4
- import { T } from '@threlte/core'
4
+ import { T, useThrelte } from '@threlte/core'
5
5
  import { Environment, Grid, interactivity, PerfMonitor, PortalTarget } from '@threlte/extras'
6
6
  import { useXR } from '@threlte/xr'
7
7
  import { ShaderMaterial, Vector3 } from 'three'
@@ -29,10 +29,14 @@
29
29
 
30
30
  let { children }: Props = $props()
31
31
 
32
+ const threlte = useThrelte()
32
33
  const settings = useSettings()
33
34
  const focusedObject3d = useFocusedObject3d()
34
35
  const origin = useOrigin()
35
36
 
37
+ // @ts-expect-error This is for debugging
38
+ globalThis.__threlte__ = threlte
39
+
36
40
  const { raycaster, enabled } = interactivity({
37
41
  filter: (intersections) => {
38
42
  const match = intersections.find((intersection) => {
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import type { Entity } from 'koota'
2
3
  import type { Snippet } from 'svelte'
3
4
 
4
5
  import { useThrelte } from '@threlte/core'
@@ -6,6 +7,7 @@
6
7
  import { ElementRect } from 'runed'
7
8
 
8
9
  import DashboardButton from '../overlay/dashboard/Button.svelte'
10
+ import { useSelectedEntity } from '../../hooks/useSelection.svelte'
9
11
  import { useSettings } from '../../hooks/useSettings.svelte'
10
12
 
11
13
  import Popover from '../overlay/Popover.svelte'
@@ -17,18 +19,21 @@
17
19
  interface Props {
18
20
  /** Whether to auto-enable lasso mode when the component mounts */
19
21
  enabled?: boolean
22
+ // TODO: remove once a Selected trait exists
23
+ autoSelectNewEntities?: boolean
20
24
  children?: Snippet
21
25
  }
22
26
 
23
27
  type SelectionType = 'lasso' | 'ellipse'
24
28
 
25
- let { enabled = false, children }: Props = $props()
29
+ let { enabled = false, autoSelectNewEntities = false, children }: Props = $props()
26
30
 
27
31
  const { dom } = useThrelte()
28
32
  const settings = useSettings()
29
33
  const isSelectionMode = $derived(settings.current.interactionMode === 'select')
30
34
 
31
- provideSelectionPlugin()
35
+ const selectionPlugin = provideSelectionPlugin()
36
+ const selectedEntity = useSelectedEntity()
32
37
  let selectionType = $state<SelectionType>('lasso')
33
38
 
34
39
  $effect(() => {
@@ -43,6 +48,19 @@
43
48
  }
44
49
  })
45
50
 
51
+ let previousEntities: Entity[] = []
52
+ $effect(() => {
53
+ if (!autoSelectNewEntities) return
54
+
55
+ const current = selectionPlugin.current
56
+ const newEntities = current.filter((entity) => !previousEntities.includes(entity))
57
+ previousEntities = [...current]
58
+
59
+ const newest = newEntities.at(-1)
60
+ if (newest === undefined) return
61
+ selectedEntity.set(newest)
62
+ })
63
+
46
64
  const rect = new ElementRect(() => dom)
47
65
  </script>
48
66
 
@@ -2,6 +2,7 @@ import type { Snippet } from 'svelte';
2
2
  interface Props {
3
3
  /** Whether to auto-enable lasso mode when the component mounts */
4
4
  enabled?: boolean;
5
+ autoSelectNewEntities?: boolean;
5
6
  children?: Snippet;
6
7
  }
7
8
  declare const Tool: import("svelte").Component<Props, {}, "">;
@@ -477,13 +477,24 @@
477
477
  <div>
478
478
  <strong class="font-semibold">parent frame</strong>
479
479
  {#if showEditFrameOptions}
480
- <div aria-label="mutable parent frame">
481
- <List
482
- options={configFrames.getParentFrameOptions(name.current ?? '') ?? []}
483
- value={parent.current ?? 'world'}
484
- on:change={handleParentChange}
485
- />
486
- </div>
480
+ <!--
481
+ Remount on entity change. svelte-tweakpane-ui's List runs
482
+ `listBlade.value = value` on the still-mounted blade before its
483
+ `options` prop has propagated, so the new entity's parent name
484
+ (absent from the previous entity's option set) hits Tweakpane's
485
+ ListConstraint, snaps to the first option, and fires a change
486
+ event that handleParentChange interprets as a user pick — silently
487
+ reparenting the clicked frame.
488
+ -->
489
+ {#key entity}
490
+ <div aria-label="mutable parent frame">
491
+ <List
492
+ options={configFrames.getParentFrameOptions(name.current ?? '') ?? []}
493
+ value={parent.current ?? 'world'}
494
+ on:change={handleParentChange}
495
+ />
496
+ </div>
497
+ {/key}
487
498
  {:else}
488
499
  <div class="mt-0.5 flex gap-3">
489
500
  {@render ImmutableField({
@@ -1,8 +1,16 @@
1
1
  import { createWorld } from 'koota';
2
2
  import { getContext, setContext } from 'svelte';
3
+ import * as relations from './relations';
4
+ import * as traits from './traits';
3
5
  export const WORLD_CONTEXT_KEY = Symbol('koota-context');
4
6
  export function provideWorld() {
5
7
  const world = createWorld();
8
+ // @ts-expect-error This is for debugging.
9
+ globalThis.__koota__ = {
10
+ world,
11
+ traits,
12
+ relations,
13
+ };
6
14
  setContext(WORLD_CONTEXT_KEY, world);
7
15
  }
8
16
  export function useWorld() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "1.25.5",
3
+ "version": "1.26.0",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "@testing-library/jest-dom": "6.8.0",
26
26
  "@testing-library/svelte": "5.2.8",
27
27
  "@testing-library/user-event": "^14.6.1",
28
- "@threlte/core": "8.5.11",
29
- "@threlte/extras": "9.15.0",
28
+ "@threlte/core": "8.5.13",
29
+ "@threlte/extras": "9.15.2",
30
30
  "@threlte/rapier": "3.4.1",
31
31
  "@threlte/xr": "1.5.2",
32
32
  "@types/bun": "1.2.21",