Texture view

This commit is contained in:
luboslenco
2019-05-17 14:05:13 +02:00
parent b892459570
commit d10b18a249
3 changed files with 68 additions and 25 deletions
+1
View File
@@ -227,6 +227,7 @@ class Importer {
var name = ar[ar.length - 1];
var asset:TAsset = {name: name, file: path, id: UITrait.inst.assetId++};
UITrait.inst.assets.push(asset);
if (UITrait.inst.selectedTexture == null) UITrait.inst.selectedTexture = asset;
UITrait.inst.assetNames.push(name);
Canvas.assetMap.set(asset.id, image);
UITrait.inst.hwnd2.redraws = 2;
+22 -5
View File
@@ -117,6 +117,7 @@ class UITrait extends iron.Trait {
public var selectedMaterial:MaterialSlot;
public var materials2:Array<MaterialSlot> = null;
public var selectedMaterial2:MaterialSlot;
public var selectedTexture:TAsset = null;
public var brushes:Array<BrushSlot> = null;
public var selectedBrush:BrushSlot;
public var selectedLogic:BrushSlot;
@@ -914,11 +915,12 @@ class UITrait extends iron.Trait {
// function showParticleNodes() {}
function show2DView() {
function show2DView(type = 0) {
// Clear input state as ui receives input events even when not drawn
@:privateAccess UIView2D.inst.ui.endInput();
UIView2D.inst.show = !UIView2D.inst.show;
if (UIView2D.inst.type != type) UIView2D.inst.show = true;
else UIView2D.inst.show = !UIView2D.inst.show;
UIView2D.inst.type = type;
arm.App.resize();
}
@@ -986,7 +988,7 @@ class UITrait extends iron.Trait {
}
public function getImage(asset:TAsset):kha.Image {
return Canvas.assetMap.get(asset.id);
return asset != null ? Canvas.assetMap.get(asset.id) : null;
}
public function mainObject():MeshObject {
@@ -2157,7 +2159,7 @@ class UITrait extends iron.Trait {
if (ui.window(hwnd2, wx, wh * 2, windowW, wh)) {
if (ui.tab(htab2, "Textures")) {
ui.row([1/4]);
ui.row([1/4, 1/4]);
if (ui.button("Import")) {
arm.App.showFiles = true;
@@ -2172,6 +2174,8 @@ class UITrait extends iron.Trait {
}
if (ui.isHovered) ui.tooltip("Import texture file (Ctrl + Shift + I)");
if (ui.button("2D View")) show2DView(1);
if (assets.length > 0) {
for (i in 0...assets.length) {
@@ -2182,9 +2186,22 @@ class UITrait extends iron.Trait {
}
var asset = assets[i];
if (asset == selectedTexture) {
var off = i % 2 == 1 ? 1 : 0;
var w = 51 - App.C.window_scale;
ui.fill(1, -2, w + 3, 2, ui.t.HIGHLIGHT_COL);
ui.fill(1, w - off, w + 3, 2 + off, ui.t.HIGHLIGHT_COL);
ui.fill(1, -2, 2, w + 3, ui.t.HIGHLIGHT_COL);
ui.fill(w + 3, -2, 2, w + 4, ui.t.HIGHLIGHT_COL);
}
var img = UITrait.inst.getImage(asset);
if (ui.image(img) == State.Started) {
arm.App.dragAsset = asset;
selectedTexture = asset;
if (iron.system.Time.time() - selectTime < 0.25) show2DView(1);
selectTime = iron.system.Time.time();
}
if (ui.isHovered) ui.tooltipImage(img, 256);
+45 -20
View File
@@ -9,6 +9,7 @@ class UIView2D extends iron.Trait {
public static var inst:UIView2D;
public var show = false;
public var type = 0; // Layer, texture
public var wx:Int;
public var wy:Int;
public var ww:Int;
@@ -88,13 +89,21 @@ class UIView2D extends iron.Trait {
// Texture
ui.g.pipeline = pipe;
var l = UITrait.inst.selectedLayer;
var tex = texType == 0 ? l.texpaint : texType == 1 ? l.texpaint_nor : l.texpaint_pack;
if (UITrait.inst.selectedLayerIsMask) tex = l.texpaint_mask;
ui.g.drawScaledImage(tex, tx, ty, tw, tw);
var tex:kha.Image = null;
if (type == 0) { // Layer
tex = texType == 0 ? l.texpaint : texType == 1 ? l.texpaint_nor : l.texpaint_pack;
if (UITrait.inst.selectedLayerIsMask) tex = l.texpaint_mask;
}
else { // Texture
tex = UITrait.inst.getImage(UITrait.inst.selectedTexture);
}
if (tex != null) ui.g.drawScaledImage(tex, tx, ty, tw, tw);
ui.g.pipeline = null;
// UV map
if (uvmapShow) {
if (type == 0 && uvmapShow) {
ui.g.drawScaledImage(UVUtil.uvmap, tx, ty, tw, tw);
}
@@ -111,8 +120,22 @@ class UIView2D extends iron.Trait {
ui._y = wh - ui.ELEMENT_H() * 1.2;
ui._w = Std.int(ui.ELEMENT_W() * 1.4);
var h = Id.handle();
h.text = l.name;
l.name = ui.textInput(h, "", Right);
if (type == 0) {
h.text = l.name;
l.name = ui.textInput(h, "", Right);
}
else {
var asset = UITrait.inst.selectedTexture;
if (asset != null) {
var assetNames = UITrait.inst.assetNames;
var i = assetNames.indexOf(asset.name);
h.text = asset.name;
asset.name = ui.textInput(h, "", Right);
assetNames[i] = asset.name;
}
}
if (h.changed) UITrait.inst.hwnd.redraws = 2;
ui.t.ACCENT_COL = ACCENT_COL;
ui.t.BUTTON_H = BUTTON_H;
@@ -120,19 +143,21 @@ class UIView2D extends iron.Trait {
ui.fontSize = FONT_SIZE;
// Controls
var ew = Std.int(ui.ELEMENT_W());
ui.g.color = ui.t.WINDOW_BG_COL;
ui.g.fillRect(0, 0, ww, 24 * ui.SCALE);
ui.g.color = 0xffffffff;
ui._x = 3;
ui._y = 3;
ui._w = ew;
texType = ui.combo(Id.handle({position: texType}), ["Base", "Normal Map", "ORM"], "Texture");
ui._x += ew + 3;
ui._y = 3;
uvmapShow = ui.check(Id.handle({selected: uvmapShow}), "UV Map");
ui._x += ew + 3;
ui._y = 3;
if (type == 0) {
var ew = Std.int(ui.ELEMENT_W());
ui.g.color = ui.t.WINDOW_BG_COL;
ui.g.fillRect(0, 0, ww, 24 * ui.SCALE);
ui.g.color = 0xffffffff;
ui._x = 3;
ui._y = 3;
ui._w = ew;
texType = ui.combo(Id.handle({position: texType}), ["Base", "Normal Map", "ORM"], "Texture");
ui._x += ew + 3;
ui._y = 3;
uvmapShow = ui.check(Id.handle({selected: uvmapShow}), "UV Map");
ui._x += ew + 3;
ui._y = 3;
}
}
ui.end();
g.begin(false);
@@ -160,7 +185,7 @@ class UIView2D extends iron.Trait {
if (panScale > 3.0) panScale = 3.0;
}
if (m.down("left")) {
if (type == 0 && m.down("left")) {
UITrait.inst.paint2d = true;
}
}