Creation of a Scene (7/9)


Description

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:

Key points

Add a new GNode to the Object node, and rename it "CollisionNode".

Now we need to load the model from a mesh file. As a first example we will use a cube as the collision object.

Add a MeshTopology to the CollisionNode, and change the Filename of the mesh to /mySofaDirectory/Sofa/share/mesh/cube.obj.

Next we need a MechanicalObject to store the positions, velocities and forces of the collision object

Add a MechanicalObject to the CollisionNode. Change the Scale of the DOFs in 3 dimensions property to "(6 6 6)".

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:

Find the BarycentricMapping component using the Filter. From the dropdown menu, select Vec3d, Vec3d.

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.

Open the BarycentricMapping properties and go to the Properties 2/2 tab. Set the Input object to map to "@.." and the Output object to map to "@."

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

Delete the current TSphereModel. Add a new TSphereModel to the CollisionNode, and change the Default contact stiffness property to "1000".


Results

Run in SOFA. Change to DT to "0.005". Animate.

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.

Apply a force on one of the spheres by holding down the Shift key, and clicking and dragging a sphere with the mouse.

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.


Previous ____________ Next