MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
InstanceNetwork.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "GeometrySlot.hpp"
4#include "NodeNetwork.hpp"
5
7
8/**
9 * @class InstanceNetwork
10 * @brief NodeNetwork whose slots are flat, peer GeometrySlots for instanced rendering.
11 *
12 * All slots may hold the same node (shared template geometry) or distinct nodes.
13 * No DAG, no parent indices. process_batch() runs the operator chain then calls
14 * compute_frame() on each slot's node. The buffer layer reads the slot list each
15 * cycle and uploads per-instance transforms as an SSBO for a single instanced
16 * draw call. Per-vertex data (color, normals, UVs) is owned by each node's
17 * vertex buffer and is unchanged by the instancing path.
18 *
19 * Usage:
20 * @code
21 * auto net = std::make_shared<InstanceNetwork>();
22 * auto tmpl = std::make_shared<PathGeneratorNode>(...);
23 *
24 * for (uint32_t i = 0; i < 200; ++i) {
25 * uint32_t idx = net->add_slot("inst_" + std::to_string(i), tmpl);
26 * net->get_slot(idx).transform = glm::translate(glm::mat4{1}, positions[i]);
27 * }
28 *
29 * auto op = net->create_operator<InstanceFieldOperator>();
30 * op->bind_position(0, Kinesis::VectorField { [](glm::vec3 p) {
31 * return p + glm::vec3(0.01F, 0, 0);
32 * }});
33 * @endcode
34 */
35class MAYAFLUX_API InstanceNetwork : public NodeNetwork {
36public:
38 ~InstanceNetwork() override = default;
39
40 uint32_t add_slot(std::string name, std::shared_ptr<GpuSync::GeometryWriterNode> node);
41
42 [[nodiscard]] GeometrySlot& get_slot(uint32_t index);
43 [[nodiscard]] const GeometrySlot& get_slot(uint32_t index) const;
44 [[nodiscard]] GeometrySlot* find_slot(std::string_view name);
45 [[nodiscard]] const GeometrySlot* find_slot(std::string_view name) const;
46
47 [[nodiscard]] size_t slot_count() const { return m_slots.size(); }
48 [[nodiscard]] const std::vector<GeometrySlot>& slots() const { return m_slots; }
49 [[nodiscard]] std::vector<GeometrySlot>& slots() { return m_slots; }
50
51 void process_batch(unsigned int num_samples) override;
52 void reset() override;
53
54 [[nodiscard]] size_t get_node_count() const override { return m_slots.size(); }
55 [[nodiscard]] std::optional<double> get_node_output(size_t index) const override;
56 [[nodiscard]] std::unordered_map<std::string, std::string> get_metadata() const override;
57
58 void set_operator(std::shared_ptr<NetworkOperator> op);
59
60 template <typename OpType, typename... Args>
61 std::shared_ptr<OpType> create_operator(Args&&... args)
62 {
63 auto op = std::make_shared<OpType>(std::forward<Args>(args)...);
64 set_operator(op);
65 return op;
66 }
67
68 NetworkOperator* get_operator() override { return m_operator.get(); }
69 const NetworkOperator* get_operator() const override { return m_operator.get(); }
70 bool has_operator() const override { return m_operator != nullptr; }
71
72private:
73 std::vector<GeometrySlot> m_slots;
74 std::shared_ptr<NetworkOperator> m_operator;
75};
76
77} // namespace MayaFlux::Nodes::Network
std::vector< GeometrySlot > & slots()
std::shared_ptr< OpType > create_operator(Args &&... args)
NetworkOperator * get_operator() override
std::shared_ptr< NetworkOperator > m_operator
const std::vector< GeometrySlot > & slots() const
size_t get_node_count() const override
Get the number of nodes in the network.
const NetworkOperator * get_operator() const override
NodeNetwork whose slots are flat, peer GeometrySlots for instanced rendering.
Domain-agnostic interpretive lens for network processing.
Abstract base class for structured collections of nodes with defined relationships.
Peer unit within an InstanceNetwork.