Physics Based Animation Toolkit
Project description
Physics Based Animation Toolkit
We recommend exploring the official CMake documentation to beginner CMake users.
Overview
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.
Our Python bindings are currently not available on MacOS via PyPI.
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).
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_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. |
Build
Build transparently across platforms using the cmake build CLI.
CMake 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. |
Install
From command line:
cd path/to/PhysicsBasedAnimationToolkit
cmake -S . -B build -A x64 -DPBAT_ENABLE_PROFILER:BOOL=ON -DPBAT_BUILD_TESTS:BOOL=ON
cmake --install build --config Release
Quick start
We recommend downloading the Tracy profiler server to analyze execution of PBAT algorithms, available as precompiled executable.
C++
Take a look at the unit tests, found in the library's source (.cpp
) files.
Python
To download and install from PyPI, run in command line:
pip install pbatoolkit libigl numpy scipy
To install locally, run in command line:
pip install .
In Python:
import pbatoolkit as pbat, pbatoolkit.fem, igl, numpy as np, scipy as sp
V, C, F = igl.read_mesh("path/to/mesh.mesh")
mesh = pbat.fem.mesh(V.T, C.T, element=pbat.fem.Element.Tetrahedron, order=1)
x = mesh.X.reshape(mesh.X.shape[0]*mesh.X.shape[1], order='f')
detJeM = pbat.fem.jacobian_determinants(mesh, quadrature_order=2)
M = pbat.fem.mass_matrix(mesh, detJeM, rho=1000., dims=3, quadrature_order=2).to_matrix()
detJeU = pbat.fem.jacobian_determinants(mesh, quadrature_order=1)
GNeU = pbat.fem.shape_function_gradients(mesh, quadrature_order=1)
Y = np.full(mesh.E.shape[1], 1e6)
nu = np.full(mesh.E.shape[1], 0.45)
hep = pbat.fem.hyper_elastic_potential(mesh, detJeU, GNeU, Y, nu, psi= pbat.fem.HyperElasticEnergy.StableNeoHookean, quadrature_order=1)
hep.precompute_hessian_sparsity()
hep.compute_element_elasticity(x)
U, gradU, HU = hep.eval(), hep.to_vector(), hep.to_matrix()
l, V = sp.sparse.linalg.eigsh(HU, k=30, M=M, which='SM')
Profiling is also accessible via the Python interface:
import pbatoolkit.profiling
profiler = pbatoolkit.profiling.Profiler()
connected = profiler.wait_for_server_connection(timeout=10)
# Check connected...
for t in range(timesteps):
profiler.begin_frame("physics")
# Physics time integration goes here...
profiler.end_frame("physics")
To profile relevant calls to pbatoolkit
functions/methods, connect to python.exe
in the Tracy
profiler server GUI.
All calls to pbat will be profiled on a per-frame basis in the Tracy profiler server GUI.
Use method
profile
ofpbatoolkit.profiling.Profiler
to profile code external to PBAT, allowing for an integrated profiling experience while using various scientific computing packages.def modes_from_stiffness_matrix(): l, V = sp.sparse.linalg.eigsh(HU, k=30, M=M, which='SM') profiler.profile("Compute stiffness' low frequency modes", modes_from_stiffness_matrix)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pbatoolkit-0.0.2-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: pbatoolkit-0.0.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f63a542dc7ef5412b42c721de03c4d23ae9e707ae7aa111a07e05fb8d4370c11 |
|
MD5 | cd532f268a9e359814cebe8220ef1b62 |
|
BLAKE2b-256 | da8d18d73ff91b918a2ef7ea99166eb6bc55b00873f2975c7547cec48c90505d |
File details
Details for the file pbatoolkit-0.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pbatoolkit-0.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 15.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e50888a0f74e7e02e8c33deddd27cc37adab53134a941f13042b41639bf84aaa |
|
MD5 | aef4b383f0db5e9ea63b0f8c2ed41d76 |
|
BLAKE2b-256 | c175f98c8cff428a3131fc9759b753605af4b73452f08cecca424da5d7f4df21 |
File details
Details for the file pbatoolkit-0.0.2-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: pbatoolkit-0.0.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8040dec5856dd1cc9a6994eace9649c98bb399563c4515fa96c1795f5106f4a0 |
|
MD5 | 73e7b515bd637b4330c71780ee786b66 |
|
BLAKE2b-256 | 89912ad2cfd12fa8e0626b624906a3c8741fa599e2f5a2d71b8d05d0a3058743 |
File details
Details for the file pbatoolkit-0.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pbatoolkit-0.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 15.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba065a21c2350641842101922e33040b3e331bc3ce7e6d15890d759e67be22a3 |
|
MD5 | 2aa6109d323cd89ea17ce7f13e7c21c4 |
|
BLAKE2b-256 | d3a9d114ea09b25987e9a1170eda2a2fac134b769faaa681cbc11dce77e107d8 |
File details
Details for the file pbatoolkit-0.0.2-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: pbatoolkit-0.0.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7f4004527bc4eff91d4836616d5940872ad86a26de812b9e32c6fd667f6cc85 |
|
MD5 | ca5a72219e99530fa94734c58260f61e |
|
BLAKE2b-256 | 8544fbfe29df43c99f2b558310f0bb8c0d5f51afb407a09cd591a6de38026b81 |
File details
Details for the file pbatoolkit-0.0.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pbatoolkit-0.0.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 15.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7da66ba62fce953570a2eeaf215409442b9270909797d3f953af326502db4752 |
|
MD5 | e2460a1f2ccfc24bdd34ed11ce500fb6 |
|
BLAKE2b-256 | 6f76eeee78f62a8ade483d3ca03232c969c1e1d627490edbcb7f88dae2a83f09 |