From b87863b925c7c72669f9b52ff548a0d8636b1223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P=2E?= Date: Fri, 24 Oct 2025 08:02:15 +0200 Subject: [PATCH] Default clipping planes --- config.js | 7 +++++++ index.html | 9 +++++---- js/scene.js | 30 ++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/config.js b/config.js index 6989630..b39571c 100644 --- a/config.js +++ b/config.js @@ -15,6 +15,13 @@ export const config = { scene : { initialExposure: 0.6, autoLP: false, + clipping: { + defaultPoint: [ + -20.3, + 7.3, + -18.3 + ], + } }, menu : { audioBtn1 diff --git a/index.html b/index.html index 01210c3..5f23868 100644 --- a/index.html +++ b/index.html @@ -84,11 +84,12 @@ translate-middle bg-light px-4 pt-2 pb-2 bg-opacity-50 rounded-bottom-3 - mt-4 text-center" + mt-4 text-dark text-center" id="clipper-bar"> - - - + Sezionamento + + + diff --git a/js/scene.js b/js/scene.js index f9e7d07..a3ff3a9 100644 --- a/js/scene.js +++ b/js/scene.js @@ -36,7 +36,7 @@ Scene.UI.toggleClipper = function(triggerSelector, targetSelector) { console.log('Clipping target:', event.target); if (event.target.id === 'clipX') { // Clip along X... - Scene.addClippingPlane('x', 1); + Scene.addClippingPlane('x', -1); } else if (event.target.id === 'clipY') { // Clip along Y... @@ -47,7 +47,6 @@ Scene.UI.toggleClipper = function(triggerSelector, targetSelector) { Scene.addClippingPlane('z', 1); } }); - //Scene.activateClipper() } else { AppState.clipping.enabled = false; ATON.disableClipPlanes(); @@ -87,15 +86,23 @@ Scene.showEdges = function(object) { */ Scene.addClippingPlane = function(axis, orientation = -1) { axis = axis.toLowerCase(); - // TODO: move to dedicated function!! + const defaultPoint = new THREE.Vector3( + ...config.scene.clipping.defaultPoint + ); + const vector = [ + axis === 'x' ? orientation : 0, + axis === 'y' ? orientation : 0, + axis === 'z' ? orientation : 0, + ]; + + // First, add a default clipping plane + // at a predefined point (bad?) + Scene.activateClipper(vector, defaultPoint); + console.log(vector, defaultPoint); + window.addEventListener('mousedown', event => { // Activate clipping when left-clicking on the scene if (AppState.clipping.enabled && event.buttons === 1) { - const vector = [ - axis === 'x' ? orientation : 0, - axis === 'y' ? orientation : 0, - axis === 'z' ? orientation : 0, - ] Scene.activateClipper(vector); } }); @@ -106,9 +113,12 @@ Scene.addClippingPlane = function(axis, orientation = -1) { * Activate clipping plane * @param {Number[]} vector - The vector array to direct the plane */ -Scene.activateClipper = function(vector) { - const point = ATON.getSceneQueriedPoint(); +Scene.activateClipper = function(vector, point = null) { + point ??= ATON.getSceneQueriedPoint(); + if (point) { + console.log('Queried point:', point); + // First remove any existing clipping planes ATON.disableClipPlanes(); // Normal of the clipping plane along the Y axis facing down