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

Support 3D Tile I3dm legacy tile format #854

Merged
merged 39 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3ba003a
Make CESIUM_DEBUG_PREFIX and CESIUM_RELEASE_PREFIX cache variables
timoore Apr 7, 2024
ff427ac
Fix CesiumGltf::Model::merge to handle EXT_mesh_gpu_instancing
timoore Apr 7, 2024
dd563d5
Add support for I3dm 3D Tile instance files
timoore Apr 8, 2024
fe1f01d
use npm format properly
timoore Apr 9, 2024
72a8fb5
Fix convert calls in tests
timoore Apr 10, 2024
9b2bde2
remove const from static_cast to satisfy gcc
timoore Apr 11, 2024
b1c9f94
More formatting fun
timoore Apr 11, 2024
37f3684
Preserve double values from i3dm, WIP
timoore Apr 11, 2024
806d0ed
WIP glTF converter functions return a Future
timoore Apr 17, 2024
81bb2ff
Change ConverterSubprocessor arguments from pointer to reference
timoore Apr 17, 2024
7db60d6
Add std::move in response to compiler warning
timoore Apr 17, 2024
0a4a5a9
Merge branch 'main' into i3dm-2024
timoore Apr 17, 2024
616bf74
Rebase instance positions to their mean
timoore Apr 19, 2024
80ade66
I3dm: Support the EAST_NORTH_UP global semantic
timoore Apr 26, 2024
9661e40
Refactor and support existing instances in GLB
timoore Apr 26, 2024
4658109
Refactor with helpers for converting glTF values to glm.
timoore Apr 26, 2024
2cef550
Merge branch 'main' into i3dm-2024
timoore Apr 26, 2024
ab70a66
Merge branch 'main' into i3dm-2024
timoore May 2, 2024
db9637d
Merge branch 'main' into i3dm-2024
timoore May 3, 2024
1cd4ab7
Modify Cesium3DTilesContent tests to use ConverterSubprocessor
timoore May 7, 2024
5731d48
Squash some CI compilation errors
timoore May 7, 2024
d238025
Add a perpVec function and use it
timoore May 7, 2024
aca7686
Merge remote-tracking branch 'origin/main' into i3dm-2024
kring May 9, 2024
ea79bb8
Reponse to feedback: change ConverterSubprocessor to AssetFetcher
timoore May 16, 2024
068f70e
WIP responding to review comments
timoore May 17, 2024
598fd2e
Break i3dm JSON parsing out into a helper function
timoore May 17, 2024
7369873
Rework applyRTC and meshGpuTransforms
timoore May 17, 2024
88a3b8d
Use gsl:span instead of raw pointers
timoore May 17, 2024
be323a4
Move rotation function to CesiumUtility/Math.h
timoore May 17, 2024
c6b5321
Merge remote-tracking branch 'origin/i3dm-2024' into i3dm-2024
timoore May 17, 2024
ed9bfa8
Merge branch 'tmp/quatFunc' into i3dm-2024
timoore May 17, 2024
e60e936
format fixes
timoore May 17, 2024
edc22cb
Test compilation and gcc fixes
timoore May 20, 2024
9af4cd7
Add tests for CesiumUtility::Math::rotation and fix a bug
timoore May 23, 2024
d822cf4
Use a fail() local function in ImplicitOctreeLoader
timoore May 23, 2024
029d0ab
Renamed LegacyUtilities to GltfConverterUtility
timoore May 23, 2024
2a284f5
formatting and name change
timoore May 23, 2024
80a5091
More changes in response to code review
timoore May 24, 2024
ba68601
Renaming and simplification
timoore May 24, 2024
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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

### v0.34.0

##### Additions :tada:

- Added support for I3dm 3D Tile content files.

### v0.33.0 - 2024-03-01

##### Breaking Changes :mega:
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ if (NOT DEFINED GLOB_USE_CONFIGURE_DEPENDS)
)
endif()

