@deck.gl/extensions 9.0.0-beta.1 → 9.0.0-beta.11
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/brushing/brushing-extension.js +80 -0
- package/{typed → dist}/brushing/shader-module.d.ts +1 -1
- package/{typed → dist}/brushing/shader-module.d.ts.map +1 -1
- package/dist/brushing/shader-module.js +92 -0
- package/{typed → dist}/clip/clip-extension.d.ts.map +1 -1
- package/dist/clip/clip-extension.js +117 -0
- package/{typed → dist}/collision-filter/collision-filter-effect.d.ts +4 -2
- package/dist/collision-filter/collision-filter-effect.d.ts.map +1 -0
- package/dist/collision-filter/collision-filter-effect.js +194 -0
- package/dist/collision-filter/collision-filter-extension.js +49 -0
- package/{typed → dist}/collision-filter/collision-filter-pass.d.ts +3 -2
- package/dist/collision-filter/collision-filter-pass.d.ts.map +1 -0
- package/dist/collision-filter/collision-filter-pass.js +23 -0
- package/{typed → dist}/collision-filter/shader-module.d.ts.map +1 -1
- package/dist/collision-filter/shader-module.js +87 -0
- package/dist/data-filter/aggregator.d.ts.map +1 -0
- package/dist/{esm/data-filter → data-filter}/aggregator.js +40 -41
- package/{typed → dist}/data-filter/data-filter-extension.d.ts +39 -7
- package/dist/data-filter/data-filter-extension.d.ts.map +1 -0
- package/dist/data-filter/data-filter-extension.js +256 -0
- package/dist/data-filter/shader-module.d.ts +39 -0
- package/dist/data-filter/shader-module.d.ts.map +1 -0
- package/dist/data-filter/shader-module.js +199 -0
- package/dist/dist.dev.js +2667 -11058
- package/{typed → dist}/fill-style/fill-style-extension.d.ts +2 -30
- package/dist/fill-style/fill-style-extension.d.ts.map +1 -0
- package/dist/fill-style/fill-style-extension.js +116 -0
- package/{typed/fill-style/shaders.glsl.d.ts → dist/fill-style/shader-module.d.ts} +1 -1
- package/dist/fill-style/shader-module.d.ts.map +1 -0
- package/dist/fill-style/shader-module.js +96 -0
- package/dist/fp64/fp64-extension.js +35 -0
- package/dist/fp64/project64.glsl.js +81 -0
- package/dist/fp64/project64.js +50 -0
- package/dist/index.cjs +2795 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/{typed → dist}/mask/mask-effect.d.ts +6 -5
- package/dist/mask/mask-effect.d.ts.map +1 -0
- package/dist/mask/mask-effect.js +192 -0
- package/dist/mask/mask-extension.js +57 -0
- package/dist/mask/mask-pass.d.ts +61 -0
- package/dist/mask/mask-pass.d.ts.map +1 -0
- package/dist/mask/mask-pass.js +52 -0
- package/{typed → dist}/mask/shader-module.d.ts.map +1 -1
- package/dist/mask/shader-module.js +77 -0
- package/{typed → dist}/path-style/path-style-extension.d.ts.map +1 -1
- package/dist/path-style/path-style-extension.js +112 -0
- package/dist/path-style/shaders.glsl.js +86 -0
- package/{typed → dist}/terrain/height-map-builder.d.ts +1 -1
- package/dist/terrain/height-map-builder.d.ts.map +1 -0
- package/dist/terrain/height-map-builder.js +104 -0
- package/{typed → dist}/terrain/shader-module.d.ts +2 -2
- package/dist/terrain/shader-module.d.ts.map +1 -0
- package/dist/terrain/shader-module.js +137 -0
- package/{typed → dist}/terrain/terrain-cover.d.ts +1 -1
- package/dist/terrain/terrain-cover.d.ts.map +1 -0
- package/dist/terrain/terrain-cover.js +188 -0
- package/{typed → dist}/terrain/terrain-effect.d.ts +6 -7
- package/dist/terrain/terrain-effect.d.ts.map +1 -0
- package/dist/terrain/terrain-effect.js +174 -0
- package/dist/terrain/terrain-extension.js +44 -0
- package/dist/terrain/terrain-pass.d.ts +53 -0
- package/dist/terrain/terrain-pass.d.ts.map +1 -0
- package/dist/terrain/terrain-pass.js +69 -0
- package/{typed → dist}/terrain/terrain-picking-pass.d.ts +1 -1
- package/dist/terrain/terrain-picking-pass.d.ts.map +1 -0
- package/dist/terrain/terrain-picking-pass.js +67 -0
- package/{typed → dist}/terrain/utils.d.ts +1 -0
- package/{typed → dist}/terrain/utils.d.ts.map +1 -1
- package/dist/terrain/utils.js +25 -0
- package/{typed → dist}/utils/debug.d.ts.map +1 -1
- package/dist/utils/debug.js +50 -0
- package/dist/utils/projection-utils.js +153 -0
- package/dist/utils/syntax-tags.d.ts +6 -0
- package/dist/utils/syntax-tags.d.ts.map +1 -0
- package/dist/utils/syntax-tags.js +5 -0
- package/dist.min.js +918 -1254
- package/package.json +19 -16
- package/src/brushing/shader-module.ts +4 -3
- package/src/clip/clip-extension.ts +10 -9
- package/src/collision-filter/collision-filter-effect.ts +35 -31
- package/src/collision-filter/collision-filter-pass.ts +7 -13
- package/src/collision-filter/shader-module.ts +6 -4
- package/src/data-filter/aggregator.ts +8 -13
- package/src/data-filter/data-filter-extension.ts +181 -56
- package/src/data-filter/shader-module.ts +132 -37
- package/src/fill-style/fill-style-extension.ts +4 -5
- package/src/fill-style/{shaders.glsl.ts → shader-module.ts} +6 -5
- package/src/mask/mask-effect.ts +30 -20
- package/src/mask/mask-pass.ts +22 -18
- package/src/mask/shader-module.ts +7 -6
- package/src/path-style/path-style-extension.ts +1 -0
- package/src/terrain/shader-module.ts +14 -13
- package/src/terrain/terrain-cover.ts +2 -1
- package/src/terrain/terrain-effect.ts +19 -23
- package/src/terrain/terrain-pass.ts +37 -37
- package/src/terrain/terrain-picking-pass.ts +19 -25
- package/src/terrain/utils.ts +13 -7
- package/src/utils/debug.ts +1 -2
- package/src/utils/syntax-tags.ts +5 -0
- package/dist/es5/brushing/brushing-extension.js +0 -108
- package/dist/es5/brushing/brushing-extension.js.map +0 -1
- package/dist/es5/brushing/shader-module.js +0 -50
- package/dist/es5/brushing/shader-module.js.map +0 -1
- package/dist/es5/clip/clip-extension.js +0 -98
- package/dist/es5/clip/clip-extension.js.map +0 -1
- package/dist/es5/collision-filter/collision-filter-effect.js +0 -294
- package/dist/es5/collision-filter/collision-filter-effect.js.map +0 -1
- package/dist/es5/collision-filter/collision-filter-extension.js +0 -109
- package/dist/es5/collision-filter/collision-filter-extension.js.map +0 -1
- package/dist/es5/collision-filter/collision-filter-pass.js +0 -79
- package/dist/es5/collision-filter/collision-filter-pass.js.map +0 -1
- package/dist/es5/collision-filter/shader-module.js +0 -39
- package/dist/es5/collision-filter/shader-module.js.map +0 -1
- package/dist/es5/data-filter/aggregator.js +0 -79
- package/dist/es5/data-filter/aggregator.js.map +0 -1
- package/dist/es5/data-filter/data-filter-extension.js +0 -236
- package/dist/es5/data-filter/data-filter-extension.js.map +0 -1
- package/dist/es5/data-filter/shader-module.js +0 -122
- package/dist/es5/data-filter/shader-module.js.map +0 -1
- package/dist/es5/fill-style/fill-style-extension.js +0 -190
- package/dist/es5/fill-style/fill-style-extension.js.map +0 -1
- package/dist/es5/fill-style/shaders.glsl.js +0 -59
- package/dist/es5/fill-style/shaders.glsl.js.map +0 -1
- package/dist/es5/fp64/fp64-extension.js +0 -55
- package/dist/es5/fp64/fp64-extension.js.map +0 -1
- package/dist/es5/fp64/project64.glsl.js +0 -9
- package/dist/es5/fp64/project64.glsl.js.map +0 -1
- package/dist/es5/fp64/project64.js +0 -52
- package/dist/es5/fp64/project64.js.map +0 -1
- package/dist/es5/index.js +0 -88
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/mask/mask-effect.js +0 -279
- package/dist/es5/mask/mask-effect.js.map +0 -1
- package/dist/es5/mask/mask-extension.js +0 -113
- package/dist/es5/mask/mask-extension.js.map +0 -1
- package/dist/es5/mask/mask-pass.js +0 -106
- package/dist/es5/mask/mask-pass.js.map +0 -1
- package/dist/es5/mask/shader-module.js +0 -38
- package/dist/es5/mask/shader-module.js.map +0 -1
- package/dist/es5/path-style/path-style-extension.js +0 -169
- package/dist/es5/path-style/path-style-extension.js.map +0 -1
- package/dist/es5/path-style/shaders.glsl.js +0 -25
- package/dist/es5/path-style/shaders.glsl.js.map +0 -1
- package/dist/es5/terrain/height-map-builder.js +0 -111
- package/dist/es5/terrain/height-map-builder.js.map +0 -1
- package/dist/es5/terrain/shader-module.js +0 -86
- package/dist/es5/terrain/shader-module.js.map +0 -1
- package/dist/es5/terrain/terrain-cover.js +0 -256
- package/dist/es5/terrain/terrain-cover.js.map +0 -1
- package/dist/es5/terrain/terrain-effect.js +0 -326
- package/dist/es5/terrain/terrain-effect.js.map +0 -1
- package/dist/es5/terrain/terrain-extension.js +0 -94
- package/dist/es5/terrain/terrain-extension.js.map +0 -1
- package/dist/es5/terrain/terrain-pass.js +0 -121
- package/dist/es5/terrain/terrain-pass.js.map +0 -1
- package/dist/es5/terrain/terrain-picking-pass.js +0 -124
- package/dist/es5/terrain/terrain-picking-pass.js.map +0 -1
- package/dist/es5/terrain/utils.js +0 -35
- package/dist/es5/terrain/utils.js.map +0 -1
- package/dist/es5/utils/debug.js +0 -71
- package/dist/es5/utils/debug.js.map +0 -1
- package/dist/es5/utils/projection-utils.js +0 -168
- package/dist/es5/utils/projection-utils.js.map +0 -1
- package/dist/esm/brushing/brushing-extension.js +0 -68
- package/dist/esm/brushing/brushing-extension.js.map +0 -1
- package/dist/esm/brushing/shader-module.js +0 -103
- package/dist/esm/brushing/shader-module.js.map +0 -1
- package/dist/esm/clip/clip-extension.js +0 -86
- package/dist/esm/clip/clip-extension.js.map +0 -1
- package/dist/esm/collision-filter/collision-filter-effect.js +0 -246
- package/dist/esm/collision-filter/collision-filter-effect.js.map +0 -1
- package/dist/esm/collision-filter/collision-filter-extension.js +0 -75
- package/dist/esm/collision-filter/collision-filter-extension.js.map +0 -1
- package/dist/esm/collision-filter/collision-filter-pass.js +0 -32
- package/dist/esm/collision-filter/collision-filter-pass.js.map +0 -1
- package/dist/esm/collision-filter/shader-module.js +0 -104
- package/dist/esm/collision-filter/shader-module.js.map +0 -1
- package/dist/esm/data-filter/aggregator.js.map +0 -1
- package/dist/esm/data-filter/data-filter-extension.js +0 -189
- package/dist/esm/data-filter/data-filter-extension.js.map +0 -1
- package/dist/esm/data-filter/shader-module.js +0 -164
- package/dist/esm/data-filter/shader-module.js.map +0 -1
- package/dist/esm/fill-style/fill-style-extension.js +0 -156
- package/dist/esm/fill-style/fill-style-extension.js.map +0 -1
- package/dist/esm/fill-style/shaders.glsl.js +0 -108
- package/dist/esm/fill-style/shaders.glsl.js.map +0 -1
- package/dist/esm/fp64/fp64-extension.js +0 -20
- package/dist/esm/fp64/fp64-extension.js.map +0 -1
- package/dist/esm/fp64/project64.glsl.js +0 -82
- package/dist/esm/fp64/project64.glsl.js.map +0 -1
- package/dist/esm/fp64/project64.js +0 -43
- package/dist/esm/fp64/project64.js.map +0 -1
- package/dist/esm/index.js +0 -11
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/mask/mask-effect.js +0 -228
- package/dist/esm/mask/mask-effect.js.map +0 -1
- package/dist/esm/mask/mask-extension.js +0 -83
- package/dist/esm/mask/mask-extension.js.map +0 -1
- package/dist/esm/mask/mask-pass.js +0 -58
- package/dist/esm/mask/mask-pass.js.map +0 -1
- package/dist/esm/mask/shader-module.js +0 -84
- package/dist/esm/mask/shader-module.js.map +0 -1
- package/dist/esm/path-style/path-style-extension.js +0 -130
- package/dist/esm/path-style/path-style-extension.js.map +0 -1
- package/dist/esm/path-style/shaders.glsl.js +0 -84
- package/dist/esm/path-style/shaders.glsl.js.map +0 -1
- package/dist/esm/terrain/height-map-builder.js +0 -86
- package/dist/esm/terrain/height-map-builder.js.map +0 -1
- package/dist/esm/terrain/shader-module.js +0 -127
- package/dist/esm/terrain/shader-module.js.map +0 -1
- package/dist/esm/terrain/terrain-cover.js +0 -212
- package/dist/esm/terrain/terrain-cover.js.map +0 -1
- package/dist/esm/terrain/terrain-effect.js +0 -219
- package/dist/esm/terrain/terrain-effect.js.map +0 -1
- package/dist/esm/terrain/terrain-extension.js +0 -59
- package/dist/esm/terrain/terrain-extension.js.map +0 -1
- package/dist/esm/terrain/terrain-pass.js +0 -71
- package/dist/esm/terrain/terrain-pass.js.map +0 -1
- package/dist/esm/terrain/terrain-picking-pass.js +0 -73
- package/dist/esm/terrain/terrain-picking-pass.js.map +0 -1
- package/dist/esm/terrain/utils.js +0 -19
- package/dist/esm/terrain/utils.js.map +0 -1
- package/dist/esm/utils/debug.js +0 -61
- package/dist/esm/utils/debug.js.map +0 -1
- package/dist/esm/utils/projection-utils.js +0 -134
- package/dist/esm/utils/projection-utils.js.map +0 -1
- package/typed/collision-filter/collision-filter-effect.d.ts.map +0 -1
- package/typed/collision-filter/collision-filter-pass.d.ts.map +0 -1
- package/typed/data-filter/aggregator.d.ts.map +0 -1
- package/typed/data-filter/data-filter-extension.d.ts.map +0 -1
- package/typed/data-filter/shader-module.d.ts +0 -9
- package/typed/data-filter/shader-module.d.ts.map +0 -1
- package/typed/fill-style/fill-style-extension.d.ts.map +0 -1
- package/typed/fill-style/shaders.glsl.d.ts.map +0 -1
- package/typed/index.d.ts +0 -19
- package/typed/index.d.ts.map +0 -1
- package/typed/mask/mask-effect.d.ts.map +0 -1
- package/typed/mask/mask-pass.d.ts +0 -19
- package/typed/mask/mask-pass.d.ts.map +0 -1
- package/typed/terrain/height-map-builder.d.ts.map +0 -1
- package/typed/terrain/shader-module.d.ts.map +0 -1
- package/typed/terrain/terrain-cover.d.ts.map +0 -1
- package/typed/terrain/terrain-effect.d.ts.map +0 -1
- package/typed/terrain/terrain-pass.d.ts +0 -11
- package/typed/terrain/terrain-pass.d.ts.map +0 -1
- package/typed/terrain/terrain-picking-pass.d.ts.map +0 -1
- /package/{typed → dist}/brushing/brushing-extension.d.ts +0 -0
- /package/{typed → dist}/brushing/brushing-extension.d.ts.map +0 -0
- /package/{typed → dist}/clip/clip-extension.d.ts +0 -0
- /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts +0 -0
- /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts.map +0 -0
- /package/{typed → dist}/collision-filter/shader-module.d.ts +0 -0
- /package/{typed → dist}/data-filter/aggregator.d.ts +0 -0
- /package/{typed → dist}/fp64/fp64-extension.d.ts +0 -0
- /package/{typed → dist}/fp64/fp64-extension.d.ts.map +0 -0
- /package/{typed → dist}/fp64/project64.d.ts +0 -0
- /package/{typed → dist}/fp64/project64.d.ts.map +0 -0
- /package/{typed → dist}/fp64/project64.glsl.d.ts +0 -0
- /package/{typed → dist}/fp64/project64.glsl.d.ts.map +0 -0
- /package/{typed → dist}/mask/mask-extension.d.ts +0 -0
- /package/{typed → dist}/mask/mask-extension.d.ts.map +0 -0
- /package/{typed → dist}/mask/shader-module.d.ts +0 -0
- /package/{typed → dist}/path-style/path-style-extension.d.ts +0 -0
- /package/{typed → dist}/path-style/shaders.glsl.d.ts +0 -0
- /package/{typed → dist}/path-style/shaders.glsl.d.ts.map +0 -0
- /package/{typed → dist}/terrain/terrain-extension.d.ts +0 -0
- /package/{typed → dist}/terrain/terrain-extension.d.ts.map +0 -0
- /package/{typed → dist}/utils/debug.d.ts +0 -0
- /package/{typed → dist}/utils/projection-utils.d.ts +0 -0
- /package/{typed → dist}/utils/projection-utils.d.ts.map +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { project } from '@deck.gl/core';
|
|
2
|
+
import { glsl } from "../utils/syntax-tags.js";
|
|
3
|
+
const vs = `
|
|
4
|
+
#ifdef NON_INSTANCED_MODEL
|
|
5
|
+
in float collisionPriorities;
|
|
6
|
+
#else
|
|
7
|
+
in float instanceCollisionPriorities;
|
|
8
|
+
#endif
|
|
9
|
+
uniform sampler2D collision_texture;
|
|
10
|
+
uniform bool collision_sort;
|
|
11
|
+
uniform bool collision_enabled;
|
|
12
|
+
vec2 collision_getCoords(vec4 position) {
|
|
13
|
+
vec4 collision_clipspace = project_common_position_to_clipspace(position);
|
|
14
|
+
return (1.0 + collision_clipspace.xy / collision_clipspace.w) / 2.0;
|
|
15
|
+
}
|
|
16
|
+
float collision_match(vec2 tex, vec3 pickingColor) {
|
|
17
|
+
vec4 collision_pickingColor = texture(collision_texture, tex);
|
|
18
|
+
float delta = dot(abs(collision_pickingColor.rgb - pickingColor), vec3(1.0));
|
|
19
|
+
float e = 0.001;
|
|
20
|
+
return step(delta, e);
|
|
21
|
+
}
|
|
22
|
+
float collision_isVisible(vec2 texCoords, vec3 pickingColor) {
|
|
23
|
+
if (!collision_enabled) {
|
|
24
|
+
return 1.0;
|
|
25
|
+
}
|
|
26
|
+
const int N = 2;
|
|
27
|
+
float accumulator = 0.0;
|
|
28
|
+
vec2 step = vec2(1.0 / project_uViewportSize);
|
|
29
|
+
const float floatN = float(N);
|
|
30
|
+
vec2 delta = -floatN * step;
|
|
31
|
+
for(int i = -N; i <= N; i++) {
|
|
32
|
+
delta.x = -step.x * floatN;
|
|
33
|
+
for(int j = -N; j <= N; j++) {
|
|
34
|
+
accumulator += collision_match(texCoords + delta, pickingColor);
|
|
35
|
+
delta.x += step.x;
|
|
36
|
+
}
|
|
37
|
+
delta.y += step.y;
|
|
38
|
+
}
|
|
39
|
+
float W = 2.0 * floatN + 1.0;
|
|
40
|
+
return pow(accumulator / (W * W), 2.2);
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
const inject = {
|
|
44
|
+
'vs:#decl': `
|
|
45
|
+
float collision_fade = 1.0;
|
|
46
|
+
`,
|
|
47
|
+
'vs:DECKGL_FILTER_GL_POSITION': `
|
|
48
|
+
if (collision_sort) {
|
|
49
|
+
#ifdef NON_INSTANCED_MODEL
|
|
50
|
+
float collisionPriority = collisionPriorities;
|
|
51
|
+
#else
|
|
52
|
+
float collisionPriority = instanceCollisionPriorities;
|
|
53
|
+
#endif
|
|
54
|
+
position.z = -0.001 * collisionPriority * position.w;
|
|
55
|
+
}
|
|
56
|
+
if (collision_enabled) {
|
|
57
|
+
vec4 collision_common_position = project_position(vec4(geometry.worldPosition, 1.0));
|
|
58
|
+
vec2 collision_texCoords = collision_getCoords(collision_common_position);
|
|
59
|
+
collision_fade = collision_isVisible(collision_texCoords, geometry.pickingColor / 255.0);
|
|
60
|
+
if (collision_fade < 0.0001) {
|
|
61
|
+
position = vec4(0.0, 0.0, 2.0, 1.0);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
`,
|
|
65
|
+
'vs:DECKGL_FILTER_COLOR': `
|
|
66
|
+
color.a *= collision_fade;
|
|
67
|
+
`
|
|
68
|
+
};
|
|
69
|
+
const getCollisionUniforms = (opts, uniforms) => {
|
|
70
|
+
if (!opts || !('dummyCollisionMap' in opts)) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
const { collisionFBO, drawToCollisionMap, dummyCollisionMap } = opts;
|
|
74
|
+
return {
|
|
75
|
+
collision_sort: Boolean(drawToCollisionMap),
|
|
76
|
+
// @ts-ignore (v9 not sure why this isn't allowed now)
|
|
77
|
+
collision_texture: !drawToCollisionMap && collisionFBO ? collisionFBO.colorAttachments[0] : dummyCollisionMap
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
// @ts-expect-error
|
|
81
|
+
export default {
|
|
82
|
+
name: 'collision',
|
|
83
|
+
dependencies: [project],
|
|
84
|
+
vs,
|
|
85
|
+
inject,
|
|
86
|
+
getUniforms: getCollisionUniforms
|
|
87
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregator.d.ts","sourceRoot":"","sources":["../../src/data-filter/aggregator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAiB,WAAW,EAAC,MAAM,eAAe,CAAC;AACjE,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AA0DtC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE3D;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG,WAAW,CAmBnF;AAGD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,EAAE,OAAO,GAAG,KAAK,CAe3F;AAED,eAAO,MAAM,UAAU;;;;;CAKb,CAAC"}
|
|
@@ -49,54 +49,53 @@ void main() {
|
|
|
49
49
|
fragColor = vColor;
|
|
50
50
|
}
|
|
51
51
|
`;
|
|
52
|
+
const FLOAT_TARGET_FEATURES = [
|
|
53
|
+
'float32-renderable-webgl', // ability to render to float texture
|
|
54
|
+
'texture-blend-float-webgl' // ability to blend when rendering to float texture
|
|
55
|
+
];
|
|
52
56
|
export function supportsFloatTarget(device) {
|
|
53
|
-
|
|
54
|
-
return Boolean(gl.getExtension('EXT_float_blend') && (gl.getExtension('EXT_color_buffer_float') || gl.getExtension('WEBGL_color_buffer_float')));
|
|
57
|
+
return FLOAT_TARGET_FEATURES.every(feature => device.features.has(feature));
|
|
55
58
|
}
|
|
59
|
+
// A 1x1 framebuffer object that encodes the total count of filtered items
|
|
56
60
|
export function getFramebuffer(device, useFloatTarget) {
|
|
57
|
-
|
|
61
|
+
if (useFloatTarget) {
|
|
62
|
+
return device.createFramebuffer({
|
|
63
|
+
width: 1,
|
|
64
|
+
height: 1,
|
|
65
|
+
colorAttachments: [
|
|
66
|
+
device.createTexture({
|
|
67
|
+
format: 'rgba32float',
|
|
68
|
+
type: 5126,
|
|
69
|
+
mipmaps: false
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
58
74
|
return device.createFramebuffer({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
format: device.info.type === 'webgl2' ? 'rgba32float' : 'rgba8unorm',
|
|
63
|
-
type: 5126,
|
|
64
|
-
mipmaps: false
|
|
65
|
-
})]
|
|
75
|
+
width: 256,
|
|
76
|
+
height: 64,
|
|
77
|
+
colorAttachments: [device.createTexture({ format: 'rgba8unorm', type: 5126, mipmaps: false })]
|
|
66
78
|
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return device.createFramebuffer({
|
|
70
|
-
width: 256,
|
|
71
|
-
height: 64,
|
|
72
|
-
colorAttachments: [device.createTexture({
|
|
73
|
-
format: 'rgba8unorm',
|
|
74
|
-
type: 5126,
|
|
75
|
-
mipmaps: false
|
|
76
|
-
})]
|
|
77
|
-
});
|
|
78
79
|
}
|
|
80
|
+
// Increments the counter based on dataFilter_value
|
|
79
81
|
export function getModel(device, shaderOptions, useFloatTarget) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
...shaderOptions
|
|
94
|
-
});
|
|
82
|
+
shaderOptions.defines.NON_INSTANCED_MODEL = 1;
|
|
83
|
+
if (useFloatTarget) {
|
|
84
|
+
shaderOptions.defines.FLOAT_TARGET = 1;
|
|
85
|
+
}
|
|
86
|
+
return new Model(device, {
|
|
87
|
+
id: 'data-filter-aggregation-model',
|
|
88
|
+
vertexCount: 1,
|
|
89
|
+
isInstanced: false,
|
|
90
|
+
drawMode: 0,
|
|
91
|
+
vs: AGGREGATE_VS,
|
|
92
|
+
fs: AGGREGATE_FS,
|
|
93
|
+
...shaderOptions
|
|
94
|
+
});
|
|
95
95
|
}
|
|
96
96
|
export const parameters = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
blend: true,
|
|
98
|
+
blendFunc: [1, 1, 1, 1],
|
|
99
|
+
blendEquation: [32774, 32774],
|
|
100
|
+
depthTest: false
|
|
101
101
|
};
|
|
102
|
-
//# sourceMappingURL=aggregator.js.map
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { Layer, LayerContext, Accessor, UpdateParameters } from '@deck.gl/core';
|
|
2
2
|
import { LayerExtension } from '@deck.gl/core';
|
|
3
|
+
type FilterCategory = number | string;
|
|
3
4
|
export type DataFilterExtensionProps<DataT = any> = {
|
|
4
5
|
/**
|
|
5
6
|
* Accessor to retrieve the value for each object that it will be filtered by.
|
|
6
7
|
* Returns either a number (if `filterSize: 1`) or an array of numbers.
|
|
7
8
|
*/
|
|
8
9
|
getFilterValue?: Accessor<DataT, number | number[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Accessor to retrieve the category (`number | string`) for each object that it will be filtered by.
|
|
12
|
+
* Returns either a single category (if `filterSize: 1`) or an array of categories.
|
|
13
|
+
*/
|
|
14
|
+
getFilterCategory?: Accessor<DataT, FilterCategory | FilterCategory[]>;
|
|
9
15
|
/**
|
|
10
16
|
* Enable/disable the data filter. If the data filter is disabled, all objects are rendered.
|
|
11
17
|
* @default true
|
|
@@ -33,6 +39,11 @@ export type DataFilterExtensionProps<DataT = any> = {
|
|
|
33
39
|
* @default true
|
|
34
40
|
*/
|
|
35
41
|
filterTransformColor?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The categories which define whether an object should be rendered.
|
|
44
|
+
* @default []
|
|
45
|
+
*/
|
|
46
|
+
filterCategories: FilterCategory[] | FilterCategory[][];
|
|
36
47
|
/**
|
|
37
48
|
* Only called if the `countItems` option is enabled.
|
|
38
49
|
*/
|
|
@@ -45,28 +56,37 @@ export type DataFilterExtensionProps<DataT = any> = {
|
|
|
45
56
|
};
|
|
46
57
|
type DataFilterExtensionOptions = {
|
|
47
58
|
/**
|
|
48
|
-
* The size of the filter (number of columns to filter by). The
|
|
59
|
+
* The size of the category filter (number of columns to filter by). The category filter can show/hide data based on 1-4 properties of each object. Set to `0` to disable category filtering.
|
|
60
|
+
* @default 0
|
|
61
|
+
*/
|
|
62
|
+
categorySize?: 0 | 1 | 2 | 3 | 4;
|
|
63
|
+
/**
|
|
64
|
+
* The size of the filter (number of columns to filter by). The data filter can show/hide data based on 1-4 numeric properties of each object. Set to `0` to disable numeric filtering.
|
|
49
65
|
* @default 1
|
|
50
66
|
*/
|
|
51
|
-
filterSize
|
|
67
|
+
filterSize?: 0 | 1 | 2 | 3 | 4;
|
|
52
68
|
/**
|
|
53
69
|
* Use 64-bit precision instead of 32-bit.
|
|
54
70
|
* @default false
|
|
55
71
|
*/
|
|
56
|
-
fp64
|
|
72
|
+
fp64?: boolean;
|
|
57
73
|
/**
|
|
58
74
|
* If `true`, reports the number of filtered objects with the `onFilteredItemsChange` callback.
|
|
59
75
|
* @default `false`.
|
|
60
76
|
*/
|
|
61
|
-
countItems
|
|
77
|
+
countItems?: boolean;
|
|
62
78
|
};
|
|
63
79
|
/** Adds GPU-based data filtering functionalities to layers. It allows the layer to show/hide objects based on user-defined properties. */
|
|
64
|
-
export default class DataFilterExtension extends LayerExtension<DataFilterExtensionOptions
|
|
80
|
+
export default class DataFilterExtension extends LayerExtension<Required<DataFilterExtensionOptions>> {
|
|
65
81
|
static defaultProps: {
|
|
66
82
|
getFilterValue: {
|
|
67
83
|
type: string;
|
|
68
84
|
value: number;
|
|
69
85
|
};
|
|
86
|
+
getFilterCategory: {
|
|
87
|
+
type: string;
|
|
88
|
+
value: number;
|
|
89
|
+
};
|
|
70
90
|
onFilteredItemsChange: {
|
|
71
91
|
type: string;
|
|
72
92
|
value: null;
|
|
@@ -75,16 +95,28 @@ export default class DataFilterExtension extends LayerExtension<DataFilterExtens
|
|
|
75
95
|
filterEnabled: boolean;
|
|
76
96
|
filterRange: number[];
|
|
77
97
|
filterSoftRange: null;
|
|
98
|
+
filterCategories: number[];
|
|
78
99
|
filterTransformSize: boolean;
|
|
79
100
|
filterTransformColor: boolean;
|
|
80
101
|
};
|
|
81
102
|
static extensionName: string;
|
|
82
|
-
constructor(
|
|
103
|
+
constructor(opts?: DataFilterExtensionOptions);
|
|
83
104
|
getShaders(this: Layer<DataFilterExtensionProps>, extension: this): any;
|
|
84
105
|
initializeState(this: Layer<DataFilterExtensionProps>, context: LayerContext, extension: this): void;
|
|
85
|
-
updateState(this: Layer<DataFilterExtensionProps>, { props, oldProps }: UpdateParameters<Layer<DataFilterExtensionProps
|
|
106
|
+
updateState(this: Layer<DataFilterExtensionProps>, { props, oldProps, changeFlags }: UpdateParameters<Layer<DataFilterExtensionProps>>, extension: this): void;
|
|
86
107
|
draw(this: Layer<DataFilterExtensionProps>, params: any, extension: this): void;
|
|
87
108
|
finalizeState(this: Layer<DataFilterExtensionProps>): void;
|
|
109
|
+
/**
|
|
110
|
+
* Updates the bitmask used on the GPU to perform the filter based on the
|
|
111
|
+
* `filterCategories` prop. The mapping between categories and bit in the bitmask
|
|
112
|
+
* is performed by `_getCategoryKey()`
|
|
113
|
+
*/
|
|
114
|
+
_updateCategoryBitMask(this: Layer<DataFilterExtensionProps>, params: any, extension: this): void;
|
|
115
|
+
/**
|
|
116
|
+
* Returns an index of bit in the bitmask for a given category. If the category has
|
|
117
|
+
* not yet been assigned a bit, a new one is assigned.
|
|
118
|
+
*/
|
|
119
|
+
_getCategoryKey(this: Layer<DataFilterExtensionProps>, category: FilterCategory, channel: number): number;
|
|
88
120
|
}
|
|
89
121
|
export {};
|
|
90
122
|
//# sourceMappingURL=data-filter-extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-filter-extension.d.ts","sourceRoot":"","sources":["../../src/data-filter/data-filter-extension.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
import { _deepEqual as deepEqual, LayerExtension, log } from '@deck.gl/core';
|
|
21
|
+
import { shaderModule, shaderModule64 } from "./shader-module.js";
|
|
22
|
+
import * as aggregator from "./aggregator.js";
|
|
23
|
+
const defaultProps = {
|
|
24
|
+
getFilterValue: { type: 'accessor', value: 0 },
|
|
25
|
+
getFilterCategory: { type: 'accessor', value: 0 },
|
|
26
|
+
onFilteredItemsChange: { type: 'function', value: null, optional: true },
|
|
27
|
+
filterEnabled: true,
|
|
28
|
+
filterRange: [-1, 1],
|
|
29
|
+
filterSoftRange: null,
|
|
30
|
+
filterCategories: [0],
|
|
31
|
+
filterTransformSize: true,
|
|
32
|
+
filterTransformColor: true
|
|
33
|
+
};
|
|
34
|
+
const defaultOptions = {
|
|
35
|
+
categorySize: 0,
|
|
36
|
+
filterSize: 1,
|
|
37
|
+
fp64: false,
|
|
38
|
+
countItems: false
|
|
39
|
+
};
|
|
40
|
+
const DATA_TYPE_FROM_SIZE = {
|
|
41
|
+
1: 'float',
|
|
42
|
+
2: 'vec2',
|
|
43
|
+
3: 'vec3',
|
|
44
|
+
4: 'vec4'
|
|
45
|
+
};
|
|
46
|
+
/** Adds GPU-based data filtering functionalities to layers. It allows the layer to show/hide objects based on user-defined properties. */
|
|
47
|
+
export default class DataFilterExtension extends LayerExtension {
|
|
48
|
+
static { this.defaultProps = defaultProps; }
|
|
49
|
+
static { this.extensionName = 'DataFilterExtension'; }
|
|
50
|
+
constructor(opts = {}) {
|
|
51
|
+
super({ ...defaultOptions, ...opts });
|
|
52
|
+
}
|
|
53
|
+
getShaders(extension) {
|
|
54
|
+
const { categorySize, filterSize, fp64 } = extension.opts;
|
|
55
|
+
const defines = {};
|
|
56
|
+
if (categorySize) {
|
|
57
|
+
defines.DATACATEGORY_TYPE = DATA_TYPE_FROM_SIZE[categorySize];
|
|
58
|
+
defines.DATACATEGORY_CHANNELS = categorySize;
|
|
59
|
+
}
|
|
60
|
+
if (filterSize) {
|
|
61
|
+
defines.DATAFILTER_TYPE = DATA_TYPE_FROM_SIZE[filterSize];
|
|
62
|
+
defines.DATAFILTER_DOUBLE = Boolean(fp64);
|
|
63
|
+
}
|
|
64
|
+
return { modules: [fp64 ? shaderModule64 : shaderModule], defines };
|
|
65
|
+
}
|
|
66
|
+
initializeState(context, extension) {
|
|
67
|
+
const attributeManager = this.getAttributeManager();
|
|
68
|
+
const { categorySize, filterSize, fp64 } = extension.opts;
|
|
69
|
+
if (attributeManager) {
|
|
70
|
+
if (filterSize) {
|
|
71
|
+
attributeManager.add({
|
|
72
|
+
filterValues: {
|
|
73
|
+
size: filterSize,
|
|
74
|
+
type: fp64 ? 'float64' : 'float32',
|
|
75
|
+
accessor: 'getFilterValue',
|
|
76
|
+
shaderAttributes: {
|
|
77
|
+
filterValues: {
|
|
78
|
+
divisor: 0
|
|
79
|
+
},
|
|
80
|
+
instanceFilterValues: {
|
|
81
|
+
divisor: 1
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (categorySize) {
|
|
88
|
+
attributeManager.add({
|
|
89
|
+
filterCategoryValues: {
|
|
90
|
+
size: categorySize,
|
|
91
|
+
accessor: 'getFilterCategory',
|
|
92
|
+
transform: categorySize === 1
|
|
93
|
+
? d => extension._getCategoryKey.call(this, d, 0)
|
|
94
|
+
: d => d.map((x, i) => extension._getCategoryKey.call(this, x, i)),
|
|
95
|
+
shaderAttributes: {
|
|
96
|
+
filterCategoryValues: {
|
|
97
|
+
divisor: 0
|
|
98
|
+
},
|
|
99
|
+
instanceFilterCategoryValues: {
|
|
100
|
+
divisor: 1
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const { device } = this.context;
|
|
108
|
+
if (attributeManager && extension.opts.countItems) {
|
|
109
|
+
const useFloatTarget = aggregator.supportsFloatTarget(device);
|
|
110
|
+
// This attribute is needed for variable-width data, e.g. Path, SolidPolygon, Text
|
|
111
|
+
// The vertex shader checks if a vertex has the same "index" as the previous vertex
|
|
112
|
+
// so that we only write one count cross multiple vertices of the same object
|
|
113
|
+
attributeManager.add({
|
|
114
|
+
filterIndices: {
|
|
115
|
+
size: useFloatTarget ? 1 : 2,
|
|
116
|
+
vertexOffset: 1,
|
|
117
|
+
type: 'unorm8',
|
|
118
|
+
accessor: (object, { index }) => {
|
|
119
|
+
const i = object && object.__source ? object.__source.index : index;
|
|
120
|
+
return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];
|
|
121
|
+
},
|
|
122
|
+
shaderAttributes: {
|
|
123
|
+
filterPrevIndices: {
|
|
124
|
+
vertexOffset: 0
|
|
125
|
+
},
|
|
126
|
+
filterIndices: {
|
|
127
|
+
vertexOffset: 1
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const filterFBO = aggregator.getFramebuffer(device, useFloatTarget);
|
|
133
|
+
const filterModel = aggregator.getModel(device, extension.getShaders.call(this, extension), useFloatTarget);
|
|
134
|
+
this.setState({ filterFBO, filterModel });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
updateState({ props, oldProps, changeFlags }, extension) {
|
|
138
|
+
const attributeManager = this.getAttributeManager();
|
|
139
|
+
const { categorySize } = extension.opts;
|
|
140
|
+
if (this.state.filterModel) {
|
|
141
|
+
const filterNeedsUpdate =
|
|
142
|
+
// attributeManager must be defined for filterModel to be set
|
|
143
|
+
attributeManager.attributes.filterValues?.needsUpdate() ||
|
|
144
|
+
attributeManager.attributes.filterCategoryValues?.needsUpdate() ||
|
|
145
|
+
props.filterEnabled !== oldProps.filterEnabled ||
|
|
146
|
+
props.filterRange !== oldProps.filterRange ||
|
|
147
|
+
props.filterSoftRange !== oldProps.filterSoftRange ||
|
|
148
|
+
props.filterCategories !== oldProps.filterCategories;
|
|
149
|
+
if (filterNeedsUpdate) {
|
|
150
|
+
this.setState({ filterNeedsUpdate });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (attributeManager?.attributes.filterCategoryValues) {
|
|
154
|
+
// Update bitmask if accessor or selected categories has changed
|
|
155
|
+
const categoryBitMaskNeedsUpdate = attributeManager.attributes.filterCategoryValues.needsUpdate() ||
|
|
156
|
+
!deepEqual(props.filterCategories, oldProps.filterCategories, 2);
|
|
157
|
+
if (categoryBitMaskNeedsUpdate) {
|
|
158
|
+
this.setState({ categoryBitMaskNeedsUpdate });
|
|
159
|
+
}
|
|
160
|
+
// Need to recreate category map if categorySize has changed
|
|
161
|
+
const resetCategories = changeFlags.dataChanged;
|
|
162
|
+
if (resetCategories) {
|
|
163
|
+
this.setState({
|
|
164
|
+
categoryMap: Array(categorySize)
|
|
165
|
+
.fill(0)
|
|
166
|
+
.map(() => ({}))
|
|
167
|
+
});
|
|
168
|
+
attributeManager.attributes.filterCategoryValues.setNeedsUpdate('categoryMap');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
draw(params, extension) {
|
|
173
|
+
const filterFBO = this.state.filterFBO;
|
|
174
|
+
const filterModel = this.state.filterModel;
|
|
175
|
+
const filterNeedsUpdate = this.state.filterNeedsUpdate;
|
|
176
|
+
const categoryBitMaskNeedsUpdate = this.state.categoryBitMaskNeedsUpdate;
|
|
177
|
+
const { onFilteredItemsChange } = this.props;
|
|
178
|
+
if (categoryBitMaskNeedsUpdate) {
|
|
179
|
+
extension._updateCategoryBitMask.call(this, params, extension);
|
|
180
|
+
}
|
|
181
|
+
if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
|
|
182
|
+
const { attributes: { filterValues, filterCategoryValues, filterIndices } } = this.getAttributeManager();
|
|
183
|
+
filterModel.setVertexCount(this.getNumInstances());
|
|
184
|
+
this.context.device.clearWebGL({ framebuffer: filterFBO, color: [0, 0, 0, 0] });
|
|
185
|
+
filterModel.updateModuleSettings(params.moduleParameters);
|
|
186
|
+
// @ts-expect-error filterValue and filterIndices should always have buffer value
|
|
187
|
+
filterModel.setAttributes({
|
|
188
|
+
...filterValues?.getValue(),
|
|
189
|
+
...filterCategoryValues?.getValue(),
|
|
190
|
+
...filterIndices?.getValue()
|
|
191
|
+
});
|
|
192
|
+
filterModel.setUniforms(params.uniforms);
|
|
193
|
+
filterModel.device.withParametersWebGL({
|
|
194
|
+
framebuffer: filterFBO,
|
|
195
|
+
// ts-ignore 'readonly' cannot be assigned to the mutable type '[GLBlendEquation, GLBlendEquation]'
|
|
196
|
+
...aggregator.parameters,
|
|
197
|
+
viewport: [0, 0, filterFBO.width, filterFBO.height]
|
|
198
|
+
}, () => {
|
|
199
|
+
filterModel.draw(this.context.renderPass);
|
|
200
|
+
});
|
|
201
|
+
const color = filterModel.device.readPixelsToArrayWebGL(filterFBO);
|
|
202
|
+
let count = 0;
|
|
203
|
+
for (let i = 0; i < color.length; i++) {
|
|
204
|
+
count += color[i];
|
|
205
|
+
}
|
|
206
|
+
onFilteredItemsChange({ id: this.id, count });
|
|
207
|
+
this.state.filterNeedsUpdate = false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
finalizeState() {
|
|
211
|
+
const filterFBO = this.state.filterFBO;
|
|
212
|
+
const filterModel = this.state.filterModel;
|
|
213
|
+
// filterFBO.color.delete();
|
|
214
|
+
filterFBO?.destroy();
|
|
215
|
+
filterModel?.destroy();
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Updates the bitmask used on the GPU to perform the filter based on the
|
|
219
|
+
* `filterCategories` prop. The mapping between categories and bit in the bitmask
|
|
220
|
+
* is performed by `_getCategoryKey()`
|
|
221
|
+
*/
|
|
222
|
+
_updateCategoryBitMask(params, extension) {
|
|
223
|
+
const { categorySize } = extension.opts;
|
|
224
|
+
const { filterCategories } = this.props;
|
|
225
|
+
const categoryBitMask = new Uint32Array([0, 0, 0, 0]);
|
|
226
|
+
const categoryFilters = (categorySize === 1 ? [filterCategories] : filterCategories);
|
|
227
|
+
const maxCategories = categorySize === 1 ? 128 : categorySize === 2 ? 64 : 32;
|
|
228
|
+
for (let c = 0; c < categoryFilters.length; c++) {
|
|
229
|
+
const categoryFilter = categoryFilters[c];
|
|
230
|
+
for (const category of categoryFilter) {
|
|
231
|
+
const key = extension._getCategoryKey.call(this, category, c);
|
|
232
|
+
if (key < maxCategories) {
|
|
233
|
+
const channel = c * (maxCategories / 32) + Math.floor(key / 32);
|
|
234
|
+
categoryBitMask[channel] += Math.pow(2, key % 32); // 1 << key fails for key > 30
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
log.warn(`Exceeded maximum number of categories (${maxCategories})`)();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/* eslint-disable-next-line camelcase */
|
|
242
|
+
params.uniforms.filter_categoryBitMask = categoryBitMask;
|
|
243
|
+
this.state.categoryBitMaskNeedsUpdate = false;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Returns an index of bit in the bitmask for a given category. If the category has
|
|
247
|
+
* not yet been assigned a bit, a new one is assigned.
|
|
248
|
+
*/
|
|
249
|
+
_getCategoryKey(category, channel) {
|
|
250
|
+
const categoryMap = this.state.categoryMap[channel];
|
|
251
|
+
if (!(category in categoryMap)) {
|
|
252
|
+
categoryMap[category] = Object.keys(categoryMap).length;
|
|
253
|
+
}
|
|
254
|
+
return categoryMap[category];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
2
|
+
import type { DataFilterExtensionProps } from "./data-filter-extension.js";
|
|
3
|
+
export type Defines = {
|
|
4
|
+
/**
|
|
5
|
+
* Primitive type of parameter used for category filtering. If undefined, category filtering disabled.
|
|
6
|
+
*/
|
|
7
|
+
DATACATEGORY_TYPE?: 'float' | 'vec2' | 'vec3' | 'vec4';
|
|
8
|
+
/**
|
|
9
|
+
* Number of category filtering channels. Must match dimension of `DATACATEGORY_TYPE`
|
|
10
|
+
*/
|
|
11
|
+
DATACATEGORY_CHANNELS?: 1 | 2 | 3 | 4;
|
|
12
|
+
/**
|
|
13
|
+
* Primitive type of parameter used for numeric filtering. If undefined, numeric filtering disabled.
|
|
14
|
+
*/
|
|
15
|
+
DATAFILTER_TYPE?: 'float' | 'vec2' | 'vec3' | 'vec4';
|
|
16
|
+
/**
|
|
17
|
+
* Enable 64-bit precision in numeric filter.
|
|
18
|
+
*/
|
|
19
|
+
DATAFILTER_DOUBLE?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Numeric filter attribute
|
|
22
|
+
*/
|
|
23
|
+
DATAFILTER_ATTRIB?: 'filterValues' | 'instanceFilterValues';
|
|
24
|
+
/**
|
|
25
|
+
* Numeric filter attribute (low bits). Only used when `DATAFILTER_DOUBLE = true`
|
|
26
|
+
*/
|
|
27
|
+
DATAFILTER_ATTRIB_64LOW?: 'filterValues64Low' | 'instanceFilterValues64Low';
|
|
28
|
+
/**
|
|
29
|
+
* Category filter attribute
|
|
30
|
+
*/
|
|
31
|
+
DATACATEGORY_ATTRIB?: 'filterCategoryValues' | 'instanceFilterCategoryValues';
|
|
32
|
+
};
|
|
33
|
+
type DataFilterModuleSettings = {
|
|
34
|
+
extensions: any[];
|
|
35
|
+
} & DataFilterExtensionProps;
|
|
36
|
+
export declare const shaderModule: ShaderModule<DataFilterModuleSettings>;
|
|
37
|
+
export declare const shaderModule64: ShaderModule<DataFilterModuleSettings>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=shader-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../src/data-filter/shader-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAC,wBAAwB,EAAC,mCAAgC;AAMtE,MAAM,MAAM,OAAO,GAAG;IAEpB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACvD;;OAEG;IACH,qBAAqB,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEtC;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAErD;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAG5B;;OAEG;IACH,iBAAiB,CAAC,EAAE,cAAc,GAAG,sBAAsB,CAAC;IAC5D;;OAEG;IACH,uBAAuB,CAAC,EAAE,mBAAmB,GAAG,2BAA2B,CAAC;IAC5E;;OAEG;IACH,mBAAmB,CAAC,EAAE,sBAAsB,GAAG,8BAA8B,CAAC;CAC/E,CAAC;AAiHF,KAAK,wBAAwB,GAAG;IAC9B,UAAU,EAAE,GAAG,EAAE,CAAC;CACnB,GAAG,wBAAwB,CAAC;AA0G7B,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,wBAAwB,CAM/D,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,wBAAwB,CAMjE,CAAC"}
|