Skip to content

Commit

Permalink
gltf: Vertex attribute は UnsignedInt に対応していないので修正 (#351)
Browse files Browse the repository at this point in the history
- 以下に従い、UnsignedIntをFloatに変更
-
https://github.com/CesiumGS/glTF/blob/proposal-EXT_mesh_features/extensions/2.0/Vendor/EXT_mesh_features/README.md#feature-id-by-vertex

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **機能変更**
-
メッシュプリミティブが`UnsignedInt`をサポートしていないため、`feature_id`を`u32`から`f32`へ変換しました。これにより、バイナリコンテンツの書き込みとアクセサコンポーネントのタイプが影響を受けます。

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
nokonoko1203 authored Feb 27, 2024
1 parent c70a1e4 commit 8acf35d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
Binary file modified demo/cesium/examples/ext_structural_metadata/PlantCover.glb
Binary file not shown.
Binary file not shown.
48 changes: 26 additions & 22 deletions demo/cesium/examples/ext_structural_metadata/tileset.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
{
"asset": {
"version": "1.1"
},
"geometricError": 1e100,
"root": {
"boundingVolume": {
"region": [
2.423545352784276, 0.6126113632476141, 2.423568686412357,
0.6126530152363875, 48.27812072424482, 61.914851977799785
]
},
"geometricError": 0.0,
"contents": [
{
"uri": "PlantCover.glb"
},
{
"uri": "SolitaryVegetationObject.glb"
}
]
}
}
"asset": {
"version": "1.1"
},
"geometricError": 1e100,
"root": {
"boundingVolume": {
"region": [
2.423545352784276,
0.6126113632476141,
2.423568686412357,
0.6126530152363875,
48.27812072424482,
61.914851977799785
]
},
"geometricError": 0.0,
"contents": [
{
"uri": "PlantCover.glb"
},
{
"uri": "SolitaryVegetationObject.glb"
}
]
}
}
9 changes: 5 additions & 4 deletions nusamai/src/sink/gltf/gltf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ pub fn build_base_gltf(class_name: &str, buffer: &Buffers, translation: [f64; 3]
let feature_ids_offset = bin_content.len();
let mut feature_ids_count = 0;
for vertex in buffer.vertices.clone() {
bin_content
.write_all(&vertex.feature_id.to_le_bytes())
.unwrap();
// UnsignedInt cannot be used as vertix attributes in MeshPrimitive
// https://github.com/CesiumGS/glTF/blob/proposal-EXT_mesh_features/extensions/2.0/Vendor/EXT_mesh_features/README.md#feature-id-by-vertex
let vertex = vertex.feature_id as f32;
bin_content.write_all(&vertex.to_le_bytes()).unwrap();
feature_ids_count += 1;
}
let feature_ids_len = bin_content.len() - feature_ids_offset;
Expand All @@ -154,7 +155,7 @@ pub fn build_base_gltf(class_name: &str, buffer: &Buffers, translation: [f64; 3]
let feature_id_max = buffer.vertices.iter().map(|v| v.feature_id).max().unwrap();
let accessor = Accessor {
buffer_view: Some(buffer_view_length),
component_type: ComponentType::UnsignedInt,
component_type: ComponentType::Float,
count: feature_ids_count,
type_: AccessorType::Scalar,
min: Some(vec![feature_id_min as f64]),
Expand Down

0 comments on commit 8acf35d

Please sign in to comment.