blenderproc.python.object.PhysicsSimulation module

Run the physics simulation for the objects in the scene.

class blenderproc.python.object.PhysicsSimulation._PhysicsSimulation[source]

Bases: object

static do_simulation(min_simulation_time, max_simulation_time, check_object_interval, object_stopped_location_threshold, object_stopped_rotation_threshold, verbose=False)[source]

Perform the simulation.

This method bakes the simulation for the configured number of iterations and returns all object positions at the last frame.

Parameters:
  • min_simulation_time (float) – The minimum number of seconds to simulate.

  • max_simulation_time (float) – The maximum number of seconds to simulate.

  • check_object_interval (float) – The interval in seconds at which all objects should be checked if they are still moving. If all objects have stopped moving, then the simulation will be stopped.

  • object_stopped_location_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

  • object_stopped_rotation_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

  • verbose (bool) – If True, more details during the physics simulation are printed.

static frames_to_seconds(frames)[source]

Converts the given number of frames into the corresponding number of seconds.

Parameters:

frames (int) – The number of frames.

Return type:

float

Returns:

The number of seconds:

static get_pose()[source]

Returns position and rotation values of all objects in the scene with ACTIVE rigid_body type.

Return type:

dict

Returns:

Dict of form {obj_name:{‘location’:[x, y, z], ‘rotation’:[x_rot, y_rot, z_rot]}}.

static have_objects_stopped_moving(last_poses, new_poses, object_stopped_location_threshold, object_stopped_rotation_threshold)[source]

Check if the difference between the two given poses per object is smaller than the configured threshold.

Parameters:
  • last_poses (dict) – Dict of form {obj_name:{‘location’:[x, y, z], ‘rotation’:[x_rot, y_rot, z_rot]}}.

  • new_poses (dict) – Dict of form {obj_name:{‘location’:[x, y, z], ‘rotation’:[x_rot, y_rot, z_rot]}}.

  • object_stopped_location_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

  • object_stopped_rotation_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

Return type:

bool

Returns:

True, if no objects are moving anymore.

static seconds_to_frames(seconds)[source]

Converts the given number of seconds into the corresponding number of blender animation frames.

Parameters:

seconds (float) – The number of seconds.

Return type:

int

Returns:

The number of frames.

blenderproc.python.object.PhysicsSimulation.simulate_physics(min_simulation_time=4.0, max_simulation_time=40.0, check_object_interval=2.0, object_stopped_location_threshold=0.01, object_stopped_rotation_threshold=0.1, substeps_per_frame=10, solver_iters=10, verbose=False)[source]

Simulates the current scene.

The simulation is run for at least min_simulation_time seconds and at a maximum max_simulation_time seconds. Every check_object_interval seconds, it is checked if the maximum object movement in the last second is below a given threshold. If that is the case, the simulation is stopped.

The origin of all objects is set to their center of mass in this function which is necessary to achieve a realistic simulation in blender (see https://blender.stackexchange.com/questions/167488/physics-not-working-as-expected) Also the scale of each participating object is persisted as scale != 1 can make the simulation unstable.

Parameters:
  • min_simulation_time (float) – The minimum number of seconds to simulate.

  • max_simulation_time (float) – The maximum number of seconds to simulate.

  • check_object_interval (float) – The interval in seconds at which all objects should be checked if they are still moving. If all objects have stopped moving, then the simulation will be stopped.

  • object_stopped_location_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

  • object_stopped_rotation_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

  • substeps_per_frame (int) – Number of simulation steps taken per frame.

  • solver_iters (int) – Number of constraint solver iterations made per simulation step.

  • verbose (bool) – If True, more details during the physics simulation are printed.

Return type:

dict

Returns:

A dict containing for every active object the shift that was added to their origins.

blenderproc.python.object.PhysicsSimulation.simulate_physics_and_fix_final_poses(min_simulation_time=4.0, max_simulation_time=40.0, check_object_interval=2.0, object_stopped_location_threshold=0.01, object_stopped_rotation_threshold=0.1, substeps_per_frame=10, solver_iters=10, verbose=False)[source]

Simulates the current scene and in the end fixes the final poses of all active objects.

The simulation is run for at least min_simulation_time seconds and at a maximum max_simulation_time seconds. Every check_object_interval seconds, it is checked if the maximum object movement in the last second is below a given threshold. If that is the case, the simulation is stopped.

After performing the simulation, the simulation cache is removed, the rigid body components are disabled and the pose of the active objects is set to their final pose in the simulation.

Parameters:
  • min_simulation_time (float) – The minimum number of seconds to simulate.

  • max_simulation_time (float) – The maximum number of seconds to simulate.

  • check_object_interval (float) – The interval in seconds at which all objects should be checked if they are still moving. If all objects have stopped moving, then the simulation will be stopped.

  • object_stopped_location_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

  • object_stopped_rotation_threshold (float) – The maximum difference per second and per coordinate in the rotation Euler vector that is allowed such that an object is still recognized as ‘stopped moving’.

  • substeps_per_frame (int) – Number of simulation steps taken per frame.

  • solver_iters (int) – Number of constraint solver iterations made per simulation step.

  • verbose (bool) – If True, more details during the physics simulation are printed.