@2112-lab/central-plant 0.1.6 โ†’ 0.1.7

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,824 @@
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
+
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n["default"] = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
27
+
28
+ var SceneViewer = /*#__PURE__*/function () {
29
+ /**
30
+ * Initialize the SceneViewer
31
+ * @param {HTMLElement} container - DOM element to render the scene
32
+ * @param {Object} options - Configuration options
33
+ * @param {Object} centralPlant - CentralPlant instance for managers
34
+ */
35
+ function SceneViewer(container) {
36
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
37
+ var centralPlant = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
38
+ _rollupPluginBabelHelpers.classCallCheck(this, SceneViewer);
39
+ // Core properties
40
+ this.container = container;
41
+ this.centralPlant = centralPlant;
42
+ this.options = _rollupPluginBabelHelpers.objectSpread2({
43
+ enableAutoRotation: false,
44
+ enableShadows: true,
45
+ enableBloom: true,
46
+ enableSSAO: false,
47
+ antialias: true,
48
+ pixelRatio: Math.min(window.devicePixelRatio, 2)
49
+ }, options);
50
+
51
+ // Instance tracking for hot-reload handling
52
+ this.instanceId = Date.now() + Math.random();
53
+
54
+ // Core Three.js objects
55
+ this.scene = null;
56
+ this.camera = null;
57
+ this.renderer = null;
58
+ this.controls = null;
59
+ this.composer = null;
60
+ this.bloomPass = null;
61
+ this.ssaoPass = null;
62
+
63
+ // Utilities
64
+ this.textureLoader = null;
65
+ this.gltfLoader = null;
66
+ this.envMap = null;
67
+ this.performanceMonitor = null;
68
+ this.resizeObserver = null;
69
+
70
+ // Scene data
71
+ this.currentSceneData = null;
72
+
73
+ // State flags
74
+ this.isDestroyed = false;
75
+ this.isInitialized = false;
76
+
77
+ // Transform controls
78
+ this.transformManager = null;
79
+ this.selectedObjectForTransform = null;
80
+ this.transformMode = 'translate';
81
+ this.transformSpace = 'world';
82
+ this.transformHistory = [];
83
+ this.previousTransformValues = null;
84
+
85
+ // Manager instances (will be attached from centralPlant)
86
+ this.managers = {};
87
+
88
+ // Event system for communication with external systems
89
+ this.eventCallbacks = new Map();
90
+
91
+ // Drag and drop state
92
+ this.isDragOver = false;
93
+ this.dragDropManager = null;
94
+
95
+ // Scene helper utility
96
+ this.sceneHelper = null;
97
+
98
+ // Pathfinder version cache
99
+ this.pathfinderVersionInfo = null;
100
+
101
+ // Transform settings
102
+ this.shouldUpdatePaths = true;
103
+
104
+ // Initialize the scene viewer
105
+ this.init();
106
+ }
107
+
108
+ /**
109
+ * Initialize the Three.js scene and all components
110
+ */
111
+ return _rollupPluginBabelHelpers.createClass(SceneViewer, [{
112
+ key: "init",
113
+ value: (function () {
114
+ var _init = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee() {
115
+ var _t;
116
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
117
+ while (1) switch (_context.n) {
118
+ case 0:
119
+ _context.p = 0;
120
+ console.log('๐Ÿš€ Initializing SceneViewer...', {
121
+ instanceId: this.instanceId,
122
+ containerSize: {
123
+ width: this.container.clientWidth,
124
+ height: this.container.clientHeight
125
+ }
126
+ });
127
+
128
+ // Attach managers from centralPlant if available
129
+ if (this.centralPlant) {
130
+ this.attachManagers();
131
+ }
132
+
133
+ // Initialize Three.js components
134
+ this.initScene();
135
+ this.initCamera();
136
+ this.initRenderer();
137
+ this.initLights();
138
+ this.initControls();
139
+ this.initPostProcessing();
140
+ this.initEventListeners();
141
+
142
+ // Initialize managers that require scene to be ready
143
+ _context.n = 1;
144
+ return this.initializeSceneManagers();
145
+ case 1:
146
+ // Start the animation loop
147
+ this.animate();
148
+ this.isInitialized = true;
149
+ this.emit('initialized', {
150
+ sceneViewer: this
151
+ });
152
+ console.log('โœ… SceneViewer initialization completed');
153
+ _context.n = 3;
154
+ break;
155
+ case 2:
156
+ _context.p = 2;
157
+ _t = _context.v;
158
+ console.error('โŒ Error initializing SceneViewer:', _t);
159
+ this.emit('error', {
160
+ error: _t,
161
+ phase: 'initialization'
162
+ });
163
+ case 3:
164
+ return _context.a(2);
165
+ }
166
+ }, _callee, this, [[0, 2]]);
167
+ }));
168
+ function init() {
169
+ return _init.apply(this, arguments);
170
+ }
171
+ return init;
172
+ }()
173
+ /**
174
+ * Attach managers from centralPlant
175
+ */
176
+ )
177
+ }, {
178
+ key: "attachManagers",
179
+ value: function attachManagers() {
180
+ var _this = this;
181
+ if (!this.centralPlant) return;
182
+
183
+ // Get all managers from centralPlant
184
+ var managers = this.centralPlant.getAllManagers();
185
+
186
+ // Attach each manager to this instance
187
+ Object.entries(managers).forEach(function (_ref) {
188
+ var _ref2 = _rollupPluginBabelHelpers.slicedToArray(_ref, 2),
189
+ key = _ref2[0],
190
+ manager = _ref2[1];
191
+ _this[key] = manager;
192
+ _this.managers[key] = manager;
193
+ });
194
+
195
+ // Also attach utilities
196
+ var utilities = this.centralPlant.getAllUtilities();
197
+ Object.entries(utilities).forEach(function (_ref3) {
198
+ var _ref4 = _rollupPluginBabelHelpers.slicedToArray(_ref3, 2),
199
+ key = _ref4[0],
200
+ utility = _ref4[1];
201
+ _this[key] = utility;
202
+ });
203
+ console.log('๐Ÿ“ฆ Managers attached to SceneViewer:', Object.keys(managers));
204
+ }
205
+
206
+ /**
207
+ * Initialize Three.js scene
208
+ */
209
+ }, {
210
+ key: "initScene",
211
+ value: function initScene() {
212
+ this.scene = new THREE__namespace.Scene();
213
+ this.scene.name = 'MainScene';
214
+
215
+ // Set background
216
+ this.scene.background = new THREE__namespace.Color(0x87CEEB); // Sky blue
217
+
218
+ console.log('๐ŸŒ Scene initialized');
219
+ }
220
+
221
+ /**
222
+ * Initialize camera
223
+ */
224
+ }, {
225
+ key: "initCamera",
226
+ value: function initCamera() {
227
+ var aspect = this.container.clientWidth / this.container.clientHeight;
228
+ this.camera = new THREE__namespace.PerspectiveCamera(75, aspect, 0.1, 1000);
229
+ this.camera.position.set(5, 5, 5);
230
+ this.camera.lookAt(0, 0, 0);
231
+ console.log('๐Ÿ“ท Camera initialized');
232
+ }
233
+
234
+ /**
235
+ * Initialize renderer
236
+ */
237
+ }, {
238
+ key: "initRenderer",
239
+ value: function initRenderer() {
240
+ this.renderer = new THREE__namespace.WebGLRenderer({
241
+ antialias: this.options.antialias,
242
+ powerPreference: 'high-performance'
243
+ });
244
+ this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
245
+ this.renderer.setPixelRatio(this.options.pixelRatio);
246
+ this.renderer.shadowMap.enabled = this.options.enableShadows;
247
+ this.renderer.shadowMap.type = THREE__namespace.PCFSoftShadowMap;
248
+ this.renderer.outputColorSpace = THREE__namespace.SRGBColorSpace;
249
+ this.renderer.toneMapping = THREE__namespace.ACESFilmicToneMapping;
250
+ this.renderer.toneMappingExposure = 1;
251
+
252
+ // Append renderer to container
253
+ this.container.appendChild(this.renderer.domElement);
254
+ console.log('๐ŸŽจ Renderer initialized');
255
+ }
256
+
257
+ /**
258
+ * Initialize lighting
259
+ */
260
+ }, {
261
+ key: "initLights",
262
+ value: function initLights() {
263
+ // Ambient light
264
+ var ambientLight = new THREE__namespace.AmbientLight(0x404040, 0.4);
265
+ this.scene.add(ambientLight);
266
+
267
+ // Directional light
268
+ var directionalLight = new THREE__namespace.DirectionalLight(0xffffff, 1);
269
+ directionalLight.position.set(10, 10, 5);
270
+ directionalLight.castShadow = this.options.enableShadows;
271
+ if (this.options.enableShadows) {
272
+ directionalLight.shadow.mapSize.width = 2048;
273
+ directionalLight.shadow.mapSize.height = 2048;
274
+ directionalLight.shadow.camera.near = 0.5;
275
+ directionalLight.shadow.camera.far = 500;
276
+ }
277
+ this.scene.add(directionalLight);
278
+ console.log('๐Ÿ’ก Lights initialized');
279
+ }
280
+
281
+ /**
282
+ * Initialize controls (if available)
283
+ */
284
+ }, {
285
+ key: "initControls",
286
+ value: function initControls() {
287
+ // Controls will be initialized by the camera controls manager
288
+ // This is just a placeholder for the base setup
289
+ console.log('๐ŸŽฎ Controls setup ready');
290
+ }
291
+
292
+ /**
293
+ * Initialize post-processing effects
294
+ */
295
+ }, {
296
+ key: "initPostProcessing",
297
+ value: function initPostProcessing() {
298
+ // Post-processing will be handled by managers
299
+ // This is just a placeholder
300
+ console.log('โœจ Post-processing setup ready');
301
+ }
302
+
303
+ /**
304
+ * Initialize event listeners
305
+ */
306
+ }, {
307
+ key: "initEventListeners",
308
+ value: function initEventListeners() {
309
+ var _this2 = this;
310
+ // Resize observer
311
+ this.resizeObserver = new ResizeObserver(function (entries) {
312
+ var _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(entries),
313
+ _step;
314
+ try {
315
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
316
+ var entry = _step.value;
317
+ _this2.handleResize();
318
+ }
319
+ } catch (err) {
320
+ _iterator.e(err);
321
+ } finally {
322
+ _iterator.f();
323
+ }
324
+ });
325
+ this.resizeObserver.observe(this.container);
326
+
327
+ // Mouse events for selection
328
+ this.container.addEventListener('click', this.handleClick.bind(this));
329
+ this.container.addEventListener('dblclick', this.handleDoubleClick.bind(this));
330
+
331
+ // Drag and drop events
332
+ this.container.addEventListener('dragover', this.handleDragOver.bind(this));
333
+ this.container.addEventListener('drop', this.handleDrop.bind(this));
334
+ this.container.addEventListener('dragenter', this.handleDragEnter.bind(this));
335
+ this.container.addEventListener('dragleave', this.handleDragLeave.bind(this));
336
+ console.log('๐Ÿ‘‚ Event listeners initialized');
337
+ }
338
+
339
+ /**
340
+ * Initialize scene managers that require the scene to be ready
341
+ */
342
+ }, {
343
+ key: "initializeSceneManagers",
344
+ value: (function () {
345
+ var _initializeSceneManagers = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2() {
346
+ var _t2;
347
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
348
+ while (1) switch (_context2.n) {
349
+ case 0:
350
+ _context2.p = 0;
351
+ if (!this.sceneInitializationManager) {
352
+ _context2.n = 1;
353
+ break;
354
+ }
355
+ _context2.n = 1;
356
+ return this.sceneInitializationManager.initializeScene();
357
+ case 1:
358
+ if (!this.environmentManager) {
359
+ _context2.n = 2;
360
+ break;
361
+ }
362
+ _context2.n = 2;
363
+ return this.environmentManager.initializeEnvironment();
364
+ case 2:
365
+ // Initialize other managers as needed
366
+ console.log('๐Ÿ—๏ธ Scene managers initialized');
367
+ _context2.n = 4;
368
+ break;
369
+ case 3:
370
+ _context2.p = 3;
371
+ _t2 = _context2.v;
372
+ console.error('โŒ Error initializing scene managers:', _t2);
373
+ case 4:
374
+ return _context2.a(2);
375
+ }
376
+ }, _callee2, this, [[0, 3]]);
377
+ }));
378
+ function initializeSceneManagers() {
379
+ return _initializeSceneManagers.apply(this, arguments);
380
+ }
381
+ return initializeSceneManagers;
382
+ }()
383
+ /**
384
+ * Main animation loop
385
+ */
386
+ )
387
+ }, {
388
+ key: "animate",
389
+ value: function animate() {
390
+ var _this3 = this;
391
+ if (this.isDestroyed) return;
392
+ requestAnimationFrame(function () {
393
+ return _this3.animate();
394
+ });
395
+ try {
396
+ // Update controls
397
+ if (this.controls && this.controls.update) {
398
+ this.controls.update();
399
+ }
400
+
401
+ // Update camera controls manager
402
+ if (this.cameraControlsManager) {
403
+ this.cameraControlsManager.update();
404
+ }
405
+
406
+ // Update animation manager
407
+ if (this.animationManager) {
408
+ this.animationManager.update();
409
+ }
410
+
411
+ // Update performance monitor
412
+ if (this.performanceMonitor) {
413
+ this.performanceMonitor.begin();
414
+ }
415
+
416
+ // Render the scene
417
+ if (this.composer) {
418
+ this.composer.render();
419
+ } else {
420
+ this.renderer.render(this.scene, this.camera);
421
+ }
422
+
423
+ // End performance monitoring
424
+ if (this.performanceMonitor) {
425
+ this.performanceMonitor.end();
426
+ }
427
+ } catch (error) {
428
+ console.error('โŒ Error in animation loop:', error);
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Handle window/container resize
434
+ */
435
+ }, {
436
+ key: "handleResize",
437
+ value: function handleResize() {
438
+ if (!this.camera || !this.renderer) return;
439
+ var width = this.container.clientWidth;
440
+ var height = this.container.clientHeight;
441
+
442
+ // Update camera
443
+ this.camera.aspect = width / height;
444
+ this.camera.updateProjectionMatrix();
445
+
446
+ // Update renderer
447
+ this.renderer.setSize(width, height);
448
+
449
+ // Update composer if available
450
+ if (this.composer) {
451
+ this.composer.setSize(width, height);
452
+ }
453
+ this.emit('resize', {
454
+ width: width,
455
+ height: height
456
+ });
457
+ }
458
+
459
+ /**
460
+ * Handle click events
461
+ */
462
+ }, {
463
+ key: "handleClick",
464
+ value: function handleClick(event) {
465
+ if (!this.camera || !this.scene) return;
466
+ var rect = this.container.getBoundingClientRect();
467
+ var mouse = new THREE__namespace.Vector2();
468
+ mouse.x = (event.clientX - rect.left) / rect.width * 2 - 1;
469
+ mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
470
+ var raycaster = new THREE__namespace.Raycaster();
471
+ raycaster.setFromCamera(mouse, this.camera);
472
+ var intersects = raycaster.intersectObjects(this.scene.children, true);
473
+ if (intersects.length > 0) {
474
+ var object = intersects[0].object;
475
+ this.selectObject(object);
476
+ } else {
477
+ this.selectObject(null);
478
+ }
479
+ }
480
+
481
+ /**
482
+ * Handle double click events
483
+ */
484
+ }, {
485
+ key: "handleDoubleClick",
486
+ value: function handleDoubleClick(event) {
487
+ // Handle double click actions
488
+ this.emit('doubleClick', {
489
+ event: event
490
+ });
491
+ }
492
+
493
+ /**
494
+ * Handle drag over events
495
+ */
496
+ }, {
497
+ key: "handleDragOver",
498
+ value: function handleDragOver(event) {
499
+ event.preventDefault();
500
+ this.isDragOver = true;
501
+ this.emit('dragOver', {
502
+ event: event
503
+ });
504
+ }
505
+
506
+ /**
507
+ * Handle drop events
508
+ */
509
+ }, {
510
+ key: "handleDrop",
511
+ value: function handleDrop(event) {
512
+ event.preventDefault();
513
+ this.isDragOver = false;
514
+ try {
515
+ var dataTransfer = event.dataTransfer.getData('text/plain');
516
+ if (dataTransfer) {
517
+ var componentData = JSON.parse(dataTransfer);
518
+
519
+ // Calculate drop position
520
+ var rect = this.container.getBoundingClientRect();
521
+ var mouse = new THREE__namespace.Vector2();
522
+ mouse.x = (event.clientX - rect.left) / rect.width * 2 - 1;
523
+ mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
524
+ var raycaster = new THREE__namespace.Raycaster();
525
+ raycaster.setFromCamera(mouse, this.camera);
526
+
527
+ // Cast ray to ground plane (y = 0)
528
+ var groundPlane = new THREE__namespace.Plane(new THREE__namespace.Vector3(0, 1, 0), 0);
529
+ var dropPosition = new THREE__namespace.Vector3();
530
+ raycaster.ray.intersectPlane(groundPlane, dropPosition);
531
+ this.emit('componentDropped', {
532
+ componentData: componentData,
533
+ position: dropPosition,
534
+ event: event
535
+ });
536
+ }
537
+ } catch (error) {
538
+ console.error('โŒ Error handling drop:', error);
539
+ this.emit('dropError', {
540
+ error: error,
541
+ event: event
542
+ });
543
+ }
544
+ }
545
+
546
+ /**
547
+ * Handle drag enter events
548
+ */
549
+ }, {
550
+ key: "handleDragEnter",
551
+ value: function handleDragEnter(event) {
552
+ event.preventDefault();
553
+ this.emit('dragEnter', {
554
+ event: event
555
+ });
556
+ }
557
+
558
+ /**
559
+ * Handle drag leave events
560
+ */
561
+ }, {
562
+ key: "handleDragLeave",
563
+ value: function handleDragLeave(event) {
564
+ this.isDragOver = false;
565
+ this.emit('dragLeave', {
566
+ event: event
567
+ });
568
+ }
569
+
570
+ /**
571
+ * Select an object in the scene
572
+ */
573
+ }, {
574
+ key: "selectObject",
575
+ value: function selectObject(object) {
576
+ // Clear previous selection
577
+ if (this.selectedObjectForTransform) {
578
+ // Remove selection indicators
579
+ this.clearObjectSelection(this.selectedObjectForTransform);
580
+ }
581
+ this.selectedObjectForTransform = object;
582
+ if (object) {
583
+ // Add selection indicators
584
+ this.highlightSelectedObject(object);
585
+
586
+ // Initialize transform controls if available
587
+ if (this.transformManager) {
588
+ this.transformManager.attachToObject(object);
589
+ }
590
+ } else {
591
+ // Clear transform controls
592
+ if (this.transformManager) {
593
+ this.transformManager.detach();
594
+ }
595
+ }
596
+ this.emit('objectSelected', {
597
+ object: object
598
+ });
599
+ }
600
+
601
+ /**
602
+ * Clear object selection visual indicators
603
+ */
604
+ }, {
605
+ key: "clearObjectSelection",
606
+ value: function clearObjectSelection(object) {
607
+ // Remove selection outline or other indicators
608
+ // This would depend on your specific selection visualization
609
+ }
610
+
611
+ /**
612
+ * Highlight selected object
613
+ */
614
+ }, {
615
+ key: "highlightSelectedObject",
616
+ value: function highlightSelectedObject(object) {
617
+ // Add selection outline or other indicators
618
+ // This would depend on your specific selection visualization
619
+ }
620
+
621
+ /**
622
+ * Load a scene from data
623
+ */
624
+ }, {
625
+ key: "loadScene",
626
+ value: (function () {
627
+ var _loadScene = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee3(sceneData) {
628
+ var _t3;
629
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context3) {
630
+ while (1) switch (_context3.n) {
631
+ case 0:
632
+ _context3.p = 0;
633
+ this.currentSceneData = sceneData;
634
+ if (!this.componentManager) {
635
+ _context3.n = 1;
636
+ break;
637
+ }
638
+ _context3.n = 1;
639
+ return this.componentManager.loadSceneFromData(sceneData);
640
+ case 1:
641
+ this.emit('sceneLoaded', {
642
+ sceneData: sceneData
643
+ });
644
+ _context3.n = 3;
645
+ break;
646
+ case 2:
647
+ _context3.p = 2;
648
+ _t3 = _context3.v;
649
+ console.error('โŒ Error loading scene:', _t3);
650
+ this.emit('sceneLoadError', {
651
+ error: _t3,
652
+ sceneData: sceneData
653
+ });
654
+ case 3:
655
+ return _context3.a(2);
656
+ }
657
+ }, _callee3, this, [[0, 2]]);
658
+ }));
659
+ function loadScene(_x) {
660
+ return _loadScene.apply(this, arguments);
661
+ }
662
+ return loadScene;
663
+ }()
664
+ /**
665
+ * Add a component to the scene
666
+ */
667
+ )
668
+ }, {
669
+ key: "addComponentToScene",
670
+ value: function addComponentToScene(componentData) {
671
+ var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE__namespace.Vector3();
672
+ try {
673
+ if (this.componentManager) {
674
+ return this.componentManager.addComponent(componentData, position);
675
+ }
676
+ return false;
677
+ } catch (error) {
678
+ console.error('โŒ Error adding component:', error);
679
+ return false;
680
+ }
681
+ }
682
+
683
+ /**
684
+ * Export scene data
685
+ */
686
+ }, {
687
+ key: "exportScene",
688
+ value: function exportScene() {
689
+ try {
690
+ if (this.sceneExportManager) {
691
+ return this.sceneExportManager.exportScene();
692
+ }
693
+ return null;
694
+ } catch (error) {
695
+ console.error('โŒ Error exporting scene:', error);
696
+ return null;
697
+ }
698
+ }
699
+
700
+ /**
701
+ * Toggle camera auto rotation
702
+ */
703
+ }, {
704
+ key: "toggleCameraRotation",
705
+ value: function toggleCameraRotation() {
706
+ if (this.cameraControlsManager) {
707
+ return this.cameraControlsManager.toggleCameraRotation();
708
+ }
709
+ return false;
710
+ }
711
+
712
+ /**
713
+ * Get selected transform data
714
+ */
715
+ }, {
716
+ key: "getSelectedTransform",
717
+ value: function getSelectedTransform() {
718
+ if (this.transformManager && this.selectedObjectForTransform) {
719
+ return this.transformManager.getTransformData(this.selectedObjectForTransform);
720
+ }
721
+ return null;
722
+ }
723
+
724
+ /**
725
+ * Event system methods
726
+ */
727
+ }, {
728
+ key: "on",
729
+ value: function on(eventName, callback) {
730
+ if (!this.eventCallbacks.has(eventName)) {
731
+ this.eventCallbacks.set(eventName, []);
732
+ }
733
+ this.eventCallbacks.get(eventName).push(callback);
734
+ }
735
+ }, {
736
+ key: "off",
737
+ value: function off(eventName, callback) {
738
+ if (this.eventCallbacks.has(eventName)) {
739
+ var callbacks = this.eventCallbacks.get(eventName);
740
+ var index = callbacks.indexOf(callback);
741
+ if (index > -1) {
742
+ callbacks.splice(index, 1);
743
+ }
744
+ }
745
+ }
746
+ }, {
747
+ key: "emit",
748
+ value: function emit(eventName) {
749
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
750
+ if (this.eventCallbacks.has(eventName)) {
751
+ this.eventCallbacks.get(eventName).forEach(function (callback) {
752
+ try {
753
+ callback(data);
754
+ } catch (error) {
755
+ console.error("\u274C Error in event callback for ".concat(eventName, ":"), error);
756
+ }
757
+ });
758
+ }
759
+ }
760
+
761
+ /**
762
+ * Dispose of the scene viewer and clean up resources
763
+ */
764
+ }, {
765
+ key: "dispose",
766
+ value: function dispose() {
767
+ console.log('๐Ÿงน Disposing SceneViewer...');
768
+ this.isDestroyed = true;
769
+ try {
770
+ // Clean up event listeners
771
+ this.eventCallbacks.clear();
772
+
773
+ // Clean up resize observer
774
+ if (this.resizeObserver) {
775
+ this.resizeObserver.disconnect();
776
+ this.resizeObserver = null;
777
+ }
778
+
779
+ // Clean up DOM event listeners
780
+ if (this.container) {
781
+ this.container.removeEventListener('click', this.handleClick);
782
+ this.container.removeEventListener('dblclick', this.handleDoubleClick);
783
+ this.container.removeEventListener('dragover', this.handleDragOver);
784
+ this.container.removeEventListener('drop', this.handleDrop);
785
+ this.container.removeEventListener('dragenter', this.handleDragEnter);
786
+ this.container.removeEventListener('dragleave', this.handleDragLeave);
787
+ }
788
+
789
+ // Dispose of managers using disposal manager
790
+ if (this.disposalManager) {
791
+ this.disposalManager.cleanupEventListeners();
792
+ this.disposalManager.cleanupPerformanceMonitoring();
793
+ this.disposalManager.cleanupControls();
794
+ this.disposalManager.cleanupScene();
795
+ this.disposalManager.cleanupRenderer();
796
+ }
797
+
798
+ // Remove renderer from DOM
799
+ if (this.renderer && this.renderer.domElement && this.container) {
800
+ this.container.removeChild(this.renderer.domElement);
801
+ }
802
+
803
+ // Dispose of renderer
804
+ if (this.renderer) {
805
+ this.renderer.dispose();
806
+ this.renderer = null;
807
+ }
808
+
809
+ // Clear references
810
+ this.scene = null;
811
+ this.camera = null;
812
+ this.controls = null;
813
+ this.currentSceneData = null;
814
+ this.selectedObjectForTransform = null;
815
+ console.log('โœ… SceneViewer disposed successfully');
816
+ } catch (error) {
817
+ console.error('โŒ Error during SceneViewer disposal:', error);
818
+ }
819
+ }
820
+ }]);
821
+ }();
822
+
823
+ exports.SceneViewer = SceneViewer;
824
+ exports["default"] = SceneViewer;