From 70230edd9a8e039c87882bdf10fa839f2a78c9ad Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Wed, 1 Mar 2023 22:09:01 +1100 Subject: [PATCH 1/2] Round feature IDs. To account for error potentially introduced by Draco encoding. --- native~/Runtime/src/CesiumMetadataImpl.cpp | 39 +++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/native~/Runtime/src/CesiumMetadataImpl.cpp b/native~/Runtime/src/CesiumMetadataImpl.cpp index 4856a948..152de0c9 100644 --- a/native~/Runtime/src/CesiumMetadataImpl.cpp +++ b/native~/Runtime/src/CesiumMetadataImpl.cpp @@ -51,6 +51,34 @@ int64_t getVertexIndexFromTriangleIndex( indicesView); } +namespace { + +struct FeatureIDFromAccessor { + int64_t operator()(std::monostate) { return -1; } + + int64_t operator()( + const CesiumGltf::AccessorView>& value) { + if (vertexIdx >= 0 && vertexIdx < value.size()) { + return static_cast(glm::round(value[vertexIdx].value[0])); + } else { + return static_cast(-1); + } + } + + template + int64_t operator()(const CesiumGltf::AccessorView& value) { + if (vertexIdx >= 0 && vertexIdx < value.size()) { + return static_cast(value[vertexIdx].value[0]); + } else { + return static_cast(-1); + } + } + + int64_t vertexIdx; +}; + +} // namespace + int64_t getFeatureIdFromVertexIndex( const CesiumGltf::Model* pModel, const CesiumGltf::MeshPrimitive* pPrimitive, @@ -106,15 +134,8 @@ int64_t getFeatureIdFromVertexIndex( default: return 0; } - return std::visit( - [vertexIndex](auto&& value) { - if (vertexIndex >= 0 && vertexIndex < value.size()) { - return static_cast(value[vertexIndex].value[0]); - } else { - return static_cast(-1); - } - }, - featureIDAccessor); + + return std::visit(FeatureIDFromAccessor{vertexIndex}, featureIDAccessor); } return -1; } From 863882a935f40f1d49995d7661fdb3cffb2836bc Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Wed, 1 Mar 2023 22:13:24 +1100 Subject: [PATCH 2/2] Update CHANGES.md. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 5898825b..b74d8f28 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ - Fixed a bug that prevented caching of 3D Tiles and overlay requests. - Fixed a bug that could cause the Cesium ion Token Troubleshooting panel to crash the Unity Editor. - Added a workaround for a crash in the Burst Compiler (bcl.exe) in Unity 2022.2 when using il2cpp. +- Fixed a bug that could cause incorrect metadata to be associated with a feature, especially in Draco-encoded tiles. ### v0.2.0