Forráskód Böngészése

Merge pull request #103373 from YeldhamDev/build_remove_physics

Allow to compile templates without physics servers
Rémi Verschelde 4 hónapja
szülő
commit
e8bc75f056
72 módosított fájl, 945 hozzáadás és 358 törlés
  1. 1 1
      .github/workflows/linux_builds.yml
  2. 22 12
      SConstruct
  3. 5 0
      core/config/project_settings.cpp
  4. 13 2
      editor/editor_node.cpp
  5. 1 1
      editor/plugins/canvas_item_editor_plugin.cpp
  6. 1 1
      editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp
  7. 1 1
      editor/plugins/gizmos/physics_bone_3d_gizmo_plugin.cpp
  8. 1 1
      editor/plugins/gizmos/soft_body_3d_gizmo_plugin.cpp
  9. 1 1
      editor/plugins/skeleton_3d_editor_plugin.cpp
  10. 7 0
      editor/project_manager.cpp
  11. 50 22
      main/main.cpp
  12. 19 9
      main/performance.cpp
  13. 34 12
      modules/csg/csg_shape.cpp
  14. 9 0
      modules/csg/csg_shape.h
  15. 2 1
      modules/gltf/extensions/SCsub
  16. 9 2
      modules/gltf/register_types.cpp
  17. 1 1
      modules/godot_physics_2d/config.py
  18. 1 1
      modules/godot_physics_3d/config.py
  19. 33 1
      modules/gridmap/grid_map.cpp
  20. 8 0
      modules/gridmap/grid_map.h
  21. 1 1
      modules/jolt_physics/config.py
  22. 1 1
      modules/vhacd/config.py
  23. 2 1
      scene/2d/SCsub
  24. 7 2
      scene/2d/audio_stream_player_2d.cpp
  25. 0 0
      scene/2d/physics/touch_screen_button.cpp
  26. 0 0
      scene/2d/physics/touch_screen_button.h
  27. 4 0
      scene/2d/tile_map.cpp
  28. 2 0
      scene/2d/tile_map.h
  29. 32 4
      scene/2d/tile_map_layer.cpp
  30. 12 0
      scene/2d/tile_map_layer.h
  31. 2 1
      scene/3d/SCsub
  32. 20 3
      scene/3d/audio_stream_player_3d.cpp
  33. 6 0
      scene/3d/audio_stream_player_3d.h
  34. 6 0
      scene/3d/camera_3d.cpp
  35. 4 0
      scene/3d/camera_3d.h
  36. 11 5
      scene/3d/mesh_instance_3d.cpp
  37. 2 0
      scene/3d/mesh_instance_3d.h
  38. 1 1
      scene/3d/physics/physical_bone_3d.cpp
  39. 0 0
      scene/3d/physics/physical_bone_simulator_3d.cpp
  40. 0 0
      scene/3d/physics/physical_bone_simulator_3d.h
  41. 0 0
      scene/3d/physics/soft_body_3d.compat.inc
  42. 0 0
      scene/3d/physics/soft_body_3d.cpp
  43. 0 0
      scene/3d/physics/soft_body_3d.h
  44. 15 11
      scene/3d/skeleton_3d.cpp
  45. 4 2
      scene/3d/skeleton_3d.h
  46. 24 7
      scene/debugger/scene_debugger.cpp
  47. 23 8
      scene/main/scene_tree.cpp
  48. 58 17
      scene/main/viewport.cpp
  49. 10 0
      scene/main/viewport.h
  50. 145 108
      scene/register_scene_types.cpp
  51. 17 2
      scene/resources/2d/SCsub
  52. 16 0
      scene/resources/2d/skeleton/SCsub
  53. 105 63
      scene/resources/2d/tile_set.cpp
  54. 17 1
      scene/resources/2d/tile_set.h
  55. 21 1
      scene/resources/3d/SCsub
  56. 6 1
      scene/resources/3d/importer_mesh.cpp
  57. 7 2
      scene/resources/3d/importer_mesh.h
  58. 16 0
      scene/resources/3d/mesh_library.cpp
  59. 13 0
      scene/resources/3d/mesh_library.h
  60. 12 0
      scene/resources/3d/world_3d.cpp
  61. 4 1
      scene/resources/3d/world_3d.h
  62. 10 8
      scene/resources/mesh.cpp
  63. 7 6
      scene/resources/mesh.h
  64. 2 0
      scene/resources/physics_material.cpp
  65. 2 0
      scene/resources/physics_material.h
  66. 14 4
      scene/resources/world_2d.cpp
  67. 6 1
      scene/resources/world_2d.h
  68. 8 6
      servers/SCsub
  69. 20 12
      servers/register_server_types.cpp
  70. 2 0
      tests/scene/test_text_edit.h
  71. 8 2
      tests/scene/test_viewport.h
  72. 21 7
      tests/test_main.cpp

+ 1 - 1
.github/workflows/linux_builds.yml

@@ -90,7 +90,7 @@ jobs:
           - name: Minimal template (target=template_release, tests=yes, everything disabled)
             cache-name: linux-template-minimal
             target: template_release
-            sconsflags: modules_enabled_by_default=no disable_3d=yes disable_advanced_gui=yes deprecated=no minizip=no
+            sconsflags: modules_enabled_by_default=no disable_3d=yes disable_advanced_gui=yes disable_physics_2d=yes disable_physics_3d=yes deprecated=no minizip=no
             bin: ./bin/godot.linuxbsd.template_release.x86_64
             tests: true
             artifact: true

+ 22 - 12
SConstruct

@@ -220,6 +220,8 @@ opts.Add("vsproj_name", "Name of the Visual Studio solution", "godot")
 opts.Add("import_env_vars", "A comma-separated list of environment variables to copy from the outer environment.", "")
 opts.Add(BoolVariable("disable_3d", "Disable 3D nodes for a smaller executable", False))
 opts.Add(BoolVariable("disable_advanced_gui", "Disable advanced GUI nodes and behaviors", False))
+opts.Add(BoolVariable("disable_physics_2d", "Disable 2D physics nodes and server", False))
+opts.Add(BoolVariable("disable_physics_3d", "Disable 3D physics nodes and server", False))
 opts.Add(BoolVariable("disable_xr", "Disable XR nodes and server", False))
 opts.Add("build_profile", "Path to a file containing a feature build profile", "")
 opts.Add(BoolVariable("modules_enabled_by_default", "If no, disable all modules except ones explicitly enabled", True))
@@ -935,21 +937,29 @@ suffix += env.extra_suffix
 sys.path.remove(tmppath)
 sys.modules.pop("detect")
 
-if env["disable_3d"]:
-    if env.editor_build:
-        print_error("Build option `disable_3d=yes` cannot be used for editor builds, only for export template builds.")
-        Exit(255)
-    else:
-        env.Append(CPPDEFINES=["_3D_DISABLED"])
-        env["disable_xr"] = True
-if env["disable_advanced_gui"]:
-    if env.editor_build:
+if env.editor_build:
+    unsupported_opts = []
+    for disable_opt in ["disable_3d", "disable_advanced_gui", "disable_physics_2d", "disable_physics_3d"]:
+        if env[disable_opt]:
+            unsupported_opts.append(disable_opt)
+    if unsupported_opts != []:
         print_error(
-            "Build option `disable_advanced_gui=yes` cannot be used for editor builds, only for export template builds."
+            "The following build option(s) cannot be used for editor builds, but only for export template builds: {}.".format(
+                ", ".join(unsupported_opts)
+            )
         )
         Exit(255)
-    else:
-        env.Append(CPPDEFINES=["ADVANCED_GUI_DISABLED"])
+
+if env["disable_3d"]:
+    env.Append(CPPDEFINES=["_3D_DISABLED"])
+    env["disable_physics_3d"] = True
+    env["disable_xr"] = True
+if env["disable_advanced_gui"]:
+    env.Append(CPPDEFINES=["ADVANCED_GUI_DISABLED"])
+if env["disable_physics_2d"]:
+    env.Append(CPPDEFINES=["PHYSICS_2D_DISABLED"])
+if env["disable_physics_3d"]:
+    env.Append(CPPDEFINES=["PHYSICS_3D_DISABLED"])
 if env["disable_xr"]:
     env.Append(CPPDEFINES=["XR_DISABLED"])
 if env["minizip"]:

+ 5 - 0
core/config/project_settings.cpp

@@ -1548,8 +1548,13 @@ ProjectSettings::ProjectSettings() {
 #else
 	custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Unsafe (deprecated),Safe,Separate");
 #endif
+
+#ifndef PHYSICS_2D_DISABLED
 	GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
+#endif // PHYSICS_3D_DISABLED
 
 	GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport"), "disabled");
 	GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand"), "keep");

+ 13 - 2
editor/editor_node.cpp

@@ -69,7 +69,6 @@
 #include "scene/theme/theme_db.h"
 #include "servers/display_server.h"
 #include "servers/navigation_server_3d.h"
-#include "servers/physics_server_2d.h"
 #include "servers/rendering_server.h"
 
 #include "editor/audio_stream_preview.h"
@@ -167,9 +166,17 @@
 
 #include "modules/modules_enabled.gen.h" // For gdscript, mono.
 
+#ifndef PHYSICS_2D_DISABLED
+#include "servers/physics_server_2d.h"
+#endif // PHYSICS_2D_DISABLED
+
+#ifndef PHYSICS_3D_DISABLED
+#include "servers/physics_server_3d.h"
+#endif // PHYSICS_3D_DISABLED
+
 #ifdef ANDROID_ENABLED
 #include "editor/gui/touch_actions_panel.h"
-#endif
+#endif // ANDROID_ENABLED
 
 #include <stdlib.h>
 
@@ -7055,8 +7062,12 @@ EditorNode::EditorNode() {
 		}
 
 		// No physics by default if in editor.
+#ifndef PHYSICS_3D_DISABLED
 		PhysicsServer3D::get_singleton()->set_active(false);
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 		PhysicsServer2D::get_singleton()->set_active(false);
+#endif // PHYSICS_2D_DISABLED
 
 		// No scripting by default if in editor (except for tool).
 		ScriptServer::set_scripting_enabled(false);

+ 1 - 1
editor/plugins/canvas_item_editor_plugin.cpp

@@ -49,10 +49,10 @@
 #include "editor/themes/editor_scale.h"
 #include "editor/themes/editor_theme_manager.h"
 #include "scene/2d/audio_stream_player_2d.h"
+#include "scene/2d/physics/touch_screen_button.h"
 #include "scene/2d/polygon_2d.h"
 #include "scene/2d/skeleton_2d.h"
 #include "scene/2d/sprite_2d.h"
-#include "scene/2d/touch_screen_button.h"
 #include "scene/gui/base_button.h"
 #include "scene/gui/flow_container.h"
 #include "scene/gui/grid_container.h"

+ 1 - 1
editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp

@@ -32,7 +32,7 @@
 
 #include "editor/plugins/node_3d_editor_plugin.h"
 #include "scene/3d/mesh_instance_3d.h"
-#include "scene/3d/soft_body_3d.h"
+#include "scene/3d/physics/soft_body_3d.h"
 #include "scene/resources/3d/primitive_meshes.h"
 
 bool MeshInstance3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {

+ 1 - 1
editor/plugins/gizmos/physics_bone_3d_gizmo_plugin.cpp

@@ -32,8 +32,8 @@
 
 #include "editor/editor_settings.h"
 #include "editor/plugins/gizmos/joint_3d_gizmo_plugin.h"
-#include "scene/3d/physical_bone_simulator_3d.h"
 #include "scene/3d/physics/physical_bone_3d.h"
+#include "scene/3d/physics/physical_bone_simulator_3d.h"
 
 PhysicalBone3DGizmoPlugin::PhysicalBone3DGizmoPlugin() {
 	create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));

+ 1 - 1
editor/plugins/gizmos/soft_body_3d_gizmo_plugin.cpp

@@ -30,7 +30,7 @@
 
 #include "soft_body_3d_gizmo_plugin.h"
 
-#include "scene/3d/soft_body_3d.h"
+#include "scene/3d/physics/soft_body_3d.h"
 
 SoftBody3DGizmoPlugin::SoftBody3DGizmoPlugin() {
 	Color gizmo_color = SceneTree::get_singleton()->get_debug_collisions_color();

+ 1 - 1
editor/plugins/skeleton_3d_editor_plugin.cpp

@@ -41,9 +41,9 @@
 #include "editor/plugins/node_3d_editor_plugin.h"
 #include "editor/themes/editor_scale.h"
 #include "scene/3d/mesh_instance_3d.h"
-#include "scene/3d/physical_bone_simulator_3d.h"
 #include "scene/3d/physics/collision_shape_3d.h"
 #include "scene/3d/physics/physical_bone_3d.h"
+#include "scene/3d/physics/physical_bone_simulator_3d.h"
 #include "scene/gui/separator.h"
 #include "scene/gui/texture_rect.h"
 #include "scene/resources/3d/capsule_shape_3d.h"

+ 7 - 0
editor/project_manager.cpp

@@ -63,7 +63,14 @@
 #include "scene/theme/theme_db.h"
 #include "servers/display_server.h"
 #include "servers/navigation_server_3d.h"
+
+#ifndef PHYSICS_3D_DISABLED
+#include "servers/physics_server_3d.h"
+#endif // PHYSICS_3D_DISABLED
+
+#ifndef PHYSICS_2D_DISABLED
 #include "servers/physics_server_2d.h"
+#endif // PHYSICS_2D_DISABLED
 
 constexpr int GODOT4_CONFIG_VERSION = 5;
 

+ 50 - 22
main/main.cpp

@@ -82,12 +82,16 @@
 // 2D
 #include "servers/navigation_server_2d.h"
 #include "servers/navigation_server_2d_dummy.h"
+#ifndef PHYSICS_2D_DISABLED
 #include "servers/physics_server_2d.h"
 #include "servers/physics_server_2d_dummy.h"
+#endif // PHYSICS_2D_DISABLED
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 #include "servers/physics_server_3d.h"
 #include "servers/physics_server_3d_dummy.h"
+#endif // PHYSICS_3D_DISABLED
+#ifndef _3D_DISABLED
 #include "servers/xr_server.h"
 #endif // _3D_DISABLED
 
@@ -164,11 +168,15 @@ static DisplayServer *display_server = nullptr;
 static RenderingServer *rendering_server = nullptr;
 static TextServerManager *tsman = nullptr;
 static ThemeDB *theme_db = nullptr;
+#ifndef PHYSICS_2D_DISABLED
 static PhysicsServer2DManager *physics_server_2d_manager = nullptr;
 static PhysicsServer2D *physics_server_2d = nullptr;
-#ifndef _3D_DISABLED
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 static PhysicsServer3DManager *physics_server_3d_manager = nullptr;
 static PhysicsServer3D *physics_server_3d = nullptr;
+#endif // PHYSICS_3D_DISABLED
+#ifndef _3D_DISABLED
 static XRServer *xr_server = nullptr;
 #endif // _3D_DISABLED
 // We error out if setup2() doesn't turn this true
@@ -327,7 +335,7 @@ static Vector<String> get_files_with_extension(const String &p_root, const Strin
 
 // FIXME: Could maybe be moved to have less code in main.cpp.
 void initialize_physics() {
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	/// 3D Physics Server
 	physics_server_3d = PhysicsServer3DManager::get_singleton()->new_server(
 			GLOBAL_GET(PhysicsServer3DManager::setting_property_name));
@@ -345,8 +353,9 @@ void initialize_physics() {
 	// 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
+#endif // PHYSICS_3D_DISABLED
 
+#ifndef PHYSICS_2D_DISABLED
 	// 2D Physics server
 	physics_server_2d = PhysicsServer2DManager::get_singleton()->new_server(
 			GLOBAL_GET(PhysicsServer2DManager::get_singleton()->setting_property_name));
@@ -364,16 +373,19 @@ void initialize_physics() {
 	// Should be impossible, but make sure it's not null.
 	ERR_FAIL_NULL_MSG(physics_server_2d, "Failed to initialize PhysicsServer2D.");
 	physics_server_2d->init();
+#endif // PHYSICS_2D_DISABLED
 }
 
 void finalize_physics() {
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	physics_server_3d->finish();
 	memdelete(physics_server_3d);
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
+#ifndef PHYSICS_2D_DISABLED
 	physics_server_2d->finish();
 	memdelete(physics_server_2d);
+#endif // PHYSICS_2D_DISABLED
 }
 
 void finalize_display() {
@@ -707,10 +719,12 @@ Error Main::test_setup() {
 		tsman->add_interface(ts);
 	}
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	physics_server_3d_manager = memnew(PhysicsServer3DManager);
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 	physics_server_2d_manager = memnew(PhysicsServer2DManager);
+#endif // PHYSICS_2D_DISABLED
 
 	// From `Main::setup2()`.
 	register_early_core_singletons();
@@ -844,14 +858,16 @@ void Main::test_cleanup() {
 	if (tsman) {
 		memdelete(tsman);
 	}
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	if (physics_server_3d_manager) {
 		memdelete(physics_server_3d_manager);
 	}
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 	if (physics_server_2d_manager) {
 		memdelete(physics_server_2d_manager);
 	}
+#endif // PHYSICS_2D_DISABLED
 	if (globals) {
 		memdelete(globals);
 	}
@@ -2975,10 +2991,12 @@ Error Main::setup2(bool p_show_boot_logo) {
 		tsman->add_interface(ts);
 	}
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	physics_server_3d_manager = memnew(PhysicsServer3DManager);
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 	physics_server_2d_manager = memnew(PhysicsServer2DManager);
+#endif // PHYSICS_2D_DISABLED
 
 	register_server_types();
 	{
@@ -3101,14 +3119,16 @@ Error Main::setup2(bool p_show_boot_logo) {
 			if (tsman) {
 				memdelete(tsman);
 			}
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 			if (physics_server_3d_manager) {
 				memdelete(physics_server_3d_manager);
 			}
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 			if (physics_server_2d_manager) {
 				memdelete(physics_server_2d_manager);
 			}
+#endif // PHYSICS_2D_DISABLED
 
 			return err;
 		}
@@ -4559,19 +4579,23 @@ bool Main::iteration() {
 		// may be the same, and no interpolation takes place.
 		OS::get_singleton()->get_main_loop()->iteration_prepare();
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 		PhysicsServer3D::get_singleton()->sync();
 		PhysicsServer3D::get_singleton()->flush_queries();
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
+#ifndef PHYSICS_2D_DISABLED
 		PhysicsServer2D::get_singleton()->sync();
 		PhysicsServer2D::get_singleton()->flush_queries();
+#endif // PHYSICS_2D_DISABLED
 
 		if (OS::get_singleton()->get_main_loop()->physics_process(physics_step * time_scale)) {
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 			PhysicsServer3D::get_singleton()->end_sync();
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 			PhysicsServer2D::get_singleton()->end_sync();
+#endif // PHYSICS_2D_DISABLED
 
 			Engine::get_singleton()->_in_physics = false;
 			exit = true;
@@ -4587,13 +4611,15 @@ bool Main::iteration() {
 
 		message_queue->flush();
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 		PhysicsServer3D::get_singleton()->end_sync();
 		PhysicsServer3D::get_singleton()->step(physics_step * time_scale);
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
+#ifndef PHYSICS_2D_DISABLED
 		PhysicsServer2D::get_singleton()->end_sync();
 		PhysicsServer2D::get_singleton()->step(physics_step * time_scale);
+#endif // PHYSICS_2D_DISABLED
 
 		message_queue->flush();
 
@@ -4868,14 +4894,16 @@ void Main::cleanup(bool p_force) {
 	if (tsman) {
 		memdelete(tsman);
 	}
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	if (physics_server_3d_manager) {
 		memdelete(physics_server_3d_manager);
 	}
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 	if (physics_server_2d_manager) {
 		memdelete(physics_server_2d_manager);
 	}
+#endif // PHYSICS_2D_DISABLED
 	if (globals) {
 		memdelete(globals);
 	}

+ 19 - 9
main/performance.cpp

@@ -38,12 +38,13 @@
 #include "servers/navigation_server_3d.h"
 #include "servers/rendering_server.h"
 
-// 2D
+#ifndef PHYSICS_2D_DISABLED
 #include "servers/physics_server_2d.h"
+#endif // PHYSICS_2D_DISABLED
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 #include "servers/physics_server_3d.h"
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
 Performance *Performance::singleton = nullptr;
 
@@ -203,27 +204,36 @@ double Performance::get_monitor(Monitor p_monitor) const {
 			return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_DRAW);
 		case PIPELINE_COMPILATIONS_SPECIALIZATION:
 			return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SPECIALIZATION);
+#ifndef PHYSICS_2D_DISABLED
 		case PHYSICS_2D_ACTIVE_OBJECTS:
 			return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS);
 		case PHYSICS_2D_COLLISION_PAIRS:
 			return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS);
 		case PHYSICS_2D_ISLAND_COUNT:
 			return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT);
-#ifdef _3D_DISABLED
-		case PHYSICS_3D_ACTIVE_OBJECTS:
+#else
+		case PHYSICS_2D_ACTIVE_OBJECTS:
 			return 0;
-		case PHYSICS_3D_COLLISION_PAIRS:
+		case PHYSICS_2D_COLLISION_PAIRS:
 			return 0;
-		case PHYSICS_3D_ISLAND_COUNT:
+		case PHYSICS_2D_ISLAND_COUNT:
 			return 0;
-#else
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 		case PHYSICS_3D_ACTIVE_OBJECTS:
 			return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS);
 		case PHYSICS_3D_COLLISION_PAIRS:
 			return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS);
 		case PHYSICS_3D_ISLAND_COUNT:
 			return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ISLAND_COUNT);
-#endif // _3D_DISABLED
+#else
+		case PHYSICS_3D_ACTIVE_OBJECTS:
+			return 0;
+		case PHYSICS_3D_COLLISION_PAIRS:
+			return 0;
+		case PHYSICS_3D_ISLAND_COUNT:
+			return 0;
+#endif // PHYSICS_3D_DISABLED
 
 		case AUDIO_OUTPUT_LATENCY:
 			return AudioServer::get_singleton()->get_output_latency();

+ 34 - 12
modules/csg/csg_shape.cpp

@@ -60,9 +60,13 @@ void CSGShape3D::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navi
 	}
 
 	NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigation_mesh->get_parsed_geometry_type();
-	uint32_t parsed_collision_mask = p_navigation_mesh->get_collision_mask();
 
-	if (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES || (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS && csgshape3d->is_using_collision() && (csgshape3d->get_collision_layer() & parsed_collision_mask)) || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH) {
+#ifndef PHYSICS_3D_DISABLED
+	bool nav_collision = (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS && csgshape3d->is_using_collision() && (csgshape3d->get_collision_layer() & p_navigation_mesh->get_collision_mask()));
+#else
+	bool nav_collision = false;
+#endif // PHYSICS_3D_DISABLED
+	if (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES || nav_collision || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH) {
 		Array meshes = csgshape3d->get_meshes();
 		if (!meshes.is_empty()) {
 			Ref<Mesh> mesh = meshes[1];
@@ -73,6 +77,7 @@ void CSGShape3D::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navi
 	}
 }
 
+#ifndef PHYSICS_3D_DISABLED
 void CSGShape3D::set_use_collision(bool p_enable) {
 	if (use_collision == p_enable) {
 		return;
@@ -186,6 +191,7 @@ void CSGShape3D::set_collision_priority(real_t p_priority) {
 real_t CSGShape3D::get_collision_priority() const {
 	return collision_priority;
 }
+#endif // PHYSICS_3D_DISABLED
 
 bool CSGShape3D::is_root_shape() const {
 	return !parent_shape;
@@ -207,15 +213,20 @@ float CSGShape3D::get_snap() const {
 #endif // DISABLE_DEPRECATED
 
 void CSGShape3D::_make_dirty(bool p_parent_removing) {
+#ifndef PHYSICS_3D_DISABLED
 	if ((p_parent_removing || is_root_shape()) && !dirty) {
 		callable_mp(this, &CSGShape3D::update_shape).call_deferred(); // Must be deferred; otherwise, is_root_shape() will use the previous parent.
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	if (!is_root_shape()) {
 		parent_shape->_make_dirty();
-	} else if (!dirty) {
+	}
+#ifndef PHYSICS_3D_DISABLED
+	else if (!dirty) {
 		callable_mp(this, &CSGShape3D::update_shape).call_deferred();
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	dirty = true;
 }
@@ -711,9 +722,20 @@ void CSGShape3D::update_shape() {
 
 	set_base(root_mesh->get_rid());
 
+#ifndef PHYSICS_3D_DISABLED
 	_update_collision_faces();
+#endif // PHYSICS_3D_DISABLED
+}
+
+Ref<ArrayMesh> CSGShape3D::bake_static_mesh() {
+	Ref<ArrayMesh> baked_mesh;
+	if (is_root_shape() && root_mesh.is_valid()) {
+		baked_mesh = root_mesh;
+	}
+	return baked_mesh;
 }
 
+#ifndef PHYSICS_3D_DISABLED
 Vector<Vector3> CSGShape3D::_get_brush_collision_faces() {
 	Vector<Vector3> collision_faces;
 	CSGBrush *n = _get_brush();
@@ -746,14 +768,6 @@ void CSGShape3D::_update_collision_faces() {
 	}
 }
 
-Ref<ArrayMesh> CSGShape3D::bake_static_mesh() {
-	Ref<ArrayMesh> baked_mesh;
-	if (is_root_shape() && root_mesh.is_valid()) {
-		baked_mesh = root_mesh;
-	}
-	return baked_mesh;
-}
-
 Ref<ConcavePolygonShape3D> CSGShape3D::bake_collision_shape() {
 	Ref<ConcavePolygonShape3D> baked_collision_shape;
 	if (is_root_shape() && root_collision_shape.is_valid()) {
@@ -800,6 +814,7 @@ void CSGShape3D::_on_transform_changed() {
 		RS::get_singleton()->instance_set_transform(root_collision_debug_instance, debug_shape_old_transform);
 	}
 }
+#endif // PHYSICS_3D_DISABLED
 
 AABB CSGShape3D::get_aabb() const {
 	return node_aabb;
@@ -872,6 +887,7 @@ void CSGShape3D::_notification(int p_what) {
 			}
 		} break;
 
+#ifndef PHYSICS_3D_DISABLED
 		case NOTIFICATION_ENTER_TREE: {
 			if (use_collision && is_root_shape()) {
 				root_collision_shape.instantiate();
@@ -904,6 +920,7 @@ void CSGShape3D::_notification(int p_what) {
 			}
 			_on_transform_changed();
 		} break;
+#endif // PHYSICS_3D_DISABLED
 	}
 }
 
@@ -980,6 +997,7 @@ void CSGShape3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_snap"), &CSGShape3D::get_snap);
 #endif // DISABLE_DEPRECATED
 
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("set_use_collision", "operation"), &CSGShape3D::set_use_collision);
 	ClassDB::bind_method(D_METHOD("is_using_collision"), &CSGShape3D::is_using_collision);
 
@@ -1000,13 +1018,15 @@ void CSGShape3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_collision_priority", "priority"), &CSGShape3D::set_collision_priority);
 	ClassDB::bind_method(D_METHOD("get_collision_priority"), &CSGShape3D::get_collision_priority);
 
+	ClassDB::bind_method(D_METHOD("bake_collision_shape"), &CSGShape3D::bake_collision_shape);
+#endif // PHYSICS_3D_DISABLED
+
 	ClassDB::bind_method(D_METHOD("set_calculate_tangents", "enabled"), &CSGShape3D::set_calculate_tangents);
 	ClassDB::bind_method(D_METHOD("is_calculating_tangents"), &CSGShape3D::is_calculating_tangents);
 
 	ClassDB::bind_method(D_METHOD("get_meshes"), &CSGShape3D::get_meshes);
 
 	ClassDB::bind_method(D_METHOD("bake_static_mesh"), &CSGShape3D::bake_static_mesh);
-	ClassDB::bind_method(D_METHOD("bake_collision_shape"), &CSGShape3D::bake_collision_shape);
 
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "operation", PROPERTY_HINT_ENUM, "Union,Intersection,Subtraction"), "set_operation", "get_operation");
 #ifndef DISABLE_DEPRECATED
@@ -1014,11 +1034,13 @@ void CSGShape3D::_bind_methods() {
 #endif // DISABLE_DEPRECATED
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "calculate_tangents"), "set_calculate_tangents", "is_calculating_tangents");
 
+#ifndef PHYSICS_3D_DISABLED
 	ADD_GROUP("Collision", "collision_");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_collision"), "set_use_collision", "is_using_collision");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_priority"), "set_collision_priority", "get_collision_priority");
+#endif // PHYSICS_3D_DISABLED
 
 	BIND_ENUM_CONSTANT(OPERATION_UNION);
 	BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);

+ 9 - 0
modules/csg/csg_shape.h

@@ -34,7 +34,10 @@
 
 #include "scene/3d/path_3d.h"
 #include "scene/3d/visual_instance_3d.h"
+
+#ifndef PHYSICS_3D_DISABLED
 #include "scene/resources/3d/concave_polygon_shape_3d.h"
+#endif // PHYSICS_3D_DISABLED
 
 #include "thirdparty/misc/mikktspace.h"
 
@@ -64,6 +67,7 @@ private:
 	bool last_visible = false;
 	float snap = 0.001;
 
+#ifndef PHYSICS_3D_DISABLED
 	bool use_collision = false;
 	uint32_t collision_layer = 1;
 	uint32_t collision_mask = 1;
@@ -72,6 +76,7 @@ private:
 	RID root_collision_instance;
 	RID root_collision_debug_instance;
 	Transform3D debug_shape_old_transform;
+#endif // PHYSICS_3D_DISABLED
 
 	bool calculate_tangents = true;
 
@@ -109,12 +114,14 @@ private:
 	static void mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT,
 			const tbool bIsOrientationPreserving, const int iFace, const int iVert);
 
+#ifndef PHYSICS_3D_DISABLED
 	void _update_collision_faces();
 	bool _is_debug_collision_shape_visible();
 	void _update_debug_collision_shape();
 	void _clear_debug_collision_shape();
 	void _on_transform_changed();
 	Vector<Vector3> _get_brush_collision_faces();
+#endif // PHYSICS_3D_DISABLED
 
 protected:
 	void _notification(int p_what);
@@ -171,7 +178,9 @@ public:
 	bool is_root_shape() const;
 
 	Ref<ArrayMesh> bake_static_mesh();
+#ifndef PHYSICS_3D_DISABLED
 	Ref<ConcavePolygonShape3D> bake_collision_shape();
+#endif // PHYSICS_3D_DISABLED
 
 	virtual Ref<TriangleMesh> generate_triangle_mesh() const override;
 

+ 2 - 1
modules/gltf/extensions/SCsub

@@ -9,4 +9,5 @@ env_gltf = env_modules.Clone()
 # Godot source files
 
 env_gltf.add_source_files(env.modules_sources, "*.cpp")
-env_gltf.add_source_files(env.modules_sources, "physics/*.cpp")
+if not env["disable_physics_3d"]:
+    env_gltf.add_source_files(env.modules_sources, "physics/*.cpp")

+ 9 - 2
modules/gltf/register_types.cpp

@@ -34,11 +34,14 @@
 #include "extensions/gltf_document_extension_texture_ktx.h"
 #include "extensions/gltf_document_extension_texture_webp.h"
 #include "extensions/gltf_spec_gloss.h"
-#include "extensions/physics/gltf_document_extension_physics.h"
 #include "gltf_document.h"
 #include "gltf_state.h"
 #include "structures/gltf_object_model_property.h"
 
+#ifndef PHYSICS_3D_DISABLED
+#include "extensions/physics/gltf_document_extension_physics.h"
+#endif // PHYSICS_3D_DISABLED
+
 #ifdef TOOLS_ENABLED
 #include "editor/editor_import_blend_runner.h"
 #include "editor/editor_scene_exporter_gltf_plugin.h"
@@ -114,17 +117,21 @@ void initialize_gltf_module(ModuleInitializationLevel p_level) {
 		GDREGISTER_CLASS(GLTFMesh);
 		GDREGISTER_CLASS(GLTFNode);
 		GDREGISTER_CLASS(GLTFObjectModelProperty);
+#ifndef PHYSICS_3D_DISABLED
 		GDREGISTER_CLASS(GLTFPhysicsBody);
 		GDREGISTER_CLASS(GLTFPhysicsShape);
+#endif // PHYSICS_3D_DISABLED
 		GDREGISTER_CLASS(GLTFSkeleton);
 		GDREGISTER_CLASS(GLTFSkin);
 		GDREGISTER_CLASS(GLTFSpecGloss);
 		GDREGISTER_CLASS(GLTFState);
 		GDREGISTER_CLASS(GLTFTexture);
 		GDREGISTER_CLASS(GLTFTextureSampler);
-		// Register GLTFDocumentExtension classes with GLTFDocument.
+// Register GLTFDocumentExtension classes with GLTFDocument.
+#ifndef PHYSICS_3D_DISABLED
 		// Ensure physics is first in this list so that physics nodes are created before other nodes.
 		GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionPhysics);
+#endif // PHYSICS_3D_DISABLED
 		GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionTextureKTX);
 		GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionTextureWebP);
 		bool is_editor = Engine::get_singleton()->is_editor_hint();

+ 1 - 1
modules/godot_physics_2d/config.py

@@ -1,5 +1,5 @@
 def can_build(env, platform):
-    return True
+    return not env["disable_physics_2d"]
 
 
 def configure(env):

+ 1 - 1
modules/godot_physics_3d/config.py

@@ -1,5 +1,5 @@
 def can_build(env, platform):
-    return not env["disable_3d"]
+    return not env["disable_physics_3d"]
 
 
 def configure(env):

+ 33 - 1
modules/gridmap/grid_map.cpp

@@ -146,6 +146,7 @@ void GridMap::_get_property_list(List<PropertyInfo> *p_list) const {
 	p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
 }
 
+#ifndef PHYSICS_3D_DISABLED
 void GridMap::set_collision_layer(uint32_t p_layer) {
 	collision_layer = p_layer;
 	_update_physics_bodies_collision_properties();
@@ -235,6 +236,7 @@ Array GridMap::get_collision_shapes() const {
 
 	return shapes;
 }
+#endif // PHYSICS_3D_DISABLED
 
 void GridMap::set_bake_navigation(bool p_bake_navigation) {
 	bake_navigation = p_bake_navigation;
@@ -373,6 +375,7 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
 		//create octant because it does not exist
 		Octant *g = memnew(Octant);
 		g->dirty = true;
+#ifndef PHYSICS_3D_DISABLED
 		g->static_body = PhysicsServer3D::get_singleton()->body_create();
 		PhysicsServer3D::get_singleton()->body_set_mode(g->static_body, PhysicsServer3D::BODY_MODE_STATIC);
 		PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
@@ -383,6 +386,7 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
 			PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->computed_friction());
 			PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce());
 		}
+#endif // PHYSICS_3D_DISABLED
 		SceneTree *st = SceneTree::get_singleton();
 
 		if (st && st->is_debugging_collisions_hint()) {
@@ -529,11 +533,13 @@ Vector3 GridMap::map_to_local(const Vector3i &p_map_position) const {
 void GridMap::_octant_transform(const OctantKey &p_key) {
 	ERR_FAIL_COND(!octant_map.has(p_key));
 	Octant &g = *octant_map[p_key];
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform());
 
 	if (g.collision_debug_instance.is_valid()) {
 		RS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	// update transform for NavigationServer regions and navigation debugmesh instances
 	for (const KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) {
@@ -559,6 +565,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
 		return false;
 	}
 
+#ifndef PHYSICS_3D_DISABLED
 	//erase body shapes
 	PhysicsServer3D::get_singleton()->body_clear_shapes(g.static_body);
 
@@ -566,6 +573,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
 	if (g.collision_debug.is_valid()) {
 		RS::get_singleton()->mesh_clear(g.collision_debug);
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	//erase navigation
 	for (KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) {
@@ -633,6 +641,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
 			}
 		}
 
+#ifndef PHYSICS_3D_DISABLED
 		Vector<MeshLibrary::ShapeData> shapes = mesh_library->get_item_shapes(c.item);
 		// add the item's shape at given xform to octant's static_body
 		for (int i = 0; i < shapes.size(); i++) {
@@ -645,6 +654,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
 				shapes.write[i].shape->add_vertices_to_array(col_debug, xform * shapes[i].local_transform);
 			}
 		}
+#endif // PHYSICS_3D_DISABLED
 
 		// add the item's navigation_mesh at given xform to GridMap's Navigation ancestor
 		Ref<NavigationMesh> navigation_mesh = mesh_library->get_item_navigation_mesh(c.item);
@@ -736,6 +746,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
 		}
 	}
 
+#ifndef PHYSICS_3D_DISABLED
 	if (col_debug.size()) {
 		Array arr;
 		arr.resize(RS::ARRAY_MAX);
@@ -747,12 +758,14 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
 			RS::get_singleton()->mesh_surface_set_material(g.collision_debug, 0, st->get_debug_collision_material()->get_rid());
 		}
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	g.dirty = false;
 
 	return false;
 }
 
