Skip to content

Commit 273daa8

Browse files
committed
Add Makie support
1 parent 3c4c8e7 commit 273daa8

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/Manifest.toml
55
/docs/Manifest.toml
66
/docs/build/
7+
fly_animation.mp4

Project.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ version = "1.0.0-DEV"
66
[deps]
77
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
88

9+
[weakdeps]
10+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
11+
12+
[extensions]
13+
FlyThroughPathsMakieExt = "Makie"
14+
915
[compat]
16+
Makie = "0.21"
1017
StaticArrays = "1"
1118
julia = "1.10"
1219

ext/FlyThroughPathsMakieExt.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module FlyThroughPathsMakieExt
2+
3+
using FlyThroughPaths
4+
using Makie
5+
6+
function FlyThroughPaths.capture_view(cam::Camera)
7+
view = ViewState(eyeposition = cam.eyeposition[], lookat = cam.lookat[])
8+
# TODO: extract fov and upvector from cam
9+
return view
10+
end
11+
FlyThroughPaths.capture_view(scene::Scene) = capture_view(scene.camera)
12+
FlyThroughPaths.capture_view(fig::Figure) = capture_view(fig.scene)
13+
14+
function FlyThroughPaths.set_view!(cam::Camera, view::ViewState)
15+
cam.eyeposition[] = view.eyeposition
16+
cam.lookat[] = view.lookat
17+
return cam
18+
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)
21+
22+
end

test/glmakie.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# These "tests" are not run as part of CI, because installing and compiling Makie would take much of the test time.
2+
# It also adds overhead in terms of ensuring a display.
3+
# But you can run them locally.
4+
5+
using GLMakie
6+
using FlyThroughPaths
7+
using LinearAlgebra
8+
9+
# From one of the examples on https://docs.makie.org/stable
10+
r = LinRange(-1, 1, 100)
11+
cube = [(x.^2 + y.^2 + z.^2) for x = r, y = r, z = r]
12+
fig, ax, plt = contour(cube, alpha=0.5)
13+
display(fig)
14+
15+
view0 = capture_view(fig)
16+
# FIXME: workaround for not knowing how to get the upvector and fov from the camera
17+
view0 = ViewState(eyeposition=view0.eyeposition, lookat=view0.lookat, upvector=[0, 0, 1], fov=45)
18+
path = Path(view0)
19+
20+
path = path * ConstrainedMove(5, ViewState(eyeposition=[norm(view0.eyeposition), 0, 0]), :none, :constant)
21+
path = path * Pause(1)
22+
path = path * ConstrainedMove(5, ViewState(eyeposition=view0.eyeposition), :rotation, :constant)
23+
24+
tlist = range(0, stop=15, length=31)
25+
26+
record(fig, "fly_animation.mp4", tlist; framerate=round(Int, length(tlist)/last(tlist))) do t
27+
set_view!(fig, path(t))
28+
end

0 commit comments

Comments
 (0)