Skip to content

Commit

Permalink
GLB encoder/decoder (#272)
Browse files Browse the repository at this point in the history
glTFの JSONチャンクとBINチャンクを .glb (Binary glTF)
としてエンコード/デコードする処理を、小さなユーティリティにしておきます。

- JSON部分の内容についての知識 (serde_json, etc.) は、あえて混入させていません。
- 公式に提供されているGLBのサンプルファイルを読み込むテストを追加しています。
  • Loading branch information
ciscorn authored Feb 14, 2024
1 parent 3f3b89b commit 44bea54
Show file tree
Hide file tree
Showing 188 changed files with 309 additions and 57,166 deletions.
7 changes: 5 additions & 2 deletions nusamai-gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ version = "0.1.0"

[dependencies]
nusamai-gltf-json = { "path" = "nusamai-gltf-json" }
clap = { version = "4.4.6", features = ["derive"] }
clap = { version = "4.5.0", features = ["derive"] }
nusamai-geometry = { path = "../nusamai-geometry" }
quick-xml = "0.31.0"
thiserror = "1.0.50"
thiserror = "1.0.57"
earcut-rs = { git = "https://github.com/MIERUNE/earcut-rs.git" }
indexmap = "2.2.3"
byteorder = "1.5.0"
serde_json = "1.0.113"

[dev-dependencies]
glob = "0.3.1"
20 changes: 0 additions & 20 deletions nusamai-gltf/nusamai-gltf-json/tests/load_3d_tiles_examples.rs

This file was deleted.

20 changes: 20 additions & 0 deletions nusamai-gltf/nusamai-gltf-json/tests/load_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@ fn load_examples() {
assert_eq!(gltf, gltf2);
}
}

#[test]
fn load_3dtiles_examples() {
for path in glob::glob("./tests/samples/3d-tiles/**/*.gltf").unwrap() {
// deserialize
let path = path.unwrap();
println!("loading {:?}", path);
let src = std::fs::read_to_string(path).unwrap();
let gltf: Gltf = serde_json::from_str(&src).unwrap();

// serialize
let ser = serde_json::to_string(&gltf).unwrap();
// 'null' should not appear in output
assert!(!ser.contains("null"));

// deserialize again (expect the same deserialization result)
let gltf2 = serde_json::from_str(&ser).unwrap();
assert_eq!(gltf, gltf2);
}
}
Loading

0 comments on commit 44bea54

Please sign in to comment.