Merge pull request #95252 from rburing/3d_physics_module

Move Godot Physics 3D into a module; add dummy 3D physics server
This commit is contained in:
Rémi Verschelde 2024-09-23 12:27:55 +02:00
commit dd71bc2d3b
No known key found for this signature in database
GPG Key ID: C3336907360768E1
61 changed files with 621 additions and 79 deletions

View File

@ -63,6 +63,39 @@ Copyright: 2011, Ole Kniemeyer, MAXON, www.maxon.net
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib
Files: ./modules/godot_physics_3d/gjk_epa.cpp
./modules/godot_physics_3d/joints/godot_generic_6dof_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_generic_6dof_joint_3d.h
./modules/godot_physics_3d/joints/godot_hinge_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_hinge_joint_3d_sw.h
./modules/godot_physics_3d/joints/godot_jacobian_entry_3d_sw.h
./modules/godot_physics_3d/joints/godot_pin_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_pin_joint_3d.h
./modules/godot_physics_3d/joints/godot_slider_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_slider_joint_3d.h
./modules/godot_physics_3d/godot_soft_body_3d.cpp
./modules/godot_physics_3d/godot_soft_body_3d.h
./modules/godot_physics_3d/godot_shape_3d.cpp
./modules/godot_physics_3d/godot_shape_3d.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2003-2008, Erwin Coumans
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib
Files: ./modules/godot_physics_3d/godot_collision_solver_3d_sat.cpp
Comment: Open Dynamics Engine
Copyright: 2001-2003, Russell L. Smith, Alen Ladavac, Nguyen Binh
License: BSD-3-clause
Files: ./modules/godot_physics_3d/joints/godot_cone_twist_joint_3d.cpp
./modules/godot_physics_3d/joints/godot_cone_twist_joint_3d.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2007, Starbreeze Studios
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib
Files: ./modules/lightmapper_rd/lm_compute.glsl
Comment: Joint Non-Local Means (JNLM) denoiser
Copyright: 2020, Manuel Prandini
@ -98,39 +131,6 @@ Comment: Chipmunk2D Joint Constraints
Copyright: 2007, Scott Lembcke
License: Expat
Files: ./servers/physics_3d/collision_solver_3d_sat.cpp
Comment: Open Dynamics Engine
Copyright: 2001-2003, Russell L. Smith, Alen Ladavac, Nguyen Binh
License: BSD-3-clause
Files: ./servers/physics_3d/gjk_epa.cpp
./servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
./servers/physics_3d/joints/generic_6dof_joint_3d_sw.h
./servers/physics_3d/joints/hinge_joint_3d_sw.cpp
./servers/physics_3d/joints/hinge_joint_3d_sw.h
./servers/physics_3d/joints/jacobian_entry_3d_sw.h
./servers/physics_3d/joints/pin_joint_3d_sw.cpp
./servers/physics_3d/joints/pin_joint_3d_sw.h
./servers/physics_3d/joints/slider_joint_3d_sw.cpp
./servers/physics_3d/joints/slider_joint_3d_sw.h
./servers/physics_3d/soft_body_3d_sw.cpp
./servers/physics_3d/soft_body_3d_sw.h
./servers/physics_3d/shape_3d_sw.cpp
./servers/physics_3d/shape_3d_sw.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2003-2008, Erwin Coumans
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib
Files: ./servers/physics_3d/joints/cone_twist_joint_3d_sw.cpp
./servers/physics_3d/joints/cone_twist_joint_3d_sw.h
Comment: Bullet Continuous Collision Detection and Physics Library
Copyright: 2007, Starbreeze Studios
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat and Zlib
Files: ./servers/rendering/renderer_rd/shaders/ss_effects_downsample.glsl
./servers/rendering/renderer_rd/shaders/ssao_blur.glsl
./servers/rendering/renderer_rd/shaders/ssao_importance_map.glsl

View File

@ -2293,6 +2293,7 @@
<member name="physics/3d/physics_engine" type="String" setter="" getter="" default="&quot;DEFAULT&quot;">
Sets which physics engine to use for 3D physics.
"DEFAULT" and "GodotPhysics3D" are the same, as there is currently no alternative 3D physics server implemented.
"Dummy" is a 3D physics server that does nothing and returns only dummy values, effectively disabling all 3D physics functionality.
</member>
<member name="physics/3d/run_on_separate_thread" type="bool" setter="" getter="" default="false">
If [code]true[/code], the 3D physics server runs on a separate thread, making better use of multi-core CPUs. If [code]false[/code], the 3D physics server runs on the main thread. Running the physics server on a separate thread can increase performance, but restricts API access to only physics process.

View File

@ -83,6 +83,7 @@
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#include "servers/physics_server_3d_dummy.h"
#include "servers/xr_server.h"
#endif // _3D_DISABLED
@ -320,7 +321,15 @@ void initialize_physics() {
// Physics server not found, Use the default physics
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
}
ERR_FAIL_NULL(physics_server_3d);
// Fall back to dummy if no default server has been registered.
if (!physics_server_3d) {
WARN_PRINT(vformat("Falling back to dummy PhysicsServer3D; 3D physics functionality will be disabled. If this is intended, set the %s project setting to Dummy.", PhysicsServer3DManager::setting_property_name));
physics_server_3d = memnew(PhysicsServer3DDummy);
}
// Should be impossible, but make sure it's not null.
ERR_FAIL_NULL_MSG(physics_server_3d, "Failed to initialize PhysicsServer3D.");
physics_server_3d->init();
#endif // _3D_DISABLED

View File

@ -0,0 +1,7 @@
#!/usr/bin/env python
Import('env')
env.add_source_files(env.modules_sources, "*.cpp")
SConscript("joints/SCsub")

View File

@ -0,0 +1,6 @@
def can_build(env, platform):
return not env["disable_3d"]
def configure(env):
pass

View File

@ -1629,8 +1629,6 @@ void GodotPhysicsServer3D::init() {
}
void GodotPhysicsServer3D::step(real_t p_step) {
#ifndef _3D_DISABLED
if (!active) {
return;
}
@ -1646,7 +1644,6 @@ void GodotPhysicsServer3D::step(real_t p_step) {
active_objects += E->get_active_objects();
collision_pairs += E->get_collision_pairs();
}
#endif
}
void GodotPhysicsServer3D::sync() {
@ -1654,8 +1651,6 @@ void GodotPhysicsServer3D::sync() {
}
void GodotPhysicsServer3D::flush_queries() {
#ifndef _3D_DISABLED
if (!active) {
return;
}
@ -1703,7 +1698,6 @@ void GodotPhysicsServer3D::flush_queries() {
values.push_front("physics_3d");
EngineDebugger::profiler_add_frame_data("servers", values);
}
#endif
}
void GodotPhysicsServer3D::end_sync() {

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python
Import('env')
env.add_source_files(env.modules_sources, "*.cpp")

View File

@ -52,8 +52,8 @@ subject to the following restrictions:
Written by: Marcus Hennix
*/
#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"
// GodotConeTwistJoint3D can be used to simulate ragdoll joints (upper arm, leg etc).
class GodotConeTwistJoint3D : public GodotJoint3D {

View File

@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/
#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"
/*
Bullet Continuous Collision Detection and Physics Library

View File

@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/
#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"
/*
Bullet Continuous Collision Detection and Physics Library

View File

@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/
#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"
/*
Bullet Continuous Collision Detection and Physics Library

View File

@ -35,8 +35,8 @@
Adapted to Godot from the Bullet library.
*/
#include "servers/physics_3d/godot_joint_3d.h"
#include "servers/physics_3d/joints/godot_jacobian_entry_3d.h"
#include "../godot_joint_3d.h"
#include "godot_jacobian_entry_3d.h"
/*
Bullet Continuous Collision Detection and Physics Library

View File

@ -0,0 +1,61 @@
/**************************************************************************/
/* register_types.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "register_types.h"
#include "godot_physics_server_3d.h"
#include "servers/physics_server_3d.h"
#include "servers/physics_server_3d_wrap_mt.h"
static PhysicsServer3D *_createGodotPhysics3DCallback() {
#ifdef THREADS_ENABLED
bool using_threads = GLOBAL_GET("physics/3d/run_on_separate_thread");
#else
bool using_threads = false;
#endif
PhysicsServer3D *physics_server_3d = memnew(GodotPhysicsServer3D(using_threads));
return memnew(PhysicsServer3DWrapMT(physics_server_3d, using_threads));
}
void initialize_godot_physics_3d_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
return;
}
PhysicsServer3DManager::get_singleton()->register_server("GodotPhysics3D", callable_mp_static(_createGodotPhysics3DCallback));
PhysicsServer3DManager::get_singleton()->set_default_server("GodotPhysics3D");
}
void uninitialize_godot_physics_3d_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
return;
}
}

View File

@ -0,0 +1,39 @@
/**************************************************************************/
/* register_types.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_PHYSICS_3D_REGISTER_TYPES_H
#define GODOT_PHYSICS_3D_REGISTER_TYPES_H
#include "modules/register_module_types.h"
void initialize_godot_physics_3d_module(ModuleInitializationLevel p_level);
void uninitialize_godot_physics_3d_module(ModuleInitializationLevel p_level);
#endif // GODOT_PHYSICS_3D_REGISTER_TYPES_H

View File

@ -322,6 +322,8 @@ def generate_scu_files(max_includes_per_scu):
process_folder(["modules/openxr"], ["register_types"])
process_folder(["modules/openxr/action_map"])
process_folder(["modules/openxr/editor"])
process_folder(["modules/godot_physics_3d"])
process_folder(["modules/godot_physics_3d/joints"])
process_folder(["modules/csg"])
process_folder(["modules/gdscript"])
@ -349,8 +351,6 @@ def generate_scu_files(max_includes_per_scu):
process_folder(["servers/rendering/renderer_rd/environment"])
process_folder(["servers/rendering/renderer_rd/storage_rd"])
process_folder(["servers/physics_2d"])
process_folder(["servers/physics_3d"])
process_folder(["servers/physics_3d/joints"])
process_folder(["servers/audio"])
process_folder(["servers/audio/effects"])

View File

@ -28,7 +28,6 @@ SConscript("text/SCsub")
SConscript("physics_2d/SCsub")
if not env["disable_3d"]:
SConscript("physics_3d/SCsub")
env.add_source_files(env.servers_sources, "physics_server_3d.cpp")
env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp")
SConscript("xr/SCsub")

View File

@ -1,7 +0,0 @@
#!/usr/bin/env python
Import("env")
env.add_source_files(env.servers_sources, "*.cpp")
SConscript("joints/SCsub")

View File

@ -1,5 +0,0 @@
#!/usr/bin/env python
Import("env")
env.add_source_files(env.servers_sources, "*.cpp")

View File

@ -1201,7 +1201,9 @@ String PhysicsServer3DManager::get_server_name(int p_id) {
}
PhysicsServer3D *PhysicsServer3DManager::new_default_server() {
ERR_FAIL_COND_V(default_server_id == -1, nullptr);
if (default_server_id == -1) {
return nullptr;
}
Variant ret;
Callable::CallError ce;
physics_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce);

View File

@ -0,0 +1,436 @@
/**************************************************************************/
/* physics_server_3d_dummy.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PHYSICS_SERVER_3D_DUMMY_H
#define PHYSICS_SERVER_3D_DUMMY_H
#include "servers/physics_server_3d.h"
class PhysicsDirectBodyState3DDummy : public PhysicsDirectBodyState3D {
GDCLASS(PhysicsDirectBodyState3DDummy, PhysicsDirectBodyState3D);
PhysicsDirectSpaceState3D *space_state_dummy = nullptr;
public:
virtual Vector3 get_total_gravity() const override { return Vector3(); }
virtual real_t get_total_angular_damp() const override { return 0; }
virtual real_t get_total_linear_damp() const override { return 0; }
virtual Vector3 get_center_of_mass() const override { return Vector3(); }
virtual Vector3 get_center_of_mass_local() const override { return Vector3(); }
virtual Basis get_principal_inertia_axes() const override { return Basis(); }
virtual real_t get_inverse_mass() const override { return 0; }
virtual Vector3 get_inverse_inertia() const override { return Vector3(); }
virtual Basis get_inverse_inertia_tensor() const override { return Basis(); }
virtual void set_linear_velocity(const Vector3 &p_velocity) override {}
virtual Vector3 get_linear_velocity() const override { return Vector3(); }
virtual void set_angular_velocity(const Vector3 &p_velocity) override {}
virtual Vector3 get_angular_velocity() const override { return Vector3(); }
virtual void set_transform(const Transform3D &p_transform) override {}
virtual Transform3D get_transform() const override { return Transform3D(); }
virtual Vector3 get_velocity_at_local_position(const Vector3 &p_position) const override { return Vector3(); }
virtual void apply_central_impulse(const Vector3 &p_impulse) override {}
virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) override {}
virtual void apply_torque_impulse(const Vector3 &p_impulse) override {}
virtual void apply_central_force(const Vector3 &p_force) override {}
virtual void apply_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) override {}
virtual void apply_torque(const Vector3 &p_torque) override {}
virtual void add_constant_central_force(const Vector3 &p_force) override {}
virtual void add_constant_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) override {}
virtual void add_constant_torque(const Vector3 &p_torque) override {}
virtual void set_constant_force(const Vector3 &p_force) override {}
virtual Vector3 get_constant_force() const override { return Vector3(); }
virtual void set_constant_torque(const Vector3 &p_torque) override {}
virtual Vector3 get_constant_torque() const override { return Vector3(); }
virtual void set_sleep_state(bool p_sleep) override {}
virtual bool is_sleeping() const override { return false; }
virtual int get_contact_count() const override { return 0; }
virtual Vector3 get_contact_local_position(int p_contact_idx) const override { return Vector3(); }
virtual Vector3 get_contact_local_normal(int p_contact_idx) const override { return Vector3(); }
virtual Vector3 get_contact_impulse(int p_contact_idx) const override { return Vector3(); }
virtual int get_contact_local_shape(int p_contact_idx) const override { return 0; }
virtual Vector3 get_contact_local_velocity_at_position(int p_contact_idx) const override { return Vector3(); }
virtual RID get_contact_collider(int p_contact_idx) const override { return RID(); }
virtual Vector3 get_contact_collider_position(int p_contact_idx) const override { return Vector3(); }
virtual ObjectID get_contact_collider_id(int p_contact_idx) const override { return ObjectID(); }
virtual Object *get_contact_collider_object(int p_contact_idx) const override { return nullptr; }
virtual int get_contact_collider_shape(int p_contact_idx) const override { return 0; }
virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const override { return Vector3(); }
virtual real_t get_step() const override { return 0; }
virtual void integrate_forces() override {}
virtual PhysicsDirectSpaceState3D *get_space_state() override { return space_state_dummy; }
PhysicsDirectBodyState3DDummy(PhysicsDirectSpaceState3D *p_space_state_dummy) {
space_state_dummy = p_space_state_dummy;
}
};
class PhysicsDirectSpaceState3DDummy : public PhysicsDirectSpaceState3D {
GDCLASS(PhysicsDirectSpaceState3DDummy, PhysicsDirectSpaceState3D);
public:
virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) override { return false; }
virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; }
virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; }
virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe, ShapeRestInfo *r_info = nullptr) override { return false; }
virtual bool collide_shape(const ShapeParameters &p_parameters, Vector3 *r_results, int p_result_max, int &r_result_count) override { return false; }
virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) override { return false; }
virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const override { return Vector3(); }
};
class PhysicsServer3DDummy : public PhysicsServer3D {
GDCLASS(PhysicsServer3DDummy, PhysicsServer3D);
PhysicsDirectBodyState3DDummy *body_state_dummy = nullptr;
PhysicsDirectSpaceState3DDummy *space_state_dummy = nullptr;
public:
virtual RID world_boundary_shape_create() override { return RID(); }
virtual RID separation_ray_shape_create() override { return RID(); }
virtual RID sphere_shape_create() override { return RID(); }
virtual RID box_shape_create() override { return RID(); }
virtual RID capsule_shape_create() override { return RID(); }
virtual RID cylinder_shape_create() override { return RID(); }
virtual RID convex_polygon_shape_create() override { return RID(); }
virtual RID concave_polygon_shape_create() override { return RID(); }
virtual RID heightmap_shape_create() override { return RID(); }
virtual RID custom_shape_create() override { return RID(); }
virtual void shape_set_data(RID p_shape, const Variant &p_data) override {}
virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) override {}
virtual ShapeType shape_get_type(RID p_shape) const override { return SHAPE_SPHERE; }
virtual Variant shape_get_data(RID p_shape) const override { return Variant(); }
virtual void shape_set_margin(RID p_shape, real_t p_margin) override {}
virtual real_t shape_get_margin(RID p_shape) const override { return 0; }
virtual real_t shape_get_custom_solver_bias(RID p_shape) const override { return 0; }
/* SPACE API */
virtual RID space_create() override { return RID(); }
virtual void space_set_active(RID p_space, bool p_active) override {}
virtual bool space_is_active(RID p_space) const override { return false; }
virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) override {}
virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const override { return 0; }
virtual PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space) override { return space_state_dummy; }
virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) override {}
virtual Vector<Vector3> space_get_contacts(RID p_space) const override { return Vector<Vector3>(); }
virtual int space_get_contact_count(RID p_space) const override { return 0; }
/* AREA API */
virtual RID area_create() override { return RID(); }
virtual void area_set_space(RID p_area, RID p_space) override {}
virtual RID area_get_space(RID p_area) const override { return RID(); }
virtual void area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform = Transform3D(), bool p_disabled = false) override {}
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) override {}
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) override {}
virtual int area_get_shape_count(RID p_area) const override { return 0; }
virtual RID area_get_shape(RID p_area, int p_shape_idx) const override { return RID(); }
virtual Transform3D area_get_shape_transform(RID p_area, int p_shape_idx) const override { return Transform3D(); }
virtual void area_remove_shape(RID p_area, int p_shape_idx) override {}
virtual void area_clear_shapes(RID p_area) override {}
virtual void area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) override {}
virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) override {}
virtual ObjectID area_get_object_instance_id(RID p_area) const override { return ObjectID(); }
virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) override {}
virtual void area_set_transform(RID p_area, const Transform3D &p_transform) override {}
virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const override { return Variant(); }
virtual Transform3D area_get_transform(RID p_area) const override { return Transform3D(); }
virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override {}
virtual uint32_t area_get_collision_layer(RID p_area) const override { return 0; }
virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override {}
virtual uint32_t area_get_collision_mask(RID p_area) const override { return 0; }
virtual void area_set_monitorable(RID p_area, bool p_monitorable) override {}
virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) override {}
virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) override {}
virtual void area_set_ray_pickable(RID p_area, bool p_enable) override {}
/* BODY API */
virtual RID body_create() override { return RID(); }
virtual void body_set_space(RID p_body, RID p_space) override {}
virtual RID body_get_space(RID p_body) const override { return RID(); }
virtual void body_set_mode(RID p_body, BodyMode p_mode) override {}
virtual BodyMode body_get_mode(RID p_body) const override { return BodyMode::BODY_MODE_STATIC; }
virtual void body_add_shape(RID p_body, RID p_shape, const Transform3D &p_transform = Transform3D(), bool p_disabled = false) override {}
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) override {}
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform3D &p_transform) override {}
virtual int body_get_shape_count(RID p_body) const override { return 0; }
virtual RID body_get_shape(RID p_body, int p_shape_idx) const override { return RID(); }
virtual Transform3D body_get_shape_transform(RID p_body, int p_shape_idx) const override { return Transform3D(); }
virtual void body_remove_shape(RID p_body, int p_shape_idx) override {}
virtual void body_clear_shapes(RID p_body) override {}
virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) override {}
virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) override {}
virtual ObjectID body_get_object_instance_id(RID p_body) const override { return ObjectID(); }
virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) override {}
virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const override { return false; }
virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) override {}
virtual uint32_t body_get_collision_layer(RID p_body) const override { return 0; }
virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) override {}
virtual uint32_t body_get_collision_mask(RID p_body) const override { return 0; }
virtual void body_set_collision_priority(RID p_body, real_t p_priority) override {}
virtual real_t body_get_collision_priority(RID p_body) const override { return 0; }
virtual void body_set_user_flags(RID p_body, uint32_t p_flags) override {}
virtual uint32_t body_get_user_flags(RID p_body) const override { return 0; }
virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) override {}
virtual Variant body_get_param(RID p_body, BodyParameter p_param) const override { return Variant(); }
virtual void body_reset_mass_properties(RID p_body) override {}
virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override {}
virtual Variant body_get_state(RID p_body, BodyState p_state) const override { return Variant(); }
virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) override {}
virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) override {}
virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) override {}
virtual void body_apply_central_force(RID p_body, const Vector3 &p_force) override {}
virtual void body_apply_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) override {}
virtual void body_apply_torque(RID p_body, const Vector3 &p_torque) override {}
virtual void body_add_constant_central_force(RID p_body, const Vector3 &p_force) override {}
virtual void body_add_constant_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) override {}
virtual void body_add_constant_torque(RID p_body, const Vector3 &p_torque) override {}
virtual void body_set_constant_force(RID p_body, const Vector3 &p_force) override {}
virtual Vector3 body_get_constant_force(RID p_body) const override { return Vector3(); }
virtual void body_set_constant_torque(RID p_body, const Vector3 &p_torque) override {}
virtual Vector3 body_get_constant_torque(RID p_body) const override { return Vector3(); }
virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) override {}
virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) override {}
virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) const override { return false; }
virtual void body_add_collision_exception(RID p_body, RID p_body_b) override {}
virtual void body_remove_collision_exception(RID p_body, RID p_body_b) override {}
virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override {}
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) override {}
virtual int body_get_max_contacts_reported(RID p_body) const override { return 0; }
virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) override {}
virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const override { return 0; }
virtual void body_set_omit_force_integration(RID p_body, bool p_omit) override {}
virtual bool body_is_omitting_force_integration(RID p_body) const override { return false; }
virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) override {}
virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) override {}
virtual void body_set_ray_pickable(RID p_body, bool p_enable) override {}
virtual PhysicsDirectBodyState3D *body_get_direct_state(RID p_body) override { return body_state_dummy; }
virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override { return false; }
/* SOFT BODY */
virtual RID soft_body_create() override { return RID(); }
virtual void soft_body_update_rendering_server(RID p_body, PhysicsServer3DRenderingServerHandler *p_rendering_server_handler) override {}
virtual void soft_body_set_space(RID p_body, RID p_space) override {}
virtual RID soft_body_get_space(RID p_body) const override { return RID(); }
virtual void soft_body_set_mesh(RID p_body, RID p_mesh) override {}
virtual AABB soft_body_get_bounds(RID p_body) const override { return AABB(); }
virtual void soft_body_set_collision_layer(RID p_body, uint32_t p_layer) override {}
virtual uint32_t soft_body_get_collision_layer(RID p_body) const override { return 0; }
virtual void soft_body_set_collision_mask(RID p_body, uint32_t p_mask) override {}
virtual uint32_t soft_body_get_collision_mask(RID p_body) const override { return 0; }
virtual void soft_body_add_collision_exception(RID p_body, RID p_body_b) override {}
virtual void soft_body_remove_collision_exception(RID p_body, RID p_body_b) override {}
virtual void soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override {}
virtual void soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override {}
virtual Variant soft_body_get_state(RID p_body, BodyState p_state) const override { return Variant(); }
virtual void soft_body_set_transform(RID p_body, const Transform3D &p_transform) override {}
virtual void soft_body_set_ray_pickable(RID p_body, bool p_enable) override {}
virtual void soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) override {}
virtual int soft_body_get_simulation_precision(RID p_body) const override { return 0; }
virtual void soft_body_set_total_mass(RID p_body, real_t p_total_mass) override {}
virtual real_t soft_body_get_total_mass(RID p_body) const override { return 0; }
virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) override {}
virtual real_t soft_body_get_linear_stiffness(RID p_body) const override { return 0; }
virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) override {}
virtual real_t soft_body_get_pressure_coefficient(RID p_body) const override { return 0; }
virtual void soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) override {}
virtual real_t soft_body_get_damping_coefficient(RID p_body) const override { return 0; }
virtual void soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) override {}
virtual real_t soft_body_get_drag_coefficient(RID p_body) const override { return 0; }
virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) override {}
virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index) const override { return Vector3(); }
virtual void soft_body_remove_all_pinned_points(RID p_body) override {}
virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) override {}
virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index) const override { return false; }
/* JOINT API */
virtual RID joint_create() override { return RID(); }
virtual void joint_clear(RID p_joint) override {}
virtual JointType joint_get_type(RID p_joint) const override { return JointType::JOINT_TYPE_PIN; }
virtual void joint_set_solver_priority(RID p_joint, int p_priority) override {}
virtual int joint_get_solver_priority(RID p_joint) const override { return 0; }
virtual void joint_disable_collisions_between_bodies(RID p_joint, bool p_disable) override {}
virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const override { return false; }
virtual void joint_make_pin(RID p_joint, RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) override {}
virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) override {}
virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const override { return 0; }
virtual void pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) override {}
virtual Vector3 pin_joint_get_local_a(RID p_joint) const override { return Vector3(); }
virtual void pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) override {}
virtual Vector3 pin_joint_get_local_b(RID p_joint) const override { return Vector3(); }
virtual void joint_make_hinge(RID p_joint, RID p_body_A, const Transform3D &p_hinge_A, RID p_body_B, const Transform3D &p_hinge_B) override {}
virtual void joint_make_hinge_simple(RID p_joint, RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) override {}
virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) override {}
virtual real_t hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const override { return 0; }
virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_enabled) override {}
virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const override { return false; }
virtual void joint_make_slider(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) override {}
virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) override {}
virtual real_t slider_joint_get_param(RID p_joint, SliderJointParam p_param) const override { return 0; }
virtual void joint_make_cone_twist(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) override {}
virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) override {}
virtual real_t cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const override { return 0; }
virtual void joint_make_generic_6dof(RID p_joint, RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) override {}
virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param, real_t p_value) override {}
virtual real_t generic_6dof_joint_get_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param) const override { return 0; }
virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag, bool p_enable) override {}
virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag) const override { return false; }
/* MISC */
virtual void free(RID p_rid) override {}
virtual void set_active(bool p_active) override {}
virtual void init() override {
space_state_dummy = memnew(PhysicsDirectSpaceState3DDummy);
body_state_dummy = memnew(PhysicsDirectBodyState3DDummy(space_state_dummy));
}
virtual void step(real_t p_step) override {}
virtual void sync() override {}
virtual void flush_queries() override {}
virtual void end_sync() override {}
virtual void finish() override {
memdelete(body_state_dummy);
memdelete(space_state_dummy);
}
virtual bool is_flushing_queries() const override { return false; }
virtual int get_process_info(ProcessInfo p_info) override { return 0; }
};
#endif // PHYSICS_SERVER_3D_DUMMY_H

