@fmsim/machine 1.0.88 → 2.0.0-beta.100

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 (165) hide show
  1. package/dist/agv-line.js.map +1 -1
  2. package/dist/agv.js +6 -2
  3. package/dist/agv.js.map +1 -1
  4. package/dist/buffer.js.map +1 -1
  5. package/dist/carrier-manager.js +183 -0
  6. package/dist/carrier-manager.js.map +1 -0
  7. package/dist/carrier.js +105 -14
  8. package/dist/carrier.js.map +1 -1
  9. package/dist/conveyor-join.js +8 -2
  10. package/dist/conveyor-join.js.map +1 -1
  11. package/dist/conveyor.js +9 -1
  12. package/dist/conveyor.js.map +1 -1
  13. package/dist/crane-rail.js +53 -0
  14. package/dist/crane-rail.js.map +1 -0
  15. package/dist/crane.js +144 -1
  16. package/dist/crane.js.map +1 -1
  17. package/dist/equipment.js.map +1 -1
  18. package/dist/factories/agv-3d.js +147 -0
  19. package/dist/factories/agv-3d.js.map +1 -0
  20. package/dist/factories/conveyor-3d.js +345 -0
  21. package/dist/factories/conveyor-3d.js.map +1 -0
  22. package/dist/factories/crane-3d.js +186 -0
  23. package/dist/factories/crane-3d.js.map +1 -0
  24. package/dist/factories/crane-rail-3d.js +95 -0
  25. package/dist/factories/crane-rail-3d.js.map +1 -0
  26. package/dist/factories/machine-3d.js +973 -0
  27. package/dist/factories/machine-3d.js.map +1 -0
  28. package/dist/factories/oht-3d.js +177 -0
  29. package/dist/factories/oht-3d.js.map +1 -0
  30. package/dist/factories/shuttle-3d.js +159 -0
  31. package/dist/factories/shuttle-3d.js.map +1 -0
  32. package/dist/factories/z-priority-defaults.js +33 -0
  33. package/dist/factories/z-priority-defaults.js.map +1 -0
  34. package/dist/factories/z-priority.js +54 -0
  35. package/dist/factories/z-priority.js.map +1 -0
  36. package/dist/features/conveyor-mixin.js.map +1 -1
  37. package/dist/features/mcs-status-default.js +15 -1
  38. package/dist/features/mcs-status-default.js.map +1 -1
  39. package/dist/features/mcs-status-mixin.js +22 -0
  40. package/dist/features/mcs-status-mixin.js.map +1 -1
  41. package/dist/features/mcs-zone-mixin.js.map +1 -1
  42. package/dist/features/parent-object-mixin.js +15 -7
  43. package/dist/features/parent-object-mixin.js.map +1 -1
  44. package/dist/floating-container.js +5 -0
  45. package/dist/floating-container.js.map +1 -1
  46. package/dist/index.js +58 -2
  47. package/dist/index.js.map +1 -1
  48. package/dist/mcs-carrier-holder.js +56 -17
  49. package/dist/mcs-carrier-holder.js.map +1 -1
  50. package/dist/mcs-machine.js +39 -0
  51. package/dist/mcs-machine.js.map +1 -1
  52. package/dist/mcs-unit.js +20 -0
  53. package/dist/mcs-unit.js.map +1 -1
  54. package/dist/mcs-vehicle.js +10 -4
  55. package/dist/mcs-vehicle.js.map +1 -1
  56. package/dist/node.js +10 -3
  57. package/dist/node.js.map +1 -1
  58. package/dist/oht-line.js.map +1 -1
  59. package/dist/oht.js +4 -0
  60. package/dist/oht.js.map +1 -1
  61. package/dist/port-flow.js +4 -0
  62. package/dist/port-flow.js.map +1 -1
  63. package/dist/port.js +4 -0
  64. package/dist/port.js.map +1 -1
  65. package/dist/scanner.js +30 -0
  66. package/dist/scanner.js.map +1 -0
  67. package/dist/scene/root-container-override.js +160 -96
  68. package/dist/scene/root-container-override.js.map +1 -1
  69. package/dist/shelf.js +4 -0
  70. package/dist/shelf.js.map +1 -1
  71. package/dist/shuttle.js.map +1 -1
  72. package/dist/static-container.js +5 -0
  73. package/dist/static-container.js.map +1 -1
  74. package/dist/stocker-abnormal-bar.js +184 -0
  75. package/dist/stocker-abnormal-bar.js.map +1 -0
  76. package/dist/stocker-capacity-bar.js +253 -6
  77. package/dist/stocker-capacity-bar.js.map +1 -1
  78. package/dist/stocker-carrier-bar.js +198 -0
  79. package/dist/stocker-carrier-bar.js.map +1 -0
  80. package/dist/stocker.js +7 -1
  81. package/dist/stocker.js.map +1 -1
  82. package/dist/templates/backdrop.js +30 -0
  83. package/dist/templates/backdrop.js.map +1 -0
  84. package/dist/templates/decal.js +21 -0
  85. package/dist/templates/decal.js.map +1 -0
  86. package/dist/templates/index.js +7 -1
  87. package/dist/templates/index.js.map +1 -1
  88. package/dist/templates/scanner.js +20 -0
  89. package/dist/templates/scanner.js.map +1 -0
  90. package/dist/tsconfig.tsbuildinfo +1 -1
  91. package/dist/utils/crane-position.js +83 -0
  92. package/dist/utils/crane-position.js.map +1 -0
  93. package/dist/utils/data-value.js +21 -0
  94. package/dist/utils/data-value.js.map +1 -0
  95. package/dist/utils/fit-gauge-scale.js +28 -0
  96. package/dist/utils/fit-gauge-scale.js.map +1 -0
  97. package/dist/utils/get-value-on-ranges.js +2 -4
  98. package/dist/utils/get-value-on-ranges.js.map +1 -1
  99. package/dist/utils/stocker-gauge.js +78 -0
  100. package/dist/utils/stocker-gauge.js.map +1 -0
  101. package/dist/zone-capacity-bar.js +3 -3
  102. package/dist/zone-capacity-bar.js.map +1 -1
  103. package/icons/backdrop.png +0 -0
  104. package/icons/decal.png +0 -0
  105. package/jest.config.js +10 -0
  106. package/package.json +7 -6
  107. package/src/agv-line.ts +1 -1
  108. package/src/agv.ts +10 -5
  109. package/src/buffer.ts +1 -1
  110. package/src/carrier-manager.ts +223 -0
  111. package/src/carrier.ts +111 -18
  112. package/src/conveyor-join.ts +6 -3
  113. package/src/conveyor.ts +10 -2
  114. package/src/crane-rail.ts +58 -0
  115. package/src/crane.ts +182 -2
  116. package/src/equipment.ts +1 -1
  117. package/src/factories/agv-3d.ts +160 -0
  118. package/src/factories/conveyor-3d.ts +398 -0
  119. package/src/factories/crane-3d.ts +217 -0
  120. package/src/factories/crane-rail-3d.ts +115 -0
  121. package/src/factories/machine-3d.ts +1192 -0
  122. package/src/factories/oht-3d.ts +196 -0
  123. package/src/factories/shuttle-3d.ts +179 -0
  124. package/src/factories/z-priority-defaults.ts +38 -0
  125. package/src/factories/z-priority.ts +60 -0
  126. package/src/features/conveyor-mixin.ts +1 -1
  127. package/src/features/mcs-status-default.ts +15 -1
  128. package/src/features/mcs-status-mixin.ts +26 -4
  129. package/src/features/mcs-zone-mixin.ts +1 -1
  130. package/src/features/parent-object-mixin.ts +17 -8
  131. package/src/floating-container.ts +5 -0
  132. package/src/index.ts +66 -2
  133. package/src/mcs-carrier-holder.ts +58 -29
  134. package/src/mcs-machine.ts +43 -1
  135. package/src/mcs-unit.ts +25 -2
  136. package/src/mcs-vehicle.ts +12 -9
  137. package/src/node.ts +9 -3
  138. package/src/oht-line.ts +1 -1
  139. package/src/oht.ts +7 -2
  140. package/src/port-flow.ts +6 -1
  141. package/src/port.ts +6 -1
  142. package/src/scanner.ts +29 -0
  143. package/src/scene/root-container-override.ts +156 -105
  144. package/src/shelf.ts +6 -1
  145. package/src/shuttle.ts +1 -1
  146. package/src/static-container.ts +5 -0
  147. package/src/stocker-abnormal-bar.ts +247 -0
  148. package/src/stocker-capacity-bar.ts +301 -10
  149. package/src/stocker-carrier-bar.ts +262 -0
  150. package/src/stocker.ts +10 -3
  151. package/src/templates/backdrop.ts +30 -0
  152. package/src/templates/decal.ts +21 -0
  153. package/src/templates/index.ts +7 -1
  154. package/src/templates/scanner.ts +20 -0
  155. package/src/utils/crane-position.ts +105 -0
  156. package/src/utils/data-value.ts +19 -0
  157. package/src/utils/fit-gauge-scale.ts +35 -0
  158. package/src/utils/get-value-on-ranges.ts +2 -4
  159. package/src/utils/stocker-gauge.ts +111 -0
  160. package/src/zone-capacity-bar.ts +5 -5
  161. package/translations/en.json +26 -1
  162. package/translations/ja.json +26 -1
  163. package/translations/ko.json +26 -1
  164. package/translations/ms.json +26 -1
  165. package/translations/zh.json +26 -1
