Soft Bodies

Upgrading from previous version

The new version of MAGES offers a more stable and easier to use softbody simulation. All the different scripts and versions have been replaced by only one script called SpringMassSoftbody. In order to update from previous version, attach the new script in the original model and use the same values as the old one for each field. More details about each variable can be found below or in the Softbodies manual.

Introduction

softbody teaser clip showing a deformable Stanford bunny

The MAGES SDK supports real time soft bodies as a part of its standard features

Note

Soft bodies are used to simulate soft and deformable surfaces like the human skin, liquids, internal organs, cloths and any other deformable surfaces.

You can read here more information about our soft bodies.

In this tutorial we will demonstrate how to set up the soft body behavior on a human bowel model (small intest and mesenter).

Tutorial overview:

  1. Exporting the model from Maya

  2. Unity importing

  3. Soft body setup

  4. Run-time and interaction

  5. General discussion

Exporting the model from Maya

The image below shows the bowel model in Maya.

bowel model in maya

This model has 5700 vertices. The number of vertices is really important in our soft body system both for the real-time simulation updates and the preload configuration and caching preprocessing time. Both operations (pre-processing and real-time updates) all depend heavily on the number of vertices under processing

Make sure to do a cleanup before exporting the FBX. In the cleanup window select the 4-sided faces, Faces with more than 4 slides and the Nonmanifold geometry.

bowel cleanup in maya

Then export the model using the FBX format.

Unity importing

When you import the model to Unity make sure you check the following parameters:

  1. Mesh compression should be off

  2. Read/Write Enabled should be checked

  3. Set Optimize Mesh to Nothing.

  4. Set Normals to Calculate.

../../../_images/bowel_import.png

If you face any other issues with the model e.g missing vertices when starting the application, consider reviewing those configurations. The underlying geometric topology plays an important role in the final quality of the simulation.

Softbody setup

Drag and drop your FBX model in the unity scene. In this example I will be using the Stanford bunny model.

Stanford bunny in the unity scene

Right click on the object in hierarchy and unpack the prefab completely. Then attach the SpringMassSoftbody script to it.

../../../_images/SimulationVariants.PNG

The initialization process consists of 2 steps:

  1. Initialization of the Softbody

  2. Saving the generated mesh and object for future use.

We will see more details for each step below.

Initialization

The most important part of this step is to configure the Clustering options consisting of the Particle Distance, the Particle Connection Distance and the Skinning Distance. All the other parameters can be changed on the fly and upon experimenting with the softbody in game.

Note

Particle Distance is the minimum geodesic distance between two particles.

Particle Connection Distance is the max distance two particles can have in order to be connected together. (Meaning that, in game, disturbing one particle will also affect all its connected particles)

Skinning Distance is the maximum distance a vertex can have from a particle in order for it to be affected.

Keep in mind the smaller the particle distance is, the most particles will be created and therefore the simulation, although more realistic, will be more computationally expensive.

Warning

After choosing the desired Particle Distance and Particle Connection Distance we must ensure that all our particles are connected. Too many connections will make the simulation run slower and too little will make parts of the mesh unstable or detach completely.

We can visualize and check our connections by pressing the Show Spring Connections button in the inspector.

If we have now Gizmos enabled we must see a result similar to this. (In order to make lines visible we can disable the mesh renderer of our object temporarily)

../../../_images/ParticleConnections.png

Here are all the settings used for the Bunny Model:

../../../_images/SimulationSettings.png

Upon choosing the appropriate values we must click the Initialize Softbody Button. When the Simulation is Initialized successfully a message will appear in the Console Log. If we need to change the values again we need to press the Reinitialize Softbody Button.

Saving the Softbody

In this step we will save the mesh as an asset and our object as a prefab for later use.

We press the Save Softbody Mesh button. If the mesh is not already saved, this will open the window shown below:

../../../_images/SaveMeshWindow.PNG

We select the folder we want to save the mesh, fill the name of the mesh asset and press Save.

Warning

Keep in mind that the folder you select to save the mesh must either be the Assets folder or a subfolder of it.

We can now simply drag and drop our object in the Assets and create a Prefab. We can later use the prefab as many times as we want without needing Initialization again.

Run-time and interaction

When entering play mode the simulation starts immediately. The user can grab any particle and stretch or hold the object.

General discussion

Soft bodies introduce a powerful way to simulate deformable surfaces. The MAGES SDK offers a plug-and-play solution for particle-based soft bodies in Unity, ideal for medical or any other use.

It is important to consider that real-time soft body simulation uses advanced physics algorithms to calculate the object’s movement per vertex, paying respect to its original shape. This is why you need to be extra careful with the script configuration as well as the model’s topology for best results.