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

Add Jolt Physics as an alternative 3D physics engine #99895

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ Copyright: 2007, Starbreeze Studios
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib

Files: ./modules/jolt_physics/spaces/jolt_temp_allocator.cpp
Comment: Jolt Physics
Copyright: 2021, Jorrit Rouwe
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat

Files: ./modules/lightmapper_rd/lm_compute.glsl
Comment: Joint Non-Local Means (JNLM) denoiser
Copyright: 2020, Manuel Prandini
Expand Down Expand Up @@ -289,6 +296,11 @@ Comment: International Components for Unicode
Copyright: 2016-2024, Unicode, Inc.
License: Unicode

Files: ./thirdparty/jolt_physics/
Comment: Jolt Physics
Copyright: 2021, Jorrit Rouwe
License: Expat

Files: ./thirdparty/jpeg-compressor/
Comment: jpeg-compressor
Copyright: 2012, Rich Geldreich
Expand Down
8 changes: 4 additions & 4 deletions core/os/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
return p_obj;
}

#define memnew(m_class) _post_initialize(new ("") m_class)
#define memnew(m_class) _post_initialize(::new ("") m_class)

#define memnew_allocator(m_class, m_allocator) _post_initialize(new (m_allocator::alloc) m_class)
#define memnew_placement(m_placement, m_class) _post_initialize(new (m_placement) m_class)
#define memnew_allocator(m_class, m_allocator) _post_initialize(::new (m_allocator::alloc) m_class)
#define memnew_placement(m_placement, m_class) _post_initialize(::new (m_placement) m_class)

