-
Notifications
You must be signed in to change notification settings - Fork 251
Read a glTF file's external data before postprocessing. #1280
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
Changes from 5 commits
fc6b169
8c32e34
3bd7cb7
fa77960
9fd6009
7b51bff
3e24f62
caffcde
7c44172
368ec2a
751bd3e
c603fa1
b689e6d
537aaa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,26 @@ CesiumAsync::Future<GltfConverterResult> BinaryToGltfConverter::convert( | |
| const std::span<const std::byte>& gltfBinary, | ||
| const CesiumGltfReader::GltfReaderOptions& options, | ||
| const AssetFetcher& assetFetcher) { | ||
| return assetFetcher.asyncSystem.createResolvedFuture( | ||
| convertImmediate(gltfBinary, options, assetFetcher)); | ||
| return _gltfReader | ||
| .readGltfAndExternalData( | ||
| gltfBinary, | ||
| assetFetcher.asyncSystem, | ||
| assetFetcher.requestHeaders, | ||
| assetFetcher.pAssetAccessor, | ||
| assetFetcher.baseUrl, | ||
| options) | ||
| .thenInWorkerThread( | ||
| [&assetFetcher](CesiumGltfReader::GltfReaderResult&& gltfResult) { | ||
|
||
| if (gltfResult.model) { | ||
|
||
| gltfResult.model->extras["gltfUpAxis"] = | ||
| static_cast<std::underlying_type_t<CesiumGeometry::Axis>>( | ||
| assetFetcher.upAxis); | ||
| } | ||
| GltfConverterResult result; | ||
| result.model = std::move(gltfResult.model); | ||
| result.errors.errors = std::move(gltfResult.errors); | ||
| result.errors.warnings = std::move(gltfResult.warnings); | ||
| return result; | ||
| }); | ||
| } | ||
| } // namespace Cesium3DTilesContent | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,6 @@ | |
| #include <CesiumGeospatial/Projection.h> | ||
| #include <CesiumGltf/Image.h> | ||
| #include <CesiumGltfContent/GltfUtilities.h> | ||
| #include <CesiumGltfReader/GltfReader.h> | ||
| #include <CesiumRasterOverlays/ActivatedRasterOverlay.h> | ||
| #include <CesiumRasterOverlays/RasterOverlay.h> | ||
| #include <CesiumRasterOverlays/RasterOverlayDetails.h> | ||
|
|
@@ -566,85 +565,16 @@ postProcessContentInWorkerThread( | |
| result.state == TileLoadResultState::Success && | ||
| "This function requires result to be success"); | ||
|
|
||
| CesiumGltf::Model& model = std::get<CesiumGltf::Model>(result.contentKind); | ||
|
|
||
| // Download any external image or buffer urls in the gltf if there are any | ||
| CesiumGltfReader::GltfReaderResult gltfResult{std::move(model), {}, {}}; | ||
|
|
||
| CesiumAsync::HttpHeaders requestHeaders; | ||
| std::string baseUrl; | ||
| if (result.pCompletedRequest) { | ||
| requestHeaders = result.pCompletedRequest->headers(); | ||
| baseUrl = result.pCompletedRequest->url(); | ||
| } | ||
|
|
||
| CesiumGltfReader::GltfReaderOptions gltfOptions; | ||
| gltfOptions.ktx2TranscodeTargets = | ||
| tileLoadInfo.contentOptions.ktx2TranscodeTargets; | ||
| gltfOptions.applyTextureTransform = | ||
| tileLoadInfo.contentOptions.applyTextureTransform; | ||
| if (tileLoadInfo.pSharedAssetSystem) { | ||
| gltfOptions.pSharedAssetSystem = tileLoadInfo.pSharedAssetSystem; | ||
| } | ||
|
|
||
| std::optional<int64_t> version = | ||
| pGltfModifier ? pGltfModifier->getCurrentVersion() : std::nullopt; | ||
|
|
||
| auto asyncSystem = tileLoadInfo.asyncSystem; | ||
| auto pAssetAccessor = result.pAssetAccessor; | ||
| return CesiumGltfReader::GltfReader::resolveExternalData( | ||
| asyncSystem, | ||
| baseUrl, | ||
| requestHeaders, | ||
| pAssetAccessor, | ||
| gltfOptions, | ||
| std::move(gltfResult)) | ||
| .thenInWorkerThread([result = std::move(result), | ||
| projections = std::move(projections), | ||
| tileLoadInfo = std::move(tileLoadInfo), | ||
| version, | ||
| pGltfModifier](CesiumGltfReader::GltfReaderResult&& | ||
| gltfResult) mutable { | ||
| if (!gltfResult.errors.empty()) { | ||
| if (result.pCompletedRequest) { | ||
| SPDLOG_LOGGER_ERROR( | ||
| tileLoadInfo.pLogger, | ||
| "Failed resolving external glTF buffers from {}:\n- {}", | ||
| result.pCompletedRequest->url(), | ||
| CesiumUtility::joinToString(gltfResult.errors, "\n- ")); | ||
| } else { | ||
| SPDLOG_LOGGER_ERROR( | ||
| tileLoadInfo.pLogger, | ||
| "Failed resolving external glTF buffers:\n- {}", | ||
| CesiumUtility::joinToString(gltfResult.errors, "\n- ")); | ||
| } | ||
| } | ||
|
|
||
| if (!gltfResult.warnings.empty()) { | ||
| if (result.pCompletedRequest) { | ||
| SPDLOG_LOGGER_WARN( | ||
| tileLoadInfo.pLogger, | ||
| "Warning when resolving external gltf buffers from " | ||
| "{}:\n- {}", | ||
| result.pCompletedRequest->url(), | ||
| CesiumUtility::joinToString(gltfResult.warnings, "\n- ")); | ||
| } else { | ||
| SPDLOG_LOGGER_ERROR( | ||
| tileLoadInfo.pLogger, | ||
| "Warning resolving external glTF buffers:\n- {}", | ||
| CesiumUtility::joinToString(gltfResult.warnings, "\n- ")); | ||
| } | ||
| } | ||
|
|
||
| if (!gltfResult.model) { | ||
| return tileLoadInfo.asyncSystem | ||
| .createResolvedFuture(TileLoadResult::createFailedResult( | ||
| result.pAssetAccessor, | ||
| nullptr)) | ||
| .thenPassThrough(std::move(tileLoadInfo)); | ||
| } | ||
|
|
||
| result.contentKind = std::move(*gltfResult.model); | ||
| return asyncSystem | ||
| .runInWorkerThread([result = std::move(result), | ||
|
||
| projections = std::move(projections), | ||
| tileLoadInfo = std::move(tileLoadInfo), | ||
| version, | ||
| pGltfModifier]() mutable { | ||
| result.initialBoundingVolume = tileLoadInfo.tileBoundingVolume; | ||
| result.initialContentBoundingVolume = | ||
| tileLoadInfo.tileContentBoundingVolume; | ||
|
|
@@ -653,7 +583,6 @@ postProcessContentInWorkerThread( | |
| result, | ||
| std::move(projections), | ||
| tileLoadInfo); | ||
|
|
||
| if (pGltfModifier && version) { | ||
| // Apply the glTF modifier right away, otherwise it will be | ||
| // triggered immediately after the renderer-side resources | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -405,6 +405,53 @@ GltfReaderResult GltfReader::readGltf( | |||||||
| return result; | ||||||||
| } | ||||||||
|
|
||||||||
| CesiumAsync::Future<GltfReaderResult> GltfReader::readGltfAndExternalData( | ||||||||
| const std::span<const std::byte>& data, | ||||||||
| const CesiumAsync::AsyncSystem& asyncSystem, | ||||||||
| const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers, | ||||||||
| const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor, | ||||||||
| const std::string& baseUrl, | ||||||||
| const GltfReaderOptions& options) const { | ||||||||
| CesiumAsync::HttpHeaders httpHeaders; | ||||||||
| httpHeaders.insert(headers.begin(), headers.end()); | ||||||||
|
||||||||
| CesiumAsync::HttpHeaders httpHeaders; | |
| httpHeaders.insert(headers.begin(), headers.end()); | |
| CesiumAsync::HttpHeaders httpHeaders(headers.begin(), headers.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kring for fixing my broken code!
Uh oh!
There was an error while loading. Please reload this page.