Compress imported model textures via WebP 0.8 to prevent 413 Payload Too Large on project save
This commit is contained in:
+12
-4
@@ -1380,13 +1380,21 @@ export default function Editor() {
|
||||
|
||||
// Fallback: draw ImageBitmap or HTMLImageElement to canvas to extract data URL
|
||||
try {
|
||||
const MAX = 1024;
|
||||
let scale = 1;
|
||||
if (img.width > MAX || img.height > MAX) {
|
||||
scale = MAX / Math.max(img.width, img.height);
|
||||
}
|
||||
const cw = Math.round((img.width || 1024) * scale);
|
||||
const ch = Math.round((img.height || 1024) * scale);
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = img.width || 1024;
|
||||
canvas.height = img.height || 1024;
|
||||
canvas.width = cw;
|
||||
canvas.height = ch;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) {
|
||||
ctx.drawImage(img, 0, 0);
|
||||
return canvas.toDataURL('image/png');
|
||||
ctx.drawImage(img, 0, 0, cw, ch);
|
||||
return canvas.toDataURL('image/webp', 0.8);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error extracting texture URL:', e);
|
||||
|
||||
Reference in New Issue
Block a user