🎳 Rust binding and wrapper over NVIDIA PhysX 🦀

Overview

🎳 physx-rs

Rust binding and wrapper over NVIDIA PhysX, a popular and mature physics engine particularly well-suited for games.

Embark Embark Crates.io Docs dependency status Build status

Created and maintained by Embark and not officially supported by NVIDIA.

This repository contains 2 crates:

Name Description Links
physx High-level interface on top of physx-sys 🚧 Crates.io Docs
physx-sys Unsafe bindings to the PhysX C++ API Crates.io Docs

Why use it?

  • You want a feature-rich and performant physics engine to use in your project.

Caveats

  • 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.

Alternatives

  • Rapier: a 2D and 3D physics engine for games, animation, and robotics written in Rust. Fully cross-platform, with web support and optional cross-platform determinism on IEEE 754-2008 compliant systems.

  • 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.

Presentation

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:

An unholy fusion of Rust and C++ in physx-rs (Stockholm Rust Meetup, October 2019)

Usage

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 = PhysicsFoundation::default();

let mut scene = physics.create(
    SceneDescriptor {
        gravity: PxVec3::new(0.0, 0.0, -9.81),
        ..SceneDescriptor::new(MySceneUserData::default())
    }
);

You can run an example with cargo run --example ball, which should show the following output:

Example

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.

Prerequisites

How to build

git submodule update --init
cargo build --release

Windows Note

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

How to release (maintainers only)

  1. Install cargo-release
  2. Look at physx/CHANGELOG.md and physx-sys/CHANGELOG.md to determine whether both or only one of the crate needs updating, and what semantic version bump we need
  3. 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
  4. Run cargo release --manifest-path <physx|physx-sys>/Cargo.toml <major|minor|patch> to automatically update the CHANGELOG, publish, tag, and push the release. If you are publishing both physx and physx-sys, you can just add the --skip-push flag to avoid pushing each crate individually and then do git push --follow-tags to push both at the same time.

Contributing

Contributor Covenant

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

License

Licensed under either of

at your option.

Note that the PhysX C++ SDK has its own BSD 3 license and depends on additional C++ third party libraries.

Contribution

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.