+#ifndef PHYSICS_3D_DISABLED
 void GridMap::_update_physics_bodies_collision_properties() {
 	for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
 		PhysicsServer3D::get_singleton()->body_set_collision_layer(E.value->static_body, collision_layer);
@@ -773,10 +786,12 @@ void GridMap::_update_physics_bodies_characteristics() {
 		PhysicsServer3D::get_singleton()->body_set_param(E.value->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, bounce);
 	}
 }
+#endif // PHYSICS_3D_DISABLED
 
 void GridMap::_octant_enter_world(const OctantKey &p_key) {
 	ERR_FAIL_COND(!octant_map.has(p_key));
 	Octant &g = *octant_map[p_key];
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform());
 	PhysicsServer3D::get_singleton()->body_set_space(g.static_body, get_world_3d()->get_space());
 
@@ -784,6 +799,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
 		RS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world_3d()->get_scenario());
 		RS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	for (int i = 0; i < g.multimesh_instances.size(); i++) {
 		RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, get_world_3d()->get_scenario());
@@ -828,17 +844,22 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
 
 void GridMap::_octant_exit_world(const OctantKey &p_key) {
 	ERR_FAIL_NULL(RenderingServer::get_singleton());
+#ifndef PHYSICS_3D_DISABLED
 	ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
+#endif // PHYSICS_3D_DISABLED
 	ERR_FAIL_NULL(NavigationServer3D::get_singleton());
 
 	ERR_FAIL_COND(!octant_map.has(p_key));
 	Octant &g = *octant_map[p_key];
+
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform());
 	PhysicsServer3D::get_singleton()->body_set_space(g.static_body, RID());
 
 	if (g.collision_debug_instance.is_valid()) {
 		RS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID());
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	for (int i = 0; i < g.multimesh_instances.size(); i++) {
 		RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID());
@@ -870,12 +891,15 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
 
 void GridMap::_octant_clean_up(const OctantKey &p_key) {
 	ERR_FAIL_NULL(RenderingServer::get_singleton());
+#ifndef PHYSICS_3D_DISABLED
 	ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
+#endif // PHYSICS_3D_DISABLED
 	ERR_FAIL_NULL(NavigationServer3D::get_singleton());
 
 	ERR_FAIL_COND(!octant_map.has(p_key));
 	Octant &g = *octant_map[p_key];
 
+#ifndef PHYSICS_3D_DISABLED
 	if (g.collision_debug.is_valid()) {
 		RS::get_singleton()->free(g.collision_debug);
 	}
@@ -884,6 +908,7 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
 	}
 
 	PhysicsServer3D::get_singleton()->free(g.static_body);
+#endif // PHYSICS_3D_DISABLED
 
 	// Erase navigation
 	for (const KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) {
@@ -1061,6 +1086,7 @@ void GridMap::_update_octants_callback() {
 }
 
 void GridMap::_bind_methods() {
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &GridMap::set_collision_layer);
 	ClassDB::bind_method(D_METHOD("get_collision_layer"), &GridMap::get_collision_layer);
 
@@ -1078,6 +1104,7 @@ void GridMap::_bind_methods() {
 
 	ClassDB::bind_method(D_METHOD("set_physics_material", "material"), &GridMap::set_physics_material);
 	ClassDB::bind_method(D_METHOD("get_physics_material"), &GridMap::get_physics_material);
+#endif // PHYSICS_3D_DISABLED
 
 	ClassDB::bind_method(D_METHOD("set_bake_navigation", "bake_navigation"), &GridMap::set_bake_navigation);
 	ClassDB::bind_method(D_METHOD("is_baking_navigation"), &GridMap::is_baking_navigation);
@@ -1139,10 +1166,12 @@ void GridMap::_bind_methods() {
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_y"), "set_center_y", "get_center_y");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_z"), "set_center_z", "get_center_z");
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_scale"), "set_cell_scale", "get_cell_scale");
+#ifndef PHYSICS_3D_DISABLED
 	ADD_GROUP("Collision", "collision_");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_priority"), "set_collision_priority", "get_collision_priority");
+#endif // PHYSICS_3D_DISABLED
 	ADD_GROUP("Navigation", "");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_navigation"), "set_bake_navigation", "is_baking_navigation");
 
@@ -1367,7 +1396,9 @@ void GridMap::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navigat
 	}
 
 	NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigation_mesh->get_parsed_geometry_type();
+#ifndef PHYSICS_3D_DISABLED
 	uint32_t parsed_collision_mask = p_navigation_mesh->get_collision_mask();
+#endif // PHYSICS_3D_DISABLED
 
 	if (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH) {
 		Array meshes = gridmap->get_meshes();
@@ -1379,7 +1410,7 @@ void GridMap::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navigat
 			}
 		}
 	}
-
+#ifndef PHYSICS_3D_DISABLED
 	else if ((parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH) && (gridmap->get_collision_layer() & parsed_collision_mask)) {
 		Array shapes = gridmap->get_collision_shapes();
 		for (int i = 0; i < shapes.size(); i += 2) {
@@ -1485,6 +1516,7 @@ void GridMap::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navigat
 			}
 		}
 	}
+#endif // PHYSICS_3D_DISABLED
 }
 
 #ifdef DEBUG_ENABLED

+ 8 - 0
modules/gridmap/grid_map.h

@@ -39,7 +39,9 @@
 
 class NavigationMesh;
 class NavigationMeshSourceGeometryData3D;
+#ifndef PHYSICS_3D_DISABLED
 class PhysicsMaterial;
+#endif // PHYSICS_3D_DISABLED
 
 class GridMap : public Node3D {
 	GDCLASS(GridMap, Node3D);
@@ -150,10 +152,12 @@ class GridMap : public Node3D {
 		OctantKey() {}
 	};
 
+#ifndef PHYSICS_3D_DISABLED
 	uint32_t collision_layer = 1;
 	uint32_t collision_mask = 1;
 	real_t collision_priority = 1.0;
 	Ref<PhysicsMaterial> physics_material;
+#endif // PHYSICS_3D_DISABLED
 	bool bake_navigation = false;
 	RID map_override;
 
@@ -187,8 +191,10 @@ class GridMap : public Node3D {
 		return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size;
 	}
 
+#ifndef PHYSICS_3D_DISABLED
 	void _update_physics_bodies_collision_properties();
 	void _update_physics_bodies_characteristics();
+#endif // PHYSICS_3D_DISABLED
 	void _octant_enter_world(const OctantKey &p_key);
 	void _octant_exit_world(const OctantKey &p_key);
 	bool _octant_update(const OctantKey &p_key);
@@ -233,6 +239,7 @@ public:
 		INVALID_CELL_ITEM = -1
 	};
 
+#ifndef PHYSICS_3D_DISABLED
 	void set_collision_layer(uint32_t p_layer);
 	uint32_t get_collision_layer() const;
 
@@ -252,6 +259,7 @@ public:
 	Ref<PhysicsMaterial> get_physics_material() const;
 
 	Array get_collision_shapes() const;
+#endif // PHYSICS_3D_DISABLED
 
 	void set_bake_navigation(bool p_bake_navigation);
 	bool is_baking_navigation();

+ 1 - 1
modules/jolt_physics/config.py

@@ -1,5 +1,5 @@
 def can_build(env, platform):
-    return not env["disable_3d"] and not env["arch"] == "ppc32"
+    return not env["disable_physics_3d"] and not env["arch"] == "ppc32"
 
 
 def configure(env):

+ 1 - 1
modules/vhacd/config.py

@@ -1,5 +1,5 @@
 def can_build(env, platform):
-    return not env["disable_3d"]
+    return not env["disable_physics_3d"]
 
 
 def configure(env):

+ 2 - 1
scene/2d/SCsub

@@ -6,4 +6,5 @@ Import("env")
 env.add_source_files(env.scene_sources, "*.cpp")
 
 # Chain load SCsubs
-SConscript("physics/SCsub")
+if not env["disable_physics_2d"]:
+    SConscript("physics/SCsub")

+ 7 - 2
scene/2d/audio_stream_player_2d.cpp

@@ -33,13 +33,16 @@
 
 #include "core/config/project_settings.h"
 #include "scene/2d/audio_listener_2d.h"
-#include "scene/2d/physics/area_2d.h"
 #include "scene/audio/audio_stream_player_internal.h"
 #include "scene/main/viewport.h"
 #include "scene/resources/world_2d.h"
 #include "servers/audio/audio_stream.h"
 #include "servers/audio_server.h"
 
+#ifndef PHYSICS_2D_DISABLED
+#include "scene/2d/physics/area_2d.h"
+#endif // PHYSICS_2D_DISABLED
+
 void AudioStreamPlayer2D::_notification(int p_what) {
 	internal->notification(p_what);
 
@@ -76,6 +79,7 @@ void AudioStreamPlayer2D::_notification(int p_what) {
 
 // Interacts with PhysicsServer2D, so can only be called during _physics_process.
 StringName AudioStreamPlayer2D::_get_actual_bus() {
+#ifndef PHYSICS_2D_DISABLED
 	Vector2 global_pos = get_global_position();
 
 	//check if any area is diverting sound into a bus
@@ -93,7 +97,6 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
 	point_params.collide_with_areas = true;
 
 	int areas = space_state->intersect_point(point_params, sr, MAX_INTERSECT_AREAS);
-
 	for (int i = 0; i < areas; i++) {
 		Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider);
 		if (!area2d) {
@@ -106,6 +109,8 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
 
 		return area2d->get_audio_bus_name();
 	}
+#endif // PHYSICS_2D_DISABLED
+
 	return internal->bus;
 }
 

+ 0 - 0
scene/2d/touch_screen_button.cpp → scene/2d/physics/touch_screen_button.cpp


+ 0 - 0
scene/2d/touch_screen_button.h → scene/2d/physics/touch_screen_button.h


+ 4 - 0
scene/2d/tile_map.cpp

@@ -597,6 +597,7 @@ TileMapCell TileMap::get_cell(int p_layer, const Vector2i &p_coords, bool p_use_
 	TILEMAP_CALL_FOR_LAYER_V(p_layer, TileMapCell(), get_cell, p_coords);
 }
 
+#ifndef PHYSICS_2D_DISABLED
 Vector2i TileMap::get_coords_for_body_rid(RID p_physics_body) {
 	for (const TileMapLayer *layer : layers) {
 		if (layer->has_body_rid(p_physics_body)) {
@@ -614,6 +615,7 @@ int TileMap::get_layer_for_body_rid(RID p_physics_body) {
 	}
 	ERR_FAIL_V_MSG(-1, vformat("No tiles for the given body RID %d.", p_physics_body.get_id()));
 }
+#endif // PHYSICS_2D_DISABLED
 
 void TileMap::fix_invalid_tiles() {
 	for (TileMapLayer *layer : layers) {
@@ -947,8 +949,10 @@ void TileMap::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("is_cell_flipped_v", "layer", "coords", "use_proxies"), &TileMap::is_cell_flipped_v, DEFVAL(false));
 	ClassDB::bind_method(D_METHOD("is_cell_transposed", "layer", "coords", "use_proxies"), &TileMap::is_cell_transposed, DEFVAL(false));
 
+#ifndef PHYSICS_2D_DISABLED
 	ClassDB::bind_method(D_METHOD("get_coords_for_body_rid", "body"), &TileMap::get_coords_for_body_rid);
 	ClassDB::bind_method(D_METHOD("get_layer_for_body_rid", "body"), &TileMap::get_layer_for_body_rid);
+#endif // PHYSICS_2D_DISABLED
 
 	ClassDB::bind_method(D_METHOD("get_pattern", "layer", "coords_array"), &TileMap::get_pattern);
 	ClassDB::bind_method(D_METHOD("map_pattern", "position_in_tilemap", "coords_in_pattern", "pattern"), &TileMap::map_pattern);

+ 2 - 0
scene/2d/tile_map.h

@@ -207,10 +207,12 @@ public:
 	virtual void set_texture_filter(CanvasItem::TextureFilter p_texture_filter) override;
 	virtual void set_texture_repeat(CanvasItem::TextureRepeat p_texture_repeat) override;
 
+#ifndef PHYSICS_2D_DISABLED
 	// For finding tiles from collision.
 	Vector2i get_coords_for_body_rid(RID p_physics_body);
 	// For getting their layers as well.
 	int get_layer_for_body_rid(RID p_physics_body);
+#endif // PHYSICS_2D_DISABLED
 
 	// Fixing and clearing methods.
 	void fix_invalid_tiles();

+ 32 - 4
scene/2d/tile_map_layer.cpp

@@ -39,6 +39,10 @@
 #include "scene/resources/world_2d.h"
 #include "servers/navigation_server_2d.h"
 
+#ifndef PHYSICS_2D_DISABLED
+#include "servers/physics_server_2d.h"
+#endif // PHYSICS_3D_DISABLED
+
 Callable TileMapLayer::_navmesh_source_geometry_parsing_callback;
 RID TileMapLayer::_navmesh_source_geometry_parser;
 
@@ -87,18 +91,22 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
 		for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
 			CellData &cell_data = kv.value;
 			quadrants_to_updates.insert(_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE));
+#ifndef PHYSICS_2D_DISABLED
 			// Physics quadrants are drawn from their origin.
 			Vector2i physics_quadrant_origin = _coords_to_quadrant_coords(cell_data.coords, physics_quadrant_size) * physics_quadrant_size;
 			quadrants_to_updates.insert(_coords_to_quadrant_coords(physics_quadrant_origin, TILE_MAP_DEBUG_QUADRANT_SIZE));
+#endif // PHYSICS_2D_DISABLED
 		}
 	} else {
 		// Update dirty cells.
 		for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
 			CellData &cell_data = *cell_data_list_element->self();
 			quadrants_to_updates.insert(_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE));
+#ifndef PHYSICS_2D_DISABLED
 			// Physics quadrants are drawn from their origin.
 			Vector2i physics_quadrant_origin = _coords_to_quadrant_coords(cell_data.coords, physics_quadrant_size) * physics_quadrant_size;
 			quadrants_to_updates.insert(_coords_to_quadrant_coords(physics_quadrant_origin, TILE_MAP_DEBUG_QUADRANT_SIZE));
+#endif // PHYSICS_2D_DISABLED
 		}
 	}
 
