mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-22 15:30:46 +01:00
Decode half-float Alembic properties
This commit is contained in:
1 parent
b982d66008
commit
afec77f5b2
2 files changed
+34
-1
No files matched your search
@@ -217,7 +217,7 @@ impl<'a> Ogawa<'a> {
|
||||
|
||||
let value_bytes = match property.pod {
|
||||
0..=2 => 1,
|
||||
3 | 4 => 2,
|
||||
3 | 4 | 9 => 2,
|
||||
5 | 6 | 10 => 4,
|
||||
7 | 8 | 11 => 8,
|
||||
other => return Err(FormatError::Unsupported(format!("Alembic property \"{}\" of data type {other}", property.name))),
|
||||
@@ -233,6 +233,7 @@ impl<'a> Ogawa<'a> {
|
||||
6 => raw.as_chunks::<4>().0.iter().map(|c| i32::from_le_bytes(*c) as f64).collect(),
|
||||
7 => raw.as_chunks::<8>().0.iter().map(|c| u64::from_le_bytes(*c) as f64).collect(),
|
||||
8 => raw.as_chunks::<8>().0.iter().map(|c| i64::from_le_bytes(*c) as f64).collect(),
|
||||
9 => raw.as_chunks::<2>().0.iter().map(|c| half::f16::from_bits(u16::from_le_bytes(*c)).to_f64()).collect(),
|
||||
10 => raw.as_chunks::<4>().0.iter().map(|c| f32::from_le_bytes(*c) as f64).collect(),
|
||||
_ => raw.as_chunks::<8>().0.iter().map(|c| f64::from_le_bytes(*c)).collect(),
|
||||
})
|
||||
|
||||
@@ -243,6 +243,38 @@ fn strip_alone_keeps_uvs_flipped_to_v_down() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn half_float_uvs_import_without_losing_values() {
|
||||
let mut a = Abc { w: Writer::new() };
|
||||
let pp = a.array("P", "", F32, 3, &f32s(&[0.0, 0.0, 0.0, 0.5, 1.0, 0.0, 1.0, 0.0, 0.0]));
|
||||
let fi = a.array(".faceIndices", "", I32, 1, &i32s(&[0, 1, 2]));
|
||||
let fc = a.array(".faceCounts", "", I32, 1, &i32s(&[3]));
|
||||
let uv_bytes: Vec<u8> = [0u16, 0, 0x3800, 0x3c00, 0x3c00, 0].iter().flat_map(|x| x.to_le_bytes()).collect();
|
||||
let uv = a.array("uv", "", 9, 2, &uv_bytes);
|
||||
let geom = a.compound(".geom", "schema=AbcGeom_PolyMesh_v1", vec![pp, fi, fc, uv]);
|
||||
let mesh = a.object(vec![geom], &[]);
|
||||
let top = a.object(vec![], &[("m", "", mesh)]);
|
||||
let imported = crate::import_mesh_bytes("m.abc", &a.archive(top, &["schema=AbcGeom_PolyMesh_v1"])).unwrap();
|
||||
assert!(!imported.report.uvs_generated);
|
||||
for (p, uv) in imported.mesh.positions.iter().zip(&imported.mesh.uvs) {
|
||||
assert_eq!(*uv, texturecraft_geom::glam::Vec2::new(p.x, 1.0 - p.y));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn half_float_values_preserve_special_values() {
|
||||
let mut a = Abc { w: Writer::new() };
|
||||
let raw: Vec<u8> = [0xc000u16, 0x0001, 0x7c00, 0x7e00].iter().flat_map(|x| x.to_le_bytes()).collect();
|
||||
let p = a.array("values", "", 9, 1, &raw);
|
||||
let property = Prop { name: p.name.into(), meta: p.meta, kind: PropKind::Array, pod: 9, extent: 1, group: p.group };
|
||||
let mut ogawa = Ogawa { b: &a.w.b, budget: MAX_DECODED_BYTES, indexed_meta: Vec::new() };
|
||||
let values = ogawa.values(&property).unwrap();
|
||||
assert_eq!(values[0], -2.0);
|
||||
assert_eq!(values[1], 2f64.powi(-24));
|
||||
assert_eq!(values[2], f64::INFINITY);
|
||||
assert!(values[3].is_nan());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hdf5_and_garbage_are_clear_errors() {
|
||||
let e = read(b"\x89HDF\r\n\x1a\n rest of an hdf5 file").err().unwrap().to_string();
|
||||
|
||||
Reference in new issue
Block a user