MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MeshWriterNode.cpp
Go to the documentation of this file.
1#include "MeshWriterNode.hpp"
2
4
6
7MeshWriterNode::MeshWriterNode(size_t initial_vertex_capacity)
8 : GeometryWriterNode(static_cast<uint32_t>(initial_vertex_capacity))
9{
10 m_vertices.reserve(initial_vertex_capacity);
12
13 auto layout = Kakshya::VertexLayout::for_meshes(sizeof(MeshVertex));
14 layout.vertex_count = 0;
15 set_vertex_layout(layout);
16
18 "Created MeshWriterNode with capacity for {} vertices", initial_vertex_capacity);
19}
20
22 std::span<const MeshVertex> vertices,
23 std::span<const uint32_t> indices)
24{
25 m_vertices.assign(vertices.begin(), vertices.end());
26 m_indices.assign(indices.begin(), indices.end());
29}
30
31void MeshWriterNode::set_mesh_vertices(std::span<const MeshVertex> vertices)
32{
33 m_vertices.assign(vertices.begin(), vertices.end());
36}
37
38void MeshWriterNode::set_mesh_indices(std::span<const uint32_t> indices)
39{
40 m_indices.assign(indices.begin(), indices.end());
42}
43
45{
46 m_vertices.clear();
47 m_indices.clear();
50}
51
56
58{
59 if (m_vertices.empty()) {
60 resize_vertex_buffer(0, false);
61 return;
62 }
63
64 set_vertices<MeshVertex>(std::span { m_vertices.data(), m_vertices.size() });
65 set_indices(std::span { m_indices.data(), m_indices.size() });
66
67 auto layout = Kakshya::VertexLayout::for_meshes(sizeof(MeshVertex));
68 layout.vertex_count = static_cast<uint32_t>(m_vertices.size());
69 set_vertex_layout(layout);
70
72 "MeshWriterNode: uploaded {} vertices, {} indices ({} faces)",
73 m_vertices.size(), m_indices.size(), m_indices.size() / 3);
74}
75
76} // namespace MayaFlux::Nodes::GpuSync
#define MF_TRACE(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
bool m_vertex_data_dirty
Flag: vertex data or layout changed since last GPU upload.
void set_vertex_layout(const Kakshya::VertexLayout &layout)
Set cached vertex layout.
void set_indices(std::span< const uint32_t > indices)
Set index buffer for indexed drawing.
void resize_vertex_buffer(uint32_t vertex_count, bool preserve_data=false)
Resize vertex buffer to hold specified number of vertices.
void set_vertex_stride(size_t stride)
Set vertex stride (bytes per vertex)
bool m_needs_layout_update
Flag indicating if layout needs update.
Base class for nodes that generate 3D geometry data.
MeshWriterNode(size_t initial_vertex_capacity=1024)
void set_mesh(std::span< const MeshVertex > vertices, std::span< const uint32_t > indices)
Replace all vertex and index data atomically.
void set_mesh_vertices(std::span< const MeshVertex > vertices)
Replace vertex array only; index array is unchanged.
Portal::Graphics::PrimitiveTopology get_primitive_topology() const override
Get primitive topology for rendering.
void set_mesh_indices(std::span< const uint32_t > indices)
Replace index array only; vertex array is unchanged.
void compute_frame() override
Compute GPU data for this frame.
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
PrimitiveTopology
Vertex assembly primitive topology.
static VertexLayout for_meshes(uint32_t stride=60)
Factory: layout for MeshVertex (position, color, weight, uv, normal, tangent)
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)