@@ -131,8 +139,10 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
 		Transform2D xform(0, quadrant_pos);
 		rs->canvas_item_set_transform(ci, xform);
 
+#ifndef PHYSICS_2D_DISABLED
 		// Draw physics.
 		_physics_draw_quadrant_debug(ci, *debug_quadrant.ptr());
+#endif // PHYSICS_2D_DISABLED
 
 		// Draw debug info.
 		for (SelfList<CellData> *cell_data_list_element = debug_quadrant->cells.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
@@ -675,6 +685,7 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve
 
 /////////////////////////////// Physics //////////////////////////////////////
 
+#ifndef PHYSICS_2D_DISABLED
 void TileMapLayer::_physics_update(bool p_force_cleanup) {
 	PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
 
@@ -1125,6 +1136,7 @@ void TileMapLayer::_physics_draw_quadrant_debug(const RID &p_canvas_item, DebugQ
 	rs->canvas_item_add_mesh(p_canvas_item, r_debug_quadrant.physics_mesh, Transform2D());
 }
 #endif // DEBUG_ENABLED
+#endif // PHYSICS_2D_DISABLED
 
 /////////////////////////////// Navigation //////////////////////////////////////
 
@@ -1870,7 +1882,9 @@ void TileMapLayer::_internal_update(bool p_force_cleanup) {
 
 	// Update all subsystems.
 	_rendering_update(p_force_cleanup);
+#ifndef PHYSICS_2D_DISABLED
 	_physics_update(p_force_cleanup);
+#endif // PHYSICS_2D_DISABLED
 	_navigation_update(p_force_cleanup);
 	_scenes_update(p_force_cleanup);
 #ifdef DEBUG_ENABLED
@@ -1972,7 +1986,9 @@ void TileMapLayer::_notification(int p_what) {
 	}
 
 	_rendering_notification(p_what);
+#ifndef PHYSICS_2D_DISABLED
 	_physics_notification(p_what);
+#endif // PHYSICS_2D_DISABLED
 	_navigation_notification(p_what);
 }
 
@@ -2005,9 +2021,11 @@ void TileMapLayer::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_cells_terrain_connect", "cells", "terrain_set", "terrain", "ignore_empty_terrains"), &TileMapLayer::set_cells_terrain_connect, DEFVAL(true));
 	ClassDB::bind_method(D_METHOD("set_cells_terrain_path", "path", "terrain_set", "terrain", "ignore_empty_terrains"), &TileMapLayer::set_cells_terrain_path, DEFVAL(true));
 
+#ifndef PHYSICS_2D_DISABLED
 	// --- Physics helpers ---
 	ClassDB::bind_method(D_METHOD("has_body_rid", "body"), &TileMapLayer::has_body_rid);
 	ClassDB::bind_method(D_METHOD("get_coords_for_body_rid", "body"), &TileMapLayer::get_coords_for_body_rid);
+#endif // PHYSICS_2D_DISABLED
 
 	// --- Runtime ---
 	ClassDB::bind_method(D_METHOD("update_internals"), &TileMapLayer::update_internals);
@@ -2872,6 +2890,7 @@ void TileMapLayer::set_cells_terrain_path(TypedArray<Vector2i> p_path, int p_ter
 	}
 }
 
+#ifndef PHYSICS_2D_DISABLED
 bool TileMapLayer::has_body_rid(RID p_physics_body) const {
 	return bodies_coords.has(p_physics_body);
 }
@@ -2881,6 +2900,7 @@ Vector2i TileMapLayer::get_coords_for_body_rid(RID p_physics_body) const {
 	ERR_FAIL_NULL_V(found, Vector2i());
 	return *found;
 }
+#endif // PHYSICS_2D_DISABLED
 
 void TileMapLayer::update_internals() {
 	_internal_update(false);
@@ -3281,14 +3301,17 @@ void TileMapLayer::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
 		return;
 	}
 
-	int physics_layers_count = tile_set->get_physics_layers_count();
 	int navigation_layers_count = tile_set->get_navigation_layers_count();
+#ifndef PHYSICS_2D_DISABLED
+	int physics_layers_count = tile_set->get_physics_layers_count();
 	if (physics_layers_count <= 0 && navigation_layers_count <= 0) {
 		return;
 	}
-
-	NavigationPolygon::ParsedGeometryType parsed_geometry_type = p_navigation_mesh->get_parsed_geometry_type();
-	uint32_t parsed_collision_mask = p_navigation_mesh->get_parsed_collision_mask();
+#else
+	if (navigation_layers_count <= 0) {
+		return;
+	}
+#endif // PHYSICS_2D_DISABLED
 
 	const Transform2D tilemap_xform = p_source_geometry_data->root_node_transform * tile_map_layer->get_global_transform();
 
@@ -3337,6 +3360,10 @@ void TileMapLayer::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
 			}
 		}
 
+#ifndef PHYSICS_2D_DISABLED
+		NavigationPolygon::ParsedGeometryType parsed_geometry_type = p_navigation_mesh->get_parsed_geometry_type();
+		uint32_t parsed_collision_mask = p_navigation_mesh->get_parsed_collision_mask();
+
 		// Parse obstacles.
 		for (int physics_layer = 0; physics_layer < physics_layers_count; physics_layer++) {
 			if ((parsed_geometry_type == NavigationPolygon::PARSED_GEOMETRY_STATIC_COLLIDERS || parsed_geometry_type == NavigationPolygon::PARSED_GEOMETRY_BOTH) &&
@@ -3365,6 +3392,7 @@ void TileMapLayer::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
 				}
 			}
 		}
+#endif // PHYSICS_2D_DISABLED
 	}
 }
 

+ 12 - 0
scene/2d/tile_map_layer.h

@@ -108,9 +108,11 @@ struct CellData {
 	SelfList<CellData> rendering_quadrant_list_element;
 	LocalVector<LocalVector<RID>> occluders;
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics.
 	Ref<PhysicsQuadrant> physics_quadrant;
 	SelfList<CellData> physics_quadrant_list_element;
+#endif // PHYSICS_2D_DISABLED
 
 	// Navigation.
 	LocalVector<RID> navigation_regions;
@@ -140,7 +142,9 @@ struct CellData {
 
 	CellData(const CellData &p_other) :
 			rendering_quadrant_list_element(this),
+#ifndef PHYSICS_2D_DISABLED
 			physics_quadrant_list_element(this),
+#endif // PHYSICS_2D_DISABLED
 			dirty_list_element(this) {
 		coords = p_other.coords;
 		cell = p_other.cell;
@@ -152,7 +156,9 @@ struct CellData {
 
 	CellData() :
 			rendering_quadrant_list_element(this),
+#ifndef PHYSICS_2D_DISABLED
 			physics_quadrant_list_element(this),
+#endif // PHYSICS_2D_DISABLED
 			dirty_list_element(this) {
 	}
 };
@@ -221,6 +227,7 @@ public:
 	}
 };
 
+#ifndef PHYSICS_2D_DISABLED
 class PhysicsQuadrant : public RefCounted {
 	GDCLASS(PhysicsQuadrant, RefCounted);
 
@@ -302,6 +309,7 @@ public:
 		cells.clear();
 	}
 };
+#endif // PHYSICS_2D_DISABLED
 
 class TileMapLayer : public Node2D {
 	GDCLASS(TileMapLayer, Node2D);
@@ -432,6 +440,7 @@ private:
 	void _rendering_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data);
 #endif // DEBUG_ENABLED
 
+#ifndef PHYSICS_2D_DISABLED
 	HashMap<Vector2i, Ref<PhysicsQuadrant>> physics_quadrant_map;
 	HashMap<RID, Vector2i> bodies_coords; // Mapping for RID to coords.
 	bool _physics_was_cleaned_up = false;
@@ -443,6 +452,7 @@ private:
 #ifdef DEBUG_ENABLED
 	void _physics_draw_quadrant_debug(const RID &p_canvas_item, DebugQuadrant &r_debug_quadrant);
 #endif // DEBUG_ENABLED
+#endif // PHYSICS_2D_DISABLED
 
 	bool _navigation_was_cleaned_up = false;
 	void _navigation_update(bool p_force_cleanup);
@@ -545,9 +555,11 @@ public:
 	void set_cells_terrain_connect(TypedArray<Vector2i> p_cells, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true);
 	void set_cells_terrain_path(TypedArray<Vector2i> p_path, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains = true);
 
+#ifndef PHYSICS_2D_DISABLED
 	// --- Physics helpers ---
 	bool has_body_rid(RID p_physics_body) const;
 	Vector2i get_coords_for_body_rid(RID p_physics_body) const; // For finding tiles from collision.
+#endif // PHYSICS_2D_DISABLED
 
 	// --- Runtime ---
 	void update_internals();

+ 2 - 1
scene/3d/SCsub

@@ -6,6 +6,7 @@ Import("env")
 env.add_source_files(env.scene_sources, "*.cpp")
 
 # Chain load SCsubs
-SConscript("physics/SCsub")
+if not env["disable_physics_3d"]:
+    SConscript("physics/SCsub")
 if not env["disable_xr"]:
     SConscript("xr/SCsub")

+ 20 - 3
scene/3d/audio_stream_player_3d.cpp

@@ -34,12 +34,15 @@
 #include "core/config/project_settings.h"
 #include "scene/3d/audio_listener_3d.h"
 #include "scene/3d/camera_3d.h"
-#include "scene/3d/physics/area_3d.h"
 #include "scene/3d/velocity_tracker_3d.h"
 #include "scene/audio/audio_stream_player_internal.h"
 #include "scene/main/viewport.h"
 #include "servers/audio/audio_stream.h"
 
+#ifndef PHYSICS_3D_DISABLED
+#include "scene/3d/physics/area_3d.h"
+#endif // PHYSICS_3D_DISABLED
+
 // Based on "A Novel Multichannel Panning Method for Standard and Arbitrary Loudspeaker Configurations" by Ramy Sadek and Chris Kyriakakis (2004)
 // Speaker-Placement Correction Amplitude Panning (SPCAP)
 class Spcap {
@@ -141,6 +144,7 @@ void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tig
 	}
 }
 
+#ifndef PHYSICS_3D_DISABLED
 void AudioStreamPlayer3D::_calc_reverb_vol(Area3D *area, Vector3 listener_area_pos, Vector<AudioFrame> direct_path_vol, Vector<AudioFrame> &reverb_vol) {
 	reverb_vol.resize(4);
 	reverb_vol.write[0] = AudioFrame(0, 0);
@@ -209,6 +213,7 @@ void AudioStreamPlayer3D::_calc_reverb_vol(Area3D *area, Vector3 listener_area_p
 		}
 	}
 }
+#endif // PHYSICS_3D_DISABLED
 
 float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
 	float att = 0;
@@ -283,6 +288,7 @@ void AudioStreamPlayer3D::_notification(int p_what) {
 	}
 }
 
+#ifndef PHYSICS_3D_DISABLED
 // Interacts with PhysicsServer3D, so can only be called during _physics_process
 Area3D *AudioStreamPlayer3D::_get_overriding_area() {
 	//check if any area is diverting sound into a bus
@@ -321,13 +327,16 @@ Area3D *AudioStreamPlayer3D::_get_overriding_area() {
 	}
 	return nullptr;
 }
+#endif // PHYSICS_3D_DISABLED
 
 // Interacts with PhysicsServer3D, so can only be called during _physics_process.
 StringName AudioStreamPlayer3D::_get_actual_bus() {
+#ifndef PHYSICS_3D_DISABLED
 	Area3D *overriding_area = _get_overriding_area();
 	if (overriding_area && overriding_area->is_overriding_audio_bus() && !overriding_area->is_using_reverb_bus()) {
 		return overriding_area->get_audio_bus_name();
 	}
+#endif // PHYSICS_3D_DISABLED
 	return internal->bus;
 }
 
@@ -358,7 +367,9 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
 	HashSet<Camera3D *> cameras = world_3d->get_cameras();
 	cameras.insert(get_viewport()->get_camera_3d());
 
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsDirectSpaceState3D *space_state = PhysicsServer3D::get_singleton()->space_get_direct_state(world_3d->get_space());
+#endif // PHYSICS_3D_DISABLED
 
 	for (Camera3D *camera : cameras) {
 		if (!camera) {
@@ -388,19 +399,22 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
 		Vector3 area_sound_pos;
 		Vector3 listener_area_pos;
 
+#ifndef PHYSICS_3D_DISABLED
 		Area3D *area = _get_overriding_area();
-
 		if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) {
 			area_sound_pos = space_state->get_closest_point_to_object_volume(area->get_rid(), listener_node->get_global_transform().origin);
 			listener_area_pos = listener_node->get_global_transform().affine_inverse().xform(area_sound_pos);
 		}
+#endif // PHYSICS_3D_DISABLED
 
 		if (max_distance > 0) {
 			float total_max = max_distance;
 
+#ifndef PHYSICS_3D_DISABLED
 			if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) {
 				total_max = MAX(total_max, listener_area_pos.length());
 			}
+#endif // PHYSICS_3D_DISABLED
 			if (dist > total_max || total_max > max_distance) {
 				if (!was_further_than_max_distance_last_frame) {
 					HashMap<StringName, Vector<AudioFrame>> bus_volumes;
@@ -445,6 +459,7 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
 		}
 
 		HashMap<StringName, Vector<AudioFrame>> bus_volumes;
+#ifndef PHYSICS_3D_DISABLED
 		if (area) {
 			if (area->is_overriding_audio_bus()) {
 				//override audio bus
@@ -457,7 +472,9 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
 				_calc_reverb_vol(area, listener_area_pos, output_volume_vector, reverb_vol);
 				bus_volumes[reverb_bus_name] = reverb_vol;
 			}
-		} else {
+		} else
+#endif // PHYSICS_3D_DISABLED
+		{
 			bus_volumes[internal->bus] = output_volume_vector;
 		}
 

+ 6 - 0
scene/3d/audio_stream_player_3d.h

@@ -33,7 +33,9 @@
 #include "scene/3d/node_3d.h"
 #include "servers/audio_server.h"
 
+#ifndef PHYSICS_3D_DISABLED
 class Area3D;
+#endif // PHYSICS_3D_DISABLED
 struct AudioFrame;
 class AudioStream;
 class AudioStreamPlayback;
@@ -80,14 +82,18 @@ private:
 
 	static void _calc_output_vol(const Vector3 &source_dir, real_t tightness, Vector<AudioFrame> &output);
 
+#ifndef PHYSICS_3D_DISABLED
 	void _calc_reverb_vol(Area3D *area, Vector3 listener_area_pos, Vector<AudioFrame> direct_path_vol, Vector<AudioFrame> &reverb_vol);
+#endif // PHYSICS_3D_DISABLED
 
 	static void _listener_changed_cb(void *self) { reinterpret_cast<AudioStreamPlayer3D *>(self)->force_update_panning = true; }
 
 	void _set_playing(bool p_enable);
 	bool _is_active() const;
 	StringName _get_actual_bus();
+#ifndef PHYSICS_3D_DISABLED
 	Area3D *_get_overriding_area();
+#endif // PHYSICS_3D_DISABLED
 	Vector<AudioFrame> _update_panning();
 
 	uint32_t area_mask = 1;

+ 6 - 0
scene/3d/camera_3d.cpp

@@ -691,7 +691,9 @@ void Camera3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_frustum"), &Camera3D::_get_frustum);
 	ClassDB::bind_method(D_METHOD("is_position_in_frustum", "world_point"), &Camera3D::is_position_in_frustum);
 	ClassDB::bind_method(D_METHOD("get_camera_rid"), &Camera3D::get_camera);
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("get_pyramid_shape_rid"), &Camera3D::get_pyramid_shape_rid);
+#endif // PHYSICS_3D_DISABLED
 
 	ClassDB::bind_method(D_METHOD("set_cull_mask_value", "layer_number", "value"), &Camera3D::set_cull_mask_value);
 	ClassDB::bind_method(D_METHOD("get_cull_mask_value", "layer_number"), &Camera3D::get_cull_mask_value);
@@ -854,6 +856,7 @@ Vector3 Camera3D::get_doppler_tracked_velocity() const {
 	}
 }
 
