Cut mesh into connected components based on ``comp_ids``. If ``comp_ids`` is ``None``, cut mesh based on UV discontinuity. Args: mesh (:class:`Mesh`): Input mesh. If ``comp_ids`` is ``None``, it must have uv coordinates stored as per-corner attribute named
(mesh, comp_ids=None)
| 4 | import numpy as np |
| 5 | |
| 6 | def cut_mesh(mesh, comp_ids=None): |
| 7 | """ Cut mesh into connected components based on ``comp_ids``. If |
| 8 | ``comp_ids`` is ``None``, cut mesh based on UV discontinuity. |
| 9 | |
| 10 | Args: |
| 11 | mesh (:class:`Mesh`): Input mesh. If ``comp_ids`` is ``None``, it must |
| 12 | have uv coordinates stored as per-corner attribute named |
| 13 | ``corner_texture``. |
| 14 | comp_ids (``numpy.ndarray``): Per-face label of how to group faces into |
| 15 | connected components. |
| 16 | |
| 17 | Returns: |
| 18 | The cutted output mesh object. |
| 19 | """ |
| 20 | |
| 21 | cutter = MeshCutter(mesh.raw_mesh) |
| 22 | if comp_ids is not None: |
| 23 | comp_ids = np.array(comp_ids) |
| 24 | cutted_mesh = Mesh(cutter.cut_with_face_labels(comp_ids)) |
| 25 | cutted_mesh.add_attribute("comp_ids") |
| 26 | cutted_mesh.set_attribute("comp_ids", comp_ids) |
| 27 | else: |
| 28 | cutted_mesh = Mesh(cutter.cut_at_uv_discontinuity()) |
| 29 | cutted_mesh.add_attribute("corner_texture") |
| 30 | cutted_mesh.set_attribute("corner_texture", |
| 31 | mesh.get_attribute("corner_texture")) |
| 32 | return cutted_mesh |
| 33 |