From 7b556a676c8983f4090953ac3d9e0679aff6ebca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Wed, 15 Oct 2025 20:49:12 +0200 Subject: [PATCH] Lame helper plane for clipping TODO: the visible plane should have its center at the axes origin --- js/scene.js | 11 ++++++++++- js/state.js | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/js/scene.js b/js/scene.js index 14fba64..f482f06 100644 --- a/js/scene.js +++ b/js/scene.js @@ -194,6 +194,8 @@ Scene.UI.toggleClipper = function(triggerSelector) { } else { AppState.clipping.enabled = false; ATON.disableClipPlanes(); + AppState.root.remove(AppState.clipping.helper); + AppState.clipping.helper = null; // Refactor!! document.querySelector(triggerSelector).classList.remove('border-info'); document.querySelector(triggerSelector).classList.remove('border-2'); @@ -218,13 +220,20 @@ Scene.init = function() { // Open settings side panel when clicking on settings btn Scene.toggleSettingsPanel('settings'); Scene.toggleContentMenu('menu'); + window.addEventListener('mousedown', event => { // Activate clipping when clicking on the scene if (AppState.clipping.enabled && event.buttons === 1) { const point = ATON.getSceneQueriedPoint(); if (point) { // Normal of the clipping plane along the Y axis facing down - ATON.addClipPlane(new THREE.Vector3(0, -1, 0), point); + const plane = ATON.addClipPlane(new THREE.Vector3(0, -1, 0), point); + // Add a visible plane helper for the clipping plane + const helper = new THREE.PlaneHelper(plane, 24, 0xffff00); + // Remove any already visbile helper plane + if (AppState.clipping.helper !== null) AppState.root.remove(AppState.clipping.helper); + AppState.root.add(helper); + AppState.clipping.helper = helper; console.log("I'm clipping, baby!"); } } diff --git a/js/state.js b/js/state.js index 3306901..549f16f 100644 --- a/js/state.js +++ b/js/state.js @@ -12,7 +12,7 @@ export const AppState = { map : null, clipping : { enabled: false, - plane : null, + helper : null, } }