2018-10-29 15:30:46 +01:00
|
|
|
package arm;
|
|
|
|
|
|
|
|
|
|
import iron.RenderPath;
|
2019-03-02 23:41:26 +01:00
|
|
|
import arm.ui.*;
|
2018-10-29 15:30:46 +01:00
|
|
|
|
|
|
|
|
class LayerSlot {
|
2018-11-02 02:12:02 +01:00
|
|
|
public static var counter = 0;
|
2018-10-29 15:30:46 +01:00
|
|
|
public var id = 0;
|
|
|
|
|
public var visible = true;
|
2018-11-01 01:57:38 +01:00
|
|
|
public var ext = "";
|
2018-10-29 15:30:46 +01:00
|
|
|
|
2019-03-27 14:26:51 +01:00
|
|
|
public var name:String;
|
|
|
|
|
|
2018-10-29 15:30:46 +01:00
|
|
|
public var texpaint:kha.Image;
|
|
|
|
|
public var texpaint_nor:kha.Image;
|
|
|
|
|
public var texpaint_pack:kha.Image;
|
|
|
|
|
|
2019-03-27 14:26:51 +01:00
|
|
|
public var texpaint_preview:kha.Image; // Layer preview
|
|
|
|
|
|
2019-03-27 18:26:37 +01:00
|
|
|
public var texpaint_mask:kha.Image = null;
|
|
|
|
|
public var texpaint_mask_preview:kha.Image;
|
2019-03-28 15:21:45 +01:00
|
|
|
public var maskOpacity = 1.0;
|
2019-03-27 18:26:37 +01:00
|
|
|
|
2018-11-01 01:57:38 +01:00
|
|
|
// For undo layer
|
|
|
|
|
public var targetLayer:LayerSlot = null;
|
|
|
|
|
public var targetObject:iron.object.MeshObject = null;
|
2018-10-29 15:30:46 +01:00
|
|
|
|
2019-03-12 17:54:08 +01:00
|
|
|
static var first = true;
|
|
|
|
|
|
2019-03-25 21:56:39 +01:00
|
|
|
public var objectMask = 0;
|
2019-03-26 15:22:07 +01:00
|
|
|
public var paintBase = true;
|
|
|
|
|
public var paintOpac = true;
|
|
|
|
|
public var paintOcc = true;
|
|
|
|
|
public var paintRough = true;
|
|
|
|
|
public var paintMet = true;
|
|
|
|
|
public var paintNor = true;
|
|
|
|
|
public var paintHeight = false;
|
|
|
|
|
public var paintEmis = false;
|
|
|
|
|
public var paintSubs = false;
|
2019-03-25 21:56:39 +01:00
|
|
|
|
2019-04-07 13:54:44 +02:00
|
|
|
var createMaskColor:Int;
|
|
|
|
|
|
2018-10-29 15:30:46 +01:00
|
|
|
public function new(ext = "") {
|
2019-03-12 17:54:08 +01:00
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
|
first = false;
|
|
|
|
|
{
|
|
|
|
|
var t = new RenderTargetRaw();
|
2019-03-27 18:26:37 +01:00
|
|
|
t.name = "texpaint_blend0";
|
2019-03-12 17:54:08 +01:00
|
|
|
t.width = Config.getTextureRes();
|
|
|
|
|
t.height = Config.getTextureRes();
|
|
|
|
|
t.format = 'R8';
|
|
|
|
|
RenderPath.active.createRenderTarget(t);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var t = new RenderTargetRaw();
|
2019-03-27 18:26:37 +01:00
|
|
|
t.name = "texpaint_blend1";
|
2019-03-12 17:54:08 +01:00
|
|
|
t.width = Config.getTextureRes();
|
|
|
|
|
t.height = Config.getTextureRes();
|
|
|
|
|
t.format = 'R8';
|
|
|
|
|
RenderPath.active.createRenderTarget(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 15:30:46 +01:00
|
|
|
if (ext == "") {
|
|
|
|
|
id = counter++;
|
|
|
|
|
ext = id + "";
|
|
|
|
|
}
|
|
|
|
|
this.ext = ext;
|
2019-03-27 14:26:51 +01:00
|
|
|
name = "Layer " + (id + 1);
|
2018-10-29 15:30:46 +01:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
var t = new RenderTargetRaw();
|
|
|
|
|
t.name = "texpaint" + ext;
|
2019-02-02 18:49:19 +01:00
|
|
|
t.width = Config.getTextureRes();
|
|
|
|
|
t.height = Config.getTextureRes();
|
2018-10-29 15:30:46 +01:00
|
|
|
t.format = 'RGBA32';
|
|
|
|
|
t.depth_buffer = "paintdb";
|
|
|
|
|
texpaint = RenderPath.active.createRenderTarget(t).image;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var t = new RenderTargetRaw();
|
|
|
|
|
t.name = "texpaint_nor" + ext;
|
2019-02-02 18:49:19 +01:00
|
|
|
t.width = Config.getTextureRes();
|
|
|
|
|
t.height = Config.getTextureRes();
|
2018-10-29 15:30:46 +01:00
|
|
|
t.format = 'RGBA32';
|
|
|
|
|
texpaint_nor = RenderPath.active.createRenderTarget(t).image;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var t = new RenderTargetRaw();
|
|
|
|
|
t.name = "texpaint_pack" + ext;
|
2019-02-02 18:49:19 +01:00
|
|
|
t.width = Config.getTextureRes();
|
|
|
|
|
t.height = Config.getTextureRes();
|
2018-10-29 15:30:46 +01:00
|
|
|
t.format = 'RGBA32';
|
|
|
|
|
texpaint_pack = RenderPath.active.createRenderTarget(t).image;
|
|
|
|
|
}
|
2019-03-27 14:26:51 +01:00
|
|
|
|
|
|
|
|
texpaint_preview = kha.Image.createRenderTarget(200, 200, kha.graphics4.TextureFormat.RGBA32);
|
2018-10-29 15:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function unload() {
|
2019-02-26 22:13:00 +01:00
|
|
|
// Set null depth so paintdb stays alive
|
|
|
|
|
if (UITrait.inst.layers.length > 0 && UITrait.inst.layers[0] != this) {
|
|
|
|
|
texpaint.setDepthStencilFrom(texpaint_nor);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 15:30:46 +01:00
|
|
|
texpaint.unload();
|
|
|
|
|
texpaint_nor.unload();
|
|
|
|
|
texpaint_pack.unload();
|
2018-10-29 17:43:40 +01:00
|
|
|
|
|
|
|
|
RenderPath.active.renderTargets.remove("texpaint" + ext);
|
|
|
|
|
RenderPath.active.renderTargets.remove("texpaint_nor" + ext);
|
|
|
|
|
RenderPath.active.renderTargets.remove("texpaint_pack" + ext);
|
2019-03-27 14:26:51 +01:00
|
|
|
|
|
|
|
|
texpaint_preview.unload();
|
2019-03-27 18:26:37 +01:00
|
|
|
|
|
|
|
|
deleteMask();
|
2018-10-29 15:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function swap(other:LayerSlot) {
|
|
|
|
|
var tp = texpaint;
|
|
|
|
|
var tp_nor = texpaint_nor;
|
|
|
|
|
var tp_pack = texpaint_pack;
|
|
|
|
|
|
2019-03-13 16:03:40 +01:00
|
|
|
RenderPath.active.renderTargets.get("texpaint" + ext).image.setDepthStencilFrom(other.texpaint);
|
|
|
|
|
|
2018-10-29 15:30:46 +01:00
|
|
|
RenderPath.active.renderTargets.get("texpaint" + ext).image = other.texpaint;
|
|
|
|
|
RenderPath.active.renderTargets.get("texpaint_nor" + ext).image = other.texpaint_nor;
|
|
|
|
|
RenderPath.active.renderTargets.get("texpaint_pack" + ext).image = other.texpaint_pack;
|
|
|
|
|
|
|
|
|
|
RenderPath.active.renderTargets.get("texpaint" + other.ext).image = texpaint;
|
|
|
|
|
RenderPath.active.renderTargets.get("texpaint_nor" + other.ext).image = texpaint_nor;
|
|
|
|
|
RenderPath.active.renderTargets.get("texpaint_pack" + other.ext).image = 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;
|
|
|
|
|
}
|
2019-03-27 18:26:37 +01:00
|
|
|
|
2019-03-28 15:21:45 +01:00
|
|
|
public function createMask(color:Int) {
|
2019-03-27 18:26:37 +01:00
|
|
|
if (texpaint_mask != null) return;
|
|
|
|
|
|
2019-03-28 15:21:45 +01:00
|
|
|
createMaskColor = color;
|
|
|
|
|
|
2019-03-27 18:26:37 +01:00
|
|
|
{
|
|
|
|
|
var t = new RenderTargetRaw();
|
|
|
|
|
t.name = "texpaint_mask" + ext;
|
|
|
|
|
t.width = Config.getTextureRes();
|
|
|
|
|
t.height = Config.getTextureRes();
|
|
|
|
|
t.format = 'R8';
|
|
|
|
|
texpaint_mask = RenderPath.active.createRenderTarget(t).image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
texpaint_mask_preview = kha.Image.createRenderTarget(200, 200, kha.graphics4.TextureFormat.L8);
|
|
|
|
|
|
|
|
|
|
iron.App.notifyOnRender(clearMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearMask(g:kha.graphics4.Graphics) {
|
|
|
|
|
g.end();
|
|
|
|
|
|
|
|
|
|
texpaint_mask.g4.begin();
|
2019-03-28 15:21:45 +01:00
|
|
|
texpaint_mask.g4.clear(createMaskColor);
|
2019-03-27 18:26:37 +01:00
|
|
|
texpaint_mask.g4.end();
|
|
|
|
|
|
|
|
|
|
g.begin();
|
|
|
|
|
iron.App.removeRender(clearMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteMask() {
|
|
|
|
|
if (texpaint_mask == null) return;
|
|
|
|
|
|
|
|
|
|
texpaint_mask.unload();
|
|
|
|
|
RenderPath.active.renderTargets.remove("texpaint_mask" + ext);
|
2019-03-27 21:23:50 +01:00
|
|
|
texpaint_mask = null;
|
2019-03-27 18:26:37 +01:00
|
|
|
|
2019-03-27 21:23:50 +01:00
|
|
|
texpaint_mask_preview.unload();
|
2019-03-27 18:26:37 +01:00
|
|
|
}
|
2018-10-29 15:30:46 +01:00
|
|
|
}
|