diff --git a/Apps/Sandcastle/gallery/3D Tiles BIM.html b/Apps/Sandcastle/gallery/3D Tiles BIM.html index 542878ac3053..bfe2780087ca 100644 --- a/Apps/Sandcastle/gallery/3D Tiles BIM.html +++ b/Apps/Sandcastle/gallery/3D Tiles BIM.html @@ -187,7 +187,9 @@ } try { - const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402); + const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402, { + disableCollision: true, + }); scene.primitives.add(tileset); viewer.zoomTo( diff --git a/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html b/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html index 7df0fc46db18..9ec05ee033b0 100644 --- a/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html +++ b/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html @@ -291,7 +291,9 @@ } // Power Plant design model provided by Bentley Systems - const bimUrl = Cesium.IonResource.fromAssetId(1240402); + const bimUrl = Cesium.IonResource.fromAssetId(1240402, { + disableCollision: true, + }); const pointCloudUrl = Cesium.IonResource.fromAssetId(16421); const instancedUrl = "../../SampleData/Cesium3DTiles/Instanced/InstancedOrientation/tileset.json"; diff --git a/Apps/Sandcastle/gallery/Ambient Occlusion.html b/Apps/Sandcastle/gallery/Ambient Occlusion.html index 95b5f26543e0..bf27722c3422 100644 --- a/Apps/Sandcastle/gallery/Ambient Occlusion.html +++ b/Apps/Sandcastle/gallery/Ambient Occlusion.html @@ -192,7 +192,9 @@ try { // Power Plant design model provided by Bentley Systems - const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402); + const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402, { + disableCollision: true, + }); viewer.scene.primitives.add(tileset); } catch (error) { console.log(`Error loading tileset: ${error}`); diff --git a/Apps/Sandcastle/gallery/MSAA.html b/Apps/Sandcastle/gallery/MSAA.html index 56d806aeecd7..072fbf9dbda8 100644 --- a/Apps/Sandcastle/gallery/MSAA.html +++ b/Apps/Sandcastle/gallery/MSAA.html @@ -139,7 +139,9 @@ roll: 6.283184816241989, }, }); - createTileset(1240402); + createTileset(1240402, { + disableCollision: true, + }); }, }, { diff --git a/Apps/Sandcastle/gallery/Polylines on 3D Tiles.html b/Apps/Sandcastle/gallery/Polylines on 3D Tiles.html index 373c63a33a65..5b6420fc8442 100644 --- a/Apps/Sandcastle/gallery/Polylines on 3D Tiles.html +++ b/Apps/Sandcastle/gallery/Polylines on 3D Tiles.html @@ -59,7 +59,9 @@ let powerPlant; let powerPlantShow = true; try { - powerPlant = await Cesium.Cesium3DTileset.fromIonAssetId(1240402); + powerPlant = await Cesium.Cesium3DTileset.fromIonAssetId(1240402, { + disableCollision: true, + }); powerPlant.show = powerPlantShow; scene.primitives.add(powerPlant); powerPlant.tileLoad.addEventListener(function (tile) { diff --git a/Apps/Sandcastle/gallery/development/3D Tiles Picking.html b/Apps/Sandcastle/gallery/development/3D Tiles Picking.html index 843b1d4f30e4..0ec0f5ed928a 100644 --- a/Apps/Sandcastle/gallery/development/3D Tiles Picking.html +++ b/Apps/Sandcastle/gallery/development/3D Tiles Picking.html @@ -76,7 +76,9 @@ onselect: async () => { scene.primitives.remove(tileset); try { - tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402); + tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402, { + disableCollision: true, + }); scene.primitives.add(tileset); viewer.zoomTo(tileset); } catch (error) { diff --git a/Specs/createGlobe.js b/Specs/createGlobe.js index 200419f42880..64495785a9b7 100644 --- a/Specs/createGlobe.js +++ b/Specs/createGlobe.js @@ -18,6 +18,7 @@ function createGlobe(ellipsoid) { imageryLayersUpdatedEvent: new Event(), _terrainProvider: undefined, terrainProviderChanged: new Event(), + tileLoadProgressEvent: new Event(), destroy: function () {}, }; diff --git a/packages/engine/Source/Scene/Cesium3DTileset.js b/packages/engine/Source/Scene/Cesium3DTileset.js index 330527ead252..bfef61202bf3 100644 --- a/packages/engine/Source/Scene/Cesium3DTileset.js +++ b/packages/engine/Source/Scene/Cesium3DTileset.js @@ -1,4 +1,5 @@ import ApproximateTerrainHeights from "../Core/ApproximateTerrainHeights.js"; +import BoundingSphere from "../Core/BoundingSphere.js"; import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; @@ -3515,42 +3516,53 @@ Cesium3DTileset.prototype.pick = function (ray, frameState, result) { const selectedTiles = this._selectedTiles; const selectedLength = selectedTiles.length; + const candidates = []; - let intersection; - let minDistance = Number.POSITIVE_INFINITY; for (let i = 0; i < selectedLength; ++i) { const tile = selectedTiles[i]; + // if (!tile.content.hasRenderableContent) { + // continue; + // } + const boundsIntersection = IntersectionTests.raySphere( ray, - tile.boundingSphere, + tile.contentBoundingVolume.boundingSphere, scratchSphereIntersection ); if (!defined(boundsIntersection)) { continue; } + candidates.push(tile); + } + + const length = candidates.length; + candidates.sort((a, b) => { + const aDist = BoundingSphere.distanceSquaredTo( + a.contentBoundingVolume.boundingSphere, + ray.origin + ); + const bDist = BoundingSphere.distanceSquaredTo( + b.contentBoundingVolume.boundingSphere, + ray.origin + ); + + return aDist - bDist; + }); + let intersection; + for (let i = 0; i < length; ++i) { + const tile = candidates[i]; const candidate = tile.content?.pick( ray, frameState, scratchPickIntersection ); - if (!defined(candidate)) { - continue; - } - - const distance = Cartesian3.distance(ray.origin, candidate); - if (distance < minDistance) { + if (defined(candidate)) { intersection = Cartesian3.clone(candidate, result); - minDistance = distance; + return intersection; } } - - if (!defined(intersection)) { - return undefined; - } - - return intersection; }; /** diff --git a/packages/engine/Source/Scene/Scene.js b/packages/engine/Source/Scene/Scene.js index 1d56d15d9333..2d649676fb86 100644 --- a/packages/engine/Source/Scene/Scene.js +++ b/packages/engine/Source/Scene/Scene.js @@ -166,6 +166,7 @@ function Scene(options) { this._groundPrimitives = new PrimitiveCollection(); this._globeHeight = undefined; + this._globeHeightDirty = undefined; this._cameraUnderground = false; this._logDepthBuffer = context.fragmentDepth; @@ -748,6 +749,11 @@ function updateGlobeListeners(scene, globe) { requestRenderAfterFrame(scene) ) ); + removeGlobeCallbacks.push( + globe.tileLoadProgressEvent.addEventListener(() => { + scene._globeHeightDirty = true; + }) + ); } scene._removeGlobeCallbacks = removeGlobeCallbacks; } @@ -3614,10 +3620,18 @@ function callAfterRenderFunctions(scene) { } function getGlobeHeight(scene) { + if (scene.mode === SceneMode.MORPHING) { + return; + } + const globe = scene._globe; const camera = scene.camera; const cartographic = camera.positionCartographic; + if (!defined(cartographic)) { + return; + } + let maxHeight = Number.NEGATIVE_INFINITY; const length = scene.primitives.length; for (let i = 0; i < length; ++i) { @@ -3632,7 +3646,7 @@ function getGlobeHeight(scene) { } } - if (defined(globe) && globe.show && defined(cartographic)) { + if (defined(globe) && globe.show) { const result = globe.getHeight(cartographic); if (result > maxHeight) { maxHeight = result; @@ -3643,7 +3657,7 @@ function getGlobeHeight(scene) { return maxHeight; } - return undefined; + return; } function isCameraUnderground(scene) { @@ -3683,7 +3697,10 @@ Scene.prototype.initializeFrame = function () { this._tweens.update(); - this._globeHeight = getGlobeHeight(this); + if (this._globeHeightDirty) { + this._globeHeight = getGlobeHeight(this); + this._globeHeightDirty = false; + } this._cameraUnderground = isCameraUnderground(this); this._globeTranslucencyState.update(this); @@ -3859,8 +3876,12 @@ Scene.prototype.render = function (time) { time = JulianDate.now(); } - // Determine if shouldRender const cameraChanged = this._view.checkForCameraUpdates(this); + if (cameraChanged) { + this._globeHeightDirty = true; + } + + // Determine if should render a new frame in request render mode let shouldRender = !this.requestRenderMode || this._renderRequested || diff --git a/packages/engine/Specs/DataSources/EntityClusterSpec.js b/packages/engine/Specs/DataSources/EntityClusterSpec.js index e24dae714fdf..87c5c782ebc2 100644 --- a/packages/engine/Specs/DataSources/EntityClusterSpec.js +++ b/packages/engine/Specs/DataSources/EntityClusterSpec.js @@ -41,6 +41,7 @@ describe( }, terrainProviderChanged: new Event(), imageryLayersUpdatedEvent: new Event(), + tileLoadProgressEvent: new Event(), beginFrame: function () {}, update: function () {}, render: function () {}, diff --git a/packages/engine/Specs/DataSources/PointVisualizerSpec.js b/packages/engine/Specs/DataSources/PointVisualizerSpec.js index dceee9b7fc14..95ccba067581 100644 --- a/packages/engine/Specs/DataSources/PointVisualizerSpec.js +++ b/packages/engine/Specs/DataSources/PointVisualizerSpec.js @@ -35,6 +35,7 @@ describe( _surface: {}, imageryLayersUpdatedEvent: new Event(), terrainProviderChanged: new Event(), + tileLoadProgressEvent: new Event(), }; scene.globe.getHeight = function () { diff --git a/packages/engine/Specs/Scene/Cesium3DTilesetSpec.js b/packages/engine/Specs/Scene/Cesium3DTilesetSpec.js index 20849c2cd004..6240d6592148 100644 --- a/packages/engine/Specs/Scene/Cesium3DTilesetSpec.js +++ b/packages/engine/Specs/Scene/Cesium3DTilesetSpec.js @@ -2577,9 +2577,9 @@ describe( ); const expected = new Cartesian3( - 1215013.8353220497, - -4736316.763939952, - 4081608.4319443353 + 1215013.1035421258, + -4736313.911345668, + 4081605.961099667 ); expect(tileset.pick(ray, scene.frameState)).toEqualEpsilon( expected, diff --git a/packages/engine/Specs/Scene/Model/ModelSpec.js b/packages/engine/Specs/Scene/Model/ModelSpec.js index 983c037b155e..4f8c2fa4c718 100644 --- a/packages/engine/Specs/Scene/Model/ModelSpec.js +++ b/packages/engine/Specs/Scene/Model/ModelSpec.js @@ -2278,6 +2278,7 @@ describe( beginFrame: function () {}, endFrame: function () {}, terrainProviderChanged: new Event(), + tileLoadProgressEvent: new Event(), }; Object.defineProperties(globe, { diff --git a/packages/engine/Specs/Scene/SceneSpec.js b/packages/engine/Specs/Scene/SceneSpec.js index 93400666cce2..349d73462b5c 100644 --- a/packages/engine/Specs/Scene/SceneSpec.js +++ b/packages/engine/Specs/Scene/SceneSpec.js @@ -2211,6 +2211,7 @@ describe( scene.morphToColumbusView(0.0); return updateGlobeUntilDone(scene).then(function () { + scene.renderForSpecs(); expect(scene.cameraUnderground).toBe(true); scene.destroyForSpecs(); }); @@ -2261,6 +2262,7 @@ describe( return updateGlobeUntilDone(scene); }) .then(function () { + scene.renderForSpecs(); expect(getFrustumCommandsLength(scene, Pass.OPAQUE)).toBe(1); scene.destroyForSpecs(); });