@2112-lab/central-plant 0.1.1 → 0.1.3

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 (55) hide show
  1. package/dist/bundle/index.js +1 -15140
  2. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -353
  3. package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1 -0
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1 -1292
  5. package/dist/cjs/node_modules/three/examples/jsm/controls/TransformControls.js +1 -1543
  6. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +1 -4374
  7. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +1 -465
  8. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +1 -117
  9. package/dist/cjs/src/animationManager.js +1 -121
  10. package/dist/cjs/src/componentManager.js +1 -151
  11. package/dist/cjs/src/debugLogger.js +1 -176
  12. package/dist/cjs/src/disposalManager.js +1 -185
  13. package/dist/cjs/src/environmentManager.js +1 -1308
  14. package/dist/cjs/src/hotReloadManager.js +1 -252
  15. package/dist/cjs/src/index.js +1 -128
  16. package/dist/cjs/src/keyboardControlsManager.js +1 -206
  17. package/dist/cjs/src/nameUtils.js +1 -106
  18. package/dist/cjs/src/pathfindingManager.js +1 -321
  19. package/dist/cjs/src/performanceMonitor.js +1 -718
  20. package/dist/cjs/src/sceneExportManager.js +1 -292
  21. package/dist/cjs/src/sceneInitializationManager.js +1 -540
  22. package/dist/cjs/src/textureConfig.js +1 -624
  23. package/dist/cjs/src/transformControlsManager.js +1 -851
  24. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +1 -328
  25. package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1 -0
  26. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1 -1287
  27. package/dist/esm/node_modules/three/examples/jsm/controls/TransformControls.js +1 -1537
  28. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +1 -4370
  29. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +1 -461
  30. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +1 -113
  31. package/dist/esm/src/animationManager.js +1 -112
  32. package/dist/esm/src/componentManager.js +1 -123
  33. package/dist/esm/src/debugLogger.js +1 -167
  34. package/dist/esm/src/disposalManager.js +1 -155
  35. package/dist/esm/src/environmentManager.js +1 -1282
  36. package/dist/esm/src/hotReloadManager.js +1 -244
  37. package/dist/esm/src/index.js +1 -118
  38. package/dist/esm/src/keyboardControlsManager.js +1 -196
  39. package/dist/esm/src/nameUtils.js +1 -99
  40. package/dist/esm/src/pathfindingManager.js +1 -295
  41. package/dist/esm/src/performanceMonitor.js +1 -712
  42. package/dist/esm/src/sceneExportManager.js +1 -286
  43. package/dist/esm/src/sceneInitializationManager.js +1 -513
  44. package/dist/esm/src/textureConfig.js +1 -595
  45. package/dist/esm/src/transformControlsManager.js +1 -827
  46. package/dist/index.d.ts +0 -4
  47. package/package.json +1 -1
  48. package/dist/cjs/src/ConnectionManager.js +0 -114
  49. package/dist/cjs/src/Pathfinder.js +0 -88
  50. package/dist/cjs/src/modelPreloader.js +0 -488
  51. package/dist/cjs/src/sceneOperationsManager.js +0 -596
  52. package/dist/esm/src/ConnectionManager.js +0 -110
  53. package/dist/esm/src/Pathfinder.js +0 -84
  54. package/dist/esm/src/modelPreloader.js +0 -464
  55. package/dist/esm/src/sceneOperationsManager.js +0 -572
