### Creation of a Scene (5/9)

Description

In this step we will use a visual model to represent our deformable object. Nevertheless, you must keep in mind that it will only be a visual representation. The computational work will be done on the particles you are not used to seeing.

Key points

Add a GNode to the Object node. Rename this node "VisualNode".

We added a Node that will contain our Visual Model. Next, we move our Visual Model from the root level to the VisualNode.

Select the OglModel in the Modeler's scene graph. Press the Copy button, found in the Modeler toolbar, 4th from the left. Select the VisualNode, and press the Paste button, found to the right of the Copy button. Right click the original OglModel, and select Delete.

Now to make the link between the deformation of the simulated particles and a given visual model, we need a mapping. As we only need to update the positions of the visual model at each time step, we will use a Visual Mapping: BarycentricMapping.

Here we really need to pay attention to the template used for this component.

Open the OglModel properties and go to the Infos tab.

Under instance, you can see that the Template is ExtVec3f. This means we need our BarycentricMapping to map from Vec3d (the template used by the MechanicalObject) to ExtVec3f.

Find the BarycentricMapping component using the Filter. Be sure that the template information to the right reads Vec3d, ExtVec3f. If it doesn't, choose that combination from the drop down menu. Add this component to the VisualModel node.

Edit the properties of the BarycentricMapping, and open the Property 2/2 tab. Change Input object to map from @ to "@..".

This refers to the MechanicalObject placed in the node above (Object node)

Change Output object to map to "@Objective".

This refers to the OglModel that we named Objective earlier

Result

Run in SOFA and animate

Now not only are the particles of the grid deformed, but this deformation is propagated to the visual model, which remains embedded inside the grid at all times.

Related

As you may have noticed, the visual model is fully independent from the simulated model: We used the same model to create the deformable grid as we did to create the visual model, but nothing stops you from using a different model. Change the visual model or the model used in the SparseGridTopology and see the effect.

To understand how the barycentric mapping works, display the Visual Mappings debug information in the SOFA main application. You will see how each point of the visual model depends on some of the points of the mechanical model.

### Previous ____________ Next