Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for walls with negative heights #9041

Merged
merged 4 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- Fixed issue where a side of the wall was missing if the first position and the last position were equal [#9044](https://github.com/CesiumGS/cesium/pull/9044)
- Fixed `translucencyByDistance` for label outline color [#9003](https://github.com/CesiumGS/cesium/pull/9003)

Expand Down
26 changes: 8 additions & 18 deletions Source/Core/WallGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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
);
}
Expand Down
15 changes: 10 additions & 5 deletions Source/Core/WallGeometryLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -53,14 +50,18 @@ 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];
var c1 = ellipsoid.cartesianToCartographic(v1, scratchCartographic2);
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!
Expand All @@ -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;
}

Expand Down