mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3.02k stars 583 forks source link

add support for path3d export to ply format #2282

Closed moberweger closed 2 months ago

moberweger commented 2 months ago

This PR adds support to export Path3D object into the PLY format. This can be used to visualize the Path3D objects in common 3D mesh viewers, such as MeshLab. These are shown as line stripes, as shown below. This PR contains:

Screenshot from 2024-09-06 16-01-43

mikedh commented 2 months ago

Awesome thanks for the PR!! It seems like we could probably merge this in with trimesh.exchange.ply and have the load function return either a Trimesh or Path3D? Do we need the separate trimesh.path.exchange.ply module? I guess since PLY is a container format the choice is between confusing return types or confusing function calls :smile:.

My only other note is we could probably support any entity type pretty easily by using the entity.discrete(path.vertices) -> (n, 2) float64 which for a Line will do the same thing as the current code:

if isinstance(e, Line):
    for pp in range(len(e.points) - 1):
        entities.append((e.points[pp], e.points[pp + 1]))
else:
    raise NotImplementedError(f"type {type(e)} not supported as entities")
moberweger commented 2 months ago

Thanks @mikedh for your feedback. I was also thinking about the integration in the common trimesh.exchange.ply , but ended up with having a unique return value being the cleaner way of doing things :sweat_smile: But let me know if you think otherwise. Thanks for the remark about the entity, I will update the PR :+1:

mikedh commented 2 months ago

Thanks for the PR and fixes!

mikedh commented 1 month ago

Sorry for the slow release, I'll try to get this out next week. I was testing this and I was wondering are there any existing packages that output or load PLY paths in this format? 3JS maybe?

moberweger commented 1 month ago

Thanks for looking into this so thoroughly. The almighty Open3D library can save the ply format, it is called LineSet over there. I used it before porting this stuff to trimesh, but Open3D was too heavy for my usecase.