Recording Animations of Simulations

Recording Animations of Simulations#

Omniverse includes tools to record animations of physics simulations. The Stage Recorder extension listens to all the motion and USD property changes within a USD stage and records them to a USD file. This file contains the time samples of the changes, which can be played back to render the animation.

The timeSampled USD file only contains the changes to the stage. It uses the same hierarchy as the original stage at the time of recording. This allows adding the animation to the original stage, or to a different stage with the same hierarchy. The timeSampled file can be directly added as a sublayer to the original stage to play back the animation.


Omniverse only supports playing animation or playing physics on a USD prim at the same time. If you want to play back the animation of a USD prim, you need to disable the physics simulation on the prim.

In Isaac Lab, we directly use the Stage Recorder extension to record the animation of the physics simulation. This is available as a feature in the BaseEnvWindow class. However, to record the animation of a simulation, you need to disable Fabric to allow reading and writing all the changes (such as motion and USD properties) to the USD stage.

Stage Recorder Settings#

Isaac Lab integration of the Stage Recorder extension assumes certain default settings. If you want to change the settings, you can directly use the Stage Recorder extension in the Omniverse Create application.

Settings used in
 1    def _toggle_recording_animation_fn(self, value: bool):
 2        """Toggles the animation recording."""
 3        if value:
 4            # log directory to save the recording
 5            if not hasattr(self, "animation_log_dir"):
 6                # create a new log directory
 7                log_dir ="%Y-%m-%d_%H-%M-%S")
 8                self.animation_log_dir = os.path.join(os.getcwd(), "recordings", log_dir)
 9            # start the recording
10            _ = omni.kit.commands.execute(
11                "StartRecording",
12                target_paths=[("/World", True)],
13                live_mode=True,
14                use_frame_range=False,
15                start_frame=0,
16                end_frame=0,
17                use_preroll=False,
18                preroll_frame=0,
19                record_to="FILE",
20                fps=0,
21                apply_root_anim=False,
22                increment_name=True,
23                record_folder=self.animation_log_dir,
24                take_name="TimeSample",
25            )
26        else:
27            # stop the recording
28            _ = omni.kit.commands.execute("StopRecording")
29            # save the current stage
30            stage = omni.usd.get_context().get_stage()
31            source_layer = stage.GetRootLayer()
32            # output the stage to a file
33            stage_usd_path = os.path.join(self.animation_log_dir, "Stage.usd")
34            source_prim_path = "/"
35            # creates empty anon layer
36            temp_layer = Sdf.Find(stage_usd_path)
37            if temp_layer is None:
38                temp_layer = Sdf.Layer.CreateNew(stage_usd_path)
39            temp_stage = Usd.Stage.Open(temp_layer)
40            # update stage data
41            UsdGeom.SetStageUpAxis(temp_stage, UsdGeom.GetStageUpAxis(stage))
42            UsdGeom.SetStageMetersPerUnit(temp_stage, UsdGeom.GetStageMetersPerUnit(stage))
43            # copy the prim
44            Sdf.CreatePrimInLayer(temp_layer, source_prim_path)
45            Sdf.CopySpec(source_layer, source_prim_path, temp_layer, source_prim_path)
46            # set the default prim
47            temp_layer.defaultPrim = Sdf.Path(source_prim_path).name
48            # remove all physics from the stage
49            for prim in temp_stage.TraverseAll():
50                # skip if the prim is an instance
51                if prim.IsInstanceable():
52                    continue
53                # if prim has articulation then disable it
54                if prim.HasAPI(UsdPhysics.ArticulationRootAPI):
55                    prim.RemoveAPI(UsdPhysics.ArticulationRootAPI)
56                    prim.RemoveAPI(PhysxSchema.PhysxArticulationAPI)
57                # if prim has rigid body then disable it
58                if prim.HasAPI(UsdPhysics.RigidBodyAPI):
59                    prim.RemoveAPI(UsdPhysics.RigidBodyAPI)
60                    prim.RemoveAPI(PhysxSchema.PhysxRigidBodyAPI)
61                # if prim is a joint type then disable it
62                if prim.IsA(UsdPhysics.Joint):
63                    prim.GetAttribute("physics:jointEnabled").Set(False)
64            # resolve all paths relative to layer path
65            omni.usd.resolve_paths(source_layer.identifier, temp_layer.identifier)
66            # save the stage
67            temp_layer.Save()
68            # print the path to the saved stage
69            print("Recording completed.")
70            print(f"\tSaved recorded stage to    : {stage_usd_path}")
71            print(f"\tSaved recorded animation to: {os.path.join(self.animation_log_dir, 'TimeSample_tk001.usd')}")
72            print("\nTo play the animation, check the instructions in the following link:")
73            print(
74                "\t"
75            )
76            print("\n")
77            # reset the log directory
78            self.animation_log_dir = None

Example Usage#

In all environment standalone scripts, Fabric can be disabled by passing the --disable_fabric flag to the script. Here we run the state-machine example and record the animation of the simulation.

./ -p source/standalone/environments/state_machine/ --num_envs 8 --cpu --disable_fabric

On running the script, the Isaac Lab UI window opens with the button “Record Animation” in the toolbar. Clicking this button starts recording the animation of the simulation. On clicking the button again, the recording stops. The recorded animation and the original stage (with all physics disabled) are saved to the recordings folder in the current working directory. The files are stored in the usd format:

  • Stage.usd: The original stage with all physics disabled

  • TimeSample_tk001.usd: The timeSampled file containing the recorded animation

You can open Omniverse Isaac Sim application to play back the animation. There are many ways to launch the application (such as from terminal or Omniverse Launcher). Here we use the terminal to open the application and play the animation.

./ -s  # Opens Isaac Sim application through _isaac_sim/

On a new stage, add the Stage.usd as a sublayer and then add the TimeSample_tk001.usd as a sublayer. You can do this by dragging and dropping the files from the file explorer to the stage. Please check out the tutorial on layering in Omniverse for more details.

You can then play the animation by pressing the play button.