diff --git a/doc/classes/SoftBody3D.xml b/doc/classes/SoftBody3D.xml index 33561b2844bf..e4e73a61f594 100644 --- a/doc/classes/SoftBody3D.xml +++ b/doc/classes/SoftBody3D.xml @@ -150,6 +150,9 @@ [NodePath] to a [CollisionObject3D] this SoftBody3D should avoid clipping. + + The number of vertices (points) on the soft body mesh. + The pressure coefficient of this soft body. Simulate pressure build-up from inside this body. Higher values increase the strength of this effect. diff --git a/scene/3d/physics/soft_body_3d.cpp b/scene/3d/physics/soft_body_3d.cpp index 2e7d2c25b36c..c328ab4a7d0d 100644 --- a/scene/3d/physics/soft_body_3d.cpp +++ b/scene/3d/physics/soft_body_3d.cpp @@ -378,6 +378,8 @@ void SoftBody3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_point_pinned", "point_index", "pinned", "attachment_path", "insert_at"), &SoftBody3D::pin_point, DEFVAL(NodePath()), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("is_point_pinned", "point_index"), &SoftBody3D::is_point_pinned); + ClassDB::bind_method(D_METHOD("get_point_count"), &SoftBody3D::get_point_count); + ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &SoftBody3D::set_ray_pickable); ClassDB::bind_method(D_METHOD("is_ray_pickable"), &SoftBody3D::is_ray_pickable); @@ -396,6 +398,8 @@ void SoftBody3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "point_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_point_count"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,KeepActive"), "set_disable_mode", "get_disable_mode"); BIND_ENUM_CONSTANT(DISABLE_MODE_REMOVE); @@ -692,6 +696,16 @@ Vector3 SoftBody3D::get_point_transform(int p_point_index) { return PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, p_point_index); } +int SoftBody3D::get_point_count() const { + if (mesh.is_null()) { + return 0; + } + + const int vertex_count = mesh->surface_get_array_len(0); + ERR_FAIL_COND_V(vertex_count < 0, 0); + return vertex_count; +} + void SoftBody3D::apply_impulse(int p_point_index, const Vector3 &p_impulse) { PhysicsServer3D::get_singleton()->soft_body_apply_point_impulse(physics_rid, p_point_index, p_impulse); } diff --git a/scene/3d/physics/soft_body_3d.h b/scene/3d/physics/soft_body_3d.h index 05ea50cfe387..05e824f0e8d2 100644 --- a/scene/3d/physics/soft_body_3d.h +++ b/scene/3d/physics/soft_body_3d.h @@ -151,6 +151,7 @@ class SoftBody3D : public MeshInstance3D { void set_parent_collision_ignore(const NodePath &p_parent_collision_ignore); const NodePath &get_parent_collision_ignore() const; + int get_point_count() const; void set_pinned_points_indices(Vector p_pinned_points_indices); Vector get_pinned_points_indices();