Skip to content

Commit 59b825a

Browse files
Expose mesh vertex count method in SoftBody3D
1 parent 320e818 commit 59b825a

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

doc/classes/SoftBody3D.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
<member name="parent_collision_ignore" type="NodePath" setter="set_parent_collision_ignore" getter="get_parent_collision_ignore" default="NodePath(&quot;&quot;)">
151151
[NodePath] to a [CollisionObject3D] this SoftBody3D should avoid clipping.
152152
</member>
153+
<member name="point_count" type="int" setter="" getter="get_point_count" default="0">
154+
The number of vertices (points) on the soft body mesh.
155+
</member>
153156
<member name="pressure_coefficient" type="float" setter="set_pressure_coefficient" getter="get_pressure_coefficient" default="0.0">
154157
The pressure coefficient of this soft body. Simulate pressure build-up from inside this body. Higher values increase the strength of this effect.
155158
</member>

scene/3d/physics/soft_body_3d.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ void SoftBody3D::_bind_methods() {
378378
ClassDB::bind_method(D_METHOD("set_point_pinned", "point_index", "pinned", "attachment_path", "insert_at"), &SoftBody3D::pin_point, DEFVAL(NodePath()), DEFVAL(-1));
379379
ClassDB::bind_method(D_METHOD("is_point_pinned", "point_index"), &SoftBody3D::is_point_pinned);
380380

381+
ClassDB::bind_method(D_METHOD("get_point_count"), &SoftBody3D::get_point_count);
382+
381383
ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &SoftBody3D::set_ray_pickable);
382384
ClassDB::bind_method(D_METHOD("is_ray_pickable"), &SoftBody3D::is_ray_pickable);
383385

@@ -396,6 +398,8 @@ void SoftBody3D::_bind_methods() {
396398

397399
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable");
398400

401+
ADD_PROPERTY(PropertyInfo(Variant::INT, "point_count"), "", "get_point_count");
402+
399403
ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,KeepActive"), "set_disable_mode", "get_disable_mode");
400404

401405
BIND_ENUM_CONSTANT(DISABLE_MODE_REMOVE);
@@ -692,6 +696,14 @@ Vector3 SoftBody3D::get_point_transform(int p_point_index) {
692696
return PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, p_point_index);
693697
}
694698

699+
uint32_t SoftBody3D::get_point_count() const {
700+
if (mesh.is_null()) {
701+
return 0;
702+
}
703+
704+
return mesh->surface_get_array_len(0);
705+
}
706+
695707
void SoftBody3D::apply_impulse(int p_point_index, const Vector3 &p_impulse) {
696708
PhysicsServer3D::get_singleton()->soft_body_apply_point_impulse(physics_rid, p_point_index, p_impulse);
697709
}

scene/3d/physics/soft_body_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class SoftBody3D : public MeshInstance3D {
151151

152152
void set_parent_collision_ignore(const NodePath &p_parent_collision_ignore);
153153
const NodePath &get_parent_collision_ignore() const;
154+
uint32_t get_point_count() const;
154155

155156
void set_pinned_points_indices(Vector<PinnedPoint> p_pinned_points_indices);
156157
Vector<PinnedPoint> get_pinned_points_indices();

0 commit comments

Comments
 (0)