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