@operato/scene-storage 10.0.0-beta.33 → 10.0.0-beta.34
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.
- package/CHANGELOG.md +14 -0
- package/dist/crane-3d.d.ts +14 -0
- package/dist/crane-3d.js +238 -0
- package/dist/crane-3d.js.map +1 -0
- package/dist/crane.d.ts +157 -0
- package/dist/crane.js +440 -0
- package/dist/crane.js.map +1 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/mobile-storage-rack.d.ts +17 -0
- package/dist/mobile-storage-rack.js +55 -0
- package/dist/mobile-storage-rack.js.map +1 -0
- package/dist/rack-column.d.ts +35 -0
- package/dist/rack-column.js +258 -0
- package/dist/rack-column.js.map +1 -0
- package/dist/rack-grid-3d.d.ts +13 -0
- package/dist/rack-grid-3d.js +94 -0
- package/dist/rack-grid-3d.js.map +1 -0
- package/dist/rack-grid-cell.d.ts +341 -0
- package/dist/rack-grid-cell.js +321 -0
- package/dist/rack-grid-cell.js.map +1 -0
- package/dist/rack-grid-helpers.d.ts +28 -0
- package/dist/rack-grid-helpers.js +71 -0
- package/dist/rack-grid-helpers.js.map +1 -0
- package/dist/rack-grid-location.d.ts +37 -0
- package/dist/rack-grid-location.js +227 -0
- package/dist/rack-grid-location.js.map +1 -0
- package/dist/rack-grid.d.ts +80 -0
- package/dist/rack-grid.js +829 -0
- package/dist/rack-grid.js.map +1 -0
- package/dist/stock.d.ts +78 -0
- package/dist/stock.js +333 -0
- package/dist/stock.js.map +1 -0
- package/dist/{rack-cell-3d.d.ts → storage-cell-3d.d.ts} +1 -1
- package/dist/{rack-cell-3d.js → storage-cell-3d.js} +3 -3
- package/dist/storage-cell-3d.js.map +1 -0
- package/dist/{rack-cell.d.ts → storage-cell.d.ts} +12 -6
- package/dist/{rack-cell.js → storage-cell.js} +9 -9
- package/dist/storage-cell.js.map +1 -0
- package/dist/{asrs-rack-3d.d.ts → storage-rack-3d.d.ts} +1 -1
- package/dist/{asrs-rack-3d.js → storage-rack-3d.js} +4 -4
- package/dist/storage-rack-3d.js.map +1 -0
- package/dist/{asrs-rack.d.ts → storage-rack.d.ts} +22 -16
- package/dist/{asrs-rack.js → storage-rack.js} +32 -26
- package/dist/storage-rack.js.map +1 -0
- package/dist/templates/index.d.ts +60 -0
- package/dist/templates/index.js +59 -17
- package/dist/templates/index.js.map +1 -1
- package/package.json +2 -2
- package/src/crane-3d.ts +273 -0
- package/src/crane.ts +538 -0
- package/src/index.ts +13 -6
- package/src/mobile-storage-rack.ts +56 -0
- package/src/rack-column.ts +340 -0
- package/src/rack-grid-3d.ts +128 -0
- package/src/rack-grid-cell.ts +404 -0
- package/src/rack-grid-helpers.ts +77 -0
- package/src/rack-grid-location.ts +286 -0
- package/src/rack-grid.ts +994 -0
- package/src/stock.ts +426 -0
- package/src/{rack-cell-3d.ts → storage-cell-3d.ts} +2 -2
- package/src/{rack-cell.ts → storage-cell.ts} +19 -13
- package/src/{asrs-rack-3d.ts → storage-rack-3d.ts} +3 -3
- package/src/{asrs-rack.ts → storage-rack.ts} +31 -25
- package/src/templates/index.ts +59 -17
- package/test/test-rack-grid-crane.ts +212 -0
- package/test/test-rack-grid.ts +77 -0
- package/test/{test-asrs-crane.ts → test-storage-rack-crane.ts} +8 -8
- package/translations/en.json +55 -7
- package/translations/ja.json +52 -4
- package/translations/ko.json +52 -4
- package/translations/ms.json +55 -7
- package/translations/zh.json +52 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/asrs-crane-3d.d.ts +0 -17
- package/dist/asrs-crane-3d.js +0 -181
- package/dist/asrs-crane-3d.js.map +0 -1
- package/dist/asrs-crane.d.ts +0 -98
- package/dist/asrs-crane.js +0 -216
- package/dist/asrs-crane.js.map +0 -1
- package/dist/asrs-rack-3d.js.map +0 -1
- package/dist/asrs-rack.js.map +0 -1
- package/dist/rack-cell-3d.js.map +0 -1
- package/dist/rack-cell.js.map +0 -1
- package/src/asrs-crane-3d.ts +0 -211
- package/src/asrs-crane.ts +0 -275
- /package/icons/{asrs-crane.png → crane.png} +0 -0
- /package/icons/{asrs-rack.png → storage-rack.png} +0 -0
package/src/crane.ts
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { Component, ComponentNature, ContainerAbstract, ContainerCapacity, RealObject, sceneComponent } from '@hatiolab/things-scene'
|
|
5
|
+
import type { SlotDef, State, Material3D } from '@hatiolab/things-scene'
|
|
6
|
+
import {
|
|
7
|
+
CarrierHolder,
|
|
8
|
+
Legendable,
|
|
9
|
+
Mover,
|
|
10
|
+
Placeable,
|
|
11
|
+
type AttachFrame,
|
|
12
|
+
type Alignment,
|
|
13
|
+
type Heights,
|
|
14
|
+
type LegendBinding,
|
|
15
|
+
type MoveOptions,
|
|
16
|
+
type PlacementArchetype
|
|
17
|
+
} from '@operato/scene-base'
|
|
18
|
+
|
|
19
|
+
import { Crane3D } from './crane-3d.js'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Crane status — the operating state of a stacker crane.
|
|
23
|
+
*
|
|
24
|
+
* - `idle` — parked at home position
|
|
25
|
+
* - `moving` — translating (horizontal) or along the mast (vertical);
|
|
26
|
+
* typically combined
|
|
27
|
+
* - `loading` — extracting a carrier from a rack cell
|
|
28
|
+
* - `unloading` — placing a carrier into a rack cell
|
|
29
|
+
* - `error` — fault / e-stop / collision warning
|
|
30
|
+
*/
|
|
31
|
+
export type CraneStatus = 'idle' | 'moving' | 'loading' | 'unloading' | 'error'
|
|
32
|
+
|
|
33
|
+
/** Crane 컴포넌트 state */
|
|
34
|
+
export interface CraneState extends State {
|
|
35
|
+
// ── 운영 상태 ──
|
|
36
|
+
status?: CraneStatus
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Crane 이 서비스 할 타깃 컴포넌트의 refid (또는 id).
|
|
40
|
+
* 명시되면 그 컴포넌트 (또는 그 children) 의 위치를 stop point 로 사용 — heuristic
|
|
41
|
+
* 으로 sibling 추정 안 함. 미명시면 sibling 안에서 추측.
|
|
42
|
+
* 예: RackGrid 의 refid 를 지정하면 그 안의 cell 들 사이에서만 이동.
|
|
43
|
+
*/
|
|
44
|
+
target?: string
|
|
45
|
+
|
|
46
|
+
// ── 액추에이터 ──
|
|
47
|
+
/** 마스트 따라 carriage 의 수직 위치 (mm). */
|
|
48
|
+
carriageHeight?: number
|
|
49
|
+
/**
|
|
50
|
+
* Fork prong 의 최대 신축 가능 길이 (mm). cell 깊이 + 여유.
|
|
51
|
+
* 일반적으로 pallet 깊이 (1200mm) + 여유 ≈ 1300mm 또는 그 이하 (default 600).
|
|
52
|
+
*/
|
|
53
|
+
forkLength?: number
|
|
54
|
+
/**
|
|
55
|
+
* Fork 의 *현재 신축 거리* (mm). 0 = collapsed (shuttle 안 들어가있음),
|
|
56
|
+
* forkLength = fully extended (cell 안 carrier 의 fork pocket 도달).
|
|
57
|
+
*
|
|
58
|
+
* 시뮬레이션 흐름:
|
|
59
|
+
* idle: 0
|
|
60
|
+
* approach → 0
|
|
61
|
+
* pick / place: 0 → forkLength (extending) → 0 (retracting with carrier)
|
|
62
|
+
*/
|
|
63
|
+
forkExtension?: number
|
|
64
|
+
/**
|
|
65
|
+
* Fork 의 *carrier 들어올림 높이* (mm). 0 = neutral (cell shelf 와 같은 면),
|
|
66
|
+
* +값 = carrier 를 *위로* 들어올림 (fork pocket 안으로 진입 후 위로 lifting).
|
|
67
|
+
*/
|
|
68
|
+
forkLift?: number
|
|
69
|
+
|
|
70
|
+
// ── 3D 재질 ──
|
|
71
|
+
material3d?: Material3D
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const BODY_LEGEND = {
|
|
75
|
+
idle: '#888',
|
|
76
|
+
moving: '#aabbcc',
|
|
77
|
+
loading: '#ffaa00',
|
|
78
|
+
unloading: '#ffaa00',
|
|
79
|
+
error: '#c66',
|
|
80
|
+
default: '#888'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const LAMP_EMISSIVE_LEGEND = {
|
|
84
|
+
idle: '#222222',
|
|
85
|
+
moving: '#44ff44',
|
|
86
|
+
loading: '#ffaa00',
|
|
87
|
+
unloading: '#ffaa00',
|
|
88
|
+
error: '#ff3333',
|
|
89
|
+
default: '#222222'
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const NATURE: ComponentNature = {
|
|
93
|
+
mutable: false,
|
|
94
|
+
resizable: true,
|
|
95
|
+
rotatable: true,
|
|
96
|
+
properties: [
|
|
97
|
+
{
|
|
98
|
+
type: 'select',
|
|
99
|
+
label: 'status',
|
|
100
|
+
name: 'status',
|
|
101
|
+
property: {
|
|
102
|
+
options: [
|
|
103
|
+
{ display: 'Idle', value: 'idle' },
|
|
104
|
+
{ display: 'Moving', value: 'moving' },
|
|
105
|
+
{ display: 'Loading', value: 'loading' },
|
|
106
|
+
{ display: 'Unloading', value: 'unloading' },
|
|
107
|
+
{ display: 'Error', value: 'error' }
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
type: 'string',
|
|
113
|
+
label: 'target',
|
|
114
|
+
name: 'target',
|
|
115
|
+
placeholder: 'refid of target (e.g., a RackGrid) — crane serves only its cells'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
type: 'number',
|
|
119
|
+
label: 'carriage-height',
|
|
120
|
+
name: 'carriageHeight',
|
|
121
|
+
placeholder: 'mm — height of carriage on mast'
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
type: 'number',
|
|
125
|
+
label: 'fork-length',
|
|
126
|
+
name: 'forkLength',
|
|
127
|
+
placeholder: 'mm — fork prong 최대 신축 길이 (default 600)'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: 'number',
|
|
131
|
+
label: 'fork-extension',
|
|
132
|
+
name: 'forkExtension',
|
|
133
|
+
placeholder: 'mm — 현재 신축 거리 (0 = collapsed)'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: 'number',
|
|
137
|
+
label: 'fork-lift',
|
|
138
|
+
name: 'forkLift',
|
|
139
|
+
placeholder: 'mm — carrier 들어올림 높이 (+ 위로)'
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
help: 'scene/component/crane'
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Mixin chain: Mover → CarrierHolder → ContainerCapacity → Legendable → Placeable → ContainerAbstract
|
|
146
|
+
//
|
|
147
|
+
// Mover: pick / place / pickAndPlace / moveTo / engage primitives
|
|
148
|
+
// CarrierHolder: attachPointFor() — where the carrier sits on the crane (carriage fork)
|
|
149
|
+
// ContainerCapacity: receive() / dispatch() / canReceive() / slots — slot tracking +
|
|
150
|
+
// TRANSFER_SLOT_KEY bookkeeping during transit
|
|
151
|
+
// Legendable: status → bodyColor / lampEmissive colour mapping
|
|
152
|
+
// Placeable: floor-archetype 3D positioning
|
|
153
|
+
// ContainerAbstract: child management — carrier becomes a child while in transit
|
|
154
|
+
//
|
|
155
|
+
// Note: ContainerAbstract replaces Shape. The 2D outline is drawn manually in
|
|
156
|
+
// render() below (a simple top-down rectangle), matching the old Shape output
|
|
157
|
+
// without the Shape base-class overhead.
|
|
158
|
+
/**
|
|
159
|
+
* Crane — a stacker / retrieval picker. Picker contract instance.
|
|
160
|
+
*
|
|
161
|
+
* Moves carriers between rack cells (or any Placeable target). The crane
|
|
162
|
+
* is *picker-side* of the Phase G/H Pickable contract — it knows how to
|
|
163
|
+
* `pick(carrier)` / `place(carrier, target)` and `engage(target, kind)`
|
|
164
|
+
* to align its actuators. It is *storage-agnostic* — any Rack / Cell /
|
|
165
|
+
* Spot / Conveyor that implements the receive/dispatch protocol is a
|
|
166
|
+
* valid target.
|
|
167
|
+
*
|
|
168
|
+
* Structure: a tall vertical mast that translates horizontally on a rail
|
|
169
|
+
* or free floor path, with a carriage that slides up/down the mast carrying
|
|
170
|
+
* a shuttle / forks.
|
|
171
|
+
*
|
|
172
|
+
* **Monitoring mode**: crane status is driven by external data binding
|
|
173
|
+
* (`state.status`, `state.carriageHeight`). The carrier is referenced
|
|
174
|
+
* via data binding — it is NOT a child of the crane in monitoring mode.
|
|
175
|
+
*
|
|
176
|
+
* **Simulation mode**: call `crane.pick(carrier)` / `crane.place(carrier, target)`
|
|
177
|
+
* (or `crane.pickAndPlace(carrier, target)`). Mover handles navigation +
|
|
178
|
+
* engage + reparent. During transit the carrier IS a child of the crane.
|
|
179
|
+
*/
|
|
180
|
+
@sceneComponent('crane')
|
|
181
|
+
export default class Crane extends Mover(CarrierHolder(ContainerCapacity(Legendable(Placeable(ContainerAbstract))))) {
|
|
182
|
+
declare state: CraneState
|
|
183
|
+
declare _realObject?: Crane3D
|
|
184
|
+
|
|
185
|
+
static legends: Record<string, LegendBinding> = {
|
|
186
|
+
bodyColor: { from: 'status', legend: BODY_LEGEND },
|
|
187
|
+
lampEmissive: { from: 'status', legend: LAMP_EMISSIVE_LEGEND }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static placement: PlacementArchetype = 'floor'
|
|
191
|
+
static align: Alignment = 'bottom'
|
|
192
|
+
static defaultDepth = (h: Heights) => h.ceiling - h.floor
|
|
193
|
+
|
|
194
|
+
/** Yaw offset: crane model is drawn with the rail axis along X (right = forward). */
|
|
195
|
+
static yawOffset = 0
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Phase H — the crane uses telescoping forks to pick up a carrier in a rack
|
|
199
|
+
* cell. Same mechanism as a forklift fork — engages the pallet's fork pocket.
|
|
200
|
+
* (Mover mixin chain is `: any` so override keyword is not usable, only the
|
|
201
|
+
* getter is defined.)
|
|
202
|
+
*/
|
|
203
|
+
get toolType(): string {
|
|
204
|
+
return 'forklift-fork'
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
get nature() {
|
|
208
|
+
return NATURE
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
get anchors() {
|
|
212
|
+
return []
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ── ContainerCapacity ─────────────────────────────────────────────────────
|
|
216
|
+
|
|
217
|
+
/** Stacker crane carries at most one load at a time on its forks. */
|
|
218
|
+
get slots(): SlotDef[] {
|
|
219
|
+
return [{ id: 'forks', maxCount: 1 }]
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ── CarrierHolder — attach frame (carriage fork position) ─────────────────
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Return the 3D attach frame on the crane's carriage (fork tip).
|
|
226
|
+
* Carriers are attached here while the crane is in transit (pick phase).
|
|
227
|
+
*
|
|
228
|
+
* The Crane3D exposes `getCarriageFrame()` — a sub-Object3D that
|
|
229
|
+
* tracks the carriage height and sits at the fork TCP. If the 3D object
|
|
230
|
+
* isn't built yet (e.g. before scene initialization), fall back to the
|
|
231
|
+
* crane's own object3d centre.
|
|
232
|
+
*/
|
|
233
|
+
attachPointFor(carrier: Component): AttachFrame | null {
|
|
234
|
+
const ro = this._realObject
|
|
235
|
+
const frame = ro?.getCarriageFrame?.()
|
|
236
|
+
if (frame) {
|
|
237
|
+
const carrierDepth = resolveCarrierDepth(carrier)
|
|
238
|
+
// fork blade 위 (top surface) 에 pallet pocket 끼우듯 얹힘. y = blade top + carrier/2.
|
|
239
|
+
// z = blade 중심 (forkLength 의 반쪽 위치 — pallet center 가 blade 중간에 위치).
|
|
240
|
+
const platformTopY = ro?.platformTopY ?? 0
|
|
241
|
+
const bladeMidZ = ro?.bladeMidZ ?? 0
|
|
242
|
+
return {
|
|
243
|
+
attach: frame,
|
|
244
|
+
localPosition: { x: 0, y: platformTopY + carrierDepth / 2, z: bladeMidZ }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const root = this._realObject?.object3d
|
|
248
|
+
if (!root) return null
|
|
249
|
+
return { attach: root }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ── Mover overrides ───────────────────────────────────────────────────────
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Domain-specific actuation between arrival and reparent.
|
|
256
|
+
*
|
|
257
|
+
* Simulation sequence for PICK:
|
|
258
|
+
* 1. Mover.pick() navigates crane to carrier position (moveTo).
|
|
259
|
+
* 2. engage('pick') → snap carriage height + status 'loading'.
|
|
260
|
+
* 3. Carrier is reparented to crane (becomes child).
|
|
261
|
+
*
|
|
262
|
+
* For now: set status and snap carriage height. A full simulation
|
|
263
|
+
* would tween the carriageHeight here (animate Crane3D).
|
|
264
|
+
*
|
|
265
|
+
* Status lifecycle:
|
|
266
|
+
* idle → (moveTo running) → engage fires → loading/unloading → (reparent) → idle
|
|
267
|
+
* The 'moving' state is not set from Mover.moveTo() because TypeScript
|
|
268
|
+
* can't call super.moveTo() on an `: any`-typed mixin. External data
|
|
269
|
+
* binding sets 'moving' in monitoring mode; override pick()/place() to
|
|
270
|
+
* set it in full simulation environments.
|
|
271
|
+
*/
|
|
272
|
+
async engage(
|
|
273
|
+
target: Component,
|
|
274
|
+
kind: 'pick' | 'place',
|
|
275
|
+
_options: MoveOptions = {}
|
|
276
|
+
): Promise<void> {
|
|
277
|
+
if (kind === 'pick') {
|
|
278
|
+
this.setState({ status: 'loading' as CraneStatus })
|
|
279
|
+
const carrierY = resolveCarrierCenterY(target)
|
|
280
|
+
if (carrierY !== null) {
|
|
281
|
+
this.setState({ carriageHeight: carrierY })
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
this.setState({ status: 'unloading' as CraneStatus })
|
|
285
|
+
}
|
|
286
|
+
// In a full simulation: await carriage-motion tween here.
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// ── Domain aliases ────────────────────────────────────────────────────────
|
|
290
|
+
|
|
291
|
+
/** Fetch a carrier from a rack cell (semantically = pick). */
|
|
292
|
+
fetch(carrier: Component, options?: MoveOptions): Promise<void> {
|
|
293
|
+
return this.pick(carrier, options)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Deposit a carrier into a rack cell (semantically = place). */
|
|
297
|
+
deposit(carrier: Component, cell: Component, options?: MoveOptions): Promise<void> {
|
|
298
|
+
return this.place(carrier, cell, options)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// ── 2D rendering ─────────────────────────────────────────────────────────
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 2D — top-down rectangle showing the crane's footprint along the rail.
|
|
305
|
+
* The crane is much taller than wide, so the 2D mark is small.
|
|
306
|
+
*/
|
|
307
|
+
render(ctx: CanvasRenderingContext2D) {
|
|
308
|
+
const { width, height, left, top } = this.state
|
|
309
|
+
const fillColor = (this.state.bodyColor as string) || '#888'
|
|
310
|
+
ctx.save()
|
|
311
|
+
ctx.fillStyle = fillColor
|
|
312
|
+
ctx.beginPath()
|
|
313
|
+
ctx.rect(left, top, width, height)
|
|
314
|
+
ctx.fill()
|
|
315
|
+
ctx.restore()
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ── 3D ───────────────────────────────────────────────────────────────────
|
|
319
|
+
|
|
320
|
+
buildRealObject(): RealObject | undefined {
|
|
321
|
+
if (!this._simStarted) {
|
|
322
|
+
this._simStarted = true
|
|
323
|
+
// 초기 지연 800~2800ms 사이 random — 여러 crane 이 동기적으로 시작하지 않도록.
|
|
324
|
+
const initialDelay = 800 + Math.random() * 2000
|
|
325
|
+
setTimeout(() => {
|
|
326
|
+
this.simulate().catch(e => console.error('[Crane] simulate', e))
|
|
327
|
+
}, initialDelay)
|
|
328
|
+
}
|
|
329
|
+
return new Crane3D(this)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ── Random animation (visual smoke test) ─────────────────────────────────
|
|
333
|
+
// things-scene 의 component.animate() (frameClock 기반, pause/speed 대응) 를 사용.
|
|
334
|
+
|
|
335
|
+
private _simStarted = false
|
|
336
|
+
private _simRunning = false
|
|
337
|
+
private _simAbort = false
|
|
338
|
+
// Rail = crane 의 *로컬 X 축* (state.rotation 적용). simulate 진입 시 1회 계산해서 캐시.
|
|
339
|
+
private _railOriginX = 0
|
|
340
|
+
private _railOriginY = 0
|
|
341
|
+
private _railCos = 1
|
|
342
|
+
private _railSin = 0
|
|
343
|
+
private _railMin = NaN // local-X 축 rail offset min
|
|
344
|
+
private _railMax = NaN // local-X 축 rail offset max
|
|
345
|
+
private _targetSide = 1 // +Z (fork +Z 로 뻗어야 하나) / -Z
|
|
346
|
+
|
|
347
|
+
/** Continuous random pick → transport → place cycles. Visual smoke test. */
|
|
348
|
+
async simulate(): Promise<void> {
|
|
349
|
+
if (this._simRunning) return
|
|
350
|
+
this._simRunning = true
|
|
351
|
+
this._simAbort = false
|
|
352
|
+
try {
|
|
353
|
+
this._initRailRange()
|
|
354
|
+
while (!this._simAbort) {
|
|
355
|
+
await this._oneCycle()
|
|
356
|
+
}
|
|
357
|
+
} finally {
|
|
358
|
+
this._simRunning = false
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* state.target bbox 를 crane 의 *로컬 X 축* 으로 projection 해서 rail range 1회 계산.
|
|
364
|
+
* Rotation 적용된 crane 의 local X (= rail) 방향으로 움직이도록 cos/sin 캐시.
|
|
365
|
+
*/
|
|
366
|
+
private _initRailRange(): void {
|
|
367
|
+
this._railMin = this._railMax = NaN
|
|
368
|
+
|
|
369
|
+
// 1순위: state.target refid 로 명시. 2순위: crane 의 parent 컴포넌트 (자연스러운
|
|
370
|
+
// "이 컨테이너 안에서만 움직여" 기본값).
|
|
371
|
+
const targetRefId = (this.state as any).target as string | undefined
|
|
372
|
+
const root = (this as any).root
|
|
373
|
+
let target = targetRefId ? root?.findById?.(targetRefId) : null
|
|
374
|
+
if (!target) {
|
|
375
|
+
const parent = (this as any).parent
|
|
376
|
+
// parent 가 root/model-layer 같은 top-level 이면 bbox 가 의미없음 → skip
|
|
377
|
+
if (parent && parent !== root && (parent.state as any)?.width > 0) {
|
|
378
|
+
target = parent
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (!target) return
|
|
382
|
+
|
|
383
|
+
const tState = target.state ?? {}
|
|
384
|
+
const tl = numOr(tState.left, 0)
|
|
385
|
+
const tt = numOr(tState.top, 0)
|
|
386
|
+
const tw = numOr(tState.width, 0)
|
|
387
|
+
const th = numOr(tState.height, 0)
|
|
388
|
+
if (tw <= 0 || th <= 0) return
|
|
389
|
+
|
|
390
|
+
const W = numOr((this.state as any).width, 100)
|
|
391
|
+
const H = numOr((this.state as any).height, 100)
|
|
392
|
+
const rotation = numOr((this.state as any).rotation, 0)
|
|
393
|
+
const cos = Math.cos(rotation)
|
|
394
|
+
const sin = Math.sin(rotation)
|
|
395
|
+
|
|
396
|
+
// Rail origin = crane 의 현재 canvas center. 이 점에서 local X 방향으로 ±rail offset.
|
|
397
|
+
this._railOriginX = numOr((this.state as any).left, 0) + W / 2
|
|
398
|
+
this._railOriginY = numOr((this.state as any).top, 0) + H / 2
|
|
399
|
+
this._railCos = cos
|
|
400
|
+
this._railSin = sin
|
|
401
|
+
|
|
402
|
+
// Target bbox 4 corner 를 crane local frame 으로 projection.
|
|
403
|
+
// local X (rail) = dx*cos + dy*sin
|
|
404
|
+
// local Z (aisle) = -dx*sin + dy*cos
|
|
405
|
+
const corners = [
|
|
406
|
+
{ x: tl, y: tt },
|
|
407
|
+
{ x: tl + tw, y: tt },
|
|
408
|
+
{ x: tl, y: tt + th },
|
|
409
|
+
{ x: tl + tw, y: tt + th }
|
|
410
|
+
]
|
|
411
|
+
let minRail = Infinity
|
|
412
|
+
let maxRail = -Infinity
|
|
413
|
+
let aisleSum = 0
|
|
414
|
+
for (const c of corners) {
|
|
415
|
+
const dx = c.x - this._railOriginX
|
|
416
|
+
const dy = c.y - this._railOriginY
|
|
417
|
+
const rail = dx * cos + dy * sin
|
|
418
|
+
const aisle = -dx * sin + dy * cos
|
|
419
|
+
if (rail < minRail) minRail = rail
|
|
420
|
+
if (rail > maxRail) maxRail = rail
|
|
421
|
+
aisleSum += aisle
|
|
422
|
+
}
|
|
423
|
+
// Crane 자체 W 만큼 안쪽으로 좁혀 — crane center 가 [minRail+W/2, maxRail-W/2] 안에
|
|
424
|
+
// 있으면 crane 전체가 target bbox 안 (local X 방향).
|
|
425
|
+
this._railMin = minRail + W / 2
|
|
426
|
+
this._railMax = Math.max(this._railMin, maxRail - W / 2)
|
|
427
|
+
this._targetSide = aisleSum >= 0 ? +1 : -1
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
stopSimulate(): void {
|
|
431
|
+
this._simAbort = true
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private async _oneCycle(): Promise<void> {
|
|
435
|
+
const W = numOr((this.state as any).width, 100)
|
|
436
|
+
const H = numOr((this.state as any).height, 100)
|
|
437
|
+
const D = numOr((this.state as any).depth, W * 4)
|
|
438
|
+
const forkLen = numOr((this.state as any).forkLength, H * 0.6)
|
|
439
|
+
|
|
440
|
+
if (!Number.isFinite(this._railMin) || !Number.isFinite(this._railMax)) {
|
|
441
|
+
await new Promise(r => setTimeout(r, 800))
|
|
442
|
+
return
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const pickRail = () => this._railMin + Math.random() * Math.max(0, this._railMax - this._railMin)
|
|
446
|
+
const toLeftTop = (rail: number) => ({
|
|
447
|
+
left: this._railOriginX + rail * this._railCos - W / 2,
|
|
448
|
+
top: this._railOriginY + rail * this._railSin - H / 2
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
const source = toLeftTop(pickRail())
|
|
452
|
+
const dest = toLeftTop(pickRail())
|
|
453
|
+
|
|
454
|
+
const sourceCH = Math.random() * D * 0.75
|
|
455
|
+
const destCH = Math.random() * D * 0.75
|
|
456
|
+
const liftH = Math.max(20, D * 0.02)
|
|
457
|
+
const side = this._targetSide
|
|
458
|
+
|
|
459
|
+
// Tween duration 은 base 의 70~130% 사이 random — 여러 crane 이 같은 타이밍으로 안 보이도록.
|
|
460
|
+
const jitter = (base: number): number => base * (0.7 + Math.random() * 0.6)
|
|
461
|
+
|
|
462
|
+
// 이동: crane local X 방향 → canvas (left, top) 둘 다 동시 변경 (rotation 적용 시 diagonal)
|
|
463
|
+
await this._tween({ status: 'moving', left: source.left, top: source.top, carriageHeight: sourceCH }, jitter(1500))
|
|
464
|
+
await this._tween({ status: 'loading', forkExtension: side * forkLen }, jitter(700))
|
|
465
|
+
await this._tween({ forkLift: liftH }, jitter(400))
|
|
466
|
+
await this._tween({ forkExtension: 0 }, jitter(700))
|
|
467
|
+
await this._tween({ status: 'moving', left: dest.left, top: dest.top, carriageHeight: destCH }, jitter(1500))
|
|
468
|
+
await this._tween({ status: 'unloading', forkExtension: side * forkLen }, jitter(700))
|
|
469
|
+
await this._tween({ forkLift: 0 }, jitter(400))
|
|
470
|
+
await this._tween({ status: 'idle', forkExtension: 0 }, jitter(700))
|
|
471
|
+
|
|
472
|
+
// 사이클 사이 짧은 idle (200~1000ms) — 자연스러운 phase 분산
|
|
473
|
+
await new Promise(r => setTimeout(r, 200 + Math.random() * 800))
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* things-scene 의 `component.animate()` 로 한 구간 tween. step 콜백에서 setState 호출.
|
|
478
|
+
* frameClock.simTime 기반이라 scene pause / speed change / suppressAnimations 모두 자동 대응.
|
|
479
|
+
*/
|
|
480
|
+
private _tween(targets: Record<string, any>, duration: number): Promise<void> {
|
|
481
|
+
const start: Record<string, number> = {}
|
|
482
|
+
for (const k of Object.keys(targets)) {
|
|
483
|
+
if (k === 'status') continue
|
|
484
|
+
const v = (this.state as any)[k]
|
|
485
|
+
start[k] = typeof v === 'number' && Number.isFinite(v) ? v : 0
|
|
486
|
+
}
|
|
487
|
+
if (typeof targets.status === 'string') {
|
|
488
|
+
this.setState({ status: targets.status })
|
|
489
|
+
}
|
|
490
|
+
return new Promise<void>(resolve => {
|
|
491
|
+
let resolved = false
|
|
492
|
+
const finish = () => {
|
|
493
|
+
if (resolved) return
|
|
494
|
+
resolved = true
|
|
495
|
+
resolve()
|
|
496
|
+
}
|
|
497
|
+
const controller = (this as any).animate({
|
|
498
|
+
duration,
|
|
499
|
+
ease: 'inout',
|
|
500
|
+
delta: 'quad',
|
|
501
|
+
step: (dx: number) => {
|
|
502
|
+
if (this._simAbort) {
|
|
503
|
+
controller.stop?.()
|
|
504
|
+
return finish()
|
|
505
|
+
}
|
|
506
|
+
const update: Record<string, number> = {}
|
|
507
|
+
for (const k of Object.keys(start)) {
|
|
508
|
+
const tgt = targets[k]
|
|
509
|
+
if (typeof tgt !== 'number') continue
|
|
510
|
+
update[k] = start[k] + (tgt - start[k]) * dx
|
|
511
|
+
}
|
|
512
|
+
this.setState(update as any)
|
|
513
|
+
},
|
|
514
|
+
onComplete: finish
|
|
515
|
+
})
|
|
516
|
+
controller.start()
|
|
517
|
+
})
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function resolveCarrierDepth(c: Component): number {
|
|
522
|
+
const eff = (c as any)._realObject?.effectiveDepth
|
|
523
|
+
if (typeof eff === 'number' && Number.isFinite(eff)) return eff
|
|
524
|
+
return numOr((c as any)?.state?.depth, 0)
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function resolveCarrierCenterY(c: Component): number | null {
|
|
528
|
+
const pos = (c as any).state
|
|
529
|
+
if (!pos) return null
|
|
530
|
+
// zPos is the 3D Y center of a Placeable component in things-scene
|
|
531
|
+
const zPos = numOr(pos.zPos, NaN)
|
|
532
|
+
if (!Number.isNaN(zPos)) return zPos
|
|
533
|
+
return null
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function numOr(v: unknown, dflt: number): number {
|
|
537
|
+
return typeof v === 'number' && Number.isFinite(v) ? v : dflt
|
|
538
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,12 +9,19 @@ export type { BoxMaterial } from './box.js'
|
|
|
9
9
|
|
|
10
10
|
export { default as Parcel } from './parcel.js'
|
|
11
11
|
|
|
12
|
-
export { default as
|
|
13
|
-
export {
|
|
14
|
-
export
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export
|
|
12
|
+
export { default as StorageRack } from './storage-rack.js'
|
|
13
|
+
export type { StorageRackState } from './storage-rack.js'
|
|
14
|
+
export { StorageRack3D } from './storage-rack-3d.js'
|
|
15
|
+
export { default as RackGrid } from './rack-grid.js'
|
|
16
|
+
export type { RackGridState } from './rack-grid.js'
|
|
17
|
+
export { RackGrid3D } from './rack-grid-3d.js'
|
|
18
|
+
export { default as MobileStorageRack } from './mobile-storage-rack.js'
|
|
19
|
+
export { default as StorageCell } from './storage-cell.js'
|
|
20
|
+
export type { StorageCellType } from './storage-cell.js'
|
|
21
|
+
export { StorageCell3D } from './storage-cell-3d.js'
|
|
22
|
+
export { default as Crane } from './crane.js'
|
|
23
|
+
export type { CraneState, CraneStatus } from './crane.js'
|
|
24
|
+
export { Crane3D } from './crane-3d.js'
|
|
18
25
|
|
|
19
26
|
export { default as Spot } from './spot.js'
|
|
20
27
|
export { Spot3D } from './spot-3d.js'
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* MobileRack — a Rack that can also move.
|
|
5
|
+
*
|
|
6
|
+
* The whole point of the storage abstraction: `Mover(Rack)` mixin gives a
|
|
7
|
+
* *moving storage* without changing Rack's role. Use cases — an AGV-mounted
|
|
8
|
+
* rack, a cart, a tote-on-conveyor, a mobile shelving unit, etc.
|
|
9
|
+
*
|
|
10
|
+
* The cells, the cell-map topology, the Pickable contract, the carrier
|
|
11
|
+
* attach-point — all unchanged. Only thing added: the rack can `moveTo(...)`,
|
|
12
|
+
* `pick(...)`, `place(...)`, `pickAndPlace(...)`.
|
|
13
|
+
*
|
|
14
|
+
* Component type: `mobile-rack`. Use `<mobile-rack levels=...>` on the
|
|
15
|
+
* board same as a Rack; pickers (Crane / Forklift / robot arm) interact
|
|
16
|
+
* with its cells via the same RackCell-side contract.
|
|
17
|
+
*
|
|
18
|
+
* Note: a moving rack is itself a *picker target* from another picker's
|
|
19
|
+
* point of view — the same RackCell.acceptanceRotation contract applies
|
|
20
|
+
* because cells, not racks, are the picker's interlocutor.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { Component, ContainerCapacity, sceneComponent } from '@hatiolab/things-scene'
|
|
24
|
+
import type { SlotDef } from '@hatiolab/things-scene'
|
|
25
|
+
import { Mover } from '@operato/scene-base'
|
|
26
|
+
|
|
27
|
+
import StorageRack from './storage-rack.js'
|
|
28
|
+
|
|
29
|
+
// `Mover(Rack)` adds moveTo / pick / place / engage. `ContainerCapacity` is
|
|
30
|
+
// also added so the rack itself participates in slot bookkeeping when it
|
|
31
|
+
// behaves as a (mobile) carrier holder during transit. Rack already extends
|
|
32
|
+
// `CarrierHolder + Placeable`, so the full chain becomes:
|
|
33
|
+
// Mover → ContainerCapacity → Rack(=CellContainer → CarrierHolder → Placeable → ContainerAbstract)
|
|
34
|
+
@sceneComponent('mobile-storage-rack')
|
|
35
|
+
export default class MobileRack extends Mover(ContainerCapacity(StorageRack as any)) {
|
|
36
|
+
/**
|
|
37
|
+
* Mobile racks carry their cells as cargo. The crane that *moves* a
|
|
38
|
+
* MobileRack treats the rack itself as the carrier — one slot, one rack.
|
|
39
|
+
*/
|
|
40
|
+
get slots(): SlotDef[] {
|
|
41
|
+
return [{ id: 'self', maxCount: 1 }]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The toolType for a fork/clamp that lifts an entire mobile rack.
|
|
46
|
+
* Different from the per-pallet tooling used to extract a carrier from
|
|
47
|
+
* a cell inside the rack.
|
|
48
|
+
*/
|
|
49
|
+
get toolType(): string {
|
|
50
|
+
return 'rack-clamp'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Re-export `Component` import to keep the file self-contained for IDEs that
|
|
55
|
+
// flatten dependency graphs. (Used implicitly by the parent mixin chain.)
|
|
56
|
+
export { Component }
|