@2112-lab/central-plant 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/index.js +33146 -1
- package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
- package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
- package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
- package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
- package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
- package/dist/cjs/src/analysis/analysis.js +560 -1
- package/dist/cjs/src/analysis/testing.js +958 -1
- package/dist/cjs/src/core/centralPlant.js +1149 -1
- package/dist/cjs/src/core/debugLogger.js +175 -1
- package/dist/cjs/src/core/mathUtils.js +574 -1
- package/dist/cjs/src/core/nameUtils.js +93 -1
- package/dist/cjs/src/data/export.js +716 -1
- package/dist/cjs/src/data/import.js +380 -1
- package/dist/cjs/src/data/numerics.js +522 -1
- package/dist/cjs/src/helpers/sceneHelper.js +572 -1
- package/dist/cjs/src/index.js +69 -1
- package/dist/cjs/src/managers/components/animationManager.js +123 -1
- package/dist/cjs/src/managers/components/componentManager.js +332 -1
- package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
- package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
- package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
- package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
- package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
- package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
- package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
- package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
- package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
- package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
- package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
- package/dist/cjs/src/managers/system/disposalManager.js +444 -1
- package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
- package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
- package/dist/cjs/src/rendering/modelPreloader.js +369 -1
- package/dist/cjs/src/rendering/rendering2D.js +631 -1
- package/dist/cjs/src/rendering/rendering3D.js +685 -1
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
- package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
- package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
- package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
- package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
- package/dist/esm/src/analysis/analysis.js +536 -1
- package/dist/esm/src/analysis/testing.js +954 -1
- package/dist/esm/src/core/centralPlant.js +1144 -1
- package/dist/esm/src/core/debugLogger.js +167 -1
- package/dist/esm/src/core/mathUtils.js +570 -1
- package/dist/esm/src/core/nameUtils.js +87 -1
- package/dist/esm/src/data/export.js +712 -1
- package/dist/esm/src/data/import.js +356 -1
- package/dist/esm/src/data/numerics.js +518 -1
- package/dist/esm/src/helpers/sceneHelper.js +547 -1
- package/dist/esm/src/index.js +35 -1
- package/dist/esm/src/managers/components/animationManager.js +119 -1
- package/dist/esm/src/managers/components/componentManager.js +328 -1
- package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
- package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
- package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
- package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
- package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
- package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
- package/dist/esm/src/managers/environment/environmentManager.js +690 -1
- package/dist/esm/src/managers/environment/textureConfig.js +202 -1
- package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
- package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
- package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
- package/dist/esm/src/managers/system/disposalManager.js +440 -1
- package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
- package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
- package/dist/esm/src/rendering/modelPreloader.js +364 -1
- package/dist/esm/src/rendering/rendering2D.js +627 -1
- package/dist/esm/src/rendering/rendering3D.js +661 -1
- package/package.json +1 -1
|
@@ -1 +1,119 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import { createClass as _createClass, classCallCheck as _classCallCheck } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { logger } from '../../core/debugLogger.js';
|
|
3
|
+
|
|
4
|
+
var AnimationManager = /*#__PURE__*/function () {
|
|
5
|
+
function AnimationManager(sceneViewer) {
|
|
6
|
+
_classCallCheck(this, AnimationManager);
|
|
7
|
+
this.sceneViewer = sceneViewer;
|
|
8
|
+
this.lastFrameTime = 0;
|
|
9
|
+
this.targetFPS = 60;
|
|
10
|
+
this.frameInterval = 1000 / this.targetFPS;
|
|
11
|
+
this.animationId = null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Start the animation loop
|
|
16
|
+
*/
|
|
17
|
+
return _createClass(AnimationManager, [{
|
|
18
|
+
key: "startAnimation",
|
|
19
|
+
value: function startAnimation() {
|
|
20
|
+
var _this = this;
|
|
21
|
+
var sceneViewer = this.sceneViewer;
|
|
22
|
+
var _loop = function loop(currentTime) {
|
|
23
|
+
// Check if sceneViewer is destroyed to prevent memory leaks
|
|
24
|
+
if (sceneViewer.isDestroyed) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
_this.animationId = requestAnimationFrame(_loop);
|
|
28
|
+
if (currentTime - _this.lastFrameTime < _this.frameInterval) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
_this.lastFrameTime = currentTime;
|
|
32
|
+
|
|
33
|
+
// Check again before updating in case sceneViewer was destroyed during frame
|
|
34
|
+
if (sceneViewer.isDestroyed || !sceneViewer.controls || !sceneViewer.renderer || !sceneViewer.scene || !sceneViewer.camera) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
_this.updateFrame();
|
|
38
|
+
};
|
|
39
|
+
_loop(0);
|
|
40
|
+
logger.info('Animation loop started');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Update a single frame
|
|
45
|
+
*/
|
|
46
|
+
}, {
|
|
47
|
+
key: "updateFrame",
|
|
48
|
+
value: function updateFrame() {
|
|
49
|
+
var sceneViewer = this.sceneViewer;
|
|
50
|
+
|
|
51
|
+
// Update controls
|
|
52
|
+
sceneViewer.controls.update();
|
|
53
|
+
|
|
54
|
+
// Update performance monitoring
|
|
55
|
+
if (sceneViewer.performanceMonitor) {
|
|
56
|
+
sceneViewer.performanceMonitor.update();
|
|
57
|
+
sceneViewer.performanceMonitor.updateSceneStats(sceneViewer.scene);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Render the scene
|
|
61
|
+
sceneViewer.renderer.render(sceneViewer.scene, sceneViewer.camera);
|
|
62
|
+
|
|
63
|
+
// Render tooltips if tooltipsManager exists
|
|
64
|
+
if (sceneViewer.tooltipsManager) {
|
|
65
|
+
sceneViewer.tooltipsManager.render();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Stop the animation loop
|
|
71
|
+
*/
|
|
72
|
+
}, {
|
|
73
|
+
key: "stopAnimation",
|
|
74
|
+
value: function stopAnimation() {
|
|
75
|
+
if (this.animationId) {
|
|
76
|
+
cancelAnimationFrame(this.animationId);
|
|
77
|
+
this.animationId = null;
|
|
78
|
+
logger.info('Animation loop stopped');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set target FPS for the animation loop
|
|
84
|
+
*/
|
|
85
|
+
}, {
|
|
86
|
+
key: "setTargetFPS",
|
|
87
|
+
value: function setTargetFPS(fps) {
|
|
88
|
+
this.targetFPS = fps;
|
|
89
|
+
this.frameInterval = 1000 / this.targetFPS;
|
|
90
|
+
logger.info("Target FPS set to: ".concat(fps));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get current FPS information
|
|
95
|
+
*/
|
|
96
|
+
}, {
|
|
97
|
+
key: "getCurrentFPS",
|
|
98
|
+
value: function getCurrentFPS() {
|
|
99
|
+
var sceneViewer = this.sceneViewer;
|
|
100
|
+
if (sceneViewer.performanceMonitor) {
|
|
101
|
+
return sceneViewer.performanceMonitor.getCurrentFPS();
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Cleanup animation resources
|
|
108
|
+
*/
|
|
109
|
+
}, {
|
|
110
|
+
key: "dispose",
|
|
111
|
+
value: function dispose() {
|
|
112
|
+
this.stopAnimation();
|
|
113
|
+
this.lastFrameTime = 0;
|
|
114
|
+
logger.info('AnimationManager disposed');
|
|
115
|
+
}
|
|
116
|
+
}]);
|
|
117
|
+
}();
|
|
118
|
+
|
|
119
|
+
export { AnimationManager };
|
|
@@ -1 +1,328 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import { createClass as _createClass, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, objectSpread2 as _objectSpread2 } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import 'three';
|
|
3
|
+
import { findObjectByHardcodedUuid } from '../../core/nameUtils.js';
|
|
4
|
+
import modelPreloader from '../../rendering/modelPreloader.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Component Manager Class
|
|
8
|
+
* Handles adding components to the scene
|
|
9
|
+
*/
|
|
10
|
+
var ComponentManager = /*#__PURE__*/function () {
|
|
11
|
+
function ComponentManager(sceneViewer) {
|
|
12
|
+
_classCallCheck(this, ComponentManager);
|
|
13
|
+
this.sceneViewer = sceneViewer;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Add a new component to the scene
|
|
18
|
+
*/
|
|
19
|
+
return _createClass(ComponentManager, [{
|
|
20
|
+
key: "addComponentToScene",
|
|
21
|
+
value: (function () {
|
|
22
|
+
var _addComponentToScene = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(componentData) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
var _gltfScene$userData, uuid, componentDictionary, dictResponse, libraryComponent, position, gltfScene, gltf, componentMesh, event, _t, _t2, _t3;
|
|
25
|
+
return _regenerator().w(function (_context) {
|
|
26
|
+
while (1) switch (_context.n) {
|
|
27
|
+
case 0:
|
|
28
|
+
_context.p = 0;
|
|
29
|
+
console.log('🎯 Adding component to scene:', componentData);
|
|
30
|
+
if (!(!componentData.libraryId || !componentData.modelKey)) {
|
|
31
|
+
_context.n = 1;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
console.error('❌ Invalid component data - missing libraryId or modelKey');
|
|
35
|
+
return _context.a(2, false);
|
|
36
|
+
case 1:
|
|
37
|
+
// Generate a unique UUID for the new component
|
|
38
|
+
uuid = componentData.libraryId + '-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9); // Get the component dictionary for model information
|
|
39
|
+
componentDictionary = {};
|
|
40
|
+
_context.p = 2;
|
|
41
|
+
_context.n = 3;
|
|
42
|
+
return fetch('./library/component-dictionary.json');
|
|
43
|
+
case 3:
|
|
44
|
+
dictResponse = _context.v;
|
|
45
|
+
_context.n = 4;
|
|
46
|
+
return dictResponse.json();
|
|
47
|
+
case 4:
|
|
48
|
+
componentDictionary = _context.v;
|
|
49
|
+
_context.n = 6;
|
|
50
|
+
break;
|
|
51
|
+
case 5:
|
|
52
|
+
_context.p = 5;
|
|
53
|
+
_t = _context.v;
|
|
54
|
+
console.warn('⚠️ Could not load component dictionary:', _t);
|
|
55
|
+
return _context.a(2, false);
|
|
56
|
+
case 6:
|
|
57
|
+
libraryComponent = componentDictionary[componentData.libraryId];
|
|
58
|
+
if (libraryComponent) {
|
|
59
|
+
_context.n = 7;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
console.error('❌ Component not found in library:', componentData.libraryId);
|
|
63
|
+
return _context.a(2, false);
|
|
64
|
+
case 7:
|
|
65
|
+
// Use provided position or default to origin
|
|
66
|
+
position = componentData.position || {
|
|
67
|
+
x: 0,
|
|
68
|
+
y: 0,
|
|
69
|
+
z: 0
|
|
70
|
+
}; // Try to get the model from the preloader cache with dimensions
|
|
71
|
+
gltfScene = modelPreloader.getCachedModelWithDimensions(libraryComponent.modelKey, componentData.libraryId);
|
|
72
|
+
if (gltfScene) {
|
|
73
|
+
_context.n = 11;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
console.log('⚠️ Model not in cache, loading directly:', libraryComponent.modelKey);
|
|
77
|
+
|
|
78
|
+
// Fallback to direct loading if not in cache
|
|
79
|
+
_context.p = 8;
|
|
80
|
+
_context.n = 9;
|
|
81
|
+
return new Promise(function (resolve, reject) {
|
|
82
|
+
_this.sceneViewer.gltfLoader.load("./library/models/".concat(libraryComponent.modelKey), resolve, undefined, reject);
|
|
83
|
+
});
|
|
84
|
+
case 9:
|
|
85
|
+
gltf = _context.v;
|
|
86
|
+
gltfScene = gltf.scene;
|
|
87
|
+
|
|
88
|
+
// Add dimensions to the directly loaded model
|
|
89
|
+
gltfScene = modelPreloader.addDimensionsToModel(gltfScene, componentData.libraryId);
|
|
90
|
+
_context.n = 11;
|
|
91
|
+
break;
|
|
92
|
+
case 10:
|
|
93
|
+
_context.p = 10;
|
|
94
|
+
_t2 = _context.v;
|
|
95
|
+
console.error('❌ Failed to load component model:', _t2);
|
|
96
|
+
return _context.a(2, false);
|
|
97
|
+
case 11:
|
|
98
|
+
// Clone the model for this instance
|
|
99
|
+
componentMesh = gltfScene.clone(); // Set up the component properties with hardcoded UUID preservation
|
|
100
|
+
componentMesh.uuid = uuid;
|
|
101
|
+
componentMesh.name = (componentData.uuid || componentData.libraryId) + ' Component';
|
|
102
|
+
componentMesh.position.set(position.x, position.y, position.z);
|
|
103
|
+
|
|
104
|
+
// Set userData for the component including dimensions
|
|
105
|
+
componentMesh.userData = _objectSpread2({
|
|
106
|
+
libraryId: componentData.libraryId,
|
|
107
|
+
componentType: 'component',
|
|
108
|
+
forExport: true,
|
|
109
|
+
originalUuid: uuid
|
|
110
|
+
}, ((_gltfScene$userData = gltfScene.userData) === null || _gltfScene$userData === void 0 ? void 0 : _gltfScene$userData.dimensions) && {
|
|
111
|
+
dimensions: gltfScene.userData.dimensions
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Also ensure dimensions are preserved in the userData
|
|
115
|
+
if (libraryComponent.boundingBox) {
|
|
116
|
+
componentMesh.userData.dimensions = {
|
|
117
|
+
x: libraryComponent.boundingBox.x,
|
|
118
|
+
y: libraryComponent.boundingBox.y,
|
|
119
|
+
z: libraryComponent.boundingBox.z
|
|
120
|
+
};
|
|
121
|
+
console.log("\uD83D\uDCCF Added dimensions to component userData for ".concat(componentData.libraryId, ":"), componentMesh.userData.dimensions);
|
|
122
|
+
}
|
|
123
|
+
if (libraryComponent.adaptedBoundingBox) {
|
|
124
|
+
componentMesh.userData.adaptedBoundingBox = {
|
|
125
|
+
x: libraryComponent.adaptedBoundingBox.x,
|
|
126
|
+
y: libraryComponent.adaptedBoundingBox.y,
|
|
127
|
+
z: libraryComponent.adaptedBoundingBox.z
|
|
128
|
+
};
|
|
129
|
+
console.log("\uD83D\uDCCF Added adaptedBoundingBox to component userData for ".concat(componentData.libraryId, ":"), componentMesh.userData.adaptedBoundingBox);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Enable shadows for all meshes in the component
|
|
133
|
+
componentMesh.traverse(function (child) {
|
|
134
|
+
if (child.isMesh) {
|
|
135
|
+
child.castShadow = true;
|
|
136
|
+
child.receiveShadow = true;
|
|
137
|
+
if (child.material) {
|
|
138
|
+
child.material.envMapIntensity = 1.0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Set forExport for connectors within the component
|
|
142
|
+
if (child.name && child.name.toLowerCase().includes('connector')) {
|
|
143
|
+
if (!child.userData) {
|
|
144
|
+
child.userData = {};
|
|
145
|
+
}
|
|
146
|
+
child.userData.forExport = true;
|
|
147
|
+
child.userData.componentType = 'connector';
|
|
148
|
+
console.log("\uD83D\uDD27 Set forExport=true for new connector: ".concat(child.name));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Add the component to the scene
|
|
154
|
+
this.sceneViewer.scene.add(componentMesh);
|
|
155
|
+
|
|
156
|
+
// Dispatch custom event for component addition
|
|
157
|
+
if (typeof window !== 'undefined') {
|
|
158
|
+
event = new CustomEvent('componentAdded', {
|
|
159
|
+
detail: {
|
|
160
|
+
component: componentMesh,
|
|
161
|
+
libraryId: componentData.libraryId,
|
|
162
|
+
uuid: uuid,
|
|
163
|
+
position: componentMesh.position,
|
|
164
|
+
dimensions: componentMesh.userData.dimensions
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
window.dispatchEvent(event);
|
|
168
|
+
console.log('📡 Dispatched componentAdded event for:', componentMesh.name);
|
|
169
|
+
}
|
|
170
|
+
console.log('✅ Component successfully added to scene:', componentMesh.name);
|
|
171
|
+
|
|
172
|
+
// Enable transform controls now that we have objects in the scene
|
|
173
|
+
if (this.sceneViewer.enableTransformControls) {
|
|
174
|
+
this.sceneViewer.enableTransformControls();
|
|
175
|
+
}
|
|
176
|
+
return _context.a(2, true);
|
|
177
|
+
case 12:
|
|
178
|
+
_context.p = 12;
|
|
179
|
+
_t3 = _context.v;
|
|
180
|
+
console.error('❌ Error adding component to scene:', _t3);
|
|
181
|
+
return _context.a(2, false);
|
|
182
|
+
}
|
|
183
|
+
}, _callee, this, [[8, 10], [2, 5], [0, 12]]);
|
|
184
|
+
}));
|
|
185
|
+
function addComponentToScene(_x) {
|
|
186
|
+
return _addComponentToScene.apply(this, arguments);
|
|
187
|
+
}
|
|
188
|
+
return addComponentToScene;
|
|
189
|
+
}()
|
|
190
|
+
/**
|
|
191
|
+
* Remove a component from the scene
|
|
192
|
+
*/
|
|
193
|
+
)
|
|
194
|
+
}, {
|
|
195
|
+
key: "removeComponentFromScene",
|
|
196
|
+
value: function removeComponentFromScene(componentUuid) {
|
|
197
|
+
try {
|
|
198
|
+
// Use the new utility function to find objects by hardcoded UUID
|
|
199
|
+
var object = findObjectByHardcodedUuid(this.sceneViewer.scene, componentUuid);
|
|
200
|
+
if (!object) {
|
|
201
|
+
console.warn('⚠️ Component not found:', componentUuid);
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Dispose of materials and geometries
|
|
206
|
+
object.traverse(function (child) {
|
|
207
|
+
if (child.geometry) {
|
|
208
|
+
child.geometry.dispose();
|
|
209
|
+
}
|
|
210
|
+
if (child.material) {
|
|
211
|
+
if (Array.isArray(child.material)) {
|
|
212
|
+
child.material.forEach(function (mat) {
|
|
213
|
+
return mat.dispose();
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
child.material.dispose();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Remove from scene
|
|
222
|
+
this.sceneViewer.scene.remove(object);
|
|
223
|
+
|
|
224
|
+
// Dispatch custom event for component removal
|
|
225
|
+
if (typeof window !== 'undefined') {
|
|
226
|
+
var _object$userData;
|
|
227
|
+
var event = new CustomEvent('componentRemoved', {
|
|
228
|
+
detail: {
|
|
229
|
+
uuid: componentUuid,
|
|
230
|
+
name: object.name,
|
|
231
|
+
libraryId: (_object$userData = object.userData) === null || _object$userData === void 0 ? void 0 : _object$userData.libraryId
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
window.dispatchEvent(event);
|
|
235
|
+
console.log('📡 Dispatched componentRemoved event for:', object.name);
|
|
236
|
+
}
|
|
237
|
+
console.log('✅ Component removed from scene:', object.name);
|
|
238
|
+
return true;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
console.error('❌ Error removing component from scene:', error);
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Get all components in the scene
|
|
247
|
+
*/
|
|
248
|
+
}, {
|
|
249
|
+
key: "getSceneComponents",
|
|
250
|
+
value: function getSceneComponents() {
|
|
251
|
+
var components = [];
|
|
252
|
+
this.sceneViewer.scene.traverse(function (child) {
|
|
253
|
+
var _child$userData;
|
|
254
|
+
if (((_child$userData = child.userData) === null || _child$userData === void 0 ? void 0 : _child$userData.componentType) === 'component') {
|
|
255
|
+
var _child$userData2;
|
|
256
|
+
components.push({
|
|
257
|
+
uuid: ((_child$userData2 = child.userData) === null || _child$userData2 === void 0 ? void 0 : _child$userData2.originalUuid) || child.uuid,
|
|
258
|
+
// Prioritize hardcoded UUID
|
|
259
|
+
name: child.name,
|
|
260
|
+
libraryId: child.userData.libraryId,
|
|
261
|
+
position: {
|
|
262
|
+
x: child.position.x,
|
|
263
|
+
y: child.position.y,
|
|
264
|
+
z: child.position.z
|
|
265
|
+
},
|
|
266
|
+
rotation: {
|
|
267
|
+
x: child.rotation.x,
|
|
268
|
+
y: child.rotation.y,
|
|
269
|
+
z: child.rotation.z
|
|
270
|
+
},
|
|
271
|
+
scale: {
|
|
272
|
+
x: child.scale.x,
|
|
273
|
+
y: child.scale.y,
|
|
274
|
+
z: child.scale.z
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
return components;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Update component properties
|
|
284
|
+
*/
|
|
285
|
+
}, {
|
|
286
|
+
key: "updateComponent",
|
|
287
|
+
value: function updateComponent(componentUuid, updates) {
|
|
288
|
+
try {
|
|
289
|
+
// Use the new utility function to find objects by hardcoded UUID
|
|
290
|
+
var object = findObjectByHardcodedUuid(this.sceneViewer.scene, componentUuid);
|
|
291
|
+
if (!object) {
|
|
292
|
+
console.warn('⚠️ Component not found:', componentUuid);
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Update position
|
|
297
|
+
if (updates.position) {
|
|
298
|
+
var _updates$position$x, _updates$position$y, _updates$position$z;
|
|
299
|
+
object.position.set((_updates$position$x = updates.position.x) !== null && _updates$position$x !== void 0 ? _updates$position$x : object.position.x, (_updates$position$y = updates.position.y) !== null && _updates$position$y !== void 0 ? _updates$position$y : object.position.y, (_updates$position$z = updates.position.z) !== null && _updates$position$z !== void 0 ? _updates$position$z : object.position.z);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Update rotation
|
|
303
|
+
if (updates.rotation) {
|
|
304
|
+
var _updates$rotation$x, _updates$rotation$y, _updates$rotation$z;
|
|
305
|
+
object.rotation.set((_updates$rotation$x = updates.rotation.x) !== null && _updates$rotation$x !== void 0 ? _updates$rotation$x : object.rotation.x, (_updates$rotation$y = updates.rotation.y) !== null && _updates$rotation$y !== void 0 ? _updates$rotation$y : object.rotation.y, (_updates$rotation$z = updates.rotation.z) !== null && _updates$rotation$z !== void 0 ? _updates$rotation$z : object.rotation.z);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Update scale
|
|
309
|
+
if (updates.scale) {
|
|
310
|
+
var _updates$scale$x, _updates$scale$y, _updates$scale$z;
|
|
311
|
+
object.scale.set((_updates$scale$x = updates.scale.x) !== null && _updates$scale$x !== void 0 ? _updates$scale$x : object.scale.x, (_updates$scale$y = updates.scale.y) !== null && _updates$scale$y !== void 0 ? _updates$scale$y : object.scale.y, (_updates$scale$z = updates.scale.z) !== null && _updates$scale$z !== void 0 ? _updates$scale$z : object.scale.z);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Update name
|
|
315
|
+
if (updates.name) {
|
|
316
|
+
object.name = updates.name;
|
|
317
|
+
}
|
|
318
|
+
console.log('✅ Component updated:', object.name);
|
|
319
|
+
return true;
|
|
320
|
+
} catch (error) {
|
|
321
|
+
console.error('❌ Error updating component:', error);
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}]);
|
|
326
|
+
}();
|
|
327
|
+
|
|
328
|
+
export { ComponentManager };
|