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

◆ as_mesh_access()

MAYAFLUX_API std::optional< MeshAccess > MayaFlux::Kakshya::as_mesh_access ( const DataVariant vertex_variant,
const DataVariant index_variant,
const VertexLayout layout,
std::optional< RegionGroup submeshes = std::nullopt 
)

Construct a MeshAccess from two DataVariant instances.

vertex_variant must hold vector<uint8_t> (canonical interleaved bytes). index_variant must hold vector<uint32_t>. layout must have stride_bytes > 0 and at least one attribute. submeshes is forwarded as-is; pass std::nullopt for single-mesh data.

Returns std::nullopt and logs an error for any type mismatch.

The RegionGroup convention: a single RegionGroup named "submeshes" holds one Region per submesh. Each Region carries coordinates [index_start, index_start + index_count) in the index dimension, with attributes "name", "material_name", and "vertex_offset". This mirrors the audio/video pattern where e.g. "transients" is the group and each onset event is a Region inside it.

Definition at line 29 of file MeshAccess.cpp.

34{
35 const auto* vbytes = std::get_if<std::vector<uint8_t>>(&vertex_variant);
36 if (!vbytes || vbytes->empty()) {
37 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
38 "as_mesh_access: vertex_variant must hold a non-empty vector<uint8_t>");
39 return std::nullopt;
40 }
41
42 const auto* ibuf = std::get_if<std::vector<uint32_t>>(&index_variant);
43 if (!ibuf || ibuf->empty()) {
44 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
45 "as_mesh_access: index_variant must hold a non-empty vector<uint32_t>");
46 return std::nullopt;
47 }
48
49 if (layout.stride_bytes == 0) {
50 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
51 "as_mesh_access: layout stride_bytes is zero");
52 return std::nullopt;
53 }
54
55 if (layout.attributes.empty()) {
56 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
57 "as_mesh_access: layout has no attributes");
58 return std::nullopt;
59 }
60
61 if (vbytes->size() % layout.stride_bytes != 0) {
62 MF_ERROR(Journal::Component::Kakshya, Journal::Context::Runtime,
63 "as_mesh_access: vertex byte count {} is not a multiple of stride {}",
64 vbytes->size(), layout.stride_bytes);
65 return std::nullopt;
66 }
67
68 MeshAccess ma;
69 ma.vertex_ptr = vbytes->data();
70 ma.vertex_bytes = vbytes->size();
71 ma.index_ptr = ibuf->data();
72 ma.index_count = static_cast<uint32_t>(ibuf->size());
73 ma.layout = layout;
74 ma.layout.vertex_count = static_cast<uint32_t>(vbytes->size() / layout.stride_bytes);
75 ma.submeshes = std::move(submeshes);
76 return ma;
77}
#define MF_ERROR(comp, ctx,...)
uint32_t stride_bytes
Total bytes per vertex (stride in Vulkan terms) e.g., 3 floats (position) + 3 floats (normal) = 24 by...
uint32_t vertex_count
Total number of vertices in this buffer.
std::vector< VertexAttributeLayout > attributes
All attributes that make up one vertex Ordered by shader location (0, 1, 2, ...)

References MayaFlux::Kakshya::VertexLayout::attributes, MayaFlux::Kakshya::MeshAccess::index_count, MayaFlux::Kakshya::MeshAccess::index_ptr, MayaFlux::Journal::Kakshya, MayaFlux::Kakshya::MeshAccess::layout, MF_ERROR, MayaFlux::Journal::Runtime, MayaFlux::Kakshya::VertexLayout::stride_bytes, MayaFlux::Kakshya::MeshAccess::submeshes, MayaFlux::Kakshya::MeshAccess::vertex_bytes, MayaFlux::Kakshya::VertexLayout::vertex_count, and MayaFlux::Kakshya::MeshAccess::vertex_ptr.

Referenced by MayaFlux::Kakshya::MeshData::access(), and MayaFlux::Kakshya::MeshInsertion::build().

+ Here is the caller graph for this function: