MakieOrg / Makie.jl

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

3D Camera glitches with WGLMakie, not with GLMakie #3900

Open xlxs4 opened 1 month ago

xlxs4 commented 1 month ago
using Pkg

pkg"activate --temp"
pkg"add GLMakie WGLMakie"

using LinearAlgebra

# using GLMakie
using WGLMakie

function center!(translate_to, ls, cam)
    current_look_direction = normalize(cam.lookat[] - cam.eyeposition[])
    desired_distance = norm(cam.eyeposition[] - cam.lookat[])

    cam.lookat[] = translate_to
    cam.eyeposition[] = translate_to - current_look_direction * desired_distance

    Makie.update_cam!(ls.scene)
    return nothing
end

function init()
    backend = Makie.current_backend()
    backend.activate!()

    fig = Figure(; backgroundcolor=:black)

    ls = LScene(fig[1, 1]; show_axis=false)
    cam = cam3d!(ls.scene; center=false)
    vertices = [
        0.0 0.0
        1.0 0.0
        1.0 1.0
        0.0 1.0
    ]
    faces = [
        1 2 3
        3 4 1
    ]
    m = mesh!(ls, vertices, faces)
    return fig, ls, cam, m
end

fig, ls, cam, m = init()

fig

for _ in 1:1000
    pos = Vec3f(normalize(rand(Float32, 3)))
    translate!(m, pos)
    center!(pos, ls, cam)
    sleep(0.01)
end

https://github.com/MakieOrg/Makie.jl/assets/54778816/8fd9fb23-fdab-414d-b9e1-63e1adfed45f

xlxs4 commented 1 month ago

Could it be related to https://github.com/MakieOrg/Makie.jl/issues/1454?

SimonDanisch commented 1 month ago

Would it be possible to make an example, that's less glitchy in itself? 😅 It seems like the expected result is that nothing happens, even though the camera is moved? For me nothing appens in WGLMakie and GLMakie, so not sure if I'm not able to reproduce it, or if the glitch is really short. I don't really understand the example, which makes it harder to debug... Does e.g. rotating around an object glitch too?

ffreyer commented 1 month ago

Isn't this just a consequence of WGLMakie being more asynchronous? I.e. WGLMakie is processing some of the events/messages here, rendering, then processing the rest?

SimonDanisch commented 1 month ago

It could be, but that's why I want to nail down the problem, which is not that easy with this example.

xlxs4 commented 1 month ago

I understand the example isn't very helpful. I tried to make a MWE centered around the actual offending function in my code (center!). Yes, the expected result is you keep seeing exactly the same, since the camera updates to follow the mesh. Here's what actually prompted me to open the issue:

GLMakie: glmakie

WGLMakie: wglmakie

I can try to come up with a different example, but then who's to tell if the glitch there has the same cause with the one due to center!? If you have any advice on what kind of example I should come up with, do tell!

SimonDanisch commented 1 month ago

Woah that looks really cool :) I think that example shows quite clearly that it's update related... Can you try throttling the updates? Will not look nice I guess, but if the problem is that update get too many, it should at least stop stuttering

xlxs4 commented 3 weeks ago

Thanks! The stuttering is still there:

https://github.com/MakieOrg/Makie.jl/assets/54778816/840a2bb7-adc7-4088-8445-88dfd1104d74