remove old object bounds, persist new bounds state

This commit is contained in:
Stewart Allen 2025-06-17 15:40:47 -04:00
commit d6e88e7461
4 changed files with 21 additions and 44 deletions

View file

@ -178,6 +178,8 @@ async function restore_space() {
}).finally(() => {
// hide loading curtain
$d('curtain','none');
// restore handles visibility
handles.setVisible(api.prefs.map.space.bounds);
if (api.prefs.map.info.welcome !== false) {
api.welcome(version);
}

View file

@ -5,6 +5,7 @@ import { history } from './history.js';
import { client as motoClient } from '../moto/client.js';
import { space as motoSpace } from '../moto/space.js';
import { base } from '../geo/base.js';
import { handles } from './handles.js';
import { util as meshUtil } from './util.js';
import { edges as meshEdges } from './edges.js';
import { group as meshGroup } from './group.js';
@ -282,9 +283,7 @@ const selection = {
},
boundsBox() {
for (let m of selection.groups()) {
m.showBounds(...arguments);
}
handles.toggleBounds();
return selection;
},
@ -1532,7 +1531,6 @@ const api = {
// @param object {MeshObject | MeshObject[] | Object}
focus(object) {
console.log({ focus: object });
let { center } = object.center ? object : meshUtil.bounds(object);
// when no valid objects supplied, set origin
if (isNaN(center.x * center.y * center.z)) {

View file

@ -25,10 +25,11 @@ class TransformTool {
this.lines = []; // Add array to track connecting lines
this.mode = '2d'; // or '3d'
this.bounds = null;
this.handleSize = 2; // Fixed size in world units
this.handleSize = 2;
this.handleColor = 0x0088ff;
this.handleOpacity = 0.5;
this.visible = false;
this.visible = true;
// Create materials
this.handleMaterial = new MeshBasicMaterial({
@ -66,14 +67,25 @@ class TransformTool {
});
}
setVisible(visible) {
this.visible = visible;
this.group.visible = this.visible;
if (meshApi && meshApi.prefs) {
meshApi.prefs.map.space.bounds = this.visible;
meshApi.prefs.save();
}
}
show() {
this.visible = true;
this.group.visible = true;
this.setVisible(true);
}
hide() {
this.visible = false;
this.group.visible = false;
this.setVisible(false);
}
toggleBounds() {
this.setVisible(!this.visible);
}
update() {
@ -88,9 +100,6 @@ class TransformTool {
return;
}
// Show transform tool
this.show();
// Get bounds based on selection type
let bounds;
if (sketch) {

View file

@ -152,40 +152,8 @@ class MeshObject {
throw "position() requires implementation";
}
showBounds(bool) {
let was = this._showBounds;
if (bool && bool.toggle) {
bool = !this._showBounds;
}
if (was === bool) {
return;
}
this._showBounds = bool;
this.updateBoundsBox();
}
updateBoundsBox() {
this.log('update-bounds-box', this._showBounds);
let helper = this._boundsBox;
let world = motoSpace.world;
if (helper) {
world.remove(helper);
}
if (this._showBounds) {
let { mid, dim } = this.bounds;
let b3 = new Box3().setFromCenterAndSize(
new Vector3(mid.x, mid.y, mid.z),
new Vector3(dim.x, dim.y, dim.z)
);
let helper = this._boundsBox = new Box3Helper(b3, 0x555555);
world.add(helper);
return true;
}
}
metaChanged(values = {}) {
this.object.updateMatrix();
this.updateBoundsBox();
motoSpace.update();
Object.assign(this.meta, values, {
// matrix: this.object.matrix.elements