add sketch and sketch item centering

This commit is contained in:
Stewart Allen 2024-07-26 00:35:36 -04:00
commit c7fed8da3b
3 changed files with 26 additions and 4 deletions

View file

@ -223,7 +223,7 @@ function space_init(data) {
case 'KeyC':
return selection.centerXY().focus();
case 'KeyF':
return selection.floor().focus();
return shiftKey ? selection.focus() : selection.floor().focus();
case 'KeyM':
return shiftKey ? api.tool.merge() : api.tool.mirror();
case 'KeyU':

View file

@ -256,7 +256,7 @@ const selection = {
},
centerXY() {
for (let s of selection.groups()) {
for (let s of [...selection.groups(), ...selection.sketches()]) {
s.centerXY(...arguments);
}
return selection;

View file

@ -168,6 +168,15 @@ mesh.sketch = class MeshSketch extends mesh.object {
broker.publish('sketch_selections');
}
return sel.length;
},
centerXY() {
let sel = sketch.items.filter(i => i.selected);
for (let s of sel) {
s.center.x = 0;
s.center.y = 0;
}
return sel.length;
}
}
}
@ -311,7 +320,15 @@ mesh.sketch = class MeshSketch extends mesh.object {
this.center = {x, y, z};
this.update();
}
}
}
centerXY() {
if (!this.selection.centerXY()) {
this.center.x = 0;
this.center.y = 0;
}
this.render();
}
drag(opt = {}) {
let { items } = this;
@ -369,7 +386,6 @@ mesh.sketch = class MeshSketch extends mesh.object {
}
extrude(opt = {}) {
console.log({ opt });
let { selection, height, chamfer, chamfer_top, chamfer_bottom } = opt;
let models = [];
let items = this.group.children
@ -421,6 +437,12 @@ class SketchItem {
return this.poly.extrude(z, opt);
}
centerXY() {
let { center } = this.item;
center.x = 0;
center.y = 0;
}
update() {
let bump = 0.0025;
let { item, sketch, order } = this;