Skip to content

Commit a58ae8e

Browse files
committed
Fixed SoftBody3D handles not being clickable in 3D Editor Viewport
Fix erratic behaviour when modifying pinned_points via inspector
1 parent 6681f25 commit a58ae8e

File tree

6 files changed

+78
-13
lines changed

6 files changed

+78
-13
lines changed

doc/classes/SoftBody3D.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<param index="0" name="point_index" type="int" />
8888
<param index="1" name="pinned" type="bool" />
8989
<param index="2" name="attachment_path" type="NodePath" default="NodePath(&quot;&quot;)" />
90+
<param index="3" name="insert_at" type="int" default="-1" />
9091
<description>
9192
Sets the pinned state of a surface vertex. When set to [code]true[/code], the optional [param attachment_path] can define a [Node3D] the pinned vertex will be attached to.
9293
</description>

editor/plugins/node_3d_editor_plugin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,9 +1951,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
19511951
surface->queue_redraw();
19521952
} else {
19531953
if (_edit.gizmo.is_valid()) {
1954-
if (_edit.original_mouse_pos != _edit.mouse_pos) {
1955-
_edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_handle_secondary, _edit.gizmo_initial_value, false);
1956-
}
1954+
_edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_handle_secondary, _edit.gizmo_initial_value, false);
1955+
spatial_editor->get_single_selected_node()->update_gizmos();
19571956
_edit.gizmo = Ref<EditorNode3DGizmo>();
19581957
break;
19591958
}

misc/extension_api_validation/4.3-stable.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ GH-94434
8080
Validate extension JSON: Error: Field 'classes/OS/methods/execute_with_pipe/arguments': size changed value in new API, from 2 to 3.
8181

8282
Optional argument added. Compatibility method registered.
83+
84+
85+
GH-94684
86+
--------
87+
Validate extension JSON: Error: Field 'classes/SoftBody3D/methods/set_point_pinned/arguments': size changed value in new API, from 3 to 4.
88+
89+
Optional argument added to allow for adding pin point at specific index. Compatibility method registered.

scene/3d/soft_body_3d.compat.inc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**************************************************************************/
2+
/* soft_body_3d.compat.inc */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#ifndef DISABLE_DEPRECATED
32+
33+
void SoftBody3D::_pin_point_bind_compat_94684(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) {
34+
pin_point(p_point_index, pin, p_spatial_attachment_path, -1);
35+
}
36+
37+
void SoftBody3D::_bind_compatibility_methods() {
38+
ClassDB::bind_compatibility_method(D_METHOD("set_point_pinned", "point_index", "pinned", "attachment_path"), &SoftBody3D::_pin_point_bind_compat_94684, DEFVAL(NodePath()));
39+
}
40+
41+
#endif // DISABLE_DEPRECATED

scene/3d/soft_body_3d.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/**************************************************************************/
3030

3131
#include "soft_body_3d.h"
32+
#include "soft_body_3d.compat.inc"
3233

3334
#include "scene/3d/physics/physics_body_3d.h"
3435

@@ -200,12 +201,18 @@ bool SoftBody3D::_set_property_pinned_points_indices(const Array &p_indices) {
200201
int point_index;
201202
for (int i = 0; i < p_indices_size; ++i) {
202203
point_index = p_indices.get(i);
203-
if (w[i].point_index != point_index) {
204-
if (-1 != w[i].point_index) {
204+
if (w[i].point_index != point_index || pinned_points.size() < p_indices_size) {
205+
bool insert = false;
206+
if (w[i].point_index != -1 && p_indices.find(w[i].point_index) == -1) {
205207
pin_point(w[i].point_index, false);
208+
insert = true;
206209
}
207210
w[i].point_index = point_index;
208-
pin_point(w[i].point_index, true);
211+
if (insert) {
212+
pin_point(w[i].point_index, true, NodePath(), i);
213+
} else {
214+
pin_point(w[i].point_index, true);
215+
}
209216
}
210217
}
211218
return true;
@@ -356,7 +363,7 @@ void SoftBody3D::_bind_methods() {
356363

357364
ClassDB::bind_method(D_METHOD("get_point_transform", "point_index"), &SoftBody3D::get_point_transform);
358365

359-
ClassDB::bind_method(D_METHOD("set_point_pinned", "point_index", "pinned", "attachment_path"), &SoftBody3D::pin_point, DEFVAL(NodePath()));
366+
ClassDB::bind_method(D_METHOD("set_point_pinned", "point_index", "pinned", "attachment_path", "insert_at"), &SoftBody3D::pin_point, DEFVAL(NodePath()), DEFVAL(-1));
360367
ClassDB::bind_method(D_METHOD("is_point_pinned", "point_index"), &SoftBody3D::is_point_pinned);
361368

362369
ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &SoftBody3D::set_ray_pickable);
@@ -668,10 +675,11 @@ void SoftBody3D::pin_point_toggle(int p_point_index) {
668675
pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index)));
669676
}
670677

671-
void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) {
678+
void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path, int p_insert_at) {
679+
ERR_FAIL_COND_MSG(p_insert_at < -1 || p_insert_at >= pinned_points.size(), "Invalid index for pin point insertion position.");
672680
_pin_point_on_physics_server(p_point_index, pin);
673681
if (pin) {
674-
_add_pinned_point(p_point_index, p_spatial_attachment_path);
682+
_add_pinned_point(p_point_index, p_spatial_attachment_path, p_insert_at);
675683
} else {
676684
_remove_pinned_point(p_point_index);
677685
}
@@ -730,7 +738,7 @@ void SoftBody3D::_pin_point_on_physics_server(int p_point_index, bool pin) {
730738
PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, p_point_index, pin);
731739
}
732740

733-
void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) {
741+
void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path, int p_insert_at) {
734742
SoftBody3D::PinnedPoint *pinned_point;
735743
if (-1 == _get_pinned_point(p_point_index, pinned_point)) {
736744
// Create new
@@ -743,7 +751,11 @@ void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_
743751
pp.offset = (pp.spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, pp.point_index));
744752
}
745753

746-
pinned_points.push_back(pp);
754+
if (p_insert_at != -1) {
755+
pinned_points.insert(p_insert_at, pp);
756+
} else {
757+
pinned_points.push_back(pp);
758+
}
747759

748760
} else {
749761
pinned_point->point_index = p_point_index;

scene/3d/soft_body_3d.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ class SoftBody3D : public MeshInstance3D {
126126
void _notification(int p_what);
127127
static void _bind_methods();
128128

129+
#ifndef DISABLE_DEPRECATED
130+
void _pin_point_bind_compat_94684(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath());
131+
static void _bind_compatibility_methods();
132+
#endif
133+
129134
PackedStringArray get_configuration_warnings() const override;
130135

131136
public:
@@ -177,7 +182,7 @@ class SoftBody3D : public MeshInstance3D {
177182
Vector3 get_point_transform(int p_point_index);
178183

179184
void pin_point_toggle(int p_point_index);
180-
void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath());
185+
void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath(), int p_insert_at = -1);
181186
bool is_point_pinned(int p_point_index) const;
182187

183188
void _pin_point_deferred(int p_point_index, bool pin, const NodePath p_spatial_attachment_path);
@@ -193,7 +198,7 @@ class SoftBody3D : public MeshInstance3D {
193198
void _update_cache_pin_points_datas();
194199

195200
void _pin_point_on_physics_server(int p_point_index, bool pin);
196-
void _add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path);
201+
void _add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path, int p_insert_at = -1);
197202
void _reset_points_offsets();
198203

199204
void _remove_pinned_point(int p_point_index);

0 commit comments

Comments
 (0)