Skip to content

Commit 7b556aa

Browse files
Enable Capsule support in animation export
- Enable support for shape kind Capsule. - Enable animation export in test Collision/BouncingCapsules.jl. - Update docu.
1 parent ee28e93 commit 7b556aa

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/AnimationExport/exportAnimation.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ function exportObject(object, elements, obj::Modia3D.Composition.Object3D, cone:
8787
return (r_obj, R_obj)
8888
end
8989

90+
function exportObject(object, elements, obj::Modia3D.Composition.Object3D, capsule::Modia3D.Shapes.Capsule, initPos, initRot)
91+
r_obj = Modia3D.ZeroVector3D
92+
R_obj = Shapes.rotateAxis2y(capsule.axis, Modia3D.NullRotation)
93+
name = String(Modia3D.fullName(obj)) * ".geometry"
94+
points = []
95+
for i in -9:0
96+
angle = i/9 * pi/2
97+
point = (; x=capsule.diameter/2*cos(angle), y=-capsule.length/2+capsule.diameter/2*sin(angle))
98+
push!(points, point)
99+
end
100+
for i in 0:9
101+
angle = i/9 * pi/2
102+
point = (; x=capsule.diameter/2*cos(angle), y=capsule.length/2+capsule.diameter/2*sin(angle))
103+
push!(points, point)
104+
end
105+
geometry = (; name=name, uuid=name2uuid(name), type="LatheGeometry", points=points, phiStart=0, phiLength=2*pi, segments=32)
106+
material = printVisuMaterialToJSON(obj, obj.visualMaterial)
107+
objectInfo = getObjectInfo(obj, geometry, material, initPos, initRot, R_obj=R_obj)
108+
printInfoToFile(object, elements, geometry, material, nothing, objectInfo)
109+
return (r_obj, R_obj)
110+
end
111+
90112
function exportObject(object, elements, obj::Modia3D.Composition.Object3D, beam::Modia3D.Shapes.Beam, initPos, initRot)
91113
if beam.axis == 1
92114
r_obj = @SVector[0.0, 0.0, -beam.thickness/2]
@@ -206,6 +228,10 @@ function printObjectToJSON(object, elements, obj; initPos=obj.r_abs, initRot=obj
206228
cone::Modia3D.Shapes.Cone = obj.shape
207229
(r_obj, R_obj) = exportObject(object, elements, obj, cone, initPos, initRot)
208230

231+
elseif shapeKind == Modia3D.CapsuleKind
232+
capsule::Modia3D.Shapes.Capsule = obj.shape
233+
(r_obj, R_obj) = exportObject(object, elements, obj, capsule, initPos, initRot)
234+
209235
elseif shapeKind == Modia3D.BeamKind
210236
beam::Modia3D.Shapes.Beam = obj.shape
211237
(r_obj, R_obj) = exportObject(object, elements, obj, beam, initPos, initRot)
@@ -329,7 +355,7 @@ function exportAnimation(scene)
329355
end
330356

331357
io = open(animationFile, "w")
332-
JSON.print(io, scene, 2) # 3rd parameter: nothing = not human readable; 0 = no indentation; n = number of indentation spaces
358+
JSON.print(io, scene, 0) # 3rd parameter: nothing = not human readable; 0 = no indentation; n = number of indentation spaces
333359
close(io)
334360

335361
println("done.")

src/Shapes/geometry.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ The reference frame = Object3D frame is located at the center of the capsule.
149149
150150
# Notes
151151
- Some versions of SimVis visualize [half ellipsoids with semi-axis length `length/2` instead of spheres with diameter `diameter`](https://github.com/ModiaSim/PrivateModia3D.jl/issues/54).
152-
- Capsule is [not supported by animation export](https://github.com/ModiaSim/PrivateModia3D.jl/issues/77).
153152
"""
154153
mutable struct Capsule <: Modia3D.AbstractGeometry
155154
axis::Int

test/Collision/BouncingCapsules.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ BouncingCapsules = Model(
1818
defaultFrameLength=0.2,
1919
visualizeBoundingBox = true,
2020
enableContactDetection=true,
21-
visualizeContactPoints=false)),
21+
visualizeContactPoints=false,
22+
animationFile="BouncingCapsules.json")),
2223
worldFrame = Object3D(parent=:world, feature=Visual(shape=CoordinateSystem(length=0.5))),
2324
ground = Object3D(parent=:world,
2425
translation=:[0.0, 0.0, -boxHeigth/2],

0 commit comments

Comments
 (0)