@2112-lab/central-plant 0.1.13 โ†’ 0.1.15

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.
@@ -0,0 +1,703 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
+ var THREE = require('three');
7
+ var BufferGeometryUtils = require('../../node_modules/three/examples/jsm/utils/BufferGeometryUtils.js');
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
28
+
29
+ var ObjProcessor = /*#__PURE__*/function () {
30
+ function ObjProcessor() {
31
+ _rollupPluginBabelHelpers.classCallCheck(this, ObjProcessor);
32
+ this.indexedGeometryCache = new Map(); // Cache for indexed geometries
33
+ this.geometrySizeCache = new Map(); // Cache for geometry sizes
34
+ this.idbSupported = this.checkIndexedDBSupport();
35
+ this.dbName = 'CentralPlantGeometryDB';
36
+ this.dbVersion = 1;
37
+ this.storeName = 'indexedGeometries';
38
+ console.log('๐Ÿ”ง ObjProcessor initialized');
39
+ console.log("\uD83D\uDCE6 IndexedDB supported: ".concat(this.idbSupported));
40
+ }
41
+
42
+ /**
43
+ * Check if IndexedDB is supported
44
+ * @returns {boolean} True if IndexedDB is supported
45
+ */
46
+ return _rollupPluginBabelHelpers.createClass(ObjProcessor, [{
47
+ key: "checkIndexedDBSupport",
48
+ value: function checkIndexedDBSupport() {
49
+ if (typeof window === 'undefined') return false;
50
+ return 'indexedDB' in window && window.indexedDB !== null;
51
+ }
52
+
53
+ /**
54
+ * Initialize IndexedDB for geometry storage
55
+ * @returns {Promise<IDBDatabase>} Promise that resolves to the database
56
+ */
57
+ }, {
58
+ key: "initializeIDB",
59
+ value: (function () {
60
+ var _initializeIDB = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee() {
61
+ var _this = this;
62
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
63
+ while (1) switch (_context.n) {
64
+ case 0:
65
+ if (this.idbSupported) {
66
+ _context.n = 1;
67
+ break;
68
+ }
69
+ throw new Error('IndexedDB not supported');
70
+ case 1:
71
+ return _context.a(2, new Promise(function (resolve, reject) {
72
+ var request = indexedDB.open(_this.dbName, _this.dbVersion);
73
+ request.onerror = function () {
74
+ console.error('โŒ Failed to open IndexedDB');
75
+ reject(request.error);
76
+ };
77
+ request.onsuccess = function () {
78
+ console.log('โœ… IndexedDB opened successfully');
79
+ resolve(request.result);
80
+ };
81
+ request.onupgradeneeded = function (event) {
82
+ console.log('๐Ÿ”„ Upgrading IndexedDB schema');
83
+ var db = event.target.result;
84
+
85
+ // Create object store for indexed geometries
86
+ if (!db.objectStoreNames.contains(_this.storeName)) {
87
+ var store = db.createObjectStore(_this.storeName, {
88
+ keyPath: 'modelKey'
89
+ });
90
+ store.createIndex('modelType', 'modelType', {
91
+ unique: false
92
+ });
93
+ store.createIndex('sizeKB', 'sizeKB', {
94
+ unique: false
95
+ });
96
+ console.log('๐Ÿ“ฆ Created geometry object store');
97
+ }
98
+ };
99
+ }));
100
+ }
101
+ }, _callee, this);
102
+ }));
103
+ function initializeIDB() {
104
+ return _initializeIDB.apply(this, arguments);
105
+ }
106
+ return initializeIDB;
107
+ }()
108
+ /**
109
+ * Convert OBJ object to indexed BufferGeometry
110
+ * @param {THREE.Object3D} objObject - The loaded OBJ object from THREE.OBJLoader
111
+ * @param {string} modelKey - The model key for identification
112
+ * @returns {Object} Object containing indexed geometry and metadata
113
+ */
114
+ )
115
+ }, {
116
+ key: "objToIndexedBufferGeometry",
117
+ value: function objToIndexedBufferGeometry(objObject, modelKey) {
118
+ var _this2 = this;
119
+ console.log("\uD83D\uDD04 Converting OBJ to indexed BufferGeometry: ".concat(modelKey));
120
+ var geometries = [];
121
+ var materials = [];
122
+
123
+ // Traverse the OBJ object and collect all geometries
124
+ objObject.traverse(function (child) {
125
+ if (child.isMesh && child.geometry) {
126
+ // Clone the geometry to avoid modifying the original
127
+ var geometry = child.geometry.clone();
128
+
129
+ // Ensure the geometry has proper attributes
130
+ if (!geometry.attributes.position) {
131
+ console.warn("\u26A0\uFE0F Geometry missing position attribute: ".concat(modelKey));
132
+ return;
133
+ }
134
+
135
+ // Compute normals if missing
136
+ if (!geometry.attributes.normal) {
137
+ geometry.computeVertexNormals();
138
+ console.log("\uD83D\uDCD0 Computed normals for geometry: ".concat(modelKey));
139
+ }
140
+
141
+ // Compute UVs if missing (simple planar mapping)
142
+ if (!geometry.attributes.uv) {
143
+ _this2.computeSimpleUVs(geometry);
144
+ console.log("\uD83D\uDDFA\uFE0F Computed UVs for geometry: ".concat(modelKey));
145
+ }
146
+ geometries.push(geometry);
147
+ materials.push(child.material);
148
+ }
149
+ });
150
+ if (geometries.length === 0) {
151
+ console.warn("\u26A0\uFE0F No valid geometries found in OBJ: ".concat(modelKey));
152
+ return null;
153
+ }
154
+
155
+ // Merge all geometries into one
156
+ var mergedGeometry;
157
+ if (geometries.length === 1) {
158
+ mergedGeometry = geometries[0];
159
+ } else {
160
+ console.log("\uD83D\uDD17 Merging ".concat(geometries.length, " geometries for: ").concat(modelKey));
161
+ mergedGeometry = BufferGeometryUtils.mergeGeometries(geometries);
162
+ }
163
+
164
+ // Convert to indexed geometry if not already indexed
165
+ var indexedGeometry = mergedGeometry;
166
+ var originalGeometry = mergedGeometry; // Keep reference to original for comparison
167
+
168
+ if (!mergedGeometry.index) {
169
+ console.log("\uD83D\uDCCA Converting to indexed geometry: ".concat(modelKey));
170
+ indexedGeometry = BufferGeometryUtils.mergeVertices(mergedGeometry);
171
+ }
172
+
173
+ // Calculate geometry statistics with original geometry for comparison
174
+ var stats = this.calculateGeometryStats(indexedGeometry, modelKey, originalGeometry);
175
+
176
+ // Prepare serializable data for storage
177
+ var geometryData = this.serializeGeometry(indexedGeometry, modelKey, stats);
178
+ console.log("\u2705 Successfully converted OBJ to indexed BufferGeometry: ".concat(modelKey));
179
+ console.log("\uD83D\uDCCA Vertices: ".concat(stats.vertexCount, ", Faces: ").concat(stats.faceCount));
180
+ console.log("\uD83D\uDCBE Indexed Size: ".concat(stats.indexedSizeKB, "KB"));
181
+ if (stats.nonIndexedSizeKB > 0) {
182
+ console.log("\uD83D\uDCBE Non-Indexed Size: ".concat(stats.nonIndexedSizeKB, "KB"));
183
+ console.log("\uD83D\uDD04 Memory Reduction: ".concat(stats.memoryReduction, "% (").concat(stats.compressionRatio, "x smaller)"));
184
+ }
185
+ return {
186
+ geometry: indexedGeometry,
187
+ geometryData: geometryData,
188
+ stats: stats,
189
+ materials: materials[0] || new THREE__namespace.MeshStandardMaterial({
190
+ color: 0x888888
191
+ })
192
+ };
193
+ }
194
+
195
+ /**
196
+ * Compute simple planar UVs for geometry
197
+ * @param {THREE.BufferGeometry} geometry - The geometry to compute UVs for
198
+ */
199
+ }, {
200
+ key: "computeSimpleUVs",
201
+ value: function computeSimpleUVs(geometry) {
202
+ var positions = geometry.attributes.position;
203
+ var uvs = new Float32Array(positions.count * 2);
204
+
205
+ // Simple planar projection on XZ plane
206
+ for (var i = 0; i < positions.count; i++) {
207
+ var x = positions.getX(i);
208
+ var z = positions.getZ(i);
209
+
210
+ // Normalize to 0-1 range (simple box projection)
211
+ uvs[i * 2] = (x + 1) * 0.5;
212
+ uvs[i * 2 + 1] = (z + 1) * 0.5;
213
+ }
214
+ geometry.setAttribute('uv', new THREE__namespace.BufferAttribute(uvs, 2));
215
+ }
216
+
217
+ /**
218
+ * Calculate geometry statistics
219
+ * @param {THREE.BufferGeometry} geometry - The geometry to analyze
220
+ * @param {string} modelKey - The model key for logging
221
+ * @param {THREE.BufferGeometry} originalGeometry - Optional original non-indexed geometry for comparison
222
+ * @returns {Object} Statistics object
223
+ */
224
+ }, {
225
+ key: "calculateGeometryStats",
226
+ value: function calculateGeometryStats(geometry, modelKey) {
227
+ var originalGeometry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
228
+ var vertexCount = geometry.attributes.position.count;
229
+ var faceCount = geometry.index ? geometry.index.count / 3 : vertexCount / 3;
230
+
231
+ // Calculate indexed geometry memory usage
232
+ var indexedBytes = 0;
233
+
234
+ // Position attribute (3 floats per vertex)
235
+ if (geometry.attributes.position) {
236
+ indexedBytes += geometry.attributes.position.array.byteLength;
237
+ }
238
+
239
+ // Normal attribute (3 floats per vertex)
240
+ if (geometry.attributes.normal) {
241
+ indexedBytes += geometry.attributes.normal.array.byteLength;
242
+ }
243
+
244
+ // UV attribute (2 floats per vertex)
245
+ if (geometry.attributes.uv) {
246
+ indexedBytes += geometry.attributes.uv.array.byteLength;
247
+ }
248
+
249
+ // Index buffer (if indexed)
250
+ if (geometry.index) {
251
+ indexedBytes += geometry.index.array.byteLength;
252
+ }
253
+ var indexedSizeKB = (indexedBytes / 1024).toFixed(2);
254
+
255
+ // Calculate non-indexed geometry memory usage for comparison
256
+ var nonIndexedBytes = 0;
257
+ var nonIndexedSizeKB = 0;
258
+ var memoryReduction = 0;
259
+ var compressionRatio = 1;
260
+ if (originalGeometry) {
261
+ // Calculate what the memory would be without indexing
262
+ var originalVertexCount = originalGeometry.attributes.position ? originalGeometry.attributes.position.count : vertexCount;
263
+
264
+ // Position: 3 floats per vertex
265
+ nonIndexedBytes += originalVertexCount * 3 * 4; // 4 bytes per float32
266
+
267
+ // Normals: 3 floats per vertex (if present)
268
+ if (originalGeometry.attributes.normal || geometry.attributes.normal) {
269
+ nonIndexedBytes += originalVertexCount * 3 * 4;
270
+ }
271
+
272
+ // UVs: 2 floats per vertex (if present)
273
+ if (originalGeometry.attributes.uv || geometry.attributes.uv) {
274
+ nonIndexedBytes += originalVertexCount * 2 * 4;
275
+ }
276
+ nonIndexedSizeKB = (nonIndexedBytes / 1024).toFixed(2);
277
+ memoryReduction = ((nonIndexedBytes - indexedBytes) / nonIndexedBytes * 100).toFixed(1);
278
+ compressionRatio = (nonIndexedBytes / indexedBytes).toFixed(2);
279
+ } else if (geometry.index) {
280
+ // Estimate non-indexed size based on face count
281
+ var estimatedNonIndexedVertices = faceCount * 3; // Each face has 3 vertices
282
+
283
+ // Position: 3 floats per vertex
284
+ nonIndexedBytes += estimatedNonIndexedVertices * 3 * 4;
285
+
286
+ // Normals: 3 floats per vertex (if present)
287
+ if (geometry.attributes.normal) {
288
+ nonIndexedBytes += estimatedNonIndexedVertices * 3 * 4;
289
+ }
290
+
291
+ // UVs: 2 floats per vertex (if present)
292
+ if (geometry.attributes.uv) {
293
+ nonIndexedBytes += estimatedNonIndexedVertices * 2 * 4;
294
+ }
295
+ nonIndexedSizeKB = (nonIndexedBytes / 1024).toFixed(2);
296
+ memoryReduction = ((nonIndexedBytes - indexedBytes) / nonIndexedBytes * 100).toFixed(1);
297
+ compressionRatio = (nonIndexedBytes / indexedBytes).toFixed(2);
298
+ }
299
+ var stats = {
300
+ modelKey: modelKey,
301
+ vertexCount: vertexCount,
302
+ faceCount: faceCount,
303
+ // Indexed geometry stats
304
+ indexedBytes: indexedBytes,
305
+ indexedSizeKB: parseFloat(indexedSizeKB),
306
+ // Non-indexed geometry stats (for comparison)
307
+ nonIndexedBytes: nonIndexedBytes,
308
+ nonIndexedSizeKB: parseFloat(nonIndexedSizeKB),
309
+ // Compression metrics
310
+ memoryReduction: parseFloat(memoryReduction),
311
+ // Percentage reduction
312
+ compressionRatio: parseFloat(compressionRatio),
313
+ // How many times smaller
314
+ // Legacy compatibility
315
+ totalBytes: indexedBytes,
316
+ // Keep for backward compatibility
317
+ sizeKB: parseFloat(indexedSizeKB),
318
+ // Keep for backward compatibility
319
+ // Features
320
+ indexed: !!geometry.index,
321
+ hasNormals: !!geometry.attributes.normal,
322
+ hasUVs: !!geometry.attributes.uv,
323
+ timestamp: Date.now()
324
+ };
325
+
326
+ // Cache the size info
327
+ this.geometrySizeCache.set(modelKey, stats);
328
+ return stats;
329
+ }
330
+
331
+ /**
332
+ * Serialize geometry for storage
333
+ * @param {THREE.BufferGeometry} geometry - The geometry to serialize
334
+ * @param {string} modelKey - The model key
335
+ * @param {Object} stats - The geometry statistics
336
+ * @returns {Object} Serializable geometry data
337
+ */
338
+ }, {
339
+ key: "serializeGeometry",
340
+ value: function serializeGeometry(geometry, modelKey, stats) {
341
+ var data = {
342
+ modelKey: modelKey,
343
+ modelType: 'obj',
344
+ stats: stats,
345
+ attributes: {}
346
+ };
347
+
348
+ // Serialize position attribute
349
+ if (geometry.attributes.position) {
350
+ data.attributes.position = {
351
+ array: Array.from(geometry.attributes.position.array),
352
+ itemSize: geometry.attributes.position.itemSize,
353
+ normalized: geometry.attributes.position.normalized
354
+ };
355
+ }
356
+
357
+ // Serialize normal attribute
358
+ if (geometry.attributes.normal) {
359
+ data.attributes.normal = {
360
+ array: Array.from(geometry.attributes.normal.array),
361
+ itemSize: geometry.attributes.normal.itemSize,
362
+ normalized: geometry.attributes.normal.normalized
363
+ };
364
+ }
365
+
366
+ // Serialize UV attribute
367
+ if (geometry.attributes.uv) {
368
+ data.attributes.uv = {
369
+ array: Array.from(geometry.attributes.uv.array),
370
+ itemSize: geometry.attributes.uv.itemSize,
371
+ normalized: geometry.attributes.uv.normalized
372
+ };
373
+ }
374
+
375
+ // Serialize index
376
+ if (geometry.index) {
377
+ data.index = {
378
+ array: Array.from(geometry.index.array),
379
+ itemSize: 1
380
+ };
381
+ }
382
+ return data;
383
+ }
384
+
385
+ /**
386
+ * Deserialize geometry data back to BufferGeometry
387
+ * @param {Object} geometryData - The serialized geometry data
388
+ * @returns {THREE.BufferGeometry} The reconstructed geometry
389
+ */
390
+ }, {
391
+ key: "deserializeGeometry",
392
+ value: function deserializeGeometry(geometryData) {
393
+ var geometry = new THREE__namespace.BufferGeometry();
394
+
395
+ // Restore attributes
396
+ Object.keys(geometryData.attributes).forEach(function (attributeName) {
397
+ var attrData = geometryData.attributes[attributeName];
398
+ var array = new Float32Array(attrData.array);
399
+ var attribute = new THREE__namespace.BufferAttribute(array, attrData.itemSize, attrData.normalized);
400
+ geometry.setAttribute(attributeName, attribute);
401
+ });
402
+
403
+ // Restore index if present
404
+ if (geometryData.index) {
405
+ var indexArray = new Uint32Array(geometryData.index.array);
406
+ geometry.setIndex(new THREE__namespace.BufferAttribute(indexArray, 1));
407
+ }
408
+ return geometry;
409
+ }
410
+
411
+ /**
412
+ * Store indexed geometry in IndexedDB
413
+ * @param {Object} geometryData - The serialized geometry data
414
+ * @returns {Promise} Promise that resolves when stored
415
+ */
416
+ }, {
417
+ key: "storeGeometryInIDB",
418
+ value: (function () {
419
+ var _storeGeometryInIDB = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2(geometryData) {
420
+ var _this3 = this;
421
+ var db, _t;
422
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
423
+ while (1) switch (_context2.n) {
424
+ case 0:
425
+ if (this.idbSupported) {
426
+ _context2.n = 1;
427
+ break;
428
+ }
429
+ console.warn('โš ๏ธ IndexedDB not supported, skipping storage');
430
+ return _context2.a(2);
431
+ case 1:
432
+ _context2.p = 1;
433
+ _context2.n = 2;
434
+ return this.initializeIDB();
435
+ case 2:
436
+ db = _context2.v;
437
+ return _context2.a(2, new Promise(function (resolve, reject) {
438
+ var transaction = db.transaction([_this3.storeName], 'readwrite');
439
+ var store = transaction.objectStore(_this3.storeName);
440
+ var request = store.put(geometryData);
441
+ request.onsuccess = function () {
442
+ console.log("\uD83D\uDCBE Stored geometry in IndexedDB: ".concat(geometryData.modelKey));
443
+ resolve();
444
+ };
445
+ request.onerror = function () {
446
+ console.error("\u274C Failed to store geometry: ".concat(geometryData.modelKey));
447
+ reject(request.error);
448
+ };
449
+ }));
450
+ case 3:
451
+ _context2.p = 3;
452
+ _t = _context2.v;
453
+ console.error('โŒ Error storing geometry in IndexedDB:', _t);
454
+ throw _t;
455
+ case 4:
456
+ return _context2.a(2);
457
+ }
458
+ }, _callee2, this, [[1, 3]]);
459
+ }));
460
+ function storeGeometryInIDB(_x) {
461
+ return _storeGeometryInIDB.apply(this, arguments);
462
+ }
463
+ return storeGeometryInIDB;
464
+ }()
465
+ /**
466
+ * Load indexed geometry from IndexedDB
467
+ * @param {string} modelKey - The model key to load
468
+ * @returns {Promise<Object>} Promise that resolves to geometry data
469
+ */
470
+ )
471
+ }, {
472
+ key: "loadGeometryFromIDB",
473
+ value: (function () {
474
+ var _loadGeometryFromIDB = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee3(modelKey) {
475
+ var _this4 = this;
476
+ var db, _t2;
477
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context3) {
478
+ while (1) switch (_context3.n) {
479
+ case 0:
480
+ if (this.idbSupported) {
481
+ _context3.n = 1;
482
+ break;
483
+ }
484
+ console.warn('โš ๏ธ IndexedDB not supported, cannot load');
485
+ return _context3.a(2, null);
486
+ case 1:
487
+ _context3.p = 1;
488
+ _context3.n = 2;
489
+ return this.initializeIDB();
490
+ case 2:
491
+ db = _context3.v;
492
+ return _context3.a(2, new Promise(function (resolve, reject) {
493
+ var transaction = db.transaction([_this4.storeName], 'readonly');
494
+ var store = transaction.objectStore(_this4.storeName);
495
+ var request = store.get(modelKey);
496
+ request.onsuccess = function () {
497
+ if (request.result) {
498
+ console.log("\uD83D\uDCE6 Loaded geometry from IndexedDB: ".concat(modelKey));
499
+ resolve(request.result);
500
+ } else {
501
+ console.log("\uD83D\uDCED No geometry found in IndexedDB: ".concat(modelKey));
502
+ resolve(null);
503
+ }
504
+ };
505
+ request.onerror = function () {
506
+ console.error("\u274C Failed to load geometry: ".concat(modelKey));
507
+ reject(request.error);
508
+ };
509
+ }));
510
+ case 3:
511
+ _context3.p = 3;
512
+ _t2 = _context3.v;
513
+ console.error('โŒ Error loading geometry from IndexedDB:', _t2);
514
+ throw _t2;
515
+ case 4:
516
+ return _context3.a(2);
517
+ }
518
+ }, _callee3, this, [[1, 3]]);
519
+ }));
520
+ function loadGeometryFromIDB(_x2) {
521
+ return _loadGeometryFromIDB.apply(this, arguments);
522
+ }
523
+ return loadGeometryFromIDB;
524
+ }()
525
+ /**
526
+ * Create a custom mesh from indexed geometry
527
+ * @param {string} modelKey - The model key
528
+ * @param {THREE.Material} material - Optional material to use
529
+ * @returns {THREE.Mesh|null} The created mesh or null if not found
530
+ */
531
+ )
532
+ }, {
533
+ key: "createCustomMesh",
534
+ value: function createCustomMesh(modelKey) {
535
+ var material = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
536
+ if (this.indexedGeometryCache.has(modelKey)) {
537
+ var cachedData = this.indexedGeometryCache.get(modelKey);
538
+ var geometry = cachedData.geometry.clone();
539
+ var defaultMaterial = new THREE__namespace.MeshStandardMaterial({
540
+ color: 0x888888,
541
+ side: THREE__namespace.DoubleSide,
542
+ wireframe: false
543
+ });
544
+ var mesh = new THREE__namespace.Mesh(geometry, material || defaultMaterial);
545
+ mesh.userData.modelKey = modelKey;
546
+ mesh.userData.stats = cachedData.stats;
547
+ mesh.userData.isCustomGeometry = true;
548
+ console.log("\uD83C\uDFAF Created custom mesh from indexed geometry: ".concat(modelKey));
549
+ return mesh;
550
+ }
551
+ console.warn("\u26A0\uFE0F Indexed geometry not found in cache: ".concat(modelKey));
552
+ return null;
553
+ }
554
+
555
+ /**
556
+ * Process an OBJ object and store the result
557
+ * @param {THREE.Object3D} objObject - The loaded OBJ object
558
+ * @param {string} modelKey - The model key
559
+ * @param {boolean} storeInIDB - Whether to store in IndexedDB
560
+ * @returns {Promise<Object>} Promise that resolves to the processed result
561
+ */
562
+ }, {
563
+ key: "processObjObject",
564
+ value: (function () {
565
+ var _processObjObject = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee4(objObject, modelKey) {
566
+ var storeInIDB,
567
+ result,
568
+ _args4 = arguments,
569
+ _t3;
570
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context4) {
571
+ while (1) switch (_context4.n) {
572
+ case 0:
573
+ storeInIDB = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : true;
574
+ _context4.p = 1;
575
+ // Convert to indexed BufferGeometry
576
+ result = this.objToIndexedBufferGeometry(objObject, modelKey);
577
+ if (result) {
578
+ _context4.n = 2;
579
+ break;
580
+ }
581
+ throw new Error("Failed to convert OBJ to indexed geometry: ".concat(modelKey));
582
+ case 2:
583
+ // Cache the result
584
+ this.indexedGeometryCache.set(modelKey, result);
585
+
586
+ // Store in IndexedDB if requested
587
+ if (!(storeInIDB && result.geometryData)) {
588
+ _context4.n = 3;
589
+ break;
590
+ }
591
+ _context4.n = 3;
592
+ return this.storeGeometryInIDB(result.geometryData);
593
+ case 3:
594
+ console.log("\u2705 Successfully processed OBJ: ".concat(modelKey));
595
+ return _context4.a(2, result);
596
+ case 4:
597
+ _context4.p = 4;
598
+ _t3 = _context4.v;
599
+ console.error("\u274C Error processing OBJ: ".concat(modelKey), _t3);
600
+ throw _t3;
601
+ case 5:
602
+ return _context4.a(2);
603
+ }
604
+ }, _callee4, this, [[1, 4]]);
605
+ }));
606
+ function processObjObject(_x3, _x4) {
607
+ return _processObjObject.apply(this, arguments);
608
+ }
609
+ return processObjObject;
610
+ }()
611
+ /**
612
+ * Get all processed geometry statistics
613
+ * @returns {Array} Array of geometry statistics
614
+ */
615
+ )
616
+ }, {
617
+ key: "getAllGeometryStats",
618
+ value: function getAllGeometryStats() {
619
+ var stats = [];
620
+ this.geometrySizeCache.forEach(function (stat, modelKey) {
621
+ stats.push(stat);
622
+ });
623
+ return stats.sort(function (a, b) {
624
+ return b.sizeKB - a.sizeKB;
625
+ }); // Sort by size descending
626
+ }
627
+
628
+ /**
629
+ * Get total memory usage of cached geometries
630
+ * @returns {Object} Memory usage statistics
631
+ */
632
+ }, {
633
+ key: "getMemoryUsage",
634
+ value: function getMemoryUsage() {
635
+ var totalIndexedBytes = 0;
636
+ var totalNonIndexedBytes = 0;
637
+ var totalGeometries = 0;
638
+ this.geometrySizeCache.forEach(function (stats) {
639
+ totalIndexedBytes += stats.indexedBytes;
640
+ totalNonIndexedBytes += stats.nonIndexedBytes;
641
+ totalGeometries++;
642
+ });
643
+ var totalMemoryReduction = totalNonIndexedBytes > 0 ? ((totalNonIndexedBytes - totalIndexedBytes) / totalNonIndexedBytes * 100).toFixed(1) : 0;
644
+ var totalCompressionRatio = totalIndexedBytes > 0 ? (totalNonIndexedBytes / totalIndexedBytes).toFixed(2) : 1;
645
+ return {
646
+ totalGeometries: totalGeometries,
647
+ // Indexed geometry stats
648
+ indexedBytes: totalIndexedBytes,
649
+ indexedKB: (totalIndexedBytes / 1024).toFixed(2),
650
+ indexedMB: (totalIndexedBytes / (1024 * 1024)).toFixed(3),
651
+ // Non-indexed geometry stats
652
+ nonIndexedBytes: totalNonIndexedBytes,
653
+ nonIndexedKB: (totalNonIndexedBytes / 1024).toFixed(2),
654
+ nonIndexedMB: (totalNonIndexedBytes / (1024 * 1024)).toFixed(3),
655
+ // Compression stats
656
+ memoryReduction: parseFloat(totalMemoryReduction),
657
+ compressionRatio: parseFloat(totalCompressionRatio),
658
+ // Legacy compatibility
659
+ totalBytes: totalIndexedBytes,
660
+ totalKB: (totalIndexedBytes / 1024).toFixed(2),
661
+ totalMB: (totalIndexedBytes / (1024 * 1024)).toFixed(2)
662
+ };
663
+ }
664
+
665
+ /**
666
+ * Clear all caches
667
+ */
668
+ }, {
669
+ key: "clearCaches",
670
+ value: function clearCaches() {
671
+ console.log('๐Ÿงน Clearing OBJ processor caches...');
672
+
673
+ // Dispose of cached geometries
674
+ this.indexedGeometryCache.forEach(function (data, modelKey) {
675
+ if (data.geometry) {
676
+ data.geometry.dispose();
677
+ }
678
+ console.log("\uD83D\uDDD1\uFE0F Disposed cached geometry: ".concat(modelKey));
679
+ });
680
+ this.indexedGeometryCache.clear();
681
+ this.geometrySizeCache.clear();
682
+ console.log('โœ… OBJ processor caches cleared');
683
+ }
684
+
685
+ /**
686
+ * Get processing status
687
+ * @returns {Object} Status information
688
+ */
689
+ }, {
690
+ key: "getStatus",
691
+ value: function getStatus() {
692
+ return {
693
+ cachedGeometries: Array.from(this.indexedGeometryCache.keys()),
694
+ totalCached: this.indexedGeometryCache.size,
695
+ idbSupported: this.idbSupported,
696
+ memoryUsage: this.getMemoryUsage()
697
+ };
698
+ }
699
+ }]);
700
+ }(); // Export the class
701
+
702
+ exports.ObjProcessor = ObjProcessor;
703
+ exports["default"] = ObjProcessor;