@2112-lab/central-plant 0.1.0

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 (54) hide show
  1. package/README.md +0 -0
  2. package/dist/bundle/index.js +14259 -0
  3. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +353 -0
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1292 -0
  5. package/dist/cjs/node_modules/three/examples/jsm/controls/TransformControls.js +1543 -0
  6. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4374 -0
  7. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +465 -0
  8. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +117 -0
  9. package/dist/cjs/src/ConnectionManager.js +114 -0
  10. package/dist/cjs/src/Pathfinder.js +88 -0
  11. package/dist/cjs/src/animationManager.js +121 -0
  12. package/dist/cjs/src/componentManager.js +151 -0
  13. package/dist/cjs/src/debugLogger.js +176 -0
  14. package/dist/cjs/src/disposalManager.js +185 -0
  15. package/dist/cjs/src/environmentManager.js +1015 -0
  16. package/dist/cjs/src/hotReloadManager.js +252 -0
  17. package/dist/cjs/src/index.js +126 -0
  18. package/dist/cjs/src/keyboardControlsManager.js +206 -0
  19. package/dist/cjs/src/modelPreloader.js +360 -0
  20. package/dist/cjs/src/nameUtils.js +106 -0
  21. package/dist/cjs/src/pathfindingManager.js +321 -0
  22. package/dist/cjs/src/performanceMonitor.js +718 -0
  23. package/dist/cjs/src/sceneExportManager.js +292 -0
  24. package/dist/cjs/src/sceneInitializationManager.js +540 -0
  25. package/dist/cjs/src/sceneOperationsManager.js +560 -0
  26. package/dist/cjs/src/textureConfig.js +195 -0
  27. package/dist/cjs/src/transformControlsManager.js +851 -0
  28. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +328 -0
  29. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1287 -0
  30. package/dist/esm/node_modules/three/examples/jsm/controls/TransformControls.js +1537 -0
  31. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4370 -0
  32. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +461 -0
  33. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +113 -0
  34. package/dist/esm/src/ConnectionManager.js +110 -0
  35. package/dist/esm/src/Pathfinder.js +84 -0
  36. package/dist/esm/src/animationManager.js +112 -0
  37. package/dist/esm/src/componentManager.js +123 -0
  38. package/dist/esm/src/debugLogger.js +167 -0
  39. package/dist/esm/src/disposalManager.js +155 -0
  40. package/dist/esm/src/environmentManager.js +989 -0
  41. package/dist/esm/src/hotReloadManager.js +244 -0
  42. package/dist/esm/src/index.js +117 -0
  43. package/dist/esm/src/keyboardControlsManager.js +196 -0
  44. package/dist/esm/src/modelPreloader.js +337 -0
  45. package/dist/esm/src/nameUtils.js +99 -0
  46. package/dist/esm/src/pathfindingManager.js +295 -0
  47. package/dist/esm/src/performanceMonitor.js +712 -0
  48. package/dist/esm/src/sceneExportManager.js +286 -0
  49. package/dist/esm/src/sceneInitializationManager.js +513 -0
  50. package/dist/esm/src/sceneOperationsManager.js +536 -0
  51. package/dist/esm/src/textureConfig.js +168 -0
  52. package/dist/esm/src/transformControlsManager.js +827 -0
  53. package/dist/index.d.ts +259 -0
  54. package/package.json +53 -0
