Skip to main content

Physics Based Animation Toolkit

Project description

Physics Based Animation Toolkit

logo

build wheels pbatoolkit downloads GitHub Releases

entei

Overview

We recommend exploring the official CMake documentation to beginner CMake users, if they wish to build this project from source.

The Physics Based Animation Toolkit (PBAT) is a (mostly templated) cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation in dimensions 1,2,3. For most use cases, we recommend using our library via its Python interface, enabling seamless integration into Python's ecosystem of powerful scientific computing packages.

Features

Currently, the master branch may contain breaking changes at any point in time. We recommend users to use specific git tags, i.e. via git checkout v<major>.<minor>.<patch>, where the version <major>.<minor>.<patch> matches the installed pbatoolkit's version downloaded from PyPI (i.e. from pip install pbatoolkit).

Table of Contents

Quick start

We recommend downloading the Tracy profiler server to analyze execution of PBAT algorithms, available as precompiled executable. PBAT currently supports Tracy 0.10.

C++

Take a look at the unit tests, found in the library's source (.cpp or .cu) files.

Python

To download and install from PyPI, run in command line

pip install pbatoolkit

or, alternatively

pip install pbatoolkit-gpu

if your environment is properly setup to use our GPU algorithms.

Verify pbatoolkit's (or pbatoolkit-gpu) contents in a Python shell

import pbatoolkit as pbat # or import pbatoolkit-gpu as pbat
help(pbat.fem)
help(pbat.geometry)
help(pbat.profiling)
help(pbat.math)
help(pbat.gpu)

A bunch of Python scripts demonstrating usage of pbatoolkit can be found in the examples folder, along with their associated requirements.txt for easily downloading necessary dependencies via pip install -r path/to/requirements.txt. Their command line interface follows the pattern

python[.exe] path/to/examples/[example].py -i path/to/input/mesh

The full interface is always revealed by -h or --help, i.e.

python[.exe] path/to/examples/[example].py -h

The examples assume the user provides the meshes to pbatoolkit. Triangle (surface) meshes can easily be obtained via Thingi10K, TurboSquid or authored yourself in Blender. Tools like TetWild, fTetWild and TetGen can then convert them into tetrahedral (volume) meshes. We provide helper scripts to facilitate mesh processing and their associated requirements.txt.

Example results are showcased in our Gallery.

Tutorial

Head over to our hands-on tutorials section to learn more about physics based animation in both theory and practice!

Dependencies

See vcpkg.json for a versioned list of our dependencies, available via vcpkg.

Use of vcpkg is not mandatory, as long as dependencies have compatible versions and are discoverable by CMake's find_package mechanism.

CUDA

PyPI

pbatoolkit-gpu (downloaded from PyPI) requires dynamically linking to an instance of the

Recall that the CUDA Runtime is ABI compatible up to major version.

On 64-bit Windows, these are cudart64_12.dll and nvcuda.dll. Ensure that they are discoverable via Windows' DLL search order. We recommend adding <drive>:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.<minor>\bin (i.e. the binary folder of your CUDA Toolkit installation) to the PATH environment variable. The driver should already be on the search path by default after installation.

On Linux, they are libcudart.so.12 and libcuda.so.1. Ensure that they are discoverable via Linux's dynamic linker/loader. If they are not already in a default search path, we recommend simply updating the library search path, i.e. export LD_LIBRARY_PATH="path/to/driver/folder;path/to/runtime/folder;$LD_LIBRARY_PATH".

MacOS does not support CUDA GPUs.

Our pbatoolkit-gpu prebuilt binaries include PTX, such that program load times will be delayed by JIT compilation on first use. Verify that your NVIDIA GPU supports compute capability at least 7.0. For example, only RTX 2060 up to 4090 chips are supported in the GeForce series. Runtime GPU performance may be constrained by the targeted compute capability.

Local

Consider locally building and installing pbatoolkit against your native GPU for the following reasons.

  • Achieve optimal GPU performance for your platform.
  • Support older/newer GPUs and CUDA Toolkit versions.

Configuration

Option Values Default Description
PBAT_BUILD_PYTHON_BINDINGS ON,OFF OFF Enable PhysicsBasedAnimationToolkit_PhysicsBasedAnimationToolkit Python bindings. Generates the CMake target PhysicsBasedAnimationToolkit_Python, an extension module for Python, built by this project.
PBAT_BUILD_TESTS ON,OFF OFF Enable PhysicsBasedAnimationToolkit_PhysicsBasedAnimationToolkit unit tests. Generates the CMake target executable PhysicsBasedAnimationToolkit_Tests, built by this project.
PBAT_ENABLE_PROFILER ON,OFF OFF Enable Tracy instrumentation profiling in built PhysicsBasedAnimationToolkit_PhysicsBasedAnimationToolkit.
PBAT_PROFILE_ON_DEMAND ON,OFF OFF Activate Tracy's on-demand profiling when PBAT_ENABLE_PROFILER is ON.
PBAT_USE_INTEL_MKL ON,OFF OFF Link to user-provided Intel MKL installation via CMake's find_package.
PBAT_USE_SUITESPARSE ON,OFF OFF Link to user-provided SuiteSparse installation via CMake's find_package.
PBAT_BUILD_SHARED_LIBS ON,OFF OFF Build project's library targets as shared/dynamic.

