Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] Add Jolt Physics as an alternative 3D physics engine #896

Draft
wants to merge 6 commits into
base: 4.3
Choose a base branch
from

Conversation

Spartan322
Copy link
Member

@Spartan322 Spartan322 commented Dec 12, 2024

Original PR: godotengine/godot#99895

Also adds Memory aligned_static functions from godotengine/godot#90993


This pull request adds a new engine module (found under modules/jolt_physics) which integrates Jolt Physics, a 3D physics engine developed by Jorrit Rouwe (@jrouwe) with a focus on games and VR applications, used in titles such as Horizon Forbidden West.

Users of this new module should (generally, but not always) be able to expect better physics performance, both in terms of CPU performance and simulation stability, when compared to Godot Physics.

This new module is a port of the Godot Jolt extension, developed by myself over the past two years, in large part as a personal project, but with the last year (including this port) being sponsored by W4 Games. I've also received a significant amount of assistance and contributions from @jrouwe during this development, which I'm very grateful for. In fact, several major features have been added to Jolt largely to cater to the needs of Godot.

Warning

Note that while this code has gone through a fair amount of battle-testing as part of the Godot Jolt extension there have been non-trivial refactorings done as part of this port that have not been tested much at all. As such, this module should be considered experimental for now. This module is also not at feature parity with Godot Physics just yet, nor at feature parity with the Godot Jolt extension either.

This does not replace Godot Physics as the default 3D physics engine. You will need to opt in by setting the physics/3d/physics_engine project setting to Jolt Physics.

Notable differences to Godot Physics

See godotengine/godot#99895

Notable differences to Godot Jolt

See godotengine/godot#99895

Things left to do

Just to give people an idea about the state of this module, and perhaps encourage future contributions if/when this pull request is merged, here is a rough copy of my to-do list:

Must-have

  • Add the ability for physics servers to add/remove/change node properties.
  • Using the ability to modify node properties, change the joint interfaces to better match Jolt.
  • Using the ability to modify node properties, move some of the project settings to instead be per-body/per-shape properties.
  • Add support for interactions between Area3D and SoftBody3D.
  • Implement the deferred compound shape mentioned above.
  • Add memory usage tracking for aligned allocations.
  • Add support for freezing PhysicalBone3D.
  • Investigate issues with motion queries mentioned above.
  • Resolve frustrations with invalid scaling.

Nice-to-have

  • Add migration for the project settings.
  • Get rid of heap allocations in shape queries when requested hits are less or equal to default.
  • Expose Jolt's debug rendering somehow (maybe as a viewport mode?).
  • Expose Jolt's debug snapshots somehow, if only just for dev_build.
  • Resolve discrepancy with single-body joints mentioned above.
  • Get rid of the body accessors in jolt_body_accessor_3d.h, in favor of just storing the JPH::Body* in JoltObject3D.
  • Try remove the use of JPH::PhysicsSystem::GetBodies, to avoid the overhead of iterating over static/sleeping bodies.
  • Maybe consider adding a temporary memory allocator that doesn't pre-allocate memory.
  • Link Jolt's Jolt.natvis file in MSVC builds for easier debugging.

What about the extension?

If/when this pull request is merged, the Godot Jolt extension will officially be considered to be in maintenance mode going forward, with only bug fixes backported to it, but so long as this engine module doesn't have full feature parity with the extension there will be new releases of the extension to ensure that projects relying on its additional features can continue to function.

If/when this engine module reaches full feature parity with the extension then the extension will be discontinued and its GitHub repository archived.

Attribution

In the interest of not cluttering every file in this new module with the copyright notice of Godot Jolt, as required by its MIT license, consider this my permission to omit it entirely. I have obtained permission from the applicable copyright holders (@jrouwe) to do so as well.

(This port is based on godot-jolt/godot-jolt@8f1212e, meaning the latest commit of Godot Jolt as of writing this.)

@Spartan322
Copy link
Member Author

Spartan322 commented Dec 12, 2024

Ah, sorry Jorrit I didn't mean to ping you here, I forgot to strip the ping from the description and just make it a link, kinda too late now.

darksylinc and others added 4 commits December 15, 2024 11:02
mihe and others added 2 commits December 17, 2024 18:54
(cherry picked from commit 5bbdb4a770d81b73863a88fcb74dbe3c86f024a4)
…support

Fixes #100557.

(cherry picked from commit 4727f0707ba12ef95f8f1ce33552edb8fa503f2e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants