Render sim with normal speed AND slow-motion

hi y’all,

say, we have a rigid body simulation in a scene with 240 frames (24fps, so 10 seconds) and two cameras (cam1 and cam2). cam1 is set up to render 240 frames in one, wide shot, the simulation is running at a simulation speed of 1, so that’s “regular” speed. now, cam2 is supposed to render a close-up shot of 1 second of a section of the simulation (still 24fps) but in “slow-motion”, let’s say at a simulation speed of 50%. how would you go about this?

I’m used to doing lots of stuff in python lately, setting up entire scenes, keyframing and rendering them programmatically - I know my way around the API. but I’m pretty sure my current approach isn’t the best in terms of efficiency and maintainability:

  1. keyframe position of cam1 for normal simulation speed.
  2. set scene end to frame 240
  3. bake the simulation cache with normal speed (speed: 1)
  4. render 240 frames with cam1
  5. keyframe cam2’s movement so that it will catch the right section of the slowed down animation.
  6. set scene end to frame 480
  7. bake the simulation cache with half speed (speed: 0.5)
  8. render 24 frames with cam2

I think what’s bothering me is that I have to change the scene length and that an event that will happen e.g. at frame 50 with normal speed will occur at frame 100 with half-speed. it’s so messy having to set up the cameras like this. is there any way around this? having it organized more neatly by having two separate timelines in a way? might “scenes” or “viewlayers” be something I should look into?

thanks for any thoughts here!

kind regards,

I got it working the way I described above and want share the result in case anyone ever needs something similar. I attached a test file where everything is setup and you can just try it out.

The script will create 3 directories in the directory of the .blend file (make sure the .blend is saved) and save the render output (render settings not defined by script) into them.

import bpy
from datetime import datetime
import os
import bpy

def create_dir(dirName):
    if not os.path.exists(dirName):
        print("Directory " , dirName ,  " Created ")
        print("Directory " , dirName ,  " already exists")    

# just creating some new folders in the same directory as the .blend file
timestamp ="%Y%m%d%H%M")
project_name = "my_project_name"
main_out_folder = project_name + "_" + timestamp
project_path = bpy.path.abspath("//")
main_out_dir = os.path.join(project_path, main_out_folder)
slowmo_subdir_1 = os.path.join(main_out_dir, "slowmo1")
slowmo_subdir_2 = os.path.join(main_out_dir, "slowmo2")


normal_speed_end_frame = 100
slow_speed_end_frame = 500

scene = bpy.context.scene
scene.frame_start = 1
scene.frame_end = normal_speed_end_frame

# physics start frame is always 1 
scene.rigidbody_world.point_cache.frame_start = 1

# normal speed physics setup
scene.rigidbody_world.time_scale = 1.0
scene.rigidbody_world.point_cache.frame_end = normal_speed_end_frame


# normal speed render frames 
bpy.context.scene.render.filepath = main_out_dir  + "\\" =['cam_01']
bpy.ops.render.render(animation=True, write_still=False, use_viewport=False, layer='', scene='')

# slow motion physics setup
scene.rigidbody_world.point_cache.frame_end = slow_speed_end_frame
scene.rigidbody_world.time_scale = 0.2


# slow motion render frames

# slowmo_shot_1
scene.frame_start = 80
scene.frame_end = 160

bpy.context.scene.render.filepath = slowmo_subdir_1 + "\\" =['slowmo_cam1']
bpy.ops.render.render(animation=True, write_still=False, use_viewport=False, layer='', scene='')

# slowmo_shot_2

scene.frame_start = 100
scene.frame_end = 140

bpy.context.scene.render.filepath = slowmo_subdir_2  + "\\" =['slowmo_cam2']
bpy.ops.render.render(animation=True, write_still=False, use_viewport=False, layer='', scene='')

# cleanup:
scene.rigidbody_world.time_scale = 1.0 =['cam_01']
scene.frame_start = 1
scene.frame_end = 100

render_physics_normal_and_slowmo.blend (1.4 MB)