Add Expand Layer to Texture Size

Fix image loading issues
This commit is contained in:
JannisX11 2023-11-10 21:05:36 +01:00
parent 8002f335f4
commit f8837ddd07
5 changed files with 33 additions and 3 deletions

View File

@ -44,12 +44,12 @@ let codec = new Codec('image', {
texture.load_callback = () => {
delete texture.load_callback;
texture.select();
if (resolution instanceof Array) {
if (resolution instanceof Array && resolution[0] && resolution[1]) {
texture.uv_width = resolution[0];
texture.uv_height = resolution[1];
} else {
texture.uv_width = texture.width;
texture.uv_height = texture.display_height;
texture.uv_width = texture.width;
}
if (i == files.length-1) {

View File

@ -246,6 +246,7 @@ class TextureLayer {
}
TextureLayer.prototype.menu = new Menu([
new MenuSeparator('settings'),
'layer_to_texture_size',
new MenuSeparator('copypaste'),
'copy',
'duplicate',
@ -391,6 +392,25 @@ BARS.defineActions(() => {
Texture.selected.updateLayerChanges(true);
}
})
new Action('layer_to_texture_size', {
icon: 'fit_screen',
category: 'layers',
condition: () => TextureLayer.selected,
click() {
let layer = TextureLayer.selected;
Undo.initEdit({layers: [layer], bitmap: true});
let copy = Painter.copyCanvas(layer.canvas);
layer.canvas.width = layer.texture.width;
layer.canvas.height = layer.texture.height;
layer.ctx.drawImage(copy, layer.offset[0], layer.offset[1]);
console.log(copy, layer.offset[0], layer.offset[1])
layer.offset.V2_set(0, 0);
Undo.finishEdit('Expand layer to texture size');
layer.texture.updateLayerChanges(true);
}
})
})
Interface.definePanels(function() {

View File

@ -1300,6 +1300,14 @@ const Painter = {
return canvas;
}
},
copyCanvas(original_canvas) {
let canvas = document.createElement('canvas');
let ctx = canvas.getContext('2d');
canvas.width = original_canvas.width;
canvas.height = original_canvas.height;
ctx.drawImage(original_canvas, 0, 0);
return canvas;
},
scanCanvas(ctx, x, y, w, h, cb) {
let local_x = x;
let local_y = y;

View File

@ -1748,7 +1748,7 @@ class Texture {
return;
}
let copy = texture.getUndoCopy();
Codecs.image.load(copy, texture.path, [texture.naturalWidth, texture.naturalHeight]);
Codecs.image.load(copy, texture.path, [texture.uv_width, texture.uv_height]);
}
},
{

View File

@ -1490,6 +1490,8 @@
"action.enable_texture_layers": "Enable Layers",
"action.disable_texture_layers": "Disable Layers",
"action.layer_opacity": "Layer Opacity",
"action.layer_to_texture_size": "Expand Layer to Texture Size",
"action.layer_to_texture_size.desc": "Expand the layer to the size of the texture",
"action.add_display_preset": "New Preset",
"action.add_display_preset.desc": "Add a new display setting preset",