diff options
-rw-r--r-- | core/math/quaternion.cpp | 4 | ||||
-rw-r--r-- | core/object/class_db.h | 19 | ||||
-rw-r--r-- | doc/classes/AnimationNode.xml | 5 | ||||
-rw-r--r-- | editor/editor_node.cpp | 58 | ||||
-rw-r--r-- | editor/editor_node.h | 1 | ||||
-rw-r--r-- | editor/editor_properties.cpp | 3 | ||||
-rw-r--r-- | editor/plugins/animation_blend_space_2d_editor.cpp | 6 | ||||
-rw-r--r-- | editor/plugins/animation_blend_space_2d_editor.h | 2 | ||||
-rw-r--r-- | editor/plugins/animation_blend_tree_editor_plugin.cpp | 8 | ||||
-rw-r--r-- | editor/plugins/animation_blend_tree_editor_plugin.h | 1 | ||||
-rw-r--r-- | editor/plugins/animation_state_machine_editor.cpp | 5 | ||||
-rw-r--r-- | editor/plugins/animation_state_machine_editor.h | 2 | ||||
-rw-r--r-- | editor/plugins/tiles/tile_atlas_view.cpp | 4 | ||||
-rw-r--r-- | editor/pot_generator.cpp | 15 | ||||
-rw-r--r-- | editor/project_converter_3_to_4.cpp | 10 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs | 4 | ||||
-rw-r--r-- | scene/animation/animation_tree.cpp | 1 | ||||
-rw-r--r-- | scene/resources/animation.cpp | 268 |
18 files changed, 162 insertions, 254 deletions
diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp index cf415a9bf9..34e212a5b6 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -220,7 +220,7 @@ Quaternion Quaternion::spherical_cubic_interpolate(const Quaternion &p_b, const ln.z = Math::cubic_interpolate(ln_from.z, ln_to.z, ln_pre.z, ln_post.z, p_weight); Quaternion q2 = to_q * ln.exp(); - // To cancel error made by Expmap ambiguity, do blends. + // To cancel error made by Expmap ambiguity, do blending. return q1.slerp(q2, p_weight); } @@ -271,7 +271,7 @@ Quaternion Quaternion::spherical_cubic_interpolate_in_time(const Quaternion &p_b ln.z = Math::cubic_interpolate_in_time(ln_from.z, ln_to.z, ln_pre.z, ln_post.z, p_weight, p_b_t, p_pre_a_t, p_post_b_t); Quaternion q2 = to_q * ln.exp(); - // To cancel error made by Expmap ambiguity, do blends. + // To cancel error made by Expmap ambiguity, do blending. return q1.slerp(q2, p_weight); } diff --git a/core/object/class_db.h b/core/object/class_db.h index f1856b1817..0e408e8845 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -372,17 +372,17 @@ public: static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting }; -#ifdef DEBUG_METHODS_ENABLED - -#define BIND_CONSTANT(m_constant) \ - ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant); - #define BIND_ENUM_CONSTANT(m_constant) \ ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant); #define BIND_BITFIELD_FLAG(m_constant) \ ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant, #m_constant), #m_constant, m_constant, true); +#define BIND_CONSTANT(m_constant) \ + ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant); + +#ifdef DEBUG_METHODS_ENABLED + _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr) { } @@ -408,15 +408,6 @@ _FORCE_INLINE_ Vector<Error> errarray(P... p_args) { #else -#define BIND_CONSTANT(m_constant) \ - ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant); - -#define BIND_ENUM_CONSTANT(m_constant) \ - ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant); - -#define BIND_BITFIELD_FLAG(m_constant) \ - ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant, true); - #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) #endif diff --git a/doc/classes/AnimationNode.xml b/doc/classes/AnimationNode.xml index 79deb008d2..a33ec2f6dc 100644 --- a/doc/classes/AnimationNode.xml +++ b/doc/classes/AnimationNode.xml @@ -165,11 +165,6 @@ </member> </members> <signals> - <signal name="removed_from_graph"> - <description> - Emitted when the node was removed from the graph. - </description> - </signal> <signal name="tree_changed"> <description> Emitted by nodes that inherit from this class and that have an internal tree when one of their nodes changes. The nodes that emit this signal are [AnimationNodeBlendSpace1D], [AnimationNodeBlendSpace2D], [AnimationNodeStateMachine], and [AnimationNodeBlendTree]. diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 9110238370..30a2a2143c 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2041,18 +2041,6 @@ void EditorNode::_dialog_action(String p_file) { } } -bool EditorNode::item_has_editor(Object *p_object) { - if (_is_class_editor_disabled_by_feature_profile(p_object->get_class())) { - return false; - } - - return editor_data.get_subeditors(p_object).size() > 0; -} - -void EditorNode::edit_item_resource(Ref<Resource> p_resource) { - edit_item(p_resource.ptr()); -} - bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName &p_class) { Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_null()) { @@ -2075,37 +2063,43 @@ bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName & } void EditorNode::edit_item(Object *p_object) { - Vector<EditorPlugin *> sub_plugins; + if (p_object && _is_class_editor_disabled_by_feature_profile(p_object->get_class())) { + return; + } + Vector<EditorPlugin *> top_plugins = editor_plugins_over->get_plugins_list(); + Vector<EditorPlugin *> item_plugins; if (p_object) { - if (_is_class_editor_disabled_by_feature_profile(p_object->get_class())) { - return; - } - sub_plugins = editor_data.get_subeditors(p_object); + item_plugins = editor_data.get_subeditors(p_object); } - if (!sub_plugins.is_empty()) { + if (!item_plugins.is_empty()) { bool same = true; - if (sub_plugins.size() == editor_plugins_over->get_plugins_list().size()) { - for (int i = 0; i < sub_plugins.size(); i++) { - if (sub_plugins[i] != editor_plugins_over->get_plugins_list()[i]) { + if (item_plugins.size() == top_plugins.size()) { + for (int i = 0; i < item_plugins.size(); i++) { + if (item_plugins[i] != top_plugins[i]) { same = false; } } } else { same = false; } + if (!same) { _display_top_editors(false); - _set_top_editors(sub_plugins); + _set_top_editors(item_plugins); } _set_editing_top_editors(p_object); _display_top_editors(true); - } else { + } else if (!top_plugins.is_empty()) { hide_top_editors(); } } +void EditorNode::edit_item_resource(Ref<Resource> p_resource) { + edit_item(p_resource.ptr()); +} + void EditorNode::push_item(Object *p_object, const String &p_property, bool p_inspector_only) { if (!p_object) { InspectorDock::get_inspector_singleton()->edit(nullptr); @@ -2351,21 +2345,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { } } - Vector<EditorPlugin *> sub_plugins; - - if (!_is_class_editor_disabled_by_feature_profile(current_obj->get_class())) { - sub_plugins = editor_data.get_subeditors(current_obj); - } - - if (!sub_plugins.is_empty()) { - _display_top_editors(false); - - _set_top_editors(sub_plugins); - _set_editing_top_editors(current_obj); - _display_top_editors(true); - } else if (!editor_plugins_over->get_plugins_list().is_empty()) { - hide_top_editors(); - } + edit_item(current_obj); } InspectorDock::get_singleton()->update(current_obj); @@ -5939,8 +5919,6 @@ void EditorNode::_bind_methods() { ClassDB::bind_method("_set_main_scene_state", &EditorNode::_set_main_scene_state); ClassDB::bind_method("_update_recent_scenes", &EditorNode::_update_recent_scenes); - ClassDB::bind_method("edit_item_resource", &EditorNode::edit_item_resource); - ClassDB::bind_method(D_METHOD("get_gui_base"), &EditorNode::get_gui_base); ADD_SIGNAL(MethodInfo("play_pressed")); diff --git a/editor/editor_node.h b/editor/editor_node.h index 5af3e88556..f3dad8e223 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -795,7 +795,6 @@ public: void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false); void edit_item(Object *p_object); void edit_item_resource(Ref<Resource> p_resource); - bool item_has_editor(Object *p_object); void hide_top_editors(); void select_editor_by_name(const String &p_name); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 45de5cde47..ba42bbf3bd 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -3925,7 +3925,7 @@ void EditorPropertyResource::_open_editor_pressed() { Ref<Resource> res = get_edited_object()->get(get_edited_property()); if (res.is_valid()) { // May clear the editor so do it deferred. - EditorNode::get_singleton()->call_deferred(SNAME("edit_item_resource"), res); + callable_mp(EditorNode::get_singleton(), &EditorNode::edit_item_resource).bind(res).call_deferred(); } } @@ -4189,7 +4189,6 @@ void EditorPropertyResource::_notification(int p_what) { } void EditorPropertyResource::_bind_methods() { - ClassDB::bind_method(D_METHOD("_open_editor_pressed"), &EditorPropertyResource::_open_editor_pressed); ClassDB::bind_method(D_METHOD("_fold_other_editors"), &EditorPropertyResource::_fold_other_editors); } diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 36eb765979..00e7f28bb5 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -855,10 +855,6 @@ void AnimationNodeBlendSpace2DEditor::_open_editor() { } } -void AnimationNodeBlendSpace2DEditor::_removed_from_graph() { - EditorNode::get_singleton()->edit_item(nullptr); -} - void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); undo_redo->create_action(TTR("Toggle Auto Triangles")); @@ -874,8 +870,6 @@ void AnimationNodeBlendSpace2DEditor::_bind_methods() { ClassDB::bind_method("_update_tool_erase", &AnimationNodeBlendSpace2DEditor::_update_tool_erase); ClassDB::bind_method("_update_edited_point_pos", &AnimationNodeBlendSpace2DEditor::_update_edited_point_pos); - - ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendSpace2DEditor::_removed_from_graph); } AnimationNodeBlendSpace2DEditor *AnimationNodeBlendSpace2DEditor::singleton = nullptr; diff --git a/editor/plugins/animation_blend_space_2d_editor.h b/editor/plugins/animation_blend_space_2d_editor.h index 1977787a24..f11cccabc1 100644 --- a/editor/plugins/animation_blend_space_2d_editor.h +++ b/editor/plugins/animation_blend_space_2d_editor.h @@ -121,8 +121,6 @@ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { void _edit_point_pos(double); void _open_editor(); - void _removed_from_graph(); - void _auto_triangles_toggled(); StringName get_blend_position_path() const; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 3ebb1e38e9..0ebc780604 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -815,12 +815,6 @@ void AnimationNodeBlendTreeEditor::_inspect_filters(const String &p_which) { filter_dialog->popup_centered(Size2(500, 500) * EDSCALE); } -void AnimationNodeBlendTreeEditor::_removed_from_graph() { - if (is_visible()) { - EditorNode::get_singleton()->edit_item(nullptr); - } -} - void AnimationNodeBlendTreeEditor::_update_editor_settings() { graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning"))); graph->set_warped_panning(bool(EDITOR_GET("editors/panning/warped_mouse_panning"))); @@ -1050,7 +1044,6 @@ bool AnimationNodeBlendTreeEditor::can_edit(const Ref<AnimationNode> &p_node) { void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) { if (blend_tree.is_valid()) { blend_tree->disconnect("node_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_changed)); - blend_tree->disconnect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph)); } blend_tree = p_node; @@ -1063,7 +1056,6 @@ void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) { read_only = EditorNode::get_singleton()->is_resource_read_only(blend_tree); blend_tree->connect("node_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_changed)); - blend_tree->connect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph)); update_graph(); } diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index fe7b2efc1c..b471d47df6 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -123,7 +123,6 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position); void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); - void _removed_from_graph(); void _update_editor_settings(); void _update_theme(); diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index ff45c526c3..4ea2f0c561 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -1760,10 +1760,6 @@ void AnimationNodeStateMachineEditor::_open_editor(const String &p_name) { AnimationTreeEditor::get_singleton()->enter_editor(p_name); } -void AnimationNodeStateMachineEditor::_removed_from_graph() { - EditorNode::get_singleton()->edit_item(nullptr); -} - void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) { const String &new_name = p_text; @@ -1942,7 +1938,6 @@ void AnimationNodeStateMachineEditor::_update_mode() { void AnimationNodeStateMachineEditor::_bind_methods() { ClassDB::bind_method("_update_graph", &AnimationNodeStateMachineEditor::_update_graph); - ClassDB::bind_method("_removed_from_graph", &AnimationNodeStateMachineEditor::_removed_from_graph); ClassDB::bind_method("_open_editor", &AnimationNodeStateMachineEditor::_open_editor); ClassDB::bind_method("_connect_to", &AnimationNodeStateMachineEditor::_connect_to); ClassDB::bind_method("_stop_connecting", &AnimationNodeStateMachineEditor::_stop_connecting); diff --git a/editor/plugins/animation_state_machine_editor.h b/editor/plugins/animation_state_machine_editor.h index 32a6539aed..46fe13ccc1 100644 --- a/editor/plugins/animation_state_machine_editor.h +++ b/editor/plugins/animation_state_machine_editor.h @@ -127,8 +127,6 @@ class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin { void _add_animation_type(int p_index); void _connect_to(int p_index); - void _removed_from_graph(); - struct NodeRect { StringName node_name; Rect2 node; diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp index 5b7da148d8..3c6ed0f049 100644 --- a/editor/plugins/tiles/tile_atlas_view.cpp +++ b/editor/plugins/tiles/tile_atlas_view.cpp @@ -53,14 +53,14 @@ void TileAtlasView::_scroll_callback(Vector2 p_scroll_vec, bool p_alt) { void TileAtlasView::_pan_callback(Vector2 p_scroll_vec) { panning += p_scroll_vec; - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); _update_zoom_and_panning(true); + emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); } void TileAtlasView::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin, bool p_alt) { zoom_widget->set_zoom_by_increments(-p_scroll_vec.y * 2); - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); _update_zoom_and_panning(true); + emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); } Size2i TileAtlasView::_compute_base_tiles_control_size() { diff --git a/editor/pot_generator.cpp b/editor/pot_generator.cpp index aa25a16a18..f70a795683 100644 --- a/editor/pot_generator.cpp +++ b/editor/pot_generator.cpp @@ -159,14 +159,15 @@ void POTGenerator::_write_to_pot(const String &p_file) { void POTGenerator::_write_msgid(Ref<FileAccess> r_file, const String &p_id, bool p_plural) { // Split \\n and \n. - Vector<String> temp = p_id.split("\\n"); Vector<String> msg_lines; + Vector<String> temp = p_id.split("\\n"); for (int i = 0; i < temp.size(); i++) { msg_lines.append_array(temp[i].split("\n")); - if (i < temp.size() - 1) { - // Add \n. - msg_lines.set(msg_lines.size() - 1, msg_lines[msg_lines.size() - 1] + "\\n"); - } + } + + // Add \n. + for (int i = 0; i < msg_lines.size() - 1; i++) { + msg_lines.set(i, msg_lines[i] + "\\n"); } if (p_plural) { @@ -175,6 +176,10 @@ void POTGenerator::_write_msgid(Ref<FileAccess> r_file, const String &p_id, bool r_file->store_string("msgid "); } + if (msg_lines.size() > 1) { + r_file->store_line("\"\""); + } + for (int i = 0; i < msg_lines.size(); i++) { r_file->store_line("\"" + msg_lines[i] + "\""); } diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp index 721dfc5169..22d118cd90 100644 --- a/editor/project_converter_3_to_4.cpp +++ b/editor/project_converter_3_to_4.cpp @@ -1240,6 +1240,14 @@ static const char *csharp_properties_renames[][2] = { { "PhysicalScancode", "PhysicalKeycode" }, // InputEventKey { "PopupExclusive", "Exclusive" }, // Window { "ProximityFadeEnable", "ProximityFadeEnabled" }, // Material + { "RectPosition", "Position" }, // Control + { "RectGlobalPosition", "GlobalPosition" }, // Control + { "RectSize", "Size" }, // Control + { "RectMinSize", "CustomMinimumSize" }, // Control + { "RectRotation", "Rotation" }, // Control + { "RectScale", "Scale" }, // Control + { "RectPivotOffset", "PivotOffset" }, // Control + { "RectClipContent", "ClipContents" }, // Control { "RefuseNewNetworkConnections", "RefuseNewConnections" }, // MultiplayerAPI { "RegionFilterClip", "RegionFilterClipEnabled" }, // Sprite2D { "ReverbBusEnable", "ReverbBusEnabled" }, // Area3D @@ -2727,7 +2735,7 @@ bool ProjectConverter3To4::test_array_names() { valid = valid && test_single_array(gdscript_function_renames, true); valid = valid && test_single_array(csharp_function_renames, true); valid = valid && test_single_array(gdscript_properties_renames, true); - valid = valid && test_single_array(csharp_properties_renames); + valid = valid && test_single_array(csharp_properties_renames, true); valid = valid && test_single_array(shaders_renames, true); valid = valid && test_single_array(gdscript_signals_renames); valid = valid && test_single_array(project_settings_renames); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index c55003586b..bd0dea0c1c 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -194,7 +194,7 @@ namespace Godot 0); Quaternion q2 = toQ * ln.Exp(); - // To cancel error made by Expmap ambiguity, do blends. + // To cancel error made by Expmap ambiguity, do blending. return q1.Slerp(q2, weight); } @@ -263,7 +263,7 @@ namespace Godot 0); Quaternion q2 = toQ * ln.Exp(); - // To cancel error made by Expmap ambiguity, do blends. + // To cancel error made by Expmap ambiguity, do blending. return q1.Slerp(q2, weight); } diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 0fb307eaf5..ab341797c7 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -431,7 +431,6 @@ void AnimationNode::_bind_methods() { GDVIRTUAL_BIND(_get_caption); GDVIRTUAL_BIND(_has_filter); - ADD_SIGNAL(MethodInfo("removed_from_graph")); ADD_SIGNAL(MethodInfo("tree_changed")); BIND_ENUM_CONSTANT(FILTER_IGNORE); diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 7e77ad423c..b371266c83 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -2463,145 +2463,127 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol int idx = _find(p_keys, p_time, p_backward); ERR_FAIL_COND_V(idx == -2, T()); + int maxi = len - 1; + bool is_start_edge = idx == -1; + bool is_end_edge = p_backward ? idx == 0 : idx >= maxi; - int next = 0; real_t c = 0.0; - // prepare for all cases of interpolation - - if (loop_mode == LOOP_LINEAR && p_loop_wrap) { - // loop - 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 { - 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; + // Prepare for all cases of interpolation. + real_t delta = 0.0; + real_t from = 0.0; + + int pre = -1; + int next = -1; + int post = -1; + real_t pre_t = 0.0; + real_t to_t = 0.0; + real_t post_t = 0.0; + + bool use_cubic = p_interp == INTERPOLATION_CUBIC || p_interp == INTERPOLATION_CUBIC_ANGLE; + + if (!p_loop_wrap || loop_mode == LOOP_NONE) { + if (is_start_edge) { + idx = p_backward ? maxi : 0; + } + next = CLAMP(idx + (p_backward ? -1 : 1), 0, maxi); + if (use_cubic) { + pre = CLAMP(idx + (p_backward ? 1 : -1), 0, maxi); + post = CLAMP(idx + (p_backward ? -2 : 2), 0, maxi); + } + } else if (loop_mode == LOOP_LINEAR) { + if (is_start_edge) { + idx = p_backward ? 0 : maxi; + } + next = Math::posmod(idx + (p_backward ? -1 : 1), len); + if (use_cubic) { + pre = Math::posmod(idx + (p_backward ? 1 : -1), len); + post = Math::posmod(idx + (p_backward ? -2 : 2), len); + } + if (is_start_edge) { + if (!p_backward) { 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; - } else { - c = from / delta; - } - } - } else { - // 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; - } - } + delta = endtime + p_keys[next].time; + from = endtime + p_time; } else { - // 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; - } + delta = endtime + length - p_keys[next].time; + from = endtime + length - p_time; + } + } else if (is_end_edge) { + if (!p_backward) { + delta = (length - p_keys[idx].time) + p_keys[next].time; + from = p_time - p_keys[idx].time; + } else { + delta = p_keys[idx].time + (length - p_keys[next].time); + from = (length - p_time) - (length - p_keys[idx].time); } } - } else { // no loop - 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 { - next = idx; + } else { + if (is_start_edge) { + idx = p_backward ? len : -1; + } + next = (int)Math::round(Math::pingpong((float)(idx + (p_backward ? -1 : 1)) + 0.5f, (float)len) - 0.5f); + if (use_cubic) { + pre = (int)Math::round(Math::pingpong((float)(idx + (p_backward ? 1 : -1)) + 0.5f, (float)len) - 0.5f); + post = (int)Math::round(Math::pingpong((float)(idx + (p_backward ? -2 : 2)) + 0.5f, (float)len) - 0.5f); + } + idx = (int)Math::round(Math::pingpong((float)idx + 0.5f, (float)len) - 0.5f); + if (is_start_edge) { + if (!p_backward) { + real_t endtime = p_keys[idx].time; + if (endtime < 0) { // may be keys past the end + endtime = 0; } + delta = endtime + p_keys[next].time; + from = endtime + p_time; } else { - idx = next = 0; - } - } else { - 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; + real_t endtime = length - p_keys[idx].time; + if (endtime > length) { // may be keys past the end + endtime = length; } + delta = endtime + length - p_keys[next].time; + from = endtime + length - p_time; + } + } else if (is_end_edge) { + if (!p_backward) { + delta = length * 2.0 - p_keys[idx].time - p_keys[next].time; + from = p_time - p_keys[idx].time; } else { - idx = next = len - 1; + delta = p_keys[idx].time + p_keys[next].time; + from = (length - p_time) - (length - p_keys[idx].time); } } } + if (!is_start_edge && !is_end_edge) { + if (!p_backward) { + delta = p_keys[next].time - p_keys[idx].time; + from = p_time - p_keys[idx].time; + } else { + delta = (length - p_keys[next].time) - (length - p_keys[idx].time); + from = (length - p_time) - (length - p_keys[idx].time); + } + } + + if (Math::is_zero_approx(delta)) { + c = 0; + } else { + c = from / delta; + } + if (p_ok) { *p_ok = true; } real_t tr = p_keys[idx].transition; - - if (tr == 0 || idx == next) { - // don't interpolate if not needed + if (tr == 0) { + // Don't interpolate if not needed. return p_keys[idx].value; } @@ -2621,48 +2603,11 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol } break; case INTERPOLATION_CUBIC: case INTERPOLATION_CUBIC_ANGLE: { - int pre = 0; - int post = 0; - if (!p_backward) { - pre = idx - 1; - if (pre < 0) { - if (loop_mode == LOOP_LINEAR && p_loop_wrap) { - pre = len - 1; - } else { - pre = 0; - } - } - post = next + 1; - if (post >= len) { - if (loop_mode == LOOP_LINEAR && p_loop_wrap) { - post = 0; - } else { - post = next; - } - } - } else { - pre = idx + 1; - if (pre >= len) { - if (loop_mode == LOOP_LINEAR && p_loop_wrap) { - pre = 0; - } else { - pre = idx; - } - } - post = next - 1; - if (post < 0) { - if (loop_mode == LOOP_LINEAR && p_loop_wrap) { - post = len - 1; - } else { - post = 0; - } - } - } - - real_t pre_t = 0.0; - real_t to_t = 0.0; - real_t post_t = 0.0; - if (loop_mode == LOOP_LINEAR && p_loop_wrap) { + if (!p_loop_wrap || loop_mode == LOOP_NONE) { + pre_t = p_keys[pre].time - p_keys[idx].time; + to_t = p_keys[next].time - p_keys[idx].time; + post_t = p_keys[post].time - p_keys[idx].time; + } else if (loop_mode == LOOP_LINEAR) { pre_t = pre > idx ? -length + p_keys[pre].time - p_keys[idx].time : p_keys[pre].time - p_keys[idx].time; to_t = next < idx ? length + p_keys[next].time - p_keys[idx].time : p_keys[next].time - p_keys[idx].time; post_t = next < idx || post <= idx ? length + p_keys[post].time - p_keys[idx].time : p_keys[post].time - p_keys[idx].time; @@ -2670,6 +2615,19 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol pre_t = p_keys[pre].time - p_keys[idx].time; to_t = p_keys[next].time - p_keys[idx].time; post_t = p_keys[post].time - p_keys[idx].time; + + if ((pre > idx && idx == next && post < next) || (pre < idx && idx == next && post > next)) { + pre_t = p_keys[idx].time - p_keys[pre].time; + } else if (pre == idx) { + pre_t = idx < next ? -p_keys[idx].time * 2.0 : (length - p_keys[idx].time) * 2.0; + } + + if (idx == next) { + to_t = pre < idx ? (length - p_keys[idx].time) * 2.0 : -p_keys[idx].time * 2.0; + post_t = p_keys[next].time - p_keys[post].time + to_t; + } else if (next == post) { + post_t = idx < next ? (length - p_keys[next].time) * 2.0 + to_t : -p_keys[next].time * 2.0 + to_t; + } } if (p_interp == INTERPOLATION_CUBIC_ANGLE) { |