@viamrobotics/motion-tools 0.19.2 → 1.0.3

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.
Files changed (150) hide show
  1. package/README.md +56 -26
  2. package/dist/FrameConfigUpdater.svelte.d.ts +11 -17
  3. package/dist/FrameConfigUpdater.svelte.js +109 -109
  4. package/dist/WorldObject.svelte.js +2 -15
  5. package/dist/common/v1/common_pb.d.ts +950 -0
  6. package/dist/common/v1/common_pb.js +1399 -0
  7. package/dist/components/App.svelte +38 -22
  8. package/dist/components/App.svelte.d.ts +1 -0
  9. package/dist/components/BatchedArrows.svelte +102 -0
  10. package/dist/components/BatchedArrows.svelte.d.ts +3 -0
  11. package/dist/components/CameraControls.svelte +2 -3
  12. package/dist/components/Details.svelte +364 -365
  13. package/dist/components/Entities.svelte +80 -0
  14. package/dist/components/{WorldObjects.svelte.d.ts → Entities.svelte.d.ts} +3 -3
  15. package/dist/components/FileDrop/FileDrop.svelte +96 -0
  16. package/dist/components/FileDrop/FileDrop.svelte.d.ts +4 -0
  17. package/dist/components/FileDrop/file-dropper.d.ts +36 -0
  18. package/dist/components/FileDrop/file-dropper.js +6 -0
  19. package/dist/components/FileDrop/file-names.d.ts +27 -0
  20. package/dist/components/FileDrop/file-names.js +85 -0
  21. package/dist/components/FileDrop/pcd-dropper.d.ts +2 -0
  22. package/dist/components/FileDrop/pcd-dropper.js +27 -0
  23. package/dist/components/FileDrop/ply-dropper.d.ts +2 -0
  24. package/dist/components/FileDrop/ply-dropper.js +27 -0
  25. package/dist/components/FileDrop/snapshot-dropper.d.ts +2 -0
  26. package/dist/components/FileDrop/snapshot-dropper.js +96 -0
  27. package/dist/components/FileDrop/useFileDrop.svelte.d.ts +9 -0
  28. package/dist/components/FileDrop/useFileDrop.svelte.js +97 -0
  29. package/dist/components/Focus.svelte +2 -3
  30. package/dist/components/Frame.svelte +41 -22
  31. package/dist/components/Frame.svelte.d.ts +4 -6
  32. package/dist/components/GLTF.svelte +36 -0
  33. package/dist/components/GLTF.svelte.d.ts +11 -0
  34. package/dist/components/Geometry2.svelte +206 -0
  35. package/dist/components/Geometry2.svelte.d.ts +18 -0
  36. package/dist/components/KeyboardControls.svelte +3 -3
  37. package/dist/components/Line.svelte +15 -14
  38. package/dist/components/Line.svelte.d.ts +2 -2
  39. package/dist/components/LiveUpdatesBanner.svelte +51 -15
  40. package/dist/components/MeasureTool.svelte +4 -5
  41. package/dist/components/Pointcloud.svelte +27 -14
  42. package/dist/components/Pointcloud.svelte.d.ts +2 -2
  43. package/dist/components/PointerMissBox.svelte +3 -3
  44. package/dist/components/Pose.svelte +31 -6
  45. package/dist/components/Pose.svelte.d.ts +2 -2
  46. package/dist/components/Scene.svelte +7 -6
  47. package/dist/components/SceneProviders.svelte +0 -6
  48. package/dist/components/Selected.svelte +22 -16
  49. package/dist/components/StaticGeometries.svelte +51 -27
  50. package/dist/components/Tree/Tree.svelte +51 -38
  51. package/dist/components/Tree/Tree.svelte.d.ts +3 -4
  52. package/dist/components/Tree/TreeContainer.svelte +75 -40
  53. package/dist/components/Tree/Widgets.svelte +2 -5
  54. package/dist/components/Tree/buildTree.d.ts +7 -6
  55. package/dist/components/Tree/buildTree.js +22 -41
  56. package/dist/components/__tests__/__fixtures__/entity.d.ts +2 -0
  57. package/dist/components/__tests__/__fixtures__/entity.js +20 -0
  58. package/dist/components/__tests__/__fixtures__/resource.d.ts +17 -0
  59. package/dist/components/__tests__/__fixtures__/resource.js +13 -0
  60. package/dist/components/dashboard/Dashboard.svelte +5 -3
  61. package/dist/components/dashboard/Dashboard.svelte.d.ts +7 -2
  62. package/dist/components/widgets/ArmPositions.svelte +19 -7
  63. package/dist/draw/v1/drawing_pb.d.ts +341 -0
  64. package/dist/draw/v1/drawing_pb.js +417 -0
  65. package/dist/draw/v1/metadata_pb.d.ts +23 -0
  66. package/dist/draw/v1/metadata_pb.js +39 -0
  67. package/dist/draw/v1/scene_pb.d.ts +230 -0
  68. package/dist/draw/v1/scene_pb.js +298 -0
  69. package/dist/draw/v1/snapshot_pb.d.ts +42 -0
  70. package/dist/draw/v1/snapshot_pb.js +61 -0
  71. package/dist/draw/v1/transforms_pb.d.ts +23 -0
  72. package/dist/draw/v1/transforms_pb.js +39 -0
  73. package/dist/ecs/index.d.ts +4 -0
  74. package/dist/ecs/index.js +4 -0
  75. package/dist/ecs/traits.d.ts +132 -0
  76. package/dist/ecs/traits.js +85 -0
  77. package/dist/ecs/useQuery.svelte.d.ts +4 -0
  78. package/dist/ecs/useQuery.svelte.js +49 -0
  79. package/dist/ecs/useTrait.svelte.d.ts +19 -0
  80. package/dist/ecs/useTrait.svelte.js +40 -0
  81. package/dist/ecs/useWorld.d.ts +4 -0
  82. package/dist/ecs/useWorld.js +10 -0
  83. package/dist/geometry.js +6 -6
  84. package/dist/hooks/__tests__/fixtures/ResizableTestWrapper.svelte +41 -0
  85. package/dist/hooks/__tests__/fixtures/ResizableTestWrapper.svelte.d.ts +6 -0
  86. package/dist/hooks/use3DModels.svelte.js +6 -4
  87. package/dist/hooks/useDrawAPI.svelte.d.ts +0 -10
  88. package/dist/hooks/useDrawAPI.svelte.js +143 -267
  89. package/dist/hooks/useFramelessComponents.svelte.js +1 -1
  90. package/dist/hooks/useFrames.svelte.d.ts +6 -2
  91. package/dist/hooks/useFrames.svelte.js +123 -19
  92. package/dist/hooks/useGeometries.svelte.d.ts +0 -2
  93. package/dist/hooks/useGeometries.svelte.js +49 -25
  94. package/dist/hooks/useObjectEvents.svelte.d.ts +3 -2
  95. package/dist/hooks/useObjectEvents.svelte.js +11 -7
  96. package/dist/hooks/usePartConfig.svelte.d.ts +1 -1
  97. package/dist/hooks/usePartConfig.svelte.js +2 -1
  98. package/dist/hooks/usePointclouds.svelte.d.ts +0 -2
  99. package/dist/hooks/usePointclouds.svelte.js +52 -21
  100. package/dist/hooks/usePose.svelte.js +15 -7
  101. package/dist/hooks/useResizable.svelte.d.ts +12 -0
  102. package/dist/hooks/useResizable.svelte.js +45 -0
  103. package/dist/hooks/useResourceByName.svelte.js +8 -5
  104. package/dist/hooks/useSelection.svelte.d.ts +13 -23
  105. package/dist/hooks/useSelection.svelte.js +45 -65
  106. package/dist/hooks/useVisibility.svelte.d.ts +2 -1
  107. package/dist/hooks/useWeblabs.svelte.d.ts +0 -1
  108. package/dist/hooks/useWeblabs.svelte.js +0 -1
  109. package/dist/hooks/useWorldState.svelte.d.ts +9 -0
  110. package/dist/hooks/useWorldState.svelte.js +158 -107
  111. package/dist/lib.d.ts +1 -0
  112. package/dist/lib.js +2 -0
  113. package/dist/three/BatchedArrow.d.ts +2 -3
  114. package/dist/three/BatchedArrow.js +3 -11
  115. package/dist/three/CapsuleGeometry.d.ts +1 -1
  116. package/dist/three/CapsuleGeometry.js +3 -1
  117. package/dist/transform.js +0 -15
  118. package/package.json +13 -7
  119. package/dist/components/FileDrop.svelte +0 -158
  120. package/dist/components/FileDrop.svelte.d.ts +0 -3
  121. package/dist/components/WorldObject.svelte +0 -28
  122. package/dist/components/WorldObject.svelte.d.ts +0 -11
  123. package/dist/components/WorldObjects.svelte +0 -159
  124. package/dist/components/WorldState.svelte +0 -92
  125. package/dist/components/WorldState.svelte.d.ts +0 -7
  126. package/dist/components/__tests__/__fixtures__/worldObject.svelte.d.ts +0 -2
  127. package/dist/components/__tests__/__fixtures__/worldObject.svelte.js +0 -35
  128. package/dist/components/portal/Portal.svelte +0 -25
  129. package/dist/components/portal/Portal.svelte.d.ts +0 -8
  130. package/dist/components/portal/PortalTarget.svelte +0 -18
  131. package/dist/components/portal/PortalTarget.svelte.d.ts +0 -6
  132. package/dist/components/portal/index.d.ts +0 -2
  133. package/dist/components/portal/index.js +0 -2
  134. package/dist/components/portal/usePortalContext.svelte.d.ts +0 -5
  135. package/dist/components/portal/usePortalContext.svelte.js +0 -5
  136. package/dist/hooks/useArrows.svelte.d.ts +0 -3
  137. package/dist/hooks/useArrows.svelte.js +0 -9
  138. package/dist/hooks/useDraggable.svelte.d.ts +0 -10
  139. package/dist/hooks/useDraggable.svelte.js +0 -36
  140. package/dist/hooks/useObjects.svelte.d.ts +0 -7
  141. package/dist/hooks/useObjects.svelte.js +0 -35
  142. package/dist/hooks/usePersistentUUIDs.svelte.d.ts +0 -5
  143. package/dist/hooks/usePersistentUUIDs.svelte.js +0 -13
  144. package/dist/hooks/useResourceByName.svelte.d.ts +0 -7
  145. package/dist/hooks/useStaticGeometries.svelte.d.ts +0 -9
  146. package/dist/hooks/useStaticGeometries.svelte.js +0 -47
  147. package/dist/workers/worldStateWorker.d.ts +0 -1
  148. package/dist/workers/worldStateWorker.js +0 -114
  149. package/dist/world-state-messages.d.ts +0 -23
  150. package/dist/world-state-messages.js +0 -1
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
- ## motion-tools
1
+ # motion-tools
2
2
 
