From c703a6ff6dfca5dac1d6a781f3f25cf7d2da6266 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 20 Jul 2020 13:37:15 -0400 Subject: [PATCH 1/2] allow walls with negative heights --- Source/Core/WallGeometry.js | 26 ++++++++------------------ Source/Core/WallGeometryLibrary.js | 15 ++++++++++----- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Source/Core/WallGeometry.js b/Source/Core/WallGeometry.js index cfa9b6b7fd34..edec6b022098 100644 --- a/Source/Core/WallGeometry.js +++ b/Source/Core/WallGeometry.js @@ -16,7 +16,6 @@ import WallGeometryLibrary from "./WallGeometryLibrary.js"; var scratchCartesian3Position1 = new Cartesian3(); var scratchCartesian3Position2 = new Cartesian3(); -var scratchCartesian3Position3 = new Cartesian3(); var scratchCartesian3Position4 = new Cartesian3(); var scratchCartesian3Position5 = new Cartesian3(); var scratchBitangent = new Cartesian3(); @@ -437,24 +436,19 @@ WallGeometry.createGeometry = function (wallGeometry) { } if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) { - var nextPosition; var nextTop = Cartesian3.clone( Cartesian3.ZERO, scratchCartesian3Position5 ); - var groundPosition = ellipsoid.scaleToGeodeticSurface( - Cartesian3.fromArray(topPositions, i3, scratchCartesian3Position2), + var groundPosition = Cartesian3.subtract( + topPosition, + ellipsoid.geodeticSurfaceNormal( + topPosition, + scratchCartesian3Position2 + ), scratchCartesian3Position2 ); if (i + 1 < length) { - nextPosition = ellipsoid.scaleToGeodeticSurface( - Cartesian3.fromArray( - topPositions, - i3 + 3, - scratchCartesian3Position3 - ), - scratchCartesian3Position3 - ); nextTop = Cartesian3.fromArray( topPositions, i3 + 3, @@ -481,18 +475,14 @@ WallGeometry.createGeometry = function (wallGeometry) { } if ( - Cartesian3.equalsEpsilon( - nextPosition, - groundPosition, - CesiumMath.EPSILON10 - ) + Cartesian3.equalsEpsilon(topPosition, nextTop, CesiumMath.EPSILON10) ) { recomputeNormal = true; } else { s += ds; if (vertexFormat.tangent) { tangent = Cartesian3.normalize( - Cartesian3.subtract(nextPosition, groundPosition, tangent), + Cartesian3.subtract(nextTop, topPosition, tangent), tangent ); } diff --git a/Source/Core/WallGeometryLibrary.js b/Source/Core/WallGeometryLibrary.js index 8c77a5fb94ec..77699d16cc90 100644 --- a/Source/Core/WallGeometryLibrary.js +++ b/Source/Core/WallGeometryLibrary.js @@ -29,7 +29,6 @@ function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) { var hasBottomHeights = defined(bottomHeights); var hasTopHeights = defined(topHeights); - var hasAllZeroHeights = true; var cleanedPositions = new Array(length); var cleanedTopHeights = new Array(length); @@ -43,8 +42,6 @@ function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) { c0.height = topHeights[0]; } - hasAllZeroHeights = hasAllZeroHeights && c0.height <= 0; - cleanedTopHeights[0] = c0.height; if (hasBottomHeights) { @@ -53,6 +50,10 @@ function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) { cleanedBottomHeights[0] = 0.0; } + var startTopHeight = cleanedTopHeights[0]; + var startBottomHeight = cleanedBottomHeights[0]; + var hasAllSameHeights = startTopHeight === startBottomHeight; + var index = 1; for (var i = 1; i < length; ++i) { var v1 = positions[i]; @@ -60,7 +61,7 @@ function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) { if (hasTopHeights) { c1.height = topHeights[i]; } - hasAllZeroHeights = hasAllZeroHeights && c1.height <= 0; + hasAllSameHeights = hasAllSameHeights && c1.height === 0; if (!latLonEquals(c0, c1)) { cleanedPositions[index] = v1; // Shallow copy! @@ -71,15 +72,19 @@ function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) { } else { cleanedBottomHeights[index] = 0.0; } + hasAllSameHeights = + hasAllSameHeights && + cleanedTopHeights[index] === cleanedBottomHeights[index]; Cartographic.clone(c1, c0); ++index; } else if (c0.height < c1.height) { + // two adjacent positions are the same, so use whichever has the greater height cleanedTopHeights[index - 1] = c1.height; } } - if (hasAllZeroHeights || index < 2) { + if (hasAllSameHeights || index < 2) { return; } From 7dc5f6f7a8c6ac8c089b11b213a9c93f6e7f4bc0 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 20 Jul 2020 13:59:10 -0400 Subject: [PATCH 2/2] CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 37f9ed3848c7..3b5beee545b7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ - Fixed 3D Tileset replacement refinement when leaf is empty. [#8996](https://github.com/CesiumGS/cesium/pull/8996) - Fixed a bug in the assessment of terrain tile visibility [#9033](https://github.com/CesiumGS/cesium/issues/9033) - Fixed vertical polylines with `arcType: ArcType.RHUMB`, including lines drawn via GeoJSON. [#9028](https://github.com/CesiumGS/cesium/pull/9028) +- Fixed wall rendering when underground [#9041](https://github.com/CesiumGS/cesium/pull/9041) ### 1.71 - 2020-07-01