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.
The MAGES SDK supports real time soft bodies as a part of its standard features
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).
Exporting the model from Maya
Soft body setup
Run-time and interaction
Exporting the model from Maya¶
The image below shows the 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.
Then export the model using the FBX format.
When you import the model to Unity make sure you check the following parameters:
Mesh compression should be off
Read/Write Enabled should be checked
Set Optimize Mesh to Nothing.
Set Normals to Calculate.
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.
Drag and drop your FBX model in the unity scene. In this example I will be using the Stanford bunny model.
Right click on the object in hierarchy and unpack the prefab completely. Then attach the SpringMassSoftbody script to it.
The initialization process consists of 2 steps:
Initialization of the Softbody
Saving the generated mesh and object for future use.
We will see more details for each step below.
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.
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.
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)
Here are all the settings used for the Bunny Model:
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:
We select the folder we want to save the mesh, fill the name of the mesh asset and press Save.
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.
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.