Comments
  • Compile errors when building from source

    Compile errors when building from source

    Describe the bug Compilation fails when attempting to build the project on Windows 10, following the "How to build" instructions in the readme. In the console I get the following messages:

    error: could not find native static library `PhysXVehicle_static_64`,` perhaps an -L flag is missing?
    
    error: aborting due to previous error
    
    error: could not compile `physx-sys`.
    warning: build failed, waiting for other jobs to finish...
    error: attempt to shift right with overflow
       --> physx\src\articulation_reduced_coordinate.rs:494:23
        |
    494 |         let (a, b) = ((self.ptr as usize >> 32) as u32, self.ptr as usize as u32);
        |                       ^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `#[deny(exceeding_bitshifts)]` on by default
    
    error: aborting due to previous error
    
    error: could not compile `physx`.
    

    To Reproduce Run cargo build --release from the cloned physx-rs directory

    Additional context I don't have any rust experience, and only a small amount of C/C++ experience. I would like to use the physx-sys C API to build a standalone DLL that I can use from C#.

    bug 
    opened by mmusu3 21
  • Android cross-compiling from Windows error

    Android cross-compiling from Windows error "cargo:warning=The command line is too long"

    When building locally on Windows to Android I've been running into Cargo errors about the cc command-line being too long which fails the build.

    Windows has a max of 8192 characters, and got over 10k characters in some of the compile invocations, mostly due to long paths for all the include paths.

    Example:

    running: "c:\\Users\\repi\\Downloads\\android-ndk-r21d\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\aarch64-linux-android30-clang++.cmd" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=aarch64-linux-android" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\common\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/common/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\fastxml\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/fastxml/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/filebuf/include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/foundation/include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/foundation/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/foundation/src/unix" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/ccd" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/common" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/contact" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/convex" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/distance" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/gjk" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/hf" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/intersection" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/mesh" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/pcm" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/geomutils/src/sweep" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/include\\cooking" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevel\\api/include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevel\\common/include/collision" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevel\\common/include/pipeline" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevel\\common/include/utils" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevel/common/src/pipeline" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevel\\software/include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevel/software/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\lowlevelaabb\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowlevelaabb/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\lowleveldynamics\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/lowleveldynamics/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physx/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physx/src/buffering" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\physxcharacterkinematic\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxcharacterkinematic/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxcooking/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxcooking/src/convex" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxcooking/src/mesh" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\physxextensions\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxextensions/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxextensions/src/serialization" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxextensions/src/serialization/Binary" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxextensions/src/serialization\\File" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxextensions/src/serialization/Xml" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\physxmetadata/core/include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxmetadata/core/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxmetadata/extensions\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxmetadata/extensions/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\physxvehicle\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxvehicle/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxvehicle/src/physxmetadata\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/physxvehicle/src/physxmetadata/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\pvd\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/pvd/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\scenequery\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/scenequery/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\simulationcontroller\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/simulationcontroller/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source\\task\\include" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/task/src" "-I" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX\\pxshared\\include" "-Wall" "-Wextra" "--sysroot=c:\\Users\\repi\\Downloads\\android-ndk-r21d\\toolchains/llvm/prebuilt\\windows-x86_64\\sysroot" "-std=c++14" "-ferror-limit=0" "-Wall" "-Wextra" "-Werror" "-Wstrict-aliasing=2" "-Weverything" "-Wno-alloca" "-Wno-anon-enum-enum-conversion" "-Wno-documentation-deprecated-sync" "-Wno-documentation-unknown-command" "-Wno-gnu-anonymous-struct" "-Wno-undef" "-Wno-unused-function" "-Wno-nested-anon-types" "-Wno-float-equal" "-Wno-padded" "-Wno-weak-vtables" "-Wno-cast-align" "-Wno-conversion" "-Wno-missing-noreturn" "-Wno-missing-variable-declarations" "-Wno-shift-sign-overflow" "-Wno-covered-switch-default" "-Wno-exit-time-destructors" "-Wno-global-constructors" "-Wno-missing-prototypes" "-Wno-unreachable-code" "-Wno-unused-macros" "-Wno-unused-member-function" "-Wno-used-but-marked-unused" "-Wno-weak-template-vtables" "-Wno-deprecated" "-Wno-non-virtual-dtor" "-Wno-invalid-noreturn" "-Wno-return-type-c-linkage" "-Wno-reserved-id-macro" "-Wno-c++98-compat-pedantic" "-Wno-unused-local-typedef" "-Wno-old-style-cast" "-Wno-newline-eof" "-Wno-unused-private-field" "-Wno-format-nonliteral" "-Wno-implicit-fallthrough" "-Wno-undefined-reinterpret-cast" "-Wno-disabled-macro-expansion" "-Wno-zero-as-null-pointer-constant" "-Wno-shadow" "-Wno-unknown-warning-option" "-Wno-atomic-implicit-seq-cst" "-Wno-extra-semi-stmt" "-Wno-gcc-compat" "-Wno-gnu-include-next" "-Wno-class-varargs" "-Wno-implicit-exception-spec-mismatch" "-Wno-macro-redefined" "-Wno-zero-length-array" "-Wno-undefined-func-template" "-Wno-c99-extensions" "-DANDROID" "-DPX_PHYSX_STATIC_LIB" "-DDISABLE_CUDA_PHYSX" "-DPX_SUPPORT_PVD=1" "-DNDEBUG=1" "-DPX_COOKING" "-o" "C:\\git\\embark\\ark\\target\\aarch64-linux-android\\release\\build\\physx-sys-b1c2471c131819bb\\out\\TaskManager.o" "-c" "C:\\Users\\repi\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\physx-sys-0.4.6\\PhysX/physx\\source/task/src\\TaskManager.cpp"
    cargo:warning=The command line is too long.
    exit code: 1
    

    cc @Jasper-Bekkers @VZout

    bug 
    opened by repi 14
  • Android Support

    Android Support

    Initial android support.

    Added casts to base.rs, rigid_static.rs and visual_debugger.rs. The internal pointer type seems to differ for android. However this should not be a problem if I cast using as _.

    Ignore the commit history

    opened by VZout 10
  • Make glam an optional dependency

    Make glam an optional dependency

    Currently upgrading rust-gpu in Ark is usually blocked on physx-rs because Ark disallows duplicate deps and glam's minor version number changes often. This PR changes it so glam is optional dependency of physx, which should allow Ark to not depend on glam from physx.

    opened by XAMPPRocky 9
  • Fix issues I ran into when porting our code to the new API

    Fix issues I ran into when porting our code to the new API

    First round of changes. Will require a major API version bump once it's all in.

    Generally this wasn't too bad but there are holes.

    A lot of the SceneDesc parameters were lost, added back a few. It's gonna be more though, so should we add a builder?

    Now includes @Hentropy 's new object creation rework.

    a: high-level-api work-in-progress rust 
    opened by hrydgard 8
  • Initial aarch64-apple-darwin support

    Initial aarch64-apple-darwin support

    Adds initial support for Mac M1 ARM CPUs.

    This may not be correct as had problems running our pxbind structgen utility on Mac M1 so for now just copy'n'pasted the x86_64 Mac structgen files. Does seem to run but could be subtle differences (that could cause catastrophic failures)?

    Resolves: #92

    opened by repi 7
  • Add project maintainers as codeowners

    Add project maintainers as codeowners

    We are making our open source project maintainers explicit with a CODEOWNERS file. Let me know /f these are not the correct maintainers for this project

    opened by lpil 7
  • Replace the Deref hack with a Class<T> trait, track user data types, improve coverage and add basic allocators

    Replace the Deref hack with a Class trait, track user data types, improve coverage and add basic allocators

    This PR is a significant refactor of the physx crate. The Deref hack has been replaced with a Class trait, and super classes are now represented by traits. The user data types are tracked throughout, mostly via Scene, and are fully generic so end users may safely use whatever user data types they want. The Px math and geometry types now have coverage, as do PxMaterial, PxAggregate and PxArticulation. The concrete types have also been flagged as Send and Sync (which was all I set out to do 😂).

    Class<T>

    Classes have interfaces that are shared across multiple types, and the tool for that in Rust is traits. All the FFI methods need is a raw pointer of the appropriate type, so if we have a trait that can do that as a super trait, the class-traits can be default-impled. This trait is very simple, just a pair of methods for getting mut/const pointers to type T:

    trait Class<T> {
        fn as_ptr(&self) -> *const T;
        fn as_mut_ptr(&mut self) -> *mut T;
    }
    

    Unlike Deref, it uses a type parameter rather than an associated type, so it can be implemented multiple times per struct, and it combines const and mut into one for convenience. Basic usage looks like this:

    impl<T> Base for T where T: Class<PxBase> {}
    pub trait Base: Class<PxBase> {
        fn get_concrete_type(&self) -> ConcreteType {
            unsafe { PxBase_getConcreteType(self.as_ptr()).into() }
        }
    }
    

    Sub-classes are represented as traits with the super class as a super trait, which in turn requires the Class bound. This isn't strictly necessary, but it's a nice sanity check. Some of the traits have generic bounds, so the blanket impl doesn't work for them but the traits are all defaulted regardless, so implementing them is just a one liner. (These generic params should get changed to assoc types in the future.) Currently, the most derived types (eg. PxRigidDynamic) are represented as structs with their interface in their inherent impl block. I had used traits for them initially too, but I couldn't see a good reason to keep the trait and struct separate, and it made importing things repetitive so I moved everything into the inherent block.

    UserData

    In C++, the user data fields are all *mut c_void, and the user must track the type stored there for themselves. Thankfully, Rust can do better than this! I was honestly quite surprised with how well this part came together. When creating an object with a user data field, the user can pass in an object of any type, and it will either be Boxed and stored as a pointer, or if it's small enough it will get jammed straight into the field (which was a major goal for me since my initial aim was to implement a bevy_physx crate, and I wanted the entity ID to go there). Because the type info is tracked, the Drop impls can deallocate this properly as well! Some types (the controllers) don't directly expose the user data field, and instead expose methods for it so they have a slightly different (but still typed and bitpacked) interface that doesn't use the trait.

    Allocators

    I just merged the allocator callback trampoline in today, so this is still very work-in-progress, but there are a couple options for allocators! It feels super rough wrapping Rust's wonderfully type-aware allocator in a C-style "here's a pointer lol" one though.

    Coverage

    This adds support for PxMaterial, PxGeometry and Px*Geometry, PxVec3/Quat/Transform, PxArticulation and PxAggregate. Coverage of some other types, like Scene, has also improved. A lot of this has not been tested, but it's mostly just straight pass throughs with maybe some buffer setup or an into call or pointer cast. Support for PxCooking has currently been removed. There is no implementation reason for this, it just got a little left behind 😢.

    Drop

    Release was removed in favor of implementing Drop wherever possible. However, I'm sure these Drop impls are leaking memory because I'm not sure what the actual ownership model of a lot of the objects is (eg. aggregate's Drop impl). As far as I know, the drop impls are safe but this is an area that needs much more testing!

    Further work

    • Drop Testing
    • Audit unsafe: there are ~600 uses of unsafe, and while most are call throughs this needs more eyes.
    • Scene Queries: need trampolines for PxSweepCallback, PxRaycastCallback and PxOverlapCallback
    • Reimplement Cooking, and the mesh builders that relied on it.
    • Change ArticulationCache to a DST to save those precious precious bytes! (gotta make up for the allocator using 16-align for 4 byte objects plus the additional 16 for storing the size somehow🤦)
    • Test and documentation! The eternal bugbear of programming.
    • Improve coverage. Character and vehicle support are particularly lacking.

    Even further work

    I started on this because I wanted to write a bevy_physx crate, and I still haven't. I'd like to wrap FemFX in a similar way, and I'd really like to explore using bevy and PhysX as an animation ML training ground.

    opened by Hentropy 7
  • Add aarch64-unknown-linux-gnu support

    Add aarch64-unknown-linux-gnu support

    Tested on Ampere Altra Arm64. Added extra run script since we already have a separate for android (this needs -fsigned-char) and didn't want to over compilcate the bash scripts

    follow up of: https://github.com/EmbarkStudios/physx-rs/pull/153

    opened by Nehliin 5
  • Enable Cross Compilation

    Enable Cross Compilation

    The biggest change is that cmake is now an optional method of building that can be enabled with the use-cmake feature flag. However, by default, cc will be used (with the parallel feature) for compilation. This was the easiest way to get physx to compile for windows uses clang-cl on a non-Windows host platform.

    In addition, the structgen executable, which is also built and executed by the build script, is also behind a feature flag, structgen, and will not be compiled or executed by default. Instead, the outputs for linux, macos, and windows have been checked in to the repository which means they can be used when running on a platform other than the target.

    Changes were made to the CI to run tests and the ball example in debug and release with all, none, only structgen, and only cmake feature flags on to make sure that the various scenarios all "work".

    Note that this supplants #41 as it takes into account the CXX compiler in the same way that cc-rs does. Resolves: #41

    TODO: Put cooking and the visual debugger behind feature flags as they're not required for the core physx functionality

    opened by Jake-Shadle 5
  • Cannot run the example on Ubuntu 16.

    Cannot run the example on Ubuntu 16.

    Describe the bug Can't run the example ball_physx.

    To Reproduce Running the example in physx-rs folder

    cargo run --example ball_physx

    Expected behavior I get the following error

     dinesh@LAPITOP (master *) /home/dinesh/phd/code/rust/physx-rs $  
    |  Dell Laptop=> cargo run --example ball_physx
       Compiling physx-sys v0.1.0+4.1
       Compiling ncollide3d v0.20.1
       Compiling nalgebra-glm v0.4.0
    error: failed to run custom build command for `physx-sys v0.1.0+4.1`
    process didn't exit successfully: `/home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-8b775e661e3df296/build-script-build` (exit code: 101)
    --- stdout
    running: "cmake" "/home/dinesh/.cargo/registry/src/github.com-1ecc6299db9ec823/physx-sys-0.1.0+4.1/PhysX/physx/source/compiler/cmake" "-DCMAKE_LIBRARY_ARCHITECTURE=x86_64-unknown-linux-gnu" "-DPX_OUTPUT_LIB_DIR=/home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-5e327d56aa7c7e67/out" "-DPX_OUTPUT_BIN_DIR=/home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-5e327d56aa7c7e67/out" "-DPX_OUTPUT_ARCH=x86" "-DPX_BUILDSNIPPETS=False" "-DPX_BUILDSAMPLES=False" "-DPX_GENERATE_STATIC_LIBRARIES=True" "-DPX_GENERATE_GPU_PROJECTS=False" "-DTARGET_BUILD_PLATFORM=linux" "-DCMAKE_C_COMPILER=clang" "-DCMAKE_CXX_COMPILER=clang++" "-DCMAKE_BUILD_TYPE=debug" "-DCMAKE_INSTALL_PREFIX=/home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-5e327d56aa7c7e67/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64"
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-5e327d56aa7c7e67/out/build
    running: "cmake" "--build" "." "--target" "install" "--config" "debug" "--"
    [  0%] Built target PhysXTask
    [  4%] Built target PhysXFoundation
    [  4%] Built target FastXml
    [  6%] Built target LowLevelAABB
    [ 10%] Built target SceneQuery
    [ 12%] Built target PhysXCharacterKinematic
    [ 17%] Built target LowLevel
    [ 20%] Built target PhysXPvdSDK
    [ 27%] Built target LowLevelDynamics
    [ 35%] Built target SimulationController
    [ 40%] Built target PhysXVehicle
    [ 73%] Built target PhysXCommon
    [ 78%] Built target PhysXCooking
    [ 88%] Built target PhysX
    [100%] Built target PhysXExtensions
    Install the project...
    -- Install configuration: "debug"
    -- Up-to-date: /home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-5e327d56aa7c7e67/out/source/foundation/include/unix/PsUnixAoS.h
    ...
    cargo:root=/home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-5e327d56aa7c7e67/out
    cargo:rustc-link-search=native=/home/dinesh/phd/code/rust/physx-rs/target/debug/build/physx-sys-5e327d56aa7c7e67/out/bin/linux.clang/debug
    cargo:rustc-link-lib=static=PhysXVehicle_static_64
    cargo:rustc-link-lib=static=PhysX_static_64
    cargo:rustc-link-lib=static=PhysXCooking_static_64
    cargo:rustc-link-lib=static=PhysXPvdSDK_static_64
    cargo:rustc-link-lib=static=PhysXCommon_static_64
    cargo:rustc-link-lib=static=PhysXFoundation_static_64
    cargo:rustc-link-lib=static=PhysXCharacterKinematic_static_64
    cargo:rustc-link-lib=static=PhysXExtensions_static_64
    TARGET = Some("x86_64-unknown-linux-gnu")
    HOST = Some("x86_64-unknown-linux-gnu")
    CXXFLAGS_x86_64-unknown-linux-gnu = None
    CXXFLAGS_x86_64_unknown_linux_gnu = None
    HOST_CXXFLAGS = None
    CXXFLAGS = None
    CRATE_CC_NO_DEFAULTS = None
    
    --- stderr
    PHYSX ROOT /home/dinesh/.cargo/registry/src/github.com-1ecc6299db9ec823/physx-sys-0.1.0+4.1/PhysX/physx
    PhysX Build Platform: linux
    Using CXX Compiler: /usr/bin/clang++
    CMake Warning (dev) at linux/CMakeLists.txt:36 (SET):
      implicitly converting 'INTERAL' to 'STRING' type.
    Call Stack (most recent call first):
      CMakeLists.txt:133 (INCLUDE)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    clang: error: unknown argument: '-fno-plt'
    thread 'main' panicked at 'failed to compile structgen even though compiler reported no failures', /home/dinesh/.cargo/registry/src/github.com-1ecc6299db9ec823/physx-sys-0.1.0+4.1/build.rs:163:9
    note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
    
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    

    Device:

    • Ubuntu 16.04
    • C++ 7.4
    • cmake 3.15.2

    Additional context This examle runs fine in ubuntu 18. WIth the same prerequiutes (C and C++ version).

    bug 
    opened by dineshadepu 5
  • how to solve the problem of

    how to solve the problem of "cannot borrow `articulation` as mutable more than once at a time" when I use the feature of artilucation.creaet_link(...)

    Excuse me, how should I to resolve this problem? when I use the method 'articulation.create_link()' to create a link, because of the result of this method will as a parameter in next called of 'articulation.create_link()',that cause the lifetime of first value as same as the second called, so occur Multiple variable borrowings。 I try to clone reference and 'root_link_met()' ,but still can not resolve this problem.

    opened by YesanQin 1
  • Port to PhysX 5

    Port to PhysX 5

    https://github.com/NVIDIA-Omniverse/PhysX

    Should mostly be mechanical changes, though we'll also have to port our fixes for cross-compilation since those are (I assume) still broken in the new one since they never responded to our PR.

    enhancement 
    opened by Jake-Shadle 0
  • Support `aarch64-pc-windows-msvc`

    Support `aarch64-pc-windows-msvc`

    We should add support for building and running on Windows for ARM with the aarch64-pc-windows-msvc target.

    Hopefully should be pretty easy with the bindgen as we already support other aarch64 targets and Windows on x86-64. Unless there are issues with PhysX C++ library itself on Windows on ARM

    enhancement 
    opened by repi 0
  • Ensure

    Ensure "global" resources can be deallocated

    Currently multiple of the trampoline parts are never deallocated, assuming that they'll live forever. This includes the new ErrorCallback, the ProfilerCallback, and potentially others. Since PhysX takes ownership of these but doesn't delete them, we have to keep the pointers around and delete them manually when the foundation is dropped, or return a collection of pointers for the user to deal with it.

    enhancement 
    opened by tgolsson 0
  • How to get collision callback to work?

    How to get collision callback to work?

    I'm using pure physx (physx-sys). The problem is that my "onConnect" (when bodies collides) never gets called. The filter shader is called though. Here is the scene creation.

    pub fn create_scene(physics: PtrPhysics, gravity: f32) -> PtrScene {
        unsafe {
            let mut scene_desc: PS::PxSceneDesc =
                PS::PxSceneDesc_new(PS::PxPhysics_getTolerancesScale(physics));
            scene_desc.gravity = PS::PxVec3 {
                x: 0.0,
                y: gravity,
                z: 0.0,
            };
    
            unsafe extern "C" fn filterShader(mut s: *mut PS::FilterShaderCallbackInfo) -> u16 {
                use PS::PxPairFlag as F;
                let mut f = PS::PxPairFlags {
                    mBits: (F::eCONTACT_DEFAULT | F::eNOTIFY_TOUCH_FOUND) as u16,
                }; //;;
                (*s).pairFlags = &mut f;
                (PS::PxFilterFlag::eDEFAULT) as u16
            }
            unsafe extern "C" fn onConnect(   //<--- This never gets called
                a: *mut std::ffi::c_void,
                b: *const PS::PxContactPairHeader,
                c: *const PS::PxContactPair,
                d: u32,
            ) {
                println!("Connecting!"); //but it doesn't :(
            };
            let info = PS::SimulationEventCallbackInfo {
                collision_callback: Some(onConnect),
                ..Default::default()
            };
            let simulation_event_callback = PS::create_simulation_event_callbacks(&info);
            scene_desc.simulationEventCallback = simulation_event_callback;
            let dispatcher = PS::phys_PxDefaultCpuDispatcherCreate(1, null_mut());
            scene_desc.cpuDispatcher = dispatcher as *mut PS::PxCpuDispatcher;
             PS::enable_custom_filter_shader(&mut scene_desc, shader, 1);
            let scene = PS::PxPhysics_createScene_mut(physics, &scene_desc);
            scene
        }
    }
    
    

    And this is how I set the filter data

    pub fn set_filter_data(actor: *mut PS::PxRigidActor) {
        unsafe {
            let data = PS::PxFilterData_new_2(2, 2, 2, 2);
            let capacity = PS::PxRigidActor_getNbShapes(actor);
            let mut buffer: Vec<*mut PS::PxShape> = Vec::with_capacity(capacity as usize);
            let len =
                PS::PxRigidActor_getShapes(actor, buffer.as_mut_ptr() as *mut *mut _, capacity, 0);
            buffer.set_len(len as usize);
             for n in 0..(len as usize) {
                let shape = buffer.get(n);
                match shape {
                    None => {}
                    Some(ptr) => {
                        PS::PxShape_setSimulationFilterData_mut(*ptr, &data);
                    }
                }
            }
        }
    }
    
    

    I saw the PxSimulationFilterCallback_pairFound_mut ? method but that is supposed to be overriden, not called, and how should it be overriden? I'm really at a loss, there is no crashes, it just doesn't work for some reason.

    Are there perhaps some examples out there on how it works? Couldn't find any so far.

    opened by mlp1802 1
Owner
Embark
The future belongs to the curious
Embark
A Godot 3.4 binding for Live2D

godot-cubism A Godot 3.4 binding for cubism-rs which itself is a binding for the native cubism sdk. Usage var factory = load("path_to_your_native_scri

null 16 Dec 23, 2022
A Rust wrapper and bindings of Allegro 5 game programming library

RustAllegro A thin Rust wrapper of Allegro 5. Game loop example extern crate allegro; extern crate allegro_font; use allegro::*; use allegro_font::*;

null 80 Dec 31, 2022
A wrapper around SDL2's game controller API.

fishsticks System for handling gamepad input, using SDL2's game controller API as the backend. License Fishsticks is dual-licensed under either Apache

null 7 Dec 8, 2022
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 27 Jan 7, 2023
Abstreet - Transportation planning and traffic simulation software for creating cities friendlier to walking, biking, and public transit

A/B Street Ever been stuck in traffic on a bus, wondering why is there legal street parking instead of a dedicated bus lane? A/B Street is a project t

A/B Street 6.8k Jan 9, 2023
"putzen" is German and means cleaning. It helps keeping your disk clean of build and dependency artifacts safely.

Putzen "putzen" is German and means cleaning. It helps keeping your disk clean of build and dependency artifacts safely. About In short, putzen solves

Sven Assmann 2 Jul 4, 2022
Plugins and helpful methods for using sepax2d with Bevy for 2d overlap detection and collision resolution.

bevy_sepax2d Plugins and helpful methods for using sepax2d with Bevy for 2d overlap detection and collision resolution. Compatible Versions bevy bevy_

null 7 Nov 14, 2022
This is the core library with the full abstraction and implementation of the Minecraft protocol and logic. (Currently WIP)

MineRust (WIP) This is the core library with the full abstraction and implementation of the Minecraft protocol and logic. This project is currently WI

MineRust Project Suite 2 Nov 20, 2022
Rust-and-opengl-lessons - Collection of example code for learning OpenGL in Rust

rust-and-opengl-lessons Project requires Rust 1.31 Collection of example code for learning OpenGL in Rust 00 - Setup 01 - Window 02 - OpenGL Context 0

Nerijus Arlauskas 348 Dec 11, 2022
RTS game/engine in Rust and WebGPU

What is this? A real time strategy game/engine written with Rust and WebGPU. Eventually it will be able to run in a web browser thanks to WebGPU. This

Thomas SIMON 258 Dec 25, 2022
grr and rust-gpu pbr rendering

grr-gltf Barebone gltf viewer using grr and rust-gpu. Currently only supports a single gltf model! Assets These files need to be downloaded and placed

Markus Siglreithmaier 28 Dec 2, 2022
A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music.

rustris A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music. (C) 2020 Ben Cantrick. This code is distri

Ben Cantrick 17 Aug 18, 2022
Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering.

Provok Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering. Input Provok is fed with a JSON

Ossama Hjaji 67 Dec 10, 2022
The Bloat-Free Browser Game in Rust but in C and in UEFI

rust-browser-game but in UEFI instead of browser quick start deps rust gnu-efi gcc make build process $ make running after building everything you wil

bit6tream 12 Nov 7, 2022
rust-browser-game but native and rendered with ncurses in C without the Browser

Spin-off of rust-browser-game-but-sdl but with ncurses Nothing much to say. Just see rust-browser-game-but-sdl and rust-browser-game. Quick Start $ ma

Tsoding 8 Apr 21, 2022
The Bloat-Free Browser Game in Rust but in C and not in a Browser

rust-browser-game but native and rendered with SDL in C without the Browser The original idea of rust-browser-game is that the game.wasm module is com

Tsoding 12 Sep 26, 2022
minesweeper-rs is a simple minesweeper game using Rust and windows-rs.

minesweeper-rs minesweeper-rs is a simple minesweeper game using Rust and windows-rs. Key Features TBA Quick Start TBA How To Contribute Contributions

Chris Ohk 15 Jun 25, 2022
A simple Rust and WebAssembly example implementing the Game of Life

rust-wasm-game-of-life rust-wasm-game-of-life is a simple Rust and WebAssembly example implementing the Game of Life based on Rust and WebAssembly boo

Chris Ohk 14 Nov 24, 2021
Rust Game engine 3D (and 2D)

A feature-rich, production-ready, general purpose 2D/3D game engine written in Rust with a scene editor.

rg3d engine 5.4k Jan 9, 2023