MayaFlux 1.0.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
50// =============================================================================
51// Private helpers
52// =============================================================================
53
55{
56 if (!slot.parent_index.has_value() || !m_slots)
57 return glm::mat4(1.0F);
58
59 const uint32_t pidx = *slot.parent_index;
60 if (pidx >= m_slots->size())
61 return glm::mat4(1.0F);
62
63 return (*m_slots)[pidx].world_transform;
64}
65
66} // namespace MayaFlux::Nodes::Network
#define MF_DEBUG(comp, ctx,...)
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
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.
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