Skip to content

Commit 9f156f0

Browse files
authored
Get the Makie integration working (#3)
- Act on the axis, not the scene - Capture the camera via `cameracontrols` - Update using `update_cam!` - Operate on axis not figure in the example - Remove outdated comments
1 parent 273daa8 commit 9f156f0

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

ext/FlyThroughPathsMakieExt.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ module FlyThroughPathsMakieExt
33
using FlyThroughPaths
44
using Makie
55

6-
function FlyThroughPaths.capture_view(cam::Camera)
7-
view = ViewState(eyeposition = cam.eyeposition[], lookat = cam.lookat[])
8-
# TODO: extract fov and upvector from cam
6+
function FlyThroughPaths.capture_view(cam::Camera3D)
7+
view = ViewState(eyeposition = cam.eyeposition[], lookat = cam.lookat[], fov = cam.fov[], upvector = cam.upvector[])
98
return view
109
end
11-
FlyThroughPaths.capture_view(scene::Scene) = capture_view(scene.camera)
12-
FlyThroughPaths.capture_view(fig::Figure) = capture_view(fig.scene)
10+
FlyThroughPaths.capture_view(scene::Scene) = capture_view(cameracontrols(scene))
11+
FlyThroughPaths.capture_view(axis::Makie.AbstractAxis) = capture_view(axis.scene) # by convention, all axes have a `ax.scene` that holds the scene with content
1312

14-
function FlyThroughPaths.set_view!(cam::Camera, view::ViewState)
15-
cam.eyeposition[] = view.eyeposition
16-
cam.lookat[] = view.lookat
17-
return cam
13+
function FlyThroughPaths.set_view!(scene::Scene, view::ViewState)
14+
Makie.update_cam!(scene, view.eyeposition, view.lookat, view.upvector)
15+
cameracontrols(scene).fov[] = view.fov[]
16+
return scene
1817
end
19-
FlyThroughPaths.set_view!(scene::Scene, view::ViewState) = set_view!(scene.camera, view)
20-
FlyThroughPaths.set_view!(fig::Figure, view::ViewState) = set_view!(fig.scene, view)
18+
19+
FlyThroughPaths.set_view!(axis::Makie.AbstractAxis, view::ViewState) = set_view!(axis.scene, view)
2120

2221
end

test/glmakie.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cube = [(x.^2 + y.^2 + z.^2) for x = r, y = r, z = r]
1212
fig, ax, plt = contour(cube, alpha=0.5)
1313
display(fig)
1414

15-
view0 = capture_view(fig)
15+
view0 = capture_view(ax)
1616
# FIXME: workaround for not knowing how to get the upvector and fov from the camera
1717
view0 = ViewState(eyeposition=view0.eyeposition, lookat=view0.lookat, upvector=[0, 0, 1], fov=45)
1818
path = Path(view0)
@@ -24,5 +24,5 @@ path = path * ConstrainedMove(5, ViewState(eyeposition=view0.eyeposition), :rota
2424
tlist = range(0, stop=15, length=31)
2525

2626
record(fig, "fly_animation.mp4", tlist; framerate=round(Int, length(tlist)/last(tlist))) do t
27-
set_view!(fig, path(t))
27+
set_view!(ax, path(t))
2828
end

0 commit comments

Comments
 (0)