# Generator animation (left machine) for ornament_machine_new_bow_anim.blend. # Run AFTER animate_shredder.py: # blender -b ornament_machine_new_bow_anim.blend --python animate_generator.py [-- --video] # # Frames 200-340 (the shredder uses 1-180), timeline markers name every stage: # 200 Gen_Press star button pushed in, flashes # 204 Gen_Magic chamber rings + emitter flare, light beam, swirling sparkles # 228 Gen_Spawn ornament grows out of a point at Ornament_Spawn_Point, spins and hovers # 264 Gen_Drop ornament sinks through the chamber floor (floor ring flashes) # 280 Gen_Output ornament drops out of the chute onto the tray, bounces, rests at Ornament_Output_Point # The ornament is a placeholder ("Ornament_Placeholder*"): in the game the real ornament model is put at the # two empties, which carry the same motion. import bpy, math, os, random, sys from mathutils import Vector, Euler random.seed(5) sc = bpy.context.scene T0 = 200 sc.frame_end = max(sc.frame_end, T0 + 140) def bbox(o): cs = [o.matrix_world @ Vector(c) for c in o.bound_box] lo = Vector(map(min, *cs)); hi = Vector(map(max, *cs)) return (lo + hi) / 2, hi - lo def fcurves_of(idb): act = idb.animation_data.action if idb.animation_data else None if act is None: return [] try: return list(act.fcurves) except AttributeError: out = [] for layer in act.layers: for strip in layer.strips: for bag in strip.channelbags: out += list(bag.fcurves) return out def key(idb, path, frame, value=None, interp=None, easing=None): if value is not None: setattr(idb, path, value) idb.keyframe_insert(data_path=path, frame=frame) if interp: for c in fcurves_of(idb): if c.data_path == path: for kp in c.keyframe_points: if abs(kp.co.x - frame) < 0.01: kp.interpolation = interp if easing: kp.easing = easing def key_input(sock, frame, value): sock.default_value = value sock.keyframe_insert("default_value", frame=frame) for name, f in (("Gen_Press", T0), ("Gen_Magic", T0 + 4), ("Gen_Spawn", T0 + 28), ("Gen_Drop", T0 + 64), ("Gen_Output", T0 + 80)): m = sc.timeline_markers.get(name) or sc.timeline_markers.new(name, frame=f) m.frame = f for name, f in (("Shredder_Start", 1), ("Shredder_Stop", 120), ("Shredder_Pour", 128)): if not sc.timeline_markers.get(name): sc.timeline_markers.new(name, frame=f) coll = bpy.data.collections.get("Generator_Anim") or bpy.data.collections.new("Generator_Anim") if coll.name not in sc.collection.children: sc.collection.children.link(coll) # ------------------------------------------------------------------ geometry from the model glass_c, glass_s = bbox(bpy.data.objects["Chamber_Glass"]) pad_c, pad_s = bbox(bpy.data.objects["Chamber_BasePad"]) emit_c, _ = bbox(bpy.data.objects["Chamber_EmitterGlow"]) tray_c, tray_s = bbox(bpy.data.objects["Gen_Tray_Floor"]) ceil_c, _ = bbox(bpy.data.objects["Gen_Chute_Ceiling"]) back_c, _ = bbox(bpy.data.objects["Gen_Chute_BackWall"]) CX, CY = glass_c.x, glass_c.y PAD_TOP = pad_c.z + pad_s.z / 2 EMIT_Z = emit_c.z SPAWN_Z = (PAD_TOP + EMIT_Z) / 2 + 0.2 # ------------------------------------------------------------------ 1) button press + flash press = Vector((0, 0.18, 0)) # pushes into the machine (+Y) for o in bpy.data.objects: if o.name.startswith(("Gen_Button_Face", "Gen_Button_Inner", "Gen_Button_Star")): rest = o.location.copy() key(o, "location", T0 - 1, rest) key(o, "location", T0 + 3, rest + press, "QUAD", "EASE_OUT") key(o, "location", T0 + 12, rest) star_glow = bpy.data.materials.get("Glow_Yellow") btn_mat = None face = bpy.data.objects.get("Gen_Button_Face") if face and face.data.materials and face.data.materials[0]: btn_mat = face.data.materials[0].copy(); btn_mat.name = "Gen_Button_Face_Anim" face.data.materials[0] = btn_mat b = next(n for n in btn_mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED") b.inputs["Emission Color"].default_value = (0.3, 1.0, 0.4, 1) for f, v in ((T0 - 1, 0.0), (T0 + 3, 3.0), (T0 + 16, 0.0)): key_input(b.inputs["Emission Strength"], f, v) # ------------------------------------------------------------------ 2) chamber magic (own copy of the cyan glow) magic = bpy.data.materials["Glow_Cyan"].copy(); magic.name = "Gen_Chamber_Magic" for n in ("Chamber_GlowRing_Low", "Chamber_GlowRing_High", "Chamber_EmitterGlow"): o = bpy.data.objects[n] for i, m in enumerate(o.data.materials): if m and m.name.startswith("Glow_Cyan"): o.data.materials[i] = magic mb = next(n for n in magic.node_tree.nodes if n.type == "BSDF_PRINCIPLED") base_e = mb.inputs["Emission Strength"].default_value for f, v in ((T0 + 3, base_e), (T0 + 14, base_e * 3.5), (T0 + 30, base_e * 5), (T0 + 56, base_e * 3), (T0 + 66, base_e)): key_input(mb.inputs["Emission Strength"], f, v) for c in fcurves_of(magic.node_tree): nm = c.modifiers.new("NOISE"); nm.scale = 2.5; nm.strength = base_e * 1.5 nm.use_restricted_range = True; nm.frame_start, nm.frame_end = T0 + 10, T0 + 60 # light beam from the emitter down to the floor beam_mat = bpy.data.materials.new("Gen_Beam") try: beam_mat.use_nodes = True except Exception: pass bb = next(n for n in beam_mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED") bb.inputs["Base Color"].default_value = (0.5, 0.95, 1.0, 1) bb.inputs["Emission Color"].default_value = (0.35, 0.9, 1.0, 1) bb.inputs["Emission Strength"].default_value = 2.0 bb.inputs["Alpha"].default_value = 0.12 for a, v in (("surface_render_method", "BLENDED"), ("blend_method", "BLEND")): try: setattr(beam_mat, a, v) except Exception: pass bpy.ops.mesh.primitive_cylinder_add(vertices=24, radius=1.0, depth=1.0, location=(CX, CY, (PAD_TOP + EMIT_Z) / 2)) beam = bpy.context.active_object beam.name = "Gen_Magic_Beam" beam.data.materials.append(beam_mat) for c in list(beam.users_collection): c.objects.unlink(beam) coll.objects.link(beam) h = EMIT_Z - PAD_TOP for f, r in ((T0 + 6, 0.0), (T0 + 16, 0.3), (T0 + 30, 0.8), (T0 + 58, 0.55), (T0 + 66, 0.0)): key(beam, "scale", f, (r, r, h if r > 0 else h * 0.2), "QUAD", "EASE_IN_OUT") key(beam, "scale", 1, (0, 0, 0), "CONSTANT") # swirling sparkles (children of a spinning, rising orbit empty) spark_mat = bpy.data.materials.new("Gen_Sparkle") try: spark_mat.use_nodes = True except Exception: pass sb = next(n for n in spark_mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED") sb.inputs["Base Color"].default_value = (1, 1, 1, 1) sb.inputs["Emission Color"].default_value = (0.75, 0.97, 1.0, 1) sb.inputs["Emission Strength"].default_value = 12.0 orbit = bpy.data.objects.new("Gen_Sparkle_Orbit", None) orbit.location = (CX, CY, PAD_TOP + 0.6) coll.objects.link(orbit) key(orbit, "rotation_euler", T0 + 6, Euler((0, 0, 0)), "QUAD", "EASE_IN") key(orbit, "rotation_euler", T0 + 62, Euler((0, 0, math.radians(360 * 4)))) key(orbit, "location", T0 + 6, orbit.location.copy()) key(orbit, "location", T0 + 62, Vector((CX, CY, PAD_TOP + 2.0))) for k in range(16): bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1, radius=0.09) s = bpy.context.active_object s.name = "Gen_Sparkle_%02d" % k s.data.materials.append(spark_mat) for c in list(s.users_collection): c.objects.unlink(s) coll.objects.link(s) a = 2 * math.pi * k / 16 r = random.uniform(1.4, 2.5) s.parent = orbit s.location = (r * math.cos(a), r * math.sin(a), random.uniform(-0.3, 3.2)) sz = random.uniform(0.8, 1.6) t_in = T0 + 8 + random.randint(0, 10) key(s, "scale", 1, (0, 0, 0), "CONSTANT") key(s, "scale", t_in - 1, (0, 0, 0)) key(s, "scale", t_in + 4, (sz, sz, sz)) key(s, "scale", T0 + 54 + random.randint(0, 6), (sz, sz, sz)) key(s, "scale", T0 + 64 + random.randint(0, 4), (0, 0, 0)) # chamber light flash bpy.ops.object.light_add(type="POINT", location=(CX, CY, SPAWN_Z)) cl = bpy.context.active_object cl.name = "Gen_Chamber_Light" for c in list(cl.users_collection): c.objects.unlink(cl) coll.objects.link(cl) cl.data.color = (0.45, 0.9, 1.0) cl.data.shadow_soft_size = 1.0 for f, e in ((T0 + 2, 0.0), (T0 + 20, 250.0), (T0 + 30, 600.0), (T0 + 40, 220.0), (T0 + 60, 180.0), (T0 + 70, 0.0)): cl.data.energy = e; cl.data.keyframe_insert("energy", frame=f) cl.data.energy = 0; cl.data.keyframe_insert("energy", frame=1) # ------------------------------------------------------------------ 2b) lightning bolts flickering inside the chamber MAGIC_A, MAGIC_B = T0 + 12, T0 + 60 # window in which the chamber is "charged" R_IN = glass_s.x / 2 - 0.45 # stay just inside the glass bolt_mat = bpy.data.materials.new("Gen_Lightning") try: bolt_mat.use_nodes = True except Exception: pass lb = next(n for n in bolt_mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED") lb.inputs["Base Color"].default_value = (0.85, 0.97, 1.0, 1) lb.inputs["Emission Color"].default_value = (0.65, 0.92, 1.0, 1) lb.inputs["Emission Strength"].default_value = 18.0 def jagged(p0, p1, n, amp): pts = [] for i in range(n + 1): t = i / n p = p0.lerp(p1, t) if 0 < i < n: p = p + Vector((random.uniform(-amp, amp), random.uniform(-amp, amp), random.uniform(-amp, amp) * 0.4)) pts.append(p) return pts def bolt_object(name, strokes, radius): cu = bpy.data.curves.new(name, "CURVE") cu.dimensions = "3D"; cu.bevel_depth = radius; cu.bevel_resolution = 1 for pts in strokes: sp = cu.splines.new("POLY") sp.points.add(len(pts) - 1) for p, v in zip(sp.points, pts): p.co = (v.x, v.y, v.z, 1) cu.materials.append(bolt_mat) o = bpy.data.objects.new(name, cu) coll.objects.link(o) return o def vis_key(o, frame, visible): o.hide_render = not visible; o.hide_viewport = not visible o.keyframe_insert("hide_render", frame=frame); o.keyframe_insert("hide_viewport", frame=frame) N_BOLT_SLOTS, VARIANTS = 5, 4 for slot in range(N_BOLT_SLOTS): variants = [] for v in range(VARIANTS): a0 = random.uniform(0, 2 * math.pi) start = Vector((CX + 0.6 * math.cos(a0), CY + 0.6 * math.sin(a0), EMIT_Z - 0.2)) if random.random() < 0.5: # down to the floor pad a1 = random.uniform(0, 2 * math.pi); r1 = random.uniform(0.6, 1.8) end = Vector((CX + r1 * math.cos(a1), CY + r1 * math.sin(a1), PAD_TOP + 0.1)) else: # sideways into the glass wall / pillars a1 = a0 + random.uniform(-1.2, 1.2) end = Vector((CX + R_IN * math.cos(a1), CY + R_IN * math.sin(a1), random.uniform(PAD_TOP + 1.0, EMIT_Z - 1.0))) main = jagged(start, end, 9, 0.45) k = random.randint(3, 6) # a forked branch branch = jagged(main[k], main[k] + Vector((random.uniform(-1.2, 1.2), random.uniform(-1.2, 1.2), -random.uniform(0.4, 1.2))), 4, 0.3) variants.append(bolt_object("Gen_Lightning_%d_%d" % (slot, v), [main, branch], random.uniform(0.035, 0.06))) for o in variants: vis_key(o, 1, False) f = MAGIC_A + slot * 2 while f < MAGIC_B: o = random.choice(variants) dur = random.randint(1, 3) vis_key(o, f, True); vis_key(o, f + dur, False) f += dur + random.randint(1, 5) for o in variants: for c in fcurves_of(o): for kp in c.keyframe_points: kp.interpolation = "CONSTANT" # ------------------------------------------------------------------ 2c) glowing fog filling the chamber fog_mat = bpy.data.materials.new("Gen_Fog") try: fog_mat.use_nodes = True except Exception: pass FN, FL = fog_mat.node_tree.nodes, fog_mat.node_tree.links FN.clear() fout = FN.new("ShaderNodeOutputMaterial") vol = FN.new("ShaderNodeVolumePrincipled") vol.inputs["Color"].default_value = (0.75, 0.92, 1.0, 1) vol.inputs["Emission Color"].default_value = (0.35, 0.8, 1.0, 1) tco = FN.new("ShaderNodeTexCoord") mp = FN.new("ShaderNodeMapping") FL.new(tco.outputs["Object"], mp.inputs["Vector"]) nz = FN.new("ShaderNodeTexNoise"); nz.noise_dimensions = "4D" nz.inputs["Scale"].default_value = 1.6; nz.inputs["Detail"].default_value = 3.0 FL.new(mp.outputs["Vector"], nz.inputs["Vector"]) ramp = FN.new("ShaderNodeMapRange") ramp.inputs["From Min"].default_value = 0.42; ramp.inputs["From Max"].default_value = 0.75 FL.new(nz.outputs["Fac"], ramp.inputs["Value"]) dens = FN.new("ShaderNodeMath"); dens.operation = "MULTIPLY" FL.new(ramp.outputs["Result"], dens.inputs[0]) FL.new(dens.outputs["Value"], vol.inputs["Density"]) emis = FN.new("ShaderNodeMath"); emis.operation = "MULTIPLY" FL.new(ramp.outputs["Result"], emis.inputs[0]) FL.new(emis.outputs["Value"], vol.inputs["Emission Strength"]) FL.new(vol.outputs["Volume"], fout.inputs["Volume"]) for f, d, e in ((1, 0.0, 0.0), (MAGIC_A - 4, 0.0, 0.0), (MAGIC_A + 10, 0.55, 0.45), (MAGIC_B - 6, 0.55, 0.45), (MAGIC_B + 10, 0.0, 0.0)): key_input(dens.inputs[1], f, d) key_input(emis.inputs[1], f, e) for f, w in ((MAGIC_A - 4, 0.0), (MAGIC_B + 10, 3.0)): # swirling wisps key_input(nz.inputs["W"], f, w) for f, rz in ((MAGIC_A - 4, 0.0), (MAGIC_B + 10, 2.5)): key_input(mp.inputs["Rotation"], f, (0, 0, rz)) bpy.ops.mesh.primitive_cylinder_add(vertices=32, radius=R_IN + 0.25, depth=EMIT_Z - PAD_TOP - 0.2, location=(CX, CY, (EMIT_Z + PAD_TOP) / 2)) fog = bpy.context.active_object fog.name = "Gen_Magic_Fog" fog.data.materials.append(fog_mat) for c in list(fog.users_collection): c.objects.unlink(fog) coll.objects.link(fog) try: sc.eevee.volumetric_tile_size = "4" sc.eevee.volumetric_samples = 64 except Exception: pass # ------------------------------------------------------------------ 2d) fast spark bursts where the bolts hit burst_mat = bpy.data.materials.new("Gen_SparkBurst") try: burst_mat.use_nodes = True except Exception: pass kb = next(n for n in burst_mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED") kb.inputs["Emission Color"].default_value = (1.0, 0.95, 0.7, 1) kb.inputs["Emission Strength"].default_value = 20.0 for k in range(36): bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1, radius=0.05) s = bpy.context.active_object s.name = "Gen_SparkBurst_%02d" % k s.data.materials.append(burst_mat) for c in list(s.users_collection): c.objects.unlink(s) coll.objects.link(s) t = random.randint(MAGIC_A, MAGIC_B - 8) a = random.uniform(0, 2 * math.pi); r = random.uniform(0.3, R_IN - 0.2) p0 = Vector((CX + r * math.cos(a), CY + r * math.sin(a), random.uniform(PAD_TOP + 0.3, EMIT_Z - 0.4))) d = Vector((random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-0.2, 1.0))).normalized() * random.uniform(0.6, 1.4) key(s, "scale", 1, (0, 0, 0), "CONSTANT") key(s, "scale", t - 1, (0, 0, 0), "LINEAR") key(s, "scale", t, (1.6, 1.6, 1.6)) key(s, "scale", t + random.randint(5, 9), (0, 0, 0)) key(s, "location", t, p0, "QUAD", "EASE_OUT") key(s, "location", t + 8, p0 + d + Vector((0, 0, -0.3))) # ------------------------------------------------------------------ 3) placeholder ornament + game anchor points spawn = bpy.data.objects.get("Ornament_Spawn_Point") or bpy.data.objects.new("Ornament_Spawn_Point", None) spawn.empty_display_type = "SPHERE"; spawn.empty_display_size = 1.2 if spawn.name not in coll.objects: coll.objects.link(spawn) spawn.location = (CX, CY, SPAWN_Z) out_pt = bpy.data.objects.get("Ornament_Output_Point") or bpy.data.objects.new("Ornament_Output_Point", None) out_pt.empty_display_type = "SPHERE"; out_pt.empty_display_size = 0.8 if out_pt.name not in coll.objects: coll.objects.link(out_pt) def placeholder(name, parent): """Simple red bauble with gold band + cap; replaced by the real ornament in the game.""" red = bpy.data.materials.get("Machine_Red"); gold = bpy.data.materials.get("Machine_Gold") bpy.ops.mesh.primitive_uv_sphere_add(segments=24, ring_count=16, radius=1.0) body = bpy.context.active_object; body.name = name; body.data.materials.append(red) bpy.ops.object.shade_smooth() bpy.ops.mesh.primitive_torus_add(major_radius=1.0, minor_radius=0.13) band = bpy.context.active_object; band.name = name + "_Band"; band.data.materials.append(gold) bpy.ops.mesh.primitive_cylinder_add(vertices=12, radius=0.28, depth=0.3, location=(0, 0, 1.05)) cap = bpy.context.active_object; cap.name = name + "_Cap"; cap.data.materials.append(gold) bpy.ops.mesh.primitive_torus_add(major_radius=0.2, minor_radius=0.06, location=(0, 0, 1.32), rotation=(math.radians(90), 0, 0)) loop = bpy.context.active_object; loop.name = name + "_Loop"; loop.data.materials.append(gold) for p in (body, band, cap, loop): for c in list(p.users_collection): c.objects.unlink(p) coll.objects.link(p) p.parent = parent return body orn = bpy.data.objects.new("Ornament_Anchor_Chamber", None) # carries the chamber motion coll.objects.link(orn) orn.parent = spawn placeholder("Ornament_Placeholder", orn) S = 0.95 # placeholder size in the chamber key(orn, "scale", 1, (0, 0, 0), "CONSTANT") key(orn, "scale", T0 + 27, (0, 0, 0), "BACK", "EASE_OUT") key(orn, "scale", T0 + 40, (S, S, S)) key(orn, "rotation_euler", T0 + 27, Euler((0, 0, 0)), "QUAD", "EASE_OUT") key(orn, "rotation_euler", T0 + 46, Euler((0, 0, math.radians(720))), "SINE", "EASE_IN_OUT") key(orn, "rotation_euler", T0 + 64, Euler((0, 0, math.radians(800)))) for f, dz in ((T0 + 40, 0.0), (T0 + 48, 0.25), (T0 + 56, -0.1), (T0 + 63, 0.15)): # hover bob key(orn, "location", f, Vector((0, 0, dz)), "SINE", "EASE_IN_OUT") drop_dz = PAD_TOP - SPAWN_Z - 0.2 key(orn, "location", T0 + 64, Vector((0, 0, 0.15)), "QUAD", "EASE_IN") key(orn, "location", T0 + 74, Vector((0, 0, drop_dz))) key(orn, "scale", T0 + 64, (S, S, S), "QUAD", "EASE_IN") key(orn, "scale", T0 + 70, (S, S, S * 0.8)) key(orn, "scale", T0 + 76, (0, 0, 0)) # floor ring flashes as it goes through low = bpy.data.objects["Chamber_GlowRing_Low"] # the ring mesh is built in world space with its origin at 0,0,0 -> scaling would slide it off-centre. # Move the origin to the ring's own centre first (looks identical, but now it pulses in place). ring_c, _ = bbox(low) local_c = low.matrix_world.inverted() @ ring_c if local_c.length > 0.001: if low.data.users > 1: low.data = low.data.copy() from mathutils import Matrix low.data.transform(Matrix.Translation(-local_c)) low.matrix_world = low.matrix_world @ Matrix.Translation(local_c) for f, sz in ((T0 + 66, 1.0), (T0 + 72, 1.25), (T0 + 80, 1.0)): key(low, "scale", f, (sz, sz, 1.0), "SINE", "EASE_IN_OUT") # ------------------------------------------------------------------ 4) drop out of the chute onto the tray tray_top = tray_c.z + tray_s.z / 2 R_OUT = 0.75 rest = Vector((tray_c.x, tray_c.y - tray_s.y * 0.12, tray_top + R_OUT * 0.9)) out_pt.location = rest start = Vector((tray_c.x, back_c.y - 0.7, ceil_c.z - 0.9)) orn2 = bpy.data.objects.new("Ornament_Anchor_Output", None) coll.objects.link(orn2) placeholder("Ornament_Placeholder_Out", orn2) orn2.location = start key(orn2, "scale", 1, (0, 0, 0), "CONSTANT") key(orn2, "scale", T0 + 79, (0, 0, 0), "LINEAR") key(orn2, "scale", T0 + 81, (R_OUT, R_OUT, R_OUT)) key(orn2, "scale", T0 + 89, (R_OUT * 1.12, R_OUT * 1.12, R_OUT * 0.8), "QUAD", "EASE_OUT") # squash on landing key(orn2, "scale", T0 + 93, (R_OUT, R_OUT, R_OUT)) key(orn2, "location", T0 + 80, start, "QUAD", "EASE_IN") key(orn2, "location", T0 + 89, rest + Vector((0, 0.4, -0.05)), "QUAD", "EASE_OUT") key(orn2, "location", T0 + 94, rest + Vector((0, 0.1, 0.55)), "QUAD", "EASE_IN") # bounce key(orn2, "location", T0 + 99, rest + Vector((0, -0.05, 0)), "QUAD", "EASE_OUT") key(orn2, "location", T0 + 102, rest + Vector((0, 0, 0.12)), "QUAD", "EASE_IN") key(orn2, "location", T0 + 105, rest) key(orn2, "rotation_euler", T0 + 80, Euler((0, 0, 0))) key(orn2, "rotation_euler", T0 + 105, Euler((math.radians(-35), 0, math.radians(25))), "SINE", "EASE_OUT") key(orn2, "rotation_euler", T0 + 118, Euler((math.radians(-10), 0, math.radians(20)))) chute_light = bpy.data.objects.get("Gen_Chute_Light") if chute_light: e0 = chute_light.data.energy for f, e in ((T0 + 76, e0), (T0 + 82, e0 * 3), (T0 + 96, e0)): chute_light.data.energy = e; chute_light.data.keyframe_insert("energy", frame=f) # ------------------------------------------------------------------ generator camera, save, renders cam = bpy.data.objects.get("Generator_Cam") if cam is None: cam = bpy.data.objects.new("Generator_Cam", bpy.data.cameras.new("Generator_Cam")) sc.collection.objects.link(cam) target = Vector((CX, CY - 2.0, (tray_c.z + EMIT_Z) / 2 + 0.5)) cam.location = target + Vector((-6.0, -24.0, 4.0)) cam.rotation_euler = (target - cam.location).to_track_quat("-Z", "Y").to_euler() cam.data.lens = 50 bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath) main_cam = sc.camera out_dir = os.path.join(os.path.dirname(bpy.data.filepath), "generator_anim") os.makedirs(out_dir, exist_ok=True) sc.camera = cam sc.render.resolution_x = sc.render.resolution_y = 900 if "--video" in sys.argv: sc.render.resolution_x = sc.render.resolution_y = 720 if hasattr(sc.render.image_settings, "media_type"): sc.render.image_settings.media_type = "VIDEO" sc.render.image_settings.file_format = "FFMPEG" sc.render.ffmpeg.format = "MPEG4"; sc.render.ffmpeg.codec = "H264" sc.render.ffmpeg.constant_rate_factor = "MEDIUM" sc.frame_start, sc.frame_end = T0 - 5, T0 + 125 sc.render.filepath = os.path.join(out_dir, "generator_preview.mp4") bpy.ops.render.render(animation=True) else: for f in (T0 + 2, T0 + 24, T0 + 33, T0 + 44, T0 + 52, T0 + 70, T0 + 88, T0 + 118): sc.frame_set(f) sc.render.filepath = os.path.join(out_dir, "gen_frame_%03d.png" % f) bpy.ops.render.render(write_still=True) sc.camera = main_cam print("DONE generator animation", bpy.data.filepath)