# Stage 44: save a blend that ALREADY contains the turntable, so viewing her needs no scripting. # # blender --background --python 44_make_spin_blend.py -- [seconds_per_turn] # # 43_spin.py has to run inside a live GUI session, and a GUI Blender launched from this agent gets # reaped when the launching command finishes. Baking the animation into the file instead means it # survives: open the file, press spacebar. import bpy, sys, math argv = sys.argv[sys.argv.index("--") + 1:] SRC, OUT = argv[0], argv[1] SEC = float(argv[2]) if len(argv) > 2 else 50.0 FPS = 24 bpy.ops.wm.open_mainfile(filepath=SRC) ob = max([o for o in bpy.data.objects if o.type == 'MESH'], key=lambda o: len(o.data.vertices)) scn = bpy.context.scene scn.render.fps = FPS scn.sync_mode = 'FRAME_DROP' # honour real time, or playback is a blur n = int(round(SEC * FPS)) scn.frame_start = 1 scn.frame_end = n # frame n+1 repeats frame 1, so the loop is seamless scn.frame_set(1) bpy.context.preferences.edit.keyframe_new_interpolation_type = 'LINEAR' ob.animation_data_clear() ob.rotation_mode = 'XYZ' ob.rotation_euler = (0.0, 0.0, 0.0) ob.keyframe_insert("rotation_euler", index=2, frame=1) ob.rotation_euler = (0.0, 0.0, 2.0 * math.pi) ob.keyframe_insert("rotation_euler", index=2, frame=n + 1) ob.rotation_euler = (0.0, 0.0, 0.0) bpy.ops.wm.save_as_mainfile(filepath=OUT) print(f"SPINBLEND_DONE {n} frames @ {FPS}fps = {SEC:.0f}s per turn -> {OUT}")