CauldronGPU.Mesh (CauldronGPU v0.3.3)

Copy Markdown View Source

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}])

Summary

Functions

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

The number of indices in mesh.

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

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

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

The number of vertices in mesh.

Types

part()

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

t()

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

vertex()

@type vertex() :: %{
  :position => {number(), number(), number()},
  optional(:normal) => {number(), number(), number()},
  optional(:uv) => {number(), number()},
  optional(:lightmap_uv) => {number(), number()},
  optional(:light_styles) => [0..255]
}

Functions

cube(size)

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

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

index_count(mesh)

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

The number of indices in mesh.

new(vertices, indices, opts \\ [])

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

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

plane(size, repeat \\ 1)

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

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

sphere(radius, rings \\ 16)

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

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

vertex_count(mesh)

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

The number of vertices in mesh.