@viamrobotics/motion-tools 0.9.2 → 0.9.3

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,11 +1,17 @@
1
1
  <script lang="ts">
2
- import { T } from '@threlte/core'
2
+ import { T, useThrelte } from '@threlte/core'
3
3
  import { useSettings } from '../hooks/useSettings.svelte'
4
+ import type { Camera } from 'three'
4
5
 
5
6
  let { children, ...rest } = $props()
6
7
 
8
+ const { camera } = useThrelte()
7
9
  const settings = useSettings()
8
10
  const mode = $derived(settings.current.cameraMode)
11
+
12
+ $effect(() => {
13
+ ;(window as unknown as { camera: Camera }).camera = $camera
14
+ })
9
15
  </script>
10
16
 
11
17
  {#if mode === 'perspective'}
@@ -1,3 +1,4 @@
1
+ import type { Camera } from 'three';
1
2
  declare const Camera: import("svelte").Component<{
2
3
  children: any;
3
4
  } & Record<string, any>, {}, "">;
@@ -19,6 +19,12 @@
19
19
  drawAPI.clearCamera()
20
20
  }
21
21
  })
22
+
23
+ $effect(() => {
24
+ if (ref) {
25
+ ;(window as unknown as { cameraControls: CameraControlsRef }).cameraControls = ref
26
+ }
27
+ })
22
28
  </script>
23
29
 
24
30
  <Portal id="dashboard">
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ import { BackSide, Vector3 } from 'three'
3
+ import { T, useThrelte } from '@threlte/core'
4
+ import { MeshDiscardMaterial } from '@threlte/extras'
5
+ import { useSelected } from '../hooks/useSelection.svelte'
6
+ import { useTransformControls } from '../hooks/useControls.svelte'
7
+
8
+ const { camera } = useThrelte()
9
+ const selected = useSelected()
10
+ const transformControls = useTransformControls()
11
+ const cameraDown = new Vector3()
12
+
13
+ const size = 1_000
14
+ </script>
15
+
16
+ <T.Mesh
17
+ onpointerdown={() => {
18
+ cameraDown.copy(camera.current.position)
19
+ }}
20
+ onpointerup={() => {
21
+ if (transformControls.active) {
22
+ return
23
+ }
24
+
25
+ if (cameraDown.distanceToSquared(camera.current.position) > 0.2) {
26
+ return
27
+ }
28
+
29
+ selected.set()
30
+ }}
31
+ >
32
+ <T.BoxGeometry args={[size, size, size]} />
33
+ <MeshDiscardMaterial side={BackSide} />
34
+ </T.Mesh>
@@ -0,0 +1,18 @@
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 PointerMissBox: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type PointerMissBox = InstanceType<typeof PointerMissBox>;
18
+ export default PointerMissBox;
@@ -16,6 +16,7 @@
16
16
  import { useSettings } from '../hooks/useSettings.svelte'
17
17
  import CameraControls from './CameraControls.svelte'
18
18
  import MeasureTool from './MeasureTool.svelte'
19
+ import PointerMissBox from './PointerMissBox.svelte'
19
20
 
20
21
  interface Props {
21
22
  children?: Snippet
@@ -66,6 +67,7 @@
66
67
  <StaticGeometries />
67
68
 
68
69
  <WorldObjects />
70
+ <PointerMissBox />
69
71
 
70
72
  <Selected />
71
73
 
@@ -1,48 +1,56 @@
1
1
  <script lang="ts">
2
2
  import { Box3, Object3D } from 'three'
3
- import { T, useTask, useThrelte } from '@threlte/core'
4
- import { useSelectedObject } from '../hooks/useSelection.svelte'
3
+ import { T, useTask } from '@threlte/core'
4
+ import { useSelectedObject, useSelectedObject3d } from '../hooks/useSelection.svelte'
5
5
  import { BoxHelper } from '../three/BoxHelper'
6
6
 
7
- const { scene } = useThrelte()
8
-
7
+ const box3 = new Box3()
9
8
  const box = new BoxHelper(new Object3D(), 0x000000)
10
9
  const selected = useSelectedObject()
10
+ const selectedObject3d = useSelectedObject3d()
11
11
 
12
- const { start, stop } = useTask(() => box.update(), { autoStart: false })
12
+ // Create a clone so that our bounding box doesn't include children
13
+ const clone = $derived.by(() => {
14
+ if (selected.current?.metadata.batched) {
15
+ return
16
+ }
13
17
 
14
- const box3 = new Box3()
18
+ return selectedObject3d.current?.clone(false)
19
+ })
20
+
21
+ const { start, stop } = useTask(
22
+ () => {
23
+ if (selected.current === undefined) {
24
+ return
25
+ }
26
+
27
+ if (selected.current.metadata.batched) {
28
+ selected.current.metadata.getBoundingBoxAt?.(box3)
29
+ box.setFromBox3(box3)
30
+ return
31
+ }
32
+
33
+ if (clone) {
34
+ selectedObject3d.current?.getWorldPosition(clone.position)
35
+ selectedObject3d.current?.getWorldQuaternion(clone.quaternion)
36
+ box.setFromObject(clone)
37
+ }
38
+ },
39
+ { autoStart: false }
40
+ )
15
41
 
16
42
  $effect.pre(() => {
17
43
  if (selected.current) {
18
44
  start()
45
+ box.visible = true
19
46
  } else {
20
47
  stop()
21
- }
22
- })
23
-
24
- $effect.pre(() => {
25
- if (!selected.current) {
26
48
  box.visible = false
27
- return
28
- }
29
-
30
- box.visible = true
31
-
32
- if (selected.current.metadata.batched) {
33
- selected.current.metadata.getBoundingBoxAt?.(box3)
34
- box.setFromBox3(box3)
35
- } else {
36
- const object3d = scene.getObjectByProperty('uuid', selected.current.uuid)
37
- if (object3d) {
38
- // Create a clone so that our bounding box doesn't include children
39
- const clone = object3d.clone(false)
40
- object3d.getWorldPosition(clone.position)
41
- object3d.getWorldQuaternion(clone.quaternion)
42
- box.setFromObject(clone)
43
- }
44
49
  }
45
50
  })
46
51
  </script>
47
52
 
48
- <T is={box} />
53
+ <T
54
+ is={box}
55
+ raycast={() => null}
56
+ />
@@ -6,5 +6,4 @@ export declare const useObjectEvents: (uuid: () => string) => {
6
6
  ondblclick: (event: IntersectionEvent<MouseEvent>) => void;
7
7
  onpointerdown: (event: IntersectionEvent<MouseEvent>) => void;
8
8
  onclick: (event: IntersectionEvent<MouseEvent>) => void;
9
- onpointermissed: () => void;
10
9
  };
@@ -44,11 +44,5 @@ export const useObjectEvents = (uuid) => {
44
44
  selected.set(uuid());
45
45
  }
46
46
  },
47
- onpointermissed: () => {
48
- if (measuring) {
49
- return;
50
- }
51
- selected.set();
52
- },
53
47
  };
54
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -87,7 +87,6 @@
87
87
  "svelte": ">=5",
88
88
  "svelte-virtuallists": ">=1"
89
89
  },
90
- "packageManager": "pnpm@8.15.6+sha256.01c01eeb990e379b31ef19c03e9d06a14afa5250b82e81303f88721c99ff2e6f",
91
90
  "svelte": "./dist/index.js",
92
91
  "types": "./dist/index.d.ts",
93
92
  "exports": {