Changeset View
Changeset View
Standalone View
Standalone View
source/blender/physics/intern/BPH_mass_spring.cpp
| Context not available. | |||||
| for (link = cloth->springs; link; link = link->next) { | for (link = cloth->springs; link; link = link->next) { | ||||
| ClothSpring *spring = (ClothSpring *)link->link; | ClothSpring *spring = (ClothSpring *)link->link; | ||||
| switch (spring->type) { | switch (spring->type) { | ||||
| case CLOTH_SPRING_TYPE_BENDING_ANG: | case CLOTH_SPRING_TYPE_BENDING_HAIR: | ||||
| /* angular bending combines 3 vertices */ | /* angular bending combines 3 vertices */ | ||||
| nondiag += 3; | nondiag += 3; | ||||
| break; | break; | ||||
| Context not available. | |||||
| s->flags &= ~CLOTH_SPRING_FLAG_NEEDED; | s->flags &= ~CLOTH_SPRING_FLAG_NEEDED; | ||||
| // calculate force of structural + shear springs | /* Calculate force of bending springs. */ | ||||
| if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SEWING)) { | if (s->type & CLOTH_SPRING_TYPE_BENDING) { | ||||
| #ifdef CLOTH_FORCE_SPRING_BEND | |||||
| float k, scaling; | |||||
| s->flags |= CLOTH_SPRING_FLAG_NEEDED; | |||||
| scaling = parms->bending + s->ang_stiffness * fabsf(parms->max_bend - parms->bending); | |||||
| k = scaling * s->restlen * 0.1f; /* Multiplying by 0.1, just to scale the forces to more reasonable values. */ | |||||
| BPH_mass_spring_force_spring_angular(data, s->ij, s->kl, s->pa, s->pb, s->la, s->lb, | |||||
| s->restang, k, parms->bending_damping); | |||||
| #endif | |||||
| } | |||||
| /* Calculate force of structural + shear springs. */ | |||||
| if (s->type & (CLOTH_SPRING_TYPE_STRUCTURAL | CLOTH_SPRING_TYPE_SEWING)) { | |||||
| #ifdef CLOTH_FORCE_SPRING_STRUCTURAL | #ifdef CLOTH_FORCE_SPRING_STRUCTURAL | ||||
| float k_tension, scaling_tension; | float k_tension, scaling_tension; | ||||
| s->flags |= CLOTH_SPRING_FLAG_NEEDED; | s->flags |= CLOTH_SPRING_FLAG_NEEDED; | ||||
| scaling_tension = parms->tension + s->stiffness * fabsf(parms->max_tension - parms->tension); | scaling_tension = parms->tension + s->lin_stiffness * fabsf(parms->max_tension - parms->tension); | ||||
| k_tension = scaling_tension / (parms->avg_spring_len + FLT_EPSILON); | k_tension = scaling_tension / (parms->avg_spring_len + FLT_EPSILON); | ||||
| if (s->type & CLOTH_SPRING_TYPE_SEWING) { | if (s->type & CLOTH_SPRING_TYPE_SEWING) { | ||||
| Context not available. | |||||
| } | } | ||||
| else { | else { | ||||
| float k_compression, scaling_compression; | float k_compression, scaling_compression; | ||||
| scaling_compression = parms->compression + s->stiffness * fabsf(parms->max_compression - parms->compression); | scaling_compression = parms->compression + s->lin_stiffness * fabsf(parms->max_compression - parms->compression); | ||||
| k_compression = scaling_compression / (parms->avg_spring_len + FLT_EPSILON); | k_compression = scaling_compression / (parms->avg_spring_len + FLT_EPSILON); | ||||
| BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, | BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, | ||||
| Context not available. | |||||
| s->flags |= CLOTH_SPRING_FLAG_NEEDED; | s->flags |= CLOTH_SPRING_FLAG_NEEDED; | ||||
| scaling = parms->shear + s->stiffness * fabsf(parms->max_shear - parms->shear); | scaling = parms->shear + s->lin_stiffness * fabsf(parms->max_shear - parms->shear); | ||||
| k = scaling / (parms->avg_spring_len + FLT_EPSILON); | k = scaling / (parms->avg_spring_len + FLT_EPSILON); | ||||
| BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k, parms->shear_damp, | BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k, parms->shear_damp, | ||||
| Context not available. | |||||
| s->flags |= CLOTH_SPRING_FLAG_NEEDED; | s->flags |= CLOTH_SPRING_FLAG_NEEDED; | ||||
| scaling = parms->bending + s->stiffness * fabsf(parms->max_bend - parms->bending); | scaling = parms->bending + s->lin_stiffness * fabsf(parms->max_bend - parms->bending); | ||||
| kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); | kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); | ||||
| // Fix for [#45084] for cloth stiffness must have cb proportional to kb | // Fix for [#45084] for cloth stiffness must have cb proportional to kb | ||||
| Context not available. | |||||
| BPH_mass_spring_force_spring_bending(data, s->ij, s->kl, s->restlen, kb, cb); | BPH_mass_spring_force_spring_bending(data, s->ij, s->kl, s->restlen, kb, cb); | ||||
| #endif | #endif | ||||
| } | } | ||||
| else if (s->type & CLOTH_SPRING_TYPE_BENDING_ANG) { | else if (s->type & CLOTH_SPRING_TYPE_BENDING_HAIR) { | ||||
| #ifdef CLOTH_FORCE_SPRING_BEND | #ifdef CLOTH_FORCE_SPRING_BEND | ||||
| float kb, cb, scaling; | float kb, cb, scaling; | ||||
| Context not available. | |||||
| * this is crap, but needed due to cloth/hair mixing ... | * this is crap, but needed due to cloth/hair mixing ... | ||||
| * max_bend factor is not even used for hair, so ... | * max_bend factor is not even used for hair, so ... | ||||
| */ | */ | ||||
| scaling = s->stiffness * parms->bending; | scaling = s->lin_stiffness * parms->bending; | ||||
| kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); | kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); | ||||
| // Fix for [#45084] for cloth stiffness must have cb proportional to kb | // Fix for [#45084] for cloth stiffness must have cb proportional to kb | ||||
| cb = kb * parms->bending_damping; | cb = kb * parms->bending_damping; | ||||
| /* XXX assuming same restlen for ij and jk segments here, this can be done correctly for hair later */ | /* XXX assuming same restlen for ij and jk segments here, this can be done correctly for hair later */ | ||||
| BPH_mass_spring_force_spring_bending_angular(data, s->ij, s->kl, s->mn, s->target, kb, cb); | BPH_mass_spring_force_spring_bending_hair(data, s->ij, s->kl, s->mn, s->target, kb, cb); | ||||
| #if 0 | #if 0 | ||||
| { | { | ||||
| Context not available. | |||||