checkpoint

This commit is contained in:
Stewart Allen 2024-08-09 23:58:36 -04:00
commit b6097be0e2
3 changed files with 29 additions and 19 deletions

View file

@ -308,18 +308,14 @@ const pattern = {
let models = selection.models();
let [ cx, cy ] = center;
for (let model of models) {
await api.tool.regroup([ model ]);
let pos = model.group.position().clone();
let pos = model.world_bounds.mid;
let stepr = (Math.PI * 2) / count;
let modnu = [ model ];
for (let i=1; i<count; i++) {
let clone = await model.duplicate();
let [x, y] = base.util.rotate(pos.x - cx, pos.y - cy, stepr * i);
clone.group.centerModels().position(0,0,0);
clone.group.rotate(0, 0, stepr * i);
clone.group.move(x + cx, y + cy, pos.z);
let clone = model.duplicate().centerTo({ x:cx, y:cy, z:pos.z });
clone.rotate(0, 0, stepr * i);
clone.reCenter();
modnu.push(clone);
// pos.z += zdelta;
}
await api.tool.regroup(modnu);
}
@ -351,14 +347,12 @@ const pattern = {
api.modal.hide();
let models = selection.models();
for (let model of models) {
await api.tool.regroup([ model ]);
let pos = model.group.position().clone();
let modnu = [ model ];
for (let i=0; i<x; i++) {
for (let j=0; j<y; j++) {
if (i === 0 && j === 0) continue;
let clone = await model.duplicate();
clone.group.centerModels().position(i * xs + pos.x, -j * ys + pos.y, pos.z);
let clone = await model.duplicate().reCenter();
clone.move(i * xs, -j * ys, 0);
modnu.push(clone);
}
}

View file

@ -44,7 +44,7 @@ mesh.group = class MeshGroup extends mesh.object {
get bounds() {
let box3 = new Box3();
for (let model of this.models) {
box3.union(model.bounds.translate(model.position()));
box3.union(model.world_bounds);
}
return box3;
}

View file

@ -128,6 +128,10 @@ mesh.model = class MeshModel extends mesh.object {
return this.geometry.boundingBox.clone();
}
get world_bounds() {
return this.bounds.translate(this.position());
}
get matrix() {
return this.mesh.matrixWorld.elements;
}
@ -218,19 +222,31 @@ mesh.model = class MeshModel extends mesh.object {
// moves mesh center to 0,0,0 via translation then
// moves mesh object to former bounds center
reCenter() {
this.log('model-center');
this.log('model-recenter');
let pos = this.position();
let { mid } = this.bounds;
let moveTo = mid.clone().add(pos);
// let moveTo = mid.clone().add(pos);
this.translate(-mid.x, -mid.y, -mid.z);
this.position(moveTo.x, moveTo.y, moveTo.z);
// this.position(moveTo.x, moveTo.y, moveTo.z);
this.position(mid.x + pos.x, mid.y + pos.y, mid.z + pos.z);
return this;
}
// preserves world location while updating mesh for rotation and scaling
// moves mesh center to x,y,z via translation then
// moves mesh object to former bounds center
centerTo(pos) {
// moves mesh center to current target offset via translation then
// moves mesh object center to target
centerTo(to) {
this.log('model-centerto', to);
let pos = this.position();
let { mid } = this.bounds;
let abs = this.world_bounds.mid;//mid.clone().add(pos);
this.translate(
-mid.x + (abs.x - to.x),
-mid.y + (abs.y - to.y),
-mid.z + (abs.z - to.z),
);
this.position(to.x, to.y, to.z);
return this;
}
updateBounds() {