@operato/scene-storage 10.0.0-beta.43 → 10.0.0-beta.46

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 (50) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/box-3d.d.ts +2 -0
  3. package/dist/box-3d.js +103 -64
  4. package/dist/box-3d.js.map +1 -1
  5. package/dist/crane-3d.d.ts +10 -0
  6. package/dist/crane-3d.js +34 -5
  7. package/dist/crane-3d.js.map +1 -1
  8. package/dist/crane.d.ts +136 -6
  9. package/dist/crane.js +567 -46
  10. package/dist/crane.js.map +1 -1
  11. package/dist/pallet-3d.d.ts +2 -0
  12. package/dist/pallet-3d.js +103 -53
  13. package/dist/pallet-3d.js.map +1 -1
  14. package/dist/parcel-3d.d.ts +1 -0
  15. package/dist/parcel-3d.js +18 -1
  16. package/dist/parcel-3d.js.map +1 -1
  17. package/dist/rack-grid-3d.js +26 -8
  18. package/dist/rack-grid-3d.js.map +1 -1
  19. package/dist/rack-grid.d.ts +94 -10
  20. package/dist/rack-grid.js +468 -86
  21. package/dist/rack-grid.js.map +1 -1
  22. package/dist/storage-rack-3d.js +1 -1
  23. package/dist/storage-rack-3d.js.map +1 -1
  24. package/dist/storage-rack.d.ts +31 -6
  25. package/dist/storage-rack.js +96 -14
  26. package/dist/storage-rack.js.map +1 -1
  27. package/package.json +3 -3
  28. package/src/box-3d.ts +121 -68
  29. package/src/crane-3d.ts +34 -4
  30. package/src/crane.ts +615 -55
  31. package/src/pallet-3d.ts +122 -55
  32. package/src/parcel-3d.ts +19 -1
  33. package/src/rack-grid-3d.ts +31 -8
  34. package/src/rack-grid.ts +488 -82
  35. package/src/storage-rack-3d.ts +1 -1
  36. package/src/storage-rack.ts +96 -14
  37. package/test/test-coord-alignment.ts +2 -2
  38. package/test/test-crane-bay-match.ts +130 -0
  39. package/test/test-crane-binding-resolve.ts +168 -0
  40. package/test/test-crane-duration.ts +90 -0
  41. package/test/test-crane-rotation-reach.ts +218 -0
  42. package/test/test-rack-grid-3d-alignment.ts +235 -0
  43. package/test/test-rack-grid-3d-attach-real.ts +375 -0
  44. package/test/test-rack-grid-cell.ts +2 -2
  45. package/test/test-rack-grid-location.ts +2 -2
  46. package/test/test-rack-grid-occupied-slots.ts +165 -0
  47. package/test/test-rack-grid-picking-position.ts +154 -0
  48. package/test/test-rack-grid-slot-api.ts +483 -0
  49. package/test/test-slot-ids-enumeration.ts +137 -0
  50. package/tsconfig.tsbuildinfo +1 -1
package/src/pallet-3d.ts CHANGED
@@ -21,6 +21,57 @@ import * as THREE from 'three'
21
21
  import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js'
22
22
  import { RealObjectGroup } from '@hatiolab/things-scene'
23
23
 
