Fix UV canvas CORS tainting preventing image export
This commit is contained in:
@@ -52,6 +52,7 @@ export function UVEditor({ onClose, onSave, targetObject, loadedModel, sceneObje
|
|||||||
const init: Layer[] = saved.map((l: any) => ({ ...l }));
|
const init: Layer[] = saved.map((l: any) => ({ ...l }));
|
||||||
init.forEach(layer => {
|
init.forEach(layer => {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
img.crossOrigin = "anonymous";
|
||||||
img.onload = () => { layer.img = img; n++; if (n === init.length) setLayers([...init]); };
|
img.onload = () => { layer.img = img; n++; if (n === init.length) setLayers([...init]); };
|
||||||
img.src = layer.url;
|
img.src = layer.url;
|
||||||
});
|
});
|
||||||
@@ -59,6 +60,7 @@ export function UVEditor({ onClose, onSave, targetObject, loadedModel, sceneObje
|
|||||||
// If no saved layers but there's a base map texture, load it as the initial layer
|
// If no saved layers but there's a base map texture, load it as the initial layer
|
||||||
const url = targetObject.materialProps.map;
|
const url = targetObject.materialProps.map;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
img.crossOrigin = "anonymous";
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
// Automatically scale the image so it fits the 1024x1024 canvas exactly
|
// Automatically scale the image so it fits the 1024x1024 canvas exactly
|
||||||
const scaleX = CANVAS_SIZE / img.width;
|
const scaleX = CANVAS_SIZE / img.width;
|
||||||
@@ -104,7 +106,12 @@ export function UVEditor({ onClose, onSave, targetObject, loadedModel, sceneObje
|
|||||||
ctx.drawImage(layer.img, sx, sy, sw, sh, -sw / 2, -sh / 2, sw, sh);
|
ctx.drawImage(layer.img, sx, sy, sw, sh, -sw / 2, -sh / 2, sw, sh);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
});
|
});
|
||||||
return c.toDataURL(transparent ? 'image/png' : 'image/jpeg');
|
try {
|
||||||
|
return c.toDataURL(transparent ? 'image/png' : 'image/jpeg');
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Canvas render error (likely CORS taint):", e);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user