+#ifndef PHYSICS_3D_DISABLED
 RID Camera3D::get_pyramid_shape_rid() {
 	ERR_FAIL_COND_V_MSG(!is_inside_tree(), RID(), "Camera is not inside scene.");
 	if (pyramid_shape == RID()) {
@@ -881,6 +884,7 @@ RID Camera3D::get_pyramid_shape_rid() {
 
 	return pyramid_shape;
 }
+#endif // PHYSICS_3D_DISABLED
 
 Camera3D::Camera3D() {
 	camera = RenderingServer::get_singleton()->camera_create();
@@ -895,8 +899,10 @@ Camera3D::Camera3D() {
 Camera3D::~Camera3D() {
 	ERR_FAIL_NULL(RenderingServer::get_singleton());
 	RenderingServer::get_singleton()->free(camera);
+#ifndef PHYSICS_3D_DISABLED
 	if (pyramid_shape.is_valid()) {
 		ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
 		PhysicsServer3D::get_singleton()->free(pyramid_shape);
 	}
+#endif // PHYSICS_3D_DISABLED
 }

+ 4 - 0
scene/3d/camera_3d.h

@@ -94,8 +94,10 @@ private:
 	DopplerTracking doppler_tracking = DOPPLER_TRACKING_DISABLED;
 	Ref<VelocityTracker3D> velocity_tracker;
 
+#ifndef PHYSICS_3D_DISABLED
 	RID pyramid_shape;
 	Vector<Vector3> pyramid_shape_points;
+#endif // PHYSICS_3D_DISABLED
 
 	///////////////////////////////////////////////////////
 	// INTERPOLATION FUNCTIONS
@@ -217,7 +219,9 @@ public:
 
 	Vector3 get_doppler_tracked_velocity() const;
 
+#ifndef PHYSICS_3D_DISABLED
 	RID get_pyramid_shape_rid();
+#endif // PHYSICS_3D_DISABLED
 
 	Camera3D();
 	~Camera3D();

+ 11 - 5
scene/3d/mesh_instance_3d.cpp

@@ -30,16 +30,18 @@
 
 #include "mesh_instance_3d.h"
 
-#include "scene/3d/physics/collision_shape_3d.h"
-#include "scene/3d/physics/static_body_3d.h"
 #include "scene/3d/skeleton_3d.h"
-#include "scene/resources/3d/concave_polygon_shape_3d.h"
-#include "scene/resources/3d/convex_polygon_shape_3d.h"
-
 #include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
 #include "scene/resources/navigation_mesh.h"
 #include "servers/navigation_server_3d.h"
 
+#ifndef PHYSICS_3D_DISABLED
+#include "scene/3d/physics/collision_shape_3d.h"
+#include "scene/3d/physics/static_body_3d.h"
+#include "scene/resources/3d/concave_polygon_shape_3d.h"
+#include "scene/resources/3d/convex_polygon_shape_3d.h"
+#endif // PHYSICS_3D_DISABLED
+
 Callable MeshInstance3D::_navmesh_source_geometry_parsing_callback;
 RID MeshInstance3D::_navmesh_source_geometry_parser;
 
@@ -230,6 +232,7 @@ AABB MeshInstance3D::get_aabb() const {
 	return AABB();
 }
 
+#ifndef PHYSICS_3D_DISABLED
 Node *MeshInstance3D::create_trimesh_collision_node() {
 	if (mesh.is_null()) {
 		return nullptr;
@@ -331,6 +334,7 @@ void MeshInstance3D::create_multiple_convex_collisions(const Ref<MeshConvexDecom
 		}
 	}
 }
+#endif // PHYSICS_3D_DISABLED
 
 void MeshInstance3D::_notification(int p_what) {
 	switch (p_what) {
@@ -889,12 +893,14 @@ void MeshInstance3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_surface_override_material", "surface"), &MeshInstance3D::get_surface_override_material);
 	ClassDB::bind_method(D_METHOD("get_active_material", "surface"), &MeshInstance3D::get_active_material);
 
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance3D::create_trimesh_collision);
 	ClassDB::set_method_flags("MeshInstance3D", "create_trimesh_collision", METHOD_FLAGS_DEFAULT);
 	ClassDB::bind_method(D_METHOD("create_convex_collision", "clean", "simplify"), &MeshInstance3D::create_convex_collision, DEFVAL(true), DEFVAL(false));
 	ClassDB::set_method_flags("MeshInstance3D", "create_convex_collision", METHOD_FLAGS_DEFAULT);
 	ClassDB::bind_method(D_METHOD("create_multiple_convex_collisions", "settings"), &MeshInstance3D::create_multiple_convex_collisions, DEFVAL(Ref<MeshConvexDecompositionSettings>()));
 	ClassDB::set_method_flags("MeshInstance3D", "create_multiple_convex_collisions", METHOD_FLAGS_DEFAULT);
+#endif // PHYSICS_3D_DISABLED
 
 	ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &MeshInstance3D::get_blend_shape_count);
 	ClassDB::bind_method(D_METHOD("find_blend_shape_by_name", "name"), &MeshInstance3D::find_blend_shape_by_name);

+ 2 - 0
scene/3d/mesh_instance_3d.h

@@ -89,6 +89,7 @@ public:
 	Ref<Material> get_surface_override_material(int p_surface) const;
 	Ref<Material> get_active_material(int p_surface) const;
 
+#ifndef PHYSICS_3D_DISABLED
 	Node *create_trimesh_collision_node();
 	void create_trimesh_collision();
 
@@ -97,6 +98,7 @@ public:
 
 	Node *create_multiple_convex_collisions_node(const Ref<MeshConvexDecompositionSettings> &p_settings = Ref<MeshConvexDecompositionSettings>());
 	void create_multiple_convex_collisions(const Ref<MeshConvexDecompositionSettings> &p_settings = Ref<MeshConvexDecompositionSettings>());
+#endif // PHYSICS_3D_DISABLED
 
 	MeshInstance3D *create_debug_tangents_node();
 	void create_debug_tangents();

+ 1 - 1
scene/3d/physics/physical_bone_3d.cpp

@@ -30,7 +30,7 @@
 
 #include "physical_bone_3d.h"
 
-#include "scene/3d/physical_bone_simulator_3d.h"
+#include "scene/3d/physics/physical_bone_simulator_3d.h"
 #ifndef DISABLE_DEPRECATED
 #include "scene/3d/skeleton_3d.h"
 #endif //_DISABLE_DEPRECATED

+ 0 - 0
scene/3d/physical_bone_simulator_3d.cpp → scene/3d/physics/physical_bone_simulator_3d.cpp


+ 0 - 0
scene/3d/physical_bone_simulator_3d.h → scene/3d/physics/physical_bone_simulator_3d.h


+ 0 - 0
scene/3d/soft_body_3d.compat.inc → scene/3d/physics/soft_body_3d.compat.inc


+ 0 - 0
scene/3d/soft_body_3d.cpp → scene/3d/physics/soft_body_3d.cpp


+ 0 - 0
scene/3d/soft_body_3d.h → scene/3d/physics/soft_body_3d.h


+ 15 - 11
scene/3d/skeleton_3d.cpp

@@ -32,9 +32,9 @@
 #include "skeleton_3d.compat.inc"
 
 #include "scene/3d/skeleton_modifier_3d.h"
-#ifndef DISABLE_DEPRECATED
-#include "scene/3d/physical_bone_simulator_3d.h"
-#endif // _DISABLE_DEPRECATED
+#if !defined(DISABLE_DEPRECATED) && !defined(PHYSICS_3D_DISABLED)
+#include "scene/3d/physics/physical_bone_simulator_3d.h"
+#endif // _DISABLE_DEPRECATED && PHYSICS_3D_DISABLED
 
 void SkinReference::_skin_changed() {
 	if (skeleton_node) {
@@ -67,12 +67,12 @@ SkinReference::~SkinReference() {
 ///////////////////////////////////////
 
 bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) {
-#ifndef DISABLE_DEPRECATED
+#if !defined(DISABLE_DEPRECATED) && !defined(PHYSICS_3D_DISABLED)
 	if (p_path == SNAME("animate_physical_bones")) {
 		set_animate_physical_bones(p_value);
 		return true;
 	}
-#endif
+#endif // _DISABLE_DEPRECATED && PHYSICS_3D_DISABLED
 	String path = p_path;
 
 	if (!path.begins_with("bones/")) {
@@ -139,12 +139,12 @@ bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) {
 }
 
 bool Skeleton3D::_get(const StringName &p_path, Variant &r_ret) const {
-#ifndef DISABLE_DEPRECATED
+#if !defined(DISABLE_DEPRECATED) && !defined(PHYSICS_3D_DISABLED)
 	if (p_path == SNAME("animate_physical_bones")) {
 		r_ret = get_animate_physical_bones();
 		return true;
 	}
-#endif
+#endif // _DISABLE_DEPRECATED && PHYSICS_3D_DISABLED
 	String path = p_path;
 
 	if (!path.begins_with("bones/")) {
@@ -297,7 +297,7 @@ StringName Skeleton3D::get_concatenated_bone_names() const {
 	return concatenated_bone_names;
 }
 
-#ifndef DISABLE_DEPRECATED
+#if !defined(DISABLE_DEPRECATED) && !defined(PHYSICS_3D_DISABLED)
 void Skeleton3D::setup_simulator() {
 	if (simulator && simulator->get_parent() == this) {
 		remove_child(simulator);
@@ -310,7 +310,7 @@ void Skeleton3D::setup_simulator() {
 	add_child(simulator, false, INTERNAL_MODE_BACK);
 	set_animate_physical_bones(animate_physical_bones);
 }
-#endif // _DISABLE_DEPRECATED
+#endif // _DISABLE_DEPRECATED && PHYSICS_3D_DISABLED
 
 void Skeleton3D::_notification(int p_what) {
 	switch (p_what) {
@@ -319,9 +319,9 @@ void Skeleton3D::_notification(int p_what) {
 			_make_dirty();
 			_make_modifiers_dirty();
 			force_update_all_dirty_bones();
-#ifndef DISABLE_DEPRECATED
+#if !defined(DISABLE_DEPRECATED) && !defined(PHYSICS_3D_DISABLED)
 			setup_simulator();
-#endif // _DISABLE_DEPRECATED
+#endif // _DISABLE_DEPRECATED && PHYSICS_3D_DISABLED
 			update_flags = UPDATE_FLAG_POSE;
 			_notification(NOTIFICATION_UPDATE_SKELETON);
 		} break;
@@ -1320,6 +1320,7 @@ void Skeleton3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_bone_global_pose_override", "bone_idx"), &Skeleton3D::get_bone_global_pose_override);
 	ClassDB::bind_method(D_METHOD("get_bone_global_pose_no_override", "bone_idx"), &Skeleton3D::get_bone_global_pose_no_override);
 
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("set_animate_physical_bones", "enabled"), &Skeleton3D::set_animate_physical_bones);
 	ClassDB::bind_method(D_METHOD("get_animate_physical_bones"), &Skeleton3D::get_animate_physical_bones);
 	ClassDB::bind_method(D_METHOD("physical_bones_stop_simulation"), &Skeleton3D::physical_bones_stop_simulation);
@@ -1329,6 +1330,7 @@ void Skeleton3D::_bind_methods() {
 
 	ADD_GROUP("Deprecated", "");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "animate_physical_bones"), "set_animate_physical_bones", "get_animate_physical_bones");
+#endif // PHYSICS_3D_DISABLED
 #endif // _DISABLE_DEPRECATED
 }
 
@@ -1365,6 +1367,7 @@ Transform3D Skeleton3D::get_bone_global_pose_no_override(int p_bone) const {
 	return bones[p_bone].pose_global_no_override;
 }
 
+#ifndef PHYSICS_3D_DISABLED
 Node *Skeleton3D::get_simulator() {
 	return simulator;
 }
@@ -1415,6 +1418,7 @@ void Skeleton3D::physical_bones_remove_collision_exception(RID p_exception) {
 	}
 	sim->physical_bones_remove_collision_exception(p_exception);
 }
+#endif // PHYSICS_3D_DISABLED
 #endif // _DISABLE_DEPRECATED
 
 Skeleton3D::Skeleton3D() {

+ 4 - 2
scene/3d/skeleton_3d.h

@@ -69,11 +69,11 @@ class Skeleton3D : public Node3D {
 	bool saving = false;
 #endif //TOOLS_ENABLED
 
-#ifndef DISABLE_DEPRECATED
+#if !defined(DISABLE_DEPRECATED) && !defined(PHYSICS_3D_DISABLED)
 	bool animate_physical_bones = true;
 	Node *simulator = nullptr;
 	void setup_simulator();
-#endif // _DISABLE_DEPRECATED
+#endif // _DISABLE_DEPRECATED && PHYSICS_3D_DISABLED
 
 public:
 	enum ModifierCallbackModeProcess {
@@ -301,12 +301,14 @@ public:
 	void set_bone_global_pose_override(int p_bone, const Transform3D &p_pose, real_t p_amount, bool p_persistent = false);
 
 	Node *get_simulator();
+#ifndef PHYSICS_3D_DISABLED
 	void set_animate_physical_bones(bool p_enabled);
 	bool get_animate_physical_bones() const;
 	void physical_bones_stop_simulation();
 	void physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones);
 	void physical_bones_add_collision_exception(RID p_exception);
 	void physical_bones_remove_collision_exception(RID p_exception);
+#endif // PHYSICS_3D_DISABLED
 #endif // _DISABLE_DEPRECATED
 
 public:

+ 24 - 7
scene/debugger/scene_debugger.cpp

@@ -36,23 +36,30 @@
 #include "core/math/math_fieldwise.h"
 #include "core/object/script_language.h"
 #include "core/templates/local_vector.h"
+#include "scene/gui/popup_menu.h"
+#include "scene/main/canvas_layer.h"
+#include "scene/main/scene_tree.h"
+#include "scene/main/window.h"
+#include "scene/resources/packed_scene.h"
+#include "scene/theme/theme_db.h"
+#include "servers/audio_server.h"
+
+#ifndef PHYSICS_2D_DISABLED
 #include "scene/2d/physics/collision_object_2d.h"
 #include "scene/2d/physics/collision_polygon_2d.h"
 #include "scene/2d/physics/collision_shape_2d.h"
+#endif // PHYSICS_2D_DISABLED
+
 #ifndef _3D_DISABLED
+#include "scene/3d/camera_3d.h"
+#ifndef PHYSICS_3D_DISABLED
 #include "scene/3d/physics/collision_object_3d.h"
 #include "scene/3d/physics/collision_shape_3d.h"
+#endif // PHYSICS_3D_DISABLED
 #include "scene/3d/visual_instance_3d.h"
 #include "scene/resources/3d/convex_polygon_shape_3d.h"
 #include "scene/resources/surface_tool.h"
 #endif // _3D_DISABLED
-#include "scene/gui/popup_menu.h"
-#include "scene/main/canvas_layer.h"
-#include "scene/main/scene_tree.h"
-#include "scene/main/window.h"
-#include "scene/resources/packed_scene.h"
-#include "scene/theme/theme_db.h"
-#include "servers/audio_server.h"
 
 SceneDebugger::SceneDebugger() {
 	singleton = this;
@@ -1921,6 +1928,7 @@ void RuntimeNodeSelect::_update_selection() {
 		if (ci->_edit_use_rect()) {
 			rect = ci->_edit_get_rect();
 		} else {
+#ifndef PHYSICS_2D_DISABLED
 			CollisionShape2D *collision_shape = Object::cast_to<CollisionShape2D>(ci);
 			if (collision_shape) {
 				Ref<Shape2D> shape = collision_shape->get_shape();
@@ -1928,6 +1936,7 @@ void RuntimeNodeSelect::_update_selection() {
 					rect = shape->get_rect();
 				}
 			}
+#endif // PHYSICS_2D_DISABLED
 		}
 
 		const Vector2 endpoints[4] = {
@@ -1960,6 +1969,7 @@ void RuntimeNodeSelect::_update_selection() {
 		if (visual_instance) {
 			bounds = visual_instance->get_aabb();
 		} else {
+#ifndef PHYSICS_2D_DISABLED
 			CollisionShape3D *collision_shape = Object::cast_to<CollisionShape3D>(node_3d);
 			if (collision_shape) {
 				Ref<Shape3D> shape = collision_shape->get_shape();
@@ -1967,6 +1977,7 @@ void RuntimeNodeSelect::_update_selection() {
 					bounds = shape->get_debug_mesh()->get_aabb();
 				}
 			}
+#endif // PHYSICS_2D_DISABLED
 		}
 
 		Transform3D xform_to_top_level_parent_space = node_3d->get_global_transform().affine_inverse() * node_3d->get_global_transform();
@@ -2162,6 +2173,7 @@ void RuntimeNodeSelect::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_n
 		res.order = ci->get_effective_z_index() + ci->get_canvas_layer();
 		r_items.push_back(res);
 
+#ifndef PHYSICS_2D_DISABLED
 		// If it's a shape, get the collision object it's from.
 		// FIXME: If the collision object has multiple shapes, only the topmost will be above it in the list.
 		if (Object::cast_to<CollisionShape2D>(ci) || Object::cast_to<CollisionPolygon2D>(ci)) {
@@ -2173,6 +2185,7 @@ void RuntimeNodeSelect::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_n
 				r_items.push_back(res_col);
 			}
 		}
+#endif // PHYSICS_2D_DISABLED
 	}
 }
 
@@ -2304,6 +2317,7 @@ void RuntimeNodeSelect::_find_3d_items_at_pos(const Point2 &p_pos, Vector<Select
 		to = pos + ray * camera->get_far();
 	}
 
+#ifndef PHYSICS_3D_DISABLED
 	// Start with physical objects.
 	PhysicsDirectSpaceState3D *ss = root->get_world_3d()->get_direct_space_state();
 	PhysicsDirectSpaceState3D::RayResult result;
@@ -2339,6 +2353,7 @@ void RuntimeNodeSelect::_find_3d_items_at_pos(const Point2 &p_pos, Vector<Select
 			break;
 		}
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	// Then go for the meshes.
 	Vector<ObjectID> items = RS::get_singleton()->instances_cull_ray(pos, to, root->get_world_3d()->get_scenario());
@@ -2442,6 +2457,7 @@ void RuntimeNodeSelect::_find_3d_items_at_rect(const Rect2 &p_rect, Vector<Selec
 	far_plane.d += zfar;
 	frustum.push_back(far_plane);
 
+#ifndef PHYSICS_3D_DISABLED
 	Vector<Vector3> points = Geometry3D::compute_convex_mesh_points(&frustum[0], frustum.size());
 	Ref<ConvexPolygonShape3D> shape;
 	shape.instantiate();
@@ -2473,6 +2489,7 @@ void RuntimeNodeSelect::_find_3d_items_at_rect(const Rect2 &p_rect, Vector<Selec
 
 		r_items.push_back(res);
 	}
+#endif // PHYSICS_3D_DISABLED
 
 	// Then go for the meshes.
 	Vector<ObjectID> items = RS::get_singleton()->instances_cull_convex(frustum, root->get_world_3d()->get_scenario());

+ 23 - 8
scene/main/scene_tree.cpp

@@ -43,19 +43,26 @@
 #include "scene/gui/control.h"
 #include "scene/main/multiplayer_api.h"
 #include "scene/main/viewport.h"
+#include "scene/main/window.h"
 #include "scene/resources/environment.h"
 #include "scene/resources/image_texture.h"
 #include "scene/resources/material.h"
 #include "scene/resources/mesh.h"
 #include "scene/resources/packed_scene.h"
 #include "scene/resources/world_2d.h"
-#include "servers/physics_server_2d.h"
+
 #ifndef _3D_DISABLED
 #include "scene/3d/node_3d.h"
 #include "scene/resources/3d/world_3d.h"
-#include "servers/physics_server_3d.h"
 #endif // _3D_DISABLED
-#include "window.h"
+
+#ifndef PHYSICS_2D_DISABLED
+#include "servers/physics_server_2d.h"
+#endif // PHYSICS_2D_DISABLED
+
+#ifndef PHYSICS_3D_DISABLED
+#include "servers/physics_server_3d.h"
+#endif // PHYSICS_3D_DISABLED
 
 void SceneTreeTimer::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_time_left", "time"), &SceneTreeTimer::set_time_left);
@@ -130,7 +137,7 @@ void SceneTree::ClientPhysicsInterpolation::physics_process() {
 		}
 	}
 }
-#endif
+#endif // _3D_DISABLED
 
 void SceneTree::tree_changed() {
 	emit_signal(tree_changed_name);
@@ -526,7 +533,9 @@ bool SceneTree::physics_process(double p_time) {
 
 	emit_signal(SNAME("physics_frame"));
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	call_group(SNAME("_picking_viewports"), SNAME("_process_picking"));
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 	_process(true);
 
@@ -970,10 +979,12 @@ void SceneTree::set_pause(bool p_enabled) {
 
 	paused = p_enabled;
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsServer3D::get_singleton()->set_active(!p_enabled);
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 	PhysicsServer2D::get_singleton()->set_active(!p_enabled);
+#endif // PHYSICS_2D_DISABLED
 	if (get_root()) {
 		get_root()->_propagate_pause_notification(p_enabled);
 	}
@@ -994,10 +1005,12 @@ void SceneTree::set_suspend(bool p_enabled) {
 
 	Engine::get_singleton()->set_freeze_time_scale(p_enabled);
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsServer3D::get_singleton()->set_active(!p_enabled && !paused);
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 	PhysicsServer2D::get_singleton()->set_active(!p_enabled && !paused);
+#endif // PHYSICS_2D_DISABLED
 	if (get_root()) {
 		get_root()->_propagate_suspend_notification(p_enabled);
 	}
@@ -2011,7 +2024,9 @@ SceneTree::SceneTree() {
 	}
 #endif // _3D_DISABLED
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	root->set_physics_object_picking(GLOBAL_DEF("physics/common/enable_object_picking", true));
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 	root->connect("close_requested", callable_mp(this, &SceneTree::_main_window_close));
 	root->connect("go_back_requested", callable_mp(this, &SceneTree::_main_window_go_back));

+ 58 - 17
scene/main/viewport.cpp

@@ -36,13 +36,6 @@
 #include "core/templates/sort_array.h"
 #include "scene/2d/audio_listener_2d.h"
 #include "scene/2d/camera_2d.h"
-#include "scene/2d/physics/collision_object_2d.h"
-#ifndef _3D_DISABLED
-#include "scene/3d/audio_listener_3d.h"
-#include "scene/3d/camera_3d.h"
-#include "scene/3d/physics/collision_object_3d.h"
-#include "scene/3d/world_environment.h"
-#endif // _3D_DISABLED
 #include "scene/gui/control.h"
 #include "scene/gui/label.h"
 #include "scene/gui/popup.h"
@@ -56,6 +49,20 @@
 #include "servers/audio_server.h"
 #include "servers/rendering/rendering_server_globals.h"
 
+#ifndef _3D_DISABLED
+#include "scene/3d/audio_listener_3d.h"
+#include "scene/3d/camera_3d.h"
+#include "scene/3d/world_environment.h"
+#endif // _3D_DISABLED
+
+#ifndef PHYSICS_2D_DISABLED
+#include "scene/2d/physics/collision_object_2d.h"
+#endif // PHYSICS_2D_DISABLED
+
+#ifndef PHYSICS_3D_DISABLED
+#include "scene/3d/physics/collision_object_3d.h"
+#endif // PHYSICS_3D_DISABLED
+
 void ViewportTexture::setup_local_to_scene() {
 	// For the same target viewport, setup is only allowed once to prevent multiple free or multiple creations.
 	if (!vp_changed) {
@@ -545,11 +552,14 @@ void Viewport::_notification(int p_what) {
 #endif // _3D_DISABLED
 
 			add_to_group("_viewports");
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 			if (get_tree()->is_debugging_collisions_hint()) {
+#ifndef PHYSICS_2D_DISABLED
 				PhysicsServer2D::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count());
 				contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create();
 				RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, current_canvas);
-#ifndef _3D_DISABLED
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 				PhysicsServer3D::get_singleton()->space_set_debug_contacts(find_world_3d()->get_space(), get_tree()->get_collision_debug_contact_count());
 				contact_3d_debug_multimesh = RenderingServer::get_singleton()->multimesh_create();
 				RenderingServer::get_singleton()->multimesh_allocate_data(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), RS::MULTIMESH_TRANSFORM_3D, false);
@@ -559,9 +569,10 @@ void Viewport::_notification(int p_what) {
 				RenderingServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh);
 				RenderingServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world_3d()->get_scenario());
 				RenderingServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true);
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 				set_physics_process_internal(true);
 			}
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 		} break;
 
 		case NOTIFICATION_READY: {
@@ -600,17 +611,21 @@ void Viewport::_notification(int p_what) {
 
 			RenderingServer::get_singleton()->viewport_set_scenario(viewport, RID());
 			RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas);
+#ifndef PHYSICS_2D_DISABLED
 			if (contact_2d_debug.is_valid()) {
 				RenderingServer::get_singleton()->free(contact_2d_debug);
 				contact_2d_debug = RID();
 			}
+#endif // PHYSICS_2D_DISABLED
 
+#ifndef PHYSICS_3D_DISABLED
 			if (contact_3d_debug_multimesh.is_valid()) {
 				RenderingServer::get_singleton()->free(contact_3d_debug_multimesh);
 				RenderingServer::get_singleton()->free(contact_3d_debug_instance);
 				contact_3d_debug_instance = RID();
 				contact_3d_debug_multimesh = RID();
 			}
+#endif // PHYSICS_3D_DISABLED
 
 			remove_from_group("_viewports");
 			set_physics_process_internal(false);
@@ -623,11 +638,13 @@ void Viewport::_notification(int p_what) {
 			_update_viewport_path();
 		} break;
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 		case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
 			if (!get_tree()) {
 				return;
 			}
 
+#ifndef PHYSICS_2D_DISABLED
 			if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
 				RenderingServer::get_singleton()->canvas_item_clear(contact_2d_debug);
 				RenderingServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index
@@ -640,7 +657,8 @@ void Viewport::_notification(int p_what) {
 					RenderingServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol);
 				}
 			}
-#ifndef _3D_DISABLED
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 			if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) {
 				Vector<Vector3> points = PhysicsServer3D::get_singleton()->space_get_contacts(find_world_3d()->get_space());
 				int point_count = PhysicsServer3D::get_singleton()->space_get_contact_count(find_world_3d()->get_space());
@@ -653,8 +671,9 @@ void Viewport::_notification(int p_what) {
 					RS::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh, i, point_transform);
 				}
 			}
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 		} break;
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 		case NOTIFICATION_VP_MOUSE_ENTER: {
 			gui.mouse_in_viewport = true;
@@ -687,6 +706,7 @@ void Viewport::_notification(int p_what) {
 	}
 }
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 void Viewport::_process_picking() {
 	if (!is_inside_tree()) {
 		return;
@@ -718,14 +738,16 @@ void Viewport::_process_picking() {
 
 	_drop_physics_mouseover(true);
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	Vector2 last_pos(1e20, 1e20);
 	CollisionObject3D *last_object = nullptr;
 	ObjectID last_id;
 	PhysicsDirectSpaceState3D::RayResult result;
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
+#ifndef PHYSICS_2D_DISABLED
 	PhysicsDirectSpaceState2D *ss2d = PhysicsServer2D::get_singleton()->space_get_direct_state(find_world_2d()->get_space());
+#endif // PHYSICS_2D_DISABLED
 
 	SubViewportContainer *parent_svc = Object::cast_to<SubViewportContainer>(get_parent());
 	bool parent_ignore_mouse = (parent_svc && parent_svc->get_mouse_filter_with_recursive() == Control::MOUSE_FILTER_IGNORE);
@@ -805,6 +827,7 @@ void Viewport::_process_picking() {
 			pos = st->get_position();
 		}
 
+#ifndef PHYSICS_2D_DISABLED
 		if (ss2d) {
 			// Send to 2D.
 
@@ -897,8 +920,9 @@ void Viewport::_process_picking() {
 				_cleanup_mouseover_colliders(false, false, frame);
 			}
 		}
+#endif // PHYSICS_2D_DISABLED
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 		if (physics_object_picking_first_only && is_input_handled()) {
 			continue;
 		}
@@ -977,9 +1001,10 @@ void Viewport::_process_picking() {
 				last_pos = pos;
 			}
 		}
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 	}
 }
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 RID Viewport::get_viewport_rid() const {
 	ERR_READ_THREAD_GUARD_V(RID());
@@ -2552,9 +2577,11 @@ void Viewport::_drop_mouse_focus() {
 }
 
 void Viewport::_drop_physics_mouseover(bool p_paused_only) {
+#ifndef PHYSICS_2D_DISABLED
 	_cleanup_mouseover_colliders(true, p_paused_only);
+#endif // PHYSICS_2D_DISABLED
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	if (physics_object_over.is_valid()) {
 		CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over));
 		if (co) {
@@ -2568,7 +2595,7 @@ void Viewport::_drop_physics_mouseover(bool p_paused_only) {
 			}
 		}
 	}
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 }
 
 void Viewport::_gui_grab_click_focus(Control *p_control) {
@@ -3341,6 +3368,7 @@ void Viewport::_push_unhandled_input_internal(const Ref<InputEvent> &p_event) {
 		get_tree()->_call_input_pause(unhandled_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_INPUT, p_event, this);
 	}
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	if (physics_object_picking && !is_input_handled()) {
 		if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED &&
 				(Object::cast_to<InputEventMouse>(*p_event) ||
@@ -3352,6 +3380,7 @@ void Viewport::_push_unhandled_input_internal(const Ref<InputEvent> &p_event) {
 			set_input_as_handled();
 		}
 	}
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 }
 
 void Viewport::notify_mouse_entered() {
@@ -3370,6 +3399,7 @@ void Viewport::notify_mouse_exited() {
 	_mouse_leave_viewport();
 }
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 void Viewport::set_physics_object_picking(bool p_enable) {
 	ERR_MAIN_THREAD_GUARD;
 	physics_object_picking = p_enable;
@@ -3405,6 +3435,7 @@ void Viewport::set_physics_object_picking_first_only(bool p_enable) {
 bool Viewport::get_physics_object_picking_first_only() {
 	return physics_object_picking_first_only;
 }
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 Vector2 Viewport::get_camera_coords(const Vector2 &p_viewport_coords) const {
 	ERR_READ_THREAD_GUARD_V(Vector2());
@@ -4041,6 +4072,7 @@ void Viewport::_camera_2d_set(Camera2D *p_camera_2d) {
 	camera_2d = p_camera_2d;
 }
 
+#ifndef PHYSICS_2D_DISABLED
 void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) {
 	List<ObjectID> to_erase;
 	List<ObjectID> to_mouse_exit;
@@ -4110,6 +4142,7 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
 		shapes_to_mouse_exit.pop_front();
 	}
 }
+#endif // PHYSICS_2D_DISABLED
 
 AudioListener2D *Viewport::get_audio_listener_2d() const {
 	ERR_READ_THREAD_GUARD_V(nullptr);
@@ -4237,6 +4270,7 @@ void Viewport::_audio_listener_3d_make_next_current(AudioListener3D *p_exclude)
 	}
 }
 
+#ifndef PHYSICS_3D_DISABLED
 void Viewport::_collision_object_3d_input_event(CollisionObject3D *p_object, Camera3D *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) {
 	Transform3D object_transform = p_object->get_global_transform();
 	Transform3D camera_transform = p_camera->get_global_transform();
@@ -4254,6 +4288,7 @@ void Viewport::_collision_object_3d_input_event(CollisionObject3D *p_object, Cam
 	physics_last_camera_transform = camera_transform;
 	physics_last_id = id;
 }
+#endif // PHYSICS_3D_DISABLED
 
 Camera3D *Viewport::get_camera_3d() const {
 	ERR_READ_THREAD_GUARD_V(nullptr);
@@ -4804,12 +4839,14 @@ void Viewport::_bind_methods() {
 
 	ClassDB::bind_method(D_METHOD("get_texture"), &Viewport::get_texture);
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	ClassDB::bind_method(D_METHOD("set_physics_object_picking", "enable"), &Viewport::set_physics_object_picking);
 	ClassDB::bind_method(D_METHOD("get_physics_object_picking"), &Viewport::get_physics_object_picking);
 	ClassDB::bind_method(D_METHOD("set_physics_object_picking_sort", "enable"), &Viewport::set_physics_object_picking_sort);
 	ClassDB::bind_method(D_METHOD("get_physics_object_picking_sort"), &Viewport::get_physics_object_picking_sort);
 	ClassDB::bind_method(D_METHOD("set_physics_object_picking_first_only", "enable"), &Viewport::set_physics_object_picking_first_only);
 	ClassDB::bind_method(D_METHOD("get_physics_object_picking_first_only"), &Viewport::get_physics_object_picking_first_only);
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 	ClassDB::bind_method(D_METHOD("get_viewport_rid"), &Viewport::get_viewport_rid);
 	ClassDB::bind_method(D_METHOD("push_text_input", "text"), &Viewport::push_text_input);
@@ -4887,7 +4924,9 @@ void Viewport::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_mesh_lod_threshold", "pixels"), &Viewport::set_mesh_lod_threshold);
 	ClassDB::bind_method(D_METHOD("get_mesh_lod_threshold"), &Viewport::get_mesh_lod_threshold);
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	ClassDB::bind_method(D_METHOD("_process_picking"), &Viewport::_process_picking);
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 	ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d);
 	ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d);
@@ -4978,10 +5017,12 @@ void Viewport::_bind_methods() {
 #ifndef _3D_DISABLED
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener_3d", "is_audio_listener_3d");
 #endif // _3D_DISABLED
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	ADD_GROUP("Physics", "physics_");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_object_picking"), "set_physics_object_picking", "get_physics_object_picking");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_object_picking_sort"), "set_physics_object_picking_sort", "get_physics_object_picking_sort");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_object_picking_first_only"), "set_physics_object_picking_first_only", "get_physics_object_picking_first_only");
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	ADD_GROUP("GUI", "gui_");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled");

+ 10 - 0
scene/main/viewport.h

@@ -268,6 +268,7 @@ private:
 	bool snap_2d_transforms_to_pixel = false;
 	bool snap_2d_vertices_to_pixel = false;
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	bool physics_object_picking = false;
 	bool physics_object_picking_sort = false;
 	bool physics_object_picking_first_only = false;
@@ -277,6 +278,7 @@ private:
 	Transform3D physics_last_object_transform;
 	Transform3D physics_last_camera_transform;
 	ObjectID physics_last_id;
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 	bool handle_input_locally = true;
 	bool local_input_handled = false;
@@ -498,7 +500,9 @@ protected:
 	bool _is_size_allocated() const;
 
 	void _notification(int p_what);
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	void _process_picking();
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	static void _bind_methods();
 	void _validate_property(PropertyInfo &p_property) const;
 
@@ -608,12 +612,14 @@ public:
 	Point2 wrap_mouse_in_rect(const Vector2 &p_relative, const Rect2 &p_rect);
 	virtual void update_mouse_cursor_state();
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	void set_physics_object_picking(bool p_enable);
 	bool get_physics_object_picking();
 	void set_physics_object_picking_sort(bool p_enable);
 	bool get_physics_object_picking_sort();
 	void set_physics_object_picking_first_only(bool p_enable);
 	bool get_physics_object_picking_first_only();
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 
 	Variant gui_get_drag_data() const;
 
@@ -718,12 +724,14 @@ private:
 	Camera2D *camera_2d = nullptr;
 	void _camera_2d_set(Camera2D *p_camera_2d);
 
+#ifndef PHYSICS_2D_DISABLED
 	// Collider to frame
 	HashMap<ObjectID, uint64_t> physics_2d_mouseover;
 	// Collider & shape to frame
 	HashMap<Pair<ObjectID, int>, uint64_t, PairHash<ObjectID, int>> physics_2d_shape_mouseover;
 	// Cleans up colliders corresponding to old frames or all of them.
 	void _cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference = 0);
+#endif // PHYSICS_2D_DISABLED
 
 public:
 	AudioListener2D *get_audio_listener_2d() const;
@@ -749,7 +757,9 @@ private:
 	void _audio_listener_3d_remove(AudioListener3D *p_listener);
 	void _audio_listener_3d_make_next_current(AudioListener3D *p_exclude);
 
+#ifndef PHYSICS_3D_DISABLED
 	void _collision_object_3d_input_event(CollisionObject3D *p_object, Camera3D *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape);
+#endif // PHYSICS_3D_DISABLED
 
 	struct Camera3DOverrideData {
 		Transform3D transform;

+ 145 - 108
scene/register_scene_types.cpp

@@ -134,7 +134,6 @@
 #include "scene/resources/navigation_mesh.h"
 #include "scene/resources/packed_scene.h"
 #include "scene/resources/particle_process_material.h"
-#include "scene/resources/physics_material.h"
 #include "scene/resources/placeholder_textures.h"
 #include "scene/resources/portable_compressed_texture.h"
 #include "scene/resources/resource_format_text.h"
@@ -157,7 +156,6 @@
 #include "scene/resources/visual_shader_nodes.h"
 #include "scene/resources/visual_shader_particle_nodes.h"
 #include "scene/resources/visual_shader_sdf_nodes.h"
-#include "scene/resources/world_2d.h"
 #include "scene/theme/theme_db.h"
 
 // 2D
@@ -184,51 +182,25 @@
 #include "scene/2d/parallax_background.h"
 #include "scene/2d/parallax_layer.h"
 #include "scene/2d/path_2d.h"
-#include "scene/2d/physics/animatable_body_2d.h"
-#include "scene/2d/physics/area_2d.h"
-#include "scene/2d/physics/character_body_2d.h"
-#include "scene/2d/physics/collision_polygon_2d.h"
-#include "scene/2d/physics/collision_shape_2d.h"
-#include "scene/2d/physics/joints/damped_spring_joint_2d.h"
-#include "scene/2d/physics/joints/groove_joint_2d.h"
-#include "scene/2d/physics/joints/joint_2d.h"
-#include "scene/2d/physics/joints/pin_joint_2d.h"
-#include "scene/2d/physics/kinematic_collision_2d.h"
-#include "scene/2d/physics/physical_bone_2d.h"
-#include "scene/2d/physics/physics_body_2d.h"
-#include "scene/2d/physics/ray_cast_2d.h"
-#include "scene/2d/physics/rigid_body_2d.h"
-#include "scene/2d/physics/shape_cast_2d.h"
-#include "scene/2d/physics/static_body_2d.h"
 #include "scene/2d/polygon_2d.h"
 #include "scene/2d/remote_transform_2d.h"
 #include "scene/2d/skeleton_2d.h"
 #include "scene/2d/sprite_2d.h"
 #include "scene/2d/tile_map.h"
 #include "scene/2d/tile_map_layer.h"
-#include "scene/2d/touch_screen_button.h"
 #include "scene/2d/visible_on_screen_notifier_2d.h"
-#include "scene/resources/2d/capsule_shape_2d.h"
-#include "scene/resources/2d/circle_shape_2d.h"
-#include "scene/resources/2d/concave_polygon_shape_2d.h"
-#include "scene/resources/2d/convex_polygon_shape_2d.h"
 #include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
 #include "scene/resources/2d/navigation_polygon.h"
 #include "scene/resources/2d/polygon_path_finder.h"
-#include "scene/resources/2d/rectangle_shape_2d.h"
-#include "scene/resources/2d/segment_shape_2d.h"
-#include "scene/resources/2d/separation_ray_shape_2d.h"
 #include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
 #include "scene/resources/2d/skeleton/skeleton_modification_2d_ccdik.h"
 #include "scene/resources/2d/skeleton/skeleton_modification_2d_fabrik.h"
-#include "scene/resources/2d/skeleton/skeleton_modification_2d_jiggle.h"
 #include "scene/resources/2d/skeleton/skeleton_modification_2d_lookat.h"
-#include "scene/resources/2d/skeleton/skeleton_modification_2d_physicalbones.h"
 #include "scene/resources/2d/skeleton/skeleton_modification_2d_stackholder.h"
 #include "scene/resources/2d/skeleton/skeleton_modification_2d_twoboneik.h"
 #include "scene/resources/2d/skeleton/skeleton_modification_stack_2d.h"
 #include "scene/resources/2d/tile_set.h"
-#include "scene/resources/2d/world_boundary_shape_2d.h"
+#include "scene/resources/world_2d.h"
 
 #ifndef _3D_DISABLED
 #include "scene/3d/audio_listener_3d.h"
@@ -256,7 +228,68 @@
 #include "scene/3d/node_3d.h"
 #include "scene/3d/occluder_instance_3d.h"
 #include "scene/3d/path_3d.h"
-#include "scene/3d/physical_bone_simulator_3d.h"
+#include "scene/3d/reflection_probe.h"
+#include "scene/3d/remote_transform_3d.h"
+#include "scene/3d/retarget_modifier_3d.h"
+#include "scene/3d/skeleton_3d.h"
+#include "scene/3d/skeleton_ik_3d.h"
+#include "scene/3d/skeleton_modifier_3d.h"
+#include "scene/3d/sprite_3d.h"
+#include "scene/3d/visible_on_screen_notifier_3d.h"
+#include "scene/3d/voxel_gi.h"
+#include "scene/3d/world_environment.h"
+#ifndef XR_DISABLED
+#include "scene/3d/xr/xr_body_modifier_3d.h"
+#include "scene/3d/xr/xr_face_modifier_3d.h"
+#include "scene/3d/xr/xr_hand_modifier_3d.h"
+#include "scene/3d/xr/xr_nodes.h"
+#endif // XR_DISABLED
+#include "scene/animation/root_motion_view.h"
+#include "scene/resources/3d/fog_material.h"
+#include "scene/resources/3d/importer_mesh.h"
+#include "scene/resources/3d/mesh_library.h"
+#include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
+#include "scene/resources/3d/primitive_meshes.h"
+#include "scene/resources/3d/sky_material.h"
+#include "scene/resources/3d/world_3d.h"
+#endif // _3D_DISABLED
+
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
+#include "scene/resources/physics_material.h"
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
+
+#ifndef PHYSICS_2D_DISABLED
+#include "scene/2d/physics/animatable_body_2d.h"
+#include "scene/2d/physics/area_2d.h"
+#include "scene/2d/physics/character_body_2d.h"
+#include "scene/2d/physics/collision_polygon_2d.h"
+#include "scene/2d/physics/collision_shape_2d.h"
+#include "scene/2d/physics/joints/damped_spring_joint_2d.h"
+#include "scene/2d/physics/joints/groove_joint_2d.h"
+#include "scene/2d/physics/joints/joint_2d.h"
+#include "scene/2d/physics/joints/pin_joint_2d.h"
+#include "scene/2d/physics/kinematic_collision_2d.h"
+#include "scene/2d/physics/physical_bone_2d.h"
+#include "scene/2d/physics/physics_body_2d.h"
+#include "scene/2d/physics/ray_cast_2d.h"
+#include "scene/2d/physics/rigid_body_2d.h"
+#include "scene/2d/physics/shape_cast_2d.h"
+#include "scene/2d/physics/static_body_2d.h"
+#include "scene/2d/physics/touch_screen_button.h"
+#include "scene/resources/2d/capsule_shape_2d.h"
+#include "scene/resources/2d/circle_shape_2d.h"
+#include "scene/resources/2d/concave_polygon_shape_2d.h"
+#include "scene/resources/2d/convex_polygon_shape_2d.h"
+#include "scene/resources/2d/rectangle_shape_2d.h"
+#include "scene/resources/2d/segment_shape_2d.h"
+#include "scene/resources/2d/separation_ray_shape_2d.h"
+#include "scene/resources/2d/shape_2d.h"
+#include "scene/resources/2d/skeleton/skeleton_modification_2d_jiggle.h"
+#include "scene/resources/2d/skeleton/skeleton_modification_2d_physicalbones.h"
+#include "scene/resources/2d/world_boundary_shape_2d.h"
+#endif // PHYSICS_2D_DISABLED
+
+#ifndef PHYSICS_3D_DISABLED
 #include "scene/3d/physics/animatable_body_3d.h"
 #include "scene/3d/physics/area_3d.h"
 #include "scene/3d/physics/character_body_3d.h"
@@ -270,53 +303,30 @@
 #include "scene/3d/physics/joints/slider_joint_3d.h"
 #include "scene/3d/physics/kinematic_collision_3d.h"
 #include "scene/3d/physics/physical_bone_3d.h"
+#include "scene/3d/physics/physical_bone_simulator_3d.h"
 #include "scene/3d/physics/physics_body_3d.h"
 #include "scene/3d/physics/ray_cast_3d.h"
 #include "scene/3d/physics/rigid_body_3d.h"
 #include "scene/3d/physics/shape_cast_3d.h"
+#include "scene/3d/physics/soft_body_3d.h"
 #include "scene/3d/physics/spring_arm_3d.h"
 #include "scene/3d/physics/static_body_3d.h"
 #include "scene/3d/physics/vehicle_body_3d.h"
-#include "scene/3d/reflection_probe.h"
-#include "scene/3d/remote_transform_3d.h"
-#include "scene/3d/retarget_modifier_3d.h"
-#include "scene/3d/skeleton_3d.h"
-#include "scene/3d/skeleton_ik_3d.h"
-#include "scene/3d/skeleton_modifier_3d.h"
-#include "scene/3d/soft_body_3d.h"
 #include "scene/3d/spring_bone_collision_3d.h"
 #include "scene/3d/spring_bone_collision_capsule_3d.h"
 #include "scene/3d/spring_bone_collision_plane_3d.h"
 #include "scene/3d/spring_bone_collision_sphere_3d.h"
 #include "scene/3d/spring_bone_simulator_3d.h"
-#include "scene/3d/sprite_3d.h"
-#include "scene/3d/visible_on_screen_notifier_3d.h"
-#include "scene/3d/voxel_gi.h"
-#include "scene/3d/world_environment.h"
-#ifndef XR_DISABLED
-#include "scene/3d/xr/xr_body_modifier_3d.h"
-#include "scene/3d/xr/xr_face_modifier_3d.h"
-#include "scene/3d/xr/xr_hand_modifier_3d.h"
-#include "scene/3d/xr/xr_nodes.h"
-#endif // XR_DISABLED
-#include "scene/animation/root_motion_view.h"
 #include "scene/resources/3d/box_shape_3d.h"
 #include "scene/resources/3d/capsule_shape_3d.h"
 #include "scene/resources/3d/concave_polygon_shape_3d.h"
 #include "scene/resources/3d/convex_polygon_shape_3d.h"
 #include "scene/resources/3d/cylinder_shape_3d.h"
-#include "scene/resources/3d/fog_material.h"
 #include "scene/resources/3d/height_map_shape_3d.h"
-#include "scene/resources/3d/importer_mesh.h"
-#include "scene/resources/3d/mesh_library.h"
-#include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
-#include "scene/resources/3d/primitive_meshes.h"
 #include "scene/resources/3d/separation_ray_shape_3d.h"
-#include "scene/resources/3d/sky_material.h"
 #include "scene/resources/3d/sphere_shape_3d.h"
-#include "scene/resources/3d/world_3d.h"
 #include "scene/resources/3d/world_boundary_shape_3d.h"
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
 static Ref<ResourceFormatSaverText> resource_saver_text;
 static Ref<ResourceFormatLoaderText> resource_loader_text;
@@ -616,14 +626,16 @@ void register_scene_types() {
 	GDREGISTER_CLASS(RootMotionView);
 	GDREGISTER_VIRTUAL_CLASS(SkeletonModifier3D);
 	GDREGISTER_CLASS(RetargetModifier3D);
+
+	OS::get_singleton()->yield(); // may take time to init
+
+#ifndef PHYSICS_3D_DISABLED
 	GDREGISTER_CLASS(SpringBoneSimulator3D);
 	GDREGISTER_VIRTUAL_CLASS(SpringBoneCollision3D);
 	GDREGISTER_CLASS(SpringBoneCollisionSphere3D);
 	GDREGISTER_CLASS(SpringBoneCollisionCapsule3D);
 	GDREGISTER_CLASS(SpringBoneCollisionPlane3D);
 
-	OS::get_singleton()->yield(); // may take time to init
-
 	GDREGISTER_ABSTRACT_CLASS(CollisionObject3D);
 	GDREGISTER_ABSTRACT_CLASS(PhysicsBody3D);
 	GDREGISTER_CLASS(StaticBody3D);
@@ -636,11 +648,13 @@ void register_scene_types() {
 	GDREGISTER_CLASS(PhysicalBoneSimulator3D);
 	GDREGISTER_CLASS(PhysicalBone3D);
 	GDREGISTER_CLASS(SoftBody3D);
+#endif // PHYSICS_3D_DISABLED
 
 	GDREGISTER_CLASS(SkeletonIK3D);
 	GDREGISTER_CLASS(BoneAttachment3D);
 	GDREGISTER_CLASS(LookAtModifier3D);
 
+#ifndef PHYSICS_3D_DISABLED
 	GDREGISTER_CLASS(VehicleBody3D);
 	GDREGISTER_CLASS(VehicleWheel3D);
 	GDREGISTER_CLASS(Area3D);
@@ -648,6 +662,7 @@ void register_scene_types() {
 	GDREGISTER_CLASS(CollisionPolygon3D);
 	GDREGISTER_CLASS(RayCast3D);
 	GDREGISTER_CLASS(ShapeCast3D);
+#endif // PHYSICS_3D_DISABLED
 	GDREGISTER_CLASS(MultiMeshInstance3D);
 
 	GDREGISTER_CLASS(Curve3D);
@@ -660,12 +675,14 @@ void register_scene_types() {
 	GDREGISTER_CLASS(FogMaterial);
 	GDREGISTER_CLASS(RemoteTransform3D);
 
+#ifndef PHYSICS_3D_DISABLED
 	GDREGISTER_ABSTRACT_CLASS(Joint3D);
 	GDREGISTER_CLASS(PinJoint3D);
 	GDREGISTER_CLASS(HingeJoint3D);
 	GDREGISTER_CLASS(SliderJoint3D);
 	GDREGISTER_CLASS(ConeTwistJoint3D);
 	GDREGISTER_CLASS(Generic6DOFJoint3D);
+#endif // PHYSICS_3D_DISABLED
 
 	GDREGISTER_CLASS(NavigationRegion3D);
 	GDREGISTER_CLASS(NavigationAgent3D);
@@ -818,6 +835,7 @@ void register_scene_types() {
 	GDREGISTER_CLASS(Line2D);
 	GDREGISTER_CLASS(MeshInstance2D);
 	GDREGISTER_CLASS(MultiMeshInstance2D);
+#ifndef PHYSICS_2D_DISABLED
 	GDREGISTER_ABSTRACT_CLASS(CollisionObject2D);
 	GDREGISTER_ABSTRACT_CLASS(PhysicsBody2D);
 	GDREGISTER_CLASS(StaticBody2D);
@@ -830,6 +848,7 @@ void register_scene_types() {
 	GDREGISTER_CLASS(CollisionPolygon2D);
 	GDREGISTER_CLASS(RayCast2D);
 	GDREGISTER_CLASS(ShapeCast2D);
+#endif // PHYSICS_2D_DISABLED
 	GDREGISTER_CLASS(VisibleOnScreenNotifier2D);
 	GDREGISTER_CLASS(VisibleOnScreenEnabler2D);
 	GDREGISTER_CLASS(Polygon2D);
@@ -846,10 +865,13 @@ void register_scene_types() {
 
 	GDREGISTER_CLASS(Camera2D);
 	GDREGISTER_CLASS(AudioListener2D);
+#ifndef PHYSICS_2D_DISABLED
 	GDREGISTER_ABSTRACT_CLASS(Joint2D);
 	GDREGISTER_CLASS(PinJoint2D);
 	GDREGISTER_CLASS(GrooveJoint2D);
 	GDREGISTER_CLASS(DampedSpringJoint2D);
+	GDREGISTER_CLASS(TouchScreenButton);
+#endif // PHYSICS_2D_DISABLED
 	GDREGISTER_CLASS(TileSet);
 	GDREGISTER_ABSTRACT_CLASS(TileSetSource);
 	GDREGISTER_CLASS(TileSetAtlasSource);
@@ -861,7 +883,6 @@ void register_scene_types() {
 	GDREGISTER_CLASS(Parallax2D);
 	GDREGISTER_CLASS(ParallaxBackground);
 	GDREGISTER_CLASS(ParallaxLayer);
-	GDREGISTER_CLASS(TouchScreenButton);
 	GDREGISTER_CLASS(RemoteTransform2D);
 
 	GDREGISTER_CLASS(SkeletonModificationStack2D);
@@ -869,12 +890,14 @@ void register_scene_types() {
 	GDREGISTER_CLASS(SkeletonModification2DLookAt);
 	GDREGISTER_CLASS(SkeletonModification2DCCDIK);
 	GDREGISTER_CLASS(SkeletonModification2DFABRIK);
-	GDREGISTER_CLASS(SkeletonModification2DJiggle);
 	GDREGISTER_CLASS(SkeletonModification2DTwoBoneIK);
 	GDREGISTER_CLASS(SkeletonModification2DStackHolder);
 
+#ifndef PHYSICS_2D_DISABLED
 	GDREGISTER_CLASS(PhysicalBone2D);
+	GDREGISTER_CLASS(SkeletonModification2DJiggle);
 	GDREGISTER_CLASS(SkeletonModification2DPhysicalBones);
+#endif // PHYSICS_2D_DISABLED
 
 	OS::get_singleton()->yield(); // may take time to init
 
@@ -923,6 +946,7 @@ void register_scene_types() {
 
 	OS::get_singleton()->yield(); // may take time to init
 
+#ifndef PHYSICS_3D_DISABLED
 	GDREGISTER_ABSTRACT_CLASS(Shape3D);
 	GDREGISTER_CLASS(SeparationRayShape3D);
 	GDREGISTER_CLASS(SphereShape3D);
@@ -933,12 +957,15 @@ void register_scene_types() {
 	GDREGISTER_CLASS(WorldBoundaryShape3D);
 	GDREGISTER_CLASS(ConvexPolygonShape3D);
 	GDREGISTER_CLASS(ConcavePolygonShape3D);
+#endif // PHYSICS_3D_DISABLED
 	GDREGISTER_CLASS(World3D);
 
 	OS::get_singleton()->yield(); // may take time to init
 #endif // _3D_DISABLED
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	GDREGISTER_CLASS(PhysicsMaterial);
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	GDREGISTER_CLASS(Compositor);
 	GDREGISTER_CLASS(Environment);
 	GDREGISTER_VIRTUAL_CLASS(CameraAttributes);
@@ -1027,6 +1054,7 @@ void register_scene_types() {
 	OS::get_singleton()->yield(); // may take time to init
 
 	GDREGISTER_CLASS(AudioStreamPlayer2D);
+#ifndef PHYSICS_2D_DISABLED
 	GDREGISTER_ABSTRACT_CLASS(Shape2D);
 	GDREGISTER_CLASS(WorldBoundaryShape2D);
 	GDREGISTER_CLASS(SegmentShape2D);
@@ -1036,6 +1064,7 @@ void register_scene_types() {
 	GDREGISTER_CLASS(CapsuleShape2D);
 	GDREGISTER_CLASS(ConvexPolygonShape2D);
 	GDREGISTER_CLASS(ConcavePolygonShape2D);
+#endif // PHYSICS_2D_DISABLED
 	GDREGISTER_CLASS(Curve2D);
 	GDREGISTER_CLASS(Path2D);
 	GDREGISTER_CLASS(PathFollow2D);
@@ -1058,14 +1087,18 @@ void register_scene_types() {
 	Polygon2D::navmesh_parse_init();
 	TileMap::navmesh_parse_init();
 	TileMapLayer::navmesh_parse_init();
+#ifndef PHYSICS_2D_DISABLED
 	StaticBody2D::navmesh_parse_init();
+#endif // PHYSICS_2D_DISABLED
 #ifndef _3D_DISABLED
 	// 3D nodes that support navmesh baking need to server register their source geometry parsers.
 	MeshInstance3D::navmesh_parse_init();
 	MultiMeshInstance3D::navmesh_parse_init();
 	NavigationObstacle3D::navmesh_parse_init();
+#ifndef PHYSICS_3D_DISABLED
 	StaticBody3D::navmesh_parse_init();
-#endif
+#endif // PHYSICS_3D_DISABLED
+#endif // _3D_DISABLED
 
 	OS::get_singleton()->yield(); // may take time to init
 
@@ -1101,7 +1134,6 @@ void register_scene_types() {
 	// Renamed in 4.0.
 	// Keep alphabetical ordering to easily locate classes and avoid duplicates.
 	ClassDB::add_compatibility_class("AnimatedSprite", "AnimatedSprite2D");
-	ClassDB::add_compatibility_class("Area", "Area3D");
 	ClassDB::add_compatibility_class("ARVRCamera", "XRCamera3D");
 	ClassDB::add_compatibility_class("ARVRController", "XRController3D");
 	ClassDB::add_compatibility_class("ARVRAnchor", "XRAnchor3D");
@@ -1111,17 +1143,8 @@ void register_scene_types() {
 	ClassDB::add_compatibility_class("ARVRServer", "XRServer");
 	ClassDB::add_compatibility_class("AStar", "AStar3D");
 	ClassDB::add_compatibility_class("BoneAttachment", "BoneAttachment3D");
-	ClassDB::add_compatibility_class("BoxShape", "BoxShape3D");
 	ClassDB::add_compatibility_class("Camera", "Camera3D");
-	ClassDB::add_compatibility_class("CapsuleShape", "CapsuleShape3D");
 	ClassDB::add_compatibility_class("ClippedCamera", "ClippedCamera3D");
-	ClassDB::add_compatibility_class("CollisionObject", "CollisionObject3D");
-	ClassDB::add_compatibility_class("CollisionPolygon", "CollisionPolygon3D");
-	ClassDB::add_compatibility_class("CollisionShape", "CollisionShape3D");
-	ClassDB::add_compatibility_class("ConcavePolygonShape", "ConcavePolygonShape3D");
-	ClassDB::add_compatibility_class("ConeTwistJoint", "ConeTwistJoint3D");
-	ClassDB::add_compatibility_class("ConvexPolygonShape", "ConvexPolygonShape3D");
-	ClassDB::add_compatibility_class("CPUParticles", "CPUParticles3D");
 	ClassDB::add_compatibility_class("CSGBox", "CSGBox3D");
 	ClassDB::add_compatibility_class("CSGCombiner", "CSGCombiner3D");
 	ClassDB::add_compatibility_class("CSGCylinder", "CSGCylinder3D");
@@ -1132,20 +1155,9 @@ void register_scene_types() {
 	ClassDB::add_compatibility_class("CSGSphere", "CSGSphere3D");
 	ClassDB::add_compatibility_class("CSGTorus", "CSGTorus3D");
 	ClassDB::add_compatibility_class("CubeMesh", "BoxMesh");
-	ClassDB::add_compatibility_class("CylinderShape", "CylinderShape3D");
-	ClassDB::add_compatibility_class("DirectionalLight", "DirectionalLight3D");
-	ClassDB::add_compatibility_class("EditorSpatialGizmo", "EditorNode3DGizmo");
-	ClassDB::add_compatibility_class("EditorSpatialGizmoPlugin", "EditorNode3DGizmoPlugin");
-	ClassDB::add_compatibility_class("Generic6DOFJoint", "Generic6DOFJoint3D");
 	ClassDB::add_compatibility_class("GIProbe", "VoxelGI");
 	ClassDB::add_compatibility_class("GIProbeData", "VoxelGIData");
 	ClassDB::add_compatibility_class("GradientTexture", "GradientTexture1D");
-	ClassDB::add_compatibility_class("HeightMapShape", "HeightMapShape3D");
-	ClassDB::add_compatibility_class("HingeJoint", "HingeJoint3D");
-	ClassDB::add_compatibility_class("Joint", "Joint3D");
-	ClassDB::add_compatibility_class("KinematicBody", "CharacterBody3D");
-	ClassDB::add_compatibility_class("KinematicBody2D", "CharacterBody2D");
-	ClassDB::add_compatibility_class("KinematicCollision", "KinematicCollision3D");
 	ClassDB::add_compatibility_class("Light", "Light3D");
 	ClassDB::add_compatibility_class("Light2D", "PointLight2D");
 	ClassDB::add_compatibility_class("LineShape2D", "WorldBoundaryShape2D");
@@ -1166,57 +1178,82 @@ void register_scene_types() {
 	ClassDB::add_compatibility_class("ParticlesMaterial", "ParticleProcessMaterial");
 	ClassDB::add_compatibility_class("Path", "Path3D");
 	ClassDB::add_compatibility_class("PathFollow", "PathFollow3D");
-	ClassDB::add_compatibility_class("PhysicalBone", "PhysicalBone3D");
+	ClassDB::add_compatibility_class("Position2D", "Marker2D");
+	ClassDB::add_compatibility_class("Position3D", "Marker3D");
+	ClassDB::add_compatibility_class("ProceduralSky", "Sky");
+	ClassDB::add_compatibility_class("RemoteTransform", "RemoteTransform3D");
+	ClassDB::add_compatibility_class("ShortCut", "Shortcut");
+	ClassDB::add_compatibility_class("Skeleton", "Skeleton3D");
+	ClassDB::add_compatibility_class("SkeletonIK", "SkeletonIK3D");
+	ClassDB::add_compatibility_class("Spatial", "Node3D");
+	ClassDB::add_compatibility_class("SpatialGizmo", "Node3DGizmo");
+	ClassDB::add_compatibility_class("SpatialMaterial", "StandardMaterial3D");
+	ClassDB::add_compatibility_class("SpotLight", "SpotLight3D");
+	ClassDB::add_compatibility_class("Sprite", "Sprite2D");
+	ClassDB::add_compatibility_class("StaticBody", "StaticBody3D");
+	ClassDB::add_compatibility_class("StreamTexture", "CompressedTexture2D");
+	ClassDB::add_compatibility_class("TextureProgress", "TextureProgressBar");
+	ClassDB::add_compatibility_class("VideoPlayer", "VideoStreamPlayer");
+	ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer");
+	ClassDB::add_compatibility_class("Viewport", "SubViewport");
+	ClassDB::add_compatibility_class("VisibilityEnabler", "VisibleOnScreenEnabler3D");
+	ClassDB::add_compatibility_class("VisibilityNotifier", "VisibleOnScreenNotifier3D");
+	ClassDB::add_compatibility_class("VisibilityNotifier2D", "VisibleOnScreenNotifier2D");
+	ClassDB::add_compatibility_class("VisibilityNotifier3D", "VisibleOnScreenNotifier3D");
+	ClassDB::add_compatibility_class("VisualServer", "RenderingServer");
+	ClassDB::add_compatibility_class("World", "World3D");
+#ifndef PHYSICS_2D_DISABLED
 	ClassDB::add_compatibility_class("Physics2DDirectBodyState", "PhysicsDirectBodyState2D");
 	ClassDB::add_compatibility_class("Physics2DDirectSpaceState", "PhysicsDirectSpaceState2D");
 	ClassDB::add_compatibility_class("Physics2DServer", "PhysicsServer2D");
 	ClassDB::add_compatibility_class("Physics2DShapeQueryParameters", "PhysicsShapeQueryParameters2D");
 	ClassDB::add_compatibility_class("Physics2DTestMotionResult", "PhysicsTestMotionResult2D");
+	ClassDB::add_compatibility_class("RayShape2D", "SeparationRayShape2D");
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
+	ClassDB::add_compatibility_class("Area", "Area3D");
+	ClassDB::add_compatibility_class("BoxShape", "BoxShape3D");
+	ClassDB::add_compatibility_class("CapsuleShape", "CapsuleShape3D");
+	ClassDB::add_compatibility_class("CollisionObject", "CollisionObject3D");
+	ClassDB::add_compatibility_class("CollisionPolygon", "CollisionPolygon3D");
+	ClassDB::add_compatibility_class("CollisionShape", "CollisionShape3D");
+	ClassDB::add_compatibility_class("ConcavePolygonShape", "ConcavePolygonShape3D");
+	ClassDB::add_compatibility_class("ConeTwistJoint", "ConeTwistJoint3D");
+	ClassDB::add_compatibility_class("ConvexPolygonShape", "ConvexPolygonShape3D");
+	ClassDB::add_compatibility_class("CPUParticles", "CPUParticles3D");
+	ClassDB::add_compatibility_class("CylinderShape", "CylinderShape3D");
+	ClassDB::add_compatibility_class("DirectionalLight", "DirectionalLight3D");
+	ClassDB::add_compatibility_class("EditorSpatialGizmo", "EditorNode3DGizmo");
+	ClassDB::add_compatibility_class("EditorSpatialGizmoPlugin", "EditorNode3DGizmoPlugin");
+	ClassDB::add_compatibility_class("Generic6DOFJoint", "Generic6DOFJoint3D");
+	ClassDB::add_compatibility_class("HeightMapShape", "HeightMapShape3D");
+	ClassDB::add_compatibility_class("HingeJoint", "HingeJoint3D");
+	ClassDB::add_compatibility_class("Joint", "Joint3D");
+	ClassDB::add_compatibility_class("KinematicBody", "CharacterBody3D");
+	ClassDB::add_compatibility_class("KinematicBody2D", "CharacterBody2D");
+	ClassDB::add_compatibility_class("KinematicCollision", "KinematicCollision3D");
 	ClassDB::add_compatibility_class("PhysicsBody", "PhysicsBody3D");
+	ClassDB::add_compatibility_class("PhysicalBone", "PhysicalBone3D");
 	ClassDB::add_compatibility_class("PhysicsDirectBodyState", "PhysicsDirectBodyState3D");
 	ClassDB::add_compatibility_class("PhysicsDirectSpaceState", "PhysicsDirectSpaceState3D");
 	ClassDB::add_compatibility_class("PhysicsServer", "PhysicsServer3D");
 	ClassDB::add_compatibility_class("PhysicsShapeQueryParameters", "PhysicsShapeQueryParameters3D");
 	ClassDB::add_compatibility_class("PinJoint", "PinJoint3D");
 	ClassDB::add_compatibility_class("PlaneShape", "WorldBoundaryShape3D");
-	ClassDB::add_compatibility_class("Position2D", "Marker2D");
-	ClassDB::add_compatibility_class("Position3D", "Marker3D");
-	ClassDB::add_compatibility_class("ProceduralSky", "Sky");
 	ClassDB::add_compatibility_class("RayCast", "RayCast3D");
 	ClassDB::add_compatibility_class("RayShape", "SeparationRayShape3D");
-	ClassDB::add_compatibility_class("RayShape2D", "SeparationRayShape2D");
-	ClassDB::add_compatibility_class("RemoteTransform", "RemoteTransform3D");
 	ClassDB::add_compatibility_class("RigidBody", "RigidBody3D");
 	ClassDB::add_compatibility_class("RigidDynamicBody2D", "RigidBody2D");
 	ClassDB::add_compatibility_class("RigidDynamicBody3D", "RigidBody3D");
 	ClassDB::add_compatibility_class("Shape", "Shape3D");
-	ClassDB::add_compatibility_class("ShortCut", "Shortcut");
-	ClassDB::add_compatibility_class("Skeleton", "Skeleton3D");
-	ClassDB::add_compatibility_class("SkeletonIK", "SkeletonIK3D");
 	ClassDB::add_compatibility_class("SliderJoint", "SliderJoint3D");
 	ClassDB::add_compatibility_class("SoftBody", "SoftBody3D");
 	ClassDB::add_compatibility_class("SoftDynamicBody3D", "SoftBody3D");
-	ClassDB::add_compatibility_class("Spatial", "Node3D");
-	ClassDB::add_compatibility_class("SpatialGizmo", "Node3DGizmo");
-	ClassDB::add_compatibility_class("SpatialMaterial", "StandardMaterial3D");
 	ClassDB::add_compatibility_class("SphereShape", "SphereShape3D");
-	ClassDB::add_compatibility_class("SpotLight", "SpotLight3D");
 	ClassDB::add_compatibility_class("SpringArm", "SpringArm3D");
-	ClassDB::add_compatibility_class("Sprite", "Sprite2D");
-	ClassDB::add_compatibility_class("StaticBody", "StaticBody3D");
-	ClassDB::add_compatibility_class("StreamTexture", "CompressedTexture2D");
-	ClassDB::add_compatibility_class("TextureProgress", "TextureProgressBar");
 	ClassDB::add_compatibility_class("VehicleBody", "VehicleBody3D");
 	ClassDB::add_compatibility_class("VehicleWheel", "VehicleWheel3D");
-	ClassDB::add_compatibility_class("VideoPlayer", "VideoStreamPlayer");
-	ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer");
-	ClassDB::add_compatibility_class("Viewport", "SubViewport");
-	ClassDB::add_compatibility_class("VisibilityEnabler", "VisibleOnScreenEnabler3D");
-	ClassDB::add_compatibility_class("VisibilityNotifier", "VisibleOnScreenNotifier3D");
-	ClassDB::add_compatibility_class("VisibilityNotifier2D", "VisibleOnScreenNotifier2D");
-	ClassDB::add_compatibility_class("VisibilityNotifier3D", "VisibleOnScreenNotifier3D");
-	ClassDB::add_compatibility_class("VisualServer", "RenderingServer");
-	ClassDB::add_compatibility_class("World", "World3D");
+#endif // PHYSICS_3D_DISABLED
 
 	// VisualShader classes.
 	ClassDB::add_compatibility_class("VisualShaderNodeScalarConstant", "VisualShaderNodeFloatConstant");

+ 17 - 2
scene/resources/2d/SCsub

@@ -3,5 +3,20 @@ from misc.utility.scons_hints import *
 
 Import("env")
 
-env.add_source_files(env.scene_sources, "*.cpp")
-env.add_source_files(env.scene_sources, "skeleton/*.cpp")
+env.add_source_files(env.scene_sources, "navigation_mesh_source_geometry_data_2d.cpp")
+env.add_source_files(env.scene_sources, "navigation_polygon.cpp")
+env.add_source_files(env.scene_sources, "polygon_path_finder.cpp")
+env.add_source_files(env.scene_sources, "tile_set.cpp")
+
+if not env["disable_physics_2d"]:
+    env.add_source_files(env.scene_sources, "capsule_shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "circle_shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "concave_polygon_shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "convex_polygon_shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "rectangle_shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "segment_shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "separation_ray_shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "shape_2d.cpp")
+    env.add_source_files(env.scene_sources, "world_boundary_shape_2d.cpp")
+
+SConscript("skeleton/SCsub")

+ 16 - 0
scene/resources/2d/skeleton/SCsub

@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+from misc.utility.scons_hints import *
+
+Import("env")
+
+env.add_source_files(env.scene_sources, "skeleton_modification_2d.cpp")
+env.add_source_files(env.scene_sources, "skeleton_modification_2d_ccdik.cpp")
+env.add_source_files(env.scene_sources, "skeleton_modification_2d_fabrik.cpp")
+env.add_source_files(env.scene_sources, "skeleton_modification_2d_lookat.cpp")
+env.add_source_files(env.scene_sources, "skeleton_modification_2d_stackholder.cpp")
+env.add_source_files(env.scene_sources, "skeleton_modification_2d_twoboneik.cpp")
+env.add_source_files(env.scene_sources, "skeleton_modification_stack_2d.cpp")
+
+if not env["disable_physics_2d"]:
+    env.add_source_files(env.scene_sources, "skeleton_modification_2d_jiggle.cpp")
+    env.add_source_files(env.scene_sources, "skeleton_modification_2d_physicalbones.cpp")

+ 105 - 63
scene/resources/2d/tile_set.cpp

@@ -635,6 +635,7 @@ bool TileSet::get_occlusion_layer_sdf_collision(int p_layer_index) const {
 	return occlusion_layers[p_layer_index].sdf_collision;
 }
 
+#ifndef PHYSICS_2D_DISABLED
 int TileSet::get_physics_layers_count() const {
 	return physics_layers.size();
 }
@@ -718,6 +719,7 @@ Ref<PhysicsMaterial> TileSet::get_physics_layer_physics_material(int p_layer_ind
 	ERR_FAIL_INDEX_V(p_layer_index, physics_layers.size(), Ref<PhysicsMaterial>());
 	return physics_layers[p_layer_index].physics_material;
 }
+#endif // PHYSICS_2D_DISABLED
 
 // Terrains
 int TileSet::get_terrain_sets_count() const {
@@ -3192,8 +3194,10 @@ void TileSet::reset_state() {
 	tile_filled_mesh.instantiate();
 	tile_meshes_dirty = true;
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics
 	physics_layers.clear();
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrains
 	terrain_sets.clear();
@@ -3424,6 +3428,7 @@ void TileSet::_compatibility_conversion() {
 
 					tile_data->set_z_index(ctd->z_index);
 
+#ifndef PHYSICS_2D_DISABLED
 					// Add the shapes.
 					if (ctd->shapes.size() > 0) {
 						if (get_physics_layers_count() < 1) {
@@ -3447,6 +3452,7 @@ void TileSet::_compatibility_conversion() {
 							}
 						}
 					}
+#endif // PHYSICS_2D_DISABLED
 				}
 				// Update the size count.
 				if (!compatibility_size_count.has(ctd->region.get_size())) {
@@ -3535,6 +3541,7 @@ void TileSet::_compatibility_conversion() {
 								tile_data->set_z_index(ctd->autotile_z_index_map[coords]);
 							}
 
+#ifndef PHYSICS_2D_DISABLED
 							// Add the shapes.
 							if (ctd->shapes.size() > 0) {
 								if (get_physics_layers_count() < 1) {
@@ -3558,6 +3565,7 @@ void TileSet::_compatibility_conversion() {
 									}
 								}
 							}
+#endif // PHYSICS_2D_DISABLED
 
 							// -- TODO: handle --
 							// Those are offset for the whole atlas, they are likely useless for the atlases, but might make sense for single tiles.
@@ -3580,6 +3588,7 @@ void TileSet::_compatibility_conversion() {
 			} break;
 		}
 
+#ifndef PHYSICS_2D_DISABLED
 		// Offset all shapes
 		for (int k = 0; k < ctd->shapes.size(); k++) {
 			Ref<ConvexPolygonShape2D> convex = ctd->shapes[k].shape;
@@ -3591,6 +3600,7 @@ void TileSet::_compatibility_conversion() {
 				convex->set_points(points);
 			}
 		}
+#endif // PHYSICS_2D_DISABLED
 	}
 
 	// Update the TileSet tile_size according to the most common size found.
@@ -3772,7 +3782,9 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
 					} else if (key == "one_way_margin") {
 						csd.one_way_margin = d[key];
 					} else if (key == "shape") {
+#ifndef PHYSICS_2D_DISABLED
 						csd.shape = d[key];
+#endif // PHYSICS_2D_DISABLED
 					} else if (key == "shape_transform") {
 						csd.transform = d[key];
 					}
@@ -3830,6 +3842,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
 				set_occlusion_layer_sdf_collision(index, p_value);
 				return true;
 			}
+#ifndef PHYSICS_2D_DISABLED
 		} else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
 			// Physics layers.
 			int index = components[0].trim_prefix("physics_layer_").to_int();
@@ -3863,6 +3876,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
 				set_physics_layer_physics_material(index, physics_material);
 				return true;
 			}
+#endif // PHYSICS_2D_DISABLED
 		} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
 			// Terrains.
 			int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
@@ -3994,6 +4008,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
 			r_ret = get_occlusion_layer_sdf_collision(index);
 			return true;
 		}
+#ifndef PHYSICS_2D_DISABLED
 	} else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
 		// Physics layers.
 		int index = components[0].trim_prefix("physics_layer_").to_int();
@@ -4013,6 +4028,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
 			r_ret = get_physics_layer_physics_material(index);
 			return true;
 		}
+#endif // PHYSICS_2D_DISABLED
 	} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
 		// Terrains.
 		int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
@@ -4122,6 +4138,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
 		p_list->push_back(property_info);
 	}
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics.
 	p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
 	for (int i = 0; i < physics_layers.size(); i++) {
@@ -4148,6 +4165,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
 		}
 		p_list->push_back(property_info);
 	}
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrains.
 	p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Terrains", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
@@ -4243,6 +4261,7 @@ void TileSet::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_occlusion_layer_sdf_collision", "layer_index", "sdf_collision"), &TileSet::set_occlusion_layer_sdf_collision);
 	ClassDB::bind_method(D_METHOD("get_occlusion_layer_sdf_collision", "layer_index"), &TileSet::get_occlusion_layer_sdf_collision);
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics
 	ClassDB::bind_method(D_METHOD("get_physics_layers_count"), &TileSet::get_physics_layers_count);
 	ClassDB::bind_method(D_METHOD("add_physics_layer", "to_position"), &TileSet::add_physics_layer, DEFVAL(-1));
@@ -4256,6 +4275,7 @@ void TileSet::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_physics_layer_collision_priority", "layer_index"), &TileSet::get_physics_layer_collision_priority);
 	ClassDB::bind_method(D_METHOD("set_physics_layer_physics_material", "layer_index", "physics_material"), &TileSet::set_physics_layer_physics_material);
 	ClassDB::bind_method(D_METHOD("get_physics_layer_physics_material", "layer_index"), &TileSet::get_physics_layer_physics_material);
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrains
 	ClassDB::bind_method(D_METHOD("get_terrain_sets_count"), &TileSet::get_terrain_sets_count);
@@ -4464,6 +4484,7 @@ void TileSetAtlasSource::remove_occlusion_layer(int p_index) {
 	}
 }
 
+#ifndef PHYSICS_2D_DISABLED
 void TileSetAtlasSource::add_physics_layer(int p_to_pos) {
 	for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
 		for (KeyValue<int, TileData *> E_alternative : E_tile.value.alternatives) {
@@ -4487,6 +4508,7 @@ void TileSetAtlasSource::remove_physics_layer(int p_index) {
 		}
 	}
 }
+#endif // PHYSICS_2D_DISABLED
 
 void TileSetAtlasSource::add_terrain_set(int p_to_pos) {
 	for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
@@ -5902,7 +5924,9 @@ void TileData::notify_tile_data_properties_should_change() {
 	}
 
 	occluders.resize(tile_set->get_occlusion_layers_count());
+#ifndef PHYSICS_2D_DISABLED
 	physics.resize(tile_set->get_physics_layers_count());
+#endif // PHYSICS_2D_DISABLED
 	for (int bit_index = 0; bit_index < 16; bit_index++) {
 		if (terrain_set < 0 || terrain_peering_bits[bit_index] >= tile_set->get_terrains_count(terrain_set)) {
 			terrain_peering_bits[bit_index] = -1;
@@ -5950,6 +5974,7 @@ void TileData::remove_occlusion_layer(int p_index) {
 	occluders.remove_at(p_index);
 }
 
+#ifndef PHYSICS_2D_DISABLED
 void TileData::add_physics_layer(int p_to_pos) {
 	if (p_to_pos < 0) {
 		p_to_pos = physics.size();
@@ -5969,6 +5994,7 @@ void TileData::remove_physics_layer(int p_index) {
 	ERR_FAIL_INDEX(p_index, physics.size());
 	physics.remove_at(p_index);
 }
+#endif // PHYSICS_2D_DISABLED
 
 void TileData::add_terrain_set(int p_to_pos) {
 	if (p_to_pos >= 0 && p_to_pos <= terrain_set) {
@@ -6109,8 +6135,10 @@ TileData *TileData::duplicate() {
 	output->z_index = z_index;
 	output->y_sort_origin = y_sort_origin;
 	output->occluders = occluders;
+#ifndef PHYSICS_2D_DISABLED
 	// Physics
 	output->physics = physics;
+#endif // PHYSICS_2D_DISABLED
 	// Terrain
 	output->terrain_set = -1;
 	memcpy(output->terrain_peering_bits, terrain_peering_bits, 16 * sizeof(int));
@@ -6280,6 +6308,7 @@ Ref<OccluderPolygon2D> TileData::get_occluder_polygon(int p_layer_id, int p_poly
 	}
 }
 
+#ifndef PHYSICS_2D_DISABLED
 // Physics
 void TileData::set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity) {
 	ERR_FAIL_INDEX(p_layer_id, physics.size());
@@ -6428,6 +6457,7 @@ Ref<ConvexPolygonShape2D> TileData::get_collision_polygon_shape(int p_layer_id,
 		return I->value[shape_index];
 	}
 }
+#endif // PHYSICS_2D_DISABLED
 
 // Terrain
 void TileData::set_terrain_set(int p_terrain_set) {
@@ -6676,7 +6706,9 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
 				return true;
 			}
 		}
-	} else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
+	} else
+#ifndef PHYSICS_2D_DISABLED
+			if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
 		// Physics layers.
 		int layer_index = components[0].trim_prefix("physics_layer_").to_int();
 		ERR_FAIL_COND_V(layer_index < 0, false);
@@ -6731,49 +6763,51 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
 				return true;
 			}
 		}
-	} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
-		// Navigation layers.
-		int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
-		ERR_FAIL_COND_V(layer_index < 0, false);
-		if (components[1] == "polygon") {
-			Ref<NavigationPolygon> polygon = p_value;
+	} else
+#endif // PHYSICS_2D_DISABLED
+		if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
+			// Navigation layers.
+			int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
+			ERR_FAIL_COND_V(layer_index < 0, false);
+			if (components[1] == "polygon") {
+				Ref<NavigationPolygon> polygon = p_value;
+
+				if (layer_index >= navigation.size()) {
+					if (tile_set) {
+						return false;
+					} else {
+						navigation.resize(layer_index + 1);
+					}
+				}
+				set_navigation_polygon(layer_index, polygon);
+				return true;
+			}
+		} else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
+			// Terrains.
+			for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
+				TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
+				if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
+					set_terrain_peering_bit(bit, p_value);
+					return true;
+				}
+			}
+			return false;
+		} else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
+			// Custom data layers.
+			int layer_index = components[0].trim_prefix("custom_data_").to_int();
+			ERR_FAIL_COND_V(layer_index < 0, false);
 
-			if (layer_index >= navigation.size()) {
+			if (layer_index >= custom_data.size()) {
 				if (tile_set) {
 					return false;
 				} else {
-					navigation.resize(layer_index + 1);
+					custom_data.resize(layer_index + 1);
 				}
 			}
-			set_navigation_polygon(layer_index, polygon);
-			return true;
-		}
-	} else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
-		// Terrains.
-		for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
-			TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
-			if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
-				set_terrain_peering_bit(bit, p_value);
-				return true;
-			}
-		}
-		return false;
-	} else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
-		// Custom data layers.
-		int layer_index = components[0].trim_prefix("custom_data_").to_int();
-		ERR_FAIL_COND_V(layer_index < 0, false);
+			set_custom_data_by_layer_id(layer_index, p_value);
 
-		if (layer_index >= custom_data.size()) {
-			if (tile_set) {
-				return false;
-			} else {
-				custom_data.resize(layer_index + 1);
-			}
+			return true;
 		}
-		set_custom_data_by_layer_id(layer_index, p_value);
-
-		return true;
-	}
 
 	return false;
 }
@@ -6820,7 +6854,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
 					return true;
 				}
 			}
-		} else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
+		} else
+#ifndef PHYSICS_2D_DISABLED
+				if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
 			// Physics layers.
 			int layer_index = components[0].trim_prefix("physics_layer_").to_int();
 			ERR_FAIL_COND_V(layer_index < 0, false);
@@ -6856,36 +6892,38 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
 					return true;
 				}
 			}
-		} else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
-			// Terrains.
-			for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
-				if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
-					r_ret = terrain_peering_bits[i];
-					return true;
+		} else
+#endif // PHYSICS_2D_DISABLED
+			if (components.size() == 2 && components[0] == "terrains_peering_bit") {
+				// Terrains.
+				for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
+					if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
+						r_ret = terrain_peering_bits[i];
+						return true;
+					}
 				}
