This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accurate near distance for spherical projection. (#2245)
* MAPSJS-2660: Accurate near distance for spherical projection. Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com> * MAPSJS-2660: Unit testing of ClipPlanesEvaluator. Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com> * MAPSJS-2660: Add missing properties to fake ds in MapViewPickingTest. minGeometryHeight and maxGeometryHeight were undefined for fake elevation DataSource. Because of this, calculation of min/max geometry height at MapView.updateCameras() was returning NaN. Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com> * MAPSJS-2660: Address review comments. Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>
- Loading branch information
1 parent
c579784
commit 8ecd5f7
Showing
6 changed files
with
550 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (C) 2021 HERE Europe B.V. | ||
* Licensed under Apache 2.0, see full license in LICENSE | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ViewRanges } from "@here/harp-datasource-protocol/lib/ViewRanges"; | ||
import { Projection } from "@here/harp-geoutils"; | ||
import * as THREE from "three"; | ||
|
||
import { ClipPlanesEvaluator } from "./ClipPlanesEvaluator"; | ||
import { ElevationProvider } from "./ElevationProvider"; | ||
|
||
/** | ||
* Provides the most basic evaluation concept giving fixed values with some constraints. | ||
*/ | ||
export class FixedClipPlanesEvaluator implements ClipPlanesEvaluator { | ||
readonly minFar: number; | ||
private m_nearPlane: number; | ||
private m_farPlane: number; | ||
|
||
constructor(readonly minNear: number = 1, readonly minFarOffset: number = 10) { | ||
this.minFar = minNear + minFarOffset; | ||
this.m_nearPlane = minNear; | ||
this.m_farPlane = this.minFar; | ||
} | ||
|
||
get nearPlane(): number { | ||
return this.m_nearPlane; | ||
} | ||
|
||
set nearPlane(fixedNear: number) { | ||
this.invalidatePlanes(fixedNear, this.m_farPlane); | ||
} | ||
|
||
get farPlane(): number { | ||
return this.m_farPlane; | ||
} | ||
|
||
set farPlane(fixedFar: number) { | ||
this.invalidatePlanes(this.m_nearPlane, fixedFar); | ||
} | ||
|
||
set minElevation(elevation: number) {} | ||
|
||
get minElevation(): number { | ||
// This evaluator does not support elevation so its always set to 0. | ||
return 0; | ||
} | ||
|
||
set maxElevation(elevation: number) {} | ||
|
||
get maxElevation(): number { | ||
// This evaluator does not support elevation so its always set to 0. | ||
return 0; | ||
} | ||
|
||
/** @override */ | ||
evaluateClipPlanes( | ||
camera: THREE.Camera, | ||
projection: Projection, | ||
elevationProvider?: ElevationProvider | ||
): ViewRanges { | ||
// We do not need to perform actual evaluation cause results are precomputed and | ||
// kept stable until somebody changes the properties. | ||
const viewRanges: ViewRanges = { | ||
near: this.m_nearPlane, | ||
far: this.m_farPlane, | ||
minimum: this.minNear, | ||
maximum: this.m_farPlane | ||
}; | ||
return viewRanges; | ||
} | ||
|
||
private invalidatePlanes(near: number, far: number) { | ||
// When clamping prefer to extend far plane at about minimum distance, giving | ||
// near distance setup priority over far. | ||
const nearDist: number = Math.max(this.minNear, near); | ||
const farDist: number = Math.max(this.minFar, far, nearDist + this.minFarOffset); | ||
this.m_nearPlane = nearDist; | ||
this.m_farPlane = farDist; | ||
} | ||
} |
Oops, something went wrong.