Skip to content

Commit

Permalink
fix updates for multiple meshes (#2277)
Browse files Browse the repository at this point in the history
* fix updates for multiple meshes

* add tests

* Update updating.jl
  • Loading branch information
SimonDanisch committed Sep 16, 2022
1 parent c64033b commit 1e50cba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
4 changes: 1 addition & 3 deletions GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,7 @@ function mesh_inner(shader_cache, mesh, transfunc, gl_attributes)
gl_attributes[:image] = Texture(const_lift(el32convert, color), minfilter = interp)
gl_attributes[:color] = nothing
elseif to_value(color) isa AbstractVector{<: Union{Number, Colorant}}
mesh = lift(mesh, color) do mesh, color
return GeometryBasics.pointmeta(mesh, color=el32convert(color))
end
gl_attributes[:vertex_color] = lift(el32convert, color)
else
error("Unsupported color type: $(typeof(to_value(color)))")
end
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/glshaders/mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function draw_mesh(shader_cache, @nospecialize(mesh), data::Dict)
@gen_defaults! data begin
shading = true
backlight = 0f0
vertex_color = nothing
vertex_color = nothing => GLBuffer
texturecoordinates = Vec2f(0)
image = nothing => Texture
matcap = nothing => Texture
Expand Down
3 changes: 3 additions & 0 deletions ReferenceTests/src/tests/refimages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ end
@testset "figures_and_makielayout.jl" begin
include("figures_and_makielayout.jl")
end
@testset "updating_plots" begin
include("updating.jl")
end
42 changes: 42 additions & 0 deletions ReferenceTests/src/tests/updating.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using ReferenceTests
@reference_test "updating 2d primitives" begin
fig = Figure()
t = Observable(1)
text(fig[1, 1], lift(i-> map(j-> ("$j", Point2f(j*30, 0)), 1:i), t), axis=(limits=(0, 380, -10, 10),), textsize=50)
scatter(fig[1, 2], lift(i-> Point2f.((1:i).*30, 0), t), axis=(limits=(0, 330, -10, 10),), markersize=50)
linesegments(fig[2, 1], lift(i-> Point2f.((2:2:4i).*30, 0), t), axis=(limits=(30, 650, -10, 10),), linewidth=20)
lines(fig[2, 2], lift(i-> Point2f.((2:2:4i).*30, 0), t), axis=(limits=(30, 650, -10, 10),), linewidth=20)

st = Stepper(fig)

foreach(1:5) do i
t[] = i
Makie.step!(st)
end

foreach(5:-1:1) do i
t[] = i
Makie.step!(st)
end
st
end

@reference_test "updating multiple meshes" begin
points = Observable(Point3f[(1,0,0), (0,1,0), (0,0,1)])

meshes = map(p->Makie.normal_mesh(Sphere(p, 0.2)), points[])
colors = map(p->RGBf(normalize(p)...), points[])

fig, ax, pl = mesh(meshes; color = colors)
st = Stepper(fig)
Makie.step!(st)
on(points) do pts
pl[1].val = map(p->Makie.normal_mesh(Sphere(p, 0.2)), points[])
pl.color.val = map(p->RGBf(normalize(p)...), points[])
notify(pl[1])
end

append!(points[], Point3f[(0,1,1), (1,0,1), (1,1,0)])
notify(points)
Makie.step!(st)
end
1 change: 0 additions & 1 deletion src/basic_recipes/contourf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ function Makie.plot!(c::Contourf{<:Tuple{<:AbstractVector{<:Real}, <:AbstractVec
highs = levels[2:end]

nbands = length(lows)

# zs needs to be transposed to match rest of makie
isos = Isoband.isobands(xs, ys, zs', lows, highs)

Expand Down
2 changes: 1 addition & 1 deletion src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ function to_color(p::Palette)
end

to_color(c::Nothing) = c # for when color is not used
to_color(c::Number) = Float32(c)
to_color(c::Real) = Float32(c)
to_color(c::Colorant) = convert(RGBA{Float32}, c)
to_color(c::Symbol) = to_color(string(c))
to_color(c::String) = parse(RGBA{Float32}, c)
Expand Down

0 comments on commit 1e50cba

Please sign in to comment.