summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/linux_builds.yml37
-rw-r--r--core/io/http_client.cpp3
-rw-r--r--core/math/color.cpp96
-rw-r--r--core/math/color.h4
-rw-r--r--core/math/math_funcs.h13
-rw-r--r--core/string/ustring.cpp6
-rw-r--r--core/variant/variant_call.cpp9
-rw-r--r--core/variant/variant_utility.cpp5
-rw-r--r--doc/classes/@GlobalScope.xml20
-rw-r--r--doc/classes/AABB.xml17
-rw-r--r--doc/classes/Animation.xml13
-rw-r--r--doc/classes/AnimationNode.xml1
-rw-r--r--doc/classes/AnimationNodeAnimation.xml9
-rw-r--r--doc/classes/Area2D.xml27
-rw-r--r--doc/classes/Area3D.xml27
-rw-r--r--doc/classes/AudioStreamSample.xml2
-rw-r--r--doc/classes/Color.xml18
-rw-r--r--doc/classes/EditorInspectorPlugin.xml17
-rw-r--r--doc/classes/NavigationPolygon.xml4
-rw-r--r--doc/classes/Node.xml14
-rw-r--r--doc/classes/PhysicsBody2D.xml6
-rw-r--r--doc/classes/PhysicsBody3D.xml6
-rw-r--r--doc/classes/PhysicsDirectSpaceState2D.xml2
-rw-r--r--doc/classes/PhysicsDirectSpaceState3D.xml2
-rw-r--r--doc/classes/PhysicsRayQueryParameters2D.xml3
-rw-r--r--doc/classes/PhysicsRayQueryParameters3D.xml6
-rw-r--r--doc/classes/PhysicsServer2D.xml46
-rw-r--r--doc/classes/PhysicsServer3D.xml54
-rw-r--r--doc/classes/ProjectSettings.xml10
-rw-r--r--doc/classes/RayCast2D.xml5
-rw-r--r--doc/classes/RayCast3D.xml5
-rw-r--r--doc/classes/Rect2.xml20
-rw-r--r--doc/classes/Rect2i.xml19
-rw-r--r--doc/classes/RenderingServer.xml4
-rw-r--r--doc/classes/Shader.xml4
-rw-r--r--doc/classes/TileSetAtlasSource.xml19
-rw-r--r--doc/classes/VisualShaderNodeCustom.xml6
-rw-r--r--doc/classes/VisualShaderNodeParticleMeshEmitter.xml17
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp34
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.h6
-rw-r--r--drivers/wasapi/audio_driver_wasapi.cpp14
-rw-r--r--editor/animation_track_editor.cpp59
-rw-r--r--editor/animation_track_editor.h3
-rw-r--r--editor/doc_tools.cpp2
-rw-r--r--editor/editor_help.cpp14
-rw-r--r--editor/editor_inspector.cpp39
-rw-r--r--editor/editor_inspector.h10
-rw-r--r--editor/editor_node.cpp5
-rw-r--r--editor/editor_properties.cpp10
-rw-r--r--editor/editor_properties.h2
-rw-r--r--editor/editor_themes.cpp2
-rw-r--r--editor/icons/MirrorX.svg1
-rw-r--r--editor/icons/MirrorY.svg1
-rw-r--r--editor/icons/PingPongLoop.svg1
-rw-r--r--editor/icons/RotateLeft.svg1
-rw-r--r--editor/icons/RotateRight.svg1
-rw-r--r--editor/import/editor_import_plugin.cpp2
-rw-r--r--editor/import/resource_importer_dynamicfont.cpp6
-rw-r--r--editor/import/resource_importer_obj.cpp8
-rw-r--r--editor/import/resource_importer_scene.cpp26
-rw-r--r--editor/import/resource_importer_wav.cpp2
-rw-r--r--editor/plugin_config_dialog.cpp2
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp9
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp10
-rw-r--r--editor/plugins/ot_features_plugin.cpp6
-rw-r--r--editor/plugins/ot_features_plugin.h2
-rw-r--r--editor/plugins/root_motion_editor_plugin.cpp12
-rw-r--r--editor/plugins/root_motion_editor_plugin.h2
-rw-r--r--editor/plugins/script_editor_plugin.cpp76
-rw-r--r--editor/plugins/script_editor_plugin.h1
-rw-r--r--editor/plugins/script_text_editor.cpp30
-rw-r--r--editor/plugins/style_box_editor_plugin.cpp7
-rw-r--r--editor/plugins/style_box_editor_plugin.h2
-rw-r--r--editor/plugins/text_editor.cpp25
-rw-r--r--editor/plugins/tiles/tile_data_editors.cpp117
-rw-r--r--editor/plugins/tiles/tile_data_editors.h11
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.cpp188
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.h36
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp17
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h2
-rw-r--r--editor/rename_dialog.cpp1
-rw-r--r--editor/rename_dialog.h7
-rw-r--r--editor/scene_tree_dock.cpp20
-rw-r--r--editor/scene_tree_dock.h2
-rw-r--r--main/main.cpp13
-rw-r--r--modules/bullet/bullet_physics_server.cpp9
-rw-r--r--modules/gdscript/gdscript.cpp16
-rw-r--r--modules/gdscript/gdscript.h1
-rw-r--r--modules/gdscript/gdscript_parser.cpp101
-rw-r--r--modules/gdscript/gdscript_tokenizer.cpp9
-rw-r--r--modules/gdscript/gdscript_vm.cpp2
-rw-r--r--modules/gdscript/language_server/gdscript_language_protocol.h2
-rw-r--r--modules/gltf/gltf_document.cpp4
-rw-r--r--modules/gltf/gltf_document.h3
-rw-r--r--modules/mono/doc_classes/CSharpScript.xml5
-rw-r--r--modules/mono/doc_classes/GodotSharp.xml29
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs18
-rw-r--r--modules/mono/mono_gd/gd_mono.cpp2
-rw-r--r--modules/navigation/navigation_mesh_generator.cpp3
-rw-r--r--modules/opensimplex/noise_texture.h3
-rw-r--r--modules/text_server_adv/text_server_adv.cpp2
-rw-r--r--modules/text_server_adv/text_server_adv.h2
-rw-r--r--modules/text_server_fb/text_server_fb.cpp4
-rw-r--r--modules/text_server_fb/text_server_fb.h2
-rw-r--r--modules/visual_script/SCsub3
-rw-r--r--modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml49
-rw-r--r--modules/visual_script/editor/visual_script_editor.cpp (renamed from modules/visual_script/visual_script_editor.cpp)33
-rw-r--r--modules/visual_script/editor/visual_script_editor.h (renamed from modules/visual_script/visual_script_editor.h)2
-rw-r--r--modules/visual_script/editor/visual_script_property_selector.cpp (renamed from modules/visual_script/visual_script_property_selector.cpp)10
-rw-r--r--modules/visual_script/editor/visual_script_property_selector.h (renamed from modules/visual_script/visual_script_property_selector.h)0
-rw-r--r--modules/visual_script/register_types.cpp3
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp17
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.h1
-rw-r--r--platform/javascript/os_javascript.cpp2
-rw-r--r--platform/linuxbsd/crash_handler_linuxbsd.cpp2
-rw-r--r--platform/osx/crash_handler_osx.mm2
-rw-r--r--platform/osx/display_server_osx.mm7
-rw-r--r--platform/windows/detect.py6
-rw-r--r--platform/windows/display_server_windows.cpp5
-rw-r--r--platform/windows/gl_manager_windows.cpp3
-rw-r--r--scene/2d/area_2d.cpp111
-rw-r--r--scene/2d/area_2d.h28
-rw-r--r--scene/2d/physics_body_2d.cpp16
-rw-r--r--scene/2d/ray_cast_2d.cpp21
-rw-r--r--scene/2d/ray_cast_2d.h5
-rw-r--r--scene/2d/tile_map.cpp12
-rw-r--r--scene/3d/area_3d.cpp113
-rw-r--r--scene/3d/area_3d.h29
-rw-r--r--scene/3d/physics_body_3d.cpp16
-rw-r--r--scene/3d/ray_cast_3d.cpp21
-rw-r--r--scene/3d/ray_cast_3d.h9
-rw-r--r--scene/animation/animation_blend_space_2d.cpp7
-rw-r--r--scene/animation/animation_blend_tree.cpp79
-rw-r--r--scene/animation/animation_blend_tree.h26
-rw-r--r--scene/animation/animation_player.cpp135
-rw-r--r--scene/animation/animation_player.h2
-rw-r--r--scene/animation/animation_tree.cpp275
-rw-r--r--scene/animation/animation_tree.h4
-rw-r--r--scene/gui/line_edit.cpp9
-rw-r--r--scene/gui/rich_text_label.cpp59
-rw-r--r--scene/gui/text_edit.cpp2
-rw-r--r--scene/main/node.cpp2
-rw-r--r--scene/property_utils.cpp5
-rw-r--r--scene/register_scene_types.cpp1
-rw-r--r--scene/resources/animation.cpp679
-rw-r--r--scene/resources/animation.h24
-rw-r--r--scene/resources/audio_stream_sample.cpp6
-rw-r--r--scene/resources/audio_stream_sample.h2
-rw-r--r--scene/resources/shader.cpp34
-rw-r--r--scene/resources/shader.h6
-rw-r--r--scene/resources/tile_set.cpp150
-rw-r--r--scene/resources/tile_set.h17
-rw-r--r--scene/resources/visual_shader.cpp32
-rw-r--r--scene/resources/visual_shader.h8
-rw-r--r--scene/resources/visual_shader_nodes.cpp17
-rw-r--r--scene/resources/visual_shader_particle_nodes.cpp280
-rw-r--r--scene/resources/visual_shader_particle_nodes.h47
-rw-r--r--servers/physics_2d/godot_area_2d.cpp23
-rw-r--r--servers/physics_2d/godot_area_2d.h10
-rw-r--r--servers/physics_2d/godot_area_pair_2d.cpp20
-rw-r--r--servers/physics_2d/godot_area_pair_2d.h1
-rw-r--r--servers/physics_2d/godot_body_2d.cpp113
-rw-r--r--servers/physics_2d/godot_body_2d.h2
-rw-r--r--servers/physics_2d/godot_physics_server_2d.cpp27
-rw-r--r--servers/physics_2d/godot_physics_server_2d.h3
-rw-r--r--servers/physics_2d/godot_space_2d.cpp16
-rw-r--r--servers/physics_3d/godot_area_3d.cpp23
-rw-r--r--servers/physics_3d/godot_area_3d.h10
-rw-r--r--servers/physics_3d/godot_area_pair_3d.cpp37
-rw-r--r--servers/physics_3d/godot_area_pair_3d.h2
-rw-r--r--servers/physics_3d/godot_body_3d.cpp111
-rw-r--r--servers/physics_3d/godot_body_3d.h2
-rw-r--r--servers/physics_3d/godot_body_pair_3d.cpp2
-rw-r--r--servers/physics_3d/godot_collision_solver_3d.cpp2
-rw-r--r--servers/physics_3d/godot_physics_server_3d.cpp27
-rw-r--r--servers/physics_3d/godot_physics_server_3d.h3
-rw-r--r--servers/physics_3d/godot_shape_3d.cpp30
-rw-r--r--servers/physics_3d/godot_shape_3d.h24
-rw-r--r--servers/physics_3d/godot_soft_body_3d.cpp96
-rw-r--r--servers/physics_3d/godot_soft_body_3d.h22
-rw-r--r--servers/physics_3d/godot_space_3d.cpp18
-rw-r--r--servers/physics_server_2d.cpp10
-rw-r--r--servers/physics_server_2d.h11
-rw-r--r--servers/physics_server_2d_wrap_mt.h3
-rw-r--r--servers/physics_server_3d.cpp14
-rw-r--r--servers/physics_server_3d.h15
-rw-r--r--servers/physics_server_3d_wrap_mt.h3
-rw-r--r--servers/rendering/rasterizer_dummy.h4
-rw-r--r--servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp15
-rw-r--r--servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h4
-rw-r--r--servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp15
-rw-r--r--servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h4
-rw-r--r--servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp15
-rw-r--r--servers/rendering/renderer_rd/renderer_canvas_render_rd.h4
-rw-r--r--servers/rendering/renderer_rd/renderer_scene_render_rd.cpp38
-rw-r--r--servers/rendering/renderer_rd/renderer_scene_render_rd.h4
-rw-r--r--servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp15
-rw-r--r--servers/rendering/renderer_rd/renderer_scene_sky_rd.h4
-rw-r--r--servers/rendering/renderer_rd/renderer_storage_rd.cpp60
-rw-r--r--servers/rendering/renderer_rd/renderer_storage_rd.h16
-rw-r--r--servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl19
-rw-r--r--servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl37
-rw-r--r--servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl12
-rw-r--r--servers/rendering/renderer_storage.h4
-rw-r--r--servers/rendering/rendering_server_default.h4
-rw-r--r--servers/rendering_server.cpp4
-rw-r--r--servers/rendering_server.h4
-rw-r--r--tests/SCsub5
-rw-r--r--tests/core/io/test_config_file.h (renamed from tests/test_config_file.h)1
-rw-r--r--tests/core/io/test_file_access.h (renamed from tests/test_file_access.h)3
-rw-r--r--tests/core/io/test_image.h (renamed from tests/test_image.h)4
-rw-r--r--tests/core/io/test_json.h (renamed from tests/test_json.h)0
-rw-r--r--tests/core/io/test_marshalls.h (renamed from tests/test_marshalls.h)0
-rw-r--r--tests/core/io/test_pck_packer.h (renamed from tests/test_pck_packer.h)1
-rw-r--r--tests/core/io/test_resource.h (renamed from tests/test_resource.h)0
-rw-r--r--tests/core/io/test_xml_parser.h (renamed from tests/test_xml_parser.h)3
-rw-r--r--tests/core/math/test_aabb.h (renamed from tests/test_aabb.h)4
-rw-r--r--tests/core/math/test_astar.h (renamed from tests/test_astar.h)5
-rw-r--r--tests/core/math/test_basis.h (renamed from tests/test_basis.h)3
-rw-r--r--tests/core/math/test_color.h (renamed from tests/test_color.h)2
-rw-r--r--tests/core/math/test_expression.h (renamed from tests/test_expression.h)0
-rw-r--r--tests/core/math/test_geometry_2d.h (renamed from tests/test_geometry_2d.h)1
-rw-r--r--tests/core/math/test_geometry_3d.h (renamed from tests/test_geometry_3d.h)4
-rw-r--r--tests/core/math/test_math.cpp (renamed from tests/test_math.cpp)14
-rw-r--r--tests/core/math/test_math.h (renamed from tests/test_math.h)2
-rw-r--r--tests/core/math/test_random_number_generator.h (renamed from tests/test_random_number_generator.h)0
-rw-r--r--tests/core/math/test_rect2.h (renamed from tests/test_rect2.h)136
-rw-r--r--tests/core/object/test_class_db.h (renamed from tests/test_class_db.h)9
-rw-r--r--tests/core/object/test_method_bind.h (renamed from tests/test_method_bind.h)4
-rw-r--r--tests/core/object/test_object.h (renamed from tests/test_object.h)4
-rw-r--r--tests/core/string/test_node_path.h (renamed from tests/test_node_path.h)2
-rw-r--r--tests/core/string/test_string.h (renamed from tests/test_string.h)14
-rw-r--r--tests/core/string/test_translation.h (renamed from tests/test_translation.h)3
-rw-r--r--tests/core/templates/test_command_queue.h (renamed from tests/test_command_queue.h)4
-rw-r--r--tests/core/templates/test_list.h (renamed from tests/test_list.h)0
-rw-r--r--tests/core/templates/test_local_vector.h (renamed from tests/test_local_vector.h)0
-rw-r--r--tests/core/templates/test_lru.h (renamed from tests/test_lru.h)1
-rw-r--r--tests/core/templates/test_oa_hash_map.cpp (renamed from tests/test_oa_hash_map.cpp)0
-rw-r--r--tests/core/templates/test_oa_hash_map.h (renamed from tests/test_oa_hash_map.h)2
-rw-r--r--tests/core/templates/test_ordered_hash_map.h (renamed from tests/test_ordered_hash_map.h)3
-rw-r--r--tests/core/templates/test_paged_array.h (renamed from tests/test_paged_array.h)0
-rw-r--r--tests/core/templates/test_vector.h (renamed from tests/test_vector.h)0
-rw-r--r--tests/core/test_crypto.h (renamed from tests/test_crypto.h)1
-rw-r--r--tests/core/test_hashing_context.h (renamed from tests/test_hashing_context.h)0
-rw-r--r--tests/core/test_time.h (renamed from tests/test_time.h)0
-rw-r--r--tests/core/variant/test_array.h (renamed from tests/test_array.h)6
-rw-r--r--tests/core/variant/test_dictionary.h (renamed from tests/test_dictionary.h)3
-rw-r--r--tests/core/variant/test_variant.h (renamed from tests/test_variant.h)0
-rw-r--r--tests/scene/test_code_edit.h (renamed from tests/test_code_edit.h)5
-rw-r--r--tests/scene/test_curve.h (renamed from tests/test_curve.h)2
-rw-r--r--tests/scene/test_gradient.h (renamed from tests/test_gradient.h)2
-rw-r--r--tests/scene/test_gui.cpp (renamed from tests/test_gui.cpp)13
-rw-r--r--tests/scene/test_gui.h (renamed from tests/test_gui.h)2
-rw-r--r--tests/scene/test_path_3d.h (renamed from tests/test_path_3d.h)1
-rw-r--r--tests/scene/test_path_follow_2d.h (renamed from tests/test_path_follow_2d.h)1
-rw-r--r--tests/scene/test_path_follow_3d.h (renamed from tests/test_path_follow_3d.h)1
-rw-r--r--tests/servers/test_physics_2d.cpp (renamed from tests/test_physics_2d.cpp)5
-rw-r--r--tests/servers/test_physics_2d.h (renamed from tests/test_physics_2d.h)2
-rw-r--r--tests/servers/test_physics_3d.cpp (renamed from tests/test_physics_3d.cpp)6
-rw-r--r--tests/servers/test_physics_3d.h (renamed from tests/test_physics_3d.h)2
-rw-r--r--tests/servers/test_render.cpp (renamed from tests/test_render.cpp)5
-rw-r--r--tests/servers/test_render.h (renamed from tests/test_render.h)4
-rw-r--r--tests/servers/test_shader_lang.cpp (renamed from tests/test_shader_lang.cpp)5
-rw-r--r--tests/servers/test_shader_lang.h (renamed from tests/test_shader_lang.h)2
-rw-r--r--tests/servers/test_text_server.h (renamed from tests/test_text_server.h)0
-rw-r--r--tests/test_macros.h6
-rw-r--r--tests/test_main.cpp102
-rw-r--r--tests/test_tools.h2
-rw-r--r--tests/test_utils.cpp2
-rw-r--r--tests/test_utils.h2
270 files changed, 3812 insertions, 1640 deletions
diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml
index f6d11e2efe..44d0cb041f 100644
--- a/.github/workflows/linux_builds.yml
+++ b/.github/workflows/linux_builds.yml
@@ -18,13 +18,15 @@ jobs:
fail-fast: false
matrix:
include:
- - name: Editor (target=release_debug, tools=yes, tests=yes)
- cache-name: linux-editor
+ - name: Editor w/ Mono (target=release_debug, tools=yes, tests=yes)
+ cache-name: linux-editor-mono
target: release_debug
tools: true
- tests: true
+ tests: false # Disabled due freeze caused by mix Mono build and CI
+ sconsflags: module_mono_enabled=yes mono_glue=no
doc-test: true
- bin: "./bin/godot.linuxbsd.opt.tools.64"
+ bin: "./bin/godot.linuxbsd.opt.tools.64.mono"
+ build-mono: true
artifact: true
- name: Editor and sanitizers (target=debug, tools=yes, tests=yes, use_asan=yes, use_ubsan=yes)
@@ -36,6 +38,7 @@ jobs:
proj-test: true
godot-cpp-test: true
bin: "./bin/godot.linuxbsd.tools.64s"
+ build-mono: false
# Skip 2GiB artifact speeding up action.
artifact: false
@@ -45,6 +48,15 @@ jobs:
tools: false
tests: false
sconsflags: module_mono_enabled=yes mono_glue=no debug_symbols=no
+ build-mono: false
+ artifact: true
+
+ - name: Minimal Template (target=release, tools=no, everything disabled)
+ cache-name: linux-template-minimal
+ target: release
+ tools: false
+ tests: false
+ sconsflags: modules_enabled_by_default=no disable_3d=yes disable_advanced_gui=yes deprecated=no minizip=no
artifact: true
steps:
@@ -80,11 +92,26 @@ jobs:
tools: ${{ matrix.tools }}
tests: ${{ matrix.tests }}
+ - name: Generate Mono glue
+ if: ${{ matrix.build-mono }}
+ run: |
+ ${{ matrix.bin }} --headless --generate-mono-glue modules/mono/glue || true
+
+ # Rebuild with mono
+ - name: Compilation (mono_glue=yes)
+ uses: ./.github/actions/godot-build
+ if: ${{ matrix.build-mono }}
+ with:
+ sconsflags: ${{ env.SCONSFLAGS }} ${{ matrix.sconsflags }} mono_glue=yes
+ platform: linuxbsd
+ target: ${{ matrix.target }}
+ tools: ${{ matrix.tools }}
+
# Execute unit tests for the editor
- name: Unit tests
if: ${{ matrix.tests }}
run: |
- ${{ matrix.bin }} --test
+ ${{ matrix.bin }} --test --headless
# Check class reference
- name: Check for class reference updates
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 5c1352c1b6..800ac779e5 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -85,8 +85,7 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) {
}
}
}
- query.erase(0, 1);
- return query;
+ return query.substr(1);
}
Dictionary HTTPClient::_get_response_headers_as_dictionary() {
diff --git a/core/math/color.cpp b/core/math/color.cpp
index dc86cacf8f..8310c342ed 100644
--- a/core/math/color.cpp
+++ b/core/math/color.cpp
@@ -107,6 +107,39 @@ uint64_t Color::to_rgba64() const {
return c;
}
+String _to_hex(float p_val) {
+ int v = Math::round(p_val * 255);
+ v = CLAMP(v, 0, 255);
+ String ret;
+
+ for (int i = 0; i < 2; i++) {
+ char32_t c[2] = { 0, 0 };
+ int lv = v & 0xF;
+ if (lv < 10) {
+ c[0] = '0' + lv;
+ } else {
+ c[0] = 'a' + lv - 10;
+ }
+
+ v >>= 4;
+ String cs = (const char32_t *)c;
+ ret = cs + ret;
+ }
+
+ return ret;
+}
+
+String Color::to_html(bool p_alpha) const {
+ String txt;
+ txt += _to_hex(r);
+ txt += _to_hex(g);
+ txt += _to_hex(b);
+ if (p_alpha) {
+ txt += _to_hex(a);
+ }
+ return txt;
+}
+
float Color::get_h() const {
float min = MIN(r, g);
min = MIN(min, b);
@@ -249,20 +282,6 @@ Color Color::hex64(uint64_t p_hex) {
return Color(r, g, b, a);
}
-Color Color::from_rgbe9995(uint32_t p_rgbe) {
- float r = p_rgbe & 0x1ff;
- float g = (p_rgbe >> 9) & 0x1ff;
- float b = (p_rgbe >> 18) & 0x1ff;
- float e = (p_rgbe >> 27);
- float m = Math::pow(2, e - 15.0 - 9.0);
-
- float rd = r * m;
- float gd = g * m;
- float bd = b * m;
-
- return Color(rd, gd, bd, 1.0f);
-}
-
static int _parse_col4(const String &p_str, int p_ofs) {
char character = p_str[p_ofs];
@@ -428,43 +447,24 @@ Color Color::from_string(const String &p_string, const Color &p_default) {
}
}
-String _to_hex(float p_val) {
- int v = Math::round(p_val * 255);
- v = CLAMP(v, 0, 255);
- String ret;
-
- for (int i = 0; i < 2; i++) {
- char32_t c[2] = { 0, 0 };
- int lv = v & 0xF;
- if (lv < 10) {
- c[0] = '0' + lv;
- } else {
- c[0] = 'a' + lv - 10;
- }
-
- v >>= 4;
- String cs = (const char32_t *)c;
- ret = cs + ret;
- }
-
- return ret;
+Color Color::from_hsv(float p_h, float p_s, float p_v, float p_alpha) {
+ Color c;
+ c.set_hsv(p_h, p_s, p_v, p_alpha);
+ return c;
}
-String Color::to_html(bool p_alpha) const {
- String txt;
- txt += _to_hex(r);
- txt += _to_hex(g);
- txt += _to_hex(b);
- if (p_alpha) {
- txt += _to_hex(a);
- }
- return txt;
-}
+Color Color::from_rgbe9995(uint32_t p_rgbe) {
+ float r = p_rgbe & 0x1ff;
+ float g = (p_rgbe >> 9) & 0x1ff;
+ float b = (p_rgbe >> 18) & 0x1ff;
+ float e = (p_rgbe >> 27);
+ float m = Math::pow(2, e - 15.0 - 9.0);
-Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
- Color c;
- c.set_hsv(p_h, p_s, p_v, p_a);
- return c;
+ float rd = r * m;
+ float gd = g * m;
+ float bd = b * m;
+
+ return Color(rd, gd, bd, 1.0f);
}
Color::operator String() const {
diff --git a/core/math/color.h b/core/math/color.h
index a95dbf4f60..ffd0fd8f6e 100644
--- a/core/math/color.h
+++ b/core/math/color.h
@@ -51,6 +51,7 @@ struct Color {
uint64_t to_rgba64() const;
uint64_t to_argb64() const;
uint64_t to_abgr64() const;
+ String to_html(bool p_alpha = true) const;
float get_h() const;
float get_s() const;
float get_v() const;
@@ -189,8 +190,7 @@ struct Color {
static String get_named_color_name(int p_idx);
static Color get_named_color(int p_idx);
static Color from_string(const String &p_string, const Color &p_default);
- String to_html(bool p_alpha = true) const;
- Color from_hsv(float p_h, float p_s, float p_v, float p_a) const;
+ static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
static Color from_rgbe9995(uint32_t p_rgbe);
_FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index baff10af98..b3eabd3e7a 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -291,6 +291,19 @@ public:
return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
}
+ static _ALWAYS_INLINE_ float fract(float value) {
+ return value - floor(value);
+ }
+ static _ALWAYS_INLINE_ double fract(double value) {
+ return value - floor(value);
+ }
+ static _ALWAYS_INLINE_ float pingpong(float value, float length) {
+ return (length != 0.0f) ? abs(fract((value - length) / (length * 2.0f)) * length * 2.0f - length) : 0.0f;
+ }
+ static _ALWAYS_INLINE_ double pingpong(double value, double length) {
+ return (length != 0.0) ? abs(fract((value - length) / (length * 2.0)) * length * 2.0 - length) : 0.0;
+ }
+
// double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 8d6da31cf3..4798cab641 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -952,10 +952,6 @@ const char32_t *String::get_data() const {
return size() ? &operator[](0) : &zero;
}
-void String::erase(int p_pos, int p_chars) {
- *this = left(MAX(p_pos, 0)) + substr(p_pos + p_chars, length() - ((p_pos + p_chars)));
-}
-
String String::capitalize() const {
String aux = this->camelcase_to_underscore(true).replace("_", " ").strip_edges();
String cap;
@@ -4420,7 +4416,7 @@ String String::property_name_encode() const {
// as well as '"', '=' or ' ' (32)
const char32_t *cstr = get_data();
for (int i = 0; cstr[i]; i++) {
- if (cstr[i] == '=' || cstr[i] == '"' || cstr[i] < 33 || cstr[i] > 126) {
+ if (cstr[i] == '=' || cstr[i] == '"' || cstr[i] == ';' || cstr[i] == '[' || cstr[i] == ']' || cstr[i] < 33 || cstr[i] > 126) {
return "\"" + c_escape_multiline() + "\"";
}
}
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index c3fe443456..65ea969146 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1412,8 +1412,6 @@ static void _register_variant_builtin_methods() {
bind_method(String, plus_file, sarray("file"), varray());
bind_method(String, unicode_at, sarray("at"), varray());
bind_method(String, dedent, sarray(), varray());
- // FIXME: String needs to be immutable when binding
- //bind_method(String, erase, sarray("position", "chars"), varray());
bind_method(String, hash, sarray(), varray());
bind_method(String, md5_text, sarray(), varray());
bind_method(String, sha1_text, sarray(), varray());
@@ -1422,8 +1420,6 @@ static void _register_variant_builtin_methods() {
bind_method(String, sha1_buffer, sarray(), varray());
bind_method(String, sha256_buffer, sarray(), varray());
bind_method(String, is_empty, sarray(), varray());
- // FIXME: Static function, not sure how to bind
- //bind_method(String, humanize_size, sarray("size"), varray());
bind_method(String, is_absolute_path, sarray(), varray());
bind_method(String, is_relative_path, sarray(), varray());
@@ -1635,17 +1631,15 @@ static void _register_variant_builtin_methods() {
bind_method(Color, to_argb64, sarray(), varray());
bind_method(Color, to_abgr64, sarray(), varray());
bind_method(Color, to_rgba64, sarray(), varray());
+ bind_method(Color, to_html, sarray("with_alpha"), varray(true));
bind_method(Color, clamp, sarray("min", "max"), varray(Color(0, 0, 0, 0), Color(1, 1, 1, 1)));
bind_method(Color, inverted, sarray(), varray());
bind_method(Color, lerp, sarray("to", "weight"), varray());
bind_method(Color, lightened, sarray("amount"), varray());
bind_method(Color, darkened, sarray("amount"), varray());
- bind_method(Color, to_html, sarray("with_alpha"), varray(true));
bind_method(Color, blend, sarray("over"), varray());
- // FIXME: Color is immutable, need to probably find a way to do this via constructor
- //ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0));
bind_method(Color, is_equal_approx, sarray("to"), varray());
bind_static_method(Color, hex, sarray("hex"), varray());
@@ -1657,6 +1651,7 @@ static void _register_variant_builtin_methods() {
bind_static_method(Color, get_named_color_name, sarray("idx"), varray());
bind_static_method(Color, get_named_color, sarray("idx"), varray());
bind_static_method(Color, from_string, sarray("str", "default"), varray());
+ bind_static_method(Color, from_hsv, sarray("h", "s", "v", "alpha"), varray(1.0));
bind_static_method(Color, from_rgbe9995, sarray("rgbe"), varray());
/* RID */
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index 666b582e39..e89bdd4faa 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -275,6 +275,10 @@ struct VariantUtilityFunctions {
return Math::wrapf(value, min, max);
}
+ static inline double pingpong(double value, double length) {
+ return Math::pingpong(value, length);
+ }
+
static inline Variant max(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (p_argcount < 2) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
@@ -1226,6 +1230,7 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(clampf, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(nearest_po2, sarray("value"), Variant::UTILITY_FUNC_TYPE_MATH);
+ FUNCBINDR(pingpong, sarray("value", "length"), Variant::UTILITY_FUNC_TYPE_MATH);
// Random
diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml
index ea49b6b634..345a769ca5 100644
--- a/doc/classes/@GlobalScope.xml
+++ b/doc/classes/@GlobalScope.xml
@@ -566,6 +566,26 @@
[b]Warning:[/b] Due to the way it is implemented, this function returns [code]0[/code] rather than [code]1[/code] for non-positive values of [code]value[/code] (in reality, 1 is the smallest integer power of 2).
</description>
</method>
+ <method name="pingpong">
+ <return type="float" />
+ <argument index="0" name="value" type="float" />
+ <argument index="1" name="length" type="float" />
+ <description>
+ Returns the [code]value[/code] wrapped between [code]0[/code] and the [code]length[/code]. If the limit is reached, the next value the function returned is decreased to the [code]0[/code] side or increased to the [code]length[/code] side (like a triangle wave). If [code]length[/code] is less than zero, it becomes positive.
+ [codeblock]
+ pingpong(-3.0, 3.0) # Returns 3
+ pingpong(-2.0, 3.0) # Returns 2
+ pingpong(-1.0, 3.0) # Returns 1
+ pingpong(0.0, 3.0) # Returns 0
+ pingpong(1.0, 3.0) # Returns 1
+ pingpong(2.0, 3.0) # Returns 2
+ pingpong(3.0, 3.0) # Returns 3
+ pingpong(4.0, 3.0) # Returns 2
+ pingpong(5.0, 3.0) # Returns 1
+ pingpong(6.0, 3.0) # Returns 0
+ [/codeblock]
+ </description>
+ </method>
<method name="posmod">
<return type="int" />
<argument index="0" name="x" type="int" />
diff --git a/doc/classes/AABB.xml b/doc/classes/AABB.xml
index f353cd19b8..15d146fba1 100644
--- a/doc/classes/AABB.xml
+++ b/doc/classes/AABB.xml
@@ -54,7 +54,22 @@
<return type="AABB" />
<argument index="0" name="to_point" type="Vector3" />
<description>
- Returns this [AABB] expanded to include a given point.
+ Returns a copy of this [AABB] expanded to include a given point.
+ [b]Example:[/b]
+ [codeblocks]
+ [gdscript]
+ # position (-3, 2, 0), size (1, 1, 1)
+ var box = AABB(Vector3(-3, 2, 0), Vector3(1, 1, 1))
+ # position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
+ var box2 = box.expand(Vector3(0, -1, 2))
+ [/gdscript]
+ [csharp]
+ // position (-3, 2, 0), size (1, 1, 1)
+ var box = new AABB(new Vector3(-3, 2, 0), new Vector3(1, 1, 1));
+ // position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
+ var box2 = box.Expand(new Vector3(0, -1, 2));
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_center" qualifiers="const">
diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml
index e3bb60f6de..dca943dec6 100644
--- a/doc/classes/Animation.xml
+++ b/doc/classes/Animation.xml
@@ -551,8 +551,8 @@
The total length of the animation (in seconds).
[b]Note:[/b] Length is not delimited by the last key, as this one may be before or after the end to ensure correct interpolation and looping.
</member>
- <member name="loop" type="bool" setter="set_loop" getter="has_loop" default="false">
- A flag indicating that the animation must loop. This is used for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.
+ <member name="loop_mode" type="int" setter="set_loop_mode" getter="get_loop_mode" enum="Animation.LoopMode" default="0">
+ Determines the behavior of both ends of the animation timeline during animation playback. This is used for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.
</member>
<member name="step" type="float" setter="set_step" getter="get_step" default="0.1">
The animation step value.
@@ -610,5 +610,14 @@
<constant name="UPDATE_CAPTURE" value="3" enum="UpdateMode">
Same as linear interpolation, but also interpolates from the current value (i.e. dynamically at runtime) if the first key isn't at 0 seconds.
</constant>
+ <constant name="LOOP_NONE" value="0" enum="LoopMode">
+ At both ends of the animation, the animation will stop playing.
+ </constant>
+ <constant name="LOOP_LINEAR" value="1" enum="LoopMode">
+ At both ends of the animation, the animation will be repeated without changing the playback direction.
+ </constant>
+ <constant name="LOOP_PINGPONG" value="2" enum="LoopMode">
+ Repeats playback and reverse playback at both ends of the animation.
+ </constant>
</constants>
</class>
diff --git a/doc/classes/AnimationNode.xml b/doc/classes/AnimationNode.xml
index 173ff43d2a..6bc44ea0a0 100644
--- a/doc/classes/AnimationNode.xml
+++ b/doc/classes/AnimationNode.xml
@@ -73,6 +73,7 @@
<argument index="2" name="delta" type="float" />
<argument index="3" name="seeked" type="bool" />
<argument index="4" name="blend" type="float" />
+ <argument index="5" name="pingponged" type="int" default="0" />
<description>
Blend an animation by [code]blend[/code] amount (name must be valid in the linked [AnimationPlayer]). A [code]time[/code] and [code]delta[/code] may be passed, as well as whether [code]seek[/code] happened.
</description>
diff --git a/doc/classes/AnimationNodeAnimation.xml b/doc/classes/AnimationNodeAnimation.xml
index 668a35226f..076e675007 100644
--- a/doc/classes/AnimationNodeAnimation.xml
+++ b/doc/classes/AnimationNodeAnimation.xml
@@ -15,5 +15,14 @@
<member name="animation" type="StringName" setter="set_animation" getter="get_animation" default="&amp;&quot;&quot;">
Animation to use as an output. It is one of the animations provided by [member AnimationTree.anim_player].
</member>
+ <member name="play_mode" type="int" setter="set_play_mode" getter="get_play_mode" enum="AnimationNodeAnimation.PlayMode" default="0">
+ Determines the playback direction of the animation.
+ </member>
</members>
+ <constants>
+ <constant name="PLAY_MODE_FORWARD" value="0" enum="PlayMode">
+ </constant>
+ <constant name="PLAY_MODE_BACKWARD" value="1" enum="PlayMode">
+ </constant>
+ </constants>
</class>
diff --git a/doc/classes/Area2D.xml b/doc/classes/Area2D.xml
index c6a3f87042..8abdaac45f 100644
--- a/doc/classes/Area2D.xml
+++ b/doc/classes/Area2D.xml
@@ -50,6 +50,9 @@
The rate at which objects stop spinning in this area. Represents the angular velocity lost per second.
See [member ProjectSettings.physics/2d/default_angular_damp] for more details about damping.
</member>
+ <member name="angular_damp_space_override" type="int" setter="set_angular_damp_space_override_mode" getter="get_angular_damp_space_override_mode" enum="Area2D.SpaceOverride" default="0">
+ Override mode for angular damping calculations within this area. See [enum SpaceOverride] for possible values.
+ </member>
<member name="audio_bus_name" type="StringName" setter="set_audio_bus_name" getter="get_audio_bus_name" default="&amp;&quot;Master&quot;">
The name of the area's audio bus.
</member>
@@ -57,21 +60,30 @@
If [code]true[/code], the area's audio bus overrides the default audio bus.
</member>
<member name="gravity" type="float" setter="set_gravity" getter="get_gravity" default="980.0">
- The area's gravity intensity (in pixels per second squared). This value multiplies the gravity vector. This is useful to alter the force of gravity without altering its direction.
+ The area's gravity intensity (in pixels per second squared). This value multiplies the gravity direction. This is useful to alter the force of gravity without altering its direction.
</member>
- <member name="gravity_distance_scale" type="float" setter="set_gravity_distance_scale" getter="get_gravity_distance_scale" default="0.0">
- The falloff factor for point gravity. The greater the value, the faster gravity decreases with distance.
+ <member name="gravity_direction" type="Vector2" setter="set_gravity_direction" getter="get_gravity_direction" default="Vector2(0, 1)">
+ The area's gravity vector (not normalized).
</member>
<member name="gravity_point" type="bool" setter="set_gravity_is_point" getter="is_gravity_a_point" default="false">
- If [code]true[/code], gravity is calculated from a point (set via [member gravity_vec]). See also [member space_override].
+ If [code]true[/code], gravity is calculated from a point (set via [member gravity_point_center]). See also [member gravity_space_override].
</member>
- <member name="gravity_vec" type="Vector2" setter="set_gravity_vector" getter="get_gravity_vector" default="Vector2(0, 1)">
- The area's gravity vector (not normalized). If gravity is a point (see [member gravity_point]), this will be the point of attraction.
+ <member name="gravity_point_center" type="Vector2" setter="set_gravity_point_center" getter="get_gravity_point_center" default="Vector2(0, 1)">
+ If gravity is a point (see [member gravity_point]), this will be the point of attraction.
+ </member>
+ <member name="gravity_point_distance_scale" type="float" setter="set_gravity_point_distance_scale" getter="get_gravity_point_distance_scale" default="0.0">
+ The falloff factor for point gravity. The greater the value, the faster gravity decreases with distance.
+ </member>
+ <member name="gravity_space_override" type="int" setter="set_gravity_space_override_mode" getter="get_gravity_space_override_mode" enum="Area2D.SpaceOverride" default="0">
+ Override mode for gravity calculations within this area. See [enum SpaceOverride] for possible values.
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.1">
The rate at which objects stop moving in this area. Represents the linear velocity lost per second.
See [member ProjectSettings.physics/2d/default_linear_damp] for more details about damping.
</member>
+ <member name="linear_damp_space_override" type="int" setter="set_linear_damp_space_override_mode" getter="get_linear_damp_space_override_mode" enum="Area2D.SpaceOverride" default="0">
+ Override mode for linear damping calculations within this area. See [enum SpaceOverride] for possible values.
+ </member>
<member name="monitorable" type="bool" setter="set_monitorable" getter="is_monitorable" default="true">
If [code]true[/code], other monitoring areas can detect this area.
</member>
@@ -81,9 +93,6 @@
<member name="priority" type="float" setter="set_priority" getter="get_priority" default="0.0">
The area's priority. Higher priority areas are processed first.
</member>
- <member name="space_override" type="int" setter="set_space_override_mode" getter="get_space_override_mode" enum="Area2D.SpaceOverride" default="0">
- Override mode for gravity and damping calculations within this area. See [enum SpaceOverride] for possible values.
- </member>
</members>
<signals>
<signal name="area_entered">
diff --git a/doc/classes/Area3D.xml b/doc/classes/Area3D.xml
index 571fd8cad3..450ed44307 100644
--- a/doc/classes/Area3D.xml
+++ b/doc/classes/Area3D.xml
@@ -48,6 +48,9 @@
The rate at which objects stop spinning in this area. Represents the angular velocity lost per second.
See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping.
</member>
+ <member name="angular_damp_space_override" type="int" setter="set_angular_damp_space_override_mode" getter="get_angular_damp_space_override_mode" enum="Area3D.SpaceOverride" default="0">
+ Override mode for angular damping calculations within this area. See [enum SpaceOverride] for possible values.
+ </member>
<member name="audio_bus_name" type="StringName" setter="set_audio_bus_name" getter="get_audio_bus_name" default="&amp;&quot;Master&quot;">
The name of the area's audio bus.
</member>
@@ -55,21 +58,30 @@
If [code]true[/code], the area's audio bus overrides the default audio bus.
</member>
<member name="gravity" type="float" setter="set_gravity" getter="get_gravity" default="9.8">
- The area's gravity intensity (in meters per second squared). This value multiplies the gravity vector. This is useful to alter the force of gravity without altering its direction.
+ The area's gravity intensity (in meters per second squared). This value multiplies the gravity direction. This is useful to alter the force of gravity without altering its direction.
</member>
- <member name="gravity_distance_scale" type="float" setter="set_gravity_distance_scale" getter="get_gravity_distance_scale" default="0.0">
- The falloff factor for point gravity. The greater the value, the faster gravity decreases with distance.
+ <member name="gravity_direction" type="Vector3" setter="set_gravity_direction" getter="get_gravity_direction" default="Vector3(0, -1, 0)">
+ The area's gravity vector (not normalized).
</member>
<member name="gravity_point" type="bool" setter="set_gravity_is_point" getter="is_gravity_a_point" default="false">
- If [code]true[/code], gravity is calculated from a point (set via [member gravity_vec]). See also [member space_override].
+ If [code]true[/code], gravity is calculated from a point (set via [member gravity_point_center]). See also [member gravity_space_override].
</member>
- <member name="gravity_vec" type="Vector3" setter="set_gravity_vector" getter="get_gravity_vector" default="Vector3(0, -1, 0)">
- The area's gravity vector (not normalized). If gravity is a point (see [member gravity_point]), this will be the point of attraction.
+ <member name="gravity_point_center" type="Vector3" setter="set_gravity_point_center" getter="get_gravity_point_center" default="Vector3(0, -1, 0)">
+ If gravity is a point (see [member gravity_point]), this will be the point of attraction.
+ </member>
+ <member name="gravity_point_distance_scale" type="float" setter="set_gravity_point_distance_scale" getter="get_gravity_point_distance_scale" default="0.0">
+ The falloff factor for point gravity. The greater the value, the faster gravity decreases with distance.
+ </member>
+ <member name="gravity_space_override" type="int" setter="set_gravity_space_override_mode" getter="get_gravity_space_override_mode" enum="Area3D.SpaceOverride" default="0">
+ Override mode for gravity calculations within this area. See [enum SpaceOverride] for possible values.
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.1">
The rate at which objects stop moving in this area. Represents the linear velocity lost per second.
See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping.
</member>
+ <member name="linear_damp_space_override" type="int" setter="set_linear_damp_space_override_mode" getter="get_linear_damp_space_override_mode" enum="Area3D.SpaceOverride" default="0">
+ Override mode for linear damping calculations within this area. See [enum SpaceOverride] for possible values.
+ </member>
<member name="monitorable" type="bool" setter="set_monitorable" getter="is_monitorable" default="true">
If [code]true[/code], other monitoring areas can detect this area.
</member>
@@ -91,9 +103,6 @@
<member name="reverb_bus_uniformity" type="float" setter="set_reverb_uniformity" getter="get_reverb_uniformity" default="0.0">
The degree to which this area's reverb is a uniform effect. Ranges from [code]0[/code] to [code]1[/code] with [code]0.1[/code] precision.
</member>
- <member name="space_override" type="int" setter="set_space_override_mode" getter="get_space_override_mode" enum="Area3D.SpaceOverride" default="0">
- Override mode for gravity and damping calculations within this area. See [enum SpaceOverride] for possible values.
- </member>
<member name="wind_attenuation_factor" type="float" setter="set_wind_attenuation_factor" getter="get_wind_attenuation_factor" default="0.0">
The exponential rate at which wind force decreases with distance from its origin.
</member>
diff --git a/doc/classes/AudioStreamSample.xml b/doc/classes/AudioStreamSample.xml
index 7e1155d89b..df7b5ff1c7 100644
--- a/doc/classes/AudioStreamSample.xml
+++ b/doc/classes/AudioStreamSample.xml
@@ -61,7 +61,7 @@
<constant name="LOOP_FORWARD" value="1" enum="LoopMode">
Audio loops the data between [member loop_begin] and [member loop_end], playing forward only.
</constant>
- <constant name="LOOP_PING_PONG" value="2" enum="LoopMode">
+ <constant name="LOOP_PINGPONG" value="2" enum="LoopMode">
Audio loops the data between [member loop_begin] and [member loop_end], playing back and forth.
</constant>
<constant name="LOOP_BACKWARD" value="3" enum="LoopMode">
diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml
index 71ec225cf6..650f10a97f 100644
--- a/doc/classes/Color.xml
+++ b/doc/classes/Color.xml
@@ -147,6 +147,24 @@
<description>
</description>
</method>
+ <method name="from_hsv" qualifiers="static">
+ <return type="Color" />
+ <argument index="0" name="h" type="float" />
+ <argument index="1" name="s" type="float" />
+ <argument index="2" name="v" type="float" />
+ <argument index="3" name="alpha" type="float" default="1.0" />
+ <description>
+ Constructs a color from an [url=https://en.wikipedia.org/wiki/HSL_and_HSV]HSV profile[/url]. [code]h[/code] (hue), [code]s[/code] (saturation), and [code]v[/code] (value) are typically between 0 and 1.
+ [codeblocks]
+ [gdscript]
+ var c = Color.from_hsv(0.58, 0.5, 0.79, 0.8)
+ [/gdscript]
+ [csharp]
+ var c = Color.FromHsv(0.58f, 0.5f, 0.79f, 0.8f);
+ [/csharp]
+ [/codeblocks]
+ </description>
+ </method>
<method name="from_rgbe9995" qualifiers="static">
<return type="Color" />
<argument index="0" name="rgbe" type="int" />
diff --git a/doc/classes/EditorInspectorPlugin.xml b/doc/classes/EditorInspectorPlugin.xml
index f65e974d47..bc5df47d57 100644
--- a/doc/classes/EditorInspectorPlugin.xml
+++ b/doc/classes/EditorInspectorPlugin.xml
@@ -25,8 +25,9 @@
</method>
<method name="_parse_begin" qualifiers="virtual">
<return type="void" />
+ <argument index="0" name="object" type="Object" />
<description>
- Called to allow adding controls at the beginning of the list.
+ Called to allow adding controls at the beginning of the property list for [code]object[/code].
</description>
</method>
<method name="_parse_category" qualifiers="virtual">
@@ -34,12 +35,22 @@
<argument index="0" name="object" type="Object" />
<argument index="1" name="category" type="String" />
<description>
+ Called to allow adding controls at the beginning of a category in the property list for [code]object[/code].
</description>
</method>
<method name="_parse_end" qualifiers="virtual">
<return type="void" />
+ <argument index="0" name="object" type="Object" />
+ <description>
+ Called to allow adding controls at the end of the property list for [code]object[/code].
+ </description>
+ </method>
+ <method name="_parse_group" qualifiers="virtual">
+ <return type="void" />
+ <argument index="0" name="object" type="Object" />
+ <argument index="1" name="group" type="String" />
<description>
- Called to allow adding controls at the end of the list.
+ Called to allow adding controls at the beginning of a group or a sub-group in the property list for [code]object[/code].
</description>
</method>
<method name="_parse_property" qualifiers="virtual">
@@ -52,7 +63,7 @@
<argument index="5" name="usage_flags" type="int" />
<argument index="6" name="wide" type="bool" />
<description>
- Called to allow adding property specific editors to the inspector. Usually these inherit [EditorProperty]. Returning [code]true[/code] removes the built-in editor for this property, otherwise allows to insert a custom editor before the built-in one.
+ Called to allow adding property-specific editors to the property list for [code]object[/code]. The added editor control must extend [EditorProperty]. Returning [code]true[/code] removes the built-in editor for this property, otherwise allows to insert a custom editor before the built-in one.
</description>
</method>
<method name="add_custom_control">
diff --git a/doc/classes/NavigationPolygon.xml b/doc/classes/NavigationPolygon.xml
index 5b5b7c42ef..7ecdca8793 100644
--- a/doc/classes/NavigationPolygon.xml
+++ b/doc/classes/NavigationPolygon.xml
@@ -28,7 +28,7 @@
var polygon = NavigationPolygon.new()
var vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
polygon.vertices = vertices
- var indices = PackedInt32Array(0, 3, 1)
+ var indices = PackedInt32Array([0, 1, 2, 3])
polygon.add_polygon(indices)
$NavigationRegion2D.navpoly = polygon
[/gdscript]
@@ -36,7 +36,7 @@
var polygon = new NavigationPolygon();
var vertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
polygon.Vertices = vertices;
- var indices = new int[] { 0, 3, 1 };
+ var indices = new int[] { 0, 1, 2, 3 };
polygon.AddPolygon(indices);
GetNode&lt;NavigationRegion2D&gt;("NavigationRegion2D").Navpoly = polygon;
[/csharp]
diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml
index 843db8c174..3745b394e0 100644
--- a/doc/classes/Node.xml
+++ b/doc/classes/Node.xml
@@ -228,11 +228,6 @@
If [code]include_internal[/code] is [code]false[/code], the returned array won't include internal children (see [code]internal[/code] parameter in [method add_child]).
</description>
</method>
- <method name="get_editor_description" qualifiers="const">
- <return type="String" />
- <description>
- </description>
- </method>
<method name="get_groups" qualifiers="const">
<return type="Array" />
<description>
@@ -618,12 +613,6 @@
Sets the editable children state of [code]node[/code] relative to this node. This method is only intended for use with editor tooling.
</description>
</method>
- <method name="set_editor_description">
- <return type="void" />
- <argument index="0" name="editor_description" type="String" />
- <description>
- </description>
- </method>
<method name="set_multiplayer_authority">
<return type="void" />
<argument index="0" name="id" type="int" />
@@ -702,6 +691,9 @@
<member name="custom_multiplayer" type="MultiplayerAPI" setter="set_custom_multiplayer" getter="get_custom_multiplayer">
The override to the default [MultiplayerAPI]. Set to [code]null[/code] to use the default [SceneTree] one.
</member>
+ <member name="editor_description" type="String" setter="set_editor_description" getter="get_editor_description" default="&quot;&quot;">
+ Add a custom description to a node.
+ </member>
<member name="multiplayer" type="MultiplayerAPI" setter="" getter="get_multiplayer">
The [MultiplayerAPI] instance associated with this node. Either the [member custom_multiplayer], or the default SceneTree one (if inside tree).
</member>
diff --git a/doc/classes/PhysicsBody2D.xml b/doc/classes/PhysicsBody2D.xml
index e108ab6298..7775cfb2f9 100644
--- a/doc/classes/PhysicsBody2D.xml
+++ b/doc/classes/PhysicsBody2D.xml
@@ -30,7 +30,7 @@
<argument index="2" name="safe_margin" type="float" default="0.08" />
<description>
Moves the body along the vector [code]linear_velocity[/code]. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
- The body will stop if it collides. Returns a [KinematicCollision2D], which contains information about the collision.
+ The body will stop if it collides. Returns a [KinematicCollision2D], which contains information about the collision when stopped, or when touching another body along the motion.
If [code]test_only[/code] is [code]true[/code], the body does not move but the would-be collision information is given.
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody2D.collision/safe_margin] for more details).
</description>
@@ -50,8 +50,8 @@
<argument index="3" name="safe_margin" type="float" default="0.08" />
<description>
Checks for collisions without moving the body. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
- Virtually sets the node's position, scale and rotation to that of the given [Transform2D], then tries to move the body along the vector [code]linear_velocity[/code]. Returns [code]true[/code] if a collision would occur.
- [code]collision[/code] is an optional object of type [KinematicCollision2D], which contains additional information about the collision (should there be one).
+ Virtually sets the node's position, scale and rotation to that of the given [Transform2D], then tries to move the body along the vector [code]linear_velocity[/code]. Returns [code]true[/code] if a collision would stop the body from moving along the whole path.
+ [code]collision[/code] is an optional object of type [KinematicCollision2D], which contains additional information about the collision when stopped, or when touching another body along the motion.
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody2D.collision/safe_margin] for more details).
</description>
</method>
diff --git a/doc/classes/PhysicsBody3D.xml b/doc/classes/PhysicsBody3D.xml
index 8718c0caa2..9cf587f2e0 100644
--- a/doc/classes/PhysicsBody3D.xml
+++ b/doc/classes/PhysicsBody3D.xml
@@ -38,7 +38,7 @@
<argument index="3" name="max_collisions" type="int" default="1" />
<description>
Moves the body along the vector [code]linear_velocity[/code]. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
- The body will stop if it collides. Returns a [KinematicCollision3D], which contains information about the collision.
+ The body will stop if it collides. Returns a [KinematicCollision3D], which contains information about the collision when stopped, or when touching another body along the motion.
If [code]test_only[/code] is [code]true[/code], the body does not move but the would-be collision information is given.
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody3D.collision/safe_margin] for more details).
[code]max_collisions[/code] allows to retrieve more than one collision result.
@@ -68,8 +68,8 @@
<argument index="4" name="max_collisions" type="int" default="1" />
<description>
Checks for collisions without moving the body. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
- Virtually sets the node's position, scale and rotation to that of the given [Transform3D], then tries to move the body along the vector [code]linear_velocity[/code]. Returns [code]true[/code] if a collision would occur.
- [code]collision[/code] is an optional object of type [KinematicCollision3D], which contains additional information about the collision (should there be one).
+ Virtually sets the node's position, scale and rotation to that of the given [Transform3D], then tries to move the body along the vector [code]linear_velocity[/code]. Returns [code]true[/code] if a collision would stop the body from moving along the whole path.
+ [code]collision[/code] is an optional object of type [KinematicCollision3D], which contains additional information about the collision when stopped, or when touching another body along the motion.
[code]safe_margin[/code] is the extra margin used for collision recovery (see [member CharacterBody3D.collision/safe_margin] for more details).
[code]max_collisions[/code] allows to retrieve more than one collision result.
</description>
diff --git a/doc/classes/PhysicsDirectSpaceState2D.xml b/doc/classes/PhysicsDirectSpaceState2D.xml
index 5892ef266f..107d276df2 100644
--- a/doc/classes/PhysicsDirectSpaceState2D.xml
+++ b/doc/classes/PhysicsDirectSpaceState2D.xml
@@ -64,7 +64,7 @@
Intersects a ray in a given space. Ray position and other parameters are defined through [PhysicsRayQueryParameters2D]. The returned object is a dictionary with the following fields:
[code]collider[/code]: The colliding object.
[code]collider_id[/code]: The colliding object's ID.
- [code]normal[/code]: The object's surface normal at the intersection point.
+ [code]normal[/code]: The object's surface normal at the intersection point, or [code]Vector2(0, 0)[/code] if the ray starts inside the shape and [member PhysicsRayQueryParameters2D.hit_from_inside] is [code]true[/code].
[code]position[/code]: The intersection point.
[code]rid[/code]: The intersecting object's [RID].
[code]shape[/code]: The shape index of the colliding shape.
diff --git a/doc/classes/PhysicsDirectSpaceState3D.xml b/doc/classes/PhysicsDirectSpaceState3D.xml
index 6a7fe46518..349ce31ab4 100644
--- a/doc/classes/PhysicsDirectSpaceState3D.xml
+++ b/doc/classes/PhysicsDirectSpaceState3D.xml
@@ -65,7 +65,7 @@
Intersects a ray in a given space. Ray position and other parameters are defined through [PhysicsRayQueryParameters3D]. The returned object is a dictionary with the following fields:
[code]collider[/code]: The colliding object.
[code]collider_id[/code]: The colliding object's ID.
- [code]normal[/code]: The object's surface normal at the intersection point.
+ [code]normal[/code]: The object's surface normal at the intersection point, or [code]Vector3(0, 0, 0)[/code] if the ray starts inside the shape and [member PhysicsRayQueryParameters3D.hit_from_inside] is [code]true[/code].
[code]position[/code]: The intersection point.
[code]rid[/code]: The intersecting object's [RID].
[code]shape[/code]: The shape index of the colliding shape.
diff --git a/doc/classes/PhysicsRayQueryParameters2D.xml b/doc/classes/PhysicsRayQueryParameters2D.xml
index 0e99e47286..b71b48f223 100644
--- a/doc/classes/PhysicsRayQueryParameters2D.xml
+++ b/doc/classes/PhysicsRayQueryParameters2D.xml
@@ -24,6 +24,9 @@
<member name="from" type="Vector2" setter="set_from" getter="get_from" default="Vector2(0, 0)">
The starting point of the ray being queried for, in global coordinates.
</member>
+ <member name="hit_from_inside" type="bool" setter="set_hit_from_inside" getter="is_hit_from_inside_enabled" default="false">
+ If [code]true[/code], the query will detect a hit when starting inside shapes. In this case the collision normal will be [code]Vector2(0, 0)[/code]. Does not affect concave polygon shapes.
+ </member>
<member name="to" type="Vector2" setter="set_to" getter="get_to" default="Vector2(0, 0)">
The ending point of the ray being queried for, in global coordinates.
</member>
diff --git a/doc/classes/PhysicsRayQueryParameters3D.xml b/doc/classes/PhysicsRayQueryParameters3D.xml
index dbd09e5128..3085ff3b35 100644
--- a/doc/classes/PhysicsRayQueryParameters3D.xml
+++ b/doc/classes/PhysicsRayQueryParameters3D.xml
@@ -24,6 +24,12 @@
<member name="from" type="Vector3" setter="set_from" getter="get_from" default="Vector3(0, 0, 0)">
The starting point of the ray being queried for, in global coordinates.
</member>
+ <member name="hit_back_faces" type="bool" setter="set_hit_back_faces" getter="is_hit_back_faces_enabled" default="true">
+ If [code]true[/code], the query will hit back faces with concave polygon shapes with back face enabled or heightmap shapes.
+ </member>
+ <member name="hit_from_inside" type="bool" setter="set_hit_from_inside" getter="is_hit_from_inside_enabled" default="false">
+ If [code]true[/code], the query will detect a hit when starting inside shapes. In this case the collision normal will be [code]Vector3(0, 0, 0)[/code]. Does not affect concave polygon shapes or heightmap shapes.
+ </member>
<member name="to" type="Vector3" setter="set_to" getter="get_to" default="Vector3(0, 0, 0)">
The ending point of the ray being queried for, in global coordinates.
</member>
diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml
index 7368fe06ab..868b58ea9f 100644
--- a/doc/classes/PhysicsServer2D.xml
+++ b/doc/classes/PhysicsServer2D.xml
@@ -98,13 +98,6 @@
Returns the space assigned to the area.
</description>
</method>
- <method name="area_get_space_override_mode" qualifiers="const">
- <return type="int" enum="PhysicsServer2D.AreaSpaceOverrideMode" />
- <argument index="0" name="area" type="RID" />
- <description>
- Returns the space override mode for the area.
- </description>
- </method>
<method name="area_get_transform" qualifiers="const">
<return type="Transform2D" />
<argument index="0" name="area" type="RID" />
@@ -207,14 +200,6 @@
Assigns a space to the area.
</description>
</method>
- <method name="area_set_space_override_mode">
- <return type="void" />
- <argument index="0" name="area" type="RID" />
- <argument index="1" name="mode" type="int" enum="PhysicsServer2D.AreaSpaceOverrideMode" />
- <description>
- Sets the space override mode for the area. See [enum AreaSpaceOverrideMode] for a list of available modes.
- </description>
- </method>
<method name="area_set_transform">
<return type="void" />
<argument index="0" name="area" type="RID" />
@@ -346,7 +331,7 @@
<return type="PhysicsDirectBodyState2D" />
<argument index="0" name="body" type="RID" />
<description>
- Returns the [PhysicsDirectBodyState2D] of the body.
+ Returns the [PhysicsDirectBodyState2D] of the body. Returns [code]null[/code] if the body is destroyed or removed from the physics space.
</description>
</method>
<method name="body_get_max_contacts_reported" qualifiers="const">
@@ -855,28 +840,37 @@
<constant name="SHAPE_CUSTOM" value="8" enum="ShapeType">
This constant is used internally by the engine. Any attempt to create this kind of shape results in an error.
</constant>
- <constant name="AREA_PARAM_GRAVITY" value="0" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_OVERRIDE_MODE" value="0" enum="AreaParameter">
+ Constant to set/get gravity override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
+ </constant>
+ <constant name="AREA_PARAM_GRAVITY" value="1" enum="AreaParameter">
Constant to set/get gravity strength in an area.
</constant>
- <constant name="AREA_PARAM_GRAVITY_VECTOR" value="1" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_VECTOR" value="2" enum="AreaParameter">
Constant to set/get gravity vector/center in an area.
</constant>
- <constant name="AREA_PARAM_GRAVITY_IS_POINT" value="2" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_IS_POINT" value="3" enum="AreaParameter">
Constant to set/get whether the gravity vector of an area is a direction, or a center point.
</constant>
- <constant name="AREA_PARAM_GRAVITY_DISTANCE_SCALE" value="3" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_DISTANCE_SCALE" value="4" enum="AreaParameter">
Constant to set/get the falloff factor for point gravity of an area. The greater this value is, the faster the strength of gravity decreases with the square of distance.
</constant>
- <constant name="AREA_PARAM_GRAVITY_POINT_ATTENUATION" value="4" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_POINT_ATTENUATION" value="5" enum="AreaParameter">
This constant was used to set/get the falloff factor for point gravity. It has been superseded by [constant AREA_PARAM_GRAVITY_DISTANCE_SCALE].
</constant>
- <constant name="AREA_PARAM_LINEAR_DAMP" value="5" enum="AreaParameter">
- Constant to set/get the linear dampening factor of an area.
+ <constant name="AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE" value="6" enum="AreaParameter">
+ Constant to set/get linear damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
+ </constant>
+ <constant name="AREA_PARAM_LINEAR_DAMP" value="7" enum="AreaParameter">
+ Constant to set/get the linear damping factor of an area.
+ </constant>
+ <constant name="AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE" value="8" enum="AreaParameter">
+ Constant to set/get angular damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
</constant>
- <constant name="AREA_PARAM_ANGULAR_DAMP" value="6" enum="AreaParameter">
- Constant to set/get the angular dampening factor of an area.
+ <constant name="AREA_PARAM_ANGULAR_DAMP" value="9" enum="AreaParameter">
+ Constant to set/get the angular damping factor of an area.
</constant>
- <constant name="AREA_PARAM_PRIORITY" value="7" enum="AreaParameter">
+ <constant name="AREA_PARAM_PRIORITY" value="10" enum="AreaParameter">
Constant to set/get the priority (order of processing) of an area.
</constant>
<constant name="AREA_SPACE_OVERRIDE_DISABLED" value="0" enum="AreaSpaceOverrideMode">
diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml
index 0f02cdf92f..dd8003be1d 100644
--- a/doc/classes/PhysicsServer3D.xml
+++ b/doc/classes/PhysicsServer3D.xml
@@ -85,13 +85,6 @@
Returns the space assigned to the area.
</description>
</method>
- <method name="area_get_space_override_mode" qualifiers="const">
- <return type="int" enum="PhysicsServer3D.AreaSpaceOverrideMode" />
- <argument index="0" name="area" type="RID" />
- <description>
- Returns the space override mode for the area.
- </description>
- </method>
<method name="area_get_transform" qualifiers="const">
<return type="Transform3D" />
<argument index="0" name="area" type="RID" />
@@ -201,14 +194,6 @@
Assigns a space to the area.
</description>
</method>
- <method name="area_set_space_override_mode">
- <return type="void" />
- <argument index="0" name="area" type="RID" />
- <argument index="1" name="mode" type="int" enum="PhysicsServer3D.AreaSpaceOverrideMode" />
- <description>
- Sets the space override mode for the area. The modes are described in the [enum AreaSpaceOverrideMode] constants.
- </description>
- </method>
<method name="area_set_transform">
<return type="void" />
<argument index="0" name="area" type="RID" />
@@ -320,7 +305,7 @@
<return type="PhysicsDirectBodyState3D" />
<argument index="0" name="body" type="RID" />
<description>
- Returns the [PhysicsDirectBodyState3D] of the body.
+ Returns the [PhysicsDirectBodyState3D] of the body. Returns [code]null[/code] if the body is destroyed or removed from the physics space.
</description>
</method>
<method name="body_get_max_contacts_reported" qualifiers="const">
@@ -1211,40 +1196,49 @@
<constant name="SHAPE_CUSTOM" value="10" enum="ShapeType">
This constant is used internally by the engine. Any attempt to create this kind of shape results in an error.
</constant>
- <constant name="AREA_PARAM_GRAVITY" value="0" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_OVERRIDE_MODE" value="0" enum="AreaParameter">
+ Constant to set/get gravity override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
+ </constant>
+ <constant name="AREA_PARAM_GRAVITY" value="1" enum="AreaParameter">
Constant to set/get gravity strength in an area.
</constant>
- <constant name="AREA_PARAM_GRAVITY_VECTOR" value="1" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_VECTOR" value="2" enum="AreaParameter">
Constant to set/get gravity vector/center in an area.
</constant>
- <constant name="AREA_PARAM_GRAVITY_IS_POINT" value="2" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_IS_POINT" value="3" enum="AreaParameter">
Constant to set/get whether the gravity vector of an area is a direction, or a center point.
</constant>
- <constant name="AREA_PARAM_GRAVITY_DISTANCE_SCALE" value="3" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_DISTANCE_SCALE" value="4" enum="AreaParameter">
Constant to set/get the falloff factor for point gravity of an area. The greater this value is, the faster the strength of gravity decreases with the square of distance.
</constant>
- <constant name="AREA_PARAM_GRAVITY_POINT_ATTENUATION" value="4" enum="AreaParameter">
+ <constant name="AREA_PARAM_GRAVITY_POINT_ATTENUATION" value="5" enum="AreaParameter">
This constant was used to set/get the falloff factor for point gravity. It has been superseded by [constant AREA_PARAM_GRAVITY_DISTANCE_SCALE].
</constant>
- <constant name="AREA_PARAM_LINEAR_DAMP" value="5" enum="AreaParameter">
- Constant to set/get the linear dampening factor of an area.
+ <constant name="AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE" value="6" enum="AreaParameter">
+ Constant to set/get linear damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
+ </constant>
+ <constant name="AREA_PARAM_LINEAR_DAMP" value="7" enum="AreaParameter">
+ Constant to set/get the linear damping factor of an area.
+ </constant>
+ <constant name="AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE" value="8" enum="AreaParameter">
+ Constant to set/get angular damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
</constant>
- <constant name="AREA_PARAM_ANGULAR_DAMP" value="6" enum="AreaParameter">
- Constant to set/get the angular dampening factor of an area.
+ <constant name="AREA_PARAM_ANGULAR_DAMP" value="9" enum="AreaParameter">
+ Constant to set/get the angular damping factor of an area.
</constant>
- <constant name="AREA_PARAM_PRIORITY" value="7" enum="AreaParameter">
+ <constant name="AREA_PARAM_PRIORITY" value="10" enum="AreaParameter">
Constant to set/get the priority (order of processing) of an area.
</constant>
- <constant name="AREA_PARAM_WIND_FORCE_MAGNITUDE" value="8" enum="AreaParameter">
+ <constant name="AREA_PARAM_WIND_FORCE_MAGNITUDE" value="11" enum="AreaParameter">
Constant to set/get the magnitude of area-specific wind force.
</constant>
- <constant name="AREA_PARAM_WIND_SOURCE" value="9" enum="AreaParameter">
+ <constant name="AREA_PARAM_WIND_SOURCE" value="12" enum="AreaParameter">
Constant to set/get the 3D vector that specifies the origin from which an area-specific wind blows.
</constant>
- <constant name="AREA_PARAM_WIND_DIRECTION" value="10" enum="AreaParameter">
+ <constant name="AREA_PARAM_WIND_DIRECTION" value="13" enum="AreaParameter">
Constant to set/get the 3D vector that specifies the direction in which an area-specific wind blows.
</constant>
- <constant name="AREA_PARAM_WIND_ATTENUATION_FACTOR" value="11" enum="AreaParameter">
+ <constant name="AREA_PARAM_WIND_ATTENUATION_FACTOR" value="14" enum="AreaParameter">
Constant to set/get the exponential rate at which wind force decreases with distance from its origin.
</constant>
<constant name="AREA_SPACE_OVERRIDE_DISABLED" value="0" enum="AreaSpaceOverrideMode">
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 30409814d2..abdd8138ad 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -289,7 +289,9 @@
Safer override for [member audio/driver/mix_rate] in the Web platform. Here [code]0[/code] means "let the browser choose" (since some browsers do not like forcing the mix rate).
</member>
<member name="audio/driver/output_latency" type="int" setter="" getter="" default="15">
- Output latency in milliseconds for audio. Lower values will result in lower audio latency at the cost of increased CPU usage. Low values may result in audible cracking on slower hardware.
+ Specifies the preferred output latency in milliseconds for audio. Lower values will result in lower audio latency at the cost of increased CPU usage. Low values may result in audible cracking on slower hardware.
+ Audio output latency may be constrained by the host operating system and audio hardware drivers. If the host can not provide the specified audio output latency then Godot will attempt to use the nearest latency allowed by the host. As such you should always use [method AudioServer.get_output_latency] to determine the actual audio output latency.
+ [b]Note:[/b] This setting is ignored on all versions of Windows prior to Windows 10.
</member>
<member name="audio/driver/output_latency.web" type="int" setter="" getter="" default="50">
Safer override for [member audio/driver/output_latency] in the Web platform, to avoid audio issues especially on mobile devices.
@@ -1315,9 +1317,9 @@
</member>
<member name="mono/profiler/enabled" type="bool" setter="" getter="" default="false">
</member>
- <member name="mono/project/auto_update_project" type="bool" setter="" getter="" default="true">
- </member>
- <member name="mono/unhandled_exception_policy" type="int" setter="" getter="" default="0">
+ <member name="mono/runtime/unhandled_exception_policy" type="int" setter="" getter="" default="0">
+ The policy to use for unhandled Mono (C#) exceptions. The default "Terminate Application" exits the project as soon as an unhandled exception is thrown. "Log Error" logs an error message to the console instead, and will not interrupt the project execution when an unhandled exception is thrown.
+ [b]Note:[/b] The unhandled exception policy is always set to "Log Error" in the editor, which also includes C# [code]tool[/code] scripts running within the editor as well as editor plugin code.
</member>
<member name="navigation/2d/default_cell_size" type="int" setter="" getter="" default="10">
Default cell size for 2D navigation maps. See [method NavigationServer2D.map_set_cell_size].
diff --git a/doc/classes/RayCast2D.xml b/doc/classes/RayCast2D.xml
index 592c074a77..d7540ef206 100644
--- a/doc/classes/RayCast2D.xml
+++ b/doc/classes/RayCast2D.xml
@@ -63,7 +63,7 @@
<method name="get_collision_normal" qualifiers="const">
<return type="Vector2" />
<description>
- Returns the normal of the intersecting object's shape at the collision point.
+ Returns the normal of the intersecting object's shape at the collision point, or [code]Vector2(0, 0)[/code] if the ray starts inside the shape and [member hit_from_inside] is [code]true[/code].
</description>
</method>
<method name="get_collision_point" qualifiers="const">
@@ -118,6 +118,9 @@
<member name="exclude_parent" type="bool" setter="set_exclude_parent_body" getter="get_exclude_parent_body" default="true">
If [code]true[/code], the parent node will be excluded from collision detection.
</member>
+ <member name="hit_from_inside" type="bool" setter="set_hit_from_inside" getter="is_hit_from_inside_enabled" default="false">
+ If [code]true[/code], the ray will detect a hit when starting inside shapes. In this case the collision normal will be [code]Vector2(0, 0)[/code]. Does not affect concave polygon shapes.
+ </member>
<member name="target_position" type="Vector2" setter="set_target_position" getter="get_target_position" default="Vector2(0, 50)">
The ray's destination point, relative to the RayCast's [code]position[/code].
</member>
diff --git a/doc/classes/RayCast3D.xml b/doc/classes/RayCast3D.xml
index c7253e81c4..f15643c93f 100644
--- a/doc/classes/RayCast3D.xml
+++ b/doc/classes/RayCast3D.xml
@@ -65,7 +65,7 @@
<method name="get_collision_normal" qualifiers="const">
<return type="Vector3" />
<description>
- Returns the normal of the intersecting object's shape at the collision point.
+ Returns the normal of the intersecting object's shape at the collision point, or [code]Vector3(0, 0, 0)[/code] if the ray starts inside the shape and [member hit_from_inside] is [code]true[/code].
</description>
</method>
<method name="get_collision_point" qualifiers="const">
@@ -127,6 +127,9 @@
<member name="exclude_parent" type="bool" setter="set_exclude_parent_body" getter="get_exclude_parent_body" default="true">
If [code]true[/code], collisions will be ignored for this RayCast3D's immediate parent.
</member>
+ <member name="hit_from_inside" type="bool" setter="set_hit_from_inside" getter="is_hit_from_inside_enabled" default="false">
+ If [code]true[/code], the ray will detect a hit when starting inside shapes. In this case the collision normal will be [code]Vector3(0, 0, 0)[/code]. Does not affect shapes with no volume like concave polygon or heightmap.
+ </member>
<member name="target_position" type="Vector3" setter="set_target_position" getter="get_target_position" default="Vector3(0, -1, 0)">
The ray's destination point, relative to the RayCast's [code]position[/code].
</member>
diff --git a/doc/classes/Rect2.xml b/doc/classes/Rect2.xml
index 01bec10ed8..ad88551d9d 100644
--- a/doc/classes/Rect2.xml
+++ b/doc/classes/Rect2.xml
@@ -71,7 +71,22 @@
<return type="Rect2" />
<argument index="0" name="to" type="Vector2" />
<description>
- Returns this [Rect2] expanded to include a given point.
+ Returns a copy of this [Rect2] expanded to include a given point.
+ [b]Example:[/b]
+ [codeblocks]
+ [gdscript]
+ # position (-3, 2), size (1, 1)
+ var rect = Rect2(Vector2(-3, 2), Vector2(1, 1))
+ # position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)
+ var rect2 = rect.expand(Vector2(0, -1))
+ [/gdscript]
+ [csharp]
+ # position (-3, 2), size (1, 1)
+ var rect = new Rect2(new Vector2(-3, 2), new Vector2(1, 1));
+ # position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)
+ var rect2 = rect.Expand(new Vector2(0, -1));
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_area" qualifiers="const">
@@ -121,7 +136,8 @@
<return type="bool" />
<argument index="0" name="point" type="Vector2" />
<description>
- Returns [code]true[/code] if the [Rect2] contains a point.
+ Returns [code]true[/code] if the [Rect2] contains a point. By convention, the right and bottom edges of the [Rect2] are considered exclusive, so points on these edges are [b]not[/b] included.
+ [b]Note:[/b] This method is not reliable for [Rect2] with a [i]negative size[/i]. Use [method abs] to get a positive sized equivalent rectangle to check for contained points.
</description>
</method>
<method name="intersection" qualifiers="const">
diff --git a/doc/classes/Rect2i.xml b/doc/classes/Rect2i.xml
index fc27c64fa5..f5ea6a6c87 100644
--- a/doc/classes/Rect2i.xml
+++ b/doc/classes/Rect2i.xml
@@ -69,7 +69,21 @@
<return type="Rect2i" />
<argument index="0" name="to" type="Vector2i" />
<description>
- Returns this [Rect2i] expanded to include a given point.
+ Returns a copy of this [Rect2i] expanded to include a given point.
+ [codeblocks]
+ [gdscript]
+ # position (-3, 2), size (1, 1)
+ var rect = Rect2i(Vector2i(-3, 2), Vector2i(1, 1))
+ # position (-3, -1), size (3, 4), so we fit both rect and Vector2i(0, -1)
+ var rect2 = rect.expand(Vector2i(0, -1))
+ [/gdscript]
+ [csharp]
+ # position (-3, 2), size (1, 1)
+ var rect = new Rect2i(new Vector2i(-3, 2), new Vector2i(1, 1));
+ # position (-3, -1), size (3, 4), so we fit both rect and Vector2i(0, -1)
+ var rect2 = rect.Expand(new Vector2i(0, -1));
+ [/csharp]
+ [/codeblocks]
</description>
</method>
<method name="get_area" qualifiers="const">
@@ -120,7 +134,8 @@
<return type="bool" />
<argument index="0" name="point" type="Vector2i" />
<description>
- Returns [code]true[/code] if the [Rect2i] contains a point.
+ Returns [code]true[/code] if the [Rect2i] contains a point. By convention, the right and bottom edges of the [Rect2i] are considered exclusive, so points on these edges are [b]not[/b] included.
+ [b]Note:[/b] This method is not reliable for [Rect2i] with a [i]negative size[/i]. Use [method abs] to get a positive sized equivalent rectangle to check for contained points.
</description>
</method>
<method name="intersection" qualifiers="const">
diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml
index 68b79ff749..ddb25788c8 100644
--- a/doc/classes/RenderingServer.xml
+++ b/doc/classes/RenderingServer.xml
@@ -2661,8 +2661,10 @@
<return type="RID" />
<argument index="0" name="shader" type="RID" />
<argument index="1" name="param" type="StringName" />
+ <argument index="2" name="index" type="int" default="0" />
<description>
Returns a default texture from a shader searched by name.
+ [b]Note:[/b] If the sampler array is used use [code]index[/code] to access the specified texture.
</description>
</method>
<method name="shader_get_param_default" qualifiers="const">
@@ -2684,8 +2686,10 @@
<argument index="0" name="shader" type="RID" />
<argument index="1" name="param" type="StringName" />
<argument index="2" name="texture" type="RID" />
+ <argument index="3" name="index" type="int" default="0" />
<description>
Sets a shader's default texture. Overwrites the texture given by name.
+ [b]Note:[/b] If the sampler array is used use [code]index[/code] to access the specified texture.
</description>
</method>
<method name="shadows_quality_set">
diff --git a/doc/classes/Shader.xml b/doc/classes/Shader.xml
index 99e38e969d..751afb9b65 100644
--- a/doc/classes/Shader.xml
+++ b/doc/classes/Shader.xml
@@ -13,9 +13,11 @@
<method name="get_default_texture_param" qualifiers="const">
<return type="Texture2D" />
<argument index="0" name="param" type="StringName" />
+ <argument index="1" name="index" type="int" default="0" />
<description>
Returns the texture that is set as default for the specified parameter.
[b]Note:[/b] [code]param[/code] must match the name of the uniform in the code exactly.
+ [b]Note:[/b] If the sampler array is used use [code]index[/code] to access the specified texture.
</description>
</method>
<method name="get_mode" qualifiers="const">
@@ -36,9 +38,11 @@
<return type="void" />
<argument index="0" name="param" type="StringName" />
<argument index="1" name="texture" type="Texture2D" />
+ <argument index="2" name="index" type="int" default="0" />
<description>
Sets the default texture to be used with a texture uniform. The default is used if a texture is not set in the [ShaderMaterial].
[b]Note:[/b] [code]param[/code] must match the name of the uniform in the code exactly.
+ [b]Note:[/b] If the sampler array is used use [code]index[/code] to access the specified texture.
</description>
</method>
</methods>
diff --git a/doc/classes/TileSetAtlasSource.xml b/doc/classes/TileSetAtlasSource.xml
index 881a1c3d07..6580c6bd4c 100644
--- a/doc/classes/TileSetAtlasSource.xml
+++ b/doc/classes/TileSetAtlasSource.xml
@@ -45,6 +45,21 @@
Returns the alternative ID a following call to [method create_alternative_tile] would return.
</description>
</method>
+ <method name="get_runtime_texture" qualifiers="const">
+ <return type="Texture2D" />
+ <description>
+ If [member use_texture_padding] is [code]false[/code], returns [member texture]. Otherwise, returns and internal [ImageTexture] created that includes the padding.
+ </description>
+ </method>
+ <method name="get_runtime_tile_texture_region" qualifiers="const">
+ <return type="Rect2i" />
+ <argument index="0" name="atlas_coords" type="Vector2i" />
+ <argument index="1" name="frame" type="int" />
+ <description>
+ Returns the region of the tile at coordinates [code]atlas_coords[/code] for frame [code]frame[/code] inside the texture returned by [method get_runtime_texture].
+ [b]Note:[/b] If [member use_texture_padding] is [code]false[/code], returns the same as [method get_tile_texture_region].
+ </description>
+ </method>
<method name="get_tile_animation_columns" qualifiers="const">
<return type="int" />
<argument index="0" name="atlas_coords" type="Vector2i" />
@@ -232,5 +247,9 @@
<member name="texture_region_size" type="Vector2i" setter="set_texture_region_size" getter="get_texture_region_size" default="Vector2i(16, 16)">
The base tile size in the texture (in pixel). This size must be bigger than the TileSet's [code]tile_size[/code] value.
</member>
+ <member name="use_texture_padding" type="bool" setter="set_use_texture_padding" getter="get_use_texture_padding" default="true">
+ If [code]true[/code], generates an internal texture with an additional one pixel padding around each tile. Texture padding avoids a common artifact where lines appear between tiles.
+ Disabling this setting might lead a small performance improvement, as generating the internal texture requires both memory and processing time when the TileSetAtlasSource resource is modified.
+ </member>
</members>
</class>
diff --git a/doc/classes/VisualShaderNodeCustom.xml b/doc/classes/VisualShaderNodeCustom.xml
index b87b59c3e4..58f345b8f9 100644
--- a/doc/classes/VisualShaderNodeCustom.xml
+++ b/doc/classes/VisualShaderNodeCustom.xml
@@ -27,8 +27,8 @@
<return type="String" />
<argument index="0" name="input_vars" type="PackedStringArray" />
<argument index="1" name="output_vars" type="String[]" />
- <argument index="2" name="mode" type="int" />
- <argument index="3" name="type" type="int" />
+ <argument index="2" name="mode" type="int" enum="Shader.Mode" />
+ <argument index="3" name="type" type="int" enum="VisualShader.Type" />
<description>
Override this method to define the actual shader code of the associated custom node. The shader code should be returned as a string, which can have multiple lines (the [code]"""[/code] multiline string construct can be used for convenience).
The [code]input_vars[/code] and [code]output_vars[/code] arrays contain the string names of the various input and output variables, as defined by [code]_get_input_*[/code] and [code]_get_output_*[/code] virtual methods in this class.
@@ -46,7 +46,7 @@
</method>
<method name="_get_global_code" qualifiers="virtual const">
<return type="String" />
- <argument index="0" name="mode" type="int" />
+ <argument index="0" name="mode" type="int" enum="Shader.Mode" />
<description>
Override this method to add shader code on top of the global shader, to define your own standard library of reusable methods, varyings, constants, uniforms, etc. The shader code should be returned as a string, which can have multiple lines (the [code]"""[/code] multiline string construct can be used for convenience).
Be careful with this functionality as it can cause name conflicts with other custom nodes, so be sure to give the defined entities unique names.
diff --git a/doc/classes/VisualShaderNodeParticleMeshEmitter.xml b/doc/classes/VisualShaderNodeParticleMeshEmitter.xml
new file mode 100644
index 0000000000..7abb330fd3
--- /dev/null
+++ b/doc/classes/VisualShaderNodeParticleMeshEmitter.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="VisualShaderNodeParticleMeshEmitter" inherits="VisualShaderNodeParticleEmitter" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <members>
+ <member name="mesh" type="Mesh" setter="set_mesh" getter="get_mesh">
+ </member>
+ <member name="surface_index" type="int" setter="set_surface_index" getter="get_surface_index" default="0">
+ </member>
+ <member name="use_all_surfaces" type="bool" setter="set_use_all_surfaces" getter="is_use_all_surfaces" default="true">
+ </member>
+ </members>
+</class>
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 8a070313f8..4759a2b0d0 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -1871,31 +1871,38 @@ void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyIn
}
}
-void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
+void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) {
Shader *shader = shader_owner.get_or_null(p_shader);
ERR_FAIL_COND(!shader);
ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
- if (p_texture.is_valid()) {
- shader->default_textures[p_name] = p_texture;
+ if (!p_texture.is_valid()) {
+ if (shader->default_textures.has(p_name) && shader->default_textures[p_name].has(p_index)) {
+ shader->default_textures[p_name].erase(p_index);
+
+ if (shader->default_textures[p_name].is_empty()) {
+ shader->default_textures.erase(p_name);
+ }
+ }
} else {
- shader->default_textures.erase(p_name);
+ if (!shader->default_textures.has(p_name)) {
+ shader->default_textures[p_name] = Map<int, RID>();
+ }
+ shader->default_textures[p_name][p_index] = p_texture;
}
_shader_make_dirty(shader);
}
-RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
+RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const {
const Shader *shader = shader_owner.get_or_null(p_shader);
ERR_FAIL_COND_V(!shader, RID());
- const Map<StringName, RID>::Element *E = shader->default_textures.find(p_name);
-
- if (!E) {
- return RID();
+ if (shader->default_textures.has(p_name) && shader->default_textures[p_name].has(p_index)) {
+ return shader->default_textures[p_name][p_index];
}
- return E->get();
+ return RID();
}
void RasterizerStorageGLES3::shader_add_custom_define(RID p_shader, const String &p_define) {
@@ -2195,10 +2202,11 @@ void RasterizerStorageGLES3::_update_material(Material *p_material) {
}
if (!texture.is_valid()) {
- Map<StringName, RID>::Element *W = p_material->shader->default_textures.find(E->key());
+ Map<StringName, Map<int, RID>>::Element *W = p_material->shader->default_textures.find(E->key());
- if (W) {
- texture = W->get();
+ // TODO: make texture uniform array properly works with GLES3
+ if (W && W->get().has(0)) {
+ texture = W->get()[0];
}
}
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
index eb5614f70f..3f9f208964 100644
--- a/drivers/gles3/rasterizer_storage_gles3.h
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -580,7 +580,7 @@ public:
SelfList<Shader> dirty_list;
- Map<StringName, RID> default_textures;
+ Map<StringName, Map<int, RID>> default_textures;
Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
@@ -706,8 +706,8 @@ public:
String shader_get_code(RID p_shader) const override;
void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const override;
- void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) override;
- RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const override;
+ void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) override;
+ RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const override;
RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const override { return RS::ShaderNativeSourceCode(); };
diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp
index 3b2f078120..520d4808fb 100644
--- a/drivers/wasapi/audio_driver_wasapi.cpp
+++ b/drivers/wasapi/audio_driver_wasapi.cpp
@@ -121,6 +121,12 @@ const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
static bool default_render_device_changed = false;
static bool default_capture_device_changed = false;
+// Silence warning due to a COM API weirdness (GH-35194).
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+
class CMMNotificationClient : public IMMNotificationClient {
LONG _cRef = 1;
IMMDeviceEnumerator *_pEnumerator = nullptr;
@@ -162,7 +168,7 @@ public:
HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId) {
return S_OK;
- };
+ }
HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId) {
return S_OK;
@@ -189,6 +195,10 @@ public:
}
};
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+
static CMMNotificationClient notif_client;
Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_capture, bool reinit) {
@@ -373,7 +383,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
hr = p_device->audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, p_capture ? REFTIMES_PER_SEC : 0, 0, pwfex, nullptr);
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: Initialize failed with error 0x" + String::num_uint64(hr, 16) + ".");
UINT32 max_frames;
- HRESULT hr = p_device->audio_client->GetBufferSize(&max_frames);
+ hr = p_device->audio_client->GetBufferSize(&max_frames);
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
// Due to WASAPI Shared Mode we have no control of the buffer size
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index a85a4450a6..b15636f775 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -1377,8 +1377,20 @@ void AnimationTimelineEdit::_anim_length_changed(double p_new_len) {
void AnimationTimelineEdit::_anim_loop_pressed() {
undo_redo->create_action(TTR("Change Animation Loop"));
- undo_redo->add_do_method(animation.ptr(), "set_loop", loop->is_pressed());
- undo_redo->add_undo_method(animation.ptr(), "set_loop", animation->has_loop());
+ switch (animation->get_loop_mode()) {
+ case Animation::LoopMode::LOOP_NONE: {
+ undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LoopMode::LOOP_LINEAR);
+ } break;
+ case Animation::LoopMode::LOOP_LINEAR: {
+ undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LoopMode::LOOP_PINGPONG);
+ } break;
+ case Animation::LoopMode::LOOP_PINGPONG: {
+ undo_redo->add_do_method(animation.ptr(), "set_loop_mode", Animation::LoopMode::LOOP_NONE);
+ } break;
+ default:
+ break;
+ }
+ undo_redo->add_undo_method(animation.ptr(), "set_loop_mode", animation->get_loop_mode());
undo_redo->commit_action();
}
@@ -1664,7 +1676,24 @@ void AnimationTimelineEdit::update_values() {
length->set_tooltip(TTR("Animation length (seconds)"));
time_icon->set_tooltip(TTR("Animation length (seconds)"));
}
- loop->set_pressed(animation->has_loop());
+
+ switch (animation->get_loop_mode()) {
+ case Animation::LoopMode::LOOP_NONE: {
+ loop->set_icon(get_theme_icon("Loop", "EditorIcons"));
+ loop->set_pressed(false);
+ } break;
+ case Animation::LoopMode::LOOP_LINEAR: {
+ loop->set_icon(get_theme_icon("Loop", "EditorIcons"));
+ loop->set_pressed(true);
+ } break;
+ case Animation::LoopMode::LOOP_PINGPONG: {
+ loop->set_icon(get_theme_icon("PingPongLoop", "EditorIcons"));
+ loop->set_pressed(true);
+ } break;
+ default:
+ break;
+ }
+
editing = false;
}
@@ -2110,25 +2139,25 @@ void AnimationTrackEdit::_notification(int p_what) {
Ref<Texture2D> icon = wrap_icon[loop_wrap ? 1 : 0];
- loop_mode_rect.position.x = ofs;
- loop_mode_rect.position.y = int(get_size().height - icon->get_height()) / 2;
- loop_mode_rect.size = icon->get_size();
+ loop_wrap_rect.position.x = ofs;
+ loop_wrap_rect.position.y = int(get_size().height - icon->get_height()) / 2;
+ loop_wrap_rect.size = icon->get_size();
if (!animation->track_is_compressed(track) && (animation->track_get_type(track) == Animation::TYPE_VALUE || animation->track_get_type(track) == Animation::TYPE_BLEND_SHAPE || animation->track_get_type(track) == Animation::TYPE_POSITION_3D || animation->track_get_type(track) == Animation::TYPE_SCALE_3D || animation->track_get_type(track) == Animation::TYPE_ROTATION_3D)) {
- draw_texture(icon, loop_mode_rect.position);
+ draw_texture(icon, loop_wrap_rect.position);
}
- loop_mode_rect.position.y = 0;
- loop_mode_rect.size.y = get_size().height;
+ loop_wrap_rect.position.y = 0;
+ loop_wrap_rect.size.y = get_size().height;
ofs += icon->get_width() + hsep;
- loop_mode_rect.size.x += hsep;
+ loop_wrap_rect.size.x += hsep;
if (!animation->track_is_compressed(track) && (animation->track_get_type(track) == Animation::TYPE_VALUE || animation->track_get_type(track) == Animation::TYPE_BLEND_SHAPE || animation->track_get_type(track) == Animation::TYPE_POSITION_3D || animation->track_get_type(track) == Animation::TYPE_SCALE_3D || animation->track_get_type(track) == Animation::TYPE_ROTATION_3D)) {
draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2));
- loop_mode_rect.size.x += down_icon->get_width();
+ loop_wrap_rect.size.x += down_icon->get_width();
} else {
- loop_mode_rect = Rect2();
+ loop_wrap_rect = Rect2();
}
ofs += down_icon->get_width();
@@ -2478,7 +2507,7 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const {
return TTR("Interpolation Mode");
}
- if (loop_mode_rect.has_point(p_pos)) {
+ if (loop_wrap_rect.has_point(p_pos)) {
return TTR("Loop Wrap Mode (Interpolate end with beginning on loop)");
}
@@ -2681,7 +2710,7 @@ void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
- if (loop_mode_rect.has_point(pos)) {
+ if (loop_wrap_rect.has_point(pos)) {
if (!menu) {
menu = memnew(PopupMenu);
add_child(menu);
@@ -2692,7 +2721,7 @@ void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
menu->add_icon_item(get_theme_icon(SNAME("InterpWrapLoop"), SNAME("EditorIcons")), TTR("Wrap Loop Interp"), MENU_LOOP_WRAP);
menu->set_as_minsize();
- Vector2 popup_pos = get_screen_position() + loop_mode_rect.position + Vector2(0, loop_mode_rect.size.height);
+ Vector2 popup_pos = get_screen_position() + loop_wrap_rect.position + Vector2(0, loop_wrap_rect.size.height);
menu->set_position(popup_pos);
menu->popup();
accept_event();
diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h
index 05cf91de1d..2bdc1d4107 100644
--- a/editor/animation_track_editor.h
+++ b/editor/animation_track_editor.h
@@ -159,7 +159,7 @@ class AnimationTrackEdit : public Control {
Rect2 update_mode_rect;
Rect2 interp_mode_rect;
- Rect2 loop_mode_rect;
+ Rect2 loop_wrap_rect;
Rect2 remove_rect;
Rect2 bezier_edit_rect;
@@ -466,6 +466,7 @@ class AnimationTrackEditor : public VBoxContainer {
Animation::TrackType track_type = Animation::TrackType::TYPE_ANIMATION;
Animation::InterpolationType interp_type = Animation::InterpolationType::INTERPOLATION_CUBIC;
Animation::UpdateMode update_mode = Animation::UpdateMode::UPDATE_CAPTURE;
+ Animation::LoopMode loop_mode = Animation::LoopMode::LOOP_LINEAR;
bool loop_wrap = false;
bool enabled = false;
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp
index 61cc6dbd4a..5ce57e936a 100644
--- a/editor/doc_tools.cpp
+++ b/editor/doc_tools.cpp
@@ -41,7 +41,7 @@
#include "scene/resources/theme.h"
// Used for a hack preserving Mono properties on non-Mono builds.
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For mono.
void DocTools::merge_from(const DocTools &p_data) {
for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 8c3569df07..43486a09a1 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -1429,14 +1429,15 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
bbcode = bbcode.replace("[/gdscript]", "[/codeblock]");
for (int pos = bbcode.find("[csharp]"); pos != -1; pos = bbcode.find("[csharp]")) {
- if (bbcode.find("[/csharp]") == -1) {
+ int end_pos = bbcode.find("[/csharp]");
+ if (end_pos == -1) {
WARN_PRINT("Unclosed [csharp] block or parse fail in code (search for tag errors)");
break;
}
- bbcode.erase(pos, bbcode.find("[/csharp]") + 9 - pos);
+ bbcode = bbcode.left(pos) + bbcode.substr(end_pos + 9); // 9 is length of "[/csharp]".
while (bbcode[pos] == '\n') {
- bbcode.erase(pos, 1);
+ bbcode = bbcode.left(pos) + bbcode.substr(pos + 1);
}
}
break;
@@ -1445,14 +1446,15 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
bbcode = bbcode.replace("[/csharp]", "[/codeblock]");
for (int pos = bbcode.find("[gdscript]"); pos != -1; pos = bbcode.find("[gdscript]")) {
- if (bbcode.find("[/gdscript]") == -1) {
+ int end_pos = bbcode.find("[/gdscript]");
+ if (end_pos == -1) {
WARN_PRINT("Unclosed [gdscript] block or parse fail in code (search for tag errors)");
break;
}
- bbcode.erase(pos, bbcode.find("[/gdscript]") + 11 - pos);
+ bbcode = bbcode.left(pos) + bbcode.substr(end_pos + 11); // 11 is length of "[/gdscript]".
while (bbcode[pos] == '\n') {
- bbcode.erase(pos, 1);
+ bbcode = bbcode.left(pos) + bbcode.substr(pos + 1);
}
}
break;
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 4ffa90777c..46cc9336be 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -1014,11 +1014,15 @@ bool EditorInspectorPlugin::can_handle(Object *p_object) {
}
void EditorInspectorPlugin::parse_begin(Object *p_object) {
- GDVIRTUAL_CALL(_parse_begin);
+ GDVIRTUAL_CALL(_parse_begin, p_object);
}
-void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_parse_category) {
- GDVIRTUAL_CALL(_parse_category, p_object, p_parse_category);
+void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_category) {
+ GDVIRTUAL_CALL(_parse_category, p_object, p_category);
+}
+
+void EditorInspectorPlugin::parse_group(Object *p_object, const String &p_group) {
+ GDVIRTUAL_CALL(_parse_group, p_object, p_group);
}
bool EditorInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
@@ -1029,8 +1033,8 @@ bool EditorInspectorPlugin::parse_property(Object *p_object, const Variant::Type
return false;
}
-void EditorInspectorPlugin::parse_end() {
- GDVIRTUAL_CALL(_parse_end);
+void EditorInspectorPlugin::parse_end(Object *p_object) {
+ GDVIRTUAL_CALL(_parse_end, p_object);
}
void EditorInspectorPlugin::_bind_methods() {
@@ -1039,10 +1043,11 @@ void EditorInspectorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties);
GDVIRTUAL_BIND(_can_handle, "object")
- GDVIRTUAL_BIND(_parse_begin)
+ GDVIRTUAL_BIND(_parse_begin, "object")
GDVIRTUAL_BIND(_parse_category, "object", "category")
+ GDVIRTUAL_BIND(_parse_group, "object", "group")
GDVIRTUAL_BIND(_parse_property, "object", "type", "name", "hint_type", "hint_string", "usage_flags", "wide");
- GDVIRTUAL_BIND(_parse_end)
+ GDVIRTUAL_BIND(_parse_end, "object")
}
////////////////////////////////////////////////
@@ -2628,6 +2633,12 @@ void EditorInspector::update_tree() {
c.a /= level;
section->setup(acc_path, component, object, c, use_folding);
+ // Add editors at the start of a group.
+ for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
+ ped->parse_group(object, path);
+ _parse_added_editors(section->get_vbox(), ped);
+ }
+
vbox_per_path[root_vbox][acc_path] = section->get_vbox();
}
@@ -2837,7 +2848,7 @@ void EditorInspector::update_tree() {
// Get the lists of to add at the end.
for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
- ped->parse_end();
+ ped->parse_end(object);
_parse_added_editors(main_vbox, ped);
}
}
@@ -3075,12 +3086,20 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
} else {
undo_redo->create_action(vformat(TTR("Set %s"), p_name), UndoRedo::MERGE_ENDS);
undo_redo->add_do_property(object, p_name, p_value);
- undo_redo->add_undo_property(object, p_name, object->get(p_name));
+ bool valid = false;
+ Variant value = object->get(p_name, &valid);
+ if (valid) {
+ undo_redo->add_undo_property(object, p_name, value);
+ }
PropertyInfo prop_info;
if (ClassDB::get_property_info(object->get_class_name(), p_name, &prop_info)) {
for (const String &linked_prop : prop_info.linked_properties) {
- undo_redo->add_undo_property(object, linked_prop, object->get(linked_prop));
+ valid = false;
+ value = object->get(linked_prop, &valid);
+ if (valid) {
+ undo_redo->add_undo_property(object, linked_prop, value);
+ }
}
}
diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h
index aabb66eeb4..f2dfe32f82 100644
--- a/editor/editor_inspector.h
+++ b/editor/editor_inspector.h
@@ -215,10 +215,11 @@ protected:
static void _bind_methods();
GDVIRTUAL1RC(bool, _can_handle, Variant)
- GDVIRTUAL0(_parse_begin)
+ GDVIRTUAL1(_parse_begin, Object *)
GDVIRTUAL2(_parse_category, Object *, String)
+ GDVIRTUAL2(_parse_group, Object *, String)
GDVIRTUAL7R(bool, _parse_property, Object *, int, String, int, String, int, bool)
- GDVIRTUAL0(_parse_end)
+ GDVIRTUAL1(_parse_end, Object *)
public:
void add_custom_control(Control *control);
@@ -227,9 +228,10 @@ public:
virtual bool can_handle(Object *p_object);
virtual void parse_begin(Object *p_object);
- virtual void parse_category(Object *p_object, const String &p_parse_category);
+ virtual void parse_category(Object *p_object, const String &p_category);
+ virtual void parse_group(Object *p_object, const String &p_group);
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false);
- virtual void parse_end();
+ virtual void parse_end(Object *p_object);
};
class EditorInspectorCategory : public Control {
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 4af7763caa..7d550d5c2f 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1717,8 +1717,10 @@ void EditorNode::_save_scene(String p_file, int idx) {
err = ResourceSaver::save(p_file, sdata, flg);
- _save_external_resources();
+ // This needs to be emitted before saving external resources.
+ emit_signal(SNAME("scene_saved"), p_file);
+ _save_external_resources();
editor_data.save_editor_external_data();
for (Ref<AnimatedValuesBackup> &E : anim_backups) {
@@ -5712,6 +5714,7 @@ void EditorNode::_bind_methods() {
ADD_SIGNAL(MethodInfo("request_help_search"));
ADD_SIGNAL(MethodInfo("script_add_function_request", PropertyInfo(Variant::OBJECT, "obj"), PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "args")));
ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "obj")));
+ ADD_SIGNAL(MethodInfo("scene_saved", PropertyInfo(Variant::STRING, "path")));
ADD_SIGNAL(MethodInfo("project_settings_changed"));
}
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 26f28ff5fb..a7b8e9c4d0 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -3170,11 +3170,7 @@ EditorPropertyResource::EditorPropertyResource() {
////////////// DEFAULT PLUGIN //////////////////////
bool EditorInspectorDefaultPlugin::can_handle(Object *p_object) {
- return true; //can handle everything
-}
-
-void EditorInspectorDefaultPlugin::parse_begin(Object *p_object) {
- //do none
+ return true; // Can handle everything.
}
bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
@@ -3185,10 +3181,6 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, const Varian
return false;
}
-void EditorInspectorDefaultPlugin::parse_end() {
- //do none
-}
-
struct EditorPropertyRangeHint {
bool angle_in_degrees = false;
bool greater = true;
diff --git a/editor/editor_properties.h b/editor/editor_properties.h
index 754d444309..42ef650adc 100644
--- a/editor/editor_properties.h
+++ b/editor/editor_properties.h
@@ -696,9 +696,7 @@ class EditorInspectorDefaultPlugin : public EditorInspectorPlugin {
public:
virtual bool can_handle(Object *p_object) override;
- virtual void parse_begin(Object *p_object) override;
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override;
- virtual void parse_end() override;
static EditorProperty *get_editor_for_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false);
};
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp
index 8e8437f1b2..637394d136 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -36,7 +36,7 @@
#include "editor_scale.h"
#include "editor_settings.h"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For svg.
#ifdef MODULE_SVG_ENABLED
#include "modules/svg/image_loader_svg.h"
#endif
diff --git a/editor/icons/MirrorX.svg b/editor/icons/MirrorX.svg
new file mode 100644
index 0000000000..fa668986ac
--- /dev/null
+++ b/editor/icons/MirrorX.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="#e0e0e0" stroke-opacity=".99608" stroke-width="2" transform="translate(0 -1036.4)"><path d="m4 1042.4-2 2 2 2" stroke-linecap="round" stroke-linejoin="round"/><path d="m2 1044.4h11"/><path d="m12 1042.4 2 2-2 2" stroke-linecap="round" stroke-linejoin="round"/></g></svg>
diff --git a/editor/icons/MirrorY.svg b/editor/icons/MirrorY.svg
new file mode 100644
index 0000000000..bb4e4d3543
--- /dev/null
+++ b/editor/icons/MirrorY.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m11.012 1048.4a1.0001 1.0001 0 0 0 -1.7168-.6973l-.29297.293v-7.1719l.29297.293a1.0001 1.0001 0 0 0 1.7148-.7266 1.0001 1.0001 0 0 0 -.30078-.6875l-2-2a1.0001 1.0001 0 0 0 -1.4141 0l-2 2a1.0001 1.0001 0 1 0 1.4141 1.4141l.29297-.293v7.1719l-.29297-.293a1.0001 1.0001 0 1 0 -1.4141 1.4141l2 2a1.0001 1.0001 0 0 0 1.4141 0l2-2a1.0001 1.0001 0 0 0 .30273-.7168z" fill="#e0e0e0" fill-opacity=".99608" transform="translate(0 -1036.4)"/></svg>
diff --git a/editor/icons/PingPongLoop.svg b/editor/icons/PingPongLoop.svg
new file mode 100644
index 0000000000..c44f889b49
--- /dev/null
+++ b/editor/icons/PingPongLoop.svg
@@ -0,0 +1 @@
+<svg enable-background="new 0 0 16 16" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#e0e0e0" fill-opacity=".9961"><path d="m10 7h-4v-2l-4 3 4 3v-2h4v2l4-3-4-3z"/><path d="m0 1v14h2v-7-7z"/><path d="m14 1v7 7h2v-14z"/></g></svg>
diff --git a/editor/icons/RotateLeft.svg b/editor/icons/RotateLeft.svg
new file mode 100644
index 0000000000..1200df1dde
--- /dev/null
+++ b/editor/icons/RotateLeft.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#e0e0e0" fill-opacity=".99608" transform="translate(0 -1036.4)"><path d="m9 2a6 6 0 0 0 -6 6h2a4 4 0 0 1 4-4 4 4 0 0 1 4 4 4 4 0 0 1 -4 4v2a6 6 0 0 0 6-6 6 6 0 0 0 -6-6z" transform="translate(0 1036.4)"/><path d="m4.118 1048.3-1.6771-.9683-1.6771-.9682 1.6771-.9683 1.6771-.9682-.0000001 1.9365z" transform="matrix(0 -1.1926 1.5492 0 -1617 1049.3)"/></g></svg>
diff --git a/editor/icons/RotateRight.svg b/editor/icons/RotateRight.svg
new file mode 100644
index 0000000000..d69e6a7705
--- /dev/null
+++ b/editor/icons/RotateRight.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#e0e0e0" fill-opacity=".99608" transform="matrix(-1 0 0 1 16.026308 -1036.4)"><path d="m9 2a6 6 0 0 0 -6 6h2a4 4 0 0 1 4-4 4 4 0 0 1 4 4 4 4 0 0 1 -4 4v2a6 6 0 0 0 6-6 6 6 0 0 0 -6-6z" transform="translate(0 1036.4)"/><path d="m4.118 1048.3-1.6771-.9683-1.6771-.9682 1.6771-.9683 1.6771-.9682-.0000001 1.9365z" transform="matrix(0 -1.1926 1.5492 0 -1617 1049.3)"/></g></svg>
diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp
index d219f6e325..2c1d2149c6 100644
--- a/editor/import/editor_import_plugin.cpp
+++ b/editor/import/editor_import_plugin.cpp
@@ -57,6 +57,7 @@ void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) c
for (int i = 0; i < extensions.size(); i++) {
p_extensions->push_back(extensions[i]);
}
+ return;
}
ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on.");
}
@@ -139,6 +140,7 @@ void EditorImportPlugin::get_import_options(List<ResourceImporter::ImportOption>
ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
r_options->push_back(option);
}
+ return;
}
ERR_FAIL_MSG("Unimplemented _get_import_options in add-on.");
diff --git a/editor/import/resource_importer_dynamicfont.cpp b/editor/import/resource_importer_dynamicfont.cpp
index 8e01adbd56..a021275917 100644
--- a/editor/import/resource_importer_dynamicfont.cpp
+++ b/editor/import/resource_importer_dynamicfont.cpp
@@ -30,12 +30,12 @@
#include "resource_importer_dynamicfont.h"
-#include "dynamicfont_import_settings.h"
-
#include "core/io/file_access.h"
#include "core/io/resource_saver.h"
+#include "dynamicfont_import_settings.h"
#include "editor/editor_node.h"
-#include "modules/modules_enabled.gen.h"
+
+#include "modules/modules_enabled.gen.h" // For freetype.
String ResourceImporterDynamicFont::get_importer_name() const {
return "font_data_dynamic";
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index 01af75c338..8eab27b533 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -405,11 +405,11 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
current_material_library = l.replace("mtllib", "").strip_edges();
if (!material_map.has(current_material_library)) {
Map<String, Ref<StandardMaterial3D>> lib;
- Error err = _parse_material_library(current_material_library, lib, r_missing_deps);
- if (err == ERR_CANT_OPEN) {
- String dir = p_path.get_base_dir();
- err = _parse_material_library(dir.plus_file(current_material_library), lib, r_missing_deps);
+ String lib_path = current_material_library;
+ if (lib_path.is_relative_path()) {
+ lib_path = p_path.get_base_dir().plus_file(current_material_library);
}
+ Error err = _parse_material_library(lib_path, lib, r_missing_deps);
if (err == OK) {
material_map[current_material_library] = lib;
}
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 5efb08b95d..9aaffe8abf 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -424,10 +424,10 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<I
String animname = E;
const int loop_string_count = 3;
- static const char *loop_strings[loop_string_count] = { "loops", "loop", "cycle" };
+ static const char *loop_strings[loop_string_count] = { "loop_mode", "loop", "cycle" };
for (int i = 0; i < loop_string_count; i++) {
if (_teststr(animname, loop_strings[i])) {
- anim->set_loop(true);
+ anim->set_loop_mode(Animation::LoopMode::LOOP_LINEAR);
animname = _fixstr(animname, loop_strings[i]);
ap->rename_animation(E, animname);
}
@@ -868,7 +868,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
String name = node_settings["clip_" + itos(i + 1) + "/name"];
int from_frame = node_settings["clip_" + itos(i + 1) + "/start_frame"];
int end_frame = node_settings["clip_" + itos(i + 1) + "/end_frame"];
- bool loop = node_settings["clip_" + itos(i + 1) + "/loops"];
+ Animation::LoopMode loop_mode = static_cast<Animation::LoopMode>((int)node_settings["clip_" + itos(i + 1) + "/loop_mode"]);
bool save_to_file = node_settings["clip_" + itos(i + 1) + "/save_to_file/enabled"];
bool save_to_path = node_settings["clip_" + itos(i + 1) + "/save_to_file/path"];
bool save_to_file_keep_custom = node_settings["clip_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"];
@@ -876,7 +876,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
animation_clips.push_back(name);
animation_clips.push_back(from_frame / p_animation_fps);
animation_clips.push_back(end_frame / p_animation_fps);
- animation_clips.push_back(loop);
+ animation_clips.push_back(loop_mode);
animation_clips.push_back(save_to_file);
animation_clips.push_back(save_to_path);
animation_clips.push_back(save_to_file_keep_custom);
@@ -903,7 +903,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
}
}
- anim->set_loop(anim_settings["settings/loops"]);
+ anim->set_loop_mode(static_cast<Animation::LoopMode>((int)anim_settings["settings/loop_mode"]));
bool save = anim_settings["save_to_file/enabled"];
String path = anim_settings["save_to_file/path"];
bool keep_custom = anim_settings["save_to_file/keep_custom_tracks"];
@@ -977,7 +977,7 @@ Ref<Animation> ResourceImporterScene::_save_animation_to_file(Ref<Animation> ani
old_anim->copy_track(i, anim);
}
}
- anim->set_loop(old_anim->has_loop());
+ anim->set_loop_mode(old_anim->get_loop_mode());
}
}
@@ -1005,7 +1005,7 @@ void ResourceImporterScene::_create_clips(AnimationPlayer *anim, const Array &p_
String name = p_clips[i];
float from = p_clips[i + 1];
float to = p_clips[i + 2];
- bool loop = p_clips[i + 3];
+ Animation::LoopMode loop_mode = static_cast<Animation::LoopMode>((int)p_clips[i + 3]);
bool save_to_file = p_clips[i + 4];
String save_to_path = p_clips[i + 5];
bool keep_current = p_clips[i + 6];
@@ -1135,7 +1135,7 @@ void ResourceImporterScene::_create_clips(AnimationPlayer *anim, const Array &p_
}
}
- new_anim->set_loop(loop);
+ new_anim->set_loop_mode(loop_mode);
new_anim->set_length(to - from);
anim->add_animation(name, new_anim);
@@ -1218,7 +1218,7 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/path", PROPERTY_HINT_FILE, "*.material,*.res,*.tres"), ""));
} break;
case INTERNAL_IMPORT_CATEGORY_ANIMATION: {
- r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "settings/loops"), false));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "settings/loop_mode"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "save_to_file/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "save_to_file/path", PROPERTY_HINT_SAVE_FILE, "*.res,*.tres"), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "save_to_file/keep_custom_tracks"), ""));
@@ -1240,7 +1240,7 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/name"), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/start_frame"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/end_frame"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/loops"), false));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/loop_mode"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/save_to_file/path", PROPERTY_HINT_SAVE_FILE, ".res,*.tres"), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"), false));
@@ -1428,7 +1428,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.1));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "skins/use_named_skins"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import"), true));
- r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 30));
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "import_script/path", PROPERTY_HINT_FILE, script_ext_hint), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::DICTIONARY, "_subresources", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), Dictionary()));
@@ -1462,7 +1462,7 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneFormatI
for (const String &F : extensions) {
if (F.to_lower() == ext) {
- importer = E;
+ importer = E->get();
break;
}
}
@@ -1492,7 +1492,7 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito
for (const String &F : extensions) {
if (F.to_lower() == ext) {
- importer = E;
+ importer = E->get();
break;
}
}
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index 89383d3dde..877bdd50fb 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -272,7 +272,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
if (loop_type == 0x00) {
loop = AudioStreamSample::LOOP_FORWARD;
} else if (loop_type == 0x01) {
- loop = AudioStreamSample::LOOP_PING_PONG;
+ loop = AudioStreamSample::LOOP_PINGPONG;
} else if (loop_type == 0x02) {
loop = AudioStreamSample::LOOP_BACKWARD;
}
diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp
index 91ca1465df..c99b34e0c2 100644
--- a/editor/plugin_config_dialog.cpp
+++ b/editor/plugin_config_dialog.cpp
@@ -38,7 +38,7 @@
#include "editor/project_settings_editor.h"
#include "scene/gui/grid_container.h"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For gdscript.
#ifdef MODULE_GDSCRIPT_ENABLED
#include "modules/gdscript/gdscript.h"
#endif
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index ea025dad3e..65238446f9 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -41,6 +41,7 @@
#include "editor/plugins/canvas_item_editor_plugin.h" // For onion skinning.
#include "editor/plugins/node_3d_editor_plugin.h" // For onion skinning.
#include "scene/main/window.h"
+#include "scene/resources/animation.h"
#include "servers/rendering_server.h"
void AnimationPlayerEditor::_node_removed(Node *p_node) {
@@ -72,7 +73,7 @@ void AnimationPlayerEditor::_notification(int p_what) {
if (player->has_animation(animname)) {
Ref<Animation> anim = player->get_animation(animname);
if (!anim.is_null()) {
- frame->set_max(anim->get_length());
+ frame->set_max((double)anim->get_length());
}
}
}
@@ -289,7 +290,7 @@ void AnimationPlayerEditor::_animation_selected(int p_which) {
track_editor->set_root(root);
}
}
- frame->set_max(anim->get_length());
+ frame->set_max((double)anim->get_length());
} else {
track_editor->set_animation(Ref<Animation>());
@@ -1014,7 +1015,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set, bool
Ref<Animation> anim;
anim = player->get_animation(current);
- float pos = CLAMP(anim->get_length() * (p_value / frame->get_max()), 0, anim->get_length());
+ float pos = CLAMP((double)anim->get_length() * (p_value / frame->get_max()), 0, (double)anim->get_length());
if (track_editor->is_snap_enabled()) {
pos = Math::snapped(pos, _get_editor_step());
}
@@ -1424,7 +1425,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() {
float pos = cpos + step_off * anim->get_step();
- bool valid = anim->has_loop() || (pos >= 0 && pos <= anim->get_length());
+ bool valid = anim->get_loop_mode() != Animation::LoopMode::LOOP_NONE || (pos >= 0 && pos <= anim->get_length());
onion.captures_valid.write[cidx] = valid;
if (valid) {
player->seek(pos, true);
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index fa5381bb10..5b1cbe6f00 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -2245,12 +2245,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
_menu_option(VIEW_RIGHT);
}
if (ED_IS_SHORTCUT("spatial_editor/orbit_view_down", p_event)) {
- cursor.x_rot -= Math_PI / 12.0;
+ // Clamp rotation to roughly -90..90 degrees so the user can't look upside-down and end up disoriented.
+ cursor.x_rot = CLAMP(cursor.x_rot - Math_PI / 12.0, -1.57, 1.57);
view_type = VIEW_TYPE_USER;
_update_name();
}
if (ED_IS_SHORTCUT("spatial_editor/orbit_view_up", p_event)) {
- cursor.x_rot += Math_PI / 12.0;
+ // Clamp rotation to roughly -90..90 degrees so the user can't look upside-down and end up disoriented.
+ cursor.x_rot = CLAMP(cursor.x_rot + Math_PI / 12.0, -1.57, 1.57);
view_type = VIEW_TYPE_USER;
_update_name();
}
@@ -2885,13 +2887,13 @@ void Node3DEditorViewport::_notification(int p_what) {
// Color labels depending on performance level ("good" = green, "OK" = yellow, "bad" = red).
// Middle point is at 15 ms.
- cpu_time_label->set_text(vformat(TTR("CPU Time: %s ms"), rtos(cpu_time).pad_decimals(1)));
+ cpu_time_label->set_text(vformat(TTR("CPU Time: %s ms"), rtos(cpu_time).pad_decimals(2)));
cpu_time_label->add_theme_color_override(
"font_color",
frame_time_gradient->get_color_at_offset(
Math::range_lerp(cpu_time, 0, 30, 0, 1)));
- gpu_time_label->set_text(vformat(TTR("GPU Time: %s ms"), rtos(gpu_time).pad_decimals(1)));
+ gpu_time_label->set_text(vformat(TTR("GPU Time: %s ms"), rtos(gpu_time).pad_decimals(2)));
// Middle point is at 15 ms.
gpu_time_label->add_theme_color_override(
"font_color",
diff --git a/editor/plugins/ot_features_plugin.cpp b/editor/plugins/ot_features_plugin.cpp
index fd42bce06e..c949621e28 100644
--- a/editor/plugins/ot_features_plugin.cpp
+++ b/editor/plugins/ot_features_plugin.cpp
@@ -185,12 +185,6 @@ bool EditorInspectorPluginOpenTypeFeatures::can_handle(Object *p_object) {
return (Object::cast_to<Control>(p_object) != nullptr);
}
-void EditorInspectorPluginOpenTypeFeatures::parse_begin(Object *p_object) {
-}
-
-void EditorInspectorPluginOpenTypeFeatures::parse_category(Object *p_object, const String &p_parse_category) {
-}
-
bool EditorInspectorPluginOpenTypeFeatures::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
if (p_path == "opentype_features/_new") {
OpenTypeFeaturesAdd *editor = memnew(OpenTypeFeaturesAdd);
diff --git a/editor/plugins/ot_features_plugin.h b/editor/plugins/ot_features_plugin.h
index dbafa3bbf6..add491ed48 100644
--- a/editor/plugins/ot_features_plugin.h
+++ b/editor/plugins/ot_features_plugin.h
@@ -86,8 +86,6 @@ class EditorInspectorPluginOpenTypeFeatures : public EditorInspectorPlugin {
public:
virtual bool can_handle(Object *p_object) override;
- virtual void parse_begin(Object *p_object) override;
- virtual void parse_category(Object *p_object, const String &p_parse_category) override;
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override;
};
diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp
index ed91f174d1..0f3c50a861 100644
--- a/editor/plugins/root_motion_editor_plugin.cpp
+++ b/editor/plugins/root_motion_editor_plugin.cpp
@@ -271,11 +271,7 @@ EditorPropertyRootMotion::EditorPropertyRootMotion() {
//////////////////////////
bool EditorInspectorRootMotionPlugin::can_handle(Object *p_object) {
- return true; //can handle everything
-}
-
-void EditorInspectorRootMotionPlugin::parse_begin(Object *p_object) {
- //do none
+ return true; // Can handle everything.
}
bool EditorInspectorRootMotionPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
@@ -288,9 +284,5 @@ bool EditorInspectorRootMotionPlugin::parse_property(Object *p_object, const Var
return true;
}
- return false; //can be overridden, although it will most likely be last anyway
-}
-
-void EditorInspectorRootMotionPlugin::parse_end() {
- //do none
+ return false;
}
diff --git a/editor/plugins/root_motion_editor_plugin.h b/editor/plugins/root_motion_editor_plugin.h
index 1484af62e8..c05975b6c3 100644
--- a/editor/plugins/root_motion_editor_plugin.h
+++ b/editor/plugins/root_motion_editor_plugin.h
@@ -64,9 +64,7 @@ class EditorInspectorRootMotionPlugin : public EditorInspectorPlugin {
public:
virtual bool can_handle(Object *p_object) override;
- virtual void parse_begin(Object *p_object) override;
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override;
- virtual void parse_end() override;
};
#endif // ROOT_MOTION_EDITOR_PLUGIN_H
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index aad378ecec..a0add041cb 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -46,7 +46,7 @@
#include "editor/find_in_files.h"
#include "editor/node_dock.h"
#include "editor/plugins/shader_editor_plugin.h"
-#include "modules/visual_script/visual_script_editor.h"
+#include "modules/visual_script/editor/visual_script_editor.h"
#include "scene/main/window.h"
#include "scene/scene_string_names.h"
#include "script_text_editor.h"
@@ -989,10 +989,6 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
RES script = se->get_edited_resource();
- if (script->is_built_in()) {
- continue; //internal script, who cares
- }
-
if (script == p_res) {
se->tag_saved_version();
}
@@ -1002,6 +998,31 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
_trigger_live_script_reload();
}
+void ScriptEditor::_scene_saved_callback(const String &p_path) {
+ // If scene was saved, mark all built-in scripts from that scene as saved.
+ for (int i = 0; i < tab_container->get_child_count(); i++) {
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
+ if (!se) {
+ continue;
+ }
+
+ RES edited_res = se->get_edited_resource();
+
+ if (!edited_res->is_built_in()) {
+ continue; // External script, who cares.
+ }
+
+ if (edited_res->get_path().get_slice("::", 0) == p_path) {
+ se->tag_saved_version();
+ }
+
+ Ref<Script> scr = edited_res;
+ if (scr.is_valid() && scr->is_tool()) {
+ scr->reload(true);
+ }
+ }
+}
+
void ScriptEditor::_trigger_live_script_reload() {
if (!pending_auto_reload && auto_reload_running_scripts) {
call_deferred(SNAME("_live_auto_reload_running_scripts"));
@@ -1525,6 +1546,7 @@ void ScriptEditor::_notification(int p_what) {
editor->connect("stop_pressed", callable_mp(this, &ScriptEditor::_editor_stop));
editor->connect("script_add_function_request", callable_mp(this, &ScriptEditor::_add_callback));
editor->connect("resource_saved", callable_mp(this, &ScriptEditor::_res_saved_callback));
+ editor->connect("scene_saved", callable_mp(this, &ScriptEditor::_scene_saved_callback));
editor->get_filesystem_dock()->connect("files_moved", callable_mp(this, &ScriptEditor::_files_moved));
editor->get_filesystem_dock()->connect("file_removed", callable_mp(this, &ScriptEditor::_file_removed));
script_list->connect("item_selected", callable_mp(this, &ScriptEditor::_script_selected));
@@ -1619,7 +1641,7 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) {
}
if (script->is_built_in() && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
- _close_tab(i);
+ _close_tab(i, false);
i--;
}
}
@@ -1926,20 +1948,7 @@ void ScriptEditor::_update_script_names() {
// to update original path to previously edited resource.
se->set_meta("_edit_res_path", path);
}
- bool built_in = !path.is_resource_file();
- String name;
-
- if (built_in) {
- name = path.get_file();
- const String &resource_name = se->get_edited_resource()->get_name();
- if (resource_name != "") {
- // If the built-in script has a custom resource name defined,
- // display the built-in script name as follows: `ResourceName (scene_file.tscn)`
- name = vformat("%s (%s)", resource_name, name.substr(0, name.find("::", 0)));
- }
- } else {
- name = se->get_name();
- }
+ String name = se->get_name();
_ScriptEditorItemData sd;
sd.icon = icon;
@@ -2403,7 +2412,17 @@ void ScriptEditor::save_current_script() {
}
}
- editor->save_resource(resource);
+ if (resource->is_built_in()) {
+ // If built-in script, save the scene instead.
+ const String scene_path = resource->get_path().get_slice("::", 0);
+ if (!scene_path.is_empty()) {
+ Vector<String> scene_to_save;
+ scene_to_save.push_back(scene_path);
+ editor->save_scene_list(scene_to_save);
+ }
+ } else {
+ editor->save_resource(resource);
+ }
if (script != nullptr) {
const Vector<DocData::ClassDoc> &documentations = script->get_documentation();
@@ -2416,6 +2435,8 @@ void ScriptEditor::save_current_script() {
}
void ScriptEditor::save_all_scripts() {
+ Vector<String> scenes_to_save;
+
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se) {
@@ -2474,9 +2495,19 @@ void ScriptEditor::save_all_scripts() {
update_doc(doc.name);
}
}
+ } else {
+ // For built-in scripts, save their scenes instead.
+ const String scene_path = edited_res->get_path().get_slice("::", 0);
+ if (!scenes_to_save.has(scene_path)) {
+ scenes_to_save.push_back(scene_path);
+ }
}
}
+ if (!scenes_to_save.is_empty()) {
+ editor->save_scene_list(scenes_to_save);
+ }
+
_update_script_names();
EditorFileSystem::get_singleton()->update_script_classes();
}
@@ -3434,6 +3465,9 @@ void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_numb
shader_editor->make_visible(true);
shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end);
return;
+ } else if (fpath.get_extension() == "tscn") {
+ editor->load_scene(fpath);
+ return;
} else {
Ref<Script> script = res;
if (script.is_valid()) {
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 2b0bdfd109..0adeca031e 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -365,6 +365,7 @@ class ScriptEditor : public PanelContainer {
void _add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args);
void _res_saved_callback(const Ref<Resource> &p_res);
+ void _scene_saved_callback(const String &p_path);
bool open_textfile_after_create = true;
bool trim_trailing_whitespace_on_save;
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 24cdc06d78..a5088a5246 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -375,18 +375,21 @@ void ScriptTextEditor::ensure_focus() {
String ScriptTextEditor::get_name() {
String name;
- if (!script->is_built_in()) {
- name = script->get_path().get_file();
- if (is_unsaved()) {
- if (script->get_path().is_empty()) {
- name = TTR("[unsaved]");
- }
- name += "(*)";
+ name = script->get_path().get_file();
+ if (name.is_empty()) {
+ // This appears for newly created built-in scripts before saving the scene.
+ name = TTR("[unsaved]");
+ } else if (script->is_built_in()) {
+ const String &script_name = script->get_name();
+ if (script_name != "") {
+ // If the built-in script has a custom resource name defined,
+ // display the built-in script name as follows: `ResourceName (scene_file.tscn)`
+ name = vformat("%s (%s)", script_name, name.get_slice("::", 0));
}
- } else if (script->get_name() != "") {
- name = script->get_name();
- } else {
- name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
+ }
+
+ if (is_unsaved()) {
+ name += "(*)";
}
return name;
@@ -1626,10 +1629,7 @@ void ScriptTextEditor::_color_changed(const Color &p_color) {
}
String line = code_editor->get_text_editor()->get_line(color_position.x);
- int color_args_pos = line.find(color_args, color_position.y);
- String line_with_replaced_args = line;
- line_with_replaced_args.erase(color_args_pos, color_args.length());
- line_with_replaced_args = line_with_replaced_args.insert(color_args_pos, new_args);
+ String line_with_replaced_args = line.replace(color_args, new_args);
color_args = new_args;
code_editor->get_text_editor()->begin_complex_operation();
diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp
index 91c5e96f08..1c7f319280 100644
--- a/editor/plugins/style_box_editor_plugin.cpp
+++ b/editor/plugins/style_box_editor_plugin.cpp
@@ -44,13 +44,6 @@ void EditorInspectorPluginStyleBox::parse_begin(Object *p_object) {
add_custom_control(preview);
}
-bool EditorInspectorPluginStyleBox::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, bool p_wide) {
- return false; //do not want
-}
-
-void EditorInspectorPluginStyleBox::parse_end() {
-}
-
void StyleBoxPreview::edit(const Ref<StyleBox> &p_stylebox) {
if (stylebox.is_valid()) {
stylebox->disconnect("changed", callable_mp(this, &StyleBoxPreview::_sb_changed));
diff --git a/editor/plugins/style_box_editor_plugin.h b/editor/plugins/style_box_editor_plugin.h
index 8ca348bd80..d82e5ab05e 100644
--- a/editor/plugins/style_box_editor_plugin.h
+++ b/editor/plugins/style_box_editor_plugin.h
@@ -61,8 +61,6 @@ class EditorInspectorPluginStyleBox : public EditorInspectorPlugin {
public:
virtual bool can_handle(Object *p_object) override;
virtual void parse_begin(Object *p_object) override;
- virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override;
- virtual void parse_end() override;
};
class StyleBoxEditorPlugin : public EditorPlugin {
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index 3b45f32927..8186c2c84c 100644
--- a/editor/plugins/text_editor.cpp
+++ b/editor/plugins/text_editor.cpp
@@ -65,18 +65,21 @@ void TextEditor::_load_theme_settings() {
String TextEditor::get_name() {
String name;
- if (!text_file->is_built_in()) {
- name = text_file->get_path().get_file();
- if (is_unsaved()) {
- if (text_file->get_path().is_empty()) {
- name = TTR("[unsaved]");
- }
- name += "(*)";
+ name = text_file->get_path().get_file();
+ if (name.is_empty()) {
+ // This appears for newly created built-in text_files before saving the scene.
+ name = TTR("[unsaved]");
+ } else if (text_file->is_built_in()) {
+ const String &text_file_name = text_file->get_name();
+ if (text_file_name != "") {
+ // If the built-in text_file has a custom resource name defined,
+ // display the built-in text_file name as follows: `ResourceName (scene_file.tscn)`
+ name = vformat("%s (%s)", text_file_name, name.get_slice("::", 0));
}
- } else if (text_file->get_name() != "") {
- name = text_file->get_name();
- } else {
- name = text_file->get_class() + "(" + itos(text_file->get_instance_id()) + ")";
+ }
+
+ if (is_unsaved()) {
+ name += "(*)";
}
return name;
diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp
index e9d80bb4b8..a215939de9 100644
--- a/editor/plugins/tiles/tile_data_editors.cpp
+++ b/editor/plugins/tiles/tile_data_editors.cpp
@@ -125,7 +125,14 @@ void GenericTilePolygonEditor::_base_control_draw() {
Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color");
const Ref<Texture2D> handle = get_theme_icon(SNAME("EditorPathSharpHandle"), SNAME("EditorIcons"));
const Ref<Texture2D> add_handle = get_theme_icon(SNAME("EditorHandleAdd"), SNAME("EditorIcons"));
+ const Ref<StyleBox> focus_stylebox = get_theme_stylebox(SNAME("Focus"), SNAME("EditorStyles"));
+ // Draw the focus rectangle.
+ if (base_control->has_focus()) {
+ base_control->draw_style_box(focus_stylebox, Rect2(Vector2(), base_control->get_size()));
+ }
+
+ // Draw tile-related things.
Size2 tile_size = tile_set->get_tile_size();
Transform2D xform;
@@ -240,9 +247,10 @@ void GenericTilePolygonEditor::_zoom_changed() {
}
void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
+ UndoRedo *undo_redo = use_undo_redo ? editor_undo_redo : memnew(UndoRedo);
switch (p_item_pressed) {
case RESET_TO_DEFAULT_TILE: {
- undo_redo->create_action(TTR("Edit Polygons"));
+ undo_redo->create_action(TTR("Reset Polygons"));
undo_redo->add_do_method(this, "clear_polygons");
Vector<Vector2> polygon = tile_set->get_tile_shape_polygon();
for (int i = 0; i < polygon.size(); i++) {
@@ -260,7 +268,7 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->commit_action(true);
} break;
case CLEAR_TILE: {
- undo_redo->create_action(TTR("Edit Polygons"));
+ undo_redo->create_action(TTR("Clear Polygons"));
undo_redo->add_do_method(this, "clear_polygons");
undo_redo->add_do_method(base_control, "update");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
@@ -272,9 +280,50 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
undo_redo->commit_action(true);
} break;
+ case ROTATE_RIGHT:
+ case ROTATE_LEFT:
+ case FLIP_HORIZONTALLY:
+ case FLIP_VERTICALLY: {
+ undo_redo->create_action(TTR("Rotate Polygons Left"));
+ for (unsigned int i = 0; i < polygons.size(); i++) {
+ Vector<Point2> new_polygon;
+ for (int point_index = 0; point_index < polygons[i].size(); point_index++) {
+ Vector2 point = polygons[i][point_index];
+ switch (p_item_pressed) {
+ case ROTATE_RIGHT: {
+ point = Vector2(-point.y, point.x);
+ } break;
+ case ROTATE_LEFT: {
+ point = Vector2(point.y, -point.x);
+ } break;
+ case FLIP_HORIZONTALLY: {
+ point = Vector2(-point.x, point.y);
+ } break;
+ case FLIP_VERTICALLY: {
+ point = Vector2(point.x, -point.y);
+ } break;
+ default:
+ break;
+ }
+ new_polygon.push_back(point);
+ }
+ undo_redo->add_do_method(this, "set_polygon", i, new_polygon);
+ }
+ undo_redo->add_do_method(base_control, "update");
+ undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
+ for (unsigned int i = 0; i < polygons.size(); i++) {
+ undo_redo->add_undo_method(this, "set_polygon", polygons[i]);
+ }
+ undo_redo->add_undo_method(base_control, "update");
+ undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
+ undo_redo->commit_action(true);
+ } break;
default:
break;
}
+ if (!use_undo_redo) {
+ memdelete(undo_redo);
+ }
}
void GenericTilePolygonEditor::_grab_polygon_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_point_index) {
@@ -359,6 +408,7 @@ void GenericTilePolygonEditor::_snap_to_half_pixel(Point2 &r_point) {
}
void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event) {
+ UndoRedo *undo_redo = use_undo_redo ? editor_undo_redo : memnew(UndoRedo);
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
hovered_polygon_index = -1;
@@ -549,21 +599,47 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
}
base_control->update();
+
+ if (!use_undo_redo) {
+ memdelete(undo_redo);
+ }
+}
+
+void GenericTilePolygonEditor::set_use_undo_redo(bool p_use_undo_redo) {
+ use_undo_redo = p_use_undo_redo;
}
void GenericTilePolygonEditor::set_tile_set(Ref<TileSet> p_tile_set) {
- if (tile_set != p_tile_set) {
- // Set the default tile shape
- clear_polygons();
- if (p_tile_set.is_valid()) {
- Vector<Vector2> polygon = p_tile_set->get_tile_shape_polygon();
- for (int i = 0; i < polygon.size(); i++) {
- polygon.write[i] = polygon[i] * p_tile_set->get_tile_size();
- }
- add_polygon(polygon);
+ ERR_FAIL_COND(!p_tile_set.is_valid());
+ if (tile_set == p_tile_set) {
+ return;
+ }
+
+ // Set the default tile shape
+ clear_polygons();
+ if (p_tile_set.is_valid()) {
+ Vector<Vector2> polygon = p_tile_set->get_tile_shape_polygon();
+ for (int i = 0; i < polygon.size(); i++) {
+ polygon.write[i] = polygon[i] * p_tile_set->get_tile_size();
}
+ add_polygon(polygon);
}
+
tile_set = p_tile_set;
+
+ // Set the default zoom value.
+ int default_control_y_size = 200 * EDSCALE;
+ Vector2 zoomed_tile = editor_zoom_widget->get_zoom() * tile_set->get_tile_size();
+ while (zoomed_tile.y < default_control_y_size) {
+ editor_zoom_widget->set_zoom_by_increments(6, false);
+ zoomed_tile = editor_zoom_widget->get_zoom() * tile_set->get_tile_size();
+ }
+ while (zoomed_tile.y > default_control_y_size) {
+ editor_zoom_widget->set_zoom_by_increments(-6, false);
+ zoomed_tile = editor_zoom_widget->get_zoom() * tile_set->get_tile_size();
+ }
+ editor_zoom_widget->set_zoom_by_increments(-6, false);
+ _zoom_changed();
}
void GenericTilePolygonEditor::set_background(Ref<Texture2D> p_texture, Rect2 p_region, Vector2 p_offset, bool p_flip_h, bool p_flip_v, bool p_transpose, Color p_modulate) {
@@ -644,6 +720,12 @@ void GenericTilePolygonEditor::_notification(int p_what) {
button_center_view->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("CenterView"), SNAME("EditorIcons")));
button_pixel_snap->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Snap"), SNAME("EditorIcons")));
button_advanced_menu->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
+
+ PopupMenu *p = button_advanced_menu->get_popup();
+ p->set_item_icon(p->get_item_index(ROTATE_RIGHT), get_theme_icon(SNAME("RotateRight"), SNAME("EditorIcons")));
+ p->set_item_icon(p->get_item_index(ROTATE_LEFT), get_theme_icon(SNAME("RotateLeft"), SNAME("EditorIcons")));
+ p->set_item_icon(p->get_item_index(FLIP_HORIZONTALLY), get_theme_icon(SNAME("MirrorX"), SNAME("EditorIcons")));
+ p->set_item_icon(p->get_item_index(FLIP_VERTICALLY), get_theme_icon(SNAME("MirrorY"), SNAME("EditorIcons")));
break;
}
}
@@ -670,18 +752,21 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() {
button_create->set_toggle_mode(true);
button_create->set_button_group(tools_button_group);
button_create->set_pressed(true);
+ button_create->set_tooltip(TTR("Add polygon tool"));
toolbar->add_child(button_create);
button_edit = memnew(Button);
button_edit->set_flat(true);
button_edit->set_toggle_mode(true);
button_edit->set_button_group(tools_button_group);
+ button_edit->set_tooltip(TTR("Edit points tool"));
toolbar->add_child(button_edit);
button_delete = memnew(Button);
button_delete->set_flat(true);
button_delete->set_toggle_mode(true);
button_delete->set_button_group(tools_button_group);
+ button_delete->set_tooltip(TTR("Delete points tool"));
toolbar->add_child(button_delete);
button_advanced_menu = memnew(MenuButton);
@@ -689,7 +774,13 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() {
button_advanced_menu->set_toggle_mode(true);
button_advanced_menu->get_popup()->add_item(TTR("Reset to default tile shape"), RESET_TO_DEFAULT_TILE);
button_advanced_menu->get_popup()->add_item(TTR("Clear"), CLEAR_TILE);
+ button_advanced_menu->get_popup()->add_separator();
+ button_advanced_menu->get_popup()->add_icon_item(get_theme_icon(SNAME("RotateRight"), SNAME("EditorIcons")), TTR("Rotate Right"), ROTATE_RIGHT);
+ button_advanced_menu->get_popup()->add_icon_item(get_theme_icon(SNAME("RotateLeft"), SNAME("EditorIcons")), TTR("Rotate Left"), ROTATE_LEFT);
+ button_advanced_menu->get_popup()->add_icon_item(get_theme_icon(SNAME("MirrorX"), SNAME("EditorIcons")), TTR("Flip Horizontally"), FLIP_HORIZONTALLY);
+ button_advanced_menu->get_popup()->add_icon_item(get_theme_icon(SNAME("MirrorY"), SNAME("EditorIcons")), TTR("Flip Vertically"), FLIP_VERTICALLY);
button_advanced_menu->get_popup()->connect("id_pressed", callable_mp(this, &GenericTilePolygonEditor::_advanced_menu_item_pressed));
+ button_advanced_menu->set_focus_mode(FOCUS_ALL);
toolbar->add_child(button_advanced_menu);
toolbar->add_child(memnew(VSeparator));
@@ -698,6 +789,7 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() {
button_pixel_snap->set_flat(true);
button_pixel_snap->set_toggle_mode(true);
button_pixel_snap->set_pressed(true);
+ button_pixel_snap->set_tooltip(TTR("Snap to half-pixel"));
toolbar->add_child(button_pixel_snap);
Control *root = memnew(Control);
@@ -717,6 +809,7 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() {
base_control->connect("draw", callable_mp(this, &GenericTilePolygonEditor::_base_control_draw));
base_control->connect("gui_input", callable_mp(this, &GenericTilePolygonEditor::_base_control_gui_input));
base_control->set_clip_contents(true);
+ base_control->set_focus_mode(Control::FOCUS_CLICK);
root->add_child(base_control);
editor_zoom_widget = memnew(EditorZoomWidget);
@@ -1432,7 +1525,7 @@ TileDataCollisionEditor::TileDataCollisionEditor() {
angular_velocity_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1));
angular_velocity_editor->update_property();
add_child(angular_velocity_editor);
- property_editors["angular_velocity"] = linear_velocity_editor;
+ property_editors["angular_velocity"] = angular_velocity_editor;
_polygons_changed();
}
diff --git a/editor/plugins/tiles/tile_data_editors.h b/editor/plugins/tiles/tile_data_editors.h
index acb4c5882d..3fc5e738bb 100644
--- a/editor/plugins/tiles/tile_data_editors.h
+++ b/editor/plugins/tiles/tile_data_editors.h
@@ -94,7 +94,8 @@ private:
LocalVector<Vector<Point2>> polygons;
bool multiple_polygon_mode = false;
- UndoRedo *undo_redo = EditorNode::get_undo_redo();
+ bool use_undo_redo = true;
+ UndoRedo *editor_undo_redo = EditorNode::get_undo_redo();
// UI
int hovered_polygon_index = -1;
@@ -108,7 +109,7 @@ private:
DRAG_TYPE_CREATE_POINT,
DRAG_TYPE_PAN,
};
- DragType drag_type;
+ DragType drag_type = DRAG_TYPE_NONE;
int drag_polygon_index;
int drag_point_index;
Vector2 drag_last_pos;
@@ -143,6 +144,10 @@ private:
enum AdvancedMenuOption {
RESET_TO_DEFAULT_TILE,
CLEAR_TILE,
+ ROTATE_RIGHT,
+ ROTATE_LEFT,
+ FLIP_HORIZONTALLY,
+ FLIP_VERTICALLY,
};
void _base_control_draw();
@@ -161,6 +166,8 @@ protected:
static void _bind_methods();
public:
+ void set_use_undo_redo(bool p_use_undo_redo);
+
void set_tile_set(Ref<TileSet> p_tile_set);
void set_background(Ref<Texture2D> p_texture, Rect2 p_region = Rect2(), Vector2 p_offset = Vector2(), bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false, Color p_modulate = Color(1.0, 1.0, 1.0, 0.0));
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
index ae744f697b..4ecb4717e3 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
@@ -99,6 +99,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_get_property_list
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "margins", PROPERTY_HINT_NONE, ""));
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "separation", PROPERTY_HINT_NONE, ""));
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "texture_region_size", PROPERTY_HINT_NONE, ""));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "use_texture_padding", PROPERTY_HINT_NONE, ""));
}
void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_bind_methods() {
@@ -2061,7 +2062,7 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo
int new_polygons_count = p_new_value;
int old_polygons_count = tile_data_proxy->get(vformat("physics_layer_%d/polygons_count", layer_index));
if (new_polygons_count < old_polygons_count) {
- for (int i = new_polygons_count - 1; i < old_polygons_count; i++) {
+ for (int i = new_polygons_count; i < old_polygons_count; i++) {
ADD_UNDO(tile_data_proxy, vformat("physics_layer_%d/polygon_%d/points", layer_index, i));
ADD_UNDO(tile_data_proxy, vformat("physics_layer_%d/polygon_%d/one_way", layer_index, i));
ADD_UNDO(tile_data_proxy, vformat("physics_layer_%d/polygon_%d/one_way_margin", layer_index, i));
@@ -2534,9 +2535,194 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
right_panel->add_child(tile_atlas_view_missing_source_label);
EditorNode::get_singleton()->get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &TileSetAtlasSourceEditor::_undo_redo_inspector_callback));
+
+ // Inspector plugin.
+ Ref<EditorInspectorPluginTileData> tile_data_inspector_plugin;
+ tile_data_inspector_plugin.instantiate();
+ EditorInspector::add_inspector_plugin(tile_data_inspector_plugin);
}
TileSetAtlasSourceEditor::~TileSetAtlasSourceEditor() {
memdelete(tile_proxy_object);
memdelete(atlas_source_proxy_object);
}
+
+////// EditorPropertyTilePolygon //////
+
+void EditorPropertyTilePolygon::_add_focusable_children(Node *p_node) {
+ Control *control = Object::cast_to<Control>(p_node);
+ if (control && control->get_focus_mode() != Control::FOCUS_NONE) {
+ add_focusable(control);
+ }
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+ _add_focusable_children(p_node->get_child(i));
+ }
+}
+
+void EditorPropertyTilePolygon::_polygons_changed() {
+ if (String(count_property).is_empty()) {
+ if (base_type == "OccluderPolygon2D") {
+ // Single OccluderPolygon2D.
+ Ref<OccluderPolygon2D> occluder;
+ if (generic_tile_polygon_editor->get_polygon_count() >= 1) {
+ occluder.instantiate();
+ occluder->set_polygon(generic_tile_polygon_editor->get_polygon(0));
+ }
+ emit_changed(get_edited_property(), occluder);
+ } else if (base_type == "NavigationPolygon") {
+ Ref<NavigationPolygon> navigation_polygon;
+ if (generic_tile_polygon_editor->get_polygon_count() >= 1) {
+ navigation_polygon.instantiate();
+ for (int i = 0; i < generic_tile_polygon_editor->get_polygon_count(); i++) {
+ Vector<Vector2> polygon = generic_tile_polygon_editor->get_polygon(i);
+ navigation_polygon->add_outline(polygon);
+ }
+ navigation_polygon->make_polygons_from_outlines();
+ }
+ emit_changed(get_edited_property(), navigation_polygon);
+ }
+ } else {
+ if (base_type.is_empty()) {
+ // Multiple array of vertices.
+ Vector<String> changed_properties;
+ Array values;
+ int count = generic_tile_polygon_editor->get_polygon_count();
+ changed_properties.push_back(count_property);
+ values.push_back(count);
+ for (int i = 0; i < count; i++) {
+ changed_properties.push_back(vformat(element_pattern, i));
+ values.push_back(generic_tile_polygon_editor->get_polygon(i));
+ }
+ emit_signal("multiple_properties_changed", changed_properties, values, false);
+ }
+ }
+}
+
+void EditorPropertyTilePolygon::update_property() {
+ TileSetAtlasSourceEditor::AtlasTileProxyObject *atlas_tile_proxy_object = Object::cast_to<TileSetAtlasSourceEditor::AtlasTileProxyObject>(get_edited_object());
+ ERR_FAIL_COND(!atlas_tile_proxy_object);
+ ERR_FAIL_COND(atlas_tile_proxy_object->get_edited_tiles().is_empty());
+
+ TileSetAtlasSource *tile_set_atlas_source = atlas_tile_proxy_object->get_edited_tile_set_atlas_source();
+ generic_tile_polygon_editor->set_tile_set(Ref<TileSet>(tile_set_atlas_source->get_tile_set()));
+
+ // Set the background
+ Vector2i coords = atlas_tile_proxy_object->get_edited_tiles().front()->get().tile;
+ int alternative = atlas_tile_proxy_object->get_edited_tiles().front()->get().alternative;
+ TileData *tile_data = Object::cast_to<TileData>(tile_set_atlas_source->get_tile_data(coords, alternative));
+ generic_tile_polygon_editor->set_background(tile_set_atlas_source->get_texture(), tile_set_atlas_source->get_tile_texture_region(coords), tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate());
+
+ // Reset the polygons.
+ generic_tile_polygon_editor->clear_polygons();
+
+ if (String(count_property).is_empty()) {
+ if (base_type == "OccluderPolygon2D") {
+ // Single OccluderPolygon2D.
+ Ref<OccluderPolygon2D> occluder = get_edited_object()->get(get_edited_property());
+ generic_tile_polygon_editor->clear_polygons();
+ if (occluder.is_valid()) {
+ generic_tile_polygon_editor->add_polygon(occluder->get_polygon());
+ }
+ } else if (base_type == "NavigationPolygon") {
+ // Single OccluderPolygon2D.
+ Ref<NavigationPolygon> navigation_polygon = get_edited_object()->get(get_edited_property());
+ generic_tile_polygon_editor->clear_polygons();
+ if (navigation_polygon.is_valid()) {
+ for (int i = 0; i < navigation_polygon->get_outline_count(); i++) {
+ generic_tile_polygon_editor->add_polygon(navigation_polygon->get_outline(i));
+ }
+ }
+ }
+ } else {
+ int count = get_edited_object()->get(count_property);
+ if (base_type.is_empty()) {
+ // Multiple array of vertices.
+ generic_tile_polygon_editor->clear_polygons();
+ for (int i = 0; i < count; i++) {
+ generic_tile_polygon_editor->add_polygon(get_edited_object()->get(vformat(element_pattern, i)));
+ }
+ }
+ }
+}
+
+void EditorPropertyTilePolygon::setup_single_mode(const StringName &p_property, const String &p_base_type) {
+ set_object_and_property(nullptr, p_property);
+ base_type = p_base_type;
+
+ generic_tile_polygon_editor->set_multiple_polygon_mode(false);
+}
+
+void EditorPropertyTilePolygon::setup_multiple_mode(const StringName &p_property, const StringName &p_count_property, const String &p_element_pattern, const String &p_base_type) {
+ set_object_and_property(nullptr, p_property);
+ count_property = p_count_property;
+ element_pattern = p_element_pattern;
+ base_type = p_base_type;
+
+ generic_tile_polygon_editor->set_multiple_polygon_mode(true);
+}
+
+EditorPropertyTilePolygon::EditorPropertyTilePolygon() {
+ // Setup the polygon editor.
+ generic_tile_polygon_editor = memnew(GenericTilePolygonEditor);
+ generic_tile_polygon_editor->set_use_undo_redo(false);
+ generic_tile_polygon_editor->clear_polygons();
+ add_child(generic_tile_polygon_editor);
+ generic_tile_polygon_editor->connect("polygons_changed", callable_mp(this, &EditorPropertyTilePolygon::_polygons_changed));
+
+ // Add all focussable children of generic_tile_polygon_editor as focussable.
+ _add_focusable_children(generic_tile_polygon_editor);
+}
+
+////// EditorInspectorPluginTileData //////
+
+bool EditorInspectorPluginTileData::can_handle(Object *p_object) {
+ return Object::cast_to<TileSetAtlasSourceEditor::AtlasTileProxyObject>(p_object) != nullptr;
+}
+
+bool EditorInspectorPluginTileData::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
+ Vector<String> components = String(p_path).split("/", true, 2);
+ if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) {
+ // Occlusion layers.
+ int layer_index = components[0].trim_prefix("occlusion_layer_").to_int();
+ ERR_FAIL_COND_V(layer_index < 0, false);
+ if (components[1] == "polygon") {
+ EditorPropertyTilePolygon *ep = memnew(EditorPropertyTilePolygon);
+ ep->setup_single_mode(p_path, "OccluderPolygon2D");
+ add_property_editor(p_path, ep);
+ return true;
+ }
+ } else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
+ // Physics layers.
+ int layer_index = components[0].trim_prefix("physics_layer_").to_int();
+ ERR_FAIL_COND_V(layer_index < 0, false);
+ if (components[1] == "polygons_count") {
+ EditorPropertyTilePolygon *ep = memnew(EditorPropertyTilePolygon);
+ ep->setup_multiple_mode(vformat("physics_layer_%d/polygons", layer_index), vformat("physics_layer_%d/polygons_count", layer_index), vformat("physics_layer_%d/polygon_%%d/points", layer_index), "");
+ Vector<String> properties;
+ properties.push_back(p_path);
+ int count = p_object->get(vformat("physics_layer_%d/polygons_count", layer_index));
+ for (int i = 0; i < count; i++) {
+ properties.push_back(vformat(vformat("physics_layer_%d/polygon_%d/points", layer_index, i)));
+ }
+ add_property_editor_for_multiple_properties("Polygons", properties, ep);
+ return true;
+ } else if (components.size() == 3 && components[1].begins_with("polygon_") && components[1].trim_prefix("polygon_").is_valid_int()) {
+ int polygon_index = components[1].trim_prefix("polygon_").to_int();
+ ERR_FAIL_COND_V(polygon_index < 0, false);
+ if (components[2] == "points") {
+ return true;
+ }
+ }
+ } else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
+ // Navigation layers.
+ int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
+ ERR_FAIL_COND_V(layer_index < 0, false);
+ if (components[1] == "polygon") {
+ EditorPropertyTilePolygon *ep = memnew(EditorPropertyTilePolygon);
+ ep->setup_single_mode(p_path, "NavigationPolygon");
+ add_property_editor(p_path, ep);
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.h b/editor/plugins/tiles/tile_set_atlas_source_editor.h
index ea6f2847ae..bd1fd2e7d0 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.h
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.h
@@ -43,7 +43,7 @@ class TileSet;
class TileSetAtlasSourceEditor : public HBoxContainer {
GDCLASS(TileSetAtlasSourceEditor, HBoxContainer);
-private:
+public:
// A class to store which tiles are selected.
struct TileSelection {
Vector2i tile = TileSetSource::INVALID_ATLAS_COORDS;
@@ -99,6 +99,9 @@ private:
static void _bind_methods();
public:
+ TileSetAtlasSource *get_edited_tile_set_atlas_source() const { return tile_set_atlas_source; };
+ Set<TileSelection> get_edited_tiles() const { return tiles; };
+
// Update the proxyed object.
void edit(TileSetAtlasSource *p_tile_set_atlas_source, Set<TileSelection> p_tiles = Set<TileSelection>());
@@ -107,6 +110,7 @@ private:
}
};
+private:
Ref<TileSet> tile_set;
TileSetAtlasSource *tile_set_atlas_source = nullptr;
int tile_set_atlas_source_id = TileSet::INVALID_SOURCE;
@@ -281,4 +285,34 @@ public:
~TileSetAtlasSourceEditor();
};
+class EditorPropertyTilePolygon : public EditorProperty {
+ GDCLASS(EditorPropertyTilePolygon, EditorProperty);
+
+ StringName count_property;
+ String element_pattern;
+ String base_type;
+
+ void _add_focusable_children(Node *p_node);
+
+ GenericTilePolygonEditor *generic_tile_polygon_editor;
+ void _polygons_changed();
+
+public:
+ virtual void update_property() override;
+ void setup_single_mode(const StringName &p_property, const String &p_base_type);
+ void setup_multiple_mode(const StringName &p_property, const StringName &p_count_property, const String &p_element_pattern, const String &p_base_type);
+ EditorPropertyTilePolygon();
+};
+
+class EditorInspectorPluginTileData : public EditorInspectorPlugin {
+ GDCLASS(EditorInspectorPluginTileData, EditorInspectorPlugin);
+
+ void _occlusion_polygon_set_callback();
+ void _polygons_changed(Object *p_generic_tile_polygon_editor, Object *p_object, const String &p_path);
+
+public:
+ virtual bool can_handle(Object *p_object) override;
+ virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override;
+};
+
#endif // TILE_SET_ATLAS_SOURCE_EDITOR_H
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 10a9b2bb10..140ee0cffc 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -4527,6 +4527,7 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("MultiplyByAxisAngle", "Particles", "Transform", "VisualShaderNodeParticleMultiplyByAxisAngle", "A node for help to multiply a position input vector by rotation using specific axis. Intended to work with emitters.", -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT | TYPE_FLAGS_PROCESS | TYPE_FLAGS_COLLIDE, Shader::MODE_PARTICLES));
add_options.push_back(AddOption("BoxEmitter", "Particles", "Emitters", "VisualShaderNodeParticleBoxEmitter", "", -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
+ add_options.push_back(AddOption("MeshEmitter", "Particles", "Emitters", "VisualShaderNodeParticleMeshEmitter", "", -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
add_options.push_back(AddOption("RingEmitter", "Particles", "Emitters", "VisualShaderNodeParticleRingEmitter", "", -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
add_options.push_back(AddOption("SphereEmitter", "Particles", "Emitters", "VisualShaderNodeParticleSphereEmitter", "", -1, VisualShaderNode::PORT_TYPE_VECTOR, TYPE_FLAGS_EMIT, Shader::MODE_PARTICLES));
@@ -5186,11 +5187,7 @@ EditorPropertyShaderMode::EditorPropertyShaderMode() {
}
bool EditorInspectorShaderModePlugin::can_handle(Object *p_object) {
- return true; //can handle everything
-}
-
-void EditorInspectorShaderModePlugin::parse_begin(Object *p_object) {
- //do none
+ return true; // Can handle everything.
}
bool EditorInspectorShaderModePlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
@@ -5203,11 +5200,7 @@ bool EditorInspectorShaderModePlugin::parse_property(Object *p_object, const Var
return true;
}
- return false; //can be overridden, although it will most likely be last anyway
-}
-
-void EditorInspectorShaderModePlugin::parse_end() {
- //do none
+ return false;
}
//////////////////////////////////
@@ -5224,7 +5217,9 @@ void VisualShaderNodePortPreview::_shader_changed() {
preview_shader.instantiate();
preview_shader->set_code(shader_code);
for (int i = 0; i < default_textures.size(); i++) {
- preview_shader->set_default_texture_param(default_textures[i].name, default_textures[i].param);
+ for (int j = 0; j < default_textures[i].params.size(); j++) {
+ preview_shader->set_default_texture_param(default_textures[i].name, default_textures[i].params[j], j);
+ }
}
Ref<ShaderMaterial> material;
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index c4a392469b..74ccda3c9a 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -523,9 +523,7 @@ class EditorInspectorShaderModePlugin : public EditorInspectorPlugin {
public:
virtual bool can_handle(Object *p_object) override;
- virtual void parse_begin(Object *p_object) override;
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override;
- virtual void parse_end() override;
};
class VisualShaderNodePortPreview : public Control {
diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp
index f5b70504fa..eb73f88e61 100644
--- a/editor/rename_dialog.cpp
+++ b/editor/rename_dialog.cpp
@@ -30,6 +30,7 @@
#include "rename_dialog.h"
+#include "modules/modules_enabled.gen.h" // For regex.
#ifdef MODULE_REGEX_ENABLED
#include "core/string/print_string.h"
diff --git a/editor/rename_dialog.h b/editor/rename_dialog.h
index 4db3ef6740..f383877eb2 100644
--- a/editor/rename_dialog.h
+++ b/editor/rename_dialog.h
@@ -31,17 +31,16 @@
#ifndef RENAME_DIALOG_H
#define RENAME_DIALOG_H
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For regex.
#ifdef MODULE_REGEX_ENABLED
+#include "core/object/undo_redo.h"
+#include "editor/scene_tree_editor.h"
#include "scene/gui/check_box.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/option_button.h"
#include "scene/gui/spin_box.h"
-#include "core/object/undo_redo.h"
-#include "editor/scene_tree_editor.h"
-
/**
@author Blazej Floch
*/
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 921befbb6b..def97345aa 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -52,6 +52,8 @@
#include "servers/display_server.h"
#include "servers/rendering_server.h"
+#include "modules/modules_enabled.gen.h" // For regex.
+
void SceneTreeDock::_nodes_drag_begin() {
if (restore_script_editor_on_drag) {
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
@@ -214,7 +216,7 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, N
for (int i = 0; i < instances.size(); i++) {
Node *instantiated_scene = instances[i];
- editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene);
+ editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene, true);
if (p_pos >= 0) {
editor_data->get_undo_redo().add_do_method(parent, "move_child", instantiated_scene, p_pos + i);
}
@@ -259,8 +261,8 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base)
int pos = base->get_index();
undo_redo->add_do_method(parent, "remove_child", base);
undo_redo->add_undo_method(parent, "remove_child", instantiated_scene);
- undo_redo->add_do_method(parent, "add_child", instantiated_scene);
- undo_redo->add_undo_method(parent, "add_child", base);
+ undo_redo->add_do_method(parent, "add_child", instantiated_scene, true);
+ undo_redo->add_undo_method(parent, "add_child", base, true);
undo_redo->add_do_method(parent, "move_child", instantiated_scene, pos);
undo_redo->add_undo_method(parent, "move_child", base, pos);
@@ -512,7 +514,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
ERR_CONTINUE(!dup);
- editor_data->get_undo_redo().add_do_method(paste_parent, "add_child", dup);
+ editor_data->get_undo_redo().add_do_method(paste_parent, "add_child", dup, true);
for (KeyValue<const Node *, Node *> &E2 : duplimap) {
Node *d = E2.value;
@@ -814,7 +816,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().create_action(TTR("Make node as Root"));
editor_data->get_undo_redo().add_do_method(node->get_parent(), "remove_child", node);
editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", node);
- editor_data->get_undo_redo().add_do_method(node, "add_child", root);
+ editor_data->get_undo_redo().add_do_method(node, "add_child", root, true);
editor_data->get_undo_redo().add_do_method(node, "set_scene_file_path", root->get_scene_file_path());
editor_data->get_undo_redo().add_do_method(root, "set_scene_file_path", String());
editor_data->get_undo_redo().add_do_method(node, "set_owner", (Object *)nullptr);
@@ -825,7 +827,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().add_undo_method(node, "set_scene_file_path", String());
editor_data->get_undo_redo().add_undo_method(node, "remove_child", root);
editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", root);
- editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node);
+ editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node, true);
editor_data->get_undo_redo().add_undo_method(node->get_parent(), "move_child", node, node->get_index());
editor_data->get_undo_redo().add_undo_method(root, "set_owner", (Object *)nullptr);
editor_data->get_undo_redo().add_undo_method(node, "set_owner", root);
@@ -1786,7 +1788,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
}
editor_data->get_undo_redo().add_do_method(node->get_parent(), "remove_child", node);
- editor_data->get_undo_redo().add_do_method(new_parent, "add_child", node);
+ editor_data->get_undo_redo().add_do_method(new_parent, "add_child", node, true);
if (p_position_in_parent >= 0) {
editor_data->get_undo_redo().add_do_method(new_parent, "move_child", node, p_position_in_parent + inc);
@@ -1859,7 +1861,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
int child_pos = node->get_index();
- editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node);
+ editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node, true);
editor_data->get_undo_redo().add_undo_method(node->get_parent(), "move_child", node, child_pos);
editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners);
if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == node) {
@@ -2072,7 +2074,7 @@ void SceneTreeDock::_delete_confirm(bool p_cut) {
}
editor_data->get_undo_redo().add_do_method(n->get_parent(), "remove_child", n);
- editor_data->get_undo_redo().add_undo_method(n->get_parent(), "add_child", n);
+ editor_data->get_undo_redo().add_undo_method(n->get_parent(), "add_child", n, true);
editor_data->get_undo_redo().add_undo_method(n->get_parent(), "move_child", n, n->get_index());
if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == n) {
editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", n);
diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h
index 8de9884019..c6e47fa002 100644
--- a/editor/scene_tree_dock.h
+++ b/editor/scene_tree_dock.h
@@ -48,6 +48,8 @@
#include "scene/gui/tree.h"
#include "scene_tree_editor.h"
+#include "modules/modules_enabled.gen.h" // For regex.
+
class EditorNode;
class ShaderCreateDialog;
diff --git a/main/main.cpp b/main/main.cpp
index 863ffccfae..f0f8c01592 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -57,7 +57,6 @@
#include "main/performance.h"
#include "main/splash.gen.h"
#include "main/splash_editor.gen.h"
-#include "modules/modules_enabled.gen.h"
#include "modules/register_module_types.h"
#include "platform/register_platform_apis.h"
#include "scene/main/scene_tree.h"
@@ -81,16 +80,16 @@
#endif
#ifdef TOOLS_ENABLED
-
#include "editor/doc_data_class_path.gen.h"
#include "editor/doc_tools.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/progress_dialog.h"
#include "editor/project_manager.h"
-
#endif
+#include "modules/modules_enabled.gen.h" // For mono.
+
/* Static members */
// Singletons
@@ -2050,9 +2049,7 @@ bool Main::start() {
GLOBAL_DEF("mono/debugger_agent/wait_timeout", 3000);
GLOBAL_DEF("mono/profiler/args", "log:calls,alloc,sample,output=output.mlpd");
GLOBAL_DEF("mono/profiler/enabled", false);
- GLOBAL_DEF("mono/unhandled_exception_policy", 0);
- // From editor/csharp_project.cpp.
- GLOBAL_DEF("mono/project/auto_update_project", true);
+ GLOBAL_DEF("mono/runtime/unhandled_exception_policy", 0);
#endif
DocTools doc;
@@ -2689,10 +2686,10 @@ bool Main::iteration() {
if (frame > 1000000) {
if (editor || project_manager) {
if (print_fps) {
- print_line(vformat("Editor FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(1)));
+ print_line(vformat("Editor FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(2)));
}
} else if (GLOBAL_GET("debug/settings/stdout/print_fps") || print_fps) {
- print_line(vformat("Project FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(1)));
+ print_line(vformat("Project FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(2)));
}
Engine::get_singleton()->_fps = frames;
diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp
index 610d2145cd..684a20cf4d 100644
--- a/modules/bullet/bullet_physics_server.cpp
+++ b/modules/bullet/bullet_physics_server.cpp
@@ -837,8 +837,17 @@ void BulletPhysicsServer3D::body_set_ray_pickable(RID p_body, bool p_enable) {
}
PhysicsDirectBodyState3D *BulletPhysicsServer3D::body_get_direct_state(RID p_body) {
+ if (!rigid_body_owner.owns(p_body)) {
+ return nullptr;
+ }
+
RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body);
ERR_FAIL_COND_V(!body, nullptr);
+
+ if (!body->get_space()) {
+ return nullptr;
+ }
+
return BulletPhysicsDirectBodyState3D::get_singleton(body);
}
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index e4d3ed118c..68da588c3d 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -361,7 +361,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) {
if (top->native.is_valid()) {
if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) {
if (EngineDebugger::is_active()) {
- GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instantiated in object of type: '" + p_this->get_class() + "'");
+ GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instantiated in object of type: '" + p_this->get_class() + "'");
}
ERR_FAIL_V_MSG(nullptr, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instantiated in object of type '" + p_this->get_class() + "'" + ".");
}
@@ -789,6 +789,14 @@ void GDScript::_set_subclass_path(Ref<GDScript> &p_sc, const String &p_path) {
}
}
+String GDScript::_get_debug_path() const {
+ if (is_built_in() && !get_name().is_empty()) {
+ return get_name() + " (" + get_path().get_slice("::", 0) + ")";
+ } else {
+ return get_path();
+ }
+}
+
Error GDScript::reload(bool p_keep_state) {
bool has_instances;
{
@@ -832,7 +840,7 @@ Error GDScript::reload(bool p_keep_state) {
Error err = parser.parse(source, path, false);
if (err) {
if (EngineDebugger::is_active()) {
- GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), parser.get_errors().front()->get().line, "Parser Error: " + parser.get_errors().front()->get().message);
+ GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), parser.get_errors().front()->get().line, "Parser Error: " + parser.get_errors().front()->get().message);
}
// TODO: Show all error messages.
_err_print_error("GDScript::reload", path.is_empty() ? "built-in" : (const char *)path.utf8().get_data(), parser.get_errors().front()->get().line, ("Parse Error: " + parser.get_errors().front()->get().message).utf8().get_data(), false, ERR_HANDLER_SCRIPT);
@@ -844,7 +852,7 @@ Error GDScript::reload(bool p_keep_state) {
if (err) {
if (EngineDebugger::is_active()) {
- GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), parser.get_errors().front()->get().line, "Parser Error: " + parser.get_errors().front()->get().message);
+ GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), parser.get_errors().front()->get().line, "Parser Error: " + parser.get_errors().front()->get().message);
}
const List<GDScriptParser::ParserError>::Element *e = parser.get_errors().front();
@@ -867,7 +875,7 @@ Error GDScript::reload(bool p_keep_state) {
if (err) {
if (can_run) {
if (EngineDebugger::is_active()) {
- GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error());
+ GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error());
}
_err_print_error("GDScript::reload", path.is_empty() ? "built-in" : (const char *)path.utf8().get_data(), compiler.get_error_line(), ("Compile Error: " + compiler.get_error()).utf8().get_data(), false, ERR_HANDLER_SCRIPT);
ERR_FAIL_V(ERR_COMPILATION_FAILED);
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 791f8a1431..ade4f247c9 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -135,6 +135,7 @@ class GDScript : public Script {
GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error);
void _set_subclass_path(Ref<GDScript> &p_sc, const String &p_path);
+ String _get_debug_path() const;
#ifdef TOOLS_ENABLED
Set<PlaceHolderScriptInstance *> placeholders;
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index b96139ac51..bde6783322 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -740,10 +740,24 @@ void GDScriptParser::parse_class_member(T *(GDScriptParser::*p_parse_function)()
#endif // TOOLS_ENABLED
if (member->identifier != nullptr) {
- // Enums may be unnamed.
- // TODO: Consider names in outer scope too, for constants and classes (and static functions?)
- if (current_class->members_indices.has(member->identifier->name)) {
- push_error(vformat(R"(%s "%s" has the same name as a previously declared %s.)", p_member_kind.capitalize(), member->identifier->name, current_class->get_member(member->identifier->name).get_type_name()), member->identifier);
+ if (!((String)member->identifier->name).is_empty()) { // Enums may be unnamed.
+ List<MethodInfo> gdscript_funcs;
+ GDScriptLanguage::get_singleton()->get_public_functions(&gdscript_funcs);
+ for (MethodInfo &info : gdscript_funcs) {
+ if (info.name == member->identifier->name) {
+ push_error(vformat(R"(%s "%s" has the same name as a built-in function.)", p_member_kind.capitalize(), member->identifier->name), member->identifier);
+ return;
+ }
+ }
+ if (current_class->members_indices.has(member->identifier->name)) {
+ push_error(vformat(R"(%s "%s" has the same name as a previously declared %s.)", p_member_kind.capitalize(), member->identifier->name, current_class->get_member(member->identifier->name).get_type_name()), member->identifier);
+ } else if (Variant::has_utility_function(member->identifier->name)) {
+ push_error(vformat(R"(%s "%s" has the same name as a built-in function.)", p_member_kind.capitalize(), member->identifier->name), member->identifier);
+ } else if (ClassDB::class_exists(member->identifier->name)) {
+ push_error(vformat(R"(%s "%s" has the same name as a global class.)", p_member_kind.capitalize(), member->identifier->name), member->identifier);
+ } else {
+ current_class->add_member(member);
+ }
} else {
current_class->add_member(member);
}
@@ -811,9 +825,27 @@ GDScriptParser::VariableNode *GDScriptParser::parse_variable(bool p_allow_proper
return nullptr;
}
+ GDScriptParser::IdentifierNode *identifier = parse_identifier();
+
+ List<MethodInfo> gdscript_funcs;
+ GDScriptLanguage::get_singleton()->get_public_functions(&gdscript_funcs);
+ for (MethodInfo &info : gdscript_funcs) {
+ if (info.name == identifier->name) {
+ push_error(vformat(R"(Local var "%s" has the same name as a built-in function.)", identifier->name), identifier);
+ return nullptr;
+ }
+ }
+ if (Variant::has_utility_function(identifier->name)) {
+ push_error(vformat(R"(Local var "%s" has the same name as a built-in function.)", identifier->name), identifier);
+ return nullptr;
+ } else if (ClassDB::class_exists(identifier->name)) {
+ push_error(vformat(R"(Local var "%s" has the same name as a global class.)", identifier->name), identifier);
+ return nullptr;
+ }
+
VariableNode *variable = alloc_node<VariableNode>();
- variable->identifier = parse_identifier();
- variable->export_info.name = variable->identifier->name;
+ variable->identifier = identifier;
+ variable->export_info.name = identifier->name;
if (match(GDScriptTokenizer::Token::COLON)) {
if (check(GDScriptTokenizer::Token::NEWLINE)) {
@@ -1066,8 +1098,26 @@ GDScriptParser::ParameterNode *GDScriptParser::parse_parameter() {
return nullptr;
}
+ GDScriptParser::IdentifierNode *identifier = parse_identifier();
+
+ List<MethodInfo> gdscript_funcs;
+ GDScriptLanguage::get_singleton()->get_public_functions(&gdscript_funcs);
+ for (MethodInfo &info : gdscript_funcs) {
+ if (info.name == identifier->name) {
+ push_error(vformat(R"(Parameter "%s" has the same name as a built-in function.)", identifier->name), identifier);
+ return nullptr;
+ }
+ }
+ if (Variant::has_utility_function(identifier->name)) {
+ push_error(vformat(R"(Parameter "%s" has the same name as a built-in function.)", identifier->name), identifier);
+ return nullptr;
+ } else if (ClassDB::class_exists(identifier->name)) {
+ push_error(vformat(R"(Parameter "%s" has the same name as a global class.)", identifier->name), identifier);
+ return nullptr;
+ }
+
ParameterNode *parameter = alloc_node<ParameterNode>();
- parameter->identifier = parse_identifier();
+ parameter->identifier = identifier;
if (match(GDScriptTokenizer::Token::COLON)) {
if (check((GDScriptTokenizer::Token::EQUAL))) {
@@ -1145,13 +1195,31 @@ GDScriptParser::EnumNode *GDScriptParser::parse_enum() {
HashMap<StringName, int> elements;
+ List<MethodInfo> gdscript_funcs;
+ GDScriptLanguage::get_singleton()->get_public_functions(&gdscript_funcs);
+
do {
if (check(GDScriptTokenizer::Token::BRACE_CLOSE)) {
break; // Allow trailing comma.
}
if (consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected identifier for enum key.)")) {
EnumNode::Value item;
- item.identifier = parse_identifier();
+ GDScriptParser::IdentifierNode *identifier = parse_identifier();
+
+ for (MethodInfo &info : gdscript_funcs) {
+ if (info.name == identifier->name) {
+ push_error(vformat(R"(Enum member "%s" has the same name as a built-in function.)", identifier->name), identifier);
+ return nullptr;
+ }
+ }
+ if (Variant::has_utility_function(identifier->name)) {
+ push_error(vformat(R"(Enum member "%s" has the same name as a built-in function.)", identifier->name), identifier);
+ return nullptr;
+ } else if (ClassDB::class_exists(identifier->name)) {
+ push_error(vformat(R"(Enum member "%s" has the same name as a global class.)", identifier->name), identifier);
+ return nullptr;
+ }
+ item.identifier = identifier;
item.parent_enum = enum_node;
item.line = previous.start_line;
item.leftmost_column = previous.leftmost_column;
@@ -2774,6 +2842,23 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_get_node(ExpressionNode *p
get_node->chain.push_back(identifier);
} while (match(GDScriptTokenizer::Token::SLASH));
return get_node;
+ } else if (match(GDScriptTokenizer::Token::SLASH)) {
+ GetNodeNode *get_node = alloc_node<GetNodeNode>();
+ IdentifierNode *identifier_root = alloc_node<IdentifierNode>();
+ get_node->chain.push_back(identifier_root);
+ int chain_position = 0;
+ do {
+ make_completion_context(COMPLETION_GET_NODE, get_node, chain_position++);
+ if (!current.is_node_name()) {
+ push_error(R"(Expect node path after "/".)");
+ return nullptr;
+ }
+ advance();
+ IdentifierNode *identifier = alloc_node<IdentifierNode>();
+ identifier->name = previous.get_identifier();
+ get_node->chain.push_back(identifier);
+ } while (match(GDScriptTokenizer::Token::SLASH));
+ return get_node;
} else {
push_error(R"(Expect node path as string or identifier after "$".)");
return nullptr;
diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp
index cd247d1d26..3725fb58f5 100644
--- a/modules/gdscript/gdscript_tokenizer.cpp
+++ b/modules/gdscript/gdscript_tokenizer.cpp
@@ -795,6 +795,15 @@ GDScriptTokenizer::Token GDScriptTokenizer::string() {
char32_t ch = _peek();
+ if (ch == 0x200E || ch == 0x200F || (ch >= 0x202A && ch <= 0x202E) || (ch >= 0x2066 && ch <= 0x2069)) {
+ Token error = make_error("Invisible text direction control character present in the string, escape it (\"\\u" + String::num_int64(ch, 16) + "\") to avoid confusion.");
+ error.start_column = column;
+ error.leftmost_column = error.start_column;
+ error.end_column = column + 1;
+ error.rightmost_column = error.end_column;
+ push_error(error);
+ }
+
if (ch == '\\') {
// Escape pattern.
_advance();
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp
index a1cc2246d6..6dd8c3e0dd 100644
--- a/modules/gdscript/gdscript_vm.cpp
+++ b/modules/gdscript/gdscript_vm.cpp
@@ -3309,7 +3309,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
int err_line = line;
if (err_text == "") {
- err_text = "Internal Script Error! - opcode #" + itos(last_opcode) + " (report please).";
+ err_text = "Internal script error! Opcode: " + itos(last_opcode) + " (please report).";
}
if (!GDScriptLanguage::get_singleton()->debug_break(err_text, false)) {
diff --git a/modules/gdscript/language_server/gdscript_language_protocol.h b/modules/gdscript/language_server/gdscript_language_protocol.h
index 899446fb42..a4a63a23a8 100644
--- a/modules/gdscript/language_server/gdscript_language_protocol.h
+++ b/modules/gdscript/language_server/gdscript_language_protocol.h
@@ -38,7 +38,7 @@
#include "gdscript_workspace.h"
#include "lsp.hpp"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For jsonrpc.
#ifdef MODULE_JSONRPC_ENABLED
#include "modules/jsonrpc/jsonrpc.h"
#else
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index ced80e26b5..fac1e61b18 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -68,7 +68,7 @@
#include "scene/resources/multimesh.h"
#include "scene/resources/surface_tool.h"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For csg, gridmap.
#ifdef MODULE_CSG_ENABLED
#include "modules/csg/csg_shape.h"
@@ -5856,7 +5856,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
animation->set_name(name);
if (anim->get_loop()) {
- animation->set_loop(true);
+ animation->set_loop_mode(Animation::LOOP_LINEAR);
}
float length = 0.0;
diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h
index f2f0b439a5..27a1f64bca 100644
--- a/modules/gltf/gltf_document.h
+++ b/modules/gltf/gltf_document.h
@@ -46,7 +46,8 @@
#include "scene/resources/material.h"
#include "scene/resources/texture.h"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For csg, gridmap.
+
#include <cstdint>
class GLTFState;
diff --git a/modules/mono/doc_classes/CSharpScript.xml b/modules/mono/doc_classes/CSharpScript.xml
index abd860a55f..2bca8bc24e 100644
--- a/modules/mono/doc_classes/CSharpScript.xml
+++ b/modules/mono/doc_classes/CSharpScript.xml
@@ -12,13 +12,10 @@
</tutorials>
<methods>
<method name="new" qualifiers="vararg">
- <return type="Variant">
- </return>
+ <return type="Variant" />
<description>
Returns a new instance of the script.
</description>
</method>
</methods>
- <constants>
- </constants>
</class>
diff --git a/modules/mono/doc_classes/GodotSharp.xml b/modules/mono/doc_classes/GodotSharp.xml
index 417f8ac704..a148072245 100644
--- a/modules/mono/doc_classes/GodotSharp.xml
+++ b/modules/mono/doc_classes/GodotSharp.xml
@@ -11,66 +11,55 @@
</tutorials>
<methods>
<method name="attach_thread">
- <return type="void">
- </return>
+ <return type="void" />
<description>
Attaches the current thread to the Mono runtime.
</description>
</method>
<method name="detach_thread">
- <return type="void">
- </return>
+ <return type="void" />
<description>
Detaches the current thread from the Mono runtime.
</description>
</method>
<method name="get_domain_id">
- <return type="int">
- </return>
+ <return type="int" />
<description>
Returns the current MonoDomain ID.
[b]Note:[/b] The Mono runtime must be initialized for this method to work (use [method is_runtime_initialized] to check). If the Mono runtime isn't initialized at the time this method is called, the engine will crash.
</description>
</method>
<method name="get_scripts_domain_id">
- <return type="int">
- </return>
+ <return type="int" />
<description>
Returns the scripts MonoDomain's ID. This will be the same MonoDomain ID as [method get_domain_id], unless the scripts domain isn't loaded.
[b]Note:[/b] The Mono runtime must be initialized for this method to work (use [method is_runtime_initialized] to check). If the Mono runtime isn't initialized at the time this method is called, the engine will crash.
</description>
</method>
<method name="is_domain_finalizing_for_unload">
- <return type="bool">
- </return>
- <argument index="0" name="domain_id" type="int">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="domain_id" type="int" />
<description>
Returns [code]true[/code] if the domain is being finalized, [code]false[/code] otherwise.
</description>
</method>
<method name="is_runtime_initialized">
- <return type="bool">
- </return>
+ <return type="bool" />
<description>
Returns [code]true[/code] if the Mono runtime is initialized, [code]false[/code] otherwise.
</description>
</method>
<method name="is_runtime_shutting_down">
- <return type="bool">
- </return>
+ <return type="bool" />
<description>
Returns [code]true[/code] if the Mono runtime is shutting down, [code]false[/code] otherwise.
</description>
</method>
<method name="is_scripts_domain_loaded">
- <return type="bool">
- </return>
+ <return type="bool" />
<description>
Returns [code]true[/code] if the scripts domain is loaded, [code]false[/code] otherwise.
</description>
</method>
</methods>
- <constants>
- </constants>
</class>
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs
index 6f7fac7429..fbc8ff64a6 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs
@@ -693,5 +693,23 @@ namespace Godot
}
return min + ((((value - min) % range) + range) % range);
}
+
+ private static real_t Fract(real_t value)
+ {
+ return value - (real_t)Math.Floor(value);
+ }
+
+ /// <summary>
+ /// Returns the [code]value[/code] wrapped between [code]0[/code] and the [code]length[/code].
+ /// If the limit is reached, the next value the function returned is decreased to the [code]0[/code] side or increased to the [code]length[/code] side (like a triangle wave).
+ /// If [code]length[/code] is less than zero, it becomes positive.
+ /// </summary>
+ /// <param name="value">The value to pingpong.</param>
+ /// <param name="length">The maximum value of the function.</param>
+ /// <returns>The ping-ponged value.</returns>
+ public static real_t PingPong(real_t value, real_t length)
+ {
+ return (length != (real_t)0.0) ? Abs(Fract((value - length) / (length * (real_t)2.0)) * length * (real_t)2.0 - length) : (real_t)0.0;
+ }
}
}
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp
index f3e83b26b9..52447bc59b 100644
--- a/modules/mono/mono_gd/gd_mono.cpp
+++ b/modules/mono/mono_gd/gd_mono.cpp
@@ -504,7 +504,7 @@ void GDMono::_init_godot_api_hashes() {
}
void GDMono::_init_exception_policy() {
- PropertyInfo exc_policy_prop = PropertyInfo(Variant::INT, "mono/unhandled_exception_policy", PROPERTY_HINT_ENUM,
+ PropertyInfo exc_policy_prop = PropertyInfo(Variant::INT, "mono/runtime/unhandled_exception_policy", PROPERTY_HINT_ENUM,
vformat("Terminate Application:%s,Log Error:%s", (int)POLICY_TERMINATE_APP, (int)POLICY_LOG_ERROR));
unhandled_exception_policy = (UnhandledExceptionPolicy)(int)GLOBAL_DEF(exc_policy_prop.name, (int)POLICY_TERMINATE_APP);
ProjectSettings::get_singleton()->set_custom_property_info(exc_policy_prop.name, exc_policy_prop);
diff --git a/modules/navigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp
index 8fd3a13e1f..05e040b518 100644
--- a/modules/navigation/navigation_mesh_generator.cpp
+++ b/modules/navigation/navigation_mesh_generator.cpp
@@ -52,7 +52,8 @@
#include "editor/editor_settings.h"
#endif
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For csg, gridmap.
+
#ifdef MODULE_CSG_ENABLED
#include "modules/csg/csg_shape.h"
#endif
diff --git a/modules/opensimplex/noise_texture.h b/modules/opensimplex/noise_texture.h
index 6237b6460d..a0b2a86c41 100644
--- a/modules/opensimplex/noise_texture.h
+++ b/modules/opensimplex/noise_texture.h
@@ -35,9 +35,6 @@
#include "core/io/image.h"
#include "core/object/ref_counted.h"
-#include "editor/editor_node.h"
-#include "editor/editor_plugin.h"
-#include "editor/property_editor.h"
class NoiseTexture : public Texture2D {
GDCLASS(NoiseTexture, Texture2D);
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index 1a0b0e357d..1adaef4d84 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -38,6 +38,8 @@
#include "thirdparty/icu4c/icudata.gen.h"
#endif
+#include "modules/modules_enabled.gen.h" // For freetype, msdfgen.
+
#ifdef MODULE_MSDFGEN_ENABLED
#include "core/ShapeDistanceFinder.h"
#include "core/contour-combiners.h"
diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h
index eb8316b200..5eaff67a6e 100644
--- a/modules/text_server_adv/text_server_adv.h
+++ b/modules/text_server_adv/text_server_adv.h
@@ -55,7 +55,7 @@
#include <unicode/ustring.h>
#include <unicode/utypes.h>
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For freetype, msdfgen.
#ifdef MODULE_FREETYPE_ENABLED
#include <ft2build.h>
diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp
index 43a636e484..80ae10c005 100644
--- a/modules/text_server_fb/text_server_fb.cpp
+++ b/modules/text_server_fb/text_server_fb.cpp
@@ -33,6 +33,8 @@
#include "core/error/error_macros.h"
#include "core/string/print_string.h"
+#include "modules/modules_enabled.gen.h" // For freetype, msdfgen.
+
#ifdef MODULE_MSDFGEN_ENABLED
#include "core/ShapeDistanceFinder.h"
#include "core/contour-combiners.h"
@@ -3265,7 +3267,9 @@ TextServerFallback::TextServerFallback() {
};
TextServerFallback::~TextServerFallback() {
+#ifdef MODULE_FREETYPE_ENABLED
if (library != nullptr) {
FT_Done_FreeType(library);
}
+#endif
};
diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h
index 2f495115e0..67b08d1eac 100644
--- a/modules/text_server_fb/text_server_fb.h
+++ b/modules/text_server_fb/text_server_fb.h
@@ -42,7 +42,7 @@
#include "core/templates/thread_work_pool.h"
#include "scene/resources/texture.h"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For freetype, msdfgen.
#ifdef MODULE_FREETYPE_ENABLED
#include <ft2build.h>
diff --git a/modules/visual_script/SCsub b/modules/visual_script/SCsub
index 16faea08d7..b91cceae09 100644
--- a/modules/visual_script/SCsub
+++ b/modules/visual_script/SCsub
@@ -6,3 +6,6 @@ Import("env_modules")
env_vs = env_modules.Clone()
env_vs.add_source_files(env.modules_sources, "*.cpp")
+
+if env["tools"]:
+ env_vs.add_source_files(env.modules_sources, "editor/*.cpp")
diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
index 942d92311b..f4abb3c122 100644
--- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
+++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
@@ -140,73 +140,76 @@
</constant>
<constant name="MATH_WRAPF" value="42" enum="BuiltinFunc">
</constant>
- <constant name="LOGIC_MAX" value="43" enum="BuiltinFunc">
+ <constant name="MATH_PINGPONG" value="43" enum="BuiltinFunc">
+ Return the [code]value[/code] wrapped between [code]0[/code] and the [code]length[/code]. If the limit is reached, the next value the function returned is decreased to the [code]0[/code] side or increased to the [code]length[/code] side (like a triangle wave). If [code]length[/code] is less than zero, it becomes positive.
+ </constant>
+ <constant name="LOGIC_MAX" value="44" enum="BuiltinFunc">
Return the greater of the two numbers, also known as their maximum.
</constant>
- <constant name="LOGIC_MIN" value="44" enum="BuiltinFunc">
+ <constant name="LOGIC_MIN" value="45" enum="BuiltinFunc">
Return the lesser of the two numbers, also known as their minimum.
</constant>
- <constant name="LOGIC_CLAMP" value="45" enum="BuiltinFunc">
+ <constant name="LOGIC_CLAMP" value="46" enum="BuiltinFunc">
Return the input clamped inside the given range, ensuring the result is never outside it. Equivalent to [code]min(max(input, range_low), range_high)[/code].
</constant>
- <constant name="LOGIC_NEAREST_PO2" value="46" enum="BuiltinFunc">
+ <constant name="LOGIC_NEAREST_PO2" value="47" enum="BuiltinFunc">
Return the nearest power of 2 to the input.
</constant>
- <constant name="OBJ_WEAKREF" value="47" enum="BuiltinFunc">
+ <constant name="OBJ_WEAKREF" value="48" enum="BuiltinFunc">
Create a [WeakRef] from the input.
</constant>
- <constant name="TYPE_CONVERT" value="48" enum="BuiltinFunc">
+ <constant name="TYPE_CONVERT" value="49" enum="BuiltinFunc">
Convert between types.
</constant>
- <constant name="TYPE_OF" value="49" enum="BuiltinFunc">
+ <constant name="TYPE_OF" value="50" enum="BuiltinFunc">
Return the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned.
</constant>
- <constant name="TYPE_EXISTS" value="50" enum="BuiltinFunc">
+ <constant name="TYPE_EXISTS" value="51" enum="BuiltinFunc">
Checks if a type is registered in the [ClassDB].
</constant>
- <constant name="TEXT_CHAR" value="51" enum="BuiltinFunc">
+ <constant name="TEXT_CHAR" value="52" enum="BuiltinFunc">
Return a character with the given ascii value.
</constant>
- <constant name="TEXT_STR" value="52" enum="BuiltinFunc">
+ <constant name="TEXT_STR" value="53" enum="BuiltinFunc">
Convert the input to a string.
</constant>
- <constant name="TEXT_PRINT" value="53" enum="BuiltinFunc">
+ <constant name="TEXT_PRINT" value="54" enum="BuiltinFunc">
Print the given string to the output window.
</constant>
- <constant name="TEXT_PRINTERR" value="54" enum="BuiltinFunc">
+ <constant name="TEXT_PRINTERR" value="55" enum="BuiltinFunc">
Print the given string to the standard error output.
</constant>
- <constant name="TEXT_PRINTRAW" value="55" enum="BuiltinFunc">
+ <constant name="TEXT_PRINTRAW" value="56" enum="BuiltinFunc">
Print the given string to the standard output, without adding a newline.
</constant>
- <constant name="TEXT_PRINT_VERBOSE" value="56" enum="BuiltinFunc">
+ <constant name="TEXT_PRINT_VERBOSE" value="57" enum="BuiltinFunc">
</constant>
- <constant name="VAR_TO_STR" value="57" enum="BuiltinFunc">
+ <constant name="VAR_TO_STR" value="58" enum="BuiltinFunc">
Serialize a [Variant] to a string.
</constant>
- <constant name="STR_TO_VAR" value="58" enum="BuiltinFunc">
+ <constant name="STR_TO_VAR" value="59" enum="BuiltinFunc">
Deserialize a [Variant] from a string serialized using [constant VAR_TO_STR].
</constant>
- <constant name="VAR_TO_BYTES" value="59" enum="BuiltinFunc">
+ <constant name="VAR_TO_BYTES" value="60" enum="BuiltinFunc">
Serialize a [Variant] to a [PackedByteArray].
</constant>
- <constant name="BYTES_TO_VAR" value="60" enum="BuiltinFunc">
+ <constant name="BYTES_TO_VAR" value="61" enum="BuiltinFunc">
Deserialize a [Variant] from a [PackedByteArray] serialized using [constant VAR_TO_BYTES].
</constant>
- <constant name="MATH_SMOOTHSTEP" value="61" enum="BuiltinFunc">
+ <constant name="MATH_SMOOTHSTEP" value="62" enum="BuiltinFunc">
Return a number smoothly interpolated between the first two inputs, based on the third input. Similar to [constant MATH_LERP], but interpolates faster at the beginning and slower at the end. Using Hermite interpolation formula:
[codeblock]
var t = clamp((weight - from) / (to - from), 0.0, 1.0)
return t * t * (3.0 - 2.0 * t)
[/codeblock]
</constant>
- <constant name="MATH_POSMOD" value="62" enum="BuiltinFunc">
+ <constant name="MATH_POSMOD" value="63" enum="BuiltinFunc">
</constant>
- <constant name="MATH_LERP_ANGLE" value="63" enum="BuiltinFunc">
+ <constant name="MATH_LERP_ANGLE" value="64" enum="BuiltinFunc">
</constant>
- <constant name="TEXT_ORD" value="64" enum="BuiltinFunc">
+ <constant name="TEXT_ORD" value="65" enum="BuiltinFunc">
</constant>
- <constant name="FUNC_MAX" value="65" enum="BuiltinFunc">
+ <constant name="FUNC_MAX" value="66" enum="BuiltinFunc">
Represents the size of the [enum BuiltinFunc] enum.
</constant>
</constants>
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/editor/visual_script_editor.cpp
index 7b4fbc67fc..6fa43636de 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/editor/visual_script_editor.cpp
@@ -30,6 +30,10 @@
#include "visual_script_editor.h"
+#include "../visual_script_expression.h"
+#include "../visual_script_flow_control.h"
+#include "../visual_script_func_nodes.h"
+#include "../visual_script_nodes.h"
#include "core/input/input.h"
#include "core/object/class_db.h"
#include "core/object/script_language.h"
@@ -39,10 +43,6 @@
#include "editor/editor_resource_preview.h"
#include "editor/editor_scale.h"
#include "scene/main/window.h"
-#include "visual_script_expression.h"
-#include "visual_script_flow_control.h"
-#include "visual_script_func_nodes.h"
-#include "visual_script_nodes.h"
#ifdef TOOLS_ENABLED
class VisualScriptEditorSignalEdit : public Object {
@@ -2587,18 +2587,21 @@ void VisualScriptEditor::reload_text() {
String VisualScriptEditor::get_name() {
String name;
- if (!script->is_built_in()) {
- name = script->get_path().get_file();
- if (is_unsaved()) {
- if (script->get_path().is_empty()) {
- name = TTR("[unsaved]");
- }
- name += "(*)";
+ name = script->get_path().get_file();
+ if (name.is_empty()) {
+ // This appears for newly created built-in scripts before saving the scene.
+ name = TTR("[unsaved]");
+ } else if (script->is_built_in()) {
+ const String &script_name = script->get_name();
+ if (script_name != "") {
+ // If the built-in script has a custom resource name defined,
+ // display the built-in script name as follows: `ResourceName (scene_file.tscn)`
+ name = vformat("%s (%s)", script_name, name.get_slice("::", 0));
}
- } else if (script->get_name() != "") {
- name = script->get_name();
- } else {
- name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
+ }
+
+ if (is_unsaved()) {
+ name += "(*)";
}
return name;
diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/editor/visual_script_editor.h
index 9467c2dea4..fd1db2bc43 100644
--- a/modules/visual_script/visual_script_editor.h
+++ b/modules/visual_script/editor/visual_script_editor.h
@@ -31,11 +31,11 @@
#ifndef VISUALSCRIPT_EDITOR_H
#define VISUALSCRIPT_EDITOR_H
+#include "../visual_script.h"
#include "editor/create_dialog.h"
#include "editor/plugins/script_editor_plugin.h"
#include "editor/property_editor.h"
#include "scene/gui/graph_edit.h"
-#include "visual_script.h"
#include "visual_script_property_selector.h"
class VisualScriptEditorSignalEdit;
diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/editor/visual_script_property_selector.cpp
index d8b88d6cd3..ace26bcdf6 100644
--- a/modules/visual_script/visual_script_property_selector.cpp
+++ b/modules/visual_script/editor/visual_script_property_selector.cpp
@@ -30,15 +30,15 @@
#include "visual_script_property_selector.h"
+#include "../visual_script.h"
+#include "../visual_script_builtin_funcs.h"
+#include "../visual_script_flow_control.h"
+#include "../visual_script_func_nodes.h"
+#include "../visual_script_nodes.h"
#include "core/os/keyboard.h"
#include "editor/doc_tools.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
-#include "modules/visual_script/visual_script.h"
-#include "modules/visual_script/visual_script_builtin_funcs.h"
-#include "modules/visual_script/visual_script_flow_control.h"
-#include "modules/visual_script/visual_script_func_nodes.h"
-#include "modules/visual_script/visual_script_nodes.h"
#include "scene/main/node.h"
#include "scene/main/window.h"
diff --git a/modules/visual_script/visual_script_property_selector.h b/modules/visual_script/editor/visual_script_property_selector.h
index 7a87f3d3ee..7a87f3d3ee 100644
--- a/modules/visual_script/visual_script_property_selector.h
+++ b/modules/visual_script/editor/visual_script_property_selector.h
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp
index 890861cf82..6f56fbbc70 100644
--- a/modules/visual_script/register_types.cpp
+++ b/modules/visual_script/register_types.cpp
@@ -34,7 +34,6 @@
#include "core/io/resource_loader.h"
#include "visual_script.h"
#include "visual_script_builtin_funcs.h"
-#include "visual_script_editor.h"
#include "visual_script_expression.h"
#include "visual_script_flow_control.h"
#include "visual_script_func_nodes.h"
@@ -42,7 +41,9 @@
#include "visual_script_yield_nodes.h"
VisualScriptLanguage *visual_script_language = nullptr;
+
#ifdef TOOLS_ENABLED
+#include "editor/visual_script_editor.h"
static VisualScriptCustomNodes *vs_custom_nodes_singleton = nullptr;
#endif
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index 7e01031128..54a5e1449f 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -81,6 +81,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"db2linear",
"wrapi",
"wrapf",
+ "pingpong",
"max",
"min",
"clamp",
@@ -190,6 +191,7 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case MATH_FMOD:
case MATH_FPOSMOD:
case MATH_POSMOD:
+ case MATH_PINGPONG:
case MATH_POW:
case MATH_EASE:
case MATH_SNAPPED:
@@ -381,6 +383,13 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case MATH_DB2LINEAR: {
return PropertyInfo(Variant::FLOAT, "db");
} break;
+ case MATH_PINGPONG: {
+ if (p_idx == 0) {
+ return PropertyInfo(Variant::FLOAT, "value");
+ } else {
+ return PropertyInfo(Variant::FLOAT, "length");
+ }
+ } break;
case MATH_WRAP: {
if (p_idx == 0) {
return PropertyInfo(Variant::INT, "value");
@@ -537,6 +546,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_RAD2DEG:
case MATH_LINEAR2DB:
case MATH_WRAPF:
+ case MATH_PINGPONG:
case MATH_DB2LINEAR: {
t = Variant::FLOAT;
} break;
@@ -859,6 +869,11 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
VALIDATE_ARG_NUM(0);
*r_return = Math::db2linear((double)*p_inputs[0]);
} break;
+ case VisualScriptBuiltinFunc::MATH_PINGPONG: {
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ *r_return = Math::pingpong((double)*p_inputs[0], (double)*p_inputs[1]);
+ } break;
case VisualScriptBuiltinFunc::MATH_WRAP: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -1206,6 +1221,7 @@ void VisualScriptBuiltinFunc::_bind_methods() {
BIND_ENUM_CONSTANT(MATH_DB2LINEAR);
BIND_ENUM_CONSTANT(MATH_WRAP);
BIND_ENUM_CONSTANT(MATH_WRAPF);
+ BIND_ENUM_CONSTANT(MATH_PINGPONG);
BIND_ENUM_CONSTANT(LOGIC_MAX);
BIND_ENUM_CONSTANT(LOGIC_MIN);
BIND_ENUM_CONSTANT(LOGIC_CLAMP);
@@ -1296,6 +1312,7 @@ void register_visual_script_builtin_func_node() {
VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapi", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAP>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAPF>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/pingpong", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_PINGPONG>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/max", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MAX>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/min", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MIN>);
diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h
index f9eb7e983f..30f1f0d417 100644
--- a/modules/visual_script/visual_script_builtin_funcs.h
+++ b/modules/visual_script/visual_script_builtin_funcs.h
@@ -81,6 +81,7 @@ public:
MATH_DB2LINEAR,
MATH_WRAP,
MATH_WRAPF,
+ MATH_PINGPONG,
LOGIC_MAX,
LOGIC_MIN,
LOGIC_CLAMP,
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 4431bd5f1b..5da9a96a90 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -36,7 +36,7 @@
#include "main/main.h"
#include "platform/javascript/display_server_javascript.h"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For websocket.
#ifdef MODULE_WEBSOCKET_ENABLED
#include "modules/websocket/remote_debugger_peer_websocket.h"
#endif
diff --git a/platform/linuxbsd/crash_handler_linuxbsd.cpp b/platform/linuxbsd/crash_handler_linuxbsd.cpp
index 0e98af71fa..9b24b24cb4 100644
--- a/platform/linuxbsd/crash_handler_linuxbsd.cpp
+++ b/platform/linuxbsd/crash_handler_linuxbsd.cpp
@@ -115,7 +115,7 @@ static void handle_crash(int sig) {
int ret;
Error err = OS::get_singleton()->execute(String("addr2line"), args, &output, &ret);
if (err == OK) {
- output.erase(output.length() - 1, 1);
+ output = output.substr(0, output.length() - 1);
}
fprintf(stderr, "[%ld] %s (%s)\n", (long int)i, fname, output.utf8().get_data());
diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm
index 31228b10b4..2252d5eb4f 100644
--- a/platform/osx/crash_handler_osx.mm
+++ b/platform/osx/crash_handler_osx.mm
@@ -146,7 +146,7 @@ static void handle_crash(int sig) {
String out = "";
Error err = OS::get_singleton()->execute(String("atos"), args, &out, &ret);
if (err == OK && out.substr(0, 2) != "0x") {
- out.erase(out.length() - 1, 1);
+ out = out.substr(0, out.length() - 1);
output = out;
}
}
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm
index 03301af0af..647f501e6b 100644
--- a/platform/osx/display_server_osx.mm
+++ b/platform/osx/display_server_osx.mm
@@ -1920,6 +1920,7 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) {
return;
}
+ WindowData &wd = windows[MAIN_WINDOW_ID];
if (p_mode == MOUSE_MODE_CAPTURED) {
// Apple Docs state that the display parameter is not used.
// "This parameter is not used. By default, you may pass kCGDirectMainDisplay."
@@ -1928,7 +1929,7 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) {
CGDisplayHideCursor(kCGDirectMainDisplay);
}
CGAssociateMouseAndMouseCursorPosition(false);
- WindowData &wd = windows[MAIN_WINDOW_ID];
+ [wd.window_object setMovable:NO];
const NSRect contentRect = [wd.window_view frame];
NSRect pointInWindowRect = NSMakeRect(contentRect.size.width / 2, contentRect.size.height / 2, 0, 0);
NSPoint pointOnScreen = [[wd.window_view window] convertRectToScreen:pointInWindowRect].origin;
@@ -1938,17 +1939,21 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
CGDisplayHideCursor(kCGDirectMainDisplay);
}
+ [wd.window_object setMovable:YES];
CGAssociateMouseAndMouseCursorPosition(true);
} else if (p_mode == MOUSE_MODE_CONFINED) {
CGDisplayShowCursor(kCGDirectMainDisplay);
+ [wd.window_object setMovable:NO];
CGAssociateMouseAndMouseCursorPosition(false);
} else if (p_mode == MOUSE_MODE_CONFINED_HIDDEN) {
if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
CGDisplayHideCursor(kCGDirectMainDisplay);
}
+ [wd.window_object setMovable:NO];
CGAssociateMouseAndMouseCursorPosition(false);
} else { // MOUSE_MODE_VISIBLE
CGDisplayShowCursor(kCGDirectMainDisplay);
+ [wd.window_object setMovable:YES];
CGAssociateMouseAndMouseCursorPosition(true);
}
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 22fbbeb74f..20deb35089 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -226,9 +226,10 @@ def configure_msvc(env, manual_msvc_config):
env.AppendUnique(CCFLAGS=["/MD"])
env.AppendUnique(CCFLAGS=["/Gd", "/GR", "/nologo"])
- # Force to use Unicode encoding
- env.AppendUnique(CCFLAGS=["/utf-8"])
+ env.AppendUnique(CCFLAGS=["/utf-8"]) # Force to use Unicode encoding.
+ env.AppendUnique(CCFLAGS=["/bigobj"]) # Allow big objects, no drawbacks.
env.AppendUnique(CXXFLAGS=["/TP"]) # assume all sources are C++
+
if manual_msvc_config: # should be automatic if SCons found it
if os.getenv("WindowsSdkDir") is not None:
env.Prepend(CPPPATH=[os.getenv("WindowsSdkDir") + "/Include"])
@@ -421,6 +422,7 @@ def configure_mingw(env):
## Compile flags
env.Append(CCFLAGS=["-mwindows"])
+ env.Append(CCFLAGS=["-Wa,-mbig-obj"]) # Allow big objects, no drawbacks.
env.Append(CPPDEFINES=["WINDOWS_ENABLED", "WASAPI_ENABLED", "WINMIDI_ENABLED"])
env.Append(CPPDEFINES=[("WINVER", env["target_win_version"]), ("_WIN32_WINNT", env["target_win_version"])])
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index e2c9951692..aa97386399 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -42,6 +42,11 @@
#include "drivers/gles3/rasterizer_gles3.h"
#endif
+#if defined(__GNUC__)
+// Workaround GCC warning from -Wcast-function-type.
+#define GetProcAddress (void *)GetProcAddress
+#endif
+
static String format_error_message(DWORD id) {
LPWSTR messageBuffer = nullptr;
size_t size = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
diff --git a/platform/windows/gl_manager_windows.cpp b/platform/windows/gl_manager_windows.cpp
index 98205d6282..1ce8b0b040 100644
--- a/platform/windows/gl_manager_windows.cpp
+++ b/platform/windows/gl_manager_windows.cpp
@@ -197,9 +197,6 @@ Error GLManager_Windows::window_create(DisplayServer::WindowID p_window_id, HWND
return FAILED;
}
- // the display could be invalid .. check NYI
- GLDisplay &gl_display = _displays[win.gldisplay_id];
-
// make current
window_make_current(_windows.size() - 1);
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index 75a1723e04..8db1491953 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -33,13 +33,13 @@
#include "scene/scene_string_names.h"
#include "servers/audio_server.h"
-void Area2D::set_space_override_mode(SpaceOverride p_mode) {
- space_override = p_mode;
- PhysicsServer2D::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer2D::AreaSpaceOverrideMode(p_mode));
+void Area2D::set_gravity_space_override_mode(SpaceOverride p_mode) {
+ gravity_space_override = p_mode;
+ PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_OVERRIDE_MODE, p_mode);
}
-Area2D::SpaceOverride Area2D::get_space_override_mode() const {
- return space_override;
+Area2D::SpaceOverride Area2D::get_gravity_space_override_mode() const {
+ return gravity_space_override;
}
void Area2D::set_gravity_is_point(bool p_enabled) {
@@ -51,21 +51,30 @@ bool Area2D::is_gravity_a_point() const {
return gravity_is_point;
}
-void Area2D::set_gravity_distance_scale(real_t p_scale) {
+void Area2D::set_gravity_point_distance_scale(real_t p_scale) {
gravity_distance_scale = p_scale;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
}
-real_t Area2D::get_gravity_distance_scale() const {
+real_t Area2D::get_gravity_point_distance_scale() const {
return gravity_distance_scale;
}
-void Area2D::set_gravity_vector(const Vector2 &p_vec) {
- gravity_vec = p_vec;
- PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, p_vec);
+void Area2D::set_gravity_point_center(const Vector2 &p_center) {
+ gravity_vec = p_center;
+ PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, p_center);
}
-Vector2 Area2D::get_gravity_vector() const {
+const Vector2 &Area2D::get_gravity_point_center() const {
+ return gravity_vec;
+}
+
+void Area2D::set_gravity_direction(const Vector2 &p_direction) {
+ gravity_vec = p_direction;
+ PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, p_direction);
+}
+
+const Vector2 &Area2D::get_gravity_direction() const {
return gravity_vec;
}
@@ -78,6 +87,24 @@ real_t Area2D::get_gravity() const {
return gravity;
}
+void Area2D::set_linear_damp_space_override_mode(SpaceOverride p_mode) {
+ linear_damp_space_override = p_mode;
+ PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE, p_mode);
+}
+
+Area2D::SpaceOverride Area2D::get_linear_damp_space_override_mode() const {
+ return linear_damp_space_override;
+}
+
+void Area2D::set_angular_damp_space_override_mode(SpaceOverride p_mode) {
+ angular_damp_space_override = p_mode;
+ PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE, p_mode);
+}
+
+Area2D::SpaceOverride Area2D::get_angular_damp_space_override_mode() const {
+ return angular_damp_space_override;
+}
+
void Area2D::set_linear_damp(real_t p_linear_damp) {
linear_damp = p_linear_damp;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_LINEAR_DAMP, p_linear_damp);
@@ -483,25 +510,56 @@ void Area2D::_validate_property(PropertyInfo &property) const {
}
property.hint_string = options;
+ } else if (property.name.begins_with("gravity") && property.name != "gravity_space_override") {
+ if (gravity_space_override == SPACE_OVERRIDE_DISABLED) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ } else {
+ if (gravity_is_point) {
+ if (property.name == "gravity_direction") {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ } else {
+ if (property.name.begins_with("gravity_point_")) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ }
+ }
+ } else if (property.name.begins_with("linear_damp") && property.name != "linear_damp_space_override") {
+ if (linear_damp_space_override == SPACE_OVERRIDE_DISABLED) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ } else if (property.name.begins_with("angular_damp") && property.name != "angular_damp_space_override") {
+ if (angular_damp_space_override == SPACE_OVERRIDE_DISABLED) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
}
}
void Area2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_space_override_mode", "space_override_mode"), &Area2D::set_space_override_mode);
- ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area2D::get_space_override_mode);
+ ClassDB::bind_method(D_METHOD("set_gravity_space_override_mode", "space_override_mode"), &Area2D::set_gravity_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_gravity_space_override_mode"), &Area2D::get_gravity_space_override_mode);
ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area2D::set_gravity_is_point);
ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area2D::is_gravity_a_point);
- ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area2D::set_gravity_distance_scale);
- ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area2D::get_gravity_distance_scale);
+ ClassDB::bind_method(D_METHOD("set_gravity_point_distance_scale", "distance_scale"), &Area2D::set_gravity_point_distance_scale);
+ ClassDB::bind_method(D_METHOD("get_gravity_point_distance_scale"), &Area2D::get_gravity_point_distance_scale);
+
+ ClassDB::bind_method(D_METHOD("set_gravity_point_center", "center"), &Area2D::set_gravity_point_center);
+ ClassDB::bind_method(D_METHOD("get_gravity_point_center"), &Area2D::get_gravity_point_center);
- ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area2D::set_gravity_vector);
- ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area2D::get_gravity_vector);
+ ClassDB::bind_method(D_METHOD("set_gravity_direction", "direction"), &Area2D::set_gravity_direction);
+ ClassDB::bind_method(D_METHOD("get_gravity_direction"), &Area2D::get_gravity_direction);
ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area2D::set_gravity);
ClassDB::bind_method(D_METHOD("get_gravity"), &Area2D::get_gravity);
+ ClassDB::bind_method(D_METHOD("set_linear_damp_space_override_mode", "space_override_mode"), &Area2D::set_linear_damp_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_linear_damp_space_override_mode"), &Area2D::get_linear_damp_space_override_mode);
+
+ ClassDB::bind_method(D_METHOD("set_angular_damp_space_override_mode", "space_override_mode"), &Area2D::set_angular_damp_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_angular_damp_space_override_mode"), &Area2D::get_angular_damp_space_override_mode);
+
ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area2D::set_linear_damp);
ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area2D::get_linear_damp);
@@ -543,13 +601,20 @@ void Area2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitorable"), "set_monitorable", "is_monitorable");
ADD_PROPERTY(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,128,1"), "set_priority", "get_priority");
- ADD_GROUP("Physics Overrides", "");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_distance_scale", "get_gravity_distance_scale");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity_vec"), "set_gravity_vector", "get_gravity_vector");
+ ADD_GROUP("Gravity", "gravity_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "gravity_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_space_override_mode", "get_gravity_space_override_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_is_point", "is_gravity_a_point");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_point_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_point_distance_scale", "get_gravity_point_distance_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity_point_center"), "set_gravity_point_center", "get_gravity_point_center");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity_direction"), "set_gravity_direction", "get_gravity_direction");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity", PROPERTY_HINT_RANGE, "-4096,4096,0.001,or_lesser,or_greater"), "set_gravity", "get_gravity");
+
+ ADD_GROUP("Linear Damp", "linear_damp_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "linear_damp_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_linear_damp_space_override_mode", "get_linear_damp_space_override_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp");
+
+ ADD_GROUP("Angular Damp", "angular_damp_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "angular_damp_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_angular_damp_space_override_mode", "get_angular_damp_space_override_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp");
ADD_GROUP("Audio Bus", "audio_bus_");
@@ -566,7 +631,7 @@ void Area2D::_bind_methods() {
Area2D::Area2D() :
CollisionObject2D(PhysicsServer2D::get_singleton()->area_create(), true) {
set_gravity(980);
- set_gravity_vector(Vector2(0, 1));
+ set_gravity_direction(Vector2(0, 1));
set_monitoring(true);
set_monitorable(true);
}
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index 2c29e4660d..98ba270a61 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -47,14 +47,19 @@ public:
};
private:
- SpaceOverride space_override = SPACE_OVERRIDE_DISABLED;
+ SpaceOverride gravity_space_override = SPACE_OVERRIDE_DISABLED;
Vector2 gravity_vec;
real_t gravity;
bool gravity_is_point = false;
real_t gravity_distance_scale = 0.0;
+
+ SpaceOverride linear_damp_space_override = SPACE_OVERRIDE_DISABLED;
+ SpaceOverride angular_damp_space_override = SPACE_OVERRIDE_DISABLED;
real_t linear_damp = 0.1;
real_t angular_damp = 1.0;
+
int priority = 0;
+
bool monitoring = false;
bool monitorable = false;
bool locked = false;
@@ -133,21 +138,30 @@ protected:
void _validate_property(PropertyInfo &property) const override;
public:
- void set_space_override_mode(SpaceOverride p_mode);
- SpaceOverride get_space_override_mode() const;
+ void set_gravity_space_override_mode(SpaceOverride p_mode);
+ SpaceOverride get_gravity_space_override_mode() const;
void set_gravity_is_point(bool p_enabled);
bool is_gravity_a_point() const;
- void set_gravity_distance_scale(real_t p_scale);
- real_t get_gravity_distance_scale() const;
+ void set_gravity_point_distance_scale(real_t p_scale);
+ real_t get_gravity_point_distance_scale() const;
- void set_gravity_vector(const Vector2 &p_vec);
- Vector2 get_gravity_vector() const;
+ void set_gravity_point_center(const Vector2 &p_center);
+ const Vector2 &get_gravity_point_center() const;
+
+ void set_gravity_direction(const Vector2 &p_direction);
+ const Vector2 &get_gravity_direction() const;
void set_gravity(real_t p_gravity);
real_t get_gravity() const;
+ void set_linear_damp_space_override_mode(SpaceOverride p_mode);
+ SpaceOverride get_linear_damp_space_override_mode() const;
+
+ void set_angular_damp_space_override_mode(SpaceOverride p_mode);
+ SpaceOverride get_angular_damp_space_override_mode() const;
+
void set_linear_damp(real_t p_linear_damp);
real_t get_linear_damp() const;
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index a43d498a62..5ec2a81108 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -133,9 +133,12 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_linear
ERR_FAIL_COND_V(!is_inside_tree(), false);
PhysicsServer2D::MotionResult *r = nullptr;
+ PhysicsServer2D::MotionResult temp_result;
if (r_collision.is_valid()) {
// Needs const_cast because method bindings don't support non-const Ref.
r = const_cast<PhysicsServer2D::MotionResult *>(&r_collision->result);
+ } else {
+ r = &temp_result;
}
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky.
@@ -143,7 +146,14 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_linear
PhysicsServer2D::MotionParameters parameters(p_from, p_linear_velocity * delta, p_margin);
- return PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), parameters, r);
+ bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), parameters, r);
+
+ if (colliding) {
+ // Don't report collision when the whole motion is done.
+ return (r->collision_safe_fraction < 1.0);
+ } else {
+ return false;
+ }
}
TypedArray<PhysicsBody2D> PhysicsBody2D::get_collision_exceptions() {
@@ -1101,6 +1111,10 @@ bool CharacterBody2D::move_and_slide() {
if (bs) {
Vector2 local_position = gt.elements[2] - bs->get_transform().elements[2];
current_platform_velocity = bs->get_velocity_at_local_position(local_position);
+ } else {
+ // Body is removed or destroyed, invalidate floor.
+ current_platform_velocity = Vector2();
+ platform_rid = RID();
}
} else {
current_platform_velocity = Vector2();
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index 7af91f3a8d..f9830a8743 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -200,6 +200,7 @@ void RayCast2D::_update_raycast_state() {
ray_params.collision_mask = collision_mask;
ray_params.collide_with_bodies = collide_with_bodies;
ray_params.collide_with_areas = collide_with_areas;
+ ray_params.hit_from_inside = hit_from_inside;
if (dss->intersect_ray(ray_params, rr)) {
collided = true;
@@ -290,22 +291,30 @@ void RayCast2D::clear_exceptions() {
exclude.clear();
}
-void RayCast2D::set_collide_with_areas(bool p_clip) {
- collide_with_areas = p_clip;
+void RayCast2D::set_collide_with_areas(bool p_enabled) {
+ collide_with_areas = p_enabled;
}
bool RayCast2D::is_collide_with_areas_enabled() const {
return collide_with_areas;
}
-void RayCast2D::set_collide_with_bodies(bool p_clip) {
- collide_with_bodies = p_clip;
+void RayCast2D::set_collide_with_bodies(bool p_enabled) {
+ collide_with_bodies = p_enabled;
}
bool RayCast2D::is_collide_with_bodies_enabled() const {
return collide_with_bodies;
}
+void RayCast2D::set_hit_from_inside(bool p_enabled) {
+ hit_from_inside = p_enabled;
+}
+
+bool RayCast2D::is_hit_from_inside_enabled() const {
+ return hit_from_inside;
+}
+
void RayCast2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast2D::set_enabled);
ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast2D::is_enabled);
@@ -344,10 +353,14 @@ void RayCast2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast2D::set_collide_with_bodies);
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast2D::is_collide_with_bodies_enabled);
+ ClassDB::bind_method(D_METHOD("set_hit_from_inside", "enable"), &RayCast2D::set_hit_from_inside);
+ ClassDB::bind_method(D_METHOD("is_hit_from_inside_enabled"), &RayCast2D::is_hit_from_inside_enabled);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "target_position"), "set_target_position", "get_target_position");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_from_inside"), "set_hit_from_inside", "is_hit_from_inside_enabled");
ADD_GROUP("Collide With", "collide_with");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_areas", "is_collide_with_areas_enabled");
diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h
index 65b6e7899b..3ee09fad32 100644
--- a/scene/2d/ray_cast_2d.h
+++ b/scene/2d/ray_cast_2d.h
@@ -51,6 +51,8 @@ class RayCast2D : public Node2D {
bool collide_with_areas = false;
bool collide_with_bodies = true;
+ bool hit_from_inside = false;
+
void _draw_debug_shape();
protected:
@@ -65,6 +67,9 @@ public:
void set_collide_with_bodies(bool p_clip);
bool is_collide_with_bodies_enabled() const;
+ void set_hit_from_inside(bool p_enable);
+ bool is_hit_from_inside_enabled() const;
+
void set_enabled(bool p_enabled);
bool is_enabled() const;
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 8af7637ffd..96c4164721 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1259,7 +1259,7 @@ void TileMap::_rendering_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
Vector2i grid_size = atlas_source->get_atlas_grid_size();
- if (!atlas_source->get_texture().is_valid() || c.get_atlas_coords().x >= grid_size.x || c.get_atlas_coords().y >= grid_size.y) {
+ if (!atlas_source->get_runtime_texture().is_valid() || c.get_atlas_coords().x >= grid_size.x || c.get_atlas_coords().y >= grid_size.y) {
// Generate a random color from the hashed values of the tiles.
Array to_hash;
to_hash.push_back(c.source_id);
@@ -1299,7 +1299,7 @@ void TileMap::draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSe
}
// Get the texture.
- Ref<Texture2D> tex = atlas_source->get_texture();
+ Ref<Texture2D> tex = atlas_source->get_runtime_texture();
if (!tex.is_valid()) {
return;
}
@@ -1321,7 +1321,7 @@ void TileMap::draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSe
// Get destination rect.
Rect2 dest_rect;
- dest_rect.size = atlas_source->get_tile_texture_region(p_atlas_coords).size;
+ dest_rect.size = atlas_source->get_runtime_tile_texture_region(p_atlas_coords).size;
dest_rect.size.x += FP_ADJUST;
dest_rect.size.y += FP_ADJUST;
@@ -1342,10 +1342,10 @@ void TileMap::draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSe
// Draw the tile.
if (p_frame >= 0) {
- Rect2i source_rect = atlas_source->get_tile_texture_region(p_atlas_coords, p_frame);
+ Rect2i source_rect = atlas_source->get_runtime_tile_texture_region(p_atlas_coords, p_frame);
tex->draw_rect_region(p_canvas_item, dest_rect, source_rect, modulate, transpose, p_tile_set->is_uv_clipping());
} else if (atlas_source->get_tile_animation_frames_count(p_atlas_coords) == 1) {
- Rect2i source_rect = atlas_source->get_tile_texture_region(p_atlas_coords, 0);
+ Rect2i source_rect = atlas_source->get_runtime_tile_texture_region(p_atlas_coords, 0);
tex->draw_rect_region(p_canvas_item, dest_rect, source_rect, modulate, transpose, p_tile_set->is_uv_clipping());
} else {
real_t speed = atlas_source->get_tile_animation_speed(p_atlas_coords);
@@ -1355,7 +1355,7 @@ void TileMap::draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSe
real_t frame_duration = atlas_source->get_tile_animation_frame_duration(p_atlas_coords, frame) / speed;
RenderingServer::get_singleton()->canvas_item_add_animation_slice(p_canvas_item, animation_duration, time, time + frame_duration, 0.0);
- Rect2i source_rect = atlas_source->get_tile_texture_region(p_atlas_coords, frame);
+ Rect2i source_rect = atlas_source->get_runtime_tile_texture_region(p_atlas_coords, frame);
tex->draw_rect_region(p_canvas_item, dest_rect, source_rect, modulate, transpose, p_tile_set->is_uv_clipping());
time += frame_duration;
diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp
index e459c42e8c..073543638f 100644
--- a/scene/3d/area_3d.cpp
+++ b/scene/3d/area_3d.cpp
@@ -33,13 +33,13 @@
#include "scene/scene_string_names.h"
#include "servers/audio_server.h"
-void Area3D::set_space_override_mode(SpaceOverride p_mode) {
- space_override = p_mode;
- PhysicsServer3D::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer3D::AreaSpaceOverrideMode(p_mode));
+void Area3D::set_gravity_space_override_mode(SpaceOverride p_mode) {
+ gravity_space_override = p_mode;
+ PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE, p_mode);
}
-Area3D::SpaceOverride Area3D::get_space_override_mode() const {
- return space_override;
+Area3D::SpaceOverride Area3D::get_gravity_space_override_mode() const {
+ return gravity_space_override;
}
void Area3D::set_gravity_is_point(bool p_enabled) {
@@ -51,21 +51,30 @@ bool Area3D::is_gravity_a_point() const {
return gravity_is_point;
}
-void Area3D::set_gravity_distance_scale(real_t p_scale) {
+void Area3D::set_gravity_point_distance_scale(real_t p_scale) {
gravity_distance_scale = p_scale;
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
}
-real_t Area3D::get_gravity_distance_scale() const {
+real_t Area3D::get_gravity_point_distance_scale() const {
return gravity_distance_scale;
}
-void Area3D::set_gravity_vector(const Vector3 &p_vec) {
- gravity_vec = p_vec;
- PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, p_vec);
+void Area3D::set_gravity_point_center(const Vector3 &p_center) {
+ gravity_vec = p_center;
+ PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, p_center);
}
-Vector3 Area3D::get_gravity_vector() const {
+const Vector3 &Area3D::get_gravity_point_center() const {
+ return gravity_vec;
+}
+
+void Area3D::set_gravity_direction(const Vector3 &p_direction) {
+ gravity_vec = p_direction;
+ PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, p_direction);
+}
+
+const Vector3 &Area3D::get_gravity_direction() const {
return gravity_vec;
}
@@ -78,6 +87,24 @@ real_t Area3D::get_gravity() const {
return gravity;
}
+void Area3D::set_linear_damp_space_override_mode(SpaceOverride p_mode) {
+ linear_damp_space_override = p_mode;
+ PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE, p_mode);
+}
+
+Area3D::SpaceOverride Area3D::get_linear_damp_space_override_mode() const {
+ return linear_damp_space_override;
+}
+
+void Area3D::set_angular_damp_space_override_mode(SpaceOverride p_mode) {
+ angular_damp_space_override = p_mode;
+ PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE, p_mode);
+}
+
+Area3D::SpaceOverride Area3D::get_angular_damp_space_override_mode() const {
+ return angular_damp_space_override;
+}
+
void Area3D::set_linear_damp(real_t p_linear_damp) {
linear_damp = p_linear_damp;
PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, p_linear_damp);
@@ -579,27 +606,58 @@ void Area3D::_validate_property(PropertyInfo &property) const {
}
property.hint_string = options;
+ } else if (property.name.begins_with("gravity") && property.name != "gravity_space_override") {
+ if (gravity_space_override == SPACE_OVERRIDE_DISABLED) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ } else {
+ if (gravity_is_point) {
+ if (property.name == "gravity_direction") {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ } else {
+ if (property.name.begins_with("gravity_point_")) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ }
+ }
+ } else if (property.name.begins_with("linear_damp") && property.name != "linear_damp_space_override") {
+ if (linear_damp_space_override == SPACE_OVERRIDE_DISABLED) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
+ } else if (property.name.begins_with("angular_damp") && property.name != "angular_damp_space_override") {
+ if (angular_damp_space_override == SPACE_OVERRIDE_DISABLED) {
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
+ }
}
CollisionObject3D::_validate_property(property);
}
void Area3D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area3D::set_space_override_mode);
- ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area3D::get_space_override_mode);
+ ClassDB::bind_method(D_METHOD("set_gravity_space_override_mode", "space_override_mode"), &Area3D::set_gravity_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_gravity_space_override_mode"), &Area3D::get_gravity_space_override_mode);
ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area3D::set_gravity_is_point);
ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area3D::is_gravity_a_point);
- ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area3D::set_gravity_distance_scale);
- ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area3D::get_gravity_distance_scale);
+ ClassDB::bind_method(D_METHOD("set_gravity_point_distance_scale", "distance_scale"), &Area3D::set_gravity_point_distance_scale);
+ ClassDB::bind_method(D_METHOD("get_gravity_point_distance_scale"), &Area3D::get_gravity_point_distance_scale);
- ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area3D::set_gravity_vector);
- ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area3D::get_gravity_vector);
+ ClassDB::bind_method(D_METHOD("set_gravity_point_center", "center"), &Area3D::set_gravity_point_center);
+ ClassDB::bind_method(D_METHOD("get_gravity_point_center"), &Area3D::get_gravity_point_center);
+
+ ClassDB::bind_method(D_METHOD("set_gravity_direction", "direction"), &Area3D::set_gravity_direction);
+ ClassDB::bind_method(D_METHOD("get_gravity_direction"), &Area3D::get_gravity_direction);
ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area3D::set_gravity);
ClassDB::bind_method(D_METHOD("get_gravity"), &Area3D::get_gravity);
+ ClassDB::bind_method(D_METHOD("set_linear_damp_space_override_mode", "space_override_mode"), &Area3D::set_linear_damp_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_linear_damp_space_override_mode"), &Area3D::get_linear_damp_space_override_mode);
+
+ ClassDB::bind_method(D_METHOD("set_angular_damp_space_override_mode", "space_override_mode"), &Area3D::set_angular_damp_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_angular_damp_space_override_mode"), &Area3D::get_angular_damp_space_override_mode);
+
ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area3D::set_angular_damp);
ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area3D::get_angular_damp);
@@ -662,14 +720,23 @@ void Area3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitorable"), "set_monitorable", "is_monitorable");
ADD_PROPERTY(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,128,1"), "set_priority", "get_priority");
- ADD_GROUP("Physics Overrides", "");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_distance_scale", "get_gravity_distance_scale");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_vec"), "set_gravity_vector", "get_gravity_vector");
+ ADD_GROUP("Gravity", "gravity_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "gravity_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_space_override_mode", "get_gravity_space_override_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_gravity_is_point", "is_gravity_a_point");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_point_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_point_distance_scale", "get_gravity_point_distance_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_point_center"), "set_gravity_point_center", "get_gravity_point_center");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_direction"), "set_gravity_direction", "get_gravity_direction");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity", PROPERTY_HINT_RANGE, "-32,32,0.001,or_lesser,or_greater"), "set_gravity", "get_gravity");
+
+ ADD_GROUP("Linear Damp", "linear_damp_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "linear_damp_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_linear_damp_space_override_mode", "get_linear_damp_space_override_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp");
+
+ ADD_GROUP("Angular Damp", "angular_damp_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "angular_damp_space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_angular_damp_space_override_mode", "get_angular_damp_space_override_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp");
+
+ ADD_GROUP("Wind", "wind_");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wind_force_magnitude", PROPERTY_HINT_RANGE, "0,10,0.001,or_greater"), "set_wind_force_magnitude", "get_wind_force_magnitude");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wind_attenuation_factor", PROPERTY_HINT_RANGE, "0.0,3.0,0.001,or_greater"), "set_wind_attenuation_factor", "get_wind_attenuation_factor");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "wind_source_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node3D"), "set_wind_source_path", "get_wind_source_path");
@@ -694,7 +761,7 @@ void Area3D::_bind_methods() {
Area3D::Area3D() :
CollisionObject3D(PhysicsServer3D::get_singleton()->area_create(), true) {
set_gravity(9.8);
- set_gravity_vector(Vector3(0, -1, 0));
+ set_gravity_direction(Vector3(0, -1, 0));
set_monitoring(true);
set_monitorable(true);
}
diff --git a/scene/3d/area_3d.h b/scene/3d/area_3d.h
index 847d1c5966..7f31be2e17 100644
--- a/scene/3d/area_3d.h
+++ b/scene/3d/area_3d.h
@@ -47,17 +47,23 @@ public:
};
private:
- SpaceOverride space_override = SPACE_OVERRIDE_DISABLED;
+ SpaceOverride gravity_space_override = SPACE_OVERRIDE_DISABLED;
Vector3 gravity_vec;
real_t gravity;
bool gravity_is_point = false;
real_t gravity_distance_scale = 0.0;
+
+ SpaceOverride linear_damp_space_override = SPACE_OVERRIDE_DISABLED;
+ SpaceOverride angular_damp_space_override = SPACE_OVERRIDE_DISABLED;
real_t angular_damp = 0.1;
real_t linear_damp = 0.1;
+
int priority = 0;
+
real_t wind_force_magnitude = 0.0;
real_t wind_attenuation_factor = 0.0;
NodePath wind_source_path;
+
bool monitoring = false;
bool monitorable = false;
bool locked = false;
@@ -144,21 +150,30 @@ protected:
static void _bind_methods();
public:
- void set_space_override_mode(SpaceOverride p_mode);
- SpaceOverride get_space_override_mode() const;
+ void set_gravity_space_override_mode(SpaceOverride p_mode);
+ SpaceOverride get_gravity_space_override_mode() const;
void set_gravity_is_point(bool p_enabled);
bool is_gravity_a_point() const;
- void set_gravity_distance_scale(real_t p_scale);
- real_t get_gravity_distance_scale() const;
+ void set_gravity_point_distance_scale(real_t p_scale);
+ real_t get_gravity_point_distance_scale() const;
- void set_gravity_vector(const Vector3 &p_vec);
- Vector3 get_gravity_vector() const;
+ void set_gravity_point_center(const Vector3 &p_center);
+ const Vector3 &get_gravity_point_center() const;
+
+ void set_gravity_direction(const Vector3 &p_direction);
+ const Vector3 &get_gravity_direction() const;
void set_gravity(real_t p_gravity);
real_t get_gravity() const;
+ void set_linear_damp_space_override_mode(SpaceOverride p_mode);
+ SpaceOverride get_linear_damp_space_override_mode() const;
+
+ void set_angular_damp_space_override_mode(SpaceOverride p_mode);
+ SpaceOverride get_angular_damp_space_override_mode() const;
+
void set_angular_damp(real_t p_angular_damp);
real_t get_angular_damp() const;
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index d0506227b4..5cb7f431e3 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -174,9 +174,12 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_linear
ERR_FAIL_COND_V(!is_inside_tree(), false);
PhysicsServer3D::MotionResult *r = nullptr;
+ PhysicsServer3D::MotionResult temp_result;
if (r_collision.is_valid()) {
// Needs const_cast because method bindings don't support non-const Ref.
r = const_cast<PhysicsServer3D::MotionResult *>(&r_collision->result);
+ } else {
+ r = &temp_result;
}
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
@@ -184,7 +187,14 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_linear
PhysicsServer3D::MotionParameters parameters(p_from, p_linear_velocity * delta, p_margin);
- return PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), parameters, r);
+ bool colliding = PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), parameters, r);
+
+ if (colliding) {
+ // Don't report collision when the whole motion is done.
+ return (r->collision_safe_fraction < 1.0);
+ } else {
+ return false;
+ }
}
void PhysicsBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) {
@@ -1145,6 +1155,10 @@ bool CharacterBody3D::move_and_slide() {
if (bs) {
Vector3 local_position = gt.origin - bs->get_transform().origin;
current_platform_velocity = bs->get_velocity_at_local_position(local_position);
+ } else {
+ // Body is removed or destroyed, invalidate floor.
+ current_platform_velocity = Vector3();
+ platform_rid = RID();
}
} else {
current_platform_velocity = Vector3();
diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp
index 646f659996..bfa397a1f5 100644
--- a/scene/3d/ray_cast_3d.cpp
+++ b/scene/3d/ray_cast_3d.cpp
@@ -219,6 +219,7 @@ void RayCast3D::_update_raycast_state() {
ray_params.collision_mask = collision_mask;
ray_params.collide_with_bodies = collide_with_bodies;
ray_params.collide_with_areas = collide_with_areas;
+ ray_params.hit_from_inside = hit_from_inside;
PhysicsDirectSpaceState3D::RayResult rr;
if (dss->intersect_ray(ray_params, rr)) {
@@ -268,22 +269,30 @@ void RayCast3D::clear_exceptions() {
exclude.clear();
}
-void RayCast3D::set_collide_with_areas(bool p_clip) {
- collide_with_areas = p_clip;
+void RayCast3D::set_collide_with_areas(bool p_enabled) {
+ collide_with_areas = p_enabled;
}
bool RayCast3D::is_collide_with_areas_enabled() const {
return collide_with_areas;
}
-void RayCast3D::set_collide_with_bodies(bool p_clip) {
- collide_with_bodies = p_clip;
+void RayCast3D::set_collide_with_bodies(bool p_enabled) {
+ collide_with_bodies = p_enabled;
}
bool RayCast3D::is_collide_with_bodies_enabled() const {
return collide_with_bodies;
}
+void RayCast3D::set_hit_from_inside(bool p_enabled) {
+ hit_from_inside = p_enabled;
+}
+
+bool RayCast3D::is_hit_from_inside_enabled() const {
+ return hit_from_inside;
+}
+
void RayCast3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast3D::set_enabled);
ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast3D::is_enabled);
@@ -322,6 +331,9 @@ void RayCast3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast3D::set_collide_with_bodies);
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast3D::is_collide_with_bodies_enabled);
+ ClassDB::bind_method(D_METHOD("set_hit_from_inside", "enable"), &RayCast3D::set_hit_from_inside);
+ ClassDB::bind_method(D_METHOD("is_hit_from_inside_enabled"), &RayCast3D::is_hit_from_inside_enabled);
+
ClassDB::bind_method(D_METHOD("set_debug_shape_custom_color", "debug_shape_custom_color"), &RayCast3D::set_debug_shape_custom_color);
ClassDB::bind_method(D_METHOD("get_debug_shape_custom_color"), &RayCast3D::get_debug_shape_custom_color);
@@ -332,6 +344,7 @@ void RayCast3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "target_position"), "set_target_position", "get_target_position");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_from_inside"), "set_hit_from_inside", "is_hit_from_inside_enabled");
ADD_GROUP("Collide With", "collide_with");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_areas", "is_collide_with_areas_enabled");
diff --git a/scene/3d/ray_cast_3d.h b/scene/3d/ray_cast_3d.h
index 3828bfb4c4..5c2a61c35b 100644
--- a/scene/3d/ray_cast_3d.h
+++ b/scene/3d/ray_cast_3d.h
@@ -65,18 +65,23 @@ class RayCast3D : public Node3D {
bool collide_with_areas = false;
bool collide_with_bodies = true;
+ bool hit_from_inside = false;
+
protected:
void _notification(int p_what);
void _update_raycast_state();
static void _bind_methods();
public:
- void set_collide_with_areas(bool p_clip);
+ void set_collide_with_areas(bool p_enabled);
bool is_collide_with_areas_enabled() const;
- void set_collide_with_bodies(bool p_clip);
+ void set_collide_with_bodies(bool p_enabled);
bool is_collide_with_bodies_enabled() const;
+ void set_hit_from_inside(bool p_enabled);
+ bool is_hit_from_inside_enabled() const;
+
void set_enabled(bool p_enabled);
bool is_enabled() const;
diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp
index b91a2869e4..e621f06ce9 100644
--- a/scene/animation/animation_blend_space_2d.cpp
+++ b/scene/animation/animation_blend_space_2d.cpp
@@ -30,6 +30,7 @@
#include "animation_blend_space_2d.h"
+#include "animation_blend_tree.h"
#include "core/math/geometry_2d.h"
void AnimationNodeBlendSpace2D::get_parameter_list(List<PropertyInfo> *r_list) const {
@@ -531,6 +532,12 @@ double AnimationNodeBlendSpace2D::process(double p_time, bool p_seek) {
if (new_closest != closest && new_closest != -1) {
float from = 0.0;
if (blend_mode == BLEND_MODE_DISCRETE_CARRY && closest != -1) {
+ //for ping-pong loop
+ Ref<AnimationNodeAnimation> na_c = static_cast<Ref<AnimationNodeAnimation>>(blend_points[closest].node);
+ Ref<AnimationNodeAnimation> na_n = static_cast<Ref<AnimationNodeAnimation>>(blend_points[new_closest].node);
+ if (!na_c.is_null() && !na_n.is_null()) {
+ na_n->set_backward(na_c->is_backward());
+ }
//see how much animation remains
from = length_internal - blend_node(blend_points[closest].name, blend_points[closest].node, p_time, false, 0.0, FILTER_IGNORE, false);
}
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index d18e1a92d8..d6c5d0b51c 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -30,6 +30,7 @@
#include "animation_blend_tree.h"
+#include "scene/resources/animation.h"
#include "scene/scene_string_names.h"
void AnimationNodeAnimation::set_animation(const StringName &p_name) {
@@ -83,30 +84,55 @@ double AnimationNodeAnimation::process(double p_time, bool p_seek) {
}
Ref<Animation> anim = ap->get_animation(animation);
-
- double step;
+ double anim_size = (double)anim->get_length();
+ double step = 0.0;
+ double prev_time = time;
+ int pingponged = 0;
+ bool current_backward = signbit(p_time);
if (p_seek) {
+ step = p_time - time;
time = p_time;
- step = 0;
} else {
- time = MAX(0, time + p_time);
- step = p_time;
+ p_time *= backward ? -1.0 : 1.0;
+ if (!(time == anim_size && !current_backward) && !(time == 0 && current_backward)) {
+ time = time + p_time;
+ step = p_time;
+ }
}
- double anim_size = anim->get_length();
-
- if (anim->has_loop()) {
+ if (anim->get_loop_mode() == Animation::LoopMode::LOOP_PINGPONG) {
if (anim_size) {
- time = Math::fposmod(time, anim_size);
+ if ((int)Math::floor(abs(time - prev_time) / anim_size) % 2 == 0) {
+ if (prev_time > 0 && time <= 0) {
+ backward = !backward;
+ pingponged = -1;
+ }
+ if (prev_time < anim_size && time >= anim_size) {
+ backward = !backward;
+ pingponged = 1;
+ }
+ }
+ time = Math::pingpong(time, anim_size);
}
-
- } else if (time > anim_size) {
- time = anim_size;
+ } else {
+ if (anim->get_loop_mode() == Animation::LoopMode::LOOP_LINEAR) {
+ if (anim_size) {
+ time = Math::fposmod(time, anim_size);
+ }
+ } else if (time < 0) {
+ time = 0;
+ } else if (time > anim_size) {
+ time = anim_size;
+ }
+ backward = false;
}
- blend_animation(animation, time, step, p_seek, 1.0);
-
+ if (play_mode == PLAY_MODE_FORWARD) {
+ blend_animation(animation, time, step, p_seek, 1.0, pingponged);
+ } else {
+ blend_animation(animation, anim_size - time, -step, p_seek, 1.0, pingponged);
+ }
set_parameter(this->time, time);
return anim_size - time;
@@ -116,11 +142,34 @@ String AnimationNodeAnimation::get_caption() const {
return "Animation";
}
+void AnimationNodeAnimation::set_play_mode(PlayMode p_play_mode) {
+ play_mode = p_play_mode;
+}
+
+AnimationNodeAnimation::PlayMode AnimationNodeAnimation::get_play_mode() const {
+ return play_mode;
+}
+
+void AnimationNodeAnimation::set_backward(bool p_backward) {
+ backward = p_backward;
+}
+
+bool AnimationNodeAnimation::is_backward() const {
+ return backward;
+}
+
void AnimationNodeAnimation::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_animation", "name"), &AnimationNodeAnimation::set_animation);
ClassDB::bind_method(D_METHOD("get_animation"), &AnimationNodeAnimation::get_animation);
+ ClassDB::bind_method(D_METHOD("set_play_mode", "mode"), &AnimationNodeAnimation::set_play_mode);
+ ClassDB::bind_method(D_METHOD("get_play_mode"), &AnimationNodeAnimation::get_play_mode);
+
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation"), "set_animation", "get_animation");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "play_mode", PROPERTY_HINT_ENUM, "Forward,Backward"), "set_play_mode", "get_play_mode");
+
+ BIND_ENUM_CONSTANT(PLAY_MODE_FORWARD);
+ BIND_ENUM_CONSTANT(PLAY_MODE_BACKWARD);
}
AnimationNodeAnimation::AnimationNodeAnimation() {
@@ -533,7 +582,7 @@ AnimationNodeBlend3::AnimationNodeBlend3() {
/////////////////////////////////
void AnimationNodeTimeScale::get_parameter_list(List<PropertyInfo> *r_list) const {
- r_list->push_back(PropertyInfo(Variant::FLOAT, scale, PROPERTY_HINT_RANGE, "0,32,0.01,or_greater"));
+ r_list->push_back(PropertyInfo(Variant::FLOAT, scale, PROPERTY_HINT_RANGE, "-32,32,0.01,or_lesser,or_greater"));
}
Variant AnimationNodeTimeScale::get_parameter_default_value(const StringName &p_parameter) const {
diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h
index 258443a999..e55dfb58ed 100644
--- a/scene/animation/animation_blend_tree.h
+++ b/scene/animation/animation_blend_tree.h
@@ -42,12 +42,12 @@ class AnimationNodeAnimation : public AnimationRootNode {
uint64_t last_version = 0;
bool skip = false;
-protected:
- void _validate_property(PropertyInfo &property) const override;
-
- static void _bind_methods();
-
public:
+ enum PlayMode {
+ PLAY_MODE_FORWARD,
+ PLAY_MODE_BACKWARD
+ };
+
void get_parameter_list(List<PropertyInfo> *r_list) const override;
static Vector<String> (*get_editable_animation_list)();
@@ -58,9 +58,25 @@ public:
void set_animation(const StringName &p_name);
StringName get_animation() const;
+ void set_play_mode(PlayMode p_play_mode);
+ PlayMode get_play_mode() const;
+
+ void set_backward(bool p_backward);
+ bool is_backward() const;
+
AnimationNodeAnimation();
+
+protected:
+ void _validate_property(PropertyInfo &property) const override;
+ static void _bind_methods();
+
+private:
+ PlayMode play_mode = PLAY_MODE_FORWARD;
+ bool backward = false;
};
+VARIANT_ENUM_CAST(AnimationNodeAnimation::PlayMode)
+
class AnimationNodeOneShot : public AnimationNode {
GDCLASS(AnimationNodeOneShot, AnimationNode);
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index f91422ac1a..93339711bd 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -398,12 +398,13 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_ov
}
}
-void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double p_time, double p_delta, float p_interp, bool p_is_current, bool p_seeked, bool p_started) {
+void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double p_time, double p_delta, float p_interp, bool p_is_current, bool p_seeked, bool p_started, int p_pingponged) {
_ensure_node_caches(p_anim);
ERR_FAIL_COND(p_anim->node_cache.size() != p_anim->animation->get_track_count());
Animation *a = p_anim->animation.operator->();
bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
+ bool backward = signbit(p_delta);
for (int i = 0; i < a->get_track_count(); i++) {
// If an animation changes this animation (or it animates itself)
@@ -557,8 +558,8 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
continue; //eeh not worth it
}
- float first_key_time = a->track_get_key_time(i, 0);
- float transition = 1.0;
+ double first_key_time = a->track_get_key_time(i, 0);
+ double transition = 1.0;
int first_key = 0;
if (first_key_time == 0.0) {
@@ -566,13 +567,13 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
if (key_count == 1) {
continue; //with one key we can't do anything
}
- transition = a->track_get_key_transition(i, 0);
+ transition = (double)a->track_get_key_transition(i, 0);
first_key_time = a->track_get_key_time(i, 1);
first_key = 1;
}
if (p_time < first_key_time) {
- float c = Math::ease(p_time / first_key_time, transition);
+ double c = Math::ease(p_time / first_key_time, transition);
Variant first_value = a->track_get_key_value(i, first_key);
Variant interp_value;
Variant::interpolate(pa->capture, first_value, c, interp_value);
@@ -614,7 +615,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
} else if (p_is_current && p_delta != 0) {
List<int> indices;
- a->value_track_get_key_indices(i, p_time, p_delta, &indices);
+ a->value_track_get_key_indices(i, p_time, p_delta, &indices, p_pingponged);
for (int &F : indices) {
Variant value = a->track_get_key_value(i, F);
@@ -673,7 +674,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
List<int> indices;
- a->method_track_get_key_indices(i, p_time, p_delta, &indices);
+ a->method_track_get_key_indices(i, p_time, p_delta, &indices, p_pingponged);
for (int &E : indices) {
StringName method = a->method_track_get_name(i, E);
@@ -728,7 +729,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
TrackNodeCache::BezierAnim *ba = &E->get();
- float bezier = a->bezier_track_interpolate(i, p_time);
+ real_t bezier = a->bezier_track_interpolate(i, p_time);
if (ba->accum_pass != accum_pass) {
ERR_CONTINUE(cache_update_bezier_size >= NODE_CACHE_UPDATE_MAX);
cache_update_bezier[cache_update_bezier_size++] = ba;
@@ -789,7 +790,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
} else {
//find stuff to play
List<int> to_play;
- a->track_get_key_indices_in_range(i, p_time, p_delta, &to_play);
+ a->track_get_key_indices_in_range(i, p_time, p_delta, &to_play, p_pingponged);
if (to_play.size()) {
int idx = to_play.back()->get();
@@ -817,12 +818,14 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
nc->audio_start = p_time;
}
} else if (nc->audio_playing) {
- bool loop = a->has_loop();
+ bool loop = a->get_loop_mode() != Animation::LoopMode::LOOP_NONE;
bool stop = false;
- if (!loop && p_time < nc->audio_start) {
- stop = true;
+ if (!loop) {
+ if ((p_time < nc->audio_start && !backward) || (p_time > nc->audio_start && backward)) {
+ stop = true;
+ }
} else if (nc->audio_len > 0) {
float len = nc->audio_start > p_time ? (a->get_length() - nc->audio_start) + p_time : p_time - nc->audio_start;
@@ -863,12 +866,23 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
Ref<Animation> anim = player->get_animation(anim_name);
- double at_anim_pos;
+ double at_anim_pos = 0.0;
- if (anim->has_loop()) {
- at_anim_pos = Math::fposmod(p_time - pos, (double)anim->get_length()); //seek to loop
- } else {
- at_anim_pos = MIN((double)anim->get_length(), p_time - pos); //seek to end
+ switch (anim->get_loop_mode()) {
+ case Animation::LoopMode::LOOP_NONE: {
+ at_anim_pos = MIN((double)anim->get_length(), p_time - pos); //seek to end
+ } break;
+
+ case Animation::LoopMode::LOOP_LINEAR: {
+ at_anim_pos = Math::fposmod(p_time - pos, (double)anim->get_length()); //seek to loop
+ } break;
+
+ case Animation::LoopMode::LOOP_PINGPONG: {
+ at_anim_pos = Math::pingpong(p_time - pos, (double)anim->get_length());
+ } break;
+
+ default:
+ break;
}
if (player->is_playing() || p_seeked) {
@@ -883,7 +897,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
} else {
//find stuff to play
List<int> to_play;
- a->track_get_key_indices_in_range(i, p_time, p_delta, &to_play);
+ a->track_get_key_indices_in_range(i, p_time, p_delta, &to_play, p_pingponged);
if (to_play.size()) {
int idx = to_play.back()->get();
@@ -913,46 +927,73 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, double p_delta,
double next_pos = cd.pos + delta;
real_t len = cd.from->animation->get_length();
- bool loop = cd.from->animation->has_loop();
+ int pingponged = 0;
+
+ switch (cd.from->animation->get_loop_mode()) {
+ case Animation::LoopMode::LOOP_NONE: {
+ if (next_pos < 0) {
+ next_pos = 0;
+ } else if (next_pos > len) {
+ next_pos = len;
+ }
- if (!loop) {
- if (next_pos < 0) {
- next_pos = 0;
- } else if (next_pos > len) {
- next_pos = len;
- }
+ bool backwards = signbit(delta); // Negative zero means playing backwards too
+ delta = next_pos - cd.pos; // Fix delta (after determination of backwards because negative zero is lost here)
- bool backwards = signbit(delta); // Negative zero means playing backwards too
- delta = next_pos - cd.pos; // Fix delta (after determination of backwards because negative zero is lost here)
+ if (&cd == &playback.current) {
+ if (!backwards && cd.pos <= len && next_pos == len) {
+ //playback finished
+ end_reached = true;
+ end_notify = cd.pos < len; // Notify only if not already at the end
+ }
- if (&cd == &playback.current) {
- if (!backwards && cd.pos <= len && next_pos == len) {
- //playback finished
- end_reached = true;
- end_notify = cd.pos < len; // Notify only if not already at the end
+ if (backwards && cd.pos >= 0 && next_pos == 0) {
+ //playback finished
+ end_reached = true;
+ end_notify = cd.pos > 0; // Notify only if not already at the beginning
+ }
}
+ } break;
- if (backwards && cd.pos >= 0 && next_pos == 0) {
- //playback finished
- end_reached = true;
- end_notify = cd.pos > 0; // Notify only if not already at the beginning
+ case Animation::LoopMode::LOOP_LINEAR: {
+ double looped_next_pos = Math::fposmod(next_pos, (double)len);
+ if (looped_next_pos == 0 && next_pos != 0) {
+ // Loop multiples of the length to it, rather than 0
+ // so state at time=length is previewable in the editor
+ next_pos = len;
+ } else {
+ next_pos = looped_next_pos;
}
- }
+ } break;
- } else {
- double looped_next_pos = Math::fposmod(next_pos, (double)len);
- if (looped_next_pos == 0 && next_pos != 0) {
- // Loop multiples of the length to it, rather than 0
- // so state at time=length is previewable in the editor
- next_pos = len;
- } else {
- next_pos = looped_next_pos;
- }
+ case Animation::LoopMode::LOOP_PINGPONG: {
+ if ((int)Math::floor(abs(next_pos - cd.pos) / len) % 2 == 0) {
+ if (next_pos < 0 && cd.pos >= 0) {
+ cd.speed_scale *= -1.0;
+ pingponged = -1;
+ }
+ if (next_pos > len && cd.pos <= len) {
+ cd.speed_scale *= -1.0;
+ pingponged = 1;
+ }
+ }
+ double looped_next_pos = Math::pingpong(next_pos, (double)len);
+ if (looped_next_pos == 0 && next_pos != 0) {
+ // Loop multiples of the length to it, rather than 0
+ // so state at time=length is previewable in the editor
+ next_pos = len;
+ } else {
+ next_pos = looped_next_pos;
+ }
+ } break;
+
+ default:
+ break;
}
cd.pos = next_pos;
- _animation_process_animation(cd.from, cd.pos, delta, p_blend, &cd == &playback.current, p_seeked, p_started);
+ _animation_process_animation(cd.from, cd.pos, delta, p_blend, &cd == &playback.current, p_seeked, p_started, pingponged);
}
void AnimationPlayer::_animation_process2(double p_delta, bool p_started) {
diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h
index d9d88b5510..ea04918988 100644
--- a/scene/animation/animation_player.h
+++ b/scene/animation/animation_player.h
@@ -231,7 +231,7 @@ private:
NodePath root;
- void _animation_process_animation(AnimationData *p_anim, double p_time, double p_delta, float p_interp, bool p_is_current = true, bool p_seeked = false, bool p_started = false);
+ void _animation_process_animation(AnimationData *p_anim, double p_time, double p_delta, float p_interp, bool p_is_current = true, bool p_seeked = false, bool p_started = false, int p_pingponged = 0);
void _ensure_node_caches(AnimationData *p_anim, Node *p_root_override = nullptr);
void _animation_process_data(PlaybackData &cd, double p_delta, float p_blend, bool p_seeked, bool p_started);
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 4b71fe7a01..37e754148c 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -32,6 +32,7 @@
#include "animation_blend_tree.h"
#include "core/config/engine.h"
+#include "scene/resources/animation.h"
#include "scene/scene_string_names.h"
#include "servers/audio/audio_stream.h"
@@ -87,7 +88,7 @@ void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) {
}
}
-void AnimationNode::blend_animation(const StringName &p_animation, real_t p_time, real_t p_delta, bool p_seeked, real_t p_blend) {
+void AnimationNode::blend_animation(const StringName &p_animation, real_t p_time, real_t p_delta, bool p_seeked, real_t p_blend, int p_pingponged) {
ERR_FAIL_COND(!state);
ERR_FAIL_COND(!state->player->has_animation(p_animation));
@@ -113,6 +114,7 @@ void AnimationNode::blend_animation(const StringName &p_animation, real_t p_time
anim_state.time = p_time;
anim_state.animation = animation;
anim_state.seeked = p_seeked;
+ anim_state.pingponged = p_pingponged;
state->animation_states.push_back(anim_state);
}
@@ -418,7 +420,7 @@ void AnimationNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_filters", "filters"), &AnimationNode::_set_filters);
ClassDB::bind_method(D_METHOD("_get_filters"), &AnimationNode::_get_filters);
- ClassDB::bind_method(D_METHOD("blend_animation", "animation", "time", "delta", "seeked", "blend"), &AnimationNode::blend_animation);
+ ClassDB::bind_method(D_METHOD("blend_animation", "animation", "time", "delta", "seeked", "blend", "pingponged"), &AnimationNode::blend_animation, DEFVAL(0));
ClassDB::bind_method(D_METHOD("blend_node", "name", "node", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_node, DEFVAL(FILTER_IGNORE), DEFVAL(true));
ClassDB::bind_method(D_METHOD("blend_input", "input_index", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_input, DEFVAL(FILTER_IGNORE), DEFVAL(true));
@@ -898,6 +900,10 @@ void AnimationTree::_process_graph(real_t p_delta) {
double delta = as.delta;
real_t weight = as.blend;
bool seeked = as.seeked;
+ int pingponged = as.pingponged;
+#ifndef _3D_DISABLED
+ bool backward = signbit(delta);
+#endif // _3D_DISABLED
for (int i = 0; i < a->get_track_count(); i++) {
NodePath path = a->track_get_path(i);
@@ -939,27 +945,63 @@ void AnimationTree::_process_graph(real_t p_delta) {
}
if (track->root_motion) {
- real_t prev_time = time - delta;
- if (prev_time < 0) {
- if (!a->has_loop()) {
- prev_time = 0;
- } else {
- prev_time = a->get_length() + prev_time;
+ double prev_time = time - delta;
+ if (!backward) {
+ if (prev_time < 0) {
+ switch (a->get_loop_mode()) {
+ case Animation::LOOP_NONE: {
+ prev_time = 0;
+ } break;
+ case Animation::LOOP_LINEAR: {
+ prev_time = Math::fposmod(prev_time, (double)a->get_length());
+ } break;
+ case Animation::LOOP_PINGPONG: {
+ prev_time = Math::pingpong(prev_time, (double)a->get_length());
+ } break;
+ default:
+ break;
+ }
+ }
+ } else {
+ if (prev_time > a->get_length()) {
+ switch (a->get_loop_mode()) {
+ case Animation::LOOP_NONE: {
+ prev_time = (double)a->get_length();
+ } break;
+ case Animation::LOOP_LINEAR: {
+ prev_time = Math::fposmod(prev_time, (double)a->get_length());
+ } break;
+ case Animation::LOOP_PINGPONG: {
+ prev_time = Math::pingpong(prev_time, (double)a->get_length());
+ } break;
+ default:
+ break;
+ }
}
}
Vector3 loc[2];
- if (prev_time > time) {
- Error err = a->position_track_interpolate(i, prev_time, &loc[0]);
- if (err != OK) {
- continue;
+ if (!backward) {
+ if (prev_time > time) {
+ Error err = a->position_track_interpolate(i, prev_time, &loc[0]);
+ if (err != OK) {
+ continue;
+ }
+ a->position_track_interpolate(i, (double)a->get_length(), &loc[1]);
+ t->loc += (loc[1] - loc[0]) * blend;
+ prev_time = 0;
+ }
+ } else {
+ if (prev_time < time) {
+ Error err = a->position_track_interpolate(i, prev_time, &loc[0]);
+ if (err != OK) {
+ continue;
+ }
+ a->position_track_interpolate(i, 0, &loc[1]);
+ t->loc += (loc[1] - loc[0]) * blend;
+ prev_time = 0;
}
-
- a->position_track_interpolate(i, a->get_length(), &loc[1]);
-
- t->loc += (loc[1] - loc[0]) * blend;
- prev_time = 0;
}
Error err = a->position_track_interpolate(i, prev_time, &loc[0]);
@@ -968,17 +1010,13 @@ void AnimationTree::_process_graph(real_t p_delta) {
}
a->position_track_interpolate(i, time, &loc[1]);
-
t->loc += (loc[1] - loc[0]) * blend;
-
- prev_time = 0;
+ prev_time = !backward ? 0 : (double)a->get_length();
} else {
Vector3 loc;
Error err = a->position_track_interpolate(i, time, &loc);
- //ERR_CONTINUE(err!=OK); //used for testing, should be removed
-
if (err != OK) {
continue;
}
@@ -1000,29 +1038,65 @@ void AnimationTree::_process_graph(real_t p_delta) {
}
if (track->root_motion) {
- real_t prev_time = time - delta;
- if (prev_time < 0) {
- if (!a->has_loop()) {
- prev_time = 0;
- } else {
- prev_time = a->get_length() + prev_time;
+ double prev_time = time - delta;
+ if (!backward) {
+ if (prev_time < 0) {
+ switch (a->get_loop_mode()) {
+ case Animation::LOOP_NONE: {
+ prev_time = 0;
+ } break;
+ case Animation::LOOP_LINEAR: {
+ prev_time = Math::fposmod(prev_time, (double)a->get_length());
+ } break;
+ case Animation::LOOP_PINGPONG: {
+ prev_time = Math::pingpong(prev_time, (double)a->get_length());
+ } break;
+ default:
+ break;
+ }
+ }
+ } else {
+ if (prev_time > a->get_length()) {
+ switch (a->get_loop_mode()) {
+ case Animation::LOOP_NONE: {
+ prev_time = (double)a->get_length();
+ } break;
+ case Animation::LOOP_LINEAR: {
+ prev_time = Math::fposmod(prev_time, (double)a->get_length());
+ } break;
+ case Animation::LOOP_PINGPONG: {
+ prev_time = Math::pingpong(prev_time, (double)a->get_length());
+ } break;
+ default:
+ break;
+ }
}
}
Quaternion rot[2];
- if (prev_time > time) {
- Error err = a->rotation_track_interpolate(i, prev_time, &rot[0]);
- if (err != OK) {
- continue;
+ if (!backward) {
+ if (prev_time > time) {
+ Error err = a->rotation_track_interpolate(i, prev_time, &rot[0]);
+ if (err != OK) {
+ continue;
+ }
+ a->rotation_track_interpolate(i, (double)a->get_length(), &rot[1]);
+ Quaternion q = Quaternion().slerp(rot[0].normalized().inverse() * rot[1].normalized(), blend).normalized();
+ t->rot = (t->rot * q).normalized();
+ prev_time = 0;
+ }
+ } else {
+ if (prev_time < time) {
+ Error err = a->rotation_track_interpolate(i, prev_time, &rot[0]);
+ if (err != OK) {
+ continue;
+ }
+ a->rotation_track_interpolate(i, 0, &rot[1]);
+ Quaternion q = Quaternion().slerp(rot[0].normalized().inverse() * rot[1].normalized(), blend).normalized();
+ t->rot = (t->rot * q).normalized();
+ prev_time = 0;
}
-
- a->rotation_track_interpolate(i, a->get_length(), &rot[1]);
-
- Quaternion q = Quaternion().slerp(rot[0].normalized().inverse() * rot[1].normalized(), blend).normalized();
- t->rot = (t->rot * q).normalized();
-
- prev_time = 0;
}
Error err = a->rotation_track_interpolate(i, prev_time, &rot[0]);
@@ -1031,18 +1105,14 @@ void AnimationTree::_process_graph(real_t p_delta) {
}
a->rotation_track_interpolate(i, time, &rot[1]);
-
Quaternion q = Quaternion().slerp(rot[0].normalized().inverse() * rot[1].normalized(), blend).normalized();
t->rot = (t->rot * q).normalized();
-
- prev_time = 0;
+ prev_time = !backward ? 0 : (double)a->get_length();
} else {
Quaternion rot;
Error err = a->rotation_track_interpolate(i, time, &rot);
- //ERR_CONTINUE(err!=OK); //used for testing, should be removed
-
if (err != OK) {
continue;
}
@@ -1071,28 +1141,63 @@ void AnimationTree::_process_graph(real_t p_delta) {
}
if (track->root_motion) {
- real_t prev_time = time - delta;
- if (prev_time < 0) {
- if (!a->has_loop()) {
- prev_time = 0;
- } else {
- prev_time = a->get_length() + prev_time;
+ double prev_time = time - delta;
+ if (!backward) {
+ if (prev_time < 0) {
+ switch (a->get_loop_mode()) {
+ case Animation::LOOP_NONE: {
+ prev_time = 0;
+ } break;
+ case Animation::LOOP_LINEAR: {
+ prev_time = Math::fposmod(prev_time, (double)a->get_length());
+ } break;
+ case Animation::LOOP_PINGPONG: {
+ prev_time = Math::pingpong(prev_time, (double)a->get_length());
+ } break;
+ default:
+ break;
+ }
+ }
+ } else {
+ if (prev_time > a->get_length()) {
+ switch (a->get_loop_mode()) {
+ case Animation::LOOP_NONE: {
+ prev_time = (double)a->get_length();
+ } break;
+ case Animation::LOOP_LINEAR: {
+ prev_time = Math::fposmod(prev_time, (double)a->get_length());
+ } break;
+ case Animation::LOOP_PINGPONG: {
+ prev_time = Math::pingpong(prev_time, (double)a->get_length());
+ } break;
+ default:
+ break;
+ }
}
}
Vector3 scale[2];
- if (prev_time > time) {
- Error err = a->scale_track_interpolate(i, prev_time, &scale[0]);
- if (err != OK) {
- continue;
+ if (!backward) {
+ if (prev_time > time) {
+ Error err = a->scale_track_interpolate(i, prev_time, &scale[0]);
+ if (err != OK) {
+ continue;
+ }
+ a->scale_track_interpolate(i, (double)a->get_length(), &scale[1]);
+ t->scale += (scale[1] - scale[0]) * blend;
+ prev_time = 0;
+ }
+ } else {
+ if (prev_time < time) {
+ Error err = a->scale_track_interpolate(i, prev_time, &scale[0]);
+ if (err != OK) {
+ continue;
+ }
+ a->scale_track_interpolate(i, 0, &scale[1]);
+ t->scale += (scale[1] - scale[0]) * blend;
+ prev_time = 0;
}
-
- a->scale_track_interpolate(i, a->get_length(), &scale[1]);
-
- t->scale += (scale[1] - scale[0]) * blend;
-
- prev_time = 0;
}
Error err = a->scale_track_interpolate(i, prev_time, &scale[0]);
@@ -1101,17 +1206,13 @@ void AnimationTree::_process_graph(real_t p_delta) {
}
a->scale_track_interpolate(i, time, &scale[1]);
-
t->scale += (scale[1] - scale[0]) * blend;
-
- prev_time = 0;
+ prev_time = !backward ? 0 : (double)a->get_length();
} else {
Vector3 scale;
Error err = a->scale_track_interpolate(i, time, &scale);
- //ERR_CONTINUE(err!=OK); //used for testing, should be removed
-
if (err != OK) {
continue;
}
@@ -1164,7 +1265,7 @@ void AnimationTree::_process_graph(real_t p_delta) {
} else {
List<int> indices;
- a->value_track_get_key_indices(i, time, delta, &indices);
+ a->value_track_get_key_indices(i, time, delta, &indices, pingponged);
for (int &F : indices) {
Variant value = a->track_get_key_value(i, F);
@@ -1181,7 +1282,7 @@ void AnimationTree::_process_graph(real_t p_delta) {
List<int> indices;
- a->method_track_get_key_indices(i, time, delta, &indices);
+ a->method_track_get_key_indices(i, time, delta, &indices, pingponged);
for (int &F : indices) {
StringName method = a->method_track_get_name(i, F);
@@ -1264,7 +1365,7 @@ void AnimationTree::_process_graph(real_t p_delta) {
} else {
//find stuff to play
List<int> to_play;
- a->track_get_key_indices_in_range(i, time, delta, &to_play);
+ a->track_get_key_indices_in_range(i, time, delta, &to_play, pingponged);
if (to_play.size()) {
int idx = to_play.back()->get();
@@ -1292,12 +1393,20 @@ void AnimationTree::_process_graph(real_t p_delta) {
t->start = time;
}
} else if (t->playing) {
- bool loop = a->has_loop();
+ bool loop = a->get_loop_mode() != Animation::LoopMode::LOOP_NONE;
bool stop = false;
- if (!loop && time < t->start) {
- stop = true;
+ if (!loop) {
+ if (delta > 0) {
+ if (time < t->start) {
+ stop = true;
+ }
+ } else if (delta < 0) {
+ if (time > t->start) {
+ stop = true;
+ }
+ }
} else if (t->len > 0) {
real_t len = t->start > time ? (a->get_length() - t->start) + time : time - t->start;
@@ -1331,7 +1440,7 @@ void AnimationTree::_process_graph(real_t p_delta) {
continue;
}
- if (delta == 0 || seeked) {
+ if (seeked) {
//seek
int idx = a->track_find_key(i, time);
if (idx < 0) {
@@ -1347,12 +1456,20 @@ void AnimationTree::_process_graph(real_t p_delta) {
Ref<Animation> anim = player2->get_animation(anim_name);
- real_t at_anim_pos;
-
- if (anim->has_loop()) {
- at_anim_pos = Math::fposmod(time - pos, (double)anim->get_length()); //seek to loop
- } else {
- at_anim_pos = MAX(anim->get_length(), time - pos); //seek to end
+ real_t at_anim_pos = 0.0;
+
+ switch (anim->get_loop_mode()) {
+ case Animation::LoopMode::LOOP_NONE: {
+ at_anim_pos = MAX((double)anim->get_length(), time - pos); //seek to end
+ } break;
+ case Animation::LoopMode::LOOP_LINEAR: {
+ at_anim_pos = Math::fposmod(time - pos, (double)anim->get_length()); //seek to loop
+ } break;
+ case Animation::LoopMode::LOOP_PINGPONG: {
+ at_anim_pos = Math::pingpong(time - pos, (double)a->get_length());
+ } break;
+ default:
+ break;
}
if (player2->is_playing() || seeked) {
@@ -1367,7 +1484,7 @@ void AnimationTree::_process_graph(real_t p_delta) {
} else {
//find stuff to play
List<int> to_play;
- a->track_get_key_indices_in_range(i, time, delta, &to_play);
+ a->track_get_key_indices_in_range(i, time, delta, &to_play, pingponged);
if (to_play.size()) {
int idx = to_play.back()->get();
diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h
index 5abea39d20..6fc051fa41 100644
--- a/scene/animation/animation_tree.h
+++ b/scene/animation/animation_tree.h
@@ -66,6 +66,7 @@ public:
const Vector<real_t> *track_blends = nullptr;
real_t blend = 0.0;
bool seeked = false;
+ int pingponged = 0;
};
struct State {
@@ -98,9 +99,10 @@ public:
real_t _blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, real_t p_time, bool p_seek, real_t p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true, real_t *r_max = nullptr);
protected:
- void blend_animation(const StringName &p_animation, real_t p_time, real_t p_delta, bool p_seeked, real_t p_blend);
+ void blend_animation(const StringName &p_animation, real_t p_time, real_t p_delta, bool p_seeked, real_t p_blend, int p_pingponged = 0);
real_t blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, real_t p_time, bool p_seek, real_t p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true);
real_t blend_input(int p_input, real_t p_time, bool p_seek, real_t p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true);
+
void make_invalid(const String &p_reason);
static void _bind_methods();
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 15fd22ced5..dc48ce9045 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -577,13 +577,12 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
if (p_data.get_type() == Variant::STRING) {
set_caret_at_pixel_pos(p_point.x);
- int selected = selection.end - selection.begin;
- text.erase(selection.begin, selected);
+ text = text.left(selection.begin) + text.substr(selection.end);
_shape();
insert_text_at_caret(p_data);
- selection.begin = caret_column - selected;
+ selection.begin = caret_column - (selection.end - selection.begin);
selection.end = caret_column;
}
}
@@ -1244,7 +1243,7 @@ void LineEdit::delete_char() {
return;
}
- text.erase(caret_column - 1, 1);
+ text = text.left(caret_column - 1) + text.substr(caret_column);
_shape();
set_caret_column(get_caret_column() - 1);
@@ -1256,7 +1255,7 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
ERR_FAIL_COND_MSG(p_from_column < 0 || p_from_column > p_to_column || p_to_column > text.length(),
vformat("Positional parameters (from: %d, to: %d) are inverted or outside the text length (%d).", p_from_column, p_to_column, text.length()));
- text.erase(p_from_column, p_to_column - p_from_column);
+ text = text.left(p_from_column) + text.substr(p_to_column);
_shape();
caret_column -= CLAMP(caret_column - p_from_column, 0, p_to_column - p_from_column);
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 308880ef18..cdca080916 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -36,7 +36,7 @@
#include "scene/scene_string_names.h"
#include "servers/display_server.h"
-#include "modules/modules_enabled.gen.h"
+#include "modules/modules_enabled.gen.h" // For regex.
#ifdef MODULE_REGEX_ENABLED
#include "modules/regex/regex.h"
#endif
@@ -3801,45 +3801,32 @@ String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p
}
}
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
+ if (it->type == ITEM_TABLE) {
+ ItemTable *table = static_cast<ItemTable *>(it);
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
+ for (int i = 0; i < frame->lines.size(); i++) {
+ text += _get_line_text(frame, i, p_selection);
+ }
+ }
+ }
if ((p_selection.to_item != nullptr) && (p_selection.to_item->index < l.from->index)) {
- break;
+ continue;
}
if ((p_selection.from_item != nullptr) && (p_selection.from_item->index >= end_idx)) {
- break;
+ continue;
}
- switch (it->type) {
- case ITEM_NEWLINE: {
- text += "\n";
- } break;
- case ITEM_TEXT: {
- ItemText *t = (ItemText *)it;
- text += t->text;
- } break;
- case ITEM_IMAGE: {
- text += " ";
- } break;
- case ITEM_TABLE: {
- ItemTable *table = static_cast<ItemTable *>(it);
- int idx = 0;
- int col_count = table->columns.size();
- for (Item *E : table->subitems) {
- ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E);
- int column = idx % col_count;
-
- for (int i = 0; i < frame->lines.size(); i++) {
- text += _get_line_text(frame, i, p_selection);
- }
- if (column == col_count - 1) {
- text += "\n";
- } else {
- text += " ";
- }
- idx++;
- }
- } break;
- default:
- break;
+ if (it->type == ITEM_DROPCAP) {
+ const ItemDropcap *dc = static_cast<ItemDropcap *>(it);
+ text += dc->text;
+ } else if (it->type == ITEM_TEXT) {
+ const ItemText *t = static_cast<ItemText *>(it);
+ text += t->text;
+ } else if (it->type == ITEM_NEWLINE) {
+ text += "\n";
+ } else if (it->type == ITEM_IMAGE) {
+ text += " ";
}
}
if ((l.from != nullptr) && (p_frame == p_selection.to_frame) && (p_selection.to_item != nullptr) && (p_selection.to_item->index >= l.from->index) && (p_selection.to_item->index < end_idx)) {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index cb7a6c0978..27f272a12d 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -3697,8 +3697,10 @@ void TextEdit::set_selection_mode(SelectionMode p_mode, int p_line, int p_column
if (p_line >= 0) {
ERR_FAIL_INDEX(p_line, text.size());
selection.selecting_line = p_line;
+ selection.selecting_column = CLAMP(selection.selecting_column, 0, text[selection.selecting_line].length());
}
if (p_column >= 0) {
+ ERR_FAIL_INDEX(selection.selecting_line, text.size());
ERR_FAIL_INDEX(p_column, text[selection.selecting_line].length());
selection.selecting_column = p_column;
}
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 3be73af861..44420fcc31 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2889,7 +2889,7 @@ void Node::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_priority"), "set_process_priority", "get_process_priority");
ADD_GROUP("Editor Description", "editor_");
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "set_editor_description", "get_editor_description");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT), "set_editor_description", "get_editor_description");
GDVIRTUAL_BIND(_process, "delta");
GDVIRTUAL_BIND(_physics_process, "delta");
diff --git a/scene/property_utils.cpp b/scene/property_utils.cpp
index 79821b8399..7df601492b 100644
--- a/scene/property_utils.cpp
+++ b/scene/property_utils.cpp
@@ -32,9 +32,12 @@
#include "core/config/engine.h"
#include "core/templates/local_vector.h"
-#include "editor/editor_node.h"
#include "scene/resources/packed_scene.h"
+#ifdef TOOLS_ENABLED
+#include "editor/editor_node.h"
+#endif // TOOLS_ENABLED
+
bool PropertyUtils::is_property_value_different(const Variant &p_a, const Variant &p_b) {
if (p_a.get_type() == Variant::FLOAT && p_b.get_type() == Variant::FLOAT) {
//this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index e4e4f682e5..056ace5e4e 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -629,6 +629,7 @@ void register_scene_types() {
GDREGISTER_CLASS(VisualShaderNodeParticleSphereEmitter);
GDREGISTER_CLASS(VisualShaderNodeParticleBoxEmitter);
GDREGISTER_CLASS(VisualShaderNodeParticleRingEmitter);
+ GDREGISTER_CLASS(VisualShaderNodeParticleMeshEmitter);
GDREGISTER_CLASS(VisualShaderNodeParticleMultiplyByAxisAngle);
GDREGISTER_CLASS(VisualShaderNodeParticleConeVelocity);
GDREGISTER_CLASS(VisualShaderNodeParticleRandomness);
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index 71d2774335..3700e87839 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -449,8 +449,8 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
return true;
} else if (name == "length") {
r_ret = length;
- } else if (name == "loop") {
- r_ret = loop;
+ } else if (name == "loop_mode") {
+ r_ret = loop_mode;
} else if (name == "step") {
r_ret = step;
} else if (name.begins_with("tracks/")) {
@@ -2231,7 +2231,7 @@ void Animation::track_set_key_transition(int p_track, int p_key_idx, real_t p_tr
}
template <class K>
-int Animation::_find(const Vector<K> &p_keys, double p_time) const {
+int Animation::_find(const Vector<K> &p_keys, double p_time, bool p_backward) const {
int len = p_keys.size();
if (len == 0) {
return -2;
@@ -2261,8 +2261,14 @@ int Animation::_find(const Vector<K> &p_keys, double p_time) const {
}
}
- if (keys[middle].time > p_time) {
- middle--;
+ if (!p_backward) {
+ if (keys[middle].time > p_time) {
+ middle--;
+ }
+ } else {
+ if (keys[middle].time < p_time) {
+ middle++;
+ }
}
return middle;
@@ -2385,7 +2391,7 @@ real_t Animation::_cubic_interpolate(const real_t &p_pre_a, const real_t &p_a, c
}
template <class T>
-T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const {
+T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok, bool p_backward) const {
int len = _find(p_keys, length) + 1; // try to find last key (there may be more past the end)
if (len <= 0) {
@@ -2403,7 +2409,7 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol
return p_keys[0].value;
}
- int idx = _find(p_keys, p_time);
+ int idx = _find(p_keys, p_time, p_backward);
ERR_FAIL_COND_V(idx == -2, T());
@@ -2412,24 +2418,42 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol
real_t c = 0.0;
// prepare for all cases of interpolation
- if (loop && p_loop_wrap) {
+ if ((loop_mode == LOOP_LINEAR || loop_mode == LOOP_PINGPONG) && p_loop_wrap) {
// loop
- if (idx >= 0) {
- if ((idx + 1) < len) {
- next = idx + 1;
- real_t delta = p_keys[next].time - p_keys[idx].time;
- real_t from = p_time - p_keys[idx].time;
-
- if (Math::is_zero_approx(delta)) {
- c = 0;
+ if (!p_backward) {
+ // no backward
+ if (idx >= 0) {
+ if (idx < len - 1) {
+ next = idx + 1;
+ real_t delta = p_keys[next].time - p_keys[idx].time;
+ real_t from = p_time - p_keys[idx].time;
+
+ if (Math::is_zero_approx(delta)) {
+ c = 0;
+ } else {
+ c = from / delta;
+ }
} else {
- c = from / delta;
- }
+ next = 0;
+ real_t delta = (length - p_keys[idx].time) + p_keys[next].time;
+ real_t from = p_time - p_keys[idx].time;
+ if (Math::is_zero_approx(delta)) {
+ c = 0;
+ } else {
+ c = from / delta;
+ }
+ }
} else {
+ // on loop, behind first key
+ idx = len - 1;
next = 0;
- real_t delta = (length - p_keys[idx].time) + p_keys[next].time;
- real_t from = p_time - p_keys[idx].time;
+ real_t endtime = (length - p_keys[idx].time);
+ if (endtime < 0) { // may be keys past the end
+ endtime = 0;
+ }
+ real_t delta = endtime + p_keys[next].time;
+ real_t from = endtime + p_time;
if (Math::is_zero_approx(delta)) {
c = 0;
@@ -2437,49 +2461,81 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol
c = from / delta;
}
}
-
} else {
- // on loop, behind first key
- idx = len - 1;
- next = 0;
- real_t endtime = (length - p_keys[idx].time);
- if (endtime < 0) { // may be keys past the end
- endtime = 0;
- }
- real_t delta = endtime + p_keys[next].time;
- real_t from = endtime + p_time;
-
- if (Math::is_zero_approx(delta)) {
- c = 0;
+ // backward
+ if (idx <= len - 1) {
+ if (idx > 0) {
+ next = idx - 1;
+ real_t delta = (length - p_keys[next].time) - (length - p_keys[idx].time);
+ real_t from = (length - p_time) - (length - p_keys[idx].time);
+
+ if (Math::is_zero_approx(delta))
+ c = 0;
+ else
+ c = from / delta;
+ } else {
+ next = len - 1;
+ real_t delta = p_keys[idx].time + (length - p_keys[next].time);
+ real_t from = (length - p_time) - (length - p_keys[idx].time);
+
+ if (Math::is_zero_approx(delta))
+ c = 0;
+ else
+ c = from / delta;
+ }
} else {
- c = from / delta;
+ // on loop, in front of last key
+ idx = 0;
+ next = len - 1;
+ real_t endtime = p_keys[idx].time;
+ if (endtime > length) // may be keys past the end
+ endtime = length;
+ real_t delta = p_keys[next].time - endtime;
+ real_t from = p_time - endtime;
+
+ if (Math::is_zero_approx(delta))
+ c = 0;
+ else
+ c = from / delta;
}
}
-
} else { // no loop
-
- if (idx >= 0) {
- if ((idx + 1) < len) {
- next = idx + 1;
- real_t delta = p_keys[next].time - p_keys[idx].time;
- real_t from = p_time - p_keys[idx].time;
-
- if (Math::is_zero_approx(delta)) {
- c = 0;
+ if (!p_backward) {
+ if (idx >= 0) {
+ if (idx < len - 1) {
+ next = idx + 1;
+ real_t delta = p_keys[next].time - p_keys[idx].time;
+ real_t from = p_time - p_keys[idx].time;
+
+ if (Math::is_zero_approx(delta)) {
+ c = 0;
+ } else {
+ c = from / delta;
+ }
} else {
- c = from / delta;
+ next = idx;
}
-
} else {
- next = idx;
+ idx = next = 0;
}
-
} else {
- // only allow extending first key to anim start if looping
- if (loop) {
- idx = next = 0;
+ if (idx <= len - 1) {
+ if (idx > 0) {
+ next = idx - 1;
+ real_t delta = (length - p_keys[next].time) - (length - p_keys[idx].time);
+ real_t from = (length - p_time) - (length - p_keys[idx].time);
+
+ if (Math::is_zero_approx(delta)) {
+ c = 0;
+ } else {
+ c = from / delta;
+ }
+
+ } else {
+ next = idx;
+ }
} else {
- result = false;
+ idx = next = len - 1;
}
}
}
@@ -2583,7 +2639,7 @@ void Animation::_value_track_get_key_indices_in_range(const ValueTrack *vt, doub
}
}
-void Animation::value_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices) const {
+void Animation::value_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged) const {
ERR_FAIL_INDEX(p_track, tracks.size());
Track *t = tracks[p_track];
ERR_FAIL_COND(t->type != TYPE_VALUE);
@@ -2597,30 +2653,50 @@ void Animation::value_track_get_key_indices(int p_track, double p_time, double p
SWAP(from_time, to_time);
}
- if (loop) {
- from_time = Math::fposmod(from_time, length);
- to_time = Math::fposmod(to_time, length);
+ switch (loop_mode) {
+ case LOOP_NONE: {
+ if (from_time < 0) {
+ from_time = 0;
+ }
+ if (from_time > length) {
+ from_time = length;
+ }
- if (from_time > to_time) {
- // handle loop by splitting
- _value_track_get_key_indices_in_range(vt, from_time, length, p_indices);
- _value_track_get_key_indices_in_range(vt, 0, to_time, p_indices);
- return;
- }
- } else {
- if (from_time < 0) {
- from_time = 0;
- }
- if (from_time > length) {
- from_time = length;
- }
+ if (to_time < 0) {
+ to_time = 0;
+ }
+ if (to_time > length) {
+ to_time = length;
+ }
+ } break;
+ case LOOP_LINEAR: {
+ from_time = Math::fposmod(from_time, length);
+ to_time = Math::fposmod(to_time, length);
- if (to_time < 0) {
- to_time = 0;
- }
- if (to_time > length) {
- to_time = length;
- }
+ if (from_time > to_time) {
+ // handle loop by splitting
+ _value_track_get_key_indices_in_range(vt, from_time, length, p_indices);
+ _value_track_get_key_indices_in_range(vt, 0, to_time, p_indices);
+ return;
+ }
+ } break;
+ case LOOP_PINGPONG: {
+ from_time = Math::pingpong(from_time, length);
+ to_time = Math::pingpong(to_time, length);
+
+ if (p_pingponged == -1) {
+ // handle loop by splitting
+ _value_track_get_key_indices_in_range(vt, 0, from_time, p_indices);
+ _value_track_get_key_indices_in_range(vt, 0, to_time, p_indices);
+ return;
+ }
+ if (p_pingponged == 1) {
+ // handle loop by splitting
+ _value_track_get_key_indices_in_range(vt, from_time, length, p_indices);
+ _value_track_get_key_indices_in_range(vt, to_time, length, p_indices);
+ return;
+ }
+ } break;
}
_value_track_get_key_indices_in_range(vt, from_time, to_time, p_indices);
@@ -2679,7 +2755,7 @@ void Animation::_track_get_key_indices_in_range(const Vector<T> &p_array, double
}
}
-void Animation::track_get_key_indices_in_range(int p_track, double p_time, double p_delta, List<int> *p_indices) const {
+void Animation::track_get_key_indices_in_range(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged) const {
ERR_FAIL_INDEX(p_track, tracks.size());
const Track *t = tracks[p_track];
@@ -2690,114 +2766,255 @@ void Animation::track_get_key_indices_in_range(int p_track, double p_time, doubl
SWAP(from_time, to_time);
}
- if (loop) {
- if (from_time > length || from_time < 0) {
- from_time = Math::fposmod(from_time, length);
- }
-
- if (to_time > length || to_time < 0) {
- to_time = Math::fposmod(to_time, length);
- }
-
- if (from_time > to_time) {
- // handle loop by splitting
-
- switch (t->type) {
- case TYPE_POSITION_3D: {
- const PositionTrack *tt = static_cast<const PositionTrack *>(t);
- if (tt->compressed_track >= 0) {
- _get_compressed_key_indices_in_range<3>(tt->compressed_track, from_time, length, p_indices);
- _get_compressed_key_indices_in_range<3>(tt->compressed_track, 0, to_time, p_indices);
-
- } else {
- _track_get_key_indices_in_range(tt->positions, from_time, length, p_indices);
- _track_get_key_indices_in_range(tt->positions, 0, to_time, p_indices);
- }
-
- } break;
- case TYPE_ROTATION_3D: {
- const RotationTrack *rt = static_cast<const RotationTrack *>(t);
- if (rt->compressed_track >= 0) {
- _get_compressed_key_indices_in_range<3>(rt->compressed_track, from_time, length, p_indices);
- _get_compressed_key_indices_in_range<3>(rt->compressed_track, 0, to_time, p_indices);
+ switch (loop_mode) {
+ case LOOP_NONE: {
+ if (from_time < 0) {
+ from_time = 0;
+ }
+ if (from_time > length) {
+ from_time = length;
+ }
- } else {
- _track_get_key_indices_in_range(rt->rotations, from_time, length, p_indices);
- _track_get_key_indices_in_range(rt->rotations, 0, to_time, p_indices);
- }
+ if (to_time < 0) {
+ to_time = 0;
+ }
+ if (to_time > length) {
+ to_time = length;
+ }
+ } break;
+ case LOOP_LINEAR: {
+ if (from_time > length || from_time < 0) {
+ from_time = Math::fposmod(from_time, length);
+ }
+ if (to_time > length || to_time < 0) {
+ to_time = Math::fposmod(to_time, length);
+ }
- } break;
- case TYPE_SCALE_3D: {
- const ScaleTrack *st = static_cast<const ScaleTrack *>(t);
- if (st->compressed_track >= 0) {
- _get_compressed_key_indices_in_range<3>(st->compressed_track, from_time, length, p_indices);
- _get_compressed_key_indices_in_range<3>(st->compressed_track, 0, to_time, p_indices);
+ if (from_time > to_time) {
+ // handle loop by splitting
+ switch (t->type) {
+ case TYPE_POSITION_3D: {
+ const PositionTrack *tt = static_cast<const PositionTrack *>(t);
+ if (tt->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(tt->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<3>(tt->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(tt->positions, from_time, length, p_indices);
+ _track_get_key_indices_in_range(tt->positions, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_ROTATION_3D: {
+ const RotationTrack *rt = static_cast<const RotationTrack *>(t);
+ if (rt->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(rt->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<3>(rt->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(rt->rotations, from_time, length, p_indices);
+ _track_get_key_indices_in_range(rt->rotations, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_SCALE_3D: {
+ const ScaleTrack *st = static_cast<const ScaleTrack *>(t);
+ if (st->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(st->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<3>(st->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(st->scales, from_time, length, p_indices);
+ _track_get_key_indices_in_range(st->scales, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_BLEND_SHAPE: {
+ const BlendShapeTrack *bst = static_cast<const BlendShapeTrack *>(t);
+ if (bst->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<1>(bst->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<1>(bst->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(bst->blend_shapes, from_time, length, p_indices);
+ _track_get_key_indices_in_range(bst->blend_shapes, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_VALUE: {
+ const ValueTrack *vt = static_cast<const ValueTrack *>(t);
+ _track_get_key_indices_in_range(vt->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(vt->values, 0, to_time, p_indices);
+ } break;
+ case TYPE_METHOD: {
+ const MethodTrack *mt = static_cast<const MethodTrack *>(t);
+ _track_get_key_indices_in_range(mt->methods, from_time, length, p_indices);
+ _track_get_key_indices_in_range(mt->methods, 0, to_time, p_indices);
+ } break;
+ case TYPE_BEZIER: {
+ const BezierTrack *bz = static_cast<const BezierTrack *>(t);
+ _track_get_key_indices_in_range(bz->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(bz->values, 0, to_time, p_indices);
+ } break;
+ case TYPE_AUDIO: {
+ const AudioTrack *ad = static_cast<const AudioTrack *>(t);
+ _track_get_key_indices_in_range(ad->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(ad->values, 0, to_time, p_indices);
+ } break;
+ case TYPE_ANIMATION: {
+ const AnimationTrack *an = static_cast<const AnimationTrack *>(t);
+ _track_get_key_indices_in_range(an->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(an->values, 0, to_time, p_indices);
+ } break;
+ }
+ return;
+ }
+ } break;
+ case LOOP_PINGPONG: {
+ if (from_time > length || from_time < 0) {
+ from_time = Math::pingpong(from_time, length);
+ }
+ if (to_time > length || to_time < 0) {
+ to_time = Math::pingpong(to_time, length);
+ }
- } else {
- _track_get_key_indices_in_range(st->scales, from_time, length, p_indices);
- _track_get_key_indices_in_range(st->scales, 0, to_time, p_indices);
+ if ((int)Math::floor(abs(p_delta) / length) % 2 == 0) {
+ if (p_pingponged == -1) {
+ // handle loop by splitting
+ switch (t->type) {
+ case TYPE_POSITION_3D: {
+ const PositionTrack *tt = static_cast<const PositionTrack *>(t);
+ if (tt->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(tt->compressed_track, 0, from_time, p_indices);
+ _get_compressed_key_indices_in_range<3>(tt->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(tt->positions, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(tt->positions, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_ROTATION_3D: {
+ const RotationTrack *rt = static_cast<const RotationTrack *>(t);
+ if (rt->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(rt->compressed_track, 0, from_time, p_indices);
+ _get_compressed_key_indices_in_range<3>(rt->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(rt->rotations, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(rt->rotations, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_SCALE_3D: {
+ const ScaleTrack *st = static_cast<const ScaleTrack *>(t);
+ if (st->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(st->compressed_track, 0, from_time, p_indices);
+ _get_compressed_key_indices_in_range<3>(st->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(st->scales, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(st->scales, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_BLEND_SHAPE: {
+ const BlendShapeTrack *bst = static_cast<const BlendShapeTrack *>(t);
+ if (bst->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<1>(bst->compressed_track, 0, from_time, p_indices);
+ _get_compressed_key_indices_in_range<1>(bst->compressed_track, 0, to_time, p_indices);
+ } else {
+ _track_get_key_indices_in_range(bst->blend_shapes, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(bst->blend_shapes, 0, to_time, p_indices);
+ }
+ } break;
+ case TYPE_VALUE: {
+ const ValueTrack *vt = static_cast<const ValueTrack *>(t);
+ _track_get_key_indices_in_range(vt->values, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(vt->values, 0, to_time, p_indices);
+ } break;
+ case TYPE_METHOD: {
+ const MethodTrack *mt = static_cast<const MethodTrack *>(t);
+ _track_get_key_indices_in_range(mt->methods, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(mt->methods, 0, to_time, p_indices);
+ } break;
+ case TYPE_BEZIER: {
+ const BezierTrack *bz = static_cast<const BezierTrack *>(t);
+ _track_get_key_indices_in_range(bz->values, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(bz->values, 0, to_time, p_indices);
+ } break;
+ case TYPE_AUDIO: {
+ const AudioTrack *ad = static_cast<const AudioTrack *>(t);
+ _track_get_key_indices_in_range(ad->values, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(ad->values, 0, to_time, p_indices);
+ } break;
+ case TYPE_ANIMATION: {
+ const AnimationTrack *an = static_cast<const AnimationTrack *>(t);
+ _track_get_key_indices_in_range(an->values, 0, from_time, p_indices);
+ _track_get_key_indices_in_range(an->values, 0, to_time, p_indices);
+ } break;
}
-
- } break;
- case TYPE_BLEND_SHAPE: {
- const BlendShapeTrack *bst = static_cast<const BlendShapeTrack *>(t);
- if (bst->compressed_track >= 0) {
- _get_compressed_key_indices_in_range<1>(bst->compressed_track, from_time, length, p_indices);
- _get_compressed_key_indices_in_range<1>(bst->compressed_track, 0, to_time, p_indices);
-
- } else {
- _track_get_key_indices_in_range(bst->blend_shapes, from_time, length, p_indices);
- _track_get_key_indices_in_range(bst->blend_shapes, 0, to_time, p_indices);
+ return;
+ }
+ if (p_pingponged == 1) {
+ // handle loop by splitting
+ switch (t->type) {
+ case TYPE_POSITION_3D: {
+ const PositionTrack *tt = static_cast<const PositionTrack *>(t);
+ if (tt->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(tt->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<3>(tt->compressed_track, to_time, length, p_indices);
+ } else {
+ _track_get_key_indices_in_range(tt->positions, from_time, length, p_indices);
+ _track_get_key_indices_in_range(tt->positions, to_time, length, p_indices);
+ }
+ } break;
+ case TYPE_ROTATION_3D: {
+ const RotationTrack *rt = static_cast<const RotationTrack *>(t);
+ if (rt->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(rt->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<3>(rt->compressed_track, to_time, length, p_indices);
+ } else {
+ _track_get_key_indices_in_range(rt->rotations, from_time, length, p_indices);
+ _track_get_key_indices_in_range(rt->rotations, to_time, length, p_indices);
+ }
+ } break;
+ case TYPE_SCALE_3D: {
+ const ScaleTrack *st = static_cast<const ScaleTrack *>(t);
+ if (st->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<3>(st->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<3>(st->compressed_track, to_time, length, p_indices);
+ } else {
+ _track_get_key_indices_in_range(st->scales, from_time, length, p_indices);
+ _track_get_key_indices_in_range(st->scales, to_time, length, p_indices);
+ }
+ } break;
+ case TYPE_BLEND_SHAPE: {
+ const BlendShapeTrack *bst = static_cast<const BlendShapeTrack *>(t);
+ if (bst->compressed_track >= 0) {
+ _get_compressed_key_indices_in_range<1>(bst->compressed_track, from_time, length, p_indices);
+ _get_compressed_key_indices_in_range<1>(bst->compressed_track, to_time, length, p_indices);
+ } else {
+ _track_get_key_indices_in_range(bst->blend_shapes, from_time, length, p_indices);
+ _track_get_key_indices_in_range(bst->blend_shapes, to_time, length, p_indices);
+ }
+ } break;
+ case TYPE_VALUE: {
+ const ValueTrack *vt = static_cast<const ValueTrack *>(t);
+ _track_get_key_indices_in_range(vt->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(vt->values, to_time, length, p_indices);
+ } break;
+ case TYPE_METHOD: {
+ const MethodTrack *mt = static_cast<const MethodTrack *>(t);
+ _track_get_key_indices_in_range(mt->methods, from_time, length, p_indices);
+ _track_get_key_indices_in_range(mt->methods, to_time, length, p_indices);
+ } break;
+ case TYPE_BEZIER: {
+ const BezierTrack *bz = static_cast<const BezierTrack *>(t);
+ _track_get_key_indices_in_range(bz->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(bz->values, to_time, length, p_indices);
+ } break;
+ case TYPE_AUDIO: {
+ const AudioTrack *ad = static_cast<const AudioTrack *>(t);
+ _track_get_key_indices_in_range(ad->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(ad->values, to_time, length, p_indices);
+ } break;
+ case TYPE_ANIMATION: {
+ const AnimationTrack *an = static_cast<const AnimationTrack *>(t);
+ _track_get_key_indices_in_range(an->values, from_time, length, p_indices);
+ _track_get_key_indices_in_range(an->values, to_time, length, p_indices);
+ } break;
}
-
- } break;
- case TYPE_VALUE: {
- const ValueTrack *vt = static_cast<const ValueTrack *>(t);
- _track_get_key_indices_in_range(vt->values, from_time, length, p_indices);
- _track_get_key_indices_in_range(vt->values, 0, to_time, p_indices);
-
- } break;
- case TYPE_METHOD: {
- const MethodTrack *mt = static_cast<const MethodTrack *>(t);
- _track_get_key_indices_in_range(mt->methods, from_time, length, p_indices);
- _track_get_key_indices_in_range(mt->methods, 0, to_time, p_indices);
-
- } break;
- case TYPE_BEZIER: {
- const BezierTrack *bz = static_cast<const BezierTrack *>(t);
- _track_get_key_indices_in_range(bz->values, from_time, length, p_indices);
- _track_get_key_indices_in_range(bz->values, 0, to_time, p_indices);
-
- } break;
- case TYPE_AUDIO: {
- const AudioTrack *ad = static_cast<const AudioTrack *>(t);
- _track_get_key_indices_in_range(ad->values, from_time, length, p_indices);
- _track_get_key_indices_in_range(ad->values, 0, to_time, p_indices);
-
- } break;
- case TYPE_ANIMATION: {
- const AnimationTrack *an = static_cast<const AnimationTrack *>(t);
- _track_get_key_indices_in_range(an->values, from_time, length, p_indices);
- _track_get_key_indices_in_range(an->values, 0, to_time, p_indices);
-
- } break;
+ return;
+ }
}
- return;
- }
- } else {
- if (from_time < 0) {
- from_time = 0;
- }
- if (from_time > length) {
- from_time = length;
- }
-
- if (to_time < 0) {
- to_time = 0;
- }
- if (to_time > length) {
- to_time = length;
- }
+ } break;
}
switch (t->type) {
@@ -2808,7 +3025,6 @@ void Animation::track_get_key_indices_in_range(int p_track, double p_time, doubl
} else {
_track_get_key_indices_in_range(tt->positions, from_time, to_time, p_indices);
}
-
} break;
case TYPE_ROTATION_3D: {
const RotationTrack *rt = static_cast<const RotationTrack *>(t);
@@ -2817,7 +3033,6 @@ void Animation::track_get_key_indices_in_range(int p_track, double p_time, doubl
} else {
_track_get_key_indices_in_range(rt->rotations, from_time, to_time, p_indices);
}
-
} break;
case TYPE_SCALE_3D: {
const ScaleTrack *st = static_cast<const ScaleTrack *>(t);
@@ -2826,7 +3041,6 @@ void Animation::track_get_key_indices_in_range(int p_track, double p_time, doubl
} else {
_track_get_key_indices_in_range(st->scales, from_time, to_time, p_indices);
}
-
} break;
case TYPE_BLEND_SHAPE: {
const BlendShapeTrack *bst = static_cast<const BlendShapeTrack *>(t);
@@ -2835,32 +3049,26 @@ void Animation::track_get_key_indices_in_range(int p_track, double p_time, doubl
} else {
_track_get_key_indices_in_range(bst->blend_shapes, from_time, to_time, p_indices);
}
-
} break;
case TYPE_VALUE: {
const ValueTrack *vt = static_cast<const ValueTrack *>(t);
_track_get_key_indices_in_range(vt->values, from_time, to_time, p_indices);
-
} break;
case TYPE_METHOD: {
const MethodTrack *mt = static_cast<const MethodTrack *>(t);
_track_get_key_indices_in_range(mt->methods, from_time, to_time, p_indices);
-
} break;
case TYPE_BEZIER: {
const BezierTrack *bz = static_cast<const BezierTrack *>(t);
_track_get_key_indices_in_range(bz->values, from_time, to_time, p_indices);
-
} break;
case TYPE_AUDIO: {
const AudioTrack *ad = static_cast<const AudioTrack *>(t);
_track_get_key_indices_in_range(ad->values, from_time, to_time, p_indices);
-
} break;
case TYPE_ANIMATION: {
const AnimationTrack *an = static_cast<const AnimationTrack *>(t);
_track_get_key_indices_in_range(an->values, from_time, to_time, p_indices);
-
} break;
}
}
@@ -2898,7 +3106,7 @@ void Animation::_method_track_get_key_indices_in_range(const MethodTrack *mt, do
}
}
-void Animation::method_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices) const {
+void Animation::method_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged) const {
ERR_FAIL_INDEX(p_track, tracks.size());
Track *t = tracks[p_track];
ERR_FAIL_COND(t->type != TYPE_METHOD);
@@ -2912,35 +3120,58 @@ void Animation::method_track_get_key_indices(int p_track, double p_time, double
SWAP(from_time, to_time);
}
- if (loop) {
- if (from_time > length || from_time < 0) {
- from_time = Math::fposmod(from_time, length);
- }
+ switch (loop_mode) {
+ case LOOP_NONE: {
+ if (from_time < 0) {
+ from_time = 0;
+ }
+ if (from_time > length) {
+ from_time = length;
+ }
- if (to_time > length || to_time < 0) {
- to_time = Math::fposmod(to_time, length);
- }
+ if (to_time < 0) {
+ to_time = 0;
+ }
+ if (to_time > length) {
+ to_time = length;
+ }
+ } break;
+ case LOOP_LINEAR: {
+ if (from_time > length || from_time < 0) {
+ from_time = Math::fposmod(from_time, length);
+ }
+ if (to_time > length || to_time < 0) {
+ to_time = Math::fposmod(to_time, length);
+ }
- if (from_time > to_time) {
- // handle loop by splitting
- _method_track_get_key_indices_in_range(mt, from_time, length, p_indices);
- _method_track_get_key_indices_in_range(mt, 0, to_time, p_indices);
- return;
- }
- } else {
- if (from_time < 0) {
- from_time = 0;
- }
- if (from_time > length) {
- from_time = length;
- }
+ if (from_time > to_time) {
+ // handle loop by splitting
+ _method_track_get_key_indices_in_range(mt, from_time, length, p_indices);
+ _method_track_get_key_indices_in_range(mt, 0, to_time, p_indices);
+ return;
+ }
+ } break;
+ case LOOP_PINGPONG: {
+ if (from_time > length || from_time < 0) {
+ from_time = Math::pingpong(from_time, length);
+ }
+ if (to_time > length || to_time < 0) {
+ to_time = Math::pingpong(to_time, length);
+ }
- if (to_time < 0) {
- to_time = 0;
- }
- if (to_time > length) {
- to_time = length;
- }
+ if (p_pingponged == -1) {
+ _method_track_get_key_indices_in_range(mt, 0, from_time, p_indices);
+ _method_track_get_key_indices_in_range(mt, 0, to_time, p_indices);
+ return;
+ }
+ if (p_pingponged == 1) {
+ _method_track_get_key_indices_in_range(mt, from_time, length, p_indices);
+ _method_track_get_key_indices_in_range(mt, to_time, length, p_indices);
+ return;
+ }
+ } break;
+ default:
+ break;
}
_method_track_get_key_indices_in_range(mt, from_time, to_time, p_indices);
@@ -3326,13 +3557,13 @@ real_t Animation::get_length() const {
return length;
}
-void Animation::set_loop(bool p_enabled) {
- loop = p_enabled;
+void Animation::set_loop_mode(Animation::LoopMode p_loop_mode) {
+ loop_mode = p_loop_mode;
emit_changed();
}
-bool Animation::has_loop() const {
- return loop;
+Animation::LoopMode Animation::get_loop_mode() const {
+ return loop_mode;
}
void Animation::track_set_imported(int p_track, bool p_imported) {
@@ -3514,8 +3745,8 @@ void Animation::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_length", "time_sec"), &Animation::set_length);
ClassDB::bind_method(D_METHOD("get_length"), &Animation::get_length);
- ClassDB::bind_method(D_METHOD("set_loop", "enabled"), &Animation::set_loop);
- ClassDB::bind_method(D_METHOD("has_loop"), &Animation::has_loop);
+ ClassDB::bind_method(D_METHOD("set_loop_mode", "loop_mode"), &Animation::set_loop_mode);
+ ClassDB::bind_method(D_METHOD("get_loop_mode"), &Animation::get_loop_mode);
ClassDB::bind_method(D_METHOD("set_step", "size_sec"), &Animation::set_step);
ClassDB::bind_method(D_METHOD("get_step"), &Animation::get_step);
@@ -3526,7 +3757,7 @@ void Animation::_bind_methods() {
ClassDB::bind_method(D_METHOD("compress", "page_size", "fps", "split_tolerance"), &Animation::compress, DEFVAL(8192), DEFVAL(120), DEFVAL(4.0));
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "0.001,99999,0.001"), "set_length", "get_length");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "has_loop");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "loop_mode"), "set_loop_mode", "get_loop_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "step", PROPERTY_HINT_RANGE, "0,4096,0.001"), "set_step", "get_step");
ADD_SIGNAL(MethodInfo("tracks_changed"));
@@ -3549,6 +3780,10 @@ void Animation::_bind_methods() {
BIND_ENUM_CONSTANT(UPDATE_DISCRETE);
BIND_ENUM_CONSTANT(UPDATE_TRIGGER);
BIND_ENUM_CONSTANT(UPDATE_CAPTURE);
+
+ BIND_ENUM_CONSTANT(LOOP_NONE);
+ BIND_ENUM_CONSTANT(LOOP_LINEAR);
+ BIND_ENUM_CONSTANT(LOOP_PINGPONG);
}
void Animation::clear() {
@@ -3556,7 +3791,7 @@ void Animation::clear() {
memdelete(tracks[i]);
}
tracks.clear();
- loop = false;
+ loop_mode = LOOP_NONE;
length = 1;
compression.enabled = false;
compression.bounds.clear();
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index ee07fb19d3..510d6c8323 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -64,7 +64,12 @@ public:
UPDATE_DISCRETE,
UPDATE_TRIGGER,
UPDATE_CAPTURE,
+ };
+ enum LoopMode {
+ LOOP_NONE,
+ LOOP_LINEAR,
+ LOOP_PINGPONG,
};
private:
@@ -208,7 +213,8 @@ private:
int _insert(double p_time, T &p_keys, const V &p_value);
template <class K>
- inline int _find(const Vector<K> &p_keys, double p_time) const;
+
+ inline int _find(const Vector<K> &p_keys, double p_time, bool p_backward = false) const;
_FORCE_INLINE_ Vector3 _interpolate(const Vector3 &p_a, const Vector3 &p_b, real_t p_c) const;
_FORCE_INLINE_ Quaternion _interpolate(const Quaternion &p_a, const Quaternion &p_b, real_t p_c) const;
@@ -221,7 +227,7 @@ private:
_FORCE_INLINE_ real_t _cubic_interpolate(const real_t &p_pre_a, const real_t &p_a, const real_t &p_b, const real_t &p_post_b, real_t p_c) const;
template <class T>
- _FORCE_INLINE_ T _interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const;
+ _FORCE_INLINE_ T _interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok, bool p_backward = false) const;
template <class T>
_FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector<T> &p_array, double from_time, double to_time, List<int> *p_indices) const;
@@ -231,7 +237,8 @@ private:
double length = 1.0;
real_t step = 0.1;
- bool loop = false;
+ LoopMode loop_mode = LOOP_NONE;
+ int pingponged = 0;
/* Animation compression page format (version 1):
*
@@ -438,23 +445,23 @@ public:
bool track_get_interpolation_loop_wrap(int p_track) const;
Variant value_track_interpolate(int p_track, double p_time) const;
- void value_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices) const;
+ void value_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged = 0) const;
void value_track_set_update_mode(int p_track, UpdateMode p_mode);
UpdateMode value_track_get_update_mode(int p_track) const;
- void method_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices) const;
+ void method_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged = 0) const;
Vector<Variant> method_track_get_params(int p_track, int p_key_idx) const;
StringName method_track_get_name(int p_track, int p_key_idx) const;
void copy_track(int p_track, Ref<Animation> p_to_animation);
- void track_get_key_indices_in_range(int p_track, double p_time, double p_delta, List<int> *p_indices) const;
+ void track_get_key_indices_in_range(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged = 0) const;
void set_length(real_t p_length);
real_t get_length() const;
- void set_loop(bool p_enabled);
- bool has_loop() const;
+ void set_loop_mode(LoopMode p_loop_mode);
+ LoopMode get_loop_mode() const;
void set_step(real_t p_step);
real_t get_step() const;
@@ -471,5 +478,6 @@ public:
VARIANT_ENUM_CAST(Animation::TrackType);
VARIANT_ENUM_CAST(Animation::InterpolationType);
VARIANT_ENUM_CAST(Animation::UpdateMode);
+VARIANT_ENUM_CAST(Animation::LoopMode);
#endif
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index 5cfc4a9d40..d3fab802c5 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -299,7 +299,7 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
if (loop_format != AudioStreamSample::LOOP_DISABLED && offset < loop_begin_fp) {
/* loopstart reached */
- if (loop_format == AudioStreamSample::LOOP_PING_PONG) {
+ if (loop_format == AudioStreamSample::LOOP_PINGPONG) {
/* bounce ping pong */
offset = loop_begin_fp + (loop_begin_fp - offset);
increment = -increment;
@@ -320,7 +320,7 @@ int AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int
if (loop_format != AudioStreamSample::LOOP_DISABLED && offset >= loop_end_fp) {
/* loopend reached */
- if (loop_format == AudioStreamSample::LOOP_PING_PONG) {
+ if (loop_format == AudioStreamSample::LOOP_PINGPONG) {
/* bounce ping pong */
offset = loop_end_fp - (offset - loop_end_fp);
increment = -increment;
@@ -650,7 +650,7 @@ void AudioStreamSample::_bind_methods() {
BIND_ENUM_CONSTANT(LOOP_DISABLED);
BIND_ENUM_CONSTANT(LOOP_FORWARD);
- BIND_ENUM_CONSTANT(LOOP_PING_PONG);
+ BIND_ENUM_CONSTANT(LOOP_PINGPONG);
BIND_ENUM_CONSTANT(LOOP_BACKWARD);
}
diff --git a/scene/resources/audio_stream_sample.h b/scene/resources/audio_stream_sample.h
index 24198e3c98..0eb34be9bf 100644
--- a/scene/resources/audio_stream_sample.h
+++ b/scene/resources/audio_stream_sample.h
@@ -92,7 +92,7 @@ public:
enum LoopMode {
LOOP_DISABLED,
LOOP_FORWARD,
- LOOP_PING_PONG,
+ LOOP_PINGPONG,
LOOP_BACKWARD
};
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index 9fab5791d6..84fa07e4f4 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -97,28 +97,36 @@ RID Shader::get_rid() const {
return shader;
}
-void Shader::set_default_texture_param(const StringName &p_param, const Ref<Texture2D> &p_texture) {
+void Shader::set_default_texture_param(const StringName &p_param, const Ref<Texture2D> &p_texture, int p_index) {
if (p_texture.is_valid()) {
- default_textures[p_param] = p_texture;
- RS::get_singleton()->shader_set_default_texture_param(shader, p_param, p_texture->get_rid());
+ if (!default_textures.has(p_param)) {
+ default_textures[p_param] = Map<int, Ref<Texture2D>>();
+ }
+ default_textures[p_param][p_index] = p_texture;
+ RS::get_singleton()->shader_set_default_texture_param(shader, p_param, p_texture->get_rid(), p_index);
} else {
- default_textures.erase(p_param);
- RS::get_singleton()->shader_set_default_texture_param(shader, p_param, RID());
+ if (default_textures.has(p_param) && default_textures[p_param].has(p_index)) {
+ default_textures[p_param].erase(p_index);
+
+ if (default_textures[p_param].is_empty()) {
+ default_textures.erase(p_param);
+ }
+ }
+ RS::get_singleton()->shader_set_default_texture_param(shader, p_param, RID(), p_index);
}
emit_changed();
}
-Ref<Texture2D> Shader::get_default_texture_param(const StringName &p_param) const {
- if (default_textures.has(p_param)) {
- return default_textures[p_param];
- } else {
- return Ref<Texture2D>();
+Ref<Texture2D> Shader::get_default_texture_param(const StringName &p_param, int p_index) const {
+ if (default_textures.has(p_param) && default_textures[p_param].has(p_index)) {
+ return default_textures[p_param][p_index];
}
+ return Ref<Texture2D>();
}
void Shader::get_default_texture_param_list(List<StringName> *r_textures) const {
- for (const KeyValue<StringName, Ref<Texture2D>> &E : default_textures) {
+ for (const KeyValue<StringName, Map<int, Ref<Texture2D>>> &E : default_textures) {
r_textures->push_back(E.key);
}
}
@@ -140,8 +148,8 @@ void Shader::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_code", "code"), &Shader::set_code);
ClassDB::bind_method(D_METHOD("get_code"), &Shader::get_code);
- ClassDB::bind_method(D_METHOD("set_default_texture_param", "param", "texture"), &Shader::set_default_texture_param);
- ClassDB::bind_method(D_METHOD("get_default_texture_param", "param"), &Shader::get_default_texture_param);
+ ClassDB::bind_method(D_METHOD("set_default_texture_param", "param", "texture", "index"), &Shader::set_default_texture_param, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_default_texture_param", "param", "index"), &Shader::get_default_texture_param, DEFVAL(0));
ClassDB::bind_method(D_METHOD("has_param", "name"), &Shader::has_param);
diff --git a/scene/resources/shader.h b/scene/resources/shader.h
index c0dc07b403..c688dc1bab 100644
--- a/scene/resources/shader.h
+++ b/scene/resources/shader.h
@@ -59,7 +59,7 @@ private:
// conversion fast and save memory.
mutable bool params_cache_dirty = true;
mutable Map<StringName, StringName> params_cache; //map a shader param to a material param..
- Map<StringName, Ref<Texture2D>> default_textures;
+ Map<StringName, Map<int, Ref<Texture2D>>> default_textures;
virtual void _update_shader() const; //used for visual shader
protected:
@@ -75,8 +75,8 @@ public:
void get_param_list(List<PropertyInfo> *p_params) const;
bool has_param(const StringName &p_param) const;
- void set_default_texture_param(const StringName &p_param, const Ref<Texture2D> &p_texture);
- Ref<Texture2D> get_default_texture_param(const StringName &p_param) const;
+ void set_default_texture_param(const StringName &p_param, const Ref<Texture2D> &p_texture, int p_index = 0);
+ Ref<Texture2D> get_default_texture_param(const StringName &p_param, int p_index = 0) const;
void get_default_texture_param_list(List<StringName> *r_textures) const;
virtual bool is_text_shader() const;
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 5256803d56..8c92445338 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -3359,6 +3359,10 @@ void TileSetAtlasSource::set_tile_set(const TileSet *p_tile_set) {
}
}
+const TileSet *TileSetAtlasSource::get_tile_set() const {
+ return tile_set;
+}
+
void TileSetAtlasSource::notify_tile_data_properties_should_change() {
// Set the TileSet on all TileData.
for (KeyValue<Vector2i, TileAlternativesData> &E_tile : tiles) {
@@ -3522,9 +3526,18 @@ void TileSetAtlasSource::reset_state() {
}
void TileSetAtlasSource::set_texture(Ref<Texture2D> p_texture) {
+ if (texture.is_valid()) {
+ texture->disconnect(SNAME("changed"), callable_mp(this, &TileSetAtlasSource::_queue_update_padded_texture));
+ }
+
texture = p_texture;
+ if (texture.is_valid()) {
+ texture->connect(SNAME("changed"), callable_mp(this, &TileSetAtlasSource::_queue_update_padded_texture));
+ }
+
_clear_tiles_outside_texture();
+ _queue_update_padded_texture();
emit_changed();
}
@@ -3541,8 +3554,10 @@ void TileSetAtlasSource::set_margins(Vector2i p_margins) {
}
_clear_tiles_outside_texture();
+ _queue_update_padded_texture();
emit_changed();
}
+
Vector2i TileSetAtlasSource::get_margins() const {
return margins;
}
@@ -3556,8 +3571,10 @@ void TileSetAtlasSource::set_separation(Vector2i p_separation) {
}
_clear_tiles_outside_texture();
+ _queue_update_padded_texture();
emit_changed();
}
+
Vector2i TileSetAtlasSource::get_separation() const {
return separation;
}
@@ -3571,12 +3588,27 @@ void TileSetAtlasSource::set_texture_region_size(Vector2i p_tile_size) {
}
_clear_tiles_outside_texture();
+ _queue_update_padded_texture();
emit_changed();
}
+
Vector2i TileSetAtlasSource::get_texture_region_size() const {
return texture_region_size;
}
+void TileSetAtlasSource::set_use_texture_padding(bool p_use_padding) {
+ if (use_texture_padding == p_use_padding) {
+ return;
+ }
+ use_texture_padding = p_use_padding;
+ _queue_update_padded_texture();
+ emit_changed();
+}
+
+bool TileSetAtlasSource::get_use_texture_padding() const {
+ return use_texture_padding;
+}
+
Vector2i TileSetAtlasSource::get_atlas_grid_size() const {
Ref<Texture2D> texture = get_texture();
if (!texture.is_valid()) {
@@ -3835,6 +3867,7 @@ void TileSetAtlasSource::create_tile(const Vector2i p_atlas_coords, const Vector
tiles_ids.sort();
_create_coords_mapping_cache(p_atlas_coords);
+ _queue_update_padded_texture();
emit_signal(SNAME("changed"));
}
@@ -3855,6 +3888,8 @@ void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) {
tiles_ids.erase(p_atlas_coords);
tiles_ids.sort();
+ _queue_update_padded_texture();
+
emit_signal(SNAME("changed"));
}
@@ -3883,6 +3918,7 @@ void TileSetAtlasSource::set_tile_animation_columns(const Vector2i p_atlas_coord
tiles[p_atlas_coords].animation_columns = p_frame_columns;
_create_coords_mapping_cache(p_atlas_coords);
+ _queue_update_padded_texture();
emit_signal(SNAME("changed"));
}
@@ -3905,6 +3941,7 @@ void TileSetAtlasSource::set_tile_animation_separation(const Vector2i p_atlas_co
tiles[p_atlas_coords].animation_separation = p_separation;
_create_coords_mapping_cache(p_atlas_coords);
+ _queue_update_padded_texture();
emit_signal(SNAME("changed"));
}
@@ -3932,19 +3969,24 @@ void TileSetAtlasSource::set_tile_animation_frames_count(const Vector2i p_atlas_
ERR_FAIL_COND_MSG(!tiles.has(p_atlas_coords), vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords)));
ERR_FAIL_COND(p_frames_count < 1);
+ int old_size = tiles[p_atlas_coords].animation_frames_durations.size();
+ if (p_frames_count == old_size) {
+ return;
+ }
+
TileAlternativesData &tad = tiles[p_atlas_coords];
bool room_for_tile = has_room_for_tile(p_atlas_coords, tad.size_in_atlas, tad.animation_columns, tad.animation_separation, p_frames_count, p_atlas_coords);
ERR_FAIL_COND_MSG(!room_for_tile, "Cannot set animation columns count, tiles are already present in the space the tile would cover.");
_clear_coords_mapping_cache(p_atlas_coords);
- int old_size = tiles[p_atlas_coords].animation_frames_durations.size();
tiles[p_atlas_coords].animation_frames_durations.resize(p_frames_count);
for (int i = old_size; i < p_frames_count; i++) {
tiles[p_atlas_coords].animation_frames_durations[i] = 1.0;
}
_create_coords_mapping_cache(p_atlas_coords);
+ _queue_update_padded_texture();
notify_property_list_changed();
@@ -4083,6 +4125,31 @@ Vector2i TileSetAtlasSource::get_tile_effective_texture_offset(Vector2i p_atlas_
return effective_texture_offset;
}
+// Getters for texture and tile region (padded or not)
+Ref<Texture2D> TileSetAtlasSource::get_runtime_texture() const {
+ if (use_texture_padding) {
+ return padded_texture;
+ } else {
+ return texture;
+ }
+}
+
+Rect2i TileSetAtlasSource::get_runtime_tile_texture_region(Vector2i p_atlas_coords, int p_frame) const {
+ ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), Rect2i(), vformat("TileSetAtlasSource has no tile at %s.", String(p_atlas_coords)));
+ ERR_FAIL_INDEX_V(p_frame, (int)tiles[p_atlas_coords].animation_frames_durations.size(), Rect2i());
+
+ Rect2i src_rect = get_tile_texture_region(p_atlas_coords, p_frame);
+ if (use_texture_padding) {
+ const TileAlternativesData &tad = tiles[p_atlas_coords];
+ Vector2i frame_coords = p_atlas_coords + (tad.size_in_atlas + tad.animation_separation) * ((tad.animation_columns > 0) ? Vector2i(p_frame % tad.animation_columns, p_frame / tad.animation_columns) : Vector2i(p_frame, 0));
+ Vector2i base_pos = frame_coords * (texture_region_size + Vector2i(2, 2)) + Vector2i(1, 1);
+
+ return Rect2i(base_pos, src_rect.size);
+ } else {
+ return src_rect;
+ }
+}
+
void TileSetAtlasSource::move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_new_atlas_coords, Vector2i p_new_size) {
ERR_FAIL_COND_MSG(!tiles.has(p_atlas_coords), vformat("TileSetAtlasSource has no tile at %s.", String(p_atlas_coords)));
@@ -4113,6 +4180,7 @@ void TileSetAtlasSource::move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_
tiles[new_atlas_coords].size_in_atlas = new_size;
_create_coords_mapping_cache(new_atlas_coords);
+ _queue_update_padded_texture();
emit_signal(SNAME("changed"));
}
@@ -4204,11 +4272,14 @@ void TileSetAtlasSource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_separation"), &TileSetAtlasSource::get_separation);
ClassDB::bind_method(D_METHOD("set_texture_region_size", "texture_region_size"), &TileSetAtlasSource::set_texture_region_size);
ClassDB::bind_method(D_METHOD("get_texture_region_size"), &TileSetAtlasSource::get_texture_region_size);
+ ClassDB::bind_method(D_METHOD("set_use_texture_padding", "use_texture_padding"), &TileSetAtlasSource::set_use_texture_padding);
+ ClassDB::bind_method(D_METHOD("get_use_texture_padding"), &TileSetAtlasSource::get_use_texture_padding);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_NO_EDITOR), "set_texture", "get_texture");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "margins", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_margins", "get_margins");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "separation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_separation", "get_separation");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "texture_region_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_texture_region_size", "get_texture_region_size");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_texture_padding", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_use_texture_padding", "get_use_texture_padding");
// Base tiles
ClassDB::bind_method(D_METHOD("create_tile", "atlas_coords", "size"), &TileSetAtlasSource::create_tile, DEFVAL(Vector2i(1, 1)));
@@ -4243,6 +4314,11 @@ void TileSetAtlasSource::_bind_methods() {
// Helpers.
ClassDB::bind_method(D_METHOD("get_atlas_grid_size"), &TileSetAtlasSource::get_atlas_grid_size);
ClassDB::bind_method(D_METHOD("get_tile_texture_region", "atlas_coords", "frame"), &TileSetAtlasSource::get_tile_texture_region, DEFVAL(0));
+
+ // Getters for texture and tile region (padded or not)
+ ClassDB::bind_method(D_METHOD("_update_padded_texture"), &TileSetAtlasSource::_update_padded_texture);
+ ClassDB::bind_method(D_METHOD("get_runtime_texture"), &TileSetAtlasSource::get_runtime_texture);
+ ClassDB::bind_method(D_METHOD("get_runtime_tile_texture_region", "atlas_coords", "frame"), &TileSetAtlasSource::get_runtime_tile_texture_region);
}
TileSetAtlasSource::~TileSetAtlasSource() {
@@ -4329,6 +4405,69 @@ void TileSetAtlasSource::_clear_tiles_outside_texture() {
}
}
+void TileSetAtlasSource::_queue_update_padded_texture() {
+ padded_texture_needs_update = true;
+ call_deferred("_update_padded_texture");
+}
+
+void TileSetAtlasSource::_update_padded_texture() {
+ if (!padded_texture_needs_update) {
+ return;
+ }
+ padded_texture_needs_update = false;
+ padded_texture = Ref<ImageTexture>();
+
+ if (!texture.is_valid()) {
+ return;
+ }
+
+ if (!use_texture_padding) {
+ return;
+ }
+
+ Size2 size = get_atlas_grid_size() * (texture_region_size + Vector2i(2, 2));
+
+ Ref<Image> src = texture->get_image();
+
+ Ref<Image> image;
+ image.instantiate();
+ image->create(size.x, size.y, false, Image::FORMAT_RGBA8);
+
+ for (KeyValue<Vector2i, TileAlternativesData> kv : tiles) {
+ for (int frame = 0; frame < (int)kv.value.animation_frames_durations.size(); frame++) {
+ // Compute the source rects.
+ Rect2i src_rect = get_tile_texture_region(kv.key, frame);
+
+ Rect2i top_src_rect = Rect2i(src_rect.position, Vector2i(src_rect.size.x, 1));
+ Rect2i bottom_src_rect = Rect2i(src_rect.position + Vector2i(0, src_rect.size.y - 1), Vector2i(src_rect.size.x, 1));
+ Rect2i left_src_rect = Rect2i(src_rect.position, Vector2i(1, src_rect.size.y));
+ Rect2i right_src_rect = Rect2i(src_rect.position + Vector2i(src_rect.size.x - 1, 0), Vector2i(1, src_rect.size.y));
+
+ // Copy the tile and the paddings.
+ Vector2i frame_coords = kv.key + (kv.value.size_in_atlas + kv.value.animation_separation) * ((kv.value.animation_columns > 0) ? Vector2i(frame % kv.value.animation_columns, frame / kv.value.animation_columns) : Vector2i(frame, 0));
+ Vector2i base_pos = frame_coords * (texture_region_size + Vector2i(2, 2)) + Vector2i(1, 1);
+
+ image->blit_rect(*src, src_rect, base_pos);
+
+ image->blit_rect(*src, top_src_rect, base_pos + Vector2i(0, -1));
+ image->blit_rect(*src, bottom_src_rect, base_pos + Vector2i(0, src_rect.size.y));
+ image->blit_rect(*src, left_src_rect, base_pos + Vector2i(-1, 0));
+ image->blit_rect(*src, right_src_rect, base_pos + Vector2i(src_rect.size.x, 0));
+
+ image->set_pixelv(base_pos + Vector2i(-1, -1), src->get_pixelv(src_rect.position));
+ image->set_pixelv(base_pos + Vector2i(src_rect.size.x, -1), src->get_pixelv(src_rect.position + Vector2i(src_rect.size.x - 1, 0)));
+ image->set_pixelv(base_pos + Vector2i(-1, src_rect.size.y), src->get_pixelv(src_rect.position + Vector2i(0, src_rect.size.y - 1)));
+ image->set_pixelv(base_pos + Vector2i(src_rect.size.x, src_rect.size.y), src->get_pixelv(src_rect.position + Vector2i(src_rect.size.x - 1, src_rect.size.y - 1)));
+ }
+ }
+
+ if (!padded_texture.is_valid()) {
+ padded_texture.instantiate();
+ }
+ padded_texture->create_from_image(image);
+ emit_changed();
+}
+
/////////////////////////////// TileSetScenesCollectionSource //////////////////////////////////////
void TileSetScenesCollectionSource::_compute_next_alternative_id() {
@@ -4858,6 +4997,9 @@ real_t TileData::get_constant_angular_velocity(int p_layer_id) const {
void TileData::set_collision_polygons_count(int p_layer_id, int p_polygons_count) {
ERR_FAIL_INDEX(p_layer_id, physics.size());
ERR_FAIL_COND(p_polygons_count < 0);
+ if (p_polygons_count == physics.write[p_layer_id].polygons.size()) {
+ return;
+ }
physics.write[p_layer_id].polygons.resize(p_polygons_count);
notify_property_list_changed();
emit_signal(SNAME("changed"));
@@ -5063,9 +5205,6 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
ERR_FAIL_COND_V(layer_index < 0, false);
if (components[1] == "polygon") {
Ref<OccluderPolygon2D> polygon = p_value;
- if (!polygon.is_valid()) {
- return false;
- }
if (layer_index >= occluders.size()) {
if (tile_set) {
@@ -5137,9 +5276,6 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
ERR_FAIL_COND_V(layer_index < 0, false);
if (components[1] == "polygon") {
Ref<NavigationPolygon> polygon = p_value;
- if (!polygon.is_valid()) {
- return false;
- }
if (layer_index >= navigation.size()) {
if (tile_set) {
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index 71559074e7..d2238c26d2 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -603,6 +603,12 @@ private:
void _clear_tiles_outside_texture();
+ bool use_texture_padding = true;
+ Ref<ImageTexture> padded_texture;
+ bool padded_texture_needs_update = false;
+ void _queue_update_padded_texture();
+ void _update_padded_texture();
+
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
@@ -613,6 +619,7 @@ protected:
public:
// Not exposed.
virtual void set_tile_set(const TileSet *p_tile_set) override;
+ const TileSet *get_tile_set() const;
virtual void notify_tile_data_properties_should_change() override;
virtual void add_occlusion_layer(int p_index) override;
virtual void move_occlusion_layer(int p_from_index, int p_to_pos) override;
@@ -644,6 +651,10 @@ public:
void set_texture_region_size(Vector2i p_tile_size);
Vector2i get_texture_region_size() const;
+ // Padding.
+ void set_use_texture_padding(bool p_use_padding);
+ bool get_use_texture_padding() const;
+
// Base tiles.
void create_tile(const Vector2i p_atlas_coords, const Vector2i p_size = Vector2i(1, 1));
void remove_tile(Vector2i p_atlas_coords);
@@ -689,6 +700,10 @@ public:
Rect2i get_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const;
Vector2i get_tile_effective_texture_offset(Vector2i p_atlas_coords, int p_alternative_tile) const;
+ // Getters for texture and tile region (padded or not)
+ Ref<Texture2D> get_runtime_texture() const;
+ Rect2i get_runtime_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const;
+
~TileSetAtlasSource();
};
@@ -766,7 +781,7 @@ private:
};
Vector2 linear_velocity;
- float angular_velocity = 0.0;
+ double angular_velocity = 0.0;
Vector<PolygonShapeTileData> polygons;
};
Vector<PhysicsLayerTileData> physics;
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 0aa79b8ceb..0bdc81330e 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -36,6 +36,11 @@
#include "visual_shader_particle_nodes.h"
#include "visual_shader_sdf_nodes.h"
+String make_unique_id(VisualShader::Type p_type, int p_id, const String &p_name) {
+ static const char *typepf[VisualShader::TYPE_MAX] = { "vtx", "frg", "lgt", "start", "process", "collide", "start_custom", "process_custom", "sky", "fog" };
+ return p_name + "_" + String(typepf[p_type]) + "_" + itos(p_id);
+}
+
bool VisualShaderNode::is_simple_decl() const {
return simple_decl;
}
@@ -354,7 +359,7 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::
}
String code = " {\n";
String _code;
- GDVIRTUAL_CALL(_get_code, input_vars, output_vars, (int)p_mode, (int)p_type, _code);
+ GDVIRTUAL_CALL(_get_code, input_vars, output_vars, p_mode, p_type, _code);
bool nend = _code.ends_with("\n");
_code = _code.insert(0, " ");
_code = _code.replace("\n", "\n ");
@@ -371,7 +376,7 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::
String VisualShaderNodeCustom::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
String ret;
- if (GDVIRTUAL_CALL(_get_global_code, (int)p_mode, ret)) {
+ if (GDVIRTUAL_CALL(_get_global_code, p_mode, ret)) {
String code = "// " + get_caption() + "\n";
code += ret;
code += "\n";
@@ -1829,6 +1834,7 @@ void VisualShader::_update_shader() const {
code += " vec3 __vec3_buff2;\n";
code += " float __scalar_buff1;\n";
code += " float __scalar_buff2;\n";
+ code += " int __scalar_ibuff;\n";
code += " vec3 __ndiff = normalize(__diff);\n\n";
}
if (has_start) {
@@ -1956,7 +1962,9 @@ void VisualShader::_update_shader() const {
const_cast<VisualShader *>(this)->set_code(final_code);
for (int i = 0; i < default_tex_params.size(); i++) {
- const_cast<VisualShader *>(this)->set_default_texture_param(default_tex_params[i].name, default_tex_params[i].param);
+ for (int j = 0; j < default_tex_params[i].params.size(); j++) {
+ const_cast<VisualShader *>(this)->set_default_texture_param(default_tex_params[i].name, default_tex_params[i].params[j], j);
+ }
}
if (previous_code != final_code) {
const_cast<VisualShader *>(this)->emit_signal(SNAME("changed"));
@@ -3444,7 +3452,7 @@ void VisualShaderNodeGroupBase::add_input_port(int p_id, int p_type, const Strin
count++;
}
- inputs.erase(index, count);
+ inputs = inputs.left(index) + inputs.substr(index + count);
inputs = inputs.insert(index, itos(i));
index += inputs_strings[i].size();
}
@@ -3467,7 +3475,7 @@ void VisualShaderNodeGroupBase::remove_input_port(int p_id) {
}
index += inputs_strings[i].size();
}
- inputs.erase(index, count);
+ inputs = inputs.left(index) + inputs.substr(index + count);
inputs_strings = inputs.split(";", false);
inputs = inputs.substr(0, index);
@@ -3520,7 +3528,7 @@ void VisualShaderNodeGroupBase::add_output_port(int p_id, int p_type, const Stri
count++;
}
- outputs.erase(index, count);
+ outputs = outputs.left(index) + outputs.substr(index + count);
outputs = outputs.insert(index, itos(i));
index += outputs_strings[i].size();
}
@@ -3543,7 +3551,7 @@ void VisualShaderNodeGroupBase::remove_output_port(int p_id) {
}
index += outputs_strings[i].size();
}
- outputs.erase(index, count);
+ outputs = outputs.left(index) + outputs.substr(index + count);
outputs_strings = outputs.split(";", false);
outputs = outputs.substr(0, index);
@@ -3595,8 +3603,7 @@ void VisualShaderNodeGroupBase::set_input_port_type(int p_id, int p_type) {
index += inputs_strings[i].size();
}
- inputs.erase(index, count);
-
+ inputs = inputs.left(index) + inputs.substr(index + count);
inputs = inputs.insert(index, itos(p_type));
_apply_port_changes();
@@ -3631,8 +3638,7 @@ void VisualShaderNodeGroupBase::set_input_port_name(int p_id, const String &p_na
index += inputs_strings[i].size();
}
- inputs.erase(index, count);
-
+ inputs = inputs.left(index) + inputs.substr(index + count);
inputs = inputs.insert(index, p_name);
_apply_port_changes();
@@ -3667,7 +3673,7 @@ void VisualShaderNodeGroupBase::set_output_port_type(int p_id, int p_type) {
index += output_strings[i].size();
}
- outputs.erase(index, count);
+ outputs = outputs.left(index) + outputs.substr(index + count);
outputs = outputs.insert(index, itos(p_type));
@@ -3703,7 +3709,7 @@ void VisualShaderNodeGroupBase::set_output_port_name(int p_id, const String &p_n
index += output_strings[i].size();
}
- outputs.erase(index, count);
+ outputs = outputs.left(index) + outputs.substr(index + count);
outputs = outputs.insert(index, p_name);
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 7743affba7..5bb9d45f39 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -70,7 +70,7 @@ public:
struct DefaultTextureParam {
StringName name;
- Ref<Texture2D> param;
+ List<Ref<Texture2D>> params;
};
private:
@@ -328,8 +328,8 @@ protected:
GDVIRTUAL0RC(int, _get_output_port_count)
GDVIRTUAL1RC(int, _get_output_port_type, int)
GDVIRTUAL1RC(String, _get_output_port_name, int)
- GDVIRTUAL4RC(String, _get_code, Vector<String>, TypedArray<String>, int, int)
- GDVIRTUAL1RC(String, _get_global_code, int)
+ GDVIRTUAL4RC(String, _get_code, Vector<String>, TypedArray<String>, Shader::Mode, VisualShader::Type)
+ GDVIRTUAL1RC(String, _get_global_code, Shader::Mode)
GDVIRTUAL0RC(bool, _is_highend)
protected:
@@ -697,4 +697,6 @@ public:
VisualShaderNodeGlobalExpression();
};
+extern String make_unique_id(VisualShader::Type p_type, int p_id, const String &p_name);
+
#endif // VISUAL_SHADER_H
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index c3d9ef7b04..951870fe34 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -494,15 +494,10 @@ String VisualShaderNodeTexture::get_input_port_default_hint(int p_port) const {
return "";
}
-static String make_unique_id(VisualShader::Type p_type, int p_id, const String &p_name) {
- static const char *typepf[VisualShader::TYPE_MAX] = { "vtx", "frg", "lgt" };
- return p_name + "_" + String(typepf[p_type]) + "_" + itos(p_id);
-}
-
Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
VisualShader::DefaultTextureParam dtp;
dtp.name = make_unique_id(p_type, p_id, "tex");
- dtp.param = texture;
+ dtp.params.push_back(texture);
Vector<VisualShader::DefaultTextureParam> ret;
ret.push_back(dtp);
return ret;
@@ -900,7 +895,7 @@ String VisualShaderNodeCurveTexture::generate_code(Shader::Mode p_mode, VisualSh
Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCurveTexture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
VisualShader::DefaultTextureParam dtp;
dtp.name = make_unique_id(p_type, p_id, "curve");
- dtp.param = texture;
+ dtp.params.push_back(texture);
Vector<VisualShader::DefaultTextureParam> ret;
ret.push_back(dtp);
return ret;
@@ -985,7 +980,7 @@ String VisualShaderNodeCurveXYZTexture::generate_code(Shader::Mode p_mode, Visua
Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCurveXYZTexture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
VisualShader::DefaultTextureParam dtp;
dtp.name = make_unique_id(p_type, p_id, "curve3d");
- dtp.param = texture;
+ dtp.params.push_back(texture);
Vector<VisualShader::DefaultTextureParam> ret;
ret.push_back(dtp);
return ret;
@@ -1167,7 +1162,7 @@ String VisualShaderNodeTexture2DArray::get_input_port_name(int p_port) const {
Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture2DArray::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
VisualShader::DefaultTextureParam dtp;
dtp.name = make_unique_id(p_type, p_id, "tex3d");
- dtp.param = texture_array;
+ dtp.params.push_back(texture_array);
Vector<VisualShader::DefaultTextureParam> ret;
ret.push_back(dtp);
return ret;
@@ -1224,7 +1219,7 @@ String VisualShaderNodeTexture3D::get_input_port_name(int p_port) const {
Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture3D::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
VisualShader::DefaultTextureParam dtp;
dtp.name = make_unique_id(p_type, p_id, "tex3d");
- dtp.param = texture;
+ dtp.params.push_back(texture);
Vector<VisualShader::DefaultTextureParam> ret;
ret.push_back(dtp);
return ret;
@@ -1323,7 +1318,7 @@ bool VisualShaderNodeCubemap::is_output_port_expandable(int p_port) const {
Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCubemap::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
VisualShader::DefaultTextureParam dtp;
dtp.name = make_unique_id(p_type, p_id, "cube");
- dtp.param = cube_map;
+ dtp.params.push_back(cube_map);
Vector<VisualShader::DefaultTextureParam> ret;
ret.push_back(dtp);
return ret;
diff --git a/scene/resources/visual_shader_particle_nodes.cpp b/scene/resources/visual_shader_particle_nodes.cpp
index ada91cec1e..7dd4eed15b 100644
--- a/scene/resources/visual_shader_particle_nodes.cpp
+++ b/scene/resources/visual_shader_particle_nodes.cpp
@@ -30,6 +30,8 @@
#include "visual_shader_particle_nodes.h"
+#include "core/core_string_names.h"
+
// VisualShaderNodeParticleEmitter
int VisualShaderNodeParticleEmitter::get_output_port_count() const {
@@ -255,6 +257,283 @@ VisualShaderNodeParticleRingEmitter::VisualShaderNodeParticleRingEmitter() {
set_input_port_default_value(2, 0.0);
}
+// VisualShaderNodeParticleMeshEmitter
+
+String VisualShaderNodeParticleMeshEmitter::get_caption() const {
+ return "MeshEmitter";
+}
+
+int VisualShaderNodeParticleMeshEmitter::get_output_port_count() const {
+ return 2;
+}
+
+VisualShaderNodeParticleBoxEmitter::PortType VisualShaderNodeParticleMeshEmitter::get_output_port_type(int p_port) const {
+ switch (p_port) {
+ case 0:
+ return PORT_TYPE_VECTOR; // position
+ case 1:
+ return PORT_TYPE_VECTOR; // normal
+ }
+ return PORT_TYPE_SCALAR;
+}
+
+String VisualShaderNodeParticleMeshEmitter::get_output_port_name(int p_port) const {
+ switch (p_port) {
+ case 0:
+ return "position";
+ case 1:
+ return "normal";
+ }
+ return String();
+}
+
+int VisualShaderNodeParticleMeshEmitter::get_input_port_count() const {
+ return 0;
+}
+
+VisualShaderNodeParticleBoxEmitter::PortType VisualShaderNodeParticleMeshEmitter::get_input_port_type(int p_port) const {
+ return PORT_TYPE_SCALAR;
+}
+
+String VisualShaderNodeParticleMeshEmitter::get_input_port_name(int p_port) const {
+ return String();
+}
+
+String VisualShaderNodeParticleMeshEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+ String code;
+
+ if (mesh.is_valid()) {
+ code += "uniform sampler2D " + make_unique_id(p_type, p_id, "mesh_vx") + ";\n";
+ code += "uniform sampler2D " + make_unique_id(p_type, p_id, "mesh_nm") + ";\n";
+ }
+
+ return code;
+}
+
+String VisualShaderNodeParticleMeshEmitter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
+ String code;
+
+ code += " __scalar_ibuff = int(__rand_from_seed(__seed) * 65535.0) % " + itos(position_texture->get_width()) + ";\n";
+
+ if (position_texture->get_width() == 0) {
+ code += " " + p_output_vars[0] + " = vec3(0.0);\n";
+ } else {
+ if (mode_2d) {
+ code += " " + p_output_vars[0] + " = vec3(";
+ code += "texelFetch(";
+ code += make_unique_id(p_type, p_id, "mesh_vx") + ", ";
+ code += "ivec2(__scalar_ibuff, 0), 0).xy, 0.0);\n";
+ } else {
+ code += " " + p_output_vars[0] + " = texelFetch(";
+ code += make_unique_id(p_type, p_id, "mesh_vx") + ", ";
+ code += "ivec2(__scalar_ibuff, 0), 0).xyz;\n";
+ }
+ }
+
+ if (normal_texture->get_width() == 0) {
+ code += " " + p_output_vars[1] + " = vec3(0.0);\n";
+ } else {
+ if (mode_2d) {
+ code += " " + p_output_vars[1] + " = vec3(";
+ code += "texelFetch(";
+ code += make_unique_id(p_type, p_id, "mesh_nm") + ", ";
+ code += "ivec2(__scalar_ibuff, 0), 0).xy, 0.0);\n";
+ } else {
+ code += " " + p_output_vars[1] + " = texelFetch(";
+ code += make_unique_id(p_type, p_id, "mesh_nm") + ", ";
+ code += "ivec2(__scalar_ibuff, 0), 0).xyz;\n";
+ }
+ }
+
+ return code;
+}
+
+Vector<VisualShader::DefaultTextureParam> VisualShaderNodeParticleMeshEmitter::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
+ VisualShader::DefaultTextureParam dtp_vx;
+ dtp_vx.name = make_unique_id(p_type, p_id, "mesh_vx");
+ dtp_vx.params.push_back(position_texture);
+
+ VisualShader::DefaultTextureParam dtp_nm;
+ dtp_nm.name = make_unique_id(p_type, p_id, "mesh_nm");
+ dtp_nm.params.push_back(normal_texture);
+
+ Vector<VisualShader::DefaultTextureParam> ret;
+ ret.push_back(dtp_vx);
+ ret.push_back(dtp_nm);
+ return ret;
+}
+
+void VisualShaderNodeParticleMeshEmitter::update_texture() {
+ if (!mesh.is_valid()) {
+ return;
+ }
+
+ Vector<Vector3> vertices;
+ Vector<Vector3> normals;
+
+ if (use_all_surfaces) {
+ for (int i = 0; i < max_surface_index; i++) {
+ Array vertex_array = mesh->surface_get_arrays(i)[Mesh::ARRAY_VERTEX];
+ for (int j = 0; j < vertex_array.size(); j++) {
+ vertices.push_back((Vector3)vertex_array[j]);
+ }
+
+ Array normal_array = mesh->surface_get_arrays(i)[Mesh::ARRAY_NORMAL];
+ for (int j = 0; j < vertex_array.size(); j++) {
+ normals.push_back((Vector3)vertex_array[j]);
+ }
+ }
+ } else {
+ Array vertex_array = mesh->surface_get_arrays(surface_index)[Mesh::ARRAY_VERTEX];
+ for (int i = 0; i < vertex_array.size(); i++) {
+ vertices.push_back((Vector3)vertex_array[i]);
+ }
+
+ Array normal_array = mesh->surface_get_arrays(surface_index)[Mesh::ARRAY_NORMAL];
+ for (int i = 0; i < normal_array.size(); i++) {
+ normals.push_back((Vector3)normal_array[i]);
+ }
+ }
+
+ // vertices
+ {
+ Ref<Image> image;
+ image.instantiate();
+ image->create(vertices.size(), 1, false, Image::Format::FORMAT_RGBF);
+
+ for (int i = 0; i < vertices.size(); i++) {
+ Vector3 v = vertices[i];
+ image->set_pixel(i, 0, Color(v.x, v.y, v.z));
+ }
+ if (position_texture->get_width() != vertices.size()) {
+ position_texture->create_from_image(image);
+ } else {
+ position_texture->update(image);
+ }
+ }
+
+ // normals
+ {
+ Ref<Image> image;
+ image.instantiate();
+ image->create(normals.size(), 1, false, Image::Format::FORMAT_RGBF);
+
+ for (int i = 0; i < normals.size(); i++) {
+ Vector3 v = normals[i];
+ image->set_pixel(i, 0, Color(v.x, v.y, v.z));
+ }
+ if (normal_texture->get_width() != normals.size()) {
+ normal_texture->create_from_image(image);
+ } else {
+ normal_texture->update(image);
+ }
+ }
+}
+
+void VisualShaderNodeParticleMeshEmitter::set_mesh(Ref<Mesh> p_mesh) {
+ if (mesh == p_mesh) {
+ return;
+ }
+
+ if (p_mesh.is_valid()) {
+ max_surface_index = p_mesh->get_surface_count();
+ } else {
+ max_surface_index = 0;
+ }
+
+ if (mesh.is_valid()) {
+ Callable callable = callable_mp(this, &VisualShaderNodeParticleMeshEmitter::update_texture);
+
+ if (mesh->is_connected(CoreStringNames::get_singleton()->changed, callable)) {
+ mesh->disconnect(CoreStringNames::get_singleton()->changed, callable);
+ }
+ }
+
+ mesh = p_mesh;
+
+ if (mesh.is_valid()) {
+ Callable callable = callable_mp(this, &VisualShaderNodeParticleMeshEmitter::update_texture);
+
+ if (!mesh->is_connected(CoreStringNames::get_singleton()->changed, callable)) {
+ mesh->connect(CoreStringNames::get_singleton()->changed, callable);
+ }
+ }
+
+ emit_changed();
+}
+
+Ref<Mesh> VisualShaderNodeParticleMeshEmitter::get_mesh() const {
+ return mesh;
+}
+
+void VisualShaderNodeParticleMeshEmitter::set_use_all_surfaces(bool p_enabled) {
+ if (use_all_surfaces == p_enabled) {
+ return;
+ }
+ use_all_surfaces = p_enabled;
+ emit_changed();
+}
+
+bool VisualShaderNodeParticleMeshEmitter::is_use_all_surfaces() const {
+ return use_all_surfaces;
+}
+
+void VisualShaderNodeParticleMeshEmitter::set_surface_index(int p_surface_index) {
+ if (p_surface_index == surface_index || p_surface_index < 0 || p_surface_index >= max_surface_index) {
+ return;
+ }
+ surface_index = p_surface_index;
+ emit_changed();
+}
+
+int VisualShaderNodeParticleMeshEmitter::get_surface_index() const {
+ return surface_index;
+}
+
+Vector<StringName> VisualShaderNodeParticleMeshEmitter::get_editable_properties() const {
+ Vector<StringName> props = VisualShaderNodeParticleEmitter::get_editable_properties();
+
+ props.push_back("mesh");
+ props.push_back("use_all_surfaces");
+ if (!use_all_surfaces) {
+ props.push_back("surface_index");
+ }
+
+ return props;
+}
+
+Map<StringName, String> VisualShaderNodeParticleMeshEmitter::get_editable_properties_names() const {
+ Map<StringName, String> names = VisualShaderNodeParticleEmitter::get_editable_properties_names();
+
+ names.insert("mesh", TTR("Mesh"));
+ names.insert("use_all_surfaces", TTR("Use All Surfaces"));
+ if (!use_all_surfaces) {
+ names.insert("surface_index", TTR("Surface Index"));
+ }
+
+ return names;
+}
+
+void VisualShaderNodeParticleMeshEmitter::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &VisualShaderNodeParticleMeshEmitter::set_mesh);
+ ClassDB::bind_method(D_METHOD("get_mesh"), &VisualShaderNodeParticleMeshEmitter::get_mesh);
+ ClassDB::bind_method(D_METHOD("set_use_all_surfaces", "enabled"), &VisualShaderNodeParticleMeshEmitter::set_use_all_surfaces);
+ ClassDB::bind_method(D_METHOD("is_use_all_surfaces"), &VisualShaderNodeParticleMeshEmitter::is_use_all_surfaces);
+ ClassDB::bind_method(D_METHOD("set_surface_index", "surface_index"), &VisualShaderNodeParticleMeshEmitter::set_surface_index);
+ ClassDB::bind_method(D_METHOD("get_surface_index"), &VisualShaderNodeParticleMeshEmitter::get_surface_index);
+
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_all_surfaces"), "set_use_all_surfaces", "is_use_all_surfaces");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "surface_index"), "set_surface_index", "get_surface_index");
+}
+
+VisualShaderNodeParticleMeshEmitter::VisualShaderNodeParticleMeshEmitter() {
+ connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &VisualShaderNodeParticleMeshEmitter::update_texture));
+
+ position_texture.instantiate();
+ normal_texture.instantiate();
+}
+
// VisualShaderNodeParticleMultiplyByAxisAngle
void VisualShaderNodeParticleMultiplyByAxisAngle::_bind_methods() {
@@ -334,7 +613,6 @@ bool VisualShaderNodeParticleMultiplyByAxisAngle::is_degrees_mode() const {
Vector<StringName> VisualShaderNodeParticleMultiplyByAxisAngle::get_editable_properties() const {
Vector<StringName> props;
props.push_back("degrees_mode");
- props.push_back("axis_amount");
return props;
}
diff --git a/scene/resources/visual_shader_particle_nodes.h b/scene/resources/visual_shader_particle_nodes.h
index 0b1fa277de..0d0f21e4bf 100644
--- a/scene/resources/visual_shader_particle_nodes.h
+++ b/scene/resources/visual_shader_particle_nodes.h
@@ -52,7 +52,7 @@ public:
bool is_mode_2d() const;
Vector<StringName> get_editable_properties() const override;
- Map<StringName, String> get_editable_properties_names() const override;
+ virtual Map<StringName, String> get_editable_properties_names() const override;
bool is_show_prop_names() const override;
VisualShaderNodeParticleEmitter();
@@ -106,6 +106,51 @@ public:
VisualShaderNodeParticleRingEmitter();
};
+class VisualShaderNodeParticleMeshEmitter : public VisualShaderNodeParticleEmitter {
+ GDCLASS(VisualShaderNodeParticleMeshEmitter, VisualShaderNodeParticleEmitter);
+ Ref<Mesh> mesh;
+ bool use_all_surfaces = true;
+ int surface_index = 0;
+ int max_surface_index = 0;
+
+ Ref<ImageTexture> position_texture;
+ Ref<ImageTexture> normal_texture;
+
+protected:
+ static void _bind_methods();
+
+public:
+ virtual String get_caption() const override;
+
+ virtual int get_output_port_count() const override;
+ virtual PortType get_output_port_type(int p_port) const override;
+ virtual String get_output_port_name(int p_port) const override;
+
+ virtual int get_input_port_count() const override;
+ virtual PortType get_input_port_type(int p_port) const override;
+ virtual String get_input_port_name(int p_port) const override;
+
+ virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
+ virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override;
+
+ void update_texture();
+
+ void set_mesh(Ref<Mesh> p_mesh);
+ Ref<Mesh> get_mesh() const;
+
+ void set_use_all_surfaces(bool p_enabled);
+ bool is_use_all_surfaces() const;
+
+ void set_surface_index(int p_surface_index);
+ int get_surface_index() const;
+
+ Vector<StringName> get_editable_properties() const override;
+ Map<StringName, String> get_editable_properties_names() const override;
+ Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
+
+ VisualShaderNodeParticleMeshEmitter();
+};
+
class VisualShaderNodeParticleMultiplyByAxisAngle : public VisualShaderNode {
GDCLASS(VisualShaderNodeParticleMultiplyByAxisAngle, VisualShaderNode);
bool degrees_mode = true;
diff --git a/servers/physics_2d/godot_area_2d.cpp b/servers/physics_2d/godot_area_2d.cpp
index 6983e28841..fb9d38e7ea 100644
--- a/servers/physics_2d/godot_area_2d.cpp
+++ b/servers/physics_2d/godot_area_2d.cpp
@@ -121,18 +121,21 @@ void GodotArea2D::set_area_monitor_callback(const Callable &p_callback) {
}
}
-void GodotArea2D::set_space_override_mode(PhysicsServer2D::AreaSpaceOverrideMode p_mode) {
- bool do_override = p_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
- if (do_override == (space_override_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)) {
+void GodotArea2D::_set_space_override_mode(PhysicsServer2D::AreaSpaceOverrideMode &r_mode, PhysicsServer2D::AreaSpaceOverrideMode p_new_mode) {
+ bool do_override = p_new_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
+ if (do_override == (r_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)) {
return;
}
_unregister_shapes();
- space_override_mode = p_mode;
+ r_mode = p_new_mode;
_shape_changed();
}
void GodotArea2D::set_param(PhysicsServer2D::AreaParameter p_param, const Variant &p_value) {
switch (p_param) {
+ case PhysicsServer2D::AREA_PARAM_GRAVITY_OVERRIDE_MODE:
+ _set_space_override_mode(gravity_override_mode, (PhysicsServer2D::AreaSpaceOverrideMode)(int)p_value);
+ break;
case PhysicsServer2D::AREA_PARAM_GRAVITY:
gravity = p_value;
break;
@@ -148,9 +151,15 @@ void GodotArea2D::set_param(PhysicsServer2D::AreaParameter p_param, const Varian
case PhysicsServer2D::AREA_PARAM_GRAVITY_POINT_ATTENUATION:
point_attenuation = p_value;
break;
+ case PhysicsServer2D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
+ _set_space_override_mode(linear_damping_override_mode, (PhysicsServer2D::AreaSpaceOverrideMode)(int)p_value);
+ break;
case PhysicsServer2D::AREA_PARAM_LINEAR_DAMP:
linear_damp = p_value;
break;
+ case PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE:
+ _set_space_override_mode(angular_damping_override_mode, (PhysicsServer2D::AreaSpaceOverrideMode)(int)p_value);
+ break;
case PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP:
angular_damp = p_value;
break;
@@ -162,6 +171,8 @@ void GodotArea2D::set_param(PhysicsServer2D::AreaParameter p_param, const Varian
Variant GodotArea2D::get_param(PhysicsServer2D::AreaParameter p_param) const {
switch (p_param) {
+ case PhysicsServer2D::AREA_PARAM_GRAVITY_OVERRIDE_MODE:
+ return gravity_override_mode;
case PhysicsServer2D::AREA_PARAM_GRAVITY:
return gravity;
case PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR:
@@ -172,8 +183,12 @@ Variant GodotArea2D::get_param(PhysicsServer2D::AreaParameter p_param) const {
return gravity_distance_scale;
case PhysicsServer2D::AREA_PARAM_GRAVITY_POINT_ATTENUATION:
return point_attenuation;
+ case PhysicsServer2D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
+ return linear_damping_override_mode;
case PhysicsServer2D::AREA_PARAM_LINEAR_DAMP:
return linear_damp;
+ case PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE:
+ return angular_damping_override_mode;
case PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP:
return angular_damp;
case PhysicsServer2D::AREA_PARAM_PRIORITY:
diff --git a/servers/physics_2d/godot_area_2d.h b/servers/physics_2d/godot_area_2d.h
index 13b3ce1bf2..699c1c1bc8 100644
--- a/servers/physics_2d/godot_area_2d.h
+++ b/servers/physics_2d/godot_area_2d.h
@@ -41,7 +41,10 @@ class GodotBody2D;
class GodotConstraint2D;
class GodotArea2D : public GodotCollisionObject2D {
- PhysicsServer2D::AreaSpaceOverrideMode space_override_mode = PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
+ PhysicsServer2D::AreaSpaceOverrideMode gravity_override_mode = PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
+ PhysicsServer2D::AreaSpaceOverrideMode linear_damping_override_mode = PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
+ PhysicsServer2D::AreaSpaceOverrideMode angular_damping_override_mode = PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
+
real_t gravity = 9.80665;
Vector2 gravity_vector = Vector2(0, -1);
bool gravity_is_point = false;
@@ -96,6 +99,8 @@ class GodotArea2D : public GodotCollisionObject2D {
virtual void _shapes_changed();
void _queue_monitor_update();
+ void _set_space_override_mode(PhysicsServer2D::AreaSpaceOverrideMode &r_mode, PhysicsServer2D::AreaSpaceOverrideMode p_new_mode);
+
public:
void set_monitor_callback(const Callable &p_callback);
_FORCE_INLINE_ bool has_monitor_callback() const { return !monitor_callback.is_null(); }
@@ -112,9 +117,6 @@ public:
void set_param(PhysicsServer2D::AreaParameter p_param, const Variant &p_value);
Variant get_param(PhysicsServer2D::AreaParameter p_param) const;
- void set_space_override_mode(PhysicsServer2D::AreaSpaceOverrideMode p_mode);
- PhysicsServer2D::AreaSpaceOverrideMode get_space_override_mode() const { return space_override_mode; }
-
_FORCE_INLINE_ void set_gravity(real_t p_gravity) { gravity = p_gravity; }
_FORCE_INLINE_ real_t get_gravity() const { return gravity; }
diff --git a/servers/physics_2d/godot_area_pair_2d.cpp b/servers/physics_2d/godot_area_pair_2d.cpp
index fdb95aa262..a98513004d 100644
--- a/servers/physics_2d/godot_area_pair_2d.cpp
+++ b/servers/physics_2d/godot_area_pair_2d.cpp
@@ -38,10 +38,18 @@ bool GodotAreaPair2D::setup(real_t p_step) {
}
process_collision = false;
+ has_space_override = false;
if (result != colliding) {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
- process_collision = true;
- } else if (area->has_monitor_callback()) {
+ if ((int)area->get_param(PhysicsServer2D::AREA_PARAM_GRAVITY_OVERRIDE_MODE) != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ has_space_override = true;
+ } else if ((int)area->get_param(PhysicsServer2D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE) != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ has_space_override = true;
+ } else if ((int)area->get_param(PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE) != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ has_space_override = true;
+ }
+ process_collision = has_space_override;
+
+ if (area->has_monitor_callback()) {
process_collision = true;
}
@@ -57,7 +65,7 @@ bool GodotAreaPair2D::pre_solve(real_t p_step) {
}
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
body->add_area(area);
}
@@ -65,7 +73,7 @@ bool GodotAreaPair2D::pre_solve(real_t p_step) {
area->add_body_to_query(body, body_shape, area_shape);
}
} else {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
body->remove_area(area);
}
@@ -95,7 +103,7 @@ GodotAreaPair2D::GodotAreaPair2D(GodotBody2D *p_body, int p_body_shape, GodotAre
GodotAreaPair2D::~GodotAreaPair2D() {
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
body->remove_area(area);
}
if (area->has_monitor_callback()) {
diff --git a/servers/physics_2d/godot_area_pair_2d.h b/servers/physics_2d/godot_area_pair_2d.h
index 7a9677f714..45bd3df1ed 100644
--- a/servers/physics_2d/godot_area_pair_2d.h
+++ b/servers/physics_2d/godot_area_pair_2d.h
@@ -41,6 +41,7 @@ class GodotAreaPair2D : public GodotConstraint2D {
int body_shape = 0;
int area_shape = 0;
bool colliding = false;
+ bool has_space_override = false;
bool process_collision = false;
public:
diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp
index 442c580920..9b97583300 100644
--- a/servers/physics_2d/godot_body_2d.cpp
+++ b/servers/physics_2d/godot_body_2d.cpp
@@ -410,15 +410,6 @@ void GodotBody2D::set_space(GodotSpace2D *p_space) {
}
}
-void GodotBody2D::_compute_area_gravity_and_damping(const GodotArea2D *p_area) {
- Vector2 area_gravity;
- p_area->compute_gravity(get_transform().get_origin(), area_gravity);
- gravity += area_gravity;
-
- total_linear_damp += p_area->get_linear_damp();
- total_angular_damp += p_area->get_angular_damp();
-}
-
void GodotBody2D::_update_transform_dependent() {
center_of_mass = get_transform().basis_xform(center_of_mass_local);
}
@@ -428,8 +419,16 @@ void GodotBody2D::integrate_forces(real_t p_step) {
return;
}
+ ERR_FAIL_COND(!get_space());
+
int ac = areas.size();
+
+ bool gravity_done = false;
+ bool linear_damp_done = false;
+ bool angular_damp_done = false;
+
bool stopped = false;
+
gravity = Vector2(0, 0);
total_linear_damp = 0.0;
@@ -440,33 +439,89 @@ void GodotBody2D::integrate_forces(real_t p_step) {
areas.sort();
const AreaCMP *aa = &areas[0];
for (int i = ac - 1; i >= 0 && !stopped; i--) {
- PhysicsServer2D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
- switch (mode) {
- case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE:
- case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
- _compute_area_gravity_and_damping(aa[i].area);
- stopped = mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
- } break;
- case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE:
- case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
- gravity = Vector2(0, 0);
- total_linear_damp = 0.0;
- total_angular_damp = 0.0;
- _compute_area_gravity_and_damping(aa[i].area);
- stopped = mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE;
- } break;
- default: {
+ if (!gravity_done) {
+ PhysicsServer2D::AreaSpaceOverrideMode area_gravity_mode = (PhysicsServer2D::AreaSpaceOverrideMode)(int)aa[i].area->get_param(PhysicsServer2D::AREA_PARAM_GRAVITY_OVERRIDE_MODE);
+ if (area_gravity_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ Vector2 area_gravity;
+ aa[i].area->compute_gravity(get_transform().get_origin(), area_gravity);
+ switch (area_gravity_mode) {
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ gravity += area_gravity;
+ gravity_done = area_gravity_mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ } break;
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ gravity = area_gravity;
+ gravity_done = area_gravity_mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE;
+ } break;
+ default: {
+ }
+ }
}
}
+ if (!linear_damp_done) {
+ PhysicsServer2D::AreaSpaceOverrideMode area_linear_damp_mode = (PhysicsServer2D::AreaSpaceOverrideMode)(int)aa[i].area->get_param(PhysicsServer2D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
+ if (area_linear_damp_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ real_t area_linear_damp = aa[i].area->get_linear_damp();
+ switch (area_linear_damp_mode) {
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ total_linear_damp += area_linear_damp;
+ linear_damp_done = area_linear_damp_mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ } break;
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ total_linear_damp = area_linear_damp;
+ linear_damp_done = area_linear_damp_mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE;
+ } break;
+ default: {
+ }
+ }
+ }
+ }
+ if (!angular_damp_done) {
+ PhysicsServer2D::AreaSpaceOverrideMode area_angular_damp_mode = (PhysicsServer2D::AreaSpaceOverrideMode)(int)aa[i].area->get_param(PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
+ if (area_angular_damp_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
+ real_t area_angular_damp = aa[i].area->get_angular_damp();
+ switch (area_angular_damp_mode) {
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ total_angular_damp += area_angular_damp;
+ angular_damp_done = area_angular_damp_mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ } break;
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ total_angular_damp = area_angular_damp;
+ angular_damp_done = area_angular_damp_mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE;
+ } break;
+ default: {
+ }
+ }
+ }
+ }
+ stopped = gravity_done && linear_damp_done && angular_damp_done;
}
}
- // Override linear damping with body's value.
+ // Add default gravity and damping from space area.
if (!stopped) {
- GodotArea2D *def_area = get_space()->get_default_area();
- ERR_FAIL_COND(!def_area);
+ GodotArea2D *default_area = get_space()->get_default_area();
+ ERR_FAIL_COND(!default_area);
- _compute_area_gravity_and_damping(def_area);
+ if (!gravity_done) {
+ Vector2 default_gravity;
+ default_area->compute_gravity(get_transform().get_origin(), default_gravity);
+ gravity += default_gravity;
+ }
+
+ if (!linear_damp_done) {
+ total_linear_damp += default_area->get_linear_damp();
+ }
+
+ if (!angular_damp_done) {
+ total_angular_damp += default_area->get_angular_damp();
+ }
}
// Override linear damping with body's value.
diff --git a/servers/physics_2d/godot_body_2d.h b/servers/physics_2d/godot_body_2d.h
index 7b11b50739..d1dbf92c1b 100644
--- a/servers/physics_2d/godot_body_2d.h
+++ b/servers/physics_2d/godot_body_2d.h
@@ -145,8 +145,6 @@ class GodotBody2D : public GodotCollisionObject2D {
uint64_t island_step = 0;
- void _compute_area_gravity_and_damping(const GodotArea2D *p_area);
-
void _update_transform_dependent();
friend class GodotPhysicsDirectBodyState2D; // i give up, too many functions to expose
diff --git a/servers/physics_2d/godot_physics_server_2d.cpp b/servers/physics_2d/godot_physics_server_2d.cpp
index cf66b80076..8ac27077fc 100644
--- a/servers/physics_2d/godot_physics_server_2d.cpp
+++ b/servers/physics_2d/godot_physics_server_2d.cpp
@@ -289,7 +289,7 @@ RID GodotPhysicsServer2D::area_create() {
RID rid = area_owner.make_rid(area);
area->set_self(rid);
return rid;
-};
+}
void GodotPhysicsServer2D::area_set_space(RID p_area, RID p_space) {
GodotArea2D *area = area_owner.get_or_null(p_area);
@@ -307,7 +307,7 @@ void GodotPhysicsServer2D::area_set_space(RID p_area, RID p_space) {
area->clear_constraints();
area->set_space(space);
-};
+}
RID GodotPhysicsServer2D::area_get_space(RID p_area) const {
GodotArea2D *area = area_owner.get_or_null(p_area);
@@ -318,20 +318,6 @@ RID GodotPhysicsServer2D::area_get_space(RID p_area) const {
return RID();
}
return space->get_self();
-};
-
-void GodotPhysicsServer2D::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
- GodotArea2D *area = area_owner.get_or_null(p_area);
- ERR_FAIL_COND(!area);
-
- area->set_space_override_mode(p_mode);
-}
-
-PhysicsServer2D::AreaSpaceOverrideMode GodotPhysicsServer2D::area_get_space_override_mode(RID p_area) const {
- const GodotArea2D *area = area_owner.get_or_null(p_area);
- ERR_FAIL_COND_V(!area, AREA_SPACE_OVERRIDE_DISABLED);
-
- return area->get_space_override_mode();
}
void GodotPhysicsServer2D::area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform, bool p_disabled) {
@@ -963,10 +949,17 @@ bool GodotPhysicsServer2D::body_test_motion(RID p_body, const MotionParameters &
PhysicsDirectBodyState2D *GodotPhysicsServer2D::body_get_direct_state(RID p_body) {
ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
+ if (!body_owner.owns(p_body)) {
+ return nullptr;
+ }
+
GodotBody2D *body = body_owner.get_or_null(p_body);
ERR_FAIL_COND_V(!body, nullptr);
- ERR_FAIL_COND_V(!body->get_space(), nullptr);
+ if (!body->get_space()) {
+ return nullptr;
+ }
+
ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
return body->get_direct_state();
diff --git a/servers/physics_2d/godot_physics_server_2d.h b/servers/physics_2d/godot_physics_server_2d.h
index b03d78a1de..1f544fee72 100644
--- a/servers/physics_2d/godot_physics_server_2d.h
+++ b/servers/physics_2d/godot_physics_server_2d.h
@@ -124,9 +124,6 @@ public:
virtual RID area_create() override;
- virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) override;
- virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const override;
-
virtual void area_set_space(RID p_area, RID p_space) override;
virtual RID area_get_space(RID p_area) const override;
diff --git a/servers/physics_2d/godot_space_2d.cpp b/servers/physics_2d/godot_space_2d.cpp
index 5c189aa06a..6465a5542c 100644
--- a/servers/physics_2d/godot_space_2d.cpp
+++ b/servers/physics_2d/godot_space_2d.cpp
@@ -153,6 +153,22 @@ bool GodotPhysicsDirectSpaceState2D::intersect_ray(const RayParameters &p_parame
Vector2 shape_point, shape_normal;
+ if (shape->contains_point(local_from)) {
+ if (p_parameters.hit_from_inside) {
+ // Hit shape at starting point.
+ min_d = 0;
+ res_point = local_from;
+ res_normal = Vector2();
+ res_shape = shape_idx;
+ res_obj = col_obj;
+ collided = true;
+ break;
+ } else {
+ // Ignore shape when starting inside.
+ continue;
+ }
+ }
+
if (shape->intersect_segment(local_from, local_to, shape_point, shape_normal)) {
Transform2D xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
shape_point = xform.xform(shape_point);
diff --git a/servers/physics_3d/godot_area_3d.cpp b/servers/physics_3d/godot_area_3d.cpp
index 973fc50968..9cdad069fe 100644
--- a/servers/physics_3d/godot_area_3d.cpp
+++ b/servers/physics_3d/godot_area_3d.cpp
@@ -128,18 +128,21 @@ void GodotArea3D::set_area_monitor_callback(const Callable &p_callback) {
}
}
-void GodotArea3D::set_space_override_mode(PhysicsServer3D::AreaSpaceOverrideMode p_mode) {
- bool do_override = p_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
- if (do_override == (space_override_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED)) {
+void GodotArea3D::_set_space_override_mode(PhysicsServer3D::AreaSpaceOverrideMode &r_mode, PhysicsServer3D::AreaSpaceOverrideMode p_new_mode) {
+ bool do_override = p_new_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
+ if (do_override == (r_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED)) {
return;
}
_unregister_shapes();
- space_override_mode = p_mode;
+ r_mode = p_new_mode;
_shape_changed();
}
void GodotArea3D::set_param(PhysicsServer3D::AreaParameter p_param, const Variant &p_value) {
switch (p_param) {
+ case PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE:
+ _set_space_override_mode(gravity_override_mode, (PhysicsServer3D::AreaSpaceOverrideMode)(int)p_value);
+ break;
case PhysicsServer3D::AREA_PARAM_GRAVITY:
gravity = p_value;
break;
@@ -155,9 +158,15 @@ void GodotArea3D::set_param(PhysicsServer3D::AreaParameter p_param, const Varian
case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION:
point_attenuation = p_value;
break;
+ case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
+ _set_space_override_mode(linear_damping_override_mode, (PhysicsServer3D::AreaSpaceOverrideMode)(int)p_value);
+ break;
case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP:
linear_damp = p_value;
break;
+ case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE:
+ _set_space_override_mode(angular_damping_override_mode, (PhysicsServer3D::AreaSpaceOverrideMode)(int)p_value);
+ break;
case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP:
angular_damp = p_value;
break;
@@ -183,6 +192,8 @@ void GodotArea3D::set_param(PhysicsServer3D::AreaParameter p_param, const Varian
Variant GodotArea3D::get_param(PhysicsServer3D::AreaParameter p_param) const {
switch (p_param) {
+ case PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE:
+ return gravity_override_mode;
case PhysicsServer3D::AREA_PARAM_GRAVITY:
return gravity;
case PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR:
@@ -193,8 +204,12 @@ Variant GodotArea3D::get_param(PhysicsServer3D::AreaParameter p_param) const {
return gravity_distance_scale;
case PhysicsServer3D::AREA_PARAM_GRAVITY_POINT_ATTENUATION:
return point_attenuation;
+ case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE:
+ return linear_damping_override_mode;
case PhysicsServer3D::AREA_PARAM_LINEAR_DAMP:
return linear_damp;
+ case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE:
+ return angular_damping_override_mode;
case PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP:
return angular_damp;
case PhysicsServer3D::AREA_PARAM_PRIORITY:
diff --git a/servers/physics_3d/godot_area_3d.h b/servers/physics_3d/godot_area_3d.h
index b02fa1d5b9..0dcf89b2b4 100644
--- a/servers/physics_3d/godot_area_3d.h
+++ b/servers/physics_3d/godot_area_3d.h
@@ -42,7 +42,10 @@ class GodotSoftBody3D;
class GodotConstraint3D;
class GodotArea3D : public GodotCollisionObject3D {
- PhysicsServer3D::AreaSpaceOverrideMode space_override_mode = PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
+ PhysicsServer3D::AreaSpaceOverrideMode gravity_override_mode = PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
+ PhysicsServer3D::AreaSpaceOverrideMode linear_damping_override_mode = PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
+ PhysicsServer3D::AreaSpaceOverrideMode angular_damping_override_mode = PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
+
real_t gravity = 9.80665;
Vector3 gravity_vector = Vector3(0, -1, 0);
bool gravity_is_point = false;
@@ -102,6 +105,8 @@ class GodotArea3D : public GodotCollisionObject3D {
virtual void _shapes_changed();
void _queue_monitor_update();
+ void _set_space_override_mode(PhysicsServer3D::AreaSpaceOverrideMode &r_mode, PhysicsServer3D::AreaSpaceOverrideMode p_new_mode);
+
public:
void set_monitor_callback(const Callable &p_callback);
_FORCE_INLINE_ bool has_monitor_callback() const { return !monitor_callback.is_null(); }
@@ -121,9 +126,6 @@ public:
void set_param(PhysicsServer3D::AreaParameter p_param, const Variant &p_value);
Variant get_param(PhysicsServer3D::AreaParameter p_param) const;
- void set_space_override_mode(PhysicsServer3D::AreaSpaceOverrideMode p_mode);
- PhysicsServer3D::AreaSpaceOverrideMode get_space_override_mode() const { return space_override_mode; }
-
_FORCE_INLINE_ void set_gravity(real_t p_gravity) { gravity = p_gravity; }
_FORCE_INLINE_ real_t get_gravity() const { return gravity; }
diff --git a/servers/physics_3d/godot_area_pair_3d.cpp b/servers/physics_3d/godot_area_pair_3d.cpp
index 7453153de6..d3623178d5 100644
--- a/servers/physics_3d/godot_area_pair_3d.cpp
+++ b/servers/physics_3d/godot_area_pair_3d.cpp
@@ -39,10 +39,18 @@ bool GodotAreaPair3D::setup(real_t p_step) {
}
process_collision = false;
+ has_space_override = false;
if (result != colliding) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
- process_collision = true;
- } else if (area->has_monitor_callback()) {
+ if ((int)area->get_param(PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE) != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ has_space_override = true;
+ } else if ((int)area->get_param(PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE) != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ has_space_override = true;
+ } else if ((int)area->get_param(PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE) != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ has_space_override = true;
+ }
+ process_collision = has_space_override;
+
+ if (area->has_monitor_callback()) {
process_collision = true;
}
@@ -58,7 +66,7 @@ bool GodotAreaPair3D::pre_solve(real_t p_step) {
}
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
body->add_area(area);
}
@@ -66,7 +74,7 @@ bool GodotAreaPair3D::pre_solve(real_t p_step) {
area->add_body_to_query(body, body_shape, area_shape);
}
} else {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
body->remove_area(area);
}
@@ -96,7 +104,7 @@ GodotAreaPair3D::GodotAreaPair3D(GodotBody3D *p_body, int p_body_shape, GodotAre
GodotAreaPair3D::~GodotAreaPair3D() {
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
body->remove_area(area);
}
if (area->has_monitor_callback()) {
@@ -207,10 +215,15 @@ bool GodotAreaSoftBodyPair3D::setup(real_t p_step) {
}
process_collision = false;
+ has_space_override = false;
if (result != colliding) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
- process_collision = true;
- } else if (area->has_monitor_callback()) {
+ if ((int)area->get_param(PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE) != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ has_space_override = true;
+ } else if (area->get_wind_force_magnitude() > CMP_EPSILON) {
+ has_space_override = true;
+ }
+
+ if (area->has_monitor_callback()) {
process_collision = true;
}
@@ -226,7 +239,7 @@ bool GodotAreaSoftBodyPair3D::pre_solve(real_t p_step) {
}
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
soft_body->add_area(area);
}
@@ -234,7 +247,7 @@ bool GodotAreaSoftBodyPair3D::pre_solve(real_t p_step) {
area->add_soft_body_to_query(soft_body, soft_body_shape, area_shape);
}
} else {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
soft_body->remove_area(area);
}
@@ -261,7 +274,7 @@ GodotAreaSoftBodyPair3D::GodotAreaSoftBodyPair3D(GodotSoftBody3D *p_soft_body, i
GodotAreaSoftBodyPair3D::~GodotAreaSoftBodyPair3D() {
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ if (has_space_override) {
soft_body->remove_area(area);
}
if (area->has_monitor_callback()) {
diff --git a/servers/physics_3d/godot_area_pair_3d.h b/servers/physics_3d/godot_area_pair_3d.h
index f55c03be03..16175e9fa8 100644
--- a/servers/physics_3d/godot_area_pair_3d.h
+++ b/servers/physics_3d/godot_area_pair_3d.h
@@ -43,6 +43,7 @@ class GodotAreaPair3D : public GodotConstraint3D {
int area_shape;
bool colliding = false;
bool process_collision = false;
+ bool has_space_override = false;
public:
virtual bool setup(real_t p_step) override;
@@ -79,6 +80,7 @@ class GodotAreaSoftBodyPair3D : public GodotConstraint3D {
int area_shape;
bool colliding = false;
bool process_collision = false;
+ bool has_space_override = false;
public:
virtual bool setup(real_t p_step) override;
diff --git a/servers/physics_3d/godot_body_3d.cpp b/servers/physics_3d/godot_body_3d.cpp
index acf60d61c2..0e21dd303f 100644
--- a/servers/physics_3d/godot_body_3d.cpp
+++ b/servers/physics_3d/godot_body_3d.cpp
@@ -457,15 +457,6 @@ void GodotBody3D::set_space(GodotSpace3D *p_space) {
}
}
-void GodotBody3D::_compute_area_gravity_and_damping(const GodotArea3D *p_area) {
- Vector3 area_gravity;
- p_area->compute_gravity(get_transform().get_origin(), area_gravity);
- gravity += area_gravity;
-
- total_linear_damp += p_area->get_linear_damp();
- total_angular_damp += p_area->get_angular_damp();
-}
-
void GodotBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock) {
if (lock) {
locked_axis |= p_axis;
@@ -483,8 +474,16 @@ void GodotBody3D::integrate_forces(real_t p_step) {
return;
}
+ ERR_FAIL_COND(!get_space());
+
int ac = areas.size();
+
+ bool gravity_done = false;
+ bool linear_damp_done = false;
+ bool angular_damp_done = false;
+
bool stopped = false;
+
gravity = Vector3(0, 0, 0);
total_linear_damp = 0.0;
@@ -495,33 +494,89 @@ void GodotBody3D::integrate_forces(real_t p_step) {
areas.sort();
const AreaCMP *aa = &areas[0];
for (int i = ac - 1; i >= 0 && !stopped; i--) {
- PhysicsServer3D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
- switch (mode) {
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE:
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
- _compute_area_gravity_and_damping(aa[i].area);
- stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
- } break;
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE:
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
- gravity = Vector3(0, 0, 0);
- total_linear_damp = 0.0;
- total_angular_damp = 0.0;
- _compute_area_gravity_and_damping(aa[i].area);
- stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
- } break;
- default: {
+ if (!gravity_done) {
+ PhysicsServer3D::AreaSpaceOverrideMode area_gravity_mode = (PhysicsServer3D::AreaSpaceOverrideMode)(int)aa[i].area->get_param(PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE);
+ if (area_gravity_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ Vector3 area_gravity;
+ aa[i].area->compute_gravity(get_transform().get_origin(), area_gravity);
+ switch (area_gravity_mode) {
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ gravity += area_gravity;
+ gravity_done = area_gravity_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ } break;
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ gravity = area_gravity;
+ gravity_done = area_gravity_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
+ } break;
+ default: {
+ }
+ }
+ }
+ }
+ if (!linear_damp_done) {
+ PhysicsServer3D::AreaSpaceOverrideMode area_linear_damp_mode = (PhysicsServer3D::AreaSpaceOverrideMode)(int)aa[i].area->get_param(PhysicsServer3D::AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
+ if (area_linear_damp_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ real_t area_linear_damp = aa[i].area->get_linear_damp();
+ switch (area_linear_damp_mode) {
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ total_linear_damp += area_linear_damp;
+ linear_damp_done = area_linear_damp_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ } break;
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ total_linear_damp = area_linear_damp;
+ linear_damp_done = area_linear_damp_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
+ } break;
+ default: {
+ }
+ }
+ }
+ }
+ if (!angular_damp_done) {
+ PhysicsServer3D::AreaSpaceOverrideMode area_angular_damp_mode = (PhysicsServer3D::AreaSpaceOverrideMode)(int)aa[i].area->get_param(PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
+ if (area_angular_damp_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ real_t area_angular_damp = aa[i].area->get_angular_damp();
+ switch (area_angular_damp_mode) {
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ total_angular_damp += area_angular_damp;
+ angular_damp_done = area_angular_damp_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ } break;
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ total_angular_damp = area_angular_damp;
+ angular_damp_done = area_angular_damp_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
+ } break;
+ default: {
+ }
+ }
}
}
+ stopped = gravity_done && linear_damp_done && angular_damp_done;
}
}
// Add default gravity and damping from space area.
if (!stopped) {
- GodotArea3D *def_area = get_space()->get_default_area();
- ERR_FAIL_COND(!def_area);
+ GodotArea3D *default_area = get_space()->get_default_area();
+ ERR_FAIL_COND(!default_area);
- _compute_area_gravity_and_damping(def_area);
+ if (!gravity_done) {
+ Vector3 default_gravity;
+ default_area->compute_gravity(get_transform().get_origin(), default_gravity);
+ gravity += default_gravity;
+ }
+
+ if (!linear_damp_done) {
+ total_linear_damp += default_area->get_linear_damp();
+ }
+
+ if (!angular_damp_done) {
+ total_angular_damp += default_area->get_angular_damp();
+ }
}
// Override linear damping with body's value.
diff --git a/servers/physics_3d/godot_body_3d.h b/servers/physics_3d/godot_body_3d.h
index 7fc2f58168..ac3131ab44 100644
--- a/servers/physics_3d/godot_body_3d.h
+++ b/servers/physics_3d/godot_body_3d.h
@@ -139,8 +139,6 @@ class GodotBody3D : public GodotCollisionObject3D {
uint64_t island_step = 0;
- void _compute_area_gravity_and_damping(const GodotArea3D *p_area);
-
void _update_transform_dependent();
friend class GodotPhysicsDirectBodyState3D; // i give up, too many functions to expose
diff --git a/servers/physics_3d/godot_body_pair_3d.cpp b/servers/physics_3d/godot_body_pair_3d.cpp
index f7d9ed9ee9..f0002870ae 100644
--- a/servers/physics_3d/godot_body_pair_3d.cpp
+++ b/servers/physics_3d/godot_body_pair_3d.cpp
@@ -191,7 +191,7 @@ bool GodotBodyPair3D::_test_ccd(real_t p_step, GodotBody3D *p_A, int p_shape_A,
Vector3 local_to = from_inv.xform(to);
Vector3 rpos, rnorm;
- if (!p_B->get_shape(p_shape_B)->intersect_segment(local_from, local_to, rpos, rnorm)) {
+ if (!p_B->get_shape(p_shape_B)->intersect_segment(local_from, local_to, rpos, rnorm, true)) {
return false;
}
diff --git a/servers/physics_3d/godot_collision_solver_3d.cpp b/servers/physics_3d/godot_collision_solver_3d.cpp
index b9f2f7506b..686f3e4d59 100644
--- a/servers/physics_3d/godot_collision_solver_3d.cpp
+++ b/servers/physics_3d/godot_collision_solver_3d.cpp
@@ -102,7 +102,7 @@ bool GodotCollisionSolver3D::solve_separation_ray(const GodotShape3D *p_shape_A,
to = ai.xform(to);
Vector3 p, n;
- if (!p_shape_B->intersect_segment(from, to, p, n)) {
+ if (!p_shape_B->intersect_segment(from, to, p, n, true)) {
return false;
}
diff --git a/servers/physics_3d/godot_physics_server_3d.cpp b/servers/physics_3d/godot_physics_server_3d.cpp
index 73654939ca..9acae62382 100644
--- a/servers/physics_3d/godot_physics_server_3d.cpp
+++ b/servers/physics_3d/godot_physics_server_3d.cpp
@@ -219,7 +219,7 @@ RID GodotPhysicsServer3D::area_create() {
RID rid = area_owner.make_rid(area);
area->set_self(rid);
return rid;
-};
+}
void GodotPhysicsServer3D::area_set_space(RID p_area, RID p_space) {
GodotArea3D *area = area_owner.get_or_null(p_area);
@@ -237,7 +237,7 @@ void GodotPhysicsServer3D::area_set_space(RID p_area, RID p_space) {
area->clear_constraints();
area->set_space(space);
-};
+}
RID GodotPhysicsServer3D::area_get_space(RID p_area) const {
GodotArea3D *area = area_owner.get_or_null(p_area);
@@ -248,20 +248,6 @@ RID GodotPhysicsServer3D::area_get_space(RID p_area) const {
return RID();
}
return space->get_self();
-};
-
-void GodotPhysicsServer3D::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
- GodotArea3D *area = area_owner.get_or_null(p_area);
- ERR_FAIL_COND(!area);
-
- area->set_space_override_mode(p_mode);
-}
-
-PhysicsServer3D::AreaSpaceOverrideMode GodotPhysicsServer3D::area_get_space_override_mode(RID p_area) const {
- const GodotArea3D *area = area_owner.get_or_null(p_area);
- ERR_FAIL_COND_V(!area, AREA_SPACE_OVERRIDE_DISABLED);
-
- return area->get_space_override_mode();
}
void GodotPhysicsServer3D::area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform, bool p_disabled) {
@@ -881,10 +867,17 @@ bool GodotPhysicsServer3D::body_test_motion(RID p_body, const MotionParameters &
PhysicsDirectBodyState3D *GodotPhysicsServer3D::body_get_direct_state(RID p_body) {
ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
+ if (!body_owner.owns(p_body)) {
+ return nullptr;
+ }
+
GodotBody3D *body = body_owner.get_or_null(p_body);
ERR_FAIL_NULL_V(body, nullptr);
- ERR_FAIL_NULL_V(body->get_space(), nullptr);
+ if (!body->get_space()) {
+ return nullptr;
+ }
+
ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
return body->get_direct_state();
diff --git a/servers/physics_3d/godot_physics_server_3d.h b/servers/physics_3d/godot_physics_server_3d.h
index 4ddd10a4e0..f5c8e0f60d 100644
--- a/servers/physics_3d/godot_physics_server_3d.h
+++ b/servers/physics_3d/godot_physics_server_3d.h
@@ -122,9 +122,6 @@ public:
virtual RID area_create() override;
- virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) override;
- virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const override;
-
virtual void area_set_space(RID p_area, RID p_space) override;
virtual RID area_get_space(RID p_area) const override;
diff --git a/servers/physics_3d/godot_shape_3d.cpp b/servers/physics_3d/godot_shape_3d.cpp
index 4c12a5a948..b520ee45c7 100644
--- a/servers/physics_3d/godot_shape_3d.cpp
+++ b/servers/physics_3d/godot_shape_3d.cpp
@@ -119,7 +119,7 @@ Vector3 GodotWorldBoundaryShape3D::get_support(const Vector3 &p_normal) const {
return p_normal * 1e15;
}
-bool GodotWorldBoundaryShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotWorldBoundaryShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
bool inters = plane.intersects_segment(p_begin, p_end, &r_result);
if (inters) {
r_normal = plane.normal;
@@ -200,7 +200,7 @@ void GodotSeparationRayShape3D::get_supports(const Vector3 &p_normal, int p_max,
}
}
-bool GodotSeparationRayShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotSeparationRayShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
return false; //simply not possible
}
@@ -268,7 +268,7 @@ void GodotSphereShape3D::get_supports(const Vector3 &p_normal, int p_max, Vector
r_type = FEATURE_POINT;
}
-bool GodotSphereShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotSphereShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
return Geometry3D::segment_intersects_sphere(p_begin, p_end, Vector3(), radius, &r_result, &r_normal);
}
@@ -410,7 +410,7 @@ void GodotBoxShape3D::get_supports(const Vector3 &p_normal, int p_max, Vector3 *
r_supports[0] = point;
}
-bool GodotBoxShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotBoxShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
AABB aabb(-half_extents, half_extents * 2.0);
return aabb.intersects_segment(p_begin, p_end, &r_result, &r_normal);
@@ -546,7 +546,7 @@ void GodotCapsuleShape3D::get_supports(const Vector3 &p_normal, int p_max, Vecto
}
}
-bool GodotCapsuleShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotCapsuleShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
Vector3 norm = (p_end - p_begin).normalized();
real_t min_d = 1e20;
@@ -761,7 +761,7 @@ void GodotCylinderShape3D::get_supports(const Vector3 &p_normal, int p_max, Vect
}
}
-bool GodotCylinderShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotCylinderShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
return Geometry3D::segment_intersects_cylinder(p_begin, p_end, height, radius, &r_result, &r_normal, 1);
}
@@ -954,7 +954,7 @@ void GodotConvexPolygonShape3D::get_supports(const Vector3 &p_normal, int p_max,
r_type = FEATURE_POINT;
}
-bool GodotConvexPolygonShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotConvexPolygonShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
const Geometry3D::MeshData::Face *faces = mesh.faces.ptr();
int fc = mesh.faces.size();
@@ -1188,12 +1188,12 @@ void GodotFaceShape3D::get_supports(const Vector3 &p_normal, int p_max, Vector3
r_supports[0] = vertex[vert_support_idx];
}
-bool GodotFaceShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotFaceShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
bool c = Geometry3D::segment_intersects_triangle(p_begin, p_end, vertex[0], vertex[1], vertex[2], &r_result);
if (c) {
r_normal = Plane(vertex[0], vertex[1], vertex[2]).normal;
if (r_normal.dot(p_end - p_begin) > 0) {
- if (backface_collision) {
+ if (backface_collision && p_hit_back_faces) {
r_normal = -r_normal;
} else {
c = false;
@@ -1304,7 +1304,7 @@ void GodotConcavePolygonShape3D::_cull_segment(int p_idx, _SegmentCullParams *p_
Vector3 res;
Vector3 normal;
- if (face->intersect_segment(p_params->from, p_params->to, res, normal)) {
+ if (face->intersect_segment(p_params->from, p_params->to, res, normal, true)) {
real_t d = p_params->dir.dot(res) - p_params->dir.dot(p_params->from);
if ((d > 0) && (d < p_params->min_d)) {
p_params->min_d = d;
@@ -1323,7 +1323,7 @@ void GodotConcavePolygonShape3D::_cull_segment(int p_idx, _SegmentCullParams *p_
}
}
-bool GodotConcavePolygonShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotConcavePolygonShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
if (faces.size() == 0) {
return false;
}
@@ -1334,7 +1334,7 @@ bool GodotConcavePolygonShape3D::intersect_segment(const Vector3 &p_begin, const
const BVH *br = bvh.ptr();
GodotFaceShape3D face;
- face.backface_collision = backface_collision;
+ face.backface_collision = backface_collision && p_hit_back_faces;
_SegmentCullParams params;
params.from = p_begin;
@@ -1675,7 +1675,7 @@ struct _HeightmapGridCullState {
_FORCE_INLINE_ bool _heightmap_face_cull_segment(_HeightmapSegmentCullParams &p_params) {
Vector3 res;
Vector3 normal;
- if (p_params.face->intersect_segment(p_params.from, p_params.to, res, normal)) {
+ if (p_params.face->intersect_segment(p_params.from, p_params.to, res, normal, true)) {
p_params.result = res;
p_params.normal = normal;
return true;
@@ -1881,7 +1881,7 @@ bool GodotHeightMapShape3D::_intersect_grid_segment(ProcessFunction &p_process,
return false;
}
-bool GodotHeightMapShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const {
+bool GodotHeightMapShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, bool p_hit_back_faces) const {
if (heights.is_empty()) {
return false;
}
@@ -1899,7 +1899,7 @@ bool GodotHeightMapShape3D::intersect_segment(const Vector3 &p_begin, const Vect
// Simple case for rays that don't traverse the grid horizontally.
// Just perform a test on the given cell.
GodotFaceShape3D face;
- face.backface_collision = false;
+ face.backface_collision = p_hit_back_faces;
_HeightmapSegmentCullParams params;
params.from = p_begin;
diff --git a/servers/physics_3d/godot_shape_3d.h b/servers/physics_3d/godot_shape_3d.h
index 1bbcd903f7..7a32b69166 100644
--- a/servers/physics_3d/godot_shape_3d.h
+++ b/servers/physics_3d/godot_shape_3d.h
@@ -80,7 +80,7 @@ public:
virtual Vector3 get_support(const Vector3 &p_normal) const;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const = 0;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const = 0;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const = 0;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, bool p_hit_back_faces) const = 0;
virtual bool intersect_point(const Vector3 &p_point) const = 0;
virtual Vector3 get_moment_of_inertia(real_t p_mass) const = 0;
@@ -126,7 +126,7 @@ public:
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
@@ -153,7 +153,7 @@ public:
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -180,7 +180,7 @@ public:
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -205,7 +205,7 @@ public:
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -234,7 +234,7 @@ public:
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -263,7 +263,7 @@ public:
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -288,7 +288,7 @@ public:
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -366,7 +366,7 @@ public:
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -429,7 +429,7 @@ public:
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -456,7 +456,7 @@ struct GodotFaceShape3D : public GodotShape3D {
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
virtual bool intersect_point(const Vector3 &p_point) const override;
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
@@ -495,7 +495,7 @@ struct GodotMotionShape3D : public GodotShape3D {
}
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override { return false; }
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override { return false; }
virtual bool intersect_point(const Vector3 &p_point) const override { return false; }
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override { return p_point; }
diff --git a/servers/physics_3d/godot_soft_body_3d.cpp b/servers/physics_3d/godot_soft_body_3d.cpp
index 4b3e8cc0d9..b8e9ab4fb9 100644
--- a/servers/physics_3d/godot_soft_body_3d.cpp
+++ b/servers/physics_3d/godot_soft_body_3d.cpp
@@ -917,9 +917,7 @@ void GodotSoftBody3D::add_velocity(const Vector3 &p_velocity) {
}
}
-void GodotSoftBody3D::apply_forces(bool p_has_wind_forces) {
- int ac = areas.size();
-
+void GodotSoftBody3D::apply_forces(const LocalVector<GodotArea3D *> &p_wind_areas) {
if (nodes.is_empty()) {
return;
}
@@ -932,7 +930,6 @@ void GodotSoftBody3D::apply_forces(bool p_has_wind_forces) {
// Iterate over faces (try not to iterate elsewhere if possible).
for (i = 0, ni = faces.size(); i < ni; ++i) {
- bool stopped = false;
const Face &face = faces[i];
Vector3 wind_force(0, 0, 0);
@@ -941,24 +938,10 @@ void GodotSoftBody3D::apply_forces(bool p_has_wind_forces) {
volume += vec3_dot(face.n[0]->x - org, vec3_cross(face.n[1]->x - org, face.n[2]->x - org));
// Compute nodal forces from area winds.
- if (ac && p_has_wind_forces) {
- const AreaCMP *aa = &areas[0];
- for (j = ac - 1; j >= 0 && !stopped; j--) {
- PhysicsServer3D::AreaSpaceOverrideMode mode = aa[j].area->get_space_override_mode();
- switch (mode) {
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE:
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
- wind_force += _compute_area_windforce(aa[j].area, &face);
- stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
- } break;
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE:
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
- wind_force = _compute_area_windforce(aa[j].area, &face);
- stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
- } break;
- default: {
- }
- }
+ int wind_area_count = p_wind_areas.size();
+ if (wind_area_count > 0) {
+ for (j = 0; j < wind_area_count; j++) {
+ wind_force += _compute_area_windforce(p_wind_areas[j], &face);
}
for (j = 0; j < 3; j++) {
@@ -1004,44 +987,59 @@ void GodotSoftBody3D::predict_motion(real_t p_delta) {
ERR_FAIL_COND(!get_space());
- GodotArea3D *def_area = get_space()->get_default_area();
- ERR_FAIL_COND(!def_area);
- gravity = def_area->get_gravity_vector() * def_area->get_gravity();
-
int ac = areas.size();
- bool stopped = false;
- bool has_wind_forces = false;
+
+ bool gravity_done = false;
+
+ LocalVector<GodotArea3D *> wind_areas;
if (ac) {
areas.sort();
const AreaCMP *aa = &areas[0];
- for (int i = ac - 1; i >= 0 && !stopped; i--) {
- // Avoids unnecessary loop in apply_forces().
- has_wind_forces = has_wind_forces || aa[i].area->get_wind_force_magnitude() > CMP_EPSILON;
-
- PhysicsServer3D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
- switch (mode) {
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE:
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
- _compute_area_gravity(aa[i].area);
- stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
- } break;
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE:
- case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
- gravity = Vector3(0, 0, 0);
- _compute_area_gravity(aa[i].area);
- stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
- } break;
- default: {
+ for (int i = ac - 1; i >= 0; i--) {
+ if (!gravity_done) {
+ PhysicsServer3D::AreaSpaceOverrideMode area_gravity_mode = (PhysicsServer3D::AreaSpaceOverrideMode)(int)aa[i].area->get_param(PhysicsServer3D::AREA_PARAM_GRAVITY_OVERRIDE_MODE);
+ if (area_gravity_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
+ Vector3 area_gravity;
+ aa[i].area->compute_gravity(get_transform().get_origin(), area_gravity);
+ switch (area_gravity_mode) {
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ gravity += area_gravity;
+ gravity_done = area_gravity_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ } break;
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ gravity = Vector3(0, 0, 0);
+ gravity = area_gravity;
+ gravity_done = area_gravity_mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
+ } break;
+ default: {
+ }
+ }
}
}
+
+ if (aa[i].area->get_wind_force_magnitude() > CMP_EPSILON) {
+ wind_areas.push_back(aa[i].area);
+ }
}
}
+ // Add default gravity and damping from space area.
+ if (!gravity_done) {
+ GodotArea3D *default_area = get_space()->get_default_area();
+ ERR_FAIL_COND(!default_area);
+
+ Vector3 default_gravity;
+ default_area->compute_gravity(get_transform().get_origin(), default_gravity);
+ gravity += default_gravity;
+ }
+
// Apply forces.
add_velocity(gravity * p_delta);
- if (pressure_coefficient > CMP_EPSILON || has_wind_forces) {
- apply_forces(has_wind_forces);
+ if (pressure_coefficient > CMP_EPSILON || !wind_areas.is_empty()) {
+ apply_forces(wind_areas);
}
// Avoid soft body from 'exploding' so use some upper threshold of maximum motion
@@ -1300,7 +1298,7 @@ struct _SoftBodyIntersectSegmentInfo {
}
};
-bool GodotSoftBodyShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool GodotSoftBodyShape3D::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const {
_SoftBodyIntersectSegmentInfo query_info;
query_info.soft_body = soft_body;
query_info.from = p_begin;
diff --git a/servers/physics_3d/godot_soft_body_3d.h b/servers/physics_3d/godot_soft_body_3d.h
index 008d5dddb8..c03951959f 100644
--- a/servers/physics_3d/godot_soft_body_3d.h
+++ b/servers/physics_3d/godot_soft_body_3d.h
@@ -232,7 +232,7 @@ private:
void add_velocity(const Vector3 &p_velocity);
- void apply_forces(bool p_has_wind_forces);
+ void apply_forces(const LocalVector<GodotArea3D *> &p_wind_areas);
bool create_from_trimesh(const Vector<int> &p_indices, const Vector<Vector3> &p_vertices);
void generate_bending_constraints(int p_distance);
@@ -257,18 +257,18 @@ class GodotSoftBodyShape3D : public GodotShape3D {
public:
GodotSoftBody3D *get_soft_body() const { return soft_body; }
- virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_SOFT_BODY; }
- virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const { r_min = r_max = 0.0; }
- virtual Vector3 get_support(const Vector3 &p_normal) const { return Vector3(); }
- virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const { r_amount = 0; }
+ virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SOFT_BODY; }
+ virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override { r_min = r_max = 0.0; }
+ virtual Vector3 get_support(const Vector3 &p_normal) const override { return Vector3(); }
+ virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
- virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
- virtual bool intersect_point(const Vector3 &p_point) const;
- virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
- virtual Vector3 get_moment_of_inertia(real_t p_mass) const { return Vector3(); }
+ virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, bool p_hit_back_faces) const override;
+ virtual bool intersect_point(const Vector3 &p_point) const override;
+ virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
+ virtual Vector3 get_moment_of_inertia(real_t p_mass) const override { return Vector3(); }
- virtual void set_data(const Variant &p_data) {}
- virtual Variant get_data() const { return Variant(); }
+ virtual void set_data(const Variant &p_data) override {}
+ virtual Variant get_data() const override { return Variant(); }
void update_bounds();
diff --git a/servers/physics_3d/godot_space_3d.cpp b/servers/physics_3d/godot_space_3d.cpp
index 77b37a2353..e2f90b90ad 100644
--- a/servers/physics_3d/godot_space_3d.cpp
+++ b/servers/physics_3d/godot_space_3d.cpp
@@ -148,7 +148,23 @@ bool GodotPhysicsDirectSpaceState3D::intersect_ray(const RayParameters &p_parame
Vector3 shape_point, shape_normal;
- if (shape->intersect_segment(local_from, local_to, shape_point, shape_normal)) {
+ if (shape->intersect_point(local_from)) {
+ if (p_parameters.hit_from_inside) {
+ // Hit shape at starting point.
+ min_d = 0;
+ res_point = local_from;
+ res_normal = Vector3();
+ res_shape = shape_idx;
+ res_obj = col_obj;
+ collided = true;
+ break;
+ } else {
+ // Ignore shape when starting inside.
+ continue;
+ }
+ }
+
+ if (shape->intersect_segment(local_from, local_to, shape_point, shape_normal, p_parameters.hit_back_faces)) {
Transform3D xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
shape_point = xform.xform(shape_point);
diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp
index fa89ccec65..76f0b74c72 100644
--- a/servers/physics_server_2d.cpp
+++ b/servers/physics_server_2d.cpp
@@ -172,12 +172,16 @@ void PhysicsRayQueryParameters2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsRayQueryParameters2D::set_collide_with_areas);
ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsRayQueryParameters2D::is_collide_with_areas_enabled);
+ ClassDB::bind_method(D_METHOD("set_hit_from_inside", "enable"), &PhysicsRayQueryParameters2D::set_hit_from_inside);
+ ClassDB::bind_method(D_METHOD("is_hit_from_inside_enabled"), &PhysicsRayQueryParameters2D::is_hit_from_inside_enabled);
+
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "from"), "set_from", "get_from");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "to"), "set_to", "get_to");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_from_inside"), "set_hit_from_inside", "is_hit_from_inside_enabled");
}
///////////////////////////////////////////////////////
@@ -605,9 +609,6 @@ void PhysicsServer2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &PhysicsServer2D::area_set_space);
ClassDB::bind_method(D_METHOD("area_get_space", "area"), &PhysicsServer2D::area_get_space);
- ClassDB::bind_method(D_METHOD("area_set_space_override_mode", "area", "mode"), &PhysicsServer2D::area_set_space_override_mode);
- ClassDB::bind_method(D_METHOD("area_get_space_override_mode", "area"), &PhysicsServer2D::area_get_space_override_mode);
-
ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform", "disabled"), &PhysicsServer2D::area_add_shape, DEFVAL(Transform2D()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &PhysicsServer2D::area_set_shape);
ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &PhysicsServer2D::area_set_shape_transform);
@@ -751,12 +752,15 @@ void PhysicsServer2D::_bind_methods() {
BIND_ENUM_CONSTANT(SHAPE_CONCAVE_POLYGON);
BIND_ENUM_CONSTANT(SHAPE_CUSTOM);
+ BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_OVERRIDE_MODE);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_DISTANCE_SCALE);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_ATTENUATION);
+ BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
+ BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP);
BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY);
diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h
index fec03a8111..2bff8f5dcb 100644
--- a/servers/physics_server_2d.h
+++ b/servers/physics_server_2d.h
@@ -121,6 +121,8 @@ public:
bool collide_with_bodies = true;
bool collide_with_areas = false;
+
+ bool hit_from_inside = false;
};
struct RayResult {
@@ -264,12 +266,15 @@ public:
//missing attenuation? missing better override?
enum AreaParameter {
+ AREA_PARAM_GRAVITY_OVERRIDE_MODE,
AREA_PARAM_GRAVITY,
AREA_PARAM_GRAVITY_VECTOR,
AREA_PARAM_GRAVITY_IS_POINT,
AREA_PARAM_GRAVITY_DISTANCE_SCALE,
AREA_PARAM_GRAVITY_POINT_ATTENUATION,
+ AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
AREA_PARAM_LINEAR_DAMP,
+ AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
AREA_PARAM_ANGULAR_DAMP,
AREA_PARAM_PRIORITY
};
@@ -287,9 +292,6 @@ public:
AREA_SPACE_OVERRIDE_REPLACE_COMBINE // Discards all previous calculations, then keeps combining
};
- virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) = 0;
- virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const = 0;
-
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0;
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) = 0;
@@ -604,6 +606,9 @@ public:
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
+ void set_hit_from_inside(bool p_enable) { parameters.hit_from_inside = p_enable; }
+ bool is_hit_from_inside_enabled() const { return parameters.hit_from_inside; }
+
void set_exclude(const Vector<RID> &p_exclude);
Vector<RID> get_exclude() const;
};
diff --git a/servers/physics_server_2d_wrap_mt.h b/servers/physics_server_2d_wrap_mt.h
index b133fa41aa..dda4eb6ffa 100644
--- a/servers/physics_server_2d_wrap_mt.h
+++ b/servers/physics_server_2d_wrap_mt.h
@@ -133,9 +133,6 @@ public:
FUNC2(area_set_space, RID, RID);
FUNC1RC(RID, area_get_space, RID);
- FUNC2(area_set_space_override_mode, RID, AreaSpaceOverrideMode);
- FUNC1RC(AreaSpaceOverrideMode, area_get_space_override_mode, RID);
-
FUNC4(area_add_shape, RID, RID, const Transform2D &, bool);
FUNC3(area_set_shape, RID, int, RID);
FUNC3(area_set_shape_transform, RID, int, const Transform2D &);
diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp
index eb52cbfe5a..373f216e01 100644
--- a/servers/physics_server_3d.cpp
+++ b/servers/physics_server_3d.cpp
@@ -175,12 +175,20 @@ void PhysicsRayQueryParameters3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsRayQueryParameters3D::set_collide_with_areas);
ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsRayQueryParameters3D::is_collide_with_areas_enabled);
+ ClassDB::bind_method(D_METHOD("set_hit_from_inside", "enable"), &PhysicsRayQueryParameters3D::set_hit_from_inside);
+ ClassDB::bind_method(D_METHOD("is_hit_from_inside_enabled"), &PhysicsRayQueryParameters3D::is_hit_from_inside_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_hit_back_faces", "enable"), &PhysicsRayQueryParameters3D::set_hit_back_faces);
+ ClassDB::bind_method(D_METHOD("is_hit_back_faces_enabled"), &PhysicsRayQueryParameters3D::is_hit_back_faces_enabled);
+
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "from"), "set_from", "get_from");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "to"), "set_to", "get_to");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude", "get_exclude");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_from_inside"), "set_hit_from_inside", "is_hit_from_inside_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hit_back_faces"), "set_hit_back_faces", "is_hit_back_faces_enabled");
}
///////////////////////////////////////////////////////
@@ -653,9 +661,6 @@ void PhysicsServer3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("area_set_space", "area", "space"), &PhysicsServer3D::area_set_space);
ClassDB::bind_method(D_METHOD("area_get_space", "area"), &PhysicsServer3D::area_get_space);
- ClassDB::bind_method(D_METHOD("area_set_space_override_mode", "area", "mode"), &PhysicsServer3D::area_set_space_override_mode);
- ClassDB::bind_method(D_METHOD("area_get_space_override_mode", "area"), &PhysicsServer3D::area_get_space_override_mode);
-
ClassDB::bind_method(D_METHOD("area_add_shape", "area", "shape", "transform", "disabled"), &PhysicsServer3D::area_add_shape, DEFVAL(Transform3D()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("area_set_shape", "area", "shape_idx", "shape"), &PhysicsServer3D::area_set_shape);
ClassDB::bind_method(D_METHOD("area_set_shape_transform", "area", "shape_idx", "transform"), &PhysicsServer3D::area_set_shape_transform);
@@ -901,12 +906,15 @@ void PhysicsServer3D::_bind_methods() {
BIND_ENUM_CONSTANT(SHAPE_SOFT_BODY);
BIND_ENUM_CONSTANT(SHAPE_CUSTOM);
+ BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_OVERRIDE_MODE);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_VECTOR);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_IS_POINT);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_DISTANCE_SCALE);
BIND_ENUM_CONSTANT(AREA_PARAM_GRAVITY_POINT_ATTENUATION);
+ BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE);
BIND_ENUM_CONSTANT(AREA_PARAM_LINEAR_DAMP);
+ BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE);
BIND_ENUM_CONSTANT(AREA_PARAM_ANGULAR_DAMP);
BIND_ENUM_CONSTANT(AREA_PARAM_PRIORITY);
BIND_ENUM_CONSTANT(AREA_PARAM_WIND_FORCE_MAGNITUDE);
diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h
index b5113fd35f..89a7eeee96 100644
--- a/servers/physics_server_3d.h
+++ b/servers/physics_server_3d.h
@@ -125,6 +125,9 @@ public:
bool collide_with_bodies = true;
bool collide_with_areas = false;
+ bool hit_from_inside = false;
+ bool hit_back_faces = true;
+
bool pick_ray = false;
};
@@ -285,12 +288,15 @@ public:
//missing attenuation? missing better override?
enum AreaParameter {
+ AREA_PARAM_GRAVITY_OVERRIDE_MODE,
AREA_PARAM_GRAVITY,
AREA_PARAM_GRAVITY_VECTOR,
AREA_PARAM_GRAVITY_IS_POINT,
AREA_PARAM_GRAVITY_DISTANCE_SCALE,
AREA_PARAM_GRAVITY_POINT_ATTENUATION,
+ AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
AREA_PARAM_LINEAR_DAMP,
+ AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
AREA_PARAM_ANGULAR_DAMP,
AREA_PARAM_PRIORITY,
AREA_PARAM_WIND_FORCE_MAGNITUDE,
@@ -312,9 +318,6 @@ public:
AREA_SPACE_OVERRIDE_REPLACE_COMBINE
};
- virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) = 0;
- virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const = 0;
-
virtual void area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform = Transform3D(), bool p_disabled = false) = 0;
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) = 0;
@@ -805,6 +808,12 @@ public:
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
+ void set_hit_from_inside(bool p_enable) { parameters.hit_from_inside = p_enable; }
+ bool is_hit_from_inside_enabled() const { return parameters.hit_from_inside; }
+
+ void set_hit_back_faces(bool p_enable) { parameters.hit_back_faces = p_enable; }
+ bool is_hit_back_faces_enabled() const { return parameters.hit_back_faces; }
+
void set_exclude(const Vector<RID> &p_exclude);
Vector<RID> get_exclude() const;
};
diff --git a/servers/physics_server_3d_wrap_mt.h b/servers/physics_server_3d_wrap_mt.h
index df3dc279fe..507427ecec 100644
--- a/servers/physics_server_3d_wrap_mt.h
+++ b/servers/physics_server_3d_wrap_mt.h
@@ -137,9 +137,6 @@ public:
FUNC2(area_set_space, RID, RID);
FUNC1RC(RID, area_get_space, RID);
- FUNC2(area_set_space_override_mode, RID, AreaSpaceOverrideMode);
- FUNC1RC(AreaSpaceOverrideMode, area_get_space_override_mode, RID);
-
FUNC4(area_add_shape, RID, RID, const Transform3D &, bool);
FUNC3(area_set_shape, RID, int, RID);
FUNC3(area_set_shape_transform, RID, int, const Transform3D &);
diff --git a/servers/rendering/rasterizer_dummy.h b/servers/rendering/rasterizer_dummy.h
index 44e07a1853..cecb009aa0 100644
--- a/servers/rendering/rasterizer_dummy.h
+++ b/servers/rendering/rasterizer_dummy.h
@@ -293,8 +293,8 @@ public:
String shader_get_code(RID p_shader) const override { return ""; }
void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const override {}
- void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) override {}
- RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const override { return RID(); }
+ void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) override {}
+ RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const override { return RID(); }
Variant shader_get_param_default(RID p_material, const StringName &p_param) const override { return Variant(); }
RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const override { return RS::ShaderNativeSourceCode(); };
diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
index b74d7f9c31..6ae76c9bf2 100644
--- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
+++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
@@ -336,11 +336,20 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
valid = true;
}
-void SceneShaderForwardClustered::ShaderData::set_default_texture_param(const StringName &p_name, RID p_texture) {
+void SceneShaderForwardClustered::ShaderData::set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) {
if (!p_texture.is_valid()) {
- default_texture_params.erase(p_name);
+ if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
+ default_texture_params[p_name].erase(p_index);
+
+ if (default_texture_params[p_name].is_empty()) {
+ default_texture_params.erase(p_name);
+ }
+ }
} else {
- default_texture_params[p_name] = p_texture;
+ if (!default_texture_params.has(p_name)) {
+ default_texture_params[p_name] = Map<int, RID>();
+ }
+ default_texture_params[p_name][p_index] = p_texture;
}
}
diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h
index b09bd7e065..f2a55939f4 100644
--- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h
+++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h
@@ -135,7 +135,7 @@ public:
uint32_t ubo_size;
String code;
- Map<StringName, RID> default_texture_params;
+ Map<StringName, Map<int, RID>> default_texture_params;
DepthDraw depth_draw;
DepthTest depth_test;
@@ -166,7 +166,7 @@ public:
uint32_t index = 0;
virtual void set_code(const String &p_Code);
- virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
+ virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp
index 16d650a540..3a6c945052 100644
--- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp
+++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp
@@ -325,11 +325,20 @@ void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) {
valid = true;
}
-void SceneShaderForwardMobile::ShaderData::set_default_texture_param(const StringName &p_name, RID p_texture) {
+void SceneShaderForwardMobile::ShaderData::set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) {
if (!p_texture.is_valid()) {
- default_texture_params.erase(p_name);
+ if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
+ default_texture_params[p_name].erase(p_index);
+
+ if (default_texture_params[p_name].is_empty()) {
+ default_texture_params.erase(p_name);
+ }
+ }
} else {
- default_texture_params[p_name] = p_texture;
+ if (!default_texture_params.has(p_name)) {
+ default_texture_params[p_name] = Map<int, RID>();
+ }
+ default_texture_params[p_name][p_index] = p_texture;
}
}
diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h
index e1c10f0206..392fac1e3e 100644
--- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h
+++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h
@@ -111,7 +111,7 @@ public:
uint32_t ubo_size;
String code;
- Map<StringName, RID> default_texture_params;
+ Map<StringName, Map<int, RID>> default_texture_params;
DepthDraw depth_draw;
DepthTest depth_test;
@@ -141,7 +141,7 @@ public:
uint32_t index = 0;
virtual void set_code(const String &p_Code);
- virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
+ virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
index 13a3e814f6..81a662c6eb 100644
--- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
@@ -2120,11 +2120,20 @@ void RendererCanvasRenderRD::ShaderData::set_code(const String &p_code) {
valid = true;
}
-void RendererCanvasRenderRD::ShaderData::set_default_texture_param(const StringName &p_name, RID p_texture) {
+void RendererCanvasRenderRD::ShaderData::set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) {
if (!p_texture.is_valid()) {
- default_texture_params.erase(p_name);
+ if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
+ default_texture_params[p_name].erase(p_index);
+
+ if (default_texture_params[p_name].is_empty()) {
+ default_texture_params.erase(p_name);
+ }
+ }
} else {
- default_texture_params[p_name] = p_texture;
+ if (!default_texture_params.has(p_name)) {
+ default_texture_params[p_name] = Map<int, RID>();
+ }
+ default_texture_params[p_name][p_index] = p_texture;
}
}
diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h
index ec7d7e2854..26ccbd3bf5 100644
--- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h
+++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h
@@ -173,14 +173,14 @@ class RendererCanvasRenderRD : public RendererCanvasRender {
uint32_t ubo_size;
String code;
- Map<StringName, RID> default_texture_params;
+ Map<StringName, Map<int, RID>> default_texture_params;
bool uses_screen_texture = false;
bool uses_sdf = false;
bool uses_time = false;
virtual void set_code(const String &p_Code);
- virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
+ virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp
index 0ca2f051fa..b8e9f40bc4 100644
--- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp
@@ -2086,7 +2086,7 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
ERR_FAIL_COND(!rb);
RendererSceneEnvironmentRD *env = environment_owner.get_or_null(p_render_data->environment);
- //glow (if enabled)
+ // Glow and override exposure (if enabled).
CameraEffects *camfx = camera_effects_owner.get_or_null(p_render_data->camera_effects);
bool can_use_effects = rb->width >= 8 && rb->height >= 8;
@@ -2102,7 +2102,7 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
EffectsRD::BokehBuffers buffers;
- // textures we use
+ // Textures we use.
buffers.base_texture_size = Size2i(rb->width, rb->height);
buffers.base_texture = rb->texture;
buffers.depth_texture = rb->depth_texture;
@@ -2114,7 +2114,7 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
if (can_use_storage) {
storage->get_effects()->bokeh_dof(buffers, camfx->dof_blur_far_enabled, camfx->dof_blur_far_distance, camfx->dof_blur_far_transition, camfx->dof_blur_near_enabled, camfx->dof_blur_near_distance, camfx->dof_blur_near_transition, bokeh_size, dof_blur_bokeh_shape, dof_blur_quality, dof_blur_use_jitter, p_render_data->z_near, p_render_data->z_far, p_render_data->cam_ortogonal);
} else {
- // set framebuffers
+ // Set framebuffers.
buffers.base_fb = rb->texture_fb;
buffers.secondary_fb = rb->weight_buffers[1].fb;
buffers.half_fb[0] = rb->weight_buffers[2].fb;
@@ -2124,7 +2124,7 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
buffers.weight_texture[2] = rb->weight_buffers[2].weight;
buffers.weight_texture[3] = rb->weight_buffers[3].weight;
- // set weight buffers
+ // Set weight buffers.
buffers.base_weight_fb = rb->base_weight_fb;
storage->get_effects()->bokeh_dof_raster(buffers, camfx->dof_blur_far_enabled, camfx->dof_blur_far_distance, camfx->dof_blur_far_transition, camfx->dof_blur_near_enabled, camfx->dof_blur_near_distance, camfx->dof_blur_near_transition, bokeh_size, dof_blur_bokeh_shape, dof_blur_quality, p_render_data->z_near, p_render_data->z_far, p_render_data->cam_ortogonal);
@@ -2147,13 +2147,13 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
} else {
storage->get_effects()->luminance_reduction_raster(rb->texture, Size2i(rb->width, rb->height), rb->luminance.reduce, rb->luminance.fb, rb->luminance.current, env->min_luminance, env->max_luminance, step, set_immediate);
}
- //swap final reduce with prev luminance
+ // Swap final reduce with prev luminance.
SWAP(rb->luminance.current, rb->luminance.reduce.write[rb->luminance.reduce.size() - 1]);
if (!can_use_storage) {
SWAP(rb->luminance.current_fb, rb->luminance.fb.write[rb->luminance.fb.size() - 1]);
}
- RenderingServerDefault::redraw_request(); //redraw all the time if auto exposure rendering is on
+ RenderingServerDefault::redraw_request(); // Redraw all the time if auto exposure rendering is on.
RD::get_singleton()->draw_command_end_label();
}
@@ -2207,7 +2207,6 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
{
RD::get_singleton()->draw_command_begin_label("Tonemap");
- //tonemap
EffectsRD::TonemapSettings tonemap;
if (can_use_effects && env && env->auto_exposure && rb->luminance.current.is_valid()) {
@@ -2246,6 +2245,10 @@ void RendererSceneRenderRD::_render_buffers_post_process_and_tonemap(const Rende
tonemap.exposure = env->exposure;
}
+ if (camfx && camfx->override_exposure_enabled) {
+ tonemap.exposure = camfx->override_exposure;
+ }
+
tonemap.use_color_correction = false;
tonemap.use_1d_color_correction = false;
tonemap.color_correction_texture = storage->texture_rd_get_default(RendererStorageRD::DEFAULT_RD_TEXTURE_3D_WHITE);
@@ -2280,6 +2283,8 @@ void RendererSceneRenderRD::_post_process_subpass(RID p_source_texture, RID p_fr
ERR_FAIL_COND(!rb);
RendererSceneEnvironmentRD *env = environment_owner.get_or_null(p_render_data->environment);
+ // Override exposure (if enabled).
+ CameraEffects *camfx = camera_effects_owner.get_or_null(p_render_data->camera_effects);
bool can_use_effects = rb->width >= 8 && rb->height >= 8;
@@ -2293,6 +2298,10 @@ void RendererSceneRenderRD::_post_process_subpass(RID p_source_texture, RID p_fr
tonemap.white = env->white;
}
+ if (camfx && camfx->override_exposure_enabled) {
+ tonemap.exposure = camfx->override_exposure;
+ }
+
// We don't support glow or auto exposure here, if they are needed, don't use subpasses!
// The problem is that we need to use the result so far and process them before we can
// apply this to our results.
@@ -3549,11 +3558,20 @@ void RendererSceneRenderRD::FogShaderData::set_code(const String &p_code) {
valid = true;
}
-void RendererSceneRenderRD::FogShaderData::set_default_texture_param(const StringName &p_name, RID p_texture) {
+void RendererSceneRenderRD::FogShaderData::set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) {
if (!p_texture.is_valid()) {
- default_texture_params.erase(p_name);
+ if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
+ default_texture_params[p_name].erase(p_index);
+
+ if (default_texture_params[p_name].is_empty()) {
+ default_texture_params.erase(p_name);
+ }
+ }
} else {
- default_texture_params[p_name] = p_texture;
+ if (!default_texture_params.has(p_name)) {
+ default_texture_params[p_name] = Map<int, RID>();
+ }
+ default_texture_params[p_name][p_index] = p_texture;
}
}
diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h
index baa0144d43..740e0e75ce 100644
--- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h
+++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h
@@ -879,12 +879,12 @@ private:
String path;
String code;
- Map<StringName, RID> default_texture_params;
+ Map<StringName, Map<int, RID>> default_texture_params;
bool uses_time;
virtual void set_code(const String &p_Code);
- virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
+ virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
virtual bool is_param_texture(const StringName &p_param) const;
diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp
index ce41e191e2..a9c39fb937 100644
--- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp
@@ -137,11 +137,20 @@ void RendererSceneSkyRD::SkyShaderData::set_code(const String &p_code) {
valid = true;
}
-void RendererSceneSkyRD::SkyShaderData::set_default_texture_param(const StringName &p_name, RID p_texture) {
+void RendererSceneSkyRD::SkyShaderData::set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) {
if (!p_texture.is_valid()) {
- default_texture_params.erase(p_name);
+ if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
+ default_texture_params[p_name].erase(p_index);
+
+ if (default_texture_params[p_name].is_empty()) {
+ default_texture_params.erase(p_name);
+ }
+ }
} else {
- default_texture_params[p_name] = p_texture;
+ if (!default_texture_params.has(p_name)) {
+ default_texture_params[p_name] = Map<int, RID>();
+ }
+ default_texture_params[p_name][p_index] = p_texture;
}
}
diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h
index 7f563c9bc4..8689395bea 100644
--- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h
+++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h
@@ -118,7 +118,7 @@ private:
String path;
String code;
- Map<StringName, RID> default_texture_params;
+ Map<StringName, Map<int, RID>> default_texture_params;
bool uses_time;
bool uses_position;
@@ -127,7 +127,7 @@ private:
bool uses_light;
virtual void set_code(const String &p_Code);
- virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
+ virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
virtual bool is_param_texture(const StringName &p_param) const;
diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp
index 5c7fee7ec9..64be176d24 100644
--- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp
@@ -1440,8 +1440,10 @@ void RendererStorageRD::shader_set_code(RID p_shader, const String &p_code) {
}
if (shader->data) {
- for (const KeyValue<StringName, RID> &E : shader->default_texture_parameter) {
- shader->data->set_default_texture_param(E.key, E.value);
+ for (const KeyValue<StringName, Map<int, RID>> &E : shader->default_texture_parameter) {
+ for (const KeyValue<int, RID> &E2 : E.value) {
+ shader->data->set_default_texture_param(E.key, E2.value, E2.key);
+ }
}
}
}
@@ -1471,17 +1473,26 @@ void RendererStorageRD::shader_get_param_list(RID p_shader, List<PropertyInfo> *
}
}
-void RendererStorageRD::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
+void RendererStorageRD::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) {
Shader *shader = shader_owner.get_or_null(p_shader);
ERR_FAIL_COND(!shader);
if (p_texture.is_valid() && texture_owner.owns(p_texture)) {
- shader->default_texture_parameter[p_name] = p_texture;
+ if (!shader->default_texture_parameter.has(p_name)) {
+ shader->default_texture_parameter[p_name] = Map<int, RID>();
+ }
+ shader->default_texture_parameter[p_name][p_index] = p_texture;
} else {
- shader->default_texture_parameter.erase(p_name);
+ if (shader->default_texture_parameter.has(p_name) && shader->default_texture_parameter[p_name].has(p_index)) {
+ shader->default_texture_parameter[p_name].erase(p_index);
+
+ if (shader->default_texture_parameter[p_name].is_empty()) {
+ shader->default_texture_parameter.erase(p_name);
+ }
+ }
}
if (shader->data) {
- shader->data->set_default_texture_param(p_name, p_texture);
+ shader->data->set_default_texture_param(p_name, p_texture, p_index);
}
for (Set<Material *>::Element *E = shader->owners.front(); E; E = E->next()) {
Material *material = E->get();
@@ -1489,11 +1500,11 @@ void RendererStorageRD::shader_set_default_texture_param(RID p_shader, const Str
}
}
-RID RendererStorageRD::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
+RID RendererStorageRD::shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const {
Shader *shader = shader_owner.get_or_null(p_shader);
ERR_FAIL_COND_V(!shader, RID());
- if (shader->default_texture_parameter.has(p_name)) {
- return shader->default_texture_parameter[p_name];
+ if (shader->default_texture_parameter.has(p_name) && shader->default_texture_parameter[p_name].has(p_index)) {
+ return shader->default_texture_parameter[p_name][p_index];
}
return RID();
@@ -2610,7 +2621,7 @@ RendererStorageRD::MaterialData::~MaterialData() {
}
}
-void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, RID> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color) {
+void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color) {
RendererStorageRD *singleton = (RendererStorageRD *)RendererStorage::base_singleton;
#ifdef TOOLS_ENABLED
Texture *roughness_detect_texture = nullptr;
@@ -2673,19 +2684,19 @@ void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Vari
if (uniform_array_size > 0) {
if (textures.size() < uniform_array_size) {
- const Map<StringName, RID>::Element *W = p_default_textures.find(uniform_name);
+ const Map<StringName, Map<int, RID>>::Element *W = p_default_textures.find(uniform_name);
for (int j = textures.size(); j < uniform_array_size; j++) {
- if (W) {
- textures.push_back(W->get());
+ if (W && W->get().has(j)) {
+ textures.push_back(W->get()[j]);
} else {
textures.push_back(RID());
}
}
}
} else if (textures.is_empty()) {
- const Map<StringName, RID>::Element *W = p_default_textures.find(uniform_name);
- if (W) {
- textures.push_back(W->get());
+ const Map<StringName, Map<int, RID>>::Element *W = p_default_textures.find(uniform_name);
+ if (W && W->get().has(0)) {
+ textures.push_back(W->get()[0]);
}
}
}
@@ -2833,7 +2844,7 @@ void RendererStorageRD::MaterialData::free_parameters_uniform_set(RID p_uniform_
}
}
-bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, RID> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier) {
+bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier) {
if ((uint32_t)ubo_data.size() != p_ubo_size) {
p_uniform_dirty = true;
if (uniform_buffer.is_valid()) {
@@ -5748,11 +5759,20 @@ void RendererStorageRD::ParticlesShaderData::set_code(const String &p_code) {
valid = true;
}
-void RendererStorageRD::ParticlesShaderData::set_default_texture_param(const StringName &p_name, RID p_texture) {
+void RendererStorageRD::ParticlesShaderData::set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) {
if (!p_texture.is_valid()) {
- default_texture_params.erase(p_name);
+ if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
+ default_texture_params[p_name].erase(p_index);
+
+ if (default_texture_params[p_name].is_empty()) {
+ default_texture_params.erase(p_name);
+ }
+ }
} else {
- default_texture_params[p_name] = p_texture;
+ if (!default_texture_params.has(p_name)) {
+ default_texture_params[p_name] = Map<int, RID>();
+ }
+ default_texture_params[p_name][p_index] = p_texture;
}
}
diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.h b/servers/rendering/renderer_rd/renderer_storage_rd.h
index f13bd4a7f4..2cd3a01c66 100644
--- a/servers/rendering/renderer_rd/renderer_storage_rd.h
+++ b/servers/rendering/renderer_rd/renderer_storage_rd.h
@@ -135,7 +135,7 @@ public:
struct ShaderData {
virtual void set_code(const String &p_Code) = 0;
- virtual void set_default_texture_param(const StringName &p_name, RID p_texture) = 0;
+ virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) = 0;
virtual void get_param_list(List<PropertyInfo> *p_param_list) const = 0;
virtual void get_instance_param_list(List<InstanceShaderParam> *p_param_list) const = 0;
@@ -152,7 +152,7 @@ public:
struct MaterialData {
void update_uniform_buffer(const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Map<StringName, Variant> &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color);
- void update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, RID> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color);
+ void update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color);
virtual void set_render_priority(int p_priority) = 0;
virtual void set_next_pass(RID p_pass) = 0;
@@ -160,7 +160,7 @@ public:
virtual ~MaterialData();
//to be used internally by update_parameters, in the most common configuration of material parameters
- bool update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, RID> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
+ bool update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
void free_parameters_uniform_set(RID p_uniform_set);
private:
@@ -374,7 +374,7 @@ private:
ShaderData *data;
String code;
ShaderType type;
- Map<StringName, RID> default_texture_parameter;
+ Map<StringName, Map<int, RID>> default_texture_parameter;
Set<Material *> owners;
};
@@ -883,14 +883,14 @@ private:
String path;
String code;
- Map<StringName, RID> default_texture_params;
+ Map<StringName, Map<int, RID>> default_texture_params;
RID pipeline;
bool uses_time;
virtual void set_code(const String &p_Code);
- virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
+ virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const;
virtual bool is_param_texture(const StringName &p_param) const;
@@ -1414,8 +1414,8 @@ public:
String shader_get_code(RID p_shader) const;
void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
- void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture);
- RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const;
+ void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index);
+ RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const;
Variant shader_get_param_default(RID p_shader, const StringName &p_param) const;
void shader_set_data_request_function(ShaderType p_shader_type, ShaderDataRequestFunction p_function);
diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl
index 4119e98d15..83c02d08a7 100644
--- a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl
+++ b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl
@@ -1529,7 +1529,7 @@ void main() {
float size_A = sc_use_light_soft_shadows ? directional_lights.data[i].size : 0.0;
- light_compute(normal, directional_lights.data[i].direction, normalize(view), size_A, directional_lights.data[i].color * directional_lights.data[i].energy, shadow, f0, orms, 1.0,
+ light_compute(normal, directional_lights.data[i].direction, normalize(view), size_A, directional_lights.data[i].color * directional_lights.data[i].energy, shadow, f0, orms, 1.0, albedo, alpha,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
@@ -1540,7 +1540,7 @@ void main() {
transmittance_z,
#endif
#ifdef LIGHT_RIM_USED
- rim, rim_tint, albedo,
+ rim, rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -1548,9 +1548,6 @@ void main() {
#ifdef LIGHT_ANISOTROPY_USED
binormal, tangent, anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- alpha,
-#endif
diffuse_light,
specular_light);
}
@@ -1603,7 +1600,7 @@ void main() {
shadow = blur_shadow(shadow);
- light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow,
+ light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
@@ -1615,7 +1612,6 @@ void main() {
#ifdef LIGHT_RIM_USED
rim,
rim_tint,
- albedo,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -1623,9 +1619,6 @@ void main() {
#ifdef LIGHT_ANISOTROPY_USED
tangent, binormal, anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- alpha,
-#endif
diffuse_light, specular_light);
}
}
@@ -1679,7 +1672,7 @@ void main() {
shadow = blur_shadow(shadow);
- light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow,
+ light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
@@ -1691,7 +1684,6 @@ void main() {
#ifdef LIGHT_RIM_USED
rim,
rim_tint,
- albedo,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -1699,9 +1691,6 @@ void main() {
#ifdef LIGHT_ANISOTROPY_USED
tangent, binormal, anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- alpha,
-#endif
diffuse_light, specular_light);
}
}
diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
index b26489ddf1..d22f936a35 100644
--- a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
+++ b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl
@@ -73,7 +73,7 @@ vec3 F0(float metallic, float specular, vec3 albedo) {
return mix(vec3(dielectric), albedo, vec3(metallic));
}
-void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float attenuation, vec3 f0, uint orms, float specular_amount,
+void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float attenuation, vec3 f0, uint orms, float specular_amount, vec3 albedo, inout float alpha,
#ifdef LIGHT_BACKLIGHT_USED
vec3 backlight,
#endif
@@ -84,7 +84,7 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float atte
float transmittance_z,
#endif
#ifdef LIGHT_RIM_USED
- float rim, float rim_tint, vec3 rim_color,
+ float rim, float rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
float clearcoat, float clearcoat_gloss,
@@ -92,9 +92,6 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float atte
#ifdef LIGHT_ANISOTROPY_USED
vec3 B, vec3 T, float anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- inout float alpha,
-#endif
inout vec3 diffuse_light, inout vec3 specular_light) {
vec4 orms_unpacked = unpackUnorm4x8(orms);
@@ -171,7 +168,7 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float atte
#if defined(LIGHT_RIM_USED)
float rim_light = pow(max(0.0, 1.0 - cNdotV), max(0.0, (1.0 - roughness) * 16.0));
- diffuse_light += rim_light * rim * mix(vec3(1.0), rim_color, rim_tint) * light_color;
+ diffuse_light += rim_light * rim * mix(vec3(1.0), albedo, rim_tint) * light_color;
#endif
#ifdef LIGHT_TRANSMITTANCE_USED
@@ -577,7 +574,7 @@ float light_process_omni_shadow(uint idx, vec3 vertex, vec3 normal) {
return 1.0;
}
-void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 vertex_ddx, vec3 vertex_ddy, vec3 f0, uint orms, float shadow,
+void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 vertex_ddx, vec3 vertex_ddy, vec3 f0, uint orms, float shadow, vec3 albedo, inout float alpha,
#ifdef LIGHT_BACKLIGHT_USED
vec3 backlight,
#endif
@@ -587,7 +584,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
float transmittance_boost,
#endif
#ifdef LIGHT_RIM_USED
- float rim, float rim_tint, vec3 rim_color,
+ float rim, float rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
float clearcoat, float clearcoat_gloss,
@@ -595,9 +592,6 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
#ifdef LIGHT_ANISOTROPY_USED
vec3 binormal, vec3 tangent, float anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- inout float alpha,
-#endif
inout vec3 diffuse_light, inout vec3 specular_light) {
vec3 light_rel_vec = omni_lights.data[idx].position - vertex;
float light_length = length(light_rel_vec);
@@ -703,7 +697,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
light_attenuation *= shadow;
- light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, light_attenuation, f0, orms, omni_lights.data[idx].specular_amount,
+ light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, light_attenuation, f0, orms, omni_lights.data[idx].specular_amount, albedo, alpha,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
@@ -714,7 +708,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
transmittance_z,
#endif
#ifdef LIGHT_RIM_USED
- rim * omni_attenuation, rim_tint, rim_color,
+ rim * omni_attenuation, rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -722,9 +716,6 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
#ifdef LIGHT_ANISOTROPY_USED
binormal, tangent, anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- alpha,
-#endif
diffuse_light,
specular_light);
}
@@ -823,7 +814,7 @@ vec2 normal_to_panorama(vec3 n) {
return panorama_coords;
}
-void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 vertex_ddx, vec3 vertex_ddy, vec3 f0, uint orms, float shadow,
+void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 vertex_ddx, vec3 vertex_ddy, vec3 f0, uint orms, float shadow, vec3 albedo, inout float alpha,
#ifdef LIGHT_BACKLIGHT_USED
vec3 backlight,
#endif
@@ -833,7 +824,7 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
float transmittance_boost,
#endif
#ifdef LIGHT_RIM_USED
- float rim, float rim_tint, vec3 rim_color,
+ float rim, float rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
float clearcoat, float clearcoat_gloss,
@@ -841,9 +832,6 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
#ifdef LIGHT_ANISOTROPY_USED
vec3 binormal, vec3 tangent, float anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- inout float alpha,
-#endif
inout vec3 diffuse_light,
inout vec3 specular_light) {
vec3 light_rel_vec = spot_lights.data[idx].position - vertex;
@@ -910,7 +898,7 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
}
light_attenuation *= shadow;
- light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, light_attenuation, f0, orms, spot_lights.data[idx].specular_amount,
+ light_compute(normal, normalize(light_rel_vec), eye_vec, size_A, color, light_attenuation, f0, orms, spot_lights.data[idx].specular_amount, albedo, alpha,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
@@ -921,7 +909,7 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
transmittance_z,
#endif
#ifdef LIGHT_RIM_USED
- rim * spot_attenuation, rim_tint, rim_color,
+ rim * spot_attenuation, rim_tint,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -929,9 +917,6 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v
#ifdef LIGHT_ANISOTROPY_USED
binormal, tangent, anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- alpha,
-#endif
diffuse_light, specular_light);
}
diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl
index 2f5cc58619..e2fec87d2a 100644
--- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl
+++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl
@@ -1395,7 +1395,7 @@ void main() {
shadow = blur_shadow(shadow);
- light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow,
+ light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
@@ -1409,7 +1409,6 @@ void main() {
#ifdef LIGHT_RIM_USED
rim,
rim_tint,
- albedo,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -1417,9 +1416,6 @@ void main() {
#ifdef LIGHT_ANISOTROPY_USED
tangent, binormal, anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- alpha,
-#endif
diffuse_light, specular_light);
}
} //omni lights
@@ -1443,7 +1439,7 @@ void main() {
shadow = blur_shadow(shadow);
- light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow,
+ light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
@@ -1457,7 +1453,6 @@ void main() {
#ifdef LIGHT_RIM_USED
rim,
rim_tint,
- albedo,
#endif
#ifdef LIGHT_CLEARCOAT_USED
clearcoat, clearcoat_gloss,
@@ -1465,9 +1460,6 @@ void main() {
#ifdef LIGHT_ANISOTROPY_USED
tangent, binormal, anisotropy,
#endif
-#ifdef USE_SHADOW_TO_OPACITY
- alpha,
-#endif
diffuse_light, specular_light);
}
} //spot lights
diff --git a/servers/rendering/renderer_storage.h b/servers/rendering/renderer_storage.h
index 2985e05e8f..8926bf24aa 100644
--- a/servers/rendering/renderer_storage.h
+++ b/servers/rendering/renderer_storage.h
@@ -183,8 +183,8 @@ public:
virtual String shader_get_code(RID p_shader) const = 0;
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const = 0;
- virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) = 0;
- virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const = 0;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) = 0;
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const = 0;
virtual Variant shader_get_param_default(RID p_material, const StringName &p_param) const = 0;
virtual RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const = 0;
diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h
index 9a592a9265..f75bca600e 100644
--- a/servers/rendering/rendering_server_default.h
+++ b/servers/rendering/rendering_server_default.h
@@ -223,8 +223,8 @@ public:
FUNC2SC(shader_get_param_list, RID, List<PropertyInfo> *)
- FUNC3(shader_set_default_texture_param, RID, const StringName &, RID)
- FUNC2RC(RID, shader_get_default_texture_param, RID, const StringName &)
+ FUNC4(shader_set_default_texture_param, RID, const StringName &, RID, int)
+ FUNC3RC(RID, shader_get_default_texture_param, RID, const StringName &, int)
FUNC2RC(Variant, shader_get_param_default, RID, const StringName &)
FUNC1RC(ShaderNativeSourceCode, shader_get_native_source_code, RID)
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index cdf7fa530e..ae72f47a44 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -1716,8 +1716,8 @@ void RenderingServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("shader_get_param_list", "shader"), &RenderingServer::_shader_get_param_list);
ClassDB::bind_method(D_METHOD("shader_get_param_default", "shader", "param"), &RenderingServer::shader_get_param_default);
- ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "param", "texture"), &RenderingServer::shader_set_default_texture_param);
- ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "param"), &RenderingServer::shader_get_default_texture_param);
+ ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "param", "texture", "index"), &RenderingServer::shader_set_default_texture_param, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "param", "index"), &RenderingServer::shader_get_default_texture_param, DEFVAL(0));
BIND_ENUM_CONSTANT(SHADER_SPATIAL);
BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM);
diff --git a/servers/rendering_server.h b/servers/rendering_server.h
index f35a633bf3..32ec0197ee 100644
--- a/servers/rendering_server.h
+++ b/servers/rendering_server.h
@@ -172,8 +172,8 @@ public:
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const = 0;
virtual Variant shader_get_param_default(RID p_shader, const StringName &p_param) const = 0;
- virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) = 0;
- virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const = 0;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index = 0) = 0;
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index = 0) const = 0;
struct ShaderNativeSourceCode {
struct Version {
diff --git a/tests/SCsub b/tests/SCsub
index 0f3c14f0bd..31466fffc1 100644
--- a/tests/SCsub
+++ b/tests/SCsub
@@ -22,6 +22,11 @@ if env_tests["platform"] == "windows":
if env_tests.msvc:
env_tests.Append(CCFLAGS=["/bigobj"])
+env_tests.add_source_files(env.tests_sources, "core/*.cpp")
+env_tests.add_source_files(env.tests_sources, "core/math/*.cpp")
+env_tests.add_source_files(env.tests_sources, "core/templates/*.cpp")
+env_tests.add_source_files(env.tests_sources, "scene/*.cpp")
+env_tests.add_source_files(env.tests_sources, "servers/*.cpp")
env_tests.add_source_files(env.tests_sources, "*.cpp")
lib = env_tests.add_library("tests", env.tests_sources)
diff --git a/tests/test_config_file.h b/tests/core/io/test_config_file.h
index e3f40e16fd..f6fbaf9a88 100644
--- a/tests/test_config_file.h
+++ b/tests/core/io/test_config_file.h
@@ -32,6 +32,7 @@
#define TEST_CONFIG_FILE_H
#include "core/io/config_file.h"
+#include "core/os/os.h"
#include "tests/test_macros.h"
diff --git a/tests/test_file_access.h b/tests/core/io/test_file_access.h
index b3da16c1d1..4ffc57afe4 100644
--- a/tests/test_file_access.h
+++ b/tests/core/io/test_file_access.h
@@ -32,7 +32,8 @@
#define TEST_FILE_ACCESS_H
#include "core/io/file_access.h"
-#include "test_utils.h"
+#include "tests/test_macros.h"
+#include "tests/test_utils.h"
namespace TestFileAccess {
diff --git a/tests/test_image.h b/tests/core/io/test_image.h
index 99c2a9380d..c4c5f1e18b 100644
--- a/tests/test_image.h
+++ b/tests/core/io/test_image.h
@@ -31,10 +31,10 @@
#ifndef TEST_IMAGE_H
#define TEST_IMAGE_H
-#include "core/io/file_access_pack.h"
#include "core/io/image.h"
-#include "test_utils.h"
+#include "core/os/os.h"
+#include "tests/test_utils.h"
#include "thirdparty/doctest/doctest.h"
namespace TestImage {
diff --git a/tests/test_json.h b/tests/core/io/test_json.h
index 3af58dfa1c..3af58dfa1c 100644
--- a/tests/test_json.h
+++ b/tests/core/io/test_json.h
diff --git a/tests/test_marshalls.h b/tests/core/io/test_marshalls.h
index 6bd916164e..6bd916164e 100644
--- a/tests/test_marshalls.h
+++ b/tests/core/io/test_marshalls.h
diff --git a/tests/test_pck_packer.h b/tests/core/io/test_pck_packer.h
index 06e4e64963..ae51d58522 100644
--- a/tests/test_pck_packer.h
+++ b/tests/core/io/test_pck_packer.h
@@ -35,6 +35,7 @@
#include "core/io/pck_packer.h"
#include "core/os/os.h"
+#include "tests/test_utils.h"
#include "thirdparty/doctest/doctest.h"
namespace TestPCKPacker {
diff --git a/tests/test_resource.h b/tests/core/io/test_resource.h
index cee3281995..cee3281995 100644
--- a/tests/test_resource.h
+++ b/tests/core/io/test_resource.h
diff --git a/tests/test_xml_parser.h b/tests/core/io/test_xml_parser.h
index 55de048d6a..2d00f29ddf 100644
--- a/tests/test_xml_parser.h
+++ b/tests/core/io/test_xml_parser.h
@@ -31,10 +31,7 @@
#ifndef TEST_XML_PARSER_H
#define TEST_XML_PARSER_H
-#include <inttypes.h>
-
#include "core/io/xml_parser.h"
-#include "core/string/ustring.h"
#include "tests/test_macros.h"
diff --git a/tests/test_aabb.h b/tests/core/math/test_aabb.h
index 0312e185a1..b838bed171 100644
--- a/tests/test_aabb.h
+++ b/tests/core/math/test_aabb.h
@@ -32,10 +32,8 @@
#define TEST_AABB_H
#include "core/math/aabb.h"
-#include "core/string/print_string.h"
-#include "tests/test_macros.h"
-#include "thirdparty/doctest/doctest.h"
+#include "tests/test_macros.h"
namespace TestAABB {
diff --git a/tests/test_astar.h b/tests/core/math/test_astar.h
index 137c477946..2c183374ac 100644
--- a/tests/test_astar.h
+++ b/tests/core/math/test_astar.h
@@ -32,11 +32,6 @@
#define TEST_ASTAR_H
#include "core/math/a_star.h"
-#include "core/math/math_funcs.h"
-#include "core/os/os.h"
-
-#include <math.h>
-#include <stdio.h>
#include "tests/test_macros.h"
diff --git a/tests/test_basis.h b/tests/core/math/test_basis.h
index b254d9fb7f..500c069a33 100644
--- a/tests/test_basis.h
+++ b/tests/core/math/test_basis.h
@@ -31,9 +31,8 @@
#ifndef TEST_BASIS_H
#define TEST_BASIS_H
+#include "core/math/basis.h"
#include "core/math/random_number_generator.h"
-#include "core/os/os.h"
-#include "core/string/ustring.h"
#include "tests/test_macros.h"
diff --git a/tests/test_color.h b/tests/core/math/test_color.h
index bffa890ae2..82cf786f7a 100644
--- a/tests/test_color.h
+++ b/tests/core/math/test_color.h
@@ -33,7 +33,7 @@
#include "core/math/color.h"
-#include "thirdparty/doctest/doctest.h"
+#include "tests/test_macros.h"
namespace TestColor {
diff --git a/tests/test_expression.h b/tests/core/math/test_expression.h
index cb1d29389f..cb1d29389f 100644
--- a/tests/test_expression.h
+++ b/tests/core/math/test_expression.h
diff --git a/tests/test_geometry_2d.h b/tests/core/math/test_geometry_2d.h
index 25af8c355e..8f6669b572 100644
--- a/tests/test_geometry_2d.h
+++ b/tests/core/math/test_geometry_2d.h
@@ -32,7 +32,6 @@
#define TEST_GEOMETRY_2D_H
#include "core/math/geometry_2d.h"
-#include "core/templates/vector.h"
#include "thirdparty/doctest/doctest.h"
diff --git a/tests/test_geometry_3d.h b/tests/core/math/test_geometry_3d.h
index ae30737fe2..f42003ffcf 100644
--- a/tests/test_geometry_3d.h
+++ b/tests/core/math/test_geometry_3d.h
@@ -32,11 +32,7 @@
#define TEST_GEOMETRY_3D_H
#include "core/math/geometry_3d.h"
-#include "core/math/plane.h"
-#include "core/math/random_number_generator.h"
-#include "core/math/vector3.h"
#include "tests/test_macros.h"
-#include "vector"
namespace TestGeometry3D {
TEST_CASE("[Geometry3D] Closest Points Between Segments") {
diff --git a/tests/test_math.cpp b/tests/core/math/test_math.cpp
index 72272382ce..6ec9bc2473 100644
--- a/tests/test_math.cpp
+++ b/tests/core/math/test_math.cpp
@@ -30,23 +30,11 @@
#include "test_math.h"
-#include "core/io/file_access.h"
-#include "core/math/basis.h"
#include "core/math/camera_matrix.h"
#include "core/math/delaunay_3d.h"
#include "core/math/geometry_2d.h"
-#include "core/math/math_funcs.h"
-#include "core/math/transform_3d.h"
-#include "core/os/keyboard.h"
+#include "core/os/main_loop.h"
#include "core/os/os.h"
-#include "core/string/print_string.h"
-#include "core/string/ustring.h"
-#include "core/templates/vmap.h"
-#include "core/variant/method_ptrcall.h"
-#include "core/variant/variant.h"
-#include "scene/main/node.h"
-#include "scene/resources/texture.h"
-#include "servers/rendering/shader_language.h"
namespace TestMath {
diff --git a/tests/test_math.h b/tests/core/math/test_math.h
index 4375925bd5..ab5fb6a050 100644
--- a/tests/test_math.h
+++ b/tests/core/math/test_math.h
@@ -31,7 +31,7 @@
#ifndef TEST_MATH_H
#define TEST_MATH_H
-#include "core/os/main_loop.h"
+class MainLoop;
namespace TestMath {
diff --git a/tests/test_random_number_generator.h b/tests/core/math/test_random_number_generator.h
index 39c4771c19..39c4771c19 100644
--- a/tests/test_random_number_generator.h
+++ b/tests/core/math/test_random_number_generator.h
diff --git a/tests/test_rect2.h b/tests/core/math/test_rect2.h
index 3d9fe5a32e..aabb950461 100644
--- a/tests/test_rect2.h
+++ b/tests/core/math/test_rect2.h
@@ -211,26 +211,74 @@ TEST_CASE("[Rect2] Growing") {
}
TEST_CASE("[Rect2] Has point") {
+ Rect2 rect = Rect2(0, 100, 1280, 720);
CHECK_MESSAGE(
- Rect2(0, 100, 1280, 720).has_point(Vector2(500, 600)),
+ rect.has_point(Vector2(500, 600)),
"has_point() with contained Vector2 should return the expected result.");
CHECK_MESSAGE(
- !Rect2(0, 100, 1280, 720).has_point(Vector2(0, 0)),
+ !rect.has_point(Vector2(0, 0)),
"has_point() with non-contained Vector2 should return the expected result.");
CHECK_MESSAGE(
- Rect2(0, 100, 1280, 720).has_point(Vector2(0, 110)),
- "has_point() with positive Vector2 on left edge should return the expected result.");
+ rect.has_point(rect.position),
+ "has_point() with positive size should include `position`.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2(1, 1)),
+ "has_point() with positive size should include `position + (1, 1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2(1, -1)),
+ "has_point() with positive size should not include `position + (1, -1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size),
+ "has_point() with positive size should not include `position + size`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size + Vector2(1, 1)),
+ "has_point() with positive size should not include `position + size + (1, 1)`.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + rect.size + Vector2(-1, -1)),
+ "has_point() with positive size should include `position + size + (-1, -1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size + Vector2(-1, 1)),
+ "has_point() with positive size should not include `position + size + (-1, 1)`.");
+
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2(0, 10)),
+ "has_point() with point located on left edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2(rect.size.x, 10)),
+ "has_point() with point located on right edge should return false.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2(10, 0)),
+ "has_point() with point located on top edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2(10, rect.size.y)),
+ "has_point() with point located on bottom edge should return false.");
+
+ /*
+ // FIXME: Disabled for now until GH-37617 is fixed one way or another.
+ // More tests should then be written like for the positive size case.
+ rect = Rect2(0, 100, -1280, -720);
+ CHECK_MESSAGE(
+ rect.has_point(rect.position),
+ "has_point() with negative size should include `position`.");
CHECK_MESSAGE(
- !Rect2(0, 100, 1280, 720).has_point(Vector2(1280, 110)),
- "has_point() with positive Vector2 on right edge should return the expected result.");
+ !rect.has_point(rect.position + rect.size),
+ "has_point() with negative size should not include `position + size`.");
+ */
+ rect = Rect2(-4000, -200, 1280, 720);
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2(0, 10)),
+ "has_point() with negative position and point located on left edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2(rect.size.x, 10)),
+ "has_point() with negative position and point located on right edge should return false.");
CHECK_MESSAGE(
- Rect2(-4000, 100, 1280, 720).has_point(Vector2(-4000, 110)),
- "has_point() with negative Vector2 on left edge should return the expected result.");
+ rect.has_point(rect.position + Vector2(10, 0)),
+ "has_point() with negative position and point located on top edge should return true.");
CHECK_MESSAGE(
- !Rect2(-4000, 100, 1280, 720).has_point(Vector2(-2720, 110)),
- "has_point() with negative Vector2 on right edge should return the expected result.");
+ !rect.has_point(rect.position + Vector2(10, rect.size.y)),
+ "has_point() with negative position and point located on bottom edge should return false.");
}
TEST_CASE("[Rect2] Intersection") {
@@ -429,26 +477,74 @@ TEST_CASE("[Rect2i] Growing") {
}
TEST_CASE("[Rect2i] Has point") {
+ Rect2i rect = Rect2i(0, 100, 1280, 720);
CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).has_point(Vector2i(500, 600)),
+ rect.has_point(Vector2i(500, 600)),
"has_point() with contained Vector2i should return the expected result.");
CHECK_MESSAGE(
- !Rect2i(0, 100, 1280, 720).has_point(Vector2i(0, 0)),
+ !rect.has_point(Vector2i(0, 0)),
"has_point() with non-contained Vector2i should return the expected result.");
CHECK_MESSAGE(
- Rect2i(0, 100, 1280, 720).has_point(Vector2(0, 110)),
- "has_point() with positive Vector2 on left edge should return the expected result.");
+ rect.has_point(rect.position),
+ "has_point() with positive size should include `position`.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(1, 1)),
+ "has_point() with positive size should include `position + (1, 1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(1, -1)),
+ "has_point() with positive size should not include `position + (1, -1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size),
+ "has_point() with positive size should not include `position + size`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size + Vector2i(1, 1)),
+ "has_point() with positive size should not include `position + size + (1, 1)`.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + rect.size + Vector2i(-1, -1)),
+ "has_point() with positive size should include `position + size + (-1, -1)`.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + rect.size + Vector2i(-1, 1)),
+ "has_point() with positive size should not include `position + size + (-1, 1)`.");
+
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(0, 10)),
+ "has_point() with point located on left edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(rect.size.x, 10)),
+ "has_point() with point located on right edge should return false.");
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(10, 0)),
+ "has_point() with point located on top edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(10, rect.size.y)),
+ "has_point() with point located on bottom edge should return false.");
+
+ /*
+ // FIXME: Disabled for now until GH-37617 is fixed one way or another.
+ // More tests should then be written like for the positive size case.
+ rect = Rect2i(0, 100, -1280, -720);
+ CHECK_MESSAGE(
+ rect.has_point(rect.position),
+ "has_point() with negative size should include `position`.");
CHECK_MESSAGE(
- !Rect2i(0, 100, 1280, 720).has_point(Vector2(1280, 110)),
- "has_point() with positive Vector2 on right edge should return the expected result.");
+ !rect.has_point(rect.position + rect.size),
+ "has_point() with negative size should not include `position + size`.");
+ */
+ rect = Rect2i(-4000, -200, 1280, 720);
+ CHECK_MESSAGE(
+ rect.has_point(rect.position + Vector2i(0, 10)),
+ "has_point() with negative position and point located on left edge should return true.");
+ CHECK_MESSAGE(
+ !rect.has_point(rect.position + Vector2i(rect.size.x, 10)),
+ "has_point() with negative position and point located on right edge should return false.");
CHECK_MESSAGE(
- Rect2i(-4000, 100, 1280, 720).has_point(Vector2(-4000, 110)),
- "has_point() with negative Vector2 on left edge should return the expected result.");
+ rect.has_point(rect.position + Vector2i(10, 0)),
+ "has_point() with negative position and point located on top edge should return true.");
CHECK_MESSAGE(
- !Rect2i(-4000, 100, 1280, 720).has_point(Vector2(-2720, 110)),
- "has_point() with negative Vector2 on right edge should return the expected result.");
+ !rect.has_point(rect.position + Vector2i(10, rect.size.y)),
+ "has_point() with negative position and point located on bottom edge should return false.");
}
TEST_CASE("[Rect2i] Intersection") {
diff --git a/tests/test_class_db.h b/tests/core/object/test_class_db.h
index 4b058a4c67..4b27905485 100644
--- a/tests/test_class_db.h
+++ b/tests/core/object/test_class_db.h
@@ -31,14 +31,9 @@
#ifndef TEST_CLASS_DB_H
#define TEST_CLASS_DB_H
-#include "core/register_core_types.h"
-
+#include "core/core_bind.h"
#include "core/core_constants.h"
-#include "core/os/os.h"
-#include "core/string/string_name.h"
-#include "core/string/ustring.h"
-#include "core/templates/ordered_hash_map.h"
-#include "core/variant/variant.h"
+#include "core/object/class_db.h"
#include "tests/test_macros.h"
diff --git a/tests/test_method_bind.h b/tests/core/object/test_method_bind.h
index 879e7949e2..c3a869a8a4 100644
--- a/tests/test_method_bind.h
+++ b/tests/core/object/test_method_bind.h
@@ -35,10 +35,6 @@
#include "tests/test_macros.h"
-#include <inttypes.h>
-#include <stdio.h>
-#include <wchar.h>
-
namespace TestMethodBind {
class MethodBindTester : public Object {
diff --git a/tests/test_object.h b/tests/core/object/test_object.h
index 8cb7116a20..4109ea521a 100644
--- a/tests/test_object.h
+++ b/tests/core/object/test_object.h
@@ -32,9 +32,11 @@
#define TEST_OBJECT_H
#include "core/core_string_names.h"
+#include "core/object/class_db.h"
#include "core/object/object.h"
+#include "core/object/script_language.h"
-#include "thirdparty/doctest/doctest.h"
+#include "tests/test_macros.h"
// Declared in global namespace because of GDCLASS macro warning (Windows):
// "Unqualified friend declaration referring to type outside of the nearest enclosing namespace
diff --git a/tests/test_node_path.h b/tests/core/string/test_node_path.h
index f30fe53c5a..0216a30f8f 100644
--- a/tests/test_node_path.h
+++ b/tests/core/string/test_node_path.h
@@ -33,7 +33,7 @@
#include "core/string/node_path.h"
-#include "thirdparty/doctest/doctest.h"
+#include "tests/test_macros.h"
namespace TestNodePath {
diff --git a/tests/test_string.h b/tests/core/string/test_string.h
index 28d1089d2f..00a9a8779a 100644
--- a/tests/test_string.h
+++ b/tests/core/string/test_string.h
@@ -31,15 +31,7 @@
#ifndef TEST_STRING_H
#define TEST_STRING_H
-#include <inttypes.h>
-#include <stdio.h>
-#include <wchar.h>
-
-#include "core/io/ip_address.h"
-#include "core/os/main_loop.h"
-#include "core/os/os.h"
#include "core/string/ustring.h"
-#include "core/variant/variant.h"
#include "tests/test_macros.h"
@@ -498,12 +490,6 @@ TEST_CASE("[String] Splitting") {
}
}
-TEST_CASE("[String] Erasing") {
- String s = "Josephine is such a cute girl!";
- s.erase(s.find("cute "), String("cute ").length());
- CHECK(s == "Josephine is such a girl!");
-}
-
struct test_27_data {
char const *data;
char const *part;
diff --git a/tests/test_translation.h b/tests/core/string/test_translation.h
index 93c53bbbc9..47e06add40 100644
--- a/tests/test_translation.h
+++ b/tests/core/string/test_translation.h
@@ -39,7 +39,8 @@
#include "editor/import/resource_importer_csv_translation.h"
#endif
-#include "thirdparty/doctest/doctest.h"
+#include "tests/test_macros.h"
+#include "tests/test_utils.h"
namespace TestTranslation {
diff --git a/tests/test_command_queue.h b/tests/core/templates/test_command_queue.h
index f0d4569942..5d228f2bf6 100644
--- a/tests/test_command_queue.h
+++ b/tests/core/templates/test_command_queue.h
@@ -33,12 +33,10 @@
#include "core/config/project_settings.h"
#include "core/math/random_number_generator.h"
-#include "core/os/mutex.h"
#include "core/os/os.h"
-#include "core/os/semaphore.h"
#include "core/os/thread.h"
#include "core/templates/command_queue_mt.h"
-#include "test_macros.h"
+#include "tests/test_macros.h"
#if !defined(NO_THREADS)
diff --git a/tests/test_list.h b/tests/core/templates/test_list.h
index 52d5edff70..52d5edff70 100644
--- a/tests/test_list.h
+++ b/tests/core/templates/test_list.h
diff --git a/tests/test_local_vector.h b/tests/core/templates/test_local_vector.h
index eff2a16abc..eff2a16abc 100644
--- a/tests/test_local_vector.h
+++ b/tests/core/templates/test_local_vector.h
diff --git a/tests/test_lru.h b/tests/core/templates/test_lru.h
index 2802754729..9359909c53 100644
--- a/tests/test_lru.h
+++ b/tests/core/templates/test_lru.h
@@ -32,7 +32,6 @@
#define TEST_LRU_H
#include "core/templates/lru.h"
-#include "core/templates/vector.h"
#include "tests/test_macros.h"
diff --git a/tests/test_oa_hash_map.cpp b/tests/core/templates/test_oa_hash_map.cpp
index 904c01642d..904c01642d 100644
--- a/tests/test_oa_hash_map.cpp
+++ b/tests/core/templates/test_oa_hash_map.cpp
diff --git a/tests/test_oa_hash_map.h b/tests/core/templates/test_oa_hash_map.h
index 9745802cc0..f229ac94ea 100644
--- a/tests/test_oa_hash_map.h
+++ b/tests/core/templates/test_oa_hash_map.h
@@ -31,7 +31,7 @@
#ifndef TEST_OA_HASH_MAP_H
#define TEST_OA_HASH_MAP_H
-#include "core/os/main_loop.h"
+class MainLoop;
namespace TestOAHashMap {
diff --git a/tests/test_ordered_hash_map.h b/tests/core/templates/test_ordered_hash_map.h
index fbaaa224cf..35ce0fc656 100644
--- a/tests/test_ordered_hash_map.h
+++ b/tests/core/templates/test_ordered_hash_map.h
@@ -31,10 +31,7 @@
#ifndef TEST_ORDERED_HASH_MAP_H
#define TEST_ORDERED_HASH_MAP_H
-#include "core/os/os.h"
#include "core/templates/ordered_hash_map.h"
-#include "core/templates/pair.h"
-#include "core/templates/vector.h"
#include "tests/test_macros.h"
diff --git a/tests/test_paged_array.h b/tests/core/templates/test_paged_array.h
index 7efd3799f3..7efd3799f3 100644
--- a/tests/test_paged_array.h
+++ b/tests/core/templates/test_paged_array.h
diff --git a/tests/test_vector.h b/tests/core/templates/test_vector.h
index bfdf389aa7..bfdf389aa7 100644
--- a/tests/test_vector.h
+++ b/tests/core/templates/test_vector.h
diff --git a/tests/test_crypto.h b/tests/core/test_crypto.h
index 8da8c75544..3b909c7df8 100644
--- a/tests/test_crypto.h
+++ b/tests/core/test_crypto.h
@@ -33,7 +33,6 @@
#include "core/crypto/crypto.h"
#include "tests/test_macros.h"
-#include <stdio.h>
namespace TestCrypto {
diff --git a/tests/test_hashing_context.h b/tests/core/test_hashing_context.h
index 728a5f2cfa..728a5f2cfa 100644
--- a/tests/test_hashing_context.h
+++ b/tests/core/test_hashing_context.h
diff --git a/tests/test_time.h b/tests/core/test_time.h
index 28f1cb2f20..28f1cb2f20 100644
--- a/tests/test_time.h
+++ b/tests/core/test_time.h
diff --git a/tests/test_array.h b/tests/core/variant/test_array.h
index 05b4eaea2a..298bd2ff63 100644
--- a/tests/test_array.h
+++ b/tests/core/variant/test_array.h
@@ -31,13 +31,7 @@
#ifndef TEST_ARRAY_H
#define TEST_ARRAY_H
-#include "core/object/class_db.h"
-#include "core/object/script_language.h"
-#include "core/templates/hashfuncs.h"
-#include "core/templates/vector.h"
#include "core/variant/array.h"
-#include "core/variant/container_type_validate.h"
-#include "core/variant/variant.h"
#include "tests/test_macros.h"
#include "tests/test_tools.h"
diff --git a/tests/test_dictionary.h b/tests/core/variant/test_dictionary.h
index 64d1d68e21..65079698a3 100644
--- a/tests/test_dictionary.h
+++ b/tests/core/variant/test_dictionary.h
@@ -31,10 +31,7 @@
#ifndef TEST_DICTIONARY_H
#define TEST_DICTIONARY_H
-#include "core/templates/ordered_hash_map.h"
-#include "core/templates/safe_refcount.h"
#include "core/variant/dictionary.h"
-#include "core/variant/variant.h"
#include "tests/test_macros.h"
namespace TestDictionary {
diff --git a/tests/test_variant.h b/tests/core/variant/test_variant.h
index 0d16fa092c..0d16fa092c 100644
--- a/tests/test_variant.h
+++ b/tests/core/variant/test_variant.h
diff --git a/tests/test_code_edit.h b/tests/scene/test_code_edit.h
index 62235ed0ae..202ba8dca5 100644
--- a/tests/test_code_edit.h
+++ b/tests/scene/test_code_edit.h
@@ -31,12 +31,7 @@
#ifndef TEST_CODE_EDIT_H
#define TEST_CODE_EDIT_H
-#include "core/input/input_map.h"
-#include "core/object/message_queue.h"
-#include "core/os/keyboard.h"
-#include "core/string/string_builder.h"
#include "scene/gui/code_edit.h"
-#include "scene/resources/default_theme/default_theme.h"
#include "tests/test_macros.h"
diff --git a/tests/test_curve.h b/tests/scene/test_curve.h
index e079905e35..60eafad460 100644
--- a/tests/test_curve.h
+++ b/tests/scene/test_curve.h
@@ -33,7 +33,7 @@
#include "scene/resources/curve.h"
-#include "thirdparty/doctest/doctest.h"
+#include "tests/test_macros.h"
namespace TestCurve {
diff --git a/tests/test_gradient.h b/tests/scene/test_gradient.h
index 8eaa6b2b64..fc595b02f2 100644
--- a/tests/test_gradient.h
+++ b/tests/scene/test_gradient.h
@@ -31,8 +31,6 @@
#ifndef TEST_GRADIENT_H
#define TEST_GRADIENT_H
-#include "core/math/color.h"
-#include "core/object/class_db.h"
#include "scene/resources/gradient.h"
#include "thirdparty/doctest/doctest.h"
diff --git a/tests/test_gui.cpp b/tests/scene/test_gui.cpp
index 0ec8aa78c4..5bd9390cb7 100644
--- a/tests/test_gui.cpp
+++ b/tests/scene/test_gui.cpp
@@ -32,29 +32,18 @@
#include "test_gui.h"
-#include "core/io/image_loader.h"
-#include "core/os/os.h"
-#include "core/string/print_string.h"
-#include "scene/2d/sprite_2d.h"
#include "scene/gui/button.h"
-#include "scene/gui/control.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/option_button.h"
#include "scene/gui/panel.h"
-#include "scene/gui/popup_menu.h"
#include "scene/gui/progress_bar.h"
#include "scene/gui/rich_text_label.h"
#include "scene/gui/scroll_bar.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/tab_container.h"
-#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"
-#include "scene/main/scene_tree.h"
-
-#include "scene/3d/camera_3d.h"
-#include "scene/main/window.h"
namespace TestGUI {
@@ -267,4 +256,4 @@ MainLoop *test() {
}
} // namespace TestGUI
-#endif
+#endif // _3D_DISABLED
diff --git a/tests/test_gui.h b/tests/scene/test_gui.h
index e5c40de7e8..84bce620e2 100644
--- a/tests/test_gui.h
+++ b/tests/scene/test_gui.h
@@ -31,7 +31,7 @@
#ifndef TEST_GUI_H
#define TEST_GUI_H
-#include "core/os/main_loop.h"
+class MainLoop;
namespace TestGUI {
diff --git a/tests/test_path_3d.h b/tests/scene/test_path_3d.h
index 9961ae6e97..1fcef3adde 100644
--- a/tests/test_path_3d.h
+++ b/tests/scene/test_path_3d.h
@@ -32,7 +32,6 @@
#define TEST_PATH_3D_H
#include "scene/3d/path_3d.h"
-#include "scene/resources/curve.h"
#include "tests/test_macros.h"
diff --git a/tests/test_path_follow_2d.h b/tests/scene/test_path_follow_2d.h
index 388b690060..ddfcc5552a 100644
--- a/tests/test_path_follow_2d.h
+++ b/tests/scene/test_path_follow_2d.h
@@ -32,7 +32,6 @@
#define TEST_PATH_FOLLOW_2D_H
#include "scene/2d/path_2d.h"
-#include "scene/resources/curve.h"
#include "tests/test_macros.h"
diff --git a/tests/test_path_follow_3d.h b/tests/scene/test_path_follow_3d.h
index b6b4c88222..6a505dbb39 100644
--- a/tests/test_path_follow_3d.h
+++ b/tests/scene/test_path_follow_3d.h
@@ -32,7 +32,6 @@
#define TEST_PATH_FOLLOW_3D_H
#include "scene/3d/path_3d.h"
-#include "scene/resources/curve.h"
#include "tests/test_macros.h"
diff --git a/tests/test_physics_2d.cpp b/tests/servers/test_physics_2d.cpp
index f6619db8fd..b6360cde8a 100644
--- a/tests/test_physics_2d.cpp
+++ b/tests/servers/test_physics_2d.cpp
@@ -31,11 +31,6 @@
#include "test_physics_2d.h"
#include "core/os/main_loop.h"
-#include "core/os/os.h"
-#include "core/string/print_string.h"
-#include "core/templates/map.h"
-#include "scene/resources/texture.h"
-#include "servers/display_server.h"
#include "servers/physics_server_2d.h"
#include "servers/rendering_server.h"
diff --git a/tests/test_physics_2d.h b/tests/servers/test_physics_2d.h
index 966d49200a..2ae1053a03 100644
--- a/tests/test_physics_2d.h
+++ b/tests/servers/test_physics_2d.h
@@ -31,7 +31,7 @@
#ifndef TEST_PHYSICS_2D_H
#define TEST_PHYSICS_2D_H
-#include "core/os/main_loop.h"
+class MainLoop;
namespace TestPhysics2D {
diff --git a/tests/test_physics_3d.cpp b/tests/servers/test_physics_3d.cpp
index d839ae26b7..4e483d628d 100644
--- a/tests/test_physics_3d.cpp
+++ b/tests/servers/test_physics_3d.cpp
@@ -31,12 +31,8 @@
#include "test_physics_3d.h"
#include "core/math/convex_hull.h"
-#include "core/math/math_funcs.h"
+#include "core/math/geometry_3d.h"
#include "core/os/main_loop.h"
-#include "core/os/os.h"
-#include "core/string/print_string.h"
-#include "core/templates/map.h"
-#include "servers/display_server.h"
#include "servers/physics_server_3d.h"
#include "servers/rendering_server.h"
diff --git a/tests/test_physics_3d.h b/tests/servers/test_physics_3d.h
index b6b66f350e..b86327cdb4 100644
--- a/tests/test_physics_3d.h
+++ b/tests/servers/test_physics_3d.h
@@ -31,7 +31,7 @@
#ifndef TEST_PHYSICS_H
#define TEST_PHYSICS_H
-#include "core/os/main_loop.h"
+class MainLoop;
namespace TestPhysics3D {
diff --git a/tests/test_render.cpp b/tests/servers/test_render.cpp
index 21b4da9b3b..183f049238 100644
--- a/tests/test_render.cpp
+++ b/tests/servers/test_render.cpp
@@ -31,12 +31,7 @@
#include "test_render.h"
#include "core/math/convex_hull.h"
-#include "core/math/math_funcs.h"
-#include "core/os/keyboard.h"
#include "core/os/main_loop.h"
-#include "core/os/os.h"
-#include "core/string/print_string.h"
-#include "servers/display_server.h"
#include "servers/rendering_server.h"
#define OBJECT_COUNT 50
diff --git a/tests/test_render.h b/tests/servers/test_render.h
index 35bb383773..1d773cb347 100644
--- a/tests/test_render.h
+++ b/tests/servers/test_render.h
@@ -31,11 +31,11 @@
#ifndef TEST_RENDER_H
#define TEST_RENDER_H
-#include "core/os/main_loop.h"
+class MainLoop;
namespace TestRender {
MainLoop *test();
}
-#endif
+#endif // TEST_RENDER_H
diff --git a/tests/test_shader_lang.cpp b/tests/servers/test_shader_lang.cpp
index 5598852f29..0591bf6adf 100644
--- a/tests/test_shader_lang.cpp
+++ b/tests/servers/test_shader_lang.cpp
@@ -30,13 +30,8 @@
#include "test_shader_lang.h"
-#include "core/io/file_access.h"
#include "core/os/main_loop.h"
#include "core/os/os.h"
-
-#include "core/string/print_string.h"
-#include "scene/gui/control.h"
-#include "scene/gui/text_edit.h"
#include "servers/rendering/shader_language.h"
typedef ShaderLanguage SL;
diff --git a/tests/test_shader_lang.h b/tests/servers/test_shader_lang.h
index 46a2e6af35..de7ec002b6 100644
--- a/tests/test_shader_lang.h
+++ b/tests/servers/test_shader_lang.h
@@ -31,7 +31,7 @@
#ifndef TEST_SHADER_LANG_H
#define TEST_SHADER_LANG_H
-#include "core/os/main_loop.h"
+class MainLoop;
namespace TestShaderLang {
diff --git a/tests/test_text_server.h b/tests/servers/test_text_server.h
index 4edffe3711..4edffe3711 100644
--- a/tests/test_text_server.h
+++ b/tests/servers/test_text_server.h
diff --git a/tests/test_macros.h b/tests/test_macros.h
index 6968f9df1f..0ec6eb9e7c 100644
--- a/tests/test_macros.h
+++ b/tests/test_macros.h
@@ -31,10 +31,8 @@
#ifndef TEST_MACROS_H
#define TEST_MACROS_H
-#include "core/object/callable_method_pointer.h"
-#include "core/object/class_db.h"
-#include "core/string/print_string.h"
-#include "core/templates/map.h"
+#include "core/input/input_map.h"
+#include "core/object/message_queue.h"
#include "core/variant/variant.h"
// See documentation for doctest at:
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 341fb1af61..a09be08de8 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -30,62 +30,62 @@
#include "test_main.h"
-#include "core/templates/list.h"
-
-#include "test_aabb.h"
-#include "test_array.h"
-#include "test_astar.h"
-#include "test_basis.h"
-#include "test_class_db.h"
-#include "test_code_edit.h"
-#include "test_color.h"
-#include "test_command_queue.h"
-#include "test_config_file.h"
-#include "test_crypto.h"
-#include "test_curve.h"
-#include "test_dictionary.h"
-#include "test_expression.h"
-#include "test_file_access.h"
-#include "test_geometry_2d.h"
-#include "test_geometry_3d.h"
-#include "test_gradient.h"
-#include "test_gui.h"
-#include "test_hashing_context.h"
-#include "test_image.h"
-#include "test_json.h"
-#include "test_list.h"
-#include "test_local_vector.h"
-#include "test_lru.h"
-#include "test_marshalls.h"
-#include "test_math.h"
-#include "test_method_bind.h"
-#include "test_node_path.h"
-#include "test_oa_hash_map.h"
-#include "test_object.h"
-#include "test_ordered_hash_map.h"
-#include "test_paged_array.h"
-#include "test_path_3d.h"
-#include "test_pck_packer.h"
-#include "test_physics_2d.h"
-#include "test_physics_3d.h"
-#include "test_random_number_generator.h"
-#include "test_rect2.h"
-#include "test_render.h"
-#include "test_resource.h"
-#include "test_shader_lang.h"
-#include "test_string.h"
-#include "test_text_server.h"
-#include "test_time.h"
-#include "test_translation.h"
-#include "test_validate_testing.h"
-#include "test_variant.h"
-#include "test_vector.h"
-#include "test_xml_parser.h"
+#include "tests/core/io/test_config_file.h"
+#include "tests/core/io/test_file_access.h"
+#include "tests/core/io/test_image.h"
+#include "tests/core/io/test_json.h"
+#include "tests/core/io/test_marshalls.h"
+#include "tests/core/io/test_pck_packer.h"
+#include "tests/core/io/test_resource.h"
+#include "tests/core/io/test_xml_parser.h"
+#include "tests/core/math/test_aabb.h"
+#include "tests/core/math/test_astar.h"
+#include "tests/core/math/test_basis.h"
+#include "tests/core/math/test_color.h"
+#include "tests/core/math/test_expression.h"
+#include "tests/core/math/test_geometry_2d.h"
+#include "tests/core/math/test_geometry_3d.h"
+#include "tests/core/math/test_math.h"
+#include "tests/core/math/test_random_number_generator.h"
+#include "tests/core/math/test_rect2.h"
+#include "tests/core/object/test_class_db.h"
+#include "tests/core/object/test_method_bind.h"
+#include "tests/core/object/test_object.h"
+#include "tests/core/string/test_node_path.h"
+#include "tests/core/string/test_string.h"
+#include "tests/core/string/test_translation.h"
+#include "tests/core/templates/test_command_queue.h"
+#include "tests/core/templates/test_list.h"
+#include "tests/core/templates/test_local_vector.h"
+#include "tests/core/templates/test_lru.h"
+#include "tests/core/templates/test_oa_hash_map.h"
+#include "tests/core/templates/test_ordered_hash_map.h"
+#include "tests/core/templates/test_paged_array.h"
+#include "tests/core/templates/test_vector.h"
+#include "tests/core/test_crypto.h"
+#include "tests/core/test_hashing_context.h"
+#include "tests/core/test_time.h"
+#include "tests/core/variant/test_array.h"
+#include "tests/core/variant/test_dictionary.h"
+#include "tests/core/variant/test_variant.h"
+#include "tests/scene/test_code_edit.h"
+#include "tests/scene/test_curve.h"
+#include "tests/scene/test_gradient.h"
+#include "tests/scene/test_gui.h"
+#include "tests/scene/test_path_3d.h"
+#include "tests/servers/test_physics_2d.h"
+#include "tests/servers/test_physics_3d.h"
+#include "tests/servers/test_render.h"
+#include "tests/servers/test_shader_lang.h"
+#include "tests/servers/test_text_server.h"
+#include "tests/test_validate_testing.h"
#include "modules/modules_tests.gen.h"
#include "tests/test_macros.h"
+#include "scene/resources/default_theme/default_theme.h"
+
int test_main(int argc, char *argv[]) {
bool run_tests = true;
diff --git a/tests/test_tools.h b/tests/test_tools.h
index ec18610f04..e1192458d0 100644
--- a/tests/test_tools.h
+++ b/tests/test_tools.h
@@ -31,8 +31,6 @@
#ifndef TEST_TOOLS_H
#define TEST_TOOLS_H
-#include "core/error/error_macros.h"
-
struct ErrorDetector {
ErrorDetector() {
eh.errfunc = _detect_error;
diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp
index 1666a257a9..890dea3ee1 100644
--- a/tests/test_utils.cpp
+++ b/tests/test_utils.cpp
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "test_utils.h"
+#include "tests/test_utils.h"
#include "core/os/os.h"
diff --git a/tests/test_utils.h b/tests/test_utils.h
index f05ab0bdb1..ccebe2e449 100644
--- a/tests/test_utils.h
+++ b/tests/test_utils.h
@@ -31,7 +31,7 @@
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
-#include "core/string/ustring.h"
+class String;
namespace TestUtils {