Allow to compile templates without physics servers

This commit is contained in:
Michael Alexsander 2025-02-27 19:01:23 -03:00
parent b13c96b097
commit 5ad414d046
No known key found for this signature in database
GPG key ID: A9C91EE110F4EABA
72 changed files with 951 additions and 364 deletions

View file

@ -90,7 +90,7 @@ jobs:
- name: Minimal template (target=template_release, tests=yes, everything disabled) - name: Minimal template (target=template_release, tests=yes, everything disabled)
cache-name: linux-template-minimal cache-name: linux-template-minimal
target: template_release 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 bin: ./bin/godot.linuxbsd.template_release.x86_64
tests: true tests: true
artifact: true artifact: true

View file

@ -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("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_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_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(BoolVariable("disable_xr", "Disable XR nodes and server", False))
opts.Add("build_profile", "Path to a file containing a feature build profile", "") 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)) 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.path.remove(tmppath)
sys.modules.pop("detect") 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( 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) Exit(255)
else:
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"]) 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"]: if env["disable_xr"]:
env.Append(CPPDEFINES=["XR_DISABLED"]) env.Append(CPPDEFINES=["XR_DISABLED"])
if env["minizip"]: if env["minizip"]:

View file

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

View file

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

View file

@ -49,10 +49,10 @@
#include "editor/themes/editor_scale.h" #include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h" #include "editor/themes/editor_theme_manager.h"
#include "scene/2d/audio_stream_player_2d.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/polygon_2d.h"
#include "scene/2d/skeleton_2d.h" #include "scene/2d/skeleton_2d.h"
#include "scene/2d/sprite_2d.h" #include "scene/2d/sprite_2d.h"
#include "scene/2d/touch_screen_button.h"
#include "scene/gui/base_button.h" #include "scene/gui/base_button.h"
#include "scene/gui/flow_container.h" #include "scene/gui/flow_container.h"
#include "scene/gui/grid_container.h" #include "scene/gui/grid_container.h"

View file

@ -32,7 +32,7 @@
#include "editor/plugins/node_3d_editor_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/mesh_instance_3d.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" #include "scene/resources/3d/primitive_meshes.h"
bool MeshInstance3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { bool MeshInstance3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {

View file

@ -32,8 +32,8 @@
#include "editor/editor_settings.h" #include "editor/editor_settings.h"
#include "editor/plugins/gizmos/joint_3d_gizmo_plugin.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_3d.h"
#include "scene/3d/physics/physical_bone_simulator_3d.h"
PhysicalBone3DGizmoPlugin::PhysicalBone3DGizmoPlugin() { PhysicalBone3DGizmoPlugin::PhysicalBone3DGizmoPlugin() {
create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint")); create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));

View file

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

View file

@ -41,9 +41,9 @@
#include "editor/plugins/node_3d_editor_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h"
#include "editor/themes/editor_scale.h" #include "editor/themes/editor_scale.h"
#include "scene/3d/mesh_instance_3d.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/collision_shape_3d.h"
#include "scene/3d/physics/physical_bone_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/separator.h"
#include "scene/gui/texture_rect.h" #include "scene/gui/texture_rect.h"
#include "scene/resources/3d/capsule_shape_3d.h" #include "scene/resources/3d/capsule_shape_3d.h"

View file

@ -63,7 +63,14 @@
#include "scene/theme/theme_db.h" #include "scene/theme/theme_db.h"
#include "servers/display_server.h" #include "servers/display_server.h"
#include "servers/navigation_server_3d.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" #include "servers/physics_server_2d.h"
#endif // PHYSICS_2D_DISABLED
constexpr int GODOT4_CONFIG_VERSION = 5; constexpr int GODOT4_CONFIG_VERSION = 5;

View file

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

View file

@ -38,12 +38,13 @@
#include "servers/navigation_server_3d.h" #include "servers/navigation_server_3d.h"
#include "servers/rendering_server.h" #include "servers/rendering_server.h"
// 2D #ifndef PHYSICS_2D_DISABLED
#include "servers/physics_server_2d.h" #include "servers/physics_server_2d.h"
#endif // PHYSICS_2D_DISABLED
#ifndef _3D_DISABLED #ifndef PHYSICS_3D_DISABLED
#include "servers/physics_server_3d.h" #include "servers/physics_server_3d.h"
#endif // _3D_DISABLED #endif // PHYSICS_3D_DISABLED
Performance *Performance::singleton = nullptr; 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); return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_DRAW);
case PIPELINE_COMPILATIONS_SPECIALIZATION: case PIPELINE_COMPILATIONS_SPECIALIZATION:
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_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: case PHYSICS_2D_ACTIVE_OBJECTS:
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS); return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS);
case PHYSICS_2D_COLLISION_PAIRS: case PHYSICS_2D_COLLISION_PAIRS:
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS); return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS);
case PHYSICS_2D_ISLAND_COUNT: case PHYSICS_2D_ISLAND_COUNT:
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT); return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT);
#ifdef _3D_DISABLED
case PHYSICS_3D_ACTIVE_OBJECTS:
return 0;
case PHYSICS_3D_COLLISION_PAIRS:
return 0;
case PHYSICS_3D_ISLAND_COUNT:
return 0;
#else #else
case PHYSICS_2D_ACTIVE_OBJECTS:
return 0;
case PHYSICS_2D_COLLISION_PAIRS:
return 0;
case PHYSICS_2D_ISLAND_COUNT:
return 0;
#endif // PHYSICS_2D_DISABLED
#ifndef PHYSICS_3D_DISABLED
case PHYSICS_3D_ACTIVE_OBJECTS: case PHYSICS_3D_ACTIVE_OBJECTS:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS); return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS);
case PHYSICS_3D_COLLISION_PAIRS: case PHYSICS_3D_COLLISION_PAIRS:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS); return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS);
case PHYSICS_3D_ISLAND_COUNT: case PHYSICS_3D_ISLAND_COUNT:
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_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: case AUDIO_OUTPUT_LATENCY:
return AudioServer::get_singleton()->get_output_latency(); return AudioServer::get_singleton()->get_output_latency();

View file

@ -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(); 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(); Array meshes = csgshape3d->get_meshes();
if (!meshes.is_empty()) { if (!meshes.is_empty()) {
Ref<Mesh> mesh = meshes[1]; 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) { void CSGShape3D::set_use_collision(bool p_enable) {
if (use_collision == p_enable) { if (use_collision == p_enable) {
return; return;
@ -186,6 +191,7 @@ void CSGShape3D::set_collision_priority(real_t p_priority) {
real_t CSGShape3D::get_collision_priority() const { real_t CSGShape3D::get_collision_priority() const {
return collision_priority; return collision_priority;
} }
#endif // PHYSICS_3D_DISABLED
bool CSGShape3D::is_root_shape() const { bool CSGShape3D::is_root_shape() const {
return !parent_shape; return !parent_shape;
@ -207,15 +213,20 @@ float CSGShape3D::get_snap() const {
#endif // DISABLE_DEPRECATED #endif // DISABLE_DEPRECATED
void CSGShape3D::_make_dirty(bool p_parent_removing) { void CSGShape3D::_make_dirty(bool p_parent_removing) {
#ifndef PHYSICS_3D_DISABLED
if ((p_parent_removing || is_root_shape()) && !dirty) { 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. 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()) { if (!is_root_shape()) {
parent_shape->_make_dirty(); parent_shape->_make_dirty();
} else if (!dirty) { }
#ifndef PHYSICS_3D_DISABLED
else if (!dirty) {
callable_mp(this, &CSGShape3D::update_shape).call_deferred(); callable_mp(this, &CSGShape3D::update_shape).call_deferred();
} }
#endif // PHYSICS_3D_DISABLED
dirty = true; dirty = true;
} }
@ -711,9 +722,20 @@ void CSGShape3D::update_shape() {
set_base(root_mesh->get_rid()); set_base(root_mesh->get_rid());
#ifndef PHYSICS_3D_DISABLED
_update_collision_faces(); _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> CSGShape3D::_get_brush_collision_faces() {
Vector<Vector3> collision_faces; Vector<Vector3> collision_faces;
CSGBrush *n = _get_brush(); 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> CSGShape3D::bake_collision_shape() {
Ref<ConcavePolygonShape3D> baked_collision_shape; Ref<ConcavePolygonShape3D> baked_collision_shape;
if (is_root_shape() && root_collision_shape.is_valid()) { 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); RS::get_singleton()->instance_set_transform(root_collision_debug_instance, debug_shape_old_transform);
} }
} }
#endif // PHYSICS_3D_DISABLED
AABB CSGShape3D::get_aabb() const { AABB CSGShape3D::get_aabb() const {
return node_aabb; return node_aabb;
@ -872,6 +887,7 @@ void CSGShape3D::_notification(int p_what) {
} }
} break; } break;
#ifndef PHYSICS_3D_DISABLED
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
if (use_collision && is_root_shape()) { if (use_collision && is_root_shape()) {
root_collision_shape.instantiate(); root_collision_shape.instantiate();
@ -904,6 +920,7 @@ void CSGShape3D::_notification(int p_what) {
} }
_on_transform_changed(); _on_transform_changed();
} break; } break;
#endif // PHYSICS_3D_DISABLED
} }
} }
@ -980,6 +997,7 @@ void CSGShape3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_snap"), &CSGShape3D::get_snap); ClassDB::bind_method(D_METHOD("get_snap"), &CSGShape3D::get_snap);
#endif // DISABLE_DEPRECATED #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("set_use_collision", "operation"), &CSGShape3D::set_use_collision);
ClassDB::bind_method(D_METHOD("is_using_collision"), &CSGShape3D::is_using_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("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("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("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("is_calculating_tangents"), &CSGShape3D::is_calculating_tangents);
ClassDB::bind_method(D_METHOD("get_meshes"), &CSGShape3D::get_meshes); 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_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"); ADD_PROPERTY(PropertyInfo(Variant::INT, "operation", PROPERTY_HINT_ENUM, "Union,Intersection,Subtraction"), "set_operation", "get_operation");
#ifndef DISABLE_DEPRECATED #ifndef DISABLE_DEPRECATED
@ -1014,11 +1034,13 @@ void CSGShape3D::_bind_methods() {
#endif // DISABLE_DEPRECATED #endif // DISABLE_DEPRECATED
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "calculate_tangents"), "set_calculate_tangents", "is_calculating_tangents"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "calculate_tangents"), "set_calculate_tangents", "is_calculating_tangents");
#ifndef PHYSICS_3D_DISABLED
ADD_GROUP("Collision", "collision_"); ADD_GROUP("Collision", "collision_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_collision"), "set_use_collision", "is_using_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_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::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"); 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_UNION);
BIND_ENUM_CONSTANT(OPERATION_INTERSECTION); BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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)); 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) { void GridMap::set_collision_layer(uint32_t p_layer) {
collision_layer = p_layer; collision_layer = p_layer;
_update_physics_bodies_collision_properties(); _update_physics_bodies_collision_properties();
@ -235,6 +236,7 @@ Array GridMap::get_collision_shapes() const {
return shapes; return shapes;
} }
#endif // PHYSICS_3D_DISABLED
void GridMap::set_bake_navigation(bool p_bake_navigation) { void GridMap::set_bake_navigation(bool p_bake_navigation) {
bake_navigation = 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 //create octant because it does not exist
Octant *g = memnew(Octant); Octant *g = memnew(Octant);
g->dirty = true; g->dirty = true;
#ifndef PHYSICS_3D_DISABLED
g->static_body = PhysicsServer3D::get_singleton()->body_create(); 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_set_mode(g->static_body, PhysicsServer3D::BODY_MODE_STATIC);
PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id()); 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_FRICTION, physics_material->computed_friction());
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce()); 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(); SceneTree *st = SceneTree::get_singleton();
if (st && st->is_debugging_collisions_hint()) { 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) { void GridMap::_octant_transform(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key)); ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[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_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform());
if (g.collision_debug_instance.is_valid()) { if (g.collision_debug_instance.is_valid()) {
RS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform()); 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 // update transform for NavigationServer regions and navigation debugmesh instances
for (const KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) { 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; return false;
} }
#ifndef PHYSICS_3D_DISABLED
//erase body shapes //erase body shapes
PhysicsServer3D::get_singleton()->body_clear_shapes(g.static_body); 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()) { if (g.collision_debug.is_valid()) {
RS::get_singleton()->mesh_clear(g.collision_debug); RS::get_singleton()->mesh_clear(g.collision_debug);
} }
#endif // PHYSICS_3D_DISABLED
//erase navigation //erase navigation
for (KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) { 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); Vector<MeshLibrary::ShapeData> shapes = mesh_library->get_item_shapes(c.item);
// add the item's shape at given xform to octant's static_body // add the item's shape at given xform to octant's static_body
for (int i = 0; i < shapes.size(); i++) { 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); 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 // 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); 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()) { if (col_debug.size()) {
Array arr; Array arr;
arr.resize(RS::ARRAY_MAX); 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()); 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; g.dirty = false;
return false; return false;
} }
#ifndef PHYSICS_3D_DISABLED
void GridMap::_update_physics_bodies_collision_properties() { void GridMap::_update_physics_bodies_collision_properties() {
for (const KeyValue<OctantKey, Octant *> &E : octant_map) { for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
PhysicsServer3D::get_singleton()->body_set_collision_layer(E.value->static_body, collision_layer); 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); 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) { void GridMap::_octant_enter_world(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key)); ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[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_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()); 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_scenario(g.collision_debug_instance, get_world_3d()->get_scenario());
RS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform()); 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++) { 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()); 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) { void GridMap::_octant_exit_world(const OctantKey &p_key) {
ERR_FAIL_NULL(RenderingServer::get_singleton()); ERR_FAIL_NULL(RenderingServer::get_singleton());
#ifndef PHYSICS_3D_DISABLED
ERR_FAIL_NULL(PhysicsServer3D::get_singleton()); ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
#endif // PHYSICS_3D_DISABLED
ERR_FAIL_NULL(NavigationServer3D::get_singleton()); ERR_FAIL_NULL(NavigationServer3D::get_singleton());
ERR_FAIL_COND(!octant_map.has(p_key)); ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[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_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform());
PhysicsServer3D::get_singleton()->body_set_space(g.static_body, RID()); PhysicsServer3D::get_singleton()->body_set_space(g.static_body, RID());
if (g.collision_debug_instance.is_valid()) { if (g.collision_debug_instance.is_valid()) {
RS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID()); 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++) { for (int i = 0; i < g.multimesh_instances.size(); i++) {
RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID()); 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) { void GridMap::_octant_clean_up(const OctantKey &p_key) {
ERR_FAIL_NULL(RenderingServer::get_singleton()); ERR_FAIL_NULL(RenderingServer::get_singleton());
#ifndef PHYSICS_3D_DISABLED
ERR_FAIL_NULL(PhysicsServer3D::get_singleton()); ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
#endif // PHYSICS_3D_DISABLED
ERR_FAIL_NULL(NavigationServer3D::get_singleton()); ERR_FAIL_NULL(NavigationServer3D::get_singleton());
ERR_FAIL_COND(!octant_map.has(p_key)); ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[p_key]; Octant &g = *octant_map[p_key];
#ifndef PHYSICS_3D_DISABLED
if (g.collision_debug.is_valid()) { if (g.collision_debug.is_valid()) {
RS::get_singleton()->free(g.collision_debug); 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); PhysicsServer3D::get_singleton()->free(g.static_body);
#endif // PHYSICS_3D_DISABLED
// Erase navigation // Erase navigation
for (const KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) { for (const KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) {
@ -1061,6 +1086,7 @@ void GridMap::_update_octants_callback() {
} }
void GridMap::_bind_methods() { 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("set_collision_layer", "layer"), &GridMap::set_collision_layer);
ClassDB::bind_method(D_METHOD("get_collision_layer"), &GridMap::get_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("set_physics_material", "material"), &GridMap::set_physics_material);
ClassDB::bind_method(D_METHOD("get_physics_material"), &GridMap::get_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("set_bake_navigation", "bake_navigation"), &GridMap::set_bake_navigation);
ClassDB::bind_method(D_METHOD("is_baking_navigation"), &GridMap::is_baking_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_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::BOOL, "cell_center_z"), "set_center_z", "get_center_z");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_scale"), "set_cell_scale", "get_cell_scale"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_scale"), "set_cell_scale", "get_cell_scale");
#ifndef PHYSICS_3D_DISABLED
ADD_GROUP("Collision", "collision_"); 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_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::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"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_priority"), "set_collision_priority", "get_collision_priority");
#endif // PHYSICS_3D_DISABLED
ADD_GROUP("Navigation", ""); ADD_GROUP("Navigation", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_navigation"), "set_bake_navigation", "is_baking_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(); 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(); 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) { if (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH) {
Array meshes = gridmap->get_meshes(); 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)) { 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(); Array shapes = gridmap->get_collision_shapes();
for (int i = 0; i < shapes.size(); i += 2) { 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 #ifdef DEBUG_ENABLED

View file

@ -39,7 +39,9 @@
class NavigationMesh; class NavigationMesh;
class NavigationMeshSourceGeometryData3D; class NavigationMeshSourceGeometryData3D;
#ifndef PHYSICS_3D_DISABLED
class PhysicsMaterial; class PhysicsMaterial;
#endif // PHYSICS_3D_DISABLED
class GridMap : public Node3D { class GridMap : public Node3D {
GDCLASS(GridMap, Node3D); GDCLASS(GridMap, Node3D);
@ -150,10 +152,12 @@ class GridMap : public Node3D {
OctantKey() {} OctantKey() {}
}; };
#ifndef PHYSICS_3D_DISABLED
uint32_t collision_layer = 1; uint32_t collision_layer = 1;
uint32_t collision_mask = 1; uint32_t collision_mask = 1;
real_t collision_priority = 1.0; real_t collision_priority = 1.0;
Ref<PhysicsMaterial> physics_material; Ref<PhysicsMaterial> physics_material;
#endif // PHYSICS_3D_DISABLED
bool bake_navigation = false; bool bake_navigation = false;
RID map_override; 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; 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_collision_properties();
void _update_physics_bodies_characteristics(); void _update_physics_bodies_characteristics();
#endif // PHYSICS_3D_DISABLED
void _octant_enter_world(const OctantKey &p_key); void _octant_enter_world(const OctantKey &p_key);
void _octant_exit_world(const OctantKey &p_key); void _octant_exit_world(const OctantKey &p_key);
bool _octant_update(const OctantKey &p_key); bool _octant_update(const OctantKey &p_key);
@ -233,6 +239,7 @@ public:
INVALID_CELL_ITEM = -1 INVALID_CELL_ITEM = -1
}; };
#ifndef PHYSICS_3D_DISABLED
void set_collision_layer(uint32_t p_layer); void set_collision_layer(uint32_t p_layer);
uint32_t get_collision_layer() const; uint32_t get_collision_layer() const;
@ -252,6 +259,7 @@ public:
Ref<PhysicsMaterial> get_physics_material() const; Ref<PhysicsMaterial> get_physics_material() const;
Array get_collision_shapes() const; Array get_collision_shapes() const;
#endif // PHYSICS_3D_DISABLED
void set_bake_navigation(bool p_bake_navigation); void set_bake_navigation(bool p_bake_navigation);
bool is_baking_navigation(); bool is_baking_navigation();

View file

@ -1,5 +1,5 @@
def can_build(env, platform): 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): def configure(env):

View file

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

View file

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

View file

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

View file

@ -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); 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) { Vector2i TileMap::get_coords_for_body_rid(RID p_physics_body) {
for (const TileMapLayer *layer : layers) { for (const TileMapLayer *layer : layers) {
if (layer->has_body_rid(p_physics_body)) { 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())); 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() { void TileMap::fix_invalid_tiles() {
for (TileMapLayer *layer : layers) { 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_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)); 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_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); 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("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); ClassDB::bind_method(D_METHOD("map_pattern", "position_in_tilemap", "coords_in_pattern", "pattern"), &TileMap::map_pattern);

View file

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

View file

@ -39,6 +39,10 @@
#include "scene/resources/world_2d.h" #include "scene/resources/world_2d.h"
#include "servers/navigation_server_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; Callable TileMapLayer::_navmesh_source_geometry_parsing_callback;
RID TileMapLayer::_navmesh_source_geometry_parser; 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) { for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
CellData &cell_data = kv.value; CellData &cell_data = kv.value;
quadrants_to_updates.insert(_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE)); 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. // Physics quadrants are drawn from their origin.
Vector2i physics_quadrant_origin = _coords_to_quadrant_coords(cell_data.coords, physics_quadrant_size) * physics_quadrant_size; 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)); quadrants_to_updates.insert(_coords_to_quadrant_coords(physics_quadrant_origin, TILE_MAP_DEBUG_QUADRANT_SIZE));
#endif // PHYSICS_2D_DISABLED
} }
} else { } else {
// Update dirty cells. // 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()) { 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(); CellData &cell_data = *cell_data_list_element->self();
quadrants_to_updates.insert(_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE)); 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. // Physics quadrants are drawn from their origin.
Vector2i physics_quadrant_origin = _coords_to_quadrant_coords(cell_data.coords, physics_quadrant_size) * physics_quadrant_size; 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)); 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); Transform2D xform(0, quadrant_pos);
rs->canvas_item_set_transform(ci, xform); rs->canvas_item_set_transform(ci, xform);
#ifndef PHYSICS_2D_DISABLED
// Draw physics. // Draw physics.
_physics_draw_quadrant_debug(ci, *debug_quadrant.ptr()); _physics_draw_quadrant_debug(ci, *debug_quadrant.ptr());
#endif // PHYSICS_2D_DISABLED
// Draw debug info. // 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()) { for (SelfList<CellData> *cell_data_list_element = debug_quadrant->cells.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
@ -680,6 +690,7 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve
/////////////////////////////// Physics ////////////////////////////////////// /////////////////////////////// Physics //////////////////////////////////////
#ifndef PHYSICS_2D_DISABLED
void TileMapLayer::_physics_update(bool p_force_cleanup) { void TileMapLayer::_physics_update(bool p_force_cleanup) {
PhysicsServer2D *ps = PhysicsServer2D::get_singleton(); PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
@ -1130,6 +1141,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()); rs->canvas_item_add_mesh(p_canvas_item, r_debug_quadrant.physics_mesh, Transform2D());
} }
#endif // DEBUG_ENABLED #endif // DEBUG_ENABLED
#endif // PHYSICS_2D_DISABLED
/////////////////////////////// Navigation ////////////////////////////////////// /////////////////////////////// Navigation //////////////////////////////////////
@ -1877,7 +1889,9 @@ void TileMapLayer::_internal_update(bool p_force_cleanup) {
// Update all subsystems. // Update all subsystems.
_rendering_update(p_force_cleanup); _rendering_update(p_force_cleanup);
#ifndef PHYSICS_2D_DISABLED
_physics_update(p_force_cleanup); _physics_update(p_force_cleanup);
#endif // PHYSICS_2D_DISABLED
_navigation_update(p_force_cleanup); _navigation_update(p_force_cleanup);
_scenes_update(p_force_cleanup); _scenes_update(p_force_cleanup);
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
@ -1979,7 +1993,9 @@ void TileMapLayer::_notification(int p_what) {
} }
_rendering_notification(p_what); _rendering_notification(p_what);
#ifndef PHYSICS_2D_DISABLED
_physics_notification(p_what); _physics_notification(p_what);
#endif // PHYSICS_2D_DISABLED
_navigation_notification(p_what); _navigation_notification(p_what);
} }
@ -2012,9 +2028,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_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)); 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 --- // --- Physics helpers ---
ClassDB::bind_method(D_METHOD("has_body_rid", "body"), &TileMapLayer::has_body_rid); 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); ClassDB::bind_method(D_METHOD("get_coords_for_body_rid", "body"), &TileMapLayer::get_coords_for_body_rid);
#endif // PHYSICS_2D_DISABLED
// --- Runtime --- // --- Runtime ---
ClassDB::bind_method(D_METHOD("update_internals"), &TileMapLayer::update_internals); ClassDB::bind_method(D_METHOD("update_internals"), &TileMapLayer::update_internals);
@ -2879,6 +2897,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 { bool TileMapLayer::has_body_rid(RID p_physics_body) const {
return bodies_coords.has(p_physics_body); return bodies_coords.has(p_physics_body);
} }
@ -2888,6 +2907,7 @@ Vector2i TileMapLayer::get_coords_for_body_rid(RID p_physics_body) const {
ERR_FAIL_NULL_V(found, Vector2i()); ERR_FAIL_NULL_V(found, Vector2i());
return *found; return *found;
} }
#endif // PHYSICS_2D_DISABLED
void TileMapLayer::update_internals() { void TileMapLayer::update_internals() {
_internal_update(false); _internal_update(false);
@ -3288,14 +3308,17 @@ void TileMapLayer::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
return; return;
} }
int physics_layers_count = tile_set->get_physics_layers_count();
int navigation_layers_count = tile_set->get_navigation_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) { if (physics_layers_count <= 0 && navigation_layers_count <= 0) {
return; return;
} }
#else
NavigationPolygon::ParsedGeometryType parsed_geometry_type = p_navigation_mesh->get_parsed_geometry_type(); if (navigation_layers_count <= 0) {
uint32_t parsed_collision_mask = p_navigation_mesh->get_parsed_collision_mask(); return;
}
#endif // PHYSICS_2D_DISABLED
const Transform2D tilemap_xform = p_source_geometry_data->root_node_transform * tile_map_layer->get_global_transform(); const Transform2D tilemap_xform = p_source_geometry_data->root_node_transform * tile_map_layer->get_global_transform();
@ -3344,6 +3367,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. // Parse obstacles.
for (int physics_layer = 0; physics_layer < physics_layers_count; physics_layer++) { 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) && if ((parsed_geometry_type == NavigationPolygon::PARSED_GEOMETRY_STATIC_COLLIDERS || parsed_geometry_type == NavigationPolygon::PARSED_GEOMETRY_BOTH) &&
@ -3372,6 +3399,7 @@ void TileMapLayer::navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p
} }
} }
} }
#endif // PHYSICS_2D_DISABLED
} }
} }

