trimesh icon indicating copy to clipboard operation
trimesh copied to clipboard

Extract 2D outlines out of 3D head meshes

Open sjain1101 opened this issue 2 years ago • 1 comments

Hi Michael,

I have a 3D head mode. I would like to extract 2D outline out of this 3D head mesh using trimesh. My first thoughts were to project the 3D mesh onto a 2D plane and later find minimum and maximum points along x/y/z axis to extract the boundaries/outlines of mesh.

My end goal is to extract head and ear dimensions, like head height, head width, ear length, ear breadth and so on. Do you think you can help me out here?

Thanks in advance.

sjain1101 avatar Aug 29 '23 08:08 sjain1101

Hey, I think you might want mesh.projected:

In [2]: import trimesh

In [3]: m = trimesh.load('models/rabbit.obj')

In [4]: m.projected?
Signature: m.projected(normal, **kwargs)
Docstring:
Project a mesh onto a plane and then extract the
polygon that outlines the mesh projection on that
plane.

Parameters
----------
mesh : trimesh.Trimesh
  Source geometry
check : bool
  If True make sure is flat
normal : (3,) float
  Normal to extract flat pattern along
origin : None or (3,) float
  Origin of plane to project mesh onto
pad : float
  Proportion to pad polygons by before unioning
  and then de-padding result by to avoid zero-width gaps.
tol_dot : float
  Tolerance for discarding on-edge triangles.
max_regions : int
  Raise an exception if the mesh has more than this
  number of disconnected regions to fail quickly before unioning.

Returns
----------
projected : trimesh.path.Path2D
  Outline of source mesh
File:      /media/psf/Dropbox/robotics/trimesh/trimesh/base.py
Type:      method

In [6]: outline = m.projected(normal=[0,1,0], origin=m.centroid)

In [7]: outline
Out[7]: <trimesh.Path2D(vertices.shape=(65, 2), len(entities)=1)>

In [8]: outline.show()
Screenshot 2023-08-29 at 2 08 03 PM

mesh.projected performs pretty well on simple meshes without a ton of curvature, but on very complicated stuff with lots of regions it might need some tuning. PR's very welcome!! Fixing #1862 might be a good test case.

mikedh avatar Aug 29 '23 18:08 mikedh