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

◆ generate_box()

MAYAFLUX_API Kakshya::MeshData MayaFlux::Kinesis::generate_box ( const glm::vec3 &  center,
const glm::vec3 &  half_extents,
uint32_t  subdivisions = 1 
)

Generate a solid box as an indexed TRIANGLE_LIST mesh.

Six faces, four vertices each, two triangles per face. Per-face normals point outward along the face axis. UV origin is bottom-left matching Vulkan image layout and the generate_quad convention.

Parameters
centerCentre of the box in world space.
half_extentsHalf-size along each axis. Non-uniform values yield a cuboid.
subdivisionsReserved for future per-face tessellation. Currently ignored.
Returns
MeshData ready for MeshBuffer::set_mesh_data() or MeshWriterNode::set_mesh().

Definition at line 824 of file GeometryPrimitives.cpp.

828{
829 const uint32_t n = std::max(subdivisions, 1U);
830
831 std::vector<Kakshya::MeshVertex> verts;
832 std::vector<uint32_t> indices;
833 verts.reserve(uint32_t(6 * (n + 1) * (n + 1)));
834 indices.reserve(uint32_t(6 * n * n * 6));
835
836 struct FaceDef {
837 glm::vec3 origin;
838 glm::vec3 u_axis;
839 glm::vec3 v_axis;
840 glm::vec3 normal;
841 };
842
843 const std::array<FaceDef, 6> faces = { {
844 { .origin = { -1, -1, 1 }, .u_axis = { 2, 0, 0 }, .v_axis = { 0, 2, 0 }, .normal = { 0, 0, 1 } },
845 { .origin = { 1, -1, -1 }, .u_axis = { -2, 0, 0 }, .v_axis = { 0, 2, 0 }, .normal = { 0, 0, -1 } },
846 { .origin = { 1, -1, 1 }, .u_axis = { 0, 0, -2 }, .v_axis = { 0, 2, 0 }, .normal = { 1, 0, 0 } },
847 { .origin = { -1, -1, -1 }, .u_axis = { 0, 0, 2 }, .v_axis = { 0, 2, 0 }, .normal = { -1, 0, 0 } },
848 { .origin = { -1, 1, 1 }, .u_axis = { 2, 0, 0 }, .v_axis = { 0, 0, -2 }, .normal = { 0, 1, 0 } },
849 { .origin = { -1, -1, -1 }, .u_axis = { 2, 0, 0 }, .v_axis = { 0, 0, 2 }, .normal = { 0, -1, 0 } },
850 } };
851
852 for (const auto& f : faces) {
853 const auto base = static_cast<uint32_t>(verts.size());
854
855 for (uint32_t row = 0; row <= n; ++row) {
856 const float fv = static_cast<float>(row) / static_cast<float>(n);
857 for (uint32_t col = 0; col <= n; ++col) {
858 const float fu = static_cast<float>(col) / static_cast<float>(n);
859 const glm::vec3 p = f.origin + f.u_axis * fu + f.v_axis * fv;
860 verts.push_back({
861 .position = center + p * half_extents,
862 .uv = { fu, 1.0F - fv },
863 .normal = f.normal,
864 });
865 }
866 }
867
868 const uint32_t stride = n + 1;
869 for (uint32_t row = 0; row < n; ++row) {
870 for (uint32_t col = 0; col < n; ++col) {
871 const uint32_t a = base + row * stride + col;
872 const uint32_t b = a + 1;
873 const uint32_t c = a + stride;
874 const uint32_t d = c + 1;
875 indices.insert(indices.end(), { a, b, d, a, d, c });
876 }
877 }
878 }
879
880 auto data = Kakshya::MeshData::empty();
881 Kakshya::MeshInsertion ins(data.vertex_variant, data.index_variant);
882 ins.insert_flat(
883 std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(verts.data()),
884 verts.size() * sizeof(Kakshya::MeshVertex)),
885 std::span<const uint32_t>(indices),
886 Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex)));
887 data.layout = Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex));
888 data.layout.vertex_count = static_cast<uint32_t>(verts.size());
889 return data;
890}
std::vector< uint32_t > indices
size_t a
size_t b

References a, b, generate_box(), indices, and MayaFlux::Kakshya::MeshInsertion::insert_flat().

Referenced by generate_box().

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