Extract connected skeletal graphs (centerlines) from 3D meshes
Project description
Mesh Skeleton
Extract connected skeletal graphs from 3D meshes. Unlike point-cloud skeletons, this tool preserves full connectivity as a NetworkX graph — enabling direct path traversal, branch analysis, and navigation.
Installation
pip install mesh-skeleton
Or from source:
git clone https://github.com/iamsalvatore/mesh-skeleton.git
cd mesh-skeleton
pip install -e .
Quick Start
Command Line
python -m mesh_skeleton input_mesh.obj # basic extraction
python -m mesh_skeleton input_mesh.stl -o skeleton.ply -r 256 # custom resolution
python -m mesh_skeleton input_mesh.obj --no_viz # skip visualization
Python API
import trimesh
from mesh_skeleton import SkeletonExtractor
mesh = trimesh.load('model.obj')
extractor = SkeletonExtractor(mesh, voxel_resolution=256)
skeleton_coords = extractor.extract_skeleton()
# Access the graph
G = extractor.skeleton_graph # NetworkX graph
endpoints = extractor.endpoints # degree-1 nodes
junctions = extractor.junctions # degree-3+ nodes
main_path = extractor.main_path # longest path indices
# Custom path between two world-space points
centerline = extractor.get_ordered_centerline(start_point=[0,0,0], end_point=[1,1,1])
# Save PLY + JSON
extractor.save_skeleton(skeleton_coords, 'skeleton.ply')
How It Works
- Interior fill — watertight meshes use ray-cast containment (
mesh.contains); non-watertight meshes use surface voxelization + morphological closing + exterior flood-fill - Skeletonization — topological thinning via scikit-image
- Graph construction — 26-connected voxel neighbors linked via KDTree
- Connectivity enforcement — disconnected components bridged with interpolated edges
- Path analysis — endpoints, junctions, main centerline (double-BFS), and non-overlapping branch segments (edge-walking)
GPU Acceleration
When PyTorch with CUDA is available, voxelization and morphological operations run on GPU automatically. No code changes needed — falls back to CPU transparently.
Output Files
skeleton.ply
PLY with vertex positions and edge connectivity.
skeleton_graph.json
{
"vertices": [[x, y, z], ...],
"edges": [[v1, v2], ...],
"endpoints": [0, 5, ...],
"junctions": [12, 34, ...],
"main_path": [0, 1, 2, ...],
"branch_paths": [[12, 13, 14], ...]
}
CLI Arguments
| Argument | Default | Description |
|---|---|---|
input_mesh |
required | Input mesh file (OBJ, STL, PLY, etc.) |
-o, --output |
skeleton.ply |
Output file path |
-r, --resolution |
256 |
Voxel grid resolution (128=fast, 256=balanced, 512=detailed) |
--no_viz |
off | Skip matplotlib visualization |
Resolution Guide
| Resolution | Use case | Notes |
|---|---|---|
| 128 | Quick preview | Fast, coarse detail |
| 256 | Production | Balanced quality and speed |
| 512 | High detail | Slower, fine structures preserved |
Troubleshooting
Empty skeleton — verify mesh has valid geometry and consistent normals. Try increasing resolution.
Many disconnected components — components <10 voxels are pruned; larger ones are bridged automatically within mesh_scale * 0.1 distance. Check if mesh is watertight.
Slow processing — the bottleneck is skeletonize (CPU-bound). Reduce resolution for faster results.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mesh_skeleton-1.0.0.tar.gz.
File metadata
- Download URL: mesh_skeleton-1.0.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
128e92b4031ce290d587e7170ac8b6d1427bc3ba3dc5654c2bbfb744a1b3451a
|
|
| MD5 |
a7025a049620de39b0081c44be7e24d7
|
|
| BLAKE2b-256 |
20bd3038be2d1a0096b18b57af5e3acac22a7259af91ce29d2ce728596ad71e7
|
File details
Details for the file mesh_skeleton-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mesh_skeleton-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b72aebac13996369275f8a6e15893cba5326fd55bd5861d3e117d70610fe8c
|
|
| MD5 |
7559b02c01c1de10a80b0993c413113b
|
|
| BLAKE2b-256 |
a88b767dde393e5730b039c9bc6017c0dd877f2216cd9a4284525ccf01499cad
|