Skip to content

andywiecko/PBD2D

Repository files navigation

PBD2D

Unity package for Position Based Dynamics in two dimensions.

Warning

The package is in a preview state. The API may change without advance notice. Production usage is not recommended.

Build Tests openupm

The package provides an implementation of position based dynamics (PBD) 1 2 3 using HPC# (via Burst compiler) including extended position based dynamics (xPBD) 4, shape-matching 5, and various collision algorithms with a basic friction model 6. There are also upcoming features regarding one-dimensional structures (rods) 7 8 and fluids 9 with soft bodies coupling.

Check out Matthias Müller's YouTube channel 10 Minute Physics for the great tutorial about PBD-related topics!

Package summary:

  • (Extended) position based dynamics, including:
    • edge length constraint
    • triangle area constraint
    • shape matching constraint
    • stencil bending constraint
  • Collision systems:
    • point-line
    • capsule-capsule
    • point-trifield
  • Generating simulation bodies using sprites.
  • Mouse interaction (translation, rotation)
  • Entities:
    • edgemesh
    • trimesh (triangle mesh)
    • ground
    • points locker
    • point point connector

Gallery

demo-01 demo-02

demo-03 demo-04

demo-05 demo-06

demo-07 demo-08

demo-09 demo-10

One can play the presented demos here. See PDB2D-examples github repo for source codes and scenes.

Warning

Currently, Burst compiler is not supported with WebGL. Demo scenes are for preview only. Performance may be limited in web builds.

Table od Contents

Getting started

Install the package using one of the following methods

Using scoped registry (recommended) Use OpenUPM CLI or add corresponding entries to the project's manifest.json manually. Add or modify scoped registries in the manifest
  "scopedRegistries": [
    {
      "name": "OpenUPM",
      "url": "https://package.openupm.com/",
      "scopes": [
        "com.andywiecko"
      ]
    }
  ]
and in the dependencies provide selected version of the package
"dependencies": {
    "com.andywiecko.pbd2d": "0.2.0",
    ...
See Unity docs for more details https://docs.unity3d.com/2021.1/Documentation/Manual/upm-scoped.html
git install Use package manager via git install: https://github.com/andywiecko/PBD2D.git#v0.2.0
Manual instalation Clone or download this repository and then select package.json using Package Manager (Window/Package Manager).

See the example project here. To run your first simulation with PBD2D follow the steps presented in TUTORIAL.md.

Architecture

The project architecture is based on the custom ECS pattern and it uses andywiecko.ECS as the implementation of the core engine.

The package consists of three main assemblies:

Below one can find a dependency graph for the main project assemblies.

%%{init: {"theme": "neutral", "flowchart": {"curve": "stepBefore", "useMaxwidth": false}}}%%

graph TB
b <--- a
c <--- a

a[Core]
b[Components]
c[Systems]

click a href "andywiecko/PBD2D/tree/main/Runtime/Core"
click b href "andywiecko/PBD2D/tree/main/Runtime/Components"
click c href "andywiecko/PBD2D/tree/main/Runtime/Systems"
Loading

Preview for upcoming features

  • Position based fluid

fluid-one-sided fluid-two-sided

Roadmap

v1.0.0:

  • TriMeshSerializedDataTriangulatorPostprocess (triangulate TriMeshSerializedData).
  • Reimport and refactor rod structure.
  • Reimport and refactor position based fluid.
  • Destructible bodies (removing points/triangles during runtime).
  • Refactor collision component and introduce collision layers.
  • GC alloc free component iterators for system scheduling.
  • TriMesh self collisions (external points/bvt/collisions).
  • Connectors and lockers.
  • Shape matching clusters.
  • Use dynamic bounding volume tree for scheduling the collision pairs.
  • Investigate performance with combined dependencies.
  • Fluid "fancy" shader.

v2.0.0:

  • (Smooth) cuttable bodies (adding points/triangles during runtime).
  • Continous collisions.
  • Position based rigid bodies
  • Sign distance field collisions.
  • GPU fluids.
  • Position based "smoke".

Known Issues

  1. Bending constraint may cause simulation instabilities when stiffness/compliance is too large.
  2. Hard locks do not support shape-matching constraints.
  3. EdgeMeshRenderer does not update after serialized data change.

Dependencies

Bibliography

Footnotes

  1. M.Müller, B.Heidelberger, M.Hennix, and J.Ratcliff, "Position based dynamics," J. Vis. Commun. Image Represent., 18, 2 (2007).

  2. J.Bender, M.Müller, and M.Macklin, "A Survey on Position Based Dynamics," EG '17: Proceedings of the European Association for Computer Graphics: Tutorials (2017).

  3. J.Bender, M.Müller, M.A.Otaduy, M.Teschner, and M.Macklin, "A survey on position‐based simulation methods in computer graphics," Computer Graphics Forum, 33:228-251 (2014).

  4. M.Macklin, M.Müller, and N.Chentanez, "XPBD: position-based simulation of compliant constrained dynamics," Proceedings of the 9th International Conference on Motion in Games (2016).

  5. M.Müller, B.Heidelberger, M.Teschner, and M.Gros, "Meshless deformations based on shape matching," ACM Trans. Graph. 24, 3 (2005).

  6. M.Macklin, M.Müller, N.Chentanez, and T.-Y.Kim, "Unified particle physics for real-time applications," ACM Trans. Graph. 33, 4 (2014).

  7. U.Nobuyuki, R.Schmidt, and J.Stam, "Position-based elastic rods," SIGGRAPH '14: ACM SIGGRAPH 2014 Talks, 47, 1 (2014).

  8. K.Tassilo, and E.Schömer, "Position and orientation based Cosserat rods," Eurographics/ ACM SIGGRAPH Symposium on Computer Animation, (2016).

  9. M.Macklin, and M.Müller, "Position based fluids," ACM Trans. Graph. 32, 4, 104 (2013).