From d65d6633e83246f9264fba0e4a31f19451ca23ef Mon Sep 17 00:00:00 2001 From: AI Bot Date: Thu, 3 Sep 2026 13:29:57 +0530 Subject: [PATCH] chore: add debug logs for texture extraction --- src/pages/Editor.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/pages/Editor.tsx b/src/pages/Editor.tsx index d3a8fff..483b85e 100644 --- a/src/pages/Editor.tsx +++ b/src/pages/Editor.tsx @@ -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 => { if (!material) return {}; const mProps: Partial = {};