Clean up a mesh using trimesh.
(mesh)
| 47 | |
| 48 | |
| 49 | def clean_mesh(mesh): |
| 50 | """Clean up a mesh using trimesh.""" |
| 51 | print(f" Original: {len(mesh.vertices)} vertices, {len(mesh.faces)} faces") |
| 52 | |
| 53 | mesh.merge_vertices(merge_tex=False, merge_norm=False) |
| 54 | mesh.remove_unreferenced_vertices() |
| 55 | try: |
| 56 | import networkx # noqa: F401 - trimesh's fix_normals requires it |
| 57 | except ImportError: |
| 58 | # A GLB exported without fixed normals imports into Unreal with |
| 59 | # degenerate normals/tangents on every mesh. Failing here makes |
| 60 | # convert_mesh() skip the GLB entirely, so the importer falls back |
| 61 | # to the source mesh and Unreal computes clean normals itself. |
| 62 | raise RuntimeError( |
| 63 | "networkx is not installed (required by trimesh.fix_normals); " |
| 64 | "skipping GLB conversion so the source mesh is imported instead. " |
| 65 | "Install it via the plugin's Python-dependency prompt or " |
| 66 | "'python -m pip install networkx'." |
| 67 | ) |
| 68 | mesh.fix_normals() |
| 69 |