From 63be2964639dc8fc18273f8517faab622e402e7e Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Mon, 30 Mar 2020 14:10:36 -0400 Subject: [PATCH] add rotate to face with meta/ctrl on selected object --- js/kiri-init.js | 10 ++++++++-- js/kiri-widget.js | 19 ++++++++++++++----- js/moto-space.js | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/js/kiri-init.js b/js/kiri-init.js index a4d7c07b..0e6398cd 100644 --- a/js/kiri-init.js +++ b/js/kiri-init.js @@ -367,7 +367,7 @@ var gs_kiri_init = exports; return; } let coord = prompt("Enter X,Y,Z degrees of rotation").split(','), - prod = Math.PI / 360, + prod = Math.PI / 180, x = parseFloat(coord[0] || 0.0) * prod, y = parseFloat(coord[1] || 0.0) * prod, z = parseFloat(coord[2] || 0.0) * prod; @@ -1549,7 +1549,13 @@ var gs_kiri_init = exports; SPACE.platform.setGrid(25, 5); SPACE.platform.opacity(0.2); - SPACE.mouse.downSelect(function() { + SPACE.mouse.downSelect(function(int,event) { + // lay flat with meta or ctrl clicking a selected face + if (int && (event.ctrlKey || event.metaKey)) { + let q = new THREE.Quaternion(); + q.setFromUnitVectors(int.face.normal, new THREE.Vector3(0,0,-1)); + API.selection.rotate(q); + } if (API.view.get() !== VIEWS.ARRANGE) return null; return API.selection.meshes(); }); diff --git a/js/kiri-widget.js b/js/kiri-widget.js index 20a89ddd..8f15ceec 100644 --- a/js/kiri-widget.js +++ b/js/kiri-widget.js @@ -450,12 +450,21 @@ var gs_kiri_widget = exports; this.bounds = null; this.setWireframe(false); this.clearSlices(); - this.mesh.geometry.applyMatrix4(new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(x || 0, y || 0, z || 0))); + let m4 = new THREE.Matrix4(); + let euler = typeof(x) === 'number'; + if (euler) { + m4 = m4.makeRotationFromEuler(new THREE.Euler(x || 0, y || 0, z || 0)); + } else { + m4 = m4.makeRotationFromQuaternion(x); + } + this.mesh.geometry.applyMatrix4(m4); this.center(); - let rot = this.orient.rot; - rot.x += (x || 0); - rot.y += (y || 0); - rot.z += (z || 0); + if (euler) { + let rot = this.orient.rot; + rot.x += (x || 0); + rot.y += (y || 0); + rot.z += (z || 0); + } }; PRO.mirror = function() { diff --git a/js/moto-space.js b/js/moto-space.js index b0a4f87b..ac23f908 100644 --- a/js/moto-space.js +++ b/js/moto-space.js @@ -440,6 +440,8 @@ var MOTO = window.moto = window.moto || {}; mouseDragPoint = trackInt.point.clone(); mouseDragStart = mouseDragPoint; viewControl.enabled = false; + } + if (selectInt) { mouseDownSelect(selectInt, event); } }