-			}
-			return false;
-		} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
-			// Occlusion layers.
-			int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
-			ERR_FAIL_COND_V(layer_index < 0, false);
-			if (layer_index >= navigation.size()) {
 				return false;
-			}
-			if (components[1] == "polygon") {
-				r_ret = get_navigation_polygon(layer_index);
+			} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
+				// Occlusion layers.
+				int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
+				ERR_FAIL_COND_V(layer_index < 0, false);
+				if (layer_index >= navigation.size()) {
+					return false;
+				}
+				if (components[1] == "polygon") {
+					r_ret = get_navigation_polygon(layer_index);
+					return true;
+				}
+			} else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
+				// Custom data layers.
+				int layer_index = components[0].trim_prefix("custom_data_").to_int();
+				ERR_FAIL_COND_V(layer_index < 0, false);
+				if (layer_index >= custom_data.size()) {
+					return false;
+				}
+				r_ret = get_custom_data_by_layer_id(layer_index);
 				return true;
 			}
-		} else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
-			// Custom data layers.
-			int layer_index = components[0].trim_prefix("custom_data_").to_int();
-			ERR_FAIL_COND_V(layer_index < 0, false);
-			if (layer_index >= custom_data.size()) {
-				return false;
-			}
-			r_ret = get_custom_data_by_layer_id(layer_index);
-			return true;
-		}
 	}
 
 	return false;
