989{
990 u_segs = std::max(u_segs, 1U);
991 v_segs = std::max(v_segs, 1U);
992
993 std::vector<Kakshya::MeshVertex> verts;
995 verts.reserve(uint32_t((u_segs + 1) * (v_segs + 1)));
996 indices.reserve(uint32_t(u_segs * v_segs * 6));
997
998 constexpr float eps = 1e-4F;
999
1000 for (uint32_t row = 0; row <= v_segs; ++row) {
1001 const float fv = static_cast<float>(row) / static_cast<float>(v_segs);
1002 for (uint32_t col = 0; col <= u_segs; ++col) {
1003 const float fu = static_cast<float>(col) / static_cast<float>(u_segs);
1004
1005 const glm::vec3 p = fn(fu, fv);
1006 const glm::vec3 pu = fn(fu + eps, fv) - fn(fu - eps, fv);
1007 const glm::vec3 pv = fn(fu, fv + eps) - fn(fu, fv - eps);
1008 const glm::vec3 n = glm::normalize(glm::cross(pu, pv));
1009
1010 verts.push_back({
1011 .position = p,
1012 .uv = { fu, 1.0F - fv },
1013 .normal = n,
1014 });
1015 }
1016 }
1017
1018 const uint32_t stride = u_segs + 1;
1019 for (uint32_t row = 0; row < v_segs; ++row) {
1020 for (uint32_t col = 0; col < u_segs; ++col) {
1021 const uint32_t
a = row * stride + col;
1022 const uint32_t
b =
a + 1;
1023 const uint32_t c =
a + stride;
1024 const uint32_t d = c + 1;
1026 }
1027 }
1028
1029 auto data = Kakshya::MeshData::empty();
1030 Kakshya::MeshInsertion ins(data.vertex_variant, data.index_variant);
1031 ins.insert_flat(
1032 std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(verts.data()),
1033 verts.size() * sizeof(Kakshya::MeshVertex)),
1034 std::span<const uint32_t>(
indices),
1035 Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex)));
1036 data.layout = Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex));
1037 data.layout.vertex_count = static_cast<uint32_t>(verts.size());
1038
1039 return data;
1040}
std::vector< uint32_t > indices