@viamrobotics/motion-tools 0.11.0 → 0.11.2
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,6 +1,4 @@
|
|
|
1
1
|
<script module>
|
|
2
|
-
import { Color, type Object3D } from 'three'
|
|
3
|
-
|
|
4
2
|
const colorUtil = new Color()
|
|
5
3
|
</script>
|
|
6
4
|
|
|
@@ -8,6 +6,7 @@
|
|
|
8
6
|
import type { Snippet } from 'svelte'
|
|
9
7
|
import type { WorldObject } from '../WorldObject.svelte'
|
|
10
8
|
import { useObjectEvents } from '../hooks/useObjectEvents.svelte'
|
|
9
|
+
import { Color, type Object3D } from 'three'
|
|
11
10
|
import Geometry from './Geometry.svelte'
|
|
12
11
|
import { useSelected } from '../hooks/useSelection.svelte'
|
|
13
12
|
import { colors, darkenColor } from '../color'
|
|
@@ -51,7 +51,7 @@ export const provideDrawAPI = () => {
|
|
|
51
51
|
const origin = new Vector3();
|
|
52
52
|
const vec3 = new Vector3();
|
|
53
53
|
const loader = new GLTFLoader();
|
|
54
|
-
const
|
|
54
|
+
const drawPCD = async (buffer) => {
|
|
55
55
|
const { positions, colors } = await parsePcdInWorker(new Uint8Array(buffer));
|
|
56
56
|
points.push(new WorldObject(`points ${++pointsIndex}`, undefined, undefined, {
|
|
57
57
|
case: 'points',
|
|
@@ -60,12 +60,12 @@ export const provideDrawAPI = () => {
|
|
|
60
60
|
};
|
|
61
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
62
|
const drawGeometry = (data, color, parent) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
existingMesh.pose = data.center;
|
|
63
|
+
const result = meshes.find((mesh) => mesh.name === data.label);
|
|
64
|
+
if (result) {
|
|
65
|
+
result.pose = data.center;
|
|
67
66
|
return;
|
|
68
67
|
}
|
|
68
|
+
let geometry;
|
|
69
69
|
if ('mesh' in data) {
|
|
70
70
|
geometry = {
|
|
71
71
|
case: 'mesh',
|
|
@@ -90,14 +90,18 @@ export const provideDrawAPI = () => {
|
|
|
90
90
|
meshes.push(object);
|
|
91
91
|
};
|
|
92
92
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
-
const
|
|
93
|
+
const drawNurbs = (data, color) => {
|
|
94
|
+
const index = nurbs.findIndex(({ name }) => name === data.name);
|
|
95
|
+
if (index !== -1) {
|
|
96
|
+
nurbs.splice(index, 1);
|
|
97
|
+
}
|
|
94
98
|
const controlPoints = data.ControlPts.map((point) => new Vector4(point.x / 1000, point.y / 1000, point.z / 1000));
|
|
95
99
|
const curve = new NURBSCurve(data.Degree, data.Knots, controlPoints);
|
|
96
100
|
const object = new WorldObject(data.name, data.pose, data.parent, { case: 'line', value: new Float32Array() }, { color, points: curve.getPoints(200) });
|
|
97
101
|
nurbs.push(object);
|
|
98
102
|
};
|
|
99
103
|
const batchedArrow = new BatchedArrow();
|
|
100
|
-
const
|
|
104
|
+
const drawPoses = async (reader) => {
|
|
101
105
|
// Read counts
|
|
102
106
|
const nPoints = reader.read();
|
|
103
107
|
const nColors = reader.read();
|
|
@@ -133,13 +137,17 @@ export const provideDrawAPI = () => {
|
|
|
133
137
|
}));
|
|
134
138
|
}
|
|
135
139
|
};
|
|
136
|
-
const
|
|
140
|
+
const drawPoints = async (reader) => {
|
|
137
141
|
// Read label length
|
|
138
142
|
const labelLen = reader.read();
|
|
139
143
|
let label = '';
|
|
140
144
|
for (let i = 0; i < labelLen; i++) {
|
|
141
145
|
label += String.fromCharCode(reader.read());
|
|
142
146
|
}
|
|
147
|
+
const index = points.findIndex(({ name }) => name === label);
|
|
148
|
+
if (index !== -1) {
|
|
149
|
+
points.splice(index, 1);
|
|
150
|
+
}
|
|
143
151
|
// Read counts
|
|
144
152
|
const nPoints = reader.read();
|
|
145
153
|
const nColors = reader.read();
|
|
@@ -184,13 +192,17 @@ export const provideDrawAPI = () => {
|
|
|
184
192
|
value: positions,
|
|
185
193
|
}, metadata));
|
|
186
194
|
};
|
|
187
|
-
const
|
|
195
|
+
const drawLine = async (reader) => {
|
|
188
196
|
// Read label length
|
|
189
197
|
const labelLen = reader.read();
|
|
190
198
|
let label = '';
|
|
191
199
|
for (let i = 0; i < labelLen; i++) {
|
|
192
200
|
label += String.fromCharCode(reader.read());
|
|
193
201
|
}
|
|
202
|
+
const index = lines.findIndex(({ name }) => name === label);
|
|
203
|
+
if (index !== -1) {
|
|
204
|
+
lines.splice(index, 1);
|
|
205
|
+
}
|
|
194
206
|
// Read counts
|
|
195
207
|
const nPoints = reader.read();
|
|
196
208
|
// Read default color
|
|
@@ -226,7 +238,7 @@ export const provideDrawAPI = () => {
|
|
|
226
238
|
i += 1;
|
|
227
239
|
}
|
|
228
240
|
};
|
|
229
|
-
const
|
|
241
|
+
const drawGLTF = async (buffer) => {
|
|
230
242
|
const blob = new Blob([buffer], { type: 'model/gltf-binary' });
|
|
231
243
|
const url = URL.createObjectURL(blob);
|
|
232
244
|
const gltf = await loader.loadAsync(url);
|
|
@@ -311,19 +323,19 @@ export const provideDrawAPI = () => {
|
|
|
311
323
|
const reader = await new Float32Reader().init(event.data);
|
|
312
324
|
const type = reader.read();
|
|
313
325
|
if (type === 0) {
|
|
314
|
-
return
|
|
326
|
+
return drawPoints(reader);
|
|
315
327
|
}
|
|
316
328
|
else if (type === 1) {
|
|
317
|
-
return
|
|
329
|
+
return drawPoses(reader);
|
|
318
330
|
}
|
|
319
331
|
else if (type === 2) {
|
|
320
|
-
return
|
|
332
|
+
return drawLine(reader);
|
|
321
333
|
}
|
|
322
334
|
else if (type === 3) {
|
|
323
|
-
return
|
|
335
|
+
return drawPCD(reader.buffer);
|
|
324
336
|
}
|
|
325
337
|
else {
|
|
326
|
-
return
|
|
338
|
+
return drawGLTF(reader.buffer);
|
|
327
339
|
}
|
|
328
340
|
}
|
|
329
341
|
const data = tryParse(event.data);
|
|
@@ -343,7 +355,7 @@ export const provideDrawAPI = () => {
|
|
|
343
355
|
return drawGeometry(data.geometry, data.color);
|
|
344
356
|
}
|
|
345
357
|
if ('Knots' in data) {
|
|
346
|
-
return
|
|
358
|
+
return drawNurbs(data, data.Color);
|
|
347
359
|
}
|
|
348
360
|
if ('remove' in data) {
|
|
349
361
|
return remove(data.names);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viamrobotics/motion-tools",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "Motion visualization with Viam",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"format": "prettier --write .",
|
|
124
124
|
"lint": "prettier --check . && eslint .",
|
|
125
125
|
"test:unit": "vitest",
|
|
126
|
-
"test:client": "go test
|
|
126
|
+
"test:client": "go test ./client/... -count=1",
|
|
127
127
|
"test": "pnpm test:unit -- --run",
|
|
128
128
|
"test:e2e": "playwright test",
|
|
129
129
|
"model-pipeline:run": "node scripts/model-pipeline.js",
|