@deck.gl/extensions 8.9.0-alpha.5 → 8.9.0-beta.2
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/dist.dev.js +3688 -14538
- package/dist/es5/brushing/brushing.js +0 -8
- package/dist/es5/brushing/brushing.js.map +1 -1
- package/dist/es5/clip/clip.js +5 -5
- package/dist/es5/clip/clip.js.map +1 -1
- package/dist/es5/collide/collide-effect.js +286 -0
- package/dist/es5/collide/collide-effect.js.map +1 -0
- package/dist/es5/collide/collide-pass.js +80 -0
- package/dist/es5/collide/collide-pass.js.map +1 -0
- package/dist/es5/collide/collide.js +116 -0
- package/dist/es5/collide/collide.js.map +1 -0
- package/dist/es5/collide/shader-module.js +39 -0
- package/dist/es5/collide/shader-module.js.map +1 -0
- package/dist/es5/common/projection-utils.js +164 -0
- package/dist/es5/common/projection-utils.js.map +1 -0
- package/dist/es5/data-filter/shader-module.js +1 -0
- package/dist/es5/data-filter/shader-module.js.map +1 -1
- package/dist/es5/fill-style/fill-style.js +16 -125
- package/dist/es5/fill-style/fill-style.js.map +1 -1
- package/dist/es5/fill-style/shaders.glsl.js +6 -8
- package/dist/es5/fill-style/shaders.glsl.js.map +1 -1
- package/dist/es5/fp64/project64.glsl.js +1 -1
- package/dist/es5/index.js +16 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/mask/mask-effect.js +280 -0
- package/dist/es5/mask/mask-effect.js.map +1 -0
- package/dist/es5/mask/mask-pass.js +106 -0
- package/dist/es5/mask/mask-pass.js.map +1 -0
- package/dist/es5/mask/mask.js +17 -4
- package/dist/es5/mask/mask.js.map +1 -1
- package/dist/es5/mask/shader-module.js +1 -1
- package/dist/es5/mask/shader-module.js.map +1 -1
- package/dist/es5/mask/utils.js +136 -0
- package/dist/es5/mask/utils.js.map +1 -0
- package/dist/es5/path-style/shaders.glsl.js +1 -1
- package/dist/es5/terrain/height-map-builder.js +116 -0
- package/dist/es5/terrain/height-map-builder.js.map +1 -0
- package/dist/es5/terrain/shader-module.js +84 -0
- package/dist/es5/terrain/shader-module.js.map +1 -0
- package/dist/es5/terrain/terrain-cover.js +259 -0
- package/dist/es5/terrain/terrain-cover.js.map +1 -0
- package/dist/es5/terrain/terrain-effect.js +337 -0
- package/dist/es5/terrain/terrain-effect.js.map +1 -0
- package/dist/es5/terrain/terrain-pass.js +122 -0
- package/dist/es5/terrain/terrain-pass.js.map +1 -0
- package/dist/es5/terrain/terrain-picking-pass.js +130 -0
- package/dist/es5/terrain/terrain-picking-pass.js.map +1 -0
- package/dist/es5/terrain/terrain.js +101 -0
- package/dist/es5/terrain/terrain.js.map +1 -0
- package/dist/es5/terrain/utils.js +32 -0
- package/dist/es5/terrain/utils.js.map +1 -0
- package/dist/es5/utils/debug.js +71 -0
- package/dist/es5/utils/debug.js.map +1 -0
- package/dist/esm/brushing/brushing.js +0 -7
- package/dist/esm/brushing/brushing.js.map +1 -1
- package/dist/esm/clip/clip.js +5 -4
- package/dist/esm/clip/clip.js.map +1 -1
- package/dist/esm/collide/collide-effect.js +251 -0
- package/dist/esm/collide/collide-effect.js.map +1 -0
- package/dist/esm/collide/collide-pass.js +30 -0
- package/dist/esm/collide/collide-pass.js.map +1 -0
- package/dist/esm/collide/collide.js +78 -0
- package/dist/esm/collide/collide.js.map +1 -0
- package/dist/esm/collide/shader-module.js +32 -0
- package/dist/esm/collide/shader-module.js.map +1 -0
- package/dist/esm/common/projection-utils.js +130 -0
- package/dist/esm/common/projection-utils.js.map +1 -0
- package/dist/esm/data-filter/shader-module.js +1 -0
- package/dist/esm/data-filter/shader-module.js.map +1 -1
- package/dist/esm/fill-style/fill-style.js +20 -72
- package/dist/esm/fill-style/fill-style.js.map +1 -1
- package/dist/esm/fill-style/shaders.glsl.js +5 -7
- package/dist/esm/fill-style/shaders.glsl.js.map +1 -1
- package/dist/esm/fp64/project64.glsl.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mask/mask-effect.js +233 -0
- package/dist/esm/mask/mask-effect.js.map +1 -0
- package/dist/esm/mask/mask-pass.js +62 -0
- package/dist/esm/mask/mask-pass.js.map +1 -0
- package/dist/esm/mask/mask.js +14 -3
- package/dist/esm/mask/mask.js.map +1 -1
- package/dist/esm/mask/shader-module.js +1 -1
- package/dist/esm/mask/shader-module.js.map +1 -1
- package/dist/esm/mask/utils.js +109 -0
- package/dist/esm/mask/utils.js.map +1 -0
- package/dist/esm/path-style/shaders.glsl.js +1 -1
- package/dist/esm/terrain/height-map-builder.js +92 -0
- package/dist/esm/terrain/height-map-builder.js.map +1 -0
- package/dist/esm/terrain/shader-module.js +73 -0
- package/dist/esm/terrain/shader-module.js.map +1 -0
- package/dist/esm/terrain/terrain-cover.js +219 -0
- package/dist/esm/terrain/terrain-cover.js.map +1 -0
- package/dist/esm/terrain/terrain-effect.js +230 -0
- package/dist/esm/terrain/terrain-effect.js.map +1 -0
- package/dist/esm/terrain/terrain-pass.js +69 -0
- package/dist/esm/terrain/terrain-pass.js.map +1 -0
- package/dist/esm/terrain/terrain-picking-pass.js +75 -0
- package/dist/esm/terrain/terrain-picking-pass.js.map +1 -0
- package/dist/esm/terrain/terrain.js +62 -0
- package/dist/esm/terrain/terrain.js.map +1 -0
- package/dist/esm/terrain/utils.js +21 -0
- package/dist/esm/terrain/utils.js.map +1 -0
- package/dist/esm/utils/debug.js +61 -0
- package/dist/esm/utils/debug.js.map +1 -0
- package/dist.min.js +1359 -1
- package/package.json +6 -4
- package/src/brushing/brushing.ts +0 -11
- package/src/clip/clip.ts +7 -6
- package/src/collide/collide-effect.ts +258 -0
- package/src/collide/collide-pass.ts +35 -0
- package/src/collide/collide.ts +79 -0
- package/src/collide/shader-module.ts +113 -0
- package/src/common/projection-utils.ts +187 -0
- package/src/data-filter/shader-module.ts +7 -1
- package/src/fill-style/fill-style.ts +15 -53
- package/src/fill-style/shaders.glsl.ts +6 -7
- package/src/index.ts +4 -0
- package/src/mask/mask-effect.ts +255 -0
- package/src/mask/mask-pass.ts +67 -0
- package/src/mask/mask.ts +17 -7
- package/src/mask/shader-module.ts +7 -1
- package/src/mask/utils.ts +148 -0
- package/src/terrain/height-map-builder.ts +120 -0
- package/src/terrain/shader-module.ts +161 -0
- package/src/terrain/terrain-cover.ts +225 -0
- package/src/terrain/terrain-effect.ts +222 -0
- package/src/terrain/terrain-pass.ts +86 -0
- package/src/terrain/terrain-picking-pass.ts +87 -0
- package/src/terrain/terrain.ts +74 -0
- package/src/terrain/utils.ts +29 -0
- package/src/utils/debug.ts +59 -0
- package/typed/brushing/brushing.d.ts +0 -1
- package/typed/brushing/brushing.d.ts.map +1 -1
- package/typed/brushing/brushing.js +83 -0
- package/typed/brushing/shader-module.js +116 -0
- package/typed/clip/clip.d.ts +5 -2
- package/typed/clip/clip.d.ts.map +1 -1
- package/typed/clip/clip.js +114 -0
- package/typed/collide/collide-effect.d.ts +28 -0
- package/typed/collide/collide-effect.d.ts.map +1 -0
- package/typed/collide/collide-pass.d.ts +14 -0
- package/typed/collide/collide-pass.d.ts.map +1 -0
- package/typed/collide/collide.d.ts +41 -0
- package/typed/collide/collide.d.ts.map +1 -0
- package/typed/collide/shader-module.d.ts +4 -0
- package/typed/collide/shader-module.d.ts.map +1 -0
- package/typed/common/projection-utils.d.ts +27 -0
- package/typed/common/projection-utils.d.ts.map +1 -0
- package/typed/data-filter/aggregator.js +98 -0
- package/typed/data-filter/data-filter.js +159 -0
- package/typed/data-filter/shader-module.d.ts.map +1 -1
- package/typed/data-filter/shader-module.js +152 -0
- package/typed/fill-style/fill-style.d.ts +14 -5
- package/typed/fill-style/fill-style.d.ts.map +1 -1
- package/typed/fill-style/fill-style.js +152 -0
- package/typed/fill-style/shaders.glsl.d.ts.map +1 -1
- package/typed/fill-style/shaders.glsl.js +95 -0
- package/typed/fp64/fp64.js +34 -0
- package/typed/fp64/project64.glsl.js +100 -0
- package/typed/fp64/project64.js +50 -0
- package/typed/index.d.ts +4 -0
- package/typed/index.d.ts.map +1 -1
- package/typed/index.js +9 -0
- package/typed/mask/mask-effect.d.ts +42 -0
- package/typed/mask/mask-effect.d.ts.map +1 -0
- package/typed/mask/mask-pass.d.ts +19 -0
- package/typed/mask/mask-pass.d.ts.map +1 -0
- package/typed/mask/mask.d.ts +9 -3
- package/typed/mask/mask.d.ts.map +1 -1
- package/typed/mask/mask.js +48 -0
- package/typed/mask/shader-module.d.ts.map +1 -1
- package/typed/mask/shader-module.js +73 -0
- package/typed/mask/utils.d.ts +13 -0
- package/typed/mask/utils.d.ts.map +1 -0
- package/typed/path-style/path-style.js +107 -0
- package/typed/path-style/shaders.glsl.js +93 -0
- package/typed/terrain/height-map-builder.d.ts +38 -0
- package/typed/terrain/height-map-builder.d.ts.map +1 -0
- package/typed/terrain/height-map.d.ts +27 -0
- package/typed/terrain/height-map.d.ts.map +1 -0
- package/typed/terrain/shader-module-offset.d.ts +4 -0
- package/typed/terrain/shader-module-offset.d.ts.map +1 -0
- package/typed/terrain/shader-module-source.d.ts +4 -0
- package/typed/terrain/shader-module-source.d.ts.map +1 -0
- package/typed/terrain/shader-module.d.ts +31 -0
- package/typed/terrain/shader-module.d.ts.map +1 -0
- package/typed/terrain/terrain-cover.d.ts +46 -0
- package/typed/terrain/terrain-cover.d.ts.map +1 -0
- package/typed/terrain/terrain-effect.d.ts +29 -0
- package/typed/terrain/terrain-effect.d.ts.map +1 -0
- package/typed/terrain/terrain-pass.d.ts +11 -0
- package/typed/terrain/terrain-pass.d.ts.map +1 -0
- package/typed/terrain/terrain-picking-pass.d.ts +19 -0
- package/typed/terrain/terrain-picking-pass.d.ts.map +1 -0
- package/typed/terrain/terrain.d.ts +21 -0
- package/typed/terrain/terrain.d.ts.map +1 -0
- package/typed/terrain/utils.d.ts +5 -0
- package/typed/terrain/utils.d.ts.map +1 -0
- package/typed/utils/debug.d.ts +6 -0
- package/typed/utils/debug.d.ts.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mask/shader-module.ts"],"names":["vs","fs","inject","getMaskUniforms","opts","mask_texture","maskMap","name","dependencies","project","getUniforms"],"mappings":";;;;;;;AAAA;;AAIA,IAAMA,EAAE,4LAAR;AAQA,IAAMC,EAAE,
|
|
1
|
+
{"version":3,"sources":["../../../src/mask/shader-module.ts"],"names":["vs","fs","inject","getMaskUniforms","opts","mask_texture","maskMap","name","dependencies","project","getUniforms"],"mappings":";;;;;;;AAAA;;AAIA,IAAMA,EAAE,4LAAR;AAQA,IAAMC,EAAE,gpBAAR;AA6BA,IAAMC,MAAM,GAAG;AACb,gDADa;AAIb,oSAJa;AAab,gDAba;AAgBb;AAhBa,CAAf;;AAkCA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAACC,IAAD,EAAyD;AAC/E,MAAIA,IAAI,IAAI,aAAaA,IAAzB,EAA+B;AAC7B,WAAO;AACLC,MAAAA,YAAY,EAAED,IAAI,CAACE;AADd,KAAP;AAGD;;AACD,SAAO,EAAP;AACD,CAPD;;eASe;AACbC,EAAAA,IAAI,EAAE,MADO;AAEbC,EAAAA,YAAY,EAAE,CAACC,aAAD,CAFD;AAGbT,EAAAA,EAAE,EAAFA,EAHa;AAIbC,EAAAA,EAAE,EAAFA,EAJa;AAKbC,EAAAA,MAAM,EAANA,MALa;AAMbQ,EAAAA,WAAW,EAAEP;AANA,C","sourcesContent":["import {project} from '@deck.gl/core';\nimport type {_ShaderModule as ShaderModule} from '@deck.gl/core';\nimport type {Texture2D} from '@luma.gl/webgl';\n\nconst vs = `\nuniform vec4 mask_bounds;\nuniform bool mask_maskByInstance;\nvec2 mask_getCoords(vec4 position) {\n return (position.xy - mask_bounds.xy) / (mask_bounds.zw - mask_bounds.xy);\n}\n`;\n\nconst fs = `\nuniform sampler2D mask_texture;\nuniform int mask_channel;\nuniform bool mask_enabled;\nuniform bool mask_inverted;\nbool mask_isInBounds(vec2 texCoords) {\n if (!mask_enabled) {\n return true;\n }\n vec4 maskColor = texture2D(mask_texture, texCoords);\n float maskValue = 1.0;\n if (mask_channel == 0) {\n maskValue = maskColor.r;\n } else if (mask_channel == 1) {\n maskValue = maskColor.g;\n } else if (mask_channel == 2) {\n maskValue = maskColor.b;\n } else if (mask_channel == 3) {\n maskValue = maskColor.a;\n }\n\n if (mask_inverted) {\n return maskValue >= 0.5;\n } else {\n return maskValue < 0.5;\n }\n}\n`;\n\nconst inject = {\n 'vs:#decl': `\nvarying vec2 mask_texCoords;\n`,\n 'vs:#main-end': `\n vec4 mask_common_position;\n if (mask_maskByInstance) {\n mask_common_position = project_position(vec4(geometry.worldPosition, 1.0));\n } else {\n mask_common_position = geometry.position;\n }\n mask_texCoords = mask_getCoords(mask_common_position);\n`,\n 'fs:#decl': `\nvarying vec2 mask_texCoords;\n`,\n 'fs:#main-start': `\n if (mask_enabled) {\n bool mask = mask_isInBounds(mask_texCoords);\n\n // Debug: show extent of render target\n // gl_FragColor = vec4(mask_texCoords, 0.0, 1.0);\n gl_FragColor = texture2D(mask_texture, mask_texCoords);\n\n if (!mask) discard;\n }\n`\n};\n\ntype MaskModuleSettings = {\n maskMap?: Texture2D;\n};\n\n/* eslint-disable camelcase */\nconst getMaskUniforms = (opts?: MaskModuleSettings | {}): Record<string, any> => {\n if (opts && 'maskMap' in opts) {\n return {\n mask_texture: opts.maskMap\n };\n }\n return {};\n};\n\nexport default {\n name: 'mask',\n dependencies: [project],\n vs,\n fs,\n inject,\n getUniforms: getMaskUniforms\n} as ShaderModule<MaskModuleSettings>;\n"],"file":"shader-module.js"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getMaskBounds = getMaskBounds;
|
|
7
|
+
exports.getMaskViewport = getMaskViewport;
|
|
8
|
+
|
|
9
|
+
var _core = require("@deck.gl/core");
|
|
10
|
+
|
|
11
|
+
var _webMercator = require("@math.gl/web-mercator");
|
|
12
|
+
|
|
13
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
14
|
+
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
+
|
|
19
|
+
function getMaskBounds(_ref) {
|
|
20
|
+
var layers = _ref.layers,
|
|
21
|
+
viewport = _ref.viewport;
|
|
22
|
+
var bounds = null;
|
|
23
|
+
|
|
24
|
+
var _iterator = _createForOfIteratorHelper(layers),
|
|
25
|
+
_step;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
29
|
+
var layer = _step.value;
|
|
30
|
+
var subLayerBounds = layer.getBounds();
|
|
31
|
+
|
|
32
|
+
if (subLayerBounds) {
|
|
33
|
+
if (bounds) {
|
|
34
|
+
bounds[0] = Math.min(bounds[0], subLayerBounds[0][0]);
|
|
35
|
+
bounds[1] = Math.min(bounds[1], subLayerBounds[0][1]);
|
|
36
|
+
bounds[2] = Math.max(bounds[2], subLayerBounds[1][0]);
|
|
37
|
+
bounds[3] = Math.max(bounds[3], subLayerBounds[1][1]);
|
|
38
|
+
} else {
|
|
39
|
+
bounds = [subLayerBounds[0][0], subLayerBounds[0][1], subLayerBounds[1][0], subLayerBounds[1][1]];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
_iterator.e(err);
|
|
45
|
+
} finally {
|
|
46
|
+
_iterator.f();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var viewportBounds = viewport.getBounds();
|
|
50
|
+
|
|
51
|
+
if (!bounds) {
|
|
52
|
+
return viewportBounds;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var paddedBounds = _doubleBounds(viewportBounds);
|
|
56
|
+
|
|
57
|
+
if (bounds[2] - bounds[0] < paddedBounds[2] - paddedBounds[0] || bounds[3] - bounds[1] < paddedBounds[3] - paddedBounds[1]) {
|
|
58
|
+
return bounds;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
bounds[0] = Math.max(bounds[0], paddedBounds[0]);
|
|
62
|
+
bounds[1] = Math.max(bounds[1], paddedBounds[1]);
|
|
63
|
+
bounds[2] = Math.min(bounds[2], paddedBounds[2]);
|
|
64
|
+
bounds[3] = Math.min(bounds[3], paddedBounds[3]);
|
|
65
|
+
return bounds;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getMaskViewport(_ref2) {
|
|
69
|
+
var bounds = _ref2.bounds,
|
|
70
|
+
viewport = _ref2.viewport,
|
|
71
|
+
width = _ref2.width,
|
|
72
|
+
height = _ref2.height;
|
|
73
|
+
|
|
74
|
+
if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (viewport.resolution !== undefined) {
|
|
79
|
+
_core.log.warn('MaskExtension is not supported in GlobeView')();
|
|
80
|
+
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var padding = 1;
|
|
85
|
+
width -= padding * 2;
|
|
86
|
+
height -= padding * 2;
|
|
87
|
+
|
|
88
|
+
if (viewport.isGeospatial) {
|
|
89
|
+
var _fitBounds = (0, _webMercator.fitBounds)({
|
|
90
|
+
width: width,
|
|
91
|
+
height: height,
|
|
92
|
+
bounds: [[bounds[0], bounds[1]], [bounds[2], bounds[3]]],
|
|
93
|
+
maxZoom: 20
|
|
94
|
+
}),
|
|
95
|
+
longitude = _fitBounds.longitude,
|
|
96
|
+
latitude = _fitBounds.latitude,
|
|
97
|
+
zoom = _fitBounds.zoom;
|
|
98
|
+
|
|
99
|
+
return new _core.WebMercatorViewport({
|
|
100
|
+
longitude: longitude,
|
|
101
|
+
latitude: latitude,
|
|
102
|
+
zoom: zoom,
|
|
103
|
+
x: padding,
|
|
104
|
+
y: padding,
|
|
105
|
+
width: width,
|
|
106
|
+
height: height
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var center = [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2, 0];
|
|
111
|
+
var scale = Math.min(1048576, width / (bounds[2] - bounds[0]), height / (bounds[3] - bounds[1]));
|
|
112
|
+
return new _core.OrthographicView({
|
|
113
|
+
x: padding,
|
|
114
|
+
y: padding
|
|
115
|
+
}).makeViewport({
|
|
116
|
+
width: width,
|
|
117
|
+
height: height,
|
|
118
|
+
viewState: {
|
|
119
|
+
target: center,
|
|
120
|
+
zoom: Math.log2(scale)
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function _doubleBounds(bounds) {
|
|
126
|
+
var size = {
|
|
127
|
+
x: bounds[2] - bounds[0],
|
|
128
|
+
y: bounds[3] - bounds[1]
|
|
129
|
+
};
|
|
130
|
+
var center = {
|
|
131
|
+
x: bounds[0] + 0.5 * size.x,
|
|
132
|
+
y: bounds[1] + 0.5 * size.y
|
|
133
|
+
};
|
|
134
|
+
return [center.x - size.x, center.y - size.y, center.x + size.x, center.y + size.y];
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mask/utils.ts"],"names":["getMaskBounds","layers","viewport","bounds","layer","subLayerBounds","getBounds","Math","min","max","viewportBounds","paddedBounds","_doubleBounds","getMaskViewport","width","height","resolution","undefined","log","warn","padding","isGeospatial","maxZoom","longitude","latitude","zoom","WebMercatorViewport","x","y","center","scale","OrthographicView","makeViewport","viewState","target","log2","size"],"mappings":";;;;;;;;AAAA;;AACA;;;;;;;;AASO,SAASA,aAAT,OAMQ;AAAA,MALbC,MAKa,QALbA,MAKa;AAAA,MAJbC,QAIa,QAJbA,QAIa;AAEb,MAAIC,MAAyB,GAAG,IAAhC;;AAFa,6CAGOF,MAHP;AAAA;;AAAA;AAGb,wDAA4B;AAAA,UAAjBG,KAAiB;AAC1B,UAAMC,cAAc,GAAGD,KAAK,CAACE,SAAN,EAAvB;;AACA,UAAID,cAAJ,EAAoB;AAClB,YAAIF,MAAJ,EAAY;AACVA,UAAAA,MAAM,CAAC,CAAD,CAAN,GAAYI,IAAI,CAACC,GAAL,CAASL,MAAM,CAAC,CAAD,CAAf,EAAoBE,cAAc,CAAC,CAAD,CAAd,CAAkB,CAAlB,CAApB,CAAZ;AACAF,UAAAA,MAAM,CAAC,CAAD,CAAN,GAAYI,IAAI,CAACC,GAAL,CAASL,MAAM,CAAC,CAAD,CAAf,EAAoBE,cAAc,CAAC,CAAD,CAAd,CAAkB,CAAlB,CAApB,CAAZ;AACAF,UAAAA,MAAM,CAAC,CAAD,CAAN,GAAYI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AHG,GAHT,CAAP;AAWD;;AAED,SAASlB,aAAT,CAAuBT,MAAvB,EAAuD;AACrD,MAAMiC,IAAI,GAAG;AACXT,IAAAA,CAAC,EAAExB,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CADV;AAEXyB,IAAAA,CAAC,EAAEzB,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD;AAFV,GAAb;AAIA,MAAM0B,MAAM,GAAG;AACbF,IAAAA,CAAC,EAAExB,MAAM,CAAC,CAAD,CAAN,GAAY,MAAMiC,IAAI,CAACT,CADb;AAEbC,IAAAA,CAAC,EAAEzB,MAAM,CAAC,CAAD,CAAN,GAAY,MAAMiC,IAAI,CAACR;AAFb,GAAf;AAIA,SAAO,CAACC,MAAM,CAACF,CAAP,GAAWS,IAAI,CAACT,CAAjB,EAAoBE,MAAM,CAACD,CAAP,GAAWQ,IAAI,CAACR,CAApC,EAAuCC,MAAM,CAACF,CAAP,GAAWS,IAAI,CAACT,CAAvD,EAA0DE,MAAM,CAACD,CAAP,GAAWQ,IAAI,CAACR,CAA1E,CAAP;AACD","sourcesContent":["import {OrthographicView, WebMercatorViewport, log, Layer, Viewport} from '@deck.gl/core';\nimport {fitBounds} from '@math.gl/web-mercator';\n\nexport type MaskBounds = [number, number, number, number];\n\n/*\n * Compute the bounds of the mask in world space, such that it covers an\n * area currently visible (extended by a buffer) or the area of the masking\n * data, whichever is smaller\n */\nexport function getMaskBounds({\n layers,\n viewport\n}: {\n layers: Layer[];\n viewport: Viewport;\n}): MaskBounds {\n // Join the bounds of layer data\n let bounds: MaskBounds | null = null;\n for (const layer of layers) {\n const subLayerBounds = layer.getBounds();\n if (subLayerBounds) {\n if (bounds) {\n bounds[0] = Math.min(bounds[0], subLayerBounds[0][0]);\n bounds[1] = Math.min(bounds[1], subLayerBounds[0][1]);\n bounds[2] = Math.max(bounds[2], subLayerBounds[1][0]);\n bounds[3] = Math.max(bounds[3], subLayerBounds[1][1]);\n } else {\n bounds = [\n subLayerBounds[0][0],\n subLayerBounds[0][1],\n subLayerBounds[1][0],\n subLayerBounds[1][1]\n ];\n }\n }\n }\n const viewportBounds = viewport.getBounds();\n if (!bounds) {\n return viewportBounds;\n }\n\n // Expand viewport bounds by 2X. Heurestically chosen to avoid masking\n // errors when mask is partially out of view\n const paddedBounds = _doubleBounds(viewportBounds);\n\n // When bounds of the mask are smaller than the viewport bounds simply use\n // mask bounds, so as to maximize resolution & avoid mask rerenders\n if (\n bounds[2] - bounds[0] < paddedBounds[2] - paddedBounds[0] ||\n bounds[3] - bounds[1] < paddedBounds[3] - paddedBounds[1]\n ) {\n return bounds;\n }\n\n // As viewport shrinks, to avoid pixelation along mask edges\n // we need to reduce the bounds and only render the visible portion\n // of the mask.\n // We pad the viewport bounds to capture the section\n // of the mask just outside the viewport to correctly maskByInstance.\n // Intersect mask & padded viewport bounds\n bounds[0] = Math.max(bounds[0], paddedBounds[0]);\n bounds[1] = Math.max(bounds[1], paddedBounds[1]);\n bounds[2] = Math.min(bounds[2], paddedBounds[2]);\n bounds[3] = Math.min(bounds[3], paddedBounds[3]);\n return bounds;\n}\n\n/*\n * Compute viewport to render the mask into, covering the given bounds\n */\nexport function getMaskViewport({\n bounds,\n viewport,\n width,\n height\n}: {\n bounds: MaskBounds;\n viewport: Viewport;\n width: number;\n height: number;\n}): Viewport | null {\n if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {\n return null;\n }\n\n if (viewport.resolution !== undefined) {\n log.warn('MaskExtension is not supported in GlobeView')();\n return null;\n }\n\n // Single pixel border to prevent mask bleeding at edge of texture\n const padding = 1;\n width -= padding * 2;\n height -= padding * 2;\n\n if (viewport.isGeospatial) {\n const {longitude, latitude, zoom} = fitBounds({\n width,\n height,\n bounds: [\n [bounds[0], bounds[1]],\n [bounds[2], bounds[3]]\n ],\n maxZoom: 20\n });\n return new WebMercatorViewport({\n longitude,\n latitude,\n zoom,\n x: padding,\n y: padding,\n width,\n height\n });\n }\n\n const center = [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2, 0];\n const scale = Math.min(\n 1048576, // maxZoom of 20: Math.pow(2, 20) = 1048576\n width / (bounds[2] - bounds[0]),\n height / (bounds[3] - bounds[1])\n );\n\n return new OrthographicView({\n x: padding,\n y: padding\n }).makeViewport({\n width,\n height,\n viewState: {\n target: center,\n zoom: Math.log2(scale)\n }\n });\n}\n\nfunction _doubleBounds(bounds: MaskBounds): MaskBounds {\n const size = {\n x: bounds[2] - bounds[0],\n y: bounds[3] - bounds[1]\n };\n const center = {\n x: bounds[0] + 0.5 * size.x,\n y: bounds[1] + 0.5 * size.y\n };\n return [center.x - size.x, center.y - size.y, center.x + size.x, center.y + size.y];\n}\n"],"file":"utils.js"}
|
|
@@ -9,7 +9,7 @@ var dashShaders = {
|
|
|
9
9
|
'vs:#decl': "\nattribute vec2 instanceDashArrays;\nattribute float instanceDashOffsets;\nvarying vec2 vDashArray;\nvarying float vDashOffset;\n",
|
|
10
10
|
'vs:#main-end': "\nvDashArray = instanceDashArrays;\nvDashOffset = instanceDashOffsets / width.x;\n",
|
|
11
11
|
'fs:#decl': "\nuniform float dashAlignMode;\nuniform float capType;\nuniform bool dashGapPickable;\nvarying vec2 vDashArray;\nvarying float vDashOffset;\n\nfloat round(float x) {\n return floor(x + 0.5);\n}\n",
|
|
12
|
-
'fs:#main-start': "\n float solidLength = vDashArray.x;\n float gapLength = vDashArray.y;\n float unitLength = solidLength + gapLength;\n\n float offset;\n\n if (unitLength > 0.0) {\n if (dashAlignMode == 0.0) {\n offset = vDashOffset;\n } else {\n unitLength = vPathLength / round(vPathLength / unitLength);\n offset = solidLength / 2.0;\n }\n\n float unitOffset = mod(clamp(vPathPosition.y, 0.0, vPathLength) + offset, unitLength);\n\n if (gapLength > 0.0 && unitOffset > solidLength) {\n if (capType <= 0.5) {\n if (!(dashGapPickable && picking_uActive)) {\n discard;\n }\n } else {\n
|
|
12
|
+
'fs:#main-start': "\n float solidLength = vDashArray.x;\n float gapLength = vDashArray.y;\n float unitLength = solidLength + gapLength;\n\n float offset;\n\n if (unitLength > 0.0) {\n if (dashAlignMode == 0.0) {\n offset = vDashOffset;\n } else {\n unitLength = vPathLength / round(vPathLength / unitLength);\n offset = solidLength / 2.0;\n }\n\n float unitOffset = mod(clamp(vPathPosition.y, 0.0, vPathLength) + offset, unitLength);\n\n if (gapLength > 0.0 && unitOffset > solidLength) {\n if (capType <= 0.5) {\n if (!(dashGapPickable && picking_uActive)) {\n discard;\n }\n } else {\n float distToEnd = length(vec2(\n min(unitOffset - solidLength, unitLength - unitOffset),\n vPathPosition.x\n ));\n if (distToEnd > 1.0) {\n if (!(dashGapPickable && picking_uActive)) {\n discard;\n }\n }\n }\n }\n }\n"
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
exports.dashShaders = dashShaders;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.HeightMapBuilder = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _core = require("@luma.gl/core");
|
|
17
|
+
|
|
18
|
+
var _projectionUtils = require("../common/projection-utils");
|
|
19
|
+
|
|
20
|
+
var _utils = require("./utils");
|
|
21
|
+
|
|
22
|
+
var MAP_MAX_SIZE = 2048;
|
|
23
|
+
|
|
24
|
+
var HeightMapBuilder = function () {
|
|
25
|
+
function HeightMapBuilder(gl) {
|
|
26
|
+
(0, _classCallCheck2.default)(this, HeightMapBuilder);
|
|
27
|
+
(0, _defineProperty2.default)(this, "renderViewport", null);
|
|
28
|
+
(0, _defineProperty2.default)(this, "bounds", null);
|
|
29
|
+
(0, _defineProperty2.default)(this, "fbo", void 0);
|
|
30
|
+
(0, _defineProperty2.default)(this, "gl", void 0);
|
|
31
|
+
(0, _defineProperty2.default)(this, "layers", []);
|
|
32
|
+
(0, _defineProperty2.default)(this, "layersBounds", []);
|
|
33
|
+
(0, _defineProperty2.default)(this, "layersBoundsCommon", null);
|
|
34
|
+
(0, _defineProperty2.default)(this, "lastViewport", null);
|
|
35
|
+
this.gl = gl;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
(0, _createClass2.default)(HeightMapBuilder, [{
|
|
39
|
+
key: "getRenderFramebuffer",
|
|
40
|
+
value: function getRenderFramebuffer() {
|
|
41
|
+
if (!this.renderViewport) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!this.fbo) {
|
|
46
|
+
this.fbo = (0, _utils.createRenderTarget)(this.gl, {
|
|
47
|
+
id: 'height-map',
|
|
48
|
+
float: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return this.fbo;
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "shouldUpdate",
|
|
56
|
+
value: function shouldUpdate(_ref) {
|
|
57
|
+
var _this = this;
|
|
58
|
+
|
|
59
|
+
var layers = _ref.layers,
|
|
60
|
+
viewport = _ref.viewport;
|
|
61
|
+
var layersChanged = layers.length !== this.layers.length || layers.some(function (layer, i) {
|
|
62
|
+
return layer !== _this.layers[i] || layer.props.transitions || layer.getBounds() !== _this.layersBounds[i];
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (layersChanged) {
|
|
66
|
+
this.layers = layers;
|
|
67
|
+
this.layersBounds = layers.map(function (layer) {
|
|
68
|
+
return layer.getBounds();
|
|
69
|
+
});
|
|
70
|
+
this.layersBoundsCommon = (0, _projectionUtils.joinLayerBounds)(layers, viewport);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var viewportChanged = !this.lastViewport || !viewport.equals(this.lastViewport);
|
|
74
|
+
|
|
75
|
+
if (!this.layersBoundsCommon) {
|
|
76
|
+
this.renderViewport = null;
|
|
77
|
+
} else if (layersChanged || viewportChanged) {
|
|
78
|
+
var bounds = (0, _projectionUtils.getRenderBounds)(this.layersBoundsCommon, viewport);
|
|
79
|
+
this.bounds = bounds;
|
|
80
|
+
this.lastViewport = viewport;
|
|
81
|
+
var scale = viewport.scale;
|
|
82
|
+
var pixelWidth = (bounds[2] - bounds[0]) * scale;
|
|
83
|
+
var pixelHeight = (bounds[3] - bounds[1]) * scale;
|
|
84
|
+
this.renderViewport = pixelWidth > 0 || pixelHeight > 0 ? (0, _projectionUtils.makeViewport)({
|
|
85
|
+
bounds: [viewport.center[0] - 1, viewport.center[1] - 1, viewport.center[0] + 1, viewport.center[1] + 1],
|
|
86
|
+
zoom: viewport.zoom,
|
|
87
|
+
width: Math.min(pixelWidth, MAP_MAX_SIZE),
|
|
88
|
+
height: Math.min(pixelHeight, MAP_MAX_SIZE),
|
|
89
|
+
viewport: viewport
|
|
90
|
+
}) : null;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "delete",
|
|
98
|
+
value: function _delete() {
|
|
99
|
+
if (this.fbo) {
|
|
100
|
+
this.fbo.color.delete();
|
|
101
|
+
this.fbo.delete();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}], [{
|
|
105
|
+
key: "isSupported",
|
|
106
|
+
value: function isSupported(gl) {
|
|
107
|
+
return _core.Framebuffer.isSupported(gl, {
|
|
108
|
+
colorBufferFloat: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}]);
|
|
112
|
+
return HeightMapBuilder;
|
|
113
|
+
}();
|
|
114
|
+
|
|
115
|
+
exports.HeightMapBuilder = HeightMapBuilder;
|
|
116
|
+
//# sourceMappingURL=height-map-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terrain/height-map-builder.ts"],"names":["MAP_MAX_SIZE","HeightMapBuilder","gl","renderViewport","fbo","id","float","layers","viewport","layersChanged","length","some","layer","i","props","transitions","getBounds","layersBounds","map","layersBoundsCommon","viewportChanged","lastViewport","equals","bounds","scale","pixelWidth","pixelHeight","center","zoom","width","Math","min","height","color","delete","Framebuffer","isSupported","colorBufferFloat"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAIA,IAAMA,YAAY,GAAG,IAArB;;IASaC,gB;AAoBX,4BAAYC,EAAZ,EAAuC;AAAA;AAAA,0DAlBL,IAkBK;AAAA,kDAhBf,IAgBe;AAAA;AAAA;AAAA,kDAXb,EAWa;AAAA,wDATiB,EASjB;AAAA,8DAPK,IAOL;AAAA,wDANC,IAMD;AACrC,SAAKA,EAAL,GAAUA,EAAV;AACD;;;;WAKD,gCAA2C;AACzC,UAAI,CAAC,KAAKC,cAAV,EAA0B;AACxB,eAAO,IAAP;AACD;;AACD,UAAI,CAAC,KAAKC,GAAV,EAAe;AACb,aAAKA,GAAL,GAAW,+BAAmB,KAAKF,EAAxB,EAA4B;AAACG,UAAAA,EAAE,EAAE,YAAL;AAAmBC,UAAAA,KAAK,EAAE;AAA1B,SAA5B,CAAX;AACD;;AACD,aAAO,KAAKF,GAAZ;AACD;;;WAGD,4BAAiF;AAAA;;AAAA,UAAnEG,MAAmE,QAAnEA,MAAmE;AAAA,UAA3DC,QAA2D,QAA3DA,QAA2D;AAC/E,UAAMC,aAAa,GACjBF,MAAM,CAACG,MAAP,KAAkB,KAAKH,MAAL,CAAYG,MAA9B,IACAH,MAAM,CAACI,IAAP,CACE,UAACC,KAAD,EAAQC,CAAR;AAAA,eAKED,KAAK,KAAK,KAAI,CAACL,MAAL,CAA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B,IAAqB,CAFf,EAGNnB,QAAQ,CAACmB,MAAT,CAAgB,CAAhB,IAAqB,CAHf,EAINnB,QAAQ,CAACmB,MAAT,CAAgB,CAAhB,IAAqB,CAJf,CALG;AAWXC,UAAAA,IAAI,EAAEpB,QAAQ,CAACoB,IAXJ;AAYXC,UAAAA,KAAK,EAAEC,IAAI,CAACC,GAAL,CAASN,UAAT,EAAqBzB,YAArB,CAZI;AAaXgC,UAAAA,MAAM,EAAEF,IAAI,CAACC,GAAL,CAASL,WAAT,EAAsB1B,YAAtB,CAbG;AAcXQ,UAAAA,QAAQ,EAARA;AAdW,SAAb,CADJ,GAiBI,IAlBN;AAmBA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD;;;WAED,mBAAS;AACP,UAAI,KAAKJ,GAAT,EAAc;AACZ,aAAKA,GAAL,CAAS6B,KAAT,CAAeC,MAAf;AACA,aAAK9B,GAAL,CAAS8B,MAAT;AACD;AACF;;;WAvFD,qBAAmBhC,EAAnB,EAAuD;AACrD,aAAOiC,kBAAYC,WAAZ,CAAwBlC,EAAxB,EAA4B;AAACmC,QAAAA,gBAAgB,EAAE;AAAnB,OAA5B,CAAP;AACD","sourcesContent":["import {Framebuffer} from '@luma.gl/core';\nimport {joinLayerBounds, getRenderBounds, makeViewport, Bounds} from '../common/projection-utils';\nimport {createRenderTarget} from './utils';\n\nimport type {Viewport, Layer} from '@deck.gl/core';\n\nconst MAP_MAX_SIZE = 2048;\n\n/**\n * Manages the lifecycle of the height map (a framebuffer that encodes elevation).\n * One instance of height map is is shared across all layers. It is updated when the viewport changes\n * or when some terrain source layer's data changes.\n * During the draw call of any terrainFittingMode:offset layers,\n * the vertex shader reads from this framebuffer to retrieve its z offset.\n */\nexport class HeightMapBuilder {\n /** Viewport used to draw into the texture */\n renderViewport: Viewport | null = null;\n /** Bounds of the height map texture, in cartesian space */\n bounds: Bounds | null = null;\n\n protected fbo?: Framebuffer;\n protected gl: WebGLRenderingContext;\n /** Last rendered layers */\n private layers: Layer[] = [];\n /** Last layer.getBounds() */\n private layersBounds: ([number[], number[]] | null)[] = [];\n /** The union of layersBounds in cartesian space */\n private layersBoundsCommon: Bounds | null = null;\n private lastViewport: Viewport | null = null;\n\n static isSupported(gl: WebGLRenderingContext): boolean {\n return Framebuffer.isSupported(gl, {colorBufferFloat: true});\n }\n\n constructor(gl: WebGLRenderingContext) {\n this.gl = gl;\n }\n\n /** Returns the height map framebuffer for read/write access.\n * Returns null when the texture is invalid.\n */\n getRenderFramebuffer(): Framebuffer | null {\n if (!this.renderViewport) {\n return null;\n }\n if (!this.fbo) {\n this.fbo = createRenderTarget(this.gl, {id: 'height-map', float: true});\n }\n return this.fbo;\n }\n\n /** Called every render cycle to check if the framebuffer needs update */\n shouldUpdate({layers, viewport}: {layers: Layer[]; viewport: Viewport}): boolean {\n const layersChanged =\n layers.length !== this.layers.length ||\n layers.some(\n (layer, i) =>\n // Layer instance is updated\n // Layer props might have changed\n // Undetermined props could have an effect on the output geometry of a terrain source,\n // for example getElevation+updateTriggers, elevationScale, modelMatrix\n layer !== this.layers[i] ||\n // Some prop is in transition\n layer.props.transitions ||\n // Layer's geometry bounds have changed\n layer.getBounds() !== this.layersBounds[i]\n );\n\n if (layersChanged) {\n // Recalculate cached bounds\n this.layers = layers;\n this.layersBounds = layers.map(layer => layer.getBounds());\n this.layersBoundsCommon = joinLayerBounds(layers, viewport);\n }\n\n const viewportChanged = !this.lastViewport || !viewport.equals(this.lastViewport);\n\n if (!this.layersBoundsCommon) {\n this.renderViewport = null;\n } else if (layersChanged || viewportChanged) {\n const bounds = getRenderBounds(this.layersBoundsCommon, viewport);\n this.bounds = bounds;\n this.lastViewport = viewport;\n\n const scale = viewport.scale;\n const pixelWidth = (bounds[2] - bounds[0]) * scale;\n const pixelHeight = (bounds[3] - bounds[1]) * scale;\n\n this.renderViewport =\n pixelWidth > 0 || pixelHeight > 0\n ? makeViewport({\n // It's not important whether the geometry is visible in this viewport, because\n // vertices will not use the standard project_to_clipspace in the DRAW_TO_HEIGHT_MAP shader\n // However the viewport must have the same center and zoom as the screen viewport\n // So that projection uniforms used for calculating z are the same\n bounds: [\n viewport.center[0] - 1,\n viewport.center[1] - 1,\n viewport.center[0] + 1,\n viewport.center[1] + 1\n ],\n zoom: viewport.zoom,\n width: Math.min(pixelWidth, MAP_MAX_SIZE),\n height: Math.min(pixelHeight, MAP_MAX_SIZE),\n viewport\n })\n : null;\n return true;\n }\n return false;\n }\n\n delete() {\n if (this.fbo) {\n this.fbo.color.delete();\n this.fbo.delete();\n }\n }\n}\n"],"file":"height-map-builder.js"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.terrainModule = exports.TERRAIN_MODE = void 0;
|
|
7
|
+
|
|
8
|
+
var _core = require("@deck.gl/core");
|
|
9
|
+
|
|
10
|
+
var TERRAIN_MODE = {
|
|
11
|
+
NONE: 0,
|
|
12
|
+
WRITE_HEIGHT_MAP: 1,
|
|
13
|
+
USE_HEIGHT_MAP: 2,
|
|
14
|
+
USE_COVER: 3,
|
|
15
|
+
USE_COVER_ONLY: 4,
|
|
16
|
+
SKIP: 5
|
|
17
|
+
};
|
|
18
|
+
exports.TERRAIN_MODE = TERRAIN_MODE;
|
|
19
|
+
var TERRAIN_MODE_CONSTANTS = Object.keys(TERRAIN_MODE).map(function (key) {
|
|
20
|
+
return "const float TERRAIN_MODE_".concat(key, " = ").concat(TERRAIN_MODE[key], ".0;");
|
|
21
|
+
}).join('\n');
|
|
22
|
+
var terrainModule = {
|
|
23
|
+
name: 'terrain',
|
|
24
|
+
dependencies: [_core.project],
|
|
25
|
+
inject: {
|
|
26
|
+
'vs:#decl': "\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n".concat(TERRAIN_MODE_CONSTANTS, "\n "),
|
|
27
|
+
'vs:#main-start': "\nif (terrain_mode == TERRAIN_MODE_SKIP) {\n gl_Position = vec4(0.0);\n return;\n}\n",
|
|
28
|
+
'vs:DECKGL_FILTER_GL_POSITION': "\ncommonPos = geometry.position.xyz;\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n position = vec4(texCoords * 2.0 - 1.0, 0.0, 1.0);\n}\nif (terrain_mode == TERRAIN_MODE_USE_HEIGHT_MAP) {\n vec3 anchor = geometry.worldPosition;\n anchor.z = 0.0;\n vec3 anchorCommon = project_position(anchor);\n vec2 texCoords = (anchorCommon.xy - terrain_bounds.xy) / terrain_bounds.zw;\n if (texCoords.x >= 0.0 && texCoords.y >= 0.0 && texCoords.x <= 1.0 && texCoords.y <= 1.0) {\n float terrainZ = texture2D(terrain_map, texCoords).r;\n geometry.position.z += terrainZ;\n position = project_common_position_to_clipspace(geometry.position);\n }\n}\n ",
|
|
29
|
+
'fs:#decl': "\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n".concat(TERRAIN_MODE_CONSTANTS, "\n "),
|
|
30
|
+
'fs:#main-start': "\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n gl_FragColor = vec4(commonPos.z, 0.0, 0.0, 1.0);\n return;\n}\n ",
|
|
31
|
+
'fs:DECKGL_FILTER_COLOR': "\nif ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY)) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n vec4 pixel = texture2D(terrain_map, texCoords);\n if (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY) {\n color = pixel;\n } else {\n // pixel is premultiplied\n color = pixel + color * (1.0 - pixel.a);\n }\n return;\n}\n "
|
|
32
|
+
},
|
|
33
|
+
getUniforms: function getUniforms() {
|
|
34
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
35
|
+
var uniforms = arguments.length > 1 ? arguments[1] : undefined;
|
|
36
|
+
|
|
37
|
+
if ('dummyHeightMap' in opts) {
|
|
38
|
+
var drawToTerrainHeightMap = opts.drawToTerrainHeightMap,
|
|
39
|
+
heightMap = opts.heightMap,
|
|
40
|
+
heightMapBounds = opts.heightMapBounds,
|
|
41
|
+
dummyHeightMap = opts.dummyHeightMap,
|
|
42
|
+
terrainCover = opts.terrainCover,
|
|
43
|
+
useTerrainHeightMap = opts.useTerrainHeightMap,
|
|
44
|
+
terrainSkipRender = opts.terrainSkipRender;
|
|
45
|
+
var project_uCommonOrigin = uniforms.project_uCommonOrigin;
|
|
46
|
+
var mode = terrainSkipRender ? TERRAIN_MODE.SKIP : TERRAIN_MODE.NONE;
|
|
47
|
+
var sampler = dummyHeightMap;
|
|
48
|
+
var bounds = null;
|
|
49
|
+
|
|
50
|
+
if (drawToTerrainHeightMap) {
|
|
51
|
+
mode = TERRAIN_MODE.WRITE_HEIGHT_MAP;
|
|
52
|
+
bounds = heightMapBounds;
|
|
53
|
+
} else if (useTerrainHeightMap && heightMap) {
|
|
54
|
+
mode = TERRAIN_MODE.USE_HEIGHT_MAP;
|
|
55
|
+
sampler = heightMap;
|
|
56
|
+
bounds = heightMapBounds;
|
|
57
|
+
} else if (terrainCover) {
|
|
58
|
+
var isPicking = opts.pickingActive;
|
|
59
|
+
sampler = isPicking ? terrainCover.getPickingFramebuffer() : terrainCover.getRenderFramebuffer();
|
|
60
|
+
|
|
61
|
+
if (isPicking) {
|
|
62
|
+
mode = TERRAIN_MODE.SKIP;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (sampler) {
|
|
66
|
+
mode = mode === TERRAIN_MODE.SKIP ? TERRAIN_MODE.USE_COVER_ONLY : TERRAIN_MODE.USE_COVER;
|
|
67
|
+
bounds = terrainCover.bounds;
|
|
68
|
+
} else {
|
|
69
|
+
sampler = dummyHeightMap;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
terrain_mode: mode,
|
|
75
|
+
terrain_map: sampler,
|
|
76
|
+
terrain_bounds: bounds ? [bounds[0] - project_uCommonOrigin[0], bounds[1] - project_uCommonOrigin[1], bounds[2] - bounds[0], bounds[3] - bounds[1]] : [0, 0, 0, 0]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.terrainModule = terrainModule;
|
|
84
|
+
//# sourceMappingURL=shader-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terrain/shader-module.ts"],"names":["TERRAIN_MODE","NONE","WRITE_HEIGHT_MAP","USE_HEIGHT_MAP","USE_COVER","USE_COVER_ONLY","SKIP","TERRAIN_MODE_CONSTANTS","Object","keys","map","key","join","terrainModule","name","dependencies","project","inject","getUniforms","opts","uniforms","drawToTerrainHeightMap","heightMap","heightMapBounds","dummyHeightMap","terrainCover","useTerrainHeightMap","terrainSkipRender","project_uCommonOrigin","mode","sampler","bounds","isPicking","pickingActive","getPickingFramebuffer","getRenderFramebuffer","terrain_mode","terrain_map","terrain_bounds"],"mappings":";;;;;;;AAAA;;AAoBO,IAAMA,YAAY,GAAG;AAC1BC,EAAAA,IAAI,EAAE,CADoB;AAG1BC,EAAAA,gBAAgB,EAAE,CAHQ;AAK1BC,EAAAA,cAAc,EAAE,CALU;AAO1BC,EAAAA,SAAS,EAAE,CAPe;AAS1BC,EAAAA,cAAc,EAAE,CATU;AAW1BC,EAAAA,IAAI,EAAE;AAXoB,CAArB;;AAcP,IAAMC,sBAAsB,GAAGC,MAAM,CAACC,IAAP,CAAYT,YAAZ,EAC5BU,GAD4B,CACxB,UAAAC,GAAG;AAAA,4CAAgCA,GAAhC,gBAAyCX,YAAY,CAACW,GAAD,CAArD;AAAA,C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AAT;AACD,OAJM,MAIA,IAAIE,YAAJ,EAAkB;AAEvB,YAAMO,SAAS,GAAGb,IAAI,CAACc,aAAvB;AACAH,QAAAA,OAAO,GAAGE,SAAS,GACfP,YAAY,CAACS,qBAAb,EADe,GAEfT,YAAY,CAACU,oBAAb,EAFJ;;AAGA,YAAIH,SAAJ,EAAe;AAEbH,UAAAA,IAAI,GAAG7B,YAAY,CAACM,IAApB;AACD;;AACD,YAAIwB,OAAJ,EAAa;AACXD,UAAAA,IAAI,GAAGA,IAAI,KAAK7B,YAAY,CAACM,IAAtB,GAA6BN,YAAY,CAACK,cAA1C,GAA2DL,YAAY,CAACI,SAA/E;AACA2B,UAAAA,MAAM,GAAGN,YAAY,CAACM,MAAtB;AACD,SAHD,MAGO;AACLD,UAAAA,OAAO,GAAGN,cAAV;AACD;AACF;;AAGD,aAAO;AACLY,QAAAA,YAAY,EAAEP,IADT;AAELQ,QAAAA,WAAW,EAAEP,OAFR;AAILQ,QAAAA,cAAc,EAAEP,MAAM,GAClB,CACEA,MAAM,CAAC,CAAD,CAAN,GAAYH,qBAAqB,CAAC,CAAD,CADnC,EAEEG,MAAM,CAAC,CAAD,CAAN,GAAYH,qBAAqB,CAAC,CAAD,CAFnC,EAGEG,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAHpB,EAIEA,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAJpB,CADkB,GAOlB,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV;AAXC,OAAP;AAaD;;AACD,WAAO,IAAP;AACD;AAzH0B,CAAtB","sourcesContent":["import {project} from '@deck.gl/core';\nimport type {_ShaderModule as ShaderModule} from '@deck.gl/core';\n\nimport type {Texture2D} from '@luma.gl/core';\nimport type {Bounds} from '../common/projection-utils';\nimport type {TerrainCover} from './terrain-cover';\n\n/** Module parameters expected by the terrain shader module */\nexport type TerrainModuleSettings = {\n pickingActive?: boolean;\n heightMap: Texture2D | null;\n heightMapBounds?: Bounds | null;\n dummyHeightMap: Texture2D;\n terrainCover?: TerrainCover | null;\n drawToTerrainHeightMap?: boolean;\n useTerrainHeightMap?: boolean;\n terrainSkipRender?: boolean;\n};\n\n/** A model can have one of the following modes */\nexport const TERRAIN_MODE = {\n NONE: 0,\n /** A terrain layer rendering encoded ground elevation into the height map */\n WRITE_HEIGHT_MAP: 1,\n /** An offset layer reading encoded ground elevation from the height map */\n USE_HEIGHT_MAP: 2,\n /** A terrain layer rendering to screen, using the cover fbo overlaid with its own texture */\n USE_COVER: 3,\n /** A terrain layer rendering to screen, using the cover fbo as texture */\n USE_COVER_ONLY: 4,\n /** Draped layer is rendered into a texture, and never to screen */\n SKIP: 5\n};\n\nconst TERRAIN_MODE_CONSTANTS = Object.keys(TERRAIN_MODE)\n .map(key => `const float TERRAIN_MODE_${key} = ${TERRAIN_MODE[key]}.0;`)\n .join('\\n');\n\nexport const terrainModule = {\n name: 'terrain',\n dependencies: [project],\n inject: {\n 'vs:#decl': `\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n${TERRAIN_MODE_CONSTANTS}\n `,\n 'vs:#main-start': `\nif (terrain_mode == TERRAIN_MODE_SKIP) {\n gl_Position = vec4(0.0);\n return;\n}\n`,\n 'vs:DECKGL_FILTER_GL_POSITION': `\ncommonPos = geometry.position.xyz;\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n position = vec4(texCoords * 2.0 - 1.0, 0.0, 1.0);\n}\nif (terrain_mode == TERRAIN_MODE_USE_HEIGHT_MAP) {\n vec3 anchor = geometry.worldPosition;\n anchor.z = 0.0;\n vec3 anchorCommon = project_position(anchor);\n vec2 texCoords = (anchorCommon.xy - terrain_bounds.xy) / terrain_bounds.zw;\n if (texCoords.x >= 0.0 && texCoords.y >= 0.0 && texCoords.x <= 1.0 && texCoords.y <= 1.0) {\n float terrainZ = texture2D(terrain_map, texCoords).r;\n geometry.position.z += terrainZ;\n position = project_common_position_to_clipspace(geometry.position);\n }\n}\n `,\n 'fs:#decl': `\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n${TERRAIN_MODE_CONSTANTS}\n `,\n 'fs:#main-start': `\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n gl_FragColor = vec4(commonPos.z, 0.0, 0.0, 1.0);\n return;\n}\n `,\n 'fs:DECKGL_FILTER_COLOR': `\nif ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY)) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n vec4 pixel = texture2D(terrain_map, texCoords);\n if (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY) {\n color = pixel;\n } else {\n // pixel is premultiplied\n color = pixel + color * (1.0 - pixel.a);\n }\n return;\n}\n `\n },\n getUniforms: (opts = {}, uniforms) => {\n if ('dummyHeightMap' in opts) {\n const {\n drawToTerrainHeightMap,\n heightMap,\n heightMapBounds,\n dummyHeightMap,\n terrainCover,\n useTerrainHeightMap,\n terrainSkipRender\n } = opts;\n const {project_uCommonOrigin} = uniforms;\n\n let mode: number = terrainSkipRender ? TERRAIN_MODE.SKIP : TERRAIN_MODE.NONE;\n // height map if case USE_HEIGHT_MAP, terrain cover if USE_COVER, otherwise empty\n let sampler: Texture2D = dummyHeightMap;\n // height map bounds if case USE_HEIGHT_MAP, terrain cover bounds if USE_COVER, otherwise null\n let bounds: number[] | null = null;\n if (drawToTerrainHeightMap) {\n mode = TERRAIN_MODE.WRITE_HEIGHT_MAP;\n bounds = heightMapBounds!;\n } else if (useTerrainHeightMap && heightMap) {\n mode = TERRAIN_MODE.USE_HEIGHT_MAP;\n sampler = heightMap;\n bounds = heightMapBounds!;\n } else if (terrainCover) {\n // This is a terrain layer\n const isPicking = opts.pickingActive;\n sampler = isPicking\n ? terrainCover.getPickingFramebuffer()\n : terrainCover.getRenderFramebuffer();\n if (isPicking) {\n // Never render the layer itself in picking pass\n mode = TERRAIN_MODE.SKIP;\n }\n if (sampler) {\n mode = mode === TERRAIN_MODE.SKIP ? TERRAIN_MODE.USE_COVER_ONLY : TERRAIN_MODE.USE_COVER;\n bounds = terrainCover.bounds;\n } else {\n sampler = dummyHeightMap;\n }\n }\n\n /* eslint-disable camelcase */\n return {\n terrain_mode: mode,\n terrain_map: sampler,\n // Convert bounds to the common space, as [minX, minY, width, height]\n terrain_bounds: bounds\n ? [\n bounds[0] - project_uCommonOrigin[0],\n bounds[1] - project_uCommonOrigin[1],\n bounds[2] - bounds[0],\n bounds[3] - bounds[1]\n ]\n : [0, 0, 0, 0]\n };\n }\n return null;\n }\n} as ShaderModule<TerrainModuleSettings>;\n"],"file":"shader-module.js"}
|