diff --git a/MakieCore/src/basic_plots.jl b/MakieCore/src/basic_plots.jl index 35a0c5b0aa2..8d9a589aebf 100644 --- a/MakieCore/src/basic_plots.jl +++ b/MakieCore/src/basic_plots.jl @@ -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" diff --git a/src/Makie.jl b/src/Makie.jl index 2a1545280ca..ea340894935 100644 --- a/src/Makie.jl +++ b/src/Makie.jl @@ -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") diff --git a/src/basic_recipes/mesh.jl b/src/basic_recipes/mesh.jl new file mode 100644 index 00000000000..4a8ea7fc4ed --- /dev/null +++ b/src/basic_recipes/mesh.jl @@ -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 diff --git a/src/layouting/data_limits.jl b/src/layouting/data_limits.jl index 8b50e06a1a3..ce94ea9cbff 100644 --- a/src/layouting/data_limits.jl +++ b/src/layouting/data_limits.jl @@ -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