@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.
- package/dist/bundle/index.js +1 -15140
- package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -353
- package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1 -0
- package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1 -1292
- package/dist/cjs/node_modules/three/examples/jsm/controls/TransformControls.js +1 -1543
- package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +1 -4374
- package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +1 -465
- package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +1 -117
- package/dist/cjs/src/animationManager.js +1 -121
- package/dist/cjs/src/componentManager.js +1 -151
- package/dist/cjs/src/debugLogger.js +1 -176
- package/dist/cjs/src/disposalManager.js +1 -185
- package/dist/cjs/src/environmentManager.js +1 -1308
- package/dist/cjs/src/hotReloadManager.js +1 -252
- package/dist/cjs/src/index.js +1 -128
- package/dist/cjs/src/keyboardControlsManager.js +1 -206
- package/dist/cjs/src/nameUtils.js +1 -106
- package/dist/cjs/src/pathfindingManager.js +1 -321
- package/dist/cjs/src/performanceMonitor.js +1 -718
- package/dist/cjs/src/sceneExportManager.js +1 -292
- package/dist/cjs/src/sceneInitializationManager.js +1 -540
- package/dist/cjs/src/textureConfig.js +1 -624
- package/dist/cjs/src/transformControlsManager.js +1 -851
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +1 -328
- package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1 -0
- package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1 -1287
- package/dist/esm/node_modules/three/examples/jsm/controls/TransformControls.js +1 -1537
- package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +1 -4370
- package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +1 -461
- package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +1 -113
- package/dist/esm/src/animationManager.js +1 -112
- package/dist/esm/src/componentManager.js +1 -123
- package/dist/esm/src/debugLogger.js +1 -167
- package/dist/esm/src/disposalManager.js +1 -155
- package/dist/esm/src/environmentManager.js +1 -1282
- package/dist/esm/src/hotReloadManager.js +1 -244
- package/dist/esm/src/index.js +1 -118
- package/dist/esm/src/keyboardControlsManager.js +1 -196
- package/dist/esm/src/nameUtils.js +1 -99
- package/dist/esm/src/pathfindingManager.js +1 -295
- package/dist/esm/src/performanceMonitor.js +1 -712
- package/dist/esm/src/sceneExportManager.js +1 -286
- package/dist/esm/src/sceneInitializationManager.js +1 -513
- package/dist/esm/src/textureConfig.js +1 -595
- package/dist/esm/src/transformControlsManager.js +1 -827
- package/dist/index.d.ts +0 -4
- package/package.json +1 -1
- package/dist/cjs/src/ConnectionManager.js +0 -114
- package/dist/cjs/src/Pathfinder.js +0 -88
- package/dist/cjs/src/modelPreloader.js +0 -488
- package/dist/cjs/src/sceneOperationsManager.js +0 -596
- package/dist/esm/src/ConnectionManager.js +0 -110
- package/dist/esm/src/Pathfinder.js +0 -84
- package/dist/esm/src/modelPreloader.js +0 -464
- package/dist/esm/src/sceneOperationsManager.js +0 -572
|
@@ -1,595 +1 @@
|
|
|
1
|
-
import
|
|
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 };
|
|
1
|
+
import{asyncToGenerator as e,regenerator as n,slicedToArray as t,objectSpread2 as r}from"../_virtual/_rollupPluginBabelHelpers.js";import*as a from"three";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 t=import.meta.url;return new URL("./assets/".concat(e),t).href}var r=import.meta.url;return new URL("../assets/".concat(e),r).href}return"assets/".concat(e)}var s={light_metal:{localPath:"textures/gravel_embedded_concrete_1k",path:"https://central-plant-assets.s3.us-east-1.amazonaws.com/textures/gravel_embedded_concrete_1k",files:{diffuse:"diffuse.jpg",normal:"normal.jpg",roughness:"rough.jpg"},repeat:{x:2,y:2},materialProps:{color:12105912,metalness:.3,roughness:.3,normalScale:[.4,.4],clearcoat:.3,clearcoatRoughness:.2,envMapIntensity:1.6,reflectivity:.5}},brick:{localPath:"textures/pavement_03_1k",path:"https://central-plant-assets.s3.us-east-1.amazonaws.com/textures/pavement_03_1k",files:{diffuse:"diffuse.jpg",normal:"normal.jpg",roughness:"rough.jpg"},repeat:{x:7.5,y:.75},materialProps:{color:10061960,roughness:.9,metalness:.1,normalScale:[1.5,1.5],bumpScale:.05,clearcoat:.05,clearcoatRoughness:.4}},gravel_embedded_concrete:{localPath:"textures/gravel_embedded_concrete_1k",path:"https://central-plant-assets.s3.us-east-1.amazonaws.com/textures/gravel_embedded_concrete_1k",files:{diffuse:"diffuse.jpg",normal:"normal.jpg",roughness:"rough.jpg"},repeat:{x:3,y:3},materialProps:{color:16777215,roughness:.9,metalness:.1,normalScale:[1,1],bumpScale:.1}}};function u(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{x:1,y:1};e||(e=new a.TextureLoader);try{var r=f(13421772),o=new Promise(function(r,o){e.load(n,function(e){!e.image||!(e.image instanceof HTMLImageElement&&e.image.complete)&&e.image instanceof HTMLImageElement?o(new Error("Texture loaded but image data not ready")):(void 0!==e.colorSpace?e.colorSpace=a.SRGBColorSpace:void 0!==e.encoding&&(e.encoding=a.sRGBEncoding),e.wrapS=a.RepeatWrapping,e.wrapT=a.RepeatWrapping,e.repeat.set(t.x,t.y),e.needsUpdate=!0,r(e))},function(e){if(e.lengthComputable)e.loaded,e.total},function(e){o(e)})});return r.wrapS=a.RepeatWrapping,r.wrapT=a.RepeatWrapping,r.repeat.set(t.x,t.y),r.loadPromise=o,r.url=n,o.then(function(e){Object.keys(e).forEach(function(n){["uuid","id","version","isTexture"].includes(n)||(r[n]=e[n])}),r.image=e.image,r.source=e.source,r.needsUpdate=!0}).catch(function(){}),r}catch(e){return f(14496563)}}function i(e,n){return c.apply(this,arguments)}function c(){return c=e(n().m(function i(c,f){var d,m,p,v,h,g,w,b,_,y,x,j,k,T,M,P,S,E;return n().w(function(i){for(;;)switch(i.n){case 0:if(c){i.n=1;break}return i.a(2,new a.MeshStandardMaterial({color:11184810}));case 1:if(m=s[f]){i.n=2;break}return i.a(2,new a.MeshStandardMaterial({color:11184810}));case 2:return"function"==typeof(p=c.textureLoader||new a.TextureLoader).setCrossOrigin&&p.setCrossOrigin("anonymous"),v=m.repeat||{x:1,y:1},h={},g=function(){var t=e(n().m(function e(t){return n().w(function(e){for(;;)switch(e.n){case 0:if("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=t,setTimeout(function(){return e(!1)},2e3)}));case 1:return e.a(2,!1)}},e)}));return function(e){return t.apply(this,arguments)}}(),w=function(){var t=e(n().m(function e(t){var r,a,s,i;return n().w(function(e){for(;;)switch(e.n){case 0:if(m.files[t]){e.n=1;break}return e.a(2,null);case 1:r=[],m.localPath&&r.push(o("".concat(m.localPath,"/").concat(m.files[t]))),r.push("/textures/".concat(f,"_1k/").concat(m.files[t])),m.path&&r.push("".concat(m.path,"/").concat(m.files[t])),a=0,s=r;case 2:if(!(a<s.length)){e.n=6;break}return i=s[a],e.n=3,g(i);case 3:if(!e.v){e.n=4;break}return e.a(2,u(p,i,v));case 4:case 5:a++,e.n=2;break;case 6:return e.a(2,null)}},e)}));return function(e){return t.apply(this,arguments)}}(),b=Object.keys(m.files).map(function(){var t=e(n().m(function e(t){return n().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,w(t);case 1:return h[t]=e.v,e.a(2,{type:t,texture:h[t]})}},e)}));return function(e){return t.apply(this,arguments)}}()),i.n=3,Promise.all(b);case 3:if(Object.entries(h).forEach(function(e){var n=t(e,2);n[0],n[1]}),_=Object.values(h).some(function(e){return null!==e}),_){i.n=4;break}return x=(null===(y=m.materialProps)||void 0===y?void 0:y.color)||11184810,i.a(2,new a.MeshStandardMaterial({color:x,roughness:.8,metalness:.2,side:a.DoubleSide}));case 4:for(j={},k=0,T=Object.entries(h);k<T.length;k++)M=t(T[k],2),P=M[0],((S=M[1])&&l(S)||S)&&(j[P]=S);return(E=new a.MeshStandardMaterial(r(r({map:j.diffuse,normalMap:j.normal,roughnessMap:j.roughness,metalnessMap:j.metalness,aoMap:j.ao,displacementMap:j.displacement},m.materialProps),{},{side:a.DoubleSide}))).map&&l(E.map)||null===(d=m.materialProps)||void 0===d||!d.color||(E.color=new a.Color(m.materialProps.color)),E.needsUpdate=!0,c.scene&&c.scene.environment&&(E.envMap=c.scene.environment),Object.entries(j).forEach(function(e){var n=t(e,2),r=(n[0],n[1]);r&&r.loadPromise&&r.loadPromise.then(function(){E.needsUpdate=!0}).catch(function(e){})}),i.a(2,E)}},i)})),c.apply(this,arguments)}function l(e){return!!e&&(!!e.image&&(e.image instanceof HTMLImageElement||e.image instanceof HTMLCanvasElement?e.image.width>0&&e.image.height>0:!(!e.image.data||!Array.isArray(e.image.data))&&e.image.data.length>0))}function f(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:13421772,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:64,t=document.createElement("canvas");t.width=n,t.height=n;var r=t.getContext("2d");if(r){var o="#"+e.toString(16).padStart(6,"0");r.fillStyle=o,r.fillRect(0,0,n,n),r.fillStyle="#"+(e+2236962&16777215).toString(16),r.fillRect(0,0,n/2,n/2),r.fillRect(n/2,n/2,n/2,n/2)}var s=new a.CanvasTexture(t);return s.needsUpdate=!0,void 0!==s.colorSpace?s.colorSpace=a.SRGBColorSpace:void 0!==s.encoding&&(s.encoding=a.sRGBEncoding),s}function d(){return{version:a.REVISION,hasNewColorSpace:void 0!==a.SRGBColorSpace,hasOldEncoding:void 0!==a.sRGBEncoding,hasTextureLoader:"function"==typeof a.TextureLoader}}function m(e){if(e){e.traverse(function(e){e.isMesh&&e.material&&(Array.isArray(e.material)?e.material:[e.material]).forEach(function(e){e&&(e.needsUpdate=!0,e.map&&(e.map.needsUpdate=!0),e.normalMap&&(e.normalMap.needsUpdate=!0),e.roughnessMap&&(e.roughnessMap.needsUpdate=!0))})})}}var p={TEXTURE_SETS:s,createTexture:u,loadTextureSetAndCreateMaterial:i,checkThreeJSCompatibility:d,forceUpdateMaterials:m,hasValidImageData:l,createPlaceholderTexture:f};export{s as TEXTURE_SETS,d as checkThreeJSCompatibility,u as createTexture,p as default,m as forceUpdateMaterials,i as loadTextureSetAndCreateMaterial};
|