bruce-cesium 7.2.9 → 7.3.0
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/bruce-cesium.es5.js +499 -22
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +497 -20
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/bruce-cesium.js +1 -1
- package/dist/lib/rendering/displaced-surface-primitive.js +468 -19
- package/dist/lib/rendering/displaced-surface-primitive.js.map +1 -1
- package/dist/lib/rendering/entity-render-engine-polygon.js +28 -0
- package/dist/lib/rendering/entity-render-engine-polygon.js.map +1 -1
- package/dist/types/bruce-cesium.d.ts +1 -1
- package/dist/types/rendering/displaced-surface-primitive.d.ts +42 -1
- package/dist/types/rendering/entity-render-engine-polygon.d.ts +15 -0
- package/package.json +1 -1
package/dist/bruce-cesium.umd.js
CHANGED
|
@@ -42366,6 +42366,17 @@
|
|
|
42366
42366
|
// Most-detailed would fetch every tile under a parcel that can be a hundred kilometres across.
|
|
42367
42367
|
const GROUND_SAMPLE_LEVEL = 11;
|
|
42368
42368
|
// Height window the packed ground texture covers, wide enough for any terrain on Earth.
|
|
42369
|
+
// Ground samples across the clearance regions rather than the whole extent.
|
|
42370
|
+
const MASK_GROUND_SAMPLES_PER_SIDE = 128;
|
|
42371
|
+
// Finest and coarsest terrain level a clearance raster is sampled at, and how many terrain tiles it is allowed to pull.
|
|
42372
|
+
const MASK_GROUND_LEVEL_MAX = 13;
|
|
42373
|
+
const MASK_GROUND_LEVEL_MIN = 8;
|
|
42374
|
+
const MASK_GROUND_TILE_BUDGET = 64;
|
|
42375
|
+
// Longest side of the rasterised region mask. The mask decides whether a texel is held up, so it
|
|
42376
|
+
// wants to be finer than the value raster it is compared against.
|
|
42377
|
+
const MASK_TEXTURE_MAX_SIDE = 1024;
|
|
42378
|
+
// Stands in for "no floor" and "no clearance", far below anything the sheet can reach.
|
|
42379
|
+
const NO_LIMIT_METRES = -1e6;
|
|
42369
42380
|
const GROUND_MIN_METRES = -1000;
|
|
42370
42381
|
const GROUND_MAX_METRES = 9000;
|
|
42371
42382
|
const DEFAULT_LOW_COLOR = { red: 255, green: 255, blue: 255, alpha: 0.12 };
|
|
@@ -42388,6 +42399,19 @@ uniform float u_skirtDepth;
|
|
|
42388
42399
|
uniform float u_groundWeight;
|
|
42389
42400
|
uniform vec2 u_groundRange;
|
|
42390
42401
|
uniform vec2 u_groundSize;
|
|
42402
|
+
uniform sampler2D u_maskTexture;
|
|
42403
|
+
uniform sampler2D u_maskGroundTexture;
|
|
42404
|
+
uniform float u_maskWeight;
|
|
42405
|
+
uniform float u_maskGroundWeight;
|
|
42406
|
+
uniform float u_maskFill;
|
|
42407
|
+
uniform float u_maskFillValue;
|
|
42408
|
+
uniform float u_maskClearance;
|
|
42409
|
+
uniform float u_maskFloor;
|
|
42410
|
+
uniform vec2 u_maskGroundSize;
|
|
42411
|
+
// West, East, North, South in degrees, for the surface and for the sampled region box.
|
|
42412
|
+
uniform vec4 u_extentDegrees;
|
|
42413
|
+
uniform vec4 u_maskGroundDegrees;
|
|
42414
|
+
uniform float u_coverageCutoffVertex;
|
|
42391
42415
|
|
|
42392
42416
|
out vec2 v_st;
|
|
42393
42417
|
out float v_value;
|
|
@@ -42417,6 +42441,46 @@ float sampleGround(vec2 uv) {
|
|
|
42417
42441
|
return mix(mix(h00, h10, f.x), mix(h01, h11, f.x), f.y);
|
|
42418
42442
|
}
|
|
42419
42443
|
|
|
42444
|
+
/*
|
|
42445
|
+
* Height of the terrain under a point of the surface, read from the region's own ground raster.
|
|
42446
|
+
*
|
|
42447
|
+
* Sampled over the regions rather than over the whole extent, so the raster is fine enough for a
|
|
42448
|
+
* clearance test to mean something.
|
|
42449
|
+
*/
|
|
42450
|
+
float sampleMaskGround(vec2 uv) {
|
|
42451
|
+
float longitude = mix(u_extentDegrees.x, u_extentDegrees.y, uv.x);
|
|
42452
|
+
float latitude = mix(u_extentDegrees.z, u_extentDegrees.w, uv.y);
|
|
42453
|
+
vec2 inBox = vec2(
|
|
42454
|
+
(longitude - u_maskGroundDegrees.x) / max(u_maskGroundDegrees.y - u_maskGroundDegrees.x, 1e-9),
|
|
42455
|
+
(u_maskGroundDegrees.z - latitude) / max(u_maskGroundDegrees.z - u_maskGroundDegrees.w, 1e-9));
|
|
42456
|
+
vec2 clamped = clamp(inBox, vec2(0.0), vec2(1.0));
|
|
42457
|
+
vec2 texel = 1.0 / u_maskGroundSize;
|
|
42458
|
+
vec2 coord = clamped * u_maskGroundSize - 0.5;
|
|
42459
|
+
vec2 base = floor(coord);
|
|
42460
|
+
vec2 f = coord - base;
|
|
42461
|
+
vec2 origin = (base + 0.5) * texel;
|
|
42462
|
+
vec4 t00 = texture(u_maskGroundTexture, origin);
|
|
42463
|
+
vec4 t10 = texture(u_maskGroundTexture, origin + vec2(texel.x, 0.0));
|
|
42464
|
+
vec4 t01 = texture(u_maskGroundTexture, origin + vec2(0.0, texel.y));
|
|
42465
|
+
vec4 t11 = texture(u_maskGroundTexture, origin + texel);
|
|
42466
|
+
// One unknown corner makes the interpolation meaningless, so the whole point is treated as
|
|
42467
|
+
// unsampled and answers low enough that no clearance built on it can win.
|
|
42468
|
+
float known = min(min(t00.a, t10.a), min(t01.a, t11.a));
|
|
42469
|
+
if (known < 0.5) {
|
|
42470
|
+
return u_groundRange.x;
|
|
42471
|
+
}
|
|
42472
|
+
vec3 p00 = t00.rgb * 255.0;
|
|
42473
|
+
vec3 p10 = t10.rgb * 255.0;
|
|
42474
|
+
vec3 p01 = t01.rgb * 255.0;
|
|
42475
|
+
vec3 p11 = t11.rgb * 255.0;
|
|
42476
|
+
vec3 weights = vec3(65536.0, 256.0, 1.0);
|
|
42477
|
+
float h00 = u_groundRange.x + dot(p00, weights) / 16777215.0 * (u_groundRange.y - u_groundRange.x);
|
|
42478
|
+
float h10 = u_groundRange.x + dot(p10, weights) / 16777215.0 * (u_groundRange.y - u_groundRange.x);
|
|
42479
|
+
float h01 = u_groundRange.x + dot(p01, weights) / 16777215.0 * (u_groundRange.y - u_groundRange.x);
|
|
42480
|
+
float h11 = u_groundRange.x + dot(p11, weights) / 16777215.0 * (u_groundRange.y - u_groundRange.x);
|
|
42481
|
+
return mix(mix(h00, h10, f.x), mix(h01, h11, f.x), f.y);
|
|
42482
|
+
}
|
|
42483
|
+
|
|
42420
42484
|
/*
|
|
42421
42485
|
* The texel's normalised value, whichever way the archive packed it.
|
|
42422
42486
|
*
|
|
@@ -42436,8 +42500,16 @@ float decodeValue(vec4 texel) {
|
|
|
42436
42500
|
void main() {
|
|
42437
42501
|
vec4 texel = texture(u_valueTexture, st);
|
|
42438
42502
|
v_st = st;
|
|
42439
|
-
|
|
42440
|
-
|
|
42503
|
+
|
|
42504
|
+
// Inside a region the scene knows is water, a texel with no value still has to paint, or the
|
|
42505
|
+
// hole the region exists to close is still a hole.
|
|
42506
|
+
// The value it paints is the shallowest the ramp is not transparent at.
|
|
42507
|
+
float inMask = u_maskWeight * texture(u_maskTexture, st).a;
|
|
42508
|
+
float hasData = step(u_coverageCutoffVertex, texel.a);
|
|
42509
|
+
float raw = decodeValue(texel);
|
|
42510
|
+
float filled = mix(u_maskFillValue, max(raw, u_maskFillValue), hasData);
|
|
42511
|
+
v_value = mix(raw, filled, inMask * u_maskFill);
|
|
42512
|
+
v_coverage = max(texel.a, inMask * u_maskFill);
|
|
42441
42513
|
|
|
42442
42514
|
// Exaggeration stretches the span above the archive's minimum rather than the height itself. On an
|
|
42443
42515
|
// elevation the height is measured from the ellipsoid, tens of metres from any of the data, so
|
|
@@ -42450,8 +42522,14 @@ void main() {
|
|
|
42450
42522
|
|
|
42451
42523
|
// Coverage scales the displacement only where it is measured from the terrain, because there a
|
|
42452
42524
|
// zero means the surface sits on the ground.
|
|
42453
|
-
float coverageScale = mix(1.0,
|
|
42454
|
-
float
|
|
42525
|
+
float coverageScale = mix(1.0, v_coverage, u_groundWeight);
|
|
42526
|
+
float placed = u_baseHeight + ground + metres * coverageScale;
|
|
42527
|
+
|
|
42528
|
+
// Held above whichever is higher, the region's own floor or the terrain under it plus a margin.
|
|
42529
|
+
// Only inside the region: lifting the whole sheet would raise it over dry land as well.
|
|
42530
|
+
float held = max(u_maskFloor, sampleMaskGround(st) * u_maskGroundWeight + u_maskClearance);
|
|
42531
|
+
float lifted = mix(placed, max(placed, held), step(0.5, inMask));
|
|
42532
|
+
float displacement = lifted - skirt * u_skirtDepth;
|
|
42455
42533
|
|
|
42456
42534
|
// Added to the LOW half of the encoded position: a metre-scale offset added to the high half
|
|
42457
42535
|
// would be lost to float32 rounding at an earth radius.
|
|
@@ -42686,6 +42764,147 @@ void main() {
|
|
|
42686
42764
|
Cesium.GeometryPipeline.encodeAttribute(geometry, "position", "position3DHigh", "position3DLow");
|
|
42687
42765
|
return geometry;
|
|
42688
42766
|
}
|
|
42767
|
+
/*
|
|
42768
|
+
* Where the ramp first paints something, as a normalised value.
|
|
42769
|
+
*
|
|
42770
|
+
* A style with a hidden floor is transparent over its lowest band, so filling a gap at zero would
|
|
42771
|
+
* fill it with nothing. This is the lowest value that actually shows.
|
|
42772
|
+
*/
|
|
42773
|
+
function firstOpaqueStop(ramp) {
|
|
42774
|
+
const stops = ramp.length / 4;
|
|
42775
|
+
for (let i = 0; i < stops; i++) {
|
|
42776
|
+
if (ramp[i * 4 + 3] > 0) {
|
|
42777
|
+
return stops > 1 ? i / (stops - 1) : 0;
|
|
42778
|
+
}
|
|
42779
|
+
}
|
|
42780
|
+
return 0;
|
|
42781
|
+
}
|
|
42782
|
+
/*
|
|
42783
|
+
* Rasterises the clearance regions into a mask over the surface's extent, alpha inside.
|
|
42784
|
+
*
|
|
42785
|
+
* Drawn north row first, matching the value raster's own row order, so one set of texture
|
|
42786
|
+
* coordinates indexes both.
|
|
42787
|
+
*/
|
|
42788
|
+
function rasteriseMask(extent, regions) {
|
|
42789
|
+
const spanX = extent.East - extent.West;
|
|
42790
|
+
const spanY = extent.North - extent.South;
|
|
42791
|
+
if (!(spanX > 0) || !(spanY > 0) || !regions.length) {
|
|
42792
|
+
return null;
|
|
42793
|
+
}
|
|
42794
|
+
// No document at all off the page, and the regions are still worth holding: the mask can be
|
|
42795
|
+
// rasterised the next time they are set, and until then the surface simply lifts nothing.
|
|
42796
|
+
if (typeof document === "undefined") {
|
|
42797
|
+
return null;
|
|
42798
|
+
}
|
|
42799
|
+
const wide = spanX >= spanY;
|
|
42800
|
+
const width = wide ? MASK_TEXTURE_MAX_SIDE : Math.max(1, Math.round(MASK_TEXTURE_MAX_SIDE * spanX / spanY));
|
|
42801
|
+
const height = wide ? Math.max(1, Math.round(MASK_TEXTURE_MAX_SIDE * spanY / spanX)) : MASK_TEXTURE_MAX_SIDE;
|
|
42802
|
+
const canvas = document.createElement("canvas");
|
|
42803
|
+
canvas.width = width;
|
|
42804
|
+
canvas.height = height;
|
|
42805
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
42806
|
+
if (!ctx) {
|
|
42807
|
+
return null;
|
|
42808
|
+
}
|
|
42809
|
+
ctx.clearRect(0, 0, width, height);
|
|
42810
|
+
ctx.fillStyle = "#ffffff";
|
|
42811
|
+
for (const region of regions) {
|
|
42812
|
+
const rings = region.rings || [];
|
|
42813
|
+
if (!rings.length) {
|
|
42814
|
+
continue;
|
|
42815
|
+
}
|
|
42816
|
+
ctx.beginPath();
|
|
42817
|
+
for (const ring of rings) {
|
|
42818
|
+
for (let i = 0; i + 1 < ring.length; i += 2) {
|
|
42819
|
+
const x = (ring[i] - extent.West) / spanX * width;
|
|
42820
|
+
const y = (extent.North - ring[i + 1]) / spanY * height;
|
|
42821
|
+
if (i === 0) {
|
|
42822
|
+
ctx.moveTo(x, y);
|
|
42823
|
+
}
|
|
42824
|
+
else {
|
|
42825
|
+
ctx.lineTo(x, y);
|
|
42826
|
+
}
|
|
42827
|
+
}
|
|
42828
|
+
ctx.closePath();
|
|
42829
|
+
}
|
|
42830
|
+
// Even odd, so a ring inside a ring is a hole without the caller having to wind them.
|
|
42831
|
+
ctx.fill("evenodd");
|
|
42832
|
+
}
|
|
42833
|
+
return { width, height, data: new Uint8Array(ctx.getImageData(0, 0, width, height).data.buffer.slice(0)) };
|
|
42834
|
+
}
|
|
42835
|
+
/*
|
|
42836
|
+
* The box every region fits inside, clipped to the surface, so the ground under them can be
|
|
42837
|
+
* sampled without sampling the whole extent.
|
|
42838
|
+
*/
|
|
42839
|
+
function boxOf(extent, regions) {
|
|
42840
|
+
let west = Infinity;
|
|
42841
|
+
let east = -Infinity;
|
|
42842
|
+
let south = Infinity;
|
|
42843
|
+
let north = -Infinity;
|
|
42844
|
+
for (const region of regions) {
|
|
42845
|
+
for (const ring of region.rings || []) {
|
|
42846
|
+
for (let i = 0; i + 1 < ring.length; i += 2) {
|
|
42847
|
+
west = Math.min(west, ring[i]);
|
|
42848
|
+
east = Math.max(east, ring[i]);
|
|
42849
|
+
south = Math.min(south, ring[i + 1]);
|
|
42850
|
+
north = Math.max(north, ring[i + 1]);
|
|
42851
|
+
}
|
|
42852
|
+
}
|
|
42853
|
+
}
|
|
42854
|
+
if (!isFinite(west) || !isFinite(south)) {
|
|
42855
|
+
return null;
|
|
42856
|
+
}
|
|
42857
|
+
return {
|
|
42858
|
+
West: Math.max(west, extent.West),
|
|
42859
|
+
East: Math.min(east, extent.East),
|
|
42860
|
+
South: Math.max(south, extent.South),
|
|
42861
|
+
North: Math.min(north, extent.North)
|
|
42862
|
+
};
|
|
42863
|
+
}
|
|
42864
|
+
/*
|
|
42865
|
+
* Packs sampled terrain heights into a texture's RGB, three bytes a height.
|
|
42866
|
+
*
|
|
42867
|
+
* A height needs more than eight bits to be useful and the surface reads it in the vertex shader,
|
|
42868
|
+
* where float textures are not guaranteed, so it goes in as a fixed point integer.
|
|
42869
|
+
*/
|
|
42870
|
+
function packHeights(sampled) {
|
|
42871
|
+
const pixels = new Uint8Array(sampled.length * 4);
|
|
42872
|
+
const span = GROUND_MAX_METRES - GROUND_MIN_METRES;
|
|
42873
|
+
for (let i = 0; i < sampled.length; i++) {
|
|
42874
|
+
const height = sampled[i] ? sampled[i].height : undefined;
|
|
42875
|
+
const known = typeof height === "number" && isFinite(height);
|
|
42876
|
+
const clamped = Math.min(GROUND_MAX_METRES, Math.max(GROUND_MIN_METRES, known ? height : 0));
|
|
42877
|
+
const packed = Math.round(((clamped - GROUND_MIN_METRES) / span) * 16777215);
|
|
42878
|
+
pixels[i * 4] = (packed >> 16) & 255;
|
|
42879
|
+
pixels[i * 4 + 1] = (packed >> 8) & 255;
|
|
42880
|
+
pixels[i * 4 + 2] = packed & 255;
|
|
42881
|
+
pixels[i * 4 + 3] = known ? 255 : 0;
|
|
42882
|
+
}
|
|
42883
|
+
return pixels;
|
|
42884
|
+
}
|
|
42885
|
+
/*
|
|
42886
|
+
* The finest terrain level a box can be sampled at inside the tile budget.
|
|
42887
|
+
*
|
|
42888
|
+
* Asked of the provider's own tiling scheme where it offers one, since a terrain set is free to
|
|
42889
|
+
* tile the world differently from the default two by one.
|
|
42890
|
+
*/
|
|
42891
|
+
function groundLevelFor(box, provider) {
|
|
42892
|
+
const scheme = provider && provider.tilingScheme;
|
|
42893
|
+
for (let level = MASK_GROUND_LEVEL_MAX; level > MASK_GROUND_LEVEL_MIN; level--) {
|
|
42894
|
+
const across = scheme && typeof scheme.getNumberOfXTilesAtLevel === "function"
|
|
42895
|
+
? scheme.getNumberOfXTilesAtLevel(level)
|
|
42896
|
+
: Math.pow(2, level + 1);
|
|
42897
|
+
const down = scheme && typeof scheme.getNumberOfYTilesAtLevel === "function"
|
|
42898
|
+
? scheme.getNumberOfYTilesAtLevel(level)
|
|
42899
|
+
: Math.pow(2, level);
|
|
42900
|
+
const tiles = Math.ceil((box.East - box.West) / (360 / across) + 1)
|
|
42901
|
+
* Math.ceil((box.North - box.South) / (180 / down) + 1);
|
|
42902
|
+
if (tiles <= MASK_GROUND_TILE_BUDGET) {
|
|
42903
|
+
return level;
|
|
42904
|
+
}
|
|
42905
|
+
}
|
|
42906
|
+
return MASK_GROUND_LEVEL_MIN;
|
|
42907
|
+
}
|
|
42689
42908
|
class Surface {
|
|
42690
42909
|
constructor(options, hasCoverage) {
|
|
42691
42910
|
var _a, _b, _c, _d;
|
|
@@ -42704,6 +42923,14 @@ void main() {
|
|
|
42704
42923
|
this.groundTexture = null;
|
|
42705
42924
|
this.groundPixels = null;
|
|
42706
42925
|
this.groundRequested = false;
|
|
42926
|
+
this.groundClearance = null;
|
|
42927
|
+
this.maskTexture = null;
|
|
42928
|
+
this.maskPixels = null;
|
|
42929
|
+
this.maskGroundTexture = null;
|
|
42930
|
+
this.maskGroundPixels = null;
|
|
42931
|
+
this.maskGroundBox = null;
|
|
42932
|
+
this.maskGroundRequested = false;
|
|
42933
|
+
this.maskGroundLevel = 0;
|
|
42707
42934
|
this.followGround = Boolean(options.followGround);
|
|
42708
42935
|
this.terrainProvider = options.terrainProvider || null;
|
|
42709
42936
|
this.extent = options.extent;
|
|
@@ -42716,7 +42943,9 @@ void main() {
|
|
|
42716
42943
|
this.pixelPlacement = options.pixelPlacement;
|
|
42717
42944
|
this.tileSkirts = Boolean(options.tileSkirts);
|
|
42718
42945
|
this.rampPixels = RampLookup(options.rampStops || null, options.lowColor || DEFAULT_LOW_COLOR, options.highColor || DEFAULT_HIGH_COLOR);
|
|
42946
|
+
this.maskFillValue = firstOpaqueStop(this.rampPixels);
|
|
42719
42947
|
this.tiles = buildTiles(hasCoverage);
|
|
42948
|
+
this.SetGroundClearance(options.groundClearance || null);
|
|
42720
42949
|
}
|
|
42721
42950
|
GetFollowsGround() {
|
|
42722
42951
|
return this.followGround;
|
|
@@ -42739,6 +42968,97 @@ void main() {
|
|
|
42739
42968
|
SetBaseHeight(baseHeight) {
|
|
42740
42969
|
this.baseHeight = baseHeight;
|
|
42741
42970
|
}
|
|
42971
|
+
GetGroundClearance() {
|
|
42972
|
+
return this.groundClearance;
|
|
42973
|
+
}
|
|
42974
|
+
/*
|
|
42975
|
+
* The terrain level the clearance regions were sampled at, once they have been.
|
|
42976
|
+
*
|
|
42977
|
+
* Worth reading rather than assuming: the level is chosen from how big the regions are, so a
|
|
42978
|
+
* region covering a whole sound gets a coarser test than a hand drawn harbour does.
|
|
42979
|
+
*/
|
|
42980
|
+
GetGroundClearanceLevel() {
|
|
42981
|
+
return this.maskGroundLevel;
|
|
42982
|
+
}
|
|
42983
|
+
/*
|
|
42984
|
+
* What the clearance regions were measured against, once they have been.
|
|
42985
|
+
* The heights are read out of whatever the terrain stores, and a terrain referenced to sea
|
|
42986
|
+
* level reads a geoid apart from an archive delivering ellipsoidal metres.
|
|
42987
|
+
*/
|
|
42988
|
+
GetGroundClearanceStats() {
|
|
42989
|
+
if (!this.maskGroundPixels) {
|
|
42990
|
+
return null;
|
|
42991
|
+
}
|
|
42992
|
+
const span = GROUND_MAX_METRES - GROUND_MIN_METRES;
|
|
42993
|
+
let min = Infinity;
|
|
42994
|
+
let max = -Infinity;
|
|
42995
|
+
let samples = 0;
|
|
42996
|
+
for (let i = 0; i < this.maskGroundPixels.length / 4; i++) {
|
|
42997
|
+
if (!this.maskGroundPixels[i * 4 + 3]) {
|
|
42998
|
+
continue;
|
|
42999
|
+
}
|
|
43000
|
+
const packed = (this.maskGroundPixels[i * 4] << 16)
|
|
43001
|
+
+ (this.maskGroundPixels[i * 4 + 1] << 8) + this.maskGroundPixels[i * 4 + 2];
|
|
43002
|
+
const height = GROUND_MIN_METRES + (packed / 16777215) * span;
|
|
43003
|
+
min = Math.min(min, height);
|
|
43004
|
+
max = Math.max(max, height);
|
|
43005
|
+
samples++;
|
|
43006
|
+
}
|
|
43007
|
+
if (!samples) {
|
|
43008
|
+
return null;
|
|
43009
|
+
}
|
|
43010
|
+
return { level: this.maskGroundLevel, min, max, samples };
|
|
43011
|
+
}
|
|
43012
|
+
/*
|
|
43013
|
+
* The real world range the texture's 0 to 1 maps onto, so a caller can compare it against what
|
|
43014
|
+
* the terrain says without having kept its own copy.
|
|
43015
|
+
*/
|
|
43016
|
+
GetValueRange() {
|
|
43017
|
+
return { min: this.valueMin, max: this.valueMax };
|
|
43018
|
+
}
|
|
43019
|
+
/*
|
|
43020
|
+
* Takes a different terrain to measure against.
|
|
43021
|
+
* The clearance raster is sampled once and cached, so a scene that swaps its terrain would
|
|
43022
|
+
* otherwise keep holding the sheet above heights read from the terrain it used to have.
|
|
43023
|
+
*/
|
|
43024
|
+
SetTerrainProvider(provider) {
|
|
43025
|
+
if (provider === this.terrainProvider) {
|
|
43026
|
+
return;
|
|
43027
|
+
}
|
|
43028
|
+
this.terrainProvider = provider;
|
|
43029
|
+
this.groundPixels = null;
|
|
43030
|
+
this.groundRequested = false;
|
|
43031
|
+
this.maskGroundPixels = null;
|
|
43032
|
+
this.maskGroundRequested = false;
|
|
43033
|
+
this.maskGroundLevel = 0;
|
|
43034
|
+
}
|
|
43035
|
+
/*
|
|
43036
|
+
* Takes a new set of clearance regions, or drops them.
|
|
43037
|
+
* The mask is rasterised here rather than on the render thread, and the ground under the
|
|
43038
|
+
* regions is re-requested, so a plugin can hand over regions the moment it has them.
|
|
43039
|
+
*/
|
|
43040
|
+
SetGroundClearance(clearance) {
|
|
43041
|
+
this.groundClearance = clearance && clearance.regions && clearance.regions.length
|
|
43042
|
+
? clearance
|
|
43043
|
+
: null;
|
|
43044
|
+
this.maskPixels = this.groundClearance
|
|
43045
|
+
? rasteriseMask(this.extent, this.groundClearance.regions)
|
|
43046
|
+
: null;
|
|
43047
|
+
if (this.maskTexture) {
|
|
43048
|
+
this.maskTexture.destroy();
|
|
43049
|
+
this.maskTexture = null;
|
|
43050
|
+
}
|
|
43051
|
+
this.maskGroundPixels = null;
|
|
43052
|
+
this.maskGroundRequested = false;
|
|
43053
|
+
this.maskGroundLevel = 0;
|
|
43054
|
+
this.maskGroundBox = this.groundClearance
|
|
43055
|
+
? boxOf(this.extent, this.groundClearance.regions)
|
|
43056
|
+
: null;
|
|
43057
|
+
if (this.maskGroundTexture) {
|
|
43058
|
+
this.maskGroundTexture.destroy();
|
|
43059
|
+
this.maskGroundTexture = null;
|
|
43060
|
+
}
|
|
43061
|
+
}
|
|
42742
43062
|
/**
|
|
42743
43063
|
* Feeds the surface from an animated frame series.
|
|
42744
43064
|
* Height and colour advance with the clock without the caller having to push each frame in.
|
|
@@ -42777,6 +43097,8 @@ void main() {
|
|
|
42777
43097
|
this.syncRampTexture(context);
|
|
42778
43098
|
this.requestGround();
|
|
42779
43099
|
this.syncGroundTexture(context);
|
|
43100
|
+
this.requestMaskGround();
|
|
43101
|
+
this.syncMaskTextures(context);
|
|
42780
43102
|
// A tile needs one mesh before it has a bounding sphere to measure against.
|
|
42781
43103
|
for (const tile of this.tiles) {
|
|
42782
43104
|
if (!tile.centre) {
|
|
@@ -42821,6 +43143,14 @@ void main() {
|
|
|
42821
43143
|
this.groundTexture.destroy();
|
|
42822
43144
|
this.groundTexture = null;
|
|
42823
43145
|
}
|
|
43146
|
+
if (this.maskTexture) {
|
|
43147
|
+
this.maskTexture.destroy();
|
|
43148
|
+
this.maskTexture = null;
|
|
43149
|
+
}
|
|
43150
|
+
if (this.maskGroundTexture) {
|
|
43151
|
+
this.maskGroundTexture.destroy();
|
|
43152
|
+
this.maskGroundTexture = null;
|
|
43153
|
+
}
|
|
42824
43154
|
return undefined;
|
|
42825
43155
|
}
|
|
42826
43156
|
/*
|
|
@@ -42853,24 +43183,123 @@ void main() {
|
|
|
42853
43183
|
if (this.destroyed || !sampled) {
|
|
42854
43184
|
return;
|
|
42855
43185
|
}
|
|
42856
|
-
|
|
42857
|
-
const span = GROUND_MAX_METRES - GROUND_MIN_METRES;
|
|
42858
|
-
for (let i = 0; i < sampled.length; i++) {
|
|
42859
|
-
const height = sampled[i] && isFinite(sampled[i].height) ? sampled[i].height : 0;
|
|
42860
|
-
const clamped = Math.min(GROUND_MAX_METRES, Math.max(GROUND_MIN_METRES, height));
|
|
42861
|
-
const packed = Math.round(((clamped - GROUND_MIN_METRES) / span) * 16777215);
|
|
42862
|
-
pixels[i * 4] = (packed >> 16) & 255;
|
|
42863
|
-
pixels[i * 4 + 1] = (packed >> 8) & 255;
|
|
42864
|
-
pixels[i * 4 + 2] = packed & 255;
|
|
42865
|
-
pixels[i * 4 + 3] = 255;
|
|
42866
|
-
}
|
|
42867
|
-
this.groundPixels = pixels;
|
|
43186
|
+
this.groundPixels = packHeights(sampled);
|
|
42868
43187
|
})
|
|
42869
43188
|
.catch(() => {
|
|
42870
43189
|
// Terrain that cannot be sampled leaves the surface on the ellipsoid, which is
|
|
42871
43190
|
// where a clamped polygon sat before this existed.
|
|
42872
43191
|
});
|
|
42873
43192
|
}
|
|
43193
|
+
/*
|
|
43194
|
+
* Samples the terrain under the clearance regions.
|
|
43195
|
+
*
|
|
43196
|
+
* Its own raster rather than the surface's, because the surface extent here is two degrees
|
|
43197
|
+
* wide and the region is a few kilometres, and a clearance test needs the finer one.
|
|
43198
|
+
*/
|
|
43199
|
+
requestMaskGround() {
|
|
43200
|
+
if (this.maskGroundRequested || !this.groundClearance || !this.maskGroundBox) {
|
|
43201
|
+
return;
|
|
43202
|
+
}
|
|
43203
|
+
if (!(this.groundClearance.clearance > NO_LIMIT_METRES / 2)) {
|
|
43204
|
+
return;
|
|
43205
|
+
}
|
|
43206
|
+
this.maskGroundRequested = true;
|
|
43207
|
+
const sampler = Cesium.sampleTerrain;
|
|
43208
|
+
if (!this.terrainProvider || typeof sampler !== "function") {
|
|
43209
|
+
return;
|
|
43210
|
+
}
|
|
43211
|
+
const box = this.maskGroundBox;
|
|
43212
|
+
const level = groundLevelFor(box, this.terrainProvider);
|
|
43213
|
+
this.maskGroundLevel = level;
|
|
43214
|
+
const total = MASK_GROUND_SAMPLES_PER_SIDE * MASK_GROUND_SAMPLES_PER_SIDE;
|
|
43215
|
+
const scheme = this.terrainProvider.tilingScheme;
|
|
43216
|
+
const asked = [];
|
|
43217
|
+
// Which slot in the raster each asked-for position belongs to, since the ones the terrain
|
|
43218
|
+
// does not cover are never asked for at all.
|
|
43219
|
+
const slots = [];
|
|
43220
|
+
for (let row = 0; row < MASK_GROUND_SAMPLES_PER_SIDE; row++) {
|
|
43221
|
+
const fy = row / (MASK_GROUND_SAMPLES_PER_SIDE - 1);
|
|
43222
|
+
const latitude = Cesium.Math.lerp(box.North, box.South, fy);
|
|
43223
|
+
for (let col = 0; col < MASK_GROUND_SAMPLES_PER_SIDE; col++) {
|
|
43224
|
+
const fx = col / (MASK_GROUND_SAMPLES_PER_SIDE - 1);
|
|
43225
|
+
const at = Cesium.Cartographic.fromDegrees(Cesium.Math.lerp(box.West, box.East, fx), latitude);
|
|
43226
|
+
// An imported terrain covers a survey area, so asking outside it answers 404 and
|
|
43227
|
+
// fills the console with failures for points that were never going to have a height.
|
|
43228
|
+
if (scheme && typeof this.terrainProvider.getTileDataAvailable === "function") {
|
|
43229
|
+
const tile = scheme.positionToTileXY(at, level);
|
|
43230
|
+
if (!tile || this.terrainProvider.getTileDataAvailable(tile.x, tile.y, level) === false) {
|
|
43231
|
+
continue;
|
|
43232
|
+
}
|
|
43233
|
+
}
|
|
43234
|
+
asked.push(at);
|
|
43235
|
+
slots.push(row * MASK_GROUND_SAMPLES_PER_SIDE + col);
|
|
43236
|
+
}
|
|
43237
|
+
}
|
|
43238
|
+
if (!asked.length) {
|
|
43239
|
+
return;
|
|
43240
|
+
}
|
|
43241
|
+
Promise.resolve(sampler(this.terrainProvider, level, asked))
|
|
43242
|
+
.then((sampled) => {
|
|
43243
|
+
if (this.destroyed || !sampled) {
|
|
43244
|
+
return;
|
|
43245
|
+
}
|
|
43246
|
+
const spread = new Array(total).fill(undefined);
|
|
43247
|
+
for (let i = 0; i < slots.length; i++) {
|
|
43248
|
+
spread[slots[i]] = sampled[i];
|
|
43249
|
+
}
|
|
43250
|
+
this.maskGroundPixels = packHeights(spread);
|
|
43251
|
+
})
|
|
43252
|
+
.catch(() => {
|
|
43253
|
+
// Unsampled terrain leaves only the region's own floor to hold the sheet up,
|
|
43254
|
+
// which is the behaviour a region with no clearance already has.
|
|
43255
|
+
});
|
|
43256
|
+
}
|
|
43257
|
+
/*
|
|
43258
|
+
* Uploads the region mask and the ground under it, with a one texel stand-in until they land
|
|
43259
|
+
* so the shader always has something bound.
|
|
43260
|
+
*/
|
|
43261
|
+
syncMaskTextures(context) {
|
|
43262
|
+
if (!this.maskTexture) {
|
|
43263
|
+
const held = this.maskPixels;
|
|
43264
|
+
this.maskTexture = new Cesium.Texture({
|
|
43265
|
+
context,
|
|
43266
|
+
pixelFormat: Cesium.PixelFormat.RGBA,
|
|
43267
|
+
source: held
|
|
43268
|
+
? { width: held.width, height: held.height, arrayBufferView: held.data }
|
|
43269
|
+
: { width: 1, height: 1, arrayBufferView: new Uint8Array([0, 0, 0, 0]) },
|
|
43270
|
+
flipY: false,
|
|
43271
|
+
sampler: new Cesium.Sampler({
|
|
43272
|
+
wrapS: Cesium.TextureWrap.CLAMP_TO_EDGE,
|
|
43273
|
+
wrapT: Cesium.TextureWrap.CLAMP_TO_EDGE
|
|
43274
|
+
})
|
|
43275
|
+
});
|
|
43276
|
+
}
|
|
43277
|
+
if (this.maskGroundTexture && (!this.maskGroundPixels
|
|
43278
|
+
|| this.maskGroundTexture.width === MASK_GROUND_SAMPLES_PER_SIDE)) {
|
|
43279
|
+
return;
|
|
43280
|
+
}
|
|
43281
|
+
if (this.maskGroundTexture) {
|
|
43282
|
+
this.maskGroundTexture.destroy();
|
|
43283
|
+
}
|
|
43284
|
+
const size = this.maskGroundPixels ? MASK_GROUND_SAMPLES_PER_SIDE : 1;
|
|
43285
|
+
this.maskGroundTexture = new Cesium.Texture({
|
|
43286
|
+
context,
|
|
43287
|
+
pixelFormat: Cesium.PixelFormat.RGBA,
|
|
43288
|
+
source: {
|
|
43289
|
+
width: size,
|
|
43290
|
+
height: size,
|
|
43291
|
+
arrayBufferView: this.maskGroundPixels || packHeights([{ height: 0 }])
|
|
43292
|
+
},
|
|
43293
|
+
flipY: false,
|
|
43294
|
+
sampler: new Cesium.Sampler({
|
|
43295
|
+
wrapS: Cesium.TextureWrap.CLAMP_TO_EDGE,
|
|
43296
|
+
wrapT: Cesium.TextureWrap.CLAMP_TO_EDGE,
|
|
43297
|
+
// Nearest, because the shader interpolates decoded heights itself.
|
|
43298
|
+
minificationFilter: Cesium.TextureMinificationFilter.NEAREST,
|
|
43299
|
+
magnificationFilter: Cesium.TextureMagnificationFilter.NEAREST
|
|
43300
|
+
})
|
|
43301
|
+
});
|
|
43302
|
+
}
|
|
42874
43303
|
/*
|
|
42875
43304
|
* Uploads whatever ground samples exist, and a flat stand-in until they arrive, so the
|
|
42876
43305
|
* shader always has a texture bound whether or not this surface follows the ground.
|
|
@@ -42882,10 +43311,8 @@ void main() {
|
|
|
42882
43311
|
if (this.groundTexture) {
|
|
42883
43312
|
this.groundTexture.destroy();
|
|
42884
43313
|
}
|
|
42885
|
-
const zero = Math.round(((0 - GROUND_MIN_METRES) / (GROUND_MAX_METRES - GROUND_MIN_METRES)) * 16777215);
|
|
42886
43314
|
const size = this.groundPixels ? GROUND_SAMPLES_PER_SIDE : 1;
|
|
42887
|
-
const arrayBufferView = this.groundPixels
|
|
42888
|
-
|| new Uint8Array([(zero >> 16) & 255, (zero >> 8) & 255, zero & 255, 255]);
|
|
43315
|
+
const arrayBufferView = this.groundPixels || packHeights([{ height: 0 }]);
|
|
42889
43316
|
this.groundTexture = new Cesium.Texture({
|
|
42890
43317
|
context,
|
|
42891
43318
|
pixelFormat: Cesium.PixelFormat.RGBA,
|
|
@@ -43094,6 +43521,28 @@ void main() {
|
|
|
43094
43521
|
u_groundWeight: () => (self.followGround && self.groundPixels ? 1 : 0),
|
|
43095
43522
|
u_groundRange: () => new Cesium.Cartesian2(GROUND_MIN_METRES, GROUND_MAX_METRES),
|
|
43096
43523
|
u_groundSize: () => new Cesium.Cartesian2(self.groundPixels ? GROUND_SAMPLES_PER_SIDE : 1, self.groundPixels ? GROUND_SAMPLES_PER_SIDE : 1),
|
|
43524
|
+
u_maskTexture: () => self.maskTexture,
|
|
43525
|
+
u_maskGroundTexture: () => self.maskGroundTexture,
|
|
43526
|
+
u_maskWeight: () => (self.groundClearance && self.maskPixels ? 1 : 0),
|
|
43527
|
+
u_maskGroundWeight: () => (self.maskGroundPixels ? 1 : 0),
|
|
43528
|
+
u_maskFill: () => (self.groundClearance && self.groundClearance.fillGaps ? 1 : 0),
|
|
43529
|
+
u_maskFillValue: () => self.maskFillValue,
|
|
43530
|
+
u_maskClearance: () => (self.groundClearance
|
|
43531
|
+
&& typeof self.groundClearance.clearance === "number"
|
|
43532
|
+
&& self.maskGroundPixels
|
|
43533
|
+
? self.groundClearance.clearance
|
|
43534
|
+
: NO_LIMIT_METRES),
|
|
43535
|
+
u_maskFloor: () => (self.groundClearance
|
|
43536
|
+
&& typeof self.groundClearance.floor === "number"
|
|
43537
|
+
? self.groundClearance.floor
|
|
43538
|
+
: NO_LIMIT_METRES),
|
|
43539
|
+
u_maskGroundSize: () => new Cesium.Cartesian2(self.maskGroundPixels ? MASK_GROUND_SAMPLES_PER_SIDE : 1, self.maskGroundPixels ? MASK_GROUND_SAMPLES_PER_SIDE : 1),
|
|
43540
|
+
u_extentDegrees: () => new Cesium.Cartesian4(self.extent.West, self.extent.East, self.extent.North, self.extent.South),
|
|
43541
|
+
u_maskGroundDegrees: () => {
|
|
43542
|
+
const box = self.maskGroundBox || self.extent;
|
|
43543
|
+
return new Cesium.Cartesian4(box.West, box.East, box.North, box.South);
|
|
43544
|
+
},
|
|
43545
|
+
u_coverageCutoffVertex: () => COVERAGE_CUTOFF,
|
|
43097
43546
|
u_metresPerTexel: () => self.metresPerTexel(),
|
|
43098
43547
|
u_valueMin: () => self.valueMin,
|
|
43099
43548
|
u_valueRange: () => self.valueMax - self.valueMin,
|
|
@@ -43729,6 +44178,34 @@ void main() {
|
|
|
43729
44178
|
return cEntities;
|
|
43730
44179
|
}
|
|
43731
44180
|
EntityRenderEnginePolygon.RenderGroup = RenderGroup;
|
|
44181
|
+
/**
|
|
44182
|
+
* The displaced surface a cEntity is drawing, if it is drawing one.
|
|
44183
|
+
*
|
|
44184
|
+
* Exposed so a background plugin can hand a rendered polygon the water regions it is supposed to
|
|
44185
|
+
* stay above without having to know where the surface is kept.
|
|
44186
|
+
* @param cEntity
|
|
44187
|
+
*/
|
|
44188
|
+
function GetDisplacedSurface(cEntity) {
|
|
44189
|
+
return (cEntity === null || cEntity === void 0 ? void 0 : cEntity[DISPLACED_SURFACE_KEY]) || null;
|
|
44190
|
+
}
|
|
44191
|
+
EntityRenderEnginePolygon.GetDisplacedSurface = GetDisplacedSurface;
|
|
44192
|
+
/**
|
|
44193
|
+
* Hands every rendered polygon in a set the regions its sheet must stay above.
|
|
44194
|
+
* @param cEntities
|
|
44195
|
+
* @param clearance Pass null to drop the regions again.
|
|
44196
|
+
*/
|
|
44197
|
+
function SetGroundClearance(cEntities, clearance) {
|
|
44198
|
+
let touched = 0;
|
|
44199
|
+
for (const cEntity of cEntities || []) {
|
|
44200
|
+
const surface = GetDisplacedSurface(cEntity);
|
|
44201
|
+
if (surface) {
|
|
44202
|
+
surface.SetGroundClearance(clearance);
|
|
44203
|
+
touched++;
|
|
44204
|
+
}
|
|
44205
|
+
}
|
|
44206
|
+
return touched;
|
|
44207
|
+
}
|
|
44208
|
+
EntityRenderEnginePolygon.SetGroundClearance = SetGroundClearance;
|
|
43732
44209
|
/**
|
|
43733
44210
|
* Disposes a cEntity's TextureFrameSeriesAnimator.Animator (if any).
|
|
43734
44211
|
*/
|
|
@@ -45776,7 +46253,7 @@ void main() {
|
|
|
45776
46253
|
StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
|
|
45777
46254
|
})(exports.StyleUtils || (exports.StyleUtils = {}));
|
|
45778
46255
|
|
|
45779
|
-
const VERSION = "7.
|
|
46256
|
+
const VERSION = "7.3.0";
|
|
45780
46257
|
/**
|
|
45781
46258
|
* Updates the environment instance used by bruce-cesium to one specified.
|
|
45782
46259
|
* This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
|