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

◆ as_mesh_vertex_access()

MAYAFLUX_API std::optional< VertexAccess > MayaFlux::Kakshya::as_mesh_vertex_access ( std::span< const DataVariant channels,
const VertexAccessConfig config = {} 
)

Assemble mesh-vertex-compatible bytes from one or more data channels.

channels[0] must supply position data (vec3 or uint8_t interleaved). channels[1..5] optionally supply color, weight, uv, normal, tangent in canonical field order. Missing trailing channels are filled from config; slot 2 defaults to config.default_weight. A single uint8_t channel of N*60 bytes is passed through zero-copy.

Parameters
channelsSource channels in canonical field order.
configDefault attribute values for absent channels.
Returns
Populated VertexAccess, or std::nullopt on empty or incompatible input.

Definition at line 176 of file VertexAccess.cpp.

179{
180 if (channels.empty()) {
181 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
182 "as_mesh_vertex_access: no channels supplied");
183 return std::nullopt;
184 }
185
186 if (channels.size() == 1) {
187 if (const auto* b = std::get_if<std::vector<uint8_t>>(&channels[0])) {
188 if (b->size() % 60 != 0) {
189 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
190 "as_mesh_vertex_access: uint8_t byte count {} not a multiple of 60",
191 b->size());
192 return std::nullopt;
193 }
194 const auto count = static_cast<uint32_t>(b->size() / 60);
195 auto layout = VertexLayout::for_meshes();
196 layout.vertex_count = count;
197 return VertexAccess { .data_ptr = b->data(), .byte_count = b->size(), .layout = layout };
198 }
199 }
200
201 const size_t count = channel_view(channels[0]).count;
202 if (count == 0) {
203 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
204 "as_mesh_vertex_access: position channel (slot 0) is empty or unsupported");
205 return std::nullopt;
206 }
207
208 VertexAccess va;
209 va.conversion_buffer.resize(count * 60);
210 assemble_vertices(channels, count, config, config.default_weight,
211 va.conversion_buffer.data());
212 va.data_ptr = va.conversion_buffer.data();
213 va.byte_count = va.conversion_buffer.size();
214 va.layout = VertexLayout::for_meshes();
215 va.layout.vertex_count = static_cast<uint32_t>(count);
216 return va;
217}
#define MF_ERROR(comp, ctx,...)
size_t b
size_t count

References b, MayaFlux::Kakshya::VertexAccess::byte_count, MayaFlux::Kakshya::VertexAccess::conversion_buffer, count, MayaFlux::Kakshya::VertexAccess::data_ptr, MayaFlux::Kakshya::VertexAccessConfig::default_weight, MayaFlux::Kakshya::VertexLayout::for_meshes(), MayaFlux::Journal::Kakshya, MayaFlux::Kakshya::VertexAccess::layout, MF_ERROR, MayaFlux::Journal::Runtime, and MayaFlux::Kakshya::VertexLayout::vertex_count.

Referenced by MayaFlux::Buffers::DataWriteProcessor::upload_vertex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: