GLMakie 中 3D 绘图的动画旋转

问题描述 投票:0回答:1

使用 GLMakie,我想增量旋转 3D 绘图,保存结果的动画。

每一帧都应将绘图旋转一个小角度(例如 1 度)。在动画过程中,情节应旋转 360 度。

这是我的意思的视频示例(ish):https://imgur.com/a/ggTCVVm

这是我目前拥有的:

using GLMakie

xs = -10:0.5:10
ys = -10:0.5:10
zs = [cos(x) * sin(y) for x in xs, y in ys]

# Explicitly create figure and axes - is this necessary?
fig = GLMakie.Figure()
ax = GLMakie.Axis3(fig[1, 1])
Makie.surface!(xs, ys, zs)
camera = Makie.cam3d!(fig.scene) # Ensure we have a 3D camera - is this necessary?

N_camera_steps = 100

GLMakie.record(
    fig,
    "test.mp4",
    [2π/N_camera_steps for _ = 1:N_camera_steps];
    framerate = 30,
) do angle 
    GLMakie.rotate_cam!(fig.scene, camera, (angle, 0, 0)) # Only rotate about one axis
end

但是,这会生成仅显示静态图的 .mp4。

我可能会误解这有多复杂 - 我没有真正考虑参考系,或者我是否应该尝试旋转相机或情节。

如何在 GLMakie 中达到我想要的结果?

plot 3d julia makie.jl
1个回答
0
投票

在 GLMakie Slack 上询问后,我想出了以下解决方案:

using GLMakie

xs = -10:0.5:10
ys = -10:0.5:10
zs = [cos(x) * sin(y) for x in xs, y in ys]

fig = GLMakie.Figure()
ax = GLMakie.Axis3(fig[1, 1])
Makie.surface!(xs, ys, zs)

start_angle = π / 4
n_frames = 120
ax.viewmode = :fit # Prevent axis from resizing during animation
record(fig, "test.mp4", 1:n_frames) do frame
    ax.azimuth[] = start_angle + 2pi * frame / n_frames
end

我发现显式创建轴和图形是必要的,因为我无法弄清楚如何从调用

surface
中获取轴和图形对象。

关键是修改ax.aximuth变量。

© www.soinside.com 2019 - 2024. All rights reserved.