# fold.jl # MWE of moving mesh
#
# All the paper test sheet's vertices and faces are defined
# according to the wavefront 3D object file format by the
# following six lines of text:
#=
v -2.0 0 2.0
v -2.0 0 -2.0
v 2.0 0 -2.0
v 2.0 0 2.0
f 1 2 4
f 3 4 2
=#
using GLMakie, GLMakie.FileIO
using GeometryBasics
include("ripga3d.jl")
# convert coordinate Point{3, Float32} to/from PGA point
function point(A::Point{3, Float32})::Vector{Float32}
return A[1]*e032 + A[2]*e013 + A[3]*e021 + e123
end
function toPoint(A::Vector{Float32})
return Point{3, Float32}(A[14],A[13],A[12])
end
function fold()
# initialize data
S = load("sheet.obj")
SC,SF = coordinates(S),faces(S)
S_obs = Observable(S)
# initialize figure
fig = Figure(resolution = (600, 650))
ax3d = Axis3(fig[1,1],
elevation = pi/16,
azimuth = -pi/4,
limits = (-2,2, -2,2, -2,2),
aspect = (1,1,1))
mesh!(ax3d, S_obs)
fig
# generate video of folding
nFrame = 200
PL = point(SC[2]) & point(SC[4]) # Pivot Line
SP = point(SC[1]) # Starting Point
record(fig, "fold.mp4", 1:nFrame) do iFrame
angle = pi*(1-abs(2*(iFrame-1)/nFrame-1))
R = rotor(angle, PL)
MP = R >>> SP # Moving Point
SC[1] = toPoint(MP)
S_obs[] = GeometryBasics.Mesh(SC, SF)
end # for each video frame
end # origami()
# quick and dirty ffmpeg conversion from fold.mp4 to fold.gif:
# /tool/ffmpeg-2022-07/bin/ffmpeg.exe -i fold.mp4 -r 24 -s 480x520 -loop 0 fold.gif
# /tool/ffmpeg-2022-07/bin/ffmpeg.exe -i fold.mp4 -r 24 -s 600x650 -loop 0 fold.gif
After porting several bivector.net ganja.js Projective Geometric Algebra application examples to Julia and GLMakie, I’d like to port the ganja.js origami application example which has more complex graphics than the other application examples I’ve ported. So I have a few questions:
- Can a mesh be like origami paper with a different color on the two sides of the paper?
- What is the simplest way to plot both the wireframe and the colored faces?
- Is a GLMakie mesh the best approach to animating the many folds of origami or would a GLMakie surface (or something else) be better?