From ffbc129a213595e99033c67ee08d9f2d8253d16c Mon Sep 17 00:00:00 2001 From: Daniel Oom Date: Sat, 3 Aug 2024 21:37:39 +0200 Subject: [PATCH] Allow skipping normals in obj parser --- wavefront/src/obj.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/wavefront/src/obj.rs b/wavefront/src/obj.rs index 345fe227..19ba7173 100644 --- a/wavefront/src/obj.rs +++ b/wavefront/src/obj.rs @@ -93,7 +93,7 @@ fn i32_or_zero(input: &str) -> IResult<&str, i32> { } fn point(input: &str) -> IResult<&str, Point> { - (i32, char('/'), i32_or_zero, char('/'), i32) + (i32, char('/'), i32_or_zero, char('/'), i32_or_zero) .parse(input) .map(|(input, (v, _, t, _, n))| (input, Point { v, t, n })) } @@ -199,6 +199,33 @@ mod tests { #[test] fn test_faces() { + assert_eq!( + obj_test("usemtl m1\nf 1/2/3").chunks, + [Chunk { + faces: vec![Face { + points: vec![Point { v: 1, t: 2, n: 3 },] + }], + material: "m1".to_string() + }] + ); + assert_eq!( + obj_test("usemtl m1\nf 1//3").chunks, + [Chunk { + faces: vec![Face { + points: vec![Point { v: 1, t: 0, n: 3 },] + }], + material: "m1".to_string() + }] + ); + assert_eq!( + obj_test("usemtl m1\nf 1//").chunks, + [Chunk { + faces: vec![Face { + points: vec![Point { v: 1, t: 0, n: 0 },] + }], + material: "m1".to_string() + }] + ); assert_eq!( obj_test("usemtl m1\nf 1/2/3 4/5/6 7/8/9").chunks, [Chunk {