diff --git a/src/kiri/conf.js b/src/kiri/conf.js index f0b4d03d..df301620 100644 --- a/src/kiri/conf.js +++ b/src/kiri/conf.js @@ -504,8 +504,8 @@ }, // --------------- settings template template: { - // CAM only bounds: {}, + // CAM only origin: {}, stock: {}, tools:[ diff --git a/src/kiri/init.js b/src/kiri/init.js index b6f1c702..5b301fd3 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -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; diff --git a/src/kiri/main.js b/src/kiri/main.js index 40af062a..d520af39 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -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) {