add preferences for auto-center and auto-floor

This commit is contained in:
Stewart Allen 2022-01-20 23:29:35 -05:00
commit c04dac8ba9
4 changed files with 37 additions and 7 deletions

View file

@ -490,6 +490,8 @@ let prefs = {
scale_group_Z: true
},
space: {
center: true,
floor: true,
wire: false,
grid: true,
dark: false,

View file

@ -182,13 +182,24 @@ gapp.broker.subscribe("mesh.log", log.emit);
// bind settings endpoint to api
api.settings = function() {
modal.show('settings', h.div([
let { prefs } = api;
let { space } = prefs.map;
modal.show('settings', h.div({ class: "settings" }, [
h.label('dark mode'),
h.input({
type: "checkbox",
h.input({ type: "checkbox",
onchange: ev => call.set_darkmode(ev.target.checked),
[ api.prefs.map.space.dark ? 'checked' : 'unchecked' ] : 1
})
[ space.dark ? 'checked' : 'unchecked' ] : 1
}),
h.label('auto floor'),
h.input({ type: "checkbox",
onchange: ev => prefs.save( space.floor = !space.floor ),
[ space.floor !== false ? 'checked' : 'unchecked' ] : 1
}),
h.label('auto center'),
h.input({ type: "checkbox",
onchange: ev => prefs.save( space.center = !space.center ),
[ space.center !== false ? 'checked' : 'unchecked' ] : 1
}),
]));
}

View file

@ -99,14 +99,17 @@ mesh.group = class MeshGroup extends mesh.object {
promote() {
this.centerModels();
let { dim } = this.bounds;
let { dim, mid } = this.bounds;
let { x, y, z } = dim;
let max = Math.max(x, y, z);
if (max < 2) {
mesh.api.log.emit(`auto-scaling import from ${max.round(5)}`);
this.scale(1000, 1000, 1000);
}
return this.centerXY().floor();
let { center, floor } = mesh.api.prefs.map.space;
if (center !== false) this.centerXY();
if (floor !== false) this.floor();
return this;
}
scale(x = 1, y = 1, z = 1) {
@ -123,6 +126,11 @@ mesh.group = class MeshGroup extends mesh.object {
for (let model of this.models) {
model.center(bounds);
}
let { center } = mesh.api.prefs.map.space;
if (center === false) {
let { mid } = bounds;
this.move(mid.x, mid.y, mid.z);
}
return this;
}