From 86f47c3ae92b3bc2e4c3b2489239f14dc846306a Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 13 Aug 2024 22:03:32 +0200 Subject: [PATCH] sort objects in WGL as in GLMakie, nest rectanglezoom (#4127) * sort objects in WGL as in GLMakie, nest rectanglezoom * add changelog --- CHANGELOG.md | 1 + WGLMakie/src/Serialization.js | 3 ++- WGLMakie/src/lines.jl | 5 +++-- WGLMakie/src/serialization.jl | 13 +++++++------ WGLMakie/src/wglmakie.bundled.js | 1 + src/makielayout/interactions.jl | 2 +- src/makielayout/types.jl | 11 +++++++---- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25bc9089c3e..7e6e0801c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- Fix RectangleZoom in WGLMakie [#4127](https://github.com/MakieOrg/Makie.jl/pull/4127) - Bring back fastpath for regular heatmaps [#4125](https://github.com/MakieOrg/Makie.jl/pull/4125) - Data inspector fixes (mostly for bar plots) [#4087](https://github.com/MakieOrg/Makie.jl/pull/4087) - Added "clip_planes" as a new generic plot and scene attribute. Up to 8 world space clip planes can be specified to hide sections of a plot. [#3958](https://github.com/MakieOrg/Makie.jl/pull/3958) diff --git a/WGLMakie/src/Serialization.js b/WGLMakie/src/Serialization.js index 246db53e217..44111b2cd00 100644 --- a/WGLMakie/src/Serialization.js +++ b/WGLMakie/src/Serialization.js @@ -159,6 +159,7 @@ export function deserialize_plot(scene, data) { mesh.frustumCulled = false; mesh.matrixAutoUpdate = false; mesh.plot_uuid = data.uuid; + mesh.renderOrder = data.zvalue; update_visible(data.visible.value); data.visible.on(update_visible); connect_uniforms(mesh, data.uniform_updater); @@ -453,7 +454,7 @@ function create_material(scene, program) { transparent: true, glslVersion: THREE.GLSL3, depthTest: !program.overdraw.value, - depthWrite: !program.transparency.value + depthWrite: !program.transparency.value, }); } diff --git a/WGLMakie/src/lines.jl b/WGLMakie/src/lines.jl index a2d3ca897ea..2a736316609 100644 --- a/WGLMakie/src/lines.jl +++ b/WGLMakie/src/lines.jl @@ -196,7 +196,7 @@ function serialize_three(scene::Scene, plot::Union{Lines, LineSegments}) uniforms[:num_clip_planes] = map(plot, plot.clip_planes, plot.space) do planes, space return Makie.is_data_space(space) ? length(planes) : 0 end - + uniforms[:clip_planes] = map(plot, scene.camera.projectionview, plot.clip_planes, plot.space) do pv, planes, space Makie.is_data_space(space) || return [Vec4f(0, 0, 0, -1e9) for _ in 1:8] @@ -226,7 +226,8 @@ function serialize_three(scene::Scene, plot::Union{Lines, LineSegments}) :uniform_updater => uniform_updater(plot, uniforms), :attributes => attributes, :transparency => plot.transparency, - :overdraw => plot.overdraw + :overdraw => plot.overdraw, + :zvalue => Makie.zvalue2d(plot) ) return attr end diff --git a/WGLMakie/src/serialization.jl b/WGLMakie/src/serialization.jl index ca053f5776a..70dfd1079a9 100644 --- a/WGLMakie/src/serialization.jl +++ b/WGLMakie/src/serialization.jl @@ -339,6 +339,7 @@ function serialize_three(scene::Scene, @nospecialize(plot::AbstractPlot)) mesh[:uuid] = js_uuid(plot) mesh[:transparency] = plot.transparency mesh[:overdraw] = plot.overdraw + mesh[:zvalue] = Makie.zvalue2d(plot) uniforms = mesh[:uniforms] updater = mesh[:uniform_updater] @@ -371,11 +372,11 @@ function serialize_three(scene::Scene, @nospecialize(plot::AbstractPlot)) # Handle clip planes if plot isa Voxels - + clip_planes = map( plot, plot.converted..., plot.model, plot.clip_planes, plot.space ) do xs, ys, zs, chunk, model, planes, space - + Makie.is_data_space(space) || return [Vec4f(0, 0, 0, -1e9) for _ in 1:8] # model/modelinv has no perspective projection so we should be fine @@ -393,7 +394,7 @@ function serialize_three(scene::Scene, @nospecialize(plot::AbstractPlot)) for i in 1:min(length(planes), 8) origin = modelinv * to_ndim(Point4f, planes[i].distance * planes[i].normal, 1) normal = transpose(_model) * to_ndim(Vec4f, planes[i].normal, 0) - distance = dot(Vec3f(origin[1], origin[2], origin[3]) / origin[4], + distance = dot(Vec3f(origin[1], origin[2], origin[3]) / origin[4], Vec3f(normal[1], normal[2], normal[3])) output[i] = Vec4f(normal[1], normal[2], normal[3], distance) end @@ -428,7 +429,7 @@ function serialize_three(scene::Scene, @nospecialize(plot::AbstractPlot)) for i in 1:min(length(planes), 8) origin = modelinv * to_ndim(Point4f, planes[i].distance * planes[i].normal, 1) normal = transpose(model2[]) * to_ndim(Vec4f, planes[i].normal, 0) - distance = dot(Vec3f(origin[1], origin[2], origin[3]) / origin[4], + distance = dot(Vec3f(origin[1], origin[2], origin[3]) / origin[4], Vec3f(normal[1], normal[2], normal[3])) output[i] = Vec4f(normal[1], normal[2], normal[3], distance) end @@ -466,9 +467,9 @@ function serialize_three(scene::Scene, @nospecialize(plot::AbstractPlot)) updater[] = [:clip_planes, serialize_three(value)] return end - + uniforms[:num_clip_planes] = serialize_three( - Makie.is_data_space(plot.space[]) ? length(clip_planes[]) : 0 + Makie.is_data_space(plot.space[]) ? length(clip_planes[]) : 0 ) onany(plot, plot.clip_planes, plot.space) do planes, space N = Makie.is_data_space(space) ? length(planes) : 0 diff --git a/WGLMakie/src/wglmakie.bundled.js b/WGLMakie/src/wglmakie.bundled.js index 947492410b4..4bde57cd51f 100644 --- a/WGLMakie/src/wglmakie.bundled.js +++ b/WGLMakie/src/wglmakie.bundled.js @@ -22413,6 +22413,7 @@ function deserialize_plot(scene, data) { mesh.frustumCulled = false; mesh.matrixAutoUpdate = false; mesh.plot_uuid = data.uuid; + mesh.renderOrder = data.zvalue; update_visible(data.visible.value); data.visible.on(update_visible); connect_uniforms(mesh, data.uniform_updater); diff --git a/src/makielayout/interactions.jl b/src/makielayout/interactions.jl index bffb16a16f6..cecff717b7b 100644 --- a/src/makielayout/interactions.jl +++ b/src/makielayout/interactions.jl @@ -123,7 +123,7 @@ end function _selection_vertices(ax_scene, outer, inner) _clamp(p, plow, phigh) = Point2(clamp(p[1], plow[1], phigh[1]), clamp(p[2], plow[2], phigh[2])) - proj(point) = project(ax_scene, point) .+ minimum(ax_scene.viewport[]) + proj(point) = project(ax_scene, point) transf = Makie.transform_func(ax_scene) outer = positivize(Makie.apply_transform(transf, outer)) inner = positivize(Makie.apply_transform(transf, inner)) diff --git a/src/makielayout/types.jl b/src/makielayout/types.jl index 02cbfea598c..8265d2e84ce 100644 --- a/src/makielayout/types.jl +++ b/src/makielayout/types.jl @@ -672,16 +672,19 @@ end function RectangleZoom(f::Function, ax::Axis; kw...) r = RectangleZoom(f; kw...) - selection_vertices = lift(_selection_vertices, ax.blockscene, Observable(ax.scene), ax.finallimits, + rect_scene = Scene(ax.scene) + selection_vertices = lift(_selection_vertices, rect_scene, Observable(ax.scene), ax.finallimits, r.rectnode) # manually specify correct faces for a rectangle with a rectangle hole inside faces = [1 2 5; 5 2 6; 2 3 6; 6 3 7; 3 4 7; 7 4 8; 4 1 8; 8 1 5] # plot to blockscene, so ax.scene stays exclusive for user plots # That's also why we need to pass `ax.scene` to _selection_vertices, so it can project to that space - mesh = mesh!(ax.blockscene, selection_vertices, faces, color = (:black, 0.2), shading = NoShading, - inspectable = false, visible=r.active, transparency=true) + mesh = mesh!(rect_scene, + selection_vertices, faces, space=:pixel, + color = (:black, 0.2), shading = NoShading, + inspectable = false, transparency=true, overdraw=true, visible=r.active) # translate forward so selection mesh and frame are never behind data - translate!(mesh, 0, 0, 100) + translate!(mesh, 0, 0, 1000) return r end