Bullet Softbody Triangles¶
Soft bodies made from triangular meshes are similar to soft body patches. just that they are not restricted to rectangular meshes; any two-dimensional triangle mesh will do. An interesting use case for such a soft body is a triangular mesh which is closed. Bullet supports simulation of a pressure for the volume captured inside such a soft body.
The following code snippet shows how to setup an gas-filled soft body. Instead
of defining the triangle mesh ourselves we use the convenience method
makeEllipsoid, which returns a ready-to-use soft body with the shape of an
ellipsoid. The last parameter to this convenience method is the “resolution” of
the ellipsoid. The soft body will have more faces if raising this value.
Increasing the value will make the soft body more realistic, but it also
requires more performance to simulate the soft body.
When comparing the soft body setup with the previous page, the soft body patch setup, we will find that there are two differences:
First, there are three lines which get the configuration objects for this soft body (
getCfg), and then set different parameters on this configuration object, in particular the “pressure coefficient”. For more detailed information on what these parameters do it is best to fall back to the original Bullet documentation. A mapping between the original Bullet members of the btSoftBodyConfig class and the Panda3D BulletSoftBodyConfig object returned by
getCfgis given on the manual page Bullet Softbody Config.
Second, the method
setPoseis called. This method sets the current state of the soft body as a “default pose” or “lowest energy state”. The soft body will try to return to this state if possible. The first parameter to this method is the volume flag, and the second parameter the frame flag. It is usually the best thing to set both flags to
Again, in order to have a visual representation of the soft body we need a
GeomNode. We can use almost the same code as we have been using for soft
body patches. The only difference is that we don’t need to make the created
geometry two-sided, since the inside of the closed mesh is usually not visible.