Skip to content

Commit

Permalink
Fix #11787
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed Jan 29, 2024
1 parent 50373e6 commit d34938c
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 29 deletions.
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/3D Tiles BIM.html
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/Ambient Occlusion.html
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/MSAA.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@
roll: 6.283184816241989,
},
});
createTileset(1240402);
createTileset(1240402, {
disableCollision: true,
});
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/Polylines on 3D Tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/development/3D Tiles Picking.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Specs/createGlobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function createGlobe(ellipsoid) {
imageryLayersUpdatedEvent: new Event(),
_terrainProvider: undefined,
terrainProviderChanged: new Event(),
tileLoadProgressEvent: new Event(),
destroy: function () {},
};

Expand Down
44 changes: 28 additions & 16 deletions packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
};

/**
Expand Down
29 changes: 25 additions & 4 deletions packages/engine/Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function Scene(options) {
this._groundPrimitives = new PrimitiveCollection();

this._globeHeight = undefined;
this._globeHeightDirty = undefined;
this._cameraUnderground = false;

this._logDepthBuffer = context.fragmentDepth;
Expand Down Expand Up @@ -748,6 +749,11 @@ function updateGlobeListeners(scene, globe) {
requestRenderAfterFrame(scene)
)
);
removeGlobeCallbacks.push(
globe.tileLoadProgressEvent.addEventListener(() => {
scene._globeHeightDirty = true;
})
);
}
scene._removeGlobeCallbacks = removeGlobeCallbacks;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -3643,7 +3657,7 @@ function getGlobeHeight(scene) {
return maxHeight;
}

return undefined;
return;
}

function isCameraUnderground(scene) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 ||
Expand Down
1 change: 1 addition & 0 deletions packages/engine/Specs/DataSources/EntityClusterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe(
},
terrainProviderChanged: new Event(),
imageryLayersUpdatedEvent: new Event(),
tileLoadProgressEvent: new Event(),
beginFrame: function () {},
update: function () {},
render: function () {},
Expand Down
1 change: 1 addition & 0 deletions packages/engine/Specs/DataSources/PointVisualizerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe(
_surface: {},
imageryLayersUpdatedEvent: new Event(),
terrainProviderChanged: new Event(),
tileLoadProgressEvent: new Event(),
};

scene.globe.getHeight = function () {
Expand Down
6 changes: 3 additions & 3 deletions packages/engine/Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/engine/Specs/Scene/Model/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,7 @@ describe(
beginFrame: function () {},
endFrame: function () {},
terrainProviderChanged: new Event(),
tileLoadProgressEvent: new Event(),
};

Object.defineProperties(globe, {
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/Specs/Scene/SceneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,7 @@ describe(
scene.morphToColumbusView(0.0);

return updateGlobeUntilDone(scene).then(function () {
scene.renderForSpecs();
expect(scene.cameraUnderground).toBe(true);
scene.destroyForSpecs();
});
Expand Down Expand Up @@ -2261,6 +2262,7 @@ describe(
return updateGlobeUntilDone(scene);
})
.then(function () {
scene.renderForSpecs();
expect(getFrustumCommandsLength(scene, Pass.OPAQUE)).toBe(1);
scene.destroyForSpecs();
});
Expand Down

0 comments on commit d34938c

Please sign in to comment.