Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice
title: Animation and video name: Animation and video summary: Motions, camera moves and texts in animations/*.py, checked for collisions, viewed as stills, exported as MP4. order: 31 category: Check and present default: on-demand when: the user wants to see parts move, an assembly sequence, a camera flight, a video or a presentation of the model topics: File and structure; Joints and timeline; Camera; Texts; Build, check, view; Feedback
Skill: Animation and video
An animation describes motion, camera and text over time. It is data, not a video: the app plays it in the 3D view,
soma render turns it into pictures and an MP4. Write it in Python in animations/<topic>.py, several
Animation(...) per file are fine. Do not change model.py for an animation.
from soma.anim import Animation
from model import HINGE_Y, HINGE_Z # reuse the model's constants (add_part has no effect here)
a = Animation("Open the lid") # unique name, the user picks it in the app
lid = a.hinge("Lid", (0, HINGE_Y, HINGE_Z), (1, HINGE_Y, HINGE_Z)) # axis through two points, like cq rotate()
drawer = a.slider("Drawer", (1, 0, 0)) # moves along a direction (mm)
a.camera.set(view="iso") # jumps; fits all parts over the whole motion
a.title("Storage box", subtitle="Lid and drawer", duration=2)
a.caption("The lid opens to 110°") # shown until the next caption
a.play(lid.to(-110), run_time=2) # everything in one play() runs at the same time
a.label("Hinge", part="Lid", at=(0, HINGE_Y, HINGE_Z))
a.play(drawer.to(60), a.camera.orbit(45), run_time=1.5, ease="linear")
a.wait(1)
Joints and timeline
hinge(parts, p1, p2): angle in degrees, right-hand rule aroundp2 - p1.slider(parts, direction): way in mm.part(parts): free motion withto(cq.Location(...)),translate((x, y, z)),rotate(p1, p2, angle).to()moves like a rigid body on a screw path: a pure turn runs on the arc about its axis (at most 180°), a pure shift straight. Do not build your own interpolation from many tiny steps for that.partsis a name fromadd_part, a group ("Housing","Housing/Screws"), a part with its group ("Housing/Lid") or a list. One joint per part. A joint on a moving part getsparent=lid, its axis is given in the model position.joint.to(value)(0 = as modelled),joint.by(delta).play(*actions, run_time=1, ease="smooth"), easessmooth,linear,in,out.wait(seconds).title()also takes time.caption,label,highlight(parts, duration=),hide,show,ghost(parts)start now and take none.
Camera
a.camera.set(view=, fit=, zoom=, target=, distance=)jumps,a.camera.move(...)is a flight insideplay(). Views: iso, front, back, left, right, top, bottom or a direction from the target to the camera.fit=["Lid"]frames these parts over their whole motion.a.camera.orbit(degrees, tilt=0)circles around Z,zoom(factor). Wide motions (explosions) leave the parts small: givefitthe parts that matter or azoom.- Keep the moving parts in view, one camera move at a time, 1 to 3 s each. Without camera calls the user turns the view freely.
Text
Captions: one short sentence in the language the user speaks, about what moves and why. Labels: 1 to 3 words.
Build, check, look
soma anim build(the app also builds when the file changes). Errors name file and line. It also warns about motion that plays back differently than written: jumps within one frame (run_time=0, a cameraset()in the middle), turns faster than about 15° per frame that wobble between the 30 samples per second, and parts still hidden at the end (also throughhide()of a group). Fix them or make sure they are intended.soma anim info "Open the lid": the timeline and the warnings as text. Read it.soma anim check "Open the lid" --gap 0.5: parts that collide or come closer than the gap during the motion. Fix collisions in the model or in the motion. Contacts and gaps as built in the model count as intended, only what gets worse during the motion is reported. A motion built from many shortplay()steps (a coupled mechanism) is fine: approximate a curve with steps of a few degrees, too coarse steps show up as small collisions.soma render --anim "Open the lid" --sheet: one picture with 9 stills and their times,--at 1.5for one moment. Open the picture and look at it.- Only when the user wants a video:
soma render --anim "Open the lid" --videowritesrenders/<id>.mp4(1280x720, 30 fps), the captions as.vttand an overview picture. You cannot watch the video, check the overview.
Feedback from the user
[Animation: "Name" (animations/x.py) at 1.50 s] and [Video: renders/x.mp4 at 00:03.20] point to a moment. A
markup may say drawn on renders/x.mp4 at 00:03.20 or animation "Name" at 1.50 s: the picture shows that
moment. Render it yourself (soma render --anim "Name" --at 1.5) before you change something.