View file

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

View file

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

View file

@ -34,12 +34,15 @@
#include "core/config/project_settings.h" #include "core/config/project_settings.h"
#include "scene/3d/audio_listener_3d.h" #include "scene/3d/audio_listener_3d.h"
#include "scene/3d/camera_3d.h" #include "scene/3d/camera_3d.h"
#include "scene/3d/physics/area_3d.h"
#include "scene/3d/velocity_tracker_3d.h" #include "scene/3d/velocity_tracker_3d.h"
#include "scene/audio/audio_stream_player_internal.h" #include "scene/audio/audio_stream_player_internal.h"
#include "scene/main/viewport.h" #include "scene/main/viewport.h"
#include "servers/audio/audio_stream.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) // 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) // Speaker-Placement Correction Amplitude Panning (SPCAP)
class 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) { 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.resize(4);
reverb_vol.write[0] = AudioFrame(0, 0); 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 AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
float att = 0; 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 // Interacts with PhysicsServer3D, so can only be called during _physics_process
Area3D *AudioStreamPlayer3D::_get_overriding_area() { Area3D *AudioStreamPlayer3D::_get_overriding_area() {
//check if any area is diverting sound into a bus //check if any area is diverting sound into a bus
@ -321,13 +327,16 @@ Area3D *AudioStreamPlayer3D::_get_overriding_area() {
} }
return nullptr; return nullptr;
} }
#endif // PHYSICS_3D_DISABLED
// Interacts with PhysicsServer3D, so can only be called during _physics_process. // Interacts with PhysicsServer3D, so can only be called during _physics_process.
StringName AudioStreamPlayer3D::_get_actual_bus() { StringName AudioStreamPlayer3D::_get_actual_bus() {
#ifndef PHYSICS_3D_DISABLED
Area3D *overriding_area = _get_overriding_area(); Area3D *overriding_area = _get_overriding_area();
if (overriding_area && overriding_area->is_overriding_audio_bus() && !overriding_area->is_using_reverb_bus()) { if (overriding_area && overriding_area->is_overriding_audio_bus() && !overriding_area->is_using_reverb_bus()) {
return overriding_area->get_audio_bus_name(); return overriding_area->get_audio_bus_name();
} }
#endif // PHYSICS_3D_DISABLED
return internal->bus; return internal->bus;
} }
@ -358,7 +367,9 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
HashSet<Camera3D *> cameras = world_3d->get_cameras(); HashSet<Camera3D *> cameras = world_3d->get_cameras();
cameras.insert(get_viewport()->get_camera_3d()); 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()); PhysicsDirectSpaceState3D *space_state = PhysicsServer3D::get_singleton()->space_get_direct_state(world_3d->get_space());
#endif // PHYSICS_3D_DISABLED
for (Camera3D *camera : cameras) { for (Camera3D *camera : cameras) {
if (!camera) { if (!camera) {
@ -388,19 +399,22 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
Vector3 area_sound_pos; Vector3 area_sound_pos;
Vector3 listener_area_pos; Vector3 listener_area_pos;
#ifndef PHYSICS_3D_DISABLED
Area3D *area = _get_overriding_area(); Area3D *area = _get_overriding_area();
if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) { 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); 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); listener_area_pos = listener_node->get_global_transform().affine_inverse().xform(area_sound_pos);
} }
#endif // PHYSICS_3D_DISABLED
if (max_distance > 0) { if (max_distance > 0) {
float total_max = max_distance; float total_max = max_distance;
#ifndef PHYSICS_3D_DISABLED
if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) { if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) {
total_max = MAX(total_max, listener_area_pos.length()); total_max = MAX(total_max, listener_area_pos.length());
} }
#endif // PHYSICS_3D_DISABLED
if (dist > total_max || total_max > max_distance) { if (dist > total_max || total_max > max_distance) {
if (!was_further_than_max_distance_last_frame) { if (!was_further_than_max_distance_last_frame) {
HashMap<StringName, Vector<AudioFrame>> bus_volumes; HashMap<StringName, Vector<AudioFrame>> bus_volumes;
@ -445,6 +459,7 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
} }
HashMap<StringName, Vector<AudioFrame>> bus_volumes; HashMap<StringName, Vector<AudioFrame>> bus_volumes;
#ifndef PHYSICS_3D_DISABLED
if (area) { if (area) {
if (area->is_overriding_audio_bus()) { if (area->is_overriding_audio_bus()) {
//override 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); _calc_reverb_vol(area, listener_area_pos, output_volume_vector, reverb_vol);
bus_volumes[reverb_bus_name] = reverb_vol; bus_volumes[reverb_bus_name] = reverb_vol;
} }
} else { } else
#endif // PHYSICS_3D_DISABLED
{
bus_volumes[internal->bus] = output_volume_vector; bus_volumes[internal->bus] = output_volume_vector;
} }

View file

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

View file

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

View file

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

View file

@ -30,16 +30,18 @@
#include "mesh_instance_3d.h" #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/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/3d/navigation_mesh_source_geometry_data_3d.h"
#include "scene/resources/navigation_mesh.h" #include "scene/resources/navigation_mesh.h"
#include "servers/navigation_server_3d.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; Callable MeshInstance3D::_navmesh_source_geometry_parsing_callback;
RID MeshInstance3D::_navmesh_source_geometry_parser; RID MeshInstance3D::_navmesh_source_geometry_parser;
@ -230,6 +232,7 @@ AABB MeshInstance3D::get_aabb() const {
return AABB(); return AABB();
} }
#ifndef PHYSICS_3D_DISABLED
Node *MeshInstance3D::create_trimesh_collision_node() { Node *MeshInstance3D::create_trimesh_collision_node() {
if (mesh.is_null()) { if (mesh.is_null()) {
return nullptr; 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) { void MeshInstance3D::_notification(int p_what) {
switch (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_surface_override_material", "surface"), &MeshInstance3D::get_surface_override_material);
ClassDB::bind_method(D_METHOD("get_active_material", "surface"), &MeshInstance3D::get_active_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::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance3D::create_trimesh_collision);
ClassDB::set_method_flags("MeshInstance3D", "create_trimesh_collision", METHOD_FLAGS_DEFAULT); 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::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::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::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); 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("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); ClassDB::bind_method(D_METHOD("find_blend_shape_by_name", "name"), &MeshInstance3D::find_blend_shape_by_name);

View file

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

View file

@ -30,7 +30,7 @@
#include "physical_bone_3d.h" #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 #ifndef DISABLE_DEPRECATED
#include "scene/3d/skeleton_3d.h" #include "scene/3d/skeleton_3d.h"
#endif //_DISABLE_DEPRECATED #endif //_DISABLE_DEPRECATED

View file

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

View file

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

View file

@ -36,16 +36,6 @@
#include "core/math/math_fieldwise.h" #include "core/math/math_fieldwise.h"
#include "core/object/script_language.h" #include "core/object/script_language.h"
#include "core/templates/local_vector.h" #include "core/templates/local_vector.h"
#include "scene/2d/physics/collision_object_2d.h"
#include "scene/2d/physics/collision_polygon_2d.h"
#include "scene/2d/physics/collision_shape_2d.h"
#ifndef _3D_DISABLED
#include "scene/3d/physics/collision_object_3d.h"
#include "scene/3d/physics/collision_shape_3d.h"
#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/gui/popup_menu.h"
#include "scene/main/canvas_layer.h" #include "scene/main/canvas_layer.h"
#include "scene/main/scene_tree.h" #include "scene/main/scene_tree.h"
@ -54,6 +44,23 @@
#include "scene/theme/theme_db.h" #include "scene/theme/theme_db.h"
#include "servers/audio_server.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
SceneDebugger::SceneDebugger() { SceneDebugger::SceneDebugger() {
singleton = this; singleton = this;
@ -1924,6 +1931,7 @@ void RuntimeNodeSelect::_update_selection() {
if (ci->_edit_use_rect()) { if (ci->_edit_use_rect()) {
rect = ci->_edit_get_rect(); rect = ci->_edit_get_rect();
} else { } else {
#ifndef PHYSICS_2D_DISABLED
CollisionShape2D *collision_shape = Object::cast_to<CollisionShape2D>(ci); CollisionShape2D *collision_shape = Object::cast_to<CollisionShape2D>(ci);
if (collision_shape) { if (collision_shape) {
Ref<Shape2D> shape = collision_shape->get_shape(); Ref<Shape2D> shape = collision_shape->get_shape();
@ -1931,6 +1939,7 @@ void RuntimeNodeSelect::_update_selection() {
rect = shape->get_rect(); rect = shape->get_rect();
} }
} }
#endif // PHYSICS_2D_DISABLED
} }
const Vector2 endpoints[4] = { const Vector2 endpoints[4] = {
@ -1963,6 +1972,7 @@ void RuntimeNodeSelect::_update_selection() {
if (visual_instance) { if (visual_instance) {
bounds = visual_instance->get_aabb(); bounds = visual_instance->get_aabb();
} else { } else {
#ifndef PHYSICS_2D_DISABLED
CollisionShape3D *collision_shape = Object::cast_to<CollisionShape3D>(node_3d); CollisionShape3D *collision_shape = Object::cast_to<CollisionShape3D>(node_3d);
if (collision_shape) { if (collision_shape) {
Ref<Shape3D> shape = collision_shape->get_shape(); Ref<Shape3D> shape = collision_shape->get_shape();
@ -1970,6 +1980,7 @@ void RuntimeNodeSelect::_update_selection() {
bounds = shape->get_debug_mesh()->get_aabb(); 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(); Transform3D xform_to_top_level_parent_space = node_3d->get_global_transform().affine_inverse() * node_3d->get_global_transform();
@ -2165,6 +2176,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(); res.order = ci->get_effective_z_index() + ci->get_canvas_layer();
r_items.push_back(res); r_items.push_back(res);
#ifndef PHYSICS_2D_DISABLED
// If it's a shape, get the collision object it's from. // 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. // 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)) { if (Object::cast_to<CollisionShape2D>(ci) || Object::cast_to<CollisionPolygon2D>(ci)) {
@ -2176,6 +2188,7 @@ void RuntimeNodeSelect::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_n
r_items.push_back(res_col); r_items.push_back(res_col);
} }
} }
#endif // PHYSICS_2D_DISABLED
} }
} }
@ -2307,6 +2320,7 @@ void RuntimeNodeSelect::_find_3d_items_at_pos(const Point2 &p_pos, Vector<Select
to = pos + ray * camera->get_far(); to = pos + ray * camera->get_far();
} }
#ifndef PHYSICS_3D_DISABLED
// Start with physical objects. // Start with physical objects.
PhysicsDirectSpaceState3D *ss = root->get_world_3d()->get_direct_space_state(); PhysicsDirectSpaceState3D *ss = root->get_world_3d()->get_direct_space_state();
PhysicsDirectSpaceState3D::RayResult result; PhysicsDirectSpaceState3D::RayResult result;
@ -2342,6 +2356,7 @@ void RuntimeNodeSelect::_find_3d_items_at_pos(const Point2 &p_pos, Vector<Select
break; break;
} }
} }
#endif // PHYSICS_3D_DISABLED
// Then go for the meshes. // Then go for the meshes.
Vector<ObjectID> items = RS::get_singleton()->instances_cull_ray(pos, to, root->get_world_3d()->get_scenario()); Vector<ObjectID> items = RS::get_singleton()->instances_cull_ray(pos, to, root->get_world_3d()->get_scenario());
@ -2445,6 +2460,7 @@ void RuntimeNodeSelect::_find_3d_items_at_rect(const Rect2 &p_rect, Vector<Selec
far_plane.d += zfar; far_plane.d += zfar;
frustum.push_back(far_plane); frustum.push_back(far_plane);
#ifndef PHYSICS_3D_DISABLED
Vector<Vector3> points = Geometry3D::compute_convex_mesh_points(&frustum[0], frustum.size()); Vector<Vector3> points = Geometry3D::compute_convex_mesh_points(&frustum[0], frustum.size());
Ref<ConvexPolygonShape3D> shape; Ref<ConvexPolygonShape3D> shape;
shape.instantiate(); shape.instantiate();
@ -2476,6 +2492,7 @@ void RuntimeNodeSelect::_find_3d_items_at_rect(const Rect2 &p_rect, Vector<Selec
r_items.push_back(res); r_items.push_back(res);
} }
#endif // PHYSICS_3D_DISABLED
// Then go for the meshes. // Then go for the meshes.
Vector<ObjectID> items = RS::get_singleton()->instances_cull_convex(frustum, root->get_world_3d()->get_scenario()); Vector<ObjectID> items = RS::get_singleton()->instances_cull_convex(frustum, root->get_world_3d()->get_scenario());

View file

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

View file

@ -36,13 +36,6 @@
#include "core/templates/sort_array.h" #include "core/templates/sort_array.h"
#include "scene/2d/audio_listener_2d.h" #include "scene/2d/audio_listener_2d.h"
#include "scene/2d/camera_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/control.h"
#include "scene/gui/label.h" #include "scene/gui/label.h"
#include "scene/gui/popup.h" #include "scene/gui/popup.h"
@ -56,6 +49,20 @@
#include "servers/audio_server.h" #include "servers/audio_server.h"
#include "servers/rendering/rendering_server_globals.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() { void ViewportTexture::setup_local_to_scene() {
// For the same target viewport, setup is only allowed once to prevent multiple free or multiple creations. // For the same target viewport, setup is only allowed once to prevent multiple free or multiple creations.
if (!vp_changed) { if (!vp_changed) {
@ -545,11 +552,14 @@ void Viewport::_notification(int p_what) {
#endif // _3D_DISABLED #endif // _3D_DISABLED
add_to_group("_viewports"); add_to_group("_viewports");
#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
if (get_tree()->is_debugging_collisions_hint()) { 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()); 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(); contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create();
RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, current_canvas); 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()); 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(); 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); 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_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_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); 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); set_physics_process_internal(true);
} }
#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
} break; } break;
case NOTIFICATION_READY: { 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_set_scenario(viewport, RID());
RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas);
#ifndef PHYSICS_2D_DISABLED
if (contact_2d_debug.is_valid()) { if (contact_2d_debug.is_valid()) {
RenderingServer::get_singleton()->free(contact_2d_debug); RenderingServer::get_singleton()->free(contact_2d_debug);
contact_2d_debug = RID(); contact_2d_debug = RID();
} }
#endif // PHYSICS_2D_DISABLED
#ifndef PHYSICS_3D_DISABLED
if (contact_3d_debug_multimesh.is_valid()) { if (contact_3d_debug_multimesh.is_valid()) {
RenderingServer::get_singleton()->free(contact_3d_debug_multimesh); RenderingServer::get_singleton()->free(contact_3d_debug_multimesh);
RenderingServer::get_singleton()->free(contact_3d_debug_instance); RenderingServer::get_singleton()->free(contact_3d_debug_instance);
contact_3d_debug_instance = RID(); contact_3d_debug_instance = RID();
contact_3d_debug_multimesh = RID(); contact_3d_debug_multimesh = RID();
} }
#endif // PHYSICS_3D_DISABLED
remove_from_group("_viewports"); remove_from_group("_viewports");
set_physics_process_internal(false); set_physics_process_internal(false);
@ -623,11 +638,13 @@ void Viewport::_notification(int p_what) {
_update_viewport_path(); _update_viewport_path();
} break; } break;
#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!get_tree()) { if (!get_tree()) {
return; return;
} }
#ifndef PHYSICS_2D_DISABLED
if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) { 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_clear(contact_2d_debug);
RenderingServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index 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); 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()) { 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()); 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()); 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); RS::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh, i, point_transform);
} }
} }
#endif // _3D_DISABLED #endif // PHYSICS_3D_DISABLED
} break; } break;
#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
case NOTIFICATION_VP_MOUSE_ENTER: { case NOTIFICATION_VP_MOUSE_ENTER: {
gui.mouse_in_viewport = true; 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() { void Viewport::_process_picking() {
if (!is_inside_tree()) { if (!is_inside_tree()) {
return; return;
@ -718,14 +738,16 @@ void Viewport::_process_picking() {
_drop_physics_mouseover(true); _drop_physics_mouseover(true);
#ifndef _3D_DISABLED #ifndef PHYSICS_3D_DISABLED
Vector2 last_pos(1e20, 1e20); Vector2 last_pos(1e20, 1e20);
CollisionObject3D *last_object = nullptr; CollisionObject3D *last_object = nullptr;
ObjectID last_id; ObjectID last_id;
PhysicsDirectSpaceState3D::RayResult result; 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()); 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()); 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); 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(); pos = st->get_position();
} }
#ifndef PHYSICS_2D_DISABLED
if (ss2d) { if (ss2d) {
// Send to 2D. // Send to 2D.
@ -897,8 +920,9 @@ void Viewport::_process_picking() {
_cleanup_mouseover_colliders(false, false, frame); _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()) { if (physics_object_picking_first_only && is_input_handled()) {
continue; continue;
} }
@ -977,9 +1001,10 @@ void Viewport::_process_picking() {
last_pos = pos; 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 { RID Viewport::get_viewport_rid() const {
ERR_READ_THREAD_GUARD_V(RID()); ERR_READ_THREAD_GUARD_V(RID());
@ -2554,9 +2579,11 @@ void Viewport::_drop_mouse_focus() {
} }
void Viewport::_drop_physics_mouseover(bool p_paused_only) { void Viewport::_drop_physics_mouseover(bool p_paused_only) {
#ifndef PHYSICS_2D_DISABLED
_cleanup_mouseover_colliders(true, p_paused_only); _cleanup_mouseover_colliders(true, p_paused_only);
#endif // PHYSICS_2D_DISABLED
#ifndef _3D_DISABLED #ifndef PHYSICS_3D_DISABLED
if (physics_object_over.is_valid()) { if (physics_object_over.is_valid()) {
CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over)); CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over));
if (co) { if (co) {
@ -2570,7 +2597,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) { void Viewport::_gui_grab_click_focus(Control *p_control) {
@ -3343,6 +3370,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); 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 (physics_object_picking && !is_input_handled()) {
if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED && if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED &&
(Object::cast_to<InputEventMouse>(*p_event) || (Object::cast_to<InputEventMouse>(*p_event) ||
@ -3354,6 +3382,7 @@ void Viewport::_push_unhandled_input_internal(const Ref<InputEvent> &p_event) {
set_input_as_handled(); set_input_as_handled();
} }
} }
#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
} }
void Viewport::notify_mouse_entered() { void Viewport::notify_mouse_entered() {
@ -3372,6 +3401,7 @@ void Viewport::notify_mouse_exited() {
_mouse_leave_viewport(); _mouse_leave_viewport();
} }
#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
void Viewport::set_physics_object_picking(bool p_enable) { void Viewport::set_physics_object_picking(bool p_enable) {
ERR_MAIN_THREAD_GUARD; ERR_MAIN_THREAD_GUARD;
physics_object_picking = p_enable; physics_object_picking = p_enable;
@ -3407,6 +3437,7 @@ void Viewport::set_physics_object_picking_first_only(bool p_enable) {
bool Viewport::get_physics_object_picking_first_only() { bool Viewport::get_physics_object_picking_first_only() {
return 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 { Vector2 Viewport::get_camera_coords(const Vector2 &p_viewport_coords) const {
ERR_READ_THREAD_GUARD_V(Vector2()); ERR_READ_THREAD_GUARD_V(Vector2());
@ -4043,6 +4074,7 @@ void Viewport::_camera_2d_set(Camera2D *p_camera_2d) {
camera_2d = 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) { 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_erase;
List<ObjectID> to_mouse_exit; List<ObjectID> to_mouse_exit;
@ -4112,6 +4144,7 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
shapes_to_mouse_exit.pop_front(); shapes_to_mouse_exit.pop_front();
} }
} }
#endif // PHYSICS_2D_DISABLED
AudioListener2D *Viewport::get_audio_listener_2d() const { AudioListener2D *Viewport::get_audio_listener_2d() const {
ERR_READ_THREAD_GUARD_V(nullptr); ERR_READ_THREAD_GUARD_V(nullptr);
@ -4239,6 +4272,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) { 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 object_transform = p_object->get_global_transform();
Transform3D camera_transform = p_camera->get_global_transform(); Transform3D camera_transform = p_camera->get_global_transform();
@ -4256,6 +4290,7 @@ void Viewport::_collision_object_3d_input_event(CollisionObject3D *p_object, Cam
physics_last_camera_transform = camera_transform; physics_last_camera_transform = camera_transform;
physics_last_id = id; physics_last_id = id;
} }
#endif // PHYSICS_3D_DISABLED
Camera3D *Viewport::get_camera_3d() const { Camera3D *Viewport::get_camera_3d() const {
ERR_READ_THREAD_GUARD_V(nullptr); ERR_READ_THREAD_GUARD_V(nullptr);
@ -4806,12 +4841,14 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_texture"), &Viewport::get_texture); 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("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("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("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("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("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); 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("get_viewport_rid"), &Viewport::get_viewport_rid);
ClassDB::bind_method(D_METHOD("push_text_input", "text"), &Viewport::push_text_input); ClassDB::bind_method(D_METHOD("push_text_input", "text"), &Viewport::push_text_input);
@ -4889,7 +4926,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("set_mesh_lod_threshold", "pixels"), &Viewport::set_mesh_lod_threshold);
ClassDB::bind_method(D_METHOD("get_mesh_lod_threshold"), &Viewport::get_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); 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("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); ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d);
@ -4980,10 +5019,12 @@ void Viewport::_bind_methods() {
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener_3d", "is_audio_listener_3d"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener_3d", "is_audio_listener_3d");
#endif // _3D_DISABLED #endif // _3D_DISABLED
#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
ADD_GROUP("Physics", "physics_"); 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"), "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_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"); 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_GROUP("GUI", "gui_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled"); 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"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled");

View file

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

View file

@ -134,7 +134,6 @@
#include "scene/resources/navigation_mesh.h" #include "scene/resources/navigation_mesh.h"
#include "scene/resources/packed_scene.h" #include "scene/resources/packed_scene.h"
#include "scene/resources/particle_process_material.h" #include "scene/resources/particle_process_material.h"
#include "scene/resources/physics_material.h"
#include "scene/resources/placeholder_textures.h" #include "scene/resources/placeholder_textures.h"
#include "scene/resources/portable_compressed_texture.h" #include "scene/resources/portable_compressed_texture.h"
#include "scene/resources/resource_format_text.h" #include "scene/resources/resource_format_text.h"
@ -157,7 +156,6 @@
#include "scene/resources/visual_shader_nodes.h" #include "scene/resources/visual_shader_nodes.h"
#include "scene/resources/visual_shader_particle_nodes.h" #include "scene/resources/visual_shader_particle_nodes.h"
#include "scene/resources/visual_shader_sdf_nodes.h" #include "scene/resources/visual_shader_sdf_nodes.h"
#include "scene/resources/world_2d.h"
#include "scene/theme/theme_db.h" #include "scene/theme/theme_db.h"
// 2D // 2D
@ -184,51 +182,25 @@
#include "scene/2d/parallax_background.h" #include "scene/2d/parallax_background.h"
#include "scene/2d/parallax_layer.h" #include "scene/2d/parallax_layer.h"
#include "scene/2d/path_2d.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/polygon_2d.h"
#include "scene/2d/remote_transform_2d.h" #include "scene/2d/remote_transform_2d.h"
#include "scene/2d/skeleton_2d.h" #include "scene/2d/skeleton_2d.h"
#include "scene/2d/sprite_2d.h" #include "scene/2d/sprite_2d.h"
#include "scene/2d/tile_map.h" #include "scene/2d/tile_map.h"
#include "scene/2d/tile_map_layer.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/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_mesh_source_geometry_data_2d.h"
#include "scene/resources/2d/navigation_polygon.h" #include "scene/resources/2d/navigation_polygon.h"
#include "scene/resources/2d/polygon_path_finder.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.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d_ccdik.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_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_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_stackholder.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d_twoboneik.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/skeleton/skeleton_modification_stack_2d.h"
#include "scene/resources/2d/tile_set.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 #ifndef _3D_DISABLED
#include "scene/3d/audio_listener_3d.h" #include "scene/3d/audio_listener_3d.h"
@ -256,7 +228,68 @@
#include "scene/3d/node_3d.h" #include "scene/3d/node_3d.h"
#include "scene/3d/occluder_instance_3d.h" #include "scene/3d/occluder_instance_3d.h"
#include "scene/3d/path_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/animatable_body_3d.h"
#include "scene/3d/physics/area_3d.h" #include "scene/3d/physics/area_3d.h"
#include "scene/3d/physics/character_body_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/joints/slider_joint_3d.h"
#include "scene/3d/physics/kinematic_collision_3d.h" #include "scene/3d/physics/kinematic_collision_3d.h"
#include "scene/3d/physics/physical_bone_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/physics_body_3d.h"
#include "scene/3d/physics/ray_cast_3d.h" #include "scene/3d/physics/ray_cast_3d.h"
#include "scene/3d/physics/rigid_body_3d.h" #include "scene/3d/physics/rigid_body_3d.h"
#include "scene/3d/physics/shape_cast_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/spring_arm_3d.h"
#include "scene/3d/physics/static_body_3d.h" #include "scene/3d/physics/static_body_3d.h"
#include "scene/3d/physics/vehicle_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_3d.h"
#include "scene/3d/spring_bone_collision_capsule_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_plane_3d.h"
#include "scene/3d/spring_bone_collision_sphere_3d.h" #include "scene/3d/spring_bone_collision_sphere_3d.h"
#include "scene/3d/spring_bone_simulator_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/box_shape_3d.h"
#include "scene/resources/3d/capsule_shape_3d.h" #include "scene/resources/3d/capsule_shape_3d.h"
#include "scene/resources/3d/concave_polygon_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/convex_polygon_shape_3d.h"
#include "scene/resources/3d/cylinder_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/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/separation_ray_shape_3d.h"
#include "scene/resources/3d/sky_material.h"
#include "scene/resources/3d/sphere_shape_3d.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" #include "scene/resources/3d/world_boundary_shape_3d.h"
#endif // _3D_DISABLED #endif // PHYSICS_3D_DISABLED
static Ref<ResourceFormatSaverText> resource_saver_text; static Ref<ResourceFormatSaverText> resource_saver_text;
static Ref<ResourceFormatLoaderText> resource_loader_text; static Ref<ResourceFormatLoaderText> resource_loader_text;
@ -616,14 +626,16 @@ void register_scene_types() {
GDREGISTER_CLASS(RootMotionView); GDREGISTER_CLASS(RootMotionView);
GDREGISTER_VIRTUAL_CLASS(SkeletonModifier3D); GDREGISTER_VIRTUAL_CLASS(SkeletonModifier3D);
GDREGISTER_CLASS(RetargetModifier3D); GDREGISTER_CLASS(RetargetModifier3D);
OS::get_singleton()->yield(); // may take time to init
#ifndef PHYSICS_3D_DISABLED
GDREGISTER_CLASS(SpringBoneSimulator3D); GDREGISTER_CLASS(SpringBoneSimulator3D);
GDREGISTER_VIRTUAL_CLASS(SpringBoneCollision3D); GDREGISTER_VIRTUAL_CLASS(SpringBoneCollision3D);
GDREGISTER_CLASS(SpringBoneCollisionSphere3D); GDREGISTER_CLASS(SpringBoneCollisionSphere3D);
GDREGISTER_CLASS(SpringBoneCollisionCapsule3D); GDREGISTER_CLASS(SpringBoneCollisionCapsule3D);
GDREGISTER_CLASS(SpringBoneCollisionPlane3D); GDREGISTER_CLASS(SpringBoneCollisionPlane3D);
OS::get_singleton()->yield(); // may take time to init
GDREGISTER_ABSTRACT_CLASS(CollisionObject3D); GDREGISTER_ABSTRACT_CLASS(CollisionObject3D);
GDREGISTER_ABSTRACT_CLASS(PhysicsBody3D); GDREGISTER_ABSTRACT_CLASS(PhysicsBody3D);
GDREGISTER_CLASS(StaticBody3D); GDREGISTER_CLASS(StaticBody3D);
@ -636,11 +648,13 @@ void register_scene_types() {
GDREGISTER_CLASS(PhysicalBoneSimulator3D); GDREGISTER_CLASS(PhysicalBoneSimulator3D);
GDREGISTER_CLASS(PhysicalBone3D); GDREGISTER_CLASS(PhysicalBone3D);
GDREGISTER_CLASS(SoftBody3D); GDREGISTER_CLASS(SoftBody3D);
#endif // PHYSICS_3D_DISABLED
GDREGISTER_CLASS(SkeletonIK3D); GDREGISTER_CLASS(SkeletonIK3D);
GDREGISTER_CLASS(BoneAttachment3D); GDREGISTER_CLASS(BoneAttachment3D);
GDREGISTER_CLASS(LookAtModifier3D); GDREGISTER_CLASS(LookAtModifier3D);
#ifndef PHYSICS_3D_DISABLED
GDREGISTER_CLASS(VehicleBody3D); GDREGISTER_CLASS(VehicleBody3D);
GDREGISTER_CLASS(VehicleWheel3D); GDREGISTER_CLASS(VehicleWheel3D);
GDREGISTER_CLASS(Area3D); GDREGISTER_CLASS(Area3D);
@ -648,6 +662,7 @@ void register_scene_types() {
GDREGISTER_CLASS(CollisionPolygon3D); GDREGISTER_CLASS(CollisionPolygon3D);
GDREGISTER_CLASS(RayCast3D); GDREGISTER_CLASS(RayCast3D);
GDREGISTER_CLASS(ShapeCast3D); GDREGISTER_CLASS(ShapeCast3D);
#endif // PHYSICS_3D_DISABLED
GDREGISTER_CLASS(MultiMeshInstance3D); GDREGISTER_CLASS(MultiMeshInstance3D);
GDREGISTER_CLASS(Curve3D); GDREGISTER_CLASS(Curve3D);
@ -660,12 +675,14 @@ void register_scene_types() {
GDREGISTER_CLASS(FogMaterial); GDREGISTER_CLASS(FogMaterial);
GDREGISTER_CLASS(RemoteTransform3D); GDREGISTER_CLASS(RemoteTransform3D);
#ifndef PHYSICS_3D_DISABLED
GDREGISTER_ABSTRACT_CLASS(Joint3D); GDREGISTER_ABSTRACT_CLASS(Joint3D);
GDREGISTER_CLASS(PinJoint3D); GDREGISTER_CLASS(PinJoint3D);
GDREGISTER_CLASS(HingeJoint3D); GDREGISTER_CLASS(HingeJoint3D);
GDREGISTER_CLASS(SliderJoint3D); GDREGISTER_CLASS(SliderJoint3D);
GDREGISTER_CLASS(ConeTwistJoint3D); GDREGISTER_CLASS(ConeTwistJoint3D);
GDREGISTER_CLASS(Generic6DOFJoint3D); GDREGISTER_CLASS(Generic6DOFJoint3D);
#endif // PHYSICS_3D_DISABLED
GDREGISTER_CLASS(NavigationRegion3D); GDREGISTER_CLASS(NavigationRegion3D);
GDREGISTER_CLASS(NavigationAgent3D); GDREGISTER_CLASS(NavigationAgent3D);
@ -818,6 +835,7 @@ void register_scene_types() {
GDREGISTER_CLASS(Line2D); GDREGISTER_CLASS(Line2D);
GDREGISTER_CLASS(MeshInstance2D); GDREGISTER_CLASS(MeshInstance2D);
GDREGISTER_CLASS(MultiMeshInstance2D); GDREGISTER_CLASS(MultiMeshInstance2D);
#ifndef PHYSICS_2D_DISABLED
GDREGISTER_ABSTRACT_CLASS(CollisionObject2D); GDREGISTER_ABSTRACT_CLASS(CollisionObject2D);
GDREGISTER_ABSTRACT_CLASS(PhysicsBody2D); GDREGISTER_ABSTRACT_CLASS(PhysicsBody2D);
GDREGISTER_CLASS(StaticBody2D); GDREGISTER_CLASS(StaticBody2D);
@ -830,6 +848,7 @@ void register_scene_types() {
GDREGISTER_CLASS(CollisionPolygon2D); GDREGISTER_CLASS(CollisionPolygon2D);
GDREGISTER_CLASS(RayCast2D); GDREGISTER_CLASS(RayCast2D);
GDREGISTER_CLASS(ShapeCast2D); GDREGISTER_CLASS(ShapeCast2D);
#endif // PHYSICS_2D_DISABLED
GDREGISTER_CLASS(VisibleOnScreenNotifier2D); GDREGISTER_CLASS(VisibleOnScreenNotifier2D);
GDREGISTER_CLASS(VisibleOnScreenEnabler2D); GDREGISTER_CLASS(VisibleOnScreenEnabler2D);
GDREGISTER_CLASS(Polygon2D); GDREGISTER_CLASS(Polygon2D);
@ -846,10 +865,13 @@ void register_scene_types() {
GDREGISTER_CLASS(Camera2D); GDREGISTER_CLASS(Camera2D);
GDREGISTER_CLASS(AudioListener2D); GDREGISTER_CLASS(AudioListener2D);
#ifndef PHYSICS_2D_DISABLED
GDREGISTER_ABSTRACT_CLASS(Joint2D); GDREGISTER_ABSTRACT_CLASS(Joint2D);
GDREGISTER_CLASS(PinJoint2D); GDREGISTER_CLASS(PinJoint2D);
GDREGISTER_CLASS(GrooveJoint2D); GDREGISTER_CLASS(GrooveJoint2D);
GDREGISTER_CLASS(DampedSpringJoint2D); GDREGISTER_CLASS(DampedSpringJoint2D);
GDREGISTER_CLASS(TouchScreenButton);
#endif // PHYSICS_2D_DISABLED
GDREGISTER_CLASS(TileSet); GDREGISTER_CLASS(TileSet);
GDREGISTER_ABSTRACT_CLASS(TileSetSource); GDREGISTER_ABSTRACT_CLASS(TileSetSource);
GDREGISTER_CLASS(TileSetAtlasSource); GDREGISTER_CLASS(TileSetAtlasSource);
@ -861,7 +883,6 @@ void register_scene_types() {
GDREGISTER_CLASS(Parallax2D); GDREGISTER_CLASS(Parallax2D);
GDREGISTER_CLASS(ParallaxBackground); GDREGISTER_CLASS(ParallaxBackground);
GDREGISTER_CLASS(ParallaxLayer); GDREGISTER_CLASS(ParallaxLayer);
GDREGISTER_CLASS(TouchScreenButton);
GDREGISTER_CLASS(RemoteTransform2D); GDREGISTER_CLASS(RemoteTransform2D);
GDREGISTER_CLASS(SkeletonModificationStack2D); GDREGISTER_CLASS(SkeletonModificationStack2D);
@ -869,12 +890,14 @@ void register_scene_types() {
GDREGISTER_CLASS(SkeletonModification2DLookAt); GDREGISTER_CLASS(SkeletonModification2DLookAt);
GDREGISTER_CLASS(SkeletonModification2DCCDIK); GDREGISTER_CLASS(SkeletonModification2DCCDIK);
GDREGISTER_CLASS(SkeletonModification2DFABRIK); GDREGISTER_CLASS(SkeletonModification2DFABRIK);
GDREGISTER_CLASS(SkeletonModification2DJiggle);
GDREGISTER_CLASS(SkeletonModification2DTwoBoneIK); GDREGISTER_CLASS(SkeletonModification2DTwoBoneIK);
GDREGISTER_CLASS(SkeletonModification2DStackHolder); GDREGISTER_CLASS(SkeletonModification2DStackHolder);
#ifndef PHYSICS_2D_DISABLED
GDREGISTER_CLASS(PhysicalBone2D); GDREGISTER_CLASS(PhysicalBone2D);
GDREGISTER_CLASS(SkeletonModification2DJiggle);
GDREGISTER_CLASS(SkeletonModification2DPhysicalBones); GDREGISTER_CLASS(SkeletonModification2DPhysicalBones);
#endif // PHYSICS_2D_DISABLED
OS::get_singleton()->yield(); // may take time to init 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 OS::get_singleton()->yield(); // may take time to init
#ifndef PHYSICS_3D_DISABLED
GDREGISTER_ABSTRACT_CLASS(Shape3D); GDREGISTER_ABSTRACT_CLASS(Shape3D);
GDREGISTER_CLASS(SeparationRayShape3D); GDREGISTER_CLASS(SeparationRayShape3D);
GDREGISTER_CLASS(SphereShape3D); GDREGISTER_CLASS(SphereShape3D);
@ -933,12 +957,15 @@ void register_scene_types() {
GDREGISTER_CLASS(WorldBoundaryShape3D); GDREGISTER_CLASS(WorldBoundaryShape3D);
GDREGISTER_CLASS(ConvexPolygonShape3D); GDREGISTER_CLASS(ConvexPolygonShape3D);
GDREGISTER_CLASS(ConcavePolygonShape3D); GDREGISTER_CLASS(ConcavePolygonShape3D);
#endif // PHYSICS_3D_DISABLED
GDREGISTER_CLASS(World3D); GDREGISTER_CLASS(World3D);
OS::get_singleton()->yield(); // may take time to init OS::get_singleton()->yield(); // may take time to init
#endif // _3D_DISABLED #endif // _3D_DISABLED
#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
GDREGISTER_CLASS(PhysicsMaterial); GDREGISTER_CLASS(PhysicsMaterial);
#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
GDREGISTER_CLASS(Compositor); GDREGISTER_CLASS(Compositor);
GDREGISTER_CLASS(Environment); GDREGISTER_CLASS(Environment);
GDREGISTER_VIRTUAL_CLASS(CameraAttributes); GDREGISTER_VIRTUAL_CLASS(CameraAttributes);
@ -1027,6 +1054,7 @@ void register_scene_types() {
OS::get_singleton()->yield(); // may take time to init OS::get_singleton()->yield(); // may take time to init
GDREGISTER_CLASS(AudioStreamPlayer2D); GDREGISTER_CLASS(AudioStreamPlayer2D);
#ifndef PHYSICS_2D_DISABLED
GDREGISTER_ABSTRACT_CLASS(Shape2D); GDREGISTER_ABSTRACT_CLASS(Shape2D);
GDREGISTER_CLASS(WorldBoundaryShape2D); GDREGISTER_CLASS(WorldBoundaryShape2D);
GDREGISTER_CLASS(SegmentShape2D); GDREGISTER_CLASS(SegmentShape2D);
@ -1036,6 +1064,7 @@ void register_scene_types() {
GDREGISTER_CLASS(CapsuleShape2D); GDREGISTER_CLASS(CapsuleShape2D);
GDREGISTER_CLASS(ConvexPolygonShape2D); GDREGISTER_CLASS(ConvexPolygonShape2D);
GDREGISTER_CLASS(ConcavePolygonShape2D); GDREGISTER_CLASS(ConcavePolygonShape2D);
#endif // PHYSICS_2D_DISABLED
GDREGISTER_CLASS(Curve2D); GDREGISTER_CLASS(Curve2D);
GDREGISTER_CLASS(Path2D); GDREGISTER_CLASS(Path2D);
GDREGISTER_CLASS(PathFollow2D); GDREGISTER_CLASS(PathFollow2D);
@ -1058,14 +1087,18 @@ void register_scene_types() {
Polygon2D::navmesh_parse_init(); Polygon2D::navmesh_parse_init();
TileMap::navmesh_parse_init(); TileMap::navmesh_parse_init();
TileMapLayer::navmesh_parse_init(); TileMapLayer::navmesh_parse_init();
#ifndef PHYSICS_2D_DISABLED
StaticBody2D::navmesh_parse_init(); StaticBody2D::navmesh_parse_init();
#endif // PHYSICS_2D_DISABLED
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
// 3D nodes that support navmesh baking need to server register their source geometry parsers. // 3D nodes that support navmesh baking need to server register their source geometry parsers.
MeshInstance3D::navmesh_parse_init(); MeshInstance3D::navmesh_parse_init();
MultiMeshInstance3D::navmesh_parse_init(); MultiMeshInstance3D::navmesh_parse_init();
NavigationObstacle3D::navmesh_parse_init(); NavigationObstacle3D::navmesh_parse_init();
#ifndef PHYSICS_3D_DISABLED
StaticBody3D::navmesh_parse_init(); StaticBody3D::navmesh_parse_init();
#endif #endif // PHYSICS_3D_DISABLED
#endif // _3D_DISABLED
OS::get_singleton()->yield(); // may take time to init OS::get_singleton()->yield(); // may take time to init
@ -1101,7 +1134,6 @@ void register_scene_types() {
// Renamed in 4.0. // Renamed in 4.0.
// Keep alphabetical ordering to easily locate classes and avoid duplicates. // Keep alphabetical ordering to easily locate classes and avoid duplicates.
ClassDB::add_compatibility_class("AnimatedSprite", "AnimatedSprite2D"); ClassDB::add_compatibility_class("AnimatedSprite", "AnimatedSprite2D");
ClassDB::add_compatibility_class("Area", "Area3D");
ClassDB::add_compatibility_class("ARVRCamera", "XRCamera3D"); ClassDB::add_compatibility_class("ARVRCamera", "XRCamera3D");
ClassDB::add_compatibility_class("ARVRController", "XRController3D"); ClassDB::add_compatibility_class("ARVRController", "XRController3D");
ClassDB::add_compatibility_class("ARVRAnchor", "XRAnchor3D"); ClassDB::add_compatibility_class("ARVRAnchor", "XRAnchor3D");
@ -1111,17 +1143,8 @@ void register_scene_types() {
ClassDB::add_compatibility_class("ARVRServer", "XRServer"); ClassDB::add_compatibility_class("ARVRServer", "XRServer");
ClassDB::add_compatibility_class("AStar", "AStar3D"); ClassDB::add_compatibility_class("AStar", "AStar3D");
ClassDB::add_compatibility_class("BoneAttachment", "BoneAttachment3D"); ClassDB::add_compatibility_class("BoneAttachment", "BoneAttachment3D");
ClassDB::add_compatibility_class("BoxShape", "BoxShape3D");
ClassDB::add_compatibility_class("Camera", "Camera3D"); ClassDB::add_compatibility_class("Camera", "Camera3D");
ClassDB::add_compatibility_class("CapsuleShape", "CapsuleShape3D");
ClassDB::add_compatibility_class("ClippedCamera", "ClippedCamera3D"); 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("CSGBox", "CSGBox3D");
ClassDB::add_compatibility_class("CSGCombiner", "CSGCombiner3D"); ClassDB::add_compatibility_class("CSGCombiner", "CSGCombiner3D");
ClassDB::add_compatibility_class("CSGCylinder", "CSGCylinder3D"); ClassDB::add_compatibility_class("CSGCylinder", "CSGCylinder3D");
@ -1132,20 +1155,9 @@ void register_scene_types() {
ClassDB::add_compatibility_class("CSGSphere", "CSGSphere3D"); ClassDB::add_compatibility_class("CSGSphere", "CSGSphere3D");
ClassDB::add_compatibility_class("CSGTorus", "CSGTorus3D"); ClassDB::add_compatibility_class("CSGTorus", "CSGTorus3D");
ClassDB::add_compatibility_class("CubeMesh", "BoxMesh"); 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("GIProbe", "VoxelGI");
ClassDB::add_compatibility_class("GIProbeData", "VoxelGIData"); ClassDB::add_compatibility_class("GIProbeData", "VoxelGIData");
ClassDB::add_compatibility_class("GradientTexture", "GradientTexture1D"); 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("Light", "Light3D");
ClassDB::add_compatibility_class("Light2D", "PointLight2D"); ClassDB::add_compatibility_class("Light2D", "PointLight2D");
ClassDB::add_compatibility_class("LineShape2D", "WorldBoundaryShape2D"); ClassDB::add_compatibility_class("LineShape2D", "WorldBoundaryShape2D");
@ -1166,48 +1178,21 @@ void register_scene_types() {
ClassDB::add_compatibility_class("ParticlesMaterial", "ParticleProcessMaterial"); ClassDB::add_compatibility_class("ParticlesMaterial", "ParticleProcessMaterial");
ClassDB::add_compatibility_class("Path", "Path3D"); ClassDB::add_compatibility_class("Path", "Path3D");
ClassDB::add_compatibility_class("PathFollow", "PathFollow3D"); ClassDB::add_compatibility_class("PathFollow", "PathFollow3D");
ClassDB::add_compatibility_class("PhysicalBone", "PhysicalBone3D");
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("PhysicsBody", "PhysicsBody3D");
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("Position2D", "Marker2D");
ClassDB::add_compatibility_class("Position3D", "Marker3D"); ClassDB::add_compatibility_class("Position3D", "Marker3D");
ClassDB::add_compatibility_class("ProceduralSky", "Sky"); 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("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("ShortCut", "Shortcut");
ClassDB::add_compatibility_class("Skeleton", "Skeleton3D"); ClassDB::add_compatibility_class("Skeleton", "Skeleton3D");
ClassDB::add_compatibility_class("SkeletonIK", "SkeletonIK3D"); 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("Spatial", "Node3D");
ClassDB::add_compatibility_class("SpatialGizmo", "Node3DGizmo"); ClassDB::add_compatibility_class("SpatialGizmo", "Node3DGizmo");
ClassDB::add_compatibility_class("SpatialMaterial", "StandardMaterial3D"); ClassDB::add_compatibility_class("SpatialMaterial", "StandardMaterial3D");
ClassDB::add_compatibility_class("SphereShape", "SphereShape3D");
ClassDB::add_compatibility_class("SpotLight", "SpotLight3D"); ClassDB::add_compatibility_class("SpotLight", "SpotLight3D");
ClassDB::add_compatibility_class("SpringArm", "SpringArm3D");
ClassDB::add_compatibility_class("Sprite", "Sprite2D"); ClassDB::add_compatibility_class("Sprite", "Sprite2D");
ClassDB::add_compatibility_class("StaticBody", "StaticBody3D"); ClassDB::add_compatibility_class("StaticBody", "StaticBody3D");
ClassDB::add_compatibility_class("StreamTexture", "CompressedTexture2D"); ClassDB::add_compatibility_class("StreamTexture", "CompressedTexture2D");
ClassDB::add_compatibility_class("TextureProgress", "TextureProgressBar"); 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("VideoPlayer", "VideoStreamPlayer");
ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer"); ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer");
ClassDB::add_compatibility_class("Viewport", "SubViewport"); ClassDB::add_compatibility_class("Viewport", "SubViewport");
@ -1217,6 +1202,58 @@ void register_scene_types() {
ClassDB::add_compatibility_class("VisibilityNotifier3D", "VisibleOnScreenNotifier3D"); ClassDB::add_compatibility_class("VisibilityNotifier3D", "VisibleOnScreenNotifier3D");
ClassDB::add_compatibility_class("VisualServer", "RenderingServer"); ClassDB::add_compatibility_class("VisualServer", "RenderingServer");
ClassDB::add_compatibility_class("World", "World3D"); 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("RayCast", "RayCast3D");
ClassDB::add_compatibility_class("RayShape", "SeparationRayShape3D");
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("SliderJoint", "SliderJoint3D");
ClassDB::add_compatibility_class("SoftBody", "SoftBody3D");
ClassDB::add_compatibility_class("SoftDynamicBody3D", "SoftBody3D");
ClassDB::add_compatibility_class("SphereShape", "SphereShape3D");
ClassDB::add_compatibility_class("SpringArm", "SpringArm3D");
ClassDB::add_compatibility_class("VehicleBody", "VehicleBody3D");
ClassDB::add_compatibility_class("VehicleWheel", "VehicleWheel3D");
#endif // PHYSICS_3D_DISABLED
// VisualShader classes. // VisualShader classes.
ClassDB::add_compatibility_class("VisualShaderNodeScalarConstant", "VisualShaderNodeFloatConstant"); ClassDB::add_compatibility_class("VisualShaderNodeScalarConstant", "VisualShaderNodeFloatConstant");

View file

@ -3,5 +3,20 @@ from misc.utility.scons_hints import *
Import("env") Import("env")
env.add_source_files(env.scene_sources, "*.cpp") env.add_source_files(env.scene_sources, "navigation_mesh_source_geometry_data_2d.cpp")
env.add_source_files(env.scene_sources, "skeleton/*.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")

View file

@ -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")

View file

@ -636,6 +636,7 @@ bool TileSet::get_occlusion_layer_sdf_collision(int p_layer_index) const {
return occlusion_layers[p_layer_index].sdf_collision; return occlusion_layers[p_layer_index].sdf_collision;
} }
#ifndef PHYSICS_2D_DISABLED
int TileSet::get_physics_layers_count() const { int TileSet::get_physics_layers_count() const {
return physics_layers.size(); return physics_layers.size();
} }
@ -719,6 +720,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>()); ERR_FAIL_INDEX_V(p_layer_index, physics_layers.size(), Ref<PhysicsMaterial>());
return physics_layers[p_layer_index].physics_material; return physics_layers[p_layer_index].physics_material;
} }
#endif // PHYSICS_2D_DISABLED
// Terrains // Terrains
int TileSet::get_terrain_sets_count() const { int TileSet::get_terrain_sets_count() const {
@ -3238,8 +3240,10 @@ void TileSet::reset_state() {
tile_filled_mesh.instantiate(); tile_filled_mesh.instantiate();
tile_meshes_dirty = true; tile_meshes_dirty = true;
#ifndef PHYSICS_2D_DISABLED
// Physics // Physics
physics_layers.clear(); physics_layers.clear();
#endif // PHYSICS_2D_DISABLED
// Terrains // Terrains
terrain_sets.clear(); terrain_sets.clear();
@ -3477,6 +3481,7 @@ void TileSet::_compatibility_conversion() {
tile_data->set_z_index(ctd->z_index); tile_data->set_z_index(ctd->z_index);
#ifndef PHYSICS_2D_DISABLED
// Add the shapes. // Add the shapes.
if (ctd->shapes.size() > 0) { if (ctd->shapes.size() > 0) {
if (get_physics_layers_count() < 1) { if (get_physics_layers_count() < 1) {
@ -3500,6 +3505,7 @@ void TileSet::_compatibility_conversion() {
} }
} }
} }
#endif // PHYSICS_2D_DISABLED
} }
// Update the size count. // Update the size count.
if (!compatibility_size_count.has(ctd->region.get_size())) { if (!compatibility_size_count.has(ctd->region.get_size())) {
@ -3596,6 +3602,7 @@ void TileSet::_compatibility_conversion() {
tile_data->set_z_index(ctd->autotile_z_index_map[coords]); tile_data->set_z_index(ctd->autotile_z_index_map[coords]);
} }
#ifndef PHYSICS_2D_DISABLED
// Add the shapes. // Add the shapes.
if (ctd->shapes.size() > 0) { if (ctd->shapes.size() > 0) {
if (get_physics_layers_count() < 1) { if (get_physics_layers_count() < 1) {
@ -3619,6 +3626,7 @@ void TileSet::_compatibility_conversion() {
} }
} }
} }
#endif // PHYSICS_2D_DISABLED
// -- TODO: handle -- // -- TODO: handle --
// Those are offset for the whole atlas, they are likely useless for the atlases, but might make sense for single tiles. // Those are offset for the whole atlas, they are likely useless for the atlases, but might make sense for single tiles.
@ -3641,6 +3649,7 @@ void TileSet::_compatibility_conversion() {
} break; } break;
} }
#ifndef PHYSICS_2D_DISABLED
// Offset all shapes // Offset all shapes
for (int k = 0; k < ctd->shapes.size(); k++) { for (int k = 0; k < ctd->shapes.size(); k++) {
Ref<ConvexPolygonShape2D> convex = ctd->shapes[k].shape; Ref<ConvexPolygonShape2D> convex = ctd->shapes[k].shape;
@ -3652,6 +3661,7 @@ void TileSet::_compatibility_conversion() {
convex->set_points(points); convex->set_points(points);
} }
} }
#endif // PHYSICS_2D_DISABLED
} }
// Update the TileSet tile_size according to the most common size found. // Update the TileSet tile_size according to the most common size found.
@ -3839,7 +3849,9 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} else if (key == "one_way_margin") { } else if (key == "one_way_margin") {
csd.one_way_margin = d[key]; csd.one_way_margin = d[key];
} else if (key == "shape") { } else if (key == "shape") {
#ifndef PHYSICS_2D_DISABLED
csd.shape = d[key]; csd.shape = d[key];
#endif // PHYSICS_2D_DISABLED
} else if (key == "shape_transform") { } else if (key == "shape_transform") {
csd.transform = d[key]; csd.transform = d[key];
} }
@ -3897,6 +3909,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_occlusion_layer_sdf_collision(index, p_value); set_occlusion_layer_sdf_collision(index, p_value);
return true; 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()) { } else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers. // Physics layers.
int index = components[0].trim_prefix("physics_layer_").to_int(); int index = components[0].trim_prefix("physics_layer_").to_int();
@ -3930,6 +3943,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_physics_layer_physics_material(index, physics_material); set_physics_layer_physics_material(index, physics_material);
return true; 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()) { } else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
// Terrains. // Terrains.
int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int(); int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
@ -4061,6 +4075,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_occlusion_layer_sdf_collision(index); r_ret = get_occlusion_layer_sdf_collision(index);
return true; 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()) { } else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers. // Physics layers.
int index = components[0].trim_prefix("physics_layer_").to_int(); int index = components[0].trim_prefix("physics_layer_").to_int();
@ -4080,6 +4095,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_physics_layer_physics_material(index); r_ret = get_physics_layer_physics_material(index);
return true; 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()) { } else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
// Terrains. // Terrains.
int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int(); int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
@ -4189,6 +4205,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(property_info); p_list->push_back(property_info);
} }
#ifndef PHYSICS_2D_DISABLED
// Physics. // Physics.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP)); p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
for (int i = 0; i < physics_layers.size(); i++) { for (int i = 0; i < physics_layers.size(); i++) {
@ -4215,6 +4232,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
} }
p_list->push_back(property_info); p_list->push_back(property_info);
} }
#endif // PHYSICS_2D_DISABLED
// Terrains. // Terrains.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Terrains", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP)); p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Terrains", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
@ -4310,6 +4328,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("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); ClassDB::bind_method(D_METHOD("get_occlusion_layer_sdf_collision", "layer_index"), &TileSet::get_occlusion_layer_sdf_collision);
#ifndef PHYSICS_2D_DISABLED
// Physics // Physics
ClassDB::bind_method(D_METHOD("get_physics_layers_count"), &TileSet::get_physics_layers_count); 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)); ClassDB::bind_method(D_METHOD("add_physics_layer", "to_position"), &TileSet::add_physics_layer, DEFVAL(-1));
@ -4323,6 +4342,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("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("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); ClassDB::bind_method(D_METHOD("get_physics_layer_physics_material", "layer_index"), &TileSet::get_physics_layer_physics_material);
#endif // PHYSICS_2D_DISABLED
// Terrains // Terrains
ClassDB::bind_method(D_METHOD("get_terrain_sets_count"), &TileSet::get_terrain_sets_count); ClassDB::bind_method(D_METHOD("get_terrain_sets_count"), &TileSet::get_terrain_sets_count);
@ -4531,6 +4551,7 @@ void TileSetAtlasSource::remove_occlusion_layer(int p_index) {
} }
} }
#ifndef PHYSICS_2D_DISABLED
void TileSetAtlasSource::add_physics_layer(int p_to_pos) { void TileSetAtlasSource::add_physics_layer(int p_to_pos) {
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) { for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
for (KeyValue<int, TileData *> E_alternative : E_tile.value.alternatives) { for (KeyValue<int, TileData *> E_alternative : E_tile.value.alternatives) {
@ -4554,6 +4575,7 @@ void TileSetAtlasSource::remove_physics_layer(int p_index) {
} }
} }
} }
#endif // PHYSICS_2D_DISABLED
void TileSetAtlasSource::add_terrain_set(int p_to_pos) { void TileSetAtlasSource::add_terrain_set(int p_to_pos) {
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) { for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
@ -5969,7 +5991,9 @@ void TileData::notify_tile_data_properties_should_change() {
} }
occluders.resize(tile_set->get_occlusion_layers_count()); occluders.resize(tile_set->get_occlusion_layers_count());
#ifndef PHYSICS_2D_DISABLED
physics.resize(tile_set->get_physics_layers_count()); physics.resize(tile_set->get_physics_layers_count());
#endif // PHYSICS_2D_DISABLED
for (int bit_index = 0; bit_index < 16; bit_index++) { 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)) { if (terrain_set < 0 || terrain_peering_bits[bit_index] >= tile_set->get_terrains_count(terrain_set)) {
terrain_peering_bits[bit_index] = -1; terrain_peering_bits[bit_index] = -1;
@ -6017,6 +6041,7 @@ void TileData::remove_occlusion_layer(int p_index) {
occluders.remove_at(p_index); occluders.remove_at(p_index);
} }
#ifndef PHYSICS_2D_DISABLED
void TileData::add_physics_layer(int p_to_pos) { void TileData::add_physics_layer(int p_to_pos) {
if (p_to_pos < 0) { if (p_to_pos < 0) {
p_to_pos = physics.size(); p_to_pos = physics.size();
@ -6036,6 +6061,7 @@ void TileData::remove_physics_layer(int p_index) {
ERR_FAIL_INDEX(p_index, physics.size()); ERR_FAIL_INDEX(p_index, physics.size());
physics.remove_at(p_index); physics.remove_at(p_index);
} }
#endif // PHYSICS_2D_DISABLED
void TileData::add_terrain_set(int p_to_pos) { void TileData::add_terrain_set(int p_to_pos) {
if (p_to_pos >= 0 && p_to_pos <= terrain_set) { if (p_to_pos >= 0 && p_to_pos <= terrain_set) {
@ -6176,8 +6202,10 @@ TileData *TileData::duplicate() {
output->z_index = z_index; output->z_index = z_index;
output->y_sort_origin = y_sort_origin; output->y_sort_origin = y_sort_origin;
output->occluders = occluders; output->occluders = occluders;
#ifndef PHYSICS_2D_DISABLED
// Physics // Physics
output->physics = physics; output->physics = physics;
#endif // PHYSICS_2D_DISABLED
// Terrain // Terrain
output->terrain_set = -1; output->terrain_set = -1;
memcpy(output->terrain_peering_bits, terrain_peering_bits, 16 * sizeof(int)); memcpy(output->terrain_peering_bits, terrain_peering_bits, 16 * sizeof(int));
@ -6347,6 +6375,7 @@ Ref<OccluderPolygon2D> TileData::get_occluder_polygon(int p_layer_id, int p_poly
} }
} }
#ifndef PHYSICS_2D_DISABLED
// Physics // Physics
void TileData::set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity) { void TileData::set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity) {
ERR_FAIL_INDEX(p_layer_id, physics.size()); ERR_FAIL_INDEX(p_layer_id, physics.size());
@ -6495,6 +6524,7 @@ Ref<ConvexPolygonShape2D> TileData::get_collision_polygon_shape(int p_layer_id,
return I->value[shape_index]; return I->value[shape_index];
} }
} }
#endif // PHYSICS_2D_DISABLED
// Terrain // Terrain
void TileData::set_terrain_set(int p_terrain_set) { void TileData::set_terrain_set(int p_terrain_set) {
@ -6743,7 +6773,9 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
return true; 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. // Physics layers.
int layer_index = components[0].trim_prefix("physics_layer_").to_int(); int layer_index = components[0].trim_prefix("physics_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -6798,7 +6830,9 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
return true; return true;
} }
} }
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) { } 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. // Navigation layers.
int layer_index = components[0].trim_prefix("navigation_layer_").to_int(); int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -6887,7 +6921,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
return true; 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. // Physics layers.
int layer_index = components[0].trim_prefix("physics_layer_").to_int(); int layer_index = components[0].trim_prefix("physics_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -6923,7 +6959,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
return true; return true;
} }
} }
} else if (components.size() == 2 && components[0] == "terrains_peering_bit") { } else
#endif // PHYSICS_2D_DISABLED
if (components.size() == 2 && components[0] == "terrains_peering_bit") {
// Terrains. // Terrains.
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) { if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
@ -6976,6 +7014,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
} }
} }
#ifndef PHYSICS_2D_DISABLED
// Physics layers. // Physics layers.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP)); p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
for (int i = 0; i < physics.size(); i++) { for (int i = 0; i < physics.size(); i++) {
@ -7018,6 +7057,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(property_info); p_list->push_back(property_info);
} }
} }
#endif // PHYSICS_2D_DISABLED
// Terrain data // Terrain data
if (terrain_set >= 0) { if (terrain_set >= 0) {
@ -7090,6 +7130,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)); 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 #endif // DISABLE_DEPRECATED
#ifndef PHYSICS_2D_DISABLED
// Physics. // Physics.
ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "layer_id", "velocity"), &TileData::set_constant_linear_velocity); 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); ClassDB::bind_method(D_METHOD("get_constant_linear_velocity", "layer_id"), &TileData::get_constant_linear_velocity);
@ -7105,6 +7146,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("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("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); 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 // Terrain
ClassDB::bind_method(D_METHOD("set_terrain_set", "terrain_set"), &TileData::set_terrain_set); ClassDB::bind_method(D_METHOD("set_terrain_set", "terrain_set"), &TileData::set_terrain_set);

