Skip to main content

soft_body_sets

Like the rigid-bodies and the colliders, the soft-bodies of a simulation are stored inside of a set: the SoftBodySet, given by PhysicsWorld.soft_bodies. The examples of this page use the PhysicsWorld, which owns all the sets of one simulation, but the sets can also be used directly (a PhysicsPipeline then simulates the soft-bodies of the set given as its soft_bodies argument). Note that the insertion of a soft-body (SoftBodySet.insert) needs the rigid-body set and the collider set as well, because a soft-body owns the rigid-body standing for it and the colliders of its surface:

# The sets can also be used directly, without the `PhysicsWorld` façade.
soft_body_set = rp.SoftBodySet()
rigid_body_set = rp.RigidBodySet()
collider_set = rp.ColliderSet()
rope = rp.SoftBody.rope((0.0, 3.0, 0.0), (2.0, 3.0, 0.0), 20)
rope_handle = soft_body_set.insert(rope, rigid_body_set, collider_set)
soft_body = soft_body_set[rope_handle]
assert soft_body.num_particles == 20
# The state of the body as a whole.
print("Mass:", soft_body.mass, "center of mass:", soft_body.center_of_mass)
print("Sleeping:", soft_body.is_sleeping)
# Every soft body of the set.
for handle, soft_body in soft_body_set:
print(handle, soft_body.num_particles)

The set supports len(), in, indexing by a SoftBodyHandle, and iteration over (handle, soft_body) pairs. The SoftBody objects it gives are live views: reading or modifying one of them reads or modifies the soft-body stored in the set, and using one of them after its soft-body was removed raises an InvalidHandle error. On the other hand, the objects describing its particles, elements, and clusters (e.g., the SoftBodyParticle given by particle) are snapshots, which don't follow the simulation.

The state of the body as a whole can be read at any time as well: its number of particles (num_particles), its total mass (mass), its mass-weighted center of mass (center_of_mass), the volume it currently encloses and its rest value (volume, rest_volume), and whether it is sleeping (is_sleeping, see also wake_up). A soft-body can also be disabled until it is enabled again with set_enabled. Conversely, the soft-body a rigid-body stands for (its root body, or the proxy of one of its clusters) is given by the soft_body property of that RigidBody, which is None for any other rigid-body.