Extract textures via Canvas Base64 fallback to prevent revoked blob URL errors
This commit is contained in:
+18
-2
@@ -1373,8 +1373,24 @@ export default function Editor() {
|
||||
|
||||
const extractTextureUrl = (texture: any) => {
|
||||
if (!texture) return undefined;
|
||||
if (texture.image && typeof texture.image.src === 'string') return texture.image.src;
|
||||
if (texture.source && texture.source.data && typeof texture.source.data.src === 'string') return texture.source.data.src;
|
||||
const img = texture.image || (texture.source && texture.source.data);
|
||||
if (!img) return undefined;
|
||||
if (typeof img.src === 'string' && img.src.length > 0) return img.src;
|
||||
if (typeof img.currentSrc === 'string' && img.currentSrc.length > 0) return img.currentSrc;
|
||||
|
||||
// Fallback: draw ImageBitmap or HTMLImageElement to canvas to extract data URL
|
||||
try {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = img.width || 1024;
|
||||
canvas.height = img.height || 1024;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
return canvas.toDataURL('image/png');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error extracting texture URL:', e);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user