Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing export from python binding #190

Merged
merged 6 commits into from
Sep 5, 2022
Merged

Removing export from python binding #190

merged 6 commits into from
Sep 5, 2022

Conversation

elalish
Copy link
Owner

@elalish elalish commented Sep 1, 2022

Fixes #128

I found a nice little python library for import/export of various mesh formats: meshio. By removing this last dependency, we can separate our library completely from Assimp. However, this isn't yet functional because it seems the to_mesh function isn't working. I get the following Python error when I try python3 run_all.py -e:

TypeError: Unregistered type : glm::vec<3, int, (glm::qualifier)0>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "run_all.py", line 38, in <module>
    cells = [("triangle", mesh.tri_verts)]
TypeError: Unable to convert function return value to a Python type! The signature was
	(self: pymanifold.Mesh) -> List[glm::vec<3, int, (glm::qualifier)0>]

I think we need to convert our std::vector<glm::vec3> into a two-dimensional python list, but I'm not sure how to do that. Any thoughts @pca006132?

UPDATE: working now.

@elalish elalish self-assigned this Sep 1, 2022
@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2022

Codecov Report

Merging #190 (656c0b7) into master (405dd63) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #190   +/-   ##
=======================================
  Coverage   98.66%   98.66%           
=======================================
  Files          32       32           
  Lines        2913     2913           
=======================================
  Hits         2874     2874           
  Misses         39       39           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@pca006132
Copy link
Collaborator

pca006132 commented Sep 4, 2022

We can use numpy array. https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html

More specifically, it should be something similar to

.def(py::init([](py::array_t<float> &vertPos, py::array_t<int> &triVerts,
py::array_t<float> &vertNormal,
py::array_t<float> &halfedgeTangent) {
auto vertPos_view = vertPos.unchecked<2>();
auto triVerts_view = triVerts.unchecked<2>();
auto vertNormal_view = vertNormal.unchecked<2>();
auto halfedgeTangent_view = halfedgeTangent.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");
if (vertNormal_view.shape(0) != 0) {
if (vertNormal_view.shape(1) != 3)
throw std::runtime_error("Invalid vert_normal shape");
if (vertNormal_view.shape(0) != vertPos_view.shape(0))
throw std::runtime_error(
"vert_normal must have the same length as vert_pos");
}
if (halfedgeTangent_view.shape(0) != 0) {
if (halfedgeTangent_view.shape(1) != 4)
throw std::runtime_error("Invalid halfedge_tangent shape");
if (halfedgeTangent_view.shape(0) != triVerts_view.shape(0) * 3)
throw std::runtime_error(
"halfedge_tangent must be three times as long as "
"tri_verts");
}
std::vector<glm::vec3> vertPos_vec(vertPos_view.shape(0));
std::vector<glm::ivec3> triVerts_vec(triVerts_view.shape(0));
std::vector<glm::vec3> vertNormal_vec(vertNormal_view.shape(0));
std::vector<glm::vec4> halfedgeTangent_vec(
halfedgeTangent_view.shape(0));

but we should flatten the buffer instead.

@elalish
Copy link
Owner Author

elalish commented Sep 5, 2022

@pca006132 Thanks, I think I've got all the python stuff working now, following your suggestion. I tried to install the python meshio package for nix (they seem to have it), but I think I'm just not familiar enough with the syntax. Would you mind giving it a look?

@pca006132
Copy link
Collaborator

Try this:

python39.withPackages(ps: with ps; [meshio])

it seems that they don't have it for 3.8.

@elalish
Copy link
Owner Author

elalish commented Sep 5, 2022

Perfect, thanks!

@elalish elalish merged commit 73a53e0 into master Sep 5, 2022
@elalish elalish deleted the pythonExport branch September 5, 2022 16:29
@elalish
Copy link
Owner Author

elalish commented Sep 6, 2022

@rsaccon This improved our python bindings considerably, which should make it a lot easier to integrate with Blender. Are you still interested in giving that a go? Would love to see that connection made.

cartesian-theatrics pushed a commit to SovereignShop/manifold that referenced this pull request Mar 11, 2024
* try python meshio

* removed meshIO dependency

* fixed to_mesh

* fix nix

* more nix fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate meshIO from manifold bundles
3 participants