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

Fix/forward kwargs #2346

Merged
merged 2 commits into from
Jan 29, 2025
Merged

Conversation

michaelbratsch
Copy link
Contributor

With the pull-request #2241, load_mesh does not respect the parameter process anymore.

With this pull-request, the kwargs are being forwarded in load_stl.

@michaelbratsch
Copy link
Contributor Author

The fix of this pull-request seems to cause a regression in the existing unit tests:

assert len(m.metadata["header"]) > 0

@mikedh What is the supposed way in the current design to forward the kwargs?

@mikedh mikedh changed the base branch from main to followup/dep January 29, 2025 18:30
@mikedh mikedh merged commit 098d744 into mikedh:followup/dep Jan 29, 2025
2 of 9 checks passed
@mikedh
Copy link
Owner

mikedh commented Jan 29, 2025

Thanks for the fix and great test! I think we have to do this in load_scene to replicate the old behavior, this needs some work but passes your test: 907d7dd

@michaelbratsch
Copy link
Contributor Author

Thank you for your quick reply and immediately taking care of it ❤️

I am also wondering about a related issue which is not being fixed with the current pull-request. I put the questions along with this example that way it is probably easiest to see. If wanted, I can open a proper issue for it.

import trimesh

file_name = "models/featuretype.stl"

with open(file_name, "rb") as fh:
    mesh = trimesh.load_mesh(file_obj=fh, file_type="stl", process=False)

    assert len(mesh.faces) == 3476
    assert len(mesh.vertices) == 10428

with open(file_name, "rb") as fh:
    mesh = trimesh.load_mesh(file_obj=fh, file_type="stl", process=True)
    
    # Why is only the number of vertices being reduced but not the number of faces?
    assert len(mesh.faces) == 3476
    assert len(mesh.vertices) == 1722
    
    mesh.export('./mesh_test.stl')

with open('./mesh_test.stl', 'rb') as fh:
    mesh = trimesh.load_mesh(file_obj=fh, file_type="stl", process=False)
    
    assert len(mesh.faces) == 3476
    # Why is the number of vertices again 10428 even though it is from the exported reduced model?
    assert len(mesh.vertices) == 10428

@mikedh
Copy link
Owner

mikedh commented Jan 29, 2025

No worries! I'm going to check whether we have the same bug in the other load entrypoints before merging.

Why is the number of vertices again 10428 even though it is from the exported reduced model?

That's actually because STL just outputs a "bundle of triangles" with no indexes (hence the need for the vertex merging on load, since trimesh started as just an STL loader haha). If you use a format with indexes (OFF, OBJ*, GLB, PLY, etc) it should pass as you expect:

    mesh.export('./mesh_test.off')

    with open('./mesh_test.off', 'rb') as fh:
        mesh = trimesh.load_mesh(file_obj=fh, file_type="off", process=False)
        assert len(mesh.faces) == 3476                                                       
        assert len(mesh.vertices) == 1722

@michaelbratsch
Copy link
Contributor Author

All right, got it. Thanks for the explanation.

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.

2 participants