MuJoCo Origami Simulator
This project is a Python-based origami folding simulator built around MuJoCo. It reconstructs a crease pattern from 2D line segments, validates the paper topology, generates a MuJoCo model for the folded sheet, applies fold-angle targets, and optionally vibrates the support table to simulate a realistic folding environment. The code is structured as an engineering pipeline rather than a pure toy example: crease patterns are normalized into a canonical format, polygon faces are built from the sheet layout, MuJoCo XML is generated from the resulting pattern, and the net displacement of the paper is measured as a forward-folding fitness signal.
What this project does
- Builds a crease network from
p1,p2, andangledata - Verifies that the crease graph tiles the square sheet without invalid sliver faces
- Creates a MuJoCo model from the pattern geometry and hinge constraints
- Drives fold actuators toward target fold angles during simulation
- Applies a small support-table vibration for dynamic motion
- Measures the forward displacement of the paper centroid
- Exports the rendered motion to video for inspection
Simulation Output
Below is the physical rendering of the simulation output, demonstrating how the paper layout reacts to active hinge joint torques and support table vibrations:
| Vibrating Table: Amplitude & Frequency | Fold Crease | Video Preview |
|---|---|---|
| Lower amplitude & frequency | Partial / standard | |
| High amplitude & frequency | Full | |
| Higher amplitude & frequency | Full |
Core modules
origami_engine/constants.py— shared physical/solver constantsorigami_engine/types.py—Crease,Pattern,SimulationResultdomain typesorigami_engine/geometry.py— crease graph / face reconstruction (build_pattern)origami_engine/model.py— MuJoCo XML generation (generate_xml)origami_engine/dynamics.py— simulation loop, table vibration, centroids (run_simulation,drive_table,paper_centroid)origami_engine/serialization.py— crease normalization and JSON I/O (validated against the packaged JSON Schema viajsonschema)origami_engine/evaluation.py— fitness-oriented APIs (evaluate_individual,evaluate_population)origami_engine/patterns.py— reusable reference crease patternsorigami_engine/simulation.py— backward-compatible facadeorigami_engine/render_individual.py— script for rendering a single pattern to an MP4/video reportorigami_engine/example.py— minimal evaluation workflowtests/test_evaluation.py— regression checks for evaluation, input validation, and JSON I/O
Project layout
.
├── origami_engine/
│ ├── __init__.py
│ ├── backend.py
│ ├── constants.py
│ ├── types.py
│ ├── geometry.py
│ ├── model.py
│ ├── dynamics.py
│ ├── serialization.py
│ ├── schemas/
│ │ └── crease_pattern.schema.json
│ ├── evaluation.py
│ ├── patterns.py
│ ├── simulation.py # facade for backward-compatible imports
│ ├── render_individual.py
│ └── example.py
├── examples/
│ ├── README.md
│ ├── 01_evaluate_reference.py
│ ├── 02_json_input.py
│ ├── 03_inspect_pattern.py
│ └── 04_evaluate_population.py
├── crease_patterns/
│ └── reference_miura_4x4.json
├── experiments/
│ ├── TIMELINE.md
│ └── prototype_notebooks.zip
├── tests/
│ └── test_evaluation.py
├── .github/workflows/ci.yml
├── ARCHITECTURE.md
├── individual_simulation.mp4
├── pyproject.toml
└── README.md
Requirements
Runtime dependencies are declared in pyproject.toml (MuJoCo, NumPy, Shapely, imageio, jsonschema) and installed with:
pip install -e ".[dev]"
which also adds pytest for running the test suite. The package is importable as origami_engine after installation.
Quick start
Create a virtual environment and install the package with development dependencies, then run the validation or rendering scripts.
python -m venv .venv
. .venv/bin/activate
pip install -e ".[dev]"
python -m pytest -q tests
python origami_engine/render_individual.py
Library API
pip install -e ".[dev]"
python -c "
from origami_engine import (
CREASE_SCHEMA,
Crease,
build_pattern,
evaluate_individual,
evaluate_population,
load_creases_from_json,
normalize_creases,
reference_miura_legacy_creases,
save_creases_to_json,
run_simulation,
paper_centroid,
)
"
A machine‑readable JSON Schema describing the crease input format is included at
origami_engine/schemas/crease_pattern.schema.json. It is used by
load_creases_from_json to validate files at load time (invalid files raise
ValueError), and is also exposed as origami_engine.CREASE_SCHEMA for
validation in your own tools before calling the library.
API Reference
Domain types
| Export | Description |
|---|---|
Crease |
A single crease segment with p1, p2 (2D points) and angle (radians). Negative = Mountain, positive = Valley. |
Pattern |
Validated face/edge graph from build_pattern(). Contains faces, edges, loop_edges, valid, reason, n_faces, n_loops. |
SimulationResult |
Result of run_simulation(): model, data, pattern, info, centroids. |
CREASE_SCHEMA |
JSON Schema for validating crease input files. |
Pattern construction
| Export | Description |
|---|---|
build_pattern(creases) |
Reconstruct polygonal faces and the spanning-tree hinge graph from a crease list. Returns a Pattern. |
load_default_creases() |
Load the default reference crease pattern from JSON, with fallback to the built-in Miura-ori. |
load_creases_from_json(path) |
Load and validate creases from a JSON file. |
save_creases_to_json(creases, path) |
Save creases to a JSON file. |
normalize_creases(creases) |
Normalize raw crease inputs (dicts or Crease objects) into Crease instances. |
reference_miura_legacy_creases() |
Legacy Miura-ori crease list. |
reference_miura_render_creases() |
Render-tuned Miura-ori crease list. |
Simulation
| Export | Description |
|---|---|
run_simulation(creases, ...) |
Run a MuJoCo simulation from creases and return a SimulationResult. |
generate_xml(pattern) |
Generate MuJoCo XML from a validated Pattern. |
drive_table(...) |
Apply support-table vibration during simulation. |
paper_centroid(data) |
Compute the paper centroid from MuJoCo data. |
Evaluation
| Export | Description |
|---|---|
evaluate_individual(creases, ...) |
Score a single crease pattern via forward displacement. |
evaluate_population(creases_list, ...) |
Score a population of crease patterns, optionally in parallel. |
compute_forward_displacement(...) |
Compute forward displacement from simulation data. |
Visualization
| Export | Description |
|---|---|
plot_pattern(creases, pat=None) |
Plot a crease pattern: Mountain=crimson dashed, Valley=royalblue dash-dot, degree labels, face indices, loop-edge markers, legend. |
Constants
| Export | Description |
|---|---|
S |
Sheet size (1.0). |
M, V |
Canonical Mountain (negative) and Valley (positive) fold angles (±45°). |
MAX_FOLD, MIN_FACE_AREA, KP, KV, ... |
Physical and solver constants. |
Example: complete workflow
from origami_engine import load_default_creases, build_pattern, plot_pattern, run_simulation
creases = load_default_creases()
pat = build_pattern(creases)
# Visualize
plot_pattern(creases, pat)
# Simulate
result = run_simulation(creases, duration=8.0)
print(result.info["n_faces"], "faces simulated")
Examples
Runnable usage snippets live in the examples/ folder:
python examples/01_evaluate_reference.py
python examples/02_json_input.py
python examples/03_inspect_pattern.py
python examples/04_evaluate_population.py
python examples/05_plot_pattern.py
Crease pattern visualization
View any crease pattern at a glance with plot_pattern:
from origami_engine import build_pattern, load_default_creases, plot_pattern
creases = load_default_creases() # default reference pattern
pat = build_pattern(creases) # validate faces / edges
plot_pattern(creases, pat) # Mountain=red dashed, Valley=blue dash-dot
plot_pattern draws the sheet between 0.0 and 1.0 on both axes, colours
Mountain folds crimson dashed and Valley folds royalblue dash-dot, labels every
crease with its fold angle in degrees, places gray face indices at each
polygon's representative point, marks loop edges with a black x, and prints a
title like "24 creases | 16 faces | 9 loop edges (x)".
Run the example script to open the figure interactively:
python examples/05_plot_pattern.py
A pre-rendered version of the default reference pattern is included in the
repository at docs/crease_pattern_plot.png:
Default reference crease pattern — 24 creases | 16 faces | 9 loop edges
Experimental history
This repository also preserves the experimental stage of the simulator before it was modularized into origami_engine/. These are the historical Jupyter notebooks (not part of the runtime package) that were used to develop the fold physics:
experiments/TIMELINE.md— phase-by-phase prototyping history (contact optimization, viscoelastic tuning, tear fixes, etc.)experiments/prototype_notebooks.zip— the archived notebook bundle (GEN_1…GEN_4)
Unzip the archive and run the notebooks locally:
unzip experiments/prototype_notebooks.zip -d experiments/notebooks
. .venv/bin/activate
pip install jupyter
jupyter notebook experiments/notebooks
Example crease input
Crease data is represented as a list of line segments with a start point, end point, and target fold angle. Target angles dictate whether a joint behaves as a Mountain fold (negative radians) or a Valley fold (positive radians).
from origami_engine.simulation import Crease
creases = [
Crease((0.2, 0.0), (0.45, 0.25), -0.7853981633974483),
Crease((0.45, 0.25), (0.2, 0.5), -0.7853981633974483),
]
Explicit Mountain-Valley Fold Pairing
Here is an explicit example of a 90-degree Mountain-Valley fold sequence along a shared crease node to create a standard V-shape:
import numpy as np
from origami_engine.simulation import Crease
crease_sequence = [
# Crease 1: Mountain Fold (-90 degrees in radians)
Crease(p1=(0.0, 0.5), p2=(0.5, 0.5), angle=-np.pi / 2),
# Crease 2: Valley Fold (+90 degrees in radians)
Crease(p1=(0.5, 0.5), p2=(1.0, 0.5), angle=np.pi / 2),
]
The project also supports JSON input with the following schema:
{
"angle_unit": "degree",
"creases": [
{ "p1": [0.0, 0.5], "p2": [0.5, 0.5], "angle": -90.0 },
{ "p1": [0.5, 0.5], "p2": [1.0, 0.5], "angle": 90.0 }
]
}
Evaluation workflow
The project exposes a small evaluation API over the MuJoCo simulation:
from origami_engine.evaluation import evaluate_individual
score = evaluate_individual(
creases,
duration=8.0,
trajectory=(1.0, 0.0, 0.0),
fold_duration=3.0,
)
print(score)
This returns the forward displacement of the paper centroid relative to the requested trajectory direction, measured after the simulated folding run.
Notes
The simulator is built around real paper topology and MuJoCo dynamics. It is not just a geometric crease renderer; it creates a physical model that can be evaluated and visualized under controlled fold and vibration conditions. For implementation details and module responsibilities, see ARCHITECTURE.md.
Metadata
Release files for origami-engine 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| origami_engine-0.1.0.tar.gz | 2.2 MB | With provenance | Details for origami_engine-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| origami_engine-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for origami_engine-0.1.0-py3-none-any.whl |
Total release size: 2.2 MB
Release files / origami_engine-0.1.0.tar.gz
| Download URL | origami_engine-0.1.0.tar.gz |
|---|---|
| Size | 2.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8fdb62ade78e9b1014e265dcc9f1eef72ca96d2ee3fbef9ee780432c18fea9ba
|
|
BLAKE2b-256 checksum How to use checksums |
6c5e6b06ca8a2696893cc0b9caf97aed87eece47773ce059c146cf8865d9224d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logRelease files / origami_engine-0.1.0-py3-none-any.whl
| Download URL | origami_engine-0.1.0-py3-none-any.whl |
|---|---|
| Size | 30.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce4d21d2b3526c1238af6a11241c8605b2b3893aa0938809a77646968863ed48
|
|
BLAKE2b-256 checksum How to use checksums |
53f00d4bab5845bf424f9b0e8fa6b0bb5504ca1ca21d9d114f4aeeeb5f0d1603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logSecurity for origami-engine 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for origami_engine-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.