SoftBody3D: Add a property for scaling rest lengths of edge constraints
This commit is contained in:
@ -1126,6 +1126,20 @@ real_t JoltPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) const {
|
||||
return (real_t)body->get_stiffness_coefficient();
|
||||
}
|
||||
|
||||
void JoltPhysicsServer3D::soft_body_set_shrinking_factor(RID p_body, real_t p_shrinking_factor) {
|
||||
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(body);
|
||||
|
||||
return body->set_shrinking_factor((float)p_shrinking_factor);
|
||||
}
|
||||
|
||||
real_t JoltPhysicsServer3D::soft_body_get_shrinking_factor(RID p_body) const {
|
||||
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL_V(body, 0.0);
|
||||
|
||||
return (real_t)body->get_shrinking_factor();
|
||||
}
|
||||
|
||||
void JoltPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_coefficient) {
|
||||
JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(body);
|
||||
|
||||
@ -331,6 +331,9 @@ public:
|
||||
virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_coefficient) 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_coefficient) override;
|
||||
virtual real_t soft_body_get_pressure_coefficient(RID p_body) const override;
|
||||
|
||||
|
||||
@ -202,6 +202,10 @@ bool JoltSoftBody3D::_ref_shared_data() {
|
||||
vertex_attrib.mCompliance = vertex_attrib.mShearCompliance = inverse_stiffness;
|
||||
|
||||
settings.CreateConstraints(&vertex_attrib, 1, JPH::SoftBodySharedSettings::EBendType::None);
|
||||
float multiplier = 1.0f - shrinking_factor;
|
||||
for (JPH::SoftBodySharedSettings::Edge &e : settings.mEdgeConstraints) {
|
||||
e.mRestLength *= multiplier;
|
||||
}
|
||||
settings.Optimize();
|
||||
} else {
|
||||
iter_shared_data->value.ref_count++;
|
||||
@ -454,6 +458,14 @@ void JoltSoftBody3D::set_stiffness_coefficient(float p_coefficient) {
|
||||
stiffness_coefficient = CLAMP(p_coefficient, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
float JoltSoftBody3D::get_shrinking_factor() const {
|
||||
return shrinking_factor;
|
||||
}
|
||||
|
||||
void JoltSoftBody3D::set_shrinking_factor(float p_shrinking_factor) {
|
||||
shrinking_factor = p_shrinking_factor;
|
||||
}
|
||||
|
||||
void JoltSoftBody3D::set_pressure(float p_pressure) {
|
||||
if (unlikely(pressure == p_pressure)) {
|
||||
return;
|
||||
|
||||
@ -64,6 +64,7 @@ class JoltSoftBody3D final : public JoltObject3D {
|
||||
float pressure = 0.0f;
|
||||
float linear_damping = 0.01f;
|
||||
float stiffness_coefficient = 0.5f;
|
||||
float shrinking_factor = 0.0f;
|
||||
|
||||
int simulation_precision = 5;
|
||||
|
||||
@ -138,6 +139,9 @@ public:
|
||||
float get_stiffness_coefficient() const;
|
||||
void set_stiffness_coefficient(float p_coefficient);
|
||||
|
||||
float get_shrinking_factor() const;
|
||||
void set_shrinking_factor(float p_shrinking_factor);
|
||||
|
||||
float get_pressure() const { return pressure; }
|
||||
void set_pressure(float p_pressure);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user