Skip to content

Commit

Permalink
feat(points): Allow custom adaptive points parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin ETOURNEAU committed Aug 23, 2023
1 parent ea3b2b3 commit 2a2a328
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ The following people have contributed to iTowns.
* [Diginove](http://diginove.com/index.php/fr/diginove-lexpertise-en-traitement-dimages/):
* [Michel Benet](https://github.com/mbenevole)

* [Sogelink](https://www.sogelink.com/)
* [Kévin ETOURNEAU](https://github.com/ketourneau)
* [Alexis DELFORGES](https://github.com/pourfex)

The following organizations are the current maintainers of iTowns:
* IGN (http://www.ign.fr)
* Ciril Group (https://www.cirilgroup.com/)
14 changes: 13 additions & 1 deletion src/Renderer/PointsMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ class PointsMaterial extends THREE.RawShaderMaterial {
/**
* @class PointsMaterial
* @param {object} [options={}] The options
* @param {number} [options.size=0] size point
* @param {number} [options.size=0] size point (adaptive size mode when size is 0)
* @param {number} [options.mode=PNTS_MODE.COLOR] display mode.
* @param {THREE.Vector4} [options.overlayColor=new THREE.Vector4(0, 0, 0, 0)] overlay color.
* @param {THREE.Vector2} [options.intensityRange=new THREE.Vector2(0, 1)] intensity range.
* @param {boolean} [options.applyOpacityClassication=false] apply opacity classification on all display mode.
* @param {Classification} [options.classification] - define points classification.
* @param {number} [options.minAdaptiveSize=3] min adaptive size point (used only when size is 0)
* @param {number} [options.maxAdaptiveSize=10] max adaptive size point (used only when size is 0)
* @param {number} [options.adaptiveScale=1] adaptive scale factor (used only when size is 0)
* @property {Classification} classification - points classification.
*
* @example
Expand All @@ -74,13 +77,19 @@ class PointsMaterial extends THREE.RawShaderMaterial {
const applyOpacityClassication = options.applyOpacityClassication == undefined ? false : options.applyOpacityClassication;
const size = options.size || 0;
const mode = options.mode || PNTS_MODE.COLOR;
const minAdaptiveSize = options.minAdaptiveSize || 3;
const maxAdaptiveSize = options.maxAdaptiveSize || 10;
const adaptiveScale = options.adaptiveScale || 1;

delete options.orientedImageMaterial;
delete options.intensityRange;
delete options.classification;
delete options.applyOpacityClassication;
delete options.size;
delete options.mode;
delete options.minAdaptiveSize;
delete options.maxAdaptiveSize;
delete options.adaptiveScale;

super(options);

Expand All @@ -97,6 +106,9 @@ class PointsMaterial extends THREE.RawShaderMaterial {
CommonMaterial.setUniformProperty(this, 'overlayColor', options.overlayColor || new THREE.Vector4(0, 0, 0, 0));
CommonMaterial.setUniformProperty(this, 'intensityRange', intensityRange);
CommonMaterial.setUniformProperty(this, 'applyOpacityClassication', applyOpacityClassication);
CommonMaterial.setUniformProperty(this, 'minAdaptiveSize', minAdaptiveSize);
CommonMaterial.setUniformProperty(this, 'maxAdaptiveSize', maxAdaptiveSize);
CommonMaterial.setUniformProperty(this, 'adaptiveScale', adaptiveScale);

// add classification texture to apply classification lut.
const data = new Uint8Array(256 * 4);
Expand Down
5 changes: 4 additions & 1 deletion src/Renderer/Shader/PointsVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ attribute vec4 unique_id;
attribute float intensity;
attribute float classification;
uniform sampler2D classificationLUT;
uniform float minAdaptiveSize;
uniform float maxAdaptiveSize;
uniform float adaptiveScale;

#if defined(NORMAL_OCT16)
attribute vec2 oct16Normal;
Expand Down Expand Up @@ -102,7 +105,7 @@ void main() {
if (size > 0.) {
gl_PointSize = size;
} else {
gl_PointSize = clamp(-size / gl_Position.w, 3.0, 10.0);
gl_PointSize = clamp(-size / gl_Position.w, minAdaptiveSize, maxAdaptiveSize) * adaptiveScale;
}

#if defined(USE_TEXTURES_PROJECTIVE)
Expand Down

0 comments on commit 2a2a328

Please sign in to comment.