Skip to content

Commit

Permalink
python bindings: New variant of Mesh constructor with 2 arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-angel committed Jun 18, 2023
1 parent f6dd8ad commit 155d8e4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bindings/python/pymanifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> &vertPos, py::array_t<int> &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<glm::vec3> vertPos_vec(vertPos_view.shape(0));
std::vector<glm::ivec3> 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();
Expand Down

0 comments on commit 155d8e4

Please sign in to comment.