@fmsim/machine 2.0.0-beta.2 → 2.0.0-beta.20
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/carrier-manager.js +92 -0
- package/dist/carrier-manager.js.map +1 -0
- package/dist/carrier.js +51 -6
- package/dist/carrier.js.map +1 -1
- package/dist/factories/agv-3d.js +34 -6
- package/dist/factories/agv-3d.js.map +1 -1
- package/dist/factories/machine-3d.js +329 -70
- package/dist/factories/machine-3d.js.map +1 -1
- package/dist/factories/oht-3d.js +34 -8
- package/dist/factories/oht-3d.js.map +1 -1
- package/dist/factories/shuttle-3d.js +32 -6
- package/dist/factories/shuttle-3d.js.map +1 -1
- package/dist/index.js +48 -34
- package/dist/index.js.map +1 -1
- package/dist/mcs-carrier-holder.js +39 -22
- package/dist/mcs-carrier-holder.js.map +1 -1
- package/dist/scene/root-container-override.js +9 -0
- package/dist/scene/root-container-override.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.js +10 -0
- package/package.json +4 -3
- package/src/carrier-manager.ts +116 -0
- package/src/carrier.ts +50 -4
- package/src/factories/agv-3d.ts +34 -6
- package/src/factories/machine-3d.ts +388 -62
- package/src/factories/oht-3d.ts +32 -8
- package/src/factories/shuttle-3d.ts +30 -6
- package/src/index.ts +54 -34
- package/src/mcs-carrier-holder.ts +38 -34
- package/src/scene/root-container-override.ts +12 -0
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import * as THREE from 'three'
|
|
12
|
-
import { RealObjectGroup, registerRealObjectFactory } from '@hatiolab/things-scene'
|
|
12
|
+
import { RealObjectGroup, registerRealObjectFactory, disposeObject3D } from '@hatiolab/things-scene'
|
|
13
13
|
import type { Component } from '@hatiolab/things-scene'
|
|
14
|
+
import { LEGEND_CAPACITY } from '../features/mcs-status-default'
|
|
15
|
+
import { getVaueOnRanges } from '../utils/get-value-on-ranges'
|
|
14
16
|
|
|
15
17
|
// ── 설정 타입 ────────────────────────────────────────────
|
|
16
18
|
|
|
@@ -28,11 +30,21 @@ interface MCS3DConfig {
|
|
|
28
30
|
/** statusColor 미사용 시 기본 색상 */
|
|
29
31
|
defaultColor: number
|
|
30
32
|
/** 'box' | 'hexagon' */
|
|
31
|
-
shape: 'box' | 'hexagon'
|
|
33
|
+
shape: 'box' | 'hexagon' | 'plane'
|
|
32
34
|
/** mesh 생성 전 가시성 판정 — false 반환 시 mesh 미생성 */
|
|
33
35
|
isVisible?: (component: Component) => boolean
|
|
34
36
|
/** 부모 대비 크기 비율 (기본 1.0). < 1이면 부모 중심에 배치. */
|
|
35
37
|
sizeRatio?: number
|
|
38
|
+
/** 상부 면 제거 (5면 개방 박스) */
|
|
39
|
+
openTop?: boolean
|
|
40
|
+
/** 상판 무반사 (MeshBasicMaterial) */
|
|
41
|
+
matteTop?: boolean
|
|
42
|
+
/** 상판에 2D 렌더링 텍스처 적용 */
|
|
43
|
+
texturedTop?: boolean
|
|
44
|
+
/** 자체 발광 강도 (0~1). 조명 약한 면에서도 색상 유지 */
|
|
45
|
+
emissiveIntensity?: number
|
|
46
|
+
/** 바닥면 유지 (기본 false — 바닥면 제거) */
|
|
47
|
+
keepBottomFace?: boolean
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
/**
|
|
@@ -62,7 +74,7 @@ class MCSRealObject3D extends RealObjectGroup {
|
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
// width, height 절대값 (음수 값은 양수로 취급)
|
|
65
|
-
|
|
77
|
+
protected get absSize(): { w: number; h: number } {
|
|
66
78
|
const { width = 10, height = 10 } = this.component.state
|
|
67
79
|
return { w: Math.abs(width), h: Math.abs(height) }
|
|
68
80
|
}
|
|
@@ -92,7 +104,7 @@ class MCSRealObject3D extends RealObjectGroup {
|
|
|
92
104
|
}
|
|
93
105
|
|
|
94
106
|
// 컴포넌트의 상태 색상(statusColor) 또는 fillStyle → Three.js 색상 변환
|
|
95
|
-
|
|
107
|
+
protected resolveColor(): number {
|
|
96
108
|
const comp = this.component as any
|
|
97
109
|
|
|
98
110
|
// 1) MCSStatusMixin.statusColor (legend 기반 상태 색상)
|
|
@@ -155,7 +167,7 @@ class MCSRealObject3D extends RealObjectGroup {
|
|
|
155
167
|
|
|
156
168
|
private buildBoxGeometry(w: number, d: number, h: number): THREE.BufferGeometry {
|
|
157
169
|
const geo = new THREE.BoxGeometry(w, d, h)
|
|
158
|
-
return this.removeBottomFace(geo)
|
|
170
|
+
return this._config.keepBottomFace ? geo : this.removeBottomFace(geo)
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
private buildHexagonGeometry(w: number, d: number, h: number): THREE.BufferGeometry {
|
|
@@ -186,8 +198,16 @@ class MCSRealObject3D extends RealObjectGroup {
|
|
|
186
198
|
return this.removeBottomFace(geo)
|
|
187
199
|
}
|
|
188
200
|
|
|
201
|
+
private buildPlaneGeometry(w: number, h: number): THREE.BufferGeometry {
|
|
202
|
+
const geo = new THREE.PlaneGeometry(w, h)
|
|
203
|
+
geo.rotateX(-Math.PI / 2)
|
|
204
|
+
return geo
|
|
205
|
+
}
|
|
206
|
+
|
|
189
207
|
// ── Build ──
|
|
190
208
|
|
|
209
|
+
protected _ownMesh?: THREE.Mesh
|
|
210
|
+
|
|
191
211
|
build() {
|
|
192
212
|
super.build()
|
|
193
213
|
|
|
@@ -207,34 +227,66 @@ class MCSRealObject3D extends RealObjectGroup {
|
|
|
207
227
|
const { opacity, metalness, roughness, shape } = this._config
|
|
208
228
|
|
|
209
229
|
const geometry =
|
|
210
|
-
shape === '
|
|
211
|
-
? this.
|
|
212
|
-
:
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
230
|
+
shape === 'plane'
|
|
231
|
+
? this.buildPlaneGeometry(w, h)
|
|
232
|
+
: shape === 'hexagon'
|
|
233
|
+
? this.buildHexagonGeometry(w, depth, h)
|
|
234
|
+
: this.buildBoxGeometry(w, depth, h)
|
|
235
|
+
|
|
236
|
+
const isPlane = shape === 'plane'
|
|
237
|
+
const material = isPlane
|
|
238
|
+
? new THREE.MeshBasicMaterial({
|
|
239
|
+
color,
|
|
240
|
+
opacity,
|
|
241
|
+
transparent: opacity < 1,
|
|
242
|
+
side: THREE.DoubleSide,
|
|
243
|
+
depthWrite: opacity >= 0.9,
|
|
244
|
+
})
|
|
245
|
+
: new THREE.MeshStandardMaterial({
|
|
246
|
+
color,
|
|
247
|
+
metalness,
|
|
248
|
+
roughness,
|
|
249
|
+
opacity,
|
|
250
|
+
transparent: opacity < 1,
|
|
251
|
+
side: opacity < 1 ? THREE.DoubleSide : THREE.FrontSide,
|
|
252
|
+
depthWrite: opacity >= 0.9,
|
|
253
|
+
...(this._config.emissiveIntensity ? { emissive: color, emissiveIntensity: this._config.emissiveIntensity } : {}),
|
|
254
|
+
})
|
|
223
255
|
// z-fighting 방지: 바닥면(floor grid)보다 항상 앞에 렌더링
|
|
224
256
|
material.polygonOffset = true
|
|
225
257
|
material.polygonOffsetFactor = -1
|
|
226
258
|
material.polygonOffsetUnit = -1
|
|
227
259
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
260
|
+
// BoxGeometry material groups: +x(0), -x(1), +y(2), -y(3), +z(4), -z(5)
|
|
261
|
+
let meshMaterial: THREE.Material | THREE.Material[] = material
|
|
262
|
+
if (shape === 'box') {
|
|
263
|
+
if (this._config.openTop) {
|
|
264
|
+
// 상단면 제거 → 5면 개방 박스
|
|
265
|
+
const invisible = new THREE.MeshBasicMaterial({ visible: false })
|
|
266
|
+
meshMaterial = [material, material, invisible, material, material, material]
|
|
267
|
+
} else if (this._config.texturedTop) {
|
|
268
|
+
// 상판에 2D 렌더링 텍스처
|
|
269
|
+
const topMat = this.buildTopTexture(w, h)
|
|
270
|
+
meshMaterial = [material, material, topMat, material, material, material]
|
|
271
|
+
} else if (this._config.matteTop) {
|
|
272
|
+
// 상판만 무반사
|
|
273
|
+
const matte = new THREE.MeshBasicMaterial({ color, opacity, transparent: opacity < 1 })
|
|
274
|
+
meshMaterial = [material, material, matte, material, material, material]
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
this._ownMesh = new THREE.Mesh(geometry, meshMaterial)
|
|
279
|
+
// sizeRatio < 1이면 부모 중심에 배치 (rawDepth/2), plane은 살짝 띄움
|
|
280
|
+
this._ownMesh.position.y = isPlane ? 1 : ratio < 1 ? rawDepth / 2 : depth / 2
|
|
281
|
+
this._ownMesh.castShadow = !isPlane
|
|
282
|
+
this._ownMesh.receiveShadow = true
|
|
283
|
+
this.object3d.add(this._ownMesh)
|
|
234
284
|
}
|
|
235
285
|
|
|
236
286
|
// ── Change handling ──
|
|
237
287
|
|
|
288
|
+
private _updatePending = false
|
|
289
|
+
|
|
238
290
|
onchange(after: Record<string, unknown>, before: Record<string, unknown>) {
|
|
239
291
|
if (
|
|
240
292
|
'width' in after ||
|
|
@@ -242,18 +294,117 @@ class MCSRealObject3D extends RealObjectGroup {
|
|
|
242
294
|
'depth' in after ||
|
|
243
295
|
'fillStyle' in after ||
|
|
244
296
|
'strokeStyle' in after ||
|
|
245
|
-
'id' in after
|
|
297
|
+
'id' in after ||
|
|
298
|
+
'EMPTYTYPE' in after ||
|
|
299
|
+
'CARRIERSTATUS' in after
|
|
246
300
|
) {
|
|
247
|
-
|
|
301
|
+
// 연속 setState에 의한 다중 rebuild 방지: 한 프레임에 한 번만 실행
|
|
302
|
+
if (!this._updatePending) {
|
|
303
|
+
this._updatePending = true
|
|
304
|
+
queueMicrotask(() => {
|
|
305
|
+
this._updatePending = false
|
|
306
|
+
this.update()
|
|
307
|
+
})
|
|
308
|
+
}
|
|
248
309
|
return
|
|
249
310
|
}
|
|
250
311
|
|
|
251
312
|
super.onchange(after, before)
|
|
252
313
|
}
|
|
253
314
|
|
|
254
|
-
|
|
315
|
+
/**
|
|
316
|
+
* 상판 텍스처: 컴포넌트의 2D render()를 캔버스에 그려서 텍스처로 사용
|
|
317
|
+
*/
|
|
318
|
+
protected buildTopTexture(w: number, h: number): THREE.MeshBasicMaterial {
|
|
319
|
+
const scale = 4
|
|
320
|
+
const cw = this.nextPow2(w * scale)
|
|
321
|
+
const ch = this.nextPow2(h * scale)
|
|
322
|
+
const canvas = document.createElement('canvas')
|
|
323
|
+
canvas.width = cw
|
|
324
|
+
canvas.height = ch
|
|
325
|
+
const ctx = canvas.getContext('2d')!
|
|
326
|
+
|
|
327
|
+
const statusColor = '#' + this.resolveColor().toString(16).padStart(6, '0')
|
|
328
|
+
const emptyType = (this.component.state as any)?.EMPTYTYPE || ''
|
|
329
|
+
const text = emptyType === 'FULL' ? 'F' : emptyType === 'EMPTY' ? 'E' : emptyType === 'EMPTYEMPTY' ? 'X' : ''
|
|
330
|
+
|
|
331
|
+
// 실제 사용 영역 (nextPow2 이전 크기)
|
|
332
|
+
const usedW = w * scale
|
|
333
|
+
const usedH = h * scale
|
|
334
|
+
|
|
335
|
+
// 바탕: 캐리어 상태 색상 (사용 영역만)
|
|
336
|
+
ctx.fillStyle = statusColor
|
|
337
|
+
ctx.fillRect(0, 0, usedW, usedH)
|
|
338
|
+
|
|
339
|
+
// 텍스트 (사용 영역 중앙)
|
|
340
|
+
if (text) {
|
|
341
|
+
const fontSize = Math.round(Math.min(usedW, usedH) * 0.7)
|
|
342
|
+
ctx.font = `bold ${fontSize}px Arial`
|
|
343
|
+
ctx.textAlign = 'center'
|
|
344
|
+
ctx.textBaseline = 'middle'
|
|
345
|
+
ctx.fillStyle = '#000000'
|
|
346
|
+
ctx.fillText(text, usedW / 2, usedH / 2)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const texture = new THREE.CanvasTexture(canvas)
|
|
350
|
+
texture.offset.set(0, 1 - usedH / ch)
|
|
351
|
+
texture.repeat.set(usedW / cw, usedH / ch)
|
|
352
|
+
texture.colorSpace = THREE.SRGBColorSpace
|
|
353
|
+
|
|
354
|
+
return new THREE.MeshBasicMaterial({
|
|
355
|
+
map: texture,
|
|
356
|
+
transparent: true,
|
|
357
|
+
side: THREE.DoubleSide,
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
private nextPow2(n: number): number {
|
|
362
|
+
if (!(n > 0)) return 1
|
|
363
|
+
let v = Math.ceil(n)
|
|
364
|
+
v--
|
|
365
|
+
v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16
|
|
366
|
+
return v + 1
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* 자신의 mesh만 제거 후 rebuild.
|
|
371
|
+
* 기본 update()는 clear()로 object3d의 모든 children을 제거하는데,
|
|
372
|
+
* 컨테이너(Port 등)의 경우 자식 컴포넌트(Carrier 등)의 3D 오브젝트도 함께 제거됨.
|
|
373
|
+
* 이를 방지하기 위해 자신이 생성한 mesh만 제거한다.
|
|
374
|
+
*/
|
|
375
|
+
update() {
|
|
376
|
+
// 자신의 mesh만 제거 (자식 컴포넌트 3D 오브젝트 보존)
|
|
377
|
+
if (this._ownMesh) {
|
|
378
|
+
this.object3d.remove(this._ownMesh)
|
|
379
|
+
disposeObject3D(this._ownMesh)
|
|
380
|
+
this._ownMesh = undefined
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
this.build()
|
|
384
|
+
this.updateTransform()
|
|
385
|
+
this.updateAlpha()
|
|
386
|
+
this.updateHidden()
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// RealObjectGroup 기본 동작 비활성화
|
|
255
390
|
updateDimension() {}
|
|
256
|
-
|
|
391
|
+
|
|
392
|
+
updateAlpha() {
|
|
393
|
+
const { alpha = 1 } = this.component.state
|
|
394
|
+
const configOpacity = this._config.opacity
|
|
395
|
+
const effective = configOpacity * alpha
|
|
396
|
+
|
|
397
|
+
this.object3d.traverse((o: any) => {
|
|
398
|
+
if (!o.material) return
|
|
399
|
+
const materials = Array.isArray(o.material) ? o.material : [o.material]
|
|
400
|
+
for (const m of materials) {
|
|
401
|
+
if (!m.visible) continue // openTop invisible face 무시
|
|
402
|
+
if (m.map) continue // 텍스처 material은 자체 transparent 유지
|
|
403
|
+
m.opacity = effective
|
|
404
|
+
m.transparent = effective < 1
|
|
405
|
+
}
|
|
406
|
+
})
|
|
407
|
+
}
|
|
257
408
|
}
|
|
258
409
|
|
|
259
410
|
// ── 팩토리 등록 헬퍼 ─────────────────────────────────────
|
|
@@ -269,7 +420,7 @@ function register(type: string, overrides: Partial<MCS3DConfig> = {}) {
|
|
|
269
420
|
|
|
270
421
|
register('Equipment', {
|
|
271
422
|
defaultDepth: 3 * TRANSPORT_SURFACE_HEIGHT,
|
|
272
|
-
opacity: 0.
|
|
423
|
+
opacity: 0.75,
|
|
273
424
|
metalness: 0.4,
|
|
274
425
|
roughness: 0.6,
|
|
275
426
|
defaultColor: 0x8899aa,
|
|
@@ -277,7 +428,7 @@ register('Equipment', {
|
|
|
277
428
|
|
|
278
429
|
register('Buffer', {
|
|
279
430
|
defaultDepth: TRANSPORT_SURFACE_HEIGHT,
|
|
280
|
-
opacity: 0
|
|
431
|
+
opacity: 1.0,
|
|
281
432
|
metalness: 0.3,
|
|
282
433
|
roughness: 0.7,
|
|
283
434
|
defaultColor: 0x99aa88,
|
|
@@ -298,26 +449,201 @@ register('OHTLine', {
|
|
|
298
449
|
defaultColor: 0x888899,
|
|
299
450
|
})
|
|
300
451
|
|
|
301
|
-
|
|
452
|
+
// STOCKER: 벽면에 용량 게이지 바를 포함하는 커스텀 3D 오브젝트
|
|
453
|
+
const STOCKER_CONFIG: MCS3DConfig = {
|
|
454
|
+
...DEFAULTS,
|
|
302
455
|
defaultDepth: 5 * TRANSPORT_SURFACE_HEIGHT,
|
|
303
|
-
opacity: 0.
|
|
456
|
+
opacity: 0.75,
|
|
304
457
|
metalness: 0.3,
|
|
305
458
|
roughness: 0.6,
|
|
306
459
|
defaultColor: 0x8899bb,
|
|
307
|
-
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
class StockerRealObject3D extends MCSRealObject3D {
|
|
463
|
+
private gaugeMesh?: THREE.Mesh
|
|
464
|
+
|
|
465
|
+
constructor(component: Component) {
|
|
466
|
+
super(component, STOCKER_CONFIG)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
build() {
|
|
470
|
+
super.build()
|
|
471
|
+
this.buildGauge()
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private buildGauge() {
|
|
475
|
+
const comp = this.component as any
|
|
476
|
+
const data = comp.data || {}
|
|
477
|
+
const gaugeMode = comp.root?.style?.stockerGaugeMode || 'capacity'
|
|
478
|
+
|
|
479
|
+
const gauge = this.resolveGauge(data, gaugeMode)
|
|
480
|
+
|
|
481
|
+
// 테두리는 스토커의 상태 색상 (machine status)
|
|
482
|
+
const statusColor = comp.statusColor
|
|
483
|
+
if (statusColor && statusColor.toUpperCase() !== '#F0F0F0') {
|
|
484
|
+
gauge.borderColor = statusColor
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const { w, h } = this.absSize
|
|
488
|
+
const depth = this.effectiveDepth
|
|
489
|
+
const isWidthLonger = w >= h
|
|
490
|
+
|
|
491
|
+
// 게이지 캔버스 (고해상도)
|
|
492
|
+
const barW = 130
|
|
493
|
+
const barH = 26
|
|
494
|
+
const scale = 4
|
|
495
|
+
const canvasW = barW * scale
|
|
496
|
+
const canvasH = barH * scale
|
|
497
|
+
const canvas = document.createElement('canvas')
|
|
498
|
+
canvas.width = canvasW
|
|
499
|
+
canvas.height = canvasH
|
|
500
|
+
const ctx = canvas.getContext('2d')!
|
|
501
|
+
|
|
502
|
+
const pad = 12
|
|
503
|
+
|
|
504
|
+
// 배경 + 테두리
|
|
505
|
+
ctx.fillStyle = '#dddddd'
|
|
506
|
+
ctx.fillRect(0, 0, canvasW, canvasH)
|
|
507
|
+
ctx.strokeStyle = gauge.borderColor
|
|
508
|
+
ctx.lineWidth = 12
|
|
509
|
+
ctx.strokeRect(6, 6, canvasW - 12, canvasH - 12)
|
|
510
|
+
|
|
511
|
+
// 세그먼트 채움 (왼→오)
|
|
512
|
+
const innerW = canvasW - pad * 2
|
|
513
|
+
const innerH = canvasH - pad * 2
|
|
514
|
+
let x = pad
|
|
515
|
+
for (const seg of gauge.segments) {
|
|
516
|
+
const segW = Math.max(innerW * seg.ratio, seg.ratio > 0 ? 1 : 0)
|
|
517
|
+
if (segW <= 0) continue
|
|
518
|
+
ctx.fillStyle = seg.color
|
|
519
|
+
ctx.fillRect(x, pad, segW, innerH)
|
|
520
|
+
x += segW
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// 텍스트
|
|
524
|
+
ctx.font = `bold ${10 * scale}px sans-serif`
|
|
525
|
+
ctx.textAlign = 'center'
|
|
526
|
+
ctx.textBaseline = 'middle'
|
|
527
|
+
ctx.fillStyle = '#333333'
|
|
528
|
+
ctx.fillText(gauge.label, canvasW / 2, canvasH / 2)
|
|
529
|
+
|
|
530
|
+
// 텍스처 → Plane
|
|
531
|
+
const texture = new THREE.CanvasTexture(canvas)
|
|
532
|
+
texture.colorSpace = THREE.SRGBColorSpace
|
|
533
|
+
|
|
534
|
+
const geo = new THREE.PlaneGeometry(barW, barH)
|
|
535
|
+
geo.rotateX(-Math.PI / 2) // 수평 (지붕 위)
|
|
536
|
+
if (!isWidthLonger) geo.rotateY(Math.PI / 2)
|
|
537
|
+
|
|
538
|
+
const mat = new THREE.MeshBasicMaterial({
|
|
539
|
+
map: texture,
|
|
540
|
+
transparent: true,
|
|
541
|
+
side: THREE.DoubleSide,
|
|
542
|
+
})
|
|
543
|
+
mat.polygonOffset = true
|
|
544
|
+
mat.polygonOffsetFactor = -2
|
|
545
|
+
mat.polygonOffsetUnit = -2
|
|
546
|
+
|
|
547
|
+
this.gaugeMesh = new THREE.Mesh(geo, mat)
|
|
548
|
+
this.gaugeMesh.position.set(0, depth + 0.5, 0)
|
|
549
|
+
this.object3d.add(this.gaugeMesh)
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
private resolveGauge(data: any, mode: string) {
|
|
553
|
+
switch (mode) {
|
|
554
|
+
case 'carrier': {
|
|
555
|
+
const full = Number(data.FULL_CNT) || 0
|
|
556
|
+
const empty = Number(data.EMPTY_CNT) || 0
|
|
557
|
+
const emptyEmpty = Number(data.EMPTYEMPTY_CNT) || 0
|
|
558
|
+
const total = full + empty + emptyEmpty
|
|
559
|
+
const segments = total > 0
|
|
560
|
+
? [
|
|
561
|
+
{ ratio: full / total, color: '#4AA7FE' },
|
|
562
|
+
{ ratio: empty / total, color: '#8BDA5B' },
|
|
563
|
+
{ ratio: emptyEmpty / total, color: '#019D59' },
|
|
564
|
+
]
|
|
565
|
+
: [{ ratio: 1, color: '#dddddd' }]
|
|
566
|
+
return {
|
|
567
|
+
segments,
|
|
568
|
+
borderColor: '#4AA7FE',
|
|
569
|
+
label: total > 0 ? `F${full} E${empty} EE${emptyEmpty}` : '',
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
case 'abnormal': {
|
|
573
|
+
const normal = Number(data.CARRIER_NORMAL) || 0
|
|
574
|
+
const abnormal = Number(data.CARRIER_ABNORMAL) || 0
|
|
575
|
+
const total = normal + abnormal
|
|
576
|
+
const segments = total > 0
|
|
577
|
+
? [
|
|
578
|
+
{ ratio: normal / total, color: '#8BDA5B' },
|
|
579
|
+
{ ratio: abnormal / total, color: '#F4B4B4' },
|
|
580
|
+
]
|
|
581
|
+
: [{ ratio: 1, color: '#dddddd' }]
|
|
582
|
+
return {
|
|
583
|
+
segments,
|
|
584
|
+
borderColor: abnormal > 0 ? '#F4B4B4' : '#8BDA5B',
|
|
585
|
+
label: total > 0 ? `N${normal} A${abnormal}` : '',
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
default: { // capacity
|
|
589
|
+
const cur = Number(data.CURRENTCAPACITY) || 0
|
|
590
|
+
const max = Number(data.MAXCAPACITY) || 100
|
|
591
|
+
const fullup = data.FULLUP === 'T'
|
|
592
|
+
const usage = Math.round((cur / max) * 100)
|
|
593
|
+
const legend = (this.component as any).root?.style?.LEGEND_CAPACITY || LEGEND_CAPACITY
|
|
594
|
+
const color = fullup ? 'red' : (getVaueOnRanges(usage, legend) || '#44aa44')
|
|
595
|
+
return {
|
|
596
|
+
segments: [{ ratio: usage / 100, color }],
|
|
597
|
+
borderColor: color,
|
|
598
|
+
label: `${usage}%`,
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
onchange(after: Record<string, unknown>, before: Record<string, unknown>) {
|
|
605
|
+
if ('data' in after) {
|
|
606
|
+
this.clearGauge()
|
|
607
|
+
this.buildGauge()
|
|
608
|
+
}
|
|
609
|
+
super.onchange(after, before)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
clear() {
|
|
613
|
+
this.clearGauge()
|
|
614
|
+
return super.clear()
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
private clearGauge() {
|
|
618
|
+
if (this.gaugeMesh) {
|
|
619
|
+
this.object3d.remove(this.gaugeMesh)
|
|
620
|
+
this.gaugeMesh.geometry?.dispose()
|
|
621
|
+
const mat = this.gaugeMesh.material as THREE.MeshBasicMaterial
|
|
622
|
+
mat?.map?.dispose()
|
|
623
|
+
mat?.dispose()
|
|
624
|
+
this.gaugeMesh = undefined
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
registerRealObjectFactory('STOCKER', (component: Component) => new StockerRealObject3D(component))
|
|
308
630
|
|
|
309
631
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
310
632
|
// Unit (이동체 · 홀더) — 낮은 depth, 불투명
|
|
311
633
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
312
634
|
|
|
313
|
-
|
|
314
|
-
|
|
635
|
+
// Port: 바닥판 (PlaneGeometry)
|
|
636
|
+
const PORT_CONFIG: MCS3DConfig = {
|
|
637
|
+
...DEFAULTS,
|
|
638
|
+
depthRatio: 0.01,
|
|
315
639
|
defaultZPosFromParent: true,
|
|
316
|
-
opacity: 0.
|
|
317
|
-
metalness: 0.
|
|
318
|
-
roughness: 0.
|
|
640
|
+
opacity: 0.1,
|
|
641
|
+
metalness: 0.3,
|
|
642
|
+
roughness: 0.8,
|
|
319
643
|
defaultColor: 0xb0a090,
|
|
320
|
-
|
|
644
|
+
shape: 'plane',
|
|
645
|
+
}
|
|
646
|
+
registerRealObjectFactory('Port', (component: Component) => new MCSRealObject3D(component, PORT_CONFIG))
|
|
321
647
|
|
|
322
648
|
register('Shelf', {
|
|
323
649
|
depthRatio: 0.25,
|
|
@@ -326,36 +652,36 @@ register('Shelf', {
|
|
|
326
652
|
defaultColor: 0xaabbcc,
|
|
327
653
|
})
|
|
328
654
|
|
|
329
|
-
|
|
655
|
+
// Carrier: CARRIERSTATUS에 따른 3D 애니메이션 지원
|
|
656
|
+
const CARRIER_CONFIG: MCS3DConfig = {
|
|
657
|
+
...DEFAULTS,
|
|
330
658
|
depthRatio: 0.5,
|
|
331
|
-
metalness: 0
|
|
332
|
-
roughness:
|
|
659
|
+
metalness: 0,
|
|
660
|
+
roughness: 1,
|
|
333
661
|
defaultColor: 0x66bb66,
|
|
334
662
|
isVisible: (c: Component) => !!(c.state as any).id,
|
|
335
663
|
sizeRatio: 0.8,
|
|
336
|
-
|
|
664
|
+
texturedTop: true,
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
class CarrierRealObject3D extends MCSRealObject3D {
|
|
668
|
+
constructor(component: Component) {
|
|
669
|
+
super(component, CARRIER_CONFIG)
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
registerRealObjectFactory('Carrier', (component: Component) => new CarrierRealObject3D(component))
|
|
337
674
|
|
|
338
675
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
339
676
|
// Gauge (용량 게이지) — 얇은 바
|
|
340
677
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
341
678
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
})
|
|
679
|
+
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
680
|
+
// Gauge (용량 게이지) — 2D 렌더링을 Plane 텍스처로 3D 표시
|
|
681
|
+
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
355
682
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
})
|
|
683
|
+
// Gauge 컴포넌트 (StockerCapacityBar, ZoneCapacityBar, MCSGaugeCapacityBar)는
|
|
684
|
+
// 3D에서 표시하지 않음. 대신 부모(STOCKER 등)의 3D 모델에서 직접 게이지를 렌더링.
|
|
685
|
+
registerRealObjectFactory('StockerCapacityBar', () => null as any)
|
|
686
|
+
registerRealObjectFactory('MCSGaugeCapacityBar', () => null as any)
|
|
687
|
+
registerRealObjectFactory('ZoneCapacityBar', () => null as any)
|
package/src/factories/oht-3d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import * as THREE from 'three'
|
|
13
13
|
import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js'
|
|
14
14
|
import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry.js'
|
|
15
|
-
import { RealObjectGroup, registerRealObjectFactory } from '@hatiolab/things-scene'
|
|
15
|
+
import { RealObjectGroup, registerRealObjectFactory, disposeObject3D } from '@hatiolab/things-scene'
|
|
16
16
|
import type { Component } from '@hatiolab/things-scene'
|
|
17
17
|
import { TRANSPORT_SURFACE_HEIGHT } from './machine-3d.js'
|
|
18
18
|
|
|
@@ -24,6 +24,7 @@ const DEFAULT_BODY_COLOR = 0x6688cc
|
|
|
24
24
|
const OHT_RAIL_HEIGHT = 6 * TRANSPORT_SURFACE_HEIGHT
|
|
25
25
|
|
|
26
26
|
export class OHT3D extends RealObjectGroup {
|
|
27
|
+
private _ownMeshes: THREE.Mesh[] = []
|
|
27
28
|
get effectiveDepth(): number {
|
|
28
29
|
const { depth } = this.component.state
|
|
29
30
|
return depth || TRANSPORT_SURFACE_HEIGHT
|
|
@@ -89,7 +90,6 @@ export class OHT3D extends RealObjectGroup {
|
|
|
89
90
|
const gripperMesh = new THREE.Mesh(gripperGeo, frameMat)
|
|
90
91
|
gripperMesh.position.y = gripperBarH / 2
|
|
91
92
|
gripperMesh.castShadow = true
|
|
92
|
-
this.object3d.add(gripperMesh)
|
|
93
93
|
|
|
94
94
|
// ── 2. 호이스트 암 (좌우 수직 기둥 + 하단 가로연결) ──
|
|
95
95
|
const armBaseY = gripperBarH
|
|
@@ -111,7 +111,6 @@ export class OHT3D extends RealObjectGroup {
|
|
|
111
111
|
|
|
112
112
|
const armMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(armGeometries), frameMat)
|
|
113
113
|
armMesh.castShadow = true
|
|
114
|
-
this.object3d.add(armMesh)
|
|
115
114
|
|
|
116
115
|
// ── 3. 본체 하우징 (statusColor 적용) ──
|
|
117
116
|
const bodyBaseY = armBaseY + armH
|
|
@@ -126,7 +125,6 @@ export class OHT3D extends RealObjectGroup {
|
|
|
126
125
|
bodyMesh.position.y = bodyBaseY + bodyH / 2
|
|
127
126
|
bodyMesh.castShadow = true
|
|
128
127
|
bodyMesh.receiveShadow = true
|
|
129
|
-
this.object3d.add(bodyMesh)
|
|
130
128
|
|
|
131
129
|
// ── 4. 상단 트롤리 플레이트 (납작하고 넓은 레일 클램프) ──
|
|
132
130
|
const trolleyBaseY = bodyBaseY + bodyH + gap
|
|
@@ -141,27 +139,53 @@ export class OHT3D extends RealObjectGroup {
|
|
|
141
139
|
const trolleyMesh = new THREE.Mesh(trolleyGeo, trolleyMat)
|
|
142
140
|
trolleyMesh.position.y = trolleyBaseY + trolleyH / 2
|
|
143
141
|
trolleyMesh.castShadow = true
|
|
144
|
-
this.object3d.add(trolleyMesh)
|
|
145
142
|
|
|
146
143
|
// ── 5. 좌우 바퀴 (트롤리 위, 레일을 타는 원통형 바퀴) ──
|
|
147
144
|
const wheelBaseY = trolleyBaseY + trolleyH
|
|
148
145
|
const wheelRadius = wheelH / 2
|
|
149
146
|
const wheelDepth = h * 0.2
|
|
147
|
+
const wheelMeshes: THREE.Mesh[] = []
|
|
150
148
|
for (const xSign of [-1, 1]) {
|
|
151
149
|
const wheelGeo = new THREE.CylinderGeometry(wheelRadius, wheelRadius, wheelDepth, 12)
|
|
152
150
|
wheelGeo.rotateX(Math.PI / 2)
|
|
153
151
|
const wheelMesh = new THREE.Mesh(wheelGeo, trolleyMat)
|
|
154
152
|
wheelMesh.position.set(xSign * (trolleyW * 0.35), wheelBaseY + wheelRadius, 0)
|
|
155
153
|
wheelMesh.castShadow = true
|
|
156
|
-
|
|
154
|
+
wheelMeshes.push(wheelMesh)
|
|
157
155
|
}
|
|
156
|
+
|
|
157
|
+
this._ownMeshes = [gripperMesh, armMesh, bodyMesh, trolleyMesh, ...wheelMeshes]
|
|
158
|
+
for (const m of this._ownMeshes) this.object3d.add(m)
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
updateDimension() {}
|
|
161
|
-
|
|
162
|
+
|
|
163
|
+
update() {
|
|
164
|
+
for (const m of this._ownMeshes) {
|
|
165
|
+
this.object3d.remove(m)
|
|
166
|
+
disposeObject3D(m)
|
|
167
|
+
}
|
|
168
|
+
this._ownMeshes = []
|
|
169
|
+
this.build()
|
|
170
|
+
this.updateTransform()
|
|
171
|
+
this.updateAlpha()
|
|
172
|
+
this.updateHidden()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
updateAlpha() {
|
|
176
|
+
const { alpha = 1 } = this.component.state
|
|
177
|
+
for (const m of this._ownMeshes) {
|
|
178
|
+
const materials = Array.isArray(m.material) ? m.material : [m.material]
|
|
179
|
+
for (const mat of materials) {
|
|
180
|
+
;(mat as THREE.MeshStandardMaterial).opacity = alpha
|
|
181
|
+
;(mat as THREE.MeshStandardMaterial).transparent = alpha < 1
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
162
185
|
|
|
163
186
|
onchange(after: Record<string, unknown>, before: Record<string, unknown>) {
|
|
164
|
-
if ('width' in after || 'height' in after || 'depth' in after ||
|
|
187
|
+
if ('width' in after || 'height' in after || 'depth' in after ||
|
|
188
|
+
'fillStyle' in after || 'strokeStyle' in after || 'id' in after) {
|
|
165
189
|
this.update()
|
|
166
190
|
return
|
|
167
191
|
}
|