From 45dfb2dbe4ee3d44dc6b7a863d8145f7eaf21681 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 27 May 2020 19:36:29 -0400 Subject: [PATCH] Move globeHeight and cameraUnderground into Scene --- Source/Scene/Scene.js | 43 ++++++++++++++++----- Source/Scene/ScreenSpaceCameraController.js | 29 ++------------ 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index a35507b1ad7e..3f1276e58e0d 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -211,6 +211,9 @@ function Scene(options) { this._primitives = new PrimitiveCollection(); this._groundPrimitives = new PrimitiveCollection(); + this._globeHeight = undefined; + this._cameraUnderground = false; + this._logDepthBuffer = context.fragmentDepth; this._logDepthBufferDirty = true; @@ -1658,6 +1661,15 @@ Object.defineProperties(Scene.prototype, { return this._globeTranslucencyState; }, }, + + /** + * @private + */ + globeHeight: { + get: function () { + return this._globeHeight; + }, + }, }); /** @@ -3702,6 +3714,16 @@ function callAfterRenderFunctions(scene) { functions.length = 0; } +function getGlobeHeight(scene) { + var globe = scene._globe; + var camera = scene.camera; + var cartographic = camera.positionCartographic; + if (defined(globe) && globe.show && defined(cartographic)) { + return globe.getHeight(cartographic); + } + return undefined; +} + function isCameraUnderground(scene) { var camera = scene.camera; var mode = scene._mode; @@ -3709,11 +3731,11 @@ function isCameraUnderground(scene) { var cameraController = scene._screenSpaceCameraController; var cartographic = camera.positionCartographic; - if ( - !cameraController.onMap() && - defined(cartographic) && - cartographic.height < 0.0 - ) { + if (!defined(cartographic)) { + return false; + } + + if (!cameraController.onMap() && cartographic.height < 0.0) { // The camera can go off the map while in Columbus View. // Make a best guess as to whether it's underground by checking if its height is less than zero. return true; @@ -3728,7 +3750,8 @@ function isCameraUnderground(scene) { return false; } - return cameraController.isCameraUnderground(camera); + var globeHeight = scene._globeHeight; + return defined(globeHeight) && cartographic.height < globeHeight; } /** @@ -3744,6 +3767,10 @@ Scene.prototype.initializeFrame = function () { this._tweens.update(); + this._globeHeight = getGlobeHeight(this); + this._cameraUnderground = isCameraUnderground(this); + this._globeTranslucencyState.update(this); + this._screenSpaceCameraController.update(); if (defined(this._deviceOrientationCameraController)) { this._deviceOrientationCameraController.update(); @@ -3751,10 +3778,6 @@ Scene.prototype.initializeFrame = function () { this.camera.update(this._mode); this.camera._updateCameraChanged(); - - this._cameraUnderground = isCameraUnderground(this); - - this._globeTranslucencyState.update(this); }; function updateDebugShowFramesPerSecond(scene, renderedThisFrame) { diff --git a/Source/Scene/ScreenSpaceCameraController.js b/Source/Scene/ScreenSpaceCameraController.js index 56be4c9b17b4..4c93dd393c60 100644 --- a/Source/Scene/ScreenSpaceCameraController.js +++ b/Source/Scene/ScreenSpaceCameraController.js @@ -277,7 +277,6 @@ function ScreenSpaceCameraController(scene) { this._zoomingOnVector = false; this._rotatingZoom = false; this._adjustedHeightForTerrain = false; - this._globeHeight = undefined; this._cameraUnderground = false; var projection = scene.mapProjection; @@ -307,19 +306,6 @@ function ScreenSpaceCameraController(scene) { this._undergroundSurfaceHeight = -20000.0; } -/** - * @private - */ -ScreenSpaceCameraController.prototype.isCameraUnderground = function (camera) { - var globeHeight = this._globeHeight; - var cartographic = camera.positionCartographic; - return ( - defined(globeHeight) && - defined(cartographic) && - cartographic.height < globeHeight - ); -}; - function decay(time, coefficient) { if (time < 0) { return 0.0; @@ -1135,7 +1121,7 @@ var scratchSurfaceNormal = new Cartesian3(); function getZoomDistanceUnderground(controller, ray, height) { var origin = ray.origin; var direction = ray.direction; - var globeHeight = defaultValue(controller._globeHeight, 0.0); + var globeHeight = defaultValue(controller._scene.globeHeight, 0.0); var distanceFromSurface = Math.abs(height - globeHeight); var distanceFromUndergroundSurface = Math.abs( height - controller._undergroundSurfaceHeight @@ -1203,7 +1189,7 @@ function getHeight(controller) { function getDistanceFromClosestSurface(controller) { var height = getHeight(controller); - var globeHeight = defaultValue(controller._globeHeight, 0.0); + var globeHeight = defaultValue(controller._scene.globeHeight, 0.0); var distanceFromSurface = Math.abs(height - globeHeight); var distanceFromUndergroundSurface = Math.abs( height - controller._undergroundSurfaceHeight @@ -2816,7 +2802,7 @@ function adjustHeightForTerrain(controller) { var heightUpdated = false; if (cartographic.height < controller._minimumCollisionTerrainHeight) { - var globeHeight = controller._globeHeight; + var globeHeight = controller._scene.globeHeight; if (defined(globeHeight)) { var height = globeHeight + controller.minimumZoomDistance; if (cartographic.height < height) { @@ -2878,12 +2864,6 @@ ScreenSpaceCameraController.prototype.update = function () { var globe = scene.globe; var mode = scene.mode; - var cartographic = camera.positionCartographic; - this._globeHeight = undefined; - if (defined(globe) && globe.show) { - this._globeHeight = globe.getHeight(cartographic); - } - if (!Matrix4.equals(camera.transform, Matrix4.IDENTITY)) { this._globe = undefined; this._ellipsoid = Ellipsoid.UNIT_SPHERE; @@ -2894,8 +2874,7 @@ ScreenSpaceCameraController.prototype.update = function () { : scene.mapProjection.ellipsoid; } - this._cameraUnderground = - this.isCameraUnderground(camera) && defined(this._globe); + this._cameraUnderground = scene.cameraUnderground && defined(this._globe); this._minimumCollisionTerrainHeight = this.minimumCollisionTerrainHeight * scene.terrainExaggeration;