Ver Fonte

SceneEditor: Round final scale after transformation when CTRL is held

trethaller há 7 anos atrás
pai
commit
bff9635f99
2 ficheiros alterados com 15 adições e 8 exclusões
  1. 10 3
      hide/comp/SceneEditor.hx
  2. 5 5
      hide/view/l3d/Gizmo.hx

+ 10 - 3
hide/comp/SceneEditor.hx

@@ -539,10 +539,17 @@ class SceneEditor {
 					obj3d.rotationY = quantize(M.radToDeg(rot.y), rotQuant);
 					obj3d.rotationZ = quantize(M.radToDeg(rot.z), rotQuant);
 					if(scale != null) {
+						inline function scaleSnap(x: Float) {
+							if(K.isDown(K.CTRL)) {
+								var step = K.isDown(K.SHIFT) ? 0.5 : 1.0;
+								x = Math.round(x / step) * step;
+							}
+							return x;
+						}
 						var s = newMat.getScale();
-						obj3d.scaleX = quantize(s.x, scaleQuant);
-						obj3d.scaleY = quantize(s.y, scaleQuant);
-						obj3d.scaleZ = quantize(s.z, scaleQuant);
+						obj3d.scaleX = quantize(scaleSnap(s.x), scaleQuant);
+						obj3d.scaleY = quantize(scaleSnap(s.y), scaleQuant);
+						obj3d.scaleZ = quantize(scaleSnap(s.z), scaleQuant);
 					}
 					obj3d.applyPos(sceneObjs[i]);
 				}

+ 5 - 5
hide/view/l3d/Gizmo.hx

@@ -148,17 +148,17 @@ class Gizmo extends h3d.scene.Object {
 				return x > 0 ? (x + 1) : 1 / (1 - x);
 			}
 
-			function snap(m: Float) {
-				if(moveStep <= 0 || !K.isDown(K.CTRL))
+			function moveSnap(m: Float) {
+				if(moveStep <= 0 || !K.isDown(K.CTRL) || axisScale)
 					return m;
 
 				var step = K.isDown(K.SHIFT) ? moveStep / 2.0 : moveStep;
 				return hxd.Math.round(m / step) * step;
 			}
 
-			if(mode == MoveX || mode == MoveXY || mode == MoveZX) vec.x = snap(delta.dot(startMat.front().toPoint()));
-			if(mode == MoveY || mode == MoveYZ || mode == MoveXY) vec.y = snap(delta.dot(startMat.right().toPoint()));
-			if(mode == MoveZ || mode == MoveZX || mode == MoveYZ) vec.z = snap(delta.dot(startMat.up().toPoint()));
+			if(mode == MoveX || mode == MoveXY || mode == MoveZX) vec.x = moveSnap(delta.dot(startMat.front().toPoint()));
+			if(mode == MoveY || mode == MoveYZ || mode == MoveXY) vec.y = moveSnap(delta.dot(startMat.right().toPoint()));
+			if(mode == MoveZ || mode == MoveZX || mode == MoveYZ) vec.z = moveSnap(delta.dot(startMat.up().toPoint()));
 
 			if(!axisScale) {
 				vec.transform3x3(startMat);