MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.42k stars 313 forks source link

Clip values of `campixel!`, `depth_shift`, and `translate!` of 2D Scenes #2638

Open jacobleft opened 1 year ago

jacobleft commented 1 year ago

MWE and expected behaviors

According to the scenes_and_subwindows section in the docs, after drawing a 3D scene (with an outline)

using GLMakie, Makie
GLMakie.activate!()
scene = Scene(backgroundcolor=:gray)
subwindow = Scene(scene, px_area=Rect(100, 100, 200, 200), clear=false, backgroundcolor=:white)
cam3d!(subwindow)
meshscatter!(subwindow, rand(Point3f, 10), color=:gray)
center!(subwindow)
relative_space = Makie.camrelative(subwindow)
# this draws a line at the scene window boundary
lines!(relative_space, Rect(0, 0, 1, 1))

a gradient background 2D image can be added by

campixel!(scene)
w, h = size(scene) # get the size of the scene in pixels
# this draws a line at the scene window boundary
image!(scene, [sin(i/w) + cos(j/h) for i in 1:w, j in 1:h])

Then, a translation is needed to make the 2D image stay behind the 3D scene.

translate!(scene.plots[1], 0, 0, -1000)

Results

Workaround

A workaround I found is to adjust the farclip value of campixel!

campixel!(scene; farclip=1)

which gives a desired plot. image But I don't exactly know why this works.

asinghvi17 commented 1 year ago

Looks like this may be specific to GLMakie - running

using CairoMakie
scene = Scene(backgroundcolor=:gray)
subwindow = Scene(scene, px_area=Rect(100, 100, 200, 200), clear=false, backgroundcolor=:white)
cam3d!(subwindow)
meshscatter!(subwindow, rand(Point3f, 10), color=:gray)
center!(subwindow)
relative_space = Makie.camrelative(subwindow)
lines!(relative_space, Rect(0, 0, 1, 1))
campixel!(scene)
w, h = size(scene)
image!(scene, [sin(i/w) + cos(j/h) for i in 1:w, j in 1:h])

yields this iTerm2 SrFObC which seems fairly accurate.

jacobleft commented 1 year ago

In your case, the translation is unnecessary. That is also inconsistent with the docs.

ffreyer commented 2 months ago

4150 would likely change how this works (at least in GLMakie)