MayaFlux 1.0.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 578 of file PhysicsOperator.cpp.

579{
580 for (size_t i = 0; i < m_bond_root.size(); ++i) {
581 uint32_t root = m_bond_root[i];
582 if (root == i) {
583 continue;
584 }
585
586 auto self_idx = resolve_global_index(i);
587 auto root_idx = resolve_global_index(root);
588 if (!self_idx || !root_idx) {
589 continue;
590 }
591
592 auto& self_state = m_collections[self_idx->group].physics_state[self_idx->local];
593 const auto& self_pos = m_collections[self_idx->group].collection->get_points()[self_idx->local].position;
594 const auto& root_pos = m_collections[root_idx->group].collection->get_points()[root_idx->local].position;
595
596 glm::vec3 delta = root_pos - self_pos;
597 float distance = glm::length(delta);
598 if (distance < 0.001F) {
599 continue;
600 }
601
602 const float rest_length = m_bond_rest_length * std::cbrt(get_accreted_mass(root));
603
604 glm::vec3 direction = delta / distance;
605 self_state.force += direction * (m_bond_stiffness * (distance - rest_length));
606 }
607}
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: