From 155d8e44aecc2440296f7cfdc64fe2c6b3fb07f9 Mon Sep 17 00:00:00 2001 From: Axel Angel Date: Sun, 18 Jun 2023 22:45:51 +0200 Subject: [PATCH] python bindings: New variant of Mesh constructor with 2 arguments --- bindings/python/pymanifold.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bindings/python/pymanifold.cpp b/bindings/python/pymanifold.cpp index 603447c48..8f13c8934 100644 --- a/bindings/python/pymanifold.cpp +++ b/bindings/python/pymanifold.cpp @@ -505,6 +505,24 @@ PYBIND11_MODULE(pymanifold, m) { }), py::arg("vert_pos"), py::arg("tri_verts"), py::arg("vert_normal"), py::arg("halfedge_tangent")) + .def(py::init([](py::array_t &vertPos, py::array_t &triVerts) { + auto vertPos_view = vertPos.unchecked<2>(); + auto triVerts_view = triVerts.unchecked<2>(); + if (vertPos_view.shape(1) != 3) + throw std::runtime_error("Invalid vert_pos shape"); + if (triVerts_view.shape(1) != 3) + throw std::runtime_error("Invalid tri_verts shape"); + std::vector vertPos_vec(vertPos_view.shape(0)); + std::vector triVerts_vec(triVerts_view.shape(0)); + for (int i = 0; i < vertPos_view.shape(0); i++) + for (const int j : {0, 1, 2}) + vertPos_vec[i][j] = vertPos_view(i, j); + for (int i = 0; i < triVerts_view.shape(0); i++) + for (const int j : {0, 1, 2}) + triVerts_vec[i][j] = triVerts_view(i, j); + return Mesh({vertPos_vec, triVerts_vec}); + }), + py::arg("vert_pos"), py::arg("tri_verts")) .def_property_readonly("vert_pos", [](Mesh &self) { const int numVert = self.vertPos.size();