Bullet Softbody Patch

Soft body patches are two-dimensional rectangular meshes, which can be used to simulate for example a flag, a tapestry, or sheets of paper.


Setting up a soft body patch is similar to soft body ropes, but a few extra settings have to be done. The following code will create rectangular path with 31 by 31 segments, and thus 32 x 32 nodes.


First we have to configure the soft body world properties, like we did for soft body ropes too. Next we define variables for the resolution in x- and y-direction, and for the four corner points of the patch.

The variable fixeds is set to the value 1+2+4+8=15, meaning that the patch should be attached to the world on all four corners. To attach it to the first and third corner (diagonal) we would set the value to 1+8=9, and to not attach it at all we would set it to 0.

Now we can create the soft body node using the factory method makePatch. The following configuration differs from what we have seen for soft body ropes.

  • First we create an additional material attached to the soft body. Initially a soft body has already one material, but for this example we want a second one.

  • On the material we set the linear stiffness, and the create bending constraints for this material.

  • Finally we choose a value of about the grid spacing for the soft bodies margin. Other bodies colliding with the soft body could fall through in between the nodes if the value is too small, and if it is too large they will already collide with the soft body when still noticeably far away.


In order to have a visual representation of the soft body patch we need a GeomNode. Panda3D’s Bullet module has a helper method which will do the work for us. The following code snippet shows how use this helper method.


The third parameter to makeGeomFromFaces is set to True, making the created geometry be two-sided. If set to False we would get a one-sided geometry, which might be enough, depending on your requirements.

So far the generated geometry has no texture and no texture coordinates. But the texture has already a column for texcoords, so we just need to write texcoords using a GeomVertexRewriter. The following code shows a convenience method which will do this for us.


Note: It is also possible to render soft body patches using a NurbsSurfaceEvaluator and SheetNode, but results are usually better when rendering patches directly, that is using linked Geom.