From c70c6b1f539972900d07e7971e854014d151c87f Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Mon, 22 Sep 2025 19:27:24 +0100 Subject: [PATCH 01/15] Call toggleGizmo("select") when focusing camera on specific mesh TODO: Get bounding box to show on specific mesh (properly get that to work) --- ui/gizmos.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/gizmos.js b/ui/gizmos.js index d53560f3..cc4313f2 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -454,6 +454,9 @@ function focusCameraOnMesh() { // Update camera position and target camera.setPosition(cameraPosition); camera.setTarget(player.position); + + // "Select" the focused mesh + toggleGizmo("select"); } else { // For other types of cameras const currentDistance = camera.radius || 10; @@ -468,6 +471,9 @@ function focusCameraOnMesh() { camera.position = newCameraPosition; camera.setTarget(newTarget); + + // "Select" the focused mesh + toggleGizmo("select"); } } From d9dec260e7c0ce65be9e9253965eae1c303f7cbf Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Tue, 23 Sep 2025 10:26:48 +0100 Subject: [PATCH 02/15] Create showBoundingBox function and call that when focusing mesh instead of calling entire toggleGizmo method --- ui/gizmos.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index cc4313f2..2b9d32d7 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -316,6 +316,14 @@ function resetBoundingBoxVisibilityIfManuallyChanged(mesh) { if (mesh && mesh.visibility === 0.001) mesh.visibility = 0; } +function showBoundingBox(mesh) { + if (mesh.parent) { + mesh = getRootMesh(mesh.parent); + mesh.visibility = 0.001; + } + mesh.showBoundingBox = true; +} + function hideBoundingBox(mesh) { mesh.showBoundingBox = false; } @@ -456,7 +464,7 @@ function focusCameraOnMesh() { camera.setTarget(player.position); // "Select" the focused mesh - toggleGizmo("select"); + showBoundingBox(mesh); } else { // For other types of cameras const currentDistance = camera.radius || 10; @@ -473,7 +481,7 @@ function focusCameraOnMesh() { camera.setTarget(newTarget); // "Select" the focused mesh - toggleGizmo("select"); + showBoundingBox(mesh); } } @@ -672,7 +680,7 @@ export function toggleGizmo(gizmoType) { gizmoManager.attachToMesh(pickedMesh); // Show bounding box for the selected mesh - pickedMesh.showBoundingBox = true; + showBoundingBox(pickedMesh) } else { if (pickedMesh && pickedMesh.name === "ground") { const position = event.pickInfo.pickedPoint; From 629cb2fbc158d7eacb7e996e2c6550941b5fb86a Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Sun, 28 Sep 2025 22:18:13 +0100 Subject: [PATCH 03/15] Add missing semicolon to showBoundingBox call Fixes error where bounding box was not showing --- ui/gizmos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index 8cb416c5..57ac0c1b 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -757,7 +757,7 @@ export function toggleGizmo(gizmoType) { gizmoManager.attachToMesh(pickedMesh); // Show bounding box for the selected mesh - showBoundingBox(pickedMesh) + showBoundingBox(pickedMesh); } else { if (pickedMesh && pickedMesh.name === "ground") { const position = event.pickInfo.pickedPoint; From 033ba277edc0aa451dcef85aab06ed90fb601870 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Sun, 28 Sep 2025 22:52:50 +0100 Subject: [PATCH 04/15] Use Boolean flag in showBoundingBox to show bounding box when focusing mesh TODO: Figure out how to turn off bounding box when shown through showBoundingBox method --- ui/gizmos.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index 57ac0c1b..bfb8d504 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -374,10 +374,14 @@ function resetBoundingBoxVisibilityIfManuallyChanged(mesh) { if (mesh && mesh.visibility === 0.001) mesh.visibility = 0; } -function showBoundingBox(mesh) { +function showBoundingBox(mesh, focusMode = false) { if (mesh.parent) { mesh = getRootMesh(mesh.parent); mesh.visibility = 0.001; + } else if (focusMode) { + // Set mesh visibility even if mesh has no parent + // focusMode is only used when camera focused on mesh + mesh.visibility = 0.001; } mesh.showBoundingBox = true; } @@ -533,7 +537,7 @@ function focusCameraOnMesh() { camera.setTarget(player.position); // "Select" the focused mesh - showBoundingBox(mesh); + showBoundingBox(mesh, true); } else { // For other types of cameras const currentDistance = camera.radius || 10; @@ -550,7 +554,7 @@ function focusCameraOnMesh() { camera.setTarget(newTarget); // "Select" the focused mesh - showBoundingBox(mesh); + showBoundingBox(mesh, true); } } From 250cc88f506e9bb7f00b1359c4d85bda7eac9ced Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Sun, 28 Sep 2025 23:24:50 +0100 Subject: [PATCH 05/15] Set gizmoManager.selectGizmoEnabled to true when "selecting" mesh and showing its bounding box in focusCameraOnMesh --- ui/gizmos.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/gizmos.js b/ui/gizmos.js index bfb8d504..b8784d95 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -537,6 +537,7 @@ function focusCameraOnMesh() { camera.setTarget(player.position); // "Select" the focused mesh + gizmoManager.selectGizmoEnabled = true; showBoundingBox(mesh, true); } else { // For other types of cameras @@ -554,6 +555,7 @@ function focusCameraOnMesh() { camera.setTarget(newTarget); // "Select" the focused mesh + gizmoManager.selectGizmoEnabled = true; showBoundingBox(mesh, true); } } From cf303a3b96b60a30037cca1be8ff4fd648a60a66 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Mon, 29 Sep 2025 08:29:41 +0100 Subject: [PATCH 06/15] Ensure focused mesh attached to gizmo manager to also ensure bounding box gets hidden when no longer needed --- ui/gizmos.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/gizmos.js b/ui/gizmos.js index b8784d95..36dd44e3 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -538,6 +538,7 @@ function focusCameraOnMesh() { // "Select" the focused mesh gizmoManager.selectGizmoEnabled = true; + gizmoManager.attachToMesh(mesh); // Unfortunately needed to ensure bounding box gets hidden showBoundingBox(mesh, true); } else { // For other types of cameras @@ -556,6 +557,7 @@ function focusCameraOnMesh() { // "Select" the focused mesh gizmoManager.selectGizmoEnabled = true; + gizmoManager.attachToMesh(mesh); // Unfortunately needed to ensure bounding box gets hidden showBoundingBox(mesh, true); } } From 96a717bd76c053c0039b9428e4dcf7e5a8891239 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Mon, 29 Sep 2025 08:33:33 +0100 Subject: [PATCH 07/15] Refactor to reduce code duplication when selecting focused mesh --- ui/gizmos.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index 36dd44e3..cb85b0cf 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -500,6 +500,13 @@ function focusCameraOnMesh() { const newTarget = boundingInfo.boundingBox.centerWorld; // Center of the new mesh const camera = flock.scene.activeCamera; + let selectFocusedMesh = () => { + // "Select" the focused mesh + gizmoManager.selectGizmoEnabled = true; + gizmoManager.attachToMesh(mesh); // Unfortunately needed to ensure bounding box gets hidden + showBoundingBox(mesh, true); + } + if (camera.metadata && camera.metadata.following) { const player = camera.metadata.following; // The player (mesh) the camera is following const playerDistance = 5; // Fixed distance between player and target @@ -536,10 +543,7 @@ function focusCameraOnMesh() { camera.setPosition(cameraPosition); camera.setTarget(player.position); - // "Select" the focused mesh - gizmoManager.selectGizmoEnabled = true; - gizmoManager.attachToMesh(mesh); // Unfortunately needed to ensure bounding box gets hidden - showBoundingBox(mesh, true); + selectFocusedMesh(); } else { // For other types of cameras const currentDistance = camera.radius || 10; @@ -555,10 +559,7 @@ function focusCameraOnMesh() { camera.position = newCameraPosition; camera.setTarget(newTarget); - // "Select" the focused mesh - gizmoManager.selectGizmoEnabled = true; - gizmoManager.attachToMesh(mesh); // Unfortunately needed to ensure bounding box gets hidden - showBoundingBox(mesh, true); + selectFocusedMesh(); } } From 1383aa360fa5bf6d57d95ee84c7417ae79a006e8 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Mon, 29 Sep 2025 08:40:41 +0100 Subject: [PATCH 08/15] Add code comment for clarification when setting visibility of non-composite meshes in cases where camera focused on them --- ui/gizmos.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/gizmos.js b/ui/gizmos.js index cb85b0cf..7168fc72 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -381,6 +381,12 @@ function showBoundingBox(mesh, focusMode = false) { } else if (focusMode) { // Set mesh visibility even if mesh has no parent // focusMode is only used when camera focused on mesh + + /* With this, non-composite meshes can still have their + visibility set to 0.001. However, this will not be a big + issue here as, even in past testing, non-composite meshes + still were not showing, so this may even be preferred. */ + mesh.visibility = 0.001; } mesh.showBoundingBox = true; From 3f8653928dfef83a47357e776bac28b6794a2440 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Mon, 29 Sep 2025 08:47:26 +0100 Subject: [PATCH 09/15] Ensure selectGizmoEnabled set to false when gizmos disabled and/or turned off --- ui/gizmos.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/gizmos.js b/ui/gizmos.js index 7168fc72..f2c438c4 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -572,6 +572,7 @@ function focusCameraOnMesh() { export function disableGizmos() { if (!gizmoManager) return; // Disable all gizmos + gizmoManager.selectGizmoEnabled = false; gizmoManager.positionGizmoEnabled = false; gizmoManager.rotationGizmoEnabled = false; gizmoManager.scaleGizmoEnabled = false; @@ -1432,6 +1433,7 @@ function turnOffAllGizmos() { resetBoundingBoxVisibilityIfManuallyChanged(gizmoManager.attachedMesh); resetAttachedMeshIfMeshAttached(); gizmoManager.attachToMesh(null); + gizmoManager.selectGizmoEnabled = false; gizmoManager.positionGizmoEnabled = false; gizmoManager.rotationGizmoEnabled = false; gizmoManager.scaleGizmoEnabled = false; From 496ad0be6abe1fe2a49c815160d358da84b56069 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Mon, 29 Sep 2025 08:58:38 +0100 Subject: [PATCH 10/15] Refactor to reduce code duplication by just calling disableGizmos method in turnOffAllGizmos instead of manually resetting gizmos again with repeated code --- ui/gizmos.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index f2c438c4..896768d0 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -1433,11 +1433,7 @@ function turnOffAllGizmos() { resetBoundingBoxVisibilityIfManuallyChanged(gizmoManager.attachedMesh); resetAttachedMeshIfMeshAttached(); gizmoManager.attachToMesh(null); - gizmoManager.selectGizmoEnabled = false; - gizmoManager.positionGizmoEnabled = false; - gizmoManager.rotationGizmoEnabled = false; - gizmoManager.scaleGizmoEnabled = false; - gizmoManager.boundingBoxGizmoEnabled = false; + disableGizmos(); } // Track DO sections and their associated blocks for cleanup From 7ad88043cc0c9393914feaffe2b44d78248a2f82 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Fri, 10 Oct 2025 10:24:20 +0100 Subject: [PATCH 11/15] Ensure primitive mesh visibility isn't set to 0.001 Fixes bug where primitive mesh visibility doesn't show upon mesh selected when focusing --- ui/gizmos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index 0ac74b78..de6d35a9 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -383,7 +383,7 @@ function showBoundingBox(mesh, focusMode = false) { if (mesh.parent) { mesh = getRootMesh(mesh.parent); mesh.visibility = 0.001; - } else if (focusMode) { + } else if (focusMode && !mesh.visibility) { // Set mesh visibility even if mesh has no parent // focusMode is only used when camera focused on mesh From 7d6d19dda3cbf6c27515f1ba11297cc737b197a0 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Mon, 13 Oct 2025 07:53:56 +0100 Subject: [PATCH 12/15] Refactor to move selectFocusedMesh call that happens at end of both if and else block to just after if-statement --- ui/gizmos.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index de6d35a9..a1f90d3e 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -553,8 +553,6 @@ function focusCameraOnMesh() { // Update camera position and target camera.setPosition(cameraPosition); camera.setTarget(player.position); - - selectFocusedMesh(); } else { // For other types of cameras const currentDistance = camera.radius || 10; @@ -569,9 +567,8 @@ function focusCameraOnMesh() { camera.position = newCameraPosition; camera.setTarget(newTarget); - - selectFocusedMesh(); } + selectFocusedMesh(); } export function disableGizmos() { From 6644f03a1ff6ae07ac4e087694afd1ffd38a98f1 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Thu, 23 Oct 2025 12:35:07 +0100 Subject: [PATCH 13/15] Set window.currentMesh to selected mesh in cases where gizmoManager has no attachedMesh but window has currentMesh --- ui/gizmos.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/gizmos.js b/ui/gizmos.js index a1f90d3e..3e2c7355 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -503,6 +503,7 @@ function focusCameraOnMesh() { (key) => meshMap[key] === window.currentBlock, ); mesh = getMeshFromBlockKey(blockKey); + window.currentMesh = mesh; } if (!mesh) return; From 0199f5f54929b71b9571afcfcf3fd43399737d14 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Thu, 23 Oct 2025 12:35:47 +0100 Subject: [PATCH 14/15] Set window.currentMesh to selected mesh in most (if not all) cases --- ui/gizmos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/gizmos.js b/ui/gizmos.js index 3e2c7355..82c70b8b 100644 --- a/ui/gizmos.js +++ b/ui/gizmos.js @@ -503,7 +503,6 @@ function focusCameraOnMesh() { (key) => meshMap[key] === window.currentBlock, ); mesh = getMeshFromBlockKey(blockKey); - window.currentMesh = mesh; } if (!mesh) return; @@ -514,6 +513,7 @@ function focusCameraOnMesh() { let selectFocusedMesh = () => { // "Select" the focused mesh + window.currentMesh = mesh; gizmoManager.selectGizmoEnabled = true; gizmoManager.attachToMesh(mesh); // Unfortunately needed to ensure bounding box gets hidden showBoundingBox(mesh, true); From 62ac411961a3caeb5bb1edea9025c91dbac17651 Mon Sep 17 00:00:00 2001 From: Zishan Rahman Date: Thu, 23 Oct 2025 13:08:37 +0100 Subject: [PATCH 15/15] Re-enable mesh focus gizmo button --- index.html | 5 ++--- ui/gizmos.js | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 6ac194ce..c7c29aef 100644 --- a/index.html +++ b/index.html @@ -1091,13 +1091,12 @@