View file

@ -36,7 +36,9 @@
#include "core/templates/rb_set.h" #include "core/templates/rb_set.h"
#include "scene/2d/light_occluder_2d.h" #include "scene/2d/light_occluder_2d.h"
#include "scene/main/canvas_item.h" #include "scene/main/canvas_item.h"
#ifndef PHYSICS_2D_DISABLED
#include "scene/resources/2d/convex_polygon_shape_2d.h" #include "scene/resources/2d/convex_polygon_shape_2d.h"
#endif // PHYSICS_2D_DISABLED
#include "scene/resources/2d/navigation_polygon.h" #include "scene/resources/2d/navigation_polygon.h"
#include "scene/resources/image_texture.h" #include "scene/resources/image_texture.h"
#include "scene/resources/packed_scene.h" #include "scene/resources/packed_scene.h"
@ -153,7 +155,9 @@ private:
Vector2i autotile_coords; Vector2i autotile_coords;
bool one_way; bool one_way;
float one_way_margin; float one_way_margin;
#ifndef PHYSICS_2D_DISABLED
Ref<Shape2D> shape; Ref<Shape2D> shape;
#endif // PHYSICS_2D_DISABLED
Transform2D transform; Transform2D transform;
}; };
@ -322,6 +326,7 @@ private:
Ref<ArrayMesh> tile_filled_mesh; Ref<ArrayMesh> tile_filled_mesh;
mutable bool tile_meshes_dirty = true; mutable bool tile_meshes_dirty = true;
#ifndef PHYSICS_2D_DISABLED
// Physics // Physics
struct PhysicsLayer { struct PhysicsLayer {
uint32_t collision_layer = 1; uint32_t collision_layer = 1;
@ -330,6 +335,7 @@ private:
Ref<PhysicsMaterial> physics_material; Ref<PhysicsMaterial> physics_material;
}; };
Vector<PhysicsLayer> physics_layers; Vector<PhysicsLayer> physics_layers;
#endif // PHYSICS_2D_DISABLED
// Terrains // Terrains
struct Terrain { struct Terrain {
@ -439,6 +445,7 @@ public:
void set_occlusion_layer_sdf_collision(int p_layer_index, bool p_sdf_collision); 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; bool get_occlusion_layer_sdf_collision(int p_layer_index) const;
#ifndef PHYSICS_2D_DISABLED
// Physics // Physics
int get_physics_layers_count() const; int get_physics_layers_count() const;
void add_physics_layer(int p_index = -1); 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; 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); 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; Ref<PhysicsMaterial> get_physics_layer_physics_material(int p_layer_index) const;
#endif // PHYSICS_2D_DISABLED
// Terrain sets // Terrain sets
int get_terrain_sets_count() const; int get_terrain_sets_count() const;
@ -685,9 +693,11 @@ public:
virtual void add_occlusion_layer(int p_index) override; 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 move_occlusion_layer(int p_from_index, int p_to_pos) override;
virtual void remove_occlusion_layer(int p_index) 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 add_physics_layer(int p_index) override;
virtual void move_physics_layer(int p_from_index, int p_to_pos) override; virtual void move_physics_layer(int p_from_index, int p_to_pos) override;
virtual void remove_physics_layer(int p_index) 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 add_terrain_set(int p_index) override;
virtual void move_terrain_set(int p_from_index, int p_to_pos) override; virtual void move_terrain_set(int p_from_index, int p_to_pos) override;
virtual void remove_terrain_set(int p_index) override; virtual void remove_terrain_set(int p_index) override;
@ -852,6 +862,7 @@ private:
}; };
Vector<OcclusionLayerTileData> occluders; Vector<OcclusionLayerTileData> occluders;
#ifndef PHYSICS_2D_DISABLED
// Physics // Physics
struct PhysicsLayerTileData { struct PhysicsLayerTileData {
struct PolygonShapeTileData { struct PolygonShapeTileData {
@ -868,6 +879,7 @@ private:
}; };
Vector<PhysicsLayerTileData> physics; Vector<PhysicsLayerTileData> physics;
// TODO add support for areas. // TODO add support for areas.
#endif // PHYSICS_2D_DISABLED
// Terrain // Terrain
int terrain_set = -1; int terrain_set = -1;
@ -907,9 +919,11 @@ public:
void add_occlusion_layer(int p_index); void add_occlusion_layer(int p_index);
void move_occlusion_layer(int p_from_index, int p_to_pos); void move_occlusion_layer(int p_from_index, int p_to_pos);
void remove_occlusion_layer(int p_index); void remove_occlusion_layer(int p_index);
#ifndef PHYSICS_2D_DISABLED
void add_physics_layer(int p_index); void add_physics_layer(int p_index);
void move_physics_layer(int p_from_index, int p_to_pos); void move_physics_layer(int p_from_index, int p_to_pos);
void remove_physics_layer(int p_index); void remove_physics_layer(int p_index);
#endif // PHYSICS_2D_DISABLED
void add_terrain_set(int p_index); void add_terrain_set(int p_index);
void move_terrain_set(int p_from_index, int p_to_pos); void move_terrain_set(int p_from_index, int p_to_pos);
void remove_terrain_set(int p_index); 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); 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; 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 // Physics
void set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity); void set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity);
Vector2 get_constant_linear_velocity(int p_layer_id) const; 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; 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; 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; 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 // Terrain
void set_terrain_set(int p_terrain_id); void set_terrain_set(int p_terrain_id);

View file

@ -3,5 +3,25 @@ from misc.utility.scons_hints import *
Import("env") 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") 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")

View file

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

View file

@ -31,11 +31,14 @@
#pragma once #pragma once
#include "core/io/resource.h" #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/mesh.h"
#include "scene/resources/navigation_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 // 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 // so the data is not registered (hence, quality loss), importing happens faster and
// its easier to modify before saving // its easier to modify before saving
@ -117,9 +120,11 @@ public:
Ref<ImporterMesh> get_shadow_mesh() const; Ref<ImporterMesh> get_shadow_mesh() const;
Vector<Face3> get_faces() const; Vector<Face3> get_faces() const;
#ifndef PHYSICS_3D_DISABLED
Vector<Ref<Shape3D>> convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const; 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<ConvexPolygonShape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
Ref<ConcavePolygonShape3D> create_trimesh_shape() const; Ref<ConcavePolygonShape3D> create_trimesh_shape() const;
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> create_navigation_mesh(); 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); 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);

View file

@ -30,7 +30,9 @@
#include "mesh_library.h" #include "mesh_library.h"
#ifndef PHYSICS_3D_DISABLED
#include "box_shape_3d.h" #include "box_shape_3d.h"
#endif // PHYSICS_3D_DISABLED
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
String prop_name = p_name; 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); set_item_mesh_cast_shadow(idx, RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON);
} break; } break;
} }
#ifndef PHYSICS_3D_DISABLED
} else if (what == "shape") { } else if (what == "shape") {
Vector<ShapeData> shapes; Vector<ShapeData> shapes;
ShapeData sd; ShapeData sd;
@ -73,6 +76,7 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
set_item_shapes(idx, shapes); set_item_shapes(idx, shapes);
} else if (what == "shapes") { } else if (what == "shapes") {
_set_item_shapes(idx, p_value); _set_item_shapes(idx, p_value);
#endif // PHYSICS_3D_DISABLED
} else if (what == "preview") { } else if (what == "preview") {
set_item_preview(idx, p_value); set_item_preview(idx, p_value);
} else if (what == "navigation_mesh") { } 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); r_ret = get_item_mesh_transform(idx);
} else if (what == "mesh_cast_shadow") { } else if (what == "mesh_cast_shadow") {
r_ret = (int)get_item_mesh_cast_shadow(idx); r_ret = (int)get_item_mesh_cast_shadow(idx);
#ifndef PHYSICS_3D_DISABLED
} else if (what == "shapes") { } else if (what == "shapes") {
r_ret = _get_item_shapes(idx); r_ret = _get_item_shapes(idx);
#endif // PHYSICS_3D_DISABLED
} else if (what == "navigation_mesh") { } else if (what == "navigation_mesh") {
r_ret = get_item_navigation_mesh(idx); r_ret = get_item_navigation_mesh(idx);
} else if (what == "navigation_mesh_transform") { } else if (what == "navigation_mesh_transform") {
@ -181,12 +187,14 @@ void MeshLibrary::set_item_mesh_cast_shadow(int p_item, RS::ShadowCastingSetting
emit_changed(); emit_changed();
} }
#ifndef PHYSICS_3D_DISABLED
void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) { 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) + "'."); ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].shapes = p_shapes; item_map[p_item].shapes = p_shapes;
emit_changed(); emit_changed();
notify_property_list_changed(); notify_property_list_changed();
} }
#endif // PHYSICS_3D_DISABLED
void MeshLibrary::set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh) { 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) + "'."); 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; return item_map[p_item].mesh_cast_shadow;
} }
#ifndef PHYSICS_3D_DISABLED
Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const { 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) + "'."); 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; return item_map[p_item].shapes;
} }
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> MeshLibrary::get_item_navigation_mesh(int p_item) const { 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) + "'."); 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) { void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) {
Array arr_shapes = p_shapes; Array arr_shapes = p_shapes;
int size = p_shapes.size(); int size = p_shapes.size();
@ -351,6 +362,7 @@ Array MeshLibrary::_get_item_shapes(int p_item) const {
return ret; return ret;
} }
#endif // PHYSICS_3D_DISABLED
void MeshLibrary::reset_state() { void MeshLibrary::reset_state() {
clear(); 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", "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_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); 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); 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("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_name", "id"), &MeshLibrary::get_item_name);
ClassDB::bind_method(D_METHOD("get_item_mesh", "id"), &MeshLibrary::get_item_mesh); 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", "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_mesh_transform", "id"), &MeshLibrary::get_item_navigation_mesh_transform);
ClassDB::bind_method(D_METHOD("get_item_navigation_layers", "id"), &MeshLibrary::get_item_navigation_layers); 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); 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("get_item_preview", "id"), &MeshLibrary::get_item_preview);
ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item); 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); ClassDB::bind_method(D_METHOD("find_item_by_name", "name"), &MeshLibrary::find_item_by_name);

View file

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

View file

@ -45,6 +45,7 @@ void World3D::_remove_camera(Camera3D *p_camera) {
} }
RID World3D::get_space() const { RID World3D::get_space() const {
#ifndef PHYSICS_3D_DISABLED
if (space.is_null()) { if (space.is_null()) {
space = PhysicsServer3D::get_singleton()->space_create(); space = PhysicsServer3D::get_singleton()->space_create();
PhysicsServer3D::get_singleton()->space_set_active(space, true); 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_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")); 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; return space;
} }
@ -139,9 +141,11 @@ Ref<Compositor> World3D::get_compositor() const {
return compositor; return compositor;
} }
#ifndef PHYSICS_3D_DISABLED
PhysicsDirectSpaceState3D *World3D::get_direct_space_state() { PhysicsDirectSpaceState3D *World3D::get_direct_space_state() {
return PhysicsServer3D::get_singleton()->space_get_direct_state(get_space()); return PhysicsServer3D::get_singleton()->space_get_direct_state(get_space());
} }
#endif // PHYSICS_3D_DISABLED
void World3D::_bind_methods() { void World3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space); 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("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("set_camera_attributes", "attributes"), &World3D::set_camera_attributes);
ClassDB::bind_method(D_METHOD("get_camera_attributes"), &World3D::get_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); 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, "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, "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::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, "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, "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"); 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"); 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() { World3D::World3D() {
@ -169,13 +177,17 @@ World3D::World3D() {
World3D::~World3D() { World3D::~World3D() {
ERR_FAIL_NULL(RenderingServer::get_singleton()); ERR_FAIL_NULL(RenderingServer::get_singleton());
#ifndef PHYSICS_3D_DISABLED
ERR_FAIL_NULL(PhysicsServer3D::get_singleton()); ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
#endif // PHYSICS_3D_DISABLED
ERR_FAIL_NULL(NavigationServer3D::get_singleton()); ERR_FAIL_NULL(NavigationServer3D::get_singleton());
RenderingServer::get_singleton()->free(scenario); RenderingServer::get_singleton()->free(scenario);
#ifndef PHYSICS_3D_DISABLED
if (space.is_valid()) { if (space.is_valid()) {
PhysicsServer3D::get_singleton()->free(space); PhysicsServer3D::get_singleton()->free(space);
} }
#endif // PHYSICS_3D_DISABLED
if (navigation_map.is_valid()) { if (navigation_map.is_valid()) {
NavigationServer3D::get_singleton()->free(navigation_map); NavigationServer3D::get_singleton()->free(navigation_map);
} }

View file

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

View file

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

View file

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

View file

@ -30,6 +30,7 @@
#include "physics_material.h" #include "physics_material.h"
#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
void PhysicsMaterial::_bind_methods() { void PhysicsMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicsMaterial::set_friction); ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicsMaterial::set_friction);
ClassDB::bind_method(D_METHOD("get_friction"), &PhysicsMaterial::get_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; absorbent = p_val;
emit_changed(); emit_changed();
} }
#endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)

View file

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

View file

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

View file

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

View file

@ -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, "display_server.cpp")
env.add_source_files(env.servers_sources, "navigation_server_2d.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, "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, "register_server_types.cpp")
env.add_source_files(env.servers_sources, "rendering_server.cpp") env.add_source_files(env.servers_sources, "rendering_server.cpp")
env.add_source_files(env.servers_sources, "text_server.cpp") env.add_source_files(env.servers_sources, "text_server.cpp")
@ -26,7 +24,11 @@ SConscript("navigation/SCsub")
SConscript("rendering/SCsub") SConscript("rendering/SCsub")
SConscript("text/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.cpp")
env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp") env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp")

View file

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

View file

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

View file

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

View file

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