Pass mask to texture synthesis

This commit is contained in:
luboslenco
2020-10-13 11:41:00 +02:00
parent b24a58a77f
commit a9b0bfa3f9
5 changed files with 62 additions and 14 deletions
+31 -14
View File
@@ -22,22 +22,39 @@ function texsynthInpaint(tiling) {
let w = arm.Config.getTextureResX();
let h = arm.Config.getTextureResY();
let l = arm.Context.layer;
if (l.texpaint_mask == null) return;
let bytes_img = l.texpaint.getPixels().b.bufferValue;
let bytes_mask = l.texpaint_mask.getPixels().b.bufferValue;
let view_img = new Uint8Array(bytes_img);
let view_mask = new Uint8Array(bytes_mask);
for (let i = 0; i < view_img.length / 4; ++i) {
view_img[i * 4 + 3] = view_mask[i];
if (l.texpaint_mask == null) {
return;
}
let bytes_img = l.texpaint.getPixels().b.bufferValue;
let bytes_mask = l.texpaint_mask.getPixels().b.bufferValue;
let bytes_out = new arm.Bytes(new ArrayBuffer(w * h * 4));
Krom.texsynthInpaint(w, h, bytes_out.b.bufferValue, bytes_img, tiling);
Krom.texsynthInpaint(w, h, bytes_out.b.bufferValue, bytes_img, bytes_mask, tiling);
let image = arm.Image.fromBytes(bytes_out, w, h);
var asset = {name: "tex_synth.png", file: "/tex_synth.png", id: arm.Project.assetId++};
iron.Data.cachedImages.h[asset.file] = image;
arm.Project.assets.push(asset);
arm.Project.assetNames.push(asset.name);
arm.Project.assetMap.h[asset.id] = image;
function apply(g) {
g.end();
arm.Context.layerIsMask = false;
arm.History.applyFilter();
l.deleteMask();
l.texpaint.unload();
l.texpaint = arm.Image.createRenderTarget(w, h);
let g2 = l.texpaint.get_g2();
g2.begin(false);
g2.drawImage(image, 0, 0);
g2.end();
let rts = iron.RenderPath.active.renderTargets;
rts.h["texpaint" + l.ext].image = l.texpaint;
arm.MakeMaterial.parseMeshMaterial();
arm.App.redrawUI();
arm.Context.layerPreviewDirty = true;
g.begin();
iron.App.removeRender(apply);
}
iron.App.notifyOnRender(apply);
}
+1
View File
@@ -322,6 +322,7 @@ class App {
UIMenubar.inst.menuHandle.redraws = 2;
UIMenubar.inst.workspaceHandle.redraws = 2;
UINodes.inst.hwnd.redraws = 2;
UIView2D.inst.hwnd.redraws = 2;
if (Context.ddirty < 0) Context.ddirty = 0; // Redraw viewport
}
+26
View File
@@ -115,6 +115,16 @@ class History {
Context.layersPreviewDirty = true;
Context.setLayer(Context.layer, true);
}
else if (step.name == "Apply Filter") {
undoI = undoI - 1 < 0 ? Config.raw.undo_steps - 1 : undoI - 1;
var lay = undoLayers[undoI];
Context.setLayer(Project.layers[step.layer], step.is_mask);
Context.layer.swap(lay);
Context.layer.createMask(0, false);
Context.layer.swapMask(lay);
lay.deleteMask();
Context.layerPreviewDirty = true;
}
else if (step.name == tr("To Fill Layer")) {
Context.layer.toPaintLayer();
undoI = undoI - 1 < 0 ? Config.raw.undo_steps - 1 : undoI - 1;
@@ -233,6 +243,16 @@ class History {
}
iron.App.notifyOnRender(makeApply);
}
else if (step.name == tr("Apply Filter")) {
var lay = undoLayers[undoI];
Context.setLayer(Project.layers[step.layer], false);
Context.layer.swap(lay);
lay.createMask(0, false);
Context.layer.swapMask(lay);
Context.layer.deleteMask();
Context.layerPreviewDirty = true;
undoI = (undoI + 1) % Config.raw.undo_steps;
}
else if (step.name == tr("To Fill Layer")) {
var lay = undoLayers[undoI];
Context.layer.swap(lay);
@@ -353,6 +373,12 @@ class History {
push(tr("Apply Mask"));
}
@:keep
public static function applyFilter() {
copyToUndoWithMask();
push(tr("Apply Filter"));
}
public static function toFillLayer() {
copyToUndo(Context.layer.id, undoI, false);
push(tr("To Fill Layer"));
+1
View File
@@ -80,6 +80,7 @@ class ArmBridge {
public static var NodesMaterial = arm.shader.NodesMaterial;
public static var NodesBrush = arm.node.NodesBrush;
public static var MaterialParser = arm.shader.MaterialParser;
public static var MakeMaterial = arm.node.MakeMaterial;
public static var Brush = arm.node.Brush;
public static var UISidebar = arm.ui.UISidebar;
public static var UINodes = arm.ui.UINodes;
+3
View File
@@ -169,6 +169,9 @@ class LayerSlot {
var _texpaint_mask = texpaint_mask;
texpaint_mask = other.texpaint_mask;
other.texpaint_mask = _texpaint_mask;
var _texpaint_mask_preview = texpaint_mask_preview;
texpaint_mask_preview = other.texpaint_mask_preview;
other.texpaint_mask_preview = _texpaint_mask_preview;
}
public function createMask(color: Int, clear = true, image: Image = null) {