From d6e88e7461cf5aea48b700fd7b22af287e6b8cc5 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 17 Jun 2025 15:40:47 -0400 Subject: [PATCH] remove old object bounds, persist new bounds state --- src2/main/mesh.js | 2 ++ src2/mesh/api.js | 6 ++---- src2/mesh/handles.js | 25 +++++++++++++++++-------- src2/mesh/object.js | 32 -------------------------------- 4 files changed, 21 insertions(+), 44 deletions(-) diff --git a/src2/main/mesh.js b/src2/main/mesh.js index 81ee431b..0c2387cb 100644 --- a/src2/main/mesh.js +++ b/src2/main/mesh.js @@ -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); } diff --git a/src2/mesh/api.js b/src2/mesh/api.js index 592c2688..5faee3d4 100644 --- a/src2/mesh/api.js +++ b/src2/mesh/api.js @@ -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)) { diff --git a/src2/mesh/handles.js b/src2/mesh/handles.js index fefcd446..e32fd954 100644 --- a/src2/mesh/handles.js +++ b/src2/mesh/handles.js @@ -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) { diff --git a/src2/mesh/object.js b/src2/mesh/object.js index 475f9dab..349d6220 100644 --- a/src2/mesh/object.js +++ b/src2/mesh/object.js @@ -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