Skip to content

StackDepth

Namespace Nfty.Model in assembly Nfty.Model.

public static class StackDepth

The stack rule, in one place: a layered picture is risen as ONE solid, never as stacked slabs (slabs z-fight wherever two layers cover a pixel). The geometry is the UNION of every solid layer's column; each of the two faces takes its color from the layer that owns it.

Remarks

Per pixel, over the layers solid there: front = the max of their fronts, back = the max of their backs (a layer with no map is paper, 0/0). The front face belongs to the topmost layer reaching the max front, the back face to the topmost layer reaching the max back; ties go to the upper layer. Where an owner is the topmost solid layer its color is the composite's own pixel. Every layer pixel must be fully opaque or fully clear — StackDepth.Combine() enforces the same one-solid-test rule Riser enforces on a single picture, across the stack: a partially transparent pixel in any layer throws PartialAlphaException naming that layer, before compositing.

Methods

Combine(IReadOnlyList<(Image<Rgba32>, DepthMap?)>, string, Image<Rgba32>?)

public static StackRise Combine(IReadOnlyList<(Image<Rgba32>, DepthMap?)> bottomFirst, string source = "the stack", Image<Rgba32>? finished = null);

Composites a stack and combines its depth and face owners by the union rule.

Parameters

  • bottomFirst (IReadOnlyList<(Image<Rgba32>, DepthMap?)>) - The layers in paint order (index 0 paints first, sits furthest back), each with its own depth map or null for paper. All the same size. Not taken.
  • source (string) - How to name the stack in a refusal, e.g. the Chest recipe.
  • finished (Image<Rgba32>?) - The finished picture, when there is one (a cooked asset); its pixels become StackRise.Art and the topmost owners' colors. Not taken.

Returns. The rise; the caller owns and disposes it.

Exceptions

  • ArgumentException - The stack is empty, a layer, map or the finished picture is another size, or the finished picture's solid pixels disagree with the layers'.
  • PartialAlphaException - Some layer has a partly transparent pixel.

CombineInto(StackRise, IReadOnlyList<(Image<Rgba32>, Func<int, int, DepthPixel>?)>, Rectangle)

public static void CombineInto(StackRise rise, IReadOnlyList<(Image<Rgba32>, Func<int, int, DepthPixel>?)> bottomFirst, Rectangle dirty);

Recombines only a rectangle of an existing rise, in place, after the layers' DEPTH changed there. It runs the same per-pixel rule StackDepth.Combine() runs, so the result is byte-equal to a whole combine of the same layers.

Parameters

  • rise (StackRise) - The rise to update: its depth, owners and faces change inside the rectangle. Single-threaded: nothing may read it while this runs.
  • bottomFirst (IReadOnlyList<(Image<Rgba32>, Func<int, int, DepthPixel>?)>) - The layers in paint order, the same ones (same pictures) the rise was combined from, each with a reader of its CURRENT depth or null for paper.
  • dirty (Rectangle) - The pixels whose depth changed in any layer; clipped to the picture.

Exceptions

  • ArgumentException - A layer is another size than the rise.

Remarks

Only depth may have changed: the layers' pixels are what the rise's art and faces were built from, and are not rescanned.

ForAsset(LoadedRecipe, GeneratedAsset, string)

public static StackRise? ForAsset(LoadedRecipe recipe, GeneratedAsset asset, string source = "the asset");

The union rise of one generated asset.

Parameters

  • recipe (LoadedRecipe) - The recipe the asset was rolled from.
  • asset (GeneratedAsset) - The asset; its traits are its present layers, in paint order, and its color rolls recolorize them.
  • source (string) - How to name the asset in a refusal.

Returns. The rise, or null for an all-absent roll (nothing painted: paper).

Exceptions

  • KeyNotFoundException - A trait names a layer or variant the recipe lacks.
  • PartialAlphaException - Some layer has a partly transparent pixel.

ForSelection(LoadedRecipe, IReadOnlyList<StackPick>, string, Image<Rgba32>?)

public static StackRise ForSelection(LoadedRecipe recipe, IReadOnlyList<StackPick> presentBottomFirst, string source = "the selection", Image<Rgba32>? finished = null);

The union rise of one rolled selection of a recipe.

Parameters

  • recipe (LoadedRecipe) - The recipe the selection was rolled from.
  • presentBottomFirst (IReadOnlyList<StackPick>) - The present layers in paint order, each with the color it rolled or null. An absent layer is simply not listed.
  • source (string) - How to name the selection in a refusal.
  • finished (Image<Rgba32>?) - The finished picture, when there is one.

Returns. The rise; the caller disposes it.

Exceptions

  • KeyNotFoundException - A named layer or variant is not in the recipe.
  • PartialAlphaException - Some layer has a partly transparent pixel.

Remarks

A pick with a color, on a colorized layer, is recolorized exactly as generation did (VariantPreview); a pick with none, or a Custom layer, uses the stored pixels. An all-absent roll has no layers — callers treat it as paper and do not call this.