allow widgets off platform to be dragged back on while still preventing new moves off platform

This commit is contained in:
Stewart Allen 2020-11-20 10:32:58 -05:00
commit 82421c11cc
3 changed files with 33 additions and 8 deletions

View file

@ -504,8 +504,8 @@
},
// --------------- settings template
template: {
// CAM only
bounds: {},
// CAM only
origin: {},
stock: {},
tools:[

View file

@ -1896,18 +1896,26 @@
if (delta && UI.freeLayout.checked) {
let set = settings();
let dev = set.device;
let bound = set.bounds;
let bound = set.bounds_sel;
let width = dev.bedWidth/2;
let depth = dev.bedDepth/2;
if (bound.min.x + delta.x <= -width) return;
if (bound.min.y + delta.y <= -depth) return;
if (bound.max.x + delta.x >= width) return;
if (bound.max.y + delta.y >= depth) return;
let isout = (
bound.min.x <= -width ||
bound.min.y <= -depth ||
bound.max.x >= width ||
bound.max.y >= depth
);
if (!isout) {
if (bound.min.x + delta.x <= -width) return;
if (bound.min.y + delta.y <= -depth) return;
if (bound.max.x + delta.x >= width) return;
if (bound.max.y + delta.y >= depth) return;
}
API.selection.for_widgets(function(widget) {
widget.move(delta.x, delta.y, 0);
API.event.emit('widget.move', {widget, delta});
});
// platform.update_stock();
API.selection.update_bounds();
API.event.emit('selection.drag', delta);
} else {
return API.selection.meshes().length > 0;

View file

@ -82,7 +82,8 @@
widgets: function() { return selectedMeshes.slice().map(m => m.widget) },
for_groups: forSelectedGroups,
for_meshes: forSelectedMeshes,
for_widgets: forSelectedWidgets
for_widgets: forSelectedWidgets,
update_bounds: updateSelectedBounds
};
const platform = {
@ -925,6 +926,22 @@
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;
updateSelectedBounds();
}
function updateSelectedBounds() {
// update bounds on selection for drag limiting
let bounds_sel = new THREE.Box3();
forSelectedWidgets(function(widget) {
let wp = widget.track.pos;
let wb = widget.mesh.getBoundingBox().clone();
wb.min.x += wp.x;
wb.max.x += wp.x;
wb.min.y += wp.y;
wb.max.y += wp.y;
bounds_sel.union(wb);
});
settings.bounds_sel = bounds_sel;
}
function setOpacity(value) {