@deck.gl/extensions 9.0.0-beta.2 → 9.0.0-beta.3

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.
Files changed (232) hide show
  1. package/dist/brushing/brushing-extension.js +80 -0
  2. package/dist/{esm/brushing → brushing}/shader-module.js +24 -30
  3. package/dist/clip/clip-extension.js +117 -0
  4. package/{typed → dist}/collision-filter/collision-filter-effect.d.ts.map +1 -1
  5. package/dist/collision-filter/collision-filter-effect.js +193 -0
  6. package/dist/collision-filter/collision-filter-extension.js +49 -0
  7. package/{typed → dist}/collision-filter/collision-filter-pass.d.ts.map +1 -1
  8. package/dist/collision-filter/collision-filter-pass.js +25 -0
  9. package/dist/{esm/collision-filter → collision-filter}/shader-module.js +17 -24
  10. package/dist/data-filter/aggregator.js +104 -0
  11. package/{typed → dist}/data-filter/data-filter-extension.d.ts.map +1 -1
  12. package/dist/data-filter/data-filter-extension.js +162 -0
  13. package/dist/data-filter/shader-module.js +159 -0
  14. package/dist/dist.dev.js +1762 -13033
  15. package/dist/fill-style/fill-style-extension.js +118 -0
  16. package/dist/{esm/fill-style → fill-style}/shaders.glsl.js +37 -43
  17. package/dist/fp64/fp64-extension.js +35 -0
  18. package/dist/{esm/fp64 → fp64}/project64.glsl.js +19 -1
  19. package/dist/fp64/project64.js +50 -0
  20. package/dist/index.cjs +2724 -0
  21. package/dist/index.cjs.map +7 -0
  22. package/dist/index.js +11 -0
  23. package/{typed → dist}/mask/mask-effect.d.ts.map +1 -1
  24. package/dist/mask/mask-effect.js +194 -0
  25. package/dist/mask/mask-extension.js +57 -0
  26. package/{typed → dist}/mask/mask-pass.d.ts.map +1 -1
  27. package/dist/mask/mask-pass.js +44 -0
  28. package/dist/{esm/mask → mask}/shader-module.js +18 -21
  29. package/dist/path-style/path-style-extension.js +111 -0
  30. package/dist/{esm/path-style → path-style}/shaders.glsl.js +20 -13
  31. package/dist/terrain/height-map-builder.js +104 -0
  32. package/dist/terrain/shader-module.js +139 -0
  33. package/dist/terrain/terrain-cover.js +187 -0
  34. package/{typed → dist}/terrain/terrain-effect.d.ts.map +1 -1
  35. package/dist/terrain/terrain-effect.js +184 -0
  36. package/dist/terrain/terrain-extension.js +44 -0
  37. package/{typed → dist}/terrain/terrain-pass.d.ts.map +1 -1
  38. package/dist/terrain/terrain-pass.js +61 -0
  39. package/{typed → dist}/terrain/terrain-picking-pass.d.ts.map +1 -1
  40. package/dist/terrain/terrain-picking-pass.js +66 -0
  41. package/dist/terrain/utils.js +21 -0
  42. package/{typed → dist}/utils/debug.d.ts.map +1 -1
  43. package/dist/utils/debug.js +50 -0
  44. package/dist/utils/projection-utils.js +153 -0
  45. package/dist.min.js +73 -205
  46. package/package.json +19 -12
  47. package/src/collision-filter/collision-filter-effect.ts +12 -8
  48. package/src/collision-filter/collision-filter-pass.ts +1 -3
  49. package/src/data-filter/data-filter-extension.ts +3 -5
  50. package/src/mask/mask-effect.ts +0 -1
  51. package/src/mask/mask-pass.ts +1 -3
  52. package/src/terrain/terrain-effect.ts +8 -2
  53. package/src/terrain/terrain-pass.ts +2 -5
  54. package/src/terrain/terrain-picking-pass.ts +1 -3
  55. package/src/utils/debug.ts +1 -2
  56. package/dist/es5/brushing/brushing-extension.js +0 -108
  57. package/dist/es5/brushing/brushing-extension.js.map +0 -1
  58. package/dist/es5/brushing/shader-module.js +0 -50
  59. package/dist/es5/brushing/shader-module.js.map +0 -1
  60. package/dist/es5/clip/clip-extension.js +0 -98
  61. package/dist/es5/clip/clip-extension.js.map +0 -1
  62. package/dist/es5/collision-filter/collision-filter-effect.js +0 -294
  63. package/dist/es5/collision-filter/collision-filter-effect.js.map +0 -1
  64. package/dist/es5/collision-filter/collision-filter-extension.js +0 -109
  65. package/dist/es5/collision-filter/collision-filter-extension.js.map +0 -1
  66. package/dist/es5/collision-filter/collision-filter-pass.js +0 -79
  67. package/dist/es5/collision-filter/collision-filter-pass.js.map +0 -1
  68. package/dist/es5/collision-filter/shader-module.js +0 -39
  69. package/dist/es5/collision-filter/shader-module.js.map +0 -1
  70. package/dist/es5/data-filter/aggregator.js +0 -79
  71. package/dist/es5/data-filter/aggregator.js.map +0 -1
  72. package/dist/es5/data-filter/data-filter-extension.js +0 -236
  73. package/dist/es5/data-filter/data-filter-extension.js.map +0 -1
  74. package/dist/es5/data-filter/shader-module.js +0 -122
  75. package/dist/es5/data-filter/shader-module.js.map +0 -1
  76. package/dist/es5/fill-style/fill-style-extension.js +0 -190
  77. package/dist/es5/fill-style/fill-style-extension.js.map +0 -1
  78. package/dist/es5/fill-style/shaders.glsl.js +0 -59
  79. package/dist/es5/fill-style/shaders.glsl.js.map +0 -1
  80. package/dist/es5/fp64/fp64-extension.js +0 -55
  81. package/dist/es5/fp64/fp64-extension.js.map +0 -1
  82. package/dist/es5/fp64/project64.glsl.js +0 -9
  83. package/dist/es5/fp64/project64.glsl.js.map +0 -1
  84. package/dist/es5/fp64/project64.js +0 -52
  85. package/dist/es5/fp64/project64.js.map +0 -1
  86. package/dist/es5/index.js +0 -88
  87. package/dist/es5/index.js.map +0 -1
  88. package/dist/es5/mask/mask-effect.js +0 -279
  89. package/dist/es5/mask/mask-effect.js.map +0 -1
  90. package/dist/es5/mask/mask-extension.js +0 -113
  91. package/dist/es5/mask/mask-extension.js.map +0 -1
  92. package/dist/es5/mask/mask-pass.js +0 -106
  93. package/dist/es5/mask/mask-pass.js.map +0 -1
  94. package/dist/es5/mask/shader-module.js +0 -38
  95. package/dist/es5/mask/shader-module.js.map +0 -1
  96. package/dist/es5/path-style/path-style-extension.js +0 -169
  97. package/dist/es5/path-style/path-style-extension.js.map +0 -1
  98. package/dist/es5/path-style/shaders.glsl.js +0 -25
  99. package/dist/es5/path-style/shaders.glsl.js.map +0 -1
  100. package/dist/es5/terrain/height-map-builder.js +0 -111
  101. package/dist/es5/terrain/height-map-builder.js.map +0 -1
  102. package/dist/es5/terrain/shader-module.js +0 -86
  103. package/dist/es5/terrain/shader-module.js.map +0 -1
  104. package/dist/es5/terrain/terrain-cover.js +0 -256
  105. package/dist/es5/terrain/terrain-cover.js.map +0 -1
  106. package/dist/es5/terrain/terrain-effect.js +0 -326
  107. package/dist/es5/terrain/terrain-effect.js.map +0 -1
  108. package/dist/es5/terrain/terrain-extension.js +0 -94
  109. package/dist/es5/terrain/terrain-extension.js.map +0 -1
  110. package/dist/es5/terrain/terrain-pass.js +0 -121
  111. package/dist/es5/terrain/terrain-pass.js.map +0 -1
  112. package/dist/es5/terrain/terrain-picking-pass.js +0 -124
  113. package/dist/es5/terrain/terrain-picking-pass.js.map +0 -1
  114. package/dist/es5/terrain/utils.js +0 -35
  115. package/dist/es5/terrain/utils.js.map +0 -1
  116. package/dist/es5/utils/debug.js +0 -71
  117. package/dist/es5/utils/debug.js.map +0 -1
  118. package/dist/es5/utils/projection-utils.js +0 -168
  119. package/dist/es5/utils/projection-utils.js.map +0 -1
  120. package/dist/esm/brushing/brushing-extension.js +0 -68
  121. package/dist/esm/brushing/brushing-extension.js.map +0 -1
  122. package/dist/esm/brushing/shader-module.js.map +0 -1
  123. package/dist/esm/clip/clip-extension.js +0 -86
  124. package/dist/esm/clip/clip-extension.js.map +0 -1
  125. package/dist/esm/collision-filter/collision-filter-effect.js +0 -246
  126. package/dist/esm/collision-filter/collision-filter-effect.js.map +0 -1
  127. package/dist/esm/collision-filter/collision-filter-extension.js +0 -75
  128. package/dist/esm/collision-filter/collision-filter-extension.js.map +0 -1
  129. package/dist/esm/collision-filter/collision-filter-pass.js +0 -32
  130. package/dist/esm/collision-filter/collision-filter-pass.js.map +0 -1
  131. package/dist/esm/collision-filter/shader-module.js.map +0 -1
  132. package/dist/esm/data-filter/aggregator.js +0 -102
  133. package/dist/esm/data-filter/aggregator.js.map +0 -1
  134. package/dist/esm/data-filter/data-filter-extension.js +0 -189
  135. package/dist/esm/data-filter/data-filter-extension.js.map +0 -1
  136. package/dist/esm/data-filter/shader-module.js +0 -164
  137. package/dist/esm/data-filter/shader-module.js.map +0 -1
  138. package/dist/esm/fill-style/fill-style-extension.js +0 -156
  139. package/dist/esm/fill-style/fill-style-extension.js.map +0 -1
  140. package/dist/esm/fill-style/shaders.glsl.js.map +0 -1
  141. package/dist/esm/fp64/fp64-extension.js +0 -20
  142. package/dist/esm/fp64/fp64-extension.js.map +0 -1
  143. package/dist/esm/fp64/project64.glsl.js.map +0 -1
  144. package/dist/esm/fp64/project64.js +0 -43
  145. package/dist/esm/fp64/project64.js.map +0 -1
  146. package/dist/esm/index.js +0 -11
  147. package/dist/esm/index.js.map +0 -1
  148. package/dist/esm/mask/mask-effect.js +0 -228
  149. package/dist/esm/mask/mask-effect.js.map +0 -1
  150. package/dist/esm/mask/mask-extension.js +0 -83
  151. package/dist/esm/mask/mask-extension.js.map +0 -1
  152. package/dist/esm/mask/mask-pass.js +0 -58
  153. package/dist/esm/mask/mask-pass.js.map +0 -1
  154. package/dist/esm/mask/shader-module.js.map +0 -1
  155. package/dist/esm/path-style/path-style-extension.js +0 -130
  156. package/dist/esm/path-style/path-style-extension.js.map +0 -1
  157. package/dist/esm/path-style/shaders.glsl.js.map +0 -1
  158. package/dist/esm/terrain/height-map-builder.js +0 -86
  159. package/dist/esm/terrain/height-map-builder.js.map +0 -1
  160. package/dist/esm/terrain/shader-module.js +0 -127
  161. package/dist/esm/terrain/shader-module.js.map +0 -1
  162. package/dist/esm/terrain/terrain-cover.js +0 -212
  163. package/dist/esm/terrain/terrain-cover.js.map +0 -1
  164. package/dist/esm/terrain/terrain-effect.js +0 -219
  165. package/dist/esm/terrain/terrain-effect.js.map +0 -1
  166. package/dist/esm/terrain/terrain-extension.js +0 -59
  167. package/dist/esm/terrain/terrain-extension.js.map +0 -1
  168. package/dist/esm/terrain/terrain-pass.js +0 -71
  169. package/dist/esm/terrain/terrain-pass.js.map +0 -1
  170. package/dist/esm/terrain/terrain-picking-pass.js +0 -73
  171. package/dist/esm/terrain/terrain-picking-pass.js.map +0 -1
  172. package/dist/esm/terrain/utils.js +0 -19
  173. package/dist/esm/terrain/utils.js.map +0 -1
  174. package/dist/esm/utils/debug.js +0 -61
  175. package/dist/esm/utils/debug.js.map +0 -1
  176. package/dist/esm/utils/projection-utils.js +0 -134
  177. package/dist/esm/utils/projection-utils.js.map +0 -1
  178. /package/{typed → dist}/brushing/brushing-extension.d.ts +0 -0
  179. /package/{typed → dist}/brushing/brushing-extension.d.ts.map +0 -0
  180. /package/{typed → dist}/brushing/shader-module.d.ts +0 -0
  181. /package/{typed → dist}/brushing/shader-module.d.ts.map +0 -0
  182. /package/{typed → dist}/clip/clip-extension.d.ts +0 -0
  183. /package/{typed → dist}/clip/clip-extension.d.ts.map +0 -0
  184. /package/{typed → dist}/collision-filter/collision-filter-effect.d.ts +0 -0
  185. /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts +0 -0
  186. /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts.map +0 -0
  187. /package/{typed → dist}/collision-filter/collision-filter-pass.d.ts +0 -0
  188. /package/{typed → dist}/collision-filter/shader-module.d.ts +0 -0
  189. /package/{typed → dist}/collision-filter/shader-module.d.ts.map +0 -0
  190. /package/{typed → dist}/data-filter/aggregator.d.ts +0 -0
  191. /package/{typed → dist}/data-filter/aggregator.d.ts.map +0 -0
  192. /package/{typed → dist}/data-filter/data-filter-extension.d.ts +0 -0
  193. /package/{typed → dist}/data-filter/shader-module.d.ts +0 -0
  194. /package/{typed → dist}/data-filter/shader-module.d.ts.map +0 -0
  195. /package/{typed → dist}/fill-style/fill-style-extension.d.ts +0 -0
  196. /package/{typed → dist}/fill-style/fill-style-extension.d.ts.map +0 -0
  197. /package/{typed → dist}/fill-style/shaders.glsl.d.ts +0 -0
  198. /package/{typed → dist}/fill-style/shaders.glsl.d.ts.map +0 -0
  199. /package/{typed → dist}/fp64/fp64-extension.d.ts +0 -0
  200. /package/{typed → dist}/fp64/fp64-extension.d.ts.map +0 -0
  201. /package/{typed → dist}/fp64/project64.d.ts +0 -0
  202. /package/{typed → dist}/fp64/project64.d.ts.map +0 -0
  203. /package/{typed → dist}/fp64/project64.glsl.d.ts +0 -0
  204. /package/{typed → dist}/fp64/project64.glsl.d.ts.map +0 -0
  205. /package/{typed → dist}/index.d.ts +0 -0
  206. /package/{typed → dist}/index.d.ts.map +0 -0
  207. /package/{typed → dist}/mask/mask-effect.d.ts +0 -0
  208. /package/{typed → dist}/mask/mask-extension.d.ts +0 -0
  209. /package/{typed → dist}/mask/mask-extension.d.ts.map +0 -0
  210. /package/{typed → dist}/mask/mask-pass.d.ts +0 -0
  211. /package/{typed → dist}/mask/shader-module.d.ts +0 -0
  212. /package/{typed → dist}/mask/shader-module.d.ts.map +0 -0
  213. /package/{typed → dist}/path-style/path-style-extension.d.ts +0 -0
  214. /package/{typed → dist}/path-style/path-style-extension.d.ts.map +0 -0
  215. /package/{typed → dist}/path-style/shaders.glsl.d.ts +0 -0
  216. /package/{typed → dist}/path-style/shaders.glsl.d.ts.map +0 -0
  217. /package/{typed → dist}/terrain/height-map-builder.d.ts +0 -0
  218. /package/{typed → dist}/terrain/height-map-builder.d.ts.map +0 -0
  219. /package/{typed → dist}/terrain/shader-module.d.ts +0 -0
  220. /package/{typed → dist}/terrain/shader-module.d.ts.map +0 -0
  221. /package/{typed → dist}/terrain/terrain-cover.d.ts +0 -0
  222. /package/{typed → dist}/terrain/terrain-cover.d.ts.map +0 -0
  223. /package/{typed → dist}/terrain/terrain-effect.d.ts +0 -0
  224. /package/{typed → dist}/terrain/terrain-extension.d.ts +0 -0
  225. /package/{typed → dist}/terrain/terrain-extension.d.ts.map +0 -0
  226. /package/{typed → dist}/terrain/terrain-pass.d.ts +0 -0
  227. /package/{typed → dist}/terrain/terrain-picking-pass.d.ts +0 -0
  228. /package/{typed → dist}/terrain/utils.d.ts +0 -0
  229. /package/{typed → dist}/terrain/utils.d.ts.map +0 -0
  230. /package/{typed → dist}/utils/debug.d.ts +0 -0
  231. /package/{typed → dist}/utils/projection-utils.d.ts +0 -0
  232. /package/{typed → dist}/utils/projection-utils.d.ts.map +0 -0
