@viamrobotics/motion-tools 1.1.4 → 1.1.5
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/components/App.svelte +7 -1
- package/dist/components/App.svelte.d.ts +2 -0
- package/dist/components/Tree/TreeContainer.svelte +33 -35
- package/dist/components/dashboard/Button.svelte +3 -2
- package/dist/components/dashboard/Button.svelte.d.ts +3 -2
- package/dist/defines.d.ts +8 -0
- package/dist/defines.js +8 -0
- package/dist/hooks/useDrawAPI.svelte.js +39 -16
- package/dist/hooks/useDrawConnectionConfig.svelte.d.ts +10 -0
- package/dist/hooks/useDrawConnectionConfig.svelte.js +13 -0
- package/dist/hooks/useFrames.svelte.js +1 -1
- package/package.json +5 -1
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
import { provideEnvironment } from '../hooks/useEnvironment.svelte'
|
|
23
23
|
import type { CameraPose } from '../hooks/useControls.svelte'
|
|
24
24
|
import { provideWorld } from '../ecs'
|
|
25
|
+
import {
|
|
26
|
+
provideDrawConnectionConfig,
|
|
27
|
+
type DrawConnectionConfig,
|
|
28
|
+
} from '../hooks/useDrawConnectionConfig.svelte'
|
|
25
29
|
|
|
26
30
|
interface LocalConfigProps {
|
|
27
31
|
getLocalPartConfig: () => Struct
|
|
@@ -36,6 +40,7 @@
|
|
|
36
40
|
children?: Snippet
|
|
37
41
|
dashboard?: Snippet
|
|
38
42
|
localConfigProps?: LocalConfigProps
|
|
43
|
+
drawConnectionConfig?: DrawConnectionConfig
|
|
39
44
|
|
|
40
45
|
/**
|
|
41
46
|
* Allows setting the initial camera pose
|
|
@@ -48,6 +53,7 @@
|
|
|
48
53
|
enableKeybindings = true,
|
|
49
54
|
localConfigProps,
|
|
50
55
|
cameraPose,
|
|
56
|
+
drawConnectionConfig,
|
|
51
57
|
children: appChildren,
|
|
52
58
|
dashboard,
|
|
53
59
|
}: Props = $props()
|
|
@@ -63,7 +69,7 @@
|
|
|
63
69
|
})
|
|
64
70
|
|
|
65
71
|
createPartIDContext(() => partID)
|
|
66
|
-
|
|
72
|
+
provideDrawConnectionConfig(() => drawConnectionConfig)
|
|
67
73
|
provideWeblabs()
|
|
68
74
|
provideToast()
|
|
69
75
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { Struct } from '@viamrobotics/sdk';
|
|
3
3
|
import type { CameraPose } from '../hooks/useControls.svelte';
|
|
4
|
+
import { type DrawConnectionConfig } from '../hooks/useDrawConnectionConfig.svelte';
|
|
4
5
|
interface LocalConfigProps {
|
|
5
6
|
getLocalPartConfig: () => Struct;
|
|
6
7
|
setLocalPartConfig: (config: Struct) => void;
|
|
@@ -13,6 +14,7 @@ interface Props {
|
|
|
13
14
|
children?: Snippet;
|
|
14
15
|
dashboard?: Snippet;
|
|
15
16
|
localConfigProps?: LocalConfigProps;
|
|
17
|
+
drawConnectionConfig?: DrawConnectionConfig;
|
|
16
18
|
/**
|
|
17
19
|
* Allows setting the initial camera pose
|
|
18
20
|
*/
|
|
@@ -69,41 +69,39 @@
|
|
|
69
69
|
})
|
|
70
70
|
</script>
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const value = event.selectedValue[0]
|
|
72
|
+
<div
|
|
73
|
+
bind:this={container}
|
|
74
|
+
class="bg-extralight border-medium absolute top-0 left-0 z-1000 m-2 resize overflow-y-auto border text-xs"
|
|
75
|
+
style:min-width="{MIN_DIMENSIONS.width}px"
|
|
76
|
+
style:min-height="{MIN_DIMENSIONS.height}px"
|
|
77
|
+
style:width={resizable.current ? `${resizable.current.width}px` : undefined}
|
|
78
|
+
style:height={resizable.current ? `${resizable.current.height}px` : undefined}
|
|
79
|
+
use:draggable={{
|
|
80
|
+
bounds: 'body',
|
|
81
|
+
handle: dragElement,
|
|
82
|
+
defaultPosition: dragPosition.current,
|
|
83
|
+
onDragEnd(data) {
|
|
84
|
+
dragPosition.current = { x: Math.max(data.offsetX, 0), y: Math.max(data.offsetY, 0) }
|
|
85
|
+
},
|
|
86
|
+
}}
|
|
87
|
+
{...rest}
|
|
88
|
+
>
|
|
89
|
+
<Tree
|
|
90
|
+
{rootNode}
|
|
91
|
+
{nodeMap}
|
|
92
|
+
bind:dragElement
|
|
93
|
+
onSelectionChange={(event) => {
|
|
94
|
+
const value = event.selectedValue[0]
|
|
96
95
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
selectedEntity.set(value ? (Number(value) as Entity) : undefined)
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
{#if environment.current.isStandalone && partID.current && partConfig.hasEditPermissions}
|
|
101
|
+
<AddFrames />
|
|
102
|
+
{/if}
|
|
104
103
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
{/if}
|
|
104
|
+
<Logs />
|
|
105
|
+
<Settings />
|
|
106
|
+
<Widgets />
|
|
107
|
+
</div>
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { Icon, type IconName, Tooltip } from '@viamrobotics/prime-core'
|
|
3
3
|
import { Ruler } from 'lucide-svelte'
|
|
4
|
+
import type { ClassValue, MouseEventHandler } from 'svelte/elements'
|
|
4
5
|
|
|
5
6
|
interface Props {
|
|
6
7
|
icon: IconName | 'ruler'
|
|
7
8
|
active?: boolean
|
|
8
9
|
description: string
|
|
9
10
|
hotkey?: string
|
|
10
|
-
class?:
|
|
11
|
-
onclick?:
|
|
11
|
+
class?: ClassValue | null | undefined
|
|
12
|
+
onclick?: MouseEventHandler<HTMLButtonElement> | null | undefined
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
let {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type IconName } from '@viamrobotics/prime-core';
|
|
2
|
+
import type { ClassValue, MouseEventHandler } from 'svelte/elements';
|
|
2
3
|
interface Props {
|
|
3
4
|
icon: IconName | 'ruler';
|
|
4
5
|
active?: boolean;
|
|
5
6
|
description: string;
|
|
6
7
|
hotkey?: string;
|
|
7
|
-
class?:
|
|
8
|
-
onclick?:
|
|
8
|
+
class?: ClassValue | null | undefined;
|
|
9
|
+
onclick?: MouseEventHandler<HTMLButtonElement> | null | undefined;
|
|
9
10
|
}
|
|
10
11
|
declare const Button: import("svelte").Component<Props, {}, "">;
|
|
11
12
|
type Button = ReturnType<typeof Button>;
|
package/dist/defines.js
ADDED
|
@@ -12,6 +12,7 @@ import {} from 'koota';
|
|
|
12
12
|
import { parsePlyInput } from '../ply';
|
|
13
13
|
import { useLogs } from './useLogs.svelte';
|
|
14
14
|
import { createBox, createCapsule, createSphere } from '../geometry';
|
|
15
|
+
import { useDrawConnectionConfig } from './useDrawConnectionConfig.svelte';
|
|
15
16
|
const colorUtil = new Color();
|
|
16
17
|
const bufferTypes = {
|
|
17
18
|
DRAW_POINTS: 0,
|
|
@@ -70,6 +71,9 @@ export const provideDrawAPI = () => {
|
|
|
70
71
|
const logs = useLogs();
|
|
71
72
|
const cameraControls = useCameraControls();
|
|
72
73
|
const { invalidate } = useThrelte();
|
|
74
|
+
const drawConnectionConfig = useDrawConnectionConfig();
|
|
75
|
+
const backendIP = $derived(drawConnectionConfig.current?.backendIP);
|
|
76
|
+
const websocketPort = $derived(drawConnectionConfig.current?.websocketPort);
|
|
73
77
|
let pointsIndex = 0;
|
|
74
78
|
let geometryIndex = 0;
|
|
75
79
|
let poseIndex = 0;
|
|
@@ -82,7 +86,7 @@ export const provideDrawAPI = () => {
|
|
|
82
86
|
const loader = new GLTFLoader();
|
|
83
87
|
const entities = new Map();
|
|
84
88
|
const sendResponse = (response) => {
|
|
85
|
-
ws
|
|
89
|
+
ws?.send(JSON.stringify(response));
|
|
86
90
|
};
|
|
87
91
|
const drawFrames = async (data) => {
|
|
88
92
|
for (const rawFrame of data) {
|
|
@@ -300,15 +304,20 @@ export const provideDrawAPI = () => {
|
|
|
300
304
|
};
|
|
301
305
|
const scheduleReconnect = () => {
|
|
302
306
|
setTimeout(() => {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
307
|
+
if (backendIP && websocketPort) {
|
|
308
|
+
reconnectDelay = Math.min(reconnectDelay * 2, maxReconnectDelay);
|
|
309
|
+
logs.add(`Reconnecting to drawing server in ${reconnectDelay / 1000} seconds...`, 'warn');
|
|
310
|
+
connect(backendIP, websocketPort);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
logs.add('No provided backend IP or websocket port', 'error');
|
|
314
|
+
}
|
|
306
315
|
}, reconnectDelay);
|
|
307
316
|
};
|
|
308
317
|
const onOpen = () => {
|
|
309
318
|
connectionStatus = 'open';
|
|
310
319
|
reconnectDelay = 1000;
|
|
311
|
-
logs.add(`Connected to drawing server at ${
|
|
320
|
+
logs.add(`Connected to drawing server at ${backendIP}:${websocketPort}`);
|
|
312
321
|
};
|
|
313
322
|
const onClose = () => {
|
|
314
323
|
connectionStatus = 'closed';
|
|
@@ -317,7 +326,7 @@ export const provideDrawAPI = () => {
|
|
|
317
326
|
};
|
|
318
327
|
const onError = (event) => {
|
|
319
328
|
const stringified = JSON.stringify(event);
|
|
320
|
-
ws
|
|
329
|
+
ws?.close();
|
|
321
330
|
if (stringified === '{"isTrusted":true}') {
|
|
322
331
|
return;
|
|
323
332
|
}
|
|
@@ -409,17 +418,31 @@ export const provideDrawAPI = () => {
|
|
|
409
418
|
}
|
|
410
419
|
invalidate();
|
|
411
420
|
};
|
|
412
|
-
const connect = () => {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
+
const connect = (backendIP, websocketPort) => {
|
|
422
|
+
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
|
423
|
+
ws = new WebSocket(`${protocol}://${backendIP}:${websocketPort}/ws`);
|
|
424
|
+
ws.onclose = onClose;
|
|
425
|
+
ws.onerror = onError;
|
|
426
|
+
ws.onopen = onOpen;
|
|
427
|
+
ws.onmessage = onMessage;
|
|
428
|
+
};
|
|
429
|
+
const disconnect = () => {
|
|
430
|
+
ws?.removeEventListener('close', onClose);
|
|
431
|
+
ws?.removeEventListener('error', onError);
|
|
432
|
+
ws?.removeEventListener('open', onOpen);
|
|
433
|
+
ws?.removeEventListener('message', onMessage);
|
|
434
|
+
ws?.close();
|
|
435
|
+
ws = undefined;
|
|
421
436
|
};
|
|
422
|
-
|
|
437
|
+
$effect(() => {
|
|
438
|
+
if (!backendIP || !websocketPort) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
connect(backendIP, websocketPort);
|
|
442
|
+
return () => {
|
|
443
|
+
disconnect();
|
|
444
|
+
};
|
|
445
|
+
});
|
|
423
446
|
setContext(key, {
|
|
424
447
|
get connectionStatus() {
|
|
425
448
|
return connectionStatus;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface DrawConnectionConfig {
|
|
2
|
+
backendIP: string;
|
|
3
|
+
websocketPort: string;
|
|
4
|
+
}
|
|
5
|
+
interface Context {
|
|
6
|
+
current: DrawConnectionConfig | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare const provideDrawConnectionConfig: (args: () => DrawConnectionConfig | undefined) => void;
|
|
9
|
+
export declare const useDrawConnectionConfig: () => Context;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
const key = Symbol('draw-connection-config-key');
|
|
3
|
+
export const provideDrawConnectionConfig = (args) => {
|
|
4
|
+
const current = $derived(args());
|
|
5
|
+
setContext(key, {
|
|
6
|
+
get current() {
|
|
7
|
+
return current;
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
export const useDrawConnectionConfig = () => {
|
|
12
|
+
return getContext(key);
|
|
13
|
+
};
|
|
@@ -18,7 +18,7 @@ export const provideFrames = (partID) => {
|
|
|
18
18
|
const machineStatus = useMachineStatus(partID);
|
|
19
19
|
const logs = useLogs();
|
|
20
20
|
const query = createRobotQuery(client, 'frameSystemConfig', () => ({
|
|
21
|
-
enabled: environment.current.viewerMode === 'monitor',
|
|
21
|
+
enabled: partID() !== '' && environment.current.viewerMode === 'monitor',
|
|
22
22
|
}));
|
|
23
23
|
const revision = $derived(machineStatus.current?.config?.revision);
|
|
24
24
|
const partConfig = usePartConfig();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viamrobotics/motion-tools",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Motion visualization with Viam",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
"@viamrobotics/svelte-sdk": "1.0.1",
|
|
40
40
|
"@vitejs/plugin-basic-ssl": "2.1.0",
|
|
41
41
|
"@vitest/coverage-v8": "^3.2.4",
|
|
42
|
+
"@zag-js/collapsible": "1.22.1",
|
|
43
|
+
"@zag-js/floating-panel": "1.22.1",
|
|
42
44
|
"@zag-js/svelte": "1.22.1",
|
|
43
45
|
"@zag-js/tree-view": "1.22.1",
|
|
44
46
|
"camera-controls": "3.1.0",
|
|
@@ -78,6 +80,8 @@
|
|
|
78
80
|
"@viamrobotics/prime-core": ">=0.1",
|
|
79
81
|
"@viamrobotics/sdk": ">=0.38",
|
|
80
82
|
"@viamrobotics/svelte-sdk": ">=0.1",
|
|
83
|
+
"@zag-js/collapsible": ">=1",
|
|
84
|
+
"@zag-js/floating-panel": ">=1",
|
|
81
85
|
"@zag-js/svelte": ">=1",
|
|
82
86
|
"@zag-js/tree-view": ">=1",
|
|
83
87
|
"camera-controls": ">=3",
|