Skip to content

Commit

Permalink
Fix CairoMakie mesh overflow (#2459)
Browse files Browse the repository at this point in the history
create a new pattern for each triangle
  • Loading branch information
jkrumbiegel authored Dec 1, 2022
1 parent e77516d commit 39cc40f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,9 @@ function draw_mesh2D(scene, screen, per_face_cols, space::Symbol,
ctx = screen.context
# Priorize colors of the mesh if present
# This is a hack, which needs cleaning up in the Mesh plot type!
pattern = Cairo.CairoPatternMesh()

for (f, (c1, c2, c3)) in zip(fs, per_face_cols)
pattern = Cairo.CairoPatternMesh()
t1, t2, t3 = project_position.(scene, space, vs[f], (model,)) #triangle points
Cairo.mesh_pattern_begin_patch(pattern)

Expand All @@ -728,10 +728,11 @@ function draw_mesh2D(scene, screen, per_face_cols, space::Symbol,
mesh_pattern_set_corner_color(pattern, 2, c3)

Cairo.mesh_pattern_end_patch(pattern)
Cairo.set_source(ctx, pattern)
Cairo.close_path(ctx)
Cairo.paint(ctx)
Cairo.destroy(pattern)
end
Cairo.set_source(ctx, pattern)
Cairo.close_path(ctx)
Cairo.paint(ctx)
return nothing
end

Expand Down Expand Up @@ -857,9 +858,9 @@ function _calculate_shaded_vertexcolors(N, v, c, lightpos, ambient, diffuse, spe
end

function draw_pattern(ctx, zorder, shading, meshfaces, ts, per_face_col, ns, vs, lightpos, shininess, diffuse, ambient, specular)
pattern = Cairo.CairoPatternMesh()

for k in reverse(zorder)
pattern = Cairo.CairoPatternMesh()

f = meshfaces[k]
# avoid SizedVector through Face indexing
t1 = ts[f[1]]
Expand Down Expand Up @@ -898,10 +899,12 @@ function draw_pattern(ctx, zorder, shading, meshfaces, ts, per_face_col, ns, vs,
mesh_pattern_set_corner_color(pattern, 2, c3)

Cairo.mesh_pattern_end_patch(pattern)
Cairo.set_source(ctx, pattern)
Cairo.close_path(ctx)
Cairo.paint(ctx)
Cairo.destroy(pattern)
end
Cairo.set_source(ctx, pattern)
Cairo.close_path(ctx)
Cairo.paint(ctx)

end

################################################################################
Expand Down

0 comments on commit 39cc40f

Please sign in to comment.