# Adding textures to rectangles using Makie

**URL:** <https://discourse.julialang.org/t/adding-textures-to-rectangles-using-makie/11465>\
**Category:** Visualization\
**Tags:** question\
**Created:** [June 6, 2018, 8:53am UTC](https://discourse.julialang.org/t/adding-textures-to-rectangles-using-makie/11465 "2018-06-06T08:53:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiangans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabiangans/32/2624_2.png) [@fabiangans](https://discourse.julialang.org/u/fabiangans)\
**Post date:** [June 6, 2018, 8:53am UTC](https://discourse.julialang.org/t/adding-textures-to-rectangles-using-makie/11465/1 "2018-06-06T08:53:08Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 6, 2018, 9:35am UTC](https://discourse.julialang.org/t/adding-textures-to-rectangles-using-makie/11465/2 "2018-06-06T09:35:28Z")

</div>

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

```nohighlight
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)

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 6, 2018, 10:45am UTC](https://discourse.julialang.org/t/adding-textures-to-rectangles-using-makie/11465/3 "2018-06-06T10:45:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fabiangans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabiangans/32/2624_2.png) [@fabiangans](https://discourse.julialang.org/u/fabiangans)\
**Post date:** [September 30, 2020, 8:43am UTC](https://discourse.julialang.org/t/adding-textures-to-rectangles-using-makie/11465/4 "2020-09-30T08:43:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 30, 2020, 8:57am UTC](https://discourse.julialang.org/t/adding-textures-to-rectangles-using-makie/11465/5 "2020-09-30T08:57:49Z")

</div>

Should be:

```nohighlight
uv_mesh(Rect(0,0,1,1))

```

And if you actually need the normals for shading:

```nohighlight
uv_normal_mesh(...)

```
