MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
LineSegmentsNode.cpp
Go to the documentation of this file.
2
4
6
8
9LineSegmentsNode::LineSegmentsNode(size_t initial_capacity)
10 : PathGeneratorNode(Kinesis::InterpolationMode::CATMULL_ROM, 0, 0, 0.5)
11{
12 auto layout = Kakshya::VertexLayout::for_lines(sizeof(LineVertex));
13 layout.vertex_count = initial_capacity;
14 set_vertex_layout(layout);
15
16 m_segments.reserve(initial_capacity);
17
19 "Created LineSegmentsNode with capacity {}", initial_capacity);
20}
21
22//-----------------------------------------------------------------------------
23// Core segment API
24//-----------------------------------------------------------------------------
25
27{
28 m_segments.push_back(a);
29 m_segments.push_back(b);
31}
32
33void LineSegmentsNode::add_axis(const LineVertex& origin, const glm::vec3& direction, float length)
34{
35 LineVertex tip = origin;
36 tip.position = origin.position + direction * length;
37 m_segments.push_back(origin);
38 m_segments.push_back(tip);
40}
41
47
48//-----------------------------------------------------------------------------
49// Differential geometry annotation
50//-----------------------------------------------------------------------------
51
53 const std::vector<LineVertex>& path_vertices,
54 float length,
55 size_t stride)
56{
57 append_pairs(Kinesis::compute_path_normals(path_vertices, length, stride));
58}
59
61 const std::vector<LineVertex>& path_vertices,
62 float length,
63 size_t stride)
64{
65 append_pairs(Kinesis::compute_path_tangents(path_vertices, length, stride));
66}
67
69 const std::vector<LineVertex>& path_vertices,
70 float scale,
71 size_t stride)
72{
73 append_pairs(Kinesis::compute_path_curvature(path_vertices, scale, stride));
74}
75
76//-----------------------------------------------------------------------------
77// compute_frame
78//-----------------------------------------------------------------------------
79
81{
82 if (m_segments.empty()) {
84 return;
85 }
86
88 return;
89 }
90
91#ifdef MAYAFLUX_PLATFORM_MACOS
92 std::vector<LineVertex> expanded = expand_lines_to_triangles(m_segments);
93 set_vertices<LineVertex>(std::span { expanded.data(), expanded.size() });
94
95 auto layout = get_vertex_layout();
96 layout->vertex_count = static_cast<uint32_t>(expanded.size());
97 set_vertex_layout(*layout);
98#else
99 set_vertices<LineVertex>(std::span { m_segments.data(), m_segments.size() });
100
101 auto layout = get_vertex_layout();
102 layout->vertex_count = static_cast<uint32_t>(m_segments.size());
103 set_vertex_layout(*layout);
104#endif
105
106 m_vertex_data_dirty = false;
107}
108
109//-----------------------------------------------------------------------------
110// Private
111//-----------------------------------------------------------------------------
112
113void LineSegmentsNode::append_pairs(const std::vector<LineVertex>& pairs)
114{
115 m_segments.insert(m_segments.end(), pairs.begin(), pairs.end());
116 m_vertex_data_dirty = true;
117}
118
119} // namespace MayaFlux::Nodes::GpuSync
#define MF_DEBUG(comp, ctx,...)
size_t a
size_t b
bool m_vertex_data_dirty
Flag: vertex data or layout changed since last GPU upload.
std::optional< Kakshya::VertexLayout > get_vertex_layout() const
Get cached vertex layout.
void set_vertex_layout(const Kakshya::VertexLayout &layout)
Set cached vertex layout.
void resize_vertex_buffer(uint32_t vertex_count, bool preserve_data=false)
Resize vertex buffer to hold specified number of vertices.
void clear_segments()
Remove all accumulated segments and reset the vertex buffer.
void add_normal(const std::vector< LineVertex > &path_vertices, float length, size_t stride=1)
Append normal segments derived from a vertex path.
void add_line(const LineVertex &a, const LineVertex &b)
Add a segment between two vertices.
void compute_frame() override
Pack accumulated segments into the GPU vertex buffer.
void append_pairs(const std::vector< LineVertex > &pairs)
void add_axis(const LineVertex &origin, const glm::vec3 &direction, float length)
Add a directed axis segment originating from a point.
void add_curvature(const std::vector< LineVertex > &path_vertices, float scale, size_t stride=1)
Append curvature segments derived from a vertex path.
LineSegmentsNode(size_t initial_capacity=256)
Construct an empty segment accumulator.
void add_tangent(const std::vector< LineVertex > &path_vertices, float length, size_t stride=1)
Append tangent segments derived from a vertex path.
Generates dense vertex paths from sparse control points or freehand drawing.
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
std::vector< Kakshya::LineVertex > compute_path_tangents(const std::vector< Kakshya::LineVertex > &path_vertices, float tangent_length, size_t stride)
Compute tangent vectors along a piecewise-linear path.
std::vector< Kakshya::LineVertex > compute_path_curvature(const std::vector< Kakshya::LineVertex > &path_vertices, float curvature_scale, size_t stride)
Compute curvature vectors along a path (2nd derivative approximation)
std::vector< Kakshya::LineVertex > compute_path_normals(const std::vector< Kakshya::LineVertex > &path_vertices, float normal_length, size_t stride)
Compute normal vectors along a piecewise-linear path.
Vertex type for line primitives (LINE_LIST / LINE_STRIP topology)
static VertexLayout for_lines(uint32_t stride=60)
Factory: layout for LineVertex (position, color, thickness, uv, normal, tangent)