3
3
  `motion-tools` aims to provide a visualization interface for any spatial information using Viam's APIs. This typically means motion-related monitoring, testing, and debugging.
4
4
 
5
- ### Getting started
5
+ ## Getting started
6
6
 
7
- #### Quick Setup (Recommended)
7
+ To run the app, you will need to set your project up by installing the app dependencies and ensuring you can connect
8
+ to your machines if required.
9
+
10
+ ### Project setup
8
11
 
9
12
  The easiest way to get started is using our automated setup script:
10
13
 
@@ -20,34 +23,15 @@ This single command will:
20
23
  4. Install **bun** runtime
21
24
  5. Install all project dependencies
22
25
 
23
- After setup completes, start the development server:
24
-
25
- ```bash
26
- make up
27
- ```
28
-
29
- #### Manual Setup
26
+ #### Manual setup
30
27
 
31
- If you prefer to install dependencies manually:
28
+ If the above does not work for you, or if you prefer to install dependencies manually:
32
29
 
33
30
  1. [Install nvm](https://github.com/nvm-sh/nvm#installing-and-updating)
34
31
  2. Install Node.js LTS: `nvm install --lts && nvm use --lts`
35
32
  3. [Install pnpm](https://pnpm.io/installation)
36
33
  4. [Install bun](https://bun.sh/docs/installation)
37
34
  5. Install dependencies: `pnpm i`
38
- 6. Run local app server: `pnpm dev`
39
-
40
- #### Available Make Commands
41
-
42
- - `make setup` - Complete development environment setup
43
- - `make up` - Start the development server
44
- - `make help` - Show available commands
45
-
46
- ### Running the visualizer
47
-
48
- To visit the visualizer, go to `http://localhost:5173/`
49
-
50
- Open the machine config page (bottom right) and enter in connection details to visualize a specific machine. You can also add machine configs from an env file (see below).
51
35
 
52
36
  ### Env files for machine configs
53
37
 
@@ -67,13 +51,59 @@ VITE_CONFIGS='
67
51
  '
68
52
  ```
69
53
 
70
- ### Executing drawing commands
54
+ ### Running the app locally
55
+
56
+ After setup completes, you can start a local app server with:
57
+
58
+ ```bash
59
+ make up
60
+ ```
61
+
62
+ This starts the app as a static site. The build part of the process will only run if you have not built the app yet as a part of `make up`, or your build is out of date.
63
+
64
+ #### Running multiple apps
65
+
66
+ If you want to be able to run multiple versions of the app, you can configure how the servers run. The `make up` command can accept two options:
67
+
68
+ 1. `STATIC_PORT` is the port for the static file server, and defaults to `5173`
69
+ 2. `WS_PORT` is the port for the websocket server used to communicate with the draw client API
70
+
71
+ > [!NOTE]
72
+ > The `WS_PORT` is not fully configurable at the moment, so passing it will only affect where the frontend listens for the websocket server, but calls with the draw client API are currently hardcoded to point to `"http://localhost:3000/"`. If this is a feature you require, please submit a request to the viz team!
73
+
74
+ To run two apps using the same web socket server, run:
75
+
76
+ ```
77
+ # in one terminal
78
+ make up
79
+
80
+ # in another terminal
81
+ make up STATIC_PORT=5174
82
+ ```
83
+
84
+ The apps should be available on `http://localhost:5173/` and `http://localhost:5174/`, and calls to the draw client API should render in both.
85
+
86
+ ### Local development
87
+
88
+ If you are contributing to `motion-tools`, you should just run the development web server with:
89
+
90
+ ```
91
+ pnpm dev
92
+ ```
93
+
94
+ ## Running the visualizer
95
+
96
+ To visit the visualizer, go to `http://localhost:5173/`
97
+
98
+ Open the machine config page (bottom right) and enter in connection details to visualize a specific machine. You can also add machine configs from an env file (see below).
99
+
100
+ ## Executing drawing commands
71
101
 
72
102
  The visualizer includes a golang package that allows executing commands to the visualizer.
73
103
 
74
104
  The list of available commands [can be found here](https://pkg.go.dev/github.com/viam-labs/motion-tools@v0.9.0/client/client).
75
105
 
76
- ### Programmatic camera control
106
+ ## Programmatic camera control
77
107
 
78
108
  It is possible to programmatically move the viewer camera and even modify the camera settings during runtime.
79
109
 
@@ -1,7 +1,7 @@
1
- import type { Frame } from './frame';
2
- import type { WorldObject } from './lib';
3
- import type { Geometries } from './WorldObject.svelte';
1
+ import type { Entity } from 'koota';
4
2
  import type { Pose } from '@viamrobotics/sdk';
3
+ import type { Frame } from './frame';
4
+ import type { Vector3Like } from 'three';
5
5
  type UpdateFrameCallback = {
6
6
  (componentName: string, referenceFrame: string, pose: Pose, geometry?: Frame['geometry']): void;
7
7
  };
@@ -9,26 +9,20 @@ type RemoveFrameCallback = {
9
9
  (componentName: string): void;
10
10
  };
11
11
  export declare class FrameConfigUpdater {
12
- private object;
13
- private referenceFrame;
14
12
  private updateFrame;
15
13
  private removeFrame;
16
- constructor(object: () => WorldObject<Geometries> | undefined, updateFrame: UpdateFrameCallback, removeFrame: RemoveFrameCallback, referenceFrame: () => string);
17
- updateLocalPosition: ({ x, y, z }: {
18
- x?: number;
19
- y?: number;
20
- z?: number;
21
- }) => void;
22
- updateLocalOrientation: ({ oX, oY, oZ, theta, }: {
14
+ constructor(updateFrame: UpdateFrameCallback, removeFrame: RemoveFrameCallback);
15
+ updateLocalPosition: (entity: Entity, position: Partial<Vector3Like>) => void;
16
+ updateLocalOrientation: (entity: Entity, orientation: {
23
17
  oX?: number;
24
18
  oY?: number;
25
19
  oZ?: number;
26
20
  theta?: number;
27
21
  }) => void;
28
- updateGeometry: (geometry: Partial<Frame["geometry"]>) => void;
29
- setFrameParent: (parentName: string) => void;
30
- deleteFrame: () => void;
31
- setGeometryType: (type: "none" | "box" | "sphere" | "capsule") => void;
32
- private sanatizeFloatValue;
22
+ updateGeometry: (entity: Entity, geometry: Partial<Frame["geometry"]>) => void;
23
+ setFrameParent: (entity: Entity, parentName: string) => void;
24
+ deleteFrame: (entity: Entity) => void;
25
+ setGeometryType: (entity: Entity, type: "none" | "box" | "sphere" | "capsule") => void;
26
+ private sanitizeFloatValue;
33
27
  }
34
28
  export {};
@@ -1,147 +1,147 @@
1
- import { createPose } from './transform';
1
+ import { traits } from './ecs';
2
2
  export class FrameConfigUpdater {
3
- object;
4
- referenceFrame;
5
3
  updateFrame;
6
4
  removeFrame;
7
- constructor(object, updateFrame, removeFrame, referenceFrame) {
8
- this.referenceFrame = referenceFrame;
9
- this.object = object;
5
+ constructor(updateFrame, removeFrame) {
10
6
  this.updateFrame = updateFrame;
11
7
  this.removeFrame = removeFrame;
12
8
  }
13
- updateLocalPosition = ({ x, y, z }) => {
14
- const object = this.object();
15
- if (!object)
16
- return;
17
- x = this.sanatizeFloatValue(x);
18
- y = this.sanatizeFloatValue(y);
19
- z = this.sanatizeFloatValue(z);
9
+ updateLocalPosition = (entity, position) => {
10
+ const x = this.sanitizeFloatValue(position.x);
11
+ const y = this.sanitizeFloatValue(position.y);
12
+ const z = this.sanitizeFloatValue(position.z);
20
13
  if (x === undefined && y === undefined && z === undefined)
21
14
  return;
22
- object.localEditedPose.x = x ?? object.localEditedPose.x;
23
- object.localEditedPose.y = y ?? object.localEditedPose.y;
24
- object.localEditedPose.z = z ?? object.localEditedPose.z;
25
- this.updateFrame(object.name ?? '', this.referenceFrame(), {
26
- x: x ?? object.localEditedPose.x,
27
- y: y ?? object.localEditedPose.y,
28
- z: z ?? object.localEditedPose.z,
29
- oX: object.localEditedPose.oX,
30
- oY: object.localEditedPose.oY,
31
- oZ: object.localEditedPose.oZ,
32
- theta: object.localEditedPose.theta,
33
- });
15
+ const change = {};
16
+ if (x !== undefined)
17
+ change.x = x;
18
+ if (y !== undefined)
19
+ change.y = y;
20
+ if (z !== undefined)
21
+ change.z = z;
22
+ entity.set(traits.EditedPose, change);
23
+ const name = entity.get(traits.Name);
24
+ const parent = entity.get(traits.Parent) ?? 'world';
25
+ const updatedPose = entity.get(traits.EditedPose);
26
+ if (name && updatedPose) {
27
+ this.updateFrame(name, parent, updatedPose);
28
+ }
34
29
  };
35
- updateLocalOrientation = ({ oX, oY, oZ, theta, }) => {
36
- const object = this.object();
37
- if (!object)
38
- return;
39
- oX = this.sanatizeFloatValue(oX);
40
- oY = this.sanatizeFloatValue(oY);
41
- oZ = this.sanatizeFloatValue(oZ);
42
- theta = this.sanatizeFloatValue(theta);
43
- if (oX === undefined && oY === undefined && oZ === undefined && theta === undefined)
30
+ updateLocalOrientation = (entity, orientation) => {
31
+ const oX = this.sanitizeFloatValue(orientation.oX);
32
+ const oY = this.sanitizeFloatValue(orientation.oY);
33
+ const oZ = this.sanitizeFloatValue(orientation.oZ);
34
+ const theta = this.sanitizeFloatValue(orientation.theta);
35
+ if (oX === undefined && oY === undefined && oZ === undefined && theta === undefined) {
44
36
  return;
45
- object.localEditedPose.oX = oX ?? object.localEditedPose.oX;
46
- object.localEditedPose.oY = oY ?? object.localEditedPose.oY;
47
- object.localEditedPose.oZ = oZ ?? object.localEditedPose.oZ;
48
- object.localEditedPose.theta = theta ?? object.localEditedPose.theta;
49
- this.updateFrame(object.name ?? '', this.referenceFrame(), {
50
- oX: oX ?? object.localEditedPose.oX,
51
- oY: oY ?? object.localEditedPose.oY,
52
- oZ: oZ ?? object.localEditedPose.oZ,
53
- theta: theta ?? object.localEditedPose.theta,
54
- x: object.localEditedPose.x,
55
- y: object.localEditedPose.y,
56
- z: object.localEditedPose.z,
57
- });
37
+ }
38
+ const change = {};
39
+ if (oX !== undefined)
40
+ change.oX = oX;
41
+ if (oY !== undefined)
42
+ change.oY = oY;
43
+ if (oZ !== undefined)
44
+ change.oZ = oZ;
45
+ if (theta !== undefined)
46
+ change.theta = theta;
47
+ entity.set(traits.EditedPose, change);
48
+ const name = entity.get(traits.Name);
49
+ const parent = entity.get(traits.Parent) ?? 'world';
50
+ const updatedPose = entity.get(traits.EditedPose);
51
+ if (name && updatedPose) {
52
+ this.updateFrame(name, parent, updatedPose);
53
+ }
58
54
  };
59
- updateGeometry = (geometry) => {
60
- const object = this.object();
61
- if (!object)
62
- return;
63
- let geometryObject;
55
+ updateGeometry = (entity, geometry) => {
56
+ const name = entity.get(traits.Name);
57
+ const parent = entity.get(traits.Parent) ?? 'world';
58
+ const pose = entity.get(traits.EditedPose);
64
59
  if (geometry?.type === 'box') {
65
- const currentGeometry = object.geometry?.geometryType.value;
66
- geometry.x = this.sanatizeFloatValue(geometry.x);
67
- geometry.y = this.sanatizeFloatValue(geometry.y);
68
- geometry.z = this.sanatizeFloatValue(geometry.z);
69
- if (geometry.x === undefined && geometry.y === undefined && geometry.z === undefined)
60
+ const x = this.sanitizeFloatValue(geometry.x);
61
+ const y = this.sanitizeFloatValue(geometry.y);
62
+ const z = this.sanitizeFloatValue(geometry.z);
63
+ if (x === undefined && y === undefined && z === undefined)
70
64
  return;
71
- geometryObject = {
72
- type: 'box',
73
- x: geometry.x ?? currentGeometry?.dimsMm?.x,
74
- y: geometry.y ?? currentGeometry?.dimsMm?.y,
75
- z: geometry.z ?? currentGeometry?.dimsMm?.z,
76
- };
65
+ const change = {};
66
+ if (x !== undefined)
67
+ change.x = x;
68
+ if (y !== undefined)
69
+ change.y = y;
70
+ if (z !== undefined)
71
+ change.z = z;
72
+ entity.set(traits.Box, change);
73
+ const box = entity.get(traits.Box);
74
+ if (name && box && pose) {
75
+ this.updateFrame(name, parent, pose, { type: 'box', ...box });
76
+ }
77
77
  }
78
78
  else if (geometry?.type === 'sphere') {
79
- const currentGeometry = object.geometry?.geometryType.value;
80
- geometry.r = this.sanatizeFloatValue(geometry.r);
81
- if (geometry.r === undefined)
79
+ const r = this.sanitizeFloatValue(geometry.r);
80
+ if (r === undefined)
82
81
  return;
83
- geometryObject = {
84
- type: 'sphere',
85
- r: geometry.r ?? currentGeometry?.radiusMm,
86
- };
82
+ entity.set(traits.Sphere, { r });
83
+ const sphere = entity.get(traits.Sphere);
84
+ if (name && sphere && pose) {
85
+ this.updateFrame(name, parent, pose, { type: 'sphere', ...sphere });
86
+ }
87
87
  }
88
88
  else if (geometry?.type === 'capsule') {
89
- const currentGeometry = object.geometry?.geometryType.value;
90
- geometry.r = this.sanatizeFloatValue(geometry.r);
91
- geometry.l = this.sanatizeFloatValue(geometry.l);
92
- if (geometry.r === undefined && geometry.l === undefined)
89
+ const r = this.sanitizeFloatValue(geometry.r);
90
+ const l = this.sanitizeFloatValue(geometry.l);
91
+ if (r === undefined && l === undefined)
93
92
  return;
94
- geometryObject = {
95
- type: 'capsule',
96
- r: geometry.r ?? currentGeometry?.radiusMm,
97
- l: geometry.l ?? currentGeometry?.lengthMm,
98
- };
93
+ const change = {};
94
+ if (r !== undefined)
95
+ change.r = r;
96
+ if (l !== undefined)
97
+ change.l = l;
98
+ entity.set(traits.Capsule, { r, l });
99
+ const capsule = entity.get(traits.Capsule);
100
+ if (name && capsule && pose) {
101
+ this.updateFrame(name, parent, pose, { type: 'capsule', ...capsule });
102
+ }
99
103
  }
100
- this.updateFrame(object.name ?? '', this.referenceFrame(), createPose(object.localEditedPose), geometryObject);
101
104
  };
102
- setFrameParent = (parentName) => {
103
- const object = this.object();
104
- if (!object)
105
- return;
106
- this.updateFrame(object.name ?? '', parentName, createPose(object.localEditedPose));
105
+ setFrameParent = (entity, parentName) => {
106
+ const name = entity.get(traits.Name);
107
+ const pose = entity.get(traits.EditedPose);
108
+ if (name && pose) {
109
+ this.updateFrame(name, parentName, pose);
110
+ }
107
111
  };
108
- deleteFrame = () => {
109
- const object = this.object();
110
- if (!object)
111
- return;
112
- this.removeFrame(object.name ?? '');
112
+ deleteFrame = (entity) => {
113
+ const name = entity.get(traits.Name);
114
+ if (name) {
115
+ this.removeFrame(name);
116
+ }
113
117
  };
114
- setGeometryType = (type) => {
115
- const object = this.object();
116
- if (!object)
118
+ setGeometryType = (entity, type) => {
119
+ const name = entity.get(traits.Name);
120
+ const parent = entity.get(traits.Parent) ?? 'world';
121
+ const pose = entity.get(traits.EditedPose);
122
+ if (!name || !pose)
117
123
  return;
118
124
  if (type === 'none') {
119
- this.updateFrame(object.name ?? '', this.referenceFrame(), createPose(object.localEditedPose), { type: 'none' });
125
+ this.updateFrame(name, parent, pose, { type: 'none' });
120
126
  }
121
127
  else if (type === 'box') {
122
- this.updateFrame(object.name ?? '', this.referenceFrame(), createPose(object.localEditedPose), { type: 'box', x: 100, y: 100, z: 100 });
128
+ this.updateFrame(name, parent, pose, { type: 'box', x: 100, y: 100, z: 100 });
123
129
  }
124
130
  else if (type === 'sphere') {
125
- this.updateFrame(object.name ?? '', this.referenceFrame(), createPose(object.localEditedPose), { type: 'sphere', r: 100 });
131
+ this.updateFrame(name, parent, pose, { type: 'sphere', r: 100 });
126
132
  }
127
133
  else if (type === 'capsule') {
128
- this.updateFrame(object.name ?? '', this.referenceFrame(), {
129
- x: object.localEditedPose.x,
130
- y: object.localEditedPose.y,
131
- z: object.localEditedPose.z,
132
- oX: object.localEditedPose.oX,
133
- oY: object.localEditedPose.oY,
134
- oZ: object.localEditedPose.oZ,
135
- theta: object.localEditedPose.theta,
136
- }, { type: 'capsule', r: 20, l: 100 });
134
+ this.updateFrame(name, parent, pose, { type: 'capsule', r: 20, l: 100 });
137
135
  }
138
136
  };
139
- sanatizeFloatValue = (value) => {
140
- if (value === undefined)
137
+ sanitizeFloatValue = (value) => {
138
+ if (value === undefined) {
141
139
  return undefined;
140
+ }
142
141
  const num = parseFloat(value.toFixed(2));
143
- if (isNaN(num))
142
+ if (Number.isNaN(num)) {
144
143
  return undefined;
145
- return num;
144
+ }
145
+ return value;
146
146
  };
147
147
  }
@@ -1,5 +1,5 @@
1
- import { BatchedMesh, Color, MathUtils, Object3D, Vector3 } from 'three';
2
- import { createPose, matrixToPose, poseToMatrix } from './transform';
1
+ import { BatchedMesh, Color, MathUtils, Vector3 } from 'three';
2
+ import { createPose } from './transform';
3
3
  import { isColorRepresentation, isRGB, parseColor, parseOpacity, parseRGB } from './color';
4
4
  export const SupportedShapes = {
5
5
  points: 'points',
@@ -136,16 +136,3 @@ export const fromTransform = (transform) => {
136
136
  worldObject.uuid = transform.uuidString;
137
137
  return worldObject;
138
138
  };
139
- export const determinePose = (object, pose) => {
140
- if (pose === undefined) {
141
- return object.localEditedPose;
142
- }
143
- else {
144
- const poseNetwork = poseToMatrix(object.pose);
145
- const poseUsePose = poseToMatrix(pose);
146
- const poseLocalEditedPose = poseToMatrix(object.localEditedPose);
147
- const poseNetworkInverse = poseNetwork.invert();
148
- const resultMatrix = poseUsePose.multiply(poseNetworkInverse).multiply(poseLocalEditedPose);
149
- return matrixToPose(resultMatrix);
150
- }
151
- };