mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Merge pull request #106321 from elzewyr/shrink-factor
SoftBody3D: Add a property for scaling rest lengths of edge constraints
This commit is contained in:
commit
05ceab6b7b
19 changed files with 126 additions and 0 deletions
|
|
@ -1132,6 +1132,20 @@ real_t GodotPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) const {
|
|||
return soft_body->get_linear_stiffness();
|
||||
}
|
||||
|
||||
void GodotPhysicsServer3D::soft_body_set_shrinking_factor(RID p_body, real_t p_shrinking_factor) {
|
||||
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(soft_body);
|
||||
|
||||
soft_body->set_shrinking_factor(p_shrinking_factor);
|
||||
}
|
||||
|
||||
real_t GodotPhysicsServer3D::soft_body_get_shrinking_factor(RID p_body) const {
|
||||
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL_V(soft_body, 0.f);
|
||||
|
||||
return soft_body->get_shrinking_factor();
|
||||
}
|
||||
|
||||
void GodotPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) {
|
||||
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(soft_body);
|
||||
|
|
|
|||
|
|
@ -294,6 +294,9 @@ public:
|
|||
virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) override;
|
||||
virtual real_t soft_body_get_linear_stiffness(RID p_body) const override;
|
||||
|
||||
virtual void soft_body_set_shrinking_factor(RID p_body, real_t p_shrinking_factor) override;
|
||||
virtual real_t soft_body_get_shrinking_factor(RID p_body) const override;
|
||||
|
||||
virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) override;
|
||||
virtual real_t soft_body_get_pressure_coefficient(RID p_body) const override;
|
||||
|
||||
|
|
|
|||
|
|
@ -272,8 +272,10 @@ void GodotSoftBody3D::update_area() {
|
|||
}
|
||||
|
||||
void GodotSoftBody3D::reset_link_rest_lengths() {
|
||||
float multiplier = 1.0 - shrinking_factor;
|
||||
for (Link &link : links) {
|
||||
link.rl = (link.n[0]->x - link.n[1]->x).length();
|
||||
link.rl *= multiplier;
|
||||
link.c1 = link.rl * link.rl;
|
||||
}
|
||||
}
|
||||
|
|
@ -861,6 +863,7 @@ void GodotSoftBody3D::append_link(uint32_t p_node1, uint32_t p_node2) {
|
|||
link.n[0] = node1;
|
||||
link.n[1] = node2;
|
||||
link.rl = (node1->x - node2->x).length();
|
||||
link.rl *= 1.0 - shrinking_factor;
|
||||
|
||||
links.push_back(link);
|
||||
}
|
||||
|
|
@ -918,6 +921,10 @@ void GodotSoftBody3D::set_linear_stiffness(real_t p_val) {
|
|||
linear_stiffness = p_val;
|
||||
}
|
||||
|
||||
void GodotSoftBody3D::set_shrinking_factor(real_t p_val) {
|
||||
shrinking_factor = p_val;
|
||||
}
|
||||
|
||||
void GodotSoftBody3D::set_pressure_coefficient(real_t p_val) {
|
||||
pressure_coefficient = p_val;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ class GodotSoftBody3D : public GodotCollisionObject3D {
|
|||
|
||||
int iteration_count = 5;
|
||||
real_t linear_stiffness = 0.5; // [0,1]
|
||||
real_t shrinking_factor = 0.0; // [-1,1]
|
||||
real_t pressure_coefficient = 0.0; // [-inf,+inf]
|
||||
real_t damping_coefficient = 0.01; // [0,1]
|
||||
real_t drag_coefficient = 0.0; // [0,1]
|
||||
|
|
@ -194,6 +195,9 @@ public:
|
|||
void set_linear_stiffness(real_t p_val);
|
||||
_FORCE_INLINE_ real_t get_linear_stiffness() const { return linear_stiffness; }
|
||||
|
||||
void set_shrinking_factor(real_t p_val);
|
||||
_FORCE_INLINE_ real_t get_shrinking_factor() const { return shrinking_factor; }
|
||||
|
||||
void set_pressure_coefficient(real_t p_val);
|
||||
_FORCE_INLINE_ real_t get_pressure_coefficient() const { return pressure_coefficient; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue