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

◆ generate_revolution() [2/2]

Kakshya::MeshData MayaFlux::Kinesis::generate_revolution ( const std::function< glm::vec2(float)> &  profile_fn,
uint32_t  profile_segs,
uint32_t  radial_segs,
float  sweep_radians 
)

Definition at line 1083 of file GeometryPrimitives.cpp.

1088{
1089 profile_segs = std::max(profile_segs, 2U);
1090 radial_segs = std::max(radial_segs, 3U);
1091
1092 std::vector<Kakshya::MeshVertex> verts;
1093 std::vector<uint32_t> indices;
1094 verts.reserve(size_t((profile_segs + 1)) * (radial_segs + 1));
1095 indices.reserve(uint32_t(profile_segs * radial_segs * 6));
1096
1097 for (uint32_t pi = 0; pi <= profile_segs; ++pi) {
1098 const float t = static_cast<float>(pi) / static_cast<float>(profile_segs);
1099 const glm::vec2 p = profile_fn(t); // p.x = radius from Y axis, p.y = height
1100
1101 for (uint32_t ri = 0; ri <= radial_segs; ++ri) {
1102 const float u = static_cast<float>(ri) / static_cast<float>(radial_segs);
1103 const float angle = u * sweep_radians;
1104 const float ca = std::cos(angle);
1105 const float sa = std::sin(angle);
1106
1107 const glm::vec3 pos { p.x * ca, p.y, p.x * sa };
1108
1109 constexpr float eps = 1e-4F;
1110 const glm::vec2 dp = profile_fn(glm::clamp(t + eps, 0.0F, 1.0F))
1111 - profile_fn(glm::clamp(t - eps, 0.0F, 1.0F));
1112 const glm::vec3 profile_tan { dp.x * ca, dp.y, dp.x * sa };
1113 const glm::vec3 radial { ca, 0.0F, sa };
1114 const glm::vec3 nrm = glm::normalize(glm::cross(profile_tan, radial));
1115
1116 verts.push_back({
1117 .position = pos,
1118 .uv = { u, 1.0F - t },
1119 .normal = nrm,
1120 });
1121 }
1122 }
1123
1124 const uint32_t stride = radial_segs + 1;
1125 for (uint32_t pi = 0; pi < profile_segs; ++pi) {
1126 for (uint32_t ri = 0; ri < radial_segs; ++ri) {
1127 const uint32_t a = pi * stride + ri;
1128 const uint32_t b = a + 1;
1129 const uint32_t c = a + stride;
1130 const uint32_t d = c + 1;
1131 indices.insert(indices.end(), { a, b, c, b, d, c });
1132 }
1133 }
1134
1135 auto data = Kakshya::MeshData::empty();
1136 Kakshya::MeshInsertion ins(data.vertex_variant, data.index_variant);
1137 ins.insert_flat(
1138 std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(verts.data()),
1139 verts.size() * sizeof(Kakshya::MeshVertex)),
1140 std::span<const uint32_t>(indices),
1141 Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex)));
1142 data.layout = Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex));
1143 data.layout.vertex_count = static_cast<uint32_t>(verts.size());
1144 return data;
1145}
size_t a
size_t b

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

Referenced by generate_revolution().

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