# `CauldronGPU.Mesh`
[🔗](https://github.com/jaman/cauldron/blob/v0.3.3/cauldron_gpu/lib/cauldron_gpu/mesh.ex#L1)

Triangles to upload: vertices, `u32` indices and parts.

`vertices` is a binary of 48-byte vertices, each twelve little-endian floats:
`x, y, z, u, nx, ny, nz, v, lu, lv, s01, s23` — position, normal, texture coordinates
`{u, v}`, lightmap coordinates `{lu, lv}`, and the vertex's four light styles as
`s0 + 256 * s1` and `s2 + 256 * s3` (255 for none; see `CauldronGPU.Material`). `indices` is a binary of little-endian
`u32`, three per counter-clockwise triangle. A part is `{first_index, index_count}`;
an instance gives one material per part. No parts means one part covering every index.

`skin`, for meshes posed with bones (`CauldronGPU.Pose`), is 8 bytes a vertex: four bone
indices, then four weights out of 255 that sum to 255; `nil` for a rigid mesh.

`colors`, 4 bytes a vertex (RGBA, display colour), multiplies each vertex's material base
colour and alpha, blended across each triangle; `nil` for none.

    CauldronGPU.Mesh.cube(1.0)
    CauldronGPU.Mesh.new(vertices, [0, 1, 2], parts: [{0, 3}])

# `part`

```elixir
@type part() :: {non_neg_integer(), non_neg_integer()}
```

# `t`

```elixir
@type t() :: %CauldronGPU.Mesh{
  colors: binary() | nil,
  indices: binary(),
  parts: [part()],
  skin: binary() | nil,
  vertices: binary()
}
```

# `vertex`

```elixir
@type vertex() :: %{
  :position =&gt; {number(), number(), number()},
  optional(:normal) =&gt; {number(), number(), number()},
  optional(:uv) =&gt; {number(), number()},
  optional(:lightmap_uv) =&gt; {number(), number()},
  optional(:light_styles) =&gt; [0..255]
}
```

# `cube`

```elixir
@spec cube(number()) :: t()
```

A cube `size` across, centred on the origin, each face with its own 0..1 texture square.

# `index_count`

```elixir
@spec index_count(t()) :: non_neg_integer()
```

The number of indices in `mesh`.

# `new`

```elixir
@spec new([vertex()], [non_neg_integer()], keyword()) :: t()
```

A mesh from vertex maps and a flat list of indices.

# `plane`

```elixir
@spec plane(number(), number()) :: t()
```

A flat square `size` across on the XZ plane facing +Y, its texture repeated `repeat` times.

# `sphere`

```elixir
@spec sphere(number(), pos_integer()) :: t()
```

A UV sphere of `radius` with `rings` bands and twice as many segments.

# `vertex_count`

```elixir
@spec vertex_count(t()) :: non_neg_integer()
```

The number of vertices in `mesh`.

---

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