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

Release: Refactor Load Types #2241

Merged
merged 82 commits into from
Jan 21, 2025
Merged

Release: Refactor Load Types #2241

merged 82 commits into from
Jan 21, 2025

Conversation

mikedh
Copy link
Owner

@mikedh mikedh commented Jun 13, 2024

A very common source of annoyance and confusion is that trimesh.load can return lots of different types depending on what type of file was passed (i.e. #2239). This refactor changes the return types for the loading functions to:

  • trimesh.load_scene -> Scene
    • This loads into a Scene, the most general container which can hold any loadable type. Most people should probably use this to load geometry.
  • trimesh.load_mesh -> Trimesh
    • Forces all mesh objects in a scene into a single Trimesh object. This potentially has to drop information and irreversibly concatenate multiple meshes.
    • The implementation of the concatenation logic is now in Scene.to_mesh rather than load.
  • trimesh.load_path -> Path
    • This loads into either a Path2D or Path3D which both inherit from Path
  • trimesh.load -> Geometry
    • This was the original load entry point and is deprecated, but there are no current plans to remove it. It has been modified into a thin wrapper for load_scene that attempts to match the behavior of the previous loader for backwards compatibility. In my testing against the current main branch it was returning the same types 99.8% of the time although there may be other subtle differences.
    • trimesh.load(..., force='mesh') will emit a deprecation warning in favor of load_mesh
    • trimesh.load(..., force='scene') will emit a deprecation warning in favor of load_scene

Additional changes:

This was referenced Sep 3, 2024
mikedh and others added 28 commits January 15, 2025 19:00
Updates the GLTF/GLB reader to include point cloud colors if available.
Hello,

While using `trimesh==4.5.0` to compute the minimum volume oriented
bounding box of a mesh, I noticed the following bug. Running the below
code seems to take an extremely long time:
```
torus_mesh = g.trimesh.creation.torus(major_radius=5, minor_radius=1, major_sections=512, minor_sections=256)
trimesh.bounds.oriented_bounds(torus_mesh.vertices)
```

But running this similar piece of code completed in ~7 seconds:
```
torus_mesh = g.trimesh.creation.torus(major_radius=5, minor_radius=1, major_sections=512, minor_sections=256)
trimesh.bounds.oriented_bounds(trimesh.Trimesh(vertices=torus_mesh.vertices))
```

My best guess is that, in the first case, the computed convex hull's
face adjacencies seem to be wrong although I'm not sure how exactly.
Line 253 in `bounds.py` computes 139156 edges that need to be checked,
which doesn't seem right. In the second case, only 516 edges are
checked.

I noticed that, in the first case, the convex hull is being computed by
`trimesh.convex.convex_hull(..., repair=False)` and, in the second case,
the convex hull is effectively being computed with
`trimesh.convex.convex_hull(..., repair=True)`. This PR makes both cases
use `repair = True`. Hopefully the solution is indeed that simple.

Thanks for the great library!
While all the other key/values for the MTL material are provided
directly on top of Trimesh's interpretation for SimpleMaterial, then
accessible through material.kwargs which is useful for custom handling
of the materials, map_Kd isn't. I've had a need for getting the map_Kd
file path directly instead of the already loaded PIL.Image.
@mikedh mikedh merged commit aed7eee into main Jan 21, 2025
9 checks passed
@mikedh mikedh deleted the refactor/loadtype branch January 21, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants