Skip to content
Draft
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
13 changes: 9 additions & 4 deletions Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,12 @@ class CESIUM3DTILESSELECTION_API Tileset final {
const TilesetFrameState& frameState,
Tile& tile,
double tilePriority,
double tileSse,
ViewUpdateResult& result);
TraversalDetails _renderInnerTile(
const TilesetFrameState& frameState,
Tile& tile,
double tileSse,
ViewUpdateResult& result);
bool _kickDescendantsAndRenderTile(
const TilesetFrameState& frameState,
Expand All @@ -517,7 +519,8 @@ class CESIUM3DTILESSELECTION_API Tileset final {
size_t firstRenderedDescendantIndex,
const TilesetViewGroup::LoadQueueCheckpoint& loadQueueBeforeChildren,
bool queuedForLoad,
double tilePriority);
double tilePriority,
double tileSse);
TileOcclusionState _checkOcclusion(const Tile& tile);

TraversalDetails _visitTile(
Expand All @@ -527,6 +530,7 @@ class CESIUM3DTILESSELECTION_API Tileset final {
bool ancestorMeetsSse,
Tile& tile,
double tilePriority,
double tileSse,
ViewUpdateResult& result);

struct CullResult {
Expand All @@ -546,11 +550,11 @@ class CESIUM3DTILESSELECTION_API Tileset final {
const TilesetFrameState& frameState,
const std::vector<double>& distances,
CullResult& cullResult);
bool _meetsSse(
double _computeSse(
const std::vector<ViewState>& frustums,
const Tile& tile,
const std::vector<double>& distances,
bool culled) const noexcept;
const std::vector<double>& distances) const noexcept;
bool _meetsSseThreshold(double sse, bool culled) const noexcept;

TraversalDetails _visitTileIfNeeded(
const TilesetFrameState& frameState,
Expand Down Expand Up @@ -585,6 +589,7 @@ class CESIUM3DTILESSELECTION_API Tileset final {
Tile& tile,
ViewUpdateResult& result,
double tilePriority,
double tileSse,
bool queuedForLoad);

void _unloadCachedTiles(double timeBudget) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@ class CESIUM3DTILESSELECTION_API ViewUpdateResult final {
* @brief The tiles that were selected by the tileset traversal this frame.
* These tiles should be rendered by the client.
*
* Tiles in this list may be fading in if
* {@link TilesetOptions::enableLodTransitionPeriod} is true.
* Tiles in this list may be fading in if \ref
* TilesetOptions::enableLodTransitionPeriod is true.
*/
std::vector<Tile::ConstPointer> tilesToRenderThisFrame;

/**
* @brief The computed screen space error of the tiles selected by the
* tileset traversal this frame. The values correspond to the tiles linked in
* \ref tilesToRenderThisFrame, and may be used by the client to influence
* rendering behavior.
*/
std::vector<double> tileScreenSpaceErrorThisFrame;

/**
* @brief Tiles on this list are no longer selected for rendering.
*
* If {@link TilesetOptions::enableLodTransitionPeriod} is true they may be
* fading out. If a tile's {TileRenderContent::lodTransitionPercentage} is 0
* or lod transitions are disabled, the tile should be hidden right away.
* If \ref TilesetOptions::enableLodTransitionPeriod is true they may be
* fading out. If a tile's \ref TileRenderContent::lodTransitionPercentage is
* 0 or LOD transitions are disabled, the tile should be hidden right away.
*/
std::unordered_set<Tile::ConstPointer> tilesFadingOut;

Expand Down
42 changes: 31 additions & 11 deletions Cesium3DTilesSelection/src/Tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,10 @@ void computeDistances(

} // namespace

bool Tileset::_meetsSse(
double Tileset::_computeSse(
const std::vector<ViewState>& frustums,
const Tile& tile,
const std::vector<double>& distances,
bool culled) const noexcept {
const std::vector<double>& distances) const noexcept {

double largestSse = 0.0;

Expand All @@ -880,10 +879,13 @@ bool Tileset::_meetsSse(
largestSse = sse;
}
}
return largestSse;
}

bool Tileset::_meetsSseThreshold(double sse, bool culled) const noexcept {
return culled ? !this->_options.enforceCulledScreenSpaceError ||
largestSse < this->_options.culledScreenSpaceError
: largestSse < this->_options.maximumScreenSpaceError;
sse < this->_options.culledScreenSpaceError
: sse < this->_options.maximumScreenSpaceError;
}

// Visits a tile for possible rendering. When we call this function with a tile:
Expand Down Expand Up @@ -992,8 +994,8 @@ Tileset::TraversalDetails Tileset::_visitTileIfNeeded(
++result.culledTilesVisited;
}

bool meetsSse =
this->_meetsSse(frameState.frustums, tile, distances, cullResult.culled);
double tileSse = this->_computeSse(frameState.frustums, tile, distances);
bool meetsSse = this->_meetsSseThreshold(tileSse, cullResult.culled);

TraversalDetails details = this->_visitTile(
frameState,
Expand All @@ -1002,6 +1004,7 @@ Tileset::TraversalDetails Tileset::_visitTileIfNeeded(
ancestorMeetsSse,
tile,
tilePriority,
tileSse,
result);

traversalState.finishNode(&tile);
Expand All @@ -1017,10 +1020,12 @@ Tileset::TraversalDetails Tileset::_renderLeaf(
const TilesetFrameState& frameState,
Tile& tile,
double tilePriority,
double tileSse,
ViewUpdateResult& result) {
frameState.viewGroup.getTraversalState().currentState() =
TileSelectionState(TileSelectionState::Result::Rendered);
result.tilesToRenderThisFrame.emplace_back(&tile);
result.tileScreenSpaceErrorThisFrame.emplace_back(tileSse);

addTileToLoadQueue(
frameState,
Expand Down Expand Up @@ -1064,6 +1069,7 @@ bool mustContinueRefiningToDeeperTiles(
Tileset::TraversalDetails Tileset::_renderInnerTile(
const TilesetFrameState& frameState,
Tile& tile,
double tileSse,
ViewUpdateResult& result) {
addCurrentTileDescendantsToTilesFadingOutIfPreviouslyRendered(
frameState.viewGroup,
Expand All @@ -1072,6 +1078,7 @@ Tileset::TraversalDetails Tileset::_renderInnerTile(
frameState.viewGroup.getTraversalState().currentState() =
TileSelectionState(TileSelectionState::Result::Rendered);
result.tilesToRenderThisFrame.emplace_back(&tile);
result.tileScreenSpaceErrorThisFrame.emplace_back(tileSse);

return Tileset::createTraversalDetailsForSingleTile(frameState, tile);
}
Expand All @@ -1081,11 +1088,13 @@ bool Tileset::_loadAndRenderAdditiveRefinedTile(
Tile& tile,
ViewUpdateResult& result,
double tilePriority,
double tileSse,
bool queuedForLoad) {
// If this tile uses additive refinement, we need to render this tile in
// addition to its children.
if (tile.getRefine() == TileRefine::Add) {
result.tilesToRenderThisFrame.emplace_back(&tile);
result.tileScreenSpaceErrorThisFrame.emplace_back(tileSse);
if (!queuedForLoad)
addTileToLoadQueue(
frameState,
Expand All @@ -1106,7 +1115,8 @@ bool Tileset::_kickDescendantsAndRenderTile(
size_t firstRenderedDescendantIndex,
const TilesetViewGroup::LoadQueueCheckpoint& loadQueueBeforeChildren,
bool queuedForLoad,
double tilePriority) {
double tilePriority,
double tileSse) {
// Mark all visited descendants of this tile as kicked.
TilesetViewGroup::TraversalState& traversalState =
frameState.viewGroup.getTraversalState();
Expand All @@ -1117,14 +1127,21 @@ bool Tileset::_kickDescendantsAndRenderTile(

// Remove all descendants from the render list and add this tile.
std::vector<Tile::ConstPointer>& renderList = result.tilesToRenderThisFrame;
std::vector<double>& sseList = result.tileScreenSpaceErrorThisFrame;
renderList.erase(
renderList.begin() +
static_cast<std::vector<Tile*>::iterator::difference_type>(
firstRenderedDescendantIndex),
renderList.end());
sseList.erase(
sseList.begin() +
static_cast<std::vector<double>::iterator::difference_type>(
firstRenderedDescendantIndex),
sseList.end());

if (tile.getRefine() != Cesium3DTilesSelection::TileRefine::Add) {
renderList.emplace_back(&tile);
sseList.push_back(tileSse);
}

traversalState.currentState() =
Expand Down Expand Up @@ -1280,6 +1297,7 @@ Tileset::TraversalDetails Tileset::_visitTile(
// children!
Tile& tile,
double tilePriority,
double tileSse,
ViewUpdateResult& result) {
TilesetViewGroup::TraversalState& traversalState =
frameState.viewGroup.getTraversalState();
Expand All @@ -1289,7 +1307,7 @@ Tileset::TraversalDetails Tileset::_visitTile(

// If this is a leaf tile, just render it (it's already been deemed visible).
if (isLeaf(tile)) {
return this->_renderLeaf(frameState, tile, tilePriority, result);
return this->_renderLeaf(frameState, tile, tilePriority, tileSse, result);
}

const bool unconditionallyRefine = tile.getUnconditionallyRefine();
Expand Down Expand Up @@ -1393,7 +1411,7 @@ Tileset::TraversalDetails Tileset::_visitTile(
tilePriority);
}

return this->_renderInnerTile(frameState, tile, result);
return this->_renderInnerTile(frameState, tile, tileSse, result);
}
}

Expand All @@ -1404,6 +1422,7 @@ Tileset::TraversalDetails Tileset::_visitTile(
tile,
result,
tilePriority,
tileSse,
queuedForLoad) ||
queuedForLoad;

Expand Down Expand Up @@ -1457,7 +1476,8 @@ Tileset::TraversalDetails Tileset::_visitTile(
firstRenderedDescendantIndex,
loadQueueBeforeChildren,
queuedForLoad,
tilePriority);
tilePriority,
tileSse);
} else {
if (tile.getRefine() != TileRefine::Add) {
addCurrentTileToTilesFadingOutIfPreviouslyRendered(
Expand Down
1 change: 1 addition & 0 deletions Cesium3DTilesSelection/src/TilesetViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void TilesetViewGroup::startNewFrame(
this->_updateResult.maxDepthVisited = 0;

this->_updateResult.tilesToRenderThisFrame.clear();
this->_updateResult.tileScreenSpaceErrorThisFrame.clear();

if (!tileset.getOptions().enableLodTransitionPeriod) {
this->_updateResult.tilesFadingOut.clear();
Expand Down
Loading