diff --git a/js/io/io.js b/js/io/io.js index b66ec4b7f..2a0bb06ba 100644 --- a/js/io/io.js +++ b/js/io/io.js @@ -105,6 +105,7 @@ async function loadImages(files, event) { img.onerror = reject; }) + // Options if (Project && texture_li && texture_li.length) { replace_texture = Texture.all.findInArray('uuid', texture_li.attr('texid')) if (replace_texture) { @@ -115,6 +116,9 @@ async function loadImages(files, event) { if (Condition(Panels.textures.condition)) { options.texture = 'action.import_texture'; } + if (Modes.paint && document.querySelector('#UVEditor:hover') && Texture.selected) { + options.layer = 'data.layer'; + } options.reference_image = 'data.reference_image'; } options.edit = 'message.load_images.edit_image'; @@ -139,6 +143,27 @@ async function loadImages(files, event) { replace_texture.fromFile(files[0]) updateSelection(); + } else if (method == 'layer') { + let texture = Texture.getDefault(); + let frame = new CanvasFrame(img); + Undo.initEdit({textures: [texture], bitmap: true}); + if (!texture.layers_enabled) { + texture.activateLayers(false); + } + let layer = new TextureLayer({name: files[0].name, offset: [0, 0]}, texture); + let image_data = frame.ctx.getImageData(0, 0, frame.width, frame.height); + layer.setSize(frame.width, frame.height); + layer.ctx.putImageData(image_data, 0, 0); + texture.layers.push(layer); + layer.select(); + layer.setLimbo(); + texture.updateLayerChanges(true); + + Undo.finishEdit('Add image as layer'); + updateInterfacePanels(); + BARS.updateConditions(); + BarItems.move_layer_tool.select(); + } else if (method == 'reference_image') { files.map(file => { diff --git a/js/texturing/layers.js b/js/texturing/layers.js index 03c5b753e..3be5444af 100644 --- a/js/texturing/layers.js +++ b/js/texturing/layers.js @@ -156,12 +156,12 @@ new Property(TextureLayer, 'boolean', 'visible', {default: true}); Object.defineProperty(TextureLayer, 'all', { get() { - Texture.selected?.layers_enabled ? Texture.selected.layers : []; + return Texture.selected?.layers_enabled ? Texture.selected.layers : []; } }) Object.defineProperty(TextureLayer, 'selected', { get() { - Texture.selected?.selected_layer; + return Texture.selected?.selected_layer; } })