human_front_render.mp4
capbara.mp4
(Actually it is a Minotaur, but Houdini official example misnamed, so do I...😂)
bunny.mp4
ball_99k.mp4
(Red: Ours; Blue: XPBD with same time budget (0.1s). The stiffer, the better.)
The code for SIGGRAPH 2025 paper "MGPBD: A Multigrid Accelerated Global XPBD Solver".
It is a Multigrid solver to solve the stalling issue of XPBD under high stiffness and high resolution.
This code use a python front-end mixed with C++/CUDA back-end. C++/CUDA code is compiled to a dll with CUDA 12, and called by ctypes in python.
SIGGRAPH 2025 presentation
Detailed explaination video in Chinese
My email: li_cl@foxmail.com Feel free to contact me for any questions.
CAUTION: The code is still not well organized and not clean. If it has bugs(highly possible), please let me know.
C++ end
- CUDA 12
- CMake
python end
pip install -r requirements.txt
I only tested it on Windows 10, VS 2022, 4090.
GPU: Any GPU above 8GB VRAM. 40 series GPU (4090,4080,4070, 4060 etc.) will be better.
This is the script to replicate the experiement of Fig. 13 in the paper.
python replicate.py
The results are ply sequence: "result/latest/mesh/XXXX.ply". Also, there is a log file in the root directory will be generated(e.g. "residual_squash_bunnyBig_AMG_2025-08-29-15-23-25.txt").
buildcuda.bat
It will generate cpp\mgcg_cuda\lib\fastmg.dll, which is the C++ back-end.
Run this python script:
python engine/soft/soft3d.py -use_json=1 -json_path='data/scene/bunny_squash/bunny_squash.json'
The expected results of bunny squash case (Fig.13 in paper) will generated in result/latest. You can aslo specify the output directory by -out_dir=xxx. The output meshes are in ply format: 0001.ply, 0002.ply, etc.
There is also a log file (e.g. "residual_squash_bunnyBig_AMG_2025-08-29-15-23-25.txt") generated in the root directory, which contains the residual history (Fig.17 in paper).
Change the values in data/scene/bunny_squash/bunny_squash.json to change the parameters. For example,
"solver_type": "XPBD",
"maxiter":10000,
and re-run the script
python engine/soft/soft3d.py -use_json=1 -json_path='data/scene/bunny_squash/bunny_squash.json'
This will give you the XPBD results showed in Fig.17.
Two ways:
- Just use python argparse, see
common_args.py. It is a bit messy but I have to support it because of backward compatibility. - Use a json file.
-use_json=1 -json_path=xxx. I recommend this way. You can easily change the parameters in json file without changing the code because python can dynamically add new attributes.
For cleanness and smaller repo size, I delete most of models, but only keep the bunny squash and armadillo collision cases. If you want to test all experiments in the paper, please let me know (propose a issue).
Just change "solver_type": "AMG", to "XPBD" and set "maxiter" to 100000. You will see that the XPBD is much harder to converge than AMG under high stiffness (Specify by "mu", the 2nd lame parameter) high resolution. This is due to the stalling issue of XPBD(See paper, the last picture).
In Windows, you should specify the dll directory manually. I use CUDA 12.5, so cuda_dir is set to "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.5/bin". If you use other version, please change it.
Related code(in the common_args.py and init_extlib.py).
parser.add_argument("-cuda_dir", type=str, default="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.5/bin")
...
os.add_dll_directory(cuda_dir)
The models are in tetgen format(.ele and .node). If you use Houdini, there is a hip to generate the tetrahedron mesh.
The python-end is easy to debug.
For C++ end, I recommond to use python c++ debugger, which is a VSCode extension.
It is becuase the pylance does not support the taichi data types, which is not a big trouble but just annoying. Adding the following code to your ./vscode/settings.json to stop the warning.
"python.analysis.diagnosticSeverityOverrides": {
"reportInvalidTypeForm": false
}
In some cases, you should manually set CMAKE_CUDA_ARCHITECTURES based on your GPU.
Change set(CMAKE_CUDA_ARCHITECTURES 89) in cpp/mgcg_cuda/CMakeLists.txt
Run cmake from cpp/mgcg_cuda in cmd(Powershell does not work for set(CMAKE_CUDA_ARCHITECTURES 89).)
I put them to the release page.
For cleanness, I delete most of messy codes in this repo. So some experiments may be missing. I put the old repo here: https://github.com/chunleili/tiPBD/tree/amg.
If you have any questions, please feel free to propose a issue.
