@operato/scene-manufacturing 10.0.0-beta.2 → 10.0.0-beta.24

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.
@@ -0,0 +1,544 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ *
4
+ * Robot Arm — generalized articulated manipulator component.
5
+ *
6
+ * Designed to cover the visualization needs of robot arms WITHOUT a
7
+ * specific URDF model. Configurable kinematic chain, link shape, joint
8
+ * housing, gripper type — same component renders as a sleek cobot, a
9
+ * heavy industrial 6-axis, a SCARA, or a minimal educational arm.
10
+ *
11
+ * State schema (all top-level properties optional except width/height):
12
+ *
13
+ * {
14
+ * // structure
15
+ * style?: 'industrial' | 'cobot' | 'scara' | 'minimal',
16
+ * chainPreset?: '6-axis-industrial' | 'cobot-6-axis' | 'scara-4-axis' | 'pick-and-place-3-axis',
17
+ * chain?: ChainElement[], // overrides preset
18
+ * joints?: number[] | { [i]: number }, // current joint values
19
+ *
20
+ * // styling overrides
21
+ * linkShape?, jointHousing?, linkRadius?, color?, accentColor?,
22
+ *
23
+ * // gripper
24
+ * gripper?: GripperConfig,
25
+ *
26
+ * // IK target (TCP world position relative to component center, in
27
+ * // 3D-z-up convention used by IK module)
28
+ * target?: { x: number, y: number, z: number },
29
+ *
30
+ * // visualization
31
+ * showReachSphere?: boolean
32
+ * }
33
+ */
34
+ import { __decorate } from "tslib";
35
+ import * as THREE from 'three';
36
+ import { ContainerAbstract, sceneComponent } from '@hatiolab/things-scene';
37
+ import { CarrierHolder, Legendable, Mover, Placeable } from '@operato/scene-base';
38
+ import { RobotArm3D } from './robot-arm-3d.js';
39
+ import { CHAIN_PRESETS } from './robot-arm-styles.js';
40
+ const BODY_LEGEND = {
41
+ idle: '#ccc',
42
+ moving: '#afd0f1',
43
+ gripping: '#cfe6c8',
44
+ warn: '#ffba00',
45
+ error: '#e9746b',
46
+ default: '#ccc'
47
+ };
48
+ const BORDER_LEGEND = {
49
+ idle: '#888',
50
+ moving: '#87b1db',
51
+ gripping: '#7aa274',
52
+ warn: '#d96f21',
53
+ error: '#a73928',
54
+ default: '#888'
55
+ };
56
+ const LAMP_EMISSIVE_LEGEND = {
57
+ idle: '#333333',
58
+ moving: '#44aaff',
59
+ gripping: '#33aa44',
60
+ warn: '#ffaa00',
61
+ error: '#ff3333',
62
+ default: '#333333'
63
+ };
64
+ const STATIC_PROPERTIES = [
65
+ {
66
+ type: 'select',
67
+ label: 'style',
68
+ name: 'style',
69
+ property: {
70
+ options: [
71
+ { display: 'Industrial', value: 'industrial' },
72
+ { display: 'Cobot', value: 'cobot' },
73
+ { display: 'SCARA', value: 'scara' },
74
+ { display: 'Minimal', value: 'minimal' }
75
+ ]
76
+ }
77
+ },
78
+ {
79
+ type: 'select',
80
+ label: 'chain-preset',
81
+ name: 'chainPreset',
82
+ property: {
83
+ options: [
84
+ { display: '6-Axis Industrial', value: '6-axis-industrial' },
85
+ { display: 'Cobot 6-Axis', value: 'cobot-6-axis' },
86
+ { display: 'SCARA 4-Axis', value: 'scara-4-axis' },
87
+ { display: 'Pick & Place 3-Axis', value: 'pick-and-place-3-axis' }
88
+ ]
89
+ }
90
+ },
91
+ { type: 'number', label: 'link-radius', name: 'linkRadius' },
92
+ {
93
+ type: 'select',
94
+ label: 'gripper-type',
95
+ name: 'gripperType',
96
+ property: {
97
+ options: [
98
+ { display: 'Parallel', value: 'parallel' },
99
+ { display: 'Suction', value: 'suction' },
100
+ { display: 'Magnetic', value: 'magnetic' },
101
+ { display: 'Three-Finger', value: 'three-finger' },
102
+ { display: 'None', value: 'none' }
103
+ ]
104
+ }
105
+ },
106
+ { type: 'checkbox', label: 'show-reach-sphere', name: 'showReachSphere' },
107
+ {
108
+ type: 'select',
109
+ label: 'status',
110
+ name: 'status',
111
+ property: {
112
+ options: [
113
+ { display: 'Idle', value: 'idle' },
114
+ { display: 'Moving', value: 'moving' },
115
+ { display: 'Gripping', value: 'gripping' },
116
+ { display: 'Warn', value: 'warn' },
117
+ { display: 'Error', value: 'error' }
118
+ ]
119
+ }
120
+ }
121
+ ];
122
+ // CarrierHolder + ContainerAbstract: the arm needs the container's child-list
123
+ // machinery (addComponent / reparent / events) AND CarrierHolder's
124
+ // attachPointFor hook. CarrierHolder mixin alone only publishes the attach
125
+ // policy; it doesn't add child management. RectPath(Shape) was wrong here —
126
+ // Shape is a leaf so reparent silently failed. ContainerAbstract provides
127
+ // the missing piece.
128
+ //
129
+ // `ContainerAbstract` (not `Container`) — Container = MixinHTMLElement(ContainerAbstract),
130
+ // which forces `isHTMLElement(): true` and trips the 3D pipeline's
131
+ // addObject DOM-skip gate. Robot arm exists purely in the 3D scene graph
132
+ // (URDF/IK joints, no DOM overlay), so the bare logical container is correct.
133
+ //
134
+ // Mover wraps the chain to publish pick/place/pickAndPlace primitives. It
135
+ // must sit OUTSIDE CarrierHolder because Mover's defaults call this.reparent,
136
+ // which CarrierHolder provides (overrides the base ContainerAbstract
137
+ // version with the attach-frame-aware variant).
138
+ //
139
+ // The instance type cast surfaces Mover's API on `this` so subclass
140
+ // `override` keywords compile and `this.pickAndPlace(...)` resolves —
141
+ // without it, the `as unknown as typeof Component` cast erases all
142
+ // mixin contributions to the static side.
143
+ const Base = Mover(CarrierHolder(Legendable(Placeable(ContainerAbstract))));
144
+ let RobotArm = class RobotArm extends Base {
145
+ static legends = {
146
+ bodyColor: { from: 'status', legend: BODY_LEGEND },
147
+ borderColor: { from: 'status', legend: BORDER_LEGEND },
148
+ lampEmissive: { from: 'status', legend: LAMP_EMISSIVE_LEGEND }
149
+ };
150
+ /**
151
+ * Robot arms sit on the floor (or mount to a ceiling/wall — that's a
152
+ * v2 feature). Default depth = operation - floor like other floor-
153
+ * mounted equipment, so the chain reach scales with the configured
154
+ * facility height.
155
+ */
156
+ static placement = 'floor';
157
+ static align = 'bottom';
158
+ static defaultDepth = (h) => h.operation - h.floor;
159
+ /**
160
+ * Dynamic nature — appends one number property per joint in the active
161
+ * chain. Each property uses the joint's range as `min`/`max` so the
162
+ * property panel can render a constrained slider/spinner. The chain
163
+ * preset can change at runtime, and `get nature()` is re-evaluated
164
+ * whenever the property panel queries it, so the joint count stays in
165
+ * sync with the active preset.
166
+ *
167
+ * For revolute joints the value is in radians; for prismatic, scene units.
168
+ */
169
+ get nature() {
170
+ const chain = this._activeChain;
171
+ // Joint values: revolute = degrees (range usually ±180), prismatic =
172
+ // scene length units. CHAIN_PRESETS already encode revolute ranges in
173
+ // degrees; the 3D side converts to radians at the math boundary.
174
+ const jointProps = chain.map((c, i) => ({
175
+ type: 'number',
176
+ label: `joint-${i + 1}`,
177
+ name: `joint${i}`,
178
+ property: {
179
+ min: c.range[0],
180
+ max: c.range[1],
181
+ step: c.type === 'revolute' ? 1 : 1
182
+ }
183
+ }));
184
+ return {
185
+ mutable: false,
186
+ resizable: true,
187
+ rotatable: true,
188
+ properties: [...STATIC_PROPERTIES, ...jointProps],
189
+ help: 'scene/component/robot-arm'
190
+ };
191
+ }
192
+ /**
193
+ * Resolve the active chain for property-panel introspection. Mirrors
194
+ * the resolution in robot-arm-3d.ts (state.chain wins, else preset,
195
+ * else default 6-axis-industrial). Kept simple — the 3D side does the
196
+ * same logic with depth-based scaling, but for property labeling we
197
+ * only need the structure (axis count + ranges), not absolute lengths.
198
+ */
199
+ get _activeChain() {
200
+ const state = this.state;
201
+ if (Array.isArray(state.chain) && state.chain.length > 0)
202
+ return state.chain;
203
+ const presetName = (state.chainPreset ?? '6-axis-industrial');
204
+ return CHAIN_PRESETS[presetName] ?? CHAIN_PRESETS['6-axis-industrial'];
205
+ }
206
+ get anchors() {
207
+ return [];
208
+ }
209
+ /**
210
+ * 2D — base rectangle + a stylized arm silhouette pointing toward the
211
+ * top-right. Just enough to identify the component as a robot arm in
212
+ * plan view; the real visual lives in 3D.
213
+ */
214
+ render(ctx) {
215
+ const { left = 0, top = 0, width = 100, height = 100 } = this.state;
216
+ const bodyFill = pickColor(this.state.fillStyle, this.state.bodyColor, BODY_LEGEND.default);
217
+ const borderColor = pickColor(this.state.strokeStyle, this.state.borderColor, BORDER_LEGEND.default);
218
+ const lineWidth = numOr(this.state.lineWidth, 1);
219
+ ctx.beginPath();
220
+ ctx.rect(left, top, width, height);
221
+ ctx.fillStyle = bodyFill;
222
+ ctx.fill();
223
+ ctx.strokeStyle = borderColor;
224
+ ctx.lineWidth = lineWidth;
225
+ ctx.stroke();
226
+ // Stylized arm silhouette: base square at center → up → bent right.
227
+ const cx = left + width / 2;
228
+ const cy = top + height / 2;
229
+ const r = Math.min(width, height) * 0.32;
230
+ ctx.save();
231
+ ctx.strokeStyle = borderColor;
232
+ ctx.lineWidth = Math.max(lineWidth, Math.min(width, height) * 0.025);
233
+ // Base pedestal
234
+ ctx.fillStyle = borderColor;
235
+ ctx.fillRect(cx - r * 0.5, cy + r * 0.6, r, r * 0.3);
236
+ // Upper arm
237
+ ctx.beginPath();
238
+ ctx.moveTo(cx, cy + r * 0.6);
239
+ ctx.lineTo(cx, cy - r * 0.2);
240
+ ctx.stroke();
241
+ // Forearm
242
+ ctx.beginPath();
243
+ ctx.moveTo(cx, cy - r * 0.2);
244
+ ctx.lineTo(cx + r * 0.7, cy - r * 0.7);
245
+ ctx.stroke();
246
+ // Joint dots
247
+ ctx.fillStyle = borderColor;
248
+ ctx.beginPath();
249
+ ctx.arc(cx, cy - r * 0.2, Math.max(2, r * 0.1), 0, Math.PI * 2);
250
+ ctx.fill();
251
+ ctx.beginPath();
252
+ ctx.arc(cx + r * 0.7, cy - r * 0.7, Math.max(1.5, r * 0.08), 0, Math.PI * 2);
253
+ ctx.fill();
254
+ ctx.restore();
255
+ }
256
+ onchange(after, before) {
257
+ // Per-joint number properties (joint0 … jointN-1) are dynamic; treat
258
+ // any key matching the pattern as a joint update.
259
+ const hasJoint = Object.keys(after).some(k => /^joint\d+$/.test(k));
260
+ if (hasJoint ||
261
+ 'style' in after ||
262
+ 'chainPreset' in after ||
263
+ 'chain' in after ||
264
+ 'joints' in after ||
265
+ 'linkShape' in after ||
266
+ 'jointHousing' in after ||
267
+ 'linkRadius' in after ||
268
+ 'color' in after ||
269
+ 'accentColor' in after ||
270
+ 'fillStyle' in after ||
271
+ 'strokeStyle' in after ||
272
+ 'lineWidth' in after ||
273
+ 'alpha' in after ||
274
+ 'material3d' in after ||
275
+ 'gripper' in after ||
276
+ 'gripperType' in after ||
277
+ 'target' in after ||
278
+ 'showReachSphere' in after ||
279
+ 'status' in after ||
280
+ 'bodyColor' in after ||
281
+ 'borderColor' in after) {
282
+ ;
283
+ this.clearCache?.('fillStyle');
284
+ this.invalidate();
285
+ }
286
+ super.onchange(after, before);
287
+ }
288
+ buildRealObject() {
289
+ return new RobotArm3D(this);
290
+ }
291
+ /**
292
+ * CarrierHolder hook — return the gripper TCP frame so any Carriable
293
+ * child (parcel/box/pallet/...) mounts onto the moving end-effector.
294
+ * IK rotation propagates to the carrier through Three.js scene-graph.
295
+ *
296
+ * Pose convention (real-world pick-and-place: gripper pointing toward
297
+ * the work, carrier hanging *beyond* the gripper tip):
298
+ *
299
+ * - Frame: TCP (gripper working point — between finger tips for
300
+ * jaws, contact face for suction/magnetic). Built by
301
+ * `RobotArm3D._buildGripper`. TCP's +Z = gripper-forward direction
302
+ * (away from the wrist).
303
+ *
304
+ * - Rotation: x:-π/2 — maps carrier's local +Y axis ("up" in the
305
+ * carrier's authored frame) to TCP's -Z direction. With the gripper
306
+ * pointing down (typical work pose), TCP +Z = world -Y (down), so
307
+ * TCP -Z = world +Y (up). Result: carrier's "up" stays world-up
308
+ * during transit, and the carrier's body extends from TCP origin
309
+ * in TCP +Z direction (down in world) — i.e. hanging BELOW the
310
+ * gripper, not buried inside it.
311
+ *
312
+ * - Position: z = +halfDepth — places the carrier's TOP face center
313
+ * at the TCP origin (where the fingers grip). Carrier's local +Y
314
+ * extent (top) = halfDepth, which after x:-π/2 rotation maps to
315
+ * TCP -halfDepth Z. Shifting carrier center to TCP +halfDepth Z
316
+ * puts that top point exactly at TCP origin. Carrier body then
317
+ * extends through TCP +Z, ending at TCP +depth (bottom face).
318
+ *
319
+ * Earlier (x:+π/2, z:-halfDepth) inverted the carrier's body direction
320
+ * — body extended back into the wrist, leaving the box visually inside
321
+ * the finger area. The current convention pushes the body OUT past the
322
+ * fingertips, where a real gripper would hold it.
323
+ */
324
+ attachPointFor(carrier) {
325
+ const ro = this._realObject;
326
+ const frame = ro?.getGripperFrame?.();
327
+ if (!frame)
328
+ return undefined;
329
+ const halfDepth = resolveDepth(carrier) / 2;
330
+ return {
331
+ attach: frame,
332
+ localPosition: { x: 0, y: 0, z: halfDepth },
333
+ localRotation: { x: -Math.PI / 2, y: 0, z: 0 }
334
+ };
335
+ }
336
+ /**
337
+ * Pick: TCP descends vertically onto the carrier's top face, gripper
338
+ * closes, carrier becomes our child.
339
+ *
340
+ * 1. TCP → APPROACH above pick (carrier's xy, +clearance in world Y)
341
+ * 2. TCP → pick (descend straight down to carrier's top face)
342
+ * 3. close gripper + reparent(carrier → this)
343
+ *
344
+ * The approach waypoint exists so the FINAL leg is a clean vertical
345
+ * descent — the gripper enters the carrier from straight above, not a
346
+ * sideways sweep that could clip or grab at a wrong angle.
347
+ *
348
+ * Pose resolution: TCP lands on the CARRIER'S TOP FACE (carrier.world.y +
349
+ * carrier.depth/2). After grip, `attachPointFor`'s `localPosition.z =
350
+ * +halfDepth` keeps the carrier's top at TCP origin during transit —
351
+ * exact, no offset drift.
352
+ *
353
+ * Each waypoint includes the carrier's world yaw so IK can spin joint 5
354
+ * (tool roll) to align the gripper's "side" with the carrier's. Without
355
+ * it, reparent at pick instantly snaps the carrier to the gripper's
356
+ * axis, visibly twisting it 0° → up to 360° in one frame.
357
+ *
358
+ * @param options.approachClearance Vertical offset (world units)
359
+ * between approach and pick targets. Default 10.
360
+ * @param options.timeoutMs Per-segment IK timeout (default 15000ms).
361
+ * @param options.reparentDuration Animation duration for reparent (default 800ms).
362
+ */
363
+ async pick(carrier, options = {}) {
364
+ const timeoutMs = options.timeoutMs ?? 15000;
365
+ const reparentDuration = options.reparentDuration ?? 800;
366
+ const clearance = options.approachClearance ?? 10;
367
+ // Read carrier height via _realObject.effectiveDepth — `state.depth`
368
+ // is often not explicitly set (carriers like Box rely on
369
+ // `static defaultDepth`), and reading state alone returns 0, which
370
+ // collapses every Y offset and drives the gripper into the carrier's
371
+ // volumetric center instead of its top face.
372
+ const carrierDepth = resolveDepth(carrier);
373
+ const halfDepth = carrierDepth / 2;
374
+ const yaw = this._yawOf(carrier);
375
+ const target = this._targetFor(carrier, halfDepth, yaw);
376
+ const approach = this._targetFor(carrier, halfDepth + clearance, yaw);
377
+ this.set('target', approach);
378
+ await waitForTcpReached(this, timeoutMs);
379
+ this.set('target', target);
380
+ await waitForTcpReached(this, timeoutMs);
381
+ this.reparent?.(carrier, { animated: true, duration: reparentDuration });
382
+ this.set('gripper', { ...(this.state.gripper ?? {}), state: 1 });
383
+ await sleep(reparentDuration);
384
+ }
385
+ /**
386
+ * Place: TCP descends vertically over the holder, gripper opens,
387
+ * carrier becomes the holder's child.
388
+ *
389
+ * 1. TCP → APPROACH above place (carrier's xy, +clearance)
390
+ * 2. TCP → place (descend straight down to drop point)
391
+ * 3. open gripper + reparent(carrier → holder)
392
+ *
393
+ * Pose resolution: TCP lands at where the carrier's top WILL BE after
394
+ * the drop, so the carrier lands with its bottom on the holder's attach
395
+ * surface. Computed as `holder.attachFrame.world.y + carrier.depth` (so
396
+ * yOffset = carrierDepth, not halfDepth like pick).
397
+ *
398
+ * @see pick — same option semantics.
399
+ */
400
+ async place(carrier, holder, options = {}) {
401
+ const timeoutMs = options.timeoutMs ?? 15000;
402
+ const reparentDuration = options.reparentDuration ?? 800;
403
+ const clearance = options.approachClearance ?? 10;
404
+ const carrierDepth = resolveDepth(carrier);
405
+ const yaw = this._yawOf(holder);
406
+ const target = this._targetFor(holder, carrierDepth, yaw); // top-of-carrier after drop
407
+ const approach = this._targetFor(holder, carrierDepth + clearance, yaw);
408
+ this.set('target', approach);
409
+ await waitForTcpReached(this, timeoutMs);
410
+ this.set('target', target);
411
+ await waitForTcpReached(this, timeoutMs);
412
+ holder.reparent?.(carrier, { animated: true, duration: reparentDuration });
413
+ this.set('gripper', { ...(this.state.gripper ?? {}), state: 0 });
414
+ await sleep(reparentDuration);
415
+ }
416
+ /**
417
+ * `pickAndPlace` is inherited from the `Mover` mixin default — runs
418
+ * `pick(carrier)` then `place(carrier, holder)` sequentially. The
419
+ * decomposition is safe: the carrier's world position only matters
420
+ * during pick (carrier-relative waypoints), and after pick the carrier
421
+ * is the TCP's child (so re-querying it would chase its own tail —
422
+ * which we don't, since place uses holder-relative waypoints only).
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * await robotArm.pickAndPlace(box, spotB)
427
+ * await robotArm.pnp(parcel, palletA, { approachClearance: 30 })
428
+ * ```
429
+ */
430
+ /** Short alias for `pickAndPlace`. Same arguments, same behavior. */
431
+ pnp(carrier, placeHolder, options) {
432
+ return this.pickAndPlace(carrier, placeHolder, options);
433
+ }
434
+ /**
435
+ * Resolve a TCP position in this arm's chain-local frame.
436
+ *
437
+ * For a CarrierHolder (has `attachPointFor`), uses the holder's own
438
+ * attach frame as the base — that's the canonical "where carriers
439
+ * sit on me" point (top of Spot's pad, gripper TCP for another arm,
440
+ * etc.). For a plain carrier, uses its world center.
441
+ *
442
+ * `worldYOffset` is added to the resolved world Y before projecting
443
+ * back to chain-local — used by pickAndPlace to lift the TCP above
444
+ * the target (approach waypoints) and to land it on the carrier's
445
+ * top face rather than its volumetric center.
446
+ */
447
+ _targetFor(component, worldYOffset = 0, yaw) {
448
+ const ro3d = this._realObject;
449
+ let baseWp;
450
+ // Prefer holder's attach frame when available.
451
+ const attachPointFor = component.attachPointFor;
452
+ if (typeof attachPointFor === 'function') {
453
+ const point = attachPointFor.call(component, this);
454
+ if (point?.attach) {
455
+ point.attach.updateWorldMatrix?.(true, false);
456
+ baseWp = point.attach.getWorldPosition?.(new THREE.Vector3());
457
+ }
458
+ }
459
+ if (!baseWp) {
460
+ const obj = component._realObject?.object3d;
461
+ if (obj) {
462
+ obj.updateWorldMatrix(true, false);
463
+ baseWp = obj.getWorldPosition(new THREE.Vector3());
464
+ }
465
+ }
466
+ if (!ro3d || !baseWp) {
467
+ // Final fallback: 2D bounds center — only before 3D builds.
468
+ const c = component.center;
469
+ return { x: c.x, y: worldYOffset, z: c.y, yaw };
470
+ }
471
+ const local = ro3d.worldToChainLocal(baseWp.x, baseWp.y + worldYOffset, baseWp.z);
472
+ return { x: local.x, y: local.y, z: local.z, yaw };
473
+ }
474
+ /**
475
+ * Extract a component's world yaw (rotation around world +Y) from its
476
+ * 3D object's world matrix. Returns 0 if the object isn't built yet.
477
+ * Used by `pickAndPlace` so the gripper can match the carrier's /
478
+ * placeHolder's current orientation — preventing a yaw snap at the
479
+ * moment of reparent.
480
+ */
481
+ _yawOf(component) {
482
+ const obj = component._realObject?.object3d;
483
+ if (!obj)
484
+ return 0;
485
+ obj.updateWorldMatrix(true, false);
486
+ const q = new THREE.Quaternion();
487
+ obj.getWorldQuaternion(q);
488
+ const e = new THREE.Euler().setFromQuaternion(q, 'YXZ');
489
+ return e.y;
490
+ }
491
+ };
492
+ RobotArm = __decorate([
493
+ sceneComponent('robot-arm')
494
+ ], RobotArm);
495
+ export default RobotArm;
496
+ /**
497
+ * Resolve when the robot arm fires `tcp-reached`, reject on timeout.
498
+ * The 3D side fires this event on smoothing completion (last joint
499
+ * value within threshold of its target).
500
+ */
501
+ function waitForTcpReached(component, timeoutMs) {
502
+ return new Promise((resolve, reject) => {
503
+ let timer;
504
+ const onReached = () => {
505
+ clearTimeout(timer);
506
+ component.off?.('tcp-reached', onReached);
507
+ resolve();
508
+ };
509
+ timer = setTimeout(() => {
510
+ ;
511
+ component.off?.('tcp-reached', onReached);
512
+ reject(new Error('TCP reach timeout'));
513
+ }, timeoutMs);
514
+ component.on?.('tcp-reached', onReached);
515
+ });
516
+ }
517
+ function sleep(ms) {
518
+ return new Promise(resolve => setTimeout(resolve, ms));
519
+ }
520
+ function numOr(v, dflt) {
521
+ return typeof v === 'number' && Number.isFinite(v) ? v : dflt;
522
+ }
523
+ /**
524
+ * Resolve a component's 3D height. things-scene v10 carriers (Box, Pallet,
525
+ * etc.) typically declare `static defaultDepth` rather than setting
526
+ * `state.depth`, so reading state alone returns 0 — wrong for a
527
+ * default-sized box. The framework resolves the actual value into
528
+ * `_realObject.effectiveDepth`. Falls back to `state.depth` for
529
+ * components built before their RealObject exists.
530
+ */
531
+ function resolveDepth(c) {
532
+ const eff = c?._realObject?.effectiveDepth;
533
+ if (typeof eff === 'number' && Number.isFinite(eff))
534
+ return eff;
535
+ return numOr(c?.state?.depth, 0);
536
+ }
537
+ function pickColor(...candidates) {
538
+ for (const c of candidates) {
539
+ if (typeof c === 'string' && c && c !== 'transparent')
540
+ return c;
541
+ }
542
+ return '#888';
543
+ }
544
+ //# sourceMappingURL=robot-arm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"robot-arm.js","sourceRoot":"","sources":["../src/robot-arm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAA8B,iBAAiB,EAAc,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAClH,OAAO,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,SAAS,EAMV,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAwB,MAAM,uBAAuB,CAAA;AAK3E,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,SAAS;IACnB,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,MAAM;CAChB,CAAA;AAED,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,SAAS;IACjB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AO,MAAM,CAAA;AACf,CAAC","sourcesContent":["/*\n * Copyright © HatioLab Inc. All rights reserved.\n *\n * Robot Arm — generalized articulated manipulator component.\n *\n * Designed to cover the visualization needs of robot arms WITHOUT a\n * specific URDF model. Configurable kinematic chain, link shape, joint\n * housing, gripper type — same component renders as a sleek cobot, a\n * heavy industrial 6-axis, a SCARA, or a minimal educational arm.\n *\n * State schema (all top-level properties optional except width/height):\n *\n * {\n * // structure\n * style?: 'industrial' | 'cobot' | 'scara' | 'minimal',\n * chainPreset?: '6-axis-industrial' | 'cobot-6-axis' | 'scara-4-axis' | 'pick-and-place-3-axis',\n * chain?: ChainElement[], // overrides preset\n * joints?: number[] | { [i]: number }, // current joint values\n *\n * // styling overrides\n * linkShape?, jointHousing?, linkRadius?, color?, accentColor?,\n *\n * // gripper\n * gripper?: GripperConfig,\n *\n * // IK target (TCP world position relative to component center, in\n * // 3D-z-up convention used by IK module)\n * target?: { x: number, y: number, z: number },\n *\n * // visualization\n * showReachSphere?: boolean\n * }\n */\n\nimport * as THREE from 'three'\nimport { Component, ComponentNature, ContainerAbstract, RealObject, sceneComponent } from '@hatiolab/things-scene'\nimport {\n CarrierHolder,\n Legendable,\n Mover,\n Placeable,\n type Alignment,\n type Heights,\n type LegendBinding,\n type MoveOptions,\n type PlacementArchetype\n} from '@operato/scene-base'\n\nimport { RobotArm3D } from './robot-arm-3d.js'\nimport { CHAIN_PRESETS, type ChainPresetName } from './robot-arm-styles.js'\nimport type { ChainElement } from './robot-arm-ik.js'\n\nexport type RobotArmStatus = 'idle' | 'moving' | 'gripping' | 'warn' | 'error'\n\nconst BODY_LEGEND = {\n idle: '#ccc',\n moving: '#afd0f1',\n gripping: '#cfe6c8',\n warn: '#ffba00',\n error: '#e9746b',\n default: '#ccc'\n}\n\nconst BORDER_LEGEND = {\n idle: '#888',\n moving: '#87b1db',\n gripping: '#7aa274',\n warn: '#d96f21',\n error: '#a73928',\n default: '#888'\n}\n\nconst LAMP_EMISSIVE_LEGEND = {\n idle: '#333333',\n moving: '#44aaff',\n gripping: '#33aa44',\n warn: '#ffaa00',\n error: '#ff3333',\n default: '#333333'\n}\n\nconst STATIC_PROPERTIES = [\n {\n type: 'select',\n label: 'style',\n name: 'style',\n property: {\n options: [\n { display: 'Industrial', value: 'industrial' },\n { display: 'Cobot', value: 'cobot' },\n { display: 'SCARA', value: 'scara' },\n { display: 'Minimal', value: 'minimal' }\n ]\n }\n },\n {\n type: 'select',\n label: 'chain-preset',\n name: 'chainPreset',\n property: {\n options: [\n { display: '6-Axis Industrial', value: '6-axis-industrial' },\n { display: 'Cobot 6-Axis', value: 'cobot-6-axis' },\n { display: 'SCARA 4-Axis', value: 'scara-4-axis' },\n { display: 'Pick & Place 3-Axis', value: 'pick-and-place-3-axis' }\n ]\n }\n },\n { type: 'number', label: 'link-radius', name: 'linkRadius' },\n {\n type: 'select',\n label: 'gripper-type',\n name: 'gripperType',\n property: {\n options: [\n { display: 'Parallel', value: 'parallel' },\n { display: 'Suction', value: 'suction' },\n { display: 'Magnetic', value: 'magnetic' },\n { display: 'Three-Finger', value: 'three-finger' },\n { display: 'None', value: 'none' }\n ]\n }\n },\n { type: 'checkbox', label: 'show-reach-sphere', name: 'showReachSphere' },\n {\n type: 'select',\n label: 'status',\n name: 'status',\n property: {\n options: [\n { display: 'Idle', value: 'idle' },\n { display: 'Moving', value: 'moving' },\n { display: 'Gripping', value: 'gripping' },\n { display: 'Warn', value: 'warn' },\n { display: 'Error', value: 'error' }\n ]\n }\n }\n]\n\n// CarrierHolder + ContainerAbstract: the arm needs the container's child-list\n// machinery (addComponent / reparent / events) AND CarrierHolder's\n// attachPointFor hook. CarrierHolder mixin alone only publishes the attach\n// policy; it doesn't add child management. RectPath(Shape) was wrong here —\n// Shape is a leaf so reparent silently failed. ContainerAbstract provides\n// the missing piece.\n//\n// `ContainerAbstract` (not `Container`) — Container = MixinHTMLElement(ContainerAbstract),\n// which forces `isHTMLElement(): true` and trips the 3D pipeline's\n// addObject DOM-skip gate. Robot arm exists purely in the 3D scene graph\n// (URDF/IK joints, no DOM overlay), so the bare logical container is correct.\n//\n// Mover wraps the chain to publish pick/place/pickAndPlace primitives. It\n// must sit OUTSIDE CarrierHolder because Mover's defaults call this.reparent,\n// which CarrierHolder provides (overrides the base ContainerAbstract\n// version with the attach-frame-aware variant).\n//\n// The instance type cast surfaces Mover's API on `this` so subclass\n// `override` keywords compile and `this.pickAndPlace(...)` resolves —\n// without it, the `as unknown as typeof Component` cast erases all\n// mixin contributions to the static side.\nconst Base = Mover(CarrierHolder(Legendable(Placeable(ContainerAbstract)))) as unknown as typeof Component & {\n new (...args: any[]): Component & {\n isMover: boolean\n pick(carrier: Component, options?: MoveOptions): Promise<void>\n place(carrier: Component, holder: Component, options?: MoveOptions): Promise<void>\n pickAndPlace(carrier: Component, holder: Component, options?: MoveOptions): Promise<void>\n }\n}\n\n@sceneComponent('robot-arm')\nexport default class RobotArm extends Base {\n static legends: Record<string, LegendBinding> = {\n bodyColor: { from: 'status', legend: BODY_LEGEND },\n borderColor: { from: 'status', legend: BORDER_LEGEND },\n lampEmissive: { from: 'status', legend: LAMP_EMISSIVE_LEGEND }\n }\n\n /**\n * Robot arms sit on the floor (or mount to a ceiling/wall — that's a\n * v2 feature). Default depth = operation - floor like other floor-\n * mounted equipment, so the chain reach scales with the configured\n * facility height.\n */\n static placement: PlacementArchetype = 'floor'\n static align: Alignment = 'bottom'\n static defaultDepth = (h: Heights) => h.operation - h.floor\n\n /**\n * Dynamic nature — appends one number property per joint in the active\n * chain. Each property uses the joint's range as `min`/`max` so the\n * property panel can render a constrained slider/spinner. The chain\n * preset can change at runtime, and `get nature()` is re-evaluated\n * whenever the property panel queries it, so the joint count stays in\n * sync with the active preset.\n *\n * For revolute joints the value is in radians; for prismatic, scene units.\n */\n get nature(): ComponentNature {\n const chain = this._activeChain\n // Joint values: revolute = degrees (range usually ±180), prismatic =\n // scene length units. CHAIN_PRESETS already encode revolute ranges in\n // degrees; the 3D side converts to radians at the math boundary.\n const jointProps = chain.map((c, i) => ({\n type: 'number',\n label: `joint-${i + 1}`,\n name: `joint${i}`,\n property: {\n min: c.range[0],\n max: c.range[1],\n step: c.type === 'revolute' ? 1 : 1\n }\n }))\n return {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [...STATIC_PROPERTIES, ...jointProps] as any,\n help: 'scene/component/robot-arm'\n }\n }\n\n /**\n * Resolve the active chain for property-panel introspection. Mirrors\n * the resolution in robot-arm-3d.ts (state.chain wins, else preset,\n * else default 6-axis-industrial). Kept simple — the 3D side does the\n * same logic with depth-based scaling, but for property labeling we\n * only need the structure (axis count + ranges), not absolute lengths.\n */\n private get _activeChain(): ChainElement[] {\n const state = this.state as any\n if (Array.isArray(state.chain) && state.chain.length > 0) return state.chain\n const presetName = (state.chainPreset ?? '6-axis-industrial') as ChainPresetName\n return CHAIN_PRESETS[presetName] ?? CHAIN_PRESETS['6-axis-industrial']\n }\n\n get anchors() {\n return []\n }\n\n /**\n * 2D — base rectangle + a stylized arm silhouette pointing toward the\n * top-right. Just enough to identify the component as a robot arm in\n * plan view; the real visual lives in 3D.\n */\n render(ctx: CanvasRenderingContext2D) {\n const { left = 0, top = 0, width = 100, height = 100 } = this.state\n const bodyFill = pickColor(this.state.fillStyle, (this.state as any).bodyColor, BODY_LEGEND.default)\n const borderColor = pickColor(this.state.strokeStyle, (this.state as any).borderColor, BORDER_LEGEND.default)\n const lineWidth = numOr(this.state.lineWidth, 1)\n\n ctx.beginPath()\n ctx.rect(left, top, width, height)\n ctx.fillStyle = bodyFill\n ctx.fill()\n ctx.strokeStyle = borderColor\n ctx.lineWidth = lineWidth\n ctx.stroke()\n\n // Stylized arm silhouette: base square at center → up → bent right.\n const cx = left + width / 2\n const cy = top + height / 2\n const r = Math.min(width, height) * 0.32\n ctx.save()\n ctx.strokeStyle = borderColor\n ctx.lineWidth = Math.max(lineWidth, Math.min(width, height) * 0.025)\n\n // Base pedestal\n ctx.fillStyle = borderColor\n ctx.fillRect(cx - r * 0.5, cy + r * 0.6, r, r * 0.3)\n // Upper arm\n ctx.beginPath()\n ctx.moveTo(cx, cy + r * 0.6)\n ctx.lineTo(cx, cy - r * 0.2)\n ctx.stroke()\n // Forearm\n ctx.beginPath()\n ctx.moveTo(cx, cy - r * 0.2)\n ctx.lineTo(cx + r * 0.7, cy - r * 0.7)\n ctx.stroke()\n // Joint dots\n ctx.fillStyle = borderColor as string\n ctx.beginPath()\n ctx.arc(cx, cy - r * 0.2, Math.max(2, r * 0.1), 0, Math.PI * 2)\n ctx.fill()\n ctx.beginPath()\n ctx.arc(cx + r * 0.7, cy - r * 0.7, Math.max(1.5, r * 0.08), 0, Math.PI * 2)\n ctx.fill()\n ctx.restore()\n }\n\n onchange(after: Record<string, unknown>, before: Record<string, unknown>) {\n // Per-joint number properties (joint0 … jointN-1) are dynamic; treat\n // any key matching the pattern as a joint update.\n const hasJoint = Object.keys(after).some(k => /^joint\\d+$/.test(k))\n if (\n hasJoint ||\n 'style' in after ||\n 'chainPreset' in after ||\n 'chain' in after ||\n 'joints' in after ||\n 'linkShape' in after ||\n 'jointHousing' in after ||\n 'linkRadius' in after ||\n 'color' in after ||\n 'accentColor' in after ||\n 'fillStyle' in after ||\n 'strokeStyle' in after ||\n 'lineWidth' in after ||\n 'alpha' in after ||\n 'material3d' in after ||\n 'gripper' in after ||\n 'gripperType' in after ||\n 'target' in after ||\n 'showReachSphere' in after ||\n 'status' in after ||\n 'bodyColor' in after ||\n 'borderColor' in after\n ) {\n ;(this as any).clearCache?.('fillStyle')\n this.invalidate()\n }\n super.onchange(after, before)\n }\n\n buildRealObject(): RealObject | undefined {\n return new RobotArm3D(this as any)\n }\n\n /**\n * CarrierHolder hook — return the gripper TCP frame so any Carriable\n * child (parcel/box/pallet/...) mounts onto the moving end-effector.\n * IK rotation propagates to the carrier through Three.js scene-graph.\n *\n * Pose convention (real-world pick-and-place: gripper pointing toward\n * the work, carrier hanging *beyond* the gripper tip):\n *\n * - Frame: TCP (gripper working point — between finger tips for\n * jaws, contact face for suction/magnetic). Built by\n * `RobotArm3D._buildGripper`. TCP's +Z = gripper-forward direction\n * (away from the wrist).\n *\n * - Rotation: x:-π/2 — maps carrier's local +Y axis (\"up\" in the\n * carrier's authored frame) to TCP's -Z direction. With the gripper\n * pointing down (typical work pose), TCP +Z = world -Y (down), so\n * TCP -Z = world +Y (up). Result: carrier's \"up\" stays world-up\n * during transit, and the carrier's body extends from TCP origin\n * in TCP +Z direction (down in world) — i.e. hanging BELOW the\n * gripper, not buried inside it.\n *\n * - Position: z = +halfDepth — places the carrier's TOP face center\n * at the TCP origin (where the fingers grip). Carrier's local +Y\n * extent (top) = halfDepth, which after x:-π/2 rotation maps to\n * TCP -halfDepth Z. Shifting carrier center to TCP +halfDepth Z\n * puts that top point exactly at TCP origin. Carrier body then\n * extends through TCP +Z, ending at TCP +depth (bottom face).\n *\n * Earlier (x:+π/2, z:-halfDepth) inverted the carrier's body direction\n * — body extended back into the wrist, leaving the box visually inside\n * the finger area. The current convention pushes the body OUT past the\n * fingertips, where a real gripper would hold it.\n */\n attachPointFor(carrier: Component) {\n const ro = (this as any)._realObject as RobotArm3D | undefined\n const frame = ro?.getGripperFrame?.()\n if (!frame) return undefined\n const halfDepth = resolveDepth(carrier) / 2\n return {\n attach: frame,\n localPosition: { x: 0, y: 0, z: halfDepth },\n localRotation: { x: -Math.PI / 2, y: 0, z: 0 }\n }\n }\n\n /**\n * Pick: TCP descends vertically onto the carrier's top face, gripper\n * closes, carrier becomes our child.\n *\n * 1. TCP → APPROACH above pick (carrier's xy, +clearance in world Y)\n * 2. TCP → pick (descend straight down to carrier's top face)\n * 3. close gripper + reparent(carrier → this)\n *\n * The approach waypoint exists so the FINAL leg is a clean vertical\n * descent — the gripper enters the carrier from straight above, not a\n * sideways sweep that could clip or grab at a wrong angle.\n *\n * Pose resolution: TCP lands on the CARRIER'S TOP FACE (carrier.world.y +\n * carrier.depth/2). After grip, `attachPointFor`'s `localPosition.z =\n * +halfDepth` keeps the carrier's top at TCP origin during transit —\n * exact, no offset drift.\n *\n * Each waypoint includes the carrier's world yaw so IK can spin joint 5\n * (tool roll) to align the gripper's \"side\" with the carrier's. Without\n * it, reparent at pick instantly snaps the carrier to the gripper's\n * axis, visibly twisting it 0° → up to 360° in one frame.\n *\n * @param options.approachClearance Vertical offset (world units)\n * between approach and pick targets. Default 10.\n * @param options.timeoutMs Per-segment IK timeout (default 15000ms).\n * @param options.reparentDuration Animation duration for reparent (default 800ms).\n */\n override async pick(carrier: Component, options: MoveOptions = {}): Promise<void> {\n const timeoutMs = (options.timeoutMs as number | undefined) ?? 15000\n const reparentDuration = (options.reparentDuration as number | undefined) ?? 800\n const clearance = (options.approachClearance as number | undefined) ?? 10\n // Read carrier height via _realObject.effectiveDepth — `state.depth`\n // is often not explicitly set (carriers like Box rely on\n // `static defaultDepth`), and reading state alone returns 0, which\n // collapses every Y offset and drives the gripper into the carrier's\n // volumetric center instead of its top face.\n const carrierDepth = resolveDepth(carrier)\n const halfDepth = carrierDepth / 2\n const yaw = this._yawOf(carrier)\n const target = this._targetFor(carrier, halfDepth, yaw)\n const approach = this._targetFor(carrier, halfDepth + clearance, yaw)\n\n this.set('target', approach)\n await waitForTcpReached(this, timeoutMs)\n\n this.set('target', target)\n await waitForTcpReached(this, timeoutMs)\n\n ;(this as any).reparent?.(carrier, { animated: true, duration: reparentDuration })\n this.set('gripper', { ...((this.state as any).gripper ?? {}), state: 1 })\n await sleep(reparentDuration)\n }\n\n /**\n * Place: TCP descends vertically over the holder, gripper opens,\n * carrier becomes the holder's child.\n *\n * 1. TCP → APPROACH above place (carrier's xy, +clearance)\n * 2. TCP → place (descend straight down to drop point)\n * 3. open gripper + reparent(carrier → holder)\n *\n * Pose resolution: TCP lands at where the carrier's top WILL BE after\n * the drop, so the carrier lands with its bottom on the holder's attach\n * surface. Computed as `holder.attachFrame.world.y + carrier.depth` (so\n * yOffset = carrierDepth, not halfDepth like pick).\n *\n * @see pick — same option semantics.\n */\n override async place(carrier: Component, holder: Component, options: MoveOptions = {}): Promise<void> {\n const timeoutMs = (options.timeoutMs as number | undefined) ?? 15000\n const reparentDuration = (options.reparentDuration as number | undefined) ?? 800\n const clearance = (options.approachClearance as number | undefined) ?? 10\n const carrierDepth = resolveDepth(carrier)\n const yaw = this._yawOf(holder)\n const target = this._targetFor(holder, carrierDepth, yaw) // top-of-carrier after drop\n const approach = this._targetFor(holder, carrierDepth + clearance, yaw)\n\n this.set('target', approach)\n await waitForTcpReached(this, timeoutMs)\n\n this.set('target', target)\n await waitForTcpReached(this, timeoutMs)\n\n ;(holder as any).reparent?.(carrier, { animated: true, duration: reparentDuration })\n this.set('gripper', { ...((this.state as any).gripper ?? {}), state: 0 })\n await sleep(reparentDuration)\n }\n\n /**\n * `pickAndPlace` is inherited from the `Mover` mixin default — runs\n * `pick(carrier)` then `place(carrier, holder)` sequentially. The\n * decomposition is safe: the carrier's world position only matters\n * during pick (carrier-relative waypoints), and after pick the carrier\n * is the TCP's child (so re-querying it would chase its own tail —\n * which we don't, since place uses holder-relative waypoints only).\n *\n * @example\n * ```ts\n * await robotArm.pickAndPlace(box, spotB)\n * await robotArm.pnp(parcel, palletA, { approachClearance: 30 })\n * ```\n */\n /** Short alias for `pickAndPlace`. Same arguments, same behavior. */\n pnp(carrier: Component, placeHolder: Component, options?: MoveOptions): Promise<void> {\n return this.pickAndPlace(carrier, placeHolder, options)\n }\n\n /**\n * Resolve a TCP position in this arm's chain-local frame.\n *\n * For a CarrierHolder (has `attachPointFor`), uses the holder's own\n * attach frame as the base — that's the canonical \"where carriers\n * sit on me\" point (top of Spot's pad, gripper TCP for another arm,\n * etc.). For a plain carrier, uses its world center.\n *\n * `worldYOffset` is added to the resolved world Y before projecting\n * back to chain-local — used by pickAndPlace to lift the TCP above\n * the target (approach waypoints) and to land it on the carrier's\n * top face rather than its volumetric center.\n */\n private _targetFor(\n component: Component,\n worldYOffset = 0,\n yaw?: number\n ): { x: number; y: number; z: number; yaw?: number } {\n const ro3d = (this as any)._realObject as RobotArm3D | undefined\n\n let baseWp: THREE.Vector3 | undefined\n // Prefer holder's attach frame when available.\n const attachPointFor = (component as any).attachPointFor\n if (typeof attachPointFor === 'function') {\n const point = attachPointFor.call(component, this)\n if (point?.attach) {\n point.attach.updateWorldMatrix?.(true, false)\n baseWp = point.attach.getWorldPosition?.(new THREE.Vector3())\n }\n }\n if (!baseWp) {\n const obj = (component as any)._realObject?.object3d\n if (obj) {\n obj.updateWorldMatrix(true, false)\n baseWp = obj.getWorldPosition(new THREE.Vector3())\n }\n }\n if (!ro3d || !baseWp) {\n // Final fallback: 2D bounds center — only before 3D builds.\n const c = component.center\n return { x: c.x, y: worldYOffset, z: c.y, yaw }\n }\n const local = ro3d.worldToChainLocal(baseWp.x, baseWp.y + worldYOffset, baseWp.z)\n return { x: local.x, y: local.y, z: local.z, yaw }\n }\n\n /**\n * Extract a component's world yaw (rotation around world +Y) from its\n * 3D object's world matrix. Returns 0 if the object isn't built yet.\n * Used by `pickAndPlace` so the gripper can match the carrier's /\n * placeHolder's current orientation — preventing a yaw snap at the\n * moment of reparent.\n */\n private _yawOf(component: Component): number {\n const obj = (component as any)._realObject?.object3d\n if (!obj) return 0\n obj.updateWorldMatrix(true, false)\n const q = new THREE.Quaternion()\n obj.getWorldQuaternion(q)\n const e = new THREE.Euler().setFromQuaternion(q, 'YXZ')\n return e.y\n }\n}\n\n/**\n * Resolve when the robot arm fires `tcp-reached`, reject on timeout.\n * The 3D side fires this event on smoothing completion (last joint\n * value within threshold of its target).\n */\nfunction waitForTcpReached(component: Component, timeoutMs: number): Promise<void> {\n return new Promise((resolve, reject) => {\n let timer: any\n const onReached = () => {\n clearTimeout(timer)\n ;(component as any).off?.('tcp-reached', onReached)\n resolve()\n }\n timer = setTimeout(() => {\n ;(component as any).off?.('tcp-reached', onReached)\n reject(new Error('TCP reach timeout'))\n }, timeoutMs)\n ;(component as any).on?.('tcp-reached', onReached)\n })\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms))\n}\n\nfunction numOr(v: unknown, dflt: number): number {\n return typeof v === 'number' && Number.isFinite(v) ? v : dflt\n}\n\n/**\n * Resolve a component's 3D height. things-scene v10 carriers (Box, Pallet,\n * etc.) typically declare `static defaultDepth` rather than setting\n * `state.depth`, so reading state alone returns 0 — wrong for a\n * default-sized box. The framework resolves the actual value into\n * `_realObject.effectiveDepth`. Falls back to `state.depth` for\n * components built before their RealObject exists.\n */\nfunction resolveDepth(c: Component): number {\n const eff = (c as any)?._realObject?.effectiveDepth\n if (typeof eff === 'number' && Number.isFinite(eff)) return eff\n return numOr((c as any)?.state?.depth, 0)\n}\n\nfunction pickColor(...candidates: unknown[]): string {\n for (const c of candidates) {\n if (typeof c === 'string' && c && c !== 'transparent') return c\n }\n return '#888'\n}\n"]}
@@ -1,4 +1,4 @@
1
- declare const _default: {
1
+ declare const _default: ({
2
2
  type: string;
3
3
  description: string;
4
4
  group: string;
@@ -22,5 +22,31 @@ declare const _default: {
22
22
  underThresholdColor: string;
23
23
  progressThreshold: number;
24
24
  };
25
- }[];
25
+ } | {
26
+ type: string;
27
+ description: string;
28
+ group: string;
29
+ icon: string;
30
+ model: {
31
+ type: string;
32
+ top: number;
33
+ left: number;
34
+ width: number;
35
+ height: number;
36
+ depth: number;
37
+ rotation: number;
38
+ linkRadius: number;
39
+ joint0: number;
40
+ joint1: number;
41
+ joint2: number;
42
+ joint3: number;
43
+ joint4: number;
44
+ joint5: number;
45
+ style: string;
46
+ chainPreset: string;
47
+ gripperType: string;
48
+ showReachSphere: boolean;
49
+ status: string;
50
+ };
51
+ })[];
26
52
  export default _default;
@@ -1,3 +1,4 @@
1
1
  import tactTimer from './tact-timer.js';
2
- export default [tactTimer];
2
+ import robotArm from './robot-arm.js';
3
+ export default [tactTimer, robotArm];
3
4
  //# sourceMappingURL=index.js.map