Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <CesiumRasterOverlays/RasterOverlayDetails.h>
#include <CesiumUtility/CreditSystem.h>
#include <CesiumUtility/ExtensibleObject.h>
#include <CesiumVectorData/GeoJsonDocument.h>

#include <memory>
#include <variant>
Expand Down Expand Up @@ -203,6 +204,52 @@ class CESIUM3DTILESSELECTION_API TileRenderContent {
float _lodTransitionFadePercentage;
};

/**
* @brief A content tag that indicates a tile has a GeoJson content and
* render resources for the resulting geometry.
*/
class CESIUM3DTILESSELECTION_API TileFeatureContent {
public:
/**
* @brief Construct the content with a GeoJson document.
*
* @param geoJson A GeoJson document that will be owned by this content
*/
explicit TileFeatureContent(CesiumVectorData::GeoJsonDocument&& geoJson);

/**
* @brief Get the render resources created for the feature content
*
* @return The created render resources
*/
void* getRenderResources() const noexcept;

/**
* @brief Set the GeoJson for this content
*
* @param geoJson a GeoJsonDocument that will be owned by this content
*/
void setGeoJson(const CesiumVectorData::GeoJsonDocument& geoJson);

/**
* @brief Set the GeoJson for this content
*
* @param geoJson a GeoJsonDocument that will be owned by this content
*/
void setGeoJson(CesiumVectorData::GeoJsonDocument&& geoJson);

/**
* @brief Set the render resources created for the feature content
*
* @param pRenderResources The created render resources
*/
void setRenderResources(void* pRenderResources) noexcept;

private:
CesiumVectorData::GeoJsonDocument _geoJson;
void* _pRenderResources;
};

/**
* @brief A tile content container that can store and query the content type
* that is currently being owned by the tile
Expand All @@ -212,7 +259,8 @@ class CESIUM3DTILESSELECTION_API TileContent {
TileUnknownContent,
TileEmptyContent,
std::unique_ptr<TileExternalContent>,
std::unique_ptr<TileRenderContent>>;
std::unique_ptr<TileRenderContent>,
std::unique_ptr<TileFeatureContent>>;

public:
/**
Expand Down Expand Up @@ -256,6 +304,11 @@ class CESIUM3DTILESSELECTION_API TileContent {
*/
void setContentKind(std::unique_ptr<TileRenderContent>&& content);

/**
* @brief Set feature content for a tile
*/
void setContentKind(std::unique_ptr<TileFeatureContent>&& content);

