Files
armorpaint/Assets/plugins/texsynth.js
T

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-10-12 09:41:08 +02:00
// Example-based texture synthesis written in Rust
2020-10-11 21:22:33 +02:00
// https://github.com/EmbarkStudios/texture-synthesis
2020-10-12 09:41:08 +02:00
// texsynth library is linked with armorcore until multi-threaded execution is supported via webassembly
2020-10-11 21:22:33 +02:00
// https://github.com/armory3d/armorpaint_plugins/tree/master/plugin_texsynth
let plugin = new arm.Plugin();
let h1 = new zui.Handle();
plugin.drawUI = function(ui) {
if (ui.panel(h1, "Texture Synthesis")) {
if (ui.button("Inpaint")) {
texsynthInpaint(false);
}
if (ui.button("Tiling")) {
texsynthInpaint(true);
}
}
};
function texsynthInpaint(tiling) {
let w = arm.Config.getTextureResX();
let h = arm.Config.getTextureResY();
let l = arm.Context.layer;
2020-10-12 09:41:08 +02:00
2020-10-13 11:41:00 +02:00
let bytes_img = l.texpaint.getPixels().b.bufferValue;
2020-10-24 13:58:26 +02:00
let bytes_mask = l.texpaint_mask != null ? l.texpaint_mask.getPixels().b.bufferValue : new ArrayBuffer(w * h);
2020-11-02 14:41:09 +01:00
let bytes_out = new core.Bytes(new ArrayBuffer(w * h * 4));
2020-10-13 11:41:00 +02:00
Krom.texsynthInpaint(w, h, bytes_out.b.bufferValue, bytes_img, bytes_mask, tiling);
2020-11-02 14:41:09 +01:00
let image = core.Image.fromBytes(bytes_out, w, h);
2020-10-13 11:41:00 +02:00
2020-10-30 11:52:50 +01:00
function _next() {
2020-10-13 11:41:00 +02:00
arm.Context.layerIsMask = false;
arm.History.applyFilter();
l.deleteMask();
l.texpaint.unload();
2020-11-02 14:41:09 +01:00
l.texpaint = core.Image.createRenderTarget(w, h);
2020-10-13 11:41:00 +02:00
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;
}
2020-10-30 11:52:50 +01:00
arm.App.notifyOnNextFrame(_next);
2020-10-11 21:22:33 +02:00
}