Either run CMake's configure step manually

cmake -S <path/to/PhysicsBasedAnimationToolkit> -B <path/to/build> -D<option>=<value> ...

or, alternatively (and preferably)

cmake --preset=<my-favorite-user-preset>

Our project provides configuration presets that capture typical use configurations. For the best experience, install vcpkg and set VCPKG_ROOT=path/to/vcpkg as an environment variable. Then, you can select one of our available presets, for example cmake --preset=default. Refer to the CMake presets documentation for more information.

Build & Install

C++

Build and install transparently across platforms using the cmake build CLI and cmake install CLI, respectively.

Our CMake project exposes the following build targets

Target Description
PhysicsBasedAnimationToolkit_PhysicsBasedAnimationToolkit The PBA Toolkit library.
PhysicsBasedAnimationToolkit_Tests The test executable, using doctest.
PhysicsBasedAnimationToolkit_Python PBAT's Python extension module, using pybind11.

For example, to build tests, run

cmake --build <path/to/build/folder> --target PhysicsBasedAnimationToolkit_Tests --config Release

To install PhysicsBasedAnimationToolkit locally, run

cd path/to/PhysicsBasedAnimationToolkit
cmake -S . -B build -D<option>=<value> ...
cmake --install build --config Release

Python

For a local installation, which builds from source, our Python bindings build relies on Scikit-build-core, which relies on CMake's install mechanism. As such, you can configure the installation as you typically would when using the CMake CLI directly, by now passing the corresponding CMake arguments in pip's config-settings parameter (refer to the Scikit-build-core documentation for the relevant parameters). See our pyinstall workflow for working examples of building from source on Linux, MacOS and Windows. Then, assuming that external dependencies are found via CMake's find_package, you can build and install our Python package pbatoolkit locally and get the most up to date features.

Consider using a Python virtual environment for this step.

As an example, assuming use of vcpkg for external dependency management with VCPKG_ROOT=path/to/vcpkg set as an environment variable, run

pip install . --config-settings=cmake.args="--preset=pip-cuda" -v

on the command line to build pbatoolkit from source with GPU algorithms included. Additional environment variables (i.e. CUDA_PATH) and/or CMake variables (i.e. CMAKE_CUDA_COMPILER) may be required to be set in order for CMake to correctly discover and compile against your targeted local CUDA installation. Refer to the CMake documentation for more details.

Gallery

Below, we show a few examples of what can be done in just a few lines of code using pbatoolkit and Python. Code can be found here.

Real-time hyper elasticity dynamics

Our GPU implementation of the eXtended Position Based Dynamics (XPBD) algorithm simulates a ~324k element FEM elastic mesh interactively with contact.

A 162k element armadillo mesh is dropped on top of another duplicate, but fixed, armadillo mesh on the bottom.

Inter-penetration free elastodynamic contact

Combining pbatoolkit's FEM+elasticity features and the IPC Toolkit results in guaranteed inter-penetration free contact dynamics between deformable bodies.

A stack of bending beams fall on top of each other, simulated via Incremental Potential Contact (IPC).

Modal analysis

The hyper elastic beam's representative deformation modes, i.e. its low frequency eigen vectors, are animated as time continuous signals.

Unconstrained hyper elastic beam's eigen frequencies

GPU broad phase collision detection

Real-time collision detection between 2 large scale meshes (~324k tetrahedra) is accelerated by highly parallel implementations of the sweep and prune algorithm, or linear bounding volume hierarchies.

Broad phase collision detection on the GPU between 2 moving tetrahedral meshes

Harmonic interpolation

A smooth (harmonic) function is constructed on Entei, required to evaluate to 1 on its paws, and 0 at the top of its tail, using piece-wise linear (left) and quadratic (right) shape functions. Its isolines are displayed as black curves.

Harmonic interpolation on Entei model using linear shape functions Harmonic interpolation on Entei model using quadratic shape functions

Heat method for geodesic distance computation

Approximate geodesic distances are computed from the top center vertex of Metagross by diffusing heat from it (left), and recovering a function whose gradient matches the normalized heat's negative gradient. Its isolines are displayed as black curves.

Heat source on top center of metagross model Reconstructed single source geodesic distance

Mesh smoothing via diffusion

Fine details of Godzilla's skin are smoothed out by diffusing x,y,z coordinates in time.

Godzilla model with fine details being smoothed out via diffusion

Profiling statistics

Computation details are gathered when using pbatoolkit and consulted in the Tracy profiling server GUI.

Profiling statistics widget in Tracy server

Contributing

Coding style

