MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ apply_bond_forces()

void MayaFlux::Nodes::Network::PhysicsOperator::apply_bond_forces ( )
private

Pull each bonded particle toward its root with a spring.

Rest length scales with cbrt(root's accreted mass): a grown body's satellites settle at a wider spread than a fresh one's, the same way any fixed-density accumulation of matter occupies more volume as it gains mass. Growth is a wider swarm of small particles, not a bigger point.

Definition at line 547 of file PhysicsOperator.cpp.

548{
549 for (size_t i = 0; i < m_bond_root.size(); ++i) {
550 uint32_t root = m_bond_root[i];
551 if (root == i) {
552 continue;
553 }
554
555 auto self_idx = resolve_global_index(i);
556 auto root_idx = resolve_global_index(root);
557 if (!self_idx || !root_idx) {
558 continue;
559 }
560
561 auto& self_state = m_collections[self_idx->group].physics_state[self_idx->local];
562 const auto& self_pos = m_collections[self_idx->group].collection->get_points()[self_idx->local].position;
563 const auto& root_pos = m_collections[root_idx->group].collection->get_points()[root_idx->local].position;
564
565 glm::vec3 delta = root_pos - self_pos;
566 float distance = glm::length(delta);
567 if (distance < 0.001F) {
568 continue;
569 }
570
571 const float rest_length = m_bond_rest_length * std::cbrt(get_accreted_mass(root));
572
573 glm::vec3 direction = delta / distance;
574 self_state.force += direction * (m_bond_stiffness * (distance - rest_length));
575 }
576}
std::optional< GroupIndex > resolve_global_index(size_t global_index) const
Resolve a global index the same way apply_impulse/get_data_at do.
std::vector< CollectionGroup > m_collections
float get_accreted_mass(size_t global_index) const
This particle's currently accreted mass.
std::vector< uint32_t > m_bond_root
Empty when no bonds are adopted; see sync_bonds_from_claims.
SpatialField distance(const glm::vec3 &anchor, float radius, DistanceMetric metric=DistanceMetric::EUCLIDEAN)
Normalized distance from an anchor point using the specified metric.

References get_accreted_mass(), m_bond_rest_length, m_bond_root, m_bond_stiffness, m_collections, and resolve_global_index().

Referenced by apply_forces().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: