Table of Contents

Class Mesh

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

Triangles with an optional color, texture coordinate or value at each vertex, for DrawMesh(Mesh, Paint?, BlendMode, ReadOnlySpan<GradientStop>): Gouraud-shaded triangles, textured triangles (a paint mapped through the texture coordinates) and PDF's free-form and lattice-form shadings (one value per vertex, mapped through gradient stops). Immutable: the constructor copies what it is given.

public sealed class Mesh
Inheritance
Mesh
Inherited Members

Examples

using (RasterCanvas<Rgba8> canvas = raster.CreateCanvas())
{
    // Gouraud shading: a color at each corner, blended across each triangle without cracks between them.
    Vector2[] quad = [new(10, 10), new(140, 20), new(130, 140), new(20, 120)];
    RgbaF32[] colors = [new(1, 0.2f, 0.2f, 1), new(1, 0.9f, 0.2f, 1), new(0.2f, 0.6f, 1, 1), new(0.6f, 0.2f, 0.9f, 1)];
    canvas.DrawMesh(new Mesh(MeshMode.Fan, quad, colors), Rgba8.White);

    // A textured mesh: each vertex says which point of the paint lands on it, here bending a photo into a trapezoid.
    Vector2[] trapezoid = [new(170, 20), new(280, 30), new(290, 140), new(160, 130)];
    Vector2[] corners = [new(0, 0), new(64, 0), new(64, 64), new(0, 64)];
    canvas.DrawMesh(new Mesh(MeshMode.Fan, trapezoid, texCoords: corners), new ImagePaint(photo));
}

Constructors

Mesh(MeshMode, ReadOnlySpan<Vector2>, ReadOnlySpan<RgbaF32>, ReadOnlySpan<Vector2>, ReadOnlySpan<float>, ReadOnlySpan<int>)

Initializes a new instance of the Mesh class.

public Mesh(MeshMode mode, ReadOnlySpan<Vector2> positions, ReadOnlySpan<RgbaF32> colors = default, ReadOnlySpan<Vector2> texCoords = default, ReadOnlySpan<float> values = default, ReadOnlySpan<int> indices = default)

Parameters

mode MeshMode

How the vertices make triangles.

positions ReadOnlySpan<Vector2>

The vertices, in the canvas's local coordinates.

colors ReadOnlySpan<RgbaF32>

One straight-alpha color per vertex, or empty for none.

texCoords ReadOnlySpan<Vector2>

One point in the paint's coordinates per vertex, or empty for none: the paint is mapped onto each triangle through them.

values ReadOnlySpan<float>

One value per vertex, or empty for none: interpolated, then mapped to a color through the stops given to DrawMesh(Mesh, Paint?, BlendMode, ReadOnlySpan<GradientStop>). A mesh has colors or values, not both.

indices ReadOnlySpan<int>

Indices into the vertices, read by mode in place of the vertices themselves, or empty to read the vertices in order.

Exceptions

ArgumentOutOfRangeException

mode is not defined, or an index is outside the vertices.

ArgumentException

A per-vertex list's length differs from the positions', both colors and values are given, or a number is not finite.

Properties

Bounds

Gets the bounds of the vertices.

public RectF Bounds { get; }

Property Value

RectF

Colors

Gets the vertex colors, or empty when there are none: for a mesh with inks, their appearances in sRGB.

public ReadOnlyMemory<RgbaF32> Colors { get; }

Property Value

ReadOnlyMemory<RgbaF32>

Indices

Gets the indices, or empty when the vertices are read in order.

public ReadOnlyMemory<int> Indices { get; }

Property Value

ReadOnlyMemory<int>

Inks

Gets the vertex colours as inks, or empty when the mesh has none (see WithInks(ReadOnlySpan<InkColor>)).

public ReadOnlyMemory<InkColor> Inks { get; }

Property Value

ReadOnlyMemory<InkColor>

Mode

Gets how the vertices make triangles.

public MeshMode Mode { get; }

Property Value

MeshMode

Positions

Gets the vertices.

public ReadOnlyMemory<Vector2> Positions { get; }

Property Value

ReadOnlyMemory<Vector2>

TexCoords

Gets the texture coordinates, or empty when there are none.

public ReadOnlyMemory<Vector2> TexCoords { get; }

Property Value

ReadOnlyMemory<Vector2>

TriangleCount

Gets the number of triangles the mode makes, degenerate ones included.

public int TriangleCount { get; }

Property Value

int

Values

Gets the vertex values, or empty when there are none.

public ReadOnlyMemory<float> Values { get; }

Property Value

ReadOnlyMemory<float>

Methods

WithInks(ReadOnlySpan<InkColor>)

Returns this mesh with a colour given as inks for each vertex: an ink canvas blends their tints across each triangle (an ink a vertex does not name counts as 0 there); other canvases use the appearances in sRGB, which become Colors.

public Mesh WithInks(ReadOnlySpan<InkColor> inks)

Parameters

inks ReadOnlySpan<InkColor>

One colour per vertex.

Returns

Mesh

The new mesh.

Exceptions

ArgumentException

The count differs from the vertices', or the mesh has values.

ArgumentNullException

A colour is null.