@@ -0,0 +1,57 @@
1
+ import { COORDINATE_SYSTEM, LayerExtension, log } from '@deck.gl/core';
2
+ import mask from "./shader-module.js";
3
+ import MaskEffect from "./mask-effect.js";
4
+ const defaultProps = {
5
+ maskId: '',
6
+ maskByInstance: undefined,
7
+ maskInverted: false
8
+ };
9
+ /** Allows layers to show/hide objects by a geofence. */
10
+ export default class MaskExtension extends LayerExtension {
11
+ static { this.defaultProps = defaultProps; }
12
+ static { this.extensionName = 'MaskExtension'; }
13
+ initializeState() {
14
+ this.context.deck?._addDefaultEffect(new MaskEffect());
15
+ }
16
+ getShaders() {
17
+ // Infer by geometry if 'maskByInstance' prop isn't explictly set
18
+ let maskByInstance = 'instancePositions' in this.getAttributeManager().attributes;
19
+ // Users can override by setting the `maskByInstance` prop
20
+ if (this.props.maskByInstance !== undefined) {
21
+ maskByInstance = Boolean(this.props.maskByInstance);
22
+ }
23
+ this.state.maskByInstance = maskByInstance;
24
+ return {
25
+ modules: [mask]
26
+ };
27
+ }
28
+ /* eslint-disable camelcase */
29
+ draw({ uniforms, context, moduleParameters }) {
30
+ uniforms.mask_maskByInstance = this.state.maskByInstance;
31
+ const { maskId, maskInverted } = this.props;
32
+ const { maskChannels } = moduleParameters;
33
+ const { viewport } = context;
34
+ if (maskChannels && maskChannels[maskId]) {
35
+ const { index, bounds, coordinateOrigin: fromCoordinateOrigin } = maskChannels[maskId];
36
+ let { coordinateSystem: fromCoordinateSystem } = maskChannels[maskId];
37
+ uniforms.mask_enabled = true;
38
+ uniforms.mask_channel = index;
39
+ uniforms.mask_inverted = maskInverted;
40
+ if (fromCoordinateSystem === COORDINATE_SYSTEM.DEFAULT) {
41
+ fromCoordinateSystem = viewport.isGeospatial
42
+ ? COORDINATE_SYSTEM.LNGLAT
43
+ : COORDINATE_SYSTEM.CARTESIAN;
44
+ }
45
+ const opts = { modelMatrix: null, fromCoordinateOrigin, fromCoordinateSystem };
46
+ const bl = this.projectPosition([bounds[0], bounds[1], 0], opts);
47
+ const tr = this.projectPosition([bounds[2], bounds[3], 0], opts);
48
+ uniforms.mask_bounds = [bl[0], bl[1], tr[0], tr[1]];
49
+ }
50
+ else {
51
+ if (maskId) {
52
+ log.warn(`Could not find a mask layer with id: ${maskId}`)();
53
+ }
54
+ uniforms.mask_enabled = false;
55
+ }
56
+ }
57
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"mask-pass.d.ts","sourceRoot":"","sources":["../../src/mask/mask-pass.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAGhE,OAAO,EAAC,WAAW,IAAI,UAAU,EAAE,uBAAuB,EAAC,MAAM,eAAe,CAAC;AAEjF,KAAK,qBAAqB,GAAG,uBAAuB,GAAG;IACrD,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,UAAU;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,WAAW,CAAC;gBAEL,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAC;IAyBjE,MAAM,CAAC,OAAO,EAAE,qBAAqB;IAkBrC,eAAe,CAAC,KAAK,KAAA;IAIrB,MAAM;CAIP"}
1
+ {"version":3,"file":"mask-pass.d.ts","sourceRoot":"","sources":["../../src/mask/mask-pass.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAC,WAAW,IAAI,UAAU,EAAE,uBAAuB,EAAC,MAAM,eAAe,CAAC;AAEjF,KAAK,qBAAqB,GAAG,uBAAuB,GAAG;IACrD,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,UAAU;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,WAAW,CAAC;gBAEL,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAC;IAyBjE,MAAM,CAAC,OAAO,EAAE,qBAAqB;IAiBrC,eAAe,CAAC,KAAK,KAAA;IAIrB,MAAM;CAIP"}
@@ -0,0 +1,44 @@
1
+ import { GL } from '@luma.gl/constants';
2
+ import { _LayersPass as LayersPass } from '@deck.gl/core';
3
+ export default class MaskPass extends LayersPass {
4
+ constructor(device, props) {
5
+ super(device, props);
6
+ const { mapSize = 2048 } = props;
7
+ this.maskMap = device.createTexture({
8
+ format: 'rgba8unorm',
9
+ width: mapSize,
10
+ height: mapSize,
11
+ sampler: {
12
+ minFilter: 'linear',
13
+ magFilter: 'linear',
14
+ addressModeU: 'clamp-to-edge',
15
+ addressModeV: 'clamp-to-edge'
16
+ }
17
+ });
18
+ this.fbo = device.createFramebuffer({
19
+ id: 'maskmap',
20
+ width: mapSize,
21
+ height: mapSize,
22
+ colorAttachments: [this.maskMap]
23
+ });
24
+ }
25
+ render(options) {
26
+ const colorMask = [false, false, false, false];
27
+ colorMask[options.channel] = true;
28
+ const clearColor = [255, 255, 255, 255];
29
+ return this.device.withParametersWebGL({
30
+ blend: true,
31
+ blendFunc: [GL.ZERO, GL.ONE],
32
+ blendEquation: GL.FUNC_SUBTRACT,
33
+ colorMask,
34
+ depthTest: false
35
+ }, () => super.render({ ...options, clearColor, target: this.fbo, pass: 'mask' }));
36
+ }
37
+ shouldDrawLayer(layer) {
38
+ return layer.props.operation.includes('mask');
39
+ }
40
+ delete() {
41
+ this.fbo.delete();
42
+ this.maskMap.delete();
43
+ }
44
+ }
@@ -35,10 +35,10 @@ bool mask_isInBounds(vec2 texCoords) {
35
35
  }
36
36
  `;
37
37
  const inject = {
38
- 'vs:#decl': `
38
+ 'vs:#decl': `
39
39
  out vec2 mask_texCoords;
40
40
  `,
41
- 'vs:#main-end': `
41
+ 'vs:#main-end': `
42
42
  vec4 mask_common_position;
43
43
  if (mask_maskByInstance) {
44
44
  mask_common_position = project_position(vec4(geometry.worldPosition, 1.0));
@@ -47,10 +47,10 @@ out vec2 mask_texCoords;
47
47
  }
48
48
  mask_texCoords = mask_getCoords(mask_common_position);
49
49
  `,
50
- 'fs:#decl': `
50
+ 'fs:#decl': `
51
51
  in vec2 mask_texCoords;
52
52
  `,
53
- 'fs:#main-start': `
53
+ 'fs:#main-start': `
54
54
  if (mask_enabled) {
55
55
  bool mask = mask_isInBounds(mask_texCoords);
56
56
 
@@ -62,23 +62,20 @@ in vec2 mask_texCoords;
62
62
  }
63
63
  `
64
64
  };
65
-
66
- const getMaskUniforms = opts => {
67
- if (opts && 'maskMap' in opts) {
68
- return {
69
- mask_texture: opts.maskMap
70
- };
71
- }
72
-
73
- return {};
65
+ /* eslint-disable camelcase */
66
+ const getMaskUniforms = (opts) => {
67
+ if (opts && 'maskMap' in opts) {
68
+ return {
69
+ mask_texture: opts.maskMap
70
+ };
71
+ }
72
+ return {};
74
73
  };
75
-
76
74
  export default {
77
- name: 'mask',
78
- dependencies: [project],
79
- vs,
80
- fs,
81
- inject,
82
- getUniforms: getMaskUniforms
75
+ name: 'mask',
76
+ dependencies: [project],
77
+ vs,
78
+ fs,
79
+ inject,
80
+ getUniforms: getMaskUniforms
83
81
  };
84
- //# sourceMappingURL=shader-module.js.map
@@ -0,0 +1,111 @@
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 { LayerExtension, _mergeShaders as mergeShaders } from '@deck.gl/core';
21
+ import { vec3 } from '@math.gl/core';
22
+ import { dashShaders, offsetShaders } from "./shaders.glsl.js";
23
+ const defaultProps = {
24
+ getDashArray: { type: 'accessor', value: [0, 0] },
25
+ getOffset: { type: 'accessor', value: 0 },
26
+ dashJustified: false,
27
+ dashGapPickable: false
28
+ };
29
+ /** Adds selected features to the `PathLayer` and composite layers that render the `PathLayer`. */
30
+ export default class PathStyleExtension extends LayerExtension {
31
+ static { this.defaultProps = defaultProps; }
32
+ static { this.extensionName = 'PathStyleExtension'; }
33
+ constructor({ dash = false, offset = false, highPrecisionDash = false } = {}) {
34
+ super({ dash: dash || highPrecisionDash, offset, highPrecisionDash });
35
+ }
36
+ isEnabled(layer) {
37
+ return 'pathTesselator' in layer.state;
38
+ }
39
+ getShaders(extension) {
40
+ if (!extension.isEnabled(this)) {
41
+ return null;
42
+ }
43
+ // Merge shader injection
44
+ let result = {};
45
+ if (extension.opts.dash) {
46
+ result = mergeShaders(result, dashShaders);
47
+ }
48
+ if (extension.opts.offset) {
49
+ result = mergeShaders(result, offsetShaders);
50
+ }
51
+ return result;
52
+ }
53
+ initializeState(context, extension) {
54
+ const attributeManager = this.getAttributeManager();
55
+ if (!attributeManager || !extension.isEnabled(this)) {
56
+ // This extension only works with the PathLayer
57
+ return;
58
+ }
59
+ if (extension.opts.dash) {
60
+ attributeManager.addInstanced({
61
+ instanceDashArrays: { size: 2, accessor: 'getDashArray' },
62
+ instanceDashOffsets: extension.opts.highPrecisionDash
63
+ ? {
64
+ size: 1,
65
+ accessor: 'getPath',
66
+ transform: extension.getDashOffsets.bind(this)
67
+ }
68
+ : {
69
+ size: 1,
70
+ update: attribute => {
71
+ attribute.constant = true;
72
+ attribute.value = [0];
73
+ }
74
+ }
75
+ });
76
+ }
77
+ if (extension.opts.offset) {
78
+ attributeManager.addInstanced({
79
+ instanceOffsets: { size: 1, accessor: 'getOffset' }
80
+ });
81
+ }
82
+ }
83
+ updateState(params, extension) {
84
+ if (!extension.isEnabled(this)) {
85
+ return;
86
+ }
87
+ const uniforms = {};
88
+ if (extension.opts.dash) {
89
+ uniforms.dashAlignMode = this.props.dashJustified ? 1 : 0;
90
+ uniforms.dashGapPickable = Boolean(this.props.dashGapPickable);
91
+ }
92
+ this.state.model?.setUniforms(uniforms);
93
+ }
94
+ getDashOffsets(path) {
95
+ const result = [0];
96
+ const positionSize = this.props.positionFormat === 'XY' ? 2 : 3;
97
+ const isNested = Array.isArray(path[0]);
98
+ const geometrySize = isNested ? path.length : path.length / positionSize;
99
+ let p;
100
+ let prevP;
101
+ for (let i = 0; i < geometrySize - 1; i++) {
102
+ p = isNested ? path[i] : path.slice(i * positionSize, i * positionSize + positionSize);
103
+ p = this.projectPosition(p);
104
+ if (i > 0) {
105
+ result[i] = result[i - 1] + vec3.dist(prevP, p);
106
+ }
107
+ prevP = p;
108
+ }
109
+ return result;
110
+ }
111
+ }
@@ -1,23 +1,31 @@
1
1
  export const dashShaders = {
2
- inject: {
3
- 'vs:#decl': `
2
+ inject: {
3
+ 'vs:#decl': `
4
4
  in vec2 instanceDashArrays;
5
5
  in float instanceDashOffsets;
6
6
  out vec2 vDashArray;
7
7
  out float vDashOffset;
8
8
  `,
9
- 'vs:#main-end': `
9
+ 'vs:#main-end': `
10
10
  vDashArray = instanceDashArrays;
11
11
  vDashOffset = instanceDashOffsets / width.x;
12
12
  `,
13
- 'fs:#decl': `
13
+ 'fs:#decl': `
14
14
  uniform float dashAlignMode;
15
15
  uniform float capType;
16
16
  uniform bool dashGapPickable;
17
17
  in vec2 vDashArray;
18
18
  in float vDashOffset;
19
19
  `,
20
- 'fs:#main-start': `
20
+ // if given position is in the gap part of the dashed line
21
+ // dashArray.x: solid stroke length, relative to width
22
+ // dashArray.y: gap length, relative to width
23
+ // alignMode:
24
+ // 0 - no adjustment
25
+ // o---- ---- ---- ---- o---- -o---- ---- o
26
+ // 1 - stretch to fit, draw half dash at each end for nicer joints
27
+ // o-- ---- ---- ---- --o-- --o-- ---- --o
28
+ 'fs:#main-start': `
21
29
  float solidLength = vDashArray.x;
22
30
  float gapLength = vDashArray.y;
23
31
  float unitLength = solidLength + gapLength;
@@ -54,31 +62,30 @@ in float vDashOffset;
54
62
  }
55
63
  }
56
64
  `
57
- }
65
+ }
58
66
  };
59
67
  export const offsetShaders = {
60
- inject: {
61
- 'vs:#decl': `
68
+ inject: {
69
+ 'vs:#decl': `
62
70
  in float instanceOffsets;
63
71
  `,
64
- 'vs:DECKGL_FILTER_SIZE': `
72
+ 'vs:DECKGL_FILTER_SIZE': `
65
73
  float offsetWidth = abs(instanceOffsets * 2.0) + 1.0;
66
74
  size *= offsetWidth;
67
75
  `,
68
- 'vs:#main-end': `
76
+ 'vs:#main-end': `
69
77
  float offsetWidth = abs(instanceOffsets * 2.0) + 1.0;
70
78
  float offsetDir = sign(instanceOffsets);
71
79
  vPathPosition.x = (vPathPosition.x + offsetDir) * offsetWidth - offsetDir;
72
80
  vPathPosition.y *= offsetWidth;
73
81
  vPathLength *= offsetWidth;
74
82
  `,
75
- 'fs:#main-start': `
83
+ 'fs:#main-start': `
76
84
  float isInside;
77
85
  isInside = step(-1.0, vPathPosition.x) * step(vPathPosition.x, 1.0);
78
86
  if (isInside == 0.0) {
79
87
  discard;
80
88
  }
81
89
  `
82
- }
90
+ }
83
91
  };
84
- //# sourceMappingURL=shaders.glsl.js.map
@@ -0,0 +1,104 @@
1
+ import { joinLayerBounds, getRenderBounds, makeViewport } from "../utils/projection-utils.js";
2
+ import { createRenderTarget } from "./utils.js";
3
+ const MAP_MAX_SIZE = 2048;
4
+ /**
5
+ * Manages the lifecycle of the height map (a framebuffer that encodes elevation).
6
+ * One instance of height map is is shared across all layers. It is updated when the viewport changes
7
+ * or when some terrain source layer's data changes.
8
+ * During the draw call of any terrainDrawMode:offset layers,
9
+ * the vertex shader reads from this framebuffer to retrieve its z offset.
10
+ */
11
+ export class HeightMapBuilder {
12
+ static isSupported(device) {
13
+ return device.isTextureFormatRenderable('rgba32float');
14
+ }
15
+ constructor(device) {
16
+ /** Viewport used to draw into the texture */
17
+ this.renderViewport = null;
18
+ /** Bounds of the height map texture, in cartesian space */
19
+ this.bounds = null;
20
+ /** Last rendered layers */
21
+ this.layers = [];
22
+ /** Last layer.getBounds() */
23
+ this.layersBounds = [];
24
+ /** The union of layersBounds in cartesian space */
25
+ this.layersBoundsCommon = null;
26
+ this.lastViewport = null;
27
+ this.device = device;
28
+ }
29
+ /** Returns the height map framebuffer for read/write access.
30
+ * Returns null when the texture is invalid.
31
+ */
32
+ getRenderFramebuffer() {
33
+ if (!this.renderViewport) {
34
+ return null;
35
+ }
36
+ if (!this.fbo) {
37
+ this.fbo = createRenderTarget(this.device, { id: 'height-map', float: true });
38
+ }
39
+ return this.fbo;
40
+ }
41
+ /** Called every render cycle to check if the framebuffer needs update */
42
+ shouldUpdate({ layers, viewport }) {
43
+ const layersChanged = layers.length !== this.layers.length ||
44
+ layers.some((layer, i) =>
45
+ // Layer instance is updated
46
+ // Layer props might have changed
47
+ // Undetermined props could have an effect on the output geometry of a terrain source,
48
+ // for example getElevation+updateTriggers, elevationScale, modelMatrix
49
+ layer !== this.layers[i] ||
50
+ // Some prop is in transition
51
+ layer.props.transitions ||
52
+ // Layer's geometry bounds have changed
53
+ layer.getBounds() !== this.layersBounds[i]);
54
+ if (layersChanged) {
55
+ // Recalculate cached bounds
56
+ this.layers = layers;
57
+ this.layersBounds = layers.map(layer => layer.getBounds());
58
+ this.layersBoundsCommon = joinLayerBounds(layers, viewport);
59
+ }
60
+ const viewportChanged = !this.lastViewport || !viewport.equals(this.lastViewport);
61
+ if (!this.layersBoundsCommon) {
62
+ this.renderViewport = null;
63
+ }
64
+ else if (layersChanged || viewportChanged) {
65
+ const bounds = getRenderBounds(this.layersBoundsCommon, viewport);
66
+ if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {
67
+ this.renderViewport = null;
68
+ return false;
69
+ }
70
+ this.bounds = bounds;
71
+ this.lastViewport = viewport;
72
+ const scale = viewport.scale;
73
+ const pixelWidth = (bounds[2] - bounds[0]) * scale;
74
+ const pixelHeight = (bounds[3] - bounds[1]) * scale;
75
+ this.renderViewport =
76
+ pixelWidth > 0 || pixelHeight > 0
77
+ ? makeViewport({
78
+ // It's not important whether the geometry is visible in this viewport, because
79
+ // vertices will not use the standard project_to_clipspace in the DRAW_TO_HEIGHT_MAP shader
80
+ // However the viewport must have the same center and zoom as the screen viewport
81
+ // So that projection uniforms used for calculating z are the same
82
+ bounds: [
83
+ viewport.center[0] - 1,
84
+ viewport.center[1] - 1,
85
+ viewport.center[0] + 1,
86
+ viewport.center[1] + 1
87
+ ],
88
+ zoom: viewport.zoom,
89
+ width: Math.min(pixelWidth, MAP_MAX_SIZE),
90
+ height: Math.min(pixelHeight, MAP_MAX_SIZE),
91
+ viewport
92
+ })
93
+ : null;
94
+ return true;
95
+ }
96
+ return false;
97
+ }
98
+ delete() {
99
+ if (this.fbo) {
100
+ this.fbo.colorAttachments[0].delete();
101
+ this.fbo.delete();
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,139 @@
1
+ /* eslint-disable camelcase */
2
+ import { project } from '@deck.gl/core';
3
+ /** A model can have one of the following modes */
4
+ export const TERRAIN_MODE = {
5
+ NONE: 0,
6
+ /** A terrain layer rendering encoded ground elevation into the height map */
7
+ WRITE_HEIGHT_MAP: 1,
8
+ /** An offset layer reading encoded ground elevation from the height map */
9
+ USE_HEIGHT_MAP: 2,
10
+ /** A terrain layer rendering to screen, using the cover fbo overlaid with its own texture */
11
+ USE_COVER: 3,
12
+ /** A terrain layer rendering to screen, using the cover fbo as texture */
13
+ USE_COVER_ONLY: 4,
14
+ /** Draped layer is rendered into a texture, and never to screen */
15
+ SKIP: 5
16
+ };
17
+ const TERRAIN_MODE_CONSTANTS = Object.keys(TERRAIN_MODE)
18
+ .map(key => `const float TERRAIN_MODE_${key} = ${TERRAIN_MODE[key]}.0;`)
19
+ .join('\n');
20
+ // @ts-expect-error
21
+ export const terrainModule = {
22
+ name: 'terrain',
23
+ dependencies: [project],
24
+ inject: {
25
+ 'vs:#decl': `
26
+ uniform float terrain_mode;
27
+ uniform sampler2D terrain_map;
28
+ uniform vec4 terrain_bounds;
29
+ out vec3 commonPos;
30
+ ${TERRAIN_MODE_CONSTANTS}
31
+ `,
32
+ 'vs:#main-start': `
33
+ if (terrain_mode == TERRAIN_MODE_SKIP) {
34
+ gl_Position = vec4(0.0);
35
+ return;
36
+ }
37
+ `,
38
+ 'vs:DECKGL_FILTER_GL_POSITION': `
39
+ commonPos = geometry.position.xyz;
40
+ if (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {
41
+ vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;
42
+ position = vec4(texCoords * 2.0 - 1.0, 0.0, 1.0);
43
+ commonPos.z += project_uCommonOrigin.z;
44
+ }
45
+ if (terrain_mode == TERRAIN_MODE_USE_HEIGHT_MAP) {
46
+ vec3 anchor = geometry.worldPosition;
47
+ anchor.z = 0.0;
48
+ vec3 anchorCommon = project_position(anchor);
49
+ vec2 texCoords = (anchorCommon.xy - terrain_bounds.xy) / terrain_bounds.zw;
50
+ if (texCoords.x >= 0.0 && texCoords.y >= 0.0 && texCoords.x <= 1.0 && texCoords.y <= 1.0) {
51
+ float terrainZ = texture(terrain_map, texCoords).r;
52
+ geometry.position.z += terrainZ;
53
+ position = project_common_position_to_clipspace(geometry.position);
54
+ }
55
+ }
56
+ `,
57
+ 'fs:#decl': `
58
+ uniform float terrain_mode;
59
+ uniform sampler2D terrain_map;
60
+ uniform vec4 terrain_bounds;
61
+ in vec3 commonPos;
62
+ ${TERRAIN_MODE_CONSTANTS}
63
+ `,
64
+ 'fs:#main-start': `
65
+ if (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {
66
+ fragColor = vec4(commonPos.z, 0.0, 0.0, 1.0);
67
+ return;
68
+ }
69
+ `,
70
+ 'fs:DECKGL_FILTER_COLOR': `
71
+ if ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY)) {
72
+ vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;
73
+ vec4 pixel = texture(terrain_map, texCoords);
74
+ if (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY) {
75
+ color = pixel;
76
+ } else {
77
+ // pixel is premultiplied
78
+ color = pixel + color * (1.0 - pixel.a);
79
+ }
80
+ return;
81
+ }
82
+ `
83
+ },
84
+ // eslint-disable-next-line complexity
85
+ getUniforms: (opts = {}, uniforms) => {
86
+ if ('dummyHeightMap' in opts) {
87
+ const { drawToTerrainHeightMap, heightMap, heightMapBounds, dummyHeightMap, terrainCover, useTerrainHeightMap, terrainSkipRender } = opts;
88
+ const { project_uCommonOrigin } = uniforms;
89
+ let mode = terrainSkipRender ? TERRAIN_MODE.SKIP : TERRAIN_MODE.NONE;
90
+ // height map if case USE_HEIGHT_MAP, terrain cover if USE_COVER, otherwise empty
91
+ let sampler = dummyHeightMap;
92
+ // height map bounds if case USE_HEIGHT_MAP, terrain cover bounds if USE_COVER, otherwise null
93
+ let bounds = null;
94
+ if (drawToTerrainHeightMap) {
95
+ mode = TERRAIN_MODE.WRITE_HEIGHT_MAP;
96
+ bounds = heightMapBounds;
97
+ }
98
+ else if (useTerrainHeightMap && heightMap) {
99
+ mode = TERRAIN_MODE.USE_HEIGHT_MAP;
100
+ sampler = heightMap;
101
+ bounds = heightMapBounds;
102
+ }
103
+ else if (terrainCover) {
104
+ // This is a terrain layer
105
+ const isPicking = opts.picking?.isActive;
106
+ // @ts-expect-error
107
+ sampler = isPicking
108
+ ? terrainCover.getPickingFramebuffer()
109
+ : terrainCover.getRenderFramebuffer();
110
+ if (isPicking) {
111
+ // Never render the layer itself in picking pass
112
+ mode = TERRAIN_MODE.SKIP;
113
+ }
114
+ if (sampler) {
115
+ mode = mode === TERRAIN_MODE.SKIP ? TERRAIN_MODE.USE_COVER_ONLY : TERRAIN_MODE.USE_COVER;
116
+ bounds = terrainCover.bounds;
117
+ }
118
+ else {
119
+ sampler = dummyHeightMap;
120
+ }
121
+ }
122
+ /* eslint-disable camelcase */
123
+ return {
124
+ terrain_mode: mode,
125
+ terrain_map: sampler,
126
+ // Convert bounds to the common space, as [minX, minY, width, height]
127
+ terrain_bounds: bounds
128
+ ? [
129
+ bounds[0] - project_uCommonOrigin[0],
130
+ bounds[1] - project_uCommonOrigin[1],
131
+ bounds[2] - bounds[0],
132
+ bounds[3] - bounds[1]
133
+ ]
134
+ : [0, 0, 0, 0]
135
+ };
136
+ }
137
+ return null;
138
+ }
139
+ };