chore: add debug logs for texture extraction
Build and Deploy / build-and-push (push) Successful in 47s
Build and Deploy / build-and-push (push) Successful in 47s
This commit is contained in:
+19
-4
@@ -265,16 +265,27 @@ const ShadowFloor = ({ bounds, opacity, rotation, softness }: { bounds: any, opa
|
||||
};
|
||||
|
||||
export const extractTextureUrl = (texture: any) => {
|
||||
console.log('[DEBUG] extractTextureUrl called with:', texture);
|
||||
if (!texture) return undefined;
|
||||
|
||||
const img = texture.image || (texture.source && texture.source.data);
|
||||
console.log('[DEBUG] extractTextureUrl found img:', img, 'type:', img ? img.constructor.name : 'null');
|
||||
|
||||
if (!img) return undefined;
|
||||
|
||||
// If we have a stable URL that isn't a blob, return it directly
|
||||
if (typeof img.src === 'string' && img.src.length > 0 && !img.src.startsWith('blob:')) return img.src;
|
||||
if (typeof img.currentSrc === 'string' && img.currentSrc.length > 0 && !img.currentSrc.startsWith('blob:')) return img.currentSrc;
|
||||
if (typeof img.src === 'string' && img.src.length > 0 && !img.src.startsWith('blob:')) {
|
||||
console.log('[DEBUG] extractTextureUrl returning img.src:', img.src);
|
||||
return img.src;
|
||||
}
|
||||
if (typeof img.currentSrc === 'string' && img.currentSrc.length > 0 && !img.currentSrc.startsWith('blob:')) {
|
||||
console.log('[DEBUG] extractTextureUrl returning img.currentSrc:', img.currentSrc);
|
||||
return img.currentSrc;
|
||||
}
|
||||
|
||||
// Fallback: draw ImageBitmap or HTMLImageElement to canvas to extract data URL
|
||||
// We MUST do this for blob: URLs because GLTFLoader revokes blob URLs after loading!
|
||||
console.log('[DEBUG] extractTextureUrl falling back to canvas extraction for', img.src || 'ImageBitmap/Blob');
|
||||
try {
|
||||
const MAX = 1024;
|
||||
let scale = 1;
|
||||
@@ -283,6 +294,7 @@ export const extractTextureUrl = (texture: any) => {
|
||||
}
|
||||
const cw = Math.round((img.width || 1024) * scale);
|
||||
const ch = Math.round((img.height || 1024) * scale);
|
||||
console.log(`[DEBUG] Canvas dimensions: ${cw}x${ch}`);
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = cw;
|
||||
@@ -290,14 +302,17 @@ export const extractTextureUrl = (texture: any) => {
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) {
|
||||
ctx.drawImage(img, 0, 0, cw, ch);
|
||||
return canvas.toDataURL('image/webp', 0.8);
|
||||
const dataUrl = canvas.toDataURL('image/webp', 0.8);
|
||||
console.log(`[DEBUG] Successfully generated dataUrl of length: ${dataUrl.length}`);
|
||||
return dataUrl;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error extracting texture URL:', e);
|
||||
console.error('[DEBUG] Error extracting texture URL:', e);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
export const extractMaterialProps = (material: any): Partial<MaterialProps> => {
|
||||
if (!material) return {};
|
||||
const mProps: Partial<MaterialProps> = {};
|
||||
|
||||
Reference in New Issue
Block a user