@@ -6909,6 +6947,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
 			}
 		}
 
+#ifndef PHYSICS_2D_DISABLED
 		// Physics layers.
 		p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
 		for (int i = 0; i < physics.size(); i++) {
@@ -6951,6 +6990,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
 				p_list->push_back(property_info);
 			}
 		}
+#endif // PHYSICS_2D_DISABLED
 
 		// Terrain data
 		if (terrain_set >= 0) {
@@ -7023,6 +7063,7 @@ void TileData::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_occluder", "layer_id", "flip_h", "flip_v", "transpose"), &TileData::get_occluder, DEFVAL(false), DEFVAL(false), DEFVAL(false));
 #endif // DISABLE_DEPRECATED
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics.
 	ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "layer_id", "velocity"), &TileData::set_constant_linear_velocity);
 	ClassDB::bind_method(D_METHOD("get_constant_linear_velocity", "layer_id"), &TileData::get_constant_linear_velocity);
@@ -7038,6 +7079,7 @@ void TileData::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("is_collision_polygon_one_way", "layer_id", "polygon_index"), &TileData::is_collision_polygon_one_way);
 	ClassDB::bind_method(D_METHOD("set_collision_polygon_one_way_margin", "layer_id", "polygon_index", "one_way_margin"), &TileData::set_collision_polygon_one_way_margin);
 	ClassDB::bind_method(D_METHOD("get_collision_polygon_one_way_margin", "layer_id", "polygon_index"), &TileData::get_collision_polygon_one_way_margin);
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrain
 	ClassDB::bind_method(D_METHOD("set_terrain_set", "terrain_set"), &TileData::set_terrain_set);

