Skip to content

Commit

Permalink
sort objects in WGL as in GLMakie, nest rectanglezoom (#4127)
Browse files Browse the repository at this point in the history
* sort objects in WGL as in GLMakie, nest rectanglezoom

* add changelog
  • Loading branch information
SimonDanisch committed Aug 13, 2024
1 parent 37619cf commit 86f47c3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion WGLMakie/src/Serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
});
}

Expand Down
5 changes: 3 additions & 2 deletions WGLMakie/src/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
13 changes: 7 additions & 6 deletions WGLMakie/src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions WGLMakie/src/wglmakie.bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/makielayout/interactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 7 additions & 4 deletions src/makielayout/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 86f47c3

Please sign in to comment.