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 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; }