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

Update python mesh #492

Merged
merged 8 commits into from
Jul 24, 2023
Merged

Update python mesh #492

merged 8 commits into from
Jul 24, 2023

Conversation

elalish
Copy link
Owner

@elalish elalish commented Jul 15, 2023

Fixes #361 - at least I think so; please remind me if I've forgotten anything.

The main thing I'm adding here is MeshGL support, which is to say updating the Python Mesh class to work as MeshGL instead, akin to our JS binding. This PR is still WIP, as I need to update our trimesh integration, but we should now be able to export vertex colors and such right through to glTF with that soon.

@elalish elalish requested a review from pca006132 July 15, 2023 06:05
@elalish elalish self-assigned this Jul 15, 2023
@pca006132
Copy link
Collaborator

Will have a look at this. I think we should also add at least one python example using MeshGL.

@pca006132
Copy link
Collaborator

  1. The original Mesh type is now deleted, but it is still used for things like to_mesh which are used in older python code by us. I think we should keep it.
  2. For immutable access to fields of MeshGL, I think there are ways to make it into some python object without copying the entire array.

@geoffder geoffder closed this Jul 15, 2023
@geoffder geoffder reopened this Jul 15, 2023
@geoffder
Copy link
Collaborator

geoffder commented Jul 15, 2023

Sorry I was writing a comment then decided it was wrong and tried to delete, and somehow fat fingered close PR (on phone). My bad!

@elalish
Copy link
Owner Author

elalish commented Jul 15, 2023

I'm going to update our examples to this, because I'd prefer to only use MeshGL in the bindings. I may even deprecate Mesh in the C++, as I don't love supporting both. If you know a more efficient way to access the vectors, that would be great. I'm no python expert. I just want the API to be the right shape so I can feel good publishing it.

@pca006132
Copy link
Collaborator

It seems that we don't really need to copy vectors of primitive types into a python array, pybind11 does that automatically for us already.

I also updated the python example to use the MeshGL API, and converted to_mesh into to_meshgl

@pca006132
Copy link
Collaborator

For the other python changes, e.g. hull, should I open another PR or should I add them here? should be relatively small change.

@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (a8626f9) 90.34% compared to head (311d25a) 90.34%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #492   +/-   ##
=======================================
  Coverage   90.34%   90.34%           
=======================================
  Files          35       35           
  Lines        4414     4414           
=======================================
  Hits         3988     3988           
  Misses        426      426           

see 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@geoffder
Copy link
Collaborator

I've got a bindings PR in the works that I included python in. Just haven't finished the JS bits yet.

@pca006132
Copy link
Collaborator

@axel-angel this should be our final breaking change. You can see the updated run_all.py for how to use the updated MeshGL that replaces Mesh.

@pca006132
Copy link
Collaborator

@elalish maybe we can merge this? As I modified this, it doesn't make sense for me to review it again, and I cannot choose you to be the reviewer.

@elalish
Copy link
Owner Author

elalish commented Jul 19, 2023

Thank you so much, @pca006132! I had intended to get back to this earlier, but I got laid up with a sinus infection instead. Thanks for figuring this out. I'll review soon.

@pca006132
Copy link
Collaborator

Btw I am thinking if we should return a flattened array, i.e. the same as our C++ interface, or a reshaped array, as numpy can do reshaping without actually copying the memory.

meshOut = trimesh.Trimesh(
vertices=mesh.vert_pos, faces=mesh.tri_verts)
vertices=vertices, faces=np.reshape(mesh.tri_verts, (-1, 3)))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to update this for properties, which will involve splitting this up and putting the rest into Trimesh.visual. That can happen as a follow-on though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to finish everything in this PR, to test the new APIs are working correctly. (in case we understood python incorrectly...)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough. Do you want to take a stab at it? Otherwise I can work on it tomorrow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you can work on it

@pca006132
Copy link
Collaborator

Note that some parameters are not constant because reshape is not a constant function.
Alternatively we can also make every parameter of the MeshGL constructor not constant.

self.halfedgeTangent.data())
.reshape(std::array<int, 3>{-1, 3, 4});
})
.def_readonly("merge_from_vert", &MeshGL::mergeFromVert)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these automatically take the pointer, or are they copying the std::vector instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that I forgot to add opaque types. https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#making-opaque-types

Now, it should auotmatically take the pointer.

Copy link
Owner Author

@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - want to go ahead and merge it?

@pca006132 pca006132 merged commit 93e06a2 into master Jul 24, 2023
@elalish elalish mentioned this pull request Nov 3, 2023
cartesian-theatrics pushed a commit to SovereignShop/manifold that referenced this pull request Mar 11, 2024
* updated python mesh

* updated python meshgl

* clean up array related stuff

* fix hsplit

* fix according to comments

* make to_mesh accept MeshGL

* fixes

---------

Co-authored-by: pca006132 <[email protected]>
@pca006132 pca006132 deleted the pythonMeshGL branch November 18, 2024 10:01
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.

Add python bindings for the rest of our APIs
3 participants