|
4 | 4 | from typing import Iterable, List |
5 | 5 |
|
6 | 6 | import numpy as np |
7 | | -import openctm |
8 | 7 | import trimesh |
9 | 8 |
|
10 | 9 | from .core import Skeleton, Soma, _bfs_parents |
11 | 10 |
|
12 | 11 | __all__ = [ |
13 | 12 | "load_mesh", |
14 | | - "to_ctm", |
15 | 13 | "load_swc", |
16 | 14 | "to_swc", |
17 | 15 | "load_npz", |
|
21 | 19 | _META_KV = re.compile(r"#\s*([^:]+)\s*:\s*(.+)") # key: value |
22 | 20 | _META_JSON = re.compile(r"#\s*meta\s+(\{.*\})") # single-line JSON |
23 | 21 |
|
24 | | - |
| 22 | + |
25 | 23 | # ------------ |
26 | 24 | # --- Mesh --- |
27 | 25 | # ------------ |
28 | 26 |
|
29 | 27 | def load_mesh(filepath: str | Path) -> trimesh.Trimesh: |
30 | 28 |
|
31 | 29 | filepath = Path(filepath) |
32 | | - |
33 | | - if filepath.suffix == ".ctm": |
34 | | - try: |
35 | | - mesh = openctm.import_mesh(filepath) |
36 | | - mesh = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, process=False) |
37 | | - except AttributeError: |
38 | | - # trimesh should work out-of-box for py>=3.12 on non-intel mac |
39 | | - mesh = trimesh.load_mesh(filepath, process=False) |
40 | | - else: |
41 | | - mesh = trimesh.load_mesh(filepath, process=False) |
42 | | - |
43 | | - return mesh |
44 | | - |
45 | | -def to_ctm(mesh: trimesh.Trimesh, path: str | Path) -> None: |
46 | | - path = Path(path) |
47 | | - if path.suffix.lower() != ".ctm": |
48 | | - mesh.export(path, file_type=path.suffix.lstrip(".")) |
49 | | - raise ValueError( |
50 | | - f"Expected a .ctm file, got {path.suffix}. " |
| 30 | + if filepath.suffix.lower() == ".ctm": |
| 31 | + print( |
| 32 | + "CTM file detected. skeliner no longer bundles explicit OpenCTM " |
| 33 | + "support. Loading will fall back to trimesh’s limited reader.\n" |
| 34 | + "Full read/write support is still possible on compatible setups:\n" |
| 35 | + " • Python ≤ 3.11, x86-64 → pip install python-openctm\n" |
| 36 | + "Then load manually:\n" |
| 37 | + " import openctm, trimesh\n" |
| 38 | + " mesh = openctm.import_mesh(filepath)\n" |
| 39 | + " mesh = trimesh.Trimesh(vertices=mesh.vertices,\n" |
| 40 | + " faces=mesh.faces,\n" |
| 41 | + " process=False)\n" |
51 | 42 | ) |
| 43 | + |
| 44 | + mesh = trimesh.load_mesh(filepath, process=False) |
52 | 45 |
|
53 | | - verts = mesh.vertices.astype(np.float32, copy=False) |
54 | | - faces = mesh.faces.astype(np.uint32, copy=False) |
55 | | - |
56 | | - ctm_mesh = openctm.CTM(verts, faces, None) |
57 | | - openctm.export_mesh(ctm_mesh, path) |
| 46 | + return mesh |
58 | 47 |
|
59 | 48 | # ----------- |
60 | 49 | # --- SWC --- |
|
0 commit comments