Skip to content

Commit ab09179

Browse files
committed
add tests for gltf extensions
1 parent 297e0b1 commit ab09179

File tree

106 files changed

+2137
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2137
-0
lines changed

tests/gltf_extensions.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use std::io::BufReader;
2+
use std::io::Read;
3+
4+
use serde::{Deserialize, Serialize};
5+
6+
use cesiumtiles::gltf_extensions::gltf;
7+
use cesiumtiles::gltf_extensions::mesh;
8+
9+
#[derive(Debug, Serialize, Deserialize)]
10+
#[serde(rename_all = "camelCase")]
11+
pub struct Gltf {
12+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
13+
pub meshes: Vec<Mesh>,
14+
15+
#[serde(skip_serializing_if = "Option::is_none")]
16+
pub extensions: Option<GltfExtension>,
17+
}
18+
19+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone)]
20+
#[serde[rename_all = "camelCase"]]
21+
pub struct Mesh {
22+
pub primitives: Vec<MeshPrimitive>,
23+
}
24+
25+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone)]
26+
#[serde[rename_all = "camelCase"]]
27+
pub struct MeshPrimitive {
28+
#[serde(skip_serializing_if = "Option::is_none")]
29+
pub extensions: Option<MeshPrimitiveExtension>,
30+
}
31+
32+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone)]
33+
pub struct MeshPrimitiveExtension {
34+
#[serde(skip_serializing_if = "Option::is_none")]
35+
#[serde(rename = "EXT_mesh_features")]
36+
pub ext_mesh_features: Option<mesh::ext_mesh_features::ExtMeshFeatures>,
37+
38+
#[serde(skip_serializing_if = "Option::is_none")]
39+
#[serde(rename = "EXT_structural_metadata")]
40+
pub ext_structural_metadata: Option<mesh::ext_structural_metadata::ExtStructuralMetadata>,
41+
}
42+
43+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
44+
pub struct GltfExtension {
45+
#[serde(rename = "EXT_structural_metadata")]
46+
#[serde(skip_serializing_if = "Option::is_none")]
47+
pub ext_structural_metadata: Option<gltf::ext_structural_metadata::ExtStructuralMetadata>,
48+
}
49+
50+
#[test]
51+
fn load_gltf_json() {
52+
for path in glob::glob("./tests/samples/**/*.gltf").unwrap() {
53+
let path = path.unwrap();
54+
println!("loading {:?}", path);
55+
let src = std::fs::read_to_string(path).unwrap();
56+
let a: Gltf = serde_json::from_str(&src).unwrap();
57+
let _ = format!("{:?}", a);
58+
59+
// 'null' should not appear in output
60+
let a = serde_json::to_string(&a).unwrap();
61+
assert!(!a.contains("null"));
62+
}
63+
}
1.77 KB
Binary file not shown.
1.77 KB
Binary file not shown.
1.77 KB
Binary file not shown.
1.77 KB
Binary file not shown.
1.77 KB
Binary file not shown.
1.77 KB
Binary file not shown.
51.2 KB
Binary file not shown.
33.8 KB
Binary file not shown.
61.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)