Skip to content

Commit 0ef1a24

Browse files
authored
Merge pull request #120 from JuliaComputing/shapetransform
allow BodyShape to take shape transformations
2 parents 3797d61 + 978be83 commit 0ef1a24

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ext/Render.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ end
408408
function render!(scene, ::typeof(BodyShape), sys, sol, t)
409409
color = get_color(sys, sol, :purple)
410410
shapepath = get_shape(sys, sol)
411+
Tshape = reshape(sol(sol.t[1], idxs=sys.shape_transform), 4, 4)
412+
scale = Vec3f(Float32(sol(sol.t[1], idxs=sys.shape_scale))*ones(Float32, 3))
411413
if isempty(shapepath)
412414
radius = Float32(sol(sol.t[1], idxs=sys.radius))
413415
r_0a = get_fun(sol, collect(sys.frame_a.r_0))
@@ -428,11 +430,11 @@ function render!(scene, ::typeof(BodyShape), sys, sol, t)
428430
m = mesh!(scene, shapemesh; color, specular = Vec3f(1.5))
429431

430432
@views on(t) do t
431-
Ta = T(t)
433+
Ta = T(t)*Tshape
432434
r1 = Point3f(Ta[1:3, 4])
433435
q = Rotations.QuatRotation(Ta[1:3, 1:3]).q
434436
Q = Makie.Quaternionf(q.v1, q.v2, q.v3, q.s)
435-
Makie.transform!(m, translation=r1, rotation=Q)
437+
Makie.transform!(m; translation=r1, rotation=Q, scale)
436438
end
437439
end
438440

src/components.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ The `BodyShape` component is similar to a [`Body`](@ref), but it has two frames
380380
381381
See also [`BodyCylinder`](@ref) and [`BodyBox`](@ref) for body components with predefined shapes and automatically computed inertial properties based on geometry and density.
382382
"""
383-
@component function BodyShape(; name, m = 1, r = [0, 0, 0], r_cm = 0.5*r, r_0 = 0, radius = 0.08, color=purple, shapefile="", kwargs...)
383+
@component function BodyShape(; name, m = 1, r = [0, 0, 0], r_cm = 0.5*r, r_0 = 0, radius = 0.08, color=purple, shapefile="", shape_transform = I(4), shape_scale = 1, kwargs...)
384384
systems = @named begin
385385
translation = FixedTranslation(r = r)
386386
body = Body(; r_cm, r_0, kwargs...)
@@ -408,10 +408,12 @@ See also [`BodyCylinder`](@ref) and [`BodyBox`](@ref) for body components with p
408408
radius = radius, [description = "Radius of the body in animations"]
409409
color[1:4] = color, [description = "Color of the body in animations"]
410410
shapefile[1:length(shapecode)] = shapecode
411+
shape_transform[1:16] = vec(shape_transform)
412+
shape_scale = shape_scale
411413
end
412414

413415

414-
pars = [r; radius; color; shapefile]
416+
pars = [r; radius; color; shapefile; shape_transform; shape_scale]
415417

416418
r_0, v_0, a_0 = collect.((r_0, v_0, a_0))
417419

0 commit comments

Comments
 (0)