@viamrobotics/motion-tools 1.1.5 → 1.1.6

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.
File without changes
@@ -0,0 +1,26 @@
1
+ export default BatchedGeometry;
2
+ type BatchedGeometry = SvelteComponent<{
3
+ [x: string]: never;
4
+ }, {
5
+ [evt: string]: CustomEvent<any>;
6
+ }, {}> & {
7
+ $$bindings?: string | undefined;
8
+ };
9
+ declare const BatchedGeometry: $$__sveltets_2_IsomorphicComponent<{
10
+ [x: string]: never;
11
+ }, {
12
+ [evt: string]: CustomEvent<any>;
13
+ }, {}, {}, string>;
14
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
15
+ new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
16
+ $$bindings?: Bindings;
17
+ } & Exports;
18
+ (internal: unknown, props: {
19
+ $$events?: Events;
20
+ $$slots?: Slots;
21
+ }): Exports & {
22
+ $set?: any;
23
+ $on?: any;
24
+ };
25
+ z_$$bindings?: Bindings;
26
+ }
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte'
3
3
  import { useObjectEvents } from '../hooks/useObjectEvents.svelte'
4
- import { Color, type Object3D } from 'three'
4
+ import { Color, Group, type Object3D } from 'three'
5
5
  import Geometry from './Geometry2.svelte'
6
6
  import { useWeblabs } from '../hooks/useWeblabs.svelte'
7
7
  import { useSelectedEntity } from '../hooks/useSelection.svelte'
@@ -13,6 +13,7 @@
13
13
  import { traits, useTrait } from '../ecs'
14
14
  import type { Pose } from '@viamrobotics/sdk'
15
15
  import { useResourceByName } from '../hooks/useResourceByName.svelte'
16
+ import { Portal, PortalTarget } from '@threlte/extras'
16
17
 
17
18
  interface Props {
18
19
  entity: Entity
@@ -22,14 +23,20 @@
22
23
 
23
24
  let { entity, pose, children }: Props = $props()
24
25
 
26
+ let ref = $state<Group>()
27
+
25
28
  const colorUtil = new Color()
29
+
26
30
  const settings = useSettings()
27
31
  const componentModels = use3DModels()
28
32
  const selectedEntity = useSelectedEntity()
29
33
  const resourceByName = useResourceByName()
30
34
  const weblabs = useWeblabs()
35
+
31
36
  const name = useTrait(() => entity, traits.Name)
37
+ const parent = useTrait(() => entity, traits.Parent)
32
38
  const entityColor = useTrait(() => entity, traits.Color)
39
+
33
40
  const events = useObjectEvents(() => entity)
34
41
  const resourceColor = $derived.by(() => {
35
42
  if (!name.current) {
@@ -66,14 +73,24 @@
66
73
  })
67
74
  </script>
68
75
 
69
- <Geometry
70
- {entity}
71
- {model}
72
- {pose}
73
- {children}
74
- renderMode={settings.current.renderArmModels}
75
- color={selectedEntity.current === entity
76
- ? `#${darkenColor(color, 75).getHexString()}`
77
- : `#${colorUtil.set(color).getHexString()}`}
78
- {...events}
79
- />
76
+ <Portal id={parent.current}>
77
+ <Geometry
78
+ bind:ref
79
+ {entity}
80
+ {model}
81
+ {pose}
82
+ renderMode={settings.current.renderArmModels}
83
+ color={selectedEntity.current === entity
84
+ ? `#${darkenColor(color, 75).getHexString()}`
85
+ : `#${colorUtil.set(color).getHexString()}`}
86
+ {...events}
87
+ >
88
+ {#if name.current}
89
+ <PortalTarget id={name.current} />
90
+ {/if}
91
+
92
+ {#if ref}
93
+ {@render children?.({ ref })}
94
+ {/if}
95
+ </Geometry>
96
+ </Portal>
@@ -1,13 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { T, useThrelte, type Props as ThrelteProps } from '@threlte/core'
3
3
  import { type Snippet } from 'svelte'
4
- import {
5
- meshBounds,
6
- MeshLineMaterial,
7
- MeshLineGeometry,
8
- Portal,
9
- PortalTarget,
10
- } from '@threlte/extras'
4
+ import { meshBounds, MeshLineMaterial, MeshLineGeometry } from '@threlte/extras'
11
5
  import { BufferGeometry, Color, DoubleSide, FrontSide, Group, Mesh } from 'three'
12
6
  import { CapsuleGeometry } from '../three/CapsuleGeometry'
13
7
  import { colors, darkenColor } from '../color'
@@ -23,6 +17,7 @@
23
17
  model?: Group
24
18
  pose?: Pose
25
19
  renderMode?: 'model' | 'colliders' | 'colliders+model'
20
+ ref?: Group
26
21
  children?: Snippet<[{ ref: Group }]>
27
22
  }
28
23
 
@@ -32,6 +27,7 @@
32
27
  model,
33
28
  renderMode = 'colliders',
34
29
  pose,
30
+ ref = $bindable(),
35
31
  children,
36
32
  ...rest
37
33
  }: Props = $props()
@@ -40,7 +36,6 @@
40
36
 
41
37
  const { invalidate } = useThrelte()
42
38
  const name = useTrait(() => entity, traits.Name)
43
- const parent = useTrait(() => entity, traits.Parent)
44
39
  const entityColor = useTrait(() => entity, traits.Color)
45
40
  const opacity = useTrait(() => entity, traits.Opacity)
46
41
  const box = useTrait(() => entity, traits.Box)
@@ -71,6 +66,8 @@
71
66
  })