+ 17 - 1
scene/resources/2d/tile_set.h

@@ -36,7 +36,9 @@
 #include "core/templates/rb_set.h"
 #include "scene/2d/light_occluder_2d.h"
 #include "scene/main/canvas_item.h"
+#ifndef PHYSICS_2D_DISABLED
 #include "scene/resources/2d/convex_polygon_shape_2d.h"
+#endif // PHYSICS_2D_DISABLED
 #include "scene/resources/2d/navigation_polygon.h"
 #include "scene/resources/image_texture.h"
 #include "scene/resources/packed_scene.h"
@@ -153,7 +155,9 @@ private:
 		Vector2i autotile_coords;
 		bool one_way;
 		float one_way_margin;
+#ifndef PHYSICS_2D_DISABLED
 		Ref<Shape2D> shape;
+#endif // PHYSICS_2D_DISABLED
 		Transform2D transform;
 	};
 
@@ -322,6 +326,7 @@ private:
 	Ref<ArrayMesh> tile_filled_mesh;
 	mutable bool tile_meshes_dirty = true;
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics
 	struct PhysicsLayer {
 		uint32_t collision_layer = 1;
@@ -330,6 +335,7 @@ private:
 		Ref<PhysicsMaterial> physics_material;
 	};
 	Vector<PhysicsLayer> physics_layers;
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrains
 	struct Terrain {
@@ -439,6 +445,7 @@ public:
 	void set_occlusion_layer_sdf_collision(int p_layer_index, bool p_sdf_collision);
 	bool get_occlusion_layer_sdf_collision(int p_layer_index) const;
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics
 	int get_physics_layers_count() const;
 	void add_physics_layer(int p_index = -1);
@@ -452,6 +459,7 @@ public:
 	real_t get_physics_layer_collision_priority(int p_layer_index) const;
 	void set_physics_layer_physics_material(int p_layer_index, Ref<PhysicsMaterial> p_physics_material);
 	Ref<PhysicsMaterial> get_physics_layer_physics_material(int p_layer_index) const;
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrain sets
 	int get_terrain_sets_count() const;
@@ -685,9 +693,11 @@ public:
 	virtual void add_occlusion_layer(int p_index) override;
 	virtual void move_occlusion_layer(int p_from_index, int p_to_pos) override;
 	virtual void remove_occlusion_layer(int p_index) override;
+#ifndef PHYSICS_2D_DISABLED
 	virtual void add_physics_layer(int p_index) override;
 	virtual void move_physics_layer(int p_from_index, int p_to_pos) override;
 	virtual void remove_physics_layer(int p_index) override;
+#endif // PHYSICS_2D_DISABLED
 	virtual void add_terrain_set(int p_index) override;
 	virtual void move_terrain_set(int p_from_index, int p_to_pos) override;
 	virtual void remove_terrain_set(int p_index) override;
@@ -852,6 +862,7 @@ private:
 	};
 	Vector<OcclusionLayerTileData> occluders;
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics
 	struct PhysicsLayerTileData {
 		struct PolygonShapeTileData {
@@ -867,7 +878,8 @@ private:
 		Vector<PolygonShapeTileData> polygons;
 	};
 	Vector<PhysicsLayerTileData> physics;
-	// TODO add support for areas.
+// TODO add support for areas.
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrain
 	int terrain_set = -1;
@@ -907,9 +919,11 @@ public:
 	void add_occlusion_layer(int p_index);
 	void move_occlusion_layer(int p_from_index, int p_to_pos);
 	void remove_occlusion_layer(int p_index);
+#ifndef PHYSICS_2D_DISABLED
 	void add_physics_layer(int p_index);
 	void move_physics_layer(int p_from_index, int p_to_pos);
 	void remove_physics_layer(int p_index);
+#endif // PHYSICS_2D_DISABLED
 	void add_terrain_set(int p_index);
 	void move_terrain_set(int p_from_index, int p_to_pos);
 	void remove_terrain_set(int p_index);
@@ -959,6 +973,7 @@ public:
 	void set_occluder_polygon(int p_layer_id, int p_polygon_index, const Ref<OccluderPolygon2D> &p_occluder_polygon);
 	Ref<OccluderPolygon2D> get_occluder_polygon(int p_layer_id, int p_polygon_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics
 	void set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity);
 	Vector2 get_constant_linear_velocity(int p_layer_id) const;
@@ -976,6 +991,7 @@ public:
 	float get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const;
 	int get_collision_polygon_shapes_count(int p_layer_id, int p_polygon_index) const;
 	Ref<ConvexPolygonShape2D> get_collision_polygon_shape(int p_layer_id, int p_polygon_index, int shape_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
+#endif // PHYSICS_2D_DISABLED
 
 	// Terrain
 	void set_terrain_set(int p_terrain_id);

+ 21 - 1
scene/resources/3d/SCsub

@@ -3,5 +3,25 @@ from misc.utility.scons_hints import *
 
 Import("env")
 
-env.add_source_files(env.scene_sources, "*.cpp")
+env.add_source_files(env.scene_sources, "fog_material.cpp")
+env.add_source_files(env.scene_sources, "importer_mesh.cpp")
+env.add_source_files(env.scene_sources, "mesh_library.cpp")
+env.add_source_files(env.scene_sources, "navigation_mesh_source_geometry_data_3d.cpp")
+env.add_source_files(env.scene_sources, "primitive_meshes.cpp")
+env.add_source_files(env.scene_sources, "skin.cpp")
+env.add_source_files(env.scene_sources, "sky_material.cpp")
+env.add_source_files(env.scene_sources, "world_3d.cpp")
 env.add_source_files(env.scene_sources, "skeleton/*.cpp")
+
+if not env["disable_physics_3d"]:
+    env.add_source_files(env.scene_sources, "box_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "capsule_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "circle_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "concave_polygon_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "convex_polygon_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "cylinder_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "height_map_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "separation_ray_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "sphere_shape_3d.cpp")
+    env.add_source_files(env.scene_sources, "world_boundary_shape_3d.cpp")

+ 6 - 1
scene/resources/3d/importer_mesh.cpp

@@ -31,10 +31,13 @@
 #include "importer_mesh.h"
 
 #include "core/io/marshalls.h"
-#include "core/math/convex_hull.h"
 #include "core/math/random_pcg.h"
 #include "scene/resources/surface_tool.h"
 
+#ifndef PHYSICS_3D_DISABLED
+#include "core/math/convex_hull.h"
+#endif // PHYSICS_3D_DISABLED
+
 String ImporterMesh::validate_blend_shape_name(const String &p_name) {
 	String name = p_name;
 	const char *characters = ":";
@@ -783,6 +786,7 @@ Vector<Face3> ImporterMesh::get_faces() const {
 	return faces;
 }
 
+#ifndef PHYSICS_3D_DISABLED
 Vector<Ref<Shape3D>> ImporterMesh::convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const {
 	ERR_FAIL_NULL_V(Mesh::convex_decomposition_function, Vector<Ref<Shape3D>>());
 
@@ -888,6 +892,7 @@ Ref<ConcavePolygonShape3D> ImporterMesh::create_trimesh_shape() const {
 	shape->set_faces(face_points);
 	return shape;
 }
+#endif // PHYSICS_3D_DISABLED
 
 Ref<NavigationMesh> ImporterMesh::create_navigation_mesh() {
 	Vector<Face3> faces = get_faces();

+ 7 - 2
scene/resources/3d/importer_mesh.h

@@ -31,11 +31,14 @@
 #pragma once
 
 #include "core/io/resource.h"
-#include "scene/resources/3d/concave_polygon_shape_3d.h"
-#include "scene/resources/3d/convex_polygon_shape_3d.h"
 #include "scene/resources/mesh.h"
 #include "scene/resources/navigation_mesh.h"
 
+#ifndef PHYSICS_3D_DISABLED
+#include "scene/resources/3d/concave_polygon_shape_3d.h"
+#include "scene/resources/3d/convex_polygon_shape_3d.h"
+#endif // PHYSICS_3D_DISABLED
+
 // The following classes are used by importers instead of ArrayMesh and MeshInstance3D
 // so the data is not registered (hence, quality loss), importing happens faster and
 // its easier to modify before saving
@@ -117,9 +120,11 @@ public:
 	Ref<ImporterMesh> get_shadow_mesh() const;
 
 	Vector<Face3> get_faces() const;
+#ifndef PHYSICS_3D_DISABLED
 	Vector<Ref<Shape3D>> convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const;
 	Ref<ConvexPolygonShape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
 	Ref<ConcavePolygonShape3D> create_trimesh_shape() const;
+#endif // PHYSICS_3D_DISABLED
 	Ref<NavigationMesh> create_navigation_mesh();
 	Error lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache);
 

+ 16 - 0
scene/resources/3d/mesh_library.cpp

@@ -30,7 +30,9 @@
 
 #include "mesh_library.h"
 
+#ifndef PHYSICS_3D_DISABLED
 #include "box_shape_3d.h"
+#endif // PHYSICS_3D_DISABLED
 
 bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
 	String prop_name = p_name;
@@ -65,6 +67,7 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
 					set_item_mesh_cast_shadow(idx, RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON);
 				} break;
 			}
+#ifndef PHYSICS_3D_DISABLED
 		} else if (what == "shape") {
 			Vector<ShapeData> shapes;
 			ShapeData sd;
@@ -73,6 +76,7 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
 			set_item_shapes(idx, shapes);
 		} else if (what == "shapes") {
 			_set_item_shapes(idx, p_value);
+#endif // PHYSICS_3D_DISABLED
 		} else if (what == "preview") {
 			set_item_preview(idx, p_value);
 		} else if (what == "navigation_mesh") {
@@ -111,8 +115,10 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {
 		r_ret = get_item_mesh_transform(idx);
 	} else if (what == "mesh_cast_shadow") {
 		r_ret = (int)get_item_mesh_cast_shadow(idx);
+#ifndef PHYSICS_3D_DISABLED
 	} else if (what == "shapes") {
 		r_ret = _get_item_shapes(idx);
+#endif // PHYSICS_3D_DISABLED
 	} else if (what == "navigation_mesh") {
 		r_ret = get_item_navigation_mesh(idx);
 	} else if (what == "navigation_mesh_transform") {
@@ -181,12 +187,14 @@ void MeshLibrary::set_item_mesh_cast_shadow(int p_item, RS::ShadowCastingSetting
 	emit_changed();
 }
 
+#ifndef PHYSICS_3D_DISABLED
 void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) {
 	ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
 	item_map[p_item].shapes = p_shapes;
 	emit_changed();
 	notify_property_list_changed();
 }
+#endif // PHYSICS_3D_DISABLED
 
 void MeshLibrary::set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh) {
 	ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
@@ -232,10 +240,12 @@ RS::ShadowCastingSetting MeshLibrary::get_item_mesh_cast_shadow(int p_item) cons
 	return item_map[p_item].mesh_cast_shadow;
 }
 
+#ifndef PHYSICS_3D_DISABLED
 Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const {
 	ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Vector<ShapeData>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
 	return item_map[p_item].shapes;
 }
+#endif // PHYSICS_3D_DISABLED
 
 Ref<NavigationMesh> MeshLibrary::get_item_navigation_mesh(int p_item) const {
 	ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<NavigationMesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
@@ -302,6 +312,7 @@ int MeshLibrary::get_last_unused_item_id() const {
 	}
 }
 
+#ifndef PHYSICS_3D_DISABLED
 void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) {
 	Array arr_shapes = p_shapes;
 	int size = p_shapes.size();
@@ -351,6 +362,7 @@ Array MeshLibrary::_get_item_shapes(int p_item) const {
 
 	return ret;
 }
+#endif // PHYSICS_3D_DISABLED
 
 void MeshLibrary::reset_state() {
 	clear();
@@ -364,7 +376,9 @@ void MeshLibrary::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_item_navigation_mesh", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh);
 	ClassDB::bind_method(D_METHOD("set_item_navigation_mesh_transform", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh_transform);
 	ClassDB::bind_method(D_METHOD("set_item_navigation_layers", "id", "navigation_layers"), &MeshLibrary::set_item_navigation_layers);
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("set_item_shapes", "id", "shapes"), &MeshLibrary::_set_item_shapes);
+#endif // PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("set_item_preview", "id", "texture"), &MeshLibrary::set_item_preview);
 	ClassDB::bind_method(D_METHOD("get_item_name", "id"), &MeshLibrary::get_item_name);
 	ClassDB::bind_method(D_METHOD("get_item_mesh", "id"), &MeshLibrary::get_item_mesh);
@@ -373,7 +387,9 @@ void MeshLibrary::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_item_navigation_mesh", "id"), &MeshLibrary::get_item_navigation_mesh);
 	ClassDB::bind_method(D_METHOD("get_item_navigation_mesh_transform", "id"), &MeshLibrary::get_item_navigation_mesh_transform);
 	ClassDB::bind_method(D_METHOD("get_item_navigation_layers", "id"), &MeshLibrary::get_item_navigation_layers);
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("get_item_shapes", "id"), &MeshLibrary::_get_item_shapes);
+#endif // PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("get_item_preview", "id"), &MeshLibrary::get_item_preview);
 	ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item);
 	ClassDB::bind_method(D_METHOD("find_item_by_name", "name"), &MeshLibrary::find_item_by_name);

+ 13 - 0
scene/resources/3d/mesh_library.h

@@ -35,23 +35,30 @@
 #include "scene/resources/mesh.h"
 #include "scene/resources/navigation_mesh.h"
 #include "servers/rendering_server.h"
+
+#ifndef PHYSICS_3D_DISABLED
 #include "shape_3d.h"
+#endif // PHYSICS_3D_DISABLED
 
 class MeshLibrary : public Resource {
 	GDCLASS(MeshLibrary, Resource);
 	RES_BASE_EXTENSION("meshlib");
 
 public:
+#ifndef PHYSICS_3D_DISABLED
 	struct ShapeData {
 		Ref<Shape3D> shape;
 		Transform3D local_transform;
 	};
+#endif // PHYSICS_3D_DISABLED
 	struct Item {
 		String name;
 		Ref<Mesh> mesh;
 		Transform3D mesh_transform;
 		RS::ShadowCastingSetting mesh_cast_shadow = RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON;
+#ifndef PHYSICS_3D_DISABLED
 		Vector<ShapeData> shapes;
+#endif // PHYSICS_3D_DISABLED
 		Ref<Texture2D> preview;
 		Ref<NavigationMesh> navigation_mesh;
 		Transform3D navigation_mesh_transform;
@@ -60,8 +67,10 @@ public:
 
 	RBMap<int, Item> item_map;
 
+#ifndef PHYSICS_3D_DISABLED
 	void _set_item_shapes(int p_item, const Array &p_shapes);
 	Array _get_item_shapes(int p_item) const;
+#endif // PHYSICS_3D_DISABLED
 
 protected:
 	bool _set(const StringName &p_name, const Variant &p_value);
@@ -80,7 +89,9 @@ public:
 	void set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh);
 	void set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform);
 	void set_item_navigation_layers(int p_item, uint32_t p_navigation_layers);
+#ifndef PHYSICS_3D_DISABLED
 	void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes);
+#endif // PHYSICS_3D_DISABLED
 	void set_item_preview(int p_item, const Ref<Texture2D> &p_preview);
 	String get_item_name(int p_item) const;
 	Ref<Mesh> get_item_mesh(int p_item) const;
@@ -89,7 +100,9 @@ public:
 	Ref<NavigationMesh> get_item_navigation_mesh(int p_item) const;
 	Transform3D get_item_navigation_mesh_transform(int p_item) const;
 	uint32_t get_item_navigation_layers(int p_item) const;
+#ifndef PHYSICS_3D_DISABLED
 	Vector<ShapeData> get_item_shapes(int p_item) const;
+#endif // PHYSICS_3D_DISABLED
 	Ref<Texture2D> get_item_preview(int p_item) const;
 
 	void remove_item(int p_item);

+ 12 - 0
scene/resources/3d/world_3d.cpp

@@ -45,6 +45,7 @@ void World3D::_remove_camera(Camera3D *p_camera) {
 }
 
 RID World3D::get_space() const {
+#ifndef PHYSICS_3D_DISABLED
 	if (space.is_null()) {
 		space = PhysicsServer3D::get_singleton()->space_create();
 		PhysicsServer3D::get_singleton()->space_set_active(space, true);
@@ -53,6 +54,7 @@ RID World3D::get_space() const {
 		PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, GLOBAL_GET("physics/3d/default_linear_damp"));
 		PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_GET("physics/3d/default_angular_damp"));
 	}
