Roberto Toro, March 2019, modified by Barry Becker, 2025.
This is a javascript version of the awesome implementation in 88 lines of c++ of the Moving Least Squares Material Point Method, by Yuanming Hu.
The original repository is https://github.com/yuanming-hu/taichi_mpm, and the c++ code can be directly downloaded from http://bit.ly/mls-mpm88. This link contains 2 files: taichi.h
, with linear algebra and helper functions; and mls-mpm88.cpp
with the actual implementation of the material point method.
In this javascript version, the linear algebra functions are in the algebra.js
file, and the MPM code in MpmSimulation.js
file (with the 88
removed).
A main tricky thing in the translation, which still is not completely solved, is that matrices in Taichi are coded transposed. In the translation, there's still a mix of functions that work transposed (svd, polar_decomp, mulMatVec), and those that don't. That makes some parts of the code a bit convoluted. Ideally, I'd like to move all the code to standard non-transposed matrix encoding.
- Consistent matrix encoding
- have user interaction with the live simulation. Perhaps a block controlled by the mouse cursor
- web workers
- more robustness/stability
- add interactive firehose or dropper
- Thanks to Yuanming Hu for making the C++ code available and for help on understanding it.
- Thanks to Kevin Chapelier for making the javascript code x5 faster and reducing the initialisation from several seconds to barely noticeable.