diff --git a/crates/formats/src/mesh_import/abc/mod.rs b/crates/formats/src/mesh_import/abc/mod.rs index fd9a7f46..5a19982c 100644 --- a/crates/formats/src/mesh_import/abc/mod.rs +++ b/crates/formats/src/mesh_import/abc/mod.rs @@ -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(), }) diff --git a/crates/formats/src/mesh_import/abc/tests.rs b/crates/formats/src/mesh_import/abc/tests.rs index dfba3ba9..fecb0623 100644 --- a/crates/formats/src/mesh_import/abc/tests.rs +++ b/crates/formats/src/mesh_import/abc/tests.rs @@ -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 = [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 = [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();