@@ -0,0 +1,292 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
6
+ var nameUtils = require('./nameUtils.js');
7
+
8
+ /**
9
+ * Class for managing scene export operations
10
+ */
11
+ var SceneExportManager = /*#__PURE__*/function () {
12
+ /**
13
+ * Create a SceneExportManager
14
+ * @param {Object} componentInstance - The component instance containing scene data
15
+ */
16
+ function SceneExportManager(componentInstance) {
17
+ _rollupPluginBabelHelpers.classCallCheck(this, SceneExportManager);
18
+ this.component = componentInstance;
19
+ }
20
+
21
+ /**
22
+ * Export function that recreates the JSON data structure from current scene objects
23
+ * @returns {Object|null} The exported scene data as JSON object or null if export failed
24
+ */
25
+ return _rollupPluginBabelHelpers.createClass(SceneExportManager, [{
26
+ key: "exportSceneData",
27
+ value: function exportSceneData() {
28
+ var _this = this;
29
+ console.log('📤 Starting scene export...');
30
+ if (!this.component.scene) {
31
+ console.warn('⚠️ No scene available for export');
32
+ return null;
33
+ }
34
+
35
+ // Helper function to extract connections from pathfinder or scene analysis
36
+ var extractConnections = function extractConnections() {
37
+ var _this$component$curre;
38
+ var connections = [];
39
+
40
+ // If we have the original connections from currentSceneData, use those as base
41
+ if ((_this$component$curre = _this.component.currentSceneData) !== null && _this$component$curre !== void 0 && _this$component$curre.connections) {
42
+ connections.push.apply(connections, _rollupPluginBabelHelpers.toConsumableArray(_this.component.currentSceneData.connections));
43
+ }
44
+
45
+ // If no currentSceneData, we'll return empty connections array
46
+ // This allows export to work even for default scenes that haven't been imported
47
+ return connections;
48
+ };
49
+
50
+ // Helper function to convert Three.js object to JSON format
51
+ var _convertObjectToJson = function convertObjectToJson(threeObject) {
52
+ var _threeObject$name, _threeObject$userData, _threeObject$userData2, _threeObject$userData3, _threeObject$userData4, _threeObject$userData5, _threeObject$userData6, _threeObject$userData8;
53
+ var isChild = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
54
+ // Skip certain objects that shouldn't be exported
55
+ if (!threeObject || (_threeObject$name = threeObject.name) !== null && _threeObject$name !== void 0 && _threeObject$name.includes('Polyline') || // Skip pipe paths
56
+ (_threeObject$userData = threeObject.userData) !== null && _threeObject$userData !== void 0 && _threeObject$userData.isBrickWall || // Skip environment
57
+ (_threeObject$userData2 = threeObject.userData) !== null && _threeObject$userData2 !== void 0 && _threeObject$userData2.isBaseGround || // Skip environment
58
+ (_threeObject$userData3 = threeObject.userData) !== null && _threeObject$userData3 !== void 0 && _threeObject$userData3.isBaseGrid ||
59
+ // Skip environment
60
+ threeObject.isLight || // Skip lights
61
+ (_threeObject$userData4 = threeObject.userData) !== null && _threeObject$userData4 !== void 0 && _threeObject$userData4.isTransformControls ||
62
+ // Skip transform controls
63
+ threeObject.isTransformControls ||
64
+ // Skip transform controls
65
+ threeObject.type && threeObject.type.includes('TransformControls')) {
66
+ return null;
67
+ }
68
+
69
+ // For top-level objects, require componentType, but allow children through
70
+ if (!isChild && !((_threeObject$userData5 = threeObject.userData) !== null && _threeObject$userData5 !== void 0 && _threeObject$userData5.componentType)) {
71
+ return null;
72
+ }
73
+
74
+ // For child objects, only include if forExport is explicitly set to true
75
+ if (isChild && !((_threeObject$userData6 = threeObject.userData) !== null && _threeObject$userData6 !== void 0 && _threeObject$userData6.forExport)) {
76
+ var _threeObject$userData7;
77
+ console.log("\uD83D\uDD3D Excluding child '".concat(threeObject.name, "' from export (forExport: ").concat((_threeObject$userData7 = threeObject.userData) === null || _threeObject$userData7 === void 0 ? void 0 : _threeObject$userData7.forExport, ")"));
78
+ return null;
79
+ }
80
+
81
+ // Log when a child is being included in export
82
+ if (isChild && (_threeObject$userData8 = threeObject.userData) !== null && _threeObject$userData8 !== void 0 && _threeObject$userData8.forExport) {
83
+ var _threeObject$userData9;
84
+ console.log("\u2705 Including child '".concat(threeObject.name, "' in export (forExport: ").concat((_threeObject$userData9 = threeObject.userData) === null || _threeObject$userData9 === void 0 ? void 0 : _threeObject$userData9.forExport, ")"));
85
+ }
86
+
87
+ // Create base JSON object with HARDCODED UUID preservation
88
+ var jsonObject = {
89
+ uuid: nameUtils.getHardcodedUuid(threeObject),
90
+ // Use utility function to get hardcoded UUID
91
+ name: threeObject.name || 'Unnamed Object',
92
+ type: threeObject.type || 'Object3D'
93
+ };
94
+
95
+ // Add userData if it exists (preserving libraryId and other important data)
96
+ if (threeObject.userData && Object.keys(threeObject.userData).length > 0) {
97
+ jsonObject.userData = {};
98
+
99
+ // Copy important userData properties, excluding temporary/runtime data
100
+ Object.keys(threeObject.userData).forEach(function (key) {
101
+ if (key !== 'worldBoundingBox' && key !== 'isBaseGround' && key !== 'isBrickWall' && key !== 'isBaseGrid' && key !== 'isTransformControls') {
102
+ jsonObject.userData[key] = threeObject.userData[key];
103
+ }
104
+ });
105
+
106
+ // If no relevant userData, remove the empty object
107
+ if (Object.keys(jsonObject.userData).length === 0) {
108
+ delete jsonObject.userData;
109
+ }
110
+ }
111
+
112
+ // Add transform data - convert from radians to degrees for rotation
113
+ jsonObject.position = {
114
+ x: parseFloat(threeObject.position.x.toFixed(6)),
115
+ y: parseFloat(threeObject.position.y.toFixed(6)),
116
+ z: parseFloat(threeObject.position.z.toFixed(6))
117
+ };
118
+ jsonObject.rotation = {
119
+ x: parseFloat((threeObject.rotation.x * (180 / Math.PI)).toFixed(6)),
120
+ y: parseFloat((threeObject.rotation.y * (180 / Math.PI)).toFixed(6)),
121
+ z: parseFloat((threeObject.rotation.z * (180 / Math.PI)).toFixed(6))
122
+ };
123
+ jsonObject.scale = {
124
+ x: parseFloat(threeObject.scale.x.toFixed(6)),
125
+ y: parseFloat(threeObject.scale.y.toFixed(6)),
126
+ z: parseFloat(threeObject.scale.z.toFixed(6))
127
+ };
128
+
129
+ // Add geometry reference for connectors and other special objects
130
+ if (threeObject.geometry) {
131
+ var _threeObject$name2, _threeObject$name3, _threeObject$userData0;
132
+ if ((_threeObject$name2 = threeObject.name) !== null && _threeObject$name2 !== void 0 && _threeObject$name2.toLowerCase().includes('connector')) {
133
+ jsonObject.geometry = 'CONNECTOR-GEO';
134
+ } else if ((_threeObject$name3 = threeObject.name) !== null && _threeObject$name3 !== void 0 && _threeObject$name3.toLowerCase().includes('gateway')) {
135
+ jsonObject.geometry = 'GATEWAY-GEO';
136
+ } else if ((_threeObject$userData0 = threeObject.userData) !== null && _threeObject$userData0 !== void 0 && _threeObject$userData0.libraryId) {
137
+ // For library objects, use a standard geometry reference
138
+ jsonObject.geometry = "".concat(threeObject.userData.libraryId, "-GEO");
139
+ }
140
+ }
141
+
142
+ // Process children recursively
143
+ if (threeObject.children && threeObject.children.length > 0) {
144
+ var validChildren = [];
145
+ threeObject.children.forEach(function (child) {
146
+ var childJson = _convertObjectToJson(child, true);
147
+ if (childJson) {
148
+ validChildren.push(childJson);
149
+ }
150
+ });
151
+ if (validChildren.length > 0) {
152
+ jsonObject.children = validChildren;
153
+ }
154
+ }
155
+ return jsonObject;
156
+ };
157
+
158
+ // Extract main scene objects (excluding environment and utility objects)
159
+ var sceneChildren = [];
160
+ this.component.scene.children.forEach(function (child) {
161
+ var jsonChild = _convertObjectToJson(child);
162
+ if (jsonChild) {
163
+ sceneChildren.push(jsonChild);
164
+ }
165
+ });
166
+
167
+ // Build the complete export data structure
168
+ var exportData = {
169
+ connections: extractConnections(),
170
+ scene: {
171
+ object: {
172
+ uuid: 'PLANT-SCENE',
173
+ name: 'Scene',
174
+ type: 'Scene',
175
+ children: sceneChildren
176
+ }
177
+ }
178
+ };
179
+
180
+ // Add metadata for tracking
181
+ exportData._metadata = {
182
+ exportedAt: new Date().toISOString(),
183
+ exportedFrom: 'SceneViewerEnhanced',
184
+ version: '1.0.0',
185
+ objectCount: sceneChildren.length
186
+ };
187
+ console.log('✅ Scene export completed:', exportData);
188
+ return exportData;
189
+ }
190
+
191
+ /**
192
+ * Helper function to download the exported scene data as JSON file
193
+ * @param {string} filename - Optional filename for the export
194
+ * @returns {boolean} Success status of the download operation
195
+ */
196
+ }, {
197
+ key: "downloadSceneExport",
198
+ value: function downloadSceneExport() {
199
+ var filename = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
200
+ var exportData = this.exportSceneData();
201
+ if (!exportData) {
202
+ console.error('❌ Failed to export scene data');
203
+ return false;
204
+ }
205
+
206
+ // Generate filename if not provided
207
+ if (!filename) {
208
+ filename = "cp-export.json";
209
+ }
210
+
211
+ // Create and download the file
212
+ try {
213
+ var jsonString = JSON.stringify(exportData, null, 2);
214
+
215
+ // Check if we're in a browser environment
216
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
217
+ var blob = new Blob([jsonString], {
218
+ type: 'application/json'
219
+ });
220
+ var url = URL.createObjectURL(blob);
221
+ var link = document.createElement('a');
222
+ link.href = url;
223
+ link.download = filename;
224
+ document.body.appendChild(link);
225
+ link.click();
226
+ document.body.removeChild(link);
227
+ URL.revokeObjectURL(url);
228
+ console.log("\uD83D\uDCC1 Scene exported successfully as: ".concat(filename));
229
+ return true;
230
+ } else {
231
+ console.warn('⚠️ Download functionality requires browser environment');
232
+ return false;
233
+ }
234
+ } catch (error) {
235
+ console.error('❌ Error downloading scene export:', error);
236
+ return false;
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Export scene data as JSON string
242
+ * @param {boolean} pretty - Whether to format the JSON with indentation
243
+ * @returns {string|null} JSON string or null if export failed
244
+ */
245
+ }, {
246
+ key: "exportSceneDataAsString",
247
+ value: function exportSceneDataAsString() {
248
+ var pretty = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
249
+ var exportData = this.exportSceneData();
250
+ if (!exportData) {
251
+ return null;
252
+ }
253
+ return pretty ? JSON.stringify(exportData, null, 2) : JSON.stringify(exportData);
254
+ }
255
+
256
+ /**
257
+ * Get export metadata
258
+ * @returns {Object|null} Export metadata or null if scene is not available
259
+ */
260
+ }, {
261
+ key: "getExportMetadata",
262
+ value: function getExportMetadata() {
263
+ var _this$component$curre2;
264
+ if (!this.component.scene) {
265
+ return null;
266
+ }
267
+ var objectCount = 0;
268
+ this.component.scene.traverse(function () {
269
+ return objectCount++;
270
+ });
271
+ return {
272
+ totalObjects: objectCount,
273
+ hasCurrentSceneData: !!this.component.currentSceneData,
274
+ connectionsCount: ((_this$component$curre2 = this.component.currentSceneData) === null || _this$component$curre2 === void 0 || (_this$component$curre2 = _this$component$curre2.connections) === null || _this$component$curre2 === void 0 ? void 0 : _this$component$curre2.length) || 0,
275
+ exportTimestamp: new Date().toISOString()
276
+ };
277
+ }
278
+ }]);
279
+ }();
280
+
281
+ /**
282
+ * Factory function to get SceneExportManager instance
283
+ * @param {CentralPlantComponent} component - The component instance
284
+ * @returns {SceneExportManager} SceneExportManager instance
285
+ */
286
+ function getSceneExportManager(component) {
287
+ return new SceneExportManager(component);
288
+ }
289
+
290
+ exports.SceneExportManager = SceneExportManager;
291
+ exports["default"] = SceneExportManager;
292
+ exports.getSceneExportManager = getSceneExportManager;