replace group inception defaults with promote to make it easier to preference

This commit is contained in:
Stewart Allen 2022-01-11 22:18:12 -05:00
commit 49f1729946
3 changed files with 7 additions and 15 deletions

View file

@ -78,7 +78,6 @@ function init() {
function restore_space() { function restore_space() {
let count = 0; let count = 0;
let space = moto.Space; let space = moto.Space;
let parray = [];
let mcache = {}; let mcache = {};
mesh.db.admin.get("camera") mesh.db.admin.get("camera")
.then(saved => { .then(saved => {
@ -105,16 +104,7 @@ function restore_space() {
.filter(r => r.md) // filter cache misses .filter(r => r.md) // filter cache misses
.map(r => new mesh.model(r.md, r.id).applyMatrix(mcache[r.id])); .map(r => new mesh.model(r.md, r.id).applyMatrix(mcache[r.id]));
mesh.api.log.emit(`restored ${models.length} model(s)`); mesh.api.log.emit(`restored ${models.length} model(s)`);
let group = mesh.api.group.new(models, id); mesh.api.group.new(models, id).applyMatrix(mcache[id]);
let matrix = mcache[id];
if (matrix) {
group.applyMatrix(matrix);
} else {
group
.centerModels()
.centerXY()
.floor();
}
} }
} }
// restore global cache only after objects are restored // restore global cache only after objects are restored
@ -305,9 +295,7 @@ function load_files(files) {
// add object loader // add object loader
function space_load(data) { function space_load(data) {
mesh.api.group.new(data.flat().map(el => new mesh.model(el))) mesh.api.group.new(data.flat().map(el => new mesh.model(el)))
.centerModels() .promote()
.centerXY()
.floor()
.focus(); .focus();
} }

View file

@ -288,7 +288,7 @@ let tool = {
let group = api.group.new([new mesh.model({ let group = api.group.new([new mesh.model({
file: `merged`, file: `merged`,
mesh: data mesh: data
})]).centerModels(); })]).promote();
api.selection.set([group]); api.selection.set([group]);
api.log.emit('merge complete').unpin(); api.log.emit('merge complete').unpin();
}); });

View file

@ -88,6 +88,10 @@ mesh.group = class MeshGroup extends mesh.object {
return this; return this;
} }
promote() {
return this.centerModels().centerXY().floor();
}
// center objects to group bounds // center objects to group bounds
// dependent on first being added to world/scene // dependent on first being added to world/scene
centerModels() { centerModels() {