# `Quiddity.Mjcf`
[🔗](https://github.com/d-led/ex.quiddity/blob/main/lib/quiddity/mjcf.ex#L1)

A part as a MuJoCo scene: the triangles quiddity meshed, as an MJCF model.

This is the bridge to a *simulated* world rather than an exact one. A B-rep can
be ray cast exactly — that is what `Quiddity.frame/2` does — but a sensor that
has to make contact, slide and be pushed needs a physics engine. MuJoCo is the
one this writes for, so the part becomes a mesh geometry in metres, which is
what an MJCF holds.

## Units

A STEP file is in millimetres and MuJoCo is in metres, so every coordinate is
divided by 1000 on the way out. Nothing else is changed: the part keeps the
place the file gives it, so a scene written from a part and a frame rendered
from the same part agree about where it is, up to that factor.

## What it is not

It is not a model of the *agent*. A scene holds the part; a body, its sensors
and its actuators are the experiment's, and putting them here would be a second
description of something the experiment already configures.

```elixir
{:ok, part} = Quiddity.open("bracket.step")
{:ok, xml} = Quiddity.Mjcf.document(part)
File.write!("bracket.xml", xml)
```

# `document`

```elixir
@spec document(Quiddity.Part.t(), keyword()) ::
  {:ok, String.t()} | {:error, Quiddity.Error.t()}
```

The scene as MJCF text.

Options: `:deflection` (mm, default 0.05), `:angular` (radians, default 0.3),
`:name` (the model's name, default `"part"`) and `:rgba` (the material's colour,
default a neutral grey).

# `write`

```elixir
@spec write(Quiddity.Part.t(), Path.t(), keyword()) ::
  :ok | {:error, Quiddity.Error.t()}
```

Writes the scene as MJCF text.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
