Skip to main content

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

  1. Interior fill — watertight meshes use ray-cast containment (mesh.contains); non-watertight meshes use surface voxelization + morphological closing + exterior flood-fill
  2. Skeletonization — topological thinning via scikit-image
  3. Graph construction — 26-connected voxel neighbors linked via KDTree
  4. Connectivity enforcement — disconnected components bridged with interpolated edges
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mesh_skeleton-1.0.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mesh_skeleton-1.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file mesh_skeleton-1.0.1.tar.gz.

File metadata

  • Download URL: mesh_skeleton-1.0.1.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

Hashes for mesh_skeleton-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3efe77f37320237b50b05cb3f260608897572730f8210c6ebfa3e24d47b56540
MD5 e1a74339e6fa44dd9751b2fff76cf2f9
BLAKE2b-256 28597af2c876bce7e88d90cbc2132dd8706834633037e3f5c935a261576d316c

See more details on using hashes here.

File details

Details for the file mesh_skeleton-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mesh_skeleton-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mesh_skeleton-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89361804758b705d09b0bc6cf7665d49e236ed95276621ac2ce7266132eae3ba
MD5 19d27d7398f08755fe8736cd3a8d0f99
BLAKE2b-256 c82516a5f33b0871f7b2526a24af884fe4220f5f83f4b90d86593fb7fa00a3cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page