# GLMakie. 2D textured Plane in 3D space

**URL:** <https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668>\
**Category:** General Usage\
**Tags:** makie, glmakie\
**Created:** [October 13, 2022, 2:21pm UTC](https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668 "2022-10-13T14:21:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeN3rd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/len3rd/32/34329_2.png) [@LeN3rd](https://discourse.julialang.org/u/LeN3rd)\
**Post date:** [October 13, 2022, 2:21pm UTC](https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668/1 "2022-10-13T14:21:03Z")

</div>

This might be a stupid question, but i want to have a simple 2d textured plane that sits in 3d space, rendered with Makie. Eventually there should be more complex 3D Meshes, but for now i struggle to even get a textured plane.

Here is what i have so far:

```julia
verts = [[-1.0,-1.0,-1.0],[1.0,-1.0,-1.0], [1.0,1.0,-1.0], [-1.0,1.0,-1.0]] #These could change specifically be rotated
points = [Point3(p) for p in verts]
poly = Polygon( points)
fig = Figure(resolution = (600,600))
axs = Axis3(fig[1,1],aspect = :data)
mesh!(axs,poly)# throws error : no method matching earcut_triangulate()

```

So this method doesn’t even render a polygon. I tried with the vertices as an array and face numbers, but i seem unable to texture that mesh.

```julia
faces = [
    1 2 3;
    3 4 1;
]
verts = [-1.0;-1.0;-1.0;; 1.0;-1.0;-1.0;; 1.0;1.0;-1.0;; -1.0;1.0;-1.0]
mesh!(axs,verts, faces)

```

This does what i want, but i seem unable to put a texture on top of my plane. Any ideas what i can do? Its hard to use GeometryObject, since the documentation is nonexistent, and there seem to be no 2d Rect for 3d rendering, so id rather avoid it. If GeometryObject.jl is the only way to texture 3D objects, a better documentation would be great. It also seems weird to me, that the library essentially redefines Vectors (Points) which seems to be a bad going forward with compatibility with other Julia modules.

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [October 14, 2022, 9:06am UTC](https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668/2 "2022-10-14T09:06:54Z")

</div>

You need texture coordinates (uv) to use textures. I don’t know if those can be generated when passing vertices and faces directly, but here is how you could do it with GeometryBasics:

```julia
ps = Point3f[[-1.0,-1.0,-1.0],[1.0,-1.0,-1.0], [1.0,1.0,-1.0], [-1.0,1.0,-1.0]]
uvs = Vec2f[(0, 0), (1, 0), (1, 1), (0, 1)]
fs = GLTriangleFace[(1, 2, 3), (1, 3, 4)]
m = GeometryBasics.Mesh(meta(ps, uv = uvs, normals = normals(ps, fs)), fs)

using FileIO
img = FileIO.load(Makie.assetpath("cow.png"))

fig = Figure()
ax = Axis3(fig[1, 1])
mesh!(ax, m, color = img)

```

---

<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:** [October 14, 2022, 10:05am UTC](https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668/3 "2022-10-14T10:05:13Z")

</div>

> [@LeN3rd](#):
>
> It also seems weird to me, that the library essentially redefines Vectors (Points) which seems to be a bad going forward with compatibility with other Julia modules.

Not sure what you mean by **re** -defining since there is no Point type defined already? What’s the actual problem you have? We do reinterpret matrices with `size(verts, 1) == 3` and for other types we try to convert, since we need that memory layout for OpenGL.  
`Vector{Vector{Float}}` is a bad idea for performance, so I don’t see any reason why we should encourage that.

> Its hard to use GeometryObject, since the documentation is nonexistent,

That is true to be fair, and I’m currently trying to free some time to work on [https://github.com/JuliaGeometry/GeometryBasics.jl/pull/173](https://github.com/JuliaGeometry/GeometryBasics.jl/pull/173), which should make GeometryBasics much more intuitive and better documented.

The kind of error you’re getting in your example should also be addressed by the above PR.

I recently tried to update the docs a bit for textured meshes, but it’s definitely still not complete:  
[https://docs.makie.org/v0.18.0/examples/plotting\_functions/mesh/index.html#using\_geometrybasicsmesh\_and\_buffersampler\_type](https://docs.makie.org/v0.18.0/examples/plotting_functions/mesh/index.html#using_geometrybasicsmesh_and_buffersampler_type)

---

<div class="post-metadata">

**Author:** ![LeN3rd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/len3rd/32/34329_2.png) [@LeN3rd](https://discourse.julialang.org/u/LeN3rd)\
**Post date:** [October 14, 2022, 10:21am UTC](https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668/4 "2022-10-14T10:21:02Z")

</div>

Thanks so much, that did it.

---

<div class="post-metadata">

**Author:** ![LeN3rd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/len3rd/32/34329_2.png) [@LeN3rd](https://discourse.julialang.org/u/LeN3rd)\
**Post date:** [October 14, 2022, 10:26am UTC](https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668/5 "2022-10-14T10:26:27Z")

</div>

First of all, thanks for all the work you do. Just started with Makie and love it so far.  
If you need the Memory layout, than its fair. I just came from the perspective, that since Julia does Vectors/Matrices so good without any help from a library like numpy, it seems strange to redefine it.  
I think my main frustration was, that the documentation for GeometryBasics was lacking, when i looked at it. Some object types that might be from the deprecated older library (forgot the name) that didn’t work and no overview of all the mesh types. Keep up the good work.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 14, 2022, 11:20am UTC](https://discourse.julialang.org/t/glmakie-2d-textured-plane-in-3d-space/88668/6 "2022-10-14T11:20:45Z")

</div>

We could use just plain Julia arrays, but then you’d have to always use a matrix of floats instead of `Vector{Point}`, and then you’re never really sure which dimension was which, etc, which is an overall annoyance. We do that conversion for you where we can, but in general it’s much clearer what you mean when you use `Point`, I’d say. From a memory layout point of view, they’re the same.
