From 7b53e095244e96be448cbf5944f4920082798b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Mon, 13 Oct 2025 15:42:06 +0200 Subject: [PATCH] Better clipping plane activation logic... --- js/scene.js | 23 +++++++++++++++++------ js/state.js | 6 ++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/js/scene.js b/js/scene.js index 0ee88af..e5a1255 100644 --- a/js/scene.js +++ b/js/scene.js @@ -32,7 +32,8 @@ Scene.showEdges = function(object) { } /** - * + * @todo WIP! + * Activate clipping plane */ Scene.activateClipper = function() { const geometry = new THREE.PlaneGeometry( 24, 24 ); @@ -42,9 +43,11 @@ Scene.activateClipper = function() { transparent: true, }); const plane = new THREE.Mesh( geometry, material ); - const root = ATON.getRootScene(); + const root = AppState.root; console.log(root, plane); root.add(plane); + AppState.clipping.enabled = true; + AppState.clipping.plane = plane; } /** @@ -155,10 +158,17 @@ Scene.toggleSettingsPanel = function(id) { }); } -Scene.UI.showClipper = function(triggerSelector) { +Scene.UI.toggleClipper = function(triggerSelector) { document.querySelector(triggerSelector).addEventListener( 'click', - () => Scene.activateClipper() + () => { + if (!AppState.clipping.enabled) { + Scene.activateClipper() + } else { + AppState.root.remove(AppState.clipping.plane); + AppState.clipping.enabled = false; + } + } ); } @@ -223,9 +233,10 @@ Scene.openScene = function(marker) { ATON.setAutoLP(true); Scene.toggleAmbientOcclusion(true); - Scene.UI.showClipper('#clipper'); + Scene.UI.toggleClipper('#clipper'); + + AppState.root = ATON.getRootScene(); } - //const rootUI = ATON.getRootUI(); } export default Scene; \ No newline at end of file diff --git a/js/state.js b/js/state.js index 1d6f1f2..3306901 100644 --- a/js/state.js +++ b/js/state.js @@ -1,4 +1,6 @@ export const AppState = { + // The root scene object + root: null, scenes : [ { id : "salvador", @@ -8,6 +10,10 @@ export const AppState = { ambientOcclusion : true, shadows : true, map : null, + clipping : { + enabled: false, + plane : null, + } } /**