diff --git a/.vscode/settings.json b/.vscode/settings.json index b9550a3de..f92e06db9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -114,8 +114,9 @@ "ktxint.h": "c", "texture.h": "c", "gl_format.h": "c", - "complex": "cpp" + "complex": "cpp", + "expected": "cpp" }, "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", "cmake.configureOnOpen": true -} \ No newline at end of file +} diff --git a/CHANGES.md b/CHANGES.md index af76ce6ce..273ad30da 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,18 @@ # Change Log +### ? - ? + +##### Breaking Changes :mega: + +- Moved `ErrorList` from `Cesium3DTilesSelection` to `CesiumUtility`. +- Moved `GltfUtilities` from `Cesium3DTilesSelection` to `Cesium3DTilesContent`. +- Moved `createRasterOverlayTextureCoordinates` method from `GltfUtilities` to a new `RasterOverlayUtilities` class in the `Cesium3DTilesSelection` library. +- `GltfUtilities::parseGltfCopyright` now returns the credits as a vector of string_views. Previously it took a `CreditSystem` and created credits directly. + +##### Additions :tada: + +- Added `Cesium3DTilesContent` library and namespace. It has classes for loading, converting, and manipulating 3D Tiles tile content. + ### v0.29.0 - 2023-11-01 ##### Breaking Changes :mega: diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cc56c489..efd419bef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,7 @@ add_subdirectory(CesiumAsync) add_subdirectory(Cesium3DTiles) add_subdirectory(Cesium3DTilesReader) add_subdirectory(Cesium3DTilesWriter) +add_subdirectory(Cesium3DTilesContent) add_subdirectory(Cesium3DTilesSelection) add_subdirectory(CesiumIonClient) diff --git a/Cesium3DTilesContent/CMakeLists.txt b/Cesium3DTilesContent/CMakeLists.txt new file mode 100644 index 000000000..8493e1397 --- /dev/null +++ b/Cesium3DTilesContent/CMakeLists.txt @@ -0,0 +1,67 @@ +add_library(Cesium3DTilesContent "") +configure_cesium_library(Cesium3DTilesContent) + +cesium_glob_files(CESIUM_3DTILES_CONTENT_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp + ${CMAKE_CURRENT_LIST_DIR}/generated/src/*.cpp +) +cesium_glob_files(CESIUM_3DTILES_CONTENT_HEADERS + ${CMAKE_CURRENT_LIST_DIR}/src/*.h + ${CMAKE_CURRENT_LIST_DIR}/generated/src/*.h +) +cesium_glob_files(CESIUM_3DTILES_CONTENT_PUBLIC_HEADERS + ${CMAKE_CURRENT_LIST_DIR}/include/Cesium3DTilesContent/*.h + ${CMAKE_CURRENT_LIST_DIR}/generated/include/Cesium3DTilesContent/*.h +) +cesium_glob_files(CESIUM_3DTILES_CONTENT_TEST_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/test/*.cpp +) +cesium_glob_files(CESIUM_3DTILES_CONTENT_TEST_HEADERS + ${CMAKE_CURRENT_LIST_DIR}/test/*.h +) + +set_target_properties(Cesium3DTilesContent + PROPERTIES + TEST_SOURCES "${CESIUM_3DTILES_CONTENT_TEST_SOURCES}" + TEST_HEADERS "${CESIUM_3DTILES_CONTENT_TEST_HEADERS}" + TEST_DATA_DIR ${CMAKE_CURRENT_LIST_DIR}/test/data +) + +set_target_properties(Cesium3DTilesContent + PROPERTIES + PUBLIC_HEADER "${CESIUM_3DTILES_CONTENT_PUBLIC_HEADERS}" +) + +target_sources( + Cesium3DTilesContent + PRIVATE + ${CESIUM_3DTILES_CONTENT_SOURCES} + ${CESIUM_3DTILES_CONTENT_HEADERS} + PUBLIC + ${CESIUM_3DTILES_CONTENT_PUBLIC_HEADERS} +) + +target_include_directories( + Cesium3DTilesContent + SYSTEM PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/include + ${CMAKE_CURRENT_LIST_DIR}/generated/include + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/src + ${CMAKE_CURRENT_LIST_DIR}/generated/src +) + +target_link_libraries(Cesium3DTilesContent + PUBLIC + CesiumAsync + CesiumGeometry + CesiumGeospatial + CesiumGltf + CesiumGltfReader + CesiumUtility +) + +install(TARGETS Cesium3DTilesContent + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Cesium3DTilesContent +) diff --git a/Cesium3DTilesSelection/src/B3dmToGltfConverter.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/B3dmToGltfConverter.h similarity index 70% rename from Cesium3DTilesSelection/src/B3dmToGltfConverter.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/B3dmToGltfConverter.h index 299106f1c..a13e643c4 100644 --- a/Cesium3DTilesSelection/src/B3dmToGltfConverter.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/B3dmToGltfConverter.h @@ -1,6 +1,7 @@ #pragma once -#include +#include "GltfConverterResult.h" + #include #include @@ -8,10 +9,10 @@ #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct B3dmToGltfConverter { static GltfConverterResult convert( const gsl::span& b3dmBinary, const CesiumGltfReader::GltfReaderOptions& options); }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/BinaryToGltfConverter.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/BinaryToGltfConverter.h similarity index 73% rename from Cesium3DTilesSelection/src/BinaryToGltfConverter.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/BinaryToGltfConverter.h index 85eeaa566..910f3c305 100644 --- a/Cesium3DTilesSelection/src/BinaryToGltfConverter.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/BinaryToGltfConverter.h @@ -1,13 +1,13 @@ #pragma once -#include +#include #include #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct BinaryToGltfConverter { public: static GltfConverterResult convert( @@ -17,4 +17,4 @@ struct BinaryToGltfConverter { private: static CesiumGltfReader::GltfReader _gltfReader; }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/CmptToGltfConverter.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/CmptToGltfConverter.h similarity index 68% rename from Cesium3DTilesSelection/src/CmptToGltfConverter.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/CmptToGltfConverter.h index 20b845456..ad7280a32 100644 --- a/Cesium3DTilesSelection/src/CmptToGltfConverter.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/CmptToGltfConverter.h @@ -1,16 +1,16 @@ #pragma once -#include +#include #include #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct CmptToGltfConverter { static GltfConverterResult convert( const gsl::span& cmptBinary, const CesiumGltfReader::GltfReaderOptions& options); }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfConverterResult.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/GltfConverterResult.h similarity index 77% rename from Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfConverterResult.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/GltfConverterResult.h index 83f50cf4b..54fd31114 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfConverterResult.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/GltfConverterResult.h @@ -2,12 +2,12 @@ #include "Library.h" -#include #include +#include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { /** * @brief The result of converting a binary content to gltf model. * @@ -15,7 +15,7 @@ namespace Cesium3DTilesSelection { * {@link GltfConverters}, when the response to a network request for * loading the tile content was received. */ -struct CESIUM3DTILESSELECTION_API GltfConverterResult { +struct CESIUM3DTILESCONTENT_API GltfConverterResult { /** * @brief The gltf model converted from a binary content. This is empty if * there are errors during the conversion @@ -26,6 +26,6 @@ struct CESIUM3DTILESSELECTION_API GltfConverterResult { * @brief The error and warning list when converting a binary content to gltf * model. This is empty if there are no errors during the conversion */ - ErrorList errors; + CesiumUtility::ErrorList errors; }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfConverters.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/GltfConverters.h similarity index 97% rename from Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfConverters.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/GltfConverters.h index f027da24c..bc07748d1 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfConverters.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/GltfConverters.h @@ -2,7 +2,7 @@ #include "Library.h" -#include +#include #include #include @@ -11,7 +11,7 @@ #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { /** * @brief Creates {@link GltfConverterResult} objects from a * a binary content. @@ -26,7 +26,7 @@ namespace Cesium3DTilesSelection { * header. Based on this header or the file extension of the network response, * the loader that will be used for processing the input can be looked up. */ -class CESIUM3DTILESSELECTION_API GltfConverters { +class CESIUM3DTILESCONTENT_API GltfConverters { public: /** * @brief A function pointer that can create a {@link GltfConverterResult} from a @@ -166,4 +166,4 @@ class CESIUM3DTILESSELECTION_API GltfConverters { static std::unordered_map _loadersByFileExtension; }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesContent/include/Cesium3DTilesContent/GltfUtilities.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/GltfUtilities.h new file mode 100644 index 000000000..5bb0c1a63 --- /dev/null +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/GltfUtilities.h @@ -0,0 +1,96 @@ +#pragma once + +#include "Library.h" + +#include +#include + +#include + +#include +#include + +namespace CesiumGltf { +struct Model; +} + +namespace Cesium3DTilesContent { +/** + * A collection of utility functions that are used to process and transform a + * gltf model + */ +struct CESIUM3DTILESCONTENT_API GltfUtilities { + /** + * @brief Applies the glTF's RTC_CENTER, if any, to the given transform. + * + * If the glTF has a `CESIUM_RTC` extension, this function will multiply the + * given matrix with the (translation) matrix that is created from the + * `RTC_CENTER` in the. If the given model does not have this extension, then + * this function will return the `rootTransform` unchanged. + * + * @param model The glTF model + * @param rootTransform The matrix that will be multiplied with the transform + * @return The result of multiplying the `RTC_CENTER` with the + * `rootTransform`. + */ + static glm::dmat4x4 applyRtcCenter( + const CesiumGltf::Model& gltf, + const glm::dmat4x4& rootTransform); + + /** + * @brief Applies the glTF's `gltfUpAxis`, if any, to the given transform. + * + * By default, the up-axis of a glTF model will the the Y-axis. + * + * If the tileset that contained the model had the `asset.gltfUpAxis` string + * property, then the information about the up-axis has been stored in as a + * number property called `gltfUpAxis` in the `extras` of the given model. + * + * Depending on whether this value is `CesiumGeometry::Axis::X`, `Y`, or `Z`, + * the given matrix will be multiplied with a matrix that converts the + * respective axis to be the Z-axis, as required by the 3D Tiles standard. + * + * @param model The glTF model + * @param rootTransform The matrix that will be multiplied with the transform + * @return The result of multiplying the `rootTransform` with the + * `gltfUpAxis`. + */ + static glm::dmat4x4 applyGltfUpAxisTransform( + const CesiumGltf::Model& model, + const glm::dmat4x4& rootTransform); + + /** + * @brief Computes a bounding region from the vertex positions in a glTF + * model. + * + * If the glTF model spans the anti-meridian, the west and east longitude + * values will be in the usual -PI to PI range, but east will have a smaller + * value than west. + * + * If the glTF contains no geometry, the returned region's rectangle + * will be {@link GlobeRectangle::EMPTY}, its minimum height will be 1.0, and + * its maximum height will be -1.0 (the minimum will be greater than the + * maximum). + * + * @param gltf The model. + * @param transform The transform from model coordinates to ECEF coordinates. + * @return The computed bounding region. + */ + static CesiumGeospatial::BoundingRegion computeBoundingRegion( + const CesiumGltf::Model& gltf, + const glm::dmat4& transform); + + /** + * @brief Parse the copyright field of a glTF model and return the individual + * credits. + * + * Credits are read from the glTF's asset.copyright field. This method assumes + * that individual credits are separated by semicolons. + * + * @param gltf The model. + * @return The credits from the glTF. + */ + static std::vector + parseGltfCopyright(const CesiumGltf::Model& gltf); +}; +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesContent/include/Cesium3DTilesContent/Library.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/Library.h new file mode 100644 index 000000000..26f187703 --- /dev/null +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/Library.h @@ -0,0 +1,16 @@ +#pragma once + +/** + * @brief Classes that support loading and converting 3D Tiles tile content. + */ +namespace Cesium3DTilesContent {} + +#if defined(_WIN32) && defined(CESIUM_SHARED) +#ifdef CESIUM3DTILESCONTENT_BUILDING +#define CESIUM3DTILESCONTENT_API __declspec(dllexport) +#else +#define CESIUM3DTILESCONTENT_API __declspec(dllimport) +#endif +#else +#define CESIUM3DTILESCONTENT_API +#endif diff --git a/Cesium3DTilesSelection/src/PntsToGltfConverter.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/PntsToGltfConverter.h similarity index 70% rename from Cesium3DTilesSelection/src/PntsToGltfConverter.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/PntsToGltfConverter.h index 47e6aa07b..48593ca00 100644 --- a/Cesium3DTilesSelection/src/PntsToGltfConverter.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/PntsToGltfConverter.h @@ -1,6 +1,7 @@ #pragma once -#include +#include "GltfConverterResult.h" + #include #include @@ -8,10 +9,10 @@ #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct PntsToGltfConverter { static GltfConverterResult convert( const gsl::span& pntsBinary, const CesiumGltfReader::GltfReaderOptions& options); }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/QuantizedMeshLoader.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/QuantizedMeshLoader.h similarity index 76% rename from Cesium3DTilesSelection/src/QuantizedMeshLoader.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/QuantizedMeshLoader.h index ab32df66b..5ffe02940 100644 --- a/Cesium3DTilesSelection/src/QuantizedMeshLoader.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/QuantizedMeshLoader.h @@ -1,12 +1,14 @@ #pragma once -#include -#include -#include -#include +#include "Library.h" + +#include #include +#include #include +#include +#include #include #include @@ -18,7 +20,7 @@ namespace CesiumAsync { class IAssetRequest; } -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct QuantizedMeshLoadResult { /** @@ -31,12 +33,12 @@ struct QuantizedMeshLoadResult { std::optional model; /** - * @brief An improved bounding volume for this tile. + * @brief An improved bounding region for this tile. * * If this is available, then it is more accurate than the one the tile used * originally. */ - std::optional updatedBoundingVolume{}; + std::optional updatedBoundingVolume{}; /** * @brief Available quadtree tiles discovered as a result of loading this @@ -52,18 +54,18 @@ struct QuantizedMeshLoadResult { */ std::shared_ptr pRequest; - ErrorList errors; + CesiumUtility::ErrorList errors; }; struct QuantizedMeshMetadataResult { std::vector availability; - ErrorList errors; + CesiumUtility::ErrorList errors; }; /** * @brief Loads `quantized-mesh-1.0` terrain data. */ -class CESIUM3DTILESSELECTION_API QuantizedMeshLoader final { +class CESIUM3DTILESCONTENT_API QuantizedMeshLoader final { public: /** * @brief Create a {@link QuantizedMeshLoadResult} from the given data. @@ -75,8 +77,8 @@ class CESIUM3DTILESSELECTION_API QuantizedMeshLoader final { * @return The {@link QuantizedMeshLoadResult} */ static QuantizedMeshLoadResult load( - const TileID& tileID, - const BoundingVolume& tileBoundingVolume, + const CesiumGeometry::QuadtreeTileID& tileID, + const CesiumGeospatial::BoundingRegion& tileBoundingVolume, const std::string& url, const gsl::span& data, bool enableWaterMask); @@ -90,4 +92,4 @@ class CESIUM3DTILESSELECTION_API QuantizedMeshLoader final { uint32_t startingLevel); }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/SkirtMeshMetadata.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/SkirtMeshMetadata.h similarity index 92% rename from Cesium3DTilesSelection/src/SkirtMeshMetadata.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/SkirtMeshMetadata.h index 543d11160..45759a44e 100644 --- a/Cesium3DTilesSelection/src/SkirtMeshMetadata.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/SkirtMeshMetadata.h @@ -4,7 +4,7 @@ #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct SkirtMeshMetadata { SkirtMeshMetadata() noexcept : noSkirtIndicesBegin{0}, @@ -33,4 +33,4 @@ struct SkirtMeshMetadata { double skirtEastHeight; double skirtNorthHeight; }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/SubtreeAvailability.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/SubtreeAvailability.h similarity index 93% rename from Cesium3DTilesSelection/src/SubtreeAvailability.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/SubtreeAvailability.h index 3e5957974..29812234a 100644 --- a/Cesium3DTilesSelection/src/SubtreeAvailability.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/SubtreeAvailability.h @@ -1,12 +1,11 @@ #pragma once -#include #include #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct SubtreeConstantAvailability { bool constant; }; @@ -64,4 +63,4 @@ class SubtreeAvailability { std::vector _contentAvailability; std::vector> _buffers; }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/registerAllTileContentTypes.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/registerAllTileContentTypes.h similarity index 68% rename from Cesium3DTilesSelection/include/Cesium3DTilesSelection/registerAllTileContentTypes.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/registerAllTileContentTypes.h index ac0ef9ee6..1f4a1fcee 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/registerAllTileContentTypes.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/registerAllTileContentTypes.h @@ -1,6 +1,6 @@ #include "Library.h" -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { /** * @brief Register all {@link Tile} content types that can be loaded. @@ -9,6 +9,6 @@ namespace Cesium3DTilesSelection { * any {@link Tileset} is loaded. It will register loaders for the * different types of tiles that can be encountered. */ -CESIUM3DTILESSELECTION_API void registerAllTileContentTypes(); +CESIUM3DTILESCONTENT_API void registerAllTileContentTypes(); -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.h b/Cesium3DTilesContent/include/Cesium3DTilesContent/upsampleGltfForRasterOverlays.h similarity index 89% rename from Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.h rename to Cesium3DTilesContent/include/Cesium3DTilesContent/upsampleGltfForRasterOverlays.h index b347b1788..52e4bdea2 100644 --- a/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.h +++ b/Cesium3DTilesContent/include/Cesium3DTilesContent/upsampleGltfForRasterOverlays.h @@ -3,7 +3,7 @@ #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { std::optional upsampleGltfForRasterOverlays( const CesiumGltf::Model& parentModel, diff --git a/Cesium3DTilesSelection/src/B3dmToGltfConverter.cpp b/Cesium3DTilesContent/src/B3dmToGltfConverter.cpp similarity index 98% rename from Cesium3DTilesSelection/src/B3dmToGltfConverter.cpp rename to Cesium3DTilesContent/src/B3dmToGltfConverter.cpp index c4c9bf5c7..629679633 100644 --- a/Cesium3DTilesSelection/src/B3dmToGltfConverter.cpp +++ b/Cesium3DTilesContent/src/B3dmToGltfConverter.cpp @@ -1,14 +1,13 @@ -#include "B3dmToGltfConverter.h" - #include "BatchTableToGltfStructuralMetadata.h" -#include "BinaryToGltfConverter.h" +#include +#include #include #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { namespace { struct B3dmHeader { unsigned char magic[4]; @@ -254,4 +253,4 @@ GltfConverterResult B3dmToGltfConverter::convert( return result; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/BatchTableHierarchyPropertyValues.cpp b/Cesium3DTilesContent/src/BatchTableHierarchyPropertyValues.cpp similarity index 99% rename from Cesium3DTilesSelection/src/BatchTableHierarchyPropertyValues.cpp rename to Cesium3DTilesContent/src/BatchTableHierarchyPropertyValues.cpp index e504760a3..de06d88c0 100644 --- a/Cesium3DTilesSelection/src/BatchTableHierarchyPropertyValues.cpp +++ b/Cesium3DTilesContent/src/BatchTableHierarchyPropertyValues.cpp @@ -2,7 +2,7 @@ #include -using namespace Cesium3DTilesSelection::CesiumImpl; +using namespace Cesium3DTilesContent::CesiumImpl; namespace { diff --git a/Cesium3DTilesSelection/src/BatchTableHierarchyPropertyValues.h b/Cesium3DTilesContent/src/BatchTableHierarchyPropertyValues.h similarity index 97% rename from Cesium3DTilesSelection/src/BatchTableHierarchyPropertyValues.h rename to Cesium3DTilesContent/src/BatchTableHierarchyPropertyValues.h index 8e124434f..a5347d429 100644 --- a/Cesium3DTilesSelection/src/BatchTableHierarchyPropertyValues.h +++ b/Cesium3DTilesContent/src/BatchTableHierarchyPropertyValues.h @@ -5,7 +5,7 @@ #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { namespace CesiumImpl { /** @@ -104,4 +104,4 @@ class BatchTableHierarchyPropertyValues { }; } // namespace CesiumImpl -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.cpp b/Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.cpp similarity index 99% rename from Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.cpp rename to Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.cpp index 4ff3abc25..245a2cfe6 100644 --- a/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.cpp +++ b/Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.cpp @@ -1,7 +1,6 @@ #include "BatchTableToGltfStructuralMetadata.h" #include "BatchTableHierarchyPropertyValues.h" -#include "Cesium3DTilesSelection/spdlog-cesium.h" #include #include @@ -19,9 +18,10 @@ #include using namespace CesiumGltf; -using namespace Cesium3DTilesSelection::CesiumImpl; +using namespace Cesium3DTilesContent::CesiumImpl; +using namespace CesiumUtility; -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { namespace { /** * Indicates how a JSON value can be interpreted as a primitive type. Does not @@ -1932,4 +1932,4 @@ ErrorList BatchTableToGltfStructuralMetadata::convertFromPnts( return result; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.h b/Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.h similarity index 72% rename from Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.h rename to Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.h index 05517786b..d52281e7b 100644 --- a/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.h +++ b/Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.h @@ -1,25 +1,25 @@ #pragma once -#include #include +#include #include #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct BatchTableToGltfStructuralMetadata { - static ErrorList convertFromB3dm( + static CesiumUtility::ErrorList convertFromB3dm( const rapidjson::Document& featureTableJson, const rapidjson::Document& batchTableJson, const gsl::span& batchTableBinaryData, CesiumGltf::Model& gltf); - static ErrorList convertFromPnts( + static CesiumUtility::ErrorList convertFromPnts( const rapidjson::Document& featureTableJson, const rapidjson::Document& batchTableJson, const gsl::span& batchTableBinaryData, CesiumGltf::Model& gltf); }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/BinaryToGltfConverter.cpp b/Cesium3DTilesContent/src/BinaryToGltfConverter.cpp similarity index 81% rename from Cesium3DTilesSelection/src/BinaryToGltfConverter.cpp rename to Cesium3DTilesContent/src/BinaryToGltfConverter.cpp index cfa4e62df..d6420c89b 100644 --- a/Cesium3DTilesSelection/src/BinaryToGltfConverter.cpp +++ b/Cesium3DTilesContent/src/BinaryToGltfConverter.cpp @@ -1,6 +1,6 @@ -#include "BinaryToGltfConverter.h" +#include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { CesiumGltfReader::GltfReader BinaryToGltfConverter::_gltfReader; GltfConverterResult BinaryToGltfConverter::convert( @@ -15,4 +15,4 @@ GltfConverterResult BinaryToGltfConverter::convert( result.errors.warnings = std::move(loadedGltf.warnings); return result; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/CmptToGltfConverter.cpp b/Cesium3DTilesContent/src/CmptToGltfConverter.cpp similarity index 94% rename from Cesium3DTilesSelection/src/CmptToGltfConverter.cpp rename to Cesium3DTilesContent/src/CmptToGltfConverter.cpp index 534dc95d1..5676e42e4 100644 --- a/Cesium3DTilesSelection/src/CmptToGltfConverter.cpp +++ b/Cesium3DTilesContent/src/CmptToGltfConverter.cpp @@ -1,10 +1,9 @@ -#include "CmptToGltfConverter.h" - -#include +#include +#include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { namespace { struct CmptHeader { char magic[4]; @@ -111,4 +110,4 @@ GltfConverterResult CmptToGltfConverter::convert( return result; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/GltfConverters.cpp b/Cesium3DTilesContent/src/GltfConverters.cpp similarity index 96% rename from Cesium3DTilesSelection/src/GltfConverters.cpp rename to Cesium3DTilesContent/src/GltfConverters.cpp index a1bf24b5a..bd0b9b9cb 100644 --- a/Cesium3DTilesSelection/src/GltfConverters.cpp +++ b/Cesium3DTilesContent/src/GltfConverters.cpp @@ -1,8 +1,10 @@ -#include +#include #include -namespace Cesium3DTilesSelection { +using namespace CesiumUtility; + +namespace Cesium3DTilesContent { std::unordered_map GltfConverters::_loadersByMagic; @@ -126,4 +128,4 @@ GltfConverters::ConverterFunction GltfConverters::getConverterByMagic( return nullptr; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesContent/src/GltfUtilities.cpp b/Cesium3DTilesContent/src/GltfUtilities.cpp new file mode 100644 index 000000000..2d19cffbb --- /dev/null +++ b/Cesium3DTilesContent/src/GltfUtilities.cpp @@ -0,0 +1,153 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace Cesium3DTilesContent { +/*static*/ glm::dmat4x4 GltfUtilities::applyRtcCenter( + const CesiumGltf::Model& gltf, + const glm::dmat4x4& rootTransform) { + const CesiumGltf::ExtensionCesiumRTC* cesiumRTC = + gltf.getExtension(); + if (cesiumRTC == nullptr) { + return rootTransform; + } + const std::vector& rtcCenter = cesiumRTC->center; + if (rtcCenter.size() != 3) { + return rootTransform; + } + const double x = rtcCenter[0]; + const double y = rtcCenter[1]; + const double z = rtcCenter[2]; + const glm::dmat4x4 rtcTransform( + glm::dvec4(1.0, 0.0, 0.0, 0.0), + glm::dvec4(0.0, 1.0, 0.0, 0.0), + glm::dvec4(0.0, 0.0, 1.0, 0.0), + glm::dvec4(x, y, z, 1.0)); + return rootTransform * rtcTransform; +} + +/*static*/ glm::dmat4x4 GltfUtilities::applyGltfUpAxisTransform( + const CesiumGltf::Model& model, + const glm::dmat4x4& rootTransform) { + auto gltfUpAxisIt = model.extras.find("gltfUpAxis"); + if (gltfUpAxisIt == model.extras.end()) { + // The default up-axis of glTF is the Y-axis, and no other + // up-axis was specified. Transform the Y-axis to the Z-axis, + // to match the 3D Tiles specification + return rootTransform * CesiumGeometry::Transforms::Y_UP_TO_Z_UP; + } + const CesiumUtility::JsonValue& gltfUpAxis = gltfUpAxisIt->second; + int gltfUpAxisValue = static_cast(gltfUpAxis.getSafeNumberOrDefault(1)); + if (gltfUpAxisValue == static_cast(CesiumGeometry::Axis::X)) { + return rootTransform * CesiumGeometry::Transforms::X_UP_TO_Z_UP; + } else if (gltfUpAxisValue == static_cast(CesiumGeometry::Axis::Y)) { + return rootTransform * CesiumGeometry::Transforms::Y_UP_TO_Z_UP; + } else if (gltfUpAxisValue == static_cast(CesiumGeometry::Axis::Z)) { + // No transform required + } + return rootTransform; +} + +/*static*/ CesiumGeospatial::BoundingRegion +GltfUtilities::computeBoundingRegion( + const CesiumGltf::Model& gltf, + const glm::dmat4& transform) { + glm::dmat4 rootTransform = transform; + rootTransform = applyRtcCenter(gltf, rootTransform); + rootTransform = applyGltfUpAxisTransform(gltf, rootTransform); + + // When computing the tile's bounds, ignore tiles that are less than 1/1000th + // of a tile width from the North or South pole. Longitudes cannot be trusted + // at such extreme latitudes. + CesiumGeospatial::BoundingRegionBuilder computedBounds; + + gltf.forEachPrimitiveInScene( + -1, + [&rootTransform, &computedBounds]( + const CesiumGltf::Model& gltf_, + const CesiumGltf::Node& /*node*/, + const CesiumGltf::Mesh& /*mesh*/, + const CesiumGltf::MeshPrimitive& primitive, + const glm::dmat4& nodeTransform) { + auto positionIt = primitive.attributes.find("POSITION"); + if (positionIt == primitive.attributes.end()) { + return; + } + + const int positionAccessorIndex = positionIt->second; + if (positionAccessorIndex < 0 || + positionAccessorIndex >= static_cast(gltf_.accessors.size())) { + return; + } + + const glm::dmat4 fullTransform = rootTransform * nodeTransform; + + const CesiumGltf::AccessorView positionView( + gltf_, + positionAccessorIndex); + if (positionView.status() != CesiumGltf::AccessorViewStatus::Valid) { + return; + } + + std::optional skirtMeshMetadata = + SkirtMeshMetadata::parseFromGltfExtras(primitive.extras); + int64_t vertexBegin, vertexEnd; + if (skirtMeshMetadata.has_value()) { + vertexBegin = skirtMeshMetadata->noSkirtVerticesBegin; + vertexEnd = skirtMeshMetadata->noSkirtVerticesBegin + + skirtMeshMetadata->noSkirtVerticesCount; + } else { + vertexBegin = 0; + vertexEnd = positionView.size(); + } + + for (int64_t i = vertexBegin; i < vertexEnd; ++i) { + // Get the ECEF position + const glm::vec3 position = positionView[i]; + const glm::dvec3 positionEcef = + glm::dvec3(fullTransform * glm::dvec4(position, 1.0)); + + // Convert it to cartographic + std::optional cartographic = + CesiumGeospatial::Ellipsoid::WGS84.cartesianToCartographic( + positionEcef); + if (!cartographic) { + continue; + } + + computedBounds.expandToIncludePosition(*cartographic); + } + }); + + return computedBounds.toRegion(); +} + +std::vector +GltfUtilities::parseGltfCopyright(const CesiumGltf::Model& gltf) { + std::vector result; + if (gltf.asset.copyright) { + const std::string_view copyright = *gltf.asset.copyright; + if (copyright.size() > 0) { + size_t start = 0; + size_t end; + size_t ltrim; + size_t rtrim; + do { + ltrim = copyright.find_first_not_of(" \t", start); + end = copyright.find(';', ltrim); + rtrim = copyright.find_last_not_of(" \t", end - 1); + result.emplace_back(copyright.substr(ltrim, rtrim - ltrim + 1)); + start = end + 1; + } while (end != std::string::npos); + } + } + + return result; +} +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/PntsToGltfConverter.cpp b/Cesium3DTilesContent/src/PntsToGltfConverter.cpp similarity index 99% rename from Cesium3DTilesSelection/src/PntsToGltfConverter.cpp rename to Cesium3DTilesContent/src/PntsToGltfConverter.cpp index d732fc7da..3b2e50868 100644 --- a/Cesium3DTilesSelection/src/PntsToGltfConverter.cpp +++ b/Cesium3DTilesContent/src/PntsToGltfConverter.cpp @@ -1,7 +1,6 @@ -#include "PntsToGltfConverter.h" - #include "BatchTableToGltfStructuralMetadata.h" +#include #include #include #include @@ -30,7 +29,7 @@ using namespace CesiumGltf; using namespace CesiumUtility; -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { namespace { struct PntsHeader { unsigned char magic[4]; @@ -228,7 +227,7 @@ struct PntsContent { std::map dracoMetadataSemantics; std::vector dracoBatchTableBinary; - Cesium3DTilesSelection::ErrorList errors; + ErrorList errors; bool dracoMetadataHasErrors = false; }; @@ -1632,4 +1631,4 @@ GltfConverterResult PntsToGltfConverter::convert( convertPntsContentToGltf(pntsBinary, header, headerLength, result); return result; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/QuantizedMeshLoader.cpp b/Cesium3DTilesContent/src/QuantizedMeshLoader.cpp similarity index 97% rename from Cesium3DTilesSelection/src/QuantizedMeshLoader.cpp rename to Cesium3DTilesContent/src/QuantizedMeshLoader.cpp index 326acbc11..0258ab120 100644 --- a/Cesium3DTilesSelection/src/QuantizedMeshLoader.cpp +++ b/Cesium3DTilesContent/src/QuantizedMeshLoader.cpp @@ -1,14 +1,9 @@ -#include "QuantizedMeshLoader.h" - -#include "Cesium3DTilesSelection/Tile.h" -#include "Cesium3DTilesSelection/Tileset.h" -#include "Cesium3DTilesSelection/spdlog-cesium.h" -#include "SkirtMeshMetadata.h" -#include "calcQuadtreeMaxGeometricError.h" - +#include +#include #include #include #include +#include #include #include #include @@ -19,10 +14,11 @@ #include #include +#include #include #include -using namespace Cesium3DTilesSelection; +using namespace Cesium3DTilesContent; using namespace CesiumUtility; using namespace CesiumGeospatial; using namespace CesiumGeometry; @@ -662,16 +658,14 @@ static std::vector generateNormals( } /*static*/ QuantizedMeshLoadResult QuantizedMeshLoader::load( - const TileID& tileID, - const BoundingVolume& tileBoundingVolume, + const QuadtreeTileID& tileID, + const BoundingRegion& tileBoundingVolume, const std::string& url, const gsl::span& data, bool enableWaterMask) { CESIUM_TRACE("Cesium3DTilesSelection::QuantizedMeshLoader::load"); - const QuadtreeTileID& id = std::get(tileID); - QuantizedMeshLoadResult result; std::optional meshView = @@ -681,23 +675,6 @@ static std::vector generateNormals( return result; } - const BoundingRegion* pRegion = - std::get_if(&tileBoundingVolume); - if (!pRegion) { - const BoundingRegionWithLooseFittingHeights* pLooseRegion = - std::get_if(&tileBoundingVolume); - if (pLooseRegion) { - pRegion = &pLooseRegion->getBoundingRegion(); - } - } - - if (!pRegion) { - result.errors.emplaceError( - "Unable to create quantized-mesh-1.0 tile because the tile's bounding " - "volume is not a bounding region."); - return result; - } - // get vertex count for this mesh const QuantizedMeshHeader* pHeader = meshView->header; const uint32_t vertexCount = pHeader->vertexCount; @@ -735,7 +712,8 @@ static std::vector generateNormals( double maxZ = std::numeric_limits::lowest(); const Ellipsoid& ellipsoid = Ellipsoid::WGS84; - const CesiumGeospatial::GlobeRectangle& rectangle = pRegion->getRectangle(); + const CesiumGeospatial::GlobeRectangle& rectangle = + tileBoundingVolume.getRectangle(); const double west = rectangle.getWest(); const double south = rectangle.getSouth(); const double east = rectangle.getEast(); @@ -797,7 +775,7 @@ static std::vector generateNormals( // decode metadata if (meshView->metadataJsonLength > 0) { QuantizedMeshMetadataResult metadata = - processMetadata(id, meshView->metadataJsonBuffer); + processMetadata(tileID, meshView->metadataJsonBuffer); result.availableTileRectangles = std::move(metadata.availability); result.errors.merge(std::move(metadata.errors)); } diff --git a/Cesium3DTilesSelection/src/SkirtMeshMetadata.cpp b/Cesium3DTilesContent/src/SkirtMeshMetadata.cpp similarity index 97% rename from Cesium3DTilesSelection/src/SkirtMeshMetadata.cpp rename to Cesium3DTilesContent/src/SkirtMeshMetadata.cpp index 29a7d6028..5d5985e76 100644 --- a/Cesium3DTilesSelection/src/SkirtMeshMetadata.cpp +++ b/Cesium3DTilesContent/src/SkirtMeshMetadata.cpp @@ -1,5 +1,4 @@ -#include "SkirtMeshMetadata.h" - +#include #include #include @@ -7,7 +6,7 @@ using namespace CesiumUtility; -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { std::optional SkirtMeshMetadata::parseFromGltfExtras(const JsonValue::Object& extras) { auto skirtIt = extras.find("skirtMeshMetadata"); @@ -113,4 +112,4 @@ JsonValue::Object SkirtMeshMetadata::createGltfExtras( {"skirtEastHeight", skirtMeshMetadata.skirtEastHeight}, {"skirtNorthHeight", skirtMeshMetadata.skirtNorthHeight}}}}; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/SubtreeAvailability.cpp b/Cesium3DTilesContent/src/SubtreeAvailability.cpp similarity index 99% rename from Cesium3DTilesSelection/src/SubtreeAvailability.cpp rename to Cesium3DTilesContent/src/SubtreeAvailability.cpp index 515f59e6e..6a89bfb2a 100644 --- a/Cesium3DTilesSelection/src/SubtreeAvailability.cpp +++ b/Cesium3DTilesContent/src/SubtreeAvailability.cpp @@ -1,5 +1,4 @@ -#include "SubtreeAvailability.h" - +#include #include #include @@ -9,7 +8,7 @@ #include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { namespace { constexpr const char* const SUBTREE_MAGIC = "subt"; @@ -583,4 +582,4 @@ bool SubtreeAvailability::isAvailableUsingBufferView( return bitValue == 1; } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/registerAllTileContentTypes.cpp b/Cesium3DTilesContent/src/registerAllTileContentTypes.cpp similarity index 55% rename from Cesium3DTilesSelection/src/registerAllTileContentTypes.cpp rename to Cesium3DTilesContent/src/registerAllTileContentTypes.cpp index ce9a98020..11d232f6b 100644 --- a/Cesium3DTilesSelection/src/registerAllTileContentTypes.cpp +++ b/Cesium3DTilesContent/src/registerAllTileContentTypes.cpp @@ -1,12 +1,11 @@ -#include "B3dmToGltfConverter.h" -#include "BinaryToGltfConverter.h" -#include "CmptToGltfConverter.h" -#include "PntsToGltfConverter.h" +#include +#include +#include +#include +#include +#include -#include -#include - -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { void registerAllTileContentTypes() { GltfConverters::registerMagic("glTF", BinaryToGltfConverter::convert); @@ -20,4 +19,4 @@ void registerAllTileContentTypes() { GltfConverters::registerFileExtension(".glb", BinaryToGltfConverter::convert); } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.cpp b/Cesium3DTilesContent/src/upsampleGltfForRasterOverlays.cpp similarity index 99% rename from Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.cpp rename to Cesium3DTilesContent/src/upsampleGltfForRasterOverlays.cpp index e198912e9..d1c996e8e 100644 --- a/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.cpp +++ b/Cesium3DTilesContent/src/upsampleGltfForRasterOverlays.cpp @@ -1,7 +1,5 @@ -#include "upsampleGltfForRasterOverlays.h" - -#include "SkirtMeshMetadata.h" - +#include +#include #include #include #include @@ -17,7 +15,7 @@ using namespace CesiumGltf; -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { struct EdgeVertex { uint32_t index; glm::vec2 uv; @@ -1263,4 +1261,4 @@ static void copyMetadataTables(const Model& parentModel, Model& result) { } } -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/test/ConvertTileToGltf.h b/Cesium3DTilesContent/test/ConvertTileToGltf.h similarity index 63% rename from Cesium3DTilesSelection/test/ConvertTileToGltf.h rename to Cesium3DTilesContent/test/ConvertTileToGltf.h index 2011ca5cb..2d343b59f 100644 --- a/Cesium3DTilesSelection/test/ConvertTileToGltf.h +++ b/Cesium3DTilesContent/test/ConvertTileToGltf.h @@ -1,12 +1,12 @@ #pragma once -#include "B3dmToGltfConverter.h" -#include "PntsToGltfConverter.h" -#include "readFile.h" +#include +#include +#include #include -namespace Cesium3DTilesSelection { +namespace Cesium3DTilesContent { class ConvertTileToGltf { public: @@ -18,4 +18,4 @@ class ConvertTileToGltf { return PntsToGltfConverter::convert(readFile(filePath), {}); } }; -} // namespace Cesium3DTilesSelection +} // namespace Cesium3DTilesContent diff --git a/Cesium3DTilesSelection/test/TestPntsToGltfConverter.cpp b/Cesium3DTilesContent/test/TestPntsToGltfConverter.cpp similarity index 99% rename from Cesium3DTilesSelection/test/TestPntsToGltfConverter.cpp rename to Cesium3DTilesContent/test/TestPntsToGltfConverter.cpp index 8cce744a9..05f2646a9 100644 --- a/Cesium3DTilesSelection/test/TestPntsToGltfConverter.cpp +++ b/Cesium3DTilesContent/test/TestPntsToGltfConverter.cpp @@ -17,7 +17,7 @@ #include using namespace CesiumGltf; -using namespace Cesium3DTilesSelection; +using namespace Cesium3DTilesContent; using namespace CesiumUtility; template diff --git a/Cesium3DTilesSelection/test/TestQuantizedMeshContent.cpp b/Cesium3DTilesContent/test/TestQuantizedMeshContent.cpp similarity index 99% rename from Cesium3DTilesSelection/test/TestQuantizedMeshContent.cpp rename to Cesium3DTilesContent/test/TestQuantizedMeshContent.cpp index 7ecfbf384..921bcb067 100644 --- a/Cesium3DTilesSelection/test/TestQuantizedMeshContent.cpp +++ b/Cesium3DTilesContent/test/TestQuantizedMeshContent.cpp @@ -1,7 +1,5 @@ -#include "Cesium3DTilesSelection/registerAllTileContentTypes.h" -#include "Cesium3DTilesSelection/spdlog-cesium.h" -#include "QuantizedMeshLoader.h" - +#include +#include #include #include #include @@ -14,7 +12,7 @@ #include -using namespace Cesium3DTilesSelection; +using namespace Cesium3DTilesContent; using namespace CesiumGeometry; using namespace CesiumGeospatial; using namespace CesiumGltf; diff --git a/Cesium3DTilesSelection/test/TestSkirtMeshMetadata.cpp b/Cesium3DTilesContent/test/TestSkirtMeshMetadata.cpp similarity index 99% rename from Cesium3DTilesSelection/test/TestSkirtMeshMetadata.cpp rename to Cesium3DTilesContent/test/TestSkirtMeshMetadata.cpp index 8a68ecf2b..d85e2c135 100644 --- a/Cesium3DTilesSelection/test/TestSkirtMeshMetadata.cpp +++ b/Cesium3DTilesContent/test/TestSkirtMeshMetadata.cpp @@ -1,10 +1,9 @@ -#include "SkirtMeshMetadata.h" - +#include #include #include -using namespace Cesium3DTilesSelection; +using namespace Cesium3DTilesContent; using namespace CesiumUtility; TEST_CASE("Test converting skirt mesh metadata to gltf extras") { diff --git a/Cesium3DTilesSelection/test/TestSubtreeAvailability.cpp b/Cesium3DTilesContent/test/TestSubtreeAvailability.cpp similarity index 99% rename from Cesium3DTilesSelection/test/TestSubtreeAvailability.cpp rename to Cesium3DTilesContent/test/TestSubtreeAvailability.cpp index 48cf6a8a2..75923d819 100644 --- a/Cesium3DTilesSelection/test/TestSubtreeAvailability.cpp +++ b/Cesium3DTilesContent/test/TestSubtreeAvailability.cpp @@ -1,9 +1,8 @@ -#include "SimpleAssetAccessor.h" -#include "SimpleTaskProcessor.h" -#include "SubtreeAvailability.h" - +#include #include #include +#include +#include #include #include @@ -14,7 +13,8 @@ #include #include -using namespace Cesium3DTilesSelection; +using namespace Cesium3DTilesContent; +using namespace CesiumNativeTests; namespace { struct SubtreeHeader { diff --git a/Cesium3DTilesSelection/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp b/Cesium3DTilesContent/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp similarity index 99% rename from Cesium3DTilesSelection/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp rename to Cesium3DTilesContent/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp index 93151e148..4e8018e2e 100644 --- a/Cesium3DTilesSelection/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp +++ b/Cesium3DTilesContent/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp @@ -18,7 +18,7 @@ #include using namespace CesiumGltf; -using namespace Cesium3DTilesSelection; +using namespace Cesium3DTilesContent; using namespace CesiumUtility; template diff --git a/Cesium3DTilesSelection/test/TestUpsampleGltfForRasterOverlay.cpp b/Cesium3DTilesContent/test/TestUpsampleGltfForRasterOverlay.cpp similarity index 99% rename from Cesium3DTilesSelection/test/TestUpsampleGltfForRasterOverlay.cpp rename to Cesium3DTilesContent/test/TestUpsampleGltfForRasterOverlay.cpp index baebb6cbb..9a70c1c5b 100644 --- a/Cesium3DTilesSelection/test/TestUpsampleGltfForRasterOverlay.cpp +++ b/Cesium3DTilesContent/test/TestUpsampleGltfForRasterOverlay.cpp @@ -1,6 +1,5 @@ -#include "SkirtMeshMetadata.h" -#include "upsampleGltfForRasterOverlays.h" - +#include +#include #include #include #include @@ -12,7 +11,7 @@ #include #include -using namespace Cesium3DTilesSelection; +using namespace Cesium3DTilesContent; using namespace CesiumUtility; using namespace CesiumGeospatial; using namespace CesiumGltf; diff --git a/Cesium3DTilesSelection/CMakeLists.txt b/Cesium3DTilesSelection/CMakeLists.txt index e0736a313..c07cd2c1d 100644 --- a/Cesium3DTilesSelection/CMakeLists.txt +++ b/Cesium3DTilesSelection/CMakeLists.txt @@ -44,6 +44,7 @@ target_include_directories( target_link_libraries(Cesium3DTilesSelection PUBLIC Cesium3DTiles + Cesium3DTilesContent Cesium3DTilesReader CesiumAsync CesiumGeospatial diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/CreditSystem.h b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/CreditSystem.h index 90bef6897..41612ca5c 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/CreditSystem.h +++ b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/CreditSystem.h @@ -38,6 +38,14 @@ struct CESIUM3DTILESSELECTION_API Credit { */ class CESIUM3DTILESSELECTION_API CreditSystem final { public: + /** + * @brief Inserts a credit string + * + * @return If this string already exists, returns a Credit handle to the + * existing entry. Otherwise returns a Credit handle to a new entry. + */ + Credit createCredit(std::string&& html, bool showOnScreen = false); + /** * @brief Inserts a credit string * diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfUtilities.h b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfUtilities.h deleted file mode 100644 index dd823816d..000000000 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/GltfUtilities.h +++ /dev/null @@ -1,139 +0,0 @@ -#pragma once - -#include "Library.h" - -#include -#include -#include -#include -#include - -#include - -#include - -namespace Cesium3DTilesSelection { -/** - * A collection of utility functions that are used to process and transform a - * gltf model - */ -struct CESIUM3DTILESSELECTION_API GltfUtilities { - /** - * @brief Applies the glTF's RTC_CENTER, if any, to the given transform. - * - * If the glTF has a `CESIUM_RTC` extension, this function will multiply the - * given matrix with the (translation) matrix that is created from the - * `RTC_CENTER` in the. If the given model does not have this extension, then - * this function will return the `rootTransform` unchanged. - * - * @param model The glTF model - * @param rootTransform The matrix that will be multiplied with the transform - * @return The result of multiplying the `RTC_CENTER` with the - * `rootTransform`. - */ - static glm::dmat4x4 applyRtcCenter( - const CesiumGltf::Model& gltf, - const glm::dmat4x4& rootTransform); - - /** - * @brief Applies the glTF's `gltfUpAxis`, if any, to the given transform. - * - * By default, the up-axis of a glTF model will the the Y-axis. - * - * If the tileset that contained the model had the `asset.gltfUpAxis` string - * property, then the information about the up-axis has been stored in as a - * number property called `gltfUpAxis` in the `extras` of the given model. - * - * Depending on whether this value is `CesiumGeometry::Axis::X`, `Y`, or `Z`, - * the given matrix will be multiplied with a matrix that converts the - * respective axis to be the Z-axis, as required by the 3D Tiles standard. - * - * @param model The glTF model - * @param rootTransform The matrix that will be multiplied with the transform - * @return The result of multiplying the `rootTransform` with the - * `gltfUpAxis`. - */ - static glm::dmat4x4 applyGltfUpAxisTransform( - const CesiumGltf::Model& model, - const glm::dmat4x4& rootTransform); - - /** - * @brief Creates texture coordinates for mapping {@link RasterOverlay} tiles - * to {@link Tileset} tiles. - * - * Generates new texture coordinates for the `gltf` using the given - * `projections`. The first new texture coordinate (`u` or `s`) will be 0.0 at - * the `minimumX` of the given `rectangle` and 1.0 at the `maximumX`. The - * second texture coordinate (`v` or `t`) will be 0.0 at the `minimumY` of - * the given `rectangle` and 1.0 at the `maximumY`. - * - * Coordinate values for vertices in between these extremes are determined by - * projecting the vertex position with the `projection` and then computing the - * fractional distance of that projected position between the minimum and - * maximum. - * - * Projected positions that fall outside the `globeRectangle` will be clamped - * to the edges, so the coordinate values will never be less then 0.0 or - * greater than 1.0. - * - * These texture coordinates are stored in the provided glTF, and a new - * primitive attribute named `_CESIUMOVERLAY_n` is added to each primitive, - * where `n` starts with the `firstTextureCoordinateID` passed to this - * function and increases with each projection. - * - * @param gltf The glTF model. - * @param modelToEcefTransform The transformation of this glTF to ECEF - * coordinates. - * @param firstTextureCoordinateID The texture coordinate ID of the first - * projection. - * @param globeRectangle The rectangle that all projected vertex positions are - * expected to lie within. If this parameter is std::nullopt, it is computed - * from the vertices. - * @param projections The projections for which to generate texture - * coordinates. There is a linear relationship between the coordinates of this - * projection and the generated texture coordinates. - * @return The detailed of the generated texture coordinates. - */ - static std::optional - createRasterOverlayTextureCoordinates( - CesiumGltf::Model& gltf, - const glm::dmat4& modelToEcefTransform, - int32_t firstTextureCoordinateID, - const std::optional& globeRectangle, - std::vector&& projections); - - /** - * @brief Computes a bounding region from the vertex positions in a glTF - * model. - * - * If the glTF model spans the anti-meridian, the west and east longitude - * values will be in the usual -PI to PI range, but east will have a smaller - * value than west. - * - * If the glTF contains no geometry, the returned region's rectangle - * will be {@link GlobeRectangle::EMPTY}, its minimum height will be 1.0, and - * its maximum height will be -1.0 (the minimum will be greater than the - * maximum). - * - * @param gltf The model. - * @param transform The transform from model coordinates to ECEF coordinates. - * @return The computed bounding region. - */ - static CesiumGeospatial::BoundingRegion computeBoundingRegion( - const CesiumGltf::Model& gltf, - const glm::dmat4& transform); - - /** - * @brief Parse the copyright field of a gltf model and create credits for it. - * - * @param creditSystems The {@link Cesium3DTilesSelection::CreditSystem} that is used to credits for the gltf's copyright - * @param gltf The model. - * @return showOnScreen The option to indicate if the created credits should - * be shown on the screen. - */ - static std::vector parseGltfCopyright( - CreditSystem& creditSystems, - const CesiumGltf::Model& gltf, - bool showOnScreen); -}; -} // namespace Cesium3DTilesSelection diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/RasterOverlayTileProvider.h b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/RasterOverlayTileProvider.h index 6d392c049..a84538286 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/RasterOverlayTileProvider.h +++ b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/RasterOverlayTileProvider.h @@ -302,7 +302,7 @@ class CESIUM3DTILESSELECTION_API RasterOverlayTileProvider /** * @brief Loads a tile immediately, without throttling requests. * - * If the tile is not in the `Tile::LoadState::Unloading` state, this method + * If the tile is not in the `Tile::LoadState::Unloaded` state, this method * returns without doing anything. Otherwise, it puts the tile into the * `Tile::LoadState::Loading` state and begins the asynchronous process * to load the tile. When the process completes, the tile will be in the diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/RasterOverlayUtilities.h b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/RasterOverlayUtilities.h new file mode 100644 index 000000000..9b2aac33d --- /dev/null +++ b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/RasterOverlayUtilities.h @@ -0,0 +1,66 @@ +#pragma once + +#include "Library.h" +#include "RasterOverlayDetails.h" + +#include + +#include + +#include +#include + +namespace CesiumGltf { +struct Model; +} + +namespace Cesium3DTilesSelection { + +struct CESIUM3DTILESSELECTION_API RasterOverlayUtilities { + /** + * @brief Creates texture coordinates for mapping {@link RasterOverlay} tiles + * to {@link Tileset} tiles. + * + * Generates new texture coordinates for the `gltf` using the given + * `projections`. The first new texture coordinate (`u` or `s`) will be 0.0 at + * the `minimumX` of the given `rectangle` and 1.0 at the `maximumX`. The + * second texture coordinate (`v` or `t`) will be 0.0 at the `minimumY` of + * the given `rectangle` and 1.0 at the `maximumY`. + * + * Coordinate values for vertices in between these extremes are determined by + * projecting the vertex position with the `projection` and then computing the + * fractional distance of that projected position between the minimum and + * maximum. + * + * Projected positions that fall outside the `globeRectangle` will be clamped + * to the edges, so the coordinate values will never be less then 0.0 or + * greater than 1.0. + * + * These texture coordinates are stored in the provided glTF, and a new + * primitive attribute named `_CESIUMOVERLAY_n` is added to each primitive, + * where `n` starts with the `firstTextureCoordinateID` passed to this + * function and increases with each projection. + * + * @param gltf The glTF model. + * @param modelToEcefTransform The transformation of this glTF to ECEF + * coordinates. + * @param firstTextureCoordinateID The texture coordinate ID of the first + * projection. + * @param globeRectangle The rectangle that all projected vertex positions are + * expected to lie within. If this parameter is std::nullopt, it is computed + * from the vertices. + * @param projections The projections for which to generate texture + * coordinates. There is a linear relationship between the coordinates of this + * projection and the generated texture coordinates. + * @return The details of the generated texture coordinates. + */ + static std::optional + createRasterOverlayTextureCoordinates( + CesiumGltf::Model& gltf, + const glm::dmat4& modelToEcefTransform, + int32_t firstTextureCoordinateID, + const std::optional& globeRectangle, + std::vector&& projections); +}; + +} // namespace Cesium3DTilesSelection diff --git a/Cesium3DTilesSelection/src/CreditSystem.cpp b/Cesium3DTilesSelection/src/CreditSystem.cpp index d2af7d75c..2f8537121 100644 --- a/Cesium3DTilesSelection/src/CreditSystem.cpp +++ b/Cesium3DTilesSelection/src/CreditSystem.cpp @@ -5,6 +5,10 @@ namespace Cesium3DTilesSelection { Credit CreditSystem::createCredit(const std::string& html, bool showOnScreen) { + return this->createCredit(std::string(html), showOnScreen); +} + +Credit CreditSystem::createCredit(std::string&& html, bool showOnScreen) { // if this credit already exists, return a Credit handle to it for (size_t id = 0; id < _credits.size(); ++id) { if (_credits[id].html == html) { @@ -14,7 +18,7 @@ Credit CreditSystem::createCredit(const std::string& html, bool showOnScreen) { } } - _credits.push_back({html, showOnScreen, -1, 0}); + _credits.push_back({std::move(html), showOnScreen, -1, 0}); return Credit(_credits.size() - 1); } diff --git a/Cesium3DTilesSelection/src/ImplicitOctreeLoader.cpp b/Cesium3DTilesSelection/src/ImplicitOctreeLoader.cpp index 85b6b6862..10e3c3080 100644 --- a/Cesium3DTilesSelection/src/ImplicitOctreeLoader.cpp +++ b/Cesium3DTilesSelection/src/ImplicitOctreeLoader.cpp @@ -2,7 +2,7 @@ #include "logTileLoadResult.h" -#include +#include #include #include #include @@ -10,6 +10,8 @@ #include #include +using namespace Cesium3DTilesContent; + namespace Cesium3DTilesSelection { namespace { struct BoundingVolumeSubdivision { diff --git a/Cesium3DTilesSelection/src/ImplicitOctreeLoader.h b/Cesium3DTilesSelection/src/ImplicitOctreeLoader.h index ca2bd35d5..bb6a88bc0 100644 --- a/Cesium3DTilesSelection/src/ImplicitOctreeLoader.h +++ b/Cesium3DTilesSelection/src/ImplicitOctreeLoader.h @@ -1,7 +1,6 @@ #pragma once -#include "SubtreeAvailability.h" - +#include #include #include #include @@ -51,7 +50,7 @@ class ImplicitOctreeLoader : public TilesetContentLoader { void addSubtreeAvailability( const CesiumGeometry::OctreeTileID& subtreeID, - SubtreeAvailability&& subtreeAvailability); + Cesium3DTilesContent::SubtreeAvailability&& subtreeAvailability); private: static std::string resolveUrl( @@ -65,7 +64,8 @@ class ImplicitOctreeLoader : public TilesetContentLoader { uint32_t _subtreeLevels; uint32_t _availableLevels; ImplicitOctreeBoundingVolume _boundingVolume; - std::vector> + std::vector< + std::unordered_map> _loadedSubtrees; }; } // namespace Cesium3DTilesSelection diff --git a/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.cpp b/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.cpp index 8b174e52e..557596e00 100644 --- a/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.cpp +++ b/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.cpp @@ -2,7 +2,7 @@ #include "logTileLoadResult.h" -#include +#include #include #include #include @@ -14,6 +14,8 @@ #include #include +using namespace Cesium3DTilesContent; + namespace Cesium3DTilesSelection { namespace { struct BoundingVolumeSubdivision { diff --git a/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.h b/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.h index bc81f3339..60c962042 100644 --- a/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.h +++ b/Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.h @@ -1,7 +1,6 @@ #pragma once -#include "SubtreeAvailability.h" - +#include #include #include #include @@ -53,7 +52,7 @@ class ImplicitQuadtreeLoader : public TilesetContentLoader { void addSubtreeAvailability( const CesiumGeometry::QuadtreeTileID& subtreeID, - SubtreeAvailability&& subtreeAvailability); + Cesium3DTilesContent::SubtreeAvailability&& subtreeAvailability); private: static std::string resolveUrl( @@ -67,7 +66,8 @@ class ImplicitQuadtreeLoader : public TilesetContentLoader { uint32_t _subtreeLevels; uint32_t _availableLevels; ImplicitQuadtreeBoundingVolume _boundingVolume; - std::vector> + std::vector< + std::unordered_map> _loadedSubtrees; }; } // namespace Cesium3DTilesSelection diff --git a/Cesium3DTilesSelection/src/LayerJsonTerrainLoader.cpp b/Cesium3DTilesSelection/src/LayerJsonTerrainLoader.cpp index 46b0aa3c8..8f44570c3 100644 --- a/Cesium3DTilesSelection/src/LayerJsonTerrainLoader.cpp +++ b/Cesium3DTilesSelection/src/LayerJsonTerrainLoader.cpp @@ -1,11 +1,11 @@ #include "LayerJsonTerrainLoader.h" -#include "QuantizedMeshLoader.h" -#include "calcQuadtreeMaxGeometricError.h" -#include "upsampleGltfForRasterOverlays.h" - -#include +#include +#include +#include +#include #include +#include #include #include @@ -13,6 +13,7 @@ #include using namespace CesiumAsync; +using namespace Cesium3DTilesContent; using namespace Cesium3DTilesSelection; using namespace CesiumGeometry; using namespace CesiumGeospatial; @@ -210,7 +211,7 @@ void generateRasterOverlayUVs( std::get_if(&result.contentKind); if (pModel) { result.rasterOverlayDetails = - GltfUtilities::createRasterOverlayTextureCoordinates( + RasterOverlayUtilities::createRasterOverlayTextureCoordinates( *pModel, tileTransform, 0, @@ -636,14 +637,14 @@ Future requestTileContent( const AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const QuadtreeTileID& tileID, - const BoundingVolume& boundingVolume, + const BoundingRegion& boundingRegion, const LayerJsonTerrainLoader::Layer& layer, const std::vector& requestHeaders, bool enableWaterMask) { std::string url = resolveTileUrl(tileID, layer); return pAssetAccessor->get(asyncSystem, url, requestHeaders) .thenInWorkerThread( - [asyncSystem, pLogger, tileID, boundingVolume, enableWaterMask]( + [asyncSystem, pLogger, tileID, boundingRegion, enableWaterMask]( std::shared_ptr&& pRequest) { const IAssetResponse* pResponse = pRequest->response(); if (!pResponse) { @@ -669,7 +670,7 @@ Future requestTileContent( return QuantizedMeshLoader::load( tileID, - boundingVolume, + boundingRegion, pRequest->url(), pResponse->data(), enableWaterMask); @@ -780,6 +781,14 @@ LayerJsonTerrainLoader::loadTileContent(const TileLoadInput& loadInput) { ++it; } + const BoundingRegion* pRegion = + getBoundingRegionFromBoundingVolume(tile.getBoundingVolume()); + if (!pRegion) { + // This tile does not have the required bounding volume type. + return asyncSystem.createResolvedFuture( + TileLoadResult::createFailedResult(nullptr)); + } + // Start the actual content request. auto& currentLayer = *firstAvailableIt; Future futureQuantizedMesh = requestTileContent( @@ -787,7 +796,7 @@ LayerJsonTerrainLoader::loadTileContent(const TileLoadInput& loadInput) { asyncSystem, pAssetAccessor, *pQuadtreeTileID, - tile.getBoundingVolume(), + *pRegion, currentLayer, requestHeaders, contentOptions.enableWaterMask); diff --git a/Cesium3DTilesSelection/src/RasterOverlayUpsampler.cpp b/Cesium3DTilesSelection/src/RasterOverlayUpsampler.cpp index ea3d1f0ef..5d58929a3 100644 --- a/Cesium3DTilesSelection/src/RasterOverlayUpsampler.cpp +++ b/Cesium3DTilesSelection/src/RasterOverlayUpsampler.cpp @@ -1,7 +1,6 @@ #include "RasterOverlayUpsampler.h" -#include "upsampleGltfForRasterOverlays.h" - +#include #include #include #include @@ -12,6 +11,8 @@ #include #include +using namespace Cesium3DTilesContent; + namespace Cesium3DTilesSelection { CesiumAsync::Future RasterOverlayUpsampler::loadTileContent(const TileLoadInput& loadInput) { diff --git a/Cesium3DTilesSelection/src/GltfUtilities.cpp b/Cesium3DTilesSelection/src/RasterOverlayUtilities.cpp similarity index 65% rename from Cesium3DTilesSelection/src/GltfUtilities.cpp rename to Cesium3DTilesSelection/src/RasterOverlayUtilities.cpp index 3ceacdd0b..028a1b769 100644 --- a/Cesium3DTilesSelection/src/GltfUtilities.cpp +++ b/Cesium3DTilesSelection/src/RasterOverlayUtilities.cpp @@ -1,63 +1,16 @@ -#include "SkirtMeshMetadata.h" - -#include -#include -#include +#include +#include +#include #include -#include #include -#include +#include -#include +using namespace Cesium3DTilesContent; namespace Cesium3DTilesSelection { -/*static*/ glm::dmat4x4 GltfUtilities::applyRtcCenter( - const CesiumGltf::Model& gltf, - const glm::dmat4x4& rootTransform) { - const CesiumGltf::ExtensionCesiumRTC* cesiumRTC = - gltf.getExtension(); - if (cesiumRTC == nullptr) { - return rootTransform; - } - const std::vector& rtcCenter = cesiumRTC->center; - if (rtcCenter.size() != 3) { - return rootTransform; - } - const double x = rtcCenter[0]; - const double y = rtcCenter[1]; - const double z = rtcCenter[2]; - const glm::dmat4x4 rtcTransform( - glm::dvec4(1.0, 0.0, 0.0, 0.0), - glm::dvec4(0.0, 1.0, 0.0, 0.0), - glm::dvec4(0.0, 0.0, 1.0, 0.0), - glm::dvec4(x, y, z, 1.0)); - return rootTransform * rtcTransform; -} - -/*static*/ glm::dmat4x4 GltfUtilities::applyGltfUpAxisTransform( - const CesiumGltf::Model& model, - const glm::dmat4x4& rootTransform) { - auto gltfUpAxisIt = model.extras.find("gltfUpAxis"); - if (gltfUpAxisIt == model.extras.end()) { - // The default up-axis of glTF is the Y-axis, and no other - // up-axis was specified. Transform the Y-axis to the Z-axis, - // to match the 3D Tiles specification - return rootTransform * CesiumGeometry::Transforms::Y_UP_TO_Z_UP; - } - const CesiumUtility::JsonValue& gltfUpAxis = gltfUpAxisIt->second; - int gltfUpAxisValue = static_cast(gltfUpAxis.getSafeNumberOrDefault(1)); - if (gltfUpAxisValue == static_cast(CesiumGeometry::Axis::X)) { - return rootTransform * CesiumGeometry::Transforms::X_UP_TO_Z_UP; - } else if (gltfUpAxisValue == static_cast(CesiumGeometry::Axis::Y)) { - return rootTransform * CesiumGeometry::Transforms::Y_UP_TO_Z_UP; - } else if (gltfUpAxisValue == static_cast(CesiumGeometry::Axis::Z)) { - // No transform required - } - return rootTransform; -} /*static*/ std::optional -GltfUtilities::createRasterOverlayTextureCoordinates( +RasterOverlayUtilities::createRasterOverlayTextureCoordinates( CesiumGltf::Model& model, const glm::dmat4& modelToEcefTransform, int32_t firstTextureCoordinateID, @@ -71,7 +24,8 @@ GltfUtilities::createRasterOverlayTextureCoordinates( CesiumGeospatial::GlobeRectangle bounds = globeRectangle ? *globeRectangle - : computeBoundingRegion(model, modelToEcefTransform).getRectangle(); + : GltfUtilities::computeBoundingRegion(model, modelToEcefTransform) + .getRectangle(); // Currently, a Longitude/Latitude Rectangle maps perfectly to all possible // projection types, because the only possible projection types are @@ -84,8 +38,8 @@ GltfUtilities::createRasterOverlayTextureCoordinates( } glm::dmat4 rootTransform = modelToEcefTransform; - rootTransform = applyRtcCenter(model, rootTransform); - rootTransform = applyGltfUpAxisTransform(model, rootTransform); + rootTransform = GltfUtilities::applyRtcCenter(model, rootTransform); + rootTransform = GltfUtilities::applyGltfUpAxisTransform(model, rootTransform); std::vector positionAccessorsToTextureCoordinateAccessor; positionAccessorsToTextureCoordinateAccessor.resize( @@ -311,104 +265,4 @@ GltfUtilities::createRasterOverlayTextureCoordinates( computedBounds.toRegion()}; } -/*static*/ CesiumGeospatial::BoundingRegion -GltfUtilities::computeBoundingRegion( - const CesiumGltf::Model& gltf, - const glm::dmat4& transform) { - glm::dmat4 rootTransform = transform; - rootTransform = applyRtcCenter(gltf, rootTransform); - rootTransform = applyGltfUpAxisTransform(gltf, rootTransform); - - // When computing the tile's bounds, ignore tiles that are less than 1/1000th - // of a tile width from the North or South pole. Longitudes cannot be trusted - // at such extreme latitudes. - CesiumGeospatial::BoundingRegionBuilder computedBounds; - - gltf.forEachPrimitiveInScene( - -1, - [&rootTransform, &computedBounds]( - const CesiumGltf::Model& gltf_, - const CesiumGltf::Node& /*node*/, - const CesiumGltf::Mesh& /*mesh*/, - const CesiumGltf::MeshPrimitive& primitive, - const glm::dmat4& nodeTransform) { - auto positionIt = primitive.attributes.find("POSITION"); - if (positionIt == primitive.attributes.end()) { - return; - } - - const int positionAccessorIndex = positionIt->second; - if (positionAccessorIndex < 0 || - positionAccessorIndex >= static_cast(gltf_.accessors.size())) { - return; - } - - const glm::dmat4 fullTransform = rootTransform * nodeTransform; - - const CesiumGltf::AccessorView positionView( - gltf_, - positionAccessorIndex); - if (positionView.status() != CesiumGltf::AccessorViewStatus::Valid) { - return; - } - - std::optional skirtMeshMetadata = - SkirtMeshMetadata::parseFromGltfExtras(primitive.extras); - int64_t vertexBegin, vertexEnd; - if (skirtMeshMetadata.has_value()) { - vertexBegin = skirtMeshMetadata->noSkirtVerticesBegin; - vertexEnd = skirtMeshMetadata->noSkirtVerticesBegin + - skirtMeshMetadata->noSkirtVerticesCount; - } else { - vertexBegin = 0; - vertexEnd = positionView.size(); - } - - for (int64_t i = vertexBegin; i < vertexEnd; ++i) { - // Get the ECEF position - const glm::vec3 position = positionView[i]; - const glm::dvec3 positionEcef = - glm::dvec3(fullTransform * glm::dvec4(position, 1.0)); - - // Convert it to cartographic - std::optional cartographic = - CesiumGeospatial::Ellipsoid::WGS84.cartesianToCartographic( - positionEcef); - if (!cartographic) { - continue; - } - - computedBounds.expandToIncludePosition(*cartographic); - } - }); - - return computedBounds.toRegion(); -} - -std::vector GltfUtilities::parseGltfCopyright( - CreditSystem& creditSystem, - const CesiumGltf::Model& gltf, - bool showOnScreen) { - std::vector result; - if (gltf.asset.copyright) { - const std::string& copyright = *gltf.asset.copyright; - if (copyright.size() > 0) { - size_t start = 0; - size_t end; - size_t ltrim; - size_t rtrim; - do { - ltrim = copyright.find_first_not_of(" \t", start); - end = copyright.find(';', ltrim); - rtrim = copyright.find_last_not_of(" \t", end - 1); - result.push_back(creditSystem.createCredit( - copyright.substr(ltrim, rtrim - ltrim + 1), - showOnScreen)); - start = end + 1; - } while (end != std::string::npos); - } - } - - return result; -} } // namespace Cesium3DTilesSelection diff --git a/Cesium3DTilesSelection/src/TilesetContentLoaderResult.h b/Cesium3DTilesSelection/src/TilesetContentLoaderResult.h index 144e0f6e0..662eef218 100644 --- a/Cesium3DTilesSelection/src/TilesetContentLoaderResult.h +++ b/Cesium3DTilesSelection/src/TilesetContentLoaderResult.h @@ -1,9 +1,9 @@ #pragma once -#include #include #include #include +#include #include #include @@ -24,7 +24,7 @@ template struct TilesetContentLoaderResult { std::unique_ptr&& pRootTile_, std::vector&& credits_, std::vector&& requestHeaders_, - ErrorList&& errors_) + CesiumUtility::ErrorList&& errors_) : pLoader{std::move(pLoader_)}, pRootTile{std::move(pRootTile_)}, credits{std::move(credits_)}, @@ -85,7 +85,7 @@ template struct TilesetContentLoaderResult { std::vector requestHeaders; - ErrorList errors; + CesiumUtility::ErrorList errors; uint16_t statusCode{200}; }; diff --git a/Cesium3DTilesSelection/src/TilesetContentManager.cpp b/Cesium3DTilesSelection/src/TilesetContentManager.cpp index 2d18a6278..669af3119 100644 --- a/Cesium3DTilesSelection/src/TilesetContentManager.cpp +++ b/Cesium3DTilesSelection/src/TilesetContentManager.cpp @@ -5,11 +5,12 @@ #include "TileContentLoadInfo.h" #include "TilesetJsonLoader.h" -#include +#include #include #include #include #include +#include #include #include #include @@ -21,6 +22,8 @@ #include +using namespace Cesium3DTilesContent; + namespace Cesium3DTilesSelection { namespace { struct RegionAndCenter { @@ -373,12 +376,13 @@ void calcRasterOverlayDetailsInWorkerThread( // generate the overlay details from the rest of projections and merge it with // the existing one - auto overlayDetails = GltfUtilities::createRasterOverlayTextureCoordinates( - model, - tileLoadInfo.tileTransform, - firstRasterOverlayTexCoord, - pRegion ? std::make_optional(pRegion->getRectangle()) : std::nullopt, - std::move(projections)); + auto overlayDetails = + RasterOverlayUtilities::createRasterOverlayTextureCoordinates( + model, + tileLoadInfo.tileTransform, + firstRasterOverlayTexCoord, + pRegion ? std::make_optional(pRegion->getRectangle()) : std::nullopt, + std::move(projections)); if (pRegion && overlayDetails) { // If the original bounding region was wrong, report it. @@ -1181,10 +1185,22 @@ void TilesetContentManager::finishLoading( assert(pRenderContent != nullptr); // add copyright - pRenderContent->setCredits(GltfUtilities::parseGltfCopyright( - *this->_externals.pCreditSystem, - pRenderContent->getModel(), - tilesetOptions.showCreditsOnScreen)); + CreditSystem* pCreditSystem = this->_externals.pCreditSystem.get(); + if (pCreditSystem) { + std::vector creditStrings = + GltfUtilities::parseGltfCopyright(pRenderContent->getModel()); + + std::vector credits; + credits.reserve(creditStrings.size()); + + for (const std::string_view& creditString : creditStrings) { + credits.emplace_back(pCreditSystem->createCredit( + std::string(creditString), + tilesetOptions.showCreditsOnScreen)); + } + + pRenderContent->setCredits(credits); + } void* pWorkerRenderResources = pRenderContent->getRenderResources(); void* pMainThreadRenderResources = diff --git a/Cesium3DTilesSelection/src/TilesetJsonLoader.cpp b/Cesium3DTilesSelection/src/TilesetJsonLoader.cpp index e6433575d..d2f6fde2c 100644 --- a/Cesium3DTilesSelection/src/TilesetJsonLoader.cpp +++ b/Cesium3DTilesSelection/src/TilesetJsonLoader.cpp @@ -4,10 +4,10 @@ #include "ImplicitQuadtreeLoader.h" #include "logTileLoadResult.h" +#include #include #include #include -#include #include #include #include @@ -24,6 +24,9 @@ #include +using namespace CesiumUtility; +using namespace Cesium3DTilesContent; + namespace Cesium3DTilesSelection { namespace { struct ExternalContentInitializer { diff --git a/Cesium3DTilesSelection/src/logTileLoadResult.cpp b/Cesium3DTilesSelection/src/logTileLoadResult.cpp index 4db7a4549..68918e7a0 100644 --- a/Cesium3DTilesSelection/src/logTileLoadResult.cpp +++ b/Cesium3DTilesSelection/src/logTileLoadResult.cpp @@ -1,5 +1,7 @@ #include "logTileLoadResult.h" +using namespace CesiumUtility; + namespace Cesium3DTilesSelection { void logTileLoadResult( const std::shared_ptr& pLogger, diff --git a/Cesium3DTilesSelection/src/logTileLoadResult.h b/Cesium3DTilesSelection/src/logTileLoadResult.h index 3747a07a4..d735eb00e 100644 --- a/Cesium3DTilesSelection/src/logTileLoadResult.h +++ b/Cesium3DTilesSelection/src/logTileLoadResult.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include @@ -11,5 +11,5 @@ namespace Cesium3DTilesSelection { void logTileLoadResult( const std::shared_ptr& pLogger, const std::string& url, - const ErrorList& errorLists); + const CesiumUtility::ErrorList& errorLists); } diff --git a/Cesium3DTilesSelection/test/SimplePrepareRendererResource.h b/Cesium3DTilesSelection/test/SimplePrepareRendererResource.h index 82d028771..59417ce53 100644 --- a/Cesium3DTilesSelection/test/SimplePrepareRendererResource.h +++ b/Cesium3DTilesSelection/test/SimplePrepareRendererResource.h @@ -4,6 +4,8 @@ #include "Cesium3DTilesSelection/RasterOverlayTile.h" #include "Cesium3DTilesSelection/Tile.h" +#include + #include namespace Cesium3DTilesSelection { diff --git a/Cesium3DTilesSelection/test/TestImplicitOctreeLoader.cpp b/Cesium3DTilesSelection/test/TestImplicitOctreeLoader.cpp index 99975f5f2..c881e8119 100644 --- a/Cesium3DTilesSelection/test/TestImplicitOctreeLoader.cpp +++ b/Cesium3DTilesSelection/test/TestImplicitOctreeLoader.cpp @@ -1,32 +1,34 @@ #include "ImplicitOctreeLoader.h" -#include "SimpleAssetAccessor.h" -#include "SimpleAssetRequest.h" -#include "SimpleAssetResponse.h" -#include "SimpleTaskProcessor.h" -#include "readFile.h" +#include #include -#include #include #include #include +#include +#include +#include +#include +#include #include #include #include +using namespace Cesium3DTilesContent; using namespace Cesium3DTilesSelection; using namespace CesiumGeometry; using namespace CesiumGeospatial; using namespace CesiumUtility; +using namespace CesiumNativeTests; namespace { std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; } TEST_CASE("Test implicit octree loader") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); auto pMockedAssetAccessor = std::make_shared( std::map>{}); @@ -197,7 +199,7 @@ TEST_CASE("Test implicit octree loader") { } TEST_CASE("Test tile subdivision for implicit octree loader") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); auto pMockedAssetAccessor = std::make_shared( std::map>{}); diff --git a/Cesium3DTilesSelection/test/TestImplicitQuadtreeLoader.cpp b/Cesium3DTilesSelection/test/TestImplicitQuadtreeLoader.cpp index 58d936ea4..00209e323 100644 --- a/Cesium3DTilesSelection/test/TestImplicitQuadtreeLoader.cpp +++ b/Cesium3DTilesSelection/test/TestImplicitQuadtreeLoader.cpp @@ -1,32 +1,34 @@ #include "ImplicitQuadtreeLoader.h" -#include "SimpleAssetAccessor.h" -#include "SimpleAssetRequest.h" -#include "SimpleAssetResponse.h" -#include "SimpleTaskProcessor.h" -#include "readFile.h" +#include #include -#include #include #include #include +#include +#include +#include +#include +#include #include #include #include +using namespace Cesium3DTilesContent; using namespace Cesium3DTilesSelection; using namespace CesiumGeometry; using namespace CesiumGeospatial; using namespace CesiumUtility; +using namespace CesiumNativeTests; namespace { std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; } TEST_CASE("Test implicit quadtree loader") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); auto pMockedAssetAccessor = std::make_shared( std::map>{}); @@ -197,7 +199,7 @@ TEST_CASE("Test implicit quadtree loader") { } TEST_CASE("Test tile subdivision for implicit quadtree loader") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); auto pMockedAssetAccessor = std::make_shared( std::map>{}); diff --git a/Cesium3DTilesSelection/test/TestLayerJsonTerrainLoader.cpp b/Cesium3DTilesSelection/test/TestLayerJsonTerrainLoader.cpp index 69635a9ca..6cd3753a8 100644 --- a/Cesium3DTilesSelection/test/TestLayerJsonTerrainLoader.cpp +++ b/Cesium3DTilesSelection/test/TestLayerJsonTerrainLoader.cpp @@ -1,15 +1,15 @@ #include "LayerJsonTerrainLoader.h" #include "MockTilesetContentManager.h" -#include "SimpleAssetAccessor.h" -#include "SimpleAssetRequest.h" -#include "SimpleAssetResponse.h" #include "SimplePrepareRendererResource.h" -#include "SimpleTaskProcessor.h" -#include "readFile.h" -#include +#include #include #include +#include +#include +#include +#include +#include #include #include @@ -21,6 +21,7 @@ using namespace CesiumGeospatial; using namespace CesiumGeometry; using namespace CesiumAsync; using namespace CesiumUtility; +using namespace CesiumNativeTests; namespace { std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; @@ -70,7 +71,7 @@ Future loadTile( } // namespace TEST_CASE("Test create layer json terrain loader") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); auto pMockedAssetAccessor = std::make_shared( std::map>{}); @@ -393,7 +394,7 @@ TEST_CASE("Test create layer json terrain loader") { } TEST_CASE("Test load layer json tile content") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); auto pMockedAssetAccessor = std::make_shared( std::map>{}); @@ -683,7 +684,7 @@ TEST_CASE("Test load layer json tile content") { } TEST_CASE("Test creating tile children for layer json") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); auto pMockedAssetAccessor = std::make_shared( std::map>{}); diff --git a/Cesium3DTilesSelection/test/TestQuadtreeRasterOverlayTileProvider.cpp b/Cesium3DTilesSelection/test/TestQuadtreeRasterOverlayTileProvider.cpp index c5366b91d..a04fe2fe2 100644 --- a/Cesium3DTilesSelection/test/TestQuadtreeRasterOverlayTileProvider.cpp +++ b/Cesium3DTilesSelection/test/TestQuadtreeRasterOverlayTileProvider.cpp @@ -1,8 +1,8 @@ #include "Cesium3DTilesSelection/QuadtreeRasterOverlayTileProvider.h" #include "Cesium3DTilesSelection/RasterOverlay.h" -#include "SimpleAssetAccessor.h" #include +#include #include @@ -12,6 +12,7 @@ using namespace CesiumGeometry; using namespace CesiumGeospatial; using namespace CesiumGltf; using namespace CesiumUtility; +using namespace CesiumNativeTests; namespace { diff --git a/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp b/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp index b563f4046..af75480df 100644 --- a/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp +++ b/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp @@ -1,20 +1,20 @@ -#include "SimpleAssetAccessor.h" -#include "SimpleAssetRequest.h" -#include "SimpleAssetResponse.h" #include "SimplePrepareRendererResource.h" -#include "SimpleTaskProcessor.h" #include "TilesetContentManager.h" -#include "readFile.h" +#include +#include #include -#include #include #include -#include #include #include #include #include +#include +#include +#include +#include +#include #include #include @@ -28,6 +28,7 @@ using namespace Cesium3DTilesSelection; using namespace CesiumGeospatial; using namespace CesiumGeometry; using namespace CesiumUtility; +using namespace CesiumNativeTests; namespace { std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; @@ -181,7 +182,7 @@ CesiumGltf::Model createGlobeGrid( } // namespace TEST_CASE("Test the manager can be initialized with correct loaders") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); // create mock tileset externals auto pMockedAssetAccessor = std::make_shared( @@ -294,7 +295,7 @@ TEST_CASE("Test the manager can be initialized with correct loaders") { } TEST_CASE("Test tile state machine") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); // create mock tileset externals auto pMockedAssetAccessor = std::make_shared( @@ -708,7 +709,7 @@ TEST_CASE("Test tile state machine") { } TEST_CASE("Test the tileset content manager's post processing for gltf") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); // create mock tileset externals auto pMockedAssetAccessor = std::make_shared( diff --git a/Cesium3DTilesSelection/test/TestTilesetJsonLoader.cpp b/Cesium3DTilesSelection/test/TestTilesetJsonLoader.cpp index 64f370bdf..2a30acbcf 100644 --- a/Cesium3DTilesSelection/test/TestTilesetJsonLoader.cpp +++ b/Cesium3DTilesSelection/test/TestTilesetJsonLoader.cpp @@ -1,13 +1,13 @@ #include "ImplicitQuadtreeLoader.h" -#include "SimpleAssetAccessor.h" -#include "SimpleAssetRequest.h" -#include "SimpleAssetResponse.h" #include "SimplePrepareRendererResource.h" -#include "SimpleTaskProcessor.h" #include "TilesetJsonLoader.h" -#include "readFile.h" -#include +#include +#include +#include +#include +#include +#include #include @@ -17,6 +17,7 @@ using namespace CesiumAsync; using namespace Cesium3DTilesSelection; +using namespace CesiumNativeTests; namespace { std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; @@ -109,7 +110,7 @@ TileLoadResult loadTileContent( } // namespace TEST_CASE("Test creating tileset json loader") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); SECTION("Create valid tileset json with REPLACE refinement") { auto loaderResult = @@ -420,7 +421,7 @@ TEST_CASE("Test creating tileset json loader") { } TEST_CASE("Test loading individual tile of tileset json") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); SECTION("Load tile that has render content") { auto loaderResult = diff --git a/Cesium3DTilesSelection/test/TestTilesetSelectionAlgorithm.cpp b/Cesium3DTilesSelection/test/TestTilesetSelectionAlgorithm.cpp index f8784addc..d3bb3dc62 100644 --- a/Cesium3DTilesSelection/test/TestTilesetSelectionAlgorithm.cpp +++ b/Cesium3DTilesSelection/test/TestTilesetSelectionAlgorithm.cpp @@ -1,14 +1,14 @@ +#include "Cesium3DTilesContent/registerAllTileContentTypes.h" #include "Cesium3DTilesSelection/Tileset.h" #include "Cesium3DTilesSelection/ViewState.h" -#include "Cesium3DTilesSelection/registerAllTileContentTypes.h" -#include "SimpleAssetAccessor.h" -#include "SimpleAssetRequest.h" -#include "SimpleAssetResponse.h" #include "SimplePrepareRendererResource.h" -#include "SimpleTaskProcessor.h" #include #include +#include +#include +#include +#include #include #include @@ -23,6 +23,7 @@ using namespace CesiumAsync; using namespace Cesium3DTilesSelection; using namespace CesiumGeospatial; using namespace CesiumUtility; +using namespace CesiumNativeTests; static std::vector readFile(const std::filesystem::path& fileName) { std::ifstream file(fileName, std::ios::binary | std::ios::ate); @@ -117,7 +118,7 @@ static ViewState zoomToTileset(const Tileset& tileset) { } TEST_CASE("Test replace refinement for render") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); // initialize REPLACE tileset // @@ -511,7 +512,7 @@ TEST_CASE("Test replace refinement for render") { } TEST_CASE("Test additive refinement") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "AddTileset"; @@ -668,7 +669,7 @@ TEST_CASE("Test additive refinement") { TEST_CASE("Render any tiles even when one of children can't be rendered for " "additive refinement") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "ErrorChildrenAddTileset"; @@ -763,7 +764,7 @@ TEST_CASE("Render any tiles even when one of children can't be rendered for " } TEST_CASE("Test multiple frustums") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "ReplaceTileset"; @@ -1093,7 +1094,7 @@ TEST_CASE("Can load example tileset.json from 3DTILES_bounding_volume_S2 " } TEST_CASE("Makes metadata available once root tile is loaded") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "WithMetadata"; @@ -1149,7 +1150,7 @@ TEST_CASE("Makes metadata available once root tile is loaded") { } TEST_CASE("Makes metadata available on external tilesets") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "WithMetadata"; @@ -1217,7 +1218,7 @@ TEST_CASE("Makes metadata available on external tilesets") { } TEST_CASE("Allows access to material variants") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "MaterialVariants"; @@ -1301,7 +1302,7 @@ TEST_CASE("Allows access to material variants") { } TEST_CASE("Allows access to material variants in an external schema") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "MaterialVariants"; @@ -1397,7 +1398,7 @@ TEST_CASE("Allows access to material variants in an external schema") { } TEST_CASE("Future from loadSchema rejects if schemaUri can't be loaded") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "MaterialVariants"; @@ -1611,7 +1612,7 @@ TEST_CASE("An unconditionally-refined tile is not rendered") { } TEST_CASE("Additive-refined tiles are added to the tilesFadingOut array") { - Cesium3DTilesSelection::registerAllTileContentTypes(); + Cesium3DTilesContent::registerAllTileContentTypes(); std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR; testDataPath = testDataPath / "AdditiveThreeLevels"; diff --git a/Cesium3DTilesSelection/src/calcQuadtreeMaxGeometricError.h b/CesiumGeospatial/include/CesiumGeospatial/calcQuadtreeMaxGeometricError.h similarity index 85% rename from Cesium3DTilesSelection/src/calcQuadtreeMaxGeometricError.h rename to CesiumGeospatial/include/CesiumGeospatial/calcQuadtreeMaxGeometricError.h index 03dad3d74..1134b2678 100644 --- a/Cesium3DTilesSelection/src/calcQuadtreeMaxGeometricError.h +++ b/CesiumGeospatial/include/CesiumGeospatial/calcQuadtreeMaxGeometricError.h @@ -1,9 +1,10 @@ #pragma once +#include "Ellipsoid.h" + #include -#include -namespace Cesium3DTilesSelection { +namespace CesiumGeospatial { /** * @brief Computes the maximum geometric error per radian of a quadtree with * certain assumptions. @@ -20,4 +21,4 @@ namespace Cesium3DTilesSelection { */ double calcQuadtreeMaxGeometricError( const CesiumGeospatial::Ellipsoid& ellipsoid) noexcept; -} // namespace Cesium3DTilesSelection +} // namespace CesiumGeospatial diff --git a/Cesium3DTilesSelection/src/calcQuadtreeMaxGeometricError.cpp b/CesiumGeospatial/src/calcQuadtreeMaxGeometricError.cpp similarity index 66% rename from Cesium3DTilesSelection/src/calcQuadtreeMaxGeometricError.cpp rename to CesiumGeospatial/src/calcQuadtreeMaxGeometricError.cpp index 90c22ec35..6d6a54ccc 100644 --- a/Cesium3DTilesSelection/src/calcQuadtreeMaxGeometricError.cpp +++ b/CesiumGeospatial/src/calcQuadtreeMaxGeometricError.cpp @@ -1,10 +1,10 @@ -#include "calcQuadtreeMaxGeometricError.h" +#include -namespace Cesium3DTilesSelection { +namespace CesiumGeospatial { double calcQuadtreeMaxGeometricError( const CesiumGeospatial::Ellipsoid& ellipsoid) noexcept { static const double mapQuality = 0.25; static const uint32_t mapWidth = 65; return ellipsoid.getMaximumRadius() * mapQuality / mapWidth; } -} // namespace Cesium3DTilesSelection +} // namespace CesiumGeospatial diff --git a/CesiumNativeTests/CMakeLists.txt b/CesiumNativeTests/CMakeLists.txt index 89604034c..f2c5bba27 100644 --- a/CesiumNativeTests/CMakeLists.txt +++ b/CesiumNativeTests/CMakeLists.txt @@ -5,6 +5,7 @@ configure_cesium_library(cesium-native-tests) # properties. set(cesium_native_targets Cesium3DTiles + Cesium3DTilesContent Cesium3DTilesReader Cesium3DTilesWriter Cesium3DTilesSelection @@ -18,10 +19,14 @@ set(cesium_native_targets CesiumUtility ) -set(test_sources "") -set(test_headers "") -set(test_include_directories "") - +cesium_glob_files(test_sources + ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp +) +cesium_glob_files(test_headers + ${CMAKE_CURRENT_LIST_DIR}/include/CesiumNativeTests/*.h + ${CMAKE_CURRENT_LIST_DIR}/generated/include/CesiumNativeTests/*.h +) +set(test_include_directories ${CMAKE_CURRENT_LIST_DIR}/include) # Iterate through all targets, extracting their private sources and test sources / test headers foreach(target ${cesium_native_targets}) diff --git a/Cesium3DTilesSelection/test/SimpleAssetAccessor.h b/CesiumNativeTests/include/CesiumNativeTests/SimpleAssetAccessor.h similarity index 95% rename from Cesium3DTilesSelection/test/SimpleAssetAccessor.h rename to CesiumNativeTests/include/CesiumNativeTests/SimpleAssetAccessor.h index 23c13983b..4c0943a50 100644 --- a/Cesium3DTilesSelection/test/SimpleAssetAccessor.h +++ b/CesiumNativeTests/include/CesiumNativeTests/SimpleAssetAccessor.h @@ -12,7 +12,7 @@ #include #include -namespace Cesium3DTilesSelection { +namespace CesiumNativeTests { class SimpleAssetAccessor : public CesiumAsync::IAssetAccessor { public: SimpleAssetAccessor( @@ -51,4 +51,4 @@ class SimpleAssetAccessor : public CesiumAsync::IAssetAccessor { std::map> mockCompletedRequests; }; -} // namespace Cesium3DTilesSelection +} // namespace CesiumNativeTests diff --git a/Cesium3DTilesSelection/test/SimpleAssetRequest.h b/CesiumNativeTests/include/CesiumNativeTests/SimpleAssetRequest.h similarity index 89% rename from Cesium3DTilesSelection/test/SimpleAssetRequest.h rename to CesiumNativeTests/include/CesiumNativeTests/SimpleAssetRequest.h index f6755ce00..3726f0e29 100644 --- a/Cesium3DTilesSelection/test/SimpleAssetRequest.h +++ b/CesiumNativeTests/include/CesiumNativeTests/SimpleAssetRequest.h @@ -1,12 +1,11 @@ #pragma once -#include "SimpleAssetResponse.h" - #include +#include #include -namespace Cesium3DTilesSelection { +namespace CesiumNativeTests { class SimpleAssetRequest : public CesiumAsync::IAssetRequest { public: SimpleAssetRequest( @@ -38,4 +37,4 @@ class SimpleAssetRequest : public CesiumAsync::IAssetRequest { CesiumAsync::HttpHeaders requestHeaders; std::unique_ptr pResponse; }; -} // namespace Cesium3DTilesSelection +} // namespace CesiumNativeTests diff --git a/Cesium3DTilesSelection/test/SimpleAssetResponse.h b/CesiumNativeTests/include/CesiumNativeTests/SimpleAssetResponse.h similarity index 93% rename from Cesium3DTilesSelection/test/SimpleAssetResponse.h rename to CesiumNativeTests/include/CesiumNativeTests/SimpleAssetResponse.h index 77de26aa9..8248d9642 100644 --- a/Cesium3DTilesSelection/test/SimpleAssetResponse.h +++ b/CesiumNativeTests/include/CesiumNativeTests/SimpleAssetResponse.h @@ -5,7 +5,7 @@ #include #include -namespace Cesium3DTilesSelection { +namespace CesiumNativeTests { class SimpleAssetResponse : public CesiumAsync::IAssetResponse { public: SimpleAssetResponse( @@ -37,4 +37,4 @@ class SimpleAssetResponse : public CesiumAsync::IAssetResponse { CesiumAsync::HttpHeaders mockHeaders; std::vector mockData; }; -} // namespace Cesium3DTilesSelection +} // namespace CesiumNativeTests diff --git a/Cesium3DTilesSelection/test/SimpleTaskProcessor.h b/CesiumNativeTests/include/CesiumNativeTests/SimpleTaskProcessor.h similarity index 73% rename from Cesium3DTilesSelection/test/SimpleTaskProcessor.h rename to CesiumNativeTests/include/CesiumNativeTests/SimpleTaskProcessor.h index 028ff219d..a9f169593 100644 --- a/Cesium3DTilesSelection/test/SimpleTaskProcessor.h +++ b/CesiumNativeTests/include/CesiumNativeTests/SimpleTaskProcessor.h @@ -2,9 +2,9 @@ #include -namespace Cesium3DTilesSelection { +namespace CesiumNativeTests { class SimpleTaskProcessor : public CesiumAsync::ITaskProcessor { public: virtual void startTask(std::function f) override { f(); } }; -} // namespace Cesium3DTilesSelection +} // namespace CesiumNativeTests diff --git a/Cesium3DTilesSelection/test/readFile.h b/CesiumNativeTests/include/CesiumNativeTests/readFile.h similarity index 100% rename from Cesium3DTilesSelection/test/readFile.h rename to CesiumNativeTests/include/CesiumNativeTests/readFile.h diff --git a/Cesium3DTilesSelection/test/readFile.cpp b/CesiumNativeTests/src/readFile.cpp similarity index 91% rename from Cesium3DTilesSelection/test/readFile.cpp rename to CesiumNativeTests/src/readFile.cpp index 2be1f2a0c..411f298ff 100644 --- a/Cesium3DTilesSelection/test/readFile.cpp +++ b/CesiumNativeTests/src/readFile.cpp @@ -1,4 +1,4 @@ -#include "readFile.h" +#include #include diff --git a/CesiumUtility/CMakeLists.txt b/CesiumUtility/CMakeLists.txt index bb704b8d0..1859e2703 100644 --- a/CesiumUtility/CMakeLists.txt +++ b/CesiumUtility/CMakeLists.txt @@ -47,6 +47,7 @@ target_link_libraries_system( PUBLIC glm uriparser + spdlog ) target_link_libraries(CesiumUtility diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/ErrorList.h b/CesiumUtility/include/CesiumUtility/ErrorList.h similarity index 94% rename from Cesium3DTilesSelection/include/Cesium3DTilesSelection/ErrorList.h rename to CesiumUtility/include/CesiumUtility/ErrorList.h index 2ebd1a43e..3626368e6 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/ErrorList.h +++ b/CesiumUtility/include/CesiumUtility/ErrorList.h @@ -1,20 +1,20 @@ #pragma once #include "Library.h" - -#include +#include "joinToString.h" #include #include #include -namespace Cesium3DTilesSelection { +namespace CesiumUtility { + /** * @brief The container to store the error and warning list when loading a tile * or glTF content */ -struct CESIUM3DTILESSELECTION_API ErrorList { +struct CESIUMUTILITY_API ErrorList { /** * @brief Merge the errors and warnings from other ErrorList together * @@ -107,4 +107,5 @@ struct CESIUM3DTILESSELECTION_API ErrorList { */ std::vector warnings; }; -} // namespace Cesium3DTilesSelection + +} // namespace CesiumUtility diff --git a/Cesium3DTilesSelection/src/ErrorList.cpp b/CesiumUtility/src/ErrorList.cpp similarity index 86% rename from Cesium3DTilesSelection/src/ErrorList.cpp rename to CesiumUtility/src/ErrorList.cpp index 4ad3cc84c..4e157c1fd 100644 --- a/Cesium3DTilesSelection/src/ErrorList.cpp +++ b/CesiumUtility/src/ErrorList.cpp @@ -1,6 +1,7 @@ -#include +#include + +namespace CesiumUtility { -namespace Cesium3DTilesSelection { void ErrorList::merge(const ErrorList& errorList) { errors.insert(errors.end(), errorList.errors.begin(), errorList.errors.end()); warnings.insert( @@ -24,4 +25,5 @@ void ErrorList::merge(ErrorList&& errorList) { bool ErrorList::hasErrors() const noexcept { return !errors.empty(); } ErrorList::operator bool() const noexcept { return hasErrors(); } -} // namespace Cesium3DTilesSelection + +} // namespace CesiumUtility