@@ -1,1308 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
6
- var THREE = require('three');
7
- var debugLogger = require('./debugLogger.js');
8
-
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n["default"] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
28
-
29
- // We'll need to import RGBELoader from three examples
30
- var RGBELoader;
31
-
32
- /**
33
- * Helper function to get asset paths that works in both bundled and modular contexts
34
- * @param {string} assetPath - Relative path from the assets directory
35
- * @returns {string} - The full path to the asset
36
- */
37
- function getAssetPath(assetPath) {
38
- // Strip leading slash if present
39
- if (assetPath.startsWith('/')) {
40
- assetPath = assetPath.substring(1);
41
- }
42
-
43
- // In browser context, check for different module formats
44
- if (typeof window !== 'undefined') {
45
- // For bundled version, assets should be in dist/bundle/assets/
46
- // For ESM/CJS, assets should be in their respective folders
47
-
48
- // Try to determine if we're using the bundled version or ESM/CJS
49
- var isBundled = typeof CentralPlantUtils !== 'undefined';
50
-
51
- // Check if we're running in a Nuxt.js environment (localhost:3000 is a common dev server)
52
- var isNuxtEnv = window.location.hostname === 'localhost' && (window.location.port === '3000' || window.location.port === '3001');
53
- if (isNuxtEnv) {
54
- // In Nuxt.js environment, assets are likely in the /static directory at the root
55
- return "/".concat(assetPath); // No /assets/ prefix in the URL path
56
- } else if (isBundled) {
57
- // Get the base URL for the module
58
- var baseUrl = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || new URL('src/environmentManager.js', document.baseURI).href));
59
- // In bundled format, assets are in the assets folder next to the bundle
60
- return new URL("./assets/".concat(assetPath), baseUrl).href;
61
- } else {
62
- // Get the base URL for the module
63
- var _baseUrl = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || new URL('src/environmentManager.js', document.baseURI).href));
64
- // In ESM/CJS format, need to go up relative to current module path
65
- return new URL("../assets/".concat(assetPath), _baseUrl).href;
66
- }
67
- }
68
-
69
- // In Node.js context
70
- return "assets/".concat(assetPath);
71
- }
72
-
73
- // Dynamic import for browser compatibility
74
- function importThreeLoaders() {
75
- return _importThreeLoaders.apply(this, arguments);
76
- } // This will be imported once textureConfig is created
77
- function _importThreeLoaders() {
78
- _importThreeLoaders = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee8() {
79
- var module, _t0;
80
- return _rollupPluginBabelHelpers.regenerator().w(function (_context0) {
81
- while (1) switch (_context0.n) {
82
- case 0:
83
- if (!(typeof window !== 'undefined')) {
84
- _context0.n = 4;
85
- break;
86
- }
87
- _context0.p = 1;
88
- console.log('📦 Attempting to dynamically import RGBELoader...');
89
- // Dynamic import for browser
90
- _context0.n = 2;
91
- return Promise.resolve().then(function () { return require('../node_modules/three/examples/jsm/loaders/RGBELoader.js'); });
92
- case 2:
93
- module = _context0.v;
94
- RGBELoader = module.RGBELoader;
95
- console.log('✅ RGBELoader imported successfully:', RGBELoader ? 'Available' : 'Undefined');
96
- return _context0.a(2, true);
97
- case 3:
98
- _context0.p = 3;
99
- _t0 = _context0.v;
100
- console.error('Failed to load Three.js loaders:', _t0);
101
- throw new Error('Failed to load Three.js loaders');
102
- case 4:
103
- return _context0.a(2, false);
104
- }
105
- }, _callee8, null, [[1, 3]]);
106
- }));
107
- return _importThreeLoaders.apply(this, arguments);
108
- }
109
- var textureConfig = {
110
- loadTextureSetAndCreateMaterial: null,
111
- checkThreeJSCompatibility: null,
112
- forceUpdateMaterials: null
113
- };
114
- function importTextureConfig() {
115
- return _importTextureConfig.apply(this, arguments);
116
- }
117
- function _importTextureConfig() {
118
- _importTextureConfig = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee9() {
119
- var module, importedFunctions, _t1;
120
- return _rollupPluginBabelHelpers.regenerator().w(function (_context1) {
121
- while (1) switch (_context1.n) {
122
- case 0:
123
- if (!(typeof window !== 'undefined')) {
124
- _context1.n = 4;
125
- break;
126
- }
127
- _context1.p = 1;
128
- console.log('📦 Attempting to dynamically import textureConfig...');
129
- _context1.n = 2;
130
- return Promise.resolve().then(function () { return require('./textureConfig.js'); });
131
- case 2:
132
- module = _context1.v;
133
- // Store all exported functions
134
- textureConfig.loadTextureSetAndCreateMaterial = module.loadTextureSetAndCreateMaterial;
135
- textureConfig.checkThreeJSCompatibility = module.checkThreeJSCompatibility;
136
- textureConfig.forceUpdateMaterials = module.forceUpdateMaterials;
137
-
138
- // Check what was successfully imported
139
- importedFunctions = Object.entries(textureConfig).filter(function (_ref2) {
140
- var _ref3 = _rollupPluginBabelHelpers.slicedToArray(_ref2, 2);
141
- _ref3[0];
142
- var fn = _ref3[1];
143
- return typeof fn === 'function';
144
- }).map(function (_ref4) {
145
- var _ref5 = _rollupPluginBabelHelpers.slicedToArray(_ref4, 1),
146
- name = _ref5[0];
147
- return name;
148
- });
149
- console.log("\u2705 TextureConfig imported successfully with functions: ".concat(importedFunctions.join(', ')));
150
-
151
- // Run compatibility check if available
152
- if (typeof textureConfig.checkThreeJSCompatibility === 'function') {
153
- textureConfig.checkThreeJSCompatibility();
154
- }
155
- return _context1.a(2, true);
156
- case 3:
157
- _context1.p = 3;
158
- _t1 = _context1.v;
159
- console.error('Failed to load texture config:', _t1);
160
- return _context1.a(2, false);
161
- case 4:
162
- return _context1.a(2, false);
163
- }
164
- }, _callee9, null, [[1, 3]]);
165
- }));
166
- return _importTextureConfig.apply(this, arguments);
167
- }
168
- var EnvironmentManager = /*#__PURE__*/function () {
169
- function EnvironmentManager(component) {
170
- _rollupPluginBabelHelpers.classCallCheck(this, EnvironmentManager);
171
- this.component = component;
172
-
173
- // Track loader status
174
- this.loadersInitialized = false;
175
-
176
- // Initialize loaders immediately
177
- this.initLoaders();
178
- }
179
- return _rollupPluginBabelHelpers.createClass(EnvironmentManager, [{
180
- key: "initLoaders",
181
- value: function () {
182
- var _initLoaders = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee() {
183
- var _t;
184
- return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
185
- while (1) switch (_context.n) {
186
- case 0:
187
- console.log('🔄 Pre-initializing loaders in EnvironmentManager constructor...');
188
- _context.p = 1;
189
- _context.n = 2;
190
- return Promise.all([importThreeLoaders(), importTextureConfig()]);
191
- case 2:
192
- this.loadersInitialized = true;
193
- console.log('✅ EnvironmentManager loaders pre-initialized successfully');
194
- _context.n = 4;
195
- break;
196
- case 3:
197
- _context.p = 3;
198
- _t = _context.v;
199
- console.warn('⚠️ Error pre-initializing loaders:', _t);
200
- case 4:
201
- return _context.a(2);
202
- }
203
- }, _callee, this, [[1, 3]]);
204
- }));
205
- function initLoaders() {
206
- return _initLoaders.apply(this, arguments);
207
- }
208
- return initLoaders;
209
- }()
210
- /**
211
- * Create skybox with HDR environment mapping
212
- */
213
- }, {
214
- key: "createSkybox",
215
- value: (function () {
216
- var _createSkybox = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2() {
217
- var _this = this;
218
- var component, isContextLost, pmremGenerator, hdrPath1, hdrPath2, jpgPath, loaders, applyEnvironmentMap, _loop, _ret, _i, _loaders, _t4, _t5, _t6;
219
- return _rollupPluginBabelHelpers.regenerator().w(function (_context4) {
220
- while (1) switch (_context4.n) {
221
- case 0:
222
- component = this.component;
223
- if (!(!component || !component.renderer || !component.scene)) {
224
- _context4.n = 1;
225
- break;
226
- }
227
- debugLogger.logger.warn('Cannot create skybox: component, renderer or scene not available');
228
- return _context4.a(2);
229
- case 1:
230
- console.log('🌍 Starting skybox creation process...');
231
-
232
- // Make sure RGBELoader is available
233
- if (RGBELoader) {
234
- _context4.n = 5;
235
- break;
236
- }
237
- console.log('⏳ RGBELoader not loaded yet, initializing now...');
238
- _context4.p = 2;
239
- _context4.n = 3;
240
- return importThreeLoaders();
241
- case 3:
242
- console.log('✅ RGBELoader loaded on demand');
243
- _context4.n = 5;
244
- break;
245
- case 4:
246
- _context4.p = 4;
247
- _t4 = _context4.v;
248
- console.error('❌ Failed to load RGBELoader:', _t4);
249
- this.createFallbackEnvironment();
250
- return _context4.a(2);
251
- case 5:
252
- _context4.p = 5;
253
- // Check if renderer is valid - safely check for context loss
254
- isContextLost = component.renderer.context && typeof component.renderer.context.isContextLost === 'function' ? component.renderer.context.isContextLost() : false;
255
- console.log('🔍 WebGL context check:', isContextLost ? 'Context lost' : 'Context valid');
256
- if (!(!component.renderer.capabilities || isContextLost)) {
257
- _context4.n = 6;
258
- break;
259
- }
260
- debugLogger.logger.warn('WebGL context is lost or invalid, using fallback environment');
261
- this.createFallbackEnvironment();
262
- return _context4.a(2);
263
- case 6:
264
- _context4.p = 6;
265
- pmremGenerator = new THREE__namespace.PMREMGenerator(component.renderer);
266
-
267
- // Check if the generator was created successfully
268
- if (pmremGenerator) {
269
- _context4.n = 7;
270
- break;
271
- }
272
- throw new Error('PMREMGenerator could not be created');
273
- case 7:
274
- // Attempt to compile the shader - this can fail if the context is limited
275
- pmremGenerator.compileEquirectangularShader();
276
- _context4.n = 9;
277
- break;
278
- case 8:
279
- _context4.p = 8;
280
- _t5 = _context4.v;
281
- debugLogger.logger.warn('Failed to initialize PMREMGenerator:', _t5);
282
- this.createFallbackEnvironment();
283
- return _context4.a(2);
284
- case 9:
285
- // Get resolved paths for better debugging
286
- hdrPath1 = getAssetPath('skyboxes/kloofendal_48d_partly_cloudy_puresky_2k.hdr');
287
- hdrPath2 = getAssetPath('skyboxes/kloofendal_48d_partly_cloudy_puresky_1k.hdr');
288
- jpgPath = getAssetPath('skyboxes/sky_fallback.jpg');
289
- console.log('🔍 Resolved HDR paths:', {
290
- hdr2k: hdrPath1,
291
- hdr1k: hdrPath2,
292
- jpg: jpgPath
293
- });
294
- loaders = [{
295
- type: 'hdr',
296
- loader: new RGBELoader(),
297
- paths: [hdrPath1, hdrPath2]
298
- }, {
299
- type: 'jpeg',
300
- loader: component.textureLoader || new THREE__namespace.TextureLoader(),
301
- paths: [jpgPath]
302
- }]; // Configure texture loaders with CORS settings
303
- loaders.forEach(function (_ref) {
304
- var loader = _ref.loader;
305
- if (loader && typeof loader.setCrossOrigin === 'function') {
306
- loader.setCrossOrigin('anonymous');
307
- }
308
- });
309
- console.log('🔄 Configured loaders with CORS settings and fallback paths');
310
- applyEnvironmentMap = function applyEnvironmentMap(envTexture, type) {
311
- try {
312
- var _component$scene$envi, _component$scene$back;
313
- // Set proper mapping
314
- envTexture.mapping = THREE__namespace.EquirectangularReflectionMapping;
315
- // Ensure a valid color space is set for the texture
316
- if (envTexture.colorSpace !== undefined) {
317
- // For Three.js >= r152 (current version)
318
- envTexture.colorSpace = component.renderer.outputColorSpace || THREE__namespace.SRGBColorSpace;
319
- } else if (envTexture.encoding !== undefined) {
320
- // For older versions (legacy support)
321
- envTexture.encoding = component.renderer.outputEncoding || THREE__namespace.sRGBEncoding;
322
- }
323
-
324
- // Generate processed environment map
325
- var processedEnvMap = pmremGenerator.fromEquirectangular(envTexture).texture;
326
-
327
- // Diagnostic logging
328
- debugLogger.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));
329
-
330
- // Clean up previous environment/background
331
- if ((_component$scene$envi = component.scene.environment) !== null && _component$scene$envi !== void 0 && _component$scene$envi.dispose) component.scene.environment.dispose();
332
- if ((_component$scene$back = component.scene.background) !== null && _component$scene$back !== void 0 && _component$scene$back.dispose) component.scene.background.dispose();
333
-
334
- // Apply to scene
335
- component.scene.environment = processedEnvMap;
336
- component.scene.background = processedEnvMap;
337
-
338
- // Clean up original texture
339
- envTexture.dispose();
340
-
341
- // Force a renderer update
342
- if (component.renderer) {
343
- component.renderer.toneMappingExposure = 1.0;
344
- component.renderer.render(component.scene, component.camera);
345
- }
346
- debugLogger.logger.info("Environment map (".concat(type, ") applied successfully"));
347
- return true;
348
- } catch (error) {
349
- debugLogger.logger.warn("Failed to apply ".concat(type, " environment map:"), error);
350
- return false;
351
- }
352
- };
353
- _loop = /*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _loop() {
354
- var _loaders$_i, type, loader, paths, _iterator, _step, _loop2, _ret2, _t3;
355
- return _rollupPluginBabelHelpers.regenerator().w(function (_context3) {
356
- while (1) switch (_context3.n) {
357
- case 0:
358
- _loaders$_i = _loaders[_i], type = _loaders$_i.type, loader = _loaders$_i.loader, paths = _loaders$_i.paths;
359
- _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(paths);
360
- _context3.p = 1;
361
- _loop2 = /*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _loop2() {
362
- var path, exists, texture, _t2;
363
- return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
364
- while (1) switch (_context2.n) {
365
- case 0:
366
- path = _step.value;
367
- _context2.p = 1;
368
- if (!(path.startsWith('/') && !path.includes('://'))) {
369
- _context2.n = 3;
370
- break;
371
- }
372
- _context2.n = 2;
373
- return _this.checkLocalTextureExists(path);
374
- case 2:
375
- exists = _context2.v;
376
- console.log("\uD83D\uDD0D Local texture check for ".concat(path, ": ").concat(exists ? 'Available' : 'Not found'));
377
- if (exists) {
378
- _context2.n = 3;
379
- break;
380
- }
381
- return _context2.a(2, 0);
382
- case 3:
383
- debugLogger.logger.info("Attempting to load ".concat(type, " texture: ").concat(path));
384
- _context2.n = 4;
385
- return new Promise(function (resolve, reject) {
386
- var timeout = setTimeout(function () {
387
- return reject(new Error("Timeout loading ".concat(path)));
388
- }, 10000);
389
-
390
- // Add event listeners for better diagnostics
391
- var onProgress = function onProgress(event) {
392
- if (event.lengthComputable) {
393
- var percentComplete = event.loaded / event.total * 100;
394
- console.log("Loading ".concat(path, ": ").concat(Math.round(percentComplete), "% complete"));
395
- }
396
- };
397
- loader.load(path, function (tex) {
398
- clearTimeout(timeout);
399
- console.log("\u2705 Successfully loaded ".concat(type, " texture: ").concat(path));
400
- resolve(tex);
401
- }, onProgress, function (err) {
402
- clearTimeout(timeout);
403
- console.warn("\u274C Failed to load ".concat(path, ":"), err.message);
404
- reject(err);
405
- });
406
- });
407
- case 4:
408
- texture = _context2.v;
409
- if (!applyEnvironmentMap(texture, type)) {
410
- _context2.n = 5;
411
- break;
412
- }
413
- pmremGenerator.dispose();
414
- return _context2.a(2, {
415
- v: {
416
- v: void 0
417
- }
418
- });
419
- case 5:
420
- _context2.n = 7;
421
- break;
422
- case 6:
423
- _context2.p = 6;
424
- _t2 = _context2.v;
425
- debugLogger.logger.warn("Failed to load ".concat(path, ":"), _t2.message);
426
- case 7:
427
- return _context2.a(2);
428
- }
429
- }, _loop2, null, [[1, 6]]);
430
- });
431
- _iterator.s();
432
- case 2:
433
- if ((_step = _iterator.n()).done) {
434
- _context3.n = 6;
435
- break;
436
- }
437
- return _context3.d(_rollupPluginBabelHelpers.regeneratorValues(_loop2()), 3);
438
- case 3:
439
- _ret2 = _context3.v;
440
- if (!(_ret2 === 0)) {
441
- _context3.n = 4;
442
- break;
443
- }
444
- return _context3.a(3, 5);
445
- case 4:
446
- if (!_ret2) {
447
- _context3.n = 5;
448
- break;
449
- }
450
- return _context3.a(2, _ret2.v);
451
- case 5:
452
- _context3.n = 2;
453
- break;
454
- case 6:
455
- _context3.n = 8;
456
- break;
457
- case 7:
458
- _context3.p = 7;
459
- _t3 = _context3.v;
460
- _iterator.e(_t3);
461
- case 8:
462
- _context3.p = 8;
463
- _iterator.f();
464
- return _context3.f(8);
465
- case 9:
466
- return _context3.a(2);
467
- }
468
- }, _loop, null, [[1, 7, 8, 9]]);
469
- });
470
- _i = 0, _loaders = loaders;
471
- case 10:
472
- if (!(_i < _loaders.length)) {
473
- _context4.n = 13;
474
- break;
475
- }
476
- return _context4.d(_rollupPluginBabelHelpers.regeneratorValues(_loop()), 11);
477
- case 11:
478
- _ret = _context4.v;
479
- if (!_ret) {
480
- _context4.n = 12;
481
- break;
482
- }
483
- return _context4.a(2, _ret.v);
484
- case 12:
485
- _i++;
486
- _context4.n = 10;
487
- break;
488
- case 13:
489
- // If we reached here, all texture attempts failed - use procedural sky
490
- this.createProceduralSky(pmremGenerator);
491
- _context4.n = 15;
492
- break;
493
- case 14:
494
- _context4.p = 14;
495
- _t6 = _context4.v;
496
- debugLogger.logger.error('Error creating skybox:', _t6);
497
- this.createFallbackEnvironment();
498
- case 15:
499
- return _context4.a(2);
500
- }
501
- }, _callee2, this, [[6, 8], [5, 14], [2, 4]]);
502
- }));
503
- function createSkybox() {
504
- return _createSkybox.apply(this, arguments);
505
- }
506
- return createSkybox;
507
- }()
508
- /**
509
- * Create a fallback environment when renderer issues occur
510
- */
511
- )
512
- }, {
513
- key: "createFallbackEnvironment",
514
- value: function createFallbackEnvironment() {
515
- var component = this.component;
516
- if (!component || !component.scene) return;
517
- debugLogger.logger.info('Creating basic fallback environment');
518
- // Add simple ambient and directional light
519
- var ambientLight = new THREE__namespace.AmbientLight(0xffffff, 0.6);
520
- component.scene.add(ambientLight);
521
- var directionalLight = new THREE__namespace.DirectionalLight(0xffffff, 0.8);
522
- directionalLight.position.set(1, 2, 3);
523
- component.scene.add(directionalLight);
524
-
525
- // Set a simple background color
526
- component.scene.background = new THREE__namespace.Color(0x87CEEB);
527
- }
528
-
529
- /**
530
- * Create procedural sky when textures fail to load
531
- */
532
- }, {
533
- key: "createProceduralSky",
534
- value: function createProceduralSky(pmremGenerator) {
535
- var component = this.component;
536
- if (!component || !component.scene) return;
537
- debugLogger.logger.info('Using procedural sky fallback');
538
- var ambientLight = new THREE__namespace.AmbientLight(0xffffff, 0.6);
539
- component.scene.add(ambientLight);
540
-
541
- // Add a directional light for better illumination
542
- var directionalLight = new THREE__namespace.DirectionalLight(0xffffff, 0.8);
543
- directionalLight.position.set(1, 1, 1);
544
- component.scene.add(directionalLight);
545
- try {
546
- // Only attempt PMREM generation if we have a valid pmremGenerator
547
- if (pmremGenerator && typeof pmremGenerator.fromScene === 'function') {
548
- var skyScene = new THREE__namespace.Scene();
549
- skyScene.add(new THREE__namespace.HemisphereLight(0x87CEEB, 0x444477, 1));
550
-
551
- // Generate environment map from scene
552
- var envMap = pmremGenerator.fromScene(skyScene);
553
- if (envMap && envMap.texture) {
554
- component.scene.environment = envMap.texture;
555
- }
556
- }
557
-
558
- // Always set a background color as fallback
559
- component.scene.background = new THREE__namespace.Color(0x87CEEB);
560
- } catch (error) {
561
- debugLogger.logger.warn('Failed to create procedural sky, using simple background', error);
562
- component.scene.background = new THREE__namespace.Color(0x87CEEB);
563
- } finally {
564
- if (pmremGenerator && typeof pmremGenerator.dispose === 'function') {
565
- pmremGenerator.dispose();
566
- }
567
- }
568
- }
569
-
570
- /**
571
- * Setup scene lighting
572
- */
573
- }, {
574
- key: "setupLighting",
575
- value: function setupLighting() {
576
- var component = this.component;
577
- if (!component || !component.scene) {
578
- debugLogger.logger.warn('Cannot setup lighting: component or scene not available');
579
- return;
580
- }
581
-
582
- // Remove existing lights first
583
- var existingLights = [];
584
- component.scene.traverse(function (object) {
585
- if (object instanceof THREE__namespace.Light) {
586
- existingLights.push(object);
587
- }
588
- });
589
- existingLights.forEach(function (light) {
590
- component.scene.remove(light);
591
- });
592
-
593
- // Main directional light (sun)
594
- var directionalLight = new THREE__namespace.DirectionalLight(0xffffff, 0.8);
595
- directionalLight.position.set(5, 10, 7);
596
- directionalLight.castShadow = true;
597
-
598
- // Optimize shadow map
599
- directionalLight.shadow.mapSize.width = 1024;
600
- directionalLight.shadow.mapSize.height = 1024;
601
- directionalLight.shadow.camera.near = 1;
602
- directionalLight.shadow.camera.far = 30;
603
- directionalLight.shadow.camera.left = -10;
604
- directionalLight.shadow.camera.right = 10;
605
- directionalLight.shadow.camera.top = 10;
606
- directionalLight.shadow.camera.bottom = -10;
607
- directionalLight.shadow.bias = -0.001;
608
- component.scene.add(directionalLight);
609
-
610
- // Ambient light for general illumination
611
- var ambientLight = new THREE__namespace.AmbientLight(0xffffff, 0.3);
612
- component.scene.add(ambientLight);
613
-
614
- // Hemisphere light to simulate sky/ground reflection
615
- var hemisphereLight = new THREE__namespace.HemisphereLight(0xffffff, 0x444477, 0.3);
616
- component.scene.add(hemisphereLight);
617
- debugLogger.logger.info('Scene lighting setup complete');
618
- }
619
-
620
- /**
621
- * Create ground plane
622
- */
623
- }, {
624
- key: "createGround",
625
- value: function createGround() {
626
- var component = this.component;
627
- if (!component || !component.scene) {
628
- debugLogger.logger.warn('Cannot create ground: component or scene not available');
629
- return null;
630
- }
631
-
632
- // Create a ground plane
633
- var groundGeometry = new THREE__namespace.PlaneGeometry(100, 100);
634
- var groundMaterial = new THREE__namespace.MeshStandardMaterial({
635
- color: 0xcccccc,
636
- roughness: 0.8,
637
- metalness: 0.2,
638
- side: THREE__namespace.DoubleSide
639
- });
640
- var ground = new THREE__namespace.Mesh(groundGeometry, groundMaterial);
641
- ground.rotation.x = -Math.PI / 2; // Rotate to be horizontal
642
- ground.position.y = -0.01; // Slightly below origin
643
- ground.receiveShadow = true;
644
-
645
- // Set user data for identification
646
- ground.userData = {
647
- isEnvironmentObject: true,
648
- type: 'ground'
649
- };
650
- component.scene.add(ground);
651
- debugLogger.logger.info('Ground plane created');
652
- return ground;
653
- }
654
-
655
- /**
656
- * Create walls for the environment
657
- */
658
- }, {
659
- key: "createWalls",
660
- value: function createWalls() {
661
- var component = this.component;
662
- if (!component || !component.scene) {
663
- debugLogger.logger.warn('Cannot create walls: component or scene not available');
664
- return [];
665
- }
666
- var walls = [];
667
- var wallHeight = 20;
668
- var roomSize = 50;
669
- var wallThickness = 1;
670
- var wallColor = 0xdddddd;
671
-
672
- // Wall materials
673
- var wallMaterial = new THREE__namespace.MeshStandardMaterial({
674
- color: wallColor,
675
- roughness: 0.9,
676
- metalness: 0.1,
677
- side: THREE__namespace.DoubleSide
678
- });
679
-
680
- // Create walls (north, east, south, west)
681
- var wallGeometries = [new THREE__namespace.BoxGeometry(roomSize, wallHeight, wallThickness),
682
- // North
683
- new THREE__namespace.BoxGeometry(wallThickness, wallHeight, roomSize),
684
- // East
685
- new THREE__namespace.BoxGeometry(roomSize, wallHeight, wallThickness),
686
- // South
687
- new THREE__namespace.BoxGeometry(wallThickness, wallHeight, roomSize) // West
688
- ];
689
- var wallPositions = [[0, wallHeight / 2, -roomSize / 2],
690
- // North
691
- [roomSize / 2, wallHeight / 2, 0],
692
- // East
693
- [0, wallHeight / 2, roomSize / 2],
694
- // South
695
- [-roomSize / 2, wallHeight / 2, 0] // West
696
- ];
697
- var wallNames = ['north-wall', 'east-wall', 'south-wall', 'west-wall'];
698
-
699
- // Create each wall
700
- for (var i = 0; i < 4; i++) {
701
- var _wall$position;
702
- var wall = new THREE__namespace.Mesh(wallGeometries[i], wallMaterial);
703
- (_wall$position = wall.position).set.apply(_wall$position, _rollupPluginBabelHelpers.toConsumableArray(wallPositions[i]));
704
- wall.receiveShadow = true;
705
- wall.castShadow = true;
706
-
707
- // Set user data for identification
708
- wall.userData = {
709
- isEnvironmentObject: true,
710
- type: 'wall',
711
- name: wallNames[i]
712
- };
713
- component.scene.add(wall);
714
- walls.push(wall);
715
- }
716
- debugLogger.logger.info('Environment walls created');
717
- return walls;
718
- }
719
-
720
- /**
721
- * Set fog in the scene
722
- */
723
- }, {
724
- key: "setFog",
725
- value: function setFog() {
726
- var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0xcccccc;
727
- var density = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.01;
728
- var component = this.component;
729
- if (!component || !component.scene) {
730
- debugLogger.logger.warn('Cannot set fog: component or scene not available');
731
- return;
732
- }
733
- component.scene.fog = new THREE__namespace.FogExp2(color, density);
734
- debugLogger.logger.info('Scene fog applied');
735
- } /**
736
- * Initialize the default environment
737
- */
738
- }, {
739
- key: "initializeEnvironment",
740
- value: (function () {
741
- var _initializeEnvironment = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee3() {
742
- var _this2 = this;
743
- var component, loadersReady, textureConfigReady, ground, walls, _t7;
744
- return _rollupPluginBabelHelpers.regenerator().w(function (_context5) {
745
- while (1) switch (_context5.n) {
746
- case 0:
747
- component = this.component; // Make sure loaders are initialized first
748
- console.log('🚀 Initializing loaders for environment...');
749
- _context5.p = 1;
750
- _context5.n = 2;
751
- return importThreeLoaders();
752
- case 2:
753
- loadersReady = _context5.v;
754
- _context5.n = 3;
755
- return importTextureConfig();
756
- case 3:
757
- textureConfigReady = _context5.v;
758
- console.log('✅ Environment loaders initialized:', {
759
- loaders: loadersReady ? 'Ready' : 'Failed',
760
- textureConfig: textureConfigReady ? 'Ready' : 'Failed'
761
- });
762
- _context5.n = 5;
763
- break;
764
- case 4:
765
- _context5.p = 4;
766
- _t7 = _context5.v;
767
- console.warn('⚠️ Error initializing environment loaders:', _t7);
768
- case 5:
769
- if (component) {
770
- _context5.n = 6;
771
- break;
772
- }
773
- debugLogger.logger.error('❌ Cannot initialize environment: component is null');
774
- return _context5.a(2);
775
- case 6:
776
- if (component.renderer) {
777
- _context5.n = 7;
778
- break;
779
- }
780
- debugLogger.logger.error('❌ Cannot initialize environment: renderer is null');
781
- return _context5.a(2);
782
- case 7:
783
- // Configure renderer for proper HDR rendering
784
- console.log('🎨 Configuring renderer for environment...');
785
-
786
- // Don't override existing settings from sceneInitializationManager
787
- // Just ensure we have reasonable values set
788
- if (!component.renderer.toneMapping) {
789
- component.renderer.toneMapping = THREE__namespace.ACESFilmicToneMapping;
790
- }
791
- component.renderer.toneMappingExposure = 1.0;
792
-
793
- // Ensure correct color space is set based on Three.js version
794
- if (component.renderer.outputColorSpace !== undefined) {
795
- component.renderer.outputColorSpace = THREE__namespace.SRGBColorSpace; // For newer Three.js
796
- console.log('✅ Set SRGBColorSpace for renderer (newer Three.js)');
797
- } else if (component.renderer.outputEncoding !== undefined) {
798
- component.renderer.outputEncoding = THREE__namespace.sRGBEncoding; // For older Three.js
799
- console.log('✅ Set sRGBEncoding for renderer (older Three.js)');
800
- }
801
- debugLogger.logger.info("Renderer configured for HDR:\n - Tone mapping: ".concat(component.renderer.toneMapping, "\n - Color space: ").concat(component.renderer.outputColorSpace || component.renderer.outputEncoding));
802
-
803
- // Create skybox (includes base lighting)
804
- _context5.n = 8;
805
- return this.createSkybox();
806
- case 8:
807
- // Add additional lighting
808
- this.setupLighting();
809
-
810
- // Use textured ground instead of basic ground
811
- console.log('🌍 Creating ground with texture...');
812
- _context5.n = 9;
813
- return this.addTexturedGround();
814
- case 9:
815
- ground = _context5.v;
816
- if (!ground) {
817
- debugLogger.logger.error('❌ Failed to create textured ground');
818
- } else {
819
- debugLogger.logger.info('✅ Ground created successfully');
820
- }
821
-
822
- // Add walls with textures
823
- console.log('🧱 Creating walls with textures...');
824
- _context5.n = 10;
825
- return this.addBrickWalls();
826
- case 10:
827
- walls = _context5.v;
828
- if (!walls || walls.length === 0) {
829
- debugLogger.logger.warn('⚠️ No walls were created');
830
- } else {
831
- debugLogger.logger.info("\u2705 Created ".concat(walls.length, " walls"));
832
- }
833
-
834
- // Add atmospheric fog
835
- this.addHorizonFog();
836
- debugLogger.logger.info('Environment initialization complete'); // Force material refresh to ensure textures are applied correctly
837
- this.forceRefreshMaterials();
838
-
839
- // Force renderer refresh
840
- if (component.renderer && component.scene && component.camera) {
841
- component.renderer.render(component.scene, component.camera);
842
- console.log('🔄 Forced initial render to refresh scene');
843
-
844
- // Schedule another render after a short delay to catch any async texture loading
845
- setTimeout(function () {
846
- if (component.renderer && !component.isDestroyed) {
847
- _this2.forceRefreshMaterials();
848
- component.renderer.render(component.scene, component.camera);
849
- console.log('🔄 Performed delayed render to catch async texture loads');
850
- }
851
- }, 1000);
852
- }
853
- case 11:
854
- return _context5.a(2);
855
- }
856
- }, _callee3, this, [[1, 4]]);
857
- }));
858
- function initializeEnvironment() {
859
- return _initializeEnvironment.apply(this, arguments);
860
- }
861
- return initializeEnvironment;
862
- }()
863
- /**
864
- * Add textured ground with materials from textureConfig
865
- */
866
- )
867
- }, {
868
- key: "addTexturedGround",
869
- value: (function () {
870
- var _addTexturedGround = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee4() {
871
- var component, groundMaterial, debugMaterial, groundGeometry, ground, debugGround, errorGeometry, errorMaterial, errorGround, _t8;
872
- return _rollupPluginBabelHelpers.regenerator().w(function (_context6) {
873
- while (1) switch (_context6.n) {
874
- case 0:
875
- if (textureConfig.loadTextureSetAndCreateMaterial) {
876
- _context6.n = 2;
877
- break;
878
- }
879
- console.log('🔄 TextureConfig module not yet loaded, importing now...');
880
- _context6.n = 1;
881
- return importTextureConfig();
882
- case 1:
883
- if (textureConfig.loadTextureSetAndCreateMaterial) {
884
- _context6.n = 2;
885
- break;
886
- }
887
- console.error('❌ Failed to load textureConfig module, falling back to basic ground');
888
- return _context6.a(2, this.createGround());
889
- case 2:
890
- component = this.component;
891
- if (!(!component || !component.scene)) {
892
- _context6.n = 3;
893
- break;
894
- }
895
- debugLogger.logger.warn('Cannot create textured ground: component or scene not available');
896
- return _context6.a(2, null);
897
- case 3:
898
- // Force texture loading with crossOrigin support
899
- if (!component.textureLoader) {
900
- console.log('🔄 Creating texture loader in component');
901
- component.textureLoader = new THREE__namespace.TextureLoader();
902
- component.textureLoader.setCrossOrigin('anonymous');
903
- }
904
-
905
- // Remove existing ground if present
906
- component.scene.traverse(function (object) {
907
- if (object.userData && object.userData.type === 'ground') {
908
- component.scene.remove(object);
909
- }
910
- });
911
- _context6.p = 4;
912
- console.log('🌍 Creating textured ground plane...');
913
- // Use the gravel_embedded_concrete texture set
914
- console.log('🔄 Loading ground material textures...');
915
- _context6.n = 5;
916
- return textureConfig.loadTextureSetAndCreateMaterial(component, 'gravel_embedded_concrete');
917
- case 5:
918
- groundMaterial = _context6.v;
919
- if (groundMaterial) {
920
- _context6.n = 6;
921
- break;
922
- }
923
- throw new Error('Failed to create ground material');
924
- case 6:
925
- console.log('✅ Ground material created');
926
-
927
- // First create a colored material to verify the mesh creation works
928
- debugMaterial = new THREE__namespace.MeshBasicMaterial({
929
- color: 0x22ff22,
930
- // Bright green for visibility
931
- wireframe: false,
932
- side: THREE__namespace.DoubleSide
933
- }); // Create a composite ground with both materials
934
- groundGeometry = new THREE__namespace.PlaneGeometry(100, 100); // Create the main ground mesh
935
- ground = new THREE__namespace.Mesh(groundGeometry, groundMaterial);
936
- ground.rotation.x = -Math.PI / 2; // Rotate to be horizontal
937
- ground.position.y = -0.01; // Slightly below origin
938
- ground.receiveShadow = true;
939
-
940
- // Create a debug ground mesh slightly below the main ground
941
- debugGround = new THREE__namespace.Mesh(groundGeometry, debugMaterial);
942
- debugGround.rotation.x = -Math.PI / 2;
943
- debugGround.position.y = -0.02; // Below the main ground
944
- debugGround.visible = false; // Hide by default
945
-
946
- // Set user data for identification
947
- ground.userData = {
948
- isEnvironmentObject: true,
949
- isBaseGround: true,
950
- type: 'ground'
951
- };
952
- debugGround.userData = {
953
- isEnvironmentObject: true,
954
- type: 'ground-debug'
955
- };
956
-
957
- // Add both to scene
958
- component.scene.add(ground);
959
- component.scene.add(debugGround);
960
-
961
- // Log some properties about the created ground
962
- console.log('🌍 Textured ground created with properties:', {
963
- material: groundMaterial.type,
964
- hasMap: !!groundMaterial.map,
965
- hasNormalMap: !!groundMaterial.normalMap,
966
- hasRoughnessMap: !!groundMaterial.roughnessMap,
967
- hasMetalnessMap: !!groundMaterial.metalnessMap,
968
- hasAoMap: !!groundMaterial.aoMap,
969
- hasBumpMap: !!groundMaterial.bumpMap,
970
- materialColor: groundMaterial.color ? "#".concat(groundMaterial.color.getHexString()) : 'none'
971
- });
972
- debugLogger.logger.info('Textured ground created');
973
- return _context6.a(2, ground);
974
- case 7:
975
- _context6.p = 7;
976
- _t8 = _context6.v;
977
- debugLogger.logger.error('Error creating textured ground:', _t8);
978
- // Create a bright colored ground so it's obvious something was wrong
979
- errorGeometry = new THREE__namespace.PlaneGeometry(100, 100);
980
- errorMaterial = new THREE__namespace.MeshBasicMaterial({
981
- color: 0xff0000,
982
- wireframe: true,
983
- side: THREE__namespace.DoubleSide
984
- });
985
- errorGround = new THREE__namespace.Mesh(errorGeometry, errorMaterial);
986
- errorGround.rotation.x = -Math.PI / 2;
987
- errorGround.position.y = -0.01;
988
- errorGround.userData = {
989
- isEnvironmentObject: true,
990
- isBaseGround: true,
991
- type: 'ground-error'
992
- };
993
- component.scene.add(errorGround);
994
- console.error('⚠️ Fallback to error ground (red wireframe) due to texture loading failure:', _t8);
995
- return _context6.a(2, errorGround);
996
- }
997
- }, _callee4, this, [[4, 7]]);
998
- }));
999
- function addTexturedGround() {
1000
- return _addTexturedGround.apply(this, arguments);
1001
- }
1002
- return addTexturedGround;
1003
- }()
1004
- /**
1005
- * Add brick walls with materials from textureConfig
1006
- */
1007
- )
1008
- }, {
1009
- key: "addBrickWalls",
1010
- value: (function () {
1011
- var _addBrickWalls = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee5() {
1012
- var component, wallMaterial, walls, wallHeight, roomSize, wallThickness, wallGeometries, wallPositions, wallNames, i, _wall$position2, wall, _t9;
1013
- return _rollupPluginBabelHelpers.regenerator().w(function (_context7) {
1014
- while (1) switch (_context7.n) {
1015
- case 0:
1016
- if (textureConfig.loadTextureSetAndCreateMaterial) {
1017
- _context7.n = 2;
1018
- break;
1019
- }
1020
- console.log('🔄 TextureConfig module not yet loaded for brick walls, importing now...');
1021
- _context7.n = 1;
1022
- return importTextureConfig();
1023
- case 1:
1024
- if (textureConfig.loadTextureSetAndCreateMaterial) {
1025
- _context7.n = 2;
1026
- break;
1027
- }
1028
- console.error('❌ Failed to load textureConfig module for brick walls');
1029
- return _context7.a(2, this.createWalls());
1030
- case 2:
1031
- component = this.component;
1032
- if (!(!component || !component.scene)) {
1033
- _context7.n = 3;
1034
- break;
1035
- }
1036
- debugLogger.logger.warn('Cannot create brick walls: component or scene not available');
1037
- return _context7.a(2, []);
1038
- case 3:
1039
- // Remove existing walls if present
1040
- component.scene.traverse(function (object) {
1041
- if (object.userData && object.userData.type === 'wall') {
1042
- component.scene.remove(object);
1043
- }
1044
- });
1045
- _context7.p = 4;
1046
- // Use the brick texture set
1047
- console.log('🧱 Loading brick wall material textures...');
1048
- _context7.n = 5;
1049
- return textureConfig.loadTextureSetAndCreateMaterial(component, 'brick');
1050
- case 5:
1051
- wallMaterial = _context7.v;
1052
- walls = [];
1053
- wallHeight = 20;
1054
- roomSize = 50;
1055
- wallThickness = 1; // Create walls (north, east, south, west)
1056
- wallGeometries = [new THREE__namespace.BoxGeometry(roomSize, wallHeight, wallThickness),
1057
- // North
1058
- new THREE__namespace.BoxGeometry(wallThickness, wallHeight, roomSize),
1059
- // East
1060
- new THREE__namespace.BoxGeometry(roomSize, wallHeight, wallThickness),
1061
- // South
1062
- new THREE__namespace.BoxGeometry(wallThickness, wallHeight, roomSize) // West
1063
- ];
1064
- wallPositions = [[0, wallHeight / 2, -roomSize / 2],
1065
- // North
1066
- [roomSize / 2, wallHeight / 2, 0],
1067
- // East
1068
- [0, wallHeight / 2, roomSize / 2],
1069
- // South
1070
- [-roomSize / 2, wallHeight / 2, 0] // West
1071
- ];
1072
- wallNames = ['north-wall', 'east-wall', 'south-wall', 'west-wall']; // Create each wall
1073
- for (i = 0; i < 4; i++) {
1074
- wall = new THREE__namespace.Mesh(wallGeometries[i], wallMaterial);
1075
- (_wall$position2 = wall.position).set.apply(_wall$position2, _rollupPluginBabelHelpers.toConsumableArray(wallPositions[i]));
1076
- wall.receiveShadow = true;
1077
- wall.castShadow = true;
1078
-
1079
- // Set user data for identification
1080
- wall.userData = {
1081
- isEnvironmentObject: true,
1082
- type: 'wall',
1083
- name: wallNames[i]
1084
- };
1085
- component.scene.add(wall);
1086
- walls.push(wall);
1087
- }
1088
- debugLogger.logger.info('Textured environment walls created');
1089
- return _context7.a(2, walls);
1090
- case 6:
1091
- _context7.p = 6;
1092
- _t9 = _context7.v;
1093
- debugLogger.logger.error('Error creating brick walls:', _t9);
1094
- // Fallback to simple walls
1095
- return _context7.a(2, this.createWalls());
1096
- }
1097
- }, _callee5, this, [[4, 6]]);
1098
- }));
1099
- function addBrickWalls() {
1100
- return _addBrickWalls.apply(this, arguments);
1101
- }
1102
- return addBrickWalls;
1103
- }()
1104
- /**
1105
- * Add horizon fog effect
1106
- */
1107
- )
1108
- }, {
1109
- key: "addHorizonFog",
1110
- value: function addHorizonFog() {
1111
- var component = this.component;
1112
- if (!component || !component.scene) {
1113
- debugLogger.logger.warn('Cannot set horizon fog: component or scene not available');
1114
- return;
1115
- }
1116
-
1117
- // Light blue-ish fog color
1118
- var fogColor = 0xd8e0ff;
1119
- // Less dense than the default fog
1120
- var fogDensity = 0.005;
1121
- component.scene.fog = new THREE__namespace.FogExp2(fogColor, fogDensity);
1122
- debugLogger.logger.info('Horizon fog applied');
1123
- }
1124
-
1125
- /**
1126
- * Helper to check if a texture exists locally in static directory
1127
- * @param {string} path - Relative path to texture in static directory
1128
- * @returns {Promise<boolean>}
1129
- */
1130
- }, {
1131
- key: "checkLocalTextureExists",
1132
- value: (function () {
1133
- var _checkLocalTextureExists = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee6(path) {
1134
- return _rollupPluginBabelHelpers.regenerator().w(function (_context8) {
1135
- while (1) switch (_context8.n) {
1136
- case 0:
1137
- // Remove leading slash if present
1138
- if (path.startsWith('/')) {
1139
- path = path.substring(1);
1140
- }
1141
-
1142
- // For browser environment
1143
- if (!(typeof window !== 'undefined')) {
1144
- _context8.n = 1;
1145
- break;
1146
- }
1147
- return _context8.a(2, new Promise(function (resolve) {
1148
- var img = new Image();
1149
- img.onload = function () {
1150
- return resolve(true);
1151
- };
1152
- img.onerror = function () {
1153
- return resolve(false);
1154
- };
1155
-
1156
- // Use the path directly - it should already be processed by getAssetPath
1157
- img.src = path;
1158
-
1159
- // Set a timeout in case the image load hangs
1160
- setTimeout(function () {
1161
- return resolve(false);
1162
- }, 2000);
1163
- }));
1164
- case 1:
1165
- return _context8.a(2, false);
1166
- }
1167
- }, _callee6);
1168
- }));
1169
- function checkLocalTextureExists(_x) {
1170
- return _checkLocalTextureExists.apply(this, arguments);
1171
- }
1172
- return checkLocalTextureExists;
1173
- }()
1174
- /**
1175
- * Force refresh all materials in the scene
1176
- * Helpful for ensuring textures are correctly displayed
1177
- */
1178
- )
1179
- }, {
1180
- key: "forceRefreshMaterials",
1181
- value: function forceRefreshMaterials() {
1182
- var component = this.component;
1183
- if (!component || !component.scene) {
1184
- debugLogger.logger.warn('Cannot refresh materials: component or scene not available');
1185
- return;
1186
- }
1187
- console.log('🔄 Forcing material refresh for all objects...');
1188
- var updatedMaterials = 0;
1189
- var textureFixes = 0;
1190
-
1191
- // Import helper functions if available
1192
- var hasValidImageData = textureConfig.hasValidImageData || function (texture) {
1193
- return texture && texture.image;
1194
- };
1195
- var createPlaceholderTexture = textureConfig.createPlaceholderTexture || function () {
1196
- return null;
1197
- };
1198
-
1199
- // Traverse all meshes in the scene
1200
- component.scene.traverse(function (object) {
1201
- if (object.isMesh && object.material) {
1202
- // Handle both single materials and material arrays
1203
- var materials = Array.isArray(object.material) ? object.material : [object.material];
1204
- materials.forEach(function (material) {
1205
- if (material) {
1206
- // Update material properties
1207
- material.needsUpdate = true;
1208
-
1209
- // Ensure color values are properly set
1210
- if (material.color) {
1211
- if (typeof material.color.convertSRGBToLinear === 'function') {
1212
- material.color.convertSRGBToLinear();
1213
- }
1214
- }
1215
-
1216
- // Check for maps and ensure they're correctly configured
1217
- var maps = ['map', 'normalMap', 'roughnessMap', 'metalnessMap', 'aoMap', 'bumpMap'];
1218
- maps.forEach(function (mapType) {
1219
- var map = material[mapType];
1220
- if (map) {
1221
- // Check if this texture might trigger the warning
1222
- var hasValidData = hasValidImageData(map);
1223
- if (!hasValidData) {
1224
- console.warn("\u26A0\uFE0F Found texture without valid image data in ".concat(mapType, " for object ").concat(object.name || object.uuid));
1225
-
1226
- // Create and use a placeholder texture for now
1227
- if (createPlaceholderTexture) {
1228
- var placeholderColor = mapType === 'normalMap' ? 0x8080ff : 0xcccccc;
1229
- var placeholder = createPlaceholderTexture(placeholderColor);
1230
- if (placeholder) {
1231
- material[mapType] = placeholder;
1232
- textureFixes++;
1233
- console.log("\uD83D\uDD04 Replaced missing image texture with placeholder for ".concat(mapType));
1234
- }
1235
- }
1236
- } else {
1237
- map.needsUpdate = true;
1238
-
1239
- // Ensure correct color space for diffuse maps
1240
- if (mapType === 'map' && map.colorSpace !== undefined) {
1241
- map.colorSpace = THREE__namespace.SRGBColorSpace;
1242
- } else if (mapType === 'map' && map.encoding !== undefined) {
1243
- map.encoding = THREE__namespace.sRGBEncoding;
1244
- }
1245
- }
1246
- }
1247
- });
1248
- updatedMaterials++;
1249
- }
1250
- });
1251
- }
1252
- });
1253
-
1254
- // Use the dedicated function from textureConfig if available
1255
- if (textureConfig.forceUpdateMaterials) {
1256
- textureConfig.forceUpdateMaterials(component.scene);
1257
- }
1258
- console.log("\u2705 Refreshed ".concat(updatedMaterials, " materials, fixed ").concat(textureFixes, " texture warnings"));
1259
-
1260
- // Force a renderer update if possible
1261
- if (component.renderer && component.camera) {
1262
- component.renderer.render(component.scene, component.camera);
1263
- }
1264
- }
1265
- }]);
1266
- }();
1267
-
1268
- // Create a singleton instance
1269
- var environmentManager = null;
1270
-
1271
- /**
1272
- * Get the global environment manager instance
1273
- */
1274
- function getEnvironmentManager() {
1275
- var component = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1276
- if (!environmentManager || component && environmentManager.component !== component) {
1277
- environmentManager = new EnvironmentManager(component);
1278
- }
1279
- return environmentManager;
1280
- }
1281
- var environmentManager$1 = {
1282
- EnvironmentManager: EnvironmentManager,
1283
- getEnvironmentManager: getEnvironmentManager,
1284
- // Default initialization method for ease of use
1285
- initializeEnvironment: function () {
1286
- var _initializeEnvironment2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee7(component) {
1287
- var manager;
1288
- return _rollupPluginBabelHelpers.regenerator().w(function (_context9) {
1289
- while (1) switch (_context9.n) {
1290
- case 0:
1291
- manager = getEnvironmentManager(component);
1292
- _context9.n = 1;
1293
- return manager.initializeEnvironment();
1294
- case 1:
1295
- return _context9.a(2, manager);
1296
- }
1297
- }, _callee7);
1298
- }));
1299
- function initializeEnvironment(_x2) {
1300
- return _initializeEnvironment2.apply(this, arguments);
1301
- }
1302
- return initializeEnvironment;
1303
- }()
1304
- };
1305
-
1306
- exports.EnvironmentManager = EnvironmentManager;
1307
- exports["default"] = environmentManager$1;
1308
- exports.getEnvironmentManager = getEnvironmentManager;
1
+ "use strict";Object.defineProperty(exports,"t",{value:!0});var e=require("../_virtual/_rollupPluginBabelHelpers.js"),n=require("three"),r=require("./debugLogger.js");function t(e){if(e&&e.t)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,Object.freeze(n)}var a,i=t(n);function o(e){if(e.startsWith("/")&&(e=e.substring(1)),"undefined"!=typeof window){var n="undefined"!=typeof CentralPlantUtils;if("localhost"===window.location.hostname&&("3000"===window.location.port||"3001"===window.location.port))return"/".concat(e);if(n){var r="undefined"==typeof document?new(require("url").URL)("file:"+__filename).href:document.currentScript&&"SCRIPT"===document.currentScript.tagName.toUpperCase()&&document.currentScript.src||new URL("src/environmentManager.js",document.baseURI).href;return new URL("./assets/".concat(e),r).href}var t="undefined"==typeof document?new(require("url").URL)("file:"+__filename).href:document.currentScript&&"SCRIPT"===document.currentScript.tagName.toUpperCase()&&document.currentScript.src||new URL("src/environmentManager.js",document.baseURI).href;return new URL("../assets/".concat(e),t).href}return"assets/".concat(e)}function u(){return c.apply(this,arguments)}function c(){return(c=e.asyncToGenerator(e.regenerator().m(function n(){var r;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if("undefined"==typeof window){e.n=4;break}return e.p=1,e.n=2,Promise.resolve().then(function(){return require("../node_modules/three/examples/jsm/loaders/RGBELoader.js")});case 2:return r=e.v,a=r.RGBELoader,e.a(2,!0);case 3:throw e.p=3,e.v,new Error("Failed to load Three.js loaders");case 4:return e.a(2,!1)}},n,null,[[1,3]])}))).apply(this,arguments)}var s={loadTextureSetAndCreateMaterial:null,checkThreeJSCompatibility:null,forceUpdateMaterials:null};function l(){return f.apply(this,arguments)}function f(){return(f=e.asyncToGenerator(e.regenerator().m(function n(){var r;return e.regenerator().w(function(n){for(;;)switch(n.n){case 0:if("undefined"==typeof window){n.n=4;break}return n.p=1,n.n=2,Promise.resolve().then(function(){return require("./textureConfig.js")});case 2:return r=n.v,s.loadTextureSetAndCreateMaterial=r.loadTextureSetAndCreateMaterial,s.checkThreeJSCompatibility=r.checkThreeJSCompatibility,s.forceUpdateMaterials=r.forceUpdateMaterials,Object.entries(s).filter(function(n){var r=e.slicedToArray(n,2);return r[0],"function"==typeof r[1]}).map(function(n){return e.slicedToArray(n,1)[0]}),"function"==typeof s.checkThreeJSCompatibility&&s.checkThreeJSCompatibility(),n.a(2,!0);case 3:return n.p=3,n.v,n.a(2,!1);case 4:return n.a(2,!1)}},n,null,[[1,3]])}))).apply(this,arguments)}var d=function(){return e.createClass(function n(r){e.classCallCheck(this,n),this.component=r,this.loadersInitialized=!1,this.initLoaders()},[{key:"initLoaders",value:(v=e.asyncToGenerator(e.regenerator().m(function n(){return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return e.p=1,e.n=2,Promise.all([u(),l()]);case 2:this.loadersInitialized=!0,e.n=4;break;case 3:e.p=3,e.v;case 4:return e.a(2)}},n,this,[[1,3]])})),function(){return v.apply(this,arguments)})},{key:"createSkybox",value:(d=e.asyncToGenerator(e.regenerator().m(function n(){var t,c,s,l,f,d,v,w,h,m,p,b,k,y,g=this;return e.regenerator().w(function(n){for(;;)switch(n.n){case 0:if((t=this.component)&&t.renderer&&t.scene){n.n=1;break}return r.logger.warn("Cannot create skybox: component, renderer or scene not available"),n.a(2);case 1:if(a){n.n=5;break}return n.p=2,n.n=3,u();case 3:n.n=5;break;case 4:return n.p=4,n.v,this.createFallbackEnvironment(),n.a(2);case 5:if(n.p=5,c=!(!t.renderer.context||"function"!=typeof t.renderer.context.isContextLost)&&t.renderer.context.isContextLost(),t.renderer.capabilities&&!c){n.n=6;break}return r.logger.warn("WebGL context is lost or invalid, using fallback environment"),this.createFallbackEnvironment(),n.a(2);case 6:if(n.p=6,s=new i.PMREMGenerator(t.renderer)){n.n=7;break}throw new Error("PMREMGenerator could not be created");case 7:s.compileEquirectangularShader(),n.n=9;break;case 8:return n.p=8,k=n.v,r.logger.warn("Failed to initialize PMREMGenerator:",k),this.createFallbackEnvironment(),n.a(2);case 9:l=o("skyboxes/kloofendal_48d_partly_cloudy_puresky_2k.hdr"),f=o("skyboxes/kloofendal_48d_partly_cloudy_puresky_1k.hdr"),d=o("skyboxes/sky_fallback.jpg"),(v=[{type:"hdr",loader:new a,paths:[l,f]},{type:"jpeg",loader:t.textureLoader||new i.TextureLoader,paths:[d]}]).forEach(function(e){var n=e.loader;n&&"function"==typeof n.setCrossOrigin&&n.setCrossOrigin("anonymous")}),w=function(e,n){try{var a,o;e.mapping=i.EquirectangularReflectionMapping,void 0!==e.colorSpace?e.colorSpace=t.renderer.outputColorSpace||i.SRGBColorSpace:void 0!==e.encoding&&(e.encoding=t.renderer.outputEncoding||i.sRGBEncoding);var u=s.fromEquirectangular(e).texture;return r.logger.info("Generating environment map:\n - Type: ".concat(n,"\n - Texture valid: ").concat(null!==e,"\n - Processed map valid: ").concat(null!==u,"\n - Renderer encoding: ").concat(t.renderer.outputEncoding||t.renderer.outputColorSpace,"\n - Texture encoding: ").concat(e.encoding||e.colorSpace)),null!==(a=t.scene.environment)&&void 0!==a&&a.dispose&&t.scene.environment.dispose(),null!==(o=t.scene.background)&&void 0!==o&&o.dispose&&t.scene.background.dispose(),t.scene.environment=u,t.scene.background=u,e.dispose(),t.renderer&&(t.renderer.toneMappingExposure=1,t.renderer.render(t.scene,t.camera)),r.logger.info("Environment map (".concat(n,") applied successfully")),!0}catch(e){return r.logger.warn("Failed to apply ".concat(n," environment map:"),e),!1}},h=e.regenerator().m(function n(){var t,a,i,o,u,c,l,f,d;return e.regenerator().w(function(n){for(;;)switch(n.n){case 0:t=b[p],a=t.type,i=t.loader,o=t.paths,u=e.createForOfIteratorHelper(o),n.p=1,l=e.regenerator().m(function n(){var t,o,u;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if(t=c.value,e.p=1,!t.startsWith("/")||t.includes("://")){e.n=3;break}return e.n=2,g.checkLocalTextureExists(t);case 2:if(e.v){e.n=3;break}return e.a(2,0);case 3:return r.logger.info("Attempting to load ".concat(a," texture: ").concat(t)),e.n=4,new Promise(function(e,n){var r=setTimeout(function(){return n(new Error("Timeout loading ".concat(t)))},1e4);i.load(t,function(n){clearTimeout(r),e(n)},function(e){e.lengthComputable&&(e.loaded,e.total)},function(e){clearTimeout(r),n(e)})});case 4:if(o=e.v,!w(o,a)){e.n=5;break}return s.dispose(),e.a(2,{v:{v:void 0}});case 5:e.n=7;break;case 6:e.p=6,u=e.v,r.logger.warn("Failed to load ".concat(t,":"),u.message);case 7:return e.a(2)}},n,null,[[1,6]])}),u.s();case 2:if((c=u.n()).done){n.n=6;break}return n.d(e.regeneratorValues(l()),3);case 3:if(0!==(f=n.v)){n.n=4;break}return n.a(3,5);case 4:if(!f){n.n=5;break}return n.a(2,f.v);case 5:n.n=2;break;case 6:n.n=8;break;case 7:n.p=7,d=n.v,u.e(d);case 8:return n.p=8,u.f(),n.f(8);case 9:return n.a(2)}},n,null,[[1,7,8,9]])}),p=0,b=v;case 10:if(!(p<b.length)){n.n=13;break}return n.d(e.regeneratorValues(h()),11);case 11:if(!(m=n.v)){n.n=12;break}return n.a(2,m.v);case 12:p++,n.n=10;break;case 13:this.createProceduralSky(s),n.n=15;break;case 14:n.p=14,y=n.v,r.logger.error("Error creating skybox:",y),this.createFallbackEnvironment();case 15:return n.a(2)}},n,this,[[6,8],[5,14],[2,4]])})),function(){return d.apply(this,arguments)})},{key:"createFallbackEnvironment",value:function(){var e=this.component;if(e&&e.scene){r.logger.info("Creating basic fallback environment");var n=new i.AmbientLight(16777215,.6);e.scene.add(n);var t=new i.DirectionalLight(16777215,.8);t.position.set(1,2,3),e.scene.add(t),e.scene.background=new i.Color(8900331)}}},{key:"createProceduralSky",value:function(e){var n=this.component;if(n&&n.scene){r.logger.info("Using procedural sky fallback");var t=new i.AmbientLight(16777215,.6);n.scene.add(t);var a=new i.DirectionalLight(16777215,.8);a.position.set(1,1,1),n.scene.add(a);try{if(e&&"function"==typeof e.fromScene){var o=new i.Scene;o.add(new i.HemisphereLight(8900331,4473975,1));var u=e.fromScene(o);u&&u.texture&&(n.scene.environment=u.texture)}n.scene.background=new i.Color(8900331)}catch(e){r.logger.warn("Failed to create procedural sky, using simple background",e),n.scene.background=new i.Color(8900331)}finally{e&&"function"==typeof e.dispose&&e.dispose()}}}},{key:"setupLighting",value:function(){var e=this.component;if(e&&e.scene){var n=[];e.scene.traverse(function(e){e instanceof i.Light&&n.push(e)}),n.forEach(function(n){e.scene.remove(n)});var t=new i.DirectionalLight(16777215,.8);t.position.set(5,10,7),t.castShadow=!0,t.shadow.mapSize.width=1024,t.shadow.mapSize.height=1024,t.shadow.camera.near=1,t.shadow.camera.far=30,t.shadow.camera.left=-10,t.shadow.camera.right=10,t.shadow.camera.top=10,t.shadow.camera.bottom=-10,t.shadow.bias=-.001,e.scene.add(t);var a=new i.AmbientLight(16777215,.3);e.scene.add(a);var o=new i.HemisphereLight(16777215,4473975,.3);e.scene.add(o),r.logger.info("Scene lighting setup complete")}else r.logger.warn("Cannot setup lighting: component or scene not available")}},{key:"createGround",value:function(){var e=this.component;if(!e||!e.scene)return r.logger.warn("Cannot create ground: component or scene not available"),null;var n=new i.PlaneGeometry(100,100),t=new i.MeshStandardMaterial({color:13421772,roughness:.8,metalness:.2,side:i.DoubleSide}),a=new i.Mesh(n,t);return a.rotation.x=-Math.PI/2,a.position.y=-.01,a.receiveShadow=!0,a.userData={isEnvironmentObject:!0,type:"ground"},e.scene.add(a),r.logger.info("Ground plane created"),a}},{key:"createWalls",value:function(){var n=this.component;if(!n||!n.scene)return r.logger.warn("Cannot create walls: component or scene not available"),[];for(var t=[],a=20,o=50,u=new i.MeshStandardMaterial({color:14540253,roughness:.9,metalness:.1,side:i.DoubleSide}),c=[new i.BoxGeometry(o,a,1),new i.BoxGeometry(1,a,o),new i.BoxGeometry(o,a,1),new i.BoxGeometry(1,a,o)],s=[[0,10,-25],[25,10,0],[0,10,25],[-25,10,0]],l=["north-wall","east-wall","south-wall","west-wall"],f=0;f<4;f++){var d,v=new i.Mesh(c[f],u);(d=v.position).set.apply(d,e.toConsumableArray(s[f])),v.receiveShadow=!0,v.castShadow=!0,v.userData={isEnvironmentObject:!0,type:"wall",name:l[f]},n.scene.add(v),t.push(v)}return r.logger.info("Environment walls created"),t}},{key:"setFog",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:13421772,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.01,t=this.component;t&&t.scene?(t.scene.fog=new i.FogExp2(e,n),r.logger.info("Scene fog applied")):r.logger.warn("Cannot set fog: component or scene not available")}},{key:"initializeEnvironment",value:(f=e.asyncToGenerator(e.regenerator().m(function n(){var t,a,o=this;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return t=this.component,e.p=1,e.n=2,u();case 2:return e.v,e.n=3,l();case 3:e.v,e.n=5;break;case 4:e.p=4,e.v;case 5:if(t){e.n=6;break}return r.logger.error("❌ Cannot initialize environment: component is null"),e.a(2);case 6:if(t.renderer){e.n=7;break}return r.logger.error("❌ Cannot initialize environment: renderer is null"),e.a(2);case 7:return t.renderer.toneMapping||(t.renderer.toneMapping=i.ACESFilmicToneMapping),t.renderer.toneMappingExposure=1,void 0!==t.renderer.outputColorSpace?t.renderer.outputColorSpace=i.SRGBColorSpace:void 0!==t.renderer.outputEncoding&&(t.renderer.outputEncoding=i.sRGBEncoding),r.logger.info("Renderer configured for HDR:\n - Tone mapping: ".concat(t.renderer.toneMapping,"\n - Color space: ").concat(t.renderer.outputColorSpace||t.renderer.outputEncoding)),e.n=8,this.createSkybox();case 8:return this.setupLighting(),e.n=9,this.addTexturedGround();case 9:return e.v?r.logger.info("✅ Ground created successfully"):r.logger.error("❌ Failed to create textured ground"),e.n=10,this.addBrickWalls();case 10:(a=e.v)&&0!==a.length?r.logger.info("✅ Created ".concat(a.length," walls")):r.logger.warn("⚠️ No walls were created"),this.addHorizonFog(),r.logger.info("Environment initialization complete"),this.forceRefreshMaterials(),t.renderer&&t.scene&&t.camera&&(t.renderer.render(t.scene,t.camera),setTimeout(function(){t.renderer&&!t.isDestroyed&&(o.forceRefreshMaterials(),t.renderer.render(t.scene,t.camera))},1e3));case 11:return e.a(2)}},n,this,[[1,4]])})),function(){return f.apply(this,arguments)})},{key:"addTexturedGround",value:(c=e.asyncToGenerator(e.regenerator().m(function n(){var t,a,o,u,c,f,d,v,w,h;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if(s.loadTextureSetAndCreateMaterial){e.n=2;break}return e.n=1,l();case 1:if(s.loadTextureSetAndCreateMaterial){e.n=2;break}return e.a(2,this.createGround());case 2:if((t=this.component)&&t.scene){e.n=3;break}return r.logger.warn("Cannot create textured ground: component or scene not available"),e.a(2,null);case 3:return t.textureLoader||(t.textureLoader=new i.TextureLoader,t.textureLoader.setCrossOrigin("anonymous")),t.scene.traverse(function(e){e.userData&&"ground"===e.userData.type&&t.scene.remove(e)}),e.p=4,e.n=5,s.loadTextureSetAndCreateMaterial(t,"gravel_embedded_concrete");case 5:if(a=e.v){e.n=6;break}throw new Error("Failed to create ground material");case 6:return o=new i.MeshBasicMaterial({color:2293538,wireframe:!1,side:i.DoubleSide}),u=new i.PlaneGeometry(100,100),(c=new i.Mesh(u,a)).rotation.x=-Math.PI/2,c.position.y=-.01,c.receiveShadow=!0,(f=new i.Mesh(u,o)).rotation.x=-Math.PI/2,f.position.y=-.02,f.visible=!1,c.userData={isEnvironmentObject:!0,isBaseGround:!0,type:"ground"},f.userData={isEnvironmentObject:!0,type:"ground-debug"},t.scene.add(c),t.scene.add(f),r.logger.info("Textured ground created"),e.a(2,c);case 7:return e.p=7,h=e.v,r.logger.error("Error creating textured ground:",h),d=new i.PlaneGeometry(100,100),v=new i.MeshBasicMaterial({color:16711680,wireframe:!0,side:i.DoubleSide}),(w=new i.Mesh(d,v)).rotation.x=-Math.PI/2,w.position.y=-.01,w.userData={isEnvironmentObject:!0,isBaseGround:!0,type:"ground-error"},t.scene.add(w),e.a(2,w)}},n,this,[[4,7]])})),function(){return c.apply(this,arguments)})},{key:"addBrickWalls",value:(t=e.asyncToGenerator(e.regenerator().m(function n(){var t,a,o,u,c,f,d,v,w,h,m,p;return e.regenerator().w(function(n){for(;;)switch(n.n){case 0:if(s.loadTextureSetAndCreateMaterial){n.n=2;break}return n.n=1,l();case 1:if(s.loadTextureSetAndCreateMaterial){n.n=2;break}return n.a(2,this.createWalls());case 2:if((t=this.component)&&t.scene){n.n=3;break}return r.logger.warn("Cannot create brick walls: component or scene not available"),n.a(2,[]);case 3:return t.scene.traverse(function(e){e.userData&&"wall"===e.userData.type&&t.scene.remove(e)}),n.p=4,n.n=5,s.loadTextureSetAndCreateMaterial(t,"brick");case 5:for(a=n.v,o=[],u=20,c=50,f=[new i.BoxGeometry(c,u,1),new i.BoxGeometry(1,u,c),new i.BoxGeometry(c,u,1),new i.BoxGeometry(1,u,c)],d=[[0,10,-25],[25,10,0],[0,10,25],[-25,10,0]],v=["north-wall","east-wall","south-wall","west-wall"],w=0;w<4;w++)m=new i.Mesh(f[w],a),(h=m.position).set.apply(h,e.toConsumableArray(d[w])),m.receiveShadow=!0,m.castShadow=!0,m.userData={isEnvironmentObject:!0,type:"wall",name:v[w]},t.scene.add(m),o.push(m);return r.logger.info("Textured environment walls created"),n.a(2,o);case 6:return n.p=6,p=n.v,r.logger.error("Error creating brick walls:",p),n.a(2,this.createWalls())}},n,this,[[4,6]])})),function(){return t.apply(this,arguments)})},{key:"addHorizonFog",value:function(){var e=this.component;if(e&&e.scene){e.scene.fog=new i.FogExp2(14213375,.005),r.logger.info("Horizon fog applied")}else r.logger.warn("Cannot set horizon fog: component or scene not available")}},{key:"checkLocalTextureExists",value:(n=e.asyncToGenerator(e.regenerator().m(function n(r){return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if(r.startsWith("/")&&(r=r.substring(1)),"undefined"==typeof window){e.n=1;break}return e.a(2,new Promise(function(e){var n=new Image;n.onload=function(){return e(!0)},n.onerror=function(){return e(!1)},n.src=r,setTimeout(function(){return e(!1)},2e3)}));case 1:return e.a(2,!1)}},n)})),function(e){return n.apply(this,arguments)})},{key:"forceRefreshMaterials",value:function(){var e=this.component;if(e&&e.scene){var n=s.hasValidImageData||function(e){return e&&e.image},t=s.createPlaceholderTexture||function(){return null};e.scene.traverse(function(e){e.isMesh&&e.material&&(Array.isArray(e.material)?e.material:[e.material]).forEach(function(e){if(e){e.needsUpdate=!0,e.color&&"function"==typeof e.color.convertSRGBToLinear&&e.color.convertSRGBToLinear();["map","normalMap","roughnessMap","metalnessMap","aoMap","bumpMap"].forEach(function(r){var a=e[r];if(a)if(n(a))a.needsUpdate=!0,"map"===r&&void 0!==a.colorSpace?a.colorSpace=i.SRGBColorSpace:"map"===r&&void 0!==a.encoding&&(a.encoding=i.sRGBEncoding);else if(t){var o=t("normalMap"===r?8421631:13421772);o&&(e[r]=o)}})}})}),s.forceUpdateMaterials&&s.forceUpdateMaterials(e.scene),e.renderer&&e.camera&&e.renderer.render(e.scene,e.camera)}else r.logger.warn("Cannot refresh materials: component or scene not available")}}]);var n,t,c,f,d,v}(),v=null;function w(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return(!v||e&&v.component!==e)&&(v=new d(e)),v}var h,m={EnvironmentManager:d,getEnvironmentManager:w,initializeEnvironment:(h=e.asyncToGenerator(e.regenerator().m(function n(r){var t;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:return t=w(r),e.n=1,t.initializeEnvironment();case 1:return e.a(2,t)}},n)})),function(e){return h.apply(this,arguments)})};exports.EnvironmentManager=d,exports.default=m,exports.getEnvironmentManager=w;