From 887738747cd864d66c11d5cc16eb093f51120edf Mon Sep 17 00:00:00 2001 From: ffreyer Date: Sat, 8 Oct 2022 08:26:55 +0200 Subject: [PATCH 1/2] fix Rect3 uv coordinates --- src/primitives/rectangles.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/primitives/rectangles.jl b/src/primitives/rectangles.jl index 28a7dd5d..494571a6 100644 --- a/src/primitives/rectangles.jl +++ b/src/primitives/rectangles.jl @@ -553,7 +553,17 @@ function coordinates(rect::Rect3) end function texturecoordinates(rect::Rect3) - return coordinates(Rect3(0, 0, 0, 1, 1, 1)) + # compatible with a texture ordered: + # [+x +y +z; -x -y -z] + uvs = map(v -> v ./ (3, 2), Vec{2, Float32}[ + (2, 0), (2, 1), (3, 1), (3, 0), + (1, 0), (1, 1), (2, 1), (2, 0), + (0, 0), (0, 1), (1, 1), (1, 0), + (2, 1), (2, 2), (3, 2), (3, 1), + (0, 1), (0, 2), (1, 2), (1, 1), + (1, 1), (1, 2), (2, 2), (2, 1), + ]) + return uvs end function faces(rect::Rect3) From b620832bff736b771214a8a9eaead3f36ac01183 Mon Sep 17 00:00:00 2001 From: ffreyer Date: Mon, 17 Oct 2022 14:20:51 +0200 Subject: [PATCH 2/2] fix test failure --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index d3369239..4d76db4e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -495,7 +495,7 @@ end r2 = Rect2(0.0, 0.0, 1.0, 1.0) @test collect(texturecoordinates(r2)) == [(0.0, 1.0), (1.0, 1.0), (0.0, 0.0), (1.0, 0.0)] r3 = Rect3(0.0, 0.0, 1.0, 1.0, 2.0, 2.0) - @test first(texturecoordinates(r3)) == Vec3(0, 0, 0) + @test collect(texturecoordinates(r3)) ≈ [[0.6666667, 0.0], [0.6666667, 0.5], [1.0, 0.5], [1.0, 0.0], [0.33333334, 0.0], [0.33333334, 0.5], [0.6666667, 0.5], [0.6666667, 0.0], [0.0, 0.0], [0.0, 0.5], [0.33333334, 0.5], [0.33333334, 0.0], [0.6666667, 0.5], [0.6666667, 1.0], [1.0, 1.0], [1.0, 0.5], [0.0, 0.5], [0.0, 1.0], [0.33333334, 1.0], [0.33333334, 0.5], [0.33333334, 0.5], [0.33333334, 1.0], [0.6666667, 1.0], [0.6666667, 0.5]] uv = decompose_uv(m) @test Rect(Point.(uv)) == Rect(0, 0, 1, 1)