PositionBasedDynamics

repository·master·Indexed 24 days ago

https://github.com/interactivecomputergraphics/positionbaseddynamics

A high-performance C++ and Python library for physically-based simulation using position-based methods (PBD and XPBD). It provides stable and fast simulations for rigid bodies, deformable solids, fluids, and elastic rods, suitable for interactive applications like games and VR. Features include cubic signed distance fields for collision detection, support for various joints and motors, and a Python interface called pyPBD.

Tokens
15.4K
Snippets
42
Records
84
Agent score
80%

What's inside PositionBasedDynamics

  1. Overview of Position Based Elastic Rods Demo

    master

    This demo provides an implementation of the 'Position Based Elastic Rods' paper (Nobuyuki Umetani et al., 2014) for the Position Based Dynamics library. It simulates elastic rod behavior using position-based methods.

    Reference Paper: http://www.nobuyuki-umetani.com/PositionBasedElasticRod/2014_sca_PositionBasedElasticRod.html

    This specific implementation is based on work by Przemyslaw Korzeniowski.

  2. Overview of PositionBasedDynamics capabilities

    master
    PositionBasedDynamics is an open-source library designed for physically-based simulation of mechanical effects. Unlike classical force-based methods, it computes position changes directly by solving a quasi-static problem. This makes the simulation fast, stable, and controllable, which is ideal for interactive environments like virtual reality, computer games, and special effects, though it prioritizes visual plausibility over absolute physical accuracy.
  3. Overview of PositionBasedDynamics features

    master

    PositionBasedDynamics is a library for physically-based simulation of mechanical effects using (eXtended) position-based constraint handling. It is designed to be fast, stable, and controllable, making it suitable for interactive environments like VR, games, and special effects.

    Key Capabilities:

    • Collision Detection: Uses cubic signed distance fields for collision detection.
    • Constraint Support:
      • Elastic Rods: bend-twist, stretch-shear, and Cosserat constraints.
      • Deformable Solids: point-point/edge/triangle distance, edge-edge, dihedral/isometric bending, volume constraints (PBD & XPBD), shape matching, FEM-based PBD, and strain-based dynamics.
      • Fluids: Position-based fluids.
      • Rigid Bodies: Contact constraints, various joints (ball, hinge, universal, slider, damper, etc.), and motors.
    • File Support: Supports PLY files, OBJ export, and JSON-based scene loading.
    • Licensing: The library is free for commercial applications (MIT License).
  4. What is pybind11?

    master
    pybind11 is a lightweight, header-only C++ library designed to expose C++ types in Python and vice versa. It is primarily used to create Python bindings for existing C++ code. It aims to minimize boilerplate by using compile-time introspection to infer type information, similar to Boost.Python but without the heavy dependency on the Boost libraries. It requires C++11 or newer and works with CPython (3.8+), PyPy, or GraalPy.
  5. How hapPLY's core abstractions work

    master

    The library is centered around the happly::PLYData class, which represents a collection of elements and their associated properties.

    • Elements: The primary containers in a PLY file (e.g., vertex, face).
    • Properties: Data associated with elements (e.g., x, y, z, color, or vertex_indices).
    • Type Promotion: When calling getProperty<T>, hapPLY automatically promotes numeric types if possible (e.g., reading a float as a double).

    Errors are communicated via C++ exceptions. While the library performs basic sanity checks, it does not guarantee robustness against malformed input.

  6. Advanced pybind11 features and 'Goodies'

    master

    Beyond core binding, pybind11 offers several advanced capabilities:

    • Lambda Support: Bind C++11 lambda functions with captured variables; the capture data is stored in the resulting Python function object.
    • Efficient Data Transfer: Uses C++11 move constructors and move assignment operators to transfer custom data types efficiently.
    • Buffer Protocol: Easily expose internal storage of custom types to Python's buffer protocol, enabling fast conversion between C++ matrix classes (like Eigen) and NumPy without expensive copies.
    • Vectorization: Automatically vectorize functions to apply them transparently to all entries of one or more NumPy array arguments.
    • Slice Support: Support Python's slice-based access and assignment with minimal code.
    • Pickling: C++ types can be pickled and unpickled like regular Python objects with little extra effort.
    • Header-only: Everything is contained in a few header files; no additional libraries need to be linked.
  7. Use or Install Python Bindings (Linux/Windows)

    master

    Using Bindings

    If you have generated the bindings (e.g., .so on Linux or .pyd on Windows), you can use them by adding their directory to sys.path in your Python script. To verify the installation, run:

    cd lib
    python3 -c "import pypbd"

    Installing Bindings via Wheel

    To install the bindings as a package, run the following from the project root. It is recommended to use a virtual environment.

    python setup.py bdist_wheel
    pip install build/dist/*.whl

    Quick Install via Pip

    You can install directly from the Git repository using pip, though this prevents incremental rebuilds if you modify the source:

    pip install git+https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git
  8. Install pyPBD Python bindings

    master

    To install the pypbd Python bindings, it is highly recommended to use a virtual environment.

    1. Create a virtual environment

    Using conda:

    conda create --name venv python=3.7
    conda activate venv

    Using virtualenv:

    python3 -m virtualenv venv --python=python3.7
    source venv/bin/activate

    2. Clone the repository

    git clone https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git

    3. Install via pip

    Important: You must call pip install from the directory above the cloned PositionBasedDynamics folder, and you must include the trailing slash to prevent pip from attempting an unsupported remote download.

    pip install PositionBasedDynamics/

    4. Verify installation

    python -c "import pypbd"

    Note: You may need to install numpy manually if it is not already present:

    pip install numpy
    pip install PositionBasedDynamics/
  9. Install and use hapPLY

    master

    hapPLY is a header-only C++ reader/writer for the PLY file format. Because it is header-only, you can use it by simply dropping happly.h into your project and including it in your source files.

    It supports both plaintext (ASCII) and binary variants of the PLY format using a unified API and provides automatic type promotion (e.g., reading a float field as a double).

    #include "happly.h"
  10. Run PositionBasedDynamics demos on Linux

    master

    Demos are located in the bin directory. You can run them directly or load a specific JSON scene file.

    On some systems, you may need to provide an OpenGL version override to ensure compatibility:

    cd ../bin
    MESA_GL_VERSION_OVERRIDE=3.3 ./SceneLoaderDemo ../data/Scenes/CarScene.json

    Once the scene is loaded, press [Space] or click the checkbox to disable pause mode and start the simulation.