diff --git a/src/Renderer/PointsMaterial.js b/src/Renderer/PointsMaterial.js index 304e6f1d8e..f8ef1851c5 100644 --- a/src/Renderer/PointsMaterial.js +++ b/src/Renderer/PointsMaterial.js @@ -133,7 +133,8 @@ class PointsMaterial extends THREE.RawShaderMaterial { * @param {number} [options.minAttenuatedSize=3] minimum scale used by 'ATTENUATED' size mode * @param {number} [options.maxAttenuatedSize=10] maximum scale used by 'ATTENUATED' size mode * - * @property {Classification} classifScheme - points classification scheme. + * @property {Scheme} classificationScheme - Color scheme for point classification values. + * @property {Scheme} discretScheme - Color scheme for all other discret values. * * @example * // change color category classification @@ -146,7 +147,7 @@ class PointsMaterial extends THREE.RawShaderMaterial { const elevationRange = options.elevationRange || new THREE.Vector2(0, 1000); const angleRange = options.angleRange || new THREE.Vector2(-90, 90); const oiMaterial = options.orientedImageMaterial; - const classifScheme = options.classification || ClassificationScheme.DEFAULT; + const classificationScheme = options.classification || ClassificationScheme.DEFAULT; const discretScheme = options.discretScheme || DiscretScheme.DEFAULT; const applyOpacityClassication = options.applyOpacityClassication == undefined ? false : options.applyOpacityClassication; const size = options.size || 0; @@ -161,7 +162,7 @@ class PointsMaterial extends THREE.RawShaderMaterial { delete options.elevationRange; delete options.angleRange; delete options.orientedImageMaterial; - delete options.classifScheme; + delete options.classificationScheme; delete options.discretScheme; delete options.applyOpacityClassication; delete options.size; @@ -205,22 +206,22 @@ class PointsMaterial extends THREE.RawShaderMaterial { texture.magFilter = THREE.NearestFilter; CommonMaterial.setUniformProperty(this, 'classificationTexture', texture); - // coloringLUT + // add texture to applying the discret lut. const dataLUT = new Uint8Array(256 * 4); const textureLUT = new THREE.DataTexture(dataLUT, 256, 1, THREE.RGBAFormat); textureLUT.needsUpdate = true; textureLUT.magFilter = THREE.NearestFilter; CommonMaterial.setUniformProperty(this, 'discretTexture', textureLUT); - // Classification scheme - this.classifScheme = classifScheme; + // Classification and other discret values scheme + this.classificationScheme = classificationScheme; this.discretScheme = discretScheme; - // Update classification aand discrete Texture + // Update classification and discrete Texture this.recomputeClassification(); this.recomputeDiscreteTexture(); - // Gradient + // Gradient texture for continuous values const gradientTexture = generateGradientTexture(Gradients[_gradient]); CommonMaterial.setUniformProperty(this, 'gradientTexture', gradientTexture); @@ -251,28 +252,30 @@ class PointsMaterial extends THREE.RawShaderMaterial { } } - recomputeClassification() { - const classification = this.classifScheme; - const data = this.classificationTexture.image.data; - const width = this.classificationTexture.image.width; + _recomputeTexture(textureName, nbClass) { + if (!['classification', 'discret'].includes(textureName)) { return; } + const scheme = this[`${textureName}Scheme`]; + if (!nbClass) { nbClass = Object.keys(scheme).length; } + const data = this[`${textureName}Texture`].image.data; + const width = this[`${textureName}Texture`].image.width; for (let i = 0; i < width; i++) { let color; let opacity; let visible = true; - if (classification[i]) { - color = classification[i].color; - visible = classification[i].visible; - opacity = classification[i].opacity; - } else if (classification[i % 32]) { - color = classification[i % 32].color; - visible = classification[i % 32].visible; - opacity = classification[i % 32].opacity; - } else if (classification.DEFAULT) { - color = classification.DEFAULT.color; - visible = classification.DEFAULT.visible; - opacity = classification.DEFAULT.opacity; + if (scheme[i]) { + color = scheme[i].color; + visible = scheme[i].visible; + opacity = scheme[i].opacity; + } else if (scheme[i % nbClass]) { + color = scheme[i % nbClass].color; + visible = scheme[i % nbClass].visible; + opacity = scheme[i % nbClass].opacity; + } else if (scheme.DEFAULT) { + color = scheme.DEFAULT.color; + visible = scheme.DEFAULT.visible; + opacity = scheme.DEFAULT.opacity; } else { color = white; opacity = 1.0; @@ -285,54 +288,19 @@ class PointsMaterial extends THREE.RawShaderMaterial { data[j + 3] = visible ? parseInt(255 * opacity, 10) : 0; } - this.classificationTexture.needsUpdate = true; + this[`${textureName}Texture`].needsUpdate = true; this.dispatchEvent({ type: 'material_property_changed', target: this.uniforms, }); } - recomputeDiscreteTexture() { - const data = this.discretTexture.image.data; - const width = this.discretTexture.image.width; - - const discretScheme = this.discretScheme; - const nbClass = Object.keys(discretScheme).length; - - for (let i = 0; i < width; i++) { - let color; - let opacity; - let visible = true; - - if (discretScheme[i]) { - color = discretScheme[i].color; - visible = discretScheme[i].visible; - opacity = discretScheme[i].opacity; - } else if (discretScheme[i % nbClass]) { - color = discretScheme[i % nbClass].color; - visible = discretScheme[i % nbClass].visible; - opacity = discretScheme[i % nbClass].opacity; - } else if (discretScheme.DEFAULT) { - color = discretScheme.DEFAULT.color; - visible = discretScheme.DEFAULT.visible; - opacity = discretScheme.DEFAULT.opacity; - } else { - color = white; - opacity = 1.0; - } - - const j = 4 * i; - data[j + 0] = parseInt(255 * color.r, 10); - data[j + 1] = parseInt(255 * color.g, 10); - data[j + 2] = parseInt(255 * color.b, 10); - data[j + 3] = visible ? parseInt(255 * opacity, 10) : 0; - } + recomputeClassification() { + this._recomputeTexture('classification', 32); + } - this.discretTexture.needsUpdate = true; - this.dispatchEvent({ - type: 'material_property_changed', - target: this.uniforms, - }); + recomputeDiscreteTexture() { + this._recomputeTexture('discret'); } onBeforeCompile(shader, renderer) {