@viamrobotics/motion-tools 0.5.4 → 0.5.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.
@@ -15,6 +15,22 @@ const tryParse = (json) => {
15
15
  return;
16
16
  }
17
17
  };
18
+ class Float32Reader {
19
+ littleEndian = true;
20
+ offset = 0;
21
+ buffer = new ArrayBuffer();
22
+ view = new DataView(this.buffer);
23
+ async init(data) {
24
+ this.buffer = await data.arrayBuffer();
25
+ this.view = new DataView(this.buffer);
26
+ return this;
27
+ }
28
+ read() {
29
+ const result = this.view.getFloat32(this.offset, this.littleEndian);
30
+ this.offset += 4;
31
+ return result;
32
+ }
33
+ }
18
34
  export const provideShapes = () => {
19
35
  let pointsIndex = 0;
20
36
  let geometryIndex = 0;
@@ -33,8 +49,7 @@ export const provideShapes = () => {
33
49
  const origin = new Vector3();
34
50
  const vec3 = new Vector3();
35
51
  const loader = new GLTFLoader();
36
- const addPCD = async (data) => {
37
- const buffer = await data.arrayBuffer();
52
+ const addPCD = async (buffer) => {
38
53
  const { positions, colors } = await parsePcdInWorker(new Uint8Array(buffer));
39
54
  points.push(new WorldObject(`points ${++pointsIndex}`, undefined, undefined, {
40
55
  case: 'points',
@@ -75,28 +90,20 @@ export const provideShapes = () => {
75
90
  nurbs.push(object);
76
91
  };
77
92
  const batchedArrow = new BatchedArrow();
78
- const addPoses = async (data) => {
79
- const buffer = await data.arrayBuffer();
80
- const view = new DataView(buffer);
81
- let offset = 0;
82
- function readFloat32() {
83
- const val = view.getFloat32(offset, true); // true = little-endian
84
- offset += 4;
85
- return val;
86
- }
93
+ const addPoses = async (reader) => {
87
94
  // Read counts
88
- const nPoints = readFloat32();
89
- const nColors = readFloat32();
90
- const arrowHeadAtPose = readFloat32();
95
+ const nPoints = reader.read();
96
+ const nColors = reader.read();
97
+ const arrowHeadAtPose = reader.read();
91
98
  // Read positions
92
99
  const nextPoses = new Float32Array(nPoints * 6);
93
100
  for (let i = 0; i < nPoints * 6; i++) {
94
- nextPoses[i] = readFloat32();
101
+ nextPoses[i] = reader.read();
95
102
  }
96
103
  // Read raw colors
97
104
  const colors = new Float32Array(nColors * 3);
98
105
  for (let i = 0; i < nColors * 3; i++) {
99
- colors[i] = readFloat32();
106
+ colors[i] = reader.read();
100
107
  }
101
108
  const length = 0.1;
102
109
  for (let i = 0, j = 0, l = nextPoses.length; i < l; i += 6, j += 3) {
@@ -119,38 +126,30 @@ export const provideShapes = () => {
119
126
  }));
120
127
  }
121
128
  };
122
- const addPoints = async (data) => {
123
- const buffer = await data.arrayBuffer();
124
- const view = new DataView(buffer);
125
- let offset = 0;
126
- function readFloat32() {
127
- const val = view.getFloat32(offset, true); // true = little-endian
128
- offset += 4;
129
- return val;
130
- }
129
+ const addPoints = async (reader) => {
131
130
  // Read label length
132
- const labelLen = readFloat32();
131
+ const labelLen = reader.read();
133
132
  let label = '';
134
133
  for (let i = 0; i < labelLen; i++) {
135
- label += String.fromCharCode(readFloat32());
134
+ label += String.fromCharCode(reader.read());
136
135
  }
137
136
  // Read counts
138
- const nPoints = readFloat32();
139
- const nColors = readFloat32();
137
+ const nPoints = reader.read();
138
+ const nColors = reader.read();
140
139
  // Read default color
141
- const r = readFloat32();
142
- const g = readFloat32();
143
- const b = readFloat32();
140
+ const r = reader.read();
141
+ const g = reader.read();
142
+ const b = reader.read();
144
143
  // Read positions
145
144
  const positions = new Float32Array(nPoints * 3);
146
145
  for (let i = 0; i < nPoints * 3; i++) {
147
- positions[i] = readFloat32();
146
+ positions[i] = reader.read();
148
147
  }
149
148
  const getColors = () => {
150
149
  // Read raw colors
151
150
  const rawColors = new Float32Array(nColors * 3);
152
151
  for (let i = 0; i < nColors * 3; i++) {
153
- rawColors[i] = readFloat32();
152
+ rawColors[i] = reader.read();
154
153
  }
155
154
  const colors = new Float32Array(nPoints * 3);
156
155
  colors.set(rawColors);
@@ -187,8 +186,7 @@ export const provideShapes = () => {
187
186
  i += 1;
188
187
  }
189
188
  };
190
- const addGLTF = async (data) => {
191
- const buffer = await data.arrayBuffer();
189
+ const addGLTF = async (buffer) => {
192
190
  const blob = new Blob([buffer], { type: 'model/gltf-binary' });
193
191
  const url = URL.createObjectURL(blob);
194
192
  const gltf = await loader.loadAsync(url);
@@ -240,15 +238,6 @@ export const provideShapes = () => {
240
238
  geometryIndex = 0;
241
239
  poseIndex = 0;
242
240
  };
243
- let metadata = undefined;
244
- const handleMetadata = (data) => {
245
- const json = tryParse(data);
246
- if ('type' in json) {
247
- metadata = json;
248
- return true;
249
- }
250
- return false;
251
- };
252
241
  const { BACKEND_IP, BUN_SERVER_PORT } = globalThis;
253
242
  const scheduleReconnect = () => {
254
243
  setTimeout(() => {
@@ -271,27 +260,21 @@ export const provideShapes = () => {
271
260
  console.log('Websocket error', JSON.stringify(event));
272
261
  ws.close();
273
262
  };
274
- const onMessage = (event) => {
275
- if (typeof event.data === 'string') {
276
- if (handleMetadata(event.data)) {
277
- return;
278
- }
279
- }
263
+ const onMessage = async (event) => {
280
264
  if (typeof event.data === 'object' && 'arrayBuffer' in event.data) {
281
- if (!metadata) {
282
- return console.error('metadata is undefined');
283
- }
284
- if (metadata.type === 'glb') {
285
- return addGLTF(event.data);
265
+ const reader = await new Float32Reader().init(event.data);
266
+ const type = reader.read();
267
+ if (type === 0) {
268
+ return addPoints(reader);
286
269
  }
287
- else if (metadata.type === 'pcd') {
288
- return addPCD(event.data);
270
+ else if (type === 1) {
271
+ return addPoses(reader);
289
272
  }
290
- else if (metadata.type === 'points') {
291
- return addPoints(event.data);
273
+ else if (type === 2) {
274
+ return addPCD(reader.buffer);
292
275
  }
293
- else if (metadata.type === 'poses') {
294
- return addPoses(event.data);
276
+ else {
277
+ return addGLTF(reader.buffer);
295
278
  }
296
279
  }
297
280
  const data = tryParse(event.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -11,8 +11,9 @@
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.29.0",
15
- "@playwright/test": "1.53.1",
14
+ "@eslint/js": "9.30.1",
15
+ "@playwright/test": "1.53.2",
16
+ "@sentry/sveltekit": "9.34.0",
16
17
  "@skeletonlabs/skeleton": "3.1.3",
17
18
  "@skeletonlabs/skeleton-svelte": "1.2.3",
18
19
  "@sveltejs/adapter-static": "3.0.8",
@@ -21,8 +22,8 @@
21
22
  "@sveltejs/vite-plugin-svelte": "5.1.0",
22
23
  "@tailwindcss/forms": "0.5.10",
23
24
  "@tailwindcss/vite": "4.1.11",
24
- "@tanstack/svelte-query": "5.81.2",
25
- "@tanstack/svelte-query-devtools": "5.81.2",
25
+ "@tanstack/svelte-query": "5.81.5",
26
+ "@tanstack/svelte-query-devtools": "5.81.5",
26
27
  "@testing-library/jest-dom": "6.6.3",
27
28
  "@testing-library/svelte": "5.2.8",
28
29
  "@threlte/core": "8.0.5",
@@ -31,25 +32,25 @@
31
32
  "@threlte/xr": "1.0.8",
32
33
  "@types/bun": "1.2.17",
33
34
  "@types/lodash-es": "4.17.12",
34
- "@types/three": "0.177.0",
35
- "@typescript-eslint/eslint-plugin": "8.35.0",
36
- "@typescript-eslint/parser": "8.35.0",
35
+ "@types/three": "0.178.0",
36
+ "@typescript-eslint/eslint-plugin": "8.35.1",
37
+ "@typescript-eslint/parser": "8.35.1",
37
38
  "@viamrobotics/prime-core": "0.1.5",
38
- "@viamrobotics/sdk": "0.44.0",
39
- "@viamrobotics/svelte-sdk": "0.4.0",
40
- "@vitejs/plugin-basic-ssl": "2.0.0",
41
- "@zag-js/svelte": "1.17.1",
42
- "@zag-js/tree-view": "1.17.1",
39
+ "@viamrobotics/sdk": "0.45.0",
40
+ "@viamrobotics/svelte-sdk": "0.4.1",
41
+ "@vitejs/plugin-basic-ssl": "2.1.0",
42
+ "@zag-js/svelte": "1.18.1",
43
+ "@zag-js/tree-view": "1.18.1",
43
44
  "camera-controls": "2.10.1",
44
- "eslint": "9.29.0",
45
+ "eslint": "9.30.1",
45
46
  "eslint-config-prettier": "10.1.5",
46
- "eslint-plugin-svelte": "3.10.0",
47
- "globals": "16.2.0",
47
+ "eslint-plugin-svelte": "3.10.1",
48
+ "globals": "16.3.0",
48
49
  "idb-keyval": "6.2.2",
49
50
  "jsdom": "26.1.0",
50
51
  "lodash-es": "4.17.21",
51
- "lucide-svelte": "0.523.0",
52
- "prettier": "3.6.1",
52
+ "lucide-svelte": "0.525.0",
53
+ "prettier": "3.6.2",
53
54
  "prettier-plugin-svelte": "3.4.0",
54
55
  "prettier-plugin-tailwindcss": "0.6.13",
55
56
  "publint": "0.3.12",
@@ -58,13 +59,13 @@
58
59
  "svelte-check": "4.2.2",
59
60
  "svelte-virtuallists": "1.4.2",
60
61
  "tailwindcss": "4.1.11",
61
- "three": "0.177.0",
62
+ "three": "0.178.0",
62
63
  "threlte-uikit": "1.2.0",
63
64
  "tsx": "4.20.3",
64
65
  "typescript": "5.8.3",
65
- "typescript-eslint": "8.35.0",
66
+ "typescript-eslint": "8.35.1",
66
67
  "vite": "6.3.5",
67
- "vite-plugin-devtools-json": "0.2.0",
68
+ "vite-plugin-devtools-json": "0.2.1",
68
69
  "vite-plugin-mkcert": "1.17.8",
69
70
  "vitest": "3.2.4"
70
71
  },