File size: 660 Bytes
bc4c433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""Shared trimesh flatten. No Open3D — safe for train-side mesh_io."""

from __future__ import annotations

from typing import Any

import trimesh


def as_trimesh(mesh: Any) -> trimesh.Trimesh:
    """Flatten a Trimesh or a Scene of triangle meshes to one Trimesh."""
    if isinstance(mesh, trimesh.Scene):
        geoms = [g for g in mesh.geometry.values() if isinstance(g, trimesh.Trimesh)]
        if not geoms:
            raise ValueError("Scene contains no triangle meshes")
        mesh = trimesh.util.concatenate(geoms)
    if not isinstance(mesh, trimesh.Trimesh):
        raise TypeError(f"Unsupported mesh type: {type(mesh)!r}")
    return mesh