From a714a59cbd3dc9b387a638d07578d95576ebb208 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 10 Oct 2021 14:19:57 -0400 Subject: [PATCH] add lay-flat toggle button --- src/kiri/tools.js | 16 +++++++++++++--- web/kiri/index.css | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/kiri/tools.js b/src/kiri/tools.js index 1efc64e9..95d1f6ae 100644 --- a/src/kiri/tools.js +++ b/src/kiri/tools.js @@ -22,6 +22,7 @@ kiri.load(function(API) { function endit() { if (enabled) { API.hide.alert(alert); + $('lay-flat').classList.remove('selected'); API.feature.hover = false; enabled = false; alert = undefined; @@ -31,10 +32,15 @@ kiri.load(function(API) { API.event.on('key.esc', endit); API.event.on('tool.mesh.lay-flat', () => { + if (enabled) { + endit(); + return; + } if (API.feature.hover) { console.log('lay flat cannot pre-empt hover'); return; } + $('lay-flat').classList.add('selected'); API.feature.hover = true; enabled = true; alert = API.show.alert('[ESC] to end lay-flat operation', 600000); @@ -46,9 +52,10 @@ kiri.load(function(API) { lastface = int.face; let obj = lastobj = int.object; let norm = int.face.normal; + let opos = obj.widget.track.pos; obj.add(pmesh); - pmesh.position.x = point.x + norm.x * 0.1; - pmesh.position.y = -point.z + norm.y * 0.1; + pmesh.position.x = point.x - opos.x + norm.x * 0.1; + pmesh.position.y = -point.z - opos.y + norm.y * 0.1; pmesh.position.z = point.y + norm.z * 0.1; let q = new THREE.Quaternion().setFromUnitVectors( new THREE.Vector3(0,0,1), @@ -58,7 +65,10 @@ kiri.load(function(API) { } }); API.event.on('mouse.hover.up', (ev) => { - let { int, point } = ev; + let { int, point, object } = ev; + if (!object) { + return; + } let q = new THREE.Quaternion().setFromUnitVectors(lastface.normal, new THREE.Vector3(0,0,-1)); API.selection.rotate(q); endit(); diff --git a/web/kiri/index.css b/web/kiri/index.css index 08829efb..cbc41e09 100644 --- a/web/kiri/index.css +++ b/web/kiri/index.css @@ -598,6 +598,9 @@ th, tr, td, label { #ft-select button { text-transform: none; } +#lay-flat.selected { + background-color: var(--main-color); +} #lt-top { height: 10px;