Skip to content

Commit

Permalink
Merge pull request #233 from CesiumGS/rounded-feature-ids
Browse files Browse the repository at this point in the history
Round feature IDs.
  • Loading branch information
kring committed Mar 1, 2023
2 parents c3df150 + 863882a commit e6a7b74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 30 additions & 9 deletions native~/Runtime/src/CesiumMetadataImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ int64_t getVertexIndexFromTriangleIndex(
indicesView);
}

namespace {

struct FeatureIDFromAccessor {
int64_t operator()(std::monostate) { return -1; }

int64_t operator()(
const CesiumGltf::AccessorView<AccessorTypes::SCALAR<float>>& value) {
if (vertexIdx >= 0 && vertexIdx < value.size()) {
return static_cast<int64_t>(glm::round(value[vertexIdx].value[0]));
} else {
return static_cast<int64_t>(-1);
}
}

template <typename T>
int64_t operator()(const CesiumGltf::AccessorView<T>& value) {
if (vertexIdx >= 0 && vertexIdx < value.size()) {
return static_cast<int64_t>(value[vertexIdx].value[0]);
} else {
return static_cast<int64_t>(-1);
}
}

int64_t vertexIdx;
};

} // namespace

int64_t getFeatureIdFromVertexIndex(
const CesiumGltf::Model* pModel,
const CesiumGltf::MeshPrimitive* pPrimitive,
Expand Down Expand Up @@ -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<int64_t>(value[vertexIndex].value[0]);
} else {
return static_cast<int64_t>(-1);
}
},
featureIDAccessor);

return std::visit(FeatureIDFromAccessor{vertexIndex}, featureIDAccessor);
}
return -1;
}
Expand Down

0 comments on commit e6a7b74

Please sign in to comment.