@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,989 @@
1
+ import { createClass as _createClass, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, classCallCheck as _classCallCheck, regeneratorValues as _regeneratorValues, createForOfIteratorHelper as _createForOfIteratorHelper } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import * as THREE from 'three';
3
+ import { logger } from './debugLogger.js';
4
+
5
+ // We'll need to import RGBELoader from three examples
6
+ var RGBELoader;
7
+
8
+ // Dynamic import for browser compatibility
9
+ function importThreeLoaders() {
10
+ return _importThreeLoaders.apply(this, arguments);
11
+ } // This will be imported once textureConfig is created
12
+ function _importThreeLoaders() {
13
+ _importThreeLoaders = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
14
+ var module, _t0;
15
+ return _regenerator().w(function (_context0) {
16
+ while (1) switch (_context0.n) {
17
+ case 0:
18
+ if (!(typeof window !== 'undefined')) {
19
+ _context0.n = 4;
20
+ break;
21
+ }
22
+ _context0.p = 1;
23
+ console.log('📦 Attempting to dynamically import RGBELoader...');
24
+ // Dynamic import for browser
25
+ _context0.n = 2;
26
+ return import('../node_modules/three/examples/jsm/loaders/RGBELoader.js');
27
+ case 2:
28
+ module = _context0.v;
29
+ RGBELoader = module.RGBELoader;
30
+ console.log('✅ RGBELoader imported successfully:', RGBELoader ? 'Available' : 'Undefined');
31
+ return _context0.a(2, true);
32
+ case 3:
33
+ _context0.p = 3;
34
+ _t0 = _context0.v;
35
+ console.error('Failed to load Three.js loaders:', _t0);
36
+ throw new Error('Failed to load Three.js loaders');
37
+ case 4:
38
+ return _context0.a(2, false);
39
+ }
40
+ }, _callee8, null, [[1, 3]]);
41
+ }));
42
+ return _importThreeLoaders.apply(this, arguments);
43
+ }
44
+ var loadTextureSetAndCreateMaterial;
45
+ function importTextureConfig() {
46
+ return _importTextureConfig.apply(this, arguments);
47
+ }
48
+ function _importTextureConfig() {
49
+ _importTextureConfig = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
50
+ var module, _t1;
51
+ return _regenerator().w(function (_context1) {
52
+ while (1) switch (_context1.n) {
53
+ case 0:
54
+ if (!(typeof window !== 'undefined')) {
55
+ _context1.n = 4;
56
+ break;
57
+ }
58
+ _context1.p = 1;
59
+ console.log('📦 Attempting to dynamically import textureConfig...');
60
+ _context1.n = 2;
61
+ return import('./textureConfig.js');
62
+ case 2:
63
+ module = _context1.v;
64
+ loadTextureSetAndCreateMaterial = module.loadTextureSetAndCreateMaterial;
65
+ console.log('✅ TextureConfig imported successfully:', loadTextureSetAndCreateMaterial ? 'Available' : 'Undefined');
66
+ return _context1.a(2, true);
67
+ case 3:
68
+ _context1.p = 3;
69
+ _t1 = _context1.v;
70
+ console.error('Failed to load texture config:', _t1);
71
+ return _context1.a(2, false);
72
+ case 4:
73
+ return _context1.a(2, false);
74
+ }
75
+ }, _callee9, null, [[1, 3]]);
76
+ }));
77
+ return _importTextureConfig.apply(this, arguments);
78
+ }
79
+ var EnvironmentManager = /*#__PURE__*/function () {
80
+ function EnvironmentManager(component) {
81
+ _classCallCheck(this, EnvironmentManager);
82
+ this.component = component;
83
+
84
+ // Track loader status
85
+ this.loadersInitialized = false;
86
+
87
+ // Initialize loaders immediately
88
+ this.initLoaders();
89
+ }
90
+ return _createClass(EnvironmentManager, [{
91
+ key: "initLoaders",
92
+ value: function () {
93
+ var _initLoaders = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
94
+ var _t;
95
+ return _regenerator().w(function (_context) {
96
+ while (1) switch (_context.n) {
97
+ case 0:
98
+ console.log('🔄 Pre-initializing loaders in EnvironmentManager constructor...');
99
+ _context.p = 1;
100
+ _context.n = 2;
101
+ return Promise.all([importThreeLoaders(), importTextureConfig()]);
102
+ case 2:
103
+ this.loadersInitialized = true;
104
+ console.log('✅ EnvironmentManager loaders pre-initialized successfully');
105
+ _context.n = 4;
106
+ break;
107
+ case 3:
108
+ _context.p = 3;
109
+ _t = _context.v;
110
+ console.warn('⚠️ Error pre-initializing loaders:', _t);
111
+ case 4:
112
+ return _context.a(2);
113
+ }
114
+ }, _callee, this, [[1, 3]]);
115
+ }));
116
+ function initLoaders() {
117
+ return _initLoaders.apply(this, arguments);
118
+ }
119
+ return initLoaders;
120
+ }()
121
+ /**
122
+ * Create skybox with HDR environment mapping
123
+ */
124
+ }, {
125
+ key: "createSkybox",
126
+ value: (function () {
127
+ var _createSkybox = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
128
+ var _this = this;
129
+ var component, isContextLost, pmremGenerator, loaders, applyEnvironmentMap, _loop, _ret, _i, _loaders, _t4, _t5, _t6;
130
+ return _regenerator().w(function (_context4) {
131
+ while (1) switch (_context4.n) {
132
+ case 0:
133
+ component = this.component;
134
+ if (!(!component || !component.renderer || !component.scene)) {
135
+ _context4.n = 1;
136
+ break;
137
+ }
138
+ logger.warn('Cannot create skybox: component, renderer or scene not available');
139
+ return _context4.a(2);
140
+ case 1:
141
+ console.log('🌍 Starting skybox creation process...');
142
+
143
+ // Make sure RGBELoader is available
144
+ if (RGBELoader) {
145
+ _context4.n = 5;
146
+ break;
147
+ }
148
+ console.log('⏳ RGBELoader not loaded yet, initializing now...');
149
+ _context4.p = 2;
150
+ _context4.n = 3;
151
+ return importThreeLoaders();
152
+ case 3:
153
+ console.log('✅ RGBELoader loaded on demand');
154
+ _context4.n = 5;
155
+ break;
156
+ case 4:
157
+ _context4.p = 4;
158
+ _t4 = _context4.v;
159
+ console.error('❌ Failed to load RGBELoader:', _t4);
160
+ this.createFallbackEnvironment();
161
+ return _context4.a(2);
162
+ case 5:
163
+ _context4.p = 5;
164
+ // Check if renderer is valid - safely check for context loss
165
+ isContextLost = component.renderer.context && typeof component.renderer.context.isContextLost === 'function' ? component.renderer.context.isContextLost() : false;
166
+ console.log('🔍 WebGL context check:', isContextLost ? 'Context lost' : 'Context valid');
167
+ if (!(!component.renderer.capabilities || isContextLost)) {
168
+ _context4.n = 6;
169
+ break;
170
+ }
171
+ logger.warn('WebGL context is lost or invalid, using fallback environment');
172
+ this.createFallbackEnvironment();
173
+ return _context4.a(2);
174
+ case 6:
175
+ _context4.p = 6;
176
+ pmremGenerator = new THREE.PMREMGenerator(component.renderer);
177
+
178
+ // Check if the generator was created successfully
179
+ if (pmremGenerator) {
180
+ _context4.n = 7;
181
+ break;
182
+ }
183
+ throw new Error('PMREMGenerator could not be created');
184
+ case 7:
185
+ // Attempt to compile the shader - this can fail if the context is limited
186
+ pmremGenerator.compileEquirectangularShader();
187
+ _context4.n = 9;
188
+ break;
189
+ case 8:
190
+ _context4.p = 8;
191
+ _t5 = _context4.v;
192
+ logger.warn('Failed to initialize PMREMGenerator:', _t5);
193
+ this.createFallbackEnvironment();
194
+ return _context4.a(2);
195
+ case 9:
196
+ loaders = [{
197
+ type: 'hdr',
198
+ loader: new RGBELoader(),
199
+ paths: [
200
+ // Try local paths first
201
+ '/skyboxes/kloofendal_48d_partly_cloudy_puresky_2k.hdr', '/skyboxes/kloofendal_48d_partly_cloudy_puresky_1k.hdr',
202
+ // Fall back to S3 paths
203
+ 'https://central-plant-assets.s3.us-east-1.amazonaws.com/skyboxes/kloofendal_48d_partly_cloudy_puresky_2k.hdr', 'https://central-plant-assets.s3.us-east-1.amazonaws.com/skyboxes/kloofendal_48d_partly_cloudy_puresky_1k.hdr']
204
+ }, {
205
+ type: 'jpeg',
206
+ loader: component.textureLoader || new THREE.TextureLoader(),
207
+ paths: [
208
+ // Try local paths first
209
+ '/skyboxes/sky_fallback.jpg',
210
+ // Fall back to S3 path
211
+ 'https://central-plant-assets.s3.us-east-1.amazonaws.com/skyboxes/sky_fallback.jpg']
212
+ }]; // Configure texture loaders with CORS settings
213
+ loaders.forEach(function (_ref) {
214
+ var loader = _ref.loader;
215
+ if (loader && typeof loader.setCrossOrigin === 'function') {
216
+ loader.setCrossOrigin('anonymous');
217
+ }
218
+ });
219
+ console.log('🔄 Configured loaders with CORS settings and fallback paths');
220
+ applyEnvironmentMap = function applyEnvironmentMap(envTexture, type) {
221
+ try {
222
+ var _component$scene$envi, _component$scene$back;
223
+ // Set proper mapping
224
+ envTexture.mapping = THREE.EquirectangularReflectionMapping;
225
+ // Ensure a valid color space is set for the texture
226
+ if (envTexture.colorSpace !== undefined) {
227
+ // For Three.js >= r152 (current version)
228
+ envTexture.colorSpace = component.renderer.outputColorSpace || THREE.SRGBColorSpace;
229
+ } else if (envTexture.encoding !== undefined) {
230
+ // For older versions (legacy support)
231
+ envTexture.encoding = component.renderer.outputEncoding || THREE.sRGBEncoding;
232
+ }
233
+
234
+ // Generate processed environment map
235
+ var processedEnvMap = pmremGenerator.fromEquirectangular(envTexture).texture;
236
+
237
+ // Diagnostic logging
238
+ logger.info("Generating environment map:\n - Type: ".concat(type, "\n - Texture valid: ").concat(envTexture !== null, "\n - Processed map valid: ").concat(processedEnvMap !== null, "\n - Renderer encoding: ").concat(component.renderer.outputEncoding || component.renderer.outputColorSpace, "\n - Texture encoding: ").concat(envTexture.encoding || envTexture.colorSpace));
239
+
240
+ // Clean up previous environment/background
241
+ if ((_component$scene$envi = component.scene.environment) !== null && _component$scene$envi !== void 0 && _component$scene$envi.dispose) component.scene.environment.dispose();
242
+ if ((_component$scene$back = component.scene.background) !== null && _component$scene$back !== void 0 && _component$scene$back.dispose) component.scene.background.dispose();
243
+
244
+ // Apply to scene
245
+ component.scene.environment = processedEnvMap;
246
+ component.scene.background = processedEnvMap;
247
+
248
+ // Clean up original texture
249
+ envTexture.dispose();
250
+
251
+ // Force a renderer update
252
+ if (component.renderer) {
253
+ component.renderer.toneMappingExposure = 1.0;
254
+ component.renderer.render(component.scene, component.camera);
255
+ }
256
+ logger.info("Environment map (".concat(type, ") applied successfully"));
257
+ return true;
258
+ } catch (error) {
259
+ logger.warn("Failed to apply ".concat(type, " environment map:"), error);
260
+ return false;
261
+ }
262
+ };
263
+ _loop = /*#__PURE__*/_regenerator().m(function _loop() {
264
+ var _loaders$_i, type, loader, paths, _iterator, _step, _loop2, _ret2, _t3;
265
+ return _regenerator().w(function (_context3) {
266
+ while (1) switch (_context3.n) {
267
+ case 0:
268
+ _loaders$_i = _loaders[_i], type = _loaders$_i.type, loader = _loaders$_i.loader, paths = _loaders$_i.paths;
269
+ _iterator = _createForOfIteratorHelper(paths);
270
+ _context3.p = 1;
271
+ _loop2 = /*#__PURE__*/_regenerator().m(function _loop2() {
272
+ var path, exists, texture, _t2;
273
+ return _regenerator().w(function (_context2) {
274
+ while (1) switch (_context2.n) {
275
+ case 0:
276
+ path = _step.value;
277
+ _context2.p = 1;
278
+ if (!path.startsWith('/')) {
279
+ _context2.n = 3;
280
+ break;
281
+ }
282
+ _context2.n = 2;
283
+ return _this.checkLocalTextureExists(path);
284
+ case 2:
285
+ exists = _context2.v;
286
+ console.log("\uD83D\uDD0D Local texture check for ".concat(path, ": ").concat(exists ? 'Available' : 'Not found'));
287
+ if (exists) {
288
+ _context2.n = 3;
289
+ break;
290
+ }
291
+ return _context2.a(2, 0);
292
+ case 3:
293
+ logger.info("Attempting to load ".concat(type, " texture: ").concat(path));
294
+ _context2.n = 4;
295
+ return new Promise(function (resolve, reject) {
296
+ var timeout = setTimeout(function () {
297
+ return reject(new Error("Timeout loading ".concat(path)));
298
+ }, 10000);
299
+
300
+ // Add event listeners for better diagnostics
301
+ var onProgress = function onProgress(event) {
302
+ if (event.lengthComputable) {
303
+ var percentComplete = event.loaded / event.total * 100;
304
+ console.log("Loading ".concat(path, ": ").concat(Math.round(percentComplete), "% complete"));
305
+ }
306
+ };
307
+ loader.load(path, function (tex) {
308
+ clearTimeout(timeout);
309
+ console.log("\u2705 Successfully loaded ".concat(type, " texture: ").concat(path));
310
+ resolve(tex);
311
+ }, onProgress, function (err) {
312
+ clearTimeout(timeout);
313
+ console.warn("\u274C Failed to load ".concat(path, ":"), err.message);
314
+ reject(err);
315
+ });
316
+ });
317
+ case 4:
318
+ texture = _context2.v;
319
+ if (!applyEnvironmentMap(texture, type)) {
320
+ _context2.n = 5;
321
+ break;
322
+ }
323
+ pmremGenerator.dispose();
324
+ return _context2.a(2, {
325
+ v: {
326
+ v: void 0
327
+ }
328
+ });
329
+ case 5:
330
+ _context2.n = 7;
331
+ break;
332
+ case 6:
333
+ _context2.p = 6;
334
+ _t2 = _context2.v;
335
+ logger.warn("Failed to load ".concat(path, ":"), _t2.message);
336
+ case 7:
337
+ return _context2.a(2);
338
+ }
339
+ }, _loop2, null, [[1, 6]]);
340
+ });
341
+ _iterator.s();
342
+ case 2:
343
+ if ((_step = _iterator.n()).done) {
344
+ _context3.n = 6;
345
+ break;
346
+ }
347
+ return _context3.d(_regeneratorValues(_loop2()), 3);
348
+ case 3:
349
+ _ret2 = _context3.v;
350
+ if (!(_ret2 === 0)) {
351
+ _context3.n = 4;
352
+ break;
353
+ }
354
+ return _context3.a(3, 5);
355
+ case 4:
356
+ if (!_ret2) {
357
+ _context3.n = 5;
358
+ break;
359
+ }
360
+ return _context3.a(2, _ret2.v);
361
+ case 5:
362
+ _context3.n = 2;
363
+ break;
364
+ case 6:
365
+ _context3.n = 8;
366
+ break;
367
+ case 7:
368
+ _context3.p = 7;
369
+ _t3 = _context3.v;
370
+ _iterator.e(_t3);
371
+ case 8:
372
+ _context3.p = 8;
373
+ _iterator.f();
374
+ return _context3.f(8);
375
+ case 9:
376
+ return _context3.a(2);
377
+ }
378
+ }, _loop, null, [[1, 7, 8, 9]]);
379
+ });
380
+ _i = 0, _loaders = loaders;
381
+ case 10:
382
+ if (!(_i < _loaders.length)) {
383
+ _context4.n = 13;
384
+ break;
385
+ }
386
+ return _context4.d(_regeneratorValues(_loop()), 11);
387
+ case 11:
388
+ _ret = _context4.v;
389
+ if (!_ret) {
390
+ _context4.n = 12;
391
+ break;
392
+ }
393
+ return _context4.a(2, _ret.v);
394
+ case 12:
395
+ _i++;
396
+ _context4.n = 10;
397
+ break;
398
+ case 13:
399
+ // If we reached here, all texture attempts failed - use procedural sky
400
+ this.createProceduralSky(pmremGenerator);
401
+ _context4.n = 15;
402
+ break;
403
+ case 14:
404
+ _context4.p = 14;
405
+ _t6 = _context4.v;
406
+ logger.error('Error creating skybox:', _t6);
407
+ this.createFallbackEnvironment();
408
+ case 15:
409
+ return _context4.a(2);
410
+ }
411
+ }, _callee2, this, [[6, 8], [5, 14], [2, 4]]);
412
+ }));
413
+ function createSkybox() {
414
+ return _createSkybox.apply(this, arguments);
415
+ }
416
+ return createSkybox;
417
+ }()
418
+ /**
419
+ * Create a fallback environment when renderer issues occur
420
+ */
421
+ )
422
+ }, {
423
+ key: "createFallbackEnvironment",
424
+ value: function createFallbackEnvironment() {
425
+ var component = this.component;
426
+ if (!component || !component.scene) return;
427
+ logger.info('Creating basic fallback environment');
428
+ // Add simple ambient and directional light
429
+ var ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
430
+ component.scene.add(ambientLight);
431
+ var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
432
+ directionalLight.position.set(1, 2, 3);
433
+ component.scene.add(directionalLight);
434
+
435
+ // Set a simple background color
436
+ component.scene.background = new THREE.Color(0x87CEEB);
437
+ }
438
+
439
+ /**
440
+ * Create procedural sky when textures fail to load
441
+ */
442
+ }, {
443
+ key: "createProceduralSky",
444
+ value: function createProceduralSky(pmremGenerator) {
445
+ var component = this.component;
446
+ if (!component || !component.scene) return;
447
+ logger.info('Using procedural sky fallback');
448
+ var ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
449
+ component.scene.add(ambientLight);
450
+
451
+ // Add a directional light for better illumination
452
+ var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
453
+ directionalLight.position.set(1, 1, 1);
454
+ component.scene.add(directionalLight);
455
+ try {
456
+ // Only attempt PMREM generation if we have a valid pmremGenerator
457
+ if (pmremGenerator && typeof pmremGenerator.fromScene === 'function') {
458
+ var skyScene = new THREE.Scene();
459
+ skyScene.add(new THREE.HemisphereLight(0x87CEEB, 0x444477, 1));
460
+
461
+ // Generate environment map from scene
462
+ var envMap = pmremGenerator.fromScene(skyScene);
463
+ if (envMap && envMap.texture) {
464
+ component.scene.environment = envMap.texture;
465
+ }
466
+ }
467
+
468
+ // Always set a background color as fallback
469
+ component.scene.background = new THREE.Color(0x87CEEB);
470
+ } catch (error) {
471
+ logger.warn('Failed to create procedural sky, using simple background', error);
472
+ component.scene.background = new THREE.Color(0x87CEEB);
473
+ } finally {
474
+ if (pmremGenerator && typeof pmremGenerator.dispose === 'function') {
475
+ pmremGenerator.dispose();
476
+ }
477
+ }
478
+ }
479
+
480
+ /**
481
+ * Setup scene lighting
482
+ */
483
+ }, {
484
+ key: "setupLighting",
485
+ value: function setupLighting() {
486
+ var component = this.component;
487
+ if (!component || !component.scene) {
488
+ logger.warn('Cannot setup lighting: component or scene not available');
489
+ return;
490
+ }
491
+
492
+ // Remove existing lights first
493
+ var existingLights = [];
494
+ component.scene.traverse(function (object) {
495
+ if (object instanceof THREE.Light) {
496
+ existingLights.push(object);
497
+ }
498
+ });
499
+ existingLights.forEach(function (light) {
500
+ component.scene.remove(light);
501
+ });
502
+
503
+ // Main directional light (sun)
504
+ var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
505
+ directionalLight.position.set(5, 10, 7);
506
+ directionalLight.castShadow = true;
507
+
508
+ // Optimize shadow map
509
+ directionalLight.shadow.mapSize.width = 1024;
510
+ directionalLight.shadow.mapSize.height = 1024;
511
+ directionalLight.shadow.camera.near = 1;
512
+ directionalLight.shadow.camera.far = 30;
513
+ directionalLight.shadow.camera.left = -10;
514
+ directionalLight.shadow.camera.right = 10;
515
+ directionalLight.shadow.camera.top = 10;
516
+ directionalLight.shadow.camera.bottom = -10;
517
+ directionalLight.shadow.bias = -0.001;
518
+ component.scene.add(directionalLight);
519
+
520
+ // Ambient light for general illumination
521
+ var ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
522
+ component.scene.add(ambientLight);
523
+
524
+ // Hemisphere light to simulate sky/ground reflection
525
+ var hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444477, 0.3);
526
+ component.scene.add(hemisphereLight);
527
+ logger.info('Scene lighting setup complete');
528
+ }
529
+
530
+ /**
531
+ * Create ground plane
532
+ */
533
+ }, {
534
+ key: "createGround",
535
+ value: function createGround() {
536
+ var component = this.component;
537
+ if (!component || !component.scene) {
538
+ logger.warn('Cannot create ground: component or scene not available');
539
+ return null;
540
+ }
541
+
542
+ // Create a ground plane
543
+ var groundGeometry = new THREE.PlaneGeometry(100, 100);
544
+ var groundMaterial = new THREE.MeshStandardMaterial({
545
+ color: 0xcccccc,
546
+ roughness: 0.8,
547
+ metalness: 0.2,
548
+ side: THREE.DoubleSide
549
+ });
550
+ var ground = new THREE.Mesh(groundGeometry, groundMaterial);
551
+ ground.rotation.x = -Math.PI / 2; // Rotate to be horizontal
552
+ ground.position.y = -0.01; // Slightly below origin
553
+ ground.receiveShadow = true;
554
+
555
+ // Set user data for identification
556
+ ground.userData = {
557
+ isEnvironmentObject: true,
558
+ type: 'ground'
559
+ };
560
+ component.scene.add(ground);
561
+ logger.info('Ground plane created');
562
+ return ground;
563
+ }
564
+
565
+ /**
566
+ * Create walls for the environment
567
+ */
568
+ }, {
569
+ key: "createWalls",
570
+ value: function createWalls() {
571
+ var component = this.component;
572
+ if (!component || !component.scene) {
573
+ logger.warn('Cannot create walls: component or scene not available');
574
+ return [];
575
+ }
576
+ var walls = [];
577
+ var wallHeight = 20;
578
+ var roomSize = 50;
579
+ var wallThickness = 1;
580
+ var wallColor = 0xdddddd;
581
+
582
+ // Wall materials
583
+ var wallMaterial = new THREE.MeshStandardMaterial({
584
+ color: wallColor,
585
+ roughness: 0.9,
586
+ metalness: 0.1,
587
+ side: THREE.DoubleSide
588
+ });
589
+
590
+ // Create walls (north, east, south, west)
591
+ var wallGeometries = [new THREE.BoxGeometry(roomSize, wallHeight, wallThickness),
592
+ // North
593
+ new THREE.BoxGeometry(wallThickness, wallHeight, roomSize),
594
+ // East
595
+ new THREE.BoxGeometry(roomSize, wallHeight, wallThickness),
596
+ // South
597
+ new THREE.BoxGeometry(wallThickness, wallHeight, roomSize) // West
598
+ ];
599
+ var wallPositions = [[0, wallHeight / 2, -roomSize / 2],
600
+ // North
601
+ [roomSize / 2, wallHeight / 2, 0],
602
+ // East
603
+ [0, wallHeight / 2, roomSize / 2],
604
+ // South
605
+ [-roomSize / 2, wallHeight / 2, 0] // West
606
+ ];
607
+ var wallNames = ['north-wall', 'east-wall', 'south-wall', 'west-wall'];
608
+
609
+ // Create each wall
610
+ for (var i = 0; i < 4; i++) {
611
+ var _wall$position;
612
+ var wall = new THREE.Mesh(wallGeometries[i], wallMaterial);
613
+ (_wall$position = wall.position).set.apply(_wall$position, _toConsumableArray(wallPositions[i]));
614
+ wall.receiveShadow = true;
615
+ wall.castShadow = true;
616
+
617
+ // Set user data for identification
618
+ wall.userData = {
619
+ isEnvironmentObject: true,
620
+ type: 'wall',
621
+ name: wallNames[i]
622
+ };
623
+ component.scene.add(wall);
624
+ walls.push(wall);
625
+ }
626
+ logger.info('Environment walls created');
627
+ return walls;
628
+ }
629
+
630
+ /**
631
+ * Set fog in the scene
632
+ */
633
+ }, {
634
+ key: "setFog",
635
+ value: function setFog() {
636
+ var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0xcccccc;
637
+ var density = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.01;
638
+ var component = this.component;
639
+ if (!component || !component.scene) {
640
+ logger.warn('Cannot set fog: component or scene not available');
641
+ return;
642
+ }
643
+ component.scene.fog = new THREE.FogExp2(color, density);
644
+ logger.info('Scene fog applied');
645
+ }
646
+ /**
647
+ * Initialize the default environment
648
+ */
649
+ }, {
650
+ key: "initializeEnvironment",
651
+ value: (function () {
652
+ var _initializeEnvironment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
653
+ var component, loadersReady, textureConfigReady, _t7;
654
+ return _regenerator().w(function (_context5) {
655
+ while (1) switch (_context5.n) {
656
+ case 0:
657
+ component = this.component; // Make sure loaders are initialized first
658
+ console.log('🚀 Initializing loaders for environment...');
659
+ _context5.p = 1;
660
+ _context5.n = 2;
661
+ return importThreeLoaders();
662
+ case 2:
663
+ loadersReady = _context5.v;
664
+ _context5.n = 3;
665
+ return importTextureConfig();
666
+ case 3:
667
+ textureConfigReady = _context5.v;
668
+ console.log('✅ Environment loaders initialized:', {
669
+ loaders: loadersReady ? 'Ready' : 'Failed',
670
+ textureConfig: textureConfigReady ? 'Ready' : 'Failed'
671
+ });
672
+ _context5.n = 5;
673
+ break;
674
+ case 4:
675
+ _context5.p = 4;
676
+ _t7 = _context5.v;
677
+ console.warn('⚠️ Error initializing environment loaders:', _t7);
678
+ case 5:
679
+ // Configure renderer for proper HDR rendering if it exists
680
+ if (component && component.renderer) {
681
+ // Ensure proper tone mapping is set for HDR
682
+ component.renderer.toneMapping = THREE.ACESFilmicToneMapping;
683
+ component.renderer.toneMappingExposure = 1.0;
684
+ // For all Three.js versions from r152+
685
+ if (component.renderer.outputColorSpace !== undefined) {
686
+ component.renderer.outputColorSpace = THREE.SRGBColorSpace;
687
+ }
688
+ // For older Three.js versions (legacy support)
689
+ else if (component.renderer.outputEncoding !== undefined) {
690
+ component.renderer.outputEncoding = THREE.sRGBEncoding;
691
+ }
692
+ logger.info("Renderer configured for HDR:\n - Tone mapping: ".concat(component.renderer.toneMapping, "\n - Color space: ").concat(component.renderer.outputColorSpace || component.renderer.outputEncoding));
693
+ }
694
+
695
+ // Create skybox (includes base lighting)
696
+ _context5.n = 6;
697
+ return this.createSkybox();
698
+ case 6:
699
+ // Add additional lighting
700
+ this.setupLighting();
701
+
702
+ // Use textured ground instead of basic ground
703
+ _context5.n = 7;
704
+ return this.addTexturedGround();
705
+ case 7:
706
+ // No walls or fog by default
707
+ // await this.addBrickWalls();
708
+ // this.addHorizonFog();
709
+
710
+ logger.info('Environment initialization complete');
711
+ case 8:
712
+ return _context5.a(2);
713
+ }
714
+ }, _callee3, this, [[1, 4]]);
715
+ }));
716
+ function initializeEnvironment() {
717
+ return _initializeEnvironment.apply(this, arguments);
718
+ }
719
+ return initializeEnvironment;
720
+ }()
721
+ /**
722
+ * Add textured ground with materials from textureConfig
723
+ */
724
+ )
725
+ }, {
726
+ key: "addTexturedGround",
727
+ value: (function () {
728
+ var _addTexturedGround = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
729
+ var component, groundMaterial, groundGeometry, ground, _t8;
730
+ return _regenerator().w(function (_context6) {
731
+ while (1) switch (_context6.n) {
732
+ case 0:
733
+ if (loadTextureSetAndCreateMaterial) {
734
+ _context6.n = 1;
735
+ break;
736
+ }
737
+ _context6.n = 1;
738
+ return importTextureConfig();
739
+ case 1:
740
+ component = this.component;
741
+ if (!(!component || !component.scene)) {
742
+ _context6.n = 2;
743
+ break;
744
+ }
745
+ logger.warn('Cannot create textured ground: component or scene not available');
746
+ return _context6.a(2, null);
747
+ case 2:
748
+ // Remove existing ground if present
749
+ component.scene.traverse(function (object) {
750
+ if (object.userData && object.userData.type === 'ground') {
751
+ component.scene.remove(object);
752
+ }
753
+ });
754
+ _context6.p = 3;
755
+ _context6.n = 4;
756
+ return loadTextureSetAndCreateMaterial(component, 'gravel_embedded_concrete');
757
+ case 4:
758
+ groundMaterial = _context6.v;
759
+ groundGeometry = new THREE.PlaneGeometry(100, 100);
760
+ ground = new THREE.Mesh(groundGeometry, groundMaterial);
761
+ ground.rotation.x = -Math.PI / 2; // Rotate to be horizontal
762
+ ground.position.y = -0.01; // Slightly below origin
763
+ ground.receiveShadow = true;
764
+
765
+ // Set user data for identification
766
+ ground.userData = {
767
+ isEnvironmentObject: true,
768
+ type: 'ground'
769
+ };
770
+ component.scene.add(ground);
771
+ logger.info('Textured ground created');
772
+ return _context6.a(2, ground);
773
+ case 5:
774
+ _context6.p = 5;
775
+ _t8 = _context6.v;
776
+ logger.error('Error creating textured ground:', _t8);
777
+ // Fallback to simple ground
778
+ return _context6.a(2, this.createGround());
779
+ }
780
+ }, _callee4, this, [[3, 5]]);
781
+ }));
782
+ function addTexturedGround() {
783
+ return _addTexturedGround.apply(this, arguments);
784
+ }
785
+ return addTexturedGround;
786
+ }()
787
+ /**
788
+ * Add brick walls with materials from textureConfig
789
+ */
790
+ )
791
+ }, {
792
+ key: "addBrickWalls",
793
+ value: (function () {
794
+ var _addBrickWalls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
795
+ var component, wallMaterial, walls, wallHeight, roomSize, wallThickness, wallGeometries, wallPositions, wallNames, i, _wall$position2, wall, _t9;
796
+ return _regenerator().w(function (_context7) {
797
+ while (1) switch (_context7.n) {
798
+ case 0:
799
+ if (loadTextureSetAndCreateMaterial) {
800
+ _context7.n = 1;
801
+ break;
802
+ }
803
+ _context7.n = 1;
804
+ return importTextureConfig();
805
+ case 1:
806
+ component = this.component;
807
+ if (!(!component || !component.scene)) {
808
+ _context7.n = 2;
809
+ break;
810
+ }
811
+ logger.warn('Cannot create brick walls: component or scene not available');
812
+ return _context7.a(2, []);
813
+ case 2:
814
+ // Remove existing walls if present
815
+ component.scene.traverse(function (object) {
816
+ if (object.userData && object.userData.type === 'wall') {
817
+ component.scene.remove(object);
818
+ }
819
+ });
820
+ _context7.p = 3;
821
+ _context7.n = 4;
822
+ return loadTextureSetAndCreateMaterial(component, 'brick');
823
+ case 4:
824
+ wallMaterial = _context7.v;
825
+ walls = [];
826
+ wallHeight = 20;
827
+ roomSize = 50;
828
+ wallThickness = 1; // Create walls (north, east, south, west)
829
+ wallGeometries = [new THREE.BoxGeometry(roomSize, wallHeight, wallThickness),
830
+ // North
831
+ new THREE.BoxGeometry(wallThickness, wallHeight, roomSize),
832
+ // East
833
+ new THREE.BoxGeometry(roomSize, wallHeight, wallThickness),
834
+ // South
835
+ new THREE.BoxGeometry(wallThickness, wallHeight, roomSize) // West
836
+ ];
837
+ wallPositions = [[0, wallHeight / 2, -roomSize / 2],
838
+ // North
839
+ [roomSize / 2, wallHeight / 2, 0],
840
+ // East
841
+ [0, wallHeight / 2, roomSize / 2],
842
+ // South
843
+ [-roomSize / 2, wallHeight / 2, 0] // West
844
+ ];
845
+ wallNames = ['north-wall', 'east-wall', 'south-wall', 'west-wall']; // Create each wall
846
+ for (i = 0; i < 4; i++) {
847
+ wall = new THREE.Mesh(wallGeometries[i], wallMaterial);
848
+ (_wall$position2 = wall.position).set.apply(_wall$position2, _toConsumableArray(wallPositions[i]));
849
+ wall.receiveShadow = true;
850
+ wall.castShadow = true;
851
+
852
+ // Set user data for identification
853
+ wall.userData = {
854
+ isEnvironmentObject: true,
855
+ type: 'wall',
856
+ name: wallNames[i]
857
+ };
858
+ component.scene.add(wall);
859
+ walls.push(wall);
860
+ }
861
+ logger.info('Textured environment walls created');
862
+ return _context7.a(2, walls);
863
+ case 5:
864
+ _context7.p = 5;
865
+ _t9 = _context7.v;
866
+ logger.error('Error creating brick walls:', _t9);
867
+ // Fallback to simple walls
868
+ return _context7.a(2, this.createWalls());
869
+ }
870
+ }, _callee5, this, [[3, 5]]);
871
+ }));
872
+ function addBrickWalls() {
873
+ return _addBrickWalls.apply(this, arguments);
874
+ }
875
+ return addBrickWalls;
876
+ }()
877
+ /**
878
+ * Add horizon fog effect
879
+ */
880
+ )
881
+ }, {
882
+ key: "addHorizonFog",
883
+ value: function addHorizonFog() {
884
+ var component = this.component;
885
+ if (!component || !component.scene) {
886
+ logger.warn('Cannot set horizon fog: component or scene not available');
887
+ return;
888
+ }
889
+
890
+ // Light blue-ish fog color
891
+ var fogColor = 0xd8e0ff;
892
+ // Less dense than the default fog
893
+ var fogDensity = 0.005;
894
+ component.scene.fog = new THREE.FogExp2(fogColor, fogDensity);
895
+ logger.info('Horizon fog applied');
896
+ }
897
+
898
+ /**
899
+ * Helper to check if a texture exists locally in static directory
900
+ * @param {string} path - Relative path to texture in static directory
901
+ * @returns {Promise<boolean>}
902
+ */
903
+ }, {
904
+ key: "checkLocalTextureExists",
905
+ value: (function () {
906
+ var _checkLocalTextureExists = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(path) {
907
+ return _regenerator().w(function (_context8) {
908
+ while (1) switch (_context8.n) {
909
+ case 0:
910
+ // Remove leading slash if present
911
+ if (path.startsWith('/')) {
912
+ path = path.substring(1);
913
+ }
914
+
915
+ // For browser environment
916
+ if (!(typeof window !== 'undefined')) {
917
+ _context8.n = 1;
918
+ break;
919
+ }
920
+ return _context8.a(2, new Promise(function (resolve) {
921
+ var img = new Image();
922
+ img.onload = function () {
923
+ return resolve(true);
924
+ };
925
+ img.onerror = function () {
926
+ return resolve(false);
927
+ };
928
+
929
+ // Create full path relative to app root
930
+ var fullPath = window.location.origin + '/' + path;
931
+ img.src = fullPath;
932
+
933
+ // Set a timeout in case the image load hangs
934
+ setTimeout(function () {
935
+ return resolve(false);
936
+ }, 2000);
937
+ }));
938
+ case 1:
939
+ return _context8.a(2, false);
940
+ }
941
+ }, _callee6);
942
+ }));
943
+ function checkLocalTextureExists(_x) {
944
+ return _checkLocalTextureExists.apply(this, arguments);
945
+ }
946
+ return checkLocalTextureExists;
947
+ }())
948
+ }]);
949
+ }();
950
+
951
+ // Create a singleton instance
952
+ var environmentManager = null;
953
+
954
+ /**
955
+ * Get the global environment manager instance
956
+ */
957
+ function getEnvironmentManager() {
958
+ var component = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
959
+ if (!environmentManager || component && environmentManager.component !== component) {
960
+ environmentManager = new EnvironmentManager(component);
961
+ }
962
+ return environmentManager;
963
+ }
964
+ var environmentManager$1 = {
965
+ EnvironmentManager: EnvironmentManager,
966
+ getEnvironmentManager: getEnvironmentManager,
967
+ // Default initialization method for ease of use
968
+ initializeEnvironment: function () {
969
+ var _initializeEnvironment2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(component) {
970
+ var manager;
971
+ return _regenerator().w(function (_context9) {
972
+ while (1) switch (_context9.n) {
973
+ case 0:
974
+ manager = getEnvironmentManager(component);
975
+ _context9.n = 1;
976
+ return manager.initializeEnvironment();
977
+ case 1:
978
+ return _context9.a(2, manager);
979
+ }
980
+ }, _callee7);
981
+ }));
982
+ function initializeEnvironment(_x2) {
983
+ return _initializeEnvironment2.apply(this, arguments);
984
+ }
985
+ return initializeEnvironment;
986
+ }()
987
+ };
988
+
989
+ export { EnvironmentManager, environmentManager$1 as default, getEnvironmentManager };