@fmsim/machine 1.0.83 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/agv-line.js.map +1 -1
  2. package/dist/agv.js.map +1 -1
  3. package/dist/buffer.js.map +1 -1
  4. package/dist/carrier.js +1 -0
  5. package/dist/carrier.js.map +1 -1
  6. package/dist/conveyor-join.js.map +1 -1
  7. package/dist/conveyor.js +1 -1
  8. package/dist/conveyor.js.map +1 -1
  9. package/dist/crane-rail.js +53 -0
  10. package/dist/crane-rail.js.map +1 -0
  11. package/dist/crane.js.map +1 -1
  12. package/dist/equipment.js.map +1 -1
  13. package/dist/factories/agv-3d.js +121 -0
  14. package/dist/factories/agv-3d.js.map +1 -0
  15. package/dist/factories/conveyor-3d.js +258 -0
  16. package/dist/factories/conveyor-3d.js.map +1 -0
  17. package/dist/factories/crane-3d.js +150 -0
  18. package/dist/factories/crane-3d.js.map +1 -0
  19. package/dist/factories/crane-rail-3d.js +95 -0
  20. package/dist/factories/crane-rail-3d.js.map +1 -0
  21. package/dist/factories/machine-3d.js +288 -0
  22. package/dist/factories/machine-3d.js.map +1 -0
  23. package/dist/factories/oht-3d.js +151 -0
  24. package/dist/factories/oht-3d.js.map +1 -0
  25. package/dist/factories/shuttle-3d.js +136 -0
  26. package/dist/factories/shuttle-3d.js.map +1 -0
  27. package/dist/index.js +38 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcs-carrier-holder.js +6 -1
  30. package/dist/mcs-carrier-holder.js.map +1 -1
  31. package/dist/mcs-machine.js.map +1 -1
  32. package/dist/mcs-unit.js.map +1 -1
  33. package/dist/mcs-vehicle.js +2 -1
  34. package/dist/mcs-vehicle.js.map +1 -1
  35. package/dist/oht-line.js.map +1 -1
  36. package/dist/oht.js.map +1 -1
  37. package/dist/port-flow.js +5 -2
  38. package/dist/port-flow.js.map +1 -1
  39. package/dist/port.js.map +1 -1
  40. package/dist/scene/root-container-override.js.map +1 -1
  41. package/dist/shelf.js.map +1 -1
  42. package/dist/shuttle.js.map +1 -1
  43. package/dist/stocker-abnormal-bar.js +180 -0
  44. package/dist/stocker-abnormal-bar.js.map +1 -0
  45. package/dist/stocker-capacity-bar.js.map +1 -1
  46. package/dist/stocker-carrier-bar.js +194 -0
  47. package/dist/stocker-carrier-bar.js.map +1 -0
  48. package/dist/stocker.js +1 -1
  49. package/dist/stocker.js.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/dist/zone-capacity-bar.js.map +1 -1
  52. package/package.json +6 -6
  53. package/src/agv-line.ts +1 -1
  54. package/src/agv.ts +3 -3
  55. package/src/buffer.ts +1 -1
  56. package/src/carrier.ts +8 -8
  57. package/src/conveyor-join.ts +1 -1
  58. package/src/conveyor.ts +2 -2
  59. package/src/crane-rail.ts +58 -0
  60. package/src/crane.ts +1 -1
  61. package/src/equipment.ts +1 -1
  62. package/src/factories/agv-3d.ts +135 -0
  63. package/src/factories/conveyor-3d.ts +311 -0
  64. package/src/factories/crane-3d.ts +176 -0
  65. package/src/factories/crane-rail-3d.ts +114 -0
  66. package/src/factories/machine-3d.ts +361 -0
  67. package/src/factories/oht-3d.ts +172 -0
  68. package/src/factories/shuttle-3d.ts +159 -0
  69. package/src/index.ts +40 -0
  70. package/src/mcs-carrier-holder.ts +8 -2
  71. package/src/mcs-machine.ts +1 -1
  72. package/src/mcs-unit.ts +1 -1
  73. package/src/mcs-vehicle.ts +3 -3
  74. package/src/oht-line.ts +1 -1
  75. package/src/oht.ts +1 -1
  76. package/src/port-flow.ts +4 -3
  77. package/src/port.ts +1 -1
  78. package/src/scene/root-container-override.ts +2 -2
  79. package/src/shelf.ts +1 -1
  80. package/src/shuttle.ts +1 -1
  81. package/src/stocker-abnormal-bar.ts +242 -0
  82. package/src/stocker-capacity-bar.ts +3 -3
  83. package/src/stocker-carrier-bar.ts +257 -0
  84. package/src/stocker.ts +3 -3
  85. package/src/zone-capacity-bar.ts +2 -2
