# Volume preserving procedural mesh deformation

I'm having difficulties trying to create a procedural mesh that deforms on impact. The deformation is meant to look and feel like metal when it is being forged. Since this is less of an aesthetic feature and more of something that would affect gameplay directly, it needs to be somewhat accurate. This means that volume of the mesh should be preserved (at least visually) such that the mesh does not gradually get too much smaller.

What I have tried:

1) Applying force on every vertex, based on the force and distance from impact point

foreach (Vector3 vertexPos in vertexList)
{
vertexPos += (force / distanceToImpactPoint.sqrMagnitude) * impactDir;
}


This led to the entire mesh gradually becoming smaller (as mentioned earlier)

2) Take into account the dot product between the impact direction and vertex normal for each vertex, as well as lerp between impact direction and normal (to simulate sides of objects bulging out when compressed

foreach (Vector3 vertexPos in vertexList)
{
float attenuatedForce = (force / distanceToImpactPoint.sqrMagnitude);
float nDotD = Vector3.Dot(impactDir, currVertexNormal);
vertexPos = attenuatedForce * nDotD * Vector3.Lerp(impactDir, currVertexNormal, nDotD);
}


This led to mesh completely splitting apart for anything that has hard shading (as there are duplicate vertices where the edges are, and also artifacts on smooth shaded objects.

Soft Shading (sort of works, but lots of artefacts and not volume preserving)

Also, both methods break completely if force is applied to an edge.

Does anyone know of a more elegant solution to do this?

• Hitting metal works like hitting a liquid with a very very high viscosity (blacksmith lower this viscisity by heating metals up). You could try some sort of fluid simulator algorithm (like Navier-Stokes) and apply force to the "liquid" where you hit it. Mar 28 '17 at 18:22
• @Bálint Fluid simulation using Navier-Stokes would not be able to have physics interactions with external colliders as far as I can tell :( (NVIDIA's implementation on the fragment shader), and a particle based approach I worry might be too computationally demanding, but I will look into. I was hoping for something that affects the mesh directly, such that I can still throw a mesh collider on it Mar 29 '17 at 9:51
• You could look into procedural mesh generation, like marching cubes. That makes you able to throw a meshcollider on iz. Mar 29 '17 at 11:01
• I can post a complete answer if you want. Mar 29 '17 at 11:01
• @Bálint If you can post a complete answer, please do!! That would be much appreciated! Mar 29 '17 at 11:12