DeformableModel.cs optimization (iMSK-Unity)

Hi again,

I was modifying my code to update tetrahedral and visual meshes ONLY when an interaction (for example Burning) needs it. This means not calling getPhysicsGeometry.extractSurfaceMesh() (That slows my program about 120FPS when calling it on Update) in each frame, so I do it only when an interaction puts a flag on.

Basically, a part from that, I’m using imstkObject.getVisualGeometry() instead of getVisualGeometry() from the visualGeomFilter. So:

Left: old code | Right: new code

Also, don’t forget to call imstkObject.setVisualGeometry(getPhysicsGeometry.extractSurfaceMesh()) to save the new visual geometry.

In conclusion, this allows me to “save” the extracted surface mesh from the tetrahedral one, to use it after this like it wasn’t a dynamical model, to avoid calling every frame the extractSurfaceMesh heavy function.

I just saw it isn’t working. This is causing the mesh to “stop” being simulated, like no collisions, no gravity, no constraints, it’s frozen in the air. I think i will need to use the “extractsurfacemesh” all the frames and this is lowering my project about 70FPS.

The visual geometry filter can’t be used instead ofthe extracted surface mesh because it’s not updated even I try to call “.setGeometry” with the new mesh after modifying the mesh. If I have 500 vertices before cutting and 520 after doing it, visual geometry filter has always 500, and it isn’t updated.

If someone I hope someone knows how to fix it, because I’m in a good way in the mesh modifying and UV generation, I just need to optimize it:

Then, the main problem is the next one:

As I can’t compare vertices indices because iMSTK reuses the deleted vertices and reorder the array to make the “new” modified mesh, I need to compare positions. The problem is that visual geometry filter is not updating ANY information about the new mesh even if I set a new inputMesh, so I can’t compare correctly.

Now I’m comparing vertices with a tolerance, that doesn’t allows me to use a better way like dictionary, that would allow me to use positions as a key.

In conclussion, I need to update the visual geometry filter when the mesh has been modified, to make it return the modified one, to compare it with a possible new modification in the mesh.

In the next images, the white lines are the deleted triangles found between the new modified mesh (cut) and the “GetVisualGeometry” function mesh.

Cutting fist time → New mesh is compared with the visual one, so I can find the created, deleted and common vertices

Cutting second time → For the geometry filter, the last deleted vertices are still part of the mesh, so they are found like deleted ones again