View File

@ -89,8 +89,8 @@
// 3D physics and navigation (3D navigation is needed for 2D).
#include "navigation_server_3d.h"
#ifndef _3D_DISABLED
#include "physics_3d/godot_physics_server_3d.h"
#include "physics_server_3d.h"
#include "physics_server_3d_dummy.h"
#include "physics_server_3d_wrap_mt.h"
#include "servers/extensions/physics_server_3d_extension.h"
#include "xr/xr_body_tracker.h"
@ -106,16 +106,8 @@
ShaderTypes *shader_types = nullptr;
#ifndef _3D_DISABLED
static PhysicsServer3D *_createGodotPhysics3DCallback() {
#ifdef THREADS_ENABLED
bool using_threads = GLOBAL_GET("physics/3d/run_on_separate_thread");
#else
bool using_threads = false;
#endif
PhysicsServer3D *physics_server_3d = memnew(GodotPhysicsServer3D(using_threads));
return memnew(PhysicsServer3DWrapMT(physics_server_3d, using_threads));
static PhysicsServer3D *_create_dummy_physics_server_3d() {
return memnew(PhysicsServer3DDummy);
}
#endif // _3D_DISABLED
@ -323,8 +315,7 @@ void register_server_types() {
GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer3DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT");
PhysicsServer3DManager::get_singleton()->register_server("GodotPhysics3D", callable_mp_static(_createGodotPhysics3DCallback));
PhysicsServer3DManager::get_singleton()->set_default_server("GodotPhysics3D");
PhysicsServer3DManager::get_singleton()->register_server("Dummy", callable_mp_static(_create_dummy_physics_server_3d));
GDREGISTER_ABSTRACT_CLASS(XRInterface);
GDREGISTER_CLASS(XRVRS);

View File

@ -176,6 +176,7 @@
#include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#include "servers/physics_server_3d_dummy.h"
#endif // _3D_DISABLED
#include "servers/rendering/rendering_server_default.h"
@ -290,6 +291,9 @@ struct GodotTestCaseListener : public doctest::IReporter {
#ifndef _3D_DISABLED
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
if (!physics_server_3d) {
physics_server_3d = memnew(PhysicsServer3DDummy);
}
physics_server_3d->init();
#endif // _3D_DISABLED