Adding textures to rectangles using Makie

I want to create a number of textured (rotated) rectangles where the 3D corner coordinates are given in a single plot using Makie.jl or GLVizualize. I want a plot similar to this example where the earth image is plotted onto the sphere here https://gist.github.com/SimonDanisch/8f5489cffaf6b89c9a3712ba3eb12a84 , but this time the images should be plotted these rectangles.

I tried adding a texture to either a HyperRectangle or a Polygon types from the GeomtryTypes package, but don;t really understand how these interact with the different mesh types etc, so an MWE that produces such a plot would be super helpful.

I had to add a fix, but this should work on latest master of Makie:

using Makie, GeometryTypes, Colors
scene = Scene()
doge = GLVisualize.loadasset("doge.png")
# For rectangles + rotation
scatter(
    Point3f0[(1,0,0), (0,1,0), (0,0,1)],
    marker = [doge, doge, doge],
    # rotation around axis... can use Vec4f0(...) for a quaternion directly
    rotations = [(Vec3f0(0, 1, 0), 0.5pi), (Vec3f0(1, 0, 0), -0.5pi), (Vec3f0(0, 0, 1), -1.2pi)]
)

# for more control:
scene = Scene(resolution = (500, 500))
mesh = GLNormalUVMesh(SimpleRectangle(0, 0, 1, 1))
# note, you can change the mesh.vertices to arbitrary values
Makie.mesh(mesh, color = doge, shading = false)
center!(scene)
1 Like

woops, didn’t noticed that the push didn’t go through! Should be pushed now:
https://github.com/JuliaPlots/Makie.jl/commit/43ec07daa0b4d84c53b2b58ace0262064cf47c7e

2 Likes

Thanks a lot for the solution, I just realized I never replied here, it worked very well. However, I wanted to re-do my plots with a recent Makie and the code does not run with the new GeometryTypes anymore (no SimpleRectangle).

So, what would be the way in current Makie to create a struct like this mesh = GLNormalUVMesh(SimpleRectangle(0, 0, 1, 1)) where I can manipulate vertices and afterwards plot it with Makie.mesh and adding a textured image?

Should be:

uv_mesh(Rect(0,0,1,1))

And if you actually need the normals for shading:

uv_normal_mesh(...)
2 Likes