use std::path::Path;
use gltforge_unity::unity_indices::UnityIndices;
const GLTF_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../.samples/Box/glTF");
#[test]
fn convert_box() {
let gltf_path = Path::new(GLTF_DIR).join("Box.gltf");
let json = std::fs::read_to_string(&gltf_path).unwrap();
let gltf = gltforge::parser::parse(&json).unwrap();
let buffers = gltforge::parser::load_buffers(&gltf, Path::new(GLTF_DIR)).unwrap();
let unity = gltforge_unity::convert::build_unity_gltf(&gltf, &buffers, "Box")
.expect("build_unity_gltf failed");
assert_eq!(unity.scene_name, "Box");
assert_eq!(unity.root_game_objects, vec![0u32]);
let node0 = unity.game_objects.get(&0).expect("node 0 missing");
assert_eq!(node0.name, "0");
assert_eq!(node0.children, vec![1u32]);
assert!(node0.mesh_indices.is_empty());
let node1 = unity.game_objects.get(&1).expect("node 1 missing");
assert_eq!(node1.name, "1");
assert!(node1.children.is_empty());
assert_eq!(node1.mesh_indices, vec![0u32]);
let mesh = unity.meshes.get(&0).expect("mesh 0 missing");
assert_eq!(mesh.name, "Mesh");
assert_eq!(mesh.vertices.len(), 24);
assert_eq!(mesh.normals.len(), 24);
assert_eq!(mesh.sub_meshes.len(), 1);
for n in &mesh.normals {
let len_sq = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
assert!((len_sq - 1.0).abs() < 1e-5, "normal not unit length: {n:?}");
}
let UnityIndices::U16(ref indices) = mesh.sub_meshes[0].indices else {
panic!("expected U16 indices for a 24-vertex mesh");
};
assert_eq!(indices.len(), 36);
}