set(CESIUM_DEBUG_POSTFIX "d")
set(CESIUM_RELEASE_POSTFIX "")
set(CESIUM_DEBUG_POSTFIX "d" CACHE STRING "debug postfix for cesium native")
set(CESIUM_RELEASE_POSTFIX "" CACHE STRING "release postfix for cesium native")

set(CMAKE_DEBUG_POSTFIX ${CESIUM_DEBUG_POSTFIX})
set(CMAKE_RELEASE_POSTFIX ${CESIUM_RELEASE_POSTFIX})
Expand Down Expand Up @@ -132,8 +132,8 @@ endfunction()
add_subdirectory(extern EXCLUDE_FROM_ALL)

# These libraries override the debug postfix, so re-override it.
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX ${CESIUM_DEBUG_POSTFIX})
set_target_properties(tinyxml2 PROPERTIES DEBUG_POSTFIX ${CESIUM_DEBUG_POSTFIX})
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "${CESIUM_DEBUG_POSTFIX}")
set_target_properties(tinyxml2 PROPERTIES DEBUG_POSTFIX "${CESIUM_DEBUG_POSTFIX}")

# Public Targets
add_subdirectory(CesiumUtility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
#include <optional>

namespace Cesium3DTilesContent {
struct ConverterSubprocessor;

struct B3dmToGltfConverter {
static GltfConverterResult convert(
const gsl::span<const std::byte>& b3dmBinary,
const CesiumGltfReader::GltfReaderOptions& options);
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor*);
};
} // namespace Cesium3DTilesContent
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
#include <cstddef>

namespace Cesium3DTilesContent {
struct ConverterSubprocessor;

struct BinaryToGltfConverter {
public:
static GltfConverterResult convert(
const gsl::span<const std::byte>& gltfBinary,
const CesiumGltfReader::GltfReaderOptions& options);
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subProcessor);

private:
static CesiumGltfReader::GltfReader _gltfReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
#include <cstddef>

namespace Cesium3DTilesContent {
struct ConverterSubprocessor;

struct CmptToGltfConverter {
static GltfConverterResult convert(
const gsl::span<const std::byte>& cmptBinary,
const CesiumGltfReader::GltfReaderOptions& options);
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor*);
};
} // namespace Cesium3DTilesContent
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#include <CesiumGltf/Model.h>
#include <CesiumUtility/ErrorList.h>

#include <glm/common.hpp>
#include <glm/gtx/quaternion.hpp>

#include <optional>
#include <string>
#include <vector>

namespace Cesium3DTilesContent {
/**
Expand Down
33 changes: 30 additions & 3 deletions Cesium3DTilesContent/include/Cesium3DTilesContent/GltfConverters.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@
#include <string_view>

namespace Cesium3DTilesContent {

/**
* Data required to make a recursive request to fetch an asset, mostly for the
* benefit of I3dm files.
*/
struct CESIUM3DTILESCONTENT_API ConverterSubprocessor {
timoore marked this conversation as resolved.
Show resolved Hide resolved
ConverterSubprocessor(
const CesiumAsync::AsyncSystem& asyncSystem_,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor_,
const std::string& baseUrl_,
const glm::dmat4 tileTransform_,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& requestHeaders_)
j9liu marked this conversation as resolved.
Show resolved Hide resolved
: asyncSystem(asyncSystem_),
pAssetAccessor(pAssetAccessor_),
baseUrl(baseUrl_),
tileTransform(tileTransform_),
requestHeaders(requestHeaders_) {}
const CesiumAsync::AsyncSystem& asyncSystem;
const std::shared_ptr<CesiumAsync::IAssetAccessor> pAssetAccessor;
const std::string baseUrl;
glm::dmat4 tileTransform;
const std::vector<CesiumAsync::IAssetAccessor::THeader>& requestHeaders;
};

/**
* @brief Creates {@link GltfConverterResult} objects from a
* a binary content.
Expand All @@ -34,7 +58,8 @@ class CESIUM3DTILESCONTENT_API GltfConverters {
*/
using ConverterFunction = GltfConverterResult (*)(
const gsl::span<const std::byte>& content,
const CesiumGltfReader::GltfReaderOptions& options);
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subprocessor);