@@ -0,0 +1,361 @@
1
+ /**
2
+ * MCS 설비 컴포넌트 3D 팩토리
3
+ *
4
+ * 10,000+ 인스턴스를 위한 최소 폴리곤 설계:
5
+ * - 컴포넌트당 단일 Mesh (draw call 최소화)
6
+ * - BoxGeometry / ExtrudeGeometry(hexagon) 만 사용
7
+ * - Machine: 높은 depth, 컨테이너는 반투명
8
+ * - Unit: 낮은 depth, 불투명
9
+ */
10
+
11
+ import * as THREE from 'three'
12
+ import { RealObjectGroup, registerRealObjectFactory } from '@hatiolab/things-scene'
13
+ import type { Component } from '@hatiolab/things-scene'
14
+
15
+ // ── 설정 타입 ────────────────────────────────────────────
16
+
17
+ interface MCS3DConfig {
18
+ /** state.depth 미설정 시 기본 depth.
19
+ * defaultDepth > 0이면 절대값, 아니면 min(w,h) * depthRatio */
20
+ depthRatio: number
21
+ defaultDepth?: number
22
+ /** true이면 syncZPosOffset = TRANSPORT_SURFACE_HEIGHT */
23
+ defaultZPosFromParent?: boolean
24
+ /** 1.0 = 불투명, 0.35 = 반투명 컨테이너 */
25
+ opacity: number
26
+ metalness: number
27
+ roughness: number
28
+ /** statusColor 미사용 시 기본 색상 */
29
+ defaultColor: number
30
+ /** 'box' | 'hexagon' */
31
+ shape: 'box' | 'hexagon'
32
+ /** mesh 생성 전 가시성 판정 — false 반환 시 mesh 미생성 */
33
+ isVisible?: (component: Component) => boolean
34
+ /** 부모 대비 크기 비율 (기본 1.0). < 1이면 부모 중심에 배치. */
35
+ sizeRatio?: number
36
+ }
37
+
38
+ /**
39
+ * 포트 기본 높이 (절대값).
40
+ * 모든 이송장치의 상단 높이 = 이 값.
41
+ * 캐리어가 이송장치 간 높이 차 없이 이동할 수 있는 기준 높이.
42
+ */
43
+ export const TRANSPORT_SURFACE_HEIGHT = 30
44
+
45
+ const DEFAULTS: MCS3DConfig = {
46
+ depthRatio: 0.5,
47
+ opacity: 1.0,
48
+ metalness: 0.3,
49
+ roughness: 0.7,
50
+ defaultColor: 0xaabbcc,
51
+ shape: 'box',
52
+ }
53
+
54
+ // ── 3D 오브젝트 ──────────────────────────────────────────
55
+
56
+ class MCSRealObject3D extends RealObjectGroup {
57
+ private _config: MCS3DConfig
58
+
59
+ constructor(component: Component, config: MCS3DConfig) {
60
+ super(component)
61
+ this._config = config
62
+ }
63
+
64
+ // width, height 절대값 (음수 값은 양수로 취급)
65
+ private get absSize(): { w: number; h: number } {
66
+ const { width = 10, height = 10 } = this.component.state
67
+ return { w: Math.abs(width), h: Math.abs(height) }
68
+ }
69
+
70
+ get effectiveDepth(): number {
71
+ const { depth } = this.component.state
72
+ if (depth) return depth
73
+ if (this._config.defaultDepth) return this._config.defaultDepth
74
+ const { w, h } = this.absSize
75
+ return Math.min(w, h) * this._config.depthRatio
76
+ }
77
+
78
+ protected get syncZPosOffset(): number {
79
+ // Port: 이송 표면 높이에 배치
80
+ if (this._config.defaultZPosFromParent) {
81
+ return TRANSPORT_SURFACE_HEIGHT
82
+ }
83
+ // Carrier: Port 안이면 중앙, 그 외 컨테이너면 상단 위
84
+ if (this._config.sizeRatio && this._config.sizeRatio < 1) {
85
+ const parentType = this.component.parent?.state?.type
86
+ if (parentType === 'Port' || parentType === 'Shelf' || parentType === 'OHT' || parentType === 'Shuttle') {
87
+ return 0
88
+ }
89
+ return TRANSPORT_SURFACE_HEIGHT
90
+ }
91
+ return 0
92
+ }
93
+
94
+ // 컴포넌트의 상태 색상(statusColor) 또는 fillStyle → Three.js 색상 변환
95
+ private resolveColor(): number {
96
+ const comp = this.component as any
97
+
98
+ // 1) MCSStatusMixin.statusColor (legend 기반 상태 색상)
99
+ // '#F0F0F0'은 상태 미설정 시 기본 fallback — 무시하고 defaultColor 사용
100
+ try {
101
+ const sc = comp.statusColor
102
+ if (typeof sc === 'string' && sc && sc.toUpperCase() !== '#F0F0F0') return new THREE.Color(sc).getHex()
103
+ } catch {
104
+ /* statusColor 미구현 시 무시 */
105
+ }
106
+
107
+ // 2) state.fillStyle fallback
108
+ const { fillStyle } = this.component.state
109
+ if (fillStyle && typeof fillStyle === 'string') {
110
+ try {
111
+ return new THREE.Color(fillStyle).getHex()
112
+ } catch {
113
+ /* 파싱 실패 시 무시 */
114
+ }
115
+ }
116
+
117
+ return this._config.defaultColor
118
+ }
119
+
120
+ // ── Geometry helpers ──
121
+
122
+ /**
123
+ * 바닥면(-Y 방향) 삼각형 제거: z-fighting 근본 해결.
124
+ * 바닥면이 없으면 floor grid와 겹칠 면 자체가 없어진다.
125
+ */
126
+ private removeBottomFace(geometry: THREE.BufferGeometry): THREE.BufferGeometry {
127
+ const posAttr = geometry.getAttribute('position')
128
+ const normAttr = geometry.getAttribute('normal')
129
+ const index = geometry.getIndex()
130
+
131
+ if (!posAttr || !normAttr || !index) return geometry
132
+
133
+ const newIndices: number[] = []
134
+ const normalY = new THREE.Vector3()
135
+
136
+ for (let i = 0; i < index.count; i += 3) {
137
+ const a = index.getX(i)
138
+ const b = index.getX(i + 1)
139
+ const c = index.getX(i + 2)
140
+
141
+ // 세 꼭짓점 노말의 Y 성분 평균으로 방향 판단
142
+ const avgY = (normAttr.getY(a) + normAttr.getY(b) + normAttr.getY(c)) / 3
143
+
144
+ // -Y 방향 삼각형 제거 (threshold -0.9: 거의 아래를 향하는 면만)
145
+ if (avgY > -0.9) {
146
+ newIndices.push(a, b, c)
147
+ }
148
+ }
149
+
150
+ geometry.setIndex(newIndices)
151
+ return geometry
152
+ }
153
+
154
+ // ── Geometry builders ──
155
+
156
+ private buildBoxGeometry(w: number, d: number, h: number): THREE.BufferGeometry {
157
+ const geo = new THREE.BoxGeometry(w, d, h)
158
+ return this.removeBottomFace(geo)
159
+ }
160
+
161
+ private buildHexagonGeometry(w: number, d: number, h: number): THREE.BufferGeometry {
162
+ // Buffer의 2D 형태: 좌우 끝이 꺾인 육각형
163
+ const offset = Math.min(w, h) * 0.2
164
+ const hw = w / 2
165
+ const hh = h / 2
166
+
167
+ const shape = new THREE.Shape()
168
+ shape.moveTo(-hw + offset, -hh)
169
+ shape.lineTo(hw - offset, -hh)
170
+ shape.lineTo(hw, 0)
171
+ shape.lineTo(hw - offset, hh)
172
+ shape.lineTo(-hw + offset, hh)
173
+ shape.lineTo(-hw, 0)
174
+ shape.closePath()
175
+
176
+ const geo = new THREE.ExtrudeGeometry(shape, {
177
+ steps: 1,
178
+ depth: d,
179
+ bevelEnabled: false,
180
+ })
181
+
182
+ // 중심 정렬 후 Y-up 좌표계 회전 (extrude 축: +Z → +Y)
183
+ geo.translate(0, 0, -d / 2)
184
+ geo.rotateX(Math.PI / 2)
185
+
186
+ return this.removeBottomFace(geo)
187
+ }
188
+
189
+ // ── Build ──
190
+
191
+ build() {
192
+ super.build()
193
+
194
+ // 가시성 판정 — e.g., Carrier는 데이터 없으면 mesh 미생성
195
+ if (this._config.isVisible && !this._config.isVisible(this.component)) return
196
+
197
+ const { w: rawW, h: rawH } = this.absSize
198
+ const rawDepth = this.effectiveDepth
199
+ if (!rawW || !rawH) return
200
+
201
+ const ratio = this._config.sizeRatio ?? 1.0
202
+ const w = rawW * ratio
203
+ const h = rawH * ratio
204
+ const depth = rawDepth * ratio
205
+
206
+ const color = this.resolveColor()
207
+ const { opacity, metalness, roughness, shape } = this._config
208
+
209
+ const geometry =
210
+ shape === 'hexagon'
211
+ ? this.buildHexagonGeometry(w, depth, h)
212
+ : this.buildBoxGeometry(w, depth, h)
213
+
214
+ const material = new THREE.MeshStandardMaterial({
215
+ color,
216
+ metalness,
217
+ roughness,
218
+ opacity,
219
+ transparent: opacity < 1,
220
+ side: opacity < 1 ? THREE.DoubleSide : THREE.FrontSide,
221
+ depthWrite: opacity >= 0.9,
222
+ })
223
+ // z-fighting 방지: 바닥면(floor grid)보다 항상 앞에 렌더링
224
+ material.polygonOffset = true
225
+ material.polygonOffsetFactor = -1
226
+ material.polygonOffsetUnit = -1
227
+
228
+ const mesh = new THREE.Mesh(geometry, material)
229
+ // sizeRatio < 1이면 부모 중심에 배치 (rawDepth/2), 아니면 자체 중심 (depth/2)
230
+ mesh.position.y = ratio < 1 ? rawDepth / 2 : depth / 2
231
+ mesh.castShadow = true
232
+ mesh.receiveShadow = true
233
+ this.object3d.add(mesh)
234
+ }
235
+
236
+ // ── Change handling ──
237
+
238
+ onchange(after: Record<string, unknown>, before: Record<string, unknown>) {
239
+ if (
240
+ 'width' in after ||
241
+ 'height' in after ||
242
+ 'depth' in after ||
243
+ 'fillStyle' in after ||
244
+ 'strokeStyle' in after ||
245
+ 'id' in after // Carrier: CARRIERNAME 변경 시 가시성 재판정
246
+ ) {
247
+ this.update()
248
+ return
249
+ }
250
+
251
+ super.onchange(after, before)
252
+ }
253
+
254
+ // RealObjectGroup 기본 동작 비활성화 (update()에서 일괄 처리)
255
+ updateDimension() {}
256
+ updateAlpha() {}
257
+ }
258
+
259
+ // ── 팩토리 등록 헬퍼 ─────────────────────────────────────
260
+
261
+ function register(type: string, overrides: Partial<MCS3DConfig> = {}) {
262
+ const config: MCS3DConfig = { ...DEFAULTS, ...overrides }
263
+ registerRealObjectFactory(type, (component: Component) => new MCSRealObject3D(component, config))
264
+ }
265
+
266
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
267
+ // Machine (인프라 설비) — 높은 depth, 컨테이너는 반투명
268
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
269
+
270
+ register('Equipment', {
271
+ defaultDepth: 3 * TRANSPORT_SURFACE_HEIGHT,
272
+ opacity: 0.5,
273
+ metalness: 0.4,
274
+ roughness: 0.6,
275
+ defaultColor: 0x8899aa,
276
+ })
277
+
278
+ register('Buffer', {
279
+ defaultDepth: TRANSPORT_SURFACE_HEIGHT,
280
+ opacity: 0.5,
281
+ metalness: 0.3,
282
+ roughness: 0.7,
283
+ defaultColor: 0x99aa88,
284
+ shape: 'hexagon',
285
+ })
286
+
287
+ register('AGVLine', {
288
+ depthRatio: 0.12,
289
+ metalness: 0.6,
290
+ roughness: 0.3,
291
+ defaultColor: 0x888899,
292
+ })
293
+
294
+ register('OHTLine', {
295
+ depthRatio: 0.12,
296
+ metalness: 0.6,
297
+ roughness: 0.3,
298
+ defaultColor: 0x888899,
299
+ })
300
+
301
+ register('STOCKER', {
302
+ defaultDepth: 5 * TRANSPORT_SURFACE_HEIGHT,
303
+ opacity: 0.35,
304
+ metalness: 0.3,
305
+ roughness: 0.6,
306
+ defaultColor: 0x8899bb,
307
+ })
308
+
309
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
310
+ // Unit (이동체 · 홀더) — 낮은 depth, 불투명
311
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
312
+
313
+ register('Port', {
314
+ depthRatio: 0.5,
315
+ defaultZPosFromParent: true,
316
+ opacity: 0.5,
317
+ metalness: 0.4,
318
+ roughness: 0.6,
319
+ defaultColor: 0xb0a090,
320
+ })
321
+
322
+ register('Shelf', {
323
+ depthRatio: 0.25,
324
+ metalness: 0.3,
325
+ roughness: 0.7,
326
+ defaultColor: 0xaabbcc,
327
+ })
328
+
329
+ register('Carrier', {
330
+ depthRatio: 0.5,
331
+ metalness: 0.2,
332
+ roughness: 0.8,
333
+ defaultColor: 0x66bb66,
334
+ isVisible: (c: Component) => !!(c.state as any).id,
335
+ sizeRatio: 0.8,
336
+ })
337
+
338
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
339
+ // Gauge (용량 게이지) — 얇은 바
340
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
341
+
342
+ register('ZoneCapacityBar', {
343
+ depthRatio: 0.15,
344
+ metalness: 0.2,
345
+ roughness: 0.8,
346
+ defaultColor: 0x44aa44,
347
+ })
348
+
349
+ register('StockerCapacityBar', {
350
+ depthRatio: 0.15,
351
+ metalness: 0.2,
352
+ roughness: 0.8,
353
+ defaultColor: 0x44aa44,
354
+ })
355
+
356
+ register('MCSGaugeCapacityBar', {
357
+ depthRatio: 0.15,
358
+ metalness: 0.2,
359
+ roughness: 0.8,
360
+ defaultColor: 0x44aa44,
361
+ })
@@ -0,0 +1,172 @@
1
+ /**
2
+ * OHT (Overhead Hoist Transport) 3D Factory
3
+ *
4
+ * 천장 레일에 매달려 이동하는 반송 차량. 캐리어를 호이스트로 운반.
5
+ * 구조 (바닥 원점, y=0~depth):
6
+ * - 하단 그리퍼 바 (캐리어 집는 가로 바)
7
+ * - 호이스트 암 (좌우 수직 기둥)
8
+ * - 본체 하우징 (statusColor 적용)
9
+ * - 상단 트롤리 (납작+넓은 레일 클램프 + 좌우 바퀴)
10
+ */
11
+
12
+ import * as THREE from 'three'
13
+ import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js'
14
+ import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry.js'
15
+ import { RealObjectGroup, registerRealObjectFactory } from '@hatiolab/things-scene'
16
+ import type { Component } from '@hatiolab/things-scene'
17
+ import { TRANSPORT_SURFACE_HEIGHT } from './machine-3d.js'
18
+
19
+ const TROLLEY_COLOR = 0x222222
20
+ const FRAME_COLOR = 0x444444
21
+ const DEFAULT_BODY_COLOR = 0x6688cc
22
+
23
+ /** OHT 레일 높이: 스토커(5x) 위 */
24
+ const OHT_RAIL_HEIGHT = 6 * TRANSPORT_SURFACE_HEIGHT
25
+
26
+ export class OHT3D extends RealObjectGroup {
27
+ get effectiveDepth(): number {
28
+ const { depth } = this.component.state
29
+ return depth || TRANSPORT_SURFACE_HEIGHT
30
+ }
31
+
32
+ /** 천장 레일 높이에 배치 */
33
+ protected get syncZPosOffset(): number {
34
+ return OHT_RAIL_HEIGHT
35
+ }
36
+
37
+ private resolveColor(): number {
38
+ const comp = this.component as any
39
+
40
+ try {
41
+ const sc = comp.statusColor
42
+ if (typeof sc === 'string' && sc && sc.toUpperCase() !== '#F0F0F0') return new THREE.Color(sc).getHex()
43
+ } catch {
44
+ /* statusColor 미구현 시 무시 */
45
+ }
46
+
47
+ const { fillStyle } = this.component.state
48
+ if (fillStyle && typeof fillStyle === 'string') {
49
+ try {
50
+ return new THREE.Color(fillStyle).getHex()
51
+ } catch {
52
+ /* 파싱 실패 시 무시 */
53
+ }
54
+ }
55
+
56
+ return DEFAULT_BODY_COLOR
57
+ }
58
+
59
+ build() {
60
+ super.build()
61
+
62
+ const { width = 10, height = 10 } = this.component.state
63
+ const w = Math.abs(width)
64
+ const h = Math.abs(height)
65
+ const d = this.effectiveDepth
66
+ if (!w || !h) return
67
+
68
+ // 높이 배분: 그리퍼 8%, 호이스트암 22%, 본체 45%, 간격 5%, 트롤리 12%, 바퀴 8%
69
+ const gripperBarH = d * 0.08
70
+ const armH = d * 0.22
71
+ const bodyH = d * 0.45
72
+ const gap = d * 0.05
73
+ const trolleyH = d * 0.12
74
+ const wheelH = d * 0.08
75
+
76
+ const armThickness = Math.min(w, h) * 0.12
77
+ const bodyCornerR = Math.min(w, h, bodyH) * 0.1
78
+
79
+ const frameMat = new THREE.MeshStandardMaterial({
80
+ color: FRAME_COLOR,
81
+ roughness: 0.5,
82
+ metalness: 0.4,
83
+ })
84
+
85
+ // ── 1. 하단 그리퍼 바 (캐리어를 집는 가로 바) ──
86
+ const gripperBarW = w * 0.7
87
+ const gripperBarD = h * 0.15
88
+ const gripperGeo = new THREE.BoxGeometry(gripperBarW, gripperBarH, gripperBarD)
89
+ const gripperMesh = new THREE.Mesh(gripperGeo, frameMat)
90
+ gripperMesh.position.y = gripperBarH / 2
91
+ gripperMesh.castShadow = true
92
+ this.object3d.add(gripperMesh)
93
+
94
+ // ── 2. 호이스트 암 (좌우 수직 기둥 + 하단 가로연결) ──
95
+ const armBaseY = gripperBarH
96
+ const armGeometries: THREE.BufferGeometry[] = []
97
+
98
+ // 좌우 수직 기둥
99
+ for (const xSign of [-1, 1]) {
100
+ const pillar = new THREE.BoxGeometry(armThickness, armH, armThickness)
101
+ pillar.translate(xSign * (w * 0.3), armBaseY + armH / 2, 0)
102
+ armGeometries.push(pillar)
103
+ }
104
+
105
+ // 하단 가로 연결 바 (그리퍼와 암을 잇는 수평 바)
106
+ const crossBarW = w * 0.6 + armThickness
107
+ const crossBarH = armThickness * 0.6
108
+ const crossBar = new THREE.BoxGeometry(crossBarW, crossBarH, armThickness)
109
+ crossBar.translate(0, armBaseY + crossBarH / 2, 0)
110
+ armGeometries.push(crossBar)
111
+
112
+ const armMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(armGeometries), frameMat)
113
+ armMesh.castShadow = true
114
+ this.object3d.add(armMesh)
115
+
116
+ // ── 3. 본체 하우징 (statusColor 적용) ──
117
+ const bodyBaseY = armBaseY + armH
118
+ const bodyColor = this.resolveColor()
119
+ const bodyGeo = new RoundedBoxGeometry(w, bodyH, h, 4, bodyCornerR)
120
+ const bodyMat = new THREE.MeshStandardMaterial({
121
+ color: bodyColor,
122
+ roughness: 0.3,
123
+ metalness: 0.5,
124
+ })
125
+ const bodyMesh = new THREE.Mesh(bodyGeo, bodyMat)
126
+ bodyMesh.position.y = bodyBaseY + bodyH / 2
127
+ bodyMesh.castShadow = true
128
+ bodyMesh.receiveShadow = true
129
+ this.object3d.add(bodyMesh)
130
+
131
+ // ── 4. 상단 트롤리 플레이트 (납작하고 넓은 레일 클램프) ──
132
+ const trolleyBaseY = bodyBaseY + bodyH + gap
133
+ const trolleyW = w * 1.15
134
+ const trolleyD = h * 0.6
135
+ const trolleyGeo = new THREE.BoxGeometry(trolleyW, trolleyH, trolleyD)
136
+ const trolleyMat = new THREE.MeshStandardMaterial({
137
+ color: TROLLEY_COLOR,
138
+ roughness: 0.6,
139
+ metalness: 0.3,
140
+ })
141
+ const trolleyMesh = new THREE.Mesh(trolleyGeo, trolleyMat)
142
+ trolleyMesh.position.y = trolleyBaseY + trolleyH / 2
143
+ trolleyMesh.castShadow = true
144
+ this.object3d.add(trolleyMesh)
145
+
146
+ // ── 5. 좌우 바퀴 (트롤리 위, 레일을 타는 원통형 바퀴) ──
147
+ const wheelBaseY = trolleyBaseY + trolleyH
148
+ const wheelRadius = wheelH / 2
149
+ const wheelDepth = h * 0.2
150
+ for (const xSign of [-1, 1]) {
151
+ const wheelGeo = new THREE.CylinderGeometry(wheelRadius, wheelRadius, wheelDepth, 12)
152
+ wheelGeo.rotateX(Math.PI / 2)
153
+ const wheelMesh = new THREE.Mesh(wheelGeo, trolleyMat)
154
+ wheelMesh.position.set(xSign * (trolleyW * 0.35), wheelBaseY + wheelRadius, 0)
155
+ wheelMesh.castShadow = true
156
+ this.object3d.add(wheelMesh)
157
+ }
158
+ }
159
+
160
+ updateDimension() {}
161
+ updateAlpha() {}
162
+
163
+ onchange(after: Record<string, unknown>, before: Record<string, unknown>) {
164
+ if ('width' in after || 'height' in after || 'depth' in after || 'fillStyle' in after || 'strokeStyle' in after) {
165
+ this.update()
166
+ return
167
+ }
168
+ super.onchange(after, before)
169
+ }
170
+ }
171
+
172
+ registerRealObjectFactory('OHT', (component: Component) => new OHT3D(component))
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Shuttle 3D Factory
3
+ *
4
+ * 스토커 내부에서 캐리어를 선반↔포트 간 이송하는 포크 캐리지.
5
+ * 수평 레일 위를 이동하며, 포크를 밀어넣어 캐리어를 적재/하역.
6
+ *
7
+ * 구조 (바닥 원점, y=0~depth):
8
+ * - 하단 베이스 플레이트 (납작, 넓음, 레일 위 주행부)
9
+ * - 중앙 마스트 (좌우 수직 기둥, statusColor 적용)
10
+ * - 상단 포크 (2개의 평행한 가로 암, 캐리어 적재면)
11
+ */
12
+
13
+ import * as THREE from 'three'
14
+ import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js'
15
+ import { RealObjectGroup, registerRealObjectFactory } from '@hatiolab/things-scene'
16
+ import type { Component } from '@hatiolab/things-scene'
17
+ import { TRANSPORT_SURFACE_HEIGHT } from './machine-3d.js'
18
+
19
+ const BASE_COLOR = 0x333333
20
+ const FORK_COLOR = 0x777777
21
+ const DEFAULT_BODY_COLOR = 0x6688cc
22
+
23
+ export class Shuttle3D extends RealObjectGroup {
24
+ get effectiveDepth(): number {
25
+ const { depth } = this.component.state
26
+ return depth || TRANSPORT_SURFACE_HEIGHT
27
+ }
28
+
29
+ protected get syncZPosOffset(): number {
30
+ return 0
31
+ }
32
+
33
+ private resolveColor(): number {
34
+ const comp = this.component as any
35
+
36
+ try {
37
+ const sc = comp.statusColor
38
+ if (typeof sc === 'string' && sc && sc.toUpperCase() !== '#F0F0F0') return new THREE.Color(sc).getHex()
39
+ } catch {
40
+ /* statusColor 미구현 시 무시 */
41
+ }
42
+
43
+ const { fillStyle } = this.component.state
44
+ if (fillStyle && typeof fillStyle === 'string') {
45
+ try {
46
+ return new THREE.Color(fillStyle).getHex()
47
+ } catch {
48
+ /* 파싱 실패 시 무시 */
49
+ }
50
+ }
51
+
52
+ return DEFAULT_BODY_COLOR
53
+ }
54
+
55
+ build() {
56
+ super.build()
57
+
58
+ const { width = 10, height = 10 } = this.component.state
59
+ const w = Math.abs(width)
60
+ const h = Math.abs(height)
61
+ const d = this.effectiveDepth
62
+ if (!w || !h) return
63
+
64
+ // 높이 배분: 베이스 15%, 마스트 55%, 포크 30%
65
+ const baseH = d * 0.15
66
+ const mastH = d * 0.55
67
+ const forkH = d * 0.30
68
+
69
+ const mastThickness = Math.min(w, h) * 0.15
70
+
71
+ // ── 1. 하단 베이스 플레이트 (납작하고 넓은 주행부) ──
72
+ const basePad = Math.min(w, h) * 0.05
73
+ const baseGeo = new THREE.BoxGeometry(w + basePad * 2, baseH, h + basePad * 2)
74
+ const baseMat = new THREE.MeshStandardMaterial({
75
+ color: BASE_COLOR,
76
+ roughness: 0.7,
77
+ metalness: 0.3,
78
+ })
79
+ const baseMesh = new THREE.Mesh(baseGeo, baseMat)
80
+ baseMesh.position.y = baseH / 2
81
+ baseMesh.castShadow = true
82
+ baseMesh.receiveShadow = true
83
+ this.object3d.add(baseMesh)
84
+
85
+ // ── 2. 좌우 마스트 기둥 (statusColor 적용) ──
86
+ const mastBaseY = baseH
87
+ const bodyColor = this.resolveColor()
88
+ const mastMat = new THREE.MeshStandardMaterial({
89
+ color: bodyColor,
90
+ roughness: 0.4,
91
+ metalness: 0.5,
92
+ })
93
+
94
+ const mastGeometries: THREE.BufferGeometry[] = []
95
+
96
+ // 좌우 수직 기둥
97
+ for (const xSign of [-1, 1]) {
98
+ const pillar = new THREE.BoxGeometry(mastThickness, mastH, mastThickness)
99
+ pillar.translate(xSign * (w / 2 - mastThickness / 2), mastBaseY + mastH / 2, 0)
100
+ mastGeometries.push(pillar)
101
+ }
102
+
103
+ // 중간 가로 연결 바 (구조 강성)
104
+ const crossBarW = w - mastThickness
105
+ const crossBarH = mastThickness * 0.5
106
+ const crossBar = new THREE.BoxGeometry(crossBarW, crossBarH, mastThickness)
107
+ crossBar.translate(0, mastBaseY + mastH * 0.4, 0)
108
+ mastGeometries.push(crossBar)
109
+
110
+ const mastMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(mastGeometries), mastMat)
111
+ mastMesh.castShadow = true
112
+ this.object3d.add(mastMesh)
113
+
114
+ // ── 3. 상단 포크 (2개의 평행 암 + 백 플레이트) ──
115
+ const forkBaseY = mastBaseY + mastH
116
+ const forkMat = new THREE.MeshStandardMaterial({
117
+ color: FORK_COLOR,
118
+ roughness: 0.4,
119
+ metalness: 0.6,
120
+ })
121
+
122
+ const forkGeometries: THREE.BufferGeometry[] = []
123
+
124
+ // 백 플레이트 (마스트 상단을 잇는 가로판)
125
+ const backPlateH = forkH * 0.4
126
+ const backPlate = new THREE.BoxGeometry(w, backPlateH, mastThickness * 0.8)
127
+ backPlate.translate(0, forkBaseY + backPlateH / 2, -h * 0.35)
128
+ forkGeometries.push(backPlate)
129
+
130
+ // 2개의 포크 암 (앞으로 뻗은 평행 막대)
131
+ const forkArmW = mastThickness * 0.7
132
+ const forkArmH = forkH * 0.25
133
+ const forkArmD = h * 0.85
134
+ const forkSpacing = w * 0.55
135
+
136
+ for (const xSign of [-1, 1]) {
137
+ const arm = new THREE.BoxGeometry(forkArmW, forkArmH, forkArmD)
138
+ arm.translate(xSign * (forkSpacing / 2), forkBaseY + forkArmH / 2, forkArmD / 2 - h * 0.35)
139
+ forkGeometries.push(arm)
140
+ }
141
+
142
+ const forkMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(forkGeometries), forkMat)
143
+ forkMesh.castShadow = true
144
+ this.object3d.add(forkMesh)
145
+ }
146
+
147
+ updateDimension() {}
148
+ updateAlpha() {}
149
+
150
+ onchange(after: Record<string, unknown>, before: Record<string, unknown>) {
151
+ if ('width' in after || 'height' in after || 'depth' in after || 'fillStyle' in after || 'strokeStyle' in after) {
152
+ this.update()
153
+ return
154
+ }
155
+ super.onchange(after, before)
156
+ }
157
+ }
158
+
159
+ registerRealObjectFactory('Shuttle', (component: Component) => new Shuttle3D(component))