MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MeshAccess.cpp
Go to the documentation of this file.
1#include "MeshAccess.hpp"
2
4
5namespace MayaFlux::Kakshya {
6
7// =============================================================================
8// MeshSubrange
9// =============================================================================
10
12{
13 Region r(
14 std::vector { static_cast<uint64_t>(index_start) },
15 std::vector { static_cast<uint64_t>(index_start + index_count) });
16 r.set_attribute("name", name);
17 r.set_attribute("material_name", material_name);
18 r.set_attribute("vertex_offset", static_cast<uint64_t>(vertex_offset));
19 r.set_attribute("index_count", static_cast<uint64_t>(index_count));
20 r.set_attribute("diffuse_path", diffuse_path);
21 r.set_attribute("diffuse_embedded", diffuse_embedded);
22 return r;
23}
24
25// =============================================================================
26// as_mesh_access
27// =============================================================================
28
29std::optional<MeshAccess> as_mesh_access(
30 const DataVariant& vertex_variant,
31 const DataVariant& index_variant,
32 const VertexLayout& layout,
33 std::optional<RegionGroup> submeshes)
34{
35 const auto* vbytes = std::get_if<std::vector<uint8_t>>(&vertex_variant);
36 if (!vbytes || vbytes->empty()) {
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()) {
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) {
51 "as_mesh_access: layout stride_bytes is zero");
52 return std::nullopt;
53 }
54
55 if (layout.attributes.empty()) {
57 "as_mesh_access: layout has no attributes");
58 return std::nullopt;
59 }
60
61 if (vbytes->size() % layout.stride_bytes != 0) {
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}
78
79} // namespace MayaFlux::Kakshya
#define MF_ERROR(comp, ctx,...)
@ Runtime
General runtime operations (default fallback)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
std::optional< MeshAccess > as_mesh_access(const DataVariant &vertex_variant, const DataVariant &index_variant, const VertexLayout &layout, std::optional< RegionGroup > submeshes)
Construct a MeshAccess from two DataVariant instances.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:76
std::optional< RegionGroup > submeshes
Non-owning read view over a pair of DataVariant streams representing interleaved vertex bytes and a f...
Region to_region() const
Convert this subrange to a Region for use in RegionGroup.
uint32_t vertex_offset
Base vertex added to each index (large-mesh batching)
void set_attribute(const std::string &key, std::any value)
Set an attribute value by key.
Definition Region.hpp:339
Represents a point or span in N-dimensional space.
Definition Region.hpp:67
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, ...)
Complete description of vertex data layout in a buffer.