Rust binding and wrapper over NVIDIA PhysX, a popular and mature physics engine particularly well-suited for games.
Created and maintained by Embark and not officially supported by NVIDIA.
This repository contains 3 crates:
Name | Description | Links |
---|---|---|
physx |
High-level interface on top of physx-sys π§ |
|
physx-sys |
Unsafe bindings to the PhysX C++ API | |
physx-macros |
Utility macros used internally by the physx crate |
- You want a feature-rich and performant physics engine to use in your project.
-
The high-level
physx
wrapper is work-in-progress, and only covers a part of PhysX functionality. You can follow our progress and see where contributions are needed in our Tracking Issue for High-Level API Completeness. -
Any other features have to be accessed through the unsafe physx-sys crate.
-
It's a large C++ codebase which requires a C++ toolchain, and comes with a non-trivial build system.
- nphysics: a 2- and 3-dimensional physics engine for games and animations written in Rust. It is a good option for projects which do not require the full feature set of PhysX or prefer a native Rust solution.
Tomasz Stachowiak did a presentation at the Stockholm Rust Meetup on October 2019 about this project that goes through the tecnical details of how C++ to Rust bindings of physx-sys
works:
The following code example shows how physx
can be initialized.
const PX_PHYSICS_VERSION: u32 = physx::version(4, 1, 1);
let mut foundation = Foundation::new(PX_PHYSICS_VERSION);
let mut physics = PhysicsBuilder::default()
.load_extensions(false) // switch this flag to load extensions during setup
.build(&mut foundation);
let mut scene = physics.create_scene(
SceneBuilder::default()
.set_gravity(glm::vec3(0.0, -9.81, 0.0))
.set_simulation_threading(SimulationThreadType::Dedicated(1)),
);
You can run an example with cargo run --example ball
, which should show the following output:
Information about all wrapper functionality can be found in the physx crate docs.
If you require functionality not covered by the physx wrapper you can use the low level physx-sys crate, which closely maps to the official PhysX SDK. You can find the PhysX user guide here.
- C++ compiler (see the
cc
crate for requirements) - CMake (optional, only used when the
use-cmake
feature is enabled) (see thecmake
crate for requirements)
git submodule update --init
cargo build --release
It is highly recommended to not enable debug info in release mode when building with MSVC, as the Physx C++ code will take an extremely long time to compile. You can disable this by putting the following in your Cargo.toml
[profile.release.package.physx-sys]
debug = false
physx-rs consists of two crates, physx and physx-sys. If you only merged changes to one of them, only that one needs a new release.
-
Look at
physx/CHANGELOG.md
andphysx-sys/CHANGELOG.md
to determine whether both or only one of the crate needs updating, and what semantic version bump we need -
Review the list of changes in the changelogs and compare with the git commit diffs to the previous release and make sure we've captured and described all changes well and that they are semantically correct
-
Create a branch:
git checkout -b release-physx-0.x.y
-
Update relevant changelogs (also update the diff links at the bottom of them!), and the version number in the Cargo.toml files for the crate(s) that you are updating.
-
Make a PR from your branch, get it reviewed and merged. If in doubt about what the PR should look like, just look at previous release PRs
-
Run
cargo publish
in the physx and physx-sys directories as appropriate. -
Once published without errors, tag the merge with
physx-v0.x.y
and/orphysx-sys-v0.z.w
tags as appropriate:git tag physx-v0.x.y -m "" git tag physx-sys-v0.x.y -m "" git push --tags
We welcome community contributions to this project.
Please read our Contributor Guide for more information on how to get started.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Note that the PhysX C++ SDK has its own BSD 3 license and depends on additional C++ third party libraries.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.