@viamrobotics/motion-tools 0.14.8 → 0.14.10

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,13 +15,23 @@
15
15
  import Label from './Label.svelte'
16
16
  import WorldState from './WorldState.svelte'
17
17
  import { determinePose } from '../WorldObject.svelte'
18
-
18
+ import { useWeblabs } from '../hooks/useWeblabs.svelte'
19
+ import type { WorldObject } from '../WorldObject.svelte'
20
+ import type { Pose as ViamPose } from '@viamrobotics/sdk'
19
21
  const points = usePointClouds()
20
22
  const drawAPI = useDrawAPI()
21
23
  const frames = useFrames()
22
24
  const geometries = useGeometries()
23
25
  const worldStates = useWorldStates()
24
26
  const batchedArrow = useArrows()
27
+ const weblabs = useWeblabs()
28
+
29
+ const weblabedDeterminePose = (object: WorldObject, pose: ViamPose | undefined) => {
30
+ if (weblabs.isActive('MOTION_TOOLS_EDIT_FRAME')) {
31
+ return determinePose(object, pose)
32
+ }
33
+ return pose ?? object.pose
34
+ }
25
35
  </script>
26
36
 
27
37
  {#each frames.current as object (object.uuid)}
@@ -30,7 +40,7 @@
30
40
  parent={object.referenceFrame}
31
41
  >
32
42
  {#snippet children({ pose })}
33
- {@const framePose = determinePose(object, pose)}
43
+ {@const framePose = weblabedDeterminePose(object, pose)}
34
44
  <Portal id={object.referenceFrame}>
35
45
  <Frame
36
46
  uuid={object.uuid}
package/dist/transform.js CHANGED
@@ -3,6 +3,8 @@ import { Euler, MathUtils, Matrix4, Quaternion, Vector3 } from 'three';
3
3
  const quaternion = new Quaternion();
4
4
  const euler = new Euler();
5
5
  const ov = new OrientationVector();
6
+ const translation = new Vector3();
7
+ const scale = new Vector3();
6
8
  export const createPose = (pose) => {
7
9
  return {
8
10
  x: pose?.x ?? 0,
@@ -90,32 +92,23 @@ export const scaleToDimensions = (scale, geometry) => {
90
92
  }
91
93
  };
92
94
  export const poseToMatrix = (pose) => {
95
+ ov.set(pose.oX, pose.oY, pose.oZ, MathUtils.degToRad(pose.theta));
96
+ ov.toQuaternion(quaternion);
93
97
  const matrix = new Matrix4();
94
- const poseQuaternion = new Quaternion().setFromAxisAngle(new Vector3(pose.oX, pose.oY, pose.oZ), pose.theta * (Math.PI / 180));
95
- matrix.makeRotationFromQuaternion(poseQuaternion);
96
- matrix.setPosition(new Vector3(pose.x, pose.y, pose.z));
98
+ matrix.makeRotationFromQuaternion(quaternion);
99
+ matrix.setPosition(pose.x, pose.y, pose.z);
97
100
  return matrix;
98
101
  };
99
102
  export const matrixToPose = (matrix) => {
100
103
  const pose = createPose();
101
- const translation = new Vector3();
102
- const quaternion = new Quaternion();
103
- matrix.decompose(translation, quaternion, new Vector3());
104
+ matrix.decompose(translation, quaternion, scale);
104
105
  pose.x = translation.x;
105
106
  pose.y = translation.y;
106
107
  pose.z = translation.z;
107
- const s = Math.sqrt(1 - quaternion.w * quaternion.w);
108
- if (s < 0.000001) {
109
- pose.oX = 0;
110
- pose.oY = 0;
111
- pose.oZ = 1;
112
- pose.theta = 0;
113
- }
114
- else {
115
- pose.oX = quaternion.x / s;
116
- pose.oY = quaternion.y / s;
117
- pose.oZ = quaternion.z / s;
118
- pose.theta = Math.acos(quaternion.w) * 2 * (180 / Math.PI);
119
- }
108
+ ov.setFromQuaternion(quaternion);
109
+ pose.oX = ov.x;
110
+ pose.oY = ov.y;
111
+ pose.oZ = ov.z;
112
+ pose.theta = MathUtils.radToDeg(ov.th);
120
113
  return pose;
121
114
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "0.14.8",
3
+ "version": "0.14.10",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",