From f55931b7271934c5981654cb6c0b65427a6cd6e0 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Tue, 7 May 2019 16:57:14 +0200 Subject: [PATCH] Mask undo --- Sources/arm/LayerSlot.hx | 17 ++++++++---- Sources/arm/Layers.hx | 2 +- Sources/arm/renderpath/RenderPathDeferred.hx | 24 +++++++++++----- Sources/arm/ui/UITrait.hx | 29 +++++++++++++++----- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/Sources/arm/LayerSlot.hx b/Sources/arm/LayerSlot.hx index f3e5de26..730f4160 100644 --- a/Sources/arm/LayerSlot.hx +++ b/Sources/arm/LayerSlot.hx @@ -25,6 +25,7 @@ class LayerSlot { // For undo layer public var targetLayer:LayerSlot = null; public var targetObject:iron.object.MeshObject = null; + public var targetIsMask = false; static var first = true; @@ -119,10 +120,6 @@ class LayerSlot { } public function swap(other:LayerSlot) { - var tp = texpaint; - var tp_nor = texpaint_nor; - var tp_pack = texpaint_pack; - RenderPath.active.renderTargets.get("texpaint" + ext).image.setDepthStencilFrom(other.texpaint); RenderPath.active.renderTargets.get("texpaint" + ext).image = other.texpaint; @@ -133,15 +130,25 @@ class LayerSlot { RenderPath.active.renderTargets.get("texpaint_nor" + other.ext).image = texpaint_nor; RenderPath.active.renderTargets.get("texpaint_pack" + other.ext).image = texpaint_pack; + var tp = texpaint; + var tp_nor = texpaint_nor; + var tp_pack = texpaint_pack; texpaint = other.texpaint; texpaint_nor = other.texpaint_nor; texpaint_pack = other.texpaint_pack; - other.texpaint = tp; other.texpaint_nor = tp_nor; other.texpaint_pack = tp_pack; } + public function swapMask(other:LayerSlot) { + RenderPath.active.renderTargets.get("texpaint_mask" + ext).image = other.texpaint_mask; + RenderPath.active.renderTargets.get("texpaint_mask" + other.ext).image = texpaint_mask; + var tp_mask = texpaint_mask; + texpaint_mask = other.texpaint_mask; + other.texpaint_mask = tp_mask; + } + public function createMask(color:Int, clear = true) { if (texpaint_mask != null) return; diff --git a/Sources/arm/Layers.hx b/Sources/arm/Layers.hx index e38fe3a9..b4edb60c 100644 --- a/Sources/arm/Layers.hx +++ b/Sources/arm/Layers.hx @@ -102,7 +102,7 @@ class Layers { if (l.texpaint_mask != null) { var texpaint_mask = l.texpaint_mask; - l.texpaint_mask = kha.Image.createRenderTarget(res, res, TextureFormat.L8, DepthStencilFormat.NoDepthAndStencil); + l.texpaint_mask = kha.Image.createRenderTarget(res, res, TextureFormat.L8); l.texpaint_mask.g2.begin(false); l.texpaint_mask.g2.drawScaledImage(texpaint_mask, 0, 0, res, res); diff --git a/Sources/arm/renderpath/RenderPathDeferred.hx b/Sources/arm/renderpath/RenderPathDeferred.hx index d312ce80..8d581956 100644 --- a/Sources/arm/renderpath/RenderPathDeferred.hx +++ b/Sources/arm/renderpath/RenderPathDeferred.hx @@ -195,14 +195,24 @@ class RenderPathDeferred { var tid = UITrait.inst.selectedLayer.id; if (UITrait.inst.pushUndo) { + var isMask = UITrait.inst.selectedLayerIsMask; var i = UITrait.inst.undoI; - path.setTarget("texpaint_undo" + i, ["texpaint_nor_undo" + i, "texpaint_pack_undo" + i]); - path.bindTarget("texpaint" + tid, "tex0"); - path.bindTarget("texpaint_nor" + tid, "tex1"); - path.bindTarget("texpaint_pack" + tid, "tex2"); - path.drawShader("shader_datas/copy_mrt3_pass/copy_mrt3_pass"); - UITrait.inst.undoLayers[UITrait.inst.undoI].targetObject = UITrait.inst.paintObject; - UITrait.inst.undoLayers[UITrait.inst.undoI].targetLayer = UITrait.inst.selectedLayer; + if (isMask) { + path.setTarget("texpaint_mask_undo" + i); + path.bindTarget("texpaint_mask" + tid, "tex"); + path.drawShader("shader_datas/copy_pass/copy_pass"); + } + else { + path.setTarget("texpaint_undo" + i, ["texpaint_nor_undo" + i, "texpaint_pack_undo" + i]); + path.bindTarget((isMask ? "texpaint_mask" : "texpaint") + tid, "tex0"); + path.bindTarget("texpaint_nor" + tid, "tex1"); + path.bindTarget("texpaint_pack" + tid, "tex2"); + path.drawShader("shader_datas/copy_mrt3_pass/copy_mrt3_pass"); + } + var undoLayer = UITrait.inst.undoLayers[UITrait.inst.undoI]; + undoLayer.targetObject = UITrait.inst.paintObject; + undoLayer.targetLayer = UITrait.inst.selectedLayer; + undoLayer.targetIsMask = isMask; UITrait.inst.undoI = (UITrait.inst.undoI + 1) % UITrait.inst.C.undo_steps; if (UITrait.inst.undos < UITrait.inst.C.undo_steps) UITrait.inst.undos++; UITrait.inst.redos = 0; diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index 41deeba0..3fd95786 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -315,7 +315,11 @@ class UITrait extends iron.Trait { } if (undoLayers == null) { undoLayers = []; - for (i in 0...C.undo_steps) undoLayers.push(new LayerSlot("_undo" + undoLayers.length)); + for (i in 0...C.undo_steps) { + var l = new LayerSlot("_undo" + undoLayers.length); + l.createMask(0, false); + undoLayers.push(l); + } } if (savedEnvmap == null) { @@ -687,8 +691,8 @@ class UITrait extends iron.Trait { var lpos = layers.indexOf(lay.targetLayer); if (opos >= 0 && lpos >= 0) { selectPaintObject(paintObjects[opos]); - setLayer(layers[lpos]); - selectedLayer.swap(lay); + setLayer(layers[lpos], lay.targetIsMask); + lay.targetIsMask ? selectedLayer.swapMask(lay) : selectedLayer.swap(lay); layerPreviewDirty = true; } undos--; @@ -704,8 +708,8 @@ class UITrait extends iron.Trait { var lpos = layers.indexOf(lay.targetLayer); if (opos >= 0 && lpos >= 0) { selectPaintObject(paintObjects[opos]); - setLayer(layers[lpos]); - selectedLayer.swap(lay); + setLayer(layers[lpos], lay.targetIsMask); + lay.targetIsMask ? selectedLayer.swapMask(lay) : selectedLayer.swap(lay); layerPreviewDirty = true; } undoI = (undoI + 1) % C.undo_steps; @@ -1955,6 +1959,10 @@ class UITrait extends iron.Trait { if (ui.isReleased) { setLayer(l, true); } + if (state == State.Started) { + if (iron.system.Time.time() - selectTime < 0.25) show2DView(); + selectTime = iron.system.Time.time(); + } } ui._y += center; @@ -2209,8 +2217,15 @@ class UITrait extends iron.Trait { C.undo_steps = Std.int(ui.slider(undoHandle, "Undo Steps", 1, 64, false, 1)); if (undoHandle.changed) { ui.g.end(); - while (undoLayers.length < C.undo_steps) undoLayers.push(new LayerSlot("_undo" + undoLayers.length)); - while (undoLayers.length > C.undo_steps) { var l = undoLayers.pop(); l.unload(); } + while (undoLayers.length < C.undo_steps) { + var l = new LayerSlot("_undo" + undoLayers.length); + l.createMask(0, false); + undoLayers.push(l); + } + while (undoLayers.length > C.undo_steps) { + var l = undoLayers.pop(); + l.unload(); + } undos = 0; redos = 0; undoI = 0;