+#endif // PHYSICS_3D_DISABLED
 	return space;
 }
 
@@ -139,9 +141,11 @@ Ref<Compositor> World3D::get_compositor() const {
 	return compositor;
 }
 
+#ifndef PHYSICS_3D_DISABLED
 PhysicsDirectSpaceState3D *World3D::get_direct_space_state() {
 	return PhysicsServer3D::get_singleton()->space_get_direct_state(get_space());
 }
+#endif // PHYSICS_3D_DISABLED
 
 void World3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space);
@@ -153,14 +157,18 @@ void World3D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_fallback_environment"), &World3D::get_fallback_environment);
 	ClassDB::bind_method(D_METHOD("set_camera_attributes", "attributes"), &World3D::set_camera_attributes);
 	ClassDB::bind_method(D_METHOD("get_camera_attributes"), &World3D::get_camera_attributes);
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World3D::get_direct_space_state);
+#endif // PHYSICS_3D_DISABLED
 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment");
 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_attributes", PROPERTY_HINT_RESOURCE_TYPE, "CameraAttributesPractical,CameraAttributesPhysical"), "set_camera_attributes", "get_camera_attributes");
 	ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_space");
 	ADD_PROPERTY(PropertyInfo(Variant::RID, "navigation_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_navigation_map");
 	ADD_PROPERTY(PropertyInfo(Variant::RID, "scenario", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_scenario");
+#ifndef PHYSICS_3D_DISABLED
 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState3D", PROPERTY_USAGE_NONE), "", "get_direct_space_state");
+#endif // PHYSICS_3D_DISABLED
 }
 
 World3D::World3D() {
@@ -169,13 +177,17 @@ World3D::World3D() {
 
 World3D::~World3D() {
 	ERR_FAIL_NULL(RenderingServer::get_singleton());
+#ifndef PHYSICS_3D_DISABLED
 	ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
+#endif // PHYSICS_3D_DISABLED
 	ERR_FAIL_NULL(NavigationServer3D::get_singleton());
 
 	RenderingServer::get_singleton()->free(scenario);
+#ifndef PHYSICS_3D_DISABLED
 	if (space.is_valid()) {
 		PhysicsServer3D::get_singleton()->free(space);
 	}
+#endif // PHYSICS_3D_DISABLED
 	if (navigation_map.is_valid()) {
 		NavigationServer3D::get_singleton()->free(navigation_map);
 	}

+ 4 - 1
scene/resources/3d/world_3d.h

@@ -33,8 +33,9 @@
 #include "core/io/resource.h"
 #include "scene/resources/compositor.h"
 #include "scene/resources/environment.h"
+#ifndef PHYSICS_3D_DISABLED
 #include "servers/physics_server_3d.h"
-#include "servers/rendering_server.h"
+#endif // PHYSICS_3D_DISABLED
 
 class CameraAttributes;
 class Camera3D;
@@ -83,7 +84,9 @@ public:
 
 	_FORCE_INLINE_ const HashSet<Camera3D *> &get_cameras() const { return cameras; }
 
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsDirectSpaceState3D *get_direct_space_state();
+#endif // PHYSICS_3D_DISABLED
 
 	World3D();
 	~World3D();

+ 10 - 8
scene/resources/mesh.cpp

@@ -34,10 +34,10 @@
 #include "core/templates/pair.h"
 #include "scene/resources/surface_tool.h"
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 #include "scene/resources/3d/concave_polygon_shape_3d.h"
 #include "scene/resources/3d/convex_polygon_shape_3d.h"
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
 void MeshConvexDecompositionSettings::set_max_concavity(real_t p_max_concavity) {
 	max_concavity = CLAMP(p_max_concavity, 0.001, 1.0);
@@ -201,7 +201,9 @@ void MeshConvexDecompositionSettings::_bind_methods() {
 	BIND_ENUM_CONSTANT(CONVEX_DECOMPOSITION_MODE_TETRAHEDRON);
 }
 
+#ifndef PHYSICS_3D_DISABLED
 Mesh::ConvexDecompositionFunc Mesh::convex_decomposition_function = nullptr;
+#endif // PHYSICS_3D_DISABLED
 
 int Mesh::get_surface_count() const {
 	int ret = 0;
@@ -521,7 +523,7 @@ Vector<Face3> Mesh::get_surface_faces(int p_surface) const {
 	return Vector<Face3>();
 }
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 Ref<ConvexPolygonShape3D> Mesh::create_convex_shape(bool p_clean, bool p_simplify) const {
 	if (p_simplify) {
 		Ref<MeshConvexDecompositionSettings> settings = Ref<MeshConvexDecompositionSettings>();
@@ -581,7 +583,7 @@ Ref<ConcavePolygonShape3D> Mesh::create_trimesh_shape() const {
 	shape->set_faces(face_points);
 	return shape;
 }
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
 Ref<Mesh> Mesh::create_outline(float p_margin) const {
 	Array arrays;
@@ -900,7 +902,7 @@ void Mesh::clear_cache() const {
 	debug_lines.clear();
 }
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 Vector<Ref<Shape3D>> Mesh::convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const {
 	ERR_FAIL_NULL_V(convex_decomposition_function, Vector<Ref<Shape3D>>());
 
@@ -937,7 +939,7 @@ Vector<Ref<Shape3D>> Mesh::convex_decompose(const Ref<MeshConvexDecompositionSet
 
 	return ret;
 }
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
 int Mesh::get_builtin_bind_pose_count() const {
 	return 0;
@@ -2297,10 +2299,10 @@ void ArrayMesh::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("surface_find_by_name", "name"), &ArrayMesh::surface_find_by_name);
 	ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &ArrayMesh::surface_set_name);
 	ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &ArrayMesh::surface_get_name);
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("create_trimesh_shape"), &ArrayMesh::create_trimesh_shape);
 	ClassDB::bind_method(D_METHOD("create_convex_shape", "clean", "simplify"), &ArrayMesh::create_convex_shape, DEFVAL(true), DEFVAL(false));
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 	ClassDB::bind_method(D_METHOD("create_outline", "margin"), &ArrayMesh::create_outline);
 	ClassDB::bind_method(D_METHOD("regen_normal_maps"), &ArrayMesh::regen_normal_maps);
 	ClassDB::set_method_flags(get_class_static(), _scs_create("regen_normal_maps"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);

+ 7 - 6
scene/resources/mesh.h

@@ -33,16 +33,17 @@
 #include "core/io/resource.h"
 #include "core/math/face3.h"
 #include "core/math/triangle_mesh.h"
-#ifndef _3D_DISABLED
-#include "scene/resources/3d/shape_3d.h"
-#endif // _3D_DISABLED
 #include "scene/resources/material.h"
 #include "servers/rendering_server.h"
 
+#ifndef PHYSICS_3D_DISABLED
+#include "scene/resources/3d/shape_3d.h"
+
 class ConcavePolygonShape3D;
 class ConvexPolygonShape3D;
-class MeshConvexDecompositionSettings;
 class Shape3D;
+#endif // PHYSICS_3D_DISABLED
+class MeshConvexDecompositionSettings;
 
 class Mesh : public Resource {
 	GDCLASS(Mesh, Resource);
@@ -191,15 +192,15 @@ public:
 	Size2i get_lightmap_size_hint() const;
 	void clear_cache() const;
 
+#ifndef PHYSICS_3D_DISABLED
 	typedef Vector<Vector<Vector3>> (*ConvexDecompositionFunc)(const real_t *p_vertices, int p_vertex_count, const uint32_t *p_triangles, int p_triangle_count, const Ref<MeshConvexDecompositionSettings> &p_settings, Vector<Vector<uint32_t>> *r_convex_indices);
 
 	static ConvexDecompositionFunc convex_decomposition_function;
 
-#ifndef _3D_DISABLED
 	Vector<Ref<Shape3D>> convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const;
 	Ref<ConvexPolygonShape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
 	Ref<ConcavePolygonShape3D> create_trimesh_shape() const;
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
 	virtual int get_builtin_bind_pose_count() const;
 	virtual Transform3D get_builtin_bind_pose(int p_index) const;

+ 2 - 0
scene/resources/physics_material.cpp

@@ -30,6 +30,7 @@
 
 #include "physics_material.h"
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 void PhysicsMaterial::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicsMaterial::set_friction);
 	ClassDB::bind_method(D_METHOD("get_friction"), &PhysicsMaterial::get_friction);
@@ -68,3 +69,4 @@ void PhysicsMaterial::set_absorbent(bool p_val) {
 	absorbent = p_val;
 	emit_changed();
 }
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)

+ 2 - 0
scene/resources/physics_material.h

@@ -30,6 +30,7 @@
 
 #pragma once
 
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 #include "core/io/resource.h"
 
 class PhysicsMaterial : public Resource {
@@ -68,3 +69,4 @@ public:
 
 	PhysicsMaterial() {}
 };
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)

+ 14 - 4
scene/resources/world_2d.cpp

@@ -33,13 +33,13 @@
 #include "core/config/project_settings.h"
 #include "scene/2d/visible_on_screen_notifier_2d.h"
 #include "servers/navigation_server_2d.h"
-#include "servers/physics_server_2d.h"
 #include "servers/rendering_server.h"
 
 RID World2D::get_canvas() const {
 	return canvas;
 }
 
+#ifndef PHYSICS_2D_DISABLED
 RID World2D::get_space() const {
 	if (space.is_null()) {
 		space = PhysicsServer2D::get_singleton()->space_create();
@@ -51,6 +51,7 @@ RID World2D::get_space() const {
 	}
 	return space;
 }
+#endif // PHYSICS_2D_DISABLED
 
 RID World2D::get_navigation_map() const {
 	if (navigation_map.is_null()) {
@@ -64,21 +65,26 @@ RID World2D::get_navigation_map() const {
 	return navigation_map;
 }
 
+#ifndef PHYSICS_2D_DISABLED
 PhysicsDirectSpaceState2D *World2D::get_direct_space_state() {
 	return PhysicsServer2D::get_singleton()->space_get_direct_state(get_space());
 }
+#endif // PHYSICS_2D_DISABLED
 
 void World2D::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_canvas"), &World2D::get_canvas);
-	ClassDB::bind_method(D_METHOD("get_space"), &World2D::get_space);
 	ClassDB::bind_method(D_METHOD("get_navigation_map"), &World2D::get_navigation_map);
-
+#ifndef PHYSICS_2D_DISABLED
+	ClassDB::bind_method(D_METHOD("get_space"), &World2D::get_space);
 	ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World2D::get_direct_space_state);
+#endif // PHYSICS_2D_DISABLED
 
 	ADD_PROPERTY(PropertyInfo(Variant::RID, "canvas", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_canvas");
-	ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_space");
 	ADD_PROPERTY(PropertyInfo(Variant::RID, "navigation_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_navigation_map");
+#ifndef PHYSICS_2D_DISABLED
+	ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_space");
 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState2D", PROPERTY_USAGE_NONE), "", "get_direct_space_state");
+#endif // PHYSICS_2D_DISABLED
 }
 
 void World2D::register_viewport(Viewport *p_viewport) {
@@ -95,12 +101,16 @@ World2D::World2D() {
 
 World2D::~World2D() {
 	ERR_FAIL_NULL(RenderingServer::get_singleton());
+#ifndef PHYSICS_2D_DISABLED
 	ERR_FAIL_NULL(PhysicsServer2D::get_singleton());
+#endif // PHYSICS_2D_DISABLED
 	ERR_FAIL_NULL(NavigationServer2D::get_singleton());
 	RenderingServer::get_singleton()->free(canvas);
+#ifndef PHYSICS_2D_DISABLED
 	if (space.is_valid()) {
 		PhysicsServer2D::get_singleton()->free(space);
 	}
+#endif // PHYSICS_2D_DISABLED
 	if (navigation_map.is_valid()) {
 		NavigationServer2D::get_singleton()->free(navigation_map);
 	}

+ 6 - 1
scene/resources/world_2d.h

@@ -31,7 +31,10 @@
 #pragma once
 
 #include "core/io/resource.h"
+
+#ifndef PHYSICS_2D_DISABLED
 #include "servers/physics_server_2d.h"
+#endif // PHYSICS_2D_DISABLED
 
 class VisibleOnScreenNotifier2D;
 class Viewport;
@@ -52,10 +55,12 @@ protected:
 
 public:
 	RID get_canvas() const;
-	RID get_space() const;
 	RID get_navigation_map() const;
 
+#ifndef PHYSICS_2D_DISABLED
+	RID get_space() const;
 	PhysicsDirectSpaceState2D *get_direct_space_state();
+#endif // PHYSICS_2D_DISABLED
 
 	void register_viewport(Viewport *p_viewport);
 	void remove_viewport(Viewport *p_viewport);

+ 8 - 6
servers/SCsub

@@ -10,8 +10,6 @@ env.add_source_files(env.servers_sources, "camera_server.cpp")
 env.add_source_files(env.servers_sources, "display_server.cpp")
 env.add_source_files(env.servers_sources, "navigation_server_2d.cpp")
 env.add_source_files(env.servers_sources, "navigation_server_3d.cpp")
-env.add_source_files(env.servers_sources, "physics_server_2d.cpp")
-env.add_source_files(env.servers_sources, "physics_server_2d_wrap_mt.cpp")
 env.add_source_files(env.servers_sources, "register_server_types.cpp")
 env.add_source_files(env.servers_sources, "rendering_server.cpp")
 env.add_source_files(env.servers_sources, "text_server.cpp")
@@ -26,13 +24,17 @@ SConscript("navigation/SCsub")
 SConscript("rendering/SCsub")
 SConscript("text/SCsub")
 
-if not env["disable_3d"]:
+if not env["disable_physics_2d"]:
+    env.add_source_files(env.servers_sources, "physics_server_2d.cpp")
+    env.add_source_files(env.servers_sources, "physics_server_2d_wrap_mt.cpp")
+
+if not env["disable_physics_3d"]:
     env.add_source_files(env.servers_sources, "physics_server_3d.cpp")
     env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp")
 
-    if not env["disable_xr"]:
-        env.add_source_files(env.servers_sources, "xr_server.cpp")
-        SConscript("xr/SCsub")
+if not env["disable_xr"]:
+    env.add_source_files(env.servers_sources, "xr_server.cpp")
+    SConscript("xr/SCsub")
 
 lib = env.add_library("servers", env.servers_sources)
 

+ 20 - 12
servers/register_server_types.cpp

@@ -81,16 +81,19 @@
 
 // 2D physics and navigation.
 #include "navigation_server_2d.h"
+#ifndef PHYSICS_2D_DISABLED
 #include "physics_server_2d.h"
 #include "physics_server_2d_dummy.h"
 #include "servers/extensions/physics_server_2d_extension.h"
+#endif // PHYSICS_2D_DISABLED
 
 // 3D physics and navigation (3D navigation is needed for 2D).
 #include "navigation_server_3d.h"
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 #include "physics_server_3d.h"
 #include "physics_server_3d_dummy.h"
 #include "servers/extensions/physics_server_3d_extension.h"
+#endif // PHYSICS_3D_DISABLED
 #ifndef XR_DISABLED
 #include "xr/xr_body_tracker.h"
 #include "xr/xr_controller_tracker.h"
@@ -101,19 +104,20 @@
 #include "xr/xr_positional_tracker.h"
 #include "xr_server.h"
 #endif // XR_DISABLED
-#endif // _3D_DISABLED
 
 ShaderTypes *shader_types = nullptr;
 
-#ifndef _3D_DISABLED
-static PhysicsServer3D *_create_dummy_physics_server_3d() {
-	return memnew(PhysicsServer3DDummy);
-}
-#endif // _3D_DISABLED
-
+#ifndef PHYSICS_2D_DISABLED
 static PhysicsServer2D *_create_dummy_physics_server_2d() {
 	return memnew(PhysicsServer2DDummy);
 }
+#endif // PHYSICS_2D_DISABLED
+
+#ifndef PHYSICS_3D_DISABLED
+static PhysicsServer3D *_create_dummy_physics_server_3d() {
+	return memnew(PhysicsServer3DDummy);
+}
+#endif // PHYSICS_3D_DISABLED
 
 static bool has_server_feature_callback(const String &p_feature) {
 	if (RenderingServer::get_singleton()) {
@@ -250,6 +254,7 @@ void register_server_types() {
 
 	ServersDebugger::initialize();
 
+#ifndef PHYSICS_2D_DISABLED
 	// Physics 2D
 	GDREGISTER_CLASS(PhysicsServer2DManager);
 	Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2DManager", PhysicsServer2DManager::get_singleton(), "PhysicsServer2DManager"));
@@ -275,12 +280,13 @@ void register_server_types() {
 	GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT");
 
 	PhysicsServer2DManager::get_singleton()->register_server("Dummy", callable_mp_static(_create_dummy_physics_server_2d));
+#endif // PHYSICS_2D_DISABLED
 
 	GDREGISTER_ABSTRACT_CLASS(NavigationServer2D);
 	GDREGISTER_CLASS(NavigationPathQueryParameters2D);
 	GDREGISTER_CLASS(NavigationPathQueryResult2D);
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	// Physics 3D
 	GDREGISTER_CLASS(PhysicsServer3DManager);
 	Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3DManager", PhysicsServer3DManager::get_singleton(), "PhysicsServer3DManager"));
@@ -308,6 +314,7 @@ void register_server_types() {
 	GLOBAL_DEF(PropertyInfo(Variant::STRING, PhysicsServer3DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT"), "DEFAULT");
 
 	PhysicsServer3DManager::get_singleton()->register_server("Dummy", callable_mp_static(_create_dummy_physics_server_3d));
+#endif // PHYSICS_3D_DISABLED
 
 #ifndef XR_DISABLED
 	GDREGISTER_ABSTRACT_CLASS(XRInterface);
@@ -322,7 +329,6 @@ void register_server_types() {
 	GDREGISTER_CLASS(XRServer);
 	GDREGISTER_ABSTRACT_CLASS(XRTracker);
 #endif // XR_DISABLED
-#endif // _3D_DISABLED
 
 	GDREGISTER_ABSTRACT_CLASS(NavigationServer3D);
 	GDREGISTER_CLASS(NavigationPathQueryParameters3D);
@@ -359,13 +365,15 @@ void register_server_singletons() {
 	Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D"));
 	Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer"));
 
+#ifndef PHYSICS_2D_DISABLED
 	Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton(), "PhysicsServer2D"));
-#ifndef _3D_DISABLED
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton(), "PhysicsServer3D"));
+#endif // PHYSICS_3D_DISABLED
 #ifndef XR_DISABLED
 	Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer"));
 #endif // XR_DISABLED
-#endif // _3D_DISABLED
 
 	OS::get_singleton()->benchmark_end_measure("Servers", "Register Singletons");
 }

+ 2 - 0
tests/scene/test_text_edit.h

@@ -54,7 +54,9 @@ static inline Array reverse_nested(Array array) {
 }
 
 TEST_CASE("[SceneTree][TextEdit] text entry") {
+#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	SceneTree::get_singleton()->get_root()->set_physics_object_picking(false);
+#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
 	TextEdit *text_edit = memnew(TextEdit);
 	SceneTree::get_singleton()->get_root()->add_child(text_edit);
 	text_edit->grab_focus();

+ 8 - 2
tests/scene/test_viewport.h

@@ -30,14 +30,18 @@
 
 #pragma once
 
-#include "scene/2d/physics/area_2d.h"
-#include "scene/2d/physics/collision_shape_2d.h"
+#include "scene/2d/node_2d.h"
 #include "scene/gui/control.h"
 #include "scene/gui/subviewport_container.h"
 #include "scene/main/canvas_layer.h"
 #include "scene/main/window.h"
+
+#ifndef PHYSICS_2D_DISABLED
+#include "scene/2d/physics/area_2d.h"
+#include "scene/2d/physics/collision_shape_2d.h"
 #include "scene/resources/2d/rectangle_shape_2d.h"
 #include "servers/physics_server_2d_dummy.h"
+#endif // PHYSICS_2D_DISABLED
 
 #include "tests/test_macros.h"
 
@@ -1510,6 +1514,7 @@ TEST_CASE("[SceneTree][Viewport] Control mouse cursor shape") {
 	}
 }
 
+#ifndef PHYSICS_2D_DISABLED
 class TestArea2D : public Area2D {
 	GDCLASS(TestArea2D, Area2D);
 
@@ -1910,6 +1915,7 @@ TEST_CASE("[SceneTree][Viewport] Physics Picking 2D") {
 		memdelete(E.a);
 	}
 }
+#endif // PHYSICS_2D_DISABLED
 
 TEST_CASE("[SceneTree][Viewport] Embedded Windows") {
 	Window *root = SceneTree::get_singleton()->get_root();

+ 21 - 7
tests/test_main.cpp

@@ -135,7 +135,9 @@
 #include "tests/scene/test_parallax_2d.h"
 #include "tests/scene/test_path_2d.h"
 #include "tests/scene/test_path_follow_2d.h"
+#ifndef PHYSICS_3D_DISABLED
 #include "tests/scene/test_physics_material.h"
+#endif // PHYSICS_3D_DISABLED
 #include "tests/scene/test_sprite_frames.h"
 #include "tests/scene/test_style_box_texture.h"
 #include "tests/scene/test_texture_progress_bar.h"
@@ -176,7 +178,9 @@
 #include "tests/scene/test_arraymesh.h"
 #include "tests/scene/test_camera_3d.h"
 #include "tests/scene/test_gltf_document.h"
+#ifndef PHYSICS_3D_DISABLED
 #include "tests/scene/test_height_map_shape_3d.h"
+#endif // PHYSICS_3D_DISABLED
 #include "tests/scene/test_path_3d.h"
 #include "tests/scene/test_path_follow_3d.h"
 #include "tests/scene/test_primitives.h"
@@ -194,12 +198,14 @@
 #include "servers/navigation_server_2d.h"
 #include "servers/navigation_server_3d.h"
 #endif // _3D_DISABLED
+#ifndef PHYSICS_2D_DISABLED
 #include "servers/physics_server_2d.h"
 #include "servers/physics_server_2d_dummy.h"
-#ifndef _3D_DISABLED
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 #include "servers/physics_server_3d.h"
 #include "servers/physics_server_3d_dummy.h"
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 #include "servers/rendering/rendering_server_default.h"
 
 int test_main(int argc, char *argv[]) {
@@ -274,9 +280,13 @@ struct GodotTestCaseListener : public doctest::IReporter {
 
 	SignalWatcher *signal_watcher = nullptr;
 
+#ifndef PHYSICS_2D_DISABLED
 	PhysicsServer2D *physics_server_2d = nullptr;
-#ifndef _3D_DISABLED
+#endif // PHYSICS_2D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 	PhysicsServer3D *physics_server_3d = nullptr;
+#endif // PHYSICS_3D_DISABLED
+#ifndef _3D_DISABLED
 	NavigationServer3D *navigation_server_3d = nullptr;
 	NavigationServer2D *navigation_server_2d = nullptr;
 #endif // _3D_DISABLED
@@ -311,19 +321,21 @@ struct GodotTestCaseListener : public doctest::IReporter {
 			ThemeDB::get_singleton()->finalize_theme();
 			ThemeDB::get_singleton()->initialize_theme();
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_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
+#endif // PHYSICS_3D_DISABLED
 
+#ifndef PHYSICS_2D_DISABLED
 			physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
 			if (!physics_server_2d) {
 				physics_server_2d = memnew(PhysicsServer2DDummy);
 			}
 			physics_server_2d->init();
+#endif // PHYSICS_2D_DISABLED
 
 #ifndef _3D_DISABLED
 			ERR_PRINT_OFF;
@@ -411,19 +423,21 @@ struct GodotTestCaseListener : public doctest::IReporter {
 		}
 #endif // _3D_DISABLED
 
-#ifndef _3D_DISABLED
+#ifndef PHYSICS_3D_DISABLED
 		if (physics_server_3d) {
 			physics_server_3d->finish();
 			memdelete(physics_server_3d);
 			physics_server_3d = nullptr;
 		}
-#endif // _3D_DISABLED
+#endif // PHYSICS_3D_DISABLED
 
+#ifndef PHYSICS_2D_DISABLED
 		if (physics_server_2d) {
 			physics_server_2d->finish();
 			memdelete(physics_server_2d);
 			physics_server_2d = nullptr;
 		}
+#endif // PHYSICS_2D_DISABLED
 
 		if (Input::get_singleton()) {
 			memdelete(Input::get_singleton());