I was thrilled to see a post by Long Nguyen over the weekend announcing his publication of a Dynamo package called WhatTheFlock – with full source code – that implements a Boids-like flocking simulation. This work is significant not because ornithologists will use Dynamo to predict or simulate murmurations (although that in itself is a fun thought) but because Long has demonstrated a valuable technique that might be used to implement other arguably more useful types of multi-agent simulation inside Dynamo.
Long is using a background process to perform calculations before rendering the results into the Dynamo window. A really useful and interesting pattern.
My first thought on seeing the flocking agents placed randomly in a cube was “wouldn’t it be cool to be able to set their positions from a point cloud?” I could just imagine scans of spaces erupting into flocks of birds. Again, not especially useful, but lots and lots of fun.
I posted the suggestion in a comment and Long was quick to implement the ability to specify initial agent positions and directions in v 1.0.1 of the package.
I dusted off some code that Rhys Goldstein had originally written to read in points from an ASCII-based PTS file (one of the simpler but least efficient point cloud formats) and used that to read in the initial locations from a classic sample point cloud of the Stanford bunny. I integrated this into the sample WhatTheFlock.dyn file Long provided with the package.
This was a good start – and it worked well enough with this file – but I really wanted something more “architectural”. The best I could do at short notice was to translate an e57 file of an outdoor oven into a PTS file. Here’s the original file, loaded into CloudCompare:
I could then save it as a space-separated PTS file that could be read into Dynamo.
If you want to see how the package works with these two point clouds without trying it for yourself, here’s a video I recorded.
Here’s a ZIP file containing the two point cloud files along with the Dynamo graphs that load and run them (they should just work if you extract them to the same folder). The oven model weighed in at a whopping 192 MB when uncompressed, which means the archive is chunkier than it otherwise might be at a little over 60 MB. The graphs are basically the same but have different options for the two files: for instance, you’ll see some logic in the graph that helps chooses a subset of the point cloud to extract – otherwise the number of points is too high – but you can play with the sliders to get things working well for you on your system.
As I mentioned at the start of this post: this approach has great potential to be used for integrating other types of simulation into Dynamo. I fully expect us to use this approach when representing results of spatial analyses performed using VASA, for instance. Many thanks to Long for this valuable contribution to the Dynamo community!