_ALWAYS_INLINE_ bool predelete_handler(void *) {
return true;
Expand Down Expand Up @@ -189,7 +189,7 @@ T *memnew_arr_template(size_t p_elements) {

/* call operator new */
for (size_t i = 0; i < p_elements; i++) {
new (&elems[i]) T;
::new (&elems[i]) T;
}
}

Expand Down
130 changes: 130 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,136 @@
[b]Note:[/b] This property is only read when the project starts. To change the physics FPS at runtime, set [member Engine.physics_ticks_per_second] instead.
[b]Note:[/b] Only [member physics/common/max_physics_steps_per_frame] physics ticks may be simulated per rendered frame at most. If more physics ticks have to be simulated per rendered frame to keep up with rendering, the project will appear to slow down (even if [code]delta[/code] is used consistently in physics calculations). Therefore, it is recommended to also increase [member physics/common/max_physics_steps_per_frame] if increasing [member physics/common/physics_ticks_per_second] significantly above its default value.
</member>
<member name="physics/jolt_physics_3d/collisions/active_edge_threshold" type="float" setter="" getter="" default="0.872665">
The maximum angle between two triangles (in a [ConcavePolygonShape3D] or [HeightMapShape3D]) within which a convex edge will be considered active or inactive.
Collisions against an inactive edge will have its normal overridden to instead be the surface normal of the triangle. This can help alleviate ghost collisions.
[b]Note:[/b] Setting this too high can result in objects not depenetrating properly.
[b]Note:[/b] This applies to all shape queries, as well as physics bodies within the simulation.
[b]Note:[/b] This does not apply when enabling Jolt's enhanced internal edge removal, which supersedes this.
</member>
<member name="physics/jolt_physics_3d/collisions/collision_margin_fraction" type="float" setter="" getter="" default="0.08">
The amount of collision margin to use for certain convex collision shapes, such as [BoxShape3D], [CylinderShape3D] and [ConvexPolygonShape3D], as a fraction of the shape's shortest axis.
[b]Note:[/b] Collision margins in Jolt do not add any extra size to the shape. Instead the shape is first shrunk by the margin and then inflated by the same amount, resulting in a shape with rounded edges. This is mainly used to speed up collision detection with convex shapes.
[b]Note:[/b] Setting this too low (e.g. 0) can also negatively affect the accuracy of the collision detection with convex shapes.
</member>
<member name="physics/jolt_physics_3d/joints/world_node" type="int" setter="" getter="" default="0">
Which of the two nodes in a single-body joint (i.e. when omitting one of the nodes) should represent the world. This can be thought of as having the omitted node be a [StaticBody3D] at [code](0, 0, 0)[/code].
[b]Note:[/b] Godot Physics uses [code]node_b[/code] as the default.
</member>
<member name="physics/jolt_physics_3d/limits/max_angular_velocity" type="float" setter="" getter="" default="47.1239">
The maximum angular velocity that a [RigidBody3D] can reach.
</member>
<member name="physics/jolt_physics_3d/limits/max_bodies" type="int" setter="" getter="" default="10240">
The maximum number of [PhysicsBody3D] to support at the same time, awake or sleeping.
[b]Note:[/b] When this limit is exceeded a warning is emitted and anything past that point is undefined behavior.
[b]Note:[/b] This limit also applies within the editor.
</member>
<member name="physics/jolt_physics_3d/limits/max_body_pairs" type="int" setter="" getter="" default="65536">
The maximum number of body pairs to allow processing of.
[b]Note:[/b] When this limit is exceeded collisions will randomly be ignored and bodies will pass through each other.
</member>
<member name="physics/jolt_physics_3d/limits/max_contact_constraints" type="int" setter="" getter="" default="20480">
The maximum number of contact constraints to allow processing of.
[b]Note:[/b] When this limit is exceeded collisions will randomly be ignored and bodies will pass through each other.
</member>
<member name="physics/jolt_physics_3d/limits/max_linear_velocity" type="float" setter="" getter="" default="500.0">
The maximum linear velocity that a [RigidBody3D] can reach.
</member>
<member name="physics/jolt_physics_3d/limits/temporary_memory_buffer_size" type="int" setter="" getter="" default="32">
The amount of memory to pre-allocate for the stack allocator used within Jolt.
</member>
<member name="physics/jolt_physics_3d/limits/world_boundary_shape_size" type="float" setter="" getter="" default="2000.0">
How wide/deep/high a [WorldBoundaryShape3D] will be.
[b]Note:[/b] Only half of this value will be used for its height.
[b]Note:[/b] Setting this too high can negatively affect the accuracy of the collision detection.
[b]Note:[/b] Collisions against the effective edges of a [WorldBoundaryShape3D] will be inconsistent.
</member>
<member name="physics/jolt_physics_3d/motion_queries/recovery_amount" type="float" setter="" getter="" default="0.4">
The amount of depenetration per iteration when depenetrating during motion queries.
[b]Note:[/b] This applies to [method CharacterBody3D.move_and_slide], [method PhysicsBody3D.move_and_collide] and [method PhysicsServer3D.body_test_motion].
</member>
<member name="physics/jolt_physics_3d/motion_queries/recovery_iterations" type="int" setter="" getter="" default="4">
The number of iterations to run when depenetrating during motion queries.
[b]Note:[/b] This applies to [method CharacterBody3D.move_and_slide], [method PhysicsBody3D.move_and_collide] and [method PhysicsServer3D.body_test_motion].
</member>
<member name="physics/jolt_physics_3d/motion_queries/use_enhanced_internal_edge_removal" type="bool" setter="" getter="" default="true">
Whether to use Jolt's enhanced internal edge removal during motion queries. This can help alleviate ghost collisions.
[b]Note:[/b] This applies to [method CharacterBody3D.move_and_slide], [method PhysicsBody3D.move_and_collide] and [method PhysicsServer3D.body_test_motion].
[b]Note:[/b] This will only remove edge collisions internal to a single body, meaning edges between separate bodies can still cause ghost collisions.
</member>
<member name="physics/jolt_physics_3d/queries/enable_ray_cast_face_index" type="bool" setter="" getter="" default="false">
Whether to populate the [code]face_index[/code] field in the results of [method PhysicsDirectSpaceState3D.intersect_ray], also accessed through [method RayCast3D.get_collision_face_index].
[b]Note:[/b] Enabling this setting will increase Jolt's memory usage for [ConcavePolygonShape3D] by around 25%.
[b]Note:[/b] The face index will be left at its default value of [code]-1[/code] when this setting is disabled.
</member>
<member name="physics/jolt_physics_3d/queries/use_enhanced_internal_edge_removal" type="bool" setter="" getter="" default="false">
Whether to use Jolt's enhanced internal edge removal during shape queries. This can help alleviate ghost collisions when using shape queries for things like character movement.
[b]Note:[/b] This applies to [method PhysicsDirectSpaceState3D.cast_motion], [method PhysicsDirectSpaceState3D.collide_shape], [method PhysicsDirectSpaceState3D.get_rest_info] and [method PhysicsDirectSpaceState3D.intersect_shape].
[b]Note:[/b] Enabling this setting can cause certain shapes to be culled from the results entirely, but you will get at least one intersection per body.
[b]Note:[/b] This will only remove edge collisions internal to a single body, meaning edges between separate bodies can still cause ghost collisions.
</member>
<member name="physics/jolt_physics_3d/simulation/allow_sleep" type="bool" setter="" getter="" default="true">
Whether [RigidBody3D] is allowed to go to sleep.
</member>
<member name="physics/jolt_physics_3d/simulation/areas_detect_static_bodies" type="bool" setter="" getter="" default="false">
Whether or not [Area3D] is able to detect overlaps with static physics bodies, such as [StaticBody3D].
[b]Note:[/b] Enabling this setting can come at a heavy CPU and memory cost if you allow many/large [Area3D] to overlap with complex static geometry, such as [ConcavePolygonShape3D] or [HeightMapShape3D]. It is strongly recommended that you set up your collision layers and masks in such a way that only a few small [Area3D] can detect static bodies.
[b]Note:[/b] This also applies to overlaps with [RigidBody3D] frozen with [constant RigidBody3D.FREEZE_MODE_STATIC].
[b]Note:[/b] This is not needed to detect overlaps with [AnimatableBody3D], which is a kinematic body.
</member>
<member name="physics/jolt_physics_3d/simulation/baumgarte_stabilization_factor" type="float" setter="" getter="" default="0.2">
How much of the position error of a [RigidBody3D] to fix during a physics step, where 0 is none and 1 is the full amount, which affect things like how quickly bodies depenetrate.
[b]Note:[/b] Setting this too high can result in instability for [RigidBody3D].
</member>
<member name="physics/jolt_physics_3d/simulation/body_pair_contact_cache_angle_threshold" type="float" setter="" getter="" default="0.0349066">
The maximum relative angle by which a body pair can move and still reuse the collision results from the previous physics step.
</member>
<member name="physics/jolt_physics_3d/simulation/body_pair_contact_cache_distance_threshold" type="float" setter="" getter="" default="0.001">
The maximum relative distance by which a body pair can move and still reuse the collision results from the previous physics step.
</member>
<member name="physics/jolt_physics_3d/simulation/body_pair_contact_cache_enabled" type="bool" setter="" getter="" default="true">
Whether the body pair contact cache is enabled, which removes the need for potentially expensive collision detection when the relative orientation between two bodies hasn't changed much.
</member>
<member name="physics/jolt_physics_3d/simulation/bounce_velocity_threshold" type="float" setter="" getter="" default="1.0">
The minimum velocity needed before a collision can be elastic.
</member>
<member name="physics/jolt_physics_3d/simulation/continuous_cd_max_penetration" type="float" setter="" getter="" default="0.25">
Fraction of its inner radius a body may penetrate another body whilst using CCD.
</member>
<member name="physics/jolt_physics_3d/simulation/continuous_cd_movement_threshold" type="float" setter="" getter="" default="0.75">
Fraction of its inner radius a body must move per step to make use of CCD.
</member>
<member name="physics/jolt_physics_3d/simulation/generate_all_kinematic_contacts" type="bool" setter="" getter="" default="false">
Whether or not a [RigidBody3D] frozen with [constant RigidBody3D.FREEZE_MODE_KINEMATIC] is able to collide with (and thus generate contacts for) other kinematic (and static) bodies.
[b]Note:[/b] This setting can come at a heavy CPU and memory cost if you allow many/large frozen kinematic bodies with a non-zero [member RigidBody3D.max_contacts_reported] to overlap with complex static geometry, such as [ConcavePolygonShape3D] or [HeightMapShape3D].
</member>
<member name="physics/jolt_physics_3d/simulation/penetration_slop" type="float" setter="" getter="" default="0.02">
How much bodies are allowed to penetrate each other.
</member>
<member name="physics/jolt_physics_3d/simulation/position_steps" type="int" setter="" getter="" default="2">
Number of solver position iterations. The greater the number of iterations, the more accurate the simulation will be, at the cost of CPU performance.
</member>
<member name="physics/jolt_physics_3d/simulation/sleep_time_threshold" type="float" setter="" getter="" default="0.5">
Time in seconds a [RigidBody3D] will spend below the sleep velocity threshold before going to sleep.
</member>
<member name="physics/jolt_physics_3d/simulation/sleep_velocity_threshold" type="float" setter="" getter="" default="0.03">
Velocity of certain points on the bounding box of a [RigidBody3D] below which it can be put to sleep.
</member>
<member name="physics/jolt_physics_3d/simulation/soft_body_point_radius" type="float" setter="" getter="" default="0.01">
How big the points of a [SoftBody3D] are. This can prevent things like cloth from laying perfectly flush against other surfaces and cause Z-fighting.
</member>
<member name="physics/jolt_physics_3d/simulation/speculative_contact_distance" type="float" setter="" getter="" default="0.02">
Radius around physics bodies inside which speculative contact points will be detected.
[b]Note:[/b] Setting this too high will result in ghost collisions, as speculative contacts are based on the closest points during the collision detection step which may not be the actual closest points by the time the two bodies hit.
</member>
<member name="physics/jolt_physics_3d/simulation/use_enhanced_internal_edge_removal" type="bool" setter="" getter="" default="true">
Whether to use Jolt's enhanced internal edge removal for [RigidBody3D]. This can help alleviate ghost collisions when (for example) a [RigidBody3D] collides with the edges of two perfectly joined [BoxShape3D].
[b]Note:[/b] This will only remove edge collisions internal to a single body, meaning edges between separate bodies can still cause ghost collisions.
</member>
<member name="physics/jolt_physics_3d/simulation/velocity_steps" type="int" setter="" getter="" default="10">
Number of solver velocity iterations. The greater the number of iterations, the more accurate the simulation will be, at the cost of CPU performance.
[b]Note:[/b] This needs to be at least [code]2[/code] in order for friction to work, as friction is applied using the non-penetration impulse from the previous iteration.
</member>
<member name="rendering/2d/batching/item_buffer_size" type="int" setter="" getter="" default="16384">
Maximum number of canvas item commands that can be batched into a single draw call.
</member>
Expand Down
Loading