Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Makie.mesh compatible with MultiMesh (GeometryBasics refactor) #4368

Draft
wants to merge 1 commit into
base: ff/GeometryBasics_refactor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MakieCore/src/basic_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ end

Plots a 3D or 2D mesh. Supported `mesh_object`s include `Mesh` types from [GeometryBasics.jl](https://github.com/JuliaGeometry/GeometryBasics.jl).
"""
@recipe Mesh (mesh::Union{AbstractVector{<:GeometryBasics.Mesh},GeometryBasics.Mesh},) begin
@recipe Mesh (mesh::Union{AbstractVector{<:GeometryBasics.Mesh},GeometryBasics.Mesh,GeometryBasics.MetaMesh},) begin
"Sets the color of the mesh. Can be a `Vector{<:Colorant}` for per vertex colors or a single `Colorant`. A `Matrix{<:Colorant}` can be used to color the mesh with a texture, which requires the mesh to contain texture coordinates."
color = @inherit patchcolor
"sets whether colors should be interpolated"
Expand Down
1 change: 1 addition & 0 deletions src/Makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ include("basic_recipes/datashader.jl")
include("basic_recipes/error_and_rangebars.jl")
include("basic_recipes/hvlines.jl")
include("basic_recipes/hvspan.jl")
include("basic_recipes/mesh.jl")
include("basic_recipes/pie.jl")
include("basic_recipes/poly.jl")
include("basic_recipes/scatterlines.jl")
Expand Down
48 changes: 48 additions & 0 deletions src/basic_recipes/mesh.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function plot!(p::Mesh{<: Tuple{<: GeometryBasics.MetaMesh}})
metamesh = p[1][]
meshes = GeometryBasics.split_mesh(metamesh.mesh)
names = metamesh[:material_names]

for (name, m) in zip(names, meshes)
attr = Attributes()
material = metamesh[:materials][name]

if haskey(material, "diffuse map")
try
x = material["diffuse map"]
tex = if haskey(x, "image")
x["image"]
elseif haskey(x, "filename")
FileIO.load(x["filename"])
else
fill(RGB{N0f8}(1,0,1))
end
repeat = get(x, "clamp", false) ? (:clamp_to_edge) : (:repeat)

attr[:color] = ShaderAbstractions.Sampler(tex;
x_repeat = repeat, mipmap = true,
minfilter = :linear_mipmap_linear, magfilter = :linear
)

scale = Vec2f(get(x, "scale", Vec2f(1)))
trans = Vec2f(get(x, "offset", Vec2f(0)))
attr[:uv_transform] = ((trans, scale), :mesh)
catch e
@error "Failed to load texture from material $name: " exception = e
end
end

# attr[:ambient] = get(material, "ambient", p.attributes[:ambient])
attr[:diffuse] = get(material, "diffuse", p.attributes[:diffuse])
attr[:specular] = get(material, "specular", p.attributes[:specular])
attr[:shininess] = get(material, "shininess", p.attributes[:shininess])

for k in Makie.attribute_names(Makie.Mesh)
get!(attr, k, p.attributes[k])
end

plt = mesh!(p, m; attr...)
end

return p
end
2 changes: 1 addition & 1 deletion src/layouting/data_limits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function point_iterator(plot::Text{<: Tuple{<: Union{GlyphCollection, AbstractVe
return plot.position[]
end

point_iterator(mesh::GeometryBasics.Mesh) = decompose(Point, mesh)
point_iterator(mesh::GeometryBasics.AbstractMesh) = decompose(Point, mesh)
point_iterator(plot::Mesh) = point_iterator(plot.mesh[])

# Fallback for other primitive plots, used in boundingbox
Expand Down
Loading