rethink scale and rotation for selections
This commit is contained in:
parent
7b7acca47d
commit
4d026fce98
4 changed files with 170 additions and 96 deletions
114
js/kiri-init.js
114
js/kiri-init.js
|
|
@ -29,8 +29,7 @@ var gs_kiri_init = exports;
|
|||
STARTMODE = SETUP.sm && SETUP.sm.length === 1 ? SETUP.sm[0] : null,
|
||||
SPACE = KIRI.space,
|
||||
STATS = API.stats,
|
||||
ROT = Math.PI/2,
|
||||
ROT5 = ROT / 9,
|
||||
DEG = Math.PI/180,
|
||||
ALL = [MODES.FDM, MODES.LASER, MODES.CAM],
|
||||
CAM = [MODES.CAM],
|
||||
FDM = [MODES.FDM],
|
||||
|
|
@ -1110,13 +1109,15 @@ var gs_kiri_init = exports;
|
|||
progress: $('progress').style,
|
||||
prostatus: $('prostatus'),
|
||||
selection: $('selection'),
|
||||
selWidth: $('sel_width'),
|
||||
selHeight: $('sel_height'),
|
||||
selDepth: $('sel_depth'),
|
||||
sizeX: $('size_x'),
|
||||
sizeY: $('size_y'),
|
||||
sizeZ: $('size_z'),
|
||||
scaleX: $('scale_x'),
|
||||
scaleY: $('scale_y'),
|
||||
scaleZ: $('scale_z'),
|
||||
scaleUniform: $('scale_uni'),
|
||||
lockX: $('lock_x'),
|
||||
lockY: $('lock_y'),
|
||||
lockZ: $('lock_z'),
|
||||
stock: $('stock'),
|
||||
stockWidth: $('stock-width'),
|
||||
stockDepth: $('stock-width'),
|
||||
|
|
@ -1454,22 +1455,67 @@ var gs_kiri_init = exports;
|
|||
'drop', dropHandler
|
||||
]);
|
||||
|
||||
function selectionSize(e) {
|
||||
let dv = parseFloat(e.target.value || 1),
|
||||
pv = parseFloat(e.target.was || 1),
|
||||
ra = dv / pv,
|
||||
xv = parseFloat(UI.sizeX.was),
|
||||
yv = parseFloat(UI.sizeY.was),
|
||||
zv = parseFloat(UI.sizeZ.was),
|
||||
xr = (UI.lockX.checked ? ra : 1),
|
||||
yr = (UI.lockY.checked ? ra : 1),
|
||||
zr = (UI.lockZ.checked ? ra : 1);
|
||||
API.selection.scale(xr,yr,zr);
|
||||
UI.sizeX.was = UI.sizeX.value = xv * xr;
|
||||
UI.sizeY.was = UI.sizeY.value = yv * yr;
|
||||
UI.sizeZ.was = UI.sizeZ.value = zv * zr;
|
||||
}
|
||||
|
||||
function selectionScale(e) {
|
||||
let dv = parseFloat(e.target.value || 1),
|
||||
pv = parseFloat(e.target.was || 1),
|
||||
ra = dv / pv,
|
||||
xv = parseFloat(UI.scaleX.was),
|
||||
yv = parseFloat(UI.scaleY.was),
|
||||
zv = parseFloat(UI.scaleZ.was),
|
||||
xr = (UI.lockX.checked ? ra : 1),
|
||||
yr = (UI.lockY.checked ? ra : 1),
|
||||
zr = (UI.lockZ.checked ? ra : 1);
|
||||
API.selection.scale(xr,yr,zr);
|
||||
UI.scaleX.was = UI.scaleX.value = xv * xr;
|
||||
UI.scaleY.was = UI.scaleY.value = yv * yr;
|
||||
UI.scaleZ.was = UI.scaleZ.value = zv * zr;
|
||||
}
|
||||
|
||||
function selectionRotate(e) {
|
||||
let deg = parseFloat(e.target.value) * DEG;
|
||||
e.target.value = 0;
|
||||
switch (e.target.id.split('').pop()) {
|
||||
case 'x': return API.selection.rotate(deg,0,0);
|
||||
case 'y': return API.selection.rotate(0,deg,0);
|
||||
case 'z': return API.selection.rotate(0,0,deg);
|
||||
}
|
||||
}
|
||||
|
||||
SPACE.onEnterKey([
|
||||
UI.layerSpan, function() { API.show.slices() },
|
||||
UI.layerID, function() { API.show.layer(UI.layerID.value) },
|
||||
|
||||
UI.scaleX, selection.scale,
|
||||
UI.scaleY, selection.scale,
|
||||
UI.scaleZ, selection.scale,
|
||||
|
||||
UI.toolName, updateTool,
|
||||
UI.toolNum, updateTool,
|
||||
UI.toolFluteDiam, updateTool,
|
||||
UI.toolFluteLen, updateTool,
|
||||
UI.toolShaftDiam, updateTool,
|
||||
UI.toolShaftLen, updateTool,
|
||||
// UI.toolTaperAngle, updateTool,
|
||||
UI.toolTaperTip, updateTool,
|
||||
UI.layerSpan, function() { API.show.slices() },
|
||||
UI.layerID, function() { API.show.layer(UI.layerID.value) },
|
||||
UI.scaleX, selectionScale,
|
||||
UI.scaleY, selectionScale,
|
||||
UI.scaleZ, selectionScale,
|
||||
UI.sizeX, selectionSize,
|
||||
UI.sizeY, selectionSize,
|
||||
UI.sizeZ, selectionSize,
|
||||
UI.toolName, updateTool,
|
||||
UI.toolNum, updateTool,
|
||||
UI.toolFluteDiam, updateTool,
|
||||
UI.toolFluteLen, updateTool,
|
||||
UI.toolShaftDiam, updateTool,
|
||||
UI.toolShaftLen, updateTool,
|
||||
UI.toolTaperTip, updateTool,
|
||||
$('rot_x'), selectionRotate,
|
||||
$('rot_y'), selectionRotate,
|
||||
$('rot_z'), selectionRotate
|
||||
]);
|
||||
|
||||
UI.layerID.convert = UC.toFloat.bind(UI.layerID);
|
||||
|
|
@ -1485,12 +1531,26 @@ var gs_kiri_init = exports;
|
|||
UI.layers.style.left = ev.target.getBoundingClientRect().left + 'px';
|
||||
};
|
||||
|
||||
$('x-').onclick = function(ev) { API.selection.rotate(ev.shiftKey ? -ROT5 : -ROT,0,0) };
|
||||
$('x+').onclick = function(ev) { API.selection.rotate(ev.shiftKey ? ROT5 : ROT,0,0) };
|
||||
$('y-').onclick = function(ev) { API.selection.rotate(0,ev.shiftKey ? -ROT5 : -ROT,0) };
|
||||
$('y+').onclick = function(ev) { API.selection.rotate(0,ev.shiftKey ? ROT5 : ROT,0) };
|
||||
$('z-').onclick = function(ev) { API.selection.rotate(0,0,ev.shiftKey ? ROT5 : ROT) };
|
||||
$('z+').onclick = function(ev) { API.selection.rotate(0,0,ev.shiftKey ? -ROT5 : -ROT) };
|
||||
// $('rot_x').onkeypress = (ev) => {
|
||||
// if (ev.key === 'Enter') {
|
||||
// API.selection.rotate(parseFloat(ev.target.value)*DEG,0,0);
|
||||
// ev.target.value = 0;
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// $('rot_y').onkeypress = (ev) => {
|
||||
// if (ev.key === 'Enter') {
|
||||
// API.selection.rotate(0,parseFloat(ev.target.value)*DEG,0);
|
||||
// ev.target.value = 0;
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// $('rot_z').onkeypress = (ev) => {
|
||||
// if (ev.key === 'Enter') {
|
||||
// API.selection.rotate(0,0,parseFloat(ev.target.value)*DEG);
|
||||
// ev.target.value = 0;
|
||||
// }
|
||||
// };
|
||||
|
||||
UI.modelOpacity.onchange = UI.modelOpacity.onclick = function(ev) {
|
||||
API.widgets.opacity(parseInt(UI.modelOpacity.value)/100);
|
||||
|
|
|
|||
58
js/kiri.js
58
js/kiri.js
|
|
@ -86,6 +86,7 @@ self.kiri.copyright = exports.COPYRIGHT;
|
|||
rotate: rotateSelection,
|
||||
meshes: function() { return selectedMeshes.slice() },
|
||||
widgets: function() { return selectedMeshes.slice().map(m => m.widget) },
|
||||
for_groups: forSelectedGroups,
|
||||
for_meshes: forSelectedMeshes,
|
||||
for_widgets: forSelectedWidgets
|
||||
};
|
||||
|
|
@ -824,18 +825,19 @@ self.kiri.copyright = exports.COPYRIGHT;
|
|||
******************************************************************* */
|
||||
|
||||
function updateSelectedInfo() {
|
||||
let bounds = new THREE.Box3();
|
||||
let bounds = new THREE.Box3(), track;
|
||||
forSelectedMeshes(mesh => {
|
||||
bounds = bounds.union(mesh.getBoundingBox());
|
||||
track = mesh.widget.track;
|
||||
});
|
||||
if (bounds.min.x === Infinity) {
|
||||
if (selectedMeshes.length === 0) {
|
||||
UI.selWidth.innerHTML = '0';
|
||||
UI.selDepth.innerHTML = '0';
|
||||
UI.selHeight.innerHTML = '0';
|
||||
UI.scaleX.value = '';
|
||||
UI.scaleY.value = '';
|
||||
UI.scaleZ.value = '';
|
||||
UI.sizeX.value = 0;
|
||||
UI.sizeY.value = 0;
|
||||
UI.sizeZ.value = 0;
|
||||
UI.scaleX.value = 1;
|
||||
UI.scaleY.value = 1;
|
||||
UI.scaleZ.value = 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -843,12 +845,12 @@ self.kiri.copyright = exports.COPYRIGHT;
|
|||
dy = bounds.max.y - bounds.min.y,
|
||||
dz = bounds.max.z - bounds.min.z,
|
||||
scale = unitScale();
|
||||
UI.selWidth.innerHTML = UTIL.round(dx/scale,2);
|
||||
UI.selDepth.innerHTML = UTIL.round(dy/scale,2);
|
||||
UI.selHeight.innerHTML = UTIL.round(dz/scale,2);
|
||||
UI.scaleX.value = 1;
|
||||
UI.scaleY.value = 1;
|
||||
UI.scaleZ.value = 1;
|
||||
UI.sizeX.value = UI.sizeX.was = UTIL.round(dx/scale,2);
|
||||
UI.sizeY.value = UI.sizeY.was = UTIL.round(dy/scale,2);
|
||||
UI.sizeZ.value = UI.sizeZ.was = UTIL.round(dz/scale,2);
|
||||
UI.scaleX.value = UI.scaleX.was = track.scale.x;
|
||||
UI.scaleY.value = UI.scaleY.was = track.scale.y;
|
||||
UI.scaleZ.value = UI.scaleZ.was = track.scale.z;
|
||||
}
|
||||
|
||||
function setOpacity(value) {
|
||||
|
|
@ -864,42 +866,20 @@ self.kiri.copyright = exports.COPYRIGHT;
|
|||
}
|
||||
|
||||
function scaleSelection() {
|
||||
if (arguments.length === 1) {
|
||||
scaleSelectionUI(...arguments);
|
||||
} else {
|
||||
let args = arguments;
|
||||
forSelectedGroups(function (w) {
|
||||
w.scale(...args);
|
||||
});
|
||||
}
|
||||
let args = arguments;
|
||||
forSelectedGroups(function (w) {
|
||||
w.scale(...args);
|
||||
});
|
||||
// skip update if last argument is strictly 'false'
|
||||
if ([...arguments].pop() === false) {
|
||||
return;
|
||||
}
|
||||
updateSelectedInfo();
|
||||
UI.scaleX.value = 1;
|
||||
UI.scaleY.value = 1;
|
||||
UI.scaleZ.value = 1;
|
||||
platform.compute_max_z();
|
||||
platform.update_stock(true);
|
||||
SPACE.update();
|
||||
}
|
||||
|
||||
function scaleSelectionUI(ev) {
|
||||
let dv = parseFloat(ev.target.value || 1);
|
||||
if (UI.scaleUniform.checked) {
|
||||
UI.scaleX.value = dv;
|
||||
UI.scaleY.value = dv;
|
||||
UI.scaleZ.value = dv;
|
||||
}
|
||||
let x = parseFloat(UI.scaleX.value || dv),
|
||||
y = parseFloat(UI.scaleY.value || dv),
|
||||
z = parseFloat(UI.scaleZ.value || dv);
|
||||
forSelectedGroups(function (w) {
|
||||
w.scale(x,y,z);
|
||||
});
|
||||
}
|
||||
|
||||
function rotateSelection(x, y, z) {
|
||||
forSelectedGroups(function (w) {
|
||||
w.rotate(x, y, z);
|
||||
|
|
|
|||
Loading…
Reference in a new issue