@fmsim/machine 2.0.0-beta.10 → 2.0.0-beta.101
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/dist/agv.js +6 -2
- package/dist/agv.js.map +1 -1
- package/dist/carrier-manager.js +183 -0
- package/dist/carrier-manager.js.map +1 -0
- package/dist/carrier.js +99 -9
- package/dist/carrier.js.map +1 -1
- package/dist/conveyor-join.js +8 -2
- package/dist/conveyor-join.js.map +1 -1
- package/dist/conveyor.js +8 -0
- package/dist/conveyor.js.map +1 -1
- package/dist/crane.js +144 -1
- package/dist/crane.js.map +1 -1
- package/dist/factories/agv-3d.js +17 -36
- package/dist/factories/agv-3d.js.map +1 -1
- package/dist/factories/conveyor-3d.js +179 -100
- package/dist/factories/conveyor-3d.js.map +1 -1
- package/dist/factories/crane-3d.js +56 -29
- package/dist/factories/crane-3d.js.map +1 -1
- package/dist/factories/crane-rail-3d.js +14 -18
- package/dist/factories/crane-rail-3d.js.map +1 -1
- package/dist/factories/machine-3d.js +533 -197
- package/dist/factories/machine-3d.js.map +1 -1
- package/dist/factories/oht-3d.js +29 -47
- package/dist/factories/oht-3d.js.map +1 -1
- package/dist/factories/shuttle-3d.js +13 -32
- package/dist/factories/shuttle-3d.js.map +1 -1
- package/dist/factories/z-priority-defaults.js +33 -0
- package/dist/factories/z-priority-defaults.js.map +1 -0
- package/dist/factories/z-priority.js +54 -0
- package/dist/factories/z-priority.js.map +1 -0
- package/dist/features/conveyor-mixin.js.map +1 -1
- package/dist/features/mcs-status-default.js +15 -1
- package/dist/features/mcs-status-default.js.map +1 -1
- package/dist/features/mcs-status-mixin.js +22 -0
- package/dist/features/mcs-status-mixin.js.map +1 -1
- package/dist/features/mcs-zone-mixin.js.map +1 -1
- package/dist/features/parent-object-mixin.js +15 -7
- package/dist/features/parent-object-mixin.js.map +1 -1
- package/dist/floating-container.js +5 -0
- package/dist/floating-container.js.map +1 -1
- package/dist/index.js +52 -34
- package/dist/index.js.map +1 -1
- package/dist/mcs-carrier-holder.js +56 -22
- package/dist/mcs-carrier-holder.js.map +1 -1
- package/dist/mcs-machine.js +20 -0
- package/dist/mcs-machine.js.map +1 -1
- package/dist/mcs-unit.js +17 -0
- package/dist/mcs-unit.js.map +1 -1
- package/dist/mcs-vehicle.js +8 -3
- package/dist/mcs-vehicle.js.map +1 -1
- package/dist/node.js +10 -3
- package/dist/node.js.map +1 -1
- package/dist/oht.js +4 -0
- package/dist/oht.js.map +1 -1
- package/dist/port-flow.js +4 -0
- package/dist/port-flow.js.map +1 -1
- package/dist/port.js +4 -0
- package/dist/port.js.map +1 -1
- package/dist/scanner.js +30 -0
- package/dist/scanner.js.map +1 -0
- package/dist/scene/root-container-override.js +160 -96
- package/dist/scene/root-container-override.js.map +1 -1
- package/dist/shelf.js +4 -0
- package/dist/shelf.js.map +1 -1
- package/dist/static-container.js +5 -0
- package/dist/static-container.js.map +1 -1
- package/dist/stocker-abnormal-bar.js +5 -1
- package/dist/stocker-abnormal-bar.js.map +1 -1
- package/dist/stocker-capacity-bar.js +253 -6
- package/dist/stocker-capacity-bar.js.map +1 -1
- package/dist/stocker-carrier-bar.js +5 -1
- package/dist/stocker-carrier-bar.js.map +1 -1
- package/dist/stocker.js +6 -0
- package/dist/stocker.js.map +1 -1
- package/dist/templates/backdrop.js +30 -0
- package/dist/templates/backdrop.js.map +1 -0
- package/dist/templates/decal.js +21 -0
- package/dist/templates/decal.js.map +1 -0
- package/dist/templates/index.js +7 -1
- package/dist/templates/index.js.map +1 -1
- package/dist/templates/scanner.js +20 -0
- package/dist/templates/scanner.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/crane-position.js +83 -0
- package/dist/utils/crane-position.js.map +1 -0
- package/dist/utils/data-value.js +21 -0
- package/dist/utils/data-value.js.map +1 -0
- package/dist/utils/fit-gauge-scale.js +28 -0
- package/dist/utils/fit-gauge-scale.js.map +1 -0
- package/dist/utils/get-value-on-ranges.js +2 -4
- package/dist/utils/get-value-on-ranges.js.map +1 -1
- package/dist/utils/stocker-gauge.js +78 -0
- package/dist/utils/stocker-gauge.js.map +1 -0
- package/dist/zone-capacity-bar.js +3 -3
- package/dist/zone-capacity-bar.js.map +1 -1
- package/icons/backdrop.png +0 -0
- package/icons/decal.png +0 -0
- package/jest.config.js +10 -0
- package/package.json +4 -3
- package/src/agv.ts +7 -2
- package/src/carrier-manager.ts +223 -0
- package/src/carrier.ts +103 -10
- package/src/conveyor-join.ts +5 -2
- package/src/conveyor.ts +8 -0
- package/src/crane.ts +181 -1
- package/src/factories/agv-3d.ts +19 -36
- package/src/factories/conveyor-3d.ts +183 -103
- package/src/factories/crane-3d.ts +62 -29
- package/src/factories/crane-rail-3d.ts +17 -20
- package/src/factories/machine-3d.ts +631 -205
- package/src/factories/oht-3d.ts +30 -46
- package/src/factories/shuttle-3d.ts +14 -32
- package/src/factories/z-priority-defaults.ts +38 -0
- package/src/factories/z-priority.ts +60 -0
- package/src/features/conveyor-mixin.ts +1 -1
- package/src/features/mcs-status-default.ts +15 -1
- package/src/features/mcs-status-mixin.ts +26 -4
- package/src/features/mcs-zone-mixin.ts +1 -1
- package/src/features/parent-object-mixin.ts +17 -8
- package/src/floating-container.ts +5 -0
- package/src/index.ts +58 -34
- package/src/mcs-carrier-holder.ts +57 -34
- package/src/mcs-machine.ts +23 -0
- package/src/mcs-unit.ts +21 -1
- package/src/mcs-vehicle.ts +9 -6
- package/src/node.ts +9 -3
- package/src/oht.ts +6 -1
- package/src/port-flow.ts +5 -0
- package/src/port.ts +5 -0
- package/src/scanner.ts +29 -0
- package/src/scene/root-container-override.ts +154 -103
- package/src/shelf.ts +5 -0
- package/src/static-container.ts +5 -0
- package/src/stocker-abnormal-bar.ts +6 -1
- package/src/stocker-capacity-bar.ts +298 -7
- package/src/stocker-carrier-bar.ts +6 -1
- package/src/stocker.ts +7 -0
- package/src/templates/backdrop.ts +30 -0
- package/src/templates/decal.ts +21 -0
- package/src/templates/index.ts +7 -1
- package/src/templates/scanner.ts +20 -0
- package/src/utils/crane-position.ts +105 -0
- package/src/utils/data-value.ts +19 -0
- package/src/utils/fit-gauge-scale.ts +35 -0
- package/src/utils/get-value-on-ranges.ts +2 -4
- package/src/utils/stocker-gauge.ts +111 -0
- package/src/zone-capacity-bar.ts +3 -3
- package/translations/en.json +26 -1
- package/translations/ja.json +26 -1
- package/translations/ko.json +26 -1
- package/translations/ms.json +26 -1
- package/translations/zh.json +26 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { Model } from '@hatiolab/things-scene'
|
|
2
|
+
import type Carrier from './carrier'
|
|
3
|
+
import type MCSCarrierHolder from './mcs-carrier-holder'
|
|
4
|
+
import { parseIfJsonString } from './utils/data-value'
|
|
5
|
+
|
|
6
|
+
// 사라진 carrier 의 dispose 지연. 같은 macrotask 안에서 holder A 의 사라짐
|
|
7
|
+
// 보고와 holder B 의 등장 보고가 순차로 들어오는 reparent 시나리오 (= 같은
|
|
8
|
+
// frame snapshot 의 여러 record 적용) 를 보호하기 위해 setTimeout(0) 의
|
|
9
|
+
// next-macrotask delay 만 둔다. 과거 1000ms grace 가 있었으나 seek 시 2단계
|
|
10
|
+
// 갱신 (1초 후 carrier 사라짐) 부작용이 명확하고 frame 누락 bouncing 깜빡임
|
|
11
|
+
// 보호 효용은 작다 판단되어 0 으로 단축 (2026-06-09).
|
|
12
|
+
const DYING_TIMEOUT = 0
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Carrier 가 들고 있는 4 키 묶음. data.CARRIERNAME 의 형제 키 (CARRIERTYPE,
|
|
16
|
+
* EMPTYTYPE, CARRIERSTATUS) 를 한 item 으로 묶는다. holder.data 의 *대표*
|
|
17
|
+
* 와 ADDITIONS 의 *각 항목* 모두 동일 shape 으로 정규화돼 stack diff 에
|
|
18
|
+
* 들어간다.
|
|
19
|
+
*
|
|
20
|
+
* 주의 — 외부 시스템이 ADDITIONS 의 각 항목 키를 다른 이름으로 (예:
|
|
21
|
+
* NAME / TYPE / EMPTY / STATUS) 줄 가능성에 대비해 이 build 함수가 단일
|
|
22
|
+
* 정규화 지점이 된다. 키 매핑 변경은 여기 한 곳만 손대면 된다.
|
|
23
|
+
*/
|
|
24
|
+
export interface CarrierStackItem {
|
|
25
|
+
CARRIERNAME: string
|
|
26
|
+
CARRIERTYPE?: string
|
|
27
|
+
EMPTYTYPE?: string
|
|
28
|
+
CARRIERSTATUS?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default class CarrierManager {
|
|
32
|
+
private carriers: Map<string, Carrier> = new Map()
|
|
33
|
+
private dyingTimers: Map<string, ReturnType<typeof setTimeout>> = new Map()
|
|
34
|
+
private root: any
|
|
35
|
+
|
|
36
|
+
constructor(root: any) {
|
|
37
|
+
this.root = root
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get(carrierName: string): Carrier | undefined {
|
|
41
|
+
return this.carriers.get(carrierName)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Holder 의 data 변경에 대응해 carrier pool 을 동기화.
|
|
46
|
+
*
|
|
47
|
+
* 정책:
|
|
48
|
+
* - holder.data 가 *single source of truth*. 대표(CARRIERNAME) +
|
|
49
|
+
* ADDITIONS[] 를 하나의 *stack list* 로 정규화한 뒤 before/after 의
|
|
50
|
+
* 이름 set diff 로 추가/제거/유지 분기.
|
|
51
|
+
* - "대표" 와 "ADDITIONS" 는 *holder.data 안의 키 위치 차이일 뿐* 이고,
|
|
52
|
+
* carrier 인스턴스끼리는 **종속/그룹 관계 없음 — 모두 독립 동등**.
|
|
53
|
+
* stack 안의 위치 (stackIndex) 만 carrier.state 에 주입한다. 2D render
|
|
54
|
+
* skip 등의 판정은 *위치 (= parent.components 의 마지막 여부)* 로 한다.
|
|
55
|
+
* - 동일 CARRIERNAME 이 *다른 holder* 에 새로 등장하면 reparent (애니메이션).
|
|
56
|
+
* *해당 carrier 만 이동* — 같은 stack 의 다른 carrier 는 따라가지 않는다.
|
|
57
|
+
* - 사라진 carrier 는 next-macrotask 에 dispose. 같은 macrotask 안에서 다른
|
|
58
|
+
* holder 가 같은 이름을 보고하면 cancel 되어 reparent 로 전환.
|
|
59
|
+
*/
|
|
60
|
+
update(holder: MCSCarrierHolder, after: Record<string, any>, before: Record<string, any>): void {
|
|
61
|
+
const afterStack = this._buildStack(after)
|
|
62
|
+
const beforeStack = this._buildStack(before)
|
|
63
|
+
|
|
64
|
+
const afterNames = new Set(afterStack.map(i => i.CARRIERNAME))
|
|
65
|
+
const beforeNames = new Set(beforeStack.map(i => i.CARRIERNAME))
|
|
66
|
+
|
|
67
|
+
// 1) 사라진 것 → dying schedule (자기 holder 의 자식인 carrier 만)
|
|
68
|
+
for (const name of beforeNames) {
|
|
69
|
+
if (afterNames.has(name)) continue
|
|
70
|
+
const carrier = this.carriers.get(name)
|
|
71
|
+
if (carrier && carrier.parent === holder) {
|
|
72
|
+
this.scheduleDying(name)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 2) afterStack 의 *순서대로* 처리 — bottom (ADDITIONS[0]) 부터 top (대표)
|
|
77
|
+
// 그래야 parent.components 가 자연스럽게 같은 순서로 정렬되어 stack index
|
|
78
|
+
// 가 일관된다.
|
|
79
|
+
afterStack.forEach((item, idx) => {
|
|
80
|
+
const name = item.CARRIERNAME
|
|
81
|
+
this.cancelDying(name)
|
|
82
|
+
|
|
83
|
+
let carrier = this.carriers.get(name)
|
|
84
|
+
const { width, height } = holder.state
|
|
85
|
+
|
|
86
|
+
if (!carrier) {
|
|
87
|
+
carrier = Model.compile(
|
|
88
|
+
{
|
|
89
|
+
id: name,
|
|
90
|
+
type: 'Carrier',
|
|
91
|
+
left: 0,
|
|
92
|
+
top: 0,
|
|
93
|
+
width,
|
|
94
|
+
height,
|
|
95
|
+
showText: holder.getState('showCarrierText') || false,
|
|
96
|
+
stackIndex: idx
|
|
97
|
+
},
|
|
98
|
+
this.root.app
|
|
99
|
+
) as unknown as Carrier
|
|
100
|
+
|
|
101
|
+
this.carriers.set(name, carrier)
|
|
102
|
+
carrier.data = item
|
|
103
|
+
holder.addComponent(carrier, { silent: true })
|
|
104
|
+
} else if (carrier.parent !== holder && !beforeNames.has(name)) {
|
|
105
|
+
// 다른 holder 에 있던 carrier 가 이번 update 에서 *새로 등장* 한 경우만
|
|
106
|
+
// reparent. before 에도 같은 이름이 있었으면 ping-pong (옛 시점의
|
|
107
|
+
// 반복 보고) 이므로 trigger 하지 않는다. (F05 의 bouncing 방지)
|
|
108
|
+
;(holder as any).reparent(carrier, { animated: true, duration: 2000, ease: 'inout' })
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (carrier.parent === holder) {
|
|
112
|
+
carrier.setState('stackIndex', idx)
|
|
113
|
+
carrier.data = item
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// *_모든 carrier 추가 완료 후* — 각자의 transform 강제 갱신. 한 줄로 처리
|
|
118
|
+
// 안 되는 이유: cz override 의 offset 계산이 *형제 carrier 의 _realObject.
|
|
119
|
+
// effectiveDepth 누적*에 의존하는데, 첫 iteration 시점엔 자기 뒤 carrier 의
|
|
120
|
+
// _realObject 가 아직 없어 offset 이 부족하게 평가될 수 있다. 모두 빌드된
|
|
121
|
+
// 뒤 한 번 더 갱신해야 적층 정확.
|
|
122
|
+
afterStack.forEach(item => {
|
|
123
|
+
const carrier = this.carriers.get(item.CARRIERNAME)
|
|
124
|
+
if (carrier && carrier.parent === holder) {
|
|
125
|
+
;(carrier as any)._realObject?.updateTransform?.()
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* data.CARRIERNAME (대표) + data.MULTICARRIERS[] 를 하나의 stack list 로 정규화.
|
|
132
|
+
* 적층 순서: multiCarriers[0..n-1] (bottom → up) + 대표 (top, 맨 마지막).
|
|
133
|
+
* (데이터 키는 모두 대문자 전제 — 케이스 정규화 없이 직접 읽는다)
|
|
134
|
+
*/
|
|
135
|
+
private _buildStack(data: any): CarrierStackItem[] {
|
|
136
|
+
if (!data) return []
|
|
137
|
+
|
|
138
|
+
const stack: CarrierStackItem[] = []
|
|
139
|
+
|
|
140
|
+
// MULTICARRIERS 값이 JSON 문자열로 올 수 있어 파싱 후 처리.
|
|
141
|
+
const list = parseIfJsonString(data.MULTICARRIERS)
|
|
142
|
+
if (Array.isArray(list)) {
|
|
143
|
+
for (const a of list) {
|
|
144
|
+
if (a && typeof a === 'object' && a.CARRIERNAME) {
|
|
145
|
+
// 항목 *원본 그대로* — 외부 시스템이 임의 키를 추가로 보낼 수 있고,
|
|
146
|
+
// 누락된 4 키는 default 없이 그대로 비워둔다 (carrier.data 에 흘리는
|
|
147
|
+
// 가공 최소화 — F03 같은 기존 테스트의 raw shape 기대와도 정합).
|
|
148
|
+
stack.push({ ...a } as CarrierStackItem)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (data.CARRIERNAME) {
|
|
154
|
+
// 대표는 *holder.data 의 carrier 관련 키만 추출* — showText / carrierDepth
|
|
155
|
+
// 같은 holder 자체 속성은 carrier 로 흘리지 않는다. 명시되지 않은 키는
|
|
156
|
+
// 생략 (default 안 채움).
|
|
157
|
+
const repr: any = { CARRIERNAME: data.CARRIERNAME }
|
|
158
|
+
if ('CARRIERTYPE' in data) repr.CARRIERTYPE = data.CARRIERTYPE
|
|
159
|
+
if ('EMPTYTYPE' in data) repr.EMPTYTYPE = data.EMPTYTYPE
|
|
160
|
+
if ('CARRIERSTATUS' in data) repr.CARRIERSTATUS = data.CARRIERSTATUS
|
|
161
|
+
stack.push(repr)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return stack
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* carrier dispose 를 *next macrotask* 로 미룬다. 동기 즉시 dispose 가 아닌
|
|
169
|
+
* 이유: 같은 macrotask 안에서 holder A 의 사라짐 보고가 step 1 에 들어오고
|
|
170
|
+
* holder B 의 등장 보고가 (별도 carrier-manager.update 호출의) step 2 에
|
|
171
|
+
* 들어오는 reparent 시나리오를 보호하기 위함. 즉시 dispose 면 step 1 에서
|
|
172
|
+
* carrier 인스턴스가 파괴돼 step 2 의 reparent 분기가 *새 인스턴스 생성*
|
|
173
|
+
* 으로 떨어지고, 3D mesh 재구축 + 이동 애니메이션 손실이 발생.
|
|
174
|
+
*
|
|
175
|
+
* 같은 macrotask 안에서 cancelDying 호출이 도달하면 clearTimeout 으로
|
|
176
|
+
* dispose 회수 → reparent 정상.
|
|
177
|
+
*/
|
|
178
|
+
private scheduleDying(carrierName: string): void {
|
|
179
|
+
this.cancelDying(carrierName)
|
|
180
|
+
|
|
181
|
+
const timer = setTimeout(() => {
|
|
182
|
+
this.dyingTimers.delete(carrierName)
|
|
183
|
+
|
|
184
|
+
const carrier = this.carriers.get(carrierName)
|
|
185
|
+
if (carrier) {
|
|
186
|
+
this.carriers.delete(carrierName)
|
|
187
|
+
if (!carrier.disposed) {
|
|
188
|
+
carrier.removeSelf(true)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}, DYING_TIMEOUT)
|
|
192
|
+
|
|
193
|
+
this.dyingTimers.set(carrierName, timer)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private cancelDying(carrierName: string): void {
|
|
197
|
+
const timer = this.dyingTimers.get(carrierName)
|
|
198
|
+
if (timer) {
|
|
199
|
+
clearTimeout(timer)
|
|
200
|
+
this.dyingTimers.delete(carrierName)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
onCarrierDisposed(carrierName: string): void {
|
|
205
|
+
this.cancelDying(carrierName)
|
|
206
|
+
this.carriers.delete(carrierName)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
dispose(): void {
|
|
210
|
+
for (const timer of this.dyingTimers.values()) {
|
|
211
|
+
clearTimeout(timer)
|
|
212
|
+
}
|
|
213
|
+
this.dyingTimers.clear()
|
|
214
|
+
|
|
215
|
+
for (const carrier of this.carriers.values()) {
|
|
216
|
+
if (!carrier.disposed) {
|
|
217
|
+
carrier.removeSelf(true)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.carriers.clear()
|
|
222
|
+
}
|
|
223
|
+
}
|
package/src/carrier.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getPopupData } from '@fmsim/api'
|
|
|
4
4
|
import { BOUNDS, Component, ComponentNature, Properties, Shape, sceneComponent } from '@hatiolab/things-scene'
|
|
5
5
|
import { ANIMATION_DEFAULT, AnimationPreset, AnimationConfig } from './features/animation-default.js'
|
|
6
6
|
import { ParentObjectMixin } from './features/parent-object-mixin.js'
|
|
7
|
-
import {
|
|
7
|
+
import { Legend, resolveCarrierLegend } from './features/mcs-status-default.js'
|
|
8
8
|
import { MCSStatusMixin } from './features/mcs-status-mixin.js'
|
|
9
9
|
|
|
10
10
|
const NATURE: ComponentNature = {
|
|
@@ -13,12 +13,31 @@ const NATURE: ComponentNature = {
|
|
|
13
13
|
rotatable: false
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Feature flag — keep status text (F / E / X) screen-axis-aligned even
|
|
19
|
+
* when the carrier (or its parent holder, or an in-flight reparent
|
|
20
|
+
* tween) is rotated. Counter-rotates ONLY the text; the polygon path
|
|
21
|
+
* still rotates with the carrier as before.
|
|
22
|
+
*
|
|
23
|
+
* ROLLBACK procedure (if customer decides to revert):
|
|
24
|
+
* 1. Flip this flag to `false` — text rotates with carrier again.
|
|
25
|
+
* 2. Or delete this constant and the — fully strip the feature: keep
|
|
26
|
+
* `if (STATUS_TEXT_COUNTER_ROTATE)` only the `else` branch in
|
|
27
|
+
* branch in `render()`. `render()` (the original code).
|
|
28
|
+
*/
|
|
29
|
+
const STATUS_TEXT_COUNTER_ROTATE = true
|
|
30
|
+
|
|
16
31
|
@sceneComponent('Carrier')
|
|
17
32
|
export default class Carrier extends MCSStatusMixin(ParentObjectMixin(Shape)) {
|
|
18
33
|
static get nature() {
|
|
19
34
|
return NATURE
|
|
20
35
|
}
|
|
21
36
|
|
|
37
|
+
get decorators() {
|
|
38
|
+
return ['decotag']
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
get path() {
|
|
23
42
|
if (!this.parent) {
|
|
24
43
|
return []
|
|
@@ -37,6 +56,44 @@ export default class Carrier extends MCSStatusMixin(ParentObjectMixin(Shape)) {
|
|
|
37
56
|
|
|
38
57
|
set path(path) {}
|
|
39
58
|
|
|
59
|
+
|
|
60
|
+
added(parent: any) {
|
|
61
|
+
super.added(parent)
|
|
62
|
+
|
|
63
|
+
// 새 부모에 맞춰 크기 및 상태 갱신 — width/height 만. depth 는 *절대로
|
|
64
|
+
// 건드리지 않는다*. machine-3d.ts 의 CARRIER_CONFIG + MCSRealObject3D.
|
|
65
|
+
// effectiveDepth 가 depthRatio(0.5) × min(w,h) 로 자동 결정한다.
|
|
66
|
+
// 여기서 state.depth 를 명시 set 하면 그 resolution chain 의 step 1 에
|
|
67
|
+
// 걸려 본래 두께가 덮어써진다 (= 사용자 호소 "두께가 줄어들었다" 의 원인).
|
|
68
|
+
if (parent) {
|
|
69
|
+
const { width, height } = parent.state || {}
|
|
70
|
+
if (width && height) {
|
|
71
|
+
this.set({ width, height })
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.syncStateFromData()
|
|
76
|
+
|
|
77
|
+
// 3D 오브젝트 최초 생성 (동기적 — reparent()에서 _realObject 필요)
|
|
78
|
+
if ((this.root as any)?.threed && !this._realObject) {
|
|
79
|
+
;(this.root as any).model_layer?._threeCapability?.addObject(this)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// reparent 애니메이션은 things-scene의 reparent()가 처리
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* data로부터 carrier 상태를 동기화 (생성 시, 부모 변경 시 공통 사용)
|
|
87
|
+
*/
|
|
88
|
+
private syncStateFromData(): void {
|
|
89
|
+
const { CARRIERNAME, CARRIERTYPE = '', EMPTYTYPE, CARRIERSTATUS } = this.data || {}
|
|
90
|
+
|
|
91
|
+
this.setState('id', CARRIERNAME)
|
|
92
|
+
this.setState('EMPTYTYPE', EMPTYTYPE)
|
|
93
|
+
this.setState('CARRIERTYPE', CARRIERTYPE)
|
|
94
|
+
this.setState('CARRIERSTATUS', CARRIERSTATUS)
|
|
95
|
+
}
|
|
96
|
+
|
|
40
97
|
onchangeData(after: Record<string, any>, before: Record<string, any>): void {
|
|
41
98
|
const { CARRIERNAME, CARRIERTYPE = '', EMPTYTYPE, CARRIERSTATUS } = this.data || {}
|
|
42
99
|
|
|
@@ -99,13 +156,8 @@ export default class Carrier extends MCSStatusMixin(ParentObjectMixin(Shape)) {
|
|
|
99
156
|
}
|
|
100
157
|
|
|
101
158
|
get legend(): Legend {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (carrierLegendName) {
|
|
105
|
-
return (this.root as any)?.style[carrierLegendName]
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return (this.root as any)?.carrierLegendTheme || LEGEND_CARRIER
|
|
159
|
+
// carrier·스토커 게이지(2D/3D) 공유 단일 소스.
|
|
160
|
+
return resolveCarrierLegend(this)
|
|
109
161
|
}
|
|
110
162
|
|
|
111
163
|
getAnimationConfig(carrierStatus): AnimationConfig | null {
|
|
@@ -129,8 +181,14 @@ export default class Carrier extends MCSStatusMixin(ParentObjectMixin(Shape)) {
|
|
|
129
181
|
}
|
|
130
182
|
|
|
131
183
|
// 캐시에 없으면 파싱하고 저장
|
|
132
|
-
|
|
184
|
+
let theme = (this.root as any)?.style?.[carrierAnimationName]
|
|
133
185
|
if (theme) {
|
|
186
|
+
// theme이 string이면 먼저 파싱
|
|
187
|
+
if (typeof theme === 'string') {
|
|
188
|
+
try { theme = JSON5.parse(theme) } catch { return ANIMATION_DEFAULT }
|
|
189
|
+
}
|
|
190
|
+
if (typeof theme !== 'object' || theme === null) return ANIMATION_DEFAULT
|
|
191
|
+
|
|
134
192
|
// 문자열 형태의 설정들을 미리 파싱
|
|
135
193
|
const parsedTheme = {}
|
|
136
194
|
for (const [status, config] of Object.entries(theme)) {
|
|
@@ -212,6 +270,18 @@ export default class Carrier extends MCSStatusMixin(ParentObjectMixin(Shape)) {
|
|
|
212
270
|
return
|
|
213
271
|
}
|
|
214
272
|
|
|
273
|
+
// 2D 에서는 stack 의 *맨 위 (= parent.components 의 마지막)* 1개만 그린다.
|
|
274
|
+
// ADDITIONS 의 carrier 들도 인스턴스로는 살아있어 조회/reparent 가 가능하지만
|
|
275
|
+
// 2D 시각에는 노출하지 않는다 — 정책: "2D 는 현행처럼" (대표 1개만).
|
|
276
|
+
// 판단 기준은 *위치* — carrier 간 그룹/종속 정보는 두지 않는다.
|
|
277
|
+
const parent = this.parent
|
|
278
|
+
if (parent && parent.components && parent.components.length > 1) {
|
|
279
|
+
const siblings = parent.components
|
|
280
|
+
if (siblings[siblings.length - 1] !== this) {
|
|
281
|
+
return
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
215
285
|
const { width, height } = this.bounds
|
|
216
286
|
const path = this.path
|
|
217
287
|
const round = Math.round(Math.min(width, height) * 0.1)
|
|
@@ -244,11 +314,34 @@ export default class Carrier extends MCSStatusMixin(ParentObjectMixin(Shape)) {
|
|
|
244
314
|
ctx.textAlign = 'center'
|
|
245
315
|
ctx.textBaseline = 'middle'
|
|
246
316
|
|
|
247
|
-
|
|
317
|
+
if (STATUS_TEXT_COUNTER_ROTATE) {
|
|
318
|
+
// Counter-rotate so the status label stays screen-axis-aligned
|
|
319
|
+
// even when the carrier (or its parent holder, or an in-flight
|
|
320
|
+
// reparent transition) is rotated. Reading the current cumulative
|
|
321
|
+
// rotation from the canvas transform handles all sources of
|
|
322
|
+
// rotation uniformly (state.rotation, parent transforms,
|
|
323
|
+
// animation tweens) — no need to enumerate them.
|
|
324
|
+
const m = ctx.getTransform()
|
|
325
|
+
const cumulRotation = Math.atan2(m.b, m.a)
|
|
326
|
+
ctx.save()
|
|
327
|
+
ctx.translate(cx, cy)
|
|
328
|
+
ctx.rotate(-cumulRotation)
|
|
329
|
+
ctx.fillText(text, -width / 8, height / 8)
|
|
330
|
+
ctx.restore()
|
|
331
|
+
} else {
|
|
332
|
+
// Original — text rotates with the carrier.
|
|
333
|
+
ctx.fillText(text, cx - width / 8, cy + height / 8)
|
|
334
|
+
}
|
|
248
335
|
}
|
|
249
336
|
}
|
|
250
337
|
}
|
|
251
338
|
|
|
339
|
+
dispose(): void {
|
|
340
|
+
;(this.root as any)?.carrierManager?.onCarrierDisposed(this.state.id)
|
|
341
|
+
|
|
342
|
+
super.dispose()
|
|
343
|
+
}
|
|
344
|
+
|
|
252
345
|
async detailInfo() {
|
|
253
346
|
const { type, id } = this.state
|
|
254
347
|
|
package/src/conveyor-join.ts
CHANGED
|
@@ -119,8 +119,11 @@ export default class ConveyorJoin extends ConveyorMixin(MCSTransport) {
|
|
|
119
119
|
if (normx * normx + normy * normy < 0.25 && ratiox * ratiox + ratioy * ratioy > 0.25) {
|
|
120
120
|
const angle = normalizeAngle(Math.atan2(-normy, normx) - Math.PI / 2)
|
|
121
121
|
|
|
122
|
-
if (
|
|
123
|
-
return true
|
|
122
|
+
if (startAngle <= endAngle) {
|
|
123
|
+
if (angle >= startAngle && angle <= endAngle) return true
|
|
124
|
+
} else {
|
|
125
|
+
// wraparound: startAngle > endAngle (예: π → 0)
|
|
126
|
+
if (angle >= startAngle || angle <= endAngle) return true
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
|
package/src/conveyor.ts
CHANGED
|
@@ -14,6 +14,14 @@ const NATURE: ComponentNature = {
|
|
|
14
14
|
options: ['', 'conveyor', 'belt', 'rail']
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
+
{
|
|
18
|
+
type: 'select',
|
|
19
|
+
label: 'conveyor-orientation',
|
|
20
|
+
name: 'orientation',
|
|
21
|
+
property: {
|
|
22
|
+
options: ['', 'horizontal', 'vertical']
|
|
23
|
+
}
|
|
24
|
+
},
|
|
17
25
|
...MCSTransport.properties
|
|
18
26
|
]
|
|
19
27
|
}
|
package/src/crane.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { Component, ComponentNature,
|
|
1
|
+
import { Component, ComponentNature, sceneComponent, frameClock } from '@hatiolab/things-scene'
|
|
2
2
|
import MCSVehicle from './mcs-vehicle'
|
|
3
3
|
import { LEGEND_CRANE } from './features/mcs-status-default'
|
|
4
|
+
import {
|
|
5
|
+
axisRatio,
|
|
6
|
+
mapCraneLocalPosition,
|
|
7
|
+
normalizeCranePosition,
|
|
8
|
+
type CranePositionData
|
|
9
|
+
} from './utils/crane-position'
|
|
4
10
|
|
|
5
11
|
const NATURE: ComponentNature = {
|
|
6
12
|
mutable: false,
|
|
@@ -11,6 +17,29 @@ const NATURE: ComponentNature = {
|
|
|
11
17
|
|
|
12
18
|
const GAP = 2
|
|
13
19
|
|
|
20
|
+
/** 좌표 보간 기본 duration (ms). data.DURATION_MS 가 없으면 이 값 사용. */
|
|
21
|
+
const DEFAULT_DURATION_MS = 1000
|
|
22
|
+
|
|
23
|
+
function lerp(a: number, b: number, t: number): number {
|
|
24
|
+
return a + (b - a) * t
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function easeInOut(t: number): number {
|
|
28
|
+
return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface CranePositionAnimator {
|
|
32
|
+
fromLeft: number
|
|
33
|
+
fromTop: number
|
|
34
|
+
fromForkZ: number
|
|
35
|
+
toLeft: number
|
|
36
|
+
toTop: number
|
|
37
|
+
toForkZ: number
|
|
38
|
+
startTime: number
|
|
39
|
+
duration: number
|
|
40
|
+
unsubscribe: () => void
|
|
41
|
+
}
|
|
42
|
+
|
|
14
43
|
@sceneComponent('Crane')
|
|
15
44
|
export default class Crane extends MCSVehicle {
|
|
16
45
|
static get nature() {
|
|
@@ -21,10 +50,161 @@ export default class Crane extends MCSVehicle {
|
|
|
21
50
|
return 'black'
|
|
22
51
|
}
|
|
23
52
|
|
|
53
|
+
/** Crane 의 parentObject 는 STOCKER. */
|
|
54
|
+
get parentObjectTypes(): string[] {
|
|
55
|
+
return ['STOCKER']
|
|
56
|
+
}
|
|
57
|
+
|
|
24
58
|
getLegendFallback() {
|
|
25
59
|
return (this.root as any).craneLegendTheme || super.getLegendFallback()
|
|
26
60
|
}
|
|
27
61
|
|
|
62
|
+
private _posAnimator?: CranePositionAnimator
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* data.cranePosition = { current: {x,y,z}, limit: {x|y|z:{min,max}} } 분기.
|
|
66
|
+
* current 를 limit 범위 안의 0~1 비율로 환산한 뒤, 부모 (보통 Stocker) 기준으로
|
|
67
|
+
* 실 좌표 (state.left/top) 와 forkZ 로 변환해 lerp 시작. x→host 긴쪽, y→짧은쪽,
|
|
68
|
+
* z→포크 높이. 보간 중 새 값이 들어오면 *현재 보간 위치* 를 from 으로 잡고 새
|
|
69
|
+
* target 으로 새 lerp 시작.
|
|
70
|
+
* NODEID 경로는 super (MCSVehicle.onchangeData) 가 처리 — cranePosition 만 있는
|
|
71
|
+
* 데이터에선 NODEID 가 없어 자연스럽게 noop.
|
|
72
|
+
*/
|
|
73
|
+
onchangeData(after: Record<string, any>, before: Record<string, any>): void {
|
|
74
|
+
const afterData = after?.data
|
|
75
|
+
// 데이터 키는 모두 대문자 전제. CRANEPOSITION 의 중첩 키(CURRENT/LIMIT/X/Y/Z/MIN/MAX)는
|
|
76
|
+
// normalizeCranePosition 이 내부 표준형(소문자)으로 변환. DURATION_MS 는 사용하지 않음.
|
|
77
|
+
const afterCP = normalizeCranePosition(afterData?.CRANEPOSITION)
|
|
78
|
+
if (afterCP) {
|
|
79
|
+
const beforeCP = normalizeCranePosition(before?.data?.CRANEPOSITION)
|
|
80
|
+
if (this._cranePositionChanged(afterCP, beforeCP)) {
|
|
81
|
+
this._startPositionAnimation(afterCP)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
super.onchangeData(after, before)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** current 또는 limit 중 하나라도 바뀌면 재계산 필요 (limit 변화도 실 위치를 바꿈). */
|
|
88
|
+
private _cranePositionChanged(a: CranePositionData, b?: CranePositionData): boolean {
|
|
89
|
+
if (!b) return true
|
|
90
|
+
return (
|
|
91
|
+
JSON.stringify(a?.current ?? null) !== JSON.stringify(b?.current ?? null) ||
|
|
92
|
+
JSON.stringify(a?.limit ?? null) !== JSON.stringify(b?.limit ?? null)
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
dispose() {
|
|
97
|
+
if (this._posAnimator) {
|
|
98
|
+
this._posAnimator.unsubscribe()
|
|
99
|
+
this._posAnimator = undefined
|
|
100
|
+
}
|
|
101
|
+
super.dispose()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private _startPositionAnimation(cranePosition: CranePositionData, durationMs?: number): void {
|
|
105
|
+
const target = this._ratioToReal(cranePosition)
|
|
106
|
+
if (!target) return // 부모(host) 없거나 크기 0 이면 변환 skip
|
|
107
|
+
|
|
108
|
+
const now = frameClock.simTime
|
|
109
|
+
const duration = Math.max(1, Number(durationMs) || DEFAULT_DURATION_MS)
|
|
110
|
+
|
|
111
|
+
// 현재 위치 — 보간 중이면 그 시점 보간값을 from 으로
|
|
112
|
+
let fromLeft = Number(this.state.left) || 0
|
|
113
|
+
let fromTop = Number(this.state.top) || 0
|
|
114
|
+
let fromForkZ = Number((this.state as any).forkZ) || 0
|
|
115
|
+
|
|
116
|
+
if (this._posAnimator) {
|
|
117
|
+
const a = this._posAnimator
|
|
118
|
+
const t = Math.min(1, Math.max(0, (now - a.startTime) / a.duration))
|
|
119
|
+
const e = easeInOut(t)
|
|
120
|
+
fromLeft = lerp(a.fromLeft, a.toLeft, e)
|
|
121
|
+
fromTop = lerp(a.fromTop, a.toTop, e)
|
|
122
|
+
fromForkZ = lerp(a.fromForkZ, a.toForkZ, e)
|
|
123
|
+
a.unsubscribe()
|
|
124
|
+
this._posAnimator = undefined
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const unsubscribe = frameClock.subscribe(
|
|
128
|
+
(_dt: number, simTime: number) => this._tickPositionAnimation(simTime),
|
|
129
|
+
{ description: 'crane-position', component: this }
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
this._posAnimator = {
|
|
133
|
+
fromLeft,
|
|
134
|
+
fromTop,
|
|
135
|
+
fromForkZ,
|
|
136
|
+
toLeft: target.left,
|
|
137
|
+
toTop: target.top,
|
|
138
|
+
toForkZ: target.forkZ,
|
|
139
|
+
startTime: now,
|
|
140
|
+
duration,
|
|
141
|
+
unsubscribe
|
|
142
|
+
}
|
|
143
|
+
// 즉시 첫 frame 반영 (t=0) — set 한 번 호출. paused 환경에서도 from→target
|
|
144
|
+
// 진입 시점이 명확.
|
|
145
|
+
this._tickPositionAnimation(now)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private _tickPositionAnimation(simTime: number): void {
|
|
149
|
+
const a = this._posAnimator
|
|
150
|
+
if (!a) return
|
|
151
|
+
const t = Math.min(1, Math.max(0, (simTime - a.startTime) / a.duration))
|
|
152
|
+
const e = easeInOut(t)
|
|
153
|
+
this.set({
|
|
154
|
+
left: lerp(a.fromLeft, a.toLeft, e),
|
|
155
|
+
top: lerp(a.fromTop, a.toTop, e),
|
|
156
|
+
forkZ: lerp(a.fromForkZ, a.toForkZ, e)
|
|
157
|
+
})
|
|
158
|
+
if (t >= 1) {
|
|
159
|
+
a.unsubscribe()
|
|
160
|
+
this._posAnimator = undefined
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* cranePosition (current + limit) → state.left/top + forkZ.
|
|
166
|
+
*
|
|
167
|
+
* 부모 오브젝트 (보통은 Stocker 이지만 다른 컨테이너일 수도) 의 width/height
|
|
168
|
+
* 만 사용해 좌표 매핑 — 타입 무관 일반화. 가상 rail 은 host 의 긴쪽:
|
|
169
|
+
* - current.x → host 의 긴쪽 (자동 판별: max(width, height))
|
|
170
|
+
* - current.y → 짧은쪽
|
|
171
|
+
* - current.z → forkZ (state 에 0~100 으로 저장, 3D 측에서 mast 비율로 매핑)
|
|
172
|
+
*
|
|
173
|
+
* 각 축 비율 = (current - limit.min) / (limit.max - limit.min) ∈ [0,1].
|
|
174
|
+
*
|
|
175
|
+
* **스토커 안쪽 오프셋**: 크레인의 폭/두께를 감안해, 크레인 *전체* 가 host 안에
|
|
176
|
+
* 머무르도록 top-left 좌표를 [0, hostLen - craneLen] 범위로 매핑한다 (= 양끝에서
|
|
177
|
+
* craneLen/2 만큼 inset 된 중심선 위를 움직임). 크레인이 host 보다 크면 span 0
|
|
178
|
+
* 으로 떨어져 host 모서리에 정렬.
|
|
179
|
+
*
|
|
180
|
+
* 참조는 ParentObjectMixin 이 제공하는 `parentObject` 사용 —
|
|
181
|
+
* state.parentObjectId 명시 시 그것, 미명시 시 this.parent 자동 fallback.
|
|
182
|
+
*/
|
|
183
|
+
private _ratioToReal(
|
|
184
|
+
cp: CranePositionData
|
|
185
|
+
): { left: number; top: number; forkZ: number } | undefined {
|
|
186
|
+
const host: any = (this as any).parentObject
|
|
187
|
+
if (!host) return undefined
|
|
188
|
+
|
|
189
|
+
const hw = Number(host.state?.width) || 0
|
|
190
|
+
const hh = Number(host.state?.height) || 0
|
|
191
|
+
const cw = Number(this.state.width) || 0
|
|
192
|
+
const ch = Number(this.state.height) || 0
|
|
193
|
+
if (!hw || !hh) return undefined
|
|
194
|
+
|
|
195
|
+
const rx = axisRatio(cp.current?.x, cp.limit?.x)
|
|
196
|
+
const ry = axisRatio(cp.current?.y, cp.limit?.y)
|
|
197
|
+
const rz = axisRatio(cp.current?.z, cp.limit?.z)
|
|
198
|
+
|
|
199
|
+
const { left, top } = mapCraneLocalPosition(hw, hh, cw, ch, rx, ry)
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
left,
|
|
203
|
+
top,
|
|
204
|
+
forkZ: rz * 100 // forkZ 0~100, 3D 측 (crane-3d) 에서 mast 비율로 매핑
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
28
208
|
render(ctx: CanvasRenderingContext2D) {
|
|
29
209
|
var { left, top, width, height } = this.bounds
|
|
30
210
|
const { x: cx, y: cy } = this.center
|