Skip to content

Commit

Permalink
Metamesh and multi mesh loading (#4496)
Browse files Browse the repository at this point in the history
* prototype `mesh(::MetaMesh)`

* tweak default color handling

* add refimg test

* add docs

* add fallback for MetaMesh

* update CI dependencies

* try matching file without capitalization

* fix CairoMakie, WGLMakie test errors

* exclude from CairoMakie

---------

Co-authored-by: ffreyer <frederic481994@hotmail.de>
  • Loading branch information
SimonDanisch and ffreyer authored Oct 31, 2024
1 parent e34c2b7 commit 4c4d7e3
Show file tree
Hide file tree
Showing 30 changed files with 162,818 additions and 12 deletions.
1 change: 1 addition & 0 deletions CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ excludes = Set([
"Miter Joints for line rendering", # CairoMakie does not show overlap here
"Scatter with FastPixel", # almost works, but scatter + markerspace=:data seems broken for 3D
"picking", # Not implemented
"MetaMesh (Sponza)", # makes little sense without per pixel depth order
])

functions = [:volume, :volume!, :uv_mesh]
Expand Down
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
29 changes: 19 additions & 10 deletions ReferenceTests/src/tests/examples3d.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

@reference_test "mesh textured and loaded" begin
f = Figure(size = (600, 600))

moon = loadasset("moon.png")
ax, meshplot = mesh(f[1, 1], Sphere(Point3f(0), 1f0), color=moon,
ax, meshplot = mesh(f[1, 1], Sphere(Point3f(0), 1f0), color=moon,
shading=NoShading, axis = (;show_axis=false))
update_cam!(ax.scene, Vec3f(-2, 2, 2), Vec3f(0))
cameracontrols(ax).settings.center[] = false # avoid recenter on display

earth = loadasset("earth.png")
m = uv_mesh(Tesselation(Sphere(Point3f(0), 1f0), 60))
mesh(f[1, 2], m, color=earth, shading=NoShading)
Expand Down Expand Up @@ -52,7 +52,7 @@ end
r = range(-1, stop=1, length=100)
matr = [(x.^2 + y.^2 + z.^2) for x = r, y = r, z = r]
volume(f[1, 1], matr .* (matr .> 1.4), algorithm=:iso, isorange=0.05, isovalue=1.7, colorrange=(0, 1))

volume(f[1, 2], RNG.rand(32, 32, 32), algorithm=:mip)

r = LinRange(-3, 3, 100); # our value range
Expand All @@ -69,9 +69,9 @@ end
ax.scene.clear[] = true

r = range(-3pi, stop=3pi, length=100)
volume(f[2, 2], r, r, r, (x, y, z) -> cos(x) + sin(y) + cos(z),
volume(f[2, 2], r, r, r, (x, y, z) -> cos(x) + sin(y) + cos(z),
colorrange=(0, 1), algorithm=:iso, isorange=0.1f0, axis = (;show_axis=false))
volume!(r, r, r, (x, y, z) -> cos(x) + sin(y) + cos(z), algorithm=:mip,
volume!(r, r, r, (x, y, z) -> cos(x) + sin(y) + cos(z), algorithm=:mip,
colorrange=(0, 1), transformation=(translation=Vec3f(6pi, 0, 0),))

f
Expand Down Expand Up @@ -606,7 +606,7 @@ end
a = LScene(f[1, 1])
a.scene.theme[:clip_planes][] = Makie.planes(Rect3f(Point3f(-0.75), Vec3f(1.5)))
linesegments!(
a, Rect3f(Point3f(-0.75), Vec3f(1.5)), clip_planes = Plane3f[],
a, Rect3f(Point3f(-0.75), Vec3f(1.5)), clip_planes = Plane3f[],
fxaa = true, transparency = false, linewidth = 3)

p = mesh!(Sphere(Point3f(0,0,1), 1f0), transparency = false, color = :orange, backlight = 1.0)
Expand Down Expand Up @@ -665,7 +665,7 @@ end
r = -10:10
data = [1 - (1 + cos(x^2) + cos(y^2) + cos(z^2)) for x in r, y in r, z in r]
clip_planes = [Plane3f(Vec3f(-1), 0.0)]

attr = (clip_planes = clip_planes, axis = (show_axis = false,))

volume(f[1, 1], -10..10, -10..10, -10..10, data; attr...,
Expand All @@ -682,7 +682,7 @@ end
algorithm = :additive)
volume(f[2, 3], -10..10, -10..10, -10..10, data; attr...,
algorithm = :indexedabsorption)

f
end

Expand Down Expand Up @@ -710,7 +710,7 @@ end
@reference_test "volumeslices" begin
r = range(-1, 1, length = 10)
data = RNG.rand(10,10,10)

fig = Figure()
volumeslices(fig[1, 1], r, r, r, data)
a, p = volumeslices(fig[1, 2], r, r, r, data, bbox_visible = false, colormap = :RdBu,
Expand All @@ -720,3 +720,12 @@ end
p.update_xy[](10)
fig
end

@reference_test "MetaMesh (Sponza)" begin
m = load(Makie.assetpath("sponza/sponza.obj"), uvtype = Vec2f)
f, a, p = mesh(m)
cameracontrols(a).settings.center[] = false
cameracontrols(a).settings.fixed_axis[] = false # irrelevant here
update_cam!(a.scene, Vec3f(-15, 7, 1), Vec3f(3, 5, 0), Vec3f(0,1,0))
f
end
Binary file added assets/sponza/00_skap.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/01_STUB-bump.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/01_STUB.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/01_S_ba.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/01_S_kap-bump.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/01_S_kap.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/01_St_kp-bump.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/01_St_kp.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/KAMEN-bump.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/KAMEN-stup.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/KAMEN.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions assets/sponza/copyright.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
http://hdri.cgtechniques.com/~sponza/files/

Sponza modeled by Marko Dabrovic, with UVs and crack errors fixed by Kenzie Lamar at Vicarious Visions.
Bump maps painted by Morgan McGuire.

---

Downloaded from https://casual-effects.com/data/
Binary file added assets/sponza/prozor1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/reljef-bump.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/reljef.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/sp_luk-bump.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sponza/sp_luk.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4c4d7e3

Please sign in to comment.