Gravity Modeling in Flex

I have flex 023 and am wondering if it would be possible to extend the API to support gravitational forces between the particles. This would allow me to use flex simultaneously for fluid dynamics (a certain set of particles) and gravitational dynamics (another set of particles). The way I understand SPH and the calculation/interaction of forces, this shouldn’t be too difficult an issue to add. At the worst case, Handling the forces myself and just providing an API to add forces to particles would be nice. Does anyone know of a way to do this currently? From the API reference I’ve found no solution.

There is no way to do that currently. Gravity is a long-range force, meaning that all particles in the scene would interact with each other. This would be very expensive, currently the particles only interact with a few neighbors.

Thanks for your response! If it is acceptable to the user/developer, we could specify a range over which the gravitational forces are integrated into the simulation(similar to the effective range of SPH interactions). I know some gravitational simulations use this technique already, though I agree it is not the preferred method. Alternatively, being able to apply external forces to the particles directly could be used to achieve gravitational dynamics on a subset of particles.

I know that we can define meshes which the particles interact with; in principle I should be able to just define my gravitational particles as a mesh and perform my gravitational dynamics on these objects myself; but that requires writing the simulation code for it or fully incorporating the rest of PhysX to perform it for me.

Perhaps I’m missing something, but adding an API to apply forces directly to specific particles (similarly to how it is possible in PhysX), shouldn’t alter the code too much (since indirectly it is already possible) and would allow for more robust simulations I believe. It would provide me the same capability for gravitational dynamics that PhysX provides, while simultaneously providing the more efficient SPH and multi-domain simulation that flex provides.

Again, please correct me if I’m missing something conceptually!

“Perhaps I’m missing something, but adding an API to apply forces directly to specific particles”

Have you tried the Spring constraints? From the 025 guide:

1.4.2 Springs
Springs in Flex are specified as pairs of particle indices, a rest-length, and a stiffness coefficient. They
are not a spring in the classical sense, but rather a distance constraint with a user-specified stiffness.
The index pairs should appear consecutively, for example the following example code sets up a chain of
particles with each edge 1 unit long, with a stiffness coefficient of 0.5:
int springIndices = { 0, 1, 1, 2, 2, 3 }
float springLengths = { 1.0f, 1.0f, 1.0f }
float springCoefficients { 0.5f, 0.5f, 0.5f }
flexSetSprings(solver, springIndices, springLengths, springCoefficients, 3);
Distance constraints are incredibly versatile, and relatively cheap to solve. When combined with dynamic
topology changes they can model interesting effects such as tearing, merging.

Hmm, so if I understand you correctly, you’re essentially saying to set the spring coefficients equal to the gravitational force premultiplied by the inverse of the distance between the two particles. That should be fine I suppose and I will try that, thanks.

In a related note, the download page I was emailed when I was admitted to the program for FLEX has not been updated to include the 025 binary or documentation; my download page still only has the 023 zip with the docs and binaries. I’m not sure what the difference is, but I know that the manual provided with the 023 release does not have a section 1.4.2 at all. Section 1.4 is practically empty (containing only 2 images and nothing else.)


We’ll be posting a new FleX build this week or next week (0.8, would have been called 026 but we changed the numbering to make it consistent with other GameWorks modules).