Metadata-Version: 2.4
Name: mayatk
Version: 0.36.0
Summary: Python toolkit for Autodesk Maya: modeling, UV, materials, animation, rigging, lighting and scene-export utilities.
Author-email: Ryan Simpson <m3trik@outlook.com>
License-Expression: LicenseRef-MIT-Commons-Clause
Project-URL: Homepage, https://github.com/m3trik/mayatk
Project-URL: Repository, https://github.com/m3trik/mayatk
Project-URL: Changelog, https://github.com/m3trik/mayatk/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/m3trik/mayatk/issues
Keywords: m3trik,maya,autodesk-maya,maya-python,rigging,animation-tools,technical-art,dcc
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Intended Audience :: Developers
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pythontk>=0.27.0
Requires-Dist: uitk>=1.12.1
Dynamic: license-file

[![License: MIT + Commons Clause](https://img.shields.io/badge/License-MIT%20%2B%20Commons%20Clause-blue.svg)](https://github.com/m3trik/mayatk/blob/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/mayatk.svg)](https://pypi.org/project/mayatk/)
[![Python](https://img.shields.io/badge/Python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![Maya](https://img.shields.io/badge/Maya-2025+-orange.svg)](https://www.autodesk.com/products/maya/)
[![Tests](https://img.shields.io/badge/Tests-9320%20passed-brightgreen.svg)](../tests/)
![Platform](https://img.shields.io/badge/Platform-Windows%2C%20Linux-lightgrey.svg)

# mayatk

<!-- short_description_start -->
*Maya 2025+ tech-art toolkit built on `maya.cmds` + `maya.api.OpenMaya` (no PyMEL) — modeling, animation, materials, rigging, and scene-pipeline automation, plus one-click bridges into Marmoset, Substance Painter, RizomUV, Blender, and Unity. The tool panels over it are [tentacle](https://github.com/m3trik/tentacle)'s.*
<!-- short_description_end -->

mayatk is the Maya layer of the `pythontk → uitk → {mayatk, blendertk} → tentacle` ecosystem: the Maya half of every [tentacle](https://github.com/m3trik/tentacle) tool, as a library a script can call.

<!-- diagram:ecosystem/mayatk -->
<!-- Generated by m3trik/scripts/generate_readme_diagrams.py from the workspace's declarations: change those and re-run it, never this block. -->
<p align="center">
<a href="https://github.com/m3trik/m3trik#readme"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/m3trik/m3trik/main/docs/diagrams/ecosystem-mayatk-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/m3trik/m3trik/main/docs/diagrams/ecosystem-mayatk-light.svg"><img alt="mayatk (highlighted) in the ecosystem: uitk requires pythontk; unitytk requires pythontk; mayatk requires uitk; blendertk requires uitk; tentacle requires uitk; extapps requires uitk; tentacle installs mayatk as its [maya] extra; tentacle installs blendertk as its [blender] extra; tentacle opens extapps by name (its [apps] extra) and never imports it; mayatk and blendertk share a mirrored API. tentacle and extapps are products, which nothing imports." src="https://raw.githubusercontent.com/m3trik/m3trik/main/docs/diagrams/ecosystem-mayatk-light.svg" width="781"></picture></a>
</p>
<!-- /diagram:ecosystem/mayatk -->

## Install

```bash
pip install mayatk
```

Maya 2025+ (Python 3.11+). Every class is reached from the package root and loaded on first use, so `import mayatk` loads declarations and nothing else.

---

## The design, and what it buys

- **The logic lives here; the panels live in tentacle.** Every tool is a class with a plain API and no UI, and its panel only calls it. Whatever an artist does from a panel, a script, a test or an AI agent does with the same call.
- **A tool records what it changes, in the scene.** Smart Bake and Texture Combine write down what they changed on a node in the scene itself, so either is reversed exactly, also after the scene was saved, closed and reopened. The Scene Exporter puts back every edit it staged before it returns.
- **A delivered file carries its own records.** What an engine needs beyond the geometry (which take is which shot, the sound cues, the lightmaps, the materials as authored) is written into the exported file. The records are declared once, in pythontk, and Unity and the WebXR viewer read them through types generated from that declaration.
- **Mirrored in Blender.** [blendertk](https://github.com/m3trik/blendertk) offers the same operations under the same names, so one tentacle panel serves both hosts, and what both need is written once, in [pythontk](https://github.com/m3trik/pythontk).
- **Your session is never the test bench.** `MayaConnection`, the test runner and the host an AI agent's calls run in each launch a Maya of their own.

## The tools

### A procedure sheet to engine-ready shots

Three tools carry a procedure from the sheet it is written on to the file an engine plays. Each one's page shows it at work, with a clip beside every feature.

![Assess, then Build: five shots appear with their keys](https://raw.githubusercontent.com/m3trik/mayatk/main/docs/images/shot_manifest_assess_build.gif)

- **[Shot Manifest](https://github.com/m3trik/mayatk/blob/main/docs/shot_manifest.md)** builds one shot per step of a build sheet (a CSV file or a Google Sheets link): named after the step, holding its objects, with the fades and highlights the sheet asks for already keyed. The sheet stays the source and the scene stays the animator's: the tool never writes the sheet, never creates the objects it names, never removes a shot and never keys over existing work. So Assess and Build can be run again at any point in production. [Watch the demo](https://github.com/m3trik/mayatk/blob/main/docs/images/shot_manifest.mp4).
- **[Shot Sequencer](https://github.com/m3trik/mayatk/blob/main/docs/shot_sequencer.md)** is a timeline where the shot is the unit, not the key: move a shot's edge and every later shot follows with its keys and audio. [Watch the demo](https://github.com/m3trik/mayatk/blob/main/docs/images/shot_sequencer.mp4).
- **[Scene Exporter](https://github.com/m3trik/mayatk/blob/main/docs/scene_exporter.md)** keeps the working scene and the exported scene apart. What it changes only for the file (the unit, the bake, the flattened joints, the takes) is staged for the write and put back afterwards, however the run ends, and a failed check stops the run before anything is written. It writes FBX, GLB or USD; in an FBX each shot goes out as its own named take, which [Unity imports as an animation clip](https://github.com/m3trik/mayatk/blob/main/docs/shot_export_unity.md). [Watch the demo](https://github.com/m3trik/mayatk/blob/main/docs/images/scene_exporter.mp4).

One job taken through all three, and on into Unity: [Tool demos](https://github.com/m3trik/m3trik/blob/main/docs/TOOL_DEMOS.md). The exporter from code, with the panel's own defaults: [Calling it from code](https://github.com/m3trik/mayatk/blob/main/docs/scene_exporter.md#calling-it-from-code).

### Smart Bake

It finds what drives the animation (constraints, set-driven keys, expressions, IK, motion paths, driven blend shapes) and bakes only those channels, over the range the drivers animate. A bake is a transaction: each phase records what it is about to change before changing it, so a phase that fails is rolled back, and a finished bake is reversed from the same record in a later session.

```python
import mayatk as mtk

result = mtk.SmartBake(optimize_keys=True).execute()
mtk.SmartBake.restore()             # the drivers resume
```

### Lightmap Baker

[Arnold lighting baked into engine lightmaps](https://github.com/m3trik/mayatk/blob/main/docs/lightmap_baker.md), wired for the engine in the same step. Light is not baked into the albedo: each mesh keeps its PBR material and texture UVs, and the lightmap is a separate HDR map on a second UV set that Unity and the glTF export both read. Every bake records what each map was baked against (the mesh, its UVs, its materials, the lights), so the tool knows which maps an edit made stale and re-bakes exactly those.

### Texture Combine

[Several materials become one atlas and one material](https://github.com/m3trik/mayatk/blob/main/docs/texture_combine.md), in place: the meshes keep their geometry, their UVs are repacked into one layout, and every map is resampled into it. The originals are recorded in the scene, so a combine is restored exactly, or run again when a source map is revised.

### Rigs for mechanical parts

- **[Articulated Rig](https://github.com/m3trik/mayatk/blob/main/docs/articulated_rig.md)** rigs a prop of rigid parts on hinges, swivels, balls and slides (a desk lamp, a monitor arm), its joints proposed from the geometry. Each control sits in its joint's rest frame, so the value an animator keys is the joint's angle with no conversion. Unity and the WebXR viewer play that same number, and a hand that grabs the prop there writes it, solved by one model that every port is held to.
- **Shadow Rig** gives an object a ground shadow an engine draws as a textured plane, projected through the light as a real shadow forms. Its Horizon type bakes a map the engine samples, so the outline follows a light that moves at runtime, drawn by one shader source that Unity and the WebXR viewer share.
- **Tube Rig** rigs a hose, cable or piston from the mesh alone: it finds the tube's centerline and sizes the controls to the measured radius.

### A preview that never touches undo

`Preview` gives any tool a live preview. A preview pass is recorded nowhere: cancel rolls the scene back from a snapshot of what the pass created, and commit replays the operation once, as a single undo step. A Ctrl+Z in the middle of a preview is still the artist's own.

### Hand-offs, and a live headset preview

One call exports the selection and opens it in **Marmoset Toolbag**, **Substance 3D Painter** or a fresh **Blender**, and runs a script from a template on arrival (`mtk.MarmosetBridge().send(template="bake")`). The **Unity** bridge exports into a Unity project's `Assets/`, and the **RizomUV** bridge unwraps the selection there and brings the UVs back.

`mtk.WebXrPreview().push()` sends the selection to a browser instead. A tab left open, including one in a PC-tethered headset, shows each new push without a reload, baked lightmaps included: [Live WebXR preview](https://github.com/m3trik/pythontk/blob/main/docs/webxr_preview.md).

### Also

- `AutoInstancer(separate_combined=True)` takes one combined mesh, sorts its shells back into the repeated assemblies they came from, and instances those: copies that touch, or that are rotated or uniformly scaled, are still matched, and what repeats nowhere is merged into one mesh.
- `SceneAnalyzer.run_audit()` is a game-readiness report (rendered against unique triangles, draw calls, each material's texture cost in GPU memory, what to fix first) that measures each mesh shape once and weights it by its instances, so an instanced scene reads as it will render.
- `HierarchySync` compares the scene's hierarchy with a reference file, then pulls in what is missing and repairs what was renamed or reparented.
- `MayaConnection` launches a Maya of its own and runs code in it from any Python process. For an AI agent, mayatk registers Maya with pythontk's operations, so calls over MCP run in a Maya started for them ([setup](https://github.com/m3trik/m3trik/blob/main/docs/AGENT_INSTRUCTIONS.md)).

<details>
<summary><b>Package map</b>: where each thing lives</summary>

| Package | What it holds |
|---|---|
| `anim_utils` | Animation curves, shots, blendshape animation, playblast, smart bake |
| `audio_utils` | Audio clips, ffmpeg-backed conversion, timeline-keyed events |
| `cam_utils` | View capture and framing, camera clipping, cameras from the current view, view state save and restore |
| `core_utils` | `CoreUtils`, `Components`, `AutoInstancer`, the scene audit and repair helpers, the tool preview, MASH bridge |
| `display_utils` | Visibility & isolation, color ID, exploded view |
| `edit_utils` | `Selection`, naming, primitives, snap, bevel, bridge, mirror, duplicate (linear/radial/grid), mesh graph |
| `env_utils` | `MayaConnection`, the `maya` operation host (`MayaSceneFiles`), workspaces, namespace sandbox, references, hierarchy sync, FBX/USD, [scene exporter](scene_exporter.md), Blender + Unity bridges, WebXR preview |
| `light_utils` | [Lightmap baker](lightmap_baker.md), [Light rigs](light_rig.md), HDR manager, lights-from-geometry |
| `mat_utils` | `GameShader`, `RenderEffects` (per-object `opacity` / `highlight` channels), `ImageToPlane`, `MatUpdater`, shader templates, emissive groups, Marmoset + Substance bridges |
| `node_utils` | `NodeUtils`, `Attributes`, the Channels engine, [shared scene data nodes](data_nodes.md) |
| `nurbs_utils` | NURBS surfaces, `ImageTracer`, curve-to-tube |
| `render_utils` | Renderer switching, render settings and their presets |
| `rig_utils` | `Controls`, skinning, tube / wheel / telescope / shadow / [articulated](articulated_rig.md) rigs |
| `ui_utils` | `MayaUiHandler` (also opens uitk's editors with no tentacle: `mtk.MayaUiHandler.instance().editors.show("ui_browser")`), the marking-menu host adapter, channel box, native menus, hotkey collision check, node icons |
| `uv_utils` | Unwrap, pack and transfer UVs, [Texture Combine](texture_combine.md), Rizom bridge |
| `xform_utils` | Freeze and restore transforms, pivots, alignment and placement, matrices |

The whole public surface, searched live from the installed source: `python -m pythontk ops run api.search "query=<words>"`.

</details>

---

## Guides

| Guide | What it covers |
|---|---|
| [Shot Manifest](shot_manifest.md) | The sheet's columns and templates, behaviors, Assess, Build, Local Edits, Export, and the rules it keeps |
| [Shot Sequencer](shot_sequencer.md) | The views, the shot, clip and key gestures, the graph editor |
| [Scene Exporter](scene_exporter.md) | Every task and check, the file-name tokens, what the file carries, presets, the call from code |
| [Shot data in the FBX → Unity](shot_export_unity.md) | Shots as named Unity animation clips, with their metadata and audio events |
| [Scene data nodes](data_nodes.md) | What each record holds, and what an FBX, GLB or USD export carries |
| [Lightmap Baker](lightmap_baker.md) | The panel, presets, which lights light a bake, where the maps land, re-baking what changed |
| [Light Rigs](light_rig.md) | A scene's lights saved as a named rig, swapped and restored exactly |
| [Texture Combine](texture_combine.md) | Packing, scale overrides per material, mesh and island, restore and re-combine, UV / texture transfer |
| [Articulated Rig](articulated_rig.md) | The joint types and how they are found, the rig, the record the runtimes pose, grab semantics |
| [Shadow Rig: the Horizon type](shadow_rig_morphing.md) | A design review: the options weighed and the contract Maya, Unity and the WebXR viewer are built against |
| [Emissive groups](emissive_groups.md) | Regions whose glow plays on its own, as materials, and what each package holds |
| [Live WebXR preview](https://github.com/m3trik/pythontk/blob/main/docs/webxr_preview.md) | What the preview builds and what survives the trip |

Format specs: [the Scene Exporter's preset JSON](../mayatk/env_utils/scene_exporter/TEMPLATE_RULES.md), key by key. The Shot Manifest writes its mapping-file reference, `MAPPING_FORMAT.md`, into the mapping folder it opens.

---

## Links

- **Full API:** `python -m pythontk ops run api.search "query=<words>"` (the installed source, searched)
- **Blender parity:** [blendertk](https://github.com/m3trik/blendertk) mirrors this package's public API (`btk.X` ↔ `mtk.X`); the map of what corresponds, and what is deliberately absent on each side, is [blendertk/docs/STRUCTURE.md](https://github.com/m3trik/blendertk/blob/main/docs/STRUCTURE.md).
- **Test suite:** [`tests/README.md`](../tests/README.md) — suite layout, base classes, runner invocations
- **Changelog:** [`CHANGELOG.md`](../CHANGELOG.md)
- **Contributor / AI-agent guide:** [`AGENTS.md`](../AGENTS.md)
- **PyPI:** https://pypi.org/project/mayatk/
- **Issues:** https://github.com/m3trik/mayatk/issues

## License

MIT with the [Commons Clause](https://commonsclause.com/) — see [LICENSE](https://github.com/m3trik/mayatk/blob/main/LICENSE). Free to use, modify and share, including in paid production work; what it forbids is selling mayatk, or a product or service whose value comes mainly from it. The Blender-side scripts under `env_utils/blender_bridge/templates/` are plain MIT, since code that runs inside Blender must be GPL-compatible.
