Skip to content

Commit 42825b6

Browse files
committed
do less work
1 parent f17016c commit 42825b6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

ext/Render.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,11 @@ end
332332
render!(scene, ::Any, args...) = false # Fallback for systems that have no rendering
333333

334334
function render!(scene, ::typeof(Body), sys, sol, t)
335-
sol(sol.t[1], idxs=sys.render)==true || return true # yes, == true
335+
render, radius, length_fraction, cylinder_radius = sol(sol.t[1], idxs=[sys.render, sys.radius, sys.length_fraction, sys.cylinder_radius]) .|> Float32
336+
render==true || return true # yes, == true
336337
color = get_color(sys, sol, :purple)
337338
r_cm = get_fun(sol, collect(sys.r_cm))
338339
framefun = get_frame_fun(sol, sys.frame_a)
339-
radius = sol(sol.t[1], idxs=sys.radius) |> Float32
340-
length_fraction = sol(sol.t[1], idxs=sys.length_fraction) |> Float32
341-
cylinder_radius = sol(sol.t[1], idxs=sys.cylinder_radius) |> Float32
342340
thing = @lift begin # Sphere
343341
Ta = framefun($t)
344342
coords = (Ta*[r_cm($t); 1])[1:3] # TODO: make use of a proper transformation library instead of rolling own?
@@ -504,8 +502,6 @@ end
504502
function render!(scene, ::typeof(BodyShape), sys, sol, t)
505503
color = get_color(sys, sol, :purple)
506504
shapepath = get_shape(sys, sol)
507-
Tshape = reshape(sol(sol.t[1], idxs=sys.shape_transform), 4, 4)
508-
scale = Vec3f(Float32(sol(sol.t[1], idxs=sys.shape_scale))*ones(Float32, 3))
509505
if isempty(shapepath)
510506
radius = Float32(sol(sol.t[1], idxs=sys.radius))
511507
r_0a = get_fun(sol, collect(sys.frame_a.r_0))
@@ -520,7 +516,9 @@ function render!(scene, ::typeof(BodyShape), sys, sol, t)
520516
mesh!(scene, thing; color, specular = Vec3f(1.5), shininess=20f0, diffuse=Vec3f(1), transparency=true)
521517
else
522518
T = get_frame_fun(sol, sys.frame_a)
523-
519+
scale = Vec3f(Float32(sol(sol.t[1], idxs=sys.shape_scale))*ones(Float32, 3))
520+
Tshape = reshape(sol(sol.t[1], idxs=sys.shape_transform), 4, 4)
521+
524522
@info "Loading shape mesh $shapepath"
525523
shapemesh = FileIO.load(shapepath)
526524
m = mesh!(scene, shapemesh; color, specular = Vec3f(1.5))
@@ -570,9 +568,7 @@ function render!(scene, ::typeof(BodyBox), sys, sol, t)
570568

571569
# NOTE: This draws a solid box without the hole in the middle. Cannot figure out how to render a hollow box
572570
color = get_color(sys, sol, [1, 0.2, 1, 0.9])
573-
width = Float32(sol(sol.t[1], idxs=sys.width))
574-
height = Float32(sol(sol.t[1], idxs=sys.height))
575-
length = Float32(sol(sol.t[1], idxs=sys.render_length))
571+
width, height, length = Float32.(sol(sol.t[1], idxs=[sys.width, sys.height, sys.render_length]))
576572

577573
length_dir = sol(sol.t[1], idxs=collect(sys.render_length_dir))
578574
width_dir = sol(sol.t[1], idxs=collect(sys.render_width_dir))

0 commit comments

Comments
 (0)