-
Notifications
You must be signed in to change notification settings - Fork 8
Mesh improvements #32
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves mesh reading and writing by updating the mesh model, header, and flag handling while adding new tests and example notebooks. Key changes include:
- New tests in tests/test_model_api.py for mesh roundtrip and flag behavior.
- Updates in src/imodmodel/models.py to introduce MeshFlags, interleave vertices and normals, and adjust indices handling.
- Refactors in writers, binary specification, and pyproject.toml along with an added example notebook.
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_model_api.py | Added new tests to verify mesh read/write roundtrips and flag property functionality. |
| src/imodmodel/writers.py | Changed mesh header serialization from .dict() to dict(header) in header writing logic. |
| src/imodmodel/models.py | Introduced MeshFlags, updated MeshHeader defaults and validators, and refined vertices/indices properties. |
| src/imodmodel/binary_specification.py | Updated field name from 'flag' to 'flags' to support the new MeshFlags implementation. |
| pyproject.toml | Added "numpydantic" to support new data structures. |
| docs/examples/smiley.ipynb | Added an example notebook demonstrating mesh export functionality. |
Files not reviewed (1)
- docs/examples/export_mesh.ipynb: File too large
Comments suppressed due to low confidence (1)
src/imodmodel/writers.py:64
- Using dict(header) instead of header.dict() may bypass pydantic's custom processing; please confirm that the intended fields are correctly serialized.
_write_to_specification(file, ModFileSpecification.MESH_HEADER, dict(header))
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Yes, Mr. AI, this is intentional to avoid converting the Flags submodel into a dictionary |
alisterburt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fantastic! Minor suggestion would be to move the obj into examples/data
Thanks for adding the notebooks too - is it easy to render notebooks in mkdocs do you know?
|
what made you remove numpydantic? I assume it avoids having to set up the custom model config when fields are numpy arrays? neat! |
I think so, let me try.
Yeah, I thought it would be neat to specify array shapes that way instead of using validators. There seem to be two packages numpydantic and pydantic-numpy. numpydantic seemed to have the cleaner API, but I haven't really looked into advantages/diadvantages. Removed it for now because it is incompatible with python 3.8 and broke the tests. |
Yes, super simple, just added a plugin. Looks great, too, the trimesh web-thing renders properly. |
if you want to add it back in and deprecate 3.8 that's fine by me! I follow NEP29 for python versions amazing re: docs, look forward to seeing these online |
This improves the reading/writing of meshes. One issue that I stumbled upon is that in the mod format the vertices actually contain vertices+normals (most of the time anyway). I modified the vertices and indices properties to remove the normals, which are now available through the normal property.
I also added support for writing of meshes. It's still a bit clunky, but functional
I also started to create some example notebooks under
docs/examplesRead meshes
Write meshes
Minor refactors
Dependency Updates:
numpydanticto the dependencies inpyproject.tomlto support new data structures.Model Enhancements:
MeshHeaderclass to use the newMeshFlagsclass and added afield_validatorfor theflagsattribute.Meshclass to initialize with default values, added amodel_validatorto update sizes, and added new properties and setters forvertices,normals, andindices. [1] [2]Code Refactoring:
flagattribute withflagsin theModFileSpecificationclass.Contourclass to useNDArrayfromnumpydanticfor thepointsattribute.Testing Enhancements:
test_read_write_read_roundtrip_meshto verify the roundtrip read and write of mesh data.test_mesh_flagsto check the mesh flags property.