MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MeshTransformOperator.cpp
Go to the documentation of this file.
2
4
6
7// =============================================================================
8// Field binding
9// =============================================================================
10
11void MeshTransformOperator::bind(uint32_t slot_index, TransformField field)
12{
13 m_fields[slot_index] = std::move(field);
14 if (!m_accumulated_time.contains(slot_index))
15 m_accumulated_time[slot_index] = 0.0F;
16
18 "MeshTransformOperator: bound field to slot {}", slot_index);
19}
20
21void MeshTransformOperator::unbind(uint32_t slot_index)
22{
23 m_fields.erase(slot_index);
24 m_accumulated_time.erase(slot_index);
25}
26
28{
29 m_fields.clear();
30 m_accumulated_time.clear();
31}
32
33// =============================================================================
34// MeshOperator interface
35// =============================================================================
36
38{
39 auto field_it = m_fields.find(slot.index);
40 if (field_it != m_fields.end() && field_it->second) {
41 float& t = m_accumulated_time[slot.index];
42 t += dt;
43 slot.local_transform = field_it->second(t);
44 }
45
47 slot.dirty = true;
48}
49
51{
52 const auto now = std::chrono::steady_clock::now();
53 const float real_dt = std::chrono::duration<float>(now - m_last_tick).count();
54 m_last_tick = now;
55
56 if (!m_slots || !m_order)
57 return;
58
59 for (uint32_t idx : *m_order)
60 process_slot((*m_slots)[idx], real_dt);
61}
62
63// =============================================================================
64// Private helpers
65// =============================================================================
66
68{
69 if (!slot.parent_index.has_value() || !m_slots)
70 return glm::mat4(1.0F);
71
72 const uint32_t pidx = *slot.parent_index;
73 if (pidx >= m_slots->size())
74 return glm::mat4(1.0F);
75
76 return (*m_slots)[pidx].world_transform;
77}
78
79} // namespace MayaFlux::Nodes::Network
#define MF_DEBUG(comp, ctx,...)
const std::vector< uint32_t > * m_order
std::vector< MeshSlot > * m_slots
std::unordered_map< uint32_t, float > m_accumulated_time
Per-slot accumulated time in seconds, keyed by slot index.
std::unordered_map< uint32_t, TransformField > m_fields
void process(float dt) override
Iterate slots in topological order and call process_slot() on each.
glm::mat4 parent_world(const MeshSlot &slot) const
Resolve the world transform of a slot's parent, or identity if root.
void process_slot(MeshSlot &slot, float dt) override
Evaluate the bound field (if any), update local_transform, then propagate the world_transform from th...
std::function< glm::mat4(float)> TransformField
Field type: maps accumulated time (seconds) to a local glm::mat4.
void bind(uint32_t slot_index, TransformField field)
Bind a TransformField to a slot.
std::chrono::steady_clock::time_point m_last_tick
Wall-clock timestamp of the last process() call.
void unbind(uint32_t slot_index)
Remove the TransformField bound to a slot.
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
bool dirty
Set when local_transform or slot config changes since last upload.
Definition MeshSlot.hpp:54
glm::mat4 local_transform
Local-space transform relative to parent (or world if root).
Definition MeshSlot.hpp:42
uint32_t index
Position of this slot in MeshNetwork::m_slots. Stable after insertion.
Definition MeshSlot.hpp:33
glm::mat4 world_transform
World-space transform, recomputed each cycle from the DAG.
Definition MeshSlot.hpp:45
std::optional< uint32_t > parent_index
Index of the parent slot, or nullopt for a root slot.
Definition MeshSlot.hpp:48
Named, independently transformable mesh unit within a MeshNetwork.
Definition MeshSlot.hpp:31