@2112-lab/central-plant 0.1.2 → 0.1.4

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 (119) hide show
  1. package/dist/bundle/index.js +1 -15498
  2. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -366
  3. package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1 -1448
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1 -1292
  5. package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +1 -0
  6. package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +1 -0
  7. package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +1 -0
  8. package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +1 -0
  9. package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +1 -0
  10. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +1 -4374
  11. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +1 -465
  12. package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +1 -0
  13. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +1 -117
  14. package/dist/cjs/src/analysis/analysis.js +1 -0
  15. package/dist/cjs/src/analysis/testing.js +1 -0
  16. package/dist/cjs/src/core/centralPlant.js +1 -0
  17. package/dist/cjs/src/core/debugLogger.js +1 -0
  18. package/dist/cjs/src/core/mathUtils.js +1 -0
  19. package/dist/cjs/src/core/nameUtils.js +1 -0
  20. package/dist/cjs/src/data/export.js +1 -0
  21. package/dist/cjs/src/data/import.js +1 -0
  22. package/dist/cjs/src/data/numerics.js +1 -0
  23. package/dist/cjs/src/helpers/sceneHelper.js +1 -0
  24. package/dist/cjs/src/index.js +1 -79
  25. package/dist/cjs/src/managers/components/animationManager.js +1 -0
  26. package/dist/cjs/src/managers/components/componentManager.js +1 -0
  27. package/dist/cjs/src/managers/components/pathfindingManager.js +1 -0
  28. package/dist/cjs/src/managers/controls/TransformControls.js +1 -0
  29. package/dist/cjs/src/managers/controls/cameraControlsManager.js +1 -0
  30. package/dist/cjs/src/managers/controls/dragDropManager.js +1 -0
  31. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +1 -0
  32. package/dist/cjs/src/managers/controls/transformControlsManager.js +1 -0
  33. package/dist/cjs/src/managers/environment/environmentManager.js +1 -0
  34. package/dist/cjs/src/managers/environment/textureConfig.js +1 -0
  35. package/dist/cjs/src/managers/scene/sceneExportManager.js +1 -0
  36. package/dist/cjs/src/managers/scene/sceneInitializationManager.js +1 -0
  37. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1 -0
  38. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +1 -0
  39. package/dist/cjs/src/managers/system/disposalManager.js +1 -0
  40. package/dist/cjs/src/managers/system/hotReloadManager.js +1 -0
  41. package/dist/cjs/src/managers/system/performanceMonitor.js +1 -0
  42. package/dist/cjs/src/rendering/modelPreloader.js +1 -0
  43. package/dist/cjs/src/rendering/rendering2D.js +1 -0
  44. package/dist/cjs/src/rendering/rendering3D.js +1 -0
  45. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +1 -339
  46. package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1 -1444
  47. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1 -1287
  48. package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +1 -0
  49. package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +1 -0
  50. package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +1 -0
  51. package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +1 -0
  52. package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +1 -0
  53. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +1 -4370
  54. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +1 -461
  55. package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +1 -0
  56. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +1 -113
  57. package/dist/esm/src/analysis/analysis.js +1 -0
  58. package/dist/esm/src/analysis/testing.js +1 -0
  59. package/dist/esm/src/core/centralPlant.js +1 -0
  60. package/dist/esm/src/core/debugLogger.js +1 -0
  61. package/dist/esm/src/core/mathUtils.js +1 -0
  62. package/dist/esm/src/core/nameUtils.js +1 -0
  63. package/dist/esm/src/data/export.js +1 -0
  64. package/dist/esm/src/data/import.js +1 -0
  65. package/dist/esm/src/data/numerics.js +1 -0
  66. package/dist/esm/src/helpers/sceneHelper.js +1 -0
  67. package/dist/esm/src/index.js +1 -70
  68. package/dist/esm/src/managers/components/animationManager.js +1 -0
  69. package/dist/esm/src/managers/components/componentManager.js +1 -0
  70. package/dist/esm/src/managers/components/pathfindingManager.js +1 -0
  71. package/dist/esm/src/managers/controls/TransformControls.js +1 -0
  72. package/dist/esm/src/managers/controls/cameraControlsManager.js +1 -0
  73. package/dist/esm/src/managers/controls/dragDropManager.js +1 -0
  74. package/dist/esm/src/managers/controls/keyboardControlsManager.js +1 -0
  75. package/dist/esm/src/managers/controls/transformControlsManager.js +1 -0
  76. package/dist/esm/src/managers/environment/environmentManager.js +1 -0
  77. package/dist/esm/src/managers/environment/textureConfig.js +1 -0
  78. package/dist/esm/src/managers/scene/sceneExportManager.js +1 -0
  79. package/dist/esm/src/managers/scene/sceneInitializationManager.js +1 -0
  80. package/dist/esm/src/managers/scene/sceneOperationsManager.js +1 -0
  81. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +1 -0
  82. package/dist/esm/src/managers/system/disposalManager.js +1 -0
  83. package/dist/esm/src/managers/system/hotReloadManager.js +1 -0
  84. package/dist/esm/src/managers/system/performanceMonitor.js +1 -0
  85. package/dist/esm/src/rendering/modelPreloader.js +1 -0
  86. package/dist/esm/src/rendering/rendering2D.js +1 -0
  87. package/dist/esm/src/rendering/rendering3D.js +1 -0
  88. package/dist/index.d.ts +52 -255
  89. package/package.json +3 -6
  90. package/dist/cjs/node_modules/three/examples/jsm/controls/TransformControls.js +0 -1543
  91. package/dist/cjs/src/animationManager.js +0 -121
  92. package/dist/cjs/src/componentManager.js +0 -151
  93. package/dist/cjs/src/debugLogger.js +0 -176
  94. package/dist/cjs/src/disposalManager.js +0 -185
  95. package/dist/cjs/src/environmentManager.js +0 -1308
  96. package/dist/cjs/src/hotReloadManager.js +0 -252
  97. package/dist/cjs/src/keyboardControlsManager.js +0 -206
  98. package/dist/cjs/src/nameUtils.js +0 -106
  99. package/dist/cjs/src/pathfindingManager.js +0 -503
  100. package/dist/cjs/src/performanceMonitor.js +0 -718
  101. package/dist/cjs/src/sceneExportManager.js +0 -292
  102. package/dist/cjs/src/sceneInitializationManager.js +0 -540
  103. package/dist/cjs/src/textureConfig.js +0 -624
  104. package/dist/cjs/src/transformControlsManager.js +0 -851
  105. package/dist/esm/node_modules/three/examples/jsm/controls/TransformControls.js +0 -1537
  106. package/dist/esm/src/animationManager.js +0 -112
  107. package/dist/esm/src/componentManager.js +0 -123
  108. package/dist/esm/src/debugLogger.js +0 -167
  109. package/dist/esm/src/disposalManager.js +0 -155
  110. package/dist/esm/src/environmentManager.js +0 -1282
  111. package/dist/esm/src/hotReloadManager.js +0 -244
  112. package/dist/esm/src/keyboardControlsManager.js +0 -196
  113. package/dist/esm/src/nameUtils.js +0 -99
  114. package/dist/esm/src/pathfindingManager.js +0 -479
  115. package/dist/esm/src/performanceMonitor.js +0 -712
  116. package/dist/esm/src/sceneExportManager.js +0 -286
  117. package/dist/esm/src/sceneInitializationManager.js +0 -513
  118. package/dist/esm/src/textureConfig.js +0 -595
  119. package/dist/esm/src/transformControlsManager.js +0 -827