A .clang-format description file is provided in the repository root which should be used to enforce a uniform coding style throughout the code base using the clang-format tool. Recent versions of Visual Studio Code and Visual Studio should come bundled with a clang-format installation. On Unix-like systems, clang-format can be installed using your favorite package manager.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pbatoolkit-0.0.8-cp312-cp312-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.12 Windows x86-64

pbatoolkit-0.0.8-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pbatoolkit-0.0.8-cp312-cp312-macosx_14_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

pbatoolkit-0.0.8-cp312-cp312-macosx_13_0_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12 macOS 13.0+ x86-64

pbatoolkit-0.0.8-cp311-cp311-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11 Windows x86-64

pbatoolkit-0.0.8-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pbatoolkit-0.0.8-cp311-cp311-macosx_14_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

pbatoolkit-0.0.8-cp311-cp311-macosx_13_0_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11 macOS 13.0+ x86-64

pbatoolkit-0.0.8-cp310-cp310-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.10 Windows x86-64

pbatoolkit-0.0.8-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pbatoolkit-0.0.8-cp310-cp310-macosx_14_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

pbatoolkit-0.0.8-cp310-cp310-macosx_13_0_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.10 macOS 13.0+ x86-64

File details

Details for the file pbatoolkit-0.0.8-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4b7041360b440bfab175ea8375056fe8295624ac351d3bd0007ac6e98e35cb26
MD5 d2c52ba0694ac627dd798dcf1c60574b
BLAKE2b-256 aac25f9e707bae464b2bbd0209e3c624890c433f99465b75b0db40a4c1ba9b4e

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 52483dd5e5964e2e67ea978c88b234a507c51792180b634a55c4659ae1abe0c1
MD5 8d354b10be9bb5e6574eb853b3eecf1e
BLAKE2b-256 b04116af1af15faa51c5926c6fcf06edd2fb217a9af39b54be9855d370b6f007

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c68cfaea8e40229d996300fe546d1e99635dfa956da8e202e2dcea8cc25d1a16
MD5 29554a2ada79be7ac41da83dbe544b3d
BLAKE2b-256 1c7843744ff347b77d5c6bbdc7fca40f1165dff4e4a2869ac5212cd6c6b2bef3

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 30987e92bcd85d373c40e8e11853de7ac107bb3735ebfac266f3db1b3de82bd9
MD5 61bbe4cc572f5a160257d0a308cc67f3
BLAKE2b-256 9daddeecb3b174adff6cfe0a14b48d7e7746f71efbf6b167d9b1c926768317f2

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f7c5018791b450d1ffd60d19f92a318716c4df287cfd77f30a50c4d315bd925e
MD5 1ed51c276616e3d4469de5fc2279f437
BLAKE2b-256 5b9658605aa445a9f52c11c6f23f2c05e700cf9231828a4daefd2f6778c49af1

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b234698f76c5c8de3698bae521f5a415fbe31321ab16256bb6acf2d369d28d6e
MD5 053016bd96e2eec4802c540ea68cd3b3
BLAKE2b-256 a52329564693bacf6829e293930af8b824d5000ff7a2e70fbc8f8f934a954e8b

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 556705b83ae0c2d9ed878372ff5cff38272ef1a748e15be027975da1d2e61638
MD5 cffabf5651fc5d90fb6c9459196451b7
BLAKE2b-256 8133e18aeae5bebe6e02c2db2cb30ba3ca1a123c75e6f88031ef08aaf2bc7435

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 b2bf31cf12dbace026a43fbcdbacb225c7250a2bd6cb5aae2086e087dbf3b932
MD5 956ab8d272e53e9f3de1fd99341860ab
BLAKE2b-256 0175859b42a10090c9d9edf937c6356d98b3945b5123f64bf1143bcc056ab500

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3bdd218d84da433cdca0cd192b233868a712aa81064c62544f70534f4d0c643a
MD5 c318f488d2cdcbe6425f92265f936780
BLAKE2b-256 ba78d3745e76310b7dd1178abfd50015aa20b38a41681d0639ad925ad9d02788

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 268a07d02b03279f887de9ab48d8e8f9419327b4d2593a96d0425c54cbda0703
MD5 c925c76c3c2b96725cbd1f9df6cb734c
BLAKE2b-256 ef61b99e3a559c4924467bfe8f62eb210eed9ba0efd0b56d541bc357665339ef

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 12294ff2b9a497ae73e1bba9c1978c2049a167554921e5d6892ba8540ba1c13c
MD5 e60218106dfce28b7f3a0872243d56d2
BLAKE2b-256 a83e0ed82e6fc7c142f3be425780f0034d230ca85c7c291959feb2efd931f73a

See more details on using hashes here.

File details

Details for the file pbatoolkit-0.0.8-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for pbatoolkit-0.0.8-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 c39626a21370aebc5fbc2fa71b8de91699ccc52f568009a3c40bc71fdca77e32
MD5 9e02897ecfe9b2ca48a334f1fd5a7777
BLAKE2b-256 b99476a7e9854b95bf8a246b781de23fdb757c6cb37d278565b4464388ae3c92

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page