72
67
 
73
68
  const group = new Group()
69
+ ref = group
70
+
74
71
  const mesh = $derived.by(() => {
75
72
  if (geometryType === undefined) {
76
73
  return
@@ -103,8 +100,8 @@
103
100
 
104
101
  let geo = $state.raw<BufferGeometry>()
105
102
 
106
- const oncreate = (ref: BufferGeometry) => {
107
- geo = ref
103
+ const oncreate = (bufferGeometry: BufferGeometry) => {
104
+ geo = bufferGeometry
108
105
  }
109
106
 
110
107
  $effect.pre(() => {
@@ -120,87 +117,81 @@
120
117
  })
121
118
  </script>
122
119
 
123
- <Portal id={parent.current}>
124
- <T
125
- is={group}
126
- {...rest}
127
- >
128
- {#if geometryType}
129
- <AxesHelper
130
- width={3}
131
- length={0.1}
132
- />
133
-
134
- <T
135
- is={mesh}
136
- name={name.current}
137
- bvh={{ enabled: geometryType === 'buffer' }}
138
- >
139
- {#if model && renderMode.includes('model')}
140
- <T is={model} />
141
- {/if}
142
-
143
- {#if !model || renderMode.includes('colliders')}
144
- {#if lineGeometry.current}
145
- <MeshLineGeometry points={lineGeometry.current} />
146
- {:else if box.current}
147
- {@const { x, y, z } = box.current ?? { x: 0, y: 0, z: 0 }}
148
- <T.BoxGeometry
149
- args={[x * 0.001, y * 0.001, z * 0.001]}
150
- {oncreate}
151
- />
152
- {:else if sphere.current}
153
- {@const { r } = sphere.current ?? { r: 0 }}
154
- <T.SphereGeometry
155
- args={[r * 0.001]}
156
- {oncreate}
157
- />
158
- {:else if capsule.current}
159
- {@const { r, l } = capsule.current ?? { r: 0, l: 0 }}
160
- <T
161
- is={CapsuleGeometry}
162
- args={[r * 0.001, l * 0.001]}
163
- {oncreate}
164
- />
165
- {/if}
166
- {/if}
167
-
120
+ <T
121
+ is={group}
122
+ {...rest}
123
+ >
124
+ {#if geometryType}
125
+ <AxesHelper
126
+ width={3}
127
+ length={0.1}
128
+ />
129
+
130
+ <T
131
+ is={mesh}
132
+ name={name.current}
133
+ bvh={{ enabled: geometryType === 'buffer' }}
134
+ >
135
+ {#if model && renderMode.includes('model')}
136
+ <T is={model} />
137
+ {/if}
138
+
139
+ {#if !model || renderMode.includes('colliders')}
168
140
  {#if lineGeometry.current}
169
- <MeshLineMaterial
170
- {color}
171
- width={0.005}
141
+ <MeshLineGeometry points={lineGeometry.current} />
142
+ {:else if box.current}
143
+ {@const { x, y, z } = box.current ?? { x: 0, y: 0, z: 0 }}
144
+ <T.BoxGeometry
145
+ args={[x * 0.001, y * 0.001, z * 0.001]}
146
+ {oncreate}
172
147
  />
173
- {:else}
174
- <T.MeshToonMaterial
175
- {color}
176
- side={geometryType === 'buffer' ? DoubleSide : FrontSide}
177
- transparent
178
- opacity={opacity.current ?? 0.7}
148
+ {:else if sphere.current}
149
+ {@const { r } = sphere.current ?? { r: 0 }}
150
+ <T.SphereGeometry
151
+ args={[r * 0.001]}
152
+ {oncreate}
179
153
  />
180
-
181
- {#if geo}
182
- <T.LineSegments
183
- raycast={() => null}
184
- bvh={{ enabled: false }}
185
- >
186
- <T.EdgesGeometry args={[geo, 0]} />
187
- <T.LineBasicMaterial color={darkenColor(color, 10)} />
188
- </T.LineSegments>
189
- {/if}
154
+ {:else if capsule.current}
155
+ {@const { r, l } = capsule.current ?? { r: 0, l: 0 }}
156
+ <T
157
+ is={CapsuleGeometry}
158
+ args={[r * 0.001, l * 0.001]}
159
+ {oncreate}
160
+ />
161
+ {/if}
162
+ {/if}
163
+
164
+ {#if lineGeometry.current}
165
+ <MeshLineMaterial
166
+ {color}
167
+ width={0.005}
168
+ />
169
+ {:else}
170
+ <T.MeshToonMaterial
171
+ {color}
172
+ side={geometryType === 'buffer' ? DoubleSide : FrontSide}
173
+ transparent
174
+ opacity={opacity.current ?? 0.7}
175
+ />
176
+
177
+ {#if geo}
178
+ <T.LineSegments
179
+ raycast={() => null}
180
+ bvh={{ enabled: false }}
181
+ >
182
+ <T.EdgesGeometry args={[geo, 0]} />
183
+ <T.LineBasicMaterial color={darkenColor(color, 10)} />
184
+ </T.LineSegments>
190
185
  {/if}
191
- </T>
192
- {:else}
193
- <AxesHelper
194
- name={name.current}
195
- width={3}
196
- length={0.1}
197
- />
198
- {/if}
199
-
200
- {@render children?.({ ref: group })}
201
-
202
- {#if name.current}
203
- <PortalTarget id={name.current} />
204
- {/if}
205
- </T>
206
- </Portal>
186
+ {/if}
187
+ </T>
188
+ {:else}
189
+ <AxesHelper
190
+ name={name.current}
191
+ width={3}
192
+ length={0.1}
193
+ />
194
+ {/if}
195
+
196
+ {@render children?.({ ref: group })}
197
+ </T>
@@ -9,10 +9,11 @@ interface Props extends ThrelteProps<Group> {
9
9
  model?: Group;
10
10
  pose?: Pose;
11
11
  renderMode?: 'model' | 'colliders' | 'colliders+model';
12
+ ref?: Group;
12
13
  children?: Snippet<[{
13
14
  ref: Group;
14
15
  }]>;
15
16
  }
16
- declare const Geometry2: import("svelte").Component<Props, {}, "">;
17
+ declare const Geometry2: import("svelte").Component<Props, {}, "ref">;
17
18
  type Geometry2 = ReturnType<typeof Geometry2>;
18
19
  export default Geometry2;
@@ -290,6 +290,7 @@ export const provideDrawAPI = () => {
290
290
  for (const entity of world.query(traits.DrawAPI)) {
291
291
  if (entity.get(traits.Name) === name) {
292
292
  entity.destroy();
293
+ entities.delete(name);
293
294
  }
294
295
  }
295
296
  }
@@ -298,6 +299,7 @@ export const provideDrawAPI = () => {
298
299
  for (const entity of world.query(traits.DrawAPI)) {
299
300
  entity.destroy();
300
301
  }
302
+ entities.clear();
301
303
  pointsIndex = 0;
302
304
  geometryIndex = 0;
303
305
  poseIndex = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",