24
+ // ── Material cache by bodyColor (shared across all Pallet3D instances) ──
25
+ // 동일 bodyColor 의 pallet 수십~수백 개 → GPU material 인스턴스 *1개로 통합*.
26
+ const woodBodyMaterials = new Map<string, THREE.MeshStandardMaterial>()
27
+ const woodStringerMaterials = new Map<string, THREE.MeshStandardMaterial>()
28
+ const plasticDeckMaterials = new Map<string, THREE.MeshStandardMaterial>()
29
+ const plasticFootMaterials = new Map<string, THREE.MeshStandardMaterial>()
30
+
31
+ function getWoodBodyMaterial(bodyColor: string): THREE.MeshStandardMaterial {
32
+ let m = woodBodyMaterials.get(bodyColor)
33
+ if (!m) {
34
+ m = new THREE.MeshStandardMaterial({ color: bodyColor, metalness: 0.0, roughness: 0.85 })
35
+ woodBodyMaterials.set(bodyColor, m)
36
+ }
37
+ return m
38
+ }
39
+
40
+ function getWoodStringerMaterial(bodyColor: string): THREE.MeshStandardMaterial {
41
+ let m = woodStringerMaterials.get(bodyColor)
42
+ if (!m) {
43
+ const tint = new THREE.Color(bodyColor).multiplyScalar(0.85)
44
+ m = new THREE.MeshStandardMaterial({ color: tint, metalness: 0.0, roughness: 0.9 })
45
+ woodStringerMaterials.set(bodyColor, m)
46
+ }
47
+ return m
48
+ }
49
+
50
+ function getPlasticDeckMaterial(bodyColor: string): THREE.MeshStandardMaterial {
51
+ let m = plasticDeckMaterials.get(bodyColor)
52
+ if (!m) {
53
+ m = new THREE.MeshStandardMaterial({ color: bodyColor, metalness: 0.1, roughness: 0.55 })
54
+ plasticDeckMaterials.set(bodyColor, m)
55
+ }
56
+ return m
57
+ }
58
+
59
+ function getPlasticFootMaterial(bodyColor: string): THREE.MeshStandardMaterial {
60
+ let m = plasticFootMaterials.get(bodyColor)
61
+ if (!m) {
62
+ const tint = new THREE.Color(bodyColor).multiplyScalar(0.85)
63
+ m = new THREE.MeshStandardMaterial({ color: tint, metalness: 0.1, roughness: 0.65 })
64
+ plasticFootMaterials.set(bodyColor, m)
65
+ }
66
+ return m
67
+ }
68
+
69
+ // ── Geometry cache by size (shared across all Pallet3D instances) ──
70
+ // 동일 width × height × depth 의 pallet → merged geometry *1세트*만 GPU 에 업로드.
71
+ // Translation / merge 비용도 동일 size pallet 끼리 *1회*만 발생.
72
+ const woodGeoCache = new Map<string, { top: THREE.BufferGeometry; stringer: THREE.BufferGeometry; bottom: THREE.BufferGeometry }>()
73
+ const plasticGeoCache = new Map<string, { deck: THREE.BufferGeometry; feet: THREE.BufferGeometry; brace: THREE.BufferGeometry }>()
74
+
24
75
  export class Pallet3D extends RealObjectGroup {
25
76
  build() {
26
77
  super.build()
@@ -38,28 +89,36 @@ export class Pallet3D extends RealObjectGroup {
38
89
 
39
90
  /** Wood EUR-style: 7 top slats + 3 stringers + 5 bottom slats. */
40
91
  private buildWood(width: number, height: number, depth: number, bodyColor: string) {
92
+ const { top, stringer, bottom } = this.getWoodGeometries(width, height, depth)
93
+
94
+ const woodMaterial = getWoodBodyMaterial(bodyColor)
95
+ const stringerMaterial = getWoodStringerMaterial(bodyColor)
96
+
97
+ const topSlatMesh = new THREE.Mesh(top, woodMaterial)
98
+ topSlatMesh.castShadow = true
99
+ topSlatMesh.receiveShadow = true
100
+ this.object3d.add(topSlatMesh)
101
+
102
+ const stringerMesh = new THREE.Mesh(stringer, stringerMaterial)
103
+ stringerMesh.castShadow = true
104
+ this.object3d.add(stringerMesh)
105
+
106
+ const botSlatMesh = new THREE.Mesh(bottom, woodMaterial)
107
+ botSlatMesh.receiveShadow = true
108
+ this.object3d.add(botSlatMesh)
109
+ }
110
+
111
+ private getWoodGeometries(width: number, height: number, depth: number) {
112
+ const key = `${width}|${height}|${depth}`
113
+ let cached = woodGeoCache.get(key)
114
+ if (cached) return cached
115
+
41
116
  const baseY = -depth / 2
42
117
  const slatThickness = depth * 0.15
43
118
  const stringerThickness = depth * 0.45
44
119
  const bottomSlatThickness = depth * 0.13
45
120
 
46
- const woodMaterial = new THREE.MeshStandardMaterial({
47
- color: bodyColor,
48
- metalness: 0.0,
49
- roughness: 0.85
50
- })
51
- const stringerColor = new THREE.Color(bodyColor).multiplyScalar(0.85)
52
- const stringerMaterial = new THREE.MeshStandardMaterial({
53
- color: stringerColor,
54
- metalness: 0.0,
55
- roughness: 0.9
56
- })
57
-
58
- // ── Top + bottom slats — same count, same z-positions, paired vertically ─
59
- // EUR-pallet style: 5 boards on top, 5 below (under the same z ranges so
60
- // they read as a single skeleton rather than two unrelated grids).
61
121
  const slatCount = 5
62
- const slatW = width
63
122
  const slatD = (height * 0.92) / (slatCount + (slatCount - 1) * 0.4)
64
123
  const gapD = slatD * 0.4
65
124
  const totalSpan = slatCount * slatD + (slatCount - 1) * gapD
@@ -72,16 +131,12 @@ export class Pallet3D extends RealObjectGroup {
72
131
 
73
132
  const topSlatGeos: THREE.BufferGeometry[] = []
74
133
  for (const z of slatPositions) {
75
- const slat = new THREE.BoxGeometry(slatW, slatThickness, slatD)
134
+ const slat = new THREE.BoxGeometry(width, slatThickness, slatD)
76
135
  slat.translate(0, baseY + depth - slatThickness / 2, z)
77
136
  topSlatGeos.push(slat)
78
137
  }
79
- const topSlatMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(topSlatGeos), woodMaterial)
80
- topSlatMesh.castShadow = true
81
- topSlatMesh.receiveShadow = true
82
- this.object3d.add(topSlatMesh)
138
+ const top = BufferGeometryUtils.mergeGeometries(topSlatGeos)
83
139
 
84
- // ── Stringers (3 perpendicular blocks between top and bottom decks) ─
85
140
  const stringerCount = 3
86
141
  const stringerW = width * 0.07
87
142
  const stringerY = baseY + bottomSlatThickness + stringerThickness / 2
@@ -93,50 +148,59 @@ export class Pallet3D extends RealObjectGroup {
93
148
  stringer.translate(x, stringerY, 0)
94
149
  stringerGeos.push(stringer)
95
150
  }
96
- const stringerMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(stringerGeos), stringerMaterial)
97
- stringerMesh.castShadow = true
98
- this.object3d.add(stringerMesh)
151
+ const stringer = BufferGeometryUtils.mergeGeometries(stringerGeos)
99
152
 
100
- // ── Bottom slats — same z-positions as top so the deck reads as paired ─
101
153
  const botSlatGeos: THREE.BufferGeometry[] = []
102
154
  for (const z of slatPositions) {
103
155
  const slat = new THREE.BoxGeometry(width, bottomSlatThickness, slatD)
104
156
  slat.translate(0, baseY + bottomSlatThickness / 2, z)
105
157
  botSlatGeos.push(slat)
106
158
  }
107
- const botSlatMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(botSlatGeos), woodMaterial)
108
- botSlatMesh.receiveShadow = true
109
- this.object3d.add(botSlatMesh)
159
+ const bottom = BufferGeometryUtils.mergeGeometries(botSlatGeos)
160
+
161
+ cached = { top, stringer, bottom }
162
+ woodGeoCache.set(key, cached)
163
+ return cached
110
164
  }
111
165
 
112
166
  /** Plastic molded: solid top deck + ribbed underside / feet. */
113
167
  private buildPlastic(width: number, height: number, depth: number, bodyColor: string) {
168
+ const { deck, feet, brace } = this.getPlasticGeometries(width, height, depth)
169
+
170
+ const deckMaterial = getPlasticDeckMaterial(bodyColor)
171
+ const footMaterial = getPlasticFootMaterial(bodyColor)
172
+
114
173
  const baseY = -depth / 2
115
174
  const deckThickness = depth * 0.30
116
- const footH = depth * 0.55
117
- const footW = width * 0.12
118
175
 
119
- const deckMaterial = new THREE.MeshStandardMaterial({
120
- color: bodyColor,
121
- metalness: 0.1,
122
- roughness: 0.55
123
- })
124
- const footColor = new THREE.Color(bodyColor).multiplyScalar(0.85)
125
- const footMaterial = new THREE.MeshStandardMaterial({
126
- color: footColor,
127
- metalness: 0.1,
128
- roughness: 0.65
129
- })
130
-
131
- // ── Solid top deck ───────────────────────────────────────────────
132
- const deckGeo = new THREE.BoxGeometry(width * 0.98, deckThickness, height * 0.98)
133
- const deckMesh = new THREE.Mesh(deckGeo, deckMaterial)
176
+ const deckMesh = new THREE.Mesh(deck, deckMaterial)
134
177
  deckMesh.position.set(0, baseY + depth - deckThickness / 2, 0)
135
178
  deckMesh.castShadow = true
136
179
  deckMesh.receiveShadow = true
137
180
  this.object3d.add(deckMesh)
138
181
 
139
- // ── 9 feet (3×3 grid — typical plastic pallet underside) ─────────
182
+ const footMesh = new THREE.Mesh(feet, footMaterial)
183
+ footMesh.castShadow = true
184
+ this.object3d.add(footMesh)
185
+
186
+ const braceMesh = new THREE.Mesh(brace, footMaterial)
187
+ this.object3d.add(braceMesh)
188
+ }
189
+
190
+ private getPlasticGeometries(width: number, height: number, depth: number) {
191
+ const key = `${width}|${height}|${depth}`
192
+ let cached = plasticGeoCache.get(key)
193
+ if (cached) return cached
194
+
195
+ const baseY = -depth / 2
196
+ const deckThickness = depth * 0.30
197
+ const footH = depth * 0.55
198
+ const footW = width * 0.12
199
+
200
+ // Deck geo — local space; mesh position applied at instantiation.
201
+ const deck = new THREE.BoxGeometry(width * 0.98, deckThickness, height * 0.98)
202
+
203
+ // 9 feet (3×3 grid) → merged geometry with translations baked in.
140
204
  const footGeos: THREE.BufferGeometry[] = []
141
205
  for (let i = -1; i <= 1; i++) {
142
206
  for (let j = -1; j <= 1; j++) {
@@ -147,18 +211,21 @@ export class Pallet3D extends RealObjectGroup {
147
211
  footGeos.push(foot)
148
212
  }
149
213
  }
150
- const footMesh = new THREE.Mesh(BufferGeometryUtils.mergeGeometries(footGeos), footMaterial)
151
- footMesh.castShadow = true
152
- this.object3d.add(footMesh)
214
+ const feet = BufferGeometryUtils.mergeGeometries(footGeos)
153
215
 
154
- // ── Cross-bracing along underside (suggests molded reinforcement)
216
+ // 3 braces merged into single mesh (이전에 mesh 3개 분리 = drawcall 3개).
155
217
  const braceH = depth * 0.10
156
- const braceGeo = new THREE.BoxGeometry(width * 0.95, braceH, height * 0.04)
218
+ const braceGeos: THREE.BufferGeometry[] = []
157
219
  for (const zSign of [-1, 0, 1]) {
158
- const brace = new THREE.Mesh(braceGeo.clone(), footMaterial)
159
- brace.position.set(0, baseY + footH - braceH / 2, zSign * height * 0.4)
160
- this.object3d.add(brace)
220
+ const b = new THREE.BoxGeometry(width * 0.95, braceH, height * 0.04)
221
+ b.translate(0, baseY + footH - braceH / 2, zSign * height * 0.4)
222
+ braceGeos.push(b)
161
223
  }
224
+ const brace = BufferGeometryUtils.mergeGeometries(braceGeos)
225
+
226
+ cached = { deck, feet, brace }
227
+ plasticGeoCache.set(key, cached)
228
+ return cached
162
229
  }
163
230
 
164
231
  updateDimension() {}
package/src/parcel-3d.ts CHANGED
@@ -70,10 +70,28 @@ function _getLabelGeo(w: number, t: number, h: number): THREE.BoxGeometry {
70
70
  }
71
71
 
72
72
  export class Parcel3D extends RealObjectGroup {
73
+ // 처음 build 에서 finite size 받으면 cache. 이후 *NaN 으로 rebuild* 시 cache
74
+ // 값 사용 — *생성 직후 실제 크기 유지*. fallback (100x100x150) 은 *cache 도
75
+ // 없는 첫 호출에 NaN* 일 때만 사용.
76
+ private _cachedSize?: { w: number; h: number; d: number }
77
+
73
78
  build() {
74
79
  super.build()
75
80
 
76
- const { width, height, depth = 150 } = this.component.state
81
+ // NaN guard + cache. carrier.state.height/width *crane.receive
82
+ // bounds reflow* 시점에 NaN 으로 변할 수 있음 (cross-module state proxy
83
+ // 의 _state.h undefined + 계산 결과 NaN). 처음 build 의 finite 값을 instance
84
+ // 에 cache → 이후 NaN rebuild 에도 *실제 carrier 크기로 BoxGeometry* 유지.
85
+ const finite = (v: any) => typeof v === 'number' && Number.isFinite(v) && v > 0
86
+ const stateW = this.component.state.width
87
+ const stateH = this.component.state.height
88
+ const stateD = this.component.state.depth
89
+ if (this._cachedSize == null && finite(stateW) && finite(stateH) && finite(stateD)) {
90
+ this._cachedSize = { w: stateW, h: stateH, d: stateD }
91
+ }
92
+ const width = finite(stateW) ? stateW : (this._cachedSize?.w ?? 100)
93
+ const height = finite(stateH) ? stateH : (this._cachedSize?.h ?? 100)
94
+ const depth = finite(stateD) ? stateD : (this._cachedSize?.d ?? 150)
77
95
  const baseY = -depth / 2
78
96
 
79
97
  // ── Main body ────────────────────────────────────────────────────
@@ -60,13 +60,16 @@ export class RackGrid3D extends RealObjectGroup {
60
60
  this._frameGroup.add(this._beamGroup)
61
61
  this.object3d.add(this._frameGroup)
62
62
 
63
- const width = (rs?.width as number) ?? 400 // 3D X
64
- const height = (rs?.depth as number) ?? 2000 // 3D Y (floor → ceiling)
65
- const depth = (rs?.height as number) ?? 200 // 3D Z (front back)
63
+ // ?? 쓰면 NaN 통과 finite + positive 검증 후 default fallback.
64
+ const finite = (v: any, fb: number) =>
65
+ typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : fb
66
+ const width = finite(rs?.width, 400) // 3D X
67
+ const height = finite(rs?.depth, 2000) // 3D Y (floor → ceiling)
68
+ const depth = finite(rs?.height, 200) // 3D Z (front → back)
66
69
  const cols = comp.columns
67
70
  const rows = comp.rackRows
68
71
  const shelves = comp.shelves
69
- const shelfBase = Math.max(0, Math.min((rs?.shelfBaseHeight as number) || 0, height * 0.9))
72
+ const shelfBase = Math.max(0, Math.min(finite(rs?.shelfBaseHeight, 0), height * 0.9))
70
73
  const shelfZone = height - shelfBase
71
74
 
72
75
  const bayW = width / cols
@@ -313,10 +316,14 @@ export class RackGrid3D extends RealObjectGroup {
313
316
  const cols = comp.columns
314
317
  const rows = comp.rackRows
315
318
  const shelves = comp.shelves
316
- const width = (rs?.width as number) ?? 400
317
- const height = (rs?.depth as number) ?? 2000
318
- const depth = (rs?.height as number) ?? 200
319
- const shelfBase = Math.max(0, Math.min((rs?.shelfBaseHeight as number) || 0, height * 0.9))
319
+ // state.width/depth/height NaN 경우 ?? 는 nullish 만 fallback 이라 NaN 통과.
320
+ // 명시적 finite 검증 default 사용. NaN BoxGeometry 의 근본 원인.
321
+ const finite = (v: any, fb: number) =>
322
+ typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : fb
323
+ const width = finite(rs?.width, 400)
324
+ const height = finite(rs?.depth, 2000)
325
+ const depth = finite(rs?.height, 200)
326
+ const shelfBase = Math.max(0, Math.min(finite(rs?.shelfBaseHeight, 0), height * 0.9))
320
327
  const shelfZone = height - shelfBase
321
328
  const bayW = width / cols
322
329
  const bayD = depth / rows
@@ -328,6 +335,22 @@ export class RackGrid3D extends RealObjectGroup {
328
335
  const stockD = cellY * 0.7
329
336
  const stockH = bayD * 0.85
330
337
 
338
+ // 최종 차원이 finite 한지 검증 — accessor + finite() 거쳤어도 *모든 입력이 0* 이거나
339
+ // 예상 못한 경로로 NaN/0 가능성. invalid 시 stock mesh 생성 자체를 skip + 진단 로그.
340
+ if (
341
+ !Number.isFinite(stockW) || stockW <= 0 ||
342
+ !Number.isFinite(stockD) || stockD <= 0 ||
343
+ !Number.isFinite(stockH) || stockH <= 0
344
+ ) {
345
+ console.error('[rack-grid-3d] rebuildStockMesh: invalid stock dims — mesh 생성 skip', {
346
+ stockW, stockD, stockH,
347
+ cols, rows, shelves,
348
+ width, height, depth, shelfBase, shelfZone, cellY, bayW, bayD,
349
+ stateW: rs?.width, stateDepth: rs?.depth, stateH: rs?.height, stateShelfBase: rs?.shelfBaseHeight
350
+ })
351
+ return
352
+ }
353
+
331
354
  const records = comp.records
332
355
  const recordsByCell = new Map<string, any>()
333
356
  for (const r of records) {