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

◆ generate_parametric_surface() [2/2]

Kakshya::MeshData MayaFlux::Kinesis::generate_parametric_surface ( const std::function< glm::vec3(float, float)> &  fn,
uint32_t  u_segs,
uint32_t  v_segs 
)

Definition at line 910 of file GeometryPrimitives.cpp.

914{
915 u_segs = std::max(u_segs, 1U);
916 v_segs = std::max(v_segs, 1U);
917
918 std::vector<Kakshya::MeshVertex> verts;
919 std::vector<uint32_t> indices;
920 verts.reserve(uint32_t((u_segs + 1) * (v_segs + 1)));
921 indices.reserve(uint32_t(u_segs * v_segs * 6));
922
923 constexpr float eps = 1e-4F;
924
925 for (uint32_t row = 0; row <= v_segs; ++row) {
926 const float fv = static_cast<float>(row) / static_cast<float>(v_segs);
927 for (uint32_t col = 0; col <= u_segs; ++col) {
928 const float fu = static_cast<float>(col) / static_cast<float>(u_segs);
929
930 const glm::vec3 p = fn(fu, fv);
931 const glm::vec3 pu = fn(fu + eps, fv) - fn(fu - eps, fv);
932 const glm::vec3 pv = fn(fu, fv + eps) - fn(fu, fv - eps);
933 const glm::vec3 n = glm::normalize(glm::cross(pu, pv));
934
935 verts.push_back({
936 .position = p,
937 .uv = { fu, 1.0F - fv },
938 .normal = n,
939 });
940 }
941 }
942
943 const uint32_t stride = u_segs + 1;
944 for (uint32_t row = 0; row < v_segs; ++row) {
945 for (uint32_t col = 0; col < u_segs; ++col) {
946 const uint32_t a = row * stride + col;
947 const uint32_t b = a + 1;
948 const uint32_t c = a + stride;
949 const uint32_t d = c + 1;
950 indices.insert(indices.end(), { a, b, c, b, d, c });
951 }
952 }
953
954 auto data = Kakshya::MeshData::empty();
955 Kakshya::MeshInsertion ins(data.vertex_variant, data.index_variant);
956 ins.insert_flat(
957 std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(verts.data()),
958 verts.size() * sizeof(Kakshya::MeshVertex)),
959 std::span<const uint32_t>(indices),
960 Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex)));
961 data.layout = Kakshya::VertexLayout::for_meshes(sizeof(Kakshya::MeshVertex));
962 data.layout.vertex_count = static_cast<uint32_t>(verts.size());
963
964 return data;
965}
size_t a
size_t b

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

Referenced by generate_parametric_surface().

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