@deck.gl/extensions 8.9.7 → 8.9.9
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 +19 -7
- package/dist/es5/terrain/height-map-builder.js +6 -0
- package/dist/es5/terrain/height-map-builder.js.map +1 -1
- package/dist/es5/terrain/shader-module.js +1 -1
- package/dist/es5/terrain/shader-module.js.map +1 -1
- package/dist/es5/terrain/terrain-cover.js +12 -8
- package/dist/es5/terrain/terrain-cover.js.map +1 -1
- package/dist/es5/utils/projection-utils.js +2 -0
- package/dist/es5/utils/projection-utils.js.map +1 -1
- package/dist/esm/terrain/height-map-builder.js +6 -0
- package/dist/esm/terrain/height-map-builder.js.map +1 -1
- package/dist/esm/terrain/shader-module.js +1 -1
- package/dist/esm/terrain/shader-module.js.map +1 -1
- package/dist/esm/terrain/terrain-cover.js +12 -8
- package/dist/esm/terrain/terrain-cover.js.map +1 -1
- package/dist/esm/utils/projection-utils.js +2 -0
- package/dist/esm/utils/projection-utils.js.map +1 -1
- package/dist.min.js +17 -16
- package/package.json +2 -2
- package/src/terrain/height-map-builder.ts +5 -0
- package/src/terrain/shader-module.ts +1 -0
- package/src/terrain/terrain-cover.ts +24 -19
- package/src/utils/projection-utils.ts +2 -0
- package/typed/collide/collide-effect.d.ts +1 -1
- package/typed/collide/collide-effect.d.ts.map +1 -1
- package/typed/collide/collide-pass.d.ts +1 -0
- package/typed/collide/collide-pass.d.ts.map +1 -1
- package/typed/collide/collide.d.ts +1 -0
- package/typed/collide/collide.d.ts.map +1 -1
- package/typed/collide/shader-module.d.ts.map +1 -1
- package/typed/effect-order.d.ts +6 -0
- package/typed/effect-order.d.ts.map +1 -0
- package/typed/terrain/height-map-builder.d.ts.map +1 -1
- package/typed/terrain/shader-module.d.ts.map +1 -1
- package/typed/terrain/terrain-cover.d.ts.map +1 -1
- package/typed/utils/projection-utils.d.ts.map +1 -1
- package/typed/brushing/brushing.js +0 -83
- package/typed/brushing/shader-module.js +0 -116
- package/typed/clip/clip.js +0 -114
- package/typed/data-filter/aggregator.js +0 -98
- package/typed/data-filter/data-filter.js +0 -159
- package/typed/data-filter/shader-module.js +0 -152
- package/typed/fill-style/fill-style.js +0 -152
- package/typed/fill-style/shaders.glsl.js +0 -95
- package/typed/fp64/fp64.js +0 -34
- package/typed/fp64/project64.glsl.js +0 -100
- package/typed/fp64/project64.js +0 -50
- package/typed/index.js +0 -9
- package/typed/mask/mask.js +0 -48
- package/typed/mask/shader-module.js +0 -73
- package/typed/path-style/path-style.js +0 -107
- package/typed/path-style/shaders.glsl.js +0 -93
- package/typed/terrain/height-map.d.ts +0 -27
- package/typed/terrain/height-map.d.ts.map +0 -1
- package/typed/terrain/shader-module-offset.d.ts +0 -4
- package/typed/terrain/shader-module-offset.d.ts.map +0 -1
- package/typed/terrain/shader-module-source.d.ts +0 -4
- package/typed/terrain/shader-module-source.d.ts.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2387,6 +2387,7 @@ float collision_isVisible(vec2 texCoords, vec3 pickingColor) {
|
|
|
2387
2387
|
}
|
|
2388
2388
|
}
|
|
2389
2389
|
return isGeospatial ? new import_core19.WebMercatorViewport({
|
|
2390
|
+
id: viewport.id,
|
|
2390
2391
|
x: border,
|
|
2391
2392
|
y: border,
|
|
2392
2393
|
width,
|
|
@@ -2396,6 +2397,7 @@ float collision_isVisible(vec2 texCoords, vec3 pickingColor) {
|
|
|
2396
2397
|
zoom,
|
|
2397
2398
|
orthographic: true
|
|
2398
2399
|
}) : new import_core19.OrthographicViewport({
|
|
2400
|
+
id: viewport.id,
|
|
2399
2401
|
x: border,
|
|
2400
2402
|
y: border,
|
|
2401
2403
|
width,
|
|
@@ -3092,6 +3094,7 @@ commonPos = geometry.position.xyz;
|
|
|
3092
3094
|
if (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {
|
|
3093
3095
|
vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;
|
|
3094
3096
|
position = vec4(texCoords * 2.0 - 1.0, 0.0, 1.0);
|
|
3097
|
+
commonPos.z += project_uCommonOrigin.z;
|
|
3095
3098
|
}
|
|
3096
3099
|
if (terrain_mode == TERRAIN_MODE_USE_HEIGHT_MAP) {
|
|
3097
3100
|
vec3 anchor = geometry.worldPosition;
|
|
@@ -3263,7 +3266,15 @@ if ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_US
|
|
|
3263
3266
|
_updateViewport(viewport) {
|
|
3264
3267
|
const targetLayer = this.targetLayer;
|
|
3265
3268
|
let shouldRedraw = false;
|
|
3266
|
-
if (this.
|
|
3269
|
+
if (this.tile && "boundingBox" in this.tile) {
|
|
3270
|
+
if (!this.targetBounds) {
|
|
3271
|
+
shouldRedraw = true;
|
|
3272
|
+
this.targetBounds = this.tile.boundingBox;
|
|
3273
|
+
const bottomLeftCommon = viewport.projectPosition(this.targetBounds[0]);
|
|
3274
|
+
const topRightCommon = viewport.projectPosition(this.targetBounds[1]);
|
|
3275
|
+
this.targetBoundsCommon = [bottomLeftCommon[0], bottomLeftCommon[1], topRightCommon[0], topRightCommon[1]];
|
|
3276
|
+
}
|
|
3277
|
+
} else if (this.targetBounds !== targetLayer.getBounds()) {
|
|
3267
3278
|
shouldRedraw = true;
|
|
3268
3279
|
this.targetBounds = targetLayer.getBounds();
|
|
3269
3280
|
this.targetBoundsCommon = joinLayerBounds([targetLayer], viewport);
|
|
@@ -3337,7 +3348,7 @@ if ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_US
|
|
|
3337
3348
|
return layers.filter((layer) => {
|
|
3338
3349
|
const tile = getTile(layer);
|
|
3339
3350
|
if (tile) {
|
|
3340
|
-
return intersect(sourceTile.
|
|
3351
|
+
return intersect(sourceTile.boundingBox, tile.boundingBox);
|
|
3341
3352
|
}
|
|
3342
3353
|
return true;
|
|
3343
3354
|
});
|
|
@@ -3355,11 +3366,8 @@ if ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_US
|
|
|
3355
3366
|
return null;
|
|
3356
3367
|
}
|
|
3357
3368
|
function intersect(b1, b2) {
|
|
3358
|
-
if (
|
|
3359
|
-
return b1
|
|
3360
|
-
}
|
|
3361
|
-
if ("left" in b1 && "left" in b2) {
|
|
3362
|
-
return b1.left < b2.right && b2.left < b1.right && b1.top < b2.bottom && b2.top < b1.bottom;
|
|
3369
|
+
if (b1 && b2) {
|
|
3370
|
+
return b1[0][0] < b2[1][0] && b2[0][0] < b1[1][0] && b1[0][1] < b2[1][1] && b2[0][1] < b1[1][1];
|
|
3363
3371
|
}
|
|
3364
3372
|
return false;
|
|
3365
3373
|
}
|
|
@@ -3528,6 +3536,10 @@ if ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_US
|
|
|
3528
3536
|
this.renderViewport = null;
|
|
3529
3537
|
} else if (layersChanged || viewportChanged) {
|
|
3530
3538
|
const bounds = getRenderBounds(this.layersBoundsCommon, viewport);
|
|
3539
|
+
if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {
|
|
3540
|
+
this.renderViewport = null;
|
|
3541
|
+
return false;
|
|
3542
|
+
}
|
|
3531
3543
|
this.bounds = bounds;
|
|
3532
3544
|
this.lastViewport = viewport;
|
|
3533
3545
|
const scale = viewport.scale;
|
|
@@ -76,6 +76,12 @@ var HeightMapBuilder = function () {
|
|
|
76
76
|
this.renderViewport = null;
|
|
77
77
|
} else if (layersChanged || viewportChanged) {
|
|
78
78
|
var bounds = (0, _projectionUtils.getRenderBounds)(this.layersBoundsCommon, viewport);
|
|
79
|
+
|
|
80
|
+
if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {
|
|
81
|
+
this.renderViewport = null;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
this.bounds = bounds;
|
|
80
86
|
this.lastViewport = viewport;
|
|
81
87
|
var scale = viewport.scale;
|
|
@@ -1 +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,CAAYM,CAAZ,CAAV,IAEAD,KAAK,CAACE,KAAN,CAAYC,WAFZ,IAIAH,KAAK,CAACI,SAAN,OAAsB,KAAI,CAACC,YAAL,CAAkBJ,CAAlB,CATxB;AAAA,OADF,CAFF;;AAeA,UAAIJ,aAAJ,EAAmB;AAEjB,aAAKF,MAAL,GAAcA,MAAd;AACA,aAAKU,YAAL,GAAoBV,MAAM,CAACW,GAAP,CAAW,UAAAN,KAAK;AAAA,iBAAIA,KAAK,CAACI,SAAN,EAAJ;AAAA,SAAhB,CAApB;AACA,aAAKG,kBAAL,GAA0B,sCAAgBZ,MAAhB,EAAwBC,QAAxB,CAA1B;AACD;;AAED,UAAMY,eAAe,GAAG,CAAC,KAAKC,YAAN,IAAsB,CAACb,QAAQ,CAACc,MAAT,CAAgB,KAAKD,YAArB,CAA/C;;AAEA,UAAI,CAAC,KAAKF,kBAAV,EAA8B;AAC5B,aAAKhB,cAAL,GAAsB,IAAtB;AACD,OAFD,MAEO,IAAIM,aAAa,IAAIW,eAArB,EAAsC;AAC3C,YAAMG,MAAM,GAAG,sCAAgB,KAAKJ,kBAArB,EAAyCX,QAAzC,CAAf;AACA,
|
|
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,e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AT,CAAeC,MAAf;AACA,aAAK9B,GAAL,CAAS8B,MAAT;AACD;AACF;;;WA5FD,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 '../utils/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 terrainDrawMode: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 if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {\n this.renderViewport = null;\n return false;\n }\n\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"}
|
|
@@ -25,7 +25,7 @@ var terrainModule = {
|
|
|
25
25
|
inject: {
|
|
26
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
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 ",
|
|
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 commonPos.z += project_uCommonOrigin.z;\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
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
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
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 "
|
|
@@ -1 +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":";;;;;;;AAEA;;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,CADqB,EAE5BC,IAF4B,CAEvB,IAFuB,CAA/B;AAIO,IAAMC,aAAa,GAAG;AAC3BC,EAAAA,IAAI,EAAE,SADqB;AAE3BC,EAAAA,YAAY,EAAE,CAACC,aAAD,CAFa;AAG3BC,EAAAA,MAAM,EAAE;AACN,gJAKFV,sBALE,WADM;AAQN,8GARM;AAcN,
|
|
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":";;;;;;;AAEA;;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,CADqB,EAE5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AJM,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;AA3H0B,CAAtB","sourcesContent":["/* eslint-disable camelcase */\n\nimport {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 '../utils/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 commonPos.z += project_uCommonOrigin.z;\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 // eslint-disable-next-line complexity\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"}
|
|
@@ -120,7 +120,15 @@ var TerrainCover = function () {
|
|
|
120
120
|
var targetLayer = this.targetLayer;
|
|
121
121
|
var shouldRedraw = false;
|
|
122
122
|
|
|
123
|
-
if (this.
|
|
123
|
+
if (this.tile && 'boundingBox' in this.tile) {
|
|
124
|
+
if (!this.targetBounds) {
|
|
125
|
+
shouldRedraw = true;
|
|
126
|
+
this.targetBounds = this.tile.boundingBox;
|
|
127
|
+
var bottomLeftCommon = viewport.projectPosition(this.targetBounds[0]);
|
|
128
|
+
var topRightCommon = viewport.projectPosition(this.targetBounds[1]);
|
|
129
|
+
this.targetBoundsCommon = [bottomLeftCommon[0], bottomLeftCommon[1], topRightCommon[0], topRightCommon[1]];
|
|
130
|
+
}
|
|
131
|
+
} else if (this.targetBounds !== targetLayer.getBounds()) {
|
|
124
132
|
shouldRedraw = true;
|
|
125
133
|
this.targetBounds = targetLayer.getBounds();
|
|
126
134
|
this.targetBoundsCommon = (0, _projectionUtils.joinLayerBounds)([targetLayer], viewport);
|
|
@@ -224,7 +232,7 @@ function getIntersectingLayers(sourceTile, layers) {
|
|
|
224
232
|
var tile = getTile(layer);
|
|
225
233
|
|
|
226
234
|
if (tile) {
|
|
227
|
-
return intersect(sourceTile.
|
|
235
|
+
return intersect(sourceTile.boundingBox, tile.boundingBox);
|
|
228
236
|
}
|
|
229
237
|
|
|
230
238
|
return true;
|
|
@@ -246,12 +254,8 @@ function getTile(layer) {
|
|
|
246
254
|
}
|
|
247
255
|
|
|
248
256
|
function intersect(b1, b2) {
|
|
249
|
-
if (
|
|
250
|
-
return b1
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if ('left' in b1 && 'left' in b2) {
|
|
254
|
-
return b1.left < b2.right && b2.left < b1.right && b1.top < b2.bottom && b2.top < b1.bottom;
|
|
257
|
+
if (b1 && b2) {
|
|
258
|
+
return b1[0][0] < b2[1][0] && b2[0][0] < b1[1][0] && b1[0][1] < b2[1][1] && b2[0][1] < b1[1][1];
|
|
255
259
|
}
|
|
256
260
|
|
|
257
261
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/terrain/terrain-cover.ts"],"names":["TerrainCover","targetLayer","tile","getTile","id","Boolean","getCurrentLayer","viewport","layers","layerNeedsRedraw","sizeChanged","_updateViewport","layersChanged","_updateLayers","needsRedraw","getIntersectingLayers","length","i","map","layer","shouldRedraw","targetBounds","getBounds","targetBoundsCommon","newZoom","Math","ceil","zoom","bounds","oldZoom","renderViewport","newBounds","oldBounds","some","x","fbo","context","gl","props","pickable","pickingFbo","filter","includes","texture","delete","sourceTile","intersect","bbox","parent","b1","b2","west","east","south","north","left","right","top","bottom"],"mappings":";;;;;;;;;;;;;;;AAIA;;AACA;;;;;;;;IAgBaA,Y;AAkBX,wBAAYC,WAAZ,EAAgC;AAAA;AAAA,mDAjBb,IAiBa;AAAA;AAAA,0DAbE,IAaF;AAAA,kDAXR,IAWQ;AAAA;AAAA;AAAA,kD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EC,EAFF,EAGW;AACT,MAAI,UAAUD,EAAV,IAAgB,UAAUC,EAA9B,EAAkC;AAChC,WAAOD,EAAE,CAACE,IAAH,GAAUD,EAAE,CAACE,IAAb,IAAqBF,EAAE,CAACC,IAAH,GAAUF,EAAE,CAACG,IAAlC,IAA0CH,EAAE,CAACI,KAAH,GAAWH,EAAE,CAACI,KAAxD,IAAiEJ,EAAE,CAACG,KAAH,GAAWJ,EAAE,CAACK,KAAtF;AACD;;AACD,MAAI,UAAUL,EAAV,IAAgB,UAAUC,EAA9B,EAAkC;AAChC,WAAOD,EAAE,CAACM,IAAH,GAAUL,EAAE,CAACM,KAAb,IAAsBN,EAAE,CAACK,IAAH,GAAUN,EAAE,CAACO,KAAnC,IAA4CP,EAAE,CAACQ,GAAH,GAASP,EAAE,CAACQ,MAAxD,IAAkER,EAAE,CAACO,GAAH,GAASR,EAAE,CAACS,MAArF;AACD;;AACD,SAAO,KAAP;AACD","sourcesContent":["import {Framebuffer} from '@luma.gl/core';\n\nimport type {Layer, Viewport} from '@deck.gl/core';\n\nimport {createRenderTarget} from './utils';\nimport {joinLayerBounds, makeViewport, getRenderBounds, Bounds} from '../utils/projection-utils';\n\n// TODO - import from loaders when Tileset2D is split out\ntype GeoBoundingBox = {west: number; north: number; east: number; south: number};\ntype NonGeoBoundingBox = {left: number; top: number; right: number; bottom: number};\ntype Tile2DHeader = {\n bbox: GeoBoundingBox | NonGeoBoundingBox;\n};\n\n/**\n * Manages the lifecycle of the terrain cover (draped textures over a terrain mesh).\n * One terrain cover is created for each unique terrain layer (primitive layer with operation:terrain).\n * It is updated when the terrain source layer's mesh changes or when any of the terrainDrawMode:drape\n * layers requires redraw.\n * During the draw call of a terrain layer, the drape texture is overlaid on top of the layer's own color.\n */\nexport class TerrainCover {\n isDirty: boolean = true;\n /** The terrain layer that this instance belongs to */\n targetLayer: Layer;\n /** Viewport used to draw into the texture */\n renderViewport: Viewport | null = null;\n /** Bounds of the terrain cover texture, in cartesian space */\n bounds: Bounds | null = null;\n\n private fbo?: Framebuffer;\n private pickingFbo?: Framebuffer;\n private layers: string[] = [];\n private tile: Tile2DHeader | null;\n /** Cached version of targetLayer.getBounds() */\n private targetBounds: [number[], number[]] | null = null;\n /** targetBounds in cartesian space */\n private targetBoundsCommon: Bounds | null = null;\n\n constructor(targetLayer: Layer) {\n this.targetLayer = targetLayer;\n this.tile = getTile(targetLayer);\n }\n\n get id() {\n return this.targetLayer.id;\n }\n\n /** returns true if the target layer is still in use (i.e. not finalized) */\n get isActive(): boolean {\n return Boolean(this.targetLayer.getCurrentLayer());\n }\n\n shouldUpdate({\n targetLayer,\n viewport,\n layers,\n layerNeedsRedraw\n }: {\n targetLayer?: Layer;\n viewport?: Viewport;\n layers?: Layer[];\n layerNeedsRedraw?: Record<string, boolean>;\n }): boolean {\n if (targetLayer) {\n this.targetLayer = targetLayer;\n }\n const sizeChanged = viewport ? this._updateViewport(viewport) : false;\n\n let layersChanged = layers ? this._updateLayers(layers) : false;\n\n if (layerNeedsRedraw) {\n for (const id of this.layers) {\n if (layerNeedsRedraw[id]) {\n layersChanged = true;\n // console.log('layer needs redraw', id);\n break;\n }\n }\n }\n\n return layersChanged || sizeChanged;\n }\n\n /** Compare layers with the last version. Only rerender if necessary. */\n private _updateLayers(layers: Layer[]): boolean {\n let needsRedraw = false;\n layers = this.tile ? getIntersectingLayers(this.tile, layers) : layers;\n\n if (layers.length !== this.layers.length) {\n needsRedraw = true;\n // console.log('layers count changed', this.layers.length, '>>', layers.length);\n } else {\n for (let i = 0; i < layers.length; i++) {\n const id = layers[i].id;\n if (id !== this.layers[i]) {\n needsRedraw = true;\n // console.log('layer added/removed', id);\n break;\n }\n }\n }\n if (needsRedraw) {\n this.layers = layers.map(layer => layer.id);\n }\n return needsRedraw;\n }\n\n /** Compare viewport and terrain bounds with the last version. Only rerender if necesary. */\n private _updateViewport(viewport: Viewport): boolean {\n const targetLayer = this.targetLayer;\n let shouldRedraw = false;\n\n if (this.targetBounds !== targetLayer.getBounds()) {\n // console.log('bounds changed', this.bounds, '>>', newBounds);\n shouldRedraw = true;\n this.targetBounds = targetLayer.getBounds();\n this.targetBoundsCommon = joinLayerBounds([targetLayer], viewport);\n }\n\n if (!this.targetBoundsCommon) {\n return false;\n }\n\n const newZoom = Math.ceil(viewport.zoom + 0.5);\n // If the terrain layer is bound to a tile, always render a texture that cover the whole tile.\n // Otherwise, use the smaller of layer bounds and the viewport bounds.\n if (this.tile) {\n this.bounds = this.targetBoundsCommon;\n } else {\n const oldZoom = this.renderViewport?.zoom;\n shouldRedraw = shouldRedraw || newZoom !== oldZoom;\n const newBounds = getRenderBounds(this.targetBoundsCommon, viewport);\n const oldBounds = this.bounds;\n shouldRedraw = shouldRedraw || !oldBounds || newBounds.some((x, i) => x !== oldBounds[i]);\n this.bounds = newBounds;\n }\n\n if (shouldRedraw) {\n this.renderViewport = makeViewport({\n bounds: this.bounds,\n zoom: newZoom,\n viewport\n });\n }\n\n return shouldRedraw;\n }\n\n getRenderFramebuffer(): Framebuffer | null {\n if (!this.renderViewport || this.layers.length === 0) {\n return null;\n }\n if (!this.fbo) {\n this.fbo = createRenderTarget(this.targetLayer.context.gl, {id: this.id});\n }\n return this.fbo;\n }\n\n getPickingFramebuffer(): Framebuffer | null {\n if (!this.renderViewport || (this.layers.length === 0 && !this.targetLayer.props.pickable)) {\n return null;\n }\n if (!this.pickingFbo) {\n this.pickingFbo = createRenderTarget(this.targetLayer.context.gl, {id: `${this.id}-picking`});\n }\n return this.pickingFbo;\n }\n\n filterLayers(layers: Layer[]) {\n return layers.filter(({id}) => this.layers.includes(id));\n }\n\n delete() {\n const {fbo, pickingFbo} = this;\n if (fbo) {\n fbo.texture.delete();\n fbo.delete();\n }\n if (pickingFbo) {\n pickingFbo.texture.delete();\n pickingFbo.delete();\n }\n }\n}\n\n/**\n * Remove layers that do not overlap with the current terrain cover.\n * This implementation only has effect when a TileLayer is overlaid on top of a TileLayer\n */\nfunction getIntersectingLayers(sourceTile: Tile2DHeader, layers: Layer[]): Layer[] {\n return layers.filter(layer => {\n const tile = getTile(layer);\n if (tile) {\n return intersect(sourceTile.bbox, tile.bbox);\n }\n return true;\n });\n}\n\n/** If layer is the descendent of a TileLayer, return the corresponding tile. */\nfunction getTile(layer: Layer): Tile2DHeader | null {\n while (layer) {\n // @ts-expect-error tile may not exist\n const {tile} = layer.props;\n if (tile) {\n return tile;\n }\n layer = layer.parent as Layer;\n }\n return null;\n}\n\nfunction intersect(\n b1: GeoBoundingBox | NonGeoBoundingBox,\n b2: GeoBoundingBox | NonGeoBoundingBox\n): boolean {\n if ('west' in b1 && 'west' in b2) {\n return b1.west < b2.east && b2.west < b1.east && b1.south < b2.north && b2.south < b1.north;\n }\n if ('left' in b1 && 'left' in b2) {\n return b1.left < b2.right && b2.left < b1.right && b1.top < b2.bottom && b2.top < b1.bottom;\n }\n return false;\n}\n"],"file":"terrain-cover.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/terrain/terrain-cover.ts"],"names":["TerrainCover","targetLayer","tile","getTile","id","Boolean","getCurrentLayer","viewport","layers","layerNeedsRedraw","sizeChanged","_updateViewport","layersChanged","_updateLayers","needsRedraw","getIntersectingLayers","length","i","map","layer","shouldRedraw","targetBounds","boundingBox","bottomLeftCommon","projectPosition","topRightCommon","targetBoundsCommon","getBounds","newZoom","Math","ceil","zoom","bounds","oldZoom","renderViewport","newBounds","oldBounds","some","x","fbo","context","gl","props","pickable","pickingFbo","filter","includes","texture","delete","sourceTile","intersect","parent","b1","b2"],"mappings":";;;;;;;;;;;;;;;AAIA;;AACA;;;;;;;;IAaaA,Y;AAkBX,wBAAYC,WAAZ,EAAgC;AAAA;AAAA,mDAjBb,IAiBa;AAAA;AAAA,0DAbE,IAaF;AAAA,kDAXR,IAWQ;AAAA;AAAA;AAAA,kDAPL,EAOK;AAAA;AAAA,wDAJoB,IAIpB;AAAA,8DAFY,IAEZ;AAC9B,SAAKA,WAAL,GAAmBA,WAAnB;AACA,SAAKC,IAAL,GAAYC,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AAD,CAApB;;AACA,QAAIjB,IAAJ,EAAU;AACR,aAAOgD,SAAS,CAACD,UAAU,CAAC3B,WAAZ,EAAyBpB,IAAI,CAACoB,WAA9B,CAAhB;AACD;;AACD,WAAO,IAAP;AACD,GANM,CAAP;AAOD;;AAGD,SAASnB,OAAT,CAAiBgB,KAAjB,EAAkD;AAChD,SAAOA,KAAP,EAAc;AAEZ,QAAOjB,IAAP,GAAeiB,KAAK,CAACuB,KAArB,CAAOxC,IAAP;;AACA,QAAIA,IAAJ,EAAU;AACR,aAAOA,IAAP;AACD;;AACDiB,IAAAA,KAAK,GAAGA,KAAK,CAACgC,MAAd;AACD;;AACD,SAAO,IAAP;AACD;;AAED,SAASD,SAAT,CAAmBE,EAAnB,EAA8CC,EAA9C,EAAkF;AAChF,MAAID,EAAE,IAAIC,EAAV,EAAc;AACZ,WAAOD,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,IAAWC,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,CAAX,IAAuBA,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,IAAWD,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,CAAlC,IAA8CA,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,IAAWC,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,CAAzD,IAAqEA,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,IAAWD,EAAE,CAAC,CAAD,CAAF,CAAM,CAAN,CAAvF;AACD;;AACD,SAAO,KAAP;AACD","sourcesContent":["import {Framebuffer} from '@luma.gl/core';\n\nimport type {Layer, Viewport} from '@deck.gl/core';\n\nimport {createRenderTarget} from './utils';\nimport {joinLayerBounds, makeViewport, getRenderBounds, Bounds} from '../utils/projection-utils';\n\ntype TileHeader = {\n boundingBox: [min: number[], max: number[]];\n};\n\n/**\n * Manages the lifecycle of the terrain cover (draped textures over a terrain mesh).\n * One terrain cover is created for each unique terrain layer (primitive layer with operation:terrain).\n * It is updated when the terrain source layer's mesh changes or when any of the terrainDrawMode:drape\n * layers requires redraw.\n * During the draw call of a terrain layer, the drape texture is overlaid on top of the layer's own color.\n */\nexport class TerrainCover {\n isDirty: boolean = true;\n /** The terrain layer that this instance belongs to */\n targetLayer: Layer;\n /** Viewport used to draw into the texture */\n renderViewport: Viewport | null = null;\n /** Bounds of the terrain cover texture, in cartesian space */\n bounds: Bounds | null = null;\n\n private fbo?: Framebuffer;\n private pickingFbo?: Framebuffer;\n private layers: string[] = [];\n private tile: TileHeader | null;\n /** Cached version of targetLayer.getBounds() */\n private targetBounds: [number[], number[]] | null = null;\n /** targetBounds in cartesian space */\n private targetBoundsCommon: Bounds | null = null;\n\n constructor(targetLayer: Layer) {\n this.targetLayer = targetLayer;\n this.tile = getTile(targetLayer);\n }\n\n get id() {\n return this.targetLayer.id;\n }\n\n /** returns true if the target layer is still in use (i.e. not finalized) */\n get isActive(): boolean {\n return Boolean(this.targetLayer.getCurrentLayer());\n }\n\n shouldUpdate({\n targetLayer,\n viewport,\n layers,\n layerNeedsRedraw\n }: {\n targetLayer?: Layer;\n viewport?: Viewport;\n layers?: Layer[];\n layerNeedsRedraw?: Record<string, boolean>;\n }): boolean {\n if (targetLayer) {\n this.targetLayer = targetLayer;\n }\n const sizeChanged = viewport ? this._updateViewport(viewport) : false;\n\n let layersChanged = layers ? this._updateLayers(layers) : false;\n\n if (layerNeedsRedraw) {\n for (const id of this.layers) {\n if (layerNeedsRedraw[id]) {\n layersChanged = true;\n // console.log('layer needs redraw', id);\n break;\n }\n }\n }\n\n return layersChanged || sizeChanged;\n }\n\n /** Compare layers with the last version. Only rerender if necessary. */\n private _updateLayers(layers: Layer[]): boolean {\n let needsRedraw = false;\n layers = this.tile ? getIntersectingLayers(this.tile, layers) : layers;\n\n if (layers.length !== this.layers.length) {\n needsRedraw = true;\n // console.log('layers count changed', this.layers.length, '>>', layers.length);\n } else {\n for (let i = 0; i < layers.length; i++) {\n const id = layers[i].id;\n if (id !== this.layers[i]) {\n needsRedraw = true;\n // console.log('layer added/removed', id);\n break;\n }\n }\n }\n if (needsRedraw) {\n this.layers = layers.map(layer => layer.id);\n }\n return needsRedraw;\n }\n\n /** Compare viewport and terrain bounds with the last version. Only rerender if necesary. */\n private _updateViewport(viewport: Viewport): boolean {\n const targetLayer = this.targetLayer;\n let shouldRedraw = false;\n\n if (this.tile && 'boundingBox' in this.tile) {\n if (!this.targetBounds) {\n shouldRedraw = true;\n this.targetBounds = this.tile.boundingBox;\n\n const bottomLeftCommon = viewport.projectPosition(this.targetBounds[0]);\n const topRightCommon = viewport.projectPosition(this.targetBounds[1]);\n this.targetBoundsCommon = [\n bottomLeftCommon[0],\n bottomLeftCommon[1],\n topRightCommon[0],\n topRightCommon[1]\n ];\n }\n } else if (this.targetBounds !== targetLayer.getBounds()) {\n // console.log('bounds changed', this.bounds, '>>', newBounds);\n shouldRedraw = true;\n this.targetBounds = targetLayer.getBounds();\n this.targetBoundsCommon = joinLayerBounds([targetLayer], viewport);\n }\n\n if (!this.targetBoundsCommon) {\n return false;\n }\n\n const newZoom = Math.ceil(viewport.zoom + 0.5);\n // If the terrain layer is bound to a tile, always render a texture that cover the whole tile.\n // Otherwise, use the smaller of layer bounds and the viewport bounds.\n if (this.tile) {\n this.bounds = this.targetBoundsCommon;\n } else {\n const oldZoom = this.renderViewport?.zoom;\n shouldRedraw = shouldRedraw || newZoom !== oldZoom;\n const newBounds = getRenderBounds(this.targetBoundsCommon, viewport);\n const oldBounds = this.bounds;\n shouldRedraw = shouldRedraw || !oldBounds || newBounds.some((x, i) => x !== oldBounds[i]);\n this.bounds = newBounds;\n }\n\n if (shouldRedraw) {\n this.renderViewport = makeViewport({\n bounds: this.bounds,\n zoom: newZoom,\n viewport\n });\n }\n\n return shouldRedraw;\n }\n\n getRenderFramebuffer(): Framebuffer | null {\n if (!this.renderViewport || this.layers.length === 0) {\n return null;\n }\n if (!this.fbo) {\n this.fbo = createRenderTarget(this.targetLayer.context.gl, {id: this.id});\n }\n return this.fbo;\n }\n\n getPickingFramebuffer(): Framebuffer | null {\n if (!this.renderViewport || (this.layers.length === 0 && !this.targetLayer.props.pickable)) {\n return null;\n }\n if (!this.pickingFbo) {\n this.pickingFbo = createRenderTarget(this.targetLayer.context.gl, {id: `${this.id}-picking`});\n }\n return this.pickingFbo;\n }\n\n filterLayers(layers: Layer[]) {\n return layers.filter(({id}) => this.layers.includes(id));\n }\n\n delete() {\n const {fbo, pickingFbo} = this;\n if (fbo) {\n fbo.texture.delete();\n fbo.delete();\n }\n if (pickingFbo) {\n pickingFbo.texture.delete();\n pickingFbo.delete();\n }\n }\n}\n\n/**\n * Remove layers that do not overlap with the current terrain cover.\n * This implementation only has effect when a TileLayer is overlaid on top of a TileLayer\n */\nfunction getIntersectingLayers(sourceTile: TileHeader, layers: Layer[]): Layer[] {\n return layers.filter(layer => {\n const tile = getTile(layer);\n if (tile) {\n return intersect(sourceTile.boundingBox, tile.boundingBox);\n }\n return true;\n });\n}\n\n/** If layer is the descendent of a TileLayer, return the corresponding tile. */\nfunction getTile(layer: Layer): TileHeader | null {\n while (layer) {\n // @ts-expect-error tile may not exist\n const {tile} = layer.props;\n if (tile) {\n return tile;\n }\n layer = layer.parent as Layer;\n }\n return null;\n}\n\nfunction intersect(b1?: [number[], number[]], b2?: [number[], number[]]): boolean {\n if (b1 && b2) {\n return b1[0][0] < b2[1][0] && b2[0][0] < b1[1][0] && b1[0][1] < b2[1][1] && b2[0][1] < b1[1][1];\n }\n return false;\n}\n"],"file":"terrain-cover.js"}
|
|
@@ -98,6 +98,7 @@ function makeViewport(opts) {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
return isGeospatial ? new _core.WebMercatorViewport({
|
|
101
|
+
id: viewport.id,
|
|
101
102
|
x: border,
|
|
102
103
|
y: border,
|
|
103
104
|
width: width,
|
|
@@ -107,6 +108,7 @@ function makeViewport(opts) {
|
|
|
107
108
|
zoom: zoom,
|
|
108
109
|
orthographic: true
|
|
109
110
|
}) : new _core.OrthographicViewport({
|
|
111
|
+
id: viewport.id,
|
|
110
112
|
x: border,
|
|
111
113
|
y: border,
|
|
112
114
|
width: width,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/projection-utils.ts"],"names":["joinLayerBounds","layers","viewport","bounds","Infinity","layer","layerBounds","getBounds","bottomLeftCommon","projectPosition","autoOffset","topRightCommon","Math","min","max","Number","isFinite","MAX_VIEWPORT_SIZE","makeViewport","opts","border","isGeospatial","centerWorld","unprojectPosition","width","height","zoom","undefined","scale","log2","round","abs","maxSize","r","WebMercatorViewport","x","y","longitude","latitude","orthographic","OrthographicViewport","target","flipY","getViewportBounds","zRange","viewportBoundsWorld","length","minZ","maxZ","bounds0","z","bounds1","viewportBottomLeftCommon","slice","viewportTopRightCommon","getRenderBounds","viewportBounds","paddedBounds","doubleBounds","dx","dy","centerX","centerY"],"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;AAUO,SAASA,eAAT,CAELC,MAFK,EAILC,QAJK,EAKU;AAEf,MAAMC,MAAc,GAAG,CAACC,QAAD,EAAWA,QAAX,EAAqB,CAACA,QAAtB,EAAgC,CAACA,QAAjC,CAAvB;;AAFe,6CAGKH,MAHL;AAAA;;AAAA;AAGf,wDAA4B;AAAA,UAAjBI,KAAiB;AAC1B,UAAMC,WAAW,GAAGD,KAAK,CAACE,SAAN,EAApB;;AACA,UAAID,WAAJ,EAAiB;AACf,YAAME,gBAAgB,GAAGH,KAAK,CAACI,eAAN,CAAsBH,WAAW,CAAC,CAAD,CAAjC,EAAsC;AAACJ,UAAAA,QAAQ,EAARA,QAAD;AAAWQ,UAAAA,UAAU,EAAE;AAAvB,SAAtC,CAAzB;AACA,YAAMC,cAAc,GAAGN,KAAK,CAACI,eAAN,CAAsBH,WAAW,CAAC,CAAD,CAAjC,EAAsC;AAACJ,UAAAA,QAAQ,EAARA,QAAD;AAAWQ,UAAAA,UAAU,EAAE;AAAvB,SAAtC,CAAvB;AAEAP,QAAAA,MAAM,CAAC,CA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AD,CAA7B;AACA,MAAM0D,OAAO,GAAG,CAAC1D,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAAnB,IAA0B,CAA1C;AACA,MAAM2D,OAAO,GAAG,CAAC3D,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAAnB,IAA0B,CAA1C;AACA,SAAO,CAAC0D,OAAO,GAAGF,EAAX,EAAeG,OAAO,GAAGF,EAAzB,EAA6BC,OAAO,GAAGF,EAAvC,EAA2CG,OAAO,GAAGF,EAArD,CAAP;AACD","sourcesContent":["import {WebMercatorViewport, OrthographicViewport} from '@deck.gl/core';\nimport type {Layer, Viewport} from '@deck.gl/core';\n\n/** Bounds in CARTESIAN coordinates */\nexport type Bounds = [minX: number, minY: number, maxX: number, maxY: number];\n\n/*\n * Compute the union of bounds from multiple layers\n * Returns bounds in CARTESIAN coordinates\n */\nexport function joinLayerBounds(\n /** The layers to combine */\n layers: Layer[],\n /** A Viewport instance that is used to determine the type of the view */\n viewport: Viewport\n): Bounds | null {\n // Join the bounds of layer data\n const bounds: Bounds = [Infinity, Infinity, -Infinity, -Infinity];\n for (const layer of layers) {\n const layerBounds = layer.getBounds();\n if (layerBounds) {\n const bottomLeftCommon = layer.projectPosition(layerBounds[0], {viewport, autoOffset: false});\n const topRightCommon = layer.projectPosition(layerBounds[1], {viewport, autoOffset: false});\n\n bounds[0] = Math.min(bounds[0], bottomLeftCommon[0]);\n bounds[1] = Math.min(bounds[1], bottomLeftCommon[1]);\n bounds[2] = Math.max(bounds[2], topRightCommon[0]);\n bounds[3] = Math.max(bounds[3], topRightCommon[1]);\n }\n }\n\n if (Number.isFinite(bounds[0])) {\n return bounds;\n }\n return null;\n}\n\nconst MAX_VIEWPORT_SIZE = 2048;\n\n/** Construct a viewport that just covers the target bounds. Used for rendering to common space indexed texture. */\nexport function makeViewport(opts: {\n /** The cartesian bounds of layers that will render into this texture */\n bounds: Bounds;\n /** Target width. If not specified, will be deduced from zoom */\n width?: number;\n /** Target height. If not specified, will be deduced from zoom */\n height?: number;\n /** Target zoom. If not specified, will be deduced from width and height */\n zoom?: number;\n /** Border around the viewport in pixels */\n border?: number;\n /** A viewport used to determine the output type */\n viewport: Viewport;\n}): Viewport | null {\n const {bounds, viewport, border = 0} = opts;\n const {isGeospatial} = viewport;\n\n if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {\n return null;\n }\n\n const centerWorld = viewport.unprojectPosition([\n (bounds[0] + bounds[2]) / 2,\n (bounds[1] + bounds[3]) / 2,\n 0\n ]);\n\n let {width, height, zoom} = opts;\n if (zoom === undefined) {\n // Use width and height to determine zoom\n width = width! - border * 2;\n height = height! - border * 2;\n const scale = Math.min(width / (bounds[2] - bounds[0]), height / (bounds[3] - bounds[1]));\n zoom = Math.min(Math.log2(scale), 20);\n } else if (!width || !height) {\n // Use zoom to determine width and height\n const scale = 2 ** zoom;\n width = Math.round(Math.abs(bounds[2] - bounds[0]) * scale);\n height = Math.round(Math.abs(bounds[3] - bounds[1]) * scale);\n const maxSize = MAX_VIEWPORT_SIZE - border * 2;\n if (width > maxSize || height > maxSize) {\n const r = maxSize / Math.max(width, height);\n width = Math.round(width * r);\n height = Math.round(height * r);\n zoom += Math.log2(r);\n }\n }\n\n // TODO - find a more generic way to construct this viewport\n // Geospatial viewports may not be web-mercator\n return isGeospatial\n ? new WebMercatorViewport({\n x: border,\n y: border,\n width,\n height,\n longitude: centerWorld[0],\n latitude: centerWorld[1],\n zoom,\n orthographic: true\n })\n : new OrthographicViewport({\n x: border,\n y: border,\n width,\n height,\n target: centerWorld,\n zoom,\n flipY: false\n });\n}\n\n/** Returns viewport bounds in CARTESIAN coordinates */\nexport function getViewportBounds(viewport: Viewport, zRange?: [number, number]): Bounds {\n // Viewport bounds in world coordinates\n let viewportBoundsWorld: Bounds;\n if (zRange && zRange.length === 2) {\n const [minZ, maxZ] = zRange;\n const bounds0 = viewport.getBounds({z: minZ});\n const bounds1 = viewport.getBounds({z: maxZ});\n viewportBoundsWorld = [\n Math.min(bounds0[0], bounds1[0]),\n Math.min(bounds0[1], bounds1[1]),\n Math.max(bounds0[2], bounds1[2]),\n Math.max(bounds0[3], bounds1[3])\n ];\n } else {\n viewportBoundsWorld = viewport.getBounds();\n }\n\n // Viewport bounds in cartesian coordinates\n const viewportBottomLeftCommon = viewport.projectPosition(viewportBoundsWorld.slice(0, 2));\n const viewportTopRightCommon = viewport.projectPosition(viewportBoundsWorld.slice(2, 4));\n return [\n viewportBottomLeftCommon[0],\n viewportBottomLeftCommon[1],\n viewportTopRightCommon[0],\n viewportTopRightCommon[1]\n ];\n}\n\n/*\n * Determine the common space bounds that best cover the given data for the given viewport\n * Returns bounds in CARTESIAN coordinates\n */\nexport function getRenderBounds(\n layerBounds: Bounds,\n viewport: Viewport,\n zRange?: [number, number]\n): Bounds {\n if (!layerBounds) {\n return [0, 0, 1, 1];\n }\n\n const viewportBounds = getViewportBounds(viewport, zRange);\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 layers are smaller than the viewport bounds simply use\n // mask bounds, so as to maximize resolution & avoid rerenders\n if (\n layerBounds[2] - layerBounds[0] <= paddedBounds[2] - paddedBounds[0] &&\n layerBounds[3] - layerBounds[1] <= paddedBounds[3] - paddedBounds[1]\n ) {\n return layerBounds;\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 return [\n Math.max(layerBounds[0], paddedBounds[0]),\n Math.max(layerBounds[1], paddedBounds[1]),\n Math.min(layerBounds[2], paddedBounds[2]),\n Math.min(layerBounds[3], paddedBounds[3])\n ];\n}\n\nfunction doubleBounds(bounds: Bounds): Bounds {\n const dx = bounds[2] - bounds[0];\n const dy = bounds[3] - bounds[1];\n const centerX = (bounds[0] + bounds[2]) / 2;\n const centerY = (bounds[1] + bounds[3]) / 2;\n return [centerX - dx, centerY - dy, centerX + dx, centerY + dy];\n}\n"],"file":"projection-utils.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/projection-utils.ts"],"names":["joinLayerBounds","layers","viewport","bounds","Infinity","layer","layerBounds","getBounds","bottomLeftCommon","projectPosition","autoOffset","topRightCommon","Math","min","max","Number","isFinite","MAX_VIEWPORT_SIZE","makeViewport","opts","border","isGeospatial","centerWorld","unprojectPosition","width","height","zoom","undefined","scale","log2","round","abs","maxSize","r","WebMercatorViewport","id","x","y","longitude","latitude","orthographic","OrthographicViewport","target","flipY","getViewportBounds","zRange","viewportBoundsWorld","length","minZ","maxZ","bounds0","z","bounds1","viewportBottomLeftCommon","slice","viewportTopRightCommon","getRenderBounds","viewportBounds","paddedBounds","doubleBounds","dx","dy","centerX","centerY"],"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;AAUO,SAASA,eAAT,CAELC,MAFK,EAILC,QAJK,EAKU;AAEf,MAAMC,MAAc,GAAG,CAACC,QAAD,EAAWA,QAAX,EAAqB,CAACA,QAAtB,EAAgC,CAACA,QAAjC,CAAvB;;AAFe,6CAGKH,MAHL;AAAA;;AAAA;AAGf,wDAA4B;AAAA,UAAjBI,KAAiB;AAC1B,UAAMC,WAAW,GAAGD,KAAK,CAACE,SAAN,EAApB;;AACA,UAAID,WAAJ,EAAiB;AACf,YAAME,gBAAgB,GAAGH,KAAK,CAACI,eAAN,CAAsBH,WAAW,CAAC,CAAD,CAAjC,EAAsC;AAACJ,UAAAA,QAAQ,EAARA,QAAD;AAAWQ,UAAAA,UAAU,EAAE;AAAvB,SAAtC,CAAzB;AACA,YAAMC,cAAc,GAAGN,KAAK,CAACI,eAAN,CAAsBH,WAAW,CAAC,CAAD,CAAjC,EAAsC;AAACJ,UAAAA,QAAQ,EAARA,QAAD;AAAWQ,UAAAA,UAAU,EAAE;AAAvB,SAAtC,CAAvB;AAEAP,QAAAA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CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAA7B;AACA,MAAM0D,EAAE,GAAG1D,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAA7B;AACA,MAAM2D,OAAO,GAAG,CAAC3D,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAAnB,IAA0B,CAA1C;AACA,MAAM4D,OAAO,GAAG,CAAC5D,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAAnB,IAA0B,CAA1C;AACA,SAAO,CAAC2D,OAAO,GAAGF,EAAX,EAAeG,OAAO,GAAGF,EAAzB,EAA6BC,OAAO,GAAGF,EAAvC,EAA2CG,OAAO,GAAGF,EAArD,CAAP;AACD","sourcesContent":["import {WebMercatorViewport, OrthographicViewport} from '@deck.gl/core';\nimport type {Layer, Viewport} from '@deck.gl/core';\n\n/** Bounds in CARTESIAN coordinates */\nexport type Bounds = [minX: number, minY: number, maxX: number, maxY: number];\n\n/*\n * Compute the union of bounds from multiple layers\n * Returns bounds in CARTESIAN coordinates\n */\nexport function joinLayerBounds(\n /** The layers to combine */\n layers: Layer[],\n /** A Viewport instance that is used to determine the type of the view */\n viewport: Viewport\n): Bounds | null {\n // Join the bounds of layer data\n const bounds: Bounds = [Infinity, Infinity, -Infinity, -Infinity];\n for (const layer of layers) {\n const layerBounds = layer.getBounds();\n if (layerBounds) {\n const bottomLeftCommon = layer.projectPosition(layerBounds[0], {viewport, autoOffset: false});\n const topRightCommon = layer.projectPosition(layerBounds[1], {viewport, autoOffset: false});\n\n bounds[0] = Math.min(bounds[0], bottomLeftCommon[0]);\n bounds[1] = Math.min(bounds[1], bottomLeftCommon[1]);\n bounds[2] = Math.max(bounds[2], topRightCommon[0]);\n bounds[3] = Math.max(bounds[3], topRightCommon[1]);\n }\n }\n\n if (Number.isFinite(bounds[0])) {\n return bounds;\n }\n return null;\n}\n\nconst MAX_VIEWPORT_SIZE = 2048;\n\n/** Construct a viewport that just covers the target bounds. Used for rendering to common space indexed texture. */\nexport function makeViewport(opts: {\n /** The cartesian bounds of layers that will render into this texture */\n bounds: Bounds;\n /** Target width. If not specified, will be deduced from zoom */\n width?: number;\n /** Target height. If not specified, will be deduced from zoom */\n height?: number;\n /** Target zoom. If not specified, will be deduced from width and height */\n zoom?: number;\n /** Border around the viewport in pixels */\n border?: number;\n /** A viewport used to determine the output type */\n viewport: Viewport;\n}): Viewport | null {\n const {bounds, viewport, border = 0} = opts;\n const {isGeospatial} = viewport;\n\n if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {\n return null;\n }\n\n const centerWorld = viewport.unprojectPosition([\n (bounds[0] + bounds[2]) / 2,\n (bounds[1] + bounds[3]) / 2,\n 0\n ]);\n\n let {width, height, zoom} = opts;\n if (zoom === undefined) {\n // Use width and height to determine zoom\n width = width! - border * 2;\n height = height! - border * 2;\n const scale = Math.min(width / (bounds[2] - bounds[0]), height / (bounds[3] - bounds[1]));\n zoom = Math.min(Math.log2(scale), 20);\n } else if (!width || !height) {\n // Use zoom to determine width and height\n const scale = 2 ** zoom;\n width = Math.round(Math.abs(bounds[2] - bounds[0]) * scale);\n height = Math.round(Math.abs(bounds[3] - bounds[1]) * scale);\n const maxSize = MAX_VIEWPORT_SIZE - border * 2;\n if (width > maxSize || height > maxSize) {\n const r = maxSize / Math.max(width, height);\n width = Math.round(width * r);\n height = Math.round(height * r);\n zoom += Math.log2(r);\n }\n }\n\n // TODO - find a more generic way to construct this viewport\n // Geospatial viewports may not be web-mercator\n return isGeospatial\n ? new WebMercatorViewport({\n id: viewport.id,\n x: border,\n y: border,\n width,\n height,\n longitude: centerWorld[0],\n latitude: centerWorld[1],\n zoom,\n orthographic: true\n })\n : new OrthographicViewport({\n id: viewport.id,\n x: border,\n y: border,\n width,\n height,\n target: centerWorld,\n zoom,\n flipY: false\n });\n}\n\n/** Returns viewport bounds in CARTESIAN coordinates */\nexport function getViewportBounds(viewport: Viewport, zRange?: [number, number]): Bounds {\n // Viewport bounds in world coordinates\n let viewportBoundsWorld: Bounds;\n if (zRange && zRange.length === 2) {\n const [minZ, maxZ] = zRange;\n const bounds0 = viewport.getBounds({z: minZ});\n const bounds1 = viewport.getBounds({z: maxZ});\n viewportBoundsWorld = [\n Math.min(bounds0[0], bounds1[0]),\n Math.min(bounds0[1], bounds1[1]),\n Math.max(bounds0[2], bounds1[2]),\n Math.max(bounds0[3], bounds1[3])\n ];\n } else {\n viewportBoundsWorld = viewport.getBounds();\n }\n\n // Viewport bounds in cartesian coordinates\n const viewportBottomLeftCommon = viewport.projectPosition(viewportBoundsWorld.slice(0, 2));\n const viewportTopRightCommon = viewport.projectPosition(viewportBoundsWorld.slice(2, 4));\n return [\n viewportBottomLeftCommon[0],\n viewportBottomLeftCommon[1],\n viewportTopRightCommon[0],\n viewportTopRightCommon[1]\n ];\n}\n\n/*\n * Determine the common space bounds that best cover the given data for the given viewport\n * Returns bounds in CARTESIAN coordinates\n */\nexport function getRenderBounds(\n layerBounds: Bounds,\n viewport: Viewport,\n zRange?: [number, number]\n): Bounds {\n if (!layerBounds) {\n return [0, 0, 1, 1];\n }\n\n const viewportBounds = getViewportBounds(viewport, zRange);\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 layers are smaller than the viewport bounds simply use\n // mask bounds, so as to maximize resolution & avoid rerenders\n if (\n layerBounds[2] - layerBounds[0] <= paddedBounds[2] - paddedBounds[0] &&\n layerBounds[3] - layerBounds[1] <= paddedBounds[3] - paddedBounds[1]\n ) {\n return layerBounds;\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 return [\n Math.max(layerBounds[0], paddedBounds[0]),\n Math.max(layerBounds[1], paddedBounds[1]),\n Math.min(layerBounds[2], paddedBounds[2]),\n Math.min(layerBounds[3], paddedBounds[3])\n ];\n}\n\nfunction doubleBounds(bounds: Bounds): Bounds {\n const dx = bounds[2] - bounds[0];\n const dy = bounds[3] - bounds[1];\n const centerX = (bounds[0] + bounds[2]) / 2;\n const centerY = (bounds[1] + bounds[3]) / 2;\n return [centerX - dx, centerY - dy, centerX + dx, centerY + dy];\n}\n"],"file":"projection-utils.js"}
|
|
@@ -63,6 +63,12 @@ export class HeightMapBuilder {
|
|
|
63
63
|
this.renderViewport = null;
|
|
64
64
|
} else if (layersChanged || viewportChanged) {
|
|
65
65
|
const bounds = getRenderBounds(this.layersBoundsCommon, viewport);
|
|
66
|
+
|
|
67
|
+
if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {
|
|
68
|
+
this.renderViewport = null;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
66
72
|
this.bounds = bounds;
|
|
67
73
|
this.lastViewport = viewport;
|
|
68
74
|
const scale = viewport.scale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/terrain/height-map-builder.ts"],"names":["Framebuffer","joinLayerBounds","getRenderBounds","makeViewport","createRenderTarget","MAP_MAX_SIZE","HeightMapBuilder","isSupported","gl","colorBufferFloat","constructor","getRenderFramebuffer","renderViewport","fbo","id","float","shouldUpdate","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","delete","color"],"mappings":";AAAA,SAAQA,WAAR,QAA0B,eAA1B;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,YAA1C,QAAqE,2BAArE;AACA,SAAQC,kBAAR,QAAiC,SAAjC;AAIA,MAAMC,YAAY,GAAG,IAArB;AASA,OAAO,MAAMC,gBAAN,CAAuB;AAgBV,SAAXC,WAAW,CAACC,EAAD,EAAqC;AACrD,WAAOR,WAAW,CAACO,WAAZ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,GAAG,CAAC,KAAKC,YAAN,IAAsB,CAACb,QAAQ,CAACc,MAAT,CAAgB,KAAKD,YAArB,CAA/C;;AAEA,QAAI,CAAC,KAAKF,kBAAV,EAA8B;AAC5B,WAAKjB,cAAL,GAAsB,IAAtB;AACD,KAFD,MAEO,IAAIO,aAAa,IAAIW,eAArB,EAAsC;AAC3C,YAAMG,MAAM,GAAG/B,eAAe,CAAC,KAAK2B,kBAAN,EAA0BX,QAA1B,CAA9B;AACA,
|
|
1
|
+
{"version":3,"sources":["../../../src/terrain/height-map-builder.ts"],"names":["Framebuffer","joinLayerBounds","getRenderBounds","makeViewport","createRenderTarget","MAP_MAX_SIZE","HeightMapBuilder","isSupported","gl","colorBufferFloat","constructor","getRenderFramebuffer","renderViewport","fbo","id","float","shouldUpdate","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","delete","color"],"mappings":";AAAA,SAAQA,WAAR,QAA0B,eAA1B;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,YAA1C,QAAqE,2BAArE;AACA,SAAQC,kBAAR,QAAiC,SAAjC;AAIA,MAAMC,YAAY,GAAG,IAArB;AASA,OAAO,MAAMC,gBAAN,CAAuB;AAgBV,SAAXC,WAAW,CAACC,EAAD,EAAqC;AACrD,WAAOR,WAAW,CAACO,WAAZ,CAAwBC,EAAxB,EAA4B;AAACC,MAAAA,gBAAgB,EAAE;AAAnB,KAA5B,CAAP;AACD;;AAEDC,EAAAA,WAAW,CAACF,EAAD,EAA4B;AAAA,4CAlBL,IAkBK;;AAAA,oCAhBf,IAgBe;;AAAA;;AAAA;;AAAA,oCAXb,EAWa;;AAAA,0CATiB,EASjB;;AAAA,gDAPK,IAOL;;AAAA,0CANC,IAMD;;AACrC,SAAKA,EAAL,GAAUA,EAAV;AACD;;AAKDG,EAAAA,oBAAoB,GAAuB;AACzC,QA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;AACA,WAAK9B,GAAL,CAAS8B,MAAT;AACD;AACF;;AA5G2B","sourcesContent":["import {Framebuffer} from '@luma.gl/core';\nimport {joinLayerBounds, getRenderBounds, makeViewport, Bounds} from '../utils/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 terrainDrawMode: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 if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {\n this.renderViewport = null;\n return false;\n }\n\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"}
|
|
@@ -14,7 +14,7 @@ export const terrainModule = {
|
|
|
14
14
|
inject: {
|
|
15
15
|
'vs:#decl': "\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n".concat(TERRAIN_MODE_CONSTANTS, "\n "),
|
|
16
16
|
'vs:#main-start': "\nif (terrain_mode == TERRAIN_MODE_SKIP) {\n gl_Position = vec4(0.0);\n return;\n}\n",
|
|
17
|
-
'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 ",
|
|
17
|
+
'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 commonPos.z += project_uCommonOrigin.z;\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 ",
|
|
18
18
|
'fs:#decl': "\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n".concat(TERRAIN_MODE_CONSTANTS, "\n "),
|
|
19
19
|
'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 ",
|
|
20
20
|
'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 "
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/terrain/shader-module.ts"],"names":["project","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","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":"AAEA,SAAQA,OAAR,QAAsB,eAAtB;AAoBA,OAAO,MAAMC,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,MAAMC,sBAAsB,GAAGC,MAAM,CAACC,IAAP,CAAYT,YAAZ,EAC5BU,GAD4B,CACxBC,GAAG,uCAAgCA,GAAhC,gBAAyCX,YAAY,CAACW,GAAD,CAArD,QADqB,EAE5BC,IAF4B,CAEvB,IAFuB,CAA/B;AAIA,OAAO,MAAMC,aAAa,GAAG;AAC3BC,EAAAA,IAAI,EAAE,SADqB;AAE3BC,EAAAA,YAAY,EAAE,CAAChB,OAAD,CAFa;AAG3BiB,EAAAA,MAAM,EAAE;AACN,gJAKFT,sBALE,WADM;AAQN,8GARM;AAcN,
|
|
1
|
+
{"version":3,"sources":["../../../src/terrain/shader-module.ts"],"names":["project","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","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":"AAEA,SAAQA,OAAR,QAAsB,eAAtB;AAoBA,OAAO,MAAMC,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,MAAMC,sBAAsB,GAAGC,MAAM,CAACC,IAAP,CAAYT,YAAZ,EAC5BU,GAD4B,CACxBC,GAAG,uCAAgCA,GAAhC,gBAAyCX,YAAY,CAACW,GAAD,CAArD,QADqB,EAE5BC,IAF4B,CAEvB,IAFuB,CAA/B;AAIA,OAAO,MAAMC,aAAa,GAAG;AAC3BC,EAAAA,IAAI,EAAE,SADqB;AAE3BC,EAAAA,YAAY,EAAE,CA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AI,GAAGA,IAAI,KAAK5B,YAAY,CAACM,IAAtB,GAA6BN,YAAY,CAACK,cAA1C,GAA2DL,YAAY,CAACI,SAA/E;AACA0B,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;AA3H0B,CAAtB","sourcesContent":["/* eslint-disable camelcase */\n\nimport {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 '../utils/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 commonPos.z += project_uCommonOrigin.z;\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 // eslint-disable-next-line complexity\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"}
|
|
@@ -88,7 +88,15 @@ export class TerrainCover {
|
|
|
88
88
|
const targetLayer = this.targetLayer;
|
|
89
89
|
let shouldRedraw = false;
|
|
90
90
|
|
|
91
|
-
if (this.
|
|
91
|
+
if (this.tile && 'boundingBox' in this.tile) {
|
|
92
|
+
if (!this.targetBounds) {
|
|
93
|
+
shouldRedraw = true;
|
|
94
|
+
this.targetBounds = this.tile.boundingBox;
|
|
95
|
+
const bottomLeftCommon = viewport.projectPosition(this.targetBounds[0]);
|
|
96
|
+
const topRightCommon = viewport.projectPosition(this.targetBounds[1]);
|
|
97
|
+
this.targetBoundsCommon = [bottomLeftCommon[0], bottomLeftCommon[1], topRightCommon[0], topRightCommon[1]];
|
|
98
|
+
}
|
|
99
|
+
} else if (this.targetBounds !== targetLayer.getBounds()) {
|
|
92
100
|
shouldRedraw = true;
|
|
93
101
|
this.targetBounds = targetLayer.getBounds();
|
|
94
102
|
this.targetBoundsCommon = joinLayerBounds([targetLayer], viewport);
|
|
@@ -182,7 +190,7 @@ function getIntersectingLayers(sourceTile, layers) {
|
|
|
182
190
|
const tile = getTile(layer);
|
|
183
191
|
|
|
184
192
|
if (tile) {
|
|
185
|
-
return intersect(sourceTile.
|
|
193
|
+
return intersect(sourceTile.boundingBox, tile.boundingBox);
|
|
186
194
|
}
|
|
187
195
|
|
|
188
196
|
return true;
|
|
@@ -206,12 +214,8 @@ function getTile(layer) {
|
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
function intersect(b1, b2) {
|
|
209
|
-
if (
|
|
210
|
-
return b1
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if ('left' in b1 && 'left' in b2) {
|
|
214
|
-
return b1.left < b2.right && b2.left < b1.right && b1.top < b2.bottom && b2.top < b1.bottom;
|
|
217
|
+
if (b1 && b2) {
|
|
218
|
+
return b1[0][0] < b2[1][0] && b2[0][0] < b1[1][0] && b1[0][1] < b2[1][1] && b2[0][1] < b1[1][1];
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
return false;
|