diff options
Diffstat (limited to 'scene/3d/soft_body_3d.cpp')
-rw-r--r-- | scene/3d/soft_body_3d.cpp | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp index 47c568e9b4..a267c57f5e 100644 --- a/scene/3d/soft_body_3d.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -115,8 +115,9 @@ SoftBody3D::PinnedPoint SoftBody3D::PinnedPoint::operator=(const PinnedPoint &ob } void SoftBody3D::_update_pickable() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } bool pickable = ray_pickable && is_visible_in_tree(); PhysicsServer3D::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable); } @@ -196,8 +197,9 @@ bool SoftBody3D::_set_property_pinned_points_indices(const Array &p_indices) { 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 (-1 != w[i].point_index) { pin_point(w[i].point_index, false); + } w[i].point_index = point_index; pin_point(w[i].point_index, true); } @@ -265,8 +267,9 @@ void SoftBody3D::_notification(int p_what) { prepare_physics_server(); } break; case NOTIFICATION_READY: { - if (!parent_collision_ignore.is_empty()) + if (!parent_collision_ignore.is_empty()) { add_collision_exception_with(get_node(parent_collision_ignore)); + } } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -377,16 +380,18 @@ String SoftBody3D::get_configuration_warning() const { String warning = MeshInstance3D::get_configuration_warning(); if (get_mesh().is_null()) { - if (!warning.empty()) + if (!warning.empty()) { warning += "\n\n"; + } warning += TTR("This body will be ignored until you set a mesh."); } Transform t = get_transform(); if ((ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(2).length() - 1.0) > 0.05)) { - if (!warning.empty()) + if (!warning.empty()) { warning += "\n\n"; + } warning += TTR("Size changes to SoftBody3D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); } @@ -395,8 +400,9 @@ String SoftBody3D::get_configuration_warning() const { } void SoftBody3D::_update_physics_server() { - if (!simulation_started) + if (!simulation_started) { return; + } _update_cache_pin_points_datas(); // Submit bone attachment @@ -410,8 +416,9 @@ void SoftBody3D::_update_physics_server() { } void SoftBody3D::_draw_soft_mesh() { - if (get_mesh().is_null()) + if (get_mesh().is_null()) { return; + } if (!rendering_server_handler.is_ready()) { rendering_server_handler.prepare(get_mesh()->get_rid(), 0); @@ -433,10 +440,11 @@ void SoftBody3D::_draw_soft_mesh() { void SoftBody3D::prepare_physics_server() { if (Engine::get_singleton()->is_editor_hint()) { - if (get_mesh().is_valid()) + if (get_mesh().is_valid()) { PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); - else + } else { PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); + } return; } @@ -454,8 +462,9 @@ void SoftBody3D::prepare_physics_server() { } void SoftBody3D::become_mesh_owner() { - if (mesh.is_null()) + if (mesh.is_null()) { return; + } if (!mesh_owner) { mesh_owner = true; @@ -507,10 +516,11 @@ uint32_t SoftBody3D::get_collision_layer() const { void SoftBody3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -520,10 +530,11 @@ bool SoftBody3D::get_collision_mask_bit(int p_bit) const { void SoftBody3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t layer = get_collision_layer(); - if (p_value) + if (p_value) { layer |= 1 << p_bit; - else + } else { layer &= ~(1 << p_bit); + } set_collision_layer(layer); } @@ -702,8 +713,9 @@ void SoftBody3D::_make_cache_dirty() { } void SoftBody3D::_update_cache_pin_points_datas() { - if (!pinned_points_cache_dirty) + if (!pinned_points_cache_dirty) { return; + } pinned_points_cache_dirty = false; @@ -749,17 +761,20 @@ void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_ } void SoftBody3D::_reset_points_offsets() { - if (!Engine::get_singleton()->is_editor_hint()) + if (!Engine::get_singleton()->is_editor_hint()) { return; + } const PinnedPoint *r = pinned_points.ptr(); PinnedPoint *w = pinned_points.ptrw(); for (int i = pinned_points.size() - 1; 0 <= i; --i) { - if (!r[i].spatial_attachment) + if (!r[i].spatial_attachment) { w[i].spatial_attachment = Object::cast_to<Node3D>(get_node(r[i].spatial_attachment_path)); + } - if (!r[i].spatial_attachment) + if (!r[i].spatial_attachment) { continue; + } w[i].offset = (r[i].spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, r[i].point_index)); } |