From d7f4b5de27f989ac1af594fb381ba76d3f6bef23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Philip=20H=C3=A4nsch?= Date: Mon, 23 Sep 2024 21:08:24 +0200 Subject: [PATCH 1/2] raytracer: add support for per-point pointsize --- src/objects/Points.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/objects/Points.js b/src/objects/Points.js index 0356847bf60d13..fcd268fba977d0 100644 --- a/src/objects/Points.js +++ b/src/objects/Points.js @@ -43,7 +43,7 @@ class Points extends Object3D { const geometry = this.geometry; const matrixWorld = this.matrixWorld; - const threshold = raycaster.params.Points.threshold; + var threshold = raycaster.params.Points.threshold; const drawRange = geometry.drawRange; // Checking boundingSphere distance to ray @@ -61,12 +61,16 @@ class Points extends Object3D { _inverseMatrix.copy( matrixWorld ).invert(); _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix ); - const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); - const localThresholdSq = localThreshold * localThreshold; - const index = geometry.index; const attributes = geometry.attributes; const positionAttribute = attributes.position; + const pointsizeAttribute = attributes.pointsize; + if (pointsizeAttribute) { + threshold = 1; + } + + const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); + const localThresholdSq = localThreshold * localThreshold; if ( index !== null ) { @@ -83,6 +87,21 @@ class Points extends Object3D { } + } else if (pointsizeAttribute) { + + const start = Math.max( 0, drawRange.start ); + const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) ); + + for ( let i = start, l = end; i < l; i ++ ) { + + _position.fromBufferAttribute( positionAttribute, i ); + + let pointsize = pointsizeAttribute.getX( i ); + + testPoint( _position, i, localThresholdSq * pointsize * pointsize, matrixWorld, raycaster, intersects, this ); + + } + } else { const start = Math.max( 0, drawRange.start ); From a09bb3dda012b1f2726c8755198ebf7165d425d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Philip=20H=C3=A4nsch?= Date: Mon, 23 Sep 2024 21:17:17 +0200 Subject: [PATCH 2/2] Fix Linter --- src/objects/Points.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/objects/Points.js b/src/objects/Points.js index fcd268fba977d0..68d33369b720f6 100644 --- a/src/objects/Points.js +++ b/src/objects/Points.js @@ -65,8 +65,11 @@ class Points extends Object3D { const attributes = geometry.attributes; const positionAttribute = attributes.position; const pointsizeAttribute = attributes.pointsize; - if (pointsizeAttribute) { + + if ( pointsizeAttribute ) { + threshold = 1; + } const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); @@ -87,7 +90,7 @@ class Points extends Object3D { } - } else if (pointsizeAttribute) { + } else if ( pointsizeAttribute ) { const start = Math.max( 0, drawRange.start ); const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) ); @@ -96,7 +99,7 @@ class Points extends Object3D { _position.fromBufferAttribute( positionAttribute, i ); - let pointsize = pointsizeAttribute.getX( i ); + const pointsize = pointsizeAttribute.getX( i ); testPoint( _position, i, localThresholdSq * pointsize * pointsize, matrixWorld, raycaster, intersects, this );