Skip to content

Commit 97e1f8f

Browse files
Expose existing SoftBody3D methods in editor
1 parent 3c7f9b9 commit 97e1f8f

19 files changed

+94
-0
lines changed

doc/classes/PhysicsServer3D.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,20 @@
11501150
Returns the current position of the given soft body point in global coordinates.
11511151
</description>
11521152
</method>
1153+
<method name="soft_body_get_point_count" qualifiers="const">
1154+
<return type="int" />
1155+
<param index="0" name="body" type="RID" />
1156+
<description>
1157+
Returns total number of points on the given soft body.
1158+
</description>
1159+
</method>
1160+
<method name="soft_body_get_bounds" qualifiers="const">
1161+
<return type="AABB" />
1162+
<param index="0" name="body" type="RID" />
1163+
<description>
1164+
Returns the [AABB] of the given soft body.
1165+
</description>
1166+
</method>
11531167
<method name="soft_body_get_pressure_coefficient" qualifiers="const">
11541168
<return type="float" />
11551169
<param index="0" name="body" type="RID" />

doc/classes/PhysicsServer3DExtension.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,18 @@
10731073
<description>
10741074
</description>
10751075
</method>
1076+
<method name="_soft_body_get_point_count" qualifiers="virtual required const">
1077+
<return type="int" />
1078+
<param index="0" name="body" type="RID" />
1079+
<description>
1080+
</description>
1081+
</method>
1082+
<method name="_soft_body_get_bounds" qualifiers="virtual required const">
1083+
<return type="AABB" />
1084+
<param index="0" name="body" type="RID" />
1085+
<description>
1086+
</description>
1087+
</method>
10761088
<method name="_soft_body_get_pressure_coefficient" qualifiers="virtual required const">
10771089
<return type="float" />
10781090
<param index="0" name="body" type="RID" />

doc/classes/SoftBody3D.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@
8484
Returns local translation of a vertex in the surface array.
8585
</description>
8686
</method>
87+
<method name="get_point_count">
88+
<return type="int" />
89+
<description>
90+
Returns total number of points on the given soft body.
91+
</description>
92+
</method>
93+
<method name="get_bounds">
94+
<return type="AABB" />
95+
<description>
96+
Returns the [AABB] of the given soft body.
97+
</description>
98+
</method>
8799
<method name="is_point_pinned" qualifiers="const">
88100
<return type="bool" />
89101
<param index="0" name="point_index" type="int" />

modules/godot_physics_3d/godot_physics_server_3d.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,13 @@ Vector3 GodotPhysicsServer3D::soft_body_get_point_global_position(RID p_body, in
12161216
return soft_body->get_vertex_position(p_point_index);
12171217
}
12181218

1219+
uint32_t GodotPhysicsServer3D::soft_body_get_point_count(RID p_body) const {
1220+
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
1221+
ERR_FAIL_NULL_V(soft_body, 0);
1222+
1223+
return soft_body->get_vertex_count();
1224+
}
1225+
12191226
void GodotPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) {
12201227
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
12211228
ERR_FAIL_NULL(soft_body);

modules/godot_physics_3d/godot_physics_server_3d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ class GodotPhysicsServer3D : public PhysicsServer3D {
313313
virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) override;
314314
virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index) const override;
315315

316+
virtual uint32_t soft_body_get_point_count(RID p_body) const override;
317+
316318
virtual void soft_body_remove_all_pinned_points(RID p_body) override;
317319
virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) override;
318320
virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index) const override;

modules/godot_physics_3d/godot_soft_body_3d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ uint32_t GodotSoftBody3D::get_node_count() const {
426426
return nodes.size();
427427
}
428428

429+
uint32_t GodotSoftBody3D::get_vertex_count() const {
430+
return map_visual_to_physics.size();
431+
}
432+
429433
real_t GodotSoftBody3D::get_node_inv_mass(uint32_t p_node_index) const {
430434
ERR_FAIL_UNSIGNED_INDEX_V(p_node_index, nodes.size(), 0.0);
431435
return nodes[p_node_index].im;

modules/godot_physics_3d/godot_soft_body_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class GodotSoftBody3D : public GodotCollisionObject3D {
168168
bool is_vertex_pinned(int p_index) const;
169169

170170
uint32_t get_node_count() const;
171+
uint32_t get_vertex_count() const;
171172
real_t get_node_inv_mass(uint32_t p_node_index) const;
172173
Vector3 get_node_position(uint32_t p_node_index) const;
173174
Vector3 get_node_velocity(uint32_t p_node_index) const;

modules/jolt_physics/jolt_physics_server_3d.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,13 @@ Vector3 JoltPhysicsServer3D::soft_body_get_point_global_position(RID p_body, int
12241224
return body->get_vertex_position(p_point_index);
12251225
}
12261226

1227+
uint32_t JoltPhysicsServer3D::soft_body_get_point_count(RID p_body) const {
1228+
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
1229+
ERR_FAIL_NULL_V(body, 0);
1230+
1231+
return body->get_vertex_count();
1232+
}
1233+
12271234
void JoltPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) {
12281235
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
12291236
ERR_FAIL_NULL(body);

modules/jolt_physics/jolt_physics_server_3d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ class JoltPhysicsServer3D final : public PhysicsServer3D {
356356

357357
virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index) const override;
358358

359+
virtual uint32_t soft_body_get_point_count(RID p_body) const override;
360+
359361
virtual void soft_body_remove_all_pinned_points(RID p_body) override;
360362

361363
virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) override;

modules/jolt_physics/objects/jolt_soft_body_3d.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,13 @@ void JoltSoftBody3D::set_vertex_position(int p_index, const Vector3 &p_position)
721721
_vertices_changed();
722722
}
723723

724+
uint32_t JoltSoftBody3D::get_vertex_count() const {
725+
ERR_FAIL_COND_V_MSG(!in_space(), false, vformat("Failed to retrieve vertex count for '%s'. Doing so without a physics space is not supported when using Jolt Physics. If this relates to a node, try adding the node to a scene tree first.", to_string()));
726+
ERR_FAIL_NULL_V(shared, 0);
727+
728+
return shared->mesh_to_physics.size();
729+
}
730+
724731
void JoltSoftBody3D::pin_vertex(int p_index) {
725732
pinned_vertices.insert(p_index);
726733

0 commit comments

Comments
 (0)