Skip to content

Commit

Permalink
Allow dropping image as new layer
Browse files Browse the repository at this point in the history
  • Loading branch information
JannisX11 committed Nov 5, 2023
1 parent 1f0ed59 commit 00db0a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions js/io/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
Expand All @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions js/texturing/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
})

Expand Down

0 comments on commit 00db0a9

Please sign in to comment.