Viewpoint shortcut

This commit is contained in:
luboslenco
2019-02-25 12:43:49 +01:00
parent 9c396b1965
commit db2fd03bc9
2 changed files with 88 additions and 16 deletions
+46 -15
View File
@@ -190,7 +190,8 @@ class UITrait extends iron.Trait {
var textureExport = false;
var textureExportPath = "";
public var projectExport = false;
var headerHandle = Id.handle({layout:Horizontal});
var headerHandle = new Zui.Handle({layout:Horizontal});
var toolbarHandle = new Zui.Handle();
var drawMenu = false;
var menuCategory = 0;
@@ -402,7 +403,7 @@ class UITrait extends iron.Trait {
}
}
}
else if (kb.started("1") && (shift || ctrl)) shift ? setBrushType(0) : selectMaterial(0);
if (kb.started("1") && (shift || ctrl)) shift ? setBrushType(0) : selectMaterial(0);
else if (kb.started("2") && (shift || ctrl)) shift ? setBrushType(1) : selectMaterial(1);
else if (kb.started("3") && (shift || ctrl)) shift ? setBrushType(2) : selectMaterial(2);
else if (kb.started("4") && (shift || ctrl)) shift ? setBrushType(3) : selectMaterial(3);
@@ -433,11 +434,12 @@ class UITrait extends iron.Trait {
UINodes.inst.parsePaintMaterial();
}
// Color pick shortcut
// Viewport shortcuts
var mouse = iron.system.Input.getMouse();
if (mouse.x > 0 && mouse.x < iron.App.w() &&
mouse.y > 0 && mouse.y < iron.App.h()) {
// Color pick shortcut
if (kb.started("alt")) {
altStartedX = mouse.x;
altStartedY = mouse.y;
@@ -455,18 +457,36 @@ class UITrait extends iron.Trait {
altStartedY = -1.0;
}
if (kb.released("-")) {
// Radius
if (kb.started("-")) {
if (brushRadius > 0.1) {
brushRadius -= 0.1;
brushRadius = Math.round((brushRadius - 0.1) * 100) / 100;
brushRadiusHandle.value = brushRadius;
headerHandle.redraws = 2;
}
}
if (kb.released("+")) {
else if (kb.started("+")) {
if (brushRadius < 2.0) {
brushRadius += 0.1;
brushRadius = Math.round((brushRadius + 0.1) * 100) / 100;
brushRadiusHandle.value = brushRadius;
headerHandle.redraws = 2;
}
}
// Viewpoint
if (kb.started("0")) {
ViewportUtil.resetViewport();
ViewportUtil.scaleToBounds();
}
else if (kb.started("1")) {
ViewportUtil.setView(0, -3, 0, Math.PI / 2, 0, 0);
}
else if (kb.started("3")) {
ViewportUtil.setView(3, 0, 0, Math.PI / 2, 0, Math.PI / 2);
}
else if (kb.started("7")) {
ViewportUtil.setView(0, 0, 3, 0, 0, 0);
}
}
for (p in Plugin.plugins) if (p.update != null) p.update();
@@ -764,6 +784,7 @@ class UITrait extends iron.Trait {
UINodes.inst.parseMeshMaterial();
hwnd.redraws = 2;
headerHandle.redraws = 2;
toolbarHandle.redraws = 2;
ddirty = 2;
}
@@ -885,7 +906,7 @@ class UITrait extends iron.Trait {
// ui.t.FILL_WINDOW_BG = false;
var panelx = (iron.App.x() - toolbarw);
if (C.ui_layout == 1 && (UINodes.inst.show || UIView2D.inst.show)) panelx = panelx - App.w() - toolbarw;
if (ui.window(Id.handle(), panelx, headerh, toolbarw, kha.System.windowHeight())) {
if (ui.window(toolbarHandle, panelx, headerh, toolbarw, kha.System.windowHeight())) {
ui._y += 2;
ui.imageScrollAlign = false;
@@ -1059,20 +1080,25 @@ class UITrait extends iron.Trait {
cameraControls = ui.combo(Id.handle({position: cameraControls}), ["Rotate", "Orbit", "Fly"], "Controls");
cameraType = ui.combo(camHandle, ["Perspective", "Orhographic"], "Type");
if (camHandle.changed) {
if (cameraType == 0) cam.data.raw.ortho = null;
if (cameraType == 0) {
cam.data.raw.ortho = null;
cam.buildProjection();
}
else {
var f32 = new kha.arrays.Float32Array(4);
f32[0] = -2;
f32[1] = 2;
f32[2] = -2 * (iron.App.h() / iron.App.w());
f32[2] = 2 * (iron.App.h() / iron.App.w());
cam.data.raw.ortho = f32;
f32[3] = 2 * (iron.App.h() / iron.App.w());
// cam.data.raw.ortho = f32; // See ViewportUtil.ortho
// cam.buildProjection();
cam.P = ViewportUtil.ortho(f32[0], f32[1], f32[2], f32[3], cam.data.raw.near_plane, cam.data.raw.far_plane);
#if arm_taa
cam.noJitterP.setFrom(cam.P);
#end
}
// if (originalShadowBias <= 0) originalShadowBias = iron.Scene.active.lights[0].data.raw.shadows_bias;
// iron.Scene.active.lights[0].data.raw.shadows_bias = cameraType == 0 ? originalShadowBias : originalShadowBias * 15;
cam.buildProjection();
ddirty = 2;
}
@@ -2004,6 +2030,11 @@ class UITrait extends iron.Trait {
ui.text("Next Object - Ctrl+Tab");
ui.text("Auto-Fill - G");
ui.text("Brush Radius - +/-");
ui.text("Brush Ruler - Hold Shift");
ui.text("View Default - 0");
ui.text("View Front - 1");
ui.text("View Right - 3");
ui.text("View Top - 7");
}
ui.separator();
+42 -1
View File
@@ -1,5 +1,9 @@
package arm;
import iron.math.Mat4;
import iron.math.Vec4;
import iron.math.Quat;
class ViewportUtil {
public static function scaleToBounds() {
var po = UITrait.inst.mergedObject == null ? UITrait.inst.mainObject() : UITrait.inst.mergedObject;
@@ -16,7 +20,7 @@ class ViewportUtil {
public static function resetViewport() {
var scene = iron.Scene.active;
var cam = scene.cameras[0];
var cam = scene.camera;
for (o in scene.raw.objects) {
if (o.type == 'camera_object') {
cam.transform.local.setF32(o.transform.values);
@@ -34,4 +38,41 @@ class ViewportUtil {
}
}
}
public static function setView(x:Float, y:Float, z:Float, rx:Float, ry:Float, rz:Float) {
UITrait.inst.selectedObject.transform.reset();
var scene = iron.Scene.active;
var cam = scene.camera;
cam.transform.loc.set(x, y, z);
cam.transform.rot.fromEuler(rx, ry, rz);
cam.transform.buildMatrix();
cam.buildProjection();
UITrait.inst.ddirty = 2;
}
public static inline function ortho(left:kha.FastFloat, right:kha.FastFloat, bottom:kha.FastFloat, top:kha.FastFloat, near:kha.FastFloat, far:kha.FastFloat):Mat4 {
// For runtime shader, D3D NDC is not matched to OGL yet
// Build proper ortho matrix
var rl = right - left;
var tb = top - bottom;
var tx = -(right + left) / (rl);
var ty = -(top + bottom) / (tb);
#if (kha_opengl || kha_webgl)
var fn = far - near;
var tz = -(far + near) / (fn);
var w = -2 / fn;
#else
var nf = near - far;
var tz = -(near) / (nf);
var w = 1 / nf;
#end
return new Mat4(
2 / rl, 0, 0, tx,
0, 2 / tb, 0, ty,
0, 0, w, tz,
0, 0, 0, 1
);
}
}