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