/**
* @brief Query if a tile has an unknown content
*/
Expand All @@ -277,6 +330,11 @@ class CESIUM3DTILESSELECTION_API TileContent {
*/
bool isRenderContent() const noexcept;

/**
* @brief Query if a tile has feature content
*/
bool isFeatureContent() const noexcept;

/**
* @brief Get the {@link TileRenderContent} which stores the glTF model
* and render resources of the tile
Expand All @@ -301,6 +359,18 @@ class CESIUM3DTILESSELECTION_API TileContent {
*/
TileExternalContent* getExternalContent() noexcept;

/**
* @brief Get the {@link TileFeatureContent} which stores GeoJson
* and render resources of the tile
*/
const TileFeatureContent* getFeatureContent() const noexcept;

/**
* @brief Get the {@link TileFeatureContent} which stores GeoJson
* and render resources of the tile
*/
TileFeatureContent* getFeatureContent() noexcept;

private:
TileContentKindImpl _contentKind;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGltf/Model.h>
#include <CesiumRasterOverlays/RasterOverlayDetails.h>
#include <CesiumVectorData/GeoJsonDocument.h>

#include <functional>
#include <memory>
Expand All @@ -33,12 +34,15 @@ class Tile;
* 3. Returning {@link TileExternalContent} means that this tile points to an external tileset
*
* 4. Returning {@link CesiumGltf::Model} means that this tile has glTF model
*
* 5. Returning {@link CesiumVectorData::GeoJsonDocument} means that this tile has feature data
*/
using TileContentKind = std::variant<
TileUnknownContent,
TileEmptyContent,
TileExternalContent,
CesiumGltf::Model>;
CesiumGltf::Model,
CesiumVectorData::GeoJsonDocument>;

/**
* @brief Indicate the status of {@link Cesium3DTilesSelection::TilesetContentLoader::loadTileContent} and
Expand Down
53 changes: 53 additions & 0 deletions Cesium3DTilesSelection/src/TileContent.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Cesium3DTilesSelection/TileContent.h>
#include <CesiumGltf/Model.h>
#include <CesiumUtility/CreditSystem.h>
#include <CesiumVectorData/GeoJsonDocument.h>

#include <memory>
#include <utility>
Expand Down Expand Up @@ -84,6 +85,28 @@ void TileRenderContent::setLodTransitionFadePercentage(
this->_lodTransitionFadePercentage = percentage;
}

TileFeatureContent::TileFeatureContent(
CesiumVectorData::GeoJsonDocument&& geoJson)
: _geoJson(std::move(geoJson)), _pRenderResources(nullptr) {}

void* TileFeatureContent::getRenderResources() const noexcept {
return _pRenderResources;
}

void TileFeatureContent::setGeoJson(
const CesiumVectorData::GeoJsonDocument& geoJson) {
_geoJson = geoJson;
}

void TileFeatureContent::setGeoJson(
CesiumVectorData::GeoJsonDocument&& geoJson) {
_geoJson = std::move(geoJson);
}

void TileFeatureContent::setRenderResources(void* pRenderResources) noexcept {
_pRenderResources = pRenderResources;
}

TileContent::TileContent() : _contentKind{TileUnknownContent{}} {}

TileContent::TileContent(TileEmptyContent content) : _contentKind{content} {}
Expand All @@ -108,6 +131,11 @@ void TileContent::setContentKind(std::unique_ptr<TileRenderContent>&& content) {
_contentKind = std::move(content);
}

void TileContent::setContentKind(
std::unique_ptr<TileFeatureContent>&& content) {
_contentKind = std::move(content);
}

bool TileContent::isUnknownContent() const noexcept {
return std::holds_alternative<TileUnknownContent>(this->_contentKind);
}
Expand All @@ -126,6 +154,11 @@ bool TileContent::isRenderContent() const noexcept {
this->_contentKind);
}

bool TileContent::isFeatureContent() const noexcept {
return std::holds_alternative<std::unique_ptr<TileFeatureContent>>(
this->_contentKind);
}

const TileRenderContent* TileContent::getRenderContent() const noexcept {
const std::unique_ptr<TileRenderContent>* pRenderContent =
std::get_if<std::unique_ptr<TileRenderContent>>(&this->_contentKind);
Expand Down Expand Up @@ -166,4 +199,24 @@ TileExternalContent* TileContent::getExternalContent() noexcept {
return nullptr;
}

const TileFeatureContent* TileContent::getFeatureContent() const noexcept {
const std::unique_ptr<TileFeatureContent>* pFeatureContent =
std::get_if<std::unique_ptr<TileFeatureContent>>(&this->_contentKind);
if (pFeatureContent) {
return pFeatureContent->get();
}

return nullptr;
}

TileFeatureContent* TileContent::getFeatureContent() noexcept {
std::unique_ptr<TileFeatureContent>* pFeatureContent =
std::get_if<std::unique_ptr<TileFeatureContent>>(&this->_contentKind);
if (pFeatureContent) {
return pFeatureContent->get();
}

return nullptr;
}

} // namespace Cesium3DTilesSelection
23 changes: 22 additions & 1 deletion Cesium3DTilesSelection/src/TilesetContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <CesiumUtility/ReferenceCounted.h>
#include <CesiumUtility/Tracing.h>
#include <CesiumUtility/joinToString.h>
#include <CesiumVectorData/GeoJsonDocument.h>

#include <fmt/format.h>
#include <glm/common.hpp>
Expand Down Expand Up @@ -123,6 +124,11 @@ struct ContentKindSetter {
tileContent.setContentKind(std::move(pRenderContent));
}

void operator()(CesiumVectorData::GeoJsonDocument&& content) {
tileContent.setContentKind(
std::make_unique<TileFeatureContent>(std::move(content)));
}

TileContent& tileContent;
std::optional<RasterOverlayDetails> rasterOverlayDetails;
void* pRenderResources;
Expand Down Expand Up @@ -1128,8 +1134,8 @@ void TilesetContentManager::loadTileContent(
// related to render content. We only ever spawn a new task in the
// worker thread if the content is a render content
if (result.state == TileLoadResultState::Success) {
auto asyncSystem = tileLoadInfo.asyncSystem;
if (std::holds_alternative<CesiumGltf::Model>(result.contentKind)) {
auto asyncSystem = tileLoadInfo.asyncSystem;
return asyncSystem.runInWorkerThread(
[result = std::move(result),
projections = std::move(projections),
Expand All @@ -1141,6 +1147,21 @@ void TilesetContentManager::loadTileContent(
std::move(tileLoadInfo),
rendererOptions);
});
} else if (
std::holds_alternative<CesiumVectorData::GeoJsonDocument>(
result.contentKind) &&
tileLoadInfo.pPrepareRendererResources) {
return asyncSystem.runInWorkerThread(
[result = std::move(result),
tileLoadInfo = std::move(tileLoadInfo),
rendererOptions]() mutable {
return tileLoadInfo.pPrepareRendererResources
->prepareInLoadThread(
tileLoadInfo.asyncSystem,
std::move(result),
tileLoadInfo.tileTransform,
rendererOptions);
});
}
}

Expand Down
Loading
Loading