Skip to content

About

Generate the muscle layouts based on the skeleton as input

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Muscle generator

Give it a leg skeleton; it returns muscles as lines with thickness and as closed volumes, attached to the bones and overlap-free by construction. The aim is a robot leg in which artificial muscles replace motors, so a layout must be buildable first and anatomical second.

This is early research code. Milestones 1 to 4 of 10 are done:

  1. A first grown leg: a gibbon given muscles borrowed from six other apes, with zero overlap and both ends of every muscle on the right bones.
  2. A dataset of 37 hind legs from published musculoskeletal models, in one format.
  3. Borrowing baselines, scored with whole groups of species hidden.
  4. Grown shapes compared voxel by voxel with real human and rat muscles.

Goals, decisions, results and the next steps are in plan.md; sources and known data faults in resources.md; the current numbers in metrics/.

What is in this repository

The code, parameters, tests and aggregate metrics. The source models and meshes, per-muscle results and pictures are not: the sources' licences vary (some are non-commercial, some state none), so the data is downloaded separately and everything derived from it stays on your machine (data/ and results/ are gitignored).

Setup

Tested on Linux. Needs uv, the system libarchive, and Blender 4.x for the volumes stage and pictures (on PATH, or set BLENDER). Runs on the CPU; the largest stage peaks at about 3 GB of memory.

uv sync                      # one locked environment (Python 3.12)
make test                    # unit tests; tests that need the data skip themselves

Data

  • Each source's link and licence label are in src/musclegen/sources.py (one record per species) and resources.md. Some SimTK projects need a free account.
  • data/raw.manifest.json pins the exact inputs: every downloaded file by size and SHA-256 under data/raw/<folder>/, and every cloned repository by commit under data/raw/git/<name>/. make verify lists what is missing or different.
  • Downloaded files are untrusted. The pipeline runs Python with -I, parses XML with defusedxml, and extracts archives with path, link and size checks.

Run

make all                     # data → legs → volumes → m1 → m3 → m4 → stroke; only stale stages rerun
make render                  # Blender (Cycles, CPU) pictures of results/m1
make test-slow               # golden output hashes, determinism, M1 gates; needs the data (minutes)
make lint
Stage Command Output (local) Metrics (committed)
verify, extract musclegen data verify, data extract data/extracted/ the inputs are checked against data/raw.manifest.json
volumes musclegen volumes data/volumes/
build musclegen build data/legs/ (one leg.json per species) metrics/build.json
m1 musclegen m1 results/m1/ (.glb, report.json) metrics/m1.json
m3 musclegen m3 results/m3/ (report.json, donors.png) metrics/m3.json
m4 musclegen m4 results/m4/ (report.json, slices, .glb per case) metrics/m4.json
stroke musclegen stroke results/stroke.json metrics/stroke.json

Parameters live in params/<stage>.yaml. The same inputs give byte-identical outputs, whatever the worker count or hash seed.

Experiments and progress

  • To try a parameter change, run python -m musclegen m1 --set growth_rounds=1000. It writes results/experiments/m1-<hash>/ and leaves the main results untouched.
  • Every run, experiments included, adds one line to metrics/runs.jsonl. The line holds the commit, whether the tree had uncommitted changes, the parameter hash, the overrides, the metrics and the time taken.
  • python -m musclegen metrics diff HEAD~3 compares the metrics of a past commit with the working tree.
  • python -m musclegen metrics log m1.attachment_error_median shows how one metric changed over the commits.
  • metrics/*.json is committed with the code that produced it.

Layout

src/musclegen/
  xmltools, meshio, geometry, sides   shared helpers
  leg                                 the leg.json schema (dataclasses), right-leg choice, mirroring
  readers/opensim, mujoco, simm       model readers → one Model type
  names, sources                      homology groups; the 37 sources with licences
  archive, prepare                    safe extraction, frog patch, volume conversion
  dataset, gallery                    the leg dataset and its picture
  transfer, volume, meshing, export   milestone 1: borrow, route, grow, mesh, write
  sculpt                              route, grow and mesh muscles on any skeleton
  borrow                              milestone 3: fit bones region by region, carry, score
  shapes                              milestone 4: real muscle shapes, their lines, Dice
  m1, m3, m4, stroke, metrics, cli    stages and tracking
scripts/blender/                      run inside Blender
tests/                                unit, integration, slow (golden hashes + determinism)

Licence

The code is under the Apache License 2.0. No source data is included; each source keeps its own licence, and the label for each is in sources.py.

The full pipeline is for non-commercial use for now. Most sources are CC BY, CC0, MIT or Apache, but some are not:

  • The sheep and emu models are non-commercial.
  • The cat and frog models, and the homology table that the muscle groups follow, state no licence.
  • The rat, mouse, horse, Australopithecus and Rajagopal models are under custom or unconfirmed terms.

So the leg dataset, results and any model built from the full set may be used for non-commercial purposes only, and each source's own terms apply on top. A mode that uses only permissively licensed sources is planned.

Human muscle shapes come from BodyParts3D, © The Database Center for Life Science, licensed under CC Attribution 4.0 International; milestone 1 uses one value taken from it, the pectineus volume.

About

Generate the muscle layouts based on the skeleton as input

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages