resolve centering model vs group so rotation works
This commit is contained in:
parent
45d59d0bbc
commit
9bb758f323
3 changed files with 24 additions and 5 deletions
|
|
@ -103,7 +103,10 @@ broker.subscribe('space_init', data => {
|
||||||
|
|
||||||
// add object loader
|
// add object loader
|
||||||
broker.subscribe('space_load', data => {
|
broker.subscribe('space_load', data => {
|
||||||
mesh.api.group.new(data.flat().map(el => new mesh.model(el))).centerXY().floor();
|
mesh.api.group.new(data.flat().map(el => new mesh.model(el)))
|
||||||
|
.centerModels()
|
||||||
|
.centerXY()
|
||||||
|
.floor();
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove version cache bust from url
|
// remove version cache bust from url
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,25 @@ if (mesh.group) return;
|
||||||
mesh.group = class MeshGroup extends mesh.object {
|
mesh.group = class MeshGroup extends mesh.object {
|
||||||
|
|
||||||
// @param group {mesh.model[]}
|
// @param group {mesh.model[]}
|
||||||
constructor(models) {
|
constructor(models = []) {
|
||||||
super();
|
super();
|
||||||
this.group = new THREE.Group();
|
this.group = new THREE.Group();
|
||||||
this.models = [];
|
this.models = [];
|
||||||
for (let model of (models || [])) {
|
for (let model of models) {
|
||||||
this.add(model);
|
this.add(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// center objects to group bounds
|
||||||
|
// dependent on first being added to world/scene
|
||||||
|
centerModels() {
|
||||||
|
let bounds = this.bounds();
|
||||||
|
for (let model of this.models) {
|
||||||
|
model.center(bounds);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
object() {
|
object() {
|
||||||
return this.group;
|
return this.group;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,14 @@ mesh.object = class MeshObject {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
centerXY() {
|
center(bounds) {
|
||||||
let b = this.bounds();
|
let b = bounds || this.bounds();
|
||||||
|
this.move(-b.center.x, b.center.y, -b.center.z);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
centerXY(bounds) {
|
||||||
|
let b = bounds || this.bounds();
|
||||||
this.move(-b.center.x, b.center.y, 0);
|
this.move(-b.center.x, b.center.y, 0);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue