itowns 2.43.2-next.17 → 2.43.2-next.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/itowns.js +1 -1
- package/dist/itowns.js.map +1 -1
- package/lib/Renderer/PointsMaterial.js +121 -91
- package/package.json +1 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
/* babel-plugin-inline-import './Shader/PointsVS.glsl' */
|
|
3
|
-
const PointsVS = "#include <
|
|
3
|
+
const PointsVS = "#include <common>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec4 vColor; // color_pars_vertex\n\n#ifdef USE_POINTS_UV\n varying vec2 vUv;\n uniform mat3 uvTransform;\n#endif\n\n#define NB_CLASS 8.\n\nuniform float size;\nuniform float scale;\n\nuniform bool picking;\nuniform int mode;\n\nuniform vec2 elevationRange;\nuniform vec2 intensityRange;\nuniform vec2 angleRange;\n\nuniform sampler2D classificationTexture;\nuniform sampler2D discreteTexture;\nuniform sampler2D gradientTexture;\nuniform int sizeMode;\nuniform float minAttenuatedSize;\nuniform float maxAttenuatedSize;\n\nattribute vec4 unique_id;\nattribute float intensity;\nattribute float classification;\nattribute float pointSourceID;\n\nattribute float returnNumber;\nattribute float numberOfReturns;\nattribute float scanAngle;\n\nvoid main() {\n vColor = vec4(1.0);\n if (picking) {\n vColor = unique_id;\n } else {\n if (mode == PNTS_MODE_CLASSIFICATION) {\n vec2 uv = vec2(classification/255., 0.5);\n vColor = texture2D(classificationTexture, uv);\n } else if (mode == PNTS_MODE_NORMAL) {\n vColor.rgb = abs(normal);\n } else if (mode == PNTS_MODE_COLOR) {\n#if defined(USE_COLOR)\n vColor.rgb = color.rgb;\n#elif defined(USE_COLOR_ALPHA)\n vColor = color;\n#endif\n } else if (mode == PNTS_MODE_RETURN_NUMBER) {\n vec2 uv = vec2(returnNumber/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_RETURN_TYPE) {\n float returnType;\n if (returnNumber > numberOfReturns) {\n returnType = 4.;\n } else if (returnNumber == 1.) {\n if (numberOfReturns == 1.) {\n // single\n returnType = 0.;\n } else {\n // first\n returnType = 1.;\n }\n } else {\n if (returnNumber == numberOfReturns) {\n // last\n returnType = 3.;\n } else {\n // intermediate\n returnType = 2.;\n }\n }\n vec2 uv = vec2(returnType/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_RETURN_COUNT) {\n vec2 uv = vec2(numberOfReturns/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_POINT_SOURCE_ID) {\n vec2 uv = vec2(mod(pointSourceID, NB_CLASS)/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_SCAN_ANGLE) {\n float i = (scanAngle - angleRange.x) / (angleRange.y - angleRange.x);\n vec2 uv = vec2(i, (1. - i));\n vColor = texture2D(gradientTexture, uv);\n } else if (mode == PNTS_MODE_INTENSITY) {\n float i = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x);\n vec2 uv = vec2(i, (1. - i));\n vColor = texture2D(gradientTexture, uv);\n } else if (mode == PNTS_MODE_ELEVATION) {\n float z = (modelMatrix * vec4(position, 1.0)).z;\n float i = (z - elevationRange.x) / (elevationRange.y - elevationRange.x);\n vec2 uv = vec2(i, (1. - i));\n vColor = texture2D(gradientTexture, uv);\n }\n }\n\n#define USE_COLOR_ALPHA\n#include <morphcolor_vertex>\n#include <begin_vertex>\n#include <morphtarget_vertex>\n#include <project_vertex>\n\n gl_PointSize = size;\n\n if (sizeMode == PNTS_SIZE_MODE_ATTENUATED) {\n bool isPerspective = isPerspectiveMatrix(projectionMatrix);\n\n if (isPerspective) {\n gl_PointSize *= scale / -mvPosition.z;\n gl_PointSize = clamp(gl_PointSize, minAttenuatedSize, maxAttenuatedSize);\n }\n }\n\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\n#include <worldpos_vertex>\n#include <fog_vertex>\n}\n";
|
|
4
4
|
/* babel-plugin-inline-import './Shader/PointsFS.glsl' */
|
|
5
|
-
const PointsFS = "#include <
|
|
6
|
-
import ShaderUtils from "./Shader/ShaderUtils.js";
|
|
5
|
+
const PointsFS = "#define USE_COLOR_ALPHA\n\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nuniform vec3 diffuse;\nuniform float opacity;\n\nuniform bool picking;\nuniform int shape;\n\nvoid main() {\n\n// Early discard (clipping planes and shape)\n#include <clipping_planes_pars_fragment>\n if (shape == PNTS_SHAPE_CIRCLE) {\n //circular rendering in glsl\n if ((length(gl_PointCoord - 0.5) > 0.5) || (vColor.a == 0.0)) {\n discard;\n }\n }\n\n#include <logdepthbuf_fragment>\n\n vec4 diffuseColor = vec4(diffuse, opacity);\n#include <map_particle_fragment>\n#include <color_fragment>\n\n#include <alphatest_fragment>\n#include <alphahash_fragment>\n\n vec3 outgoingLight = diffuseColor.rgb;\n#include <opaque_fragment> // gl_FragColor\n#include <tonemapping_fragment>\n#include <fog_fragment>\n#include <premultiplied_alpha_fragment>\n\n}\n";
|
|
7
6
|
import CommonMaterial from "./CommonMaterial.js";
|
|
8
7
|
import Gradients from "../Utils/Gradients.js";
|
|
9
8
|
export const PNTS_MODE = {
|
|
@@ -289,54 +288,49 @@ class PointsMaterial extends THREE.ShaderMaterial {
|
|
|
289
288
|
*/
|
|
290
289
|
constructor() {
|
|
291
290
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
super(options);
|
|
291
|
+
const gradients = {
|
|
292
|
+
...options.gradient,
|
|
293
|
+
...Gradients
|
|
294
|
+
};
|
|
295
|
+
options.gradient = Object.values(gradients)[0];
|
|
296
|
+
const {
|
|
297
|
+
intensityRange = new THREE.Vector2(1, 65536),
|
|
298
|
+
elevationRange = new THREE.Vector2(0, 1000),
|
|
299
|
+
angleRange = new THREE.Vector2(-90, 90),
|
|
300
|
+
classificationScheme = ClassificationScheme.DEFAULT,
|
|
301
|
+
discreteScheme = DiscreteScheme.DEFAULT,
|
|
302
|
+
size = 1,
|
|
303
|
+
mode = PNTS_MODE.COLOR,
|
|
304
|
+
shape = PNTS_SHAPE.CIRCLE,
|
|
305
|
+
sizeMode = PNTS_SIZE_MODE.ATTENUATED,
|
|
306
|
+
minAttenuatedSize = 3,
|
|
307
|
+
maxAttenuatedSize = 10,
|
|
308
|
+
gradient,
|
|
309
|
+
scale = 0.05 * 0.5 / Math.tan(1.0 / 2.0),
|
|
310
|
+
...materialOptions
|
|
311
|
+
} = options;
|
|
312
|
+
super({
|
|
313
|
+
...materialOptions,
|
|
314
|
+
fog: true,
|
|
315
|
+
precision: 'highp',
|
|
316
|
+
vertexColors: true
|
|
317
|
+
});
|
|
318
|
+
this.uniforms = THREE.UniformsUtils.merge([
|
|
319
|
+
// THREE.PointsMaterial uniforms
|
|
320
|
+
THREE.UniformsLib.points, THREE.UniformsLib.fog]);
|
|
321
|
+
this.vertexShader = PointsVS;
|
|
322
|
+
this.fragmentShader = PointsFS;
|
|
325
323
|
this.userData.needTransparency = {};
|
|
326
324
|
this.gradients = gradients;
|
|
327
325
|
this.gradientTexture = new THREE.CanvasTexture();
|
|
328
|
-
this.vertexShader = PointsVS;
|
|
329
|
-
const scale = options.scale || 0.05 * 0.5 / Math.tan(1.0 / 2.0); // autosizing scale
|
|
330
|
-
|
|
331
326
|
CommonMaterial.setDefineMapping(this, 'PNTS_MODE', PNTS_MODE);
|
|
332
327
|
CommonMaterial.setDefineMapping(this, 'PNTS_SHAPE', PNTS_SHAPE);
|
|
333
328
|
CommonMaterial.setDefineMapping(this, 'PNTS_SIZE_MODE', PNTS_SIZE_MODE);
|
|
334
|
-
|
|
329
|
+
this.size = size;
|
|
335
330
|
CommonMaterial.setUniformProperty(this, 'mode', mode);
|
|
336
331
|
CommonMaterial.setUniformProperty(this, 'shape', shape);
|
|
337
332
|
CommonMaterial.setUniformProperty(this, 'picking', false);
|
|
338
333
|
CommonMaterial.setUniformProperty(this, 'opacity', this.opacity);
|
|
339
|
-
CommonMaterial.setUniformProperty(this, 'overlayColor', options.overlayColor || new THREE.Vector4(0, 0, 0, 0));
|
|
340
334
|
CommonMaterial.setUniformProperty(this, 'intensityRange', intensityRange);
|
|
341
335
|
CommonMaterial.setUniformProperty(this, 'elevationRange', elevationRange);
|
|
342
336
|
CommonMaterial.setUniformProperty(this, 'angleRange', angleRange);
|
|
@@ -368,26 +362,95 @@ class PointsMaterial extends THREE.ShaderMaterial {
|
|
|
368
362
|
this.recomputeDiscreteTexture();
|
|
369
363
|
|
|
370
364
|
// Gradient texture for continuous values
|
|
371
|
-
this.gradient =
|
|
365
|
+
this.gradient = gradient;
|
|
372
366
|
CommonMaterial.setUniformProperty(this, 'gradientTexture', this.gradientTexture);
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
this.defines.USE_BASE_MATERIAL = true;
|
|
385
|
-
// three loop unrolling of ShaderMaterial only supports integer
|
|
386
|
-
// bounds, see https://github.com/mrdoob/three.js/issues/28020
|
|
387
|
-
this.fragmentShader = ShaderUtils.unrollLoops(PointsFS, this.defines);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Copy the parameters from the passed material into this material.
|
|
371
|
+
* @override
|
|
372
|
+
* @param {THREE.PointsMaterial} source
|
|
373
|
+
* @returns {this}
|
|
374
|
+
*/
|
|
375
|
+
copy(source) {
|
|
376
|
+
if (source.isShaderMaterial) {
|
|
377
|
+
super.copy(source);
|
|
388
378
|
} else {
|
|
389
|
-
this
|
|
379
|
+
THREE.Material.prototype.copy.call(this, source);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Parameters of THREE.PointsMaterial
|
|
383
|
+
this.color.copy(source.color);
|
|
384
|
+
this.map = source.map;
|
|
385
|
+
this.alphaMap = source.alphaMap;
|
|
386
|
+
this.size = source.size;
|
|
387
|
+
this.sizeAttenuation = source.sizeAttenuation;
|
|
388
|
+
this.fog = source.fog;
|
|
389
|
+
return this;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** @returns {THREE.Color} */
|
|
393
|
+
get color() {
|
|
394
|
+
return this.uniforms.diffuse.value;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** @param {THREE.Color} color */
|
|
398
|
+
set color(color) {
|
|
399
|
+
this.uniforms.diffuse.value.copy(color);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** @returns {THREE.Texture | null} */
|
|
403
|
+
get map() {
|
|
404
|
+
return this.uniforms.map.value;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** @param {THREE.Texture | null} map */
|
|
408
|
+
set map(map) {
|
|
409
|
+
this.uniforms.map.value = map;
|
|
410
|
+
if (!map) {
|
|
411
|
+
return;
|
|
390
412
|
}
|
|
413
|
+
if (map.matrixAutoUpdate) {
|
|
414
|
+
map.updateMatrix();
|
|
415
|
+
}
|
|
416
|
+
this.uniforms.uvTransform.value.copy(map.matrix);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** @returns {THREE.Texture | null} */
|
|
420
|
+
get alphaMap() {
|
|
421
|
+
return this.uniforms.alphaMap.value;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** @param {THREE.Texture | null} map */
|
|
425
|
+
set alphaMap(map) {
|
|
426
|
+
this.uniforms.alphaMap.value = map;
|
|
427
|
+
if (!map) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (map.matrixAutoUpdate) {
|
|
431
|
+
map.updateMatrix();
|
|
432
|
+
}
|
|
433
|
+
this.uniforms.alphaMapTransform.value.copy(map.matrix);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** @returns {number} */
|
|
437
|
+
get size() {
|
|
438
|
+
return this.uniforms.size.value;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** @param {number} size */
|
|
442
|
+
set size(size) {
|
|
443
|
+
this.uniforms.size.value = size;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** @returns {boolean} */
|
|
447
|
+
get sizeAttenuation() {
|
|
448
|
+
return this.sizeMode !== PNTS_SIZE_MODE.VALUE;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** @param {boolean} value */
|
|
452
|
+
set sizeAttenuation(value) {
|
|
453
|
+
this.sizeMode = value ? PNTS_SIZE_MODE.ATTENUATED : PNTS_SIZE_MODE.VALUE;
|
|
391
454
|
}
|
|
392
455
|
recomputeClassification() {
|
|
393
456
|
const needTransparency = recomputeTexture(this.classificationScheme, this.classificationTexture, 256);
|
|
@@ -408,43 +471,10 @@ class PointsMaterial extends THREE.ShaderMaterial {
|
|
|
408
471
|
target: this.uniforms
|
|
409
472
|
});
|
|
410
473
|
}
|
|
411
|
-
copy(source) {
|
|
412
|
-
super.copy(source);
|
|
413
|
-
if (source.uniforms.projectiveTextureAlphaBorder) {
|
|
414
|
-
// Don't copy oriented image because, it's a link to oriented image material.
|
|
415
|
-
// It needs a reference to oriented image material.
|
|
416
|
-
this.uniforms.projectiveTextureAlphaBorder = source.uniforms.projectiveTextureAlphaBorder;
|
|
417
|
-
this.uniforms.projectiveTextureDistortion = source.uniforms.projectiveTextureDistortion;
|
|
418
|
-
this.uniforms.projectiveTextureMatrix = source.uniforms.projectiveTextureMatrix;
|
|
419
|
-
this.uniforms.projectiveTexture = source.uniforms.projectiveTexture;
|
|
420
|
-
this.uniforms.mask = source.uniforms.mask;
|
|
421
|
-
this.uniforms.boostLight = source.uniforms.boostLight;
|
|
422
|
-
}
|
|
423
|
-
return this;
|
|
424
|
-
}
|
|
425
474
|
enablePicking(picking) {
|
|
426
475
|
this.picking = picking;
|
|
427
476
|
this.blending = picking ? THREE.NoBlending : THREE.NormalBlending;
|
|
428
477
|
}
|
|
429
|
-
update(source) {
|
|
430
|
-
this.visible = source.visible;
|
|
431
|
-
this.opacity = source.opacity;
|
|
432
|
-
this.transparent = source.transparent;
|
|
433
|
-
this.size = source.size;
|
|
434
|
-
this.mode = source.mode;
|
|
435
|
-
this.shape = source.shape;
|
|
436
|
-
this.sizeMode = source.sizeMode;
|
|
437
|
-
this.minAttenuatedSize = source.minAttenuatedSize;
|
|
438
|
-
this.maxAttenuatedSize = source.maxAttenuatedSize;
|
|
439
|
-
this.picking = source.picking;
|
|
440
|
-
this.scale = source.scale;
|
|
441
|
-
this.overlayColor.copy(source.overlayColor);
|
|
442
|
-
this.intensityRange.copy(source.intensityRange);
|
|
443
|
-
this.elevationRange.copy(source.elevationRange);
|
|
444
|
-
this.angleRange.copy(source.angleRange);
|
|
445
|
-
Object.assign(this.defines, source.defines);
|
|
446
|
-
return this;
|
|
447
|
-
}
|
|
448
478
|
set gradient(value) {
|
|
449
479
|
this.gradientTexture = generateGradientTexture(value);
|
|
450
480
|
}
|