While the components provided in the Unity plugin cover the vast majority of Dynamo SDK use cases, in some cases it may still be necessary to do some C# scripting to get the most out of some of the features. Guides on how to use these features with the DeformDynamics namespace are presented below.
The force field demo available in Deform Dynamics/Scenes/Demos/ForceField shows how a custom force field can be used to create a slowly moving sine wave and how to add impulses to random vertices on the cloth. The script used to create the force field is called DeformForceField, and is attached to the DeformManager object in the ForceField scene.
Force fields are defined as an array of 3d vectors with a size that is equal to the total number of simulated vertices. To retrieve the number of simulated vertices, the DeformPlugin.GetNumVertices() function is used. In the script, this function is called to be able to initialize the forces array, which is then passed to the Dynamo SDK to update the force field every time the simulation is updated.
To create impulses on a random vertex when the user presses the 'F' key, a random index is first found, and the y-value of the force at that index in the forces array is set to a value of 10000. The force field is then updated using DeformPlugin.SimulationParameters.SetForceField(forces).