# Makie show image on surface

**URL:** <https://discourse.julialang.org/t/makie-show-image-on-surface/126893>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [March 13, 2025, 1:55am UTC](https://discourse.julialang.org/t/makie-show-image-on-surface/126893 "2025-03-13T01:55:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)\
**Post date:** [March 13, 2025, 1:55am UTC](https://discourse.julialang.org/t/makie-show-image-on-surface/126893/1 "2025-03-13T01:55:36Z")

</div>

I’m trying to display images as posters around a 3D environment using GLMakie. For that purpose, I wrote the following code

```julia
using Makie
using GeometryBasics
using FileIO

struct Sprite{T<:RGB,T2<:Integer,T3<:Point3, T4<:Point2,T5<:Vec3}
    points::Vector{T3}
    faces::Vector{TriangleFace{T2}}
    normals::Vector{T5}
    uv::Vector{T4}
    img::Matrix{T}
end

"""
Map `img` onto a flat 3D surface
"""
function sprite(img,rect=Rect2(-0.5, -0.5, 1.0, 1.0))
    points = decompose(Point3f, rect)
    normals = decompose(GeometryBasics.Normal(Vec3f), rect)
    faces = decompose(GLTriangleFace, rect)
    uv = decompose(UV(Point2f), rect)

    Sprite(points, faces, normals, uv, img)
end

function Makie.convert_arguments(::Type{<:AbstractPlot}, sp::Sprite)
    gb_mesh = GeometryBasics.Mesh(sp.points, sp.faces; uv = sp.uv, normal =sp.normals) # this does not error, but I can't see the image
    # gb_mesh = GeometryBasics.Mesh(GeometryBasics.meta(sp.points; uv=sp.uv, sp.normals), sp.faces) # this used to work, but now errors.
    PlotSpec(Makie.Mesh, gb_mesh,color=sp.img)
end

```

When I call the plot function on a Sprite object, I used to see the image projected onto a 3D surface, that I could then rotate and place around my environment. However, in the latest version of Makie, I no longer see the image. In fact, the commented line in the plot function produces an error, and when I replace it with the previous line, I do not see the image, but just a beige looking rectangle.

```julia
img = FileIO.load("camel.png")
sp = Sprite(mg, Rect2(-1.25, -2.5/1.2/2, 2.5, 2.5/1.2))
plot(sp)

```

 ![testimage](https://global.discourse-cdn.com/julialang/original/3X/9/1/9120143f9f13fc794f15f31c0bce32b6e6790771.png)

What is the proper way of creating such orientable sprites in GLMakie? The test image “camel.png” can be downloaded from here: [Hippocampus.jl/artefacts/camel 1.png at 0ebdc6d5a12eaa01efe4052b99ef54dceaa0b41f · grero/Hippocampus.jl · GitHub](https://github.com/grero/Hippocampus.jl/blob/0ebdc6d5a12eaa01efe4052b99ef54dceaa0b41f/artefacts/camel%201.png)

---

<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:** [March 13, 2025, 7:10am UTC](https://discourse.julialang.org/t/makie-show-image-on-surface/126893/2 "2025-03-13T07:10:25Z")

</div>

@ffreyer did something change about uvs?

---

<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:** [March 13, 2025, 10:17am UTC](https://discourse.julialang.org/t/makie-show-image-on-surface/126893/3 "2025-03-13T10:17:48Z")

</div>

I’m not sure why this has changed, but it seems if you use Point2f for `uv`, it just silently skips them.

So this fixes it for me: `uv=Vec2f.(sp.uv)`.  
Worth opening an issue!

---

<div class="post-metadata">

**Author:** ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)\
**Post date:** [March 13, 2025, 1:52pm UTC](https://discourse.julialang.org/t/makie-show-image-on-surface/126893/4 "2025-03-13T13:52:56Z")

</div>

Hm, I still don’t see the image. Could it be a version issue? I’m using GLMakie version v0.22.2?

This is the update plot function, for reference

```julia
function Makie.convert_arguments(::Type{<:AbstractPlot}, sp::Sprite)
    gb_mesh = GeometryBasics.Mesh(sp.points, sp.faces; uv = Vec2f.(sp.uv), normal =sp.normals)
    PlotSpec(Makie.Mesh, gb_mesh,color=sp.img)
end

```

---

<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:** [March 13, 2025, 2:19pm UTC](https://discourse.julialang.org/t/makie-show-image-on-surface/126893/5 "2025-03-13T14:19:51Z")

</div>

I’m on 0.22.2 and this works:

```julia
using Makie
using GeometryBasics
using Colors 

struct Sprite{T<:RGB,T2<:Integer,T3<:Point3,T5<:Vec3}
    points::Vector{T3}
    faces::Vector{TriangleFace{T2}}
    normals::Vector{T5}
    uv::Vector{Vec2f}
    img::Matrix{T}
end

"""
Map `img` onto a flat 3D surface
"""
function sprite(img, rect=Rect2(-0.5, -0.5, 1.0, 1.0))
    points = decompose(Point3f, rect)
    normals = decompose(GeometryBasics.Normal(Vec3f), rect)
    faces = decompose(GLTriangleFace, rect)
    uv = decompose(UV(Vec2f), rect)
    Sprite(points, faces, normals, uv, img)
end

function Makie.convert_arguments(::Type{<:AbstractPlot}, sp::Sprite)
    gb_mesh = GeometryBasics.Mesh(sp.points, sp.faces; uv=sp.uv, normal=sp.normals) # this does not error, but I can't see the image
    # gb_mesh = GeometryBasics.Mesh(GeometryBasics.meta(sp.points; uv=sp.uv, sp.normals), sp.faces) # this used to work, but now errors.
    PlotSpec(Makie.Mesh, gb_mesh, color=sp.img)
end

plot(sprite(rand(RGBf, 100, 100)))

```

---

<div class="post-metadata">

**Author:** ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)\
**Post date:** [March 14, 2025, 12:33am UTC](https://discourse.julialang.org/t/makie-show-image-on-surface/126893/6 "2025-03-14T00:33:59Z")

</div>

Thanks Simon, indeed it does work! I probably didn’t clear my workspace properly or something just now.
