Like we did in this part of the tutorial, we will map another model to the simulated mechanical object.
This time, it won't be only a visual model, but a mechanical object which aims at handling the collisions, and to transmit the forces due to the collision response to the simulated object.
Once this model is able to transmit the forces, we just need to add some collision models like we did here
Remember:
Now we need to load the model from a mesh file. As a first example we will use a cube as the collision object.
Next we need a MechanicalObject to store the positions, velocities and forces of the collision object
The collision object is mapped to the simulated deformable model using a Mapping, this time a MechanicalMapping: BarycentricMapping. You may wonder what the difference is between this mapping and the one used for the visual model, as we are using the same component! What makes a mapping visual or mechanical?
This is determined by the template used to create the mapping:
This mean it transforms a state expressed by Vec3d type into Vec3d. Remember, collision models are only expressed in Vec3d type, so the mapped state must be of Vec3d types.
This corresponds to mapping from the MechanicalObject from one node above to the MechanicalObject of the current node.
Finally, we will remove our old TSphereModel, and replace it with one in the CollisionNode
You can see height spheres, corresponding to the height corners of the cube chosen to represent our collision mode. Of course, using four height spheres to do the collision detection is much faster than 171 as in the previous scene. But the behavior is also very different.
You will be able to deform the object. This is due to the MechanicalMapping.
We display some debug information about the mechanical mapping using blue lines. Each point of the collision model depends on several points of the simulated object. If a force is applied to one of the collision model's points, the force will be propagated to all the points that depend on it.