Skip to content

Commit

Permalink
switch rendering backend to GLMakie (#86)
Browse files Browse the repository at this point in the history
* switch rendering backend to WGLMakie

* try something

* try GLMakie instead

* rm sudo

* rm apt install

this is done permanently on the CI machine

* add DISPLAY env

* string

* more display

* up example
  • Loading branch information
baggepinnen authored Jun 24, 2024
1 parent 4a13a9c commit 3d12cab
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 86 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ jobs:
private_registry_name: JuliaSimRegistry
private_registry_uuid: 309a7822-a73e-4490-9504-7d1983f27685
- name: Install dependencies
run: julia --project=docs -e 'using Pkg;
run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs -e 'using Pkg;
ENV["DISPLAY"] = "0";
Pkg.setprotocol!(; domain = "github.com", protocol = "ssh");
Pkg.add(PackageSpec(name = "JuliaSimCompiler", url = "https://github.com/JuliaComputing/JuliaSimCompiler.jl", rev = "master"));
Pkg.develop(PackageSpec(path=pwd()));
Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
run: julia --project=docs/ docs/make.jl
run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs/ docs/make.jl
130 changes: 65 additions & 65 deletions docs/Manifest.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
JuliaSimCompiler = "8391cb6b-4921-5777-4e45-fd9aab8cb88d"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Expand Down
4 changes: 3 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Multibody
using Documenter
using CairoMakie
using GLMakie
GLMakie.activate!()

ENV["JULIA_DEBUG"]=Documenter # Enable this for debugging
ENV["DOCS_BUILD"] = true # used to lower the default frame rate in animations for the docs

Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/free_motion.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ plot(sol, idxs = [body.r_0...])
```

```@example FREE_MOTION
import CairoMakie
import GLMakie
Multibody.render(model, sol, filename = "free_body.gif")
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/gyroscopic_effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using Test # hide
@test sol(5, idxs=collect(model.body2.r_0[1:3])) ≈ [-0.0357364, -0.188245, 0.02076935] atol=1e-3 # hide
# plot(sol, idxs=collect(model.body2.r_0)) # hide
import CairoMakie
import GLMakie
Multibody.render(model, sol; x=1, z=1, filename = "gyro.gif") # Use "gyro.mp4" for a video file
nothing # hide
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/kinematic_loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ using Test
Multibody.jl supports automatic 3D rendering of mechanisms, we use this feature to illustrate the result of the simulation below:

```@example kinloop
import CairoMakie
import GLMakie
Multibody.render(fourbar, sol, 0:0.05:10; x=4, y=-1, z=4, lookat=[0, -1, 0], filename = "fourbar.gif") # Use "fourbar.mp4" for a video file
nothing # hide
```
Expand Down Expand Up @@ -136,7 +136,7 @@ plot(sol, idxs=[j2.s]) # Plot the joint coordinate of the prismatic joint (green
```

```@example kinloop
import CairoMakie
import GLMakie
Multibody.render(fourbar2, sol; x=-2, y = 2, z = 3, filename = "fourbar2.gif") # Use "fourbar2.mp4" for a video file
nothing # hide
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/pendulum.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The solution `sol` can be plotted directly if the Plots package is loaded. The f
Multibody.jl supports automatic 3D rendering of mechanisms, we use this feature to illustrate the result of the simulation below:

```@example pendulum
import CairoMakie # GLMakie is another alternative, suitable for interactive plots
import GLMakie # GLMakie is another alternative, suitable for interactive plots
Multibody.render(model, sol; filename = "pendulum.gif") # Use "pendulum.mp4" for a video file
nothing # hide
```
Expand Down Expand Up @@ -226,7 +226,7 @@ plot(sol, layout=4)
```

```@example pendulum
import CairoMakie
import GLMakie
Multibody.render(model, sol, filename = "furuta.gif")
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/robot.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ plot(sol, idxs = [
Multibody.jl supports automatic 3D rendering of mechanisms, we use this feature to illustrate the result of the simulation below:

```@example robot
import CairoMakie
import GLMakie
Multibody.render(robot, sol; y=2, lookat=[0,1,0], filename = "robot.gif")
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/ropes_and_cables.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ prob = ODEProblem(ssys, [], (0, 5))
sol = solve(prob, Rodas4(autodiff=false))
@test SciMLBase.successful_retcode(sol)
import CairoMakie
import GLMakie
Multibody.render(stiff_rope, sol, filename = "stiff_rope.gif") # May take long time for n>=10
```
![stiff_rope animation](stiff_rope.gif)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ plot(sol)


```@example SPACE
import CairoMakie
import GLMakie
Multibody.render(model, sol, filename = "space.gif")
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/spherical_pendulum.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ plot(sol, idxs = [body.r_0...])
Multibody.jl supports automatic 3D rendering of mechanisms, we use this feature to illustrate the result of the simulation below:

```@example spring_mass_system
import CairoMakie
import GLMakie
Multibody.render(model, sol; filename = "spherical.gif") # Use "spherical.mp4" for a video file
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/spring_damper_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ In this example we used separate springs and dampers, see also the component [`S
Multibody.jl supports automatic 3D rendering of mechanisms, we use this feature to illustrate the result of the simulation below:

```@example spring_damper_system
import CairoMakie
import GLMakie
Multibody.render(model, sol; filename = "springdamper.gif")
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/spring_mass_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The plot indicates that the two systems behave identically.
Multibody.jl supports automatic 3D rendering of mechanisms, we use this feature to illustrate the result of the simulation below:

```@example spring_mass_system
import CairoMakie
import GLMakie
Multibody.render(model, sol; x=5, z = 5, filename = "springmass.gif")
nothing # hide
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/swing.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sol = solve(prob, ImplicitEuler(autodiff=false), reltol=5e-3)
```

```@example SWING
import CairoMakie
import GLMakie
Multibody.render(model, sol; z = -5, filename = "simple_swing.gif") # Use "simple_swing.mp4" for a video file
nothing # hide
```
Expand Down Expand Up @@ -155,7 +155,7 @@ Plots.plot(sol, idxs = [collect(model.body.r_0);])
```

```@example SWING
import CairoMakie
import GLMakie
Multibody.render(model, sol; y = -1, z = -3, lookat = [0, -1, 0], filename = "swing.gif") # Use "swing.mp4" for a video file
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/three_springs.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Plots.plot(sol, idxs = [body1.r_0...])
Multibody.jl supports automatic 3D rendering of mechanisms, we use this feature to illustrate the result of the simulation below:

```@example spring_mass_system
import CairoMakie
import GLMakie
Multibody.render(model, sol; filename = "three_springs.gif") # Use "three_springs.mp4" for a video file
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ prob = ODEProblem(ssys, [], (0.0, 3.51))
sol = solve(prob, Rodas5P())
Plots.plot(sol)
import CairoMakie
import GLMakie
framerate = 30
timevec = [zeros(30); range(sol.t[1], sol.t[end], step=1/framerate)] |> reverse
render(logo, sol, timevec; z=-2.5, x=0, y=-0.5, lookat=[0.2,-0.5, 0], filename="JuliaSim_logo.gif", framerate)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ or
using CairoMakie
```
!!! note "Backend choice"
GLMakie produces much nicer-looking animations and is also significantly faster. CairoMakie is used to produce the graphics in the documentation due to the constraints imposed by the web environment. CairoMakie also struggles with the Z-order of drawn objects, sometimes making bodies that should have been visible hidden behind bodies that are further back in the scene.
GLMakie and WGLMakie produce much nicer-looking animations and is also significantly faster than CairoMakie. CairoMakie may be used to produce the graphics in some web environments if constraints imposed by the web environment do not allow any of the GL alternatives. CairoMakie struggles with the Z-order of drawn objects, sometimes making bodies that should have been visible hidden behind bodies that are further back in the scene.

After that, the [`render`](@ref) function is the main entry point to create 3D renderings. This function has the following methods:

Expand Down

0 comments on commit 3d12cab

Please sign in to comment.