Particle Connect with Distance and Density Control

On September 26, 2013 by jw

This is a simple MEL script that draws a line between two particles if their distance is less than a user defined value. I added a density control to reduce the amount of duplicate connections by skipping particle distance checks. This increases execution speed but reduces accuracy.



I started to sketch out the logic. The pseudo code on the right hand side is what I ended up going with.


The logic is a simple nested for loop that checks the distance of the current particle to all other particles in the system. This happens for every particle in the system on any given frame. If the distance is less that the user defined threshold, a linear two point NURBS curve is drawn between the two particles. This happens on every frame. A visibility key is set to only display the current frame’s calculated connections.

Here is main loop:


I made a GUI to help the user dial in the desired distance and density variables. The current frame connections can be drawn and deleted. Every frame within the range slider can be drawn and deleted.





Finally I added curve render attributes for rendering with Arnold


The idea for this script came to me while researching fluid solvers written in Processing. Some great examples like this can be found at BlueThen.
Here are two ideas for optimizations to reduce file size and execution time.
Currently this script creates duplicate connections resulting with lines on top of lines. Adding a check to prevent duplicate connections will lighten the scene by reducing the amount of lines drawn. It may or may not reduce execution time.
Spatial partitioning will reduce the total amount of distance calculations needed for accurate results. Instead of checking every particle in the system this optimization will only check particles within a defined partition. A 3d fluid container could define a set of spatial partitions. Then each particle will only calculate the distances from itself to the other particles within its partition.

Leave a Reply

Your email address will not be published. Required fields are marked *