@@ -1,595 +0,0 @@
1
- import { asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import * as THREE from 'three';
3
-
4
- /**
5
- * Helper function to get asset paths that works in both bundled and modular contexts
6
- * @param {string} assetPath - Relative path from the assets directory
7
- * @returns {string} - The full path to the asset
8
- */
9
- function getAssetPath(assetPath) {
10
- // Strip leading slash if present
11
- if (assetPath.startsWith('/')) {
12
- assetPath = assetPath.substring(1);
13
- }
14
-
15
- // In browser context, check for different module formats
16
- if (typeof window !== 'undefined') {
17
- // For bundled version, assets should be in dist/bundle/assets/
18
- // For ESM/CJS, assets should be in their respective folders
19
-
20
- // Try to determine if we're using the bundled version or ESM/CJS
21
- var isBundled = typeof CentralPlantUtils !== 'undefined';
22
-
23
- // Check if we're running in a Nuxt.js environment (localhost:3000 is a common dev server)
24
- var isNuxtEnv = window.location.hostname === 'localhost' && (window.location.port === '3000' || window.location.port === '3001');
25
- if (isNuxtEnv) {
26
- // In Nuxt.js environment, assets are likely in the /static directory at the root
27
- return "/".concat(assetPath); // No /assets/ prefix in the URL path
28
- } else if (isBundled) {
29
- // Get the base URL for the module
30
- var baseUrl = import.meta.url;
31
- // In bundled format, assets are in the assets folder next to the bundle
32
- return new URL("./assets/".concat(assetPath), baseUrl).href;
33
- } else {
34
- // Get the base URL for the module
35
- var _baseUrl = import.meta.url;
36
- // In ESM/CJS format, need to go up relative to current module path
37
- return new URL("../assets/".concat(assetPath), _baseUrl).href;
38
- }
39
- }
40
-
41
- // In Node.js context
42
- return "assets/".concat(assetPath);
43
- }
44
- var TEXTURE_SETS = {
45
- // Light metallic texture using the gravel_embedded_concrete with metallic properties
46
- light_metal: {
47
- // Local path first, with fallback to S3
48
- localPath: 'textures/gravel_embedded_concrete_1k',
49
- path: 'https://central-plant-assets.s3.us-east-1.amazonaws.com/textures/gravel_embedded_concrete_1k',
50
- files: {
51
- diffuse: 'diffuse.jpg',
52
- normal: 'normal.jpg',
53
- roughness: 'rough.jpg'
54
- },
55
- repeat: {
56
- x: 2,
57
- y: 2
58
- },
59
- // Moderate tiling for surface detail
60
- materialProps: {
61
- color: 0xb8b8b8,
62
- // Light metallic base color
63
- metalness: 0.3,
64
- roughness: 0.3,
65
- normalScale: [0.4, 0.4],
66
- // Subtle surface detail
67
- clearcoat: 0.3,
68
- clearcoatRoughness: 0.2,
69
- envMapIntensity: 1.6,
70
- reflectivity: 0.5
71
- }
72
- },
73
- brick: {
74
- // Local path first, with fallback to S3
75
- localPath: 'textures/pavement_03_1k',
76
- path: 'https://central-plant-assets.s3.us-east-1.amazonaws.com/textures/pavement_03_1k',
77
- files: {
78
- diffuse: 'diffuse.jpg',
79
- normal: 'normal.jpg',
80
- roughness: 'rough.jpg'
81
- },
82
- repeat: {
83
- x: 7.5,
84
- y: 0.75
85
- },
86
- // Adjust for proper brick scale
87
- materialProps: {
88
- color: 0x998888,
89
- roughness: 0.9,
90
- metalness: 0.1,
91
- normalScale: [1.5, 1.5],
92
- bumpScale: 0.05,
93
- clearcoat: 0.05,
94
- clearcoatRoughness: 0.4
95
- }
96
- },
97
- gravel_embedded_concrete: {
98
- // Local path first, with fallback to S3
99
- localPath: 'textures/gravel_embedded_concrete_1k',
100
- path: 'https://central-plant-assets.s3.us-east-1.amazonaws.com/textures/gravel_embedded_concrete_1k',
101
- files: {
102
- diffuse: 'diffuse.jpg',
103
- normal: 'normal.jpg',
104
- roughness: 'rough.jpg'
105
- },
106
- repeat: {
107
- x: 3,
108
- y: 3
109
- },
110
- materialProps: {
111
- color: 0xffffff,
112
- roughness: 0.9,
113
- metalness: 0.1,
114
- normalScale: [1.0, 1.0],
115
- bumpScale: 0.1
116
- }
117
- }
118
- };
119
-
120
- /**
121
- * Create a Three.js texture with appropriate settings
122
- */
123
- function createTexture(textureLoader, url) {
124
- var repeat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
125
- x: 1,
126
- y: 1
127
- };
128
- if (!textureLoader) {
129
- textureLoader = new THREE.TextureLoader();
130
- }
131
- try {
132
- console.log("\uD83D\uDD0D Beginning texture load from: ".concat(url));
133
-
134
- // Create placeholder texture for immediate use
135
- // This will prevent the "no image data found" warning
136
- var placeholderTexture = createPlaceholderTexture(0xcccccc);
137
-
138
- // Create a promise to track when the real texture is loaded
139
- var loadPromise = new Promise(function (resolve, reject) {
140
- textureLoader.load(url, function (loadedTexture) {
141
- console.log("\u2705 Successfully loaded texture from: ".concat(url));
142
-
143
- // Check if the loaded texture has valid image data
144
- if (loadedTexture.image && (loadedTexture.image instanceof HTMLImageElement && loadedTexture.image.complete || !(loadedTexture.image instanceof HTMLImageElement))) {
145
- console.log("\u2705 Image data verified for ".concat(url));
146
-
147
- // Explicitly set colorSpace for all textures to ensure proper rendering
148
- if (loadedTexture.colorSpace !== undefined) {
149
- loadedTexture.colorSpace = THREE.SRGBColorSpace;
150
- console.log("\uD83C\uDFA8 Set colorSpace to SRGBColorSpace for ".concat(url));
151
- } else if (loadedTexture.encoding !== undefined) {
152
- loadedTexture.encoding = THREE.sRGBEncoding;
153
- console.log("\uD83C\uDFA8 Set encoding to sRGBEncoding for ".concat(url));
154
- }
155
-
156
- // Configure texture properties
157
- loadedTexture.wrapS = THREE.RepeatWrapping;
158
- loadedTexture.wrapT = THREE.RepeatWrapping;
159
- loadedTexture.repeat.set(repeat.x, repeat.y);
160
- loadedTexture.needsUpdate = true;
161
- resolve(loadedTexture);
162
- } else {
163
- console.warn("\u26A0\uFE0F Loaded texture from ".concat(url, " but image data is not ready"));
164
- reject(new Error('Texture loaded but image data not ready'));
165
- }
166
- }, function (progressEvent) {
167
- if (progressEvent.lengthComputable) {
168
- var percentComplete = progressEvent.loaded / progressEvent.total * 100;
169
- console.log("Loading texture ".concat(url, ": ").concat(Math.round(percentComplete), "% complete"));
170
- }
171
- }, function (error) {
172
- console.error("\u274C Error loading texture from ".concat(url, ":"), error);
173
- reject(error);
174
- });
175
- });
176
-
177
- // Configure placeholder texture properties
178
- placeholderTexture.wrapS = THREE.RepeatWrapping;
179
- placeholderTexture.wrapT = THREE.RepeatWrapping;
180
- placeholderTexture.repeat.set(repeat.x, repeat.y);
181
-
182
- // Store the load promise and url for later reference
183
- placeholderTexture.loadPromise = loadPromise;
184
- placeholderTexture.url = url;
185
-
186
- // When the real texture loads, we'll swap it in
187
- loadPromise.then(function (realTexture) {
188
- // Copy all properties from the real texture to the placeholder
189
- Object.keys(realTexture).forEach(function (key) {
190
- // Skip certain properties that shouldn't be copied
191
- if (['uuid', 'id', 'version', 'isTexture'].includes(key)) return;
192
- placeholderTexture[key] = realTexture[key];
193
- });
194
- placeholderTexture.image = realTexture.image;
195
- placeholderTexture.source = realTexture.source;
196
- placeholderTexture.needsUpdate = true;
197
- console.log("\uD83D\uDD04 Updated placeholder texture with real image data for ".concat(url));
198
- }).catch(function () {
199
- console.warn("\u26A0\uFE0F Using placeholder for texture: ".concat(url));
200
- });
201
- return placeholderTexture;
202
- } catch (error) {
203
- console.error("Failed to load texture: ".concat(url), error);
204
- return createPlaceholderTexture(0xdd3333); // Red placeholder for errors
205
- }
206
- }
207
-
208
- /**
209
- * Load a texture set and create a material
210
- */
211
- function loadTextureSetAndCreateMaterial(_x, _x2) {
212
- return _loadTextureSetAndCreateMaterial.apply(this, arguments);
213
- }
214
-
215
- /**
216
- * Check if a texture has valid image data
217
- * @param {THREE.Texture} texture - The texture to check
218
- * @returns {boolean} - Whether the texture has valid image data
219
- */
220
- function _loadTextureSetAndCreateMaterial() {
221
- _loadTextureSetAndCreateMaterial = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(component, textureSetName) {
222
- var _textureSet$materialP2;
223
- var textureSet, textureLoader, repeat, loadedTextures, checkFileExists, loadTexture, texturePromises, hasAnyTextures, _textureSet$materialP, fallbackColor, texturesWithValidData, _i2, _Object$entries, _Object$entries$_i, type, texture, material;
224
- return _regenerator().w(function (_context4) {
225
- while (1) switch (_context4.n) {
226
- case 0:
227
- if (component) {
228
- _context4.n = 1;
229
- break;
230
- }
231
- console.warn('Component is required for texture loading');
232
- return _context4.a(2, new THREE.MeshStandardMaterial({
233
- color: 0xaaaaaa
234
- }));
235
- case 1:
236
- textureSet = TEXTURE_SETS[textureSetName];
237
- if (textureSet) {
238
- _context4.n = 2;
239
- break;
240
- }
241
- console.warn("Texture set not found: ".concat(textureSetName));
242
- return _context4.a(2, new THREE.MeshStandardMaterial({
243
- color: 0xaaaaaa
244
- }));
245
- case 2:
246
- console.log("\uD83C\uDF08 Loading texture set: ".concat(textureSetName));
247
- textureLoader = component.textureLoader || new THREE.TextureLoader(); // Set cross-origin attribute to allow texture loading from different domains
248
- if (typeof textureLoader.setCrossOrigin === 'function') {
249
- textureLoader.setCrossOrigin('anonymous');
250
- console.log('📡 Set cross-origin to anonymous for texture loading');
251
- }
252
- repeat = textureSet.repeat || {
253
- x: 1,
254
- y: 1
255
- };
256
- loadedTextures = {}; // Function to check if a file exists
257
- checkFileExists = /*#__PURE__*/function () {
258
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
259
- return _regenerator().w(function (_context) {
260
- while (1) switch (_context.n) {
261
- case 0:
262
- if (!(typeof window !== 'undefined')) {
263
- _context.n = 1;
264
- break;
265
- }
266
- return _context.a(2, new Promise(function (resolve) {
267
- var img = new Image();
268
- img.onload = function () {
269
- return resolve(true);
270
- };
271
- img.onerror = function () {
272
- return resolve(false);
273
- };
274
- img.src = url;
275
- setTimeout(function () {
276
- return resolve(false);
277
- }, 2000);
278
- }));
279
- case 1:
280
- return _context.a(2, false);
281
- }
282
- }, _callee);
283
- }));
284
- return function checkFileExists(_x3) {
285
- return _ref.apply(this, arguments);
286
- };
287
- }(); // Function to load a specific texture from the set
288
- loadTexture = /*#__PURE__*/function () {
289
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(type) {
290
- var paths, _i, _paths, path, exists;
291
- return _regenerator().w(function (_context2) {
292
- while (1) switch (_context2.n) {
293
- case 0:
294
- if (textureSet.files[type]) {
295
- _context2.n = 1;
296
- break;
297
- }
298
- return _context2.a(2, null);
299
- case 1:
300
- // Try multiple paths to find the texture
301
- paths = []; // 1. Try local bundled path first
302
- if (textureSet.localPath) {
303
- paths.push(getAssetPath("".concat(textureSet.localPath, "/").concat(textureSet.files[type])));
304
- }
305
-
306
- // 2. Try direct path to static folder
307
- paths.push("/textures/".concat(textureSetName, "_1k/").concat(textureSet.files[type]));
308
-
309
- // 3. Try remote path as fallback
310
- if (textureSet.path) {
311
- paths.push("".concat(textureSet.path, "/").concat(textureSet.files[type]));
312
- }
313
- console.log("\uD83D\uDD0D Will try loading texture ".concat(type, " from paths:"), paths);
314
-
315
- // Try each path until one works
316
- _i = 0, _paths = paths;
317
- case 2:
318
- if (!(_i < _paths.length)) {
319
- _context2.n = 6;
320
- break;
321
- }
322
- path = _paths[_i];
323
- console.log("\uD83D\uDD04 Checking if texture exists at: ".concat(path));
324
- _context2.n = 3;
325
- return checkFileExists(path);
326
- case 3:
327
- exists = _context2.v;
328
- if (!exists) {
329
- _context2.n = 4;
330
- break;
331
- }
332
- console.log("\u2705 Texture found at: ".concat(path));
333
- return _context2.a(2, createTexture(textureLoader, path, repeat));
334
- case 4:
335
- console.log("\u274C Texture not found at: ".concat(path));
336
- case 5:
337
- _i++;
338
- _context2.n = 2;
339
- break;
340
- case 6:
341
- console.error("\u274C Failed to load ".concat(type, " texture from any path"));
342
- return _context2.a(2, null);
343
- }
344
- }, _callee2);
345
- }));
346
- return function loadTexture(_x4) {
347
- return _ref2.apply(this, arguments);
348
- };
349
- }(); // Load all textures in the set
350
- texturePromises = Object.keys(textureSet.files).map(/*#__PURE__*/function () {
351
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(type) {
352
- return _regenerator().w(function (_context3) {
353
- while (1) switch (_context3.n) {
354
- case 0:
355
- _context3.n = 1;
356
- return loadTexture(type);
357
- case 1:
358
- loadedTextures[type] = _context3.v;
359
- return _context3.a(2, {
360
- type: type,
361
- texture: loadedTextures[type]
362
- });
363
- }
364
- }, _callee3);
365
- }));
366
- return function (_x5) {
367
- return _ref3.apply(this, arguments);
368
- };
369
- }());
370
- _context4.n = 3;
371
- return Promise.all(texturePromises);
372
- case 3:
373
- // Log successful texture loads
374
- Object.entries(loadedTextures).forEach(function (_ref4) {
375
- var _ref5 = _slicedToArray(_ref4, 2),
376
- type = _ref5[0],
377
- texture = _ref5[1];
378
- console.log("".concat(texture ? '✅' : '❌', " ").concat(type, " texture: ").concat(texture ? 'Loaded' : 'Failed'));
379
- }); // Create material with textures and properties
380
- console.log('Creating material with loaded textures and properties:', textureSet.materialProps);
381
-
382
- // Check if we have at least one texture that's not null
383
- hasAnyTextures = Object.values(loadedTextures).some(function (texture) {
384
- return texture !== null;
385
- });
386
- if (hasAnyTextures) {
387
- _context4.n = 4;
388
- break;
389
- }
390
- console.warn('⚠️ No textures loaded successfully for material. Using fallback color material.');
391
-
392
- // Create a colored material as fallback
393
- fallbackColor = ((_textureSet$materialP = textureSet.materialProps) === null || _textureSet$materialP === void 0 ? void 0 : _textureSet$materialP.color) || 0xaaaaaa;
394
- return _context4.a(2, new THREE.MeshStandardMaterial({
395
- color: fallbackColor,
396
- roughness: 0.8,
397
- metalness: 0.2,
398
- side: THREE.DoubleSide
399
- }));
400
- case 4:
401
- // Verify if the textures have valid image data
402
- texturesWithValidData = {};
403
- for (_i2 = 0, _Object$entries = Object.entries(loadedTextures); _i2 < _Object$entries.length; _i2++) {
404
- _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2), type = _Object$entries$_i[0], texture = _Object$entries$_i[1];
405
- if (texture && hasValidImageData(texture)) {
406
- console.log("\u2705 Texture '".concat(type, "' has valid image data"));
407
- texturesWithValidData[type] = texture;
408
- } else if (texture) {
409
- console.log("\u26A0\uFE0F Texture '".concat(type, "' doesn't have valid image data yet"));
410
- // Keep the texture even if it doesn't have valid data yet
411
- // Our createTexture function now handles this with placeholders
412
- texturesWithValidData[type] = texture;
413
- }
414
- }
415
-
416
- // Create the standard material with loaded textures
417
- material = new THREE.MeshStandardMaterial(_objectSpread2(_objectSpread2({
418
- map: texturesWithValidData.diffuse,
419
- normalMap: texturesWithValidData.normal,
420
- roughnessMap: texturesWithValidData.roughness,
421
- metalnessMap: texturesWithValidData.metalness,
422
- aoMap: texturesWithValidData.ao,
423
- displacementMap: texturesWithValidData.displacement
424
- }, textureSet.materialProps), {}, {
425
- side: THREE.DoubleSide // Always set DoubleSide to avoid rendering issues
426
- })); // Ensure color is applied even if textures are loading
427
-
428
- if ((!material.map || !hasValidImageData(material.map)) && (_textureSet$materialP2 = textureSet.materialProps) !== null && _textureSet$materialP2 !== void 0 && _textureSet$materialP2.color) {
429
- material.color = new THREE.Color(textureSet.materialProps.color);
430
- console.log("\uD83C\uDFA8 Applied fallback color: #".concat(material.color.getHexString()));
431
- }
432
-
433
- // Make sure material updates when textures load
434
- material.needsUpdate = true;
435
-
436
- // Add the environment map if available from the component
437
- if (component.scene && component.scene.environment) {
438
- material.envMap = component.scene.environment;
439
- console.log('🌐 Added environment map to material');
440
- }
441
-
442
- // Set up texture load monitoring for each texture with a load promise
443
- Object.entries(texturesWithValidData).forEach(function (_ref6) {
444
- var _ref7 = _slicedToArray(_ref6, 2),
445
- type = _ref7[0],
446
- texture = _ref7[1];
447
- if (texture && texture.loadPromise) {
448
- texture.loadPromise.then(function () {
449
- console.log("\u2705 Texture '".concat(type, "' finished loading, updating material"));
450
- material.needsUpdate = true;
451
- }).catch(function (error) {
452
- console.warn("\u26A0\uFE0F Failed to load '".concat(type, "' texture:"), error);
453
- });
454
- }
455
- });
456
- return _context4.a(2, material);
457
- }
458
- }, _callee4);
459
- }));
460
- return _loadTextureSetAndCreateMaterial.apply(this, arguments);
461
- }
462
- function hasValidImageData(texture) {
463
- if (!texture) return false;
464
-
465
- // Check if image exists
466
- if (!texture.image) return false;
467
-
468
- // For image objects, check width and height
469
- if (texture.image instanceof HTMLImageElement || texture.image instanceof HTMLCanvasElement) {
470
- return texture.image.width > 0 && texture.image.height > 0;
471
- }
472
-
473
- // For other image types (like ImageBitmap)
474
- if (texture.image.data && Array.isArray(texture.image.data)) {
475
- return texture.image.data.length > 0;
476
- }
477
- return false;
478
- }
479
-
480
- /**
481
- * Create a placeholder colored texture when image loading fails
482
- * @param {number} color - The color for the placeholder texture
483
- * @param {number} size - The size of the texture in pixels
484
- * @returns {THREE.Texture} - A colored placeholder texture
485
- */
486
- function createPlaceholderTexture() {
487
- var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0xcccccc;
488
- var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 64;
489
- // Create a canvas element
490
- var canvas = document.createElement('canvas');
491
- canvas.width = size;
492
- canvas.height = size;
493
-
494
- // Get the 2D context and fill with color
495
- var context = canvas.getContext('2d');
496
- if (context) {
497
- var hexColor = '#' + color.toString(16).padStart(6, '0');
498
- context.fillStyle = hexColor;
499
- context.fillRect(0, 0, size, size);
500
-
501
- // Optional: Add a pattern to make it obvious it's a placeholder
502
- context.fillStyle = '#' + (color + 0x222222 & 0xffffff).toString(16);
503
- context.fillRect(0, 0, size / 2, size / 2);
504
- context.fillRect(size / 2, size / 2, size / 2, size / 2);
505
- }
506
-
507
- // Create a texture from the canvas
508
- var texture = new THREE.CanvasTexture(canvas);
509
- texture.needsUpdate = true;
510
-
511
- // Set proper color space
512
- if (texture.colorSpace !== undefined) {
513
- texture.colorSpace = THREE.SRGBColorSpace;
514
- } else if (texture.encoding !== undefined) {
515
- texture.encoding = THREE.sRGBEncoding;
516
- }
517
- return texture;
518
- }
519
-
520
- /**
521
- * Helper function to check Three.js compatibility and configuration
522
- */
523
- function checkThreeJSCompatibility() {
524
- console.group('🔍 Three.js Compatibility Check');
525
-
526
- // Check Three.js version
527
- console.log('Three.js version:', THREE.REVISION);
528
-
529
- // Check color space constants
530
- console.log('Color space support:', {
531
- SRGBColorSpace: typeof THREE.SRGBColorSpace !== 'undefined',
532
- LinearSRGBColorSpace: typeof THREE.LinearSRGBColorSpace !== 'undefined',
533
- sRGBEncoding: typeof THREE.sRGBEncoding !== 'undefined'
534
- });
535
-
536
- // Check texture-related features
537
- console.log('Texture features:', {
538
- TextureLoader: typeof THREE.TextureLoader === 'function',
539
- RepeatWrapping: typeof THREE.RepeatWrapping !== 'undefined',
540
- MirroredRepeatWrapping: typeof THREE.MirroredRepeatWrapping !== 'undefined'
541
- });
542
-
543
- // Check shader and material features
544
- console.log('Material features:', {
545
- MeshStandardMaterial: typeof THREE.MeshStandardMaterial === 'function',
546
- MeshBasicMaterial: typeof THREE.MeshBasicMaterial === 'function',
547
- ShaderMaterial: typeof THREE.ShaderMaterial === 'function'
548
- });
549
- console.groupEnd();
550
- return {
551
- version: THREE.REVISION,
552
- hasNewColorSpace: typeof THREE.SRGBColorSpace !== 'undefined',
553
- hasOldEncoding: typeof THREE.sRGBEncoding !== 'undefined',
554
- hasTextureLoader: typeof THREE.TextureLoader === 'function'
555
- };
556
- }
557
- function forceUpdateMaterials(scene) {
558
- if (!scene) return;
559
- console.log('🔄 Forcing update on all scene materials...');
560
- var materialCount = 0;
561
- scene.traverse(function (node) {
562
- if (node.isMesh && node.material) {
563
- var materials = Array.isArray(node.material) ? node.material : [node.material];
564
- materials.forEach(function (material) {
565
- if (material) {
566
- material.needsUpdate = true;
567
- materialCount++;
568
-
569
- // Ensure maps are properly set
570
- if (material.map) {
571
- material.map.needsUpdate = true;
572
- }
573
- if (material.normalMap) {
574
- material.normalMap.needsUpdate = true;
575
- }
576
- if (material.roughnessMap) {
577
- material.roughnessMap.needsUpdate = true;
578
- }
579
- }
580
- });
581
- }
582
- });
583
- console.log("\u2705 Updated ".concat(materialCount, " materials in the scene"));
584
- }
585
- var textureConfig = {
586
- TEXTURE_SETS: TEXTURE_SETS,
587
- createTexture: createTexture,
588
- loadTextureSetAndCreateMaterial: loadTextureSetAndCreateMaterial,
589
- checkThreeJSCompatibility: checkThreeJSCompatibility,
590
- forceUpdateMaterials: forceUpdateMaterials,
591
- hasValidImageData: hasValidImageData,
592
- createPlaceholderTexture: createPlaceholderTexture
593
- };
594
-
595
- export { TEXTURE_SETS, checkThreeJSCompatibility, createTexture, textureConfig as default, forceUpdateMaterials, loadTextureSetAndCreateMaterial };