chore: add debug logs for texture extraction
Build and Deploy / build-and-push (push) Successful in 47s

This commit is contained in:
AI Bot
2026-09-03 13:29:57 +05:30
parent 2c319ecb24
commit d65d6633e8
+19 -4
View File
@@ -265,16 +265,27 @@ const ShadowFloor = ({ bounds, opacity, rotation, softness }: { bounds: any, opa
}; };
export const extractTextureUrl = (texture: any) => { export const extractTextureUrl = (texture: any) => {
console.log('[DEBUG] extractTextureUrl called with:', texture);
if (!texture) return undefined; if (!texture) return undefined;
const img = texture.image || (texture.source && texture.source.data); 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 (!img) return undefined;
// If we have a stable URL that isn't a blob, return it directly // 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.src === 'string' && img.src.length > 0 && !img.src.startsWith('blob:')) {
if (typeof img.currentSrc === 'string' && img.currentSrc.length > 0 && !img.currentSrc.startsWith('blob:')) return img.currentSrc; 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 // 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! // 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 { try {
const MAX = 1024; const MAX = 1024;
let scale = 1; let scale = 1;
@@ -283,6 +294,7 @@ export const extractTextureUrl = (texture: any) => {
} }
const cw = Math.round((img.width || 1024) * scale); const cw = Math.round((img.width || 1024) * scale);
const ch = Math.round((img.height || 1024) * scale); const ch = Math.round((img.height || 1024) * scale);
console.log(`[DEBUG] Canvas dimensions: ${cw}x${ch}`);
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
canvas.width = cw; canvas.width = cw;
@@ -290,14 +302,17 @@ export const extractTextureUrl = (texture: any) => {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
if (ctx) { if (ctx) {
ctx.drawImage(img, 0, 0, cw, ch); 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) { } catch (e) {
console.error('Error extracting texture URL:', e); console.error('[DEBUG] Error extracting texture URL:', e);
} }
return undefined; return undefined;
}; };
export const extractMaterialProps = (material: any): Partial<MaterialProps> => { export const extractMaterialProps = (material: any): Partial<MaterialProps> => {
if (!material) return {}; if (!material) return {};
const mProps: Partial<MaterialProps> = {}; const mProps: Partial<MaterialProps> = {};