/**
* @brief Register the given function for the given magic header.
Expand Down Expand Up @@ -123,7 +148,8 @@ class CESIUM3DTILESCONTENT_API GltfConverters {
static GltfConverterResult convert(
const std::string& filePath,
const gsl::span<const std::byte>& content,
const CesiumGltfReader::GltfReaderOptions& options);
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subprocessor);

/**
* @brief Creates the {@link GltfConverterResult} from the given
Expand All @@ -147,7 +173,8 @@ class CESIUM3DTILESCONTENT_API GltfConverters {
*/
static GltfConverterResult convert(
const gsl::span<const std::byte>& content,
const CesiumGltfReader::GltfReaderOptions& options);
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subprocessor);

private:
static std::string toLowerCase(const std::string_view& str);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <Cesium3DTilesContent/GltfConverterResult.h>

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

#include <glm/mat4x4.hpp>
#include <gsl/span>

#include <optional>

namespace Cesium3DTilesContent {
struct ConverterSubprocessor;

struct I3dmToGltfConverter {
static GltfConverterResult convert(
const gsl::span<const std::byte>& instancesBinary,
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subprocessor);
};
} // namespace Cesium3DTilesContent
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma once

#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumAsync/IAssetRequest.h>

#include <Cesium3DTilesContent/GltfConverters.h>
#include <CesiumUtility/ErrorList.h>

#include <glm/fwd.hpp>

#include <rapidjson/document.h>

#include <cstdint>
#include <optional>
#include <vector>

namespace CesiumGltf {
class Model;
class Buffer;
}

