Skip to content

Commit 6aa98fd

Browse files
authored
3dtiles: structural metadata のエンコーダ (#393)
## Tasks - [x] 3D Metadata Spec の Schema と Property tables を組む仕組み - [x] Code type を ENUM にエンコードする - [x] STRING (stringOffset) に対応する - [x] (STRING以外で) array (arrayOffset) に対応する - [x] STRING + array (arrayOffset) に対応する - [x] noData 値を適当に設定 ## 既知の問題 - テストがない #406 - BOOLEAN (bitstreamでの表現) に対応していない #407 - 複数の地物種類 contents を含めた Tileset を作ると一部のタイル表示されなくなる(これは今回の変更とは関係なく、以前から発生していた可能性が高い) #408 ![stractural metadata](https://github.com/MIERUNE/PLATEAU-GIS-Converter/assets/5351911/00b89f42-167f-4d25-9be6-830c5b8da74a) Close #376 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **新機能** - Rust Analyzerの保存時チェック機能を無効にする設定を追加しました。 - 構造メタデータのための`metadata_encoder`を使用して、ダミーメタデータの生成を置き換えました。 - 特徴属性を特定の形式にエンコードするモジュールを追加しました。 - メタデータエンコーディングプロセスに新しい機能とデータ構造を追加しました。 - 可変バイトベクターを指定されたアライメントにパディングする新しい公開関数`add_padding`を追加しました。 - **バグ修正** - 多角形のリング長を比較するネストされたループを削除し、`ApplyAppearanceTransform`実装内の処理ロジックに影響を与えました。 - **リファクタ** - 複数のファイルでインポートの再編成、関数への新しいパラメーターの追加、バッファーとアクセサーの命名と扱いの更新、コードの構造と可読性の向上、およびメタデータエンコーディングプロセスのリファクタリングを行いました。 - **スタイル** - `Image`構造体の実装を変更して、`BufferView`作成プロセス内で`name`フィールドを"image"に設定しました。 - **機能改善** - `DataRequirements`構造体の`key_value`フィールドを`KeyValueSpec::JsonifyObjectsAndArrays`に変更しました。 - `KeyValueSpec`列挙型を精緻化して、ネストされたオブジェクトと配列の変換に影響を与える`JsonifyObjectsAndArrays`と`JsonifyObjects`を区別しました。 <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1069a3d commit 6aa98fd

File tree

9 files changed

+580
-126
lines changed

9 files changed

+580
-126
lines changed

nusamai/src/sink/cesiumtiles/gltf.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::io::Write;
22

3-
use crate::sink::cesiumtiles::metadata::make_dummy_metadata;
4-
5-
use super::material;
3+
use super::{material, metadata::MetadataEncoder};
64
use ahash::{HashMap, HashSet};
75
use byteorder::{ByteOrder, LittleEndian};
86
use indexmap::IndexSet;
@@ -16,13 +14,13 @@ pub struct PrimitiveInfo {
1614

1715
pub type Primitives = HashMap<material::Material, PrimitiveInfo>;
1816

19-
/// とりいそぎの実装
2017
pub fn write_gltf_glb<W: Write>(
2118
writer: W,
2219
translation: [f64; 3],
2320
vertices: impl IntoIterator<Item = [u32; 9]>,
2421
primitives: Primitives,
2522
num_features: usize,
23+
metadata_encoder: MetadataEncoder,
2624
) -> std::io::Result<()> {
2725
use nusamai_gltf_json::*;
2826

@@ -62,6 +60,7 @@ pub fn write_gltf_glb<W: Write>(
6260
let len_vertices = bin_content.len() - buffer_offset;
6361
if len_vertices > 0 {
6462
gltf_buffer_views.push(BufferView {
63+
name: Some("vertices".to_string()),
6564
byte_offset: buffer_offset as u32,
6665
byte_length: len_vertices as u32,
6766
byte_stride: Some(VERTEX_BYTE_STRIDE as u8),
@@ -71,6 +70,7 @@ pub fn write_gltf_glb<W: Write>(
7170

7271
// accessor (positions)
7372
gltf_accessors.push(Accessor {
73+
name: Some("positions".to_string()),
7474
buffer_view: Some(gltf_buffer_views.len() as u32 - 1),
7575
component_type: ComponentType::Float,
7676
count: vertices_count,
@@ -82,6 +82,7 @@ pub fn write_gltf_glb<W: Write>(
8282

8383
// accessor (normal)
8484
gltf_accessors.push(Accessor {
85+
name: Some("normals".to_string()),
8586
buffer_view: Some(gltf_buffer_views.len() as u32 - 1),
8687
byte_offset: 4 * 3,
8788
component_type: ComponentType::Float,
@@ -92,6 +93,7 @@ pub fn write_gltf_glb<W: Write>(
9293

9394
// accessor (texcoords)
9495
gltf_accessors.push(Accessor {
96+
name: Some("texcoords".to_string()),
9597
buffer_view: Some(gltf_buffer_views.len() as u32 - 1),
9698
byte_offset: 4 * 6,
9799
component_type: ComponentType::Float,
@@ -102,6 +104,7 @@ pub fn write_gltf_glb<W: Write>(
102104

103105
// accessor (feature_id)
104106
gltf_accessors.push(Accessor {
107+
name: Some("_feature_ids".to_string()),
105108
buffer_view: Some(gltf_buffer_views.len() as u32 - 1),
106109
byte_offset: 4 * 8,
107110
component_type: ComponentType::Float,
@@ -114,6 +117,9 @@ pub fn write_gltf_glb<W: Write>(
114117

115118
let mut gltf_primitives = vec![];
116119

120+
let structural_metadata =
121+
metadata_encoder.into_metadata(&mut bin_content, &mut gltf_buffer_views);
122+
117123
// indices
118124
{
119125
let indices_offset = bin_content.len();
@@ -127,6 +133,7 @@ pub fn write_gltf_glb<W: Write>(
127133
}
128134

129135
gltf_accessors.push(Accessor {
136+
name: Some("indices".to_string()),
130137
buffer_view: Some(gltf_buffer_views.len() as u32),
131138
byte_offset,
132139
component_type: ComponentType::UnsignedInt,
@@ -170,6 +177,7 @@ pub fn write_gltf_glb<W: Write>(
170177
let indices_len = bin_content.len() - indices_offset;
171178
if indices_len > 0 {
172179
gltf_buffer_views.push(BufferView {
180+
name: Some("indices".to_string()),
173181
byte_offset: indices_offset as u32,
174182
byte_length: indices_len as u32,
175183
target: Some(BufferViewTarget::ElementArrayBuffer),
@@ -205,9 +213,6 @@ pub fn write_gltf_glb<W: Write>(
205213
});
206214
}
207215

208-
let ext_structural_metadata =
209-
make_dummy_metadata(num_features, &mut bin_content, &mut gltf_buffer_views);
210-
211216
let gltf_buffers = {
212217
let mut buffers = vec![];
213218
if !bin_content.is_empty() {
@@ -238,7 +243,7 @@ pub fn write_gltf_glb<W: Write>(
238243
buffer_views: gltf_buffer_views,
239244
buffers: gltf_buffers,
240245
extensions: nusamai_gltf_json::extensions::gltf::Gltf {
241-
ext_structural_metadata,
246+
ext_structural_metadata: structural_metadata,
242247
..Default::default()
243248
}
244249
.into(),

nusamai/src/sink/cesiumtiles/material.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl Image {
8787
let content = load_image(&path)?;
8888

8989
buffer_views.push(BufferView {
90+
name: Some("image".to_string()),
9091
byte_offset: bin_content.len() as u32,
9192
byte_length: content.len() as u32,
9293
..Default::default()

0 commit comments

Comments
 (0)