fix centering, poly scaling
This commit is contained in:
parent
18b6b8567a
commit
e608091603
4 changed files with 23 additions and 6 deletions
|
|
@ -81,6 +81,13 @@ class Point {
|
|||
return this;
|
||||
}
|
||||
|
||||
scale(x = 1,y = 1,z = 1) {
|
||||
this.x *= x;
|
||||
this.y *= y;
|
||||
this.z *= z;
|
||||
return this;
|
||||
}
|
||||
|
||||
round(precision) {
|
||||
return newPoint(
|
||||
this.x.round(precision),
|
||||
|
|
|
|||
|
|
@ -615,6 +615,7 @@ class Polygon {
|
|||
* @returns {Polygon|Point} a new polygon centered on x=0, y=0, z=0
|
||||
*/
|
||||
center(point) {
|
||||
throw "does not work";
|
||||
let ap = newPoint(0, 0, 0, null),
|
||||
np = newPolygon(),
|
||||
pa = this.points;
|
||||
|
|
|
|||
|
|
@ -494,11 +494,13 @@ let sketch = {
|
|||
sketch.selection.bounded_op((sketch, bounds, recs) => {
|
||||
let center = bounds.center(0);
|
||||
for (let rec of recs) {
|
||||
rec.poly.move({ x: -center.x, y: -center.y, z:0 });
|
||||
Object.assign(rec.item, rec.poly.toObject());
|
||||
let { item } = rec;
|
||||
let poly = newPolygon().fromObject(item);
|
||||
poly.move({ x: -center.x, y: -center.y, z:0 });
|
||||
Object.assign(rec.item, poly.toObject());
|
||||
}
|
||||
selection.centerXY();
|
||||
sketch.render();
|
||||
selection.centerXY();
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
gapp.register("mesh.build", [], (root, exports) => {
|
||||
|
||||
const { broker } = gapp;
|
||||
const { mesh, moto } = root;
|
||||
const { base, mesh, moto } = root;
|
||||
const { api, util } = mesh;
|
||||
const { space } = moto;
|
||||
const { bind, div, label, input, hr } = h;
|
||||
|
|
@ -873,10 +873,17 @@ function ui_build() {
|
|||
// polygon scaling, circle radius
|
||||
let el2 = bound[`item_val_${axis.toUpperCase()}_size`];
|
||||
if (!el2) continue;
|
||||
sel_item.type !== 'polygon' && el2.classList.add('editable');
|
||||
el2.classList.add('editable');
|
||||
el2.onclick = field_edit(`${axis} size`, (nval, oval) => {
|
||||
if (sel_item.type === 'polygon') {
|
||||
// todo
|
||||
let scale = {x:1,y:1,z:1};
|
||||
let poly = base.newPolygon().fromObject(sel_item);
|
||||
let bounds = poly.bounds;
|
||||
scale[axis] = nval/oval;
|
||||
poly.move(bounds.center().scale(-1,-1,-1));
|
||||
poly.scale(scale);
|
||||
poly.move(bounds.center());
|
||||
Object.assign(sel_item, poly.toObject());
|
||||
} else if (sel_item.type === 'circle') {
|
||||
sel_item.radius = nval / 2;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue