Skip to content

Commit

Permalink
Fixed SoftBody3D handles not being clickable in 3D Editor Viewport
Browse files Browse the repository at this point in the history
Fix erratic behaviour when modifying pinned_points via inspector
  • Loading branch information
Musicgun47 committed Aug 30, 2024
1 parent db76de5 commit bb8cbc5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 2 additions & 3 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1935,9 +1935,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
surface->queue_redraw();
} else {
if (_edit.gizmo.is_valid()) {
if (_edit.original_mouse_pos != _edit.mouse_pos) {
_edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_handle_secondary, _edit.gizmo_initial_value, false);
}
_edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_handle_secondary, _edit.gizmo_initial_value, false);
spatial_editor->get_single_selected_node()->update_gizmos();
_edit.gizmo = Ref<EditorNode3DGizmo>();
break;
}
Expand Down
24 changes: 17 additions & 7 deletions scene/3d/soft_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,18 @@ bool SoftBody3D::_set_property_pinned_points_indices(const Array &p_indices) {
int point_index;
for (int i = 0; i < p_indices_size; ++i) {
point_index = p_indices.get(i);
if (w[i].point_index != point_index) {
if (-1 != w[i].point_index) {
if (w[i].point_index != point_index || pinned_points.size() < p_indices_size) {
bool insert = false;
if (-1 != w[i].point_index && -1 == p_indices.find(w[i].point_index)) {
pin_point(w[i].point_index, false);
insert = true;
}
w[i].point_index = point_index;
pin_point(w[i].point_index, true);
if (insert) {
pin_point(w[i].point_index, true, NodePath(), i);
} else {
pin_point(w[i].point_index, true);
}
}
}
return true;
Expand Down Expand Up @@ -668,10 +674,10 @@ void SoftBody3D::pin_point_toggle(int p_point_index) {
pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index)));
}

void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) {
void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path, int p_insert_at) {
_pin_point_on_physics_server(p_point_index, pin);
if (pin) {
_add_pinned_point(p_point_index, p_spatial_attachment_path);
_add_pinned_point(p_point_index, p_spatial_attachment_path, p_insert_at);
} else {
_remove_pinned_point(p_point_index);
}
Expand Down Expand Up @@ -730,7 +736,7 @@ void SoftBody3D::_pin_point_on_physics_server(int p_point_index, bool pin) {
PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, p_point_index, pin);
}

void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) {
void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path, int p_insert_at) {
SoftBody3D::PinnedPoint *pinned_point;
if (-1 == _get_pinned_point(p_point_index, pinned_point)) {
// Create new
Expand All @@ -743,7 +749,11 @@ void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_
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));
}

pinned_points.push_back(pp);
if (-1 != p_insert_at) {
pinned_points.insert(p_insert_at, pp);
} else {
pinned_points.push_back(pp);
}

} else {
pinned_point->point_index = p_point_index;
Expand Down
4 changes: 2 additions & 2 deletions scene/3d/soft_body_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class SoftBody3D : public MeshInstance3D {
Vector3 get_point_transform(int p_point_index);

void pin_point_toggle(int p_point_index);
void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath());
void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath(), int p_insert_at = -1);
bool is_point_pinned(int p_point_index) const;

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

void _pin_point_on_physics_server(int p_point_index, bool pin);
void _add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path);
void _add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path, int p_insert_at = -1);
void _reset_points_offsets();

void _remove_pinned_point(int p_point_index);
Expand Down

0 comments on commit bb8cbc5

Please sign in to comment.