namespace Cesium3DTilesContent {

struct ByteResult {
std::vector<std::byte> bytes;
CesiumUtility::ErrorList errorList;
};

CesiumAsync::Future<ByteResult> get(const ConverterSubprocessor& subprocessor, const std::string& relativeUrl);

namespace LegacyUtilities {
j9liu marked this conversation as resolved.
Show resolved Hide resolved
std::optional<uint32_t> parseOffset(const rapidjson::Document& document, const char* semantic, CesiumUtility::ErrorList& errorList);

typedef bool (rapidjson::Value::*ValuePredicate)() const;

template<typename T> bool isValue(const rapidjson::Value& value);
template<typename T> T getValue(const rapidjson::Value& value);

template<typename T>
std::optional<T> getOpt(const rapidjson::Value& value) {
if (isValue<T>(value)) {
return std::make_optional(getValue<T>(value));
}
return {};
}

template<typename T>
std::optional<T> getValue(const rapidjson::Document& document, const char *semantic) {
const auto valueIt = document.FindMember(semantic);
if (valueIt == document.MemberEnd() || !isValue<T>(valueIt->value)) {
return {};
}
return std::make_optional(getValue<T>(valueIt->value));
}

template<>
inline bool isValue<bool>(const rapidjson::Value& value) {
return value.IsBool();
}

template<>
inline bool getValue<bool>(const rapidjson::Value& value) {
return value.GetBool();
}

template<>
inline bool isValue<uint32_t>(const rapidjson::Value& value) {
return value.IsUint();
}

template<>
inline uint32_t getValue<uint32_t>(const rapidjson::Value& value) {
return value.GetUint();
}

bool validateJsonArrayValues(const rapidjson::Value& arrayValue, uint32_t expectedLength, ValuePredicate predicate);

std::optional<glm::vec3> parseArrayValueVec3(const rapidjson::Value& arrayValue);

std::optional<glm::vec3> parseArrayValueVec3(const rapidjson::Document& document, const char *name);

int32_t createBufferInGltf(CesiumGltf::Model& gltf);
int32_t createBufferInGltf(CesiumGltf::Model& gltf, std::vector<std::byte>&& buffer);

int32_t createBufferViewInGltf(
CesiumGltf::Model& gltf,
const int32_t bufferId,
const int64_t byteLength,
const int64_t byteStride);

int32_t createAccessorInGltf(
CesiumGltf::Model& gltf,
const int32_t bufferViewId,
const int32_t componentType,
const int64_t count,
const std::string type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
#include <optional>

namespace Cesium3DTilesContent {
struct ConverterSubprocessor;

struct PntsToGltfConverter {
static GltfConverterResult convert(
const gsl::span<const std::byte>& pntsBinary,
const CesiumGltfReader::GltfReaderOptions& options);
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor*);
};
} // namespace Cesium3DTilesContent
5 changes: 3 additions & 2 deletions Cesium3DTilesContent/src/B3dmToGltfConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void convertB3dmContentToGltf(
b3dmBinary.subspan(glbStart, glbEnd - glbStart);

GltfConverterResult binToGltfResult =
BinaryToGltfConverter::convert(glbData, options);
BinaryToGltfConverter::convert(glbData, options, nullptr);

result.model = std::move(binToGltfResult.model);
result.errors.merge(std::move(binToGltfResult.errors));
Expand Down Expand Up @@ -231,7 +231,8 @@ void convertB3dmMetadataToGltfStructuralMetadata(

GltfConverterResult B3dmToGltfConverter::convert(
const gsl::span<const std::byte>& b3dmBinary,
const CesiumGltfReader::GltfReaderOptions& options) {
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor*) {
GltfConverterResult result;
B3dmHeader header;
uint32_t headerLength = 0;
Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTilesContent/src/BinaryToGltfConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ CesiumGltfReader::GltfReader BinaryToGltfConverter::_gltfReader;

GltfConverterResult BinaryToGltfConverter::convert(
const gsl::span<const std::byte>& gltfBinary,
const CesiumGltfReader::GltfReaderOptions& options) {
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor*) {
CesiumGltfReader::GltfReaderResult loadedGltf =
_gltfReader.readGltf(gltfBinary, options);

Expand Down
6 changes: 4 additions & 2 deletions Cesium3DTilesContent/src/CmptToGltfConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static_assert(sizeof(InnerHeader) == 12);

GltfConverterResult CmptToGltfConverter::convert(
const gsl::span<const std::byte>& cmptBinary,
const CesiumGltfReader::GltfReaderOptions& options) {
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subProcessor) {
GltfConverterResult result;
if (cmptBinary.size() < sizeof(CmptHeader)) {
result.errors.emplaceWarning("Composite tile must be at least 16 bytes.");
Expand Down Expand Up @@ -78,7 +79,8 @@ GltfConverterResult CmptToGltfConverter::convert(

pos += pInner->byteLength;

innerTiles.emplace_back(GltfConverters::convert(innerData, options));
innerTiles.emplace_back(
GltfConverters::convert(innerData, options, subProcessor));
}

uint32_t tilesLength = pHeader->tilesLength;
Expand Down
12 changes: 7 additions & 5 deletions Cesium3DTilesContent/src/GltfConverters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ GltfConverters::getConverterByMagic(const gsl::span<const std::byte>& content) {
GltfConverterResult GltfConverters::convert(
const std::string& filePath,
const gsl::span<const std::byte>& content,
const CesiumGltfReader::GltfReaderOptions& options) {
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subprocessor) {
std::string magic;
auto converterFun = getConverterByMagic(content, magic);
if (converterFun) {
return converterFun(content, options);
return converterFun(content, options, subprocessor);
}

std::string fileExtension;
converterFun = getConverterByFileExtension(filePath, fileExtension);
if (converterFun) {
return converterFun(content, options);
return converterFun(content, options, subprocessor);
}

ErrorList errors;
Expand All @@ -65,11 +66,12 @@ GltfConverterResult GltfConverters::convert(

GltfConverterResult GltfConverters::convert(
const gsl::span<const std::byte>& content,
const CesiumGltfReader::GltfReaderOptions& options) {
const CesiumGltfReader::GltfReaderOptions& options,
ConverterSubprocessor* subprocessor) {
std::string magic;
auto converter = getConverterByMagic(content, magic);
if (converter) {
return converter(content, options);
return converter(content, options, subprocessor);
}

ErrorList errors;
Expand Down
Loading
Loading