Falling Sand

Published on Sunday, 15. May 2022

You know how it is1. You are saying you want to get serious about writing again, that you want to spend more time working on your blog. But while thinking about this week's post, a friend of your sends you an article about creating a particle-based sand simulation. Without thinking too much about it, you start to recreate it in 3D with Bevy, a game engine you wanted to try out for a long time. And suddenly, it's the end of the week and you sit in front of a bit of Rust code, desperately trying to turn it into something to write about.

This is exactly the situation I'm in now. It's not that there isn't anything I could write about. In fact, there are many things. For example, I could recreate the post this project was based on. I could explain what I did to write the simulation, and how it works. This feels disingenuous. The only big change I made was to write the simulation in 3D. But extending the general idea to work with an additional dimension is trivial. And making my post as educationally valuable as the original takes much more work than I am willing to spend on it. So, just go read the original. It's excellent.

I could also write about what I learned from building this simulation. Because it was a great project to go beyond Bevy's getting started guide. But as with all first projects, the project in itself has been simple. Yes, there are a few things I spend much more time on than necessary, which I could relay here (for example how to render a transparent object2). But the learning was more about developing a feel for how working with Bevy looks like. And even though it is still in early development, the team behind it already compiled great resources to learn about it. Everything I could write about is much better explained there.

There are other things I could write about that only have tangentially to do with this project. I could write about the Pareto principle, and about how most of my time went into researching the wireframe rendering I didn't use in the end, positioning the camera, and figuring out how to export the project for the web instead of actually writing the voxel simulation. I could write about the value of looking at a problem with fresh eyes after a good night's sleep. How I, already exhausted, looked into host the web build with nginx. And how I came back the next morning and figured out how to integrate it in this post directly, making the setup more resilient.

I could write about lucky coincidences in the creative process, using the final product as a springboard. Originally I had planned to have an interactive plane hovering on top of the scene. This, however, felt wonky. So I moved the plane to the bottom of the coordinate system. Because I didn't like the result of rendering the plane as a wireframe I had changed it to a semi-transparent plane earlier. And because a small inconsistency in how the voxel positions are calculated (their coordinates are based on the bottom left corner of the cube, but their graphical representation is aligned to their center), the plane and the cubes overlapped. This reminded me a bit of an ocean to place sand islands in and is the final result you are now seeing. But all these topics are not enough to fill a whole post.

This leaves me with a fun project I don't know how to tell a story about. That's ok. There are many things worth doing that don't create a great story. It only leaves me in a bit of a predicament because I want to write about it. Which means, that once again, I wrote a post about not knowing what to write about. Maybe the next project I'll pick can be turned in a story by itself. In the meantime, here's the final result. Feel free to click around in it (be patient, it's laggy).

You can check out the code here.

---

1:

By which I mean you probably don't.

2:

Create a PbrBundle with a material instantiated like StandardMaterial { base_color: Color::rgba(...), alpha_mode: AlphaMode::Blend, ..default() }. You're welcome.