Godot bindings for the Rapier3D physics engine

Overview

Godot bindings for the Rapier3D physics library

How to use

There are two parts:

  • A Godot module which must be compiled with the engine. This is necessary to communicate with the library through the PhysicsServer
  • A library with the actual bindings

Linux:

  • Run module/generate.py first
  • Then, either make a symlink or copy the contents of module to the engine source modules/pluggable_physics
  • Build the engine
  • Build the library with the provided Makefile using make
  • Set 3d/physics_engine to Custom

Windows:

  • Run python module/generate.py
  • Copy module/api.json to rapier3d/api.json
  • Then, either make a symlink or copy the contents of module to the engine source modules/pluggable_physics
  • Build the engine
  • Build the library following these steps:
    • ensure LIBCLANG_PATH environment variable is set to llvm's bin folder containing libclang.dll
    • rustup default nightly-msvc
      • If you get an error try: cargo update
    • run build_win.bat
  • Set 3d/physics_engine to Custom

If you have difficulties, please contact me or open an issue.

The editor may crash if you keep 3d/physics_engine set to Custom. If it does, uncomment it in project.godot

Issues
  • ConvexPolygonShape not supported? Tips for using the binding?

    ConvexPolygonShape not supported? Tips for using the binding?

    Hi, Sorry to bother you with so many issues. But my hopes of a dropin replacement for Bullet were dashed. :) I tried dropping in rapier into my third person controller project, and my rigidbodies fell through my floor. I got a bunch of errors:

    ERROR: Not implemented
       At: modules\pluggable_physics\server.gen.cpp:584
    ERROR: Not implemented
       At: modules\pluggable_physics\server.gen.cpp:593
    

    584 referring to body_test_motion and 593 is body_test_ray_separation.

    Here's what it's supposed to look like

    https://user-images.githubusercontent.com/27040/120148491-29307580-c19d-11eb-87b1-9aa1ac655262.mp4

    The RigidBodys are meshes I imported from blender and have a ConvexPolygonShape that was generated from the MeshInstance -> Mesh -> Create Single Convex Collision Sibling.

    I created a simple scene with a rounded cube from blender and another cube created in godot.

    https://user-images.githubusercontent.com/27040/120148317-e2428000-c19c-11eb-9710-20f10061cfbe.mp4

    And I get this error:

    ERROR: <native>: Failed to apply data: IncompleteTriangle
       At: rapier3d\src\server\shape.rs:304
    

    What would it take to get ConvexPolygonShape supported? What I'm really after is creating a third person controller, KinematicBody, that can navigate a terrain and interact with RigidBodys. Do you have any tips for getting my project working or working with the binding in general?

    opened by geekrelief 3
  • Add a test to figure out the value of `collider` from `intersect_ray`

    Add a test to figure out the value of `collider` from `intersect_ray`

    While reading the Godot documentation I noticed that the keys in the returned are called collider and collider_id. However, AFAICT there is no way to set an object/instance ID per collider/shape. You can only do this per Body/Area.

    While the function seems to work as expected a test should be added to ensure it actually matches the Bullet behaviour.

    documentation good first issue 
    opened by Demindiro 2
  • godot complains about leaked instances on exit

    godot complains about leaked instances on exit

    WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
         at: ObjectDB::cleanup (core\object.cpp:2069)
    Leaked instance: PluggablePhysicsDirectSpaceState:579
    Leaked instance: PluggablePhysicsDirectBodyState:578
    Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).
    Orphan StringName: PluggablePhysicsDirectBodyState
    Orphan StringName: PluggablePhysicsDirectSpaceState
    StringName: 2 unclaimed string names at exit.
    

    I think we need to memdelete the singletons the server references.

    opened by geekrelief 2
  • gravity_well.tscn not working?

    gravity_well.tscn not working?

    Now I'm not sure if I have things setup properly. I assumed gravity_well.tscn is supposed to attract all the balls to the origin, but the balls just fall. Is there some setting I missed?

    opened by geekrelief 2
  • godot_rapier3d\addons\rapier3d\lib folder never created on Windows

    godot_rapier3d\addons\rapier3d\lib folder never created on Windows

    When you build the library is this folder supposed to be created? After I built Godot and the library and ran Godot (both in the benchmark and a new project), CMD was being spammed with Not Implemented errors and I realised in the debugger it said it couldn't find rapier3d.dll in this folder, the folder didn't even exist. I just created the folder myself and put the dll in it (which I found in godot_rapier3d\target\x86_64-pc-windows-msvc\release\deps) and it fixed the issue, but it's not supposed to be like that is it?

    bug good first issue 
    opened by Kair0ss 1
  • Does this work with Godot 3.3 or is this a 4.0 exlusive module?

    Does this work with Godot 3.3 or is this a 4.0 exlusive module?

    With the references to the PhysicsServer in the documentation, this seems like something built for 4.0. I'm really hoping that this could work with 3.3 as well though. Sorry for all of the questions by the way, I'm just very excited about this project.

    opened by ValorZard 1
  • Registering types for GDNative, fixed formatting

    Registering types for GDNative, fixed formatting

    I'm exposing some classes for GDNative. I needed these to compile code for Nim. Fixed some spaces/tabs. The rest of the edits are from Godot's .clang-format.

    opened by geekrelief 1
  • Use from_convex_hull instead of from_convex_mesh.

    Use from_convex_hull instead of from_convex_mesh.

    from_convex_hull automagically works and also does some optimization like deduplicating points it seems.

    #22 should be merged first.

    Closes #19

    @geekrelief can you check if this patch fixes your issue?

    opened by Demindiro 1
  • Box loose instances.

    Box loose instances.

    Rapier's RigidBody and joint structures are quite large, which bloated the Instance enum. This is very wasteful as loose instances are uncommon. Storing them on the heap significantly reduces the sizes of Areas, Bodies and Joints:

    • Area: 488 -> 216

    • Body: 536 -> 264

    • Joint: 200 -> 32

    opened by Demindiro 0
  • Replace RwLock with Mutex

    Replace RwLock with Mutex

    RwLock is a lot slower (up to ~2x) than a Mutex and only provides a benefit if multiple threads are reading data at the same time. Since most Godot applications are single-threaded and it's likely most will be using functions that require a write lock anyways, it's better to use Mutexes instead.

    enhancement performance 
    opened by Demindiro 0
  • Implement call to allow accessing additional functionality

    Implement call to allow accessing additional functionality

    This allows implementing additional Rapier-specific functionality without needing to modify the module (and recompiling the engine). It also keeps the module somewhat Rapier-agnostic.

    From the Godot side it's fairly clean, but using it from the Rust side is still a bit ugly.

    There is some overhead from the get_rid & get_index calls. There is not much that can be done about I'm afraid.

    body_set_local_com has been implemented already as it was easy to do so & I also need it for another project.

    Closes #38

    enhancement 
    opened by Demindiro 0
  • wchar library uses 32 bit chars for Windows builds instead of 16 bit.

    wchar library uses 32 bit chars for Windows builds instead of 16 bit.

    When running a Windows build with Wine the method argument in call has this value:

    [
        7274594,
        7929956,
        7536735,
        7602277,
        7077983,
        6488175,
        7077985,
        6488159,
        7143535,
    ]
    

    These are obviously not valid characters. However, when interpreting the values as 16 bit values with this Python code you get the expected string:

    for c in a:
        print(chr(c & 0xff), end="")
        print(chr(c >> 16), end="")
    

    Corresponding issue on the wchar repo: https://github.com/Juici/wchar-rs/issues/9.

    bug 
    opened by Demindiro 1
  • Are we able to enable determinism?

    Are we able to enable determinism?

    Hello! I'm quite interested in working on a rollback netcode project using Rapier, since it has a deterministic component. Godot's own physics are not great for this, but apparently according to this person, they were able to get a similar effect by controlling Box2D. https://github.com/godotengine/godot-proposals/issues/2821#issuecomment-854124881 I was wondering if a similar effect could be enabled with this, especially if the determinism feature flag could be enabled.

    documentation 
    opened by ValorZard 2
  • What's the purpose of rapier3d_standalone?

    What's the purpose of rapier3d_standalone?

    I'm playing around with the IntegrationParameters and noticed rapier3d_standalone is taking 20 seconds out of the 30 seconds to compile. So I commented it out, and it doesn't seem to affect running things in Godot.

    documentation 
    opened by geekrelief 3
  • Performance? Errors

    Performance? Errors

    First off, thanks for making this available. I'm looking forward to playing with this more to see if it's a good replacement for Bullet.

    I was wondering what kind of performance numbers you're getting on the benchmark? I'm running a Ryzen 5 3600 and I get quite a bit of stuttering and the framerate quickly drops. I added the time patch, looks like there's typo in the return type of get_physics_step_time_usec in engine.h. It's returning float when it should be uint64_t.

    Anyway, the dense test is giving me about 15fps. The initial framerate of sparse is >100 but quickly drops to the 40s when things start to collapse.

    I notice I'm getting a bunch of errors too:

    ERROR: <native>: TODO 0
       At: rapier3d\src\server\mod.rs:290
    ERROR: <native>: TODO 1
       At: rapier3d\src\server\mod.rs:290
    ERROR: <native>: TODO 2
       At: rapier3d\src\server\mod.rs:290
    ERROR: <native>: TODO free shape
       At: rapier3d\src\server\shape.rs:235
    ERROR: <native>: TODO free shape
       At: rapier3d\src\server\shape.rs:235
    ERROR: Not implemented
       At: modules\pluggable_physics\server.gen.cpp:1251
    WARNING: ObjectDB::cleanup: ObjectDB instances leaked at exit (run with --verbose for details).
         At: core\object.cpp:2069
    

    The TODOs are being spammed. Could that affect performance?

    Also, can you point me to where I can modify the velocity and position iterations? Thanks!

    performance 
    opened by geekrelief 4
  • [Tracker] Godot feature parity

    [Tracker] Godot feature parity

    This issue is to keep track of what features are still missing to achieve full compatibility with Godot.

    Area

    Fully implemented

    Body

    • [x] Contact events (#6)
    • [x] Ray pickable: it simply prevents the body from being detected by rays (#10)
    • [x] Continuous Collision Detection (CCD)
    • [x] Axis locking (#13)
      • Translation axises cannot be individually locked yet. I'm also not sure if it is worth spending effort into making it work (if it can be made to work properly at all).
    • [ ] Character controller
    • [ ] body_test_motion. This is not publicly documented but is present in Godot's source.
    • [ ] body_test_ray_separation. Ditto.

    Won't be implemented

    • Margins: they are not relevant in Rapier.

    Joints

    • [ ] 6DOF joint (requires FreeJoint to be implemented upstream)
    • [ ] Cone twist joint (not sure what exactly it's supposed to do, but it sounds like a BallJoint with limits)
    • [ ] Pin joint (FixedJoint)
    • [ ] Slider joint (can be partially implemented with PrismaticJoint, but requires PinslotJoint for rotations)
    • [ ] Angle limits for hinge joint (requires upstream implementation)

    Won't be implemented

    • Solver priority: Even Bullet doesn't support this (I've been bamboozled! Damnit)

    Soft bodies

    Soft bodies can't be implemented as they don't exist. It doesn't seem like they will be implemented soon either (no roadmap).

    Spaces

    Direct space state

    • [ ] cast_motion
    • [ ] get_rest_info
    • [x] intersect_shape (#31)
    enhancement 
    opened by Demindiro 5
Owner
David Hoppenbrouwers
Please check https://git.salt-inc.org/ for up-to-date repos. --- Not a duck, but I do quack from time to time.
David Hoppenbrouwers
Godex is a Godot Engine ECS library.

Godex Godex is a Godot Engine ecs library. Disclaimer: this module is still in development, open an issues to report any problem or a new discussion i

GodotECS 652 Jun 28, 2022
Steam API for the Godot game engine

Steam API for the Godot game engine

GP Garcia 1.2k Jul 1, 2022
Bounce is a 3D physics engine for games.

Bounce Welcome! Bounce is a 3D physics engine for games. Features Common Efficient data structures with no use of STL Fast memory allocators Built-in

Irlan Robson 64 Jun 25, 2022
SKR_Physics is a lightweight and easy to use 2D physics engine which is written in C++.

SKR_Physics SKR_Physics is a lightweight and easy to use 2D physics engine which is written in C++. Features Rectangle based collision system Very sim

Şükrü 0 Mar 8, 2022
Sequential impulses physics engine made for learning purposes

A 3D physics engine that uses Separating Axis Test for collision detection, the clipping method for generating contact manifold, contact point reducti

Ahmad Saleh 1 Nov 24, 2021
Box2D is a 2D physics engine for games

Build Status Box2D Box2D is a 2D physics engine for games. Contributing Please do not submit pull requests with new features or core library changes.

Erin Catto 5.7k Jul 2, 2022
C++ library for multi-physics simulation

Project Chrono represents a community effort aimed at producing a physics-based modelling and simulation infrastructure based on a platform-independent, open-source design.

null 1.4k Jun 23, 2022
A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.

Jolt Physics Library A multi core friendly rigid body physics and collision detection library suitable for games and VR applications. A YouTube video

null 1.8k Jun 27, 2022
This repository is about a school project about games with physics, written in C++.

Eight Ball Pool ?? A game about playing physics-based eight ball pool. ?? Table of Contents About Getting Started Usage Built Using About the creators

Valeri Ivanov 17 May 22, 2022
A game with basic physics and platforming.

Physgun A simple game with basic physics and platforming. Planned features Work in progress: Physics engine. Swept AABB collision algorithm. Elastic a

Bad Games Studio 24 Dec 17, 2021
Source code for Game Physics Cookbook

Game Physics Cookbook Website Facebook Twitter This book is a comprehensive guide to the linear algebra and collision detection games commonly use, bu

Gabor Szauer 612 Jun 27, 2022
🎮 C Bindings/Wrappers for Apple's METAL framework

Apple's Metal for C C Wrapper for Apple's METAL framework. This library is C bindings of Metal API (MetalGL). Since OpenGL is deprecated, this library

Recep Aslantas 104 Jun 24, 2022
LibRaylib Bindings for Crystal.

raylib-cr Crystal Bindings for raylib, a small and easy to use game development library. As for now the bindings only support the raw function calls f

Ian Rash 20 May 22, 2022
Improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World.

OpenXRay OpenXRay is an improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World. S

null 2k Jun 29, 2022
Flax Engine – multi-platform 3D game engine

Flax Engine – multi-platform 3D game engine

Flax Engine 3.4k Jul 1, 2022
CLUSEK-RT is a complex game engine written in C++ and the successor of the CLUSEK game engine

CLUSEK-RT is a complex game engine written in C++ and the successor of the CLUSEK game engine. This engine has been designed with a cross-platform design in mind. Thanks to Vulkan API it delivers a next-gen experience with ray tracing to both Linux and Windows platforms

Jakub Biliński 27 Jun 12, 2022
MAZE (My AmaZing Engine) - 🎮 Personal open-source cross-platform game engine

MAZE (My AmaZing Engine) is the self-written open-source cross-platform game engine in the active development stage. At the moment it is my main pet project, developed for the purpose of learning and preserving different game dev technologies.

Dmitriy Nosov 11 Jan 9, 2022
Ground Engine is an easy to use Game Engine for 3D Game Development written in C++

Ground Engine is an easy to use Game Engine Framework for 3D Game Development written in C++. It's currently under development and its creation will b

 PardCode 51 Jun 10, 2022
Rogy-Engine- - My 3D game engine source code.

Rogy-Engine Development My 3D game engine. (NOT THE FINAL VERSION- Windows only) Features: PBR shading and reflection probes with parallax correction.

AlaX 92 Jun 18, 2022