Skip to content

Commit

Permalink
Add tests for sparse accessor without buffer view
Browse files Browse the repository at this point in the history
  • Loading branch information
derwiath committed Jan 8, 2024
1 parent c747273 commit 7983ca0
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/test_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,48 @@ fn test_sparse_accessor_with_base_buffer_view_yield_all_values() {
}
}
}

/// "box_sparse.gltf" contains an animation with a sampler with output of two values.
/// The values are specified with a sparse accessor that is missing a base `bufferView` field.
/// Which means that each value in it will be 0.0, except the values contained in the sparse
/// buffer view itself. In this case the second value is read from the sparse accessor (1.0),
/// while the first is left at the default zero.
const BOX_SPARSE_GLTF: &str = "tests/box_sparse.gltf";

#[test]
fn test_sparse_accessor_without_base_buffer_view_yield_exact_size_hints() {
let (document, buffers, _) = gltf::import(BOX_SPARSE_GLTF).unwrap();

let animation = document.animations().next().unwrap();
let sampler = animation.samplers().next().unwrap();
let output_accessor = sampler.output();
let mut outputs_iter =
gltf::accessor::Iter::<f32>::new(output_accessor, |buffer: gltf::Buffer| {
buffers.get(buffer.index()).map(|data| &data.0[..])
})
.unwrap();
const EXPECTED_OUTPUT_COUNT: usize = 2;
for i in (0..=EXPECTED_OUTPUT_COUNT).rev() {
assert_eq!(outputs_iter.size_hint(), (i, Some(i)));
outputs_iter.next();
}
}

#[test]
fn test_sparse_accessor_without_base_buffer_view_yield_all_values() {
let (document, buffers, _) = gltf::import(BOX_SPARSE_GLTF).unwrap();

let animation = document.animations().next().unwrap();
let sampler = animation.samplers().next().unwrap();
let output_accessor = sampler.output();
let output_iter = gltf::accessor::Iter::<f32>::new(output_accessor, |buffer: gltf::Buffer| {
buffers.get(buffer.index()).map(|data| &data.0[..])
})
.unwrap();
const EXPECTED_OUTPUTS: [f32; 2] = [0.0, 1.0];
let outputs = output_iter.collect::<Vec<_>>();
assert_eq!(outputs.len(), EXPECTED_OUTPUTS.len());
for (i, o) in outputs.iter().enumerate() {
assert_eq!(o - EXPECTED_OUTPUTS[i], 0.0);
}
}

0 comments on commit 7983ca0

Please sign in to comment.