fix recentering
This commit is contained in:
parent
cd978a85c3
commit
77e4d39431
6 changed files with 27 additions and 46 deletions
|
|
@ -11,6 +11,7 @@ import { api } from '../mesh/api.js';
|
|||
import { space } from '../moto/space.js';
|
||||
import { broker } from '../moto/broker.js';
|
||||
import { $, $d, h, estop } from '../moto/webui.js';
|
||||
import { handles } from '../mesh/handles.js';
|
||||
import { client as motoClient } from '../moto/client.js';
|
||||
import { split as meshSplit } from '../mesh/split.js';
|
||||
import { model as meshModel, materials } from '../mesh/model.js';
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ const pattern = {
|
|||
let models = selection.models();
|
||||
let [ cx, cy ] = center;
|
||||
for (let model of models) {
|
||||
let pos = model.world_bounds.mid;
|
||||
let pos = model.bounds.mid;
|
||||
let stepr = (Math.PI * 2) / count;
|
||||
let modnu = [ model ];
|
||||
for (let i=1; i<count; i++) {
|
||||
|
|
@ -506,7 +506,7 @@ let sketch = {
|
|||
for (let rec of recs) {
|
||||
let { item } = rec;
|
||||
let poly = newPolygon().fromObject(item);
|
||||
poly.move({ x: -center.x, y: -center.y, z:0 });
|
||||
poly.move({ x: -center.x, y: -center.y, z: 0 });
|
||||
Object.assign(rec.item, poly.toObject());
|
||||
}
|
||||
sketch.render();
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class MeshGroup extends meshObject {
|
|||
get bounds() {
|
||||
let box3 = new Box3();
|
||||
for (let model of this.models) {
|
||||
box3.union(model.world_bounds);
|
||||
box3.union(model.bounds);
|
||||
}
|
||||
return box3;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,12 +114,16 @@ class MeshModel extends meshObject {
|
|||
return this.mesh;
|
||||
}
|
||||
|
||||
get bounds() {
|
||||
get geo_bounds() {
|
||||
return this.geometry.boundingBox.clone();
|
||||
}
|
||||
|
||||
get world_bounds() {
|
||||
return this.bounds.translate(this.position());
|
||||
get bounds() {
|
||||
// console.log('bounds',
|
||||
// this.geometry.boundingBox.clone(),
|
||||
// this.position().clone()
|
||||
// );
|
||||
return this.geometry.boundingBox.clone().translate(this.position());
|
||||
}
|
||||
|
||||
get positions() {
|
||||
|
|
@ -220,13 +224,15 @@ class MeshModel extends meshObject {
|
|||
// moves mesh object center to target
|
||||
centerTo(to) {
|
||||
this.log('model-centerto', to);
|
||||
let { mid } = this.bounds;
|
||||
let abs = this.world_bounds.mid;
|
||||
this.translate(
|
||||
-mid.x + (abs.x - to.x),
|
||||
-mid.y + (abs.y - to.y),
|
||||
-mid.z + (abs.z - to.z),
|
||||
);
|
||||
let geo = this.geo_bounds;
|
||||
let { mid } = this.bounds.translate({
|
||||
x: -to.x,
|
||||
y: -to.y,
|
||||
z: -to.z
|
||||
});
|
||||
// this.translate(-geo.mid.x, -geo.mid.y, -geo.mid.z);
|
||||
// this.translate(mid.x, mid.y, mid.z);
|
||||
this.translate(-geo.mid.x+mid.x, -geo.mid.y+mid.y, -geo.mid.z+mid.z);
|
||||
this.position(to.x, to.y, to.z);
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class MeshObject {
|
|||
}
|
||||
|
||||
log() {
|
||||
// api.log.emit(this.id, this.type, ...arguments);
|
||||
api.log.emit(this.id, this.type, ...arguments);
|
||||
}
|
||||
|
||||
get type() {
|
||||
|
|
@ -104,20 +104,15 @@ class MeshObject {
|
|||
}
|
||||
|
||||
floor() {
|
||||
let b = this.bounds;
|
||||
return this.move(0, 0, -b.min.z);
|
||||
return this.move(0, 0, -this.bounds.min.z);
|
||||
}
|
||||
|
||||
center() {
|
||||
throw "center() requires implementation";
|
||||
let b = this.bounds;
|
||||
return this.move(-b.mid.x, -b.mid.y, -b.mid.z);
|
||||
}
|
||||
|
||||
centerXY() {
|
||||
throw "centerXY() requires implementation";
|
||||
let b = this.bounds;
|
||||
return this.move(-b.mid.x, -b.mid.y, 0);
|
||||
}
|
||||
|
||||
move() {
|
||||
|
|
|
|||
|
|
@ -64,8 +64,7 @@ const util = {
|
|||
}
|
||||
},
|
||||
|
||||
// @param object {THREE.Object3D | THREE.Object3D[] | MeshObject | MeshObject[]}
|
||||
// @returns bounds modified for moto.space
|
||||
// @param object {MeshObject | MeshObject[]}
|
||||
bounds(object) {
|
||||
// console.log({ bounds: object });
|
||||
let box = new Box3();
|
||||
|
|
@ -76,29 +75,9 @@ const util = {
|
|||
} else if (object) {
|
||||
box.union(object.bounds);
|
||||
}
|
||||
let bnd = {
|
||||
min: {
|
||||
x: box.min.x,
|
||||
y: box.min.y,
|
||||
z: box.min.z
|
||||
},
|
||||
max: {
|
||||
x: box.max.x,
|
||||
y: box.max.y,
|
||||
z: box.max.z
|
||||
}
|
||||
};
|
||||
bnd.size = bnd.dim = {
|
||||
x: bnd.max.x - bnd.min.x,
|
||||
y: bnd.max.y - bnd.min.y,
|
||||
z: bnd.max.z - bnd.min.z
|
||||
};
|
||||
bnd.center = bnd.mid = {
|
||||
x: (bnd.max.x + bnd.min.x) / 2,
|
||||
y: -(bnd.max.y + bnd.min.y) / 2,
|
||||
z: (bnd.max.z + bnd.min.z) / 2
|
||||
};
|
||||
return bnd;
|
||||
box.size = box.dim;
|
||||
box.center = box.mid;
|
||||
return box;
|
||||
},
|
||||
|
||||
// extract object fields into an array with optional rounding
|
||||
|
|
|
|||
Loading…
Reference in a new issue