@@ -0,0 +1,973 @@
1
+ /**
2
+ * MCS 설비 컴포넌트 3D 팩토리
3
+ *
4
+ * 10,000+ 인스턴스를 위한 최소 폴리곤 설계:
5
+ * - 컴포넌트당 단일 Mesh (draw call 최소화)
6
+ * - BoxGeometry / ExtrudeGeometry(hexagon) 만 사용
7
+ * - Machine: 높은 depth, 컨테이너는 반투명
8
+ * - Unit: 낮은 depth, 불투명
9
+ */
10
+ import * as THREE from 'three';
11
+ import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
12
+ import { RealObjectGroup, registerRealObjectFactory, disposeObject3D } from '@hatiolab/things-scene';
13
+ import { LEGEND_CAPACITY, resolveCarrierLegend } from '../features/mcs-status-default';
14
+ import { getValueOnRanges } from '../utils/get-value-on-ranges';
15
+ import { fitGaugeScale } from '../utils/fit-gauge-scale';
16
+ import { carrierSegmentsFromData, abnormalSegmentsFromData, carrierColorsFromLegend, ABNORMAL_COLORS } from '../utils/stocker-gauge';
17
+ import { Z_FMSIM } from './z-priority';
18
+ /**
19
+ * 포트 기본 높이 (절대값).
20
+ * 모든 이송장치의 상단 높이 = 이 값.
21
+ * 캐리어가 이송장치 간 높이 차 없이 이동할 수 있는 기준 높이.
22
+ */
23
+ export const TRANSPORT_SURFACE_HEIGHT = 30;
24
+ const DEFAULTS = {
25
+ depthRatio: 0.5,
26
+ opacity: 1.0,
27
+ metalness: 0.3,
28
+ roughness: 0.7,
29
+ defaultColor: 0xaabbcc,
30
+ shape: 'box',
31
+ };
32
+ // ── 3D 오브젝트 ──────────────────────────────────────────
33
+ class MCSRealObject3D extends RealObjectGroup {
34
+ constructor(component, config) {
35
+ super(component);
36
+ // ── Change handling ──
37
+ this._updatePending = false;
38
+ this._config = config;
39
+ }
40
+ get zPriority() {
41
+ var _a;
42
+ return (_a = this._config.zPriority) !== null && _a !== void 0 ? _a : 0;
43
+ }
44
+ // width, height 절대값 (음수 값은 양수로 취급).
45
+ // `resizable:false` 컴포넌트(예: Scanner)는 state.width/height 가 없고
46
+ // bounds 만 있을 수 있으므로 bounds 를 fallback 으로 사용.
47
+ //
48
+ // `??` only catches null/undefined — a property-panel input that produced
49
+ // NaN would slip through and corrupt every downstream Math.* call. Use a
50
+ // finite check so NaN falls through to bounds → 10 like missing values do.
51
+ get absSize() {
52
+ const state = (this.component.state || {});
53
+ const bounds = (this.component.bounds || {});
54
+ const width = pickFinite(state.width, bounds.width, 10);
55
+ const height = pickFinite(state.height, bounds.height, 10);
56
+ return { w: Math.abs(width), h: Math.abs(height) };
57
+ }
58
+ get effectiveDepth() {
59
+ const { depth } = this.component.state;
60
+ // Truthy `if (depth)` already rejected NaN/0/undefined, but be explicit
61
+ // so the intent (and the resolution chain) reads cleanly: only an
62
+ // explicit positive finite number wins; everything else → defaults.
63
+ if (typeof depth === 'number' && Number.isFinite(depth) && depth > 0) {
64
+ return depth;
65
+ }
66
+ if (this._config.defaultDepth)
67
+ return this._config.defaultDepth;
68
+ const { w, h } = this.absSize;
69
+ return Math.min(w, h) * this._config.depthRatio;
70
+ }
71
+ get syncZPosOffset() {
72
+ var _a, _b;
73
+ // syncZPosOffset = placement + geometric (center origin = effectiveDepth/2)
74
+ // 중첩 보정(parent shift 상쇄)은 base RealObject.cz가 parent.geometricOffsetY를
75
+ // 빼는 방식으로 처리하므로 여기선 placement + 본인 geometric만 반환
76
+ const halfD = this.effectiveDepth / 2;
77
+ // zPosOverride: 고정 높이 (OHTLine 등)
78
+ if (this._config.zPosOverride != null) {
79
+ return this._config.zPosOverride + halfD;
80
+ }
81
+ // Port: 이송 표면 높이에 배치
82
+ if (this._config.defaultZPosFromParent) {
83
+ return TRANSPORT_SURFACE_HEIGHT + halfD;
84
+ }
85
+ // Carrier: 부모 유형에 따라 배치 위치 결정
86
+ if (this._config.sizeRatio && this._config.sizeRatio < 1) {
87
+ const parentType = (_b = (_a = this.component.parent) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.type;
88
+ // OHT: 그리퍼 아래에 매달림 — placement = -effectiveDepth(carrier top이 OHT bottom)
89
+ if (parentType === 'OHT') {
90
+ return -this.effectiveDepth + halfD;
91
+ }
92
+ if (parentType === 'Port' || parentType === 'Shelf' || parentType === 'Shuttle') {
93
+ return halfD;
94
+ }
95
+ return TRANSPORT_SURFACE_HEIGHT + halfD;
96
+ }
97
+ return halfD;
98
+ }
99
+ // geometric 부분(center origin: depth/2)은 base 기본값 사용 — override 불필요
100
+ // 컴포넌트의 상태 색상(statusColor) 또는 fillStyle → Three.js 색상 변환
101
+ resolveColor() {
102
+ const comp = this.component;
103
+ // 1) MCSStatusMixin.statusColor (legend 기반 상태 색상)
104
+ // '#F0F0F0'은 상태 미설정 시 기본 fallback — 무시하고 defaultColor 사용
105
+ try {
106
+ const sc = comp.statusColor;
107
+ if (typeof sc === 'string' && sc && sc.toUpperCase() !== '#F0F0F0' && sc !== 'transparent')
108
+ return new THREE.Color(sc).getHex();
109
+ }
110
+ catch (_a) {
111
+ /* statusColor 미구현 시 무시 */
112
+ }
113
+ // 2) state.fillStyle fallback
114
+ const { fillStyle } = this.component.state;
115
+ if (fillStyle && typeof fillStyle === 'string' && fillStyle !== 'transparent') {
116
+ try {
117
+ return new THREE.Color(fillStyle).getHex();
118
+ }
119
+ catch (_b) {
120
+ /* 파싱 실패 시 무시 */
121
+ }
122
+ }
123
+ return this._config.defaultColor;
124
+ }
125
+ // ── Geometry helpers ──
126
+ /**
127
+ * 바닥면(-Y 방향) 삼각형 제거: z-fighting 근본 해결.
128
+ * 바닥면이 없으면 floor grid와 겹칠 면 자체가 없어진다.
129
+ */
130
+ removeBottomFace(geometry) {
131
+ const posAttr = geometry.getAttribute('position');
132
+ const normAttr = geometry.getAttribute('normal');
133
+ const index = geometry.getIndex();
134
+ if (!posAttr || !normAttr || !index)
135
+ return geometry;
136
+ const newIndices = [];
137
+ const normalY = new THREE.Vector3();
138
+ for (let i = 0; i < index.count; i += 3) {
139
+ const a = index.getX(i);
140
+ const b = index.getX(i + 1);
141
+ const c = index.getX(i + 2);
142
+ // 세 꼭짓점 노말의 Y 성분 평균으로 방향 판단
143
+ const avgY = (normAttr.getY(a) + normAttr.getY(b) + normAttr.getY(c)) / 3;
144
+ // -Y 방향 삼각형 제거 (threshold -0.9: 거의 아래를 향하는 면만)
145
+ if (avgY > -0.9) {
146
+ newIndices.push(a, b, c);
147
+ }
148
+ }
149
+ geometry.setIndex(newIndices);
150
+ return geometry;
151
+ }
152
+ // ── Geometry builders ──
153
+ buildBoxGeometry(w, d, h) {
154
+ const geo = new THREE.BoxGeometry(w, d, h);
155
+ return this._config.keepBottomFace ? geo : this.removeBottomFace(geo);
156
+ }
157
+ buildHexagonGeometry(w, d, h) {
158
+ // Buffer의 2D 형태: 좌우 끝이 꺾인 육각형
159
+ const offset = Math.min(w, h) * 0.2;
160
+ const hw = w / 2;
161
+ const hh = h / 2;
162
+ const shape = new THREE.Shape();
163
+ shape.moveTo(-hw + offset, -hh);
164
+ shape.lineTo(hw - offset, -hh);
165
+ shape.lineTo(hw, 0);
166
+ shape.lineTo(hw - offset, hh);
167
+ shape.lineTo(-hw + offset, hh);
168
+ shape.lineTo(-hw, 0);
169
+ shape.closePath();
170
+ const geo = new THREE.ExtrudeGeometry(shape, {
171
+ steps: 1,
172
+ depth: d,
173
+ bevelEnabled: false,
174
+ });
175
+ // 중심 정렬 후 Y-up 좌표계 회전 (extrude 축: +Z → +Y)
176
+ geo.translate(0, 0, -d / 2);
177
+ geo.rotateX(Math.PI / 2);
178
+ return this.removeBottomFace(geo);
179
+ }
180
+ buildPlaneGeometry(w, h) {
181
+ const geo = new THREE.PlaneGeometry(w, h);
182
+ geo.rotateX(-Math.PI / 2);
183
+ return geo;
184
+ }
185
+ /**
186
+ * 삼각형 prism — 2D Triangle 의 꼭짓점(state.x1/y1, x2/y2, x3/y3) 을 그대로 사용.
187
+ * things-scene 의 TriangleExtrude 와 동일한 방식 — 각 Scanner 인스턴스의
188
+ * 실제 정점 배치(방향, 비대칭 등) 가 3D 에 반영된다.
189
+ *
190
+ * `geometry.center()` 로 로컬 원점을 bounding-box 중심으로 맞추므로
191
+ * 후속 placement 와 정합.
192
+ */
193
+ buildTriangleGeometry(d) {
194
+ const state = (this.component.state || {});
195
+ const { x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0 } = state;
196
+ const shape = new THREE.Shape();
197
+ shape.moveTo(x1, y1);
198
+ shape.lineTo(x2, y2);
199
+ shape.lineTo(x3, y3);
200
+ shape.closePath();
201
+ const geo = new THREE.ExtrudeGeometry(shape, {
202
+ steps: 1,
203
+ depth: d,
204
+ bevelEnabled: false,
205
+ });
206
+ // bounding box 중심으로 원점 정렬 후 Y-up 좌표계로 회전
207
+ geo.center();
208
+ geo.rotateX(Math.PI / 2);
209
+ return this.removeBottomFace(geo);
210
+ }
211
+ build() {
212
+ var _a;
213
+ super.build();
214
+ // 가시성 판정 — e.g., Carrier는 데이터 없으면 mesh 미생성
215
+ if (this._config.isVisible && !this._config.isVisible(this.component))
216
+ return;
217
+ const { w: rawW, h: rawH } = this.absSize;
218
+ const rawDepth = this.effectiveDepth;
219
+ if (!rawW || !rawH)
220
+ return;
221
+ const ratio = (_a = this._config.sizeRatio) !== null && _a !== void 0 ? _a : 1.0;
222
+ const w = rawW * ratio;
223
+ const h = rawH * ratio;
224
+ const depth = rawDepth * ratio;
225
+ const color = this.resolveColor();
226
+ const { opacity, metalness, roughness, shape } = this._config;
227
+ const geometry = shape === 'plane'
228
+ ? this.buildPlaneGeometry(w, h)
229
+ : shape === 'hexagon'
230
+ ? this.buildHexagonGeometry(w, depth, h)
231
+ : shape === 'triangle'
232
+ ? this.buildTriangleGeometry(depth)
233
+ : this.buildBoxGeometry(w, depth, h);
234
+ const isPlane = shape === 'plane';
235
+ const material = isPlane
236
+ ? new THREE.MeshBasicMaterial({
237
+ color,
238
+ opacity,
239
+ transparent: opacity < 1,
240
+ side: THREE.DoubleSide,
241
+ })
242
+ : new THREE.MeshStandardMaterial(Object.assign({ color,
243
+ metalness,
244
+ roughness,
245
+ opacity, transparent: opacity < 1, side: opacity < 1 ? THREE.DoubleSide : THREE.FrontSide }, (this._config.emissiveIntensity ? { emissive: color, emissiveIntensity: this._config.emissiveIntensity } : {})));
246
+ // z-fighting 방지: 바닥면(floor grid)보다 항상 앞에 렌더링
247
+ material.polygonOffset = true;
248
+ material.polygonOffsetFactor = -1;
249
+ material.polygonOffsetUnit = -1;
250
+ // BoxGeometry material groups: +x(0), -x(1), +y(2), -y(3), +z(4), -z(5)
251
+ let meshMaterial = material;
252
+ if (shape === 'box') {
253
+ if (this._config.openTop) {
254
+ // 상단면 제거 → 5면 개방 박스
255
+ const invisible = new THREE.MeshBasicMaterial({ visible: false });
256
+ meshMaterial = [material, material, invisible, material, material, material];
257
+ }
258
+ else if (this._config.texturedTop) {
259
+ // 상판에 2D 렌더링 텍스처
260
+ const topMat = this.buildTopTexture(w, h);
261
+ meshMaterial = [material, material, topMat, material, material, material];
262
+ }
263
+ else if (this._config.matteTop) {
264
+ // 상판만 무반사
265
+ const matte = new THREE.MeshBasicMaterial({ color, opacity, transparent: opacity < 1 });
266
+ meshMaterial = [material, material, matte, material, material, material];
267
+ }
268
+ }
269
+ this._ownMesh = new THREE.Mesh(geometry, meshMaterial);
270
+ // ownGroup 기준(bottom-up): mesh 바닥을 y=0에 맞추고 ownGroup이 -d/2로 shift해
271
+ // center-origin object3d에 정렬됨.
272
+ // box/hexagon (center-local geometry): y=rawDepth/2 (바닥을 0에 맞춤)
273
+ // plane: y=1 (바닥 살짝 띄움)
274
+ this._ownMesh.position.y = isPlane ? 1 : rawDepth / 2;
275
+ this._ownMesh.castShadow = !isPlane;
276
+ this._ownMesh.receiveShadow = true;
277
+ this.components3D.add(this._ownMesh);
278
+ }
279
+ onchange(after, before) {
280
+ if ('width' in after ||
281
+ 'height' in after ||
282
+ 'depth' in after ||
283
+ 'fillStyle' in after ||
284
+ 'strokeStyle' in after ||
285
+ 'id' in after ||
286
+ 'EMPTYTYPE' in after ||
287
+ 'CARRIERSTATUS' in after) {
288
+ // 연속 setState에 의한 다중 rebuild 방지: 한 프레임에 한 번만 실행
289
+ if (!this._updatePending) {
290
+ this._updatePending = true;
291
+ queueMicrotask(() => {
292
+ this._updatePending = false;
293
+ this.update();
294
+ });
295
+ }
296
+ return;
297
+ }
298
+ super.onchange(after, before);
299
+ }
300
+ /**
301
+ * 상판 텍스처: 컴포넌트의 2D render()를 캔버스에 그려서 텍스처로 사용
302
+ */
303
+ buildTopTexture(w, h) {
304
+ var _a;
305
+ const scale = 4;
306
+ const cw = this.nextPow2(w * scale);
307
+ const ch = this.nextPow2(h * scale);
308
+ const canvas = document.createElement('canvas');
309
+ canvas.width = cw;
310
+ canvas.height = ch;
311
+ const ctx = canvas.getContext('2d');
312
+ const statusColor = '#' + this.resolveColor().toString(16).padStart(6, '0');
313
+ const emptyType = ((_a = this.component.state) === null || _a === void 0 ? void 0 : _a.EMPTYTYPE) || '';
314
+ const text = emptyType === 'FULL' ? 'F' : emptyType === 'EMPTY' ? 'E' : emptyType === 'EMPTYEMPTY' ? 'X' : '';
315
+ // 실제 사용 영역 (nextPow2 이전 크기)
316
+ const usedW = w * scale;
317
+ const usedH = h * scale;
318
+ // 바탕: 캐리어 상태 색상 (사용 영역만)
319
+ ctx.fillStyle = statusColor;
320
+ ctx.fillRect(0, 0, usedW, usedH);
321
+ // 텍스트 (사용 영역 중앙)
322
+ if (text) {
323
+ const fontSize = Math.round(Math.min(usedW, usedH) * 0.7);
324
+ ctx.font = `bold ${fontSize}px Arial`;
325
+ ctx.textAlign = 'center';
326
+ ctx.textBaseline = 'middle';
327
+ ctx.fillStyle = '#000000';
328
+ ctx.fillText(text, usedW / 2, usedH / 2);
329
+ }
330
+ const texture = new THREE.CanvasTexture(canvas);
331
+ texture.offset.set(0, 1 - usedH / ch);
332
+ texture.repeat.set(usedW / cw, usedH / ch);
333
+ texture.colorSpace = THREE.SRGBColorSpace;
334
+ return new THREE.MeshBasicMaterial({
335
+ map: texture,
336
+ transparent: true,
337
+ side: THREE.DoubleSide,
338
+ });
339
+ }
340
+ nextPow2(n) {
341
+ if (!(n > 0))
342
+ return 1;
343
+ let v = Math.ceil(n);
344
+ v--;
345
+ v |= v >> 1;
346
+ v |= v >> 2;
347
+ v |= v >> 4;
348
+ v |= v >> 8;
349
+ v |= v >> 16;
350
+ return v + 1;
351
+ }
352
+ /**
353
+ * 자신의 mesh만 제거 후 rebuild.
354
+ * 기본 update()는 clear()로 object3d의 모든 children을 제거하는데,
355
+ * 컨테이너(Port 등)의 경우 자식 컴포넌트(Carrier 등)의 3D 오브젝트도 함께 제거됨.
356
+ * 이를 방지하기 위해 자신이 생성한 mesh만 제거한다.
357
+ */
358
+ update() {
359
+ // 자신의 mesh만 제거 (자식 컴포넌트 3D 오브젝트 보존)
360
+ if (this._ownMesh) {
361
+ this.components3D.remove(this._ownMesh);
362
+ disposeObject3D(this._ownMesh);
363
+ this._ownMesh = undefined;
364
+ }
365
+ this.build();
366
+ this.updateTransform();
367
+ this.updateAlpha();
368
+ this.updateHidden();
369
+ }
370
+ // RealObjectGroup 기본 동작 비활성화
371
+ updateDimension() { }
372
+ updateAlpha() {
373
+ const state = this.component.state;
374
+ // alpha가 명시적으로 설정되어 있으면 그 값을 사용, 없으면 config 기본값 적용
375
+ const effective = ('alpha' in state) ? state.alpha : this._config.opacity;
376
+ this.object3d.traverse((o) => {
377
+ if (!o.material)
378
+ return;
379
+ const materials = Array.isArray(o.material) ? o.material : [o.material];
380
+ for (const m of materials) {
381
+ if (!m.visible)
382
+ continue; // openTop invisible face 무시
383
+ if (m.map)
384
+ continue; // 텍스처 material은 자체 transparent 유지
385
+ m.opacity = effective;
386
+ m.transparent = effective < 1;
387
+ }
388
+ });
389
+ }
390
+ }
391
+ // ── 헬퍼 ────────────────────────────────────────────────
392
+ /**
393
+ * Returns the first argument that is a finite number. NaN slips past `??`
394
+ * (which only catches null/undefined), so without this a property-panel
395
+ * input producing NaN would corrupt absSize and cascade through Math.*.
396
+ */
397
+ function pickFinite(...candidates) {
398
+ for (const c of candidates) {
399
+ if (typeof c === 'number' && Number.isFinite(c))
400
+ return c;
401
+ }
402
+ return 0;
403
+ }
404
+ // ── 팩토리 등록 헬퍼 ─────────────────────────────────────
405
+ function register(type, overrides = {}) {
406
+ const config = Object.assign(Object.assign({}, DEFAULTS), overrides);
407
+ registerRealObjectFactory(type, (component) => new MCSRealObject3D(component, config));
408
+ }
409
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
410
+ // Machine (인프라 설비) — 높은 depth, 컨테이너는 반투명
411
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
412
+ register('Equipment', {
413
+ defaultDepth: 3 * TRANSPORT_SURFACE_HEIGHT,
414
+ opacity: 0.75,
415
+ metalness: 0.4,
416
+ roughness: 0.6,
417
+ defaultColor: 0x8899aa,
418
+ zPriority: Z_FMSIM.EQUIPMENT,
419
+ });
420
+ register('Buffer', {
421
+ defaultDepth: TRANSPORT_SURFACE_HEIGHT,
422
+ opacity: 1.0,
423
+ metalness: 0.3,
424
+ roughness: 0.7,
425
+ defaultColor: 0x99aa88,
426
+ shape: 'hexagon',
427
+ zPriority: Z_FMSIM.BUFFER,
428
+ });
429
+ register('AGVLine', {
430
+ depthRatio: 0,
431
+ defaultDepth: 0.1,
432
+ metalness: 0.6,
433
+ roughness: 0.3,
434
+ defaultColor: 0x888899,
435
+ zPriority: Z_FMSIM.AGV_LINE,
436
+ });
437
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
438
+ // OHTLine — 천장 I-beam 레일
439
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
440
+ const OHT_LINE_RAIL_COLOR = 0xcccccc;
441
+ const OHT_LINE_HEIGHT = 7 * TRANSPORT_SURFACE_HEIGHT; // OHT 상단과 일치
442
+ class OHTLineRealObject3D extends RealObjectGroup {
443
+ get zPriority() { return Z_FMSIM.OHT_LINE; }
444
+ get effectiveDepth() { return 0; }
445
+ get syncZPosOffset() { return OHT_LINE_HEIGHT; }
446
+ build() {
447
+ super.build();
448
+ const { width = 10, height = 10 } = this.component.state;
449
+ const w = Math.abs(width);
450
+ const h = Math.abs(height);
451
+ if (!w || !h)
452
+ return;
453
+ // I-beam 치수: 이송 방향 = 긴 변, 폭은 2D의 1/2
454
+ const isVertical = w < h;
455
+ const shortSide = isVertical ? w : h; // 2D 원본 짧은 쪽 폭
456
+ const beltW = shortSide * 0.25; // I-beam 폭: 원본의 1/4
457
+ const beamH = Math.max(beltW * 0.5, 3); // I-beam 전체 높이
458
+ const inset = shortSide * 0.5; // 양끝 여백: 원본 폭의 1/2
459
+ const railLen = (isVertical ? h : w) - inset * 2;
460
+ const flangeH = beamH * 0.2; // 플랜지 두께
461
+ const flangeW = beltW * 0.8; // 플랜지 폭
462
+ const webH = beamH - flangeH * 2; // 웹 높이
463
+ const webW = Math.max(flangeW * 0.25, 1); // 웹 두께
464
+ const mat = new THREE.MeshStandardMaterial({
465
+ color: OHT_LINE_RAIL_COLOR,
466
+ metalness: 0.5,
467
+ roughness: 0.4,
468
+ });
469
+ const geoms = [];
470
+ // 상부 플랜지
471
+ const topFlange = isVertical
472
+ ? new THREE.BoxGeometry(flangeW, flangeH, railLen)
473
+ : new THREE.BoxGeometry(railLen, flangeH, flangeW);
474
+ topFlange.translate(0, -flangeH / 2, 0);
475
+ geoms.push(topFlange);
476
+ // 웹 (수직판)
477
+ const web = isVertical
478
+ ? new THREE.BoxGeometry(webW, webH, railLen)
479
+ : new THREE.BoxGeometry(railLen, webH, webW);
480
+ web.translate(0, -flangeH - webH / 2, 0);
481
+ geoms.push(web);
482
+ // 하부 플랜지
483
+ const botFlange = isVertical
484
+ ? new THREE.BoxGeometry(flangeW, flangeH, railLen)
485
+ : new THREE.BoxGeometry(railLen, flangeH, flangeW);
486
+ botFlange.translate(0, -flangeH - webH - flangeH / 2, 0);
487
+ geoms.push(botFlange);
488
+ this._mesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(geoms), mat);
489
+ this._mesh.castShadow = true;
490
+ this.object3d.add(this._mesh);
491
+ }
492
+ update() {
493
+ if (this._mesh) {
494
+ this.object3d.remove(this._mesh);
495
+ this._mesh.geometry.dispose();
496
+ this._mesh.material.dispose();
497
+ this._mesh = undefined;
498
+ }
499
+ this.build();
500
+ this.updateTransform();
501
+ this.updateHidden();
502
+ }
503
+ onchange(after, before) {
504
+ if ('width' in after || 'height' in after || 'depth' in after ||
505
+ 'fillStyle' in after || 'strokeStyle' in after) {
506
+ this.update();
507
+ return;
508
+ }
509
+ super.onchange(after, before);
510
+ }
511
+ updateDimension() { }
512
+ updateAlpha() { }
513
+ }
514
+ registerRealObjectFactory('OHTLine', (component) => new OHTLineRealObject3D(component));
515
+ // STOCKER: 벽면에 용량 게이지 바를 포함하는 커스텀 3D 오브젝트
516
+ const STOCKER_CONFIG = Object.assign(Object.assign({}, DEFAULTS), { defaultDepth: 5 * TRANSPORT_SURFACE_HEIGHT, opacity: 0.75, metalness: 0.3, roughness: 0.6, defaultColor: 0x8899bb, zPriority: Z_FMSIM.STOCKER });
517
+ class StockerRealObject3D extends MCSRealObject3D {
518
+ constructor(component) {
519
+ super(component, STOCKER_CONFIG);
520
+ }
521
+ build() {
522
+ super.build();
523
+ this.buildGauge();
524
+ }
525
+ buildGauge() {
526
+ var _a, _b;
527
+ const comp = this.component;
528
+ const data = comp.data || {};
529
+ const gaugeMode = ((_a = comp.root) === null || _a === void 0 ? void 0 : _a.stockerGaugeMode) || 'capacity';
530
+ const gauge = this.resolveGauge(data, gaugeMode);
531
+ // 테두리는 스토커의 상태 색상 (machine status)
532
+ const statusColor = comp.statusColor;
533
+ if (statusColor && statusColor.toUpperCase() !== '#F0F0F0') {
534
+ gauge.borderColor = statusColor;
535
+ }
536
+ const { w, h } = this.absSize;
537
+ const depth = this.effectiveDepth;
538
+ const isWidthLonger = w >= h;
539
+ // 게이지 최대 크기 (스토커가 충분히 크면 이 크기 그대로 사용).
540
+ const MAX_BAR_W = 130;
541
+ const MAX_BAR_H = 26;
542
+ // 스토커 지붕 footprint 에 맞춰 비례 축소 (확대는 안 함 — 현재 크기가 상한).
543
+ const fit = fitGaugeScale(w, h, MAX_BAR_W, MAX_BAR_H);
544
+ // PlaneGeometry 의 월드 크기는 clamp, 텍스처 캔버스 해상도는 최대 크기 기준 고정
545
+ // (축소되어도 선명도 유지).
546
+ const barW = MAX_BAR_W * fit;
547
+ const barH = MAX_BAR_H * fit;
548
+ const scale = 4;
549
+ const canvasW = MAX_BAR_W * scale;
550
+ const canvasH = MAX_BAR_H * scale;
551
+ const canvas = document.createElement('canvas');
552
+ canvas.width = canvasW;
553
+ canvas.height = canvasH;
554
+ const ctx = canvas.getContext('2d');
555
+ const pad = 12;
556
+ // 배경 + 테두리
557
+ ctx.fillStyle = '#dddddd';
558
+ ctx.fillRect(0, 0, canvasW, canvasH);
559
+ ctx.strokeStyle = gauge.borderColor;
560
+ ctx.lineWidth = 12;
561
+ ctx.strokeRect(6, 6, canvasW - 12, canvasH - 12);
562
+ // 세그먼트 채움 (왼→오) + carrier/abnormal 은 세그먼트별 숫자(%) 표기 (2D 와 동일)
563
+ const innerW = canvasW - pad * 2;
564
+ const innerH = canvasH - pad * 2;
565
+ // 컴포넌트 폰트 설정(fontFamily/bold/italic) 을 그대로, 크기만 텍스처 scale 배 (2D 와 상대 크기 일치).
566
+ const fontSize = (Number((_b = this.component.state) === null || _b === void 0 ? void 0 : _b.fontSize) || 15) * scale;
567
+ const font = this.gaugeFont(fontSize);
568
+ let x = pad;
569
+ for (const seg of gauge.segments) {
570
+ const segW = Math.max(innerW * seg.ratio, seg.ratio > 0 ? 1 : 0);
571
+ if (segW <= 0)
572
+ continue;
573
+ ctx.fillStyle = seg.color;
574
+ ctx.fillRect(x, pad, segW, innerH);
575
+ if (gauge.perSegment) {
576
+ this.drawGaugeSegmentNumber(ctx, seg.ratio, x, pad, segW, innerH, font, fontSize);
577
+ }
578
+ x += segW;
579
+ }
580
+ // capacity: 전체 중앙에 usage% 한 개 (2D 와 동일). carrier/abnormal 은 위 세그먼트별 숫자 사용.
581
+ if (gauge.label) {
582
+ ctx.font = font;
583
+ ctx.textAlign = 'center';
584
+ ctx.textBaseline = 'middle';
585
+ ctx.fillStyle = '#333333';
586
+ ctx.fillText(gauge.label, canvasW / 2, canvasH / 2);
587
+ }
588
+ // 텍스처 → Plane
589
+ const texture = new THREE.CanvasTexture(canvas);
590
+ texture.colorSpace = THREE.SRGBColorSpace;
591
+ const geo = new THREE.PlaneGeometry(barW, barH);
592
+ geo.rotateX(-Math.PI / 2); // 수평 (지붕 위)
593
+ if (!isWidthLonger)
594
+ geo.rotateY(Math.PI / 2);
595
+ const mat = new THREE.MeshBasicMaterial({
596
+ map: texture,
597
+ transparent: true,
598
+ side: THREE.DoubleSide,
599
+ });
600
+ mat.polygonOffset = true;
601
+ mat.polygonOffsetFactor = -2;
602
+ mat.polygonOffsetUnit = -2;
603
+ this.gaugeMesh = new THREE.Mesh(geo, mat);
604
+ // ownGroup 기준(bottom-up): 볼륨 상단 = +depth. 그 위로 0.5 띄움.
605
+ this.gaugeMesh.position.set(0, depth + 0.5, 0);
606
+ this.components3D.add(this.gaugeMesh);
607
+ }
608
+ resolveGauge(data, mode) {
609
+ var _a;
610
+ switch (mode) {
611
+ case 'carrier': {
612
+ // 세그먼트 비율/색상은 2D 와 공유되는 단일 소스에서 계산 (필드/색상 drift 방지).
613
+ // 색상은 carrier 컴포넌트와 동일한 legend(테마)에서 취득.
614
+ const colors = carrierColorsFromLegend(resolveCarrierLegend(this.component));
615
+ const [f, e, ee] = carrierSegmentsFromData(data, colors);
616
+ const total = f.count + e.count + ee.count;
617
+ // 접두사 없는 세그먼트별 숫자(%)로 표기 (capacity·2D 와 동일). label(중앙 한 개) 미사용.
618
+ return total > 0
619
+ ? {
620
+ segments: [f, e, ee].map(s => ({ ratio: s.ratio, color: s.color })),
621
+ borderColor: colors.full,
622
+ label: null,
623
+ perSegment: true,
624
+ }
625
+ : { segments: [{ ratio: 1, color: '#dddddd' }], borderColor: colors.full, label: null, perSegment: false };
626
+ }
627
+ case 'abnormal': {
628
+ const [n, a] = abnormalSegmentsFromData(data);
629
+ const total = n.count + a.count;
630
+ return total > 0
631
+ ? {
632
+ segments: [n, a].map(s => ({ ratio: s.ratio, color: s.color })),
633
+ borderColor: a.count > 0 ? ABNORMAL_COLORS.abnormal : ABNORMAL_COLORS.normal,
634
+ label: null,
635
+ perSegment: true,
636
+ }
637
+ : {
638
+ segments: [{ ratio: 1, color: '#dddddd' }],
639
+ borderColor: ABNORMAL_COLORS.normal,
640
+ label: null,
641
+ perSegment: false,
642
+ };
643
+ }
644
+ default: { // capacity — 전체 중앙에 usage% 한 개
645
+ const cur = Number(data.CURRENTCAPACITY) || 0;
646
+ const max = Number(data.MAXCAPACITY) || 100;
647
+ const fullup = data.FULLUP === 'T';
648
+ const usage = Math.round((cur / max) * 100);
649
+ const legend = ((_a = this.component.root) === null || _a === void 0 ? void 0 : _a.stockerCapacityLegendTheme) || LEGEND_CAPACITY;
650
+ const color = fullup ? 'red' : (getValueOnRanges(usage, legend) || '#44aa44');
651
+ return {
652
+ segments: [{ ratio: usage / 100, color }],
653
+ borderColor: color,
654
+ label: `${usage}%`,
655
+ perSegment: false,
656
+ };
657
+ }
658
+ }
659
+ }
660
+ /** 컴포넌트 폰트 설정(fontFamily/bold/italic)으로 CSS font 문자열 조합. size 는 텍스처 스케일 반영값. */
661
+ gaugeFont(sizePx) {
662
+ const st = this.component.state || {};
663
+ const parts = [];
664
+ if (st.bold)
665
+ parts.push('bold');
666
+ if (st.italic)
667
+ parts.push('italic');
668
+ parts.push(`${sizePx}px`);
669
+ parts.push(st.fontFamily || 'sans-serif');
670
+ return parts.join(' ');
671
+ }
672
+ /** 세그먼트 영역 중심에 숫자(%)만 표기. 좁으면 값% → 값 → 생략 (2D _drawSegmentLabel 과 동일 정책). */
673
+ drawGaugeSegmentNumber(ctx, ratio, x, y, w, h, font, fontSize) {
674
+ ctx.font = font;
675
+ ctx.textAlign = 'center';
676
+ ctx.textBaseline = 'middle';
677
+ ctx.fillStyle = '#333333';
678
+ const value = `${Math.round(ratio * 100)}`;
679
+ const cx = x + w / 2;
680
+ const cy = y + h / 2;
681
+ if (fontSize <= h && ctx.measureText(`${value}%`).width <= w) {
682
+ ctx.fillText(`${value}%`, cx, cy);
683
+ }
684
+ else if (fontSize <= h && ctx.measureText(value).width <= w) {
685
+ ctx.fillText(value, cx, cy);
686
+ }
687
+ }
688
+ update() {
689
+ this.clearGauge();
690
+ super.update();
691
+ }
692
+ onchange(after, before) {
693
+ if ('data' in after) {
694
+ this.clearGauge();
695
+ this.buildGauge();
696
+ }
697
+ super.onchange(after, before);
698
+ }
699
+ clear() {
700
+ this.clearGauge();
701
+ return super.clear();
702
+ }
703
+ clearGauge() {
704
+ var _a, _b;
705
+ if (this.gaugeMesh) {
706
+ this.components3D.remove(this.gaugeMesh);
707
+ (_a = this.gaugeMesh.geometry) === null || _a === void 0 ? void 0 : _a.dispose();
708
+ const mat = this.gaugeMesh.material;
709
+ (_b = mat === null || mat === void 0 ? void 0 : mat.map) === null || _b === void 0 ? void 0 : _b.dispose();
710
+ mat === null || mat === void 0 ? void 0 : mat.dispose();
711
+ this.gaugeMesh = undefined;
712
+ }
713
+ }
714
+ }
715
+ registerRealObjectFactory('STOCKER', (component) => new StockerRealObject3D(component));
716
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
717
+ // Unit (이동체 · 홀더) — 낮은 depth, 불투명
718
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
719
+ // Port: 바닥판 (PlaneGeometry)
720
+ const PORT_CONFIG = Object.assign(Object.assign({}, DEFAULTS), { depthRatio: 0.01, defaultZPosFromParent: true, opacity: 0.1, metalness: 0.3, roughness: 0.8, defaultColor: 0xb0a090, shape: 'plane', zPriority: Z_FMSIM.PORT });
721
+ registerRealObjectFactory('Port', (component) => new MCSRealObject3D(component, PORT_CONFIG));
722
+ register('Shelf', {
723
+ depthRatio: 0.25,
724
+ metalness: 0.3,
725
+ roughness: 0.7,
726
+ defaultColor: 0xaabbcc,
727
+ zPriority: Z_FMSIM.SHELF,
728
+ });
729
+ // Carrier: CARRIERSTATUS에 따른 3D 애니메이션 지원
730
+ const CARRIER_CONFIG = Object.assign(Object.assign({}, DEFAULTS), { depthRatio: 0.5, metalness: 0, roughness: 1, defaultColor: 0xf0f0f0, isVisible: (c) => !!c.state.id, sizeRatio: 0.8, texturedTop: true });
731
+ /**
732
+ * 적층 시 다음 carrier 의 z-position 이 *_이전 carrier 의 effectiveDepth × N*
733
+ * 만큼 위에 놓인다. N=1 이면 carrier 들이 맞붙어 적층 (기존), N<1 이면 부분
734
+ * overlap (3D box 들이 겹쳐서 적층). 사용자 의도 — carrier 두께는 두꺼워도
735
+ * 적층 시 *_compact 하게 보이도록* — N 을 작게.
736
+ */
737
+ const CARRIER_STACK_STEP_RATIO = 0.9;
738
+ class CarrierRealObject3D extends MCSRealObject3D {
739
+ constructor(component) {
740
+ super(component, CARRIER_CONFIG);
741
+ }
742
+ /**
743
+ * cz override — *carrier 자기 결정* 의 적층 위치.
744
+ * parent.components 안 자기 index 까지의 형제 carrier 들의 effectiveDepth
745
+ * 누적합을 base cz 위에 더한다. holder 측에 별도 layout 책임을 두지 않고,
746
+ * carrier 가 자기 stack 위치를 알아서 결정.
747
+ */
748
+ get cz() {
749
+ var _a, _b;
750
+ const base = super.cz;
751
+ const parent = this.component.parent;
752
+ if (!(parent === null || parent === void 0 ? void 0 : parent.components))
753
+ return base;
754
+ const siblings = parent.components;
755
+ const idx = siblings.indexOf(this.component);
756
+ if (idx <= 0)
757
+ return base;
758
+ let offset = 0;
759
+ for (let i = 0; i < idx; i++) {
760
+ const ro = (_a = siblings[i]) === null || _a === void 0 ? void 0 : _a._realObject;
761
+ const eff = Number(ro === null || ro === void 0 ? void 0 : ro.effectiveDepth);
762
+ const d = Number.isFinite(eff) && eff > 0 ? eff : 1;
763
+ offset += d * CARRIER_STACK_STEP_RATIO;
764
+ }
765
+ // 적층 방향 — placement (= 부모 holder 타입) 에 따라 결정.
766
+ // OHT 처럼 그리퍼 아래에 매달리는 holder 는 carrier 가 *_아래로_* 누적,
767
+ // 그 외 (Port / Shelf / Shuttle / Vehicle) 는 위로 누적.
768
+ // MCSRealObject3D.syncZPosOffset 의 OHT 분기 (-effectiveDepth + halfD) 와
769
+ // 같은 방향성 일관 적용.
770
+ const parentType = (_b = parent === null || parent === void 0 ? void 0 : parent.state) === null || _b === void 0 ? void 0 : _b.type;
771
+ const dir = parentType === 'OHT' ? -1 : 1;
772
+ return base + dir * offset;
773
+ }
774
+ }
775
+ registerRealObjectFactory('Carrier', (component) => new CarrierRealObject3D(component));
776
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
777
+ // Gauge (용량 게이지) — 얇은 바
778
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
779
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
780
+ // Gauge (용량 게이지) — 2D 렌더링을 Plane 텍스처로 3D 표시
781
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
782
+ // Gauge 컴포넌트는 3D에서 표시하지 않음 (부모 STOCKER의 3D 모델에서 직접 게이지 렌더링)
783
+ // null 반환으로 3D 오브젝트 생성을 억제하고, default factory fallback도 방지
784
+ registerRealObjectFactory('StockerCapacityBar', () => undefined);
785
+ registerRealObjectFactory('MCSGaugeCapacityBar', () => undefined);
786
+ registerRealObjectFactory('ZoneCapacityBar', () => undefined);
787
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
788
+ // PortFlow — 2D render를 Plane 텍스처로 3D 표시
789
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
790
+ class PortFlowRealObject3D extends RealObjectGroup {
791
+ get zPriority() { return Z_FMSIM.PORT_FLOW; }
792
+ get effectiveDepth() { return 0; }
793
+ get syncZPosOffset() {
794
+ var _a;
795
+ // 부모 Port/Conveyor의 zPos와 동일하게
796
+ const parent = this.component.parentObject;
797
+ if (((_a = parent === null || parent === void 0 ? void 0 : parent.state) === null || _a === void 0 ? void 0 : _a.zPos) != null)
798
+ return parent.state.zPos;
799
+ return TRANSPORT_SURFACE_HEIGHT;
800
+ }
801
+ build() {
802
+ super.build();
803
+ const { width = 10, height = 10 } = this.component.state;
804
+ const w = Math.abs(width);
805
+ const h = Math.abs(height);
806
+ if (!w || !h)
807
+ return;
808
+ // 2D render를 캔버스에 캡처
809
+ // 화살표 날개 + 텍스트 영역이 bounds 밖으로 나가므로 전체 영역 계산
810
+ const { left, top } = this.component.bounds;
811
+ const { fontSize = 24, labelPosition = 'top' } = this.component.state;
812
+ const arrowPad = Math.min(w, h) * 0.4;
813
+ // 텍스트 영역 확장
814
+ let padLeft = arrowPad, padRight = arrowPad, padTop = arrowPad, padBottom = arrowPad;
815
+ if (this.component.hasTextProperty) {
816
+ switch (labelPosition) {
817
+ case 'top':
818
+ padTop = Math.max(padTop, fontSize + 4);
819
+ break;
820
+ case 'bottom':
821
+ padBottom = Math.max(padBottom, fontSize + 4);
822
+ break;
823
+ case 'left':
824
+ padLeft = Math.max(padLeft, fontSize * 4 + 4);
825
+ break;
826
+ case 'right':
827
+ padRight = Math.max(padRight, fontSize * 4 + 4);
828
+ break;
829
+ }
830
+ }
831
+ const totalW = w + padLeft + padRight;
832
+ const totalH = h + padTop + padBottom;
833
+ const scale = 2;
834
+ const canvas = document.createElement('canvas');
835
+ canvas.width = totalW * scale;
836
+ canvas.height = totalH * scale;
837
+ const ctx = canvas.getContext('2d');
838
+ ctx.save();
839
+ ctx.scale(scale, scale);
840
+ ctx.translate(-left + padLeft, -top + padTop);
841
+ try {
842
+ // 화살표 렌더
843
+ this.component.render(ctx);
844
+ ctx.fillStyle = this.component.state.strokeStyle || '#666666';
845
+ ctx.fill();
846
+ // 텍스트 렌더
847
+ if (this.component.hasTextProperty && this.component.drawText) {
848
+ ;
849
+ this.component.drawText(ctx);
850
+ }
851
+ }
852
+ catch ( /* render 실패 시 빈 텍스처 */_a) { /* render 실패 시 빈 텍스처 */ }
853
+ ctx.restore();
854
+ this._texture = new THREE.CanvasTexture(canvas);
855
+ this._texture.colorSpace = THREE.SRGBColorSpace;
856
+ const geo = new THREE.PlaneGeometry(totalW, totalH);
857
+ geo.rotateX(-Math.PI / 2);
858
+ const mat = new THREE.MeshBasicMaterial({
859
+ map: this._texture,
860
+ alphaTest: 0.1,
861
+ side: THREE.DoubleSide,
862
+ });
863
+ this._mesh = new THREE.Mesh(geo, mat);
864
+ // 비대칭 패딩 보정: 플레인 센터를 컴포넌트 bounds 센터에 맞춤
865
+ this._mesh.position.x = (padRight - padLeft) / 2;
866
+ this._mesh.position.y = 1;
867
+ this._mesh.position.z = (padBottom - padTop) / 2;
868
+ this.object3d.add(this._mesh);
869
+ }
870
+ update() {
871
+ var _a;
872
+ if (this._mesh) {
873
+ this.object3d.remove(this._mesh);
874
+ this._mesh.geometry.dispose();
875
+ this._mesh.material.dispose();
876
+ (_a = this._texture) === null || _a === void 0 ? void 0 : _a.dispose();
877
+ this._mesh = undefined;
878
+ this._texture = undefined;
879
+ }
880
+ this.build();
881
+ this.updateTransform();
882
+ this.updateHidden();
883
+ }
884
+ onchange(after, before) {
885
+ if ('width' in after || 'height' in after || 'orientation' in after ||
886
+ 'direction' in after || 'strokeStyle' in after || 'INOUTTYPE' in after) {
887
+ this.update();
888
+ return;
889
+ }
890
+ super.onchange(after, before);
891
+ }
892
+ updateDimension() { }
893
+ updateAlpha() { }
894
+ }
895
+ registerRealObjectFactory('PortFlow', (component) => new PortFlowRealObject3D(component));
896
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
897
+ // Node — 2D render를 바닥 Plane 텍스처로 3D 표시
898
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
899
+ class NodeRealObject3D extends RealObjectGroup {
900
+ get zPriority() { return Z_FMSIM.NODE; }
901
+ get effectiveDepth() { return 0; }
902
+ get syncZPosOffset() { return 0; }
903
+ build() {
904
+ super.build();
905
+ const { cx, cy } = this.component.state;
906
+ const radius = 8;
907
+ const size = radius * 2;
908
+ const scale = 2;
909
+ const pad = 2;
910
+ const canvas = document.createElement('canvas');
911
+ canvas.width = (size + pad * 2) * scale;
912
+ canvas.height = (size + pad * 2) * scale;
913
+ const ctx = canvas.getContext('2d');
914
+ ctx.save();
915
+ ctx.scale(scale, scale);
916
+ ctx.translate(-cx + radius + pad, -cy + radius + pad);
917
+ try {
918
+ this.component.render(ctx);
919
+ const { fillStyle = '#888888' } = this.component.state;
920
+ ctx.fillStyle = typeof fillStyle === 'string' ? fillStyle : '#888888';
921
+ ctx.fill();
922
+ const { strokeStyle } = this.component.state;
923
+ if (strokeStyle && typeof strokeStyle === 'string') {
924
+ ctx.strokeStyle = strokeStyle;
925
+ ctx.lineWidth = 1;
926
+ ctx.stroke();
927
+ }
928
+ }
929
+ catch ( /* render 실패 시 빈 텍스처 */_a) { /* render 실패 시 빈 텍스처 */ }
930
+ ctx.restore();
931
+ this._texture = new THREE.CanvasTexture(canvas);
932
+ this._texture.colorSpace = THREE.SRGBColorSpace;
933
+ const geo = new THREE.PlaneGeometry(size + pad * 2, size + pad * 2);
934
+ geo.rotateX(-Math.PI / 2);
935
+ const mat = new THREE.MeshBasicMaterial({
936
+ map: this._texture,
937
+ alphaTest: 0.1,
938
+ side: THREE.DoubleSide,
939
+ });
940
+ this._mesh = new THREE.Mesh(geo, mat);
941
+ this._mesh.position.y = 1;
942
+ this.object3d.add(this._mesh);
943
+ }
944
+ update() {
945
+ var _a;
946
+ if (this._mesh) {
947
+ this.object3d.remove(this._mesh);
948
+ this._mesh.geometry.dispose();
949
+ this._mesh.material.dispose();
950
+ (_a = this._texture) === null || _a === void 0 ? void 0 : _a.dispose();
951
+ this._mesh = undefined;
952
+ this._texture = undefined;
953
+ }
954
+ this.build();
955
+ this.updateTransform();
956
+ this.updateHidden();
957
+ }
958
+ onchange(after, before) {
959
+ if ('fillStyle' in after || 'strokeStyle' in after) {
960
+ this.update();
961
+ return;
962
+ }
963
+ super.onchange(after, before);
964
+ }
965
+ updateDimension() { }
966
+ updateAlpha() { }
967
+ }
968
+ registerRealObjectFactory('Node', (component) => new NodeRealObject3D(component));
969
+ // Scanner — 2D Triangle 실루엣과 정합되는 삼각형 prism.
970
+ // 이송 표면 높이의 0.2배(=6) 얇은 기둥 — 원래 값 유지, shape 만 'box' → 'triangle'.
971
+ const SCANNER_CONFIG = Object.assign(Object.assign({}, DEFAULTS), { defaultDepth: TRANSPORT_SURFACE_HEIGHT * 0.2, defaultZPosFromParent: true, opacity: 1, metalness: 0.3, roughness: 0.7, defaultColor: 0x888888, shape: 'triangle', zPriority: Z_FMSIM.SCANNER });
972
+ registerRealObjectFactory('Scanner', (component) => new MCSRealObject3D(component, SCANNER_CONFIG));
973
+ //# sourceMappingURL=machine-3d.js.map