MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ insert_submesh()

void MayaFlux::Kakshya::MeshInsertion::insert_submesh ( std::span< const uint8_t >  vertex_bytes,
std::span< const uint32_t >  index_data,
std::string_view  name = {},
std::string_view  material_name = {},
const VertexLayout layout = VertexLayout::for_meshes(60) 
)

Append one submesh batch, accumulating into the shared buffers.

Vertex bytes are appended to the existing vector<uint8_t>; indices are offset by the current vertex count and appended to vector<uint32_t>. A Region is added to the internal submesh RegionGroup recording the index sub-range and names.

layout is taken from the first call; subsequent calls must have the same stride_bytes and attribute count. Mismatches log an error and skip the batch.

Parameters
vertex_bytesRaw interleaved vertex data for this submesh.
index_dataTriangle indices local to this submesh (0-based).
nameSubmesh name (may be empty).
material_nameMaterial name (may be empty).
layoutVertex layout; ignored after first call.

Definition at line 101 of file MeshInsertion.cpp.

107{
108 if (layout.stride_bytes == 0) {
110 "MeshInsertion::insert_submesh: layout stride_bytes is zero");
111 return;
112 }
113 if (vertex_bytes.size() % layout.stride_bytes != 0) {
115 "MeshInsertion::insert_submesh: vertex_bytes {} not a multiple of stride {}",
116 vertex_bytes.size(), layout.stride_bytes);
117 return;
118 }
119 if (index_data.size() % 3 != 0) {
121 "MeshInsertion::insert_submesh: index count {} is not a multiple of 3",
122 index_data.size());
123 return;
124 }
125
126 if (!m_layout_set) {
127 m_layout = layout;
128 m_layout_set = true;
129 } else if (!validate_layout(layout)) {
130 return;
131 }
132
135
136 auto& vbuf = std::get<std::vector<uint8_t>>(m_vertex_variant);
137 auto& ibuf = std::get<std::vector<uint32_t>>(m_index_variant);
138
139 const auto submesh_vcount = static_cast<uint32_t>(vertex_bytes.size() / layout.stride_bytes);
140 const uint32_t index_start = m_index_count;
141
142 vbuf.insert(vbuf.end(), vertex_bytes.begin(), vertex_bytes.end());
143
144 ibuf.reserve(ibuf.size() + index_data.size());
145 for (const uint32_t idx : index_data) {
146 ibuf.push_back(idx + m_vertex_count);
147 }
148
149 MeshSubrange sub;
150 sub.index_start = index_start;
151 sub.index_count = static_cast<uint32_t>(index_data.size());
152 sub.vertex_offset = m_vertex_count;
153 sub.name = std::string(name);
154 sub.material_name = std::string(material_name);
155
156 if (!m_submeshes.has_value()) {
157 m_submeshes = RegionGroup("submeshes");
158 }
159 m_submeshes->add_region(sub.to_region());
160
161 m_vertex_count += submesh_vcount;
162 m_index_count += static_cast<uint32_t>(index_data.size());
164
166 "MeshInsertion::insert_submesh: '{}' +{} vertices, +{} indices, "
167 "running totals: {} vertices / {} indices",
168 name.empty() ? "<unnamed>" : name,
169 submesh_vcount, index_data.size(),
171}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Range size
std::optional< RegionGroup > m_submeshes
uint32_t m_vertex_count
Running total across all submitted batches.
bool validate_layout(const VertexLayout &incoming) const
@ Runtime
General runtime operations (default fallback)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
uint32_t vertex_count
Total number of vertices in this buffer.

References ensure_index_storage(), ensure_vertex_storage(), MayaFlux::Kakshya::MeshSubrange::index_count, MayaFlux::Kakshya::MeshSubrange::index_start, MayaFlux::Journal::Kakshya, m_index_count, m_index_variant, m_layout, m_layout_set, m_submeshes, m_vertex_count, m_vertex_variant, MayaFlux::Kakshya::MeshSubrange::material_name, MF_DEBUG, MF_ERROR, MayaFlux::Kakshya::MeshSubrange::name, MayaFlux::Journal::Runtime, MayaFlux::Kakshya::VertexLayout::stride_bytes, MayaFlux::Kakshya::MeshSubrange::to_region(), validate_layout(), MayaFlux::Kakshya::VertexLayout::vertex_count, and MayaFlux::Kakshya::MeshSubrange::vertex_offset.

+ Here is the call graph for this function: