@viamrobotics/motion-tools 0.16.0 → 0.16.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.
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
lang="ts"
|
|
4
4
|
>
|
|
5
5
|
import { OrientationVector } from '../three/OrientationVector'
|
|
6
|
-
import { Quaternion, Vector3 } from 'three'
|
|
6
|
+
import { Quaternion, Vector3, MathUtils } from 'three'
|
|
7
7
|
|
|
8
8
|
const vec3 = new Vector3()
|
|
9
9
|
const quaternion = new Quaternion()
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
import { useWeblabs } from '../hooks/useWeblabs.svelte'
|
|
30
30
|
import { WEBLABS_EXPERIMENTS } from '../hooks/useWeblabs.svelte'
|
|
31
31
|
import { useEnvironment } from '../hooks/useEnvironment.svelte'
|
|
32
|
+
|
|
32
33
|
const { ...rest } = $props()
|
|
33
34
|
|
|
34
35
|
const focused = useFocused()
|
|
@@ -265,19 +266,20 @@
|
|
|
265
266
|
{#if worldPosition}
|
|
266
267
|
<div>
|
|
267
268
|
<strong class="font-semibold">world position</strong>
|
|
269
|
+
<span class="text-subtle-2">(m)</span>
|
|
268
270
|
|
|
269
271
|
<div class="flex gap-3">
|
|
270
272
|
<div>
|
|
271
273
|
<span class="text-subtle-2">x</span>
|
|
272
|
-
{
|
|
274
|
+
{worldPosition.x.toFixed(2)}
|
|
273
275
|
</div>
|
|
274
276
|
<div>
|
|
275
277
|
<span class="text-subtle-2">y</span>
|
|
276
|
-
{
|
|
278
|
+
{worldPosition.y.toFixed(2)}
|
|
277
279
|
</div>
|
|
278
280
|
<div>
|
|
279
281
|
<span class="text-subtle-2">z</span>
|
|
280
|
-
{
|
|
282
|
+
{worldPosition.z.toFixed(2)}
|
|
281
283
|
</div>
|
|
282
284
|
</div>
|
|
283
285
|
</div>
|
|
@@ -286,6 +288,7 @@
|
|
|
286
288
|
{#if worldOrientation}
|
|
287
289
|
<div>
|
|
288
290
|
<strong class="font-semibold">world orientation</strong>
|
|
291
|
+
<span class="text-subtle-2">(deg)</span>
|
|
289
292
|
<div class="flex gap-3">
|
|
290
293
|
<div>
|
|
291
294
|
<span class="text-subtle-2">x</span>
|
|
@@ -301,7 +304,7 @@
|
|
|
301
304
|
</div>
|
|
302
305
|
<div>
|
|
303
306
|
<span class="text-subtle-2">th</span>
|
|
304
|
-
{worldOrientation.th.toFixed(2)}
|
|
307
|
+
{MathUtils.radToDeg(worldOrientation.th).toFixed(2)}
|
|
305
308
|
</div>
|
|
306
309
|
</div>
|
|
307
310
|
</div>
|
|
@@ -326,6 +329,7 @@
|
|
|
326
329
|
{@const PoseAttribute = showEditFrameOptions ? MutableField : ImmutableField}
|
|
327
330
|
<div>
|
|
328
331
|
<strong class="font-semibold">local position</strong>
|
|
332
|
+
<span class="text-subtle-2">(m)</span>
|
|
329
333
|
|
|
330
334
|
<div class="flex gap-3">
|
|
331
335
|
{@render PoseAttribute({
|
|
@@ -354,6 +358,7 @@
|
|
|
354
358
|
|
|
355
359
|
<div>
|
|
356
360
|
<strong class="font-semibold">local orientation</strong>
|
|
361
|
+
<span class="text-subtle-2">(deg)</span>
|
|
357
362
|
<div class="flex {showEditFrameOptions ? 'gap-2' : 'gap-3'}">
|
|
358
363
|
{@render PoseAttribute({
|
|
359
364
|
label: 'x',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte';
|
|
2
|
-
import { Color, Vector3, Vector4 } from 'three';
|
|
2
|
+
import { Color, MathUtils, Quaternion, Vector3, Vector4 } from 'three';
|
|
3
3
|
import { NURBSCurve } from 'three/addons/curves/NURBSCurve.js';
|
|
4
4
|
import { parsePcdInWorker } from '../loaders/pcd';
|
|
5
5
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
@@ -8,6 +8,11 @@ import { useArrows } from './useArrows.svelte';
|
|
|
8
8
|
import { createGeometry } from '../geometry';
|
|
9
9
|
import { createPose, createPoseFromFrame } from '../transform';
|
|
10
10
|
import { useCameraControls } from './useControls.svelte';
|
|
11
|
+
import { useThrelte } from '@threlte/core';
|
|
12
|
+
import { OrientationVector } from '../three/OrientationVector';
|
|
13
|
+
const axis = new Vector3();
|
|
14
|
+
const quaternion = new Quaternion();
|
|
15
|
+
const ov = new OrientationVector();
|
|
11
16
|
const key = Symbol('draw-api-context-key');
|
|
12
17
|
const tryParse = (json) => {
|
|
13
18
|
try {
|
|
@@ -51,6 +56,7 @@ class Float32Reader {
|
|
|
51
56
|
}
|
|
52
57
|
export const provideDrawAPI = () => {
|
|
53
58
|
const cameraControls = useCameraControls();
|
|
59
|
+
const { invalidate } = useThrelte();
|
|
54
60
|
let pointsIndex = 0;
|
|
55
61
|
let geometryIndex = 0;
|
|
56
62
|
let poseIndex = 0;
|
|
@@ -167,7 +173,27 @@ export const provideDrawAPI = () => {
|
|
|
167
173
|
direction.set(nextPoses[i + 3], nextPoses[i + 4], nextPoses[i + 5]);
|
|
168
174
|
color.set(colors[j], colors[j + 1], colors[j + 2]);
|
|
169
175
|
const arrowId = batchedArrow.addArrow(direction, origin, length, color, arrowHeadAtPose === 1);
|
|
170
|
-
|
|
176
|
+
const pose = createPose();
|
|
177
|
+
pose.x = origin.x;
|
|
178
|
+
pose.y = origin.y;
|
|
179
|
+
pose.z = origin.z;
|
|
180
|
+
if (direction.y > 0.99999) {
|
|
181
|
+
quaternion.set(0, 0, 0, 1);
|
|
182
|
+
}
|
|
183
|
+
else if (direction.y < -0.99999) {
|
|
184
|
+
quaternion.set(1, 0, 0, 0);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
axis.set(direction.z, 0, -direction.x).normalize();
|
|
188
|
+
const radians = Math.acos(direction.y);
|
|
189
|
+
quaternion.setFromAxisAngle(axis, radians);
|
|
190
|
+
}
|
|
191
|
+
ov.setFromQuaternion(quaternion);
|
|
192
|
+
pose.oX = ov.x;
|
|
193
|
+
pose.oY = ov.y;
|
|
194
|
+
pose.oZ = ov.z;
|
|
195
|
+
pose.theta = MathUtils.radToDeg(ov.th);
|
|
196
|
+
poses.push(new WorldObject(`pose ${++poseIndex}`, pose, 'world', undefined, {
|
|
171
197
|
getBoundingBoxAt(box3) {
|
|
172
198
|
return batchedArrow.getBoundingBoxAt(arrowId, box3);
|
|
173
199
|
},
|
|
@@ -177,6 +203,7 @@ export const provideDrawAPI = () => {
|
|
|
177
203
|
},
|
|
178
204
|
}));
|
|
179
205
|
}
|
|
206
|
+
invalidate();
|
|
180
207
|
};
|
|
181
208
|
const drawPoints = async (reader) => {
|
|
182
209
|
// Read label length
|