Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First round of refactoring for enabling use of cesium-native for loading/manipulating/saving 3D Tiles #747

Merged
merged 8 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
67 changes: 67 additions & 0 deletions Cesium3DTilesContent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#pragma once

#include <Cesium3DTilesSelection/GltfConverterResult.h>
#include "GltfConverterResult.h"

#include <CesiumGltf/Model.h>
#include <CesiumGltfReader/GltfReader.h>

#include <gsl/span>

#include <optional>

namespace Cesium3DTilesSelection {
namespace Cesium3DTilesContent {
struct B3dmToGltfConverter {
static GltfConverterResult convert(
const gsl::span<const std::byte>& b3dmBinary,
const CesiumGltfReader::GltfReaderOptions& options);
};
} // namespace Cesium3DTilesSelection
} // namespace Cesium3DTilesContent
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include <Cesium3DTilesSelection/GltfConverterResult.h>
#include <Cesium3DTilesContent/GltfConverterResult.h>
#include <CesiumGltfReader/GltfReader.h>

#include <gsl/span>

#include <cstddef>

namespace Cesium3DTilesSelection {
namespace Cesium3DTilesContent {
struct BinaryToGltfConverter {
public:
static GltfConverterResult convert(
Expand All @@ -17,4 +17,4 @@ struct BinaryToGltfConverter {
private:
static CesiumGltfReader::GltfReader _gltfReader;
};
} // namespace Cesium3DTilesSelection
} // namespace Cesium3DTilesContent
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once

#include <Cesium3DTilesSelection/GltfConverterResult.h>
#include <Cesium3DTilesContent/GltfConverterResult.h>
#include <CesiumGltfReader/GltfReader.h>

#include <gsl/span>

#include <cstddef>

namespace Cesium3DTilesSelection {
namespace Cesium3DTilesContent {
struct CmptToGltfConverter {
static GltfConverterResult convert(
const gsl::span<const std::byte>& cmptBinary,
const CesiumGltfReader::GltfReaderOptions& options);
};
} // namespace Cesium3DTilesSelection
} // namespace Cesium3DTilesContent
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

#include "Library.h"

#include <Cesium3DTilesSelection/ErrorList.h>
#include <CesiumGltf/Model.h>
#include <CesiumUtility/ErrorList.h>

#include <optional>

namespace Cesium3DTilesSelection {
namespace Cesium3DTilesContent {
/**
* @brief The result of converting a binary content to gltf model.
*
* Instances of this structure are created internally, by the
* {@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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Library.h"

#include <Cesium3DTilesSelection/GltfConverterResult.h>
#include <Cesium3DTilesContent/GltfConverterResult.h>
#include <CesiumGltfReader/GltfReader.h>

#include <gsl/span>
Expand All @@ -11,7 +11,7 @@
#include <string>
#include <string_view>

namespace Cesium3DTilesSelection {
namespace Cesium3DTilesContent {
/**
* @brief Creates {@link GltfConverterResult} objects from a
* a binary content.
Expand All @@ -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
Expand Down Expand Up @@ -166,4 +166,4 @@ class CESIUM3DTILESSELECTION_API GltfConverters {
static std::unordered_map<std::string, ConverterFunction>
_loadersByFileExtension;
};
} // namespace Cesium3DTilesSelection
} // namespace Cesium3DTilesContent
96 changes: 96 additions & 0 deletions Cesium3DTilesContent/include/Cesium3DTilesContent/GltfUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#pragma once

#include "Library.h"

#include <CesiumGeospatial/BoundingRegion.h>
#include <CesiumGeospatial/GlobeRectangle.h>

#include <glm/fwd.hpp>

#include <string_view>
#include <vector>

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<std::string_view>
parseGltfCopyright(const CesiumGltf::Model& gltf);
};
} // namespace Cesium3DTilesContent
16 changes: 16 additions & 0 deletions Cesium3DTilesContent/include/Cesium3DTilesContent/Library.h
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#pragma once

#include <Cesium3DTilesSelection/GltfConverterResult.h>
#include "GltfConverterResult.h"

#include <CesiumGltf/Model.h>
#include <CesiumGltfReader/GltfReader.h>

#include <gsl/span>

#include <optional>

namespace Cesium3DTilesSelection {
namespace Cesium3DTilesContent {
struct PntsToGltfConverter {
static GltfConverterResult convert(
const gsl::span<const std::byte>& pntsBinary,
const CesiumGltfReader::GltfReaderOptions& options);
};
} // namespace Cesium3DTilesSelection
} // namespace Cesium3DTilesContent
Loading