1257{
1258 profile_segs = std::max(profile_segs, 2U);
1259 radial_segs = std::max(radial_segs, 3U);
1260
1261 std::vector<Kakshya::MeshVertex> verts;
1262 std::vector<uint32_t>
indices;
1263 verts.reserve(size_t((profile_segs + 1)) * (radial_segs + 1));
1264 indices.reserve(uint32_t(profile_segs * radial_segs * 6));
1265
1266 for (uint32_t pi = 0; pi <= profile_segs; ++pi) {
1267 const float t = static_cast<float>(pi) / static_cast<float>(profile_segs);
1268 const glm::vec2 p = profile_fn(t);
1269
1270 for (uint32_t ri = 0; ri <= radial_segs; ++ri) {
1271 const float u = static_cast<float>(ri) / static_cast<float>(radial_segs);
1272 const float angle = u * sweep_radians;
1273 const float ca = std::cos(angle);
1274 const float sa = std::sin(angle);
1275
1276 const glm::vec3 pos { p.x * ca, p.y, p.x * sa };
1277
1278 constexpr float eps = 1e-4F;
1279 const glm::vec2 dp = profile_fn(glm::clamp(t + eps, 0.0F, 1.0F))
1280 - profile_fn(glm::clamp(t - eps, 0.0F, 1.0F));
1281 const glm::vec3 profile_tan { dp.x * ca, dp.y, dp.x * sa };
1282 const glm::vec3 radial { ca, 0.0F, sa };
1283 const glm::vec3 nrm = glm::normalize(glm::cross(profile_tan, radial));
1284
1285 verts.push_back({
1286 .position = pos,
1287 .uv = { u, 1.0F - t },
1288 .normal = nrm,
1289 });
1290 }
1291 }
1292
1293 const uint32_t stride = radial_segs + 1;
1294 for (uint32_t pi = 0; pi < profile_segs; ++pi) {
1295 for (uint32_t ri = 0; ri < radial_segs; ++ri) {
1296 const uint32_t
a = pi * stride + ri;
1297 const uint32_t
b =
a + 1;
1298 const uint32_t c =
a + stride;
1299 const uint32_t d = c + 1;
1301 }
1302 }
1303
1304 auto data = Kakshya::MeshData::empty();
1305 Kakshya::MeshInsertion ins(data.vertex_variant, data.index_variant);
1306 ins.insert_flat(
1307 std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(verts.data()),
1308 verts.size() * sizeof(Kakshya::MeshVertex)),
1309 std::span<const uint32_t>(
indices),
1310 Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex)));
1311 data.layout = Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex));
1312 data.layout.vertex_count = static_cast<uint32_t>(verts.size());
1313 return data;
1314}
std::vector< uint32_t > indices