Scaling with 3d gizmo

This commit is contained in:
luboslenco
2020-12-11 17:12:31 +01:00
parent dc96e26e70
commit f02e47fbfd
9 changed files with 139 additions and 75 deletions
+1
View File
@@ -1,3 +1,4 @@
build*/
.vscode
*.DS_Store
*.blend1
Binary file not shown.
Binary file not shown.
+19 -9
View File
@@ -137,15 +137,25 @@ class Context {
public static var cloneDeltaY = 0.0;
public static var gizmo: Object = null;
public static var gizmoX: Object = null;
public static var gizmoY: Object = null;
public static var gizmoZ: Object = null;
public static var axisX = false;
public static var axisY = false;
public static var axisZ = false;
public static var axisStarted = false;
public static var axisStart = 0.0;
public static var axisLoc = 0.0;
public static var gizmoTranslateX: Object = null;
public static var gizmoTranslateY: Object = null;
public static var gizmoTranslateZ: Object = null;
public static var gizmoScaleX: Object = null;
public static var gizmoScaleY: Object = null;
public static var gizmoScaleZ: Object = null;
public static var gizmoStarted = false;
public static var gizmoOffset = 0.0;
public static var gizmoDrag = 0.0;
public static var gizmoDragLast = 0.0;
public static var translateX = false;
public static var translateY = false;
public static var translateZ = false;
public static var scaleX = false;
public static var scaleY = false;
public static var scaleZ = false;
public static var rotateX = false;
public static var rotateY = false;
public static var rotateZ = false;
public static var brushNodesRadius = 1.0;
public static var brushNodesOpacity = 1.0;
+1 -1
View File
@@ -220,7 +220,7 @@ class Project {
}
}
var n = Context.projectType == ModelRoundedCube ? "Cube" : "Tessellated";
var n = Context.projectType == ModelRoundedCube ? ".Cube" : "Tessellated";
Data.getMesh("Scene", n, function(md: MeshData) {
var current = @:privateAccess kha.graphics2.Graphics.current;
+90 -39
View File
@@ -5,6 +5,7 @@ import iron.object.LightObject;
import iron.system.Input;
import iron.math.RayCaster;
import iron.math.Vec4;
import iron.math.Quat;
import iron.Scene;
import arm.ui.UISidebar;
import arm.ui.UIHeader;
@@ -13,6 +14,8 @@ import arm.Enums;
class Gizmo {
static var v = new Vec4();
static var v0 = new Vec4();
static var q = new Quat();
public static function update() {
@@ -37,9 +40,12 @@ class Gizmo {
var cam = Scene.active.camera;
var dist = Vec4.distance(cam.transform.loc, gizmo.transform.loc) / 10;
gizmo.transform.scale.set(dist, dist, dist);
Context.gizmoX.transform.scale.set(dist, dist, dist);
Context.gizmoY.transform.scale.set(dist, dist, dist);
Context.gizmoZ.transform.scale.set(dist, dist, dist);
Context.gizmoTranslateX.transform.scale.set(dist / 2, dist, dist);
Context.gizmoTranslateY.transform.scale.set(dist, dist / 2, dist);
Context.gizmoTranslateZ.transform.scale.set(dist, dist, dist / 2);
Context.gizmoScaleX.transform.scale.set(dist, dist, dist);
Context.gizmoScaleY.transform.scale.set(dist, dist, dist);
Context.gizmoScaleZ.transform.scale.set(dist, dist, dist);
gizmo.transform.buildMatrix();
// Scene control
@@ -106,16 +112,26 @@ class Gizmo {
#end
}
if (Context.axisX || Context.axisY || Context.axisZ) {
if (Context.axisX) {
Context.object.transform.loc.x = Context.axisLoc;
if (Context.translateX || Context.translateY || Context.translateZ || Context.scaleX || Context.scaleY || Context.scaleZ) {
if (Context.translateX) {
Context.object.transform.loc.x = Context.gizmoDrag;
}
else if (Context.axisY) {
Context.object.transform.loc.y = Context.axisLoc;
else if (Context.translateY) {
Context.object.transform.loc.y = Context.gizmoDrag;
}
else if (Context.axisZ) {
Context.object.transform.loc.z = Context.axisLoc;
else if (Context.translateZ) {
Context.object.transform.loc.z = Context.gizmoDrag;
}
else if (Context.scaleX) {
Context.object.transform.scale.x += Context.gizmoDrag - Context.gizmoDragLast;
}
else if (Context.scaleY) {
Context.object.transform.scale.y += Context.gizmoDrag - Context.gizmoDragLast;
}
else if (Context.scaleZ) {
Context.object.transform.scale.z += Context.gizmoDrag - Context.gizmoDragLast;
}
Context.gizmoDragLast = Context.gizmoDrag;
Context.object.transform.buildMatrix();
#if arm_physics
@@ -126,43 +142,76 @@ class Gizmo {
}
// Decal layer control
else if (isDecal) {
if (Context.axisX || Context.axisY || Context.axisZ) {
if (Context.axisX) {
Context.layer.decalMat._30 = Context.axisLoc;
if (Context.translateX || Context.translateY || Context.translateZ || Context.scaleX || Context.scaleY || Context.scaleZ) {
if (Context.translateX) {
Context.layer.decalMat._30 = Context.gizmoDrag;
}
else if (Context.axisY) {
Context.layer.decalMat._31 = Context.axisLoc;
else if (Context.translateY) {
Context.layer.decalMat._31 = Context.gizmoDrag;
}
else if (Context.axisZ) {
Context.layer.decalMat._32 = Context.axisLoc;
else if (Context.translateZ) {
Context.layer.decalMat._32 = Context.gizmoDrag;
}
else if (Context.scaleX) {
Context.layer.decalMat.decompose(v, q, v0);
v0.x += Context.gizmoDrag - Context.gizmoDragLast;
Context.layer.decalMat.compose(v, q, v0);
}
else if (Context.scaleY) {
Context.layer.decalMat.decompose(v, q, v0);
v0.y += Context.gizmoDrag - Context.gizmoDragLast;
Context.layer.decalMat.compose(v, q, v0);
}
else if (Context.scaleZ) {
Context.layer.decalMat.decompose(v, q, v0);
v0.z += Context.gizmoDrag - Context.gizmoDragLast;
Context.layer.decalMat.compose(v, q, v0);
}
Context.gizmoDragLast = Context.gizmoDrag;
if (Context.material != Context.layer.fill_layer) {
Context.setMaterial(Context.layer.fill_layer);
}
Layers.updateFillLayer(Context.axisStarted);
Layers.updateFillLayer(Context.gizmoStarted);
}
}
// Axis movement
Context.axisStarted = false;
Context.gizmoStarted = false;
if (mouse.started("left") && Context.object.name != "Scene") {
var trs = [Context.gizmoX.transform, Context.gizmoY.transform, Context.gizmoZ.transform];
// Translate
var trs = [Context.gizmoTranslateX.transform, Context.gizmoTranslateY.transform, Context.gizmoTranslateZ.transform];
var hit = RayCaster.closestBoxIntersect(trs, mouse.viewX, mouse.viewY, Scene.active.camera);
if (hit != null) {
if (hit.object == Context.gizmoX) Context.axisX = true;
else if (hit.object == Context.gizmoY) Context.axisY = true;
else if (hit.object == Context.gizmoZ) Context.axisZ = true;
if (Context.axisX || Context.axisY || Context.axisZ) {
Context.axisStart = 0.0;
Context.axisStarted = true;
if (hit.object == Context.gizmoTranslateX) Context.translateX = true;
else if (hit.object == Context.gizmoTranslateY) Context.translateY = true;
else if (hit.object == Context.gizmoTranslateZ) Context.translateZ = true;
if (Context.translateX || Context.translateY || Context.translateZ) {
Context.gizmoOffset = 0.0;
Context.gizmoStarted = true;
}
}
else {
// Scale
var trs = [Context.gizmoScaleX.transform, Context.gizmoScaleY.transform, Context.gizmoScaleZ.transform];
var hit = RayCaster.closestBoxIntersect(trs, mouse.viewX, mouse.viewY, Scene.active.camera);
if (hit != null) {
if (hit.object == Context.gizmoScaleX) Context.scaleX = true;
else if (hit.object == Context.gizmoScaleY) Context.scaleY = true;
else if (hit.object == Context.gizmoScaleZ) Context.scaleZ = true;
if (Context.scaleX || Context.scaleY || Context.scaleZ) {
Context.gizmoOffset = 0.0;
Context.gizmoStarted = true;
}
}
}
}
else if (mouse.released("left")) {
Context.axisX = Context.axisY = Context.axisZ = false;
Context.translateX = Context.translateY = Context.translateZ = false;
Context.scaleX = Context.scaleY = Context.scaleZ = false;
}
if (Context.axisX || Context.axisY || Context.axisZ) {
if (Context.translateX || Context.translateY || Context.translateZ || Context.scaleX || Context.scaleY || Context.scaleZ) {
Context.rdirty = 2;
if (isObject) {
@@ -173,29 +222,31 @@ class Gizmo {
v.set(Context.layer.decalMat._30, Context.layer.decalMat._31, Context.layer.decalMat._32);
}
if (Context.axisX) {
if (Context.translateX || Context.scaleX) {
var hit = RayCaster.planeIntersect(Vec4.yAxis(), v, mouse.viewX, mouse.viewY, Scene.active.camera);
if (hit != null) {
if (Context.axisStart == 0) Context.axisStart = hit.x - v.x;
Context.axisLoc = hit.x - Context.axisStart;
if (Context.gizmoStarted) Context.gizmoOffset = hit.x - v.x;
Context.gizmoDrag = hit.x - Context.gizmoOffset;
}
}
else if (Context.axisY) {
else if (Context.translateY || Context.scaleY) {
var hit = RayCaster.planeIntersect(Vec4.xAxis(), v, mouse.viewX, mouse.viewY, Scene.active.camera);
if (hit != null) {
if (Context.axisStart == 0) Context.axisStart = hit.y - v.y;
Context.axisLoc = hit.y - Context.axisStart;
if (Context.gizmoStarted) Context.gizmoOffset = hit.y - v.y;
Context.gizmoDrag = hit.y - Context.gizmoOffset;
}
}
else if (Context.axisZ) {
else if (Context.translateZ || Context.scaleZ) {
var hit = RayCaster.planeIntersect(Vec4.xAxis(), v, mouse.viewX, mouse.viewY, Scene.active.camera);
if (hit != null) {
if (Context.axisStart == 0) Context.axisStart = hit.z - v.z;
Context.axisLoc = hit.z - Context.axisStart;
if (Context.gizmoStarted) Context.gizmoOffset = hit.z - v.z;
Context.gizmoDrag = hit.z - Context.gizmoOffset;
}
}
if (Context.gizmoStarted) Context.gizmoDragLast = Context.gizmoDrag;
}
Input.occupied = (Context.axisX || Context.axisY || Context.axisZ) && mouse.viewX < App.w();
Input.occupied = (Context.translateX || Context.translateY || Context.translateZ || Context.scaleX || Context.scaleY || Context.scaleZ) && mouse.viewX < App.w();
}
}
+17 -17
View File
@@ -90,31 +90,31 @@ class Inc {
if (Context.showCompass) {
var scene = Scene.active;
var cam = Scene.active.camera;
var gizmo: MeshObject = cast scene.getChild(".GizmoTranslate");
var compass: MeshObject = cast scene.getChild(".Compass");
var visible = gizmo.visible;
var parent = gizmo.parent;
var loc = gizmo.transform.loc;
var rot = gizmo.transform.rot;
var visible = compass.visible;
var parent = compass.parent;
var loc = compass.transform.loc;
var rot = compass.transform.rot;
var crot = cam.transform.rot;
var ratio = iron.App.w() / iron.App.h();
var P = cam.P;
cam.P = Mat4.ortho(-8 * ratio, 8 * ratio, -8, 8, -2, 2);
gizmo.visible = true;
gizmo.parent = cam;
gizmo.transform.loc = new Vec4(7.4 * ratio, 7.0, -1);
gizmo.transform.rot = new Quat(-crot.x, -crot.y, -crot.z, crot.w);
gizmo.transform.scale.set(0.4, 0.4, 0.4);
gizmo.transform.buildMatrix();
compass.visible = true;
compass.parent = cam;
compass.transform.loc = new Vec4(7.4 * ratio, 7.0, -1);
compass.transform.rot = new Quat(-crot.x, -crot.y, -crot.z, crot.w);
compass.transform.scale.set(0.4, 0.4, 0.4);
compass.transform.buildMatrix();
gizmo.render(currentG, "overlay", []);
compass.render(currentG, "overlay", []);
cam.P = P;
gizmo.visible = visible;
gizmo.parent = parent;
gizmo.transform.loc = loc;
gizmo.transform.rot = rot;
gizmo.transform.buildMatrix();
compass.visible = visible;
compass.parent = parent;
compass.transform.loc = loc;
compass.transform.rot = rot;
compass.transform.buildMatrix();
}
}
+2
View File
@@ -42,6 +42,8 @@ class LineDraw {
public static function render(g4: kha.graphics4.Graphics) {
return; ////
var isPaint = UIHeader.inst.worktab.position == SpacePaint;
var isDecal = isPaint && Context.layer.fill_layer != null && Context.layer.uvType == UVProject;
if (!isDecal) return;
+9 -9
View File
@@ -137,16 +137,16 @@ class UISidebar {
function done() {
if (ui.SCALE() > 1) setIconScale();
//
Context.gizmo = Scene.active.getChild(".GizmoTranslate");
Context.gizmo.transform.scale.set(0.5, 0.5, 0.5);
Context.gizmo.transform.buildMatrix();
Context.gizmoX = Scene.active.getChild("GizmoX");
Context.gizmoY = Scene.active.getChild("GizmoY");
Context.gizmoZ = Scene.active.getChild("GizmoZ");
//
Context.object = Scene.active.getChild("Cube");
Context.gizmo = Scene.active.getChild(".Gizmo");
Context.gizmoTranslateX = Context.gizmo.getChild(".TranslateX");
Context.gizmoTranslateY = Context.gizmo.getChild(".TranslateY");
Context.gizmoTranslateZ = Context.gizmo.getChild(".TranslateZ");
Context.gizmoScaleX = Context.gizmo.getChild(".ScaleX");
Context.gizmoScaleY = Context.gizmo.getChild(".ScaleY");
Context.gizmoScaleZ = Context.gizmo.getChild(".ScaleZ");
Context.object = Scene.active.getChild(".Cube");
Context.paintObject = cast(Context.object, MeshObject);
Project.paintObjects = [Context.paintObject];