TextureAtlas class Assets and loading
A uniform grid texture atlas: one or more equally sized PBR maps packed as
columns x rows square tiles, with an optional gutter of padding texels
around each tile so mip sampling does not bleed across tile edges.
The atlas does the UV bookkeeping for tiled content (voxel block faces, sprite sheets, terrain tiles). Resolve a tile's atlas-space UV box with tileBounds, or map a within-tile coordinate with tileUv; a mesh writes those UVs into its texture coordinates so a single material and draw call covers every tile.
Maps follow the glTF metallic-roughness convention (baseColor, metallicRoughness with metallic in B and roughness in G, normal, occlusion); toMaterial wires them into a PhysicallyBasedMaterial.
This is a CPU-side atlas (one packed texture). Once Flutter GPU gains 2D array textures, a tile becomes an array layer and this padding/inset dance is no longer needed; see the texture-array work tracked upstream.
Constructors
- TextureAtlas({required int columns, required int rows, required int tileSize, int padding = 0, Texture2D? baseColor, Texture2D? metallicRoughness, Texture2D? normal, Texture2D? occlusion})
-
Creates an atlas of
columnsxrowstiles, eachtileSizetexels square, separated bypaddingtexels of gutter. The PBR maps are optional so the UV math can be used (and unit tested) on its own.
Properties
- baseColor → Texture2D?
-
Packed PBR maps, all sharing the same grid layout. Any may be null.
final
- columns → int
-
Tile grid dimensions.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → int
-
no setter
- metallicRoughness → Texture2D?
-
final
- normal → Texture2D?
-
final
- occlusion → Texture2D?
-
final
- padding → int
-
Gutter of (typically edge-replicated) texels around each tile, in texels.
final
- rows → int
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tileCount → int
-
Total number of tiles.
no setter
- tileSize → int
-
Edge length of a tile's content area, in texels.
final
- width → int
-
Atlas dimensions in texels (including the padding gutters).
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
tileBounds(
int index) → Vector4 -
The atlas-space UV box of tile
index's content area as(minU, minV, maxU, maxV), inset past the padding gutter so sampling stays inside the tile. Tiles are row-major with a top-left origin. -
tileUv(
int index, double u, double v) → Vector2 -
Maps a within-tile coordinate (
u,v, each in[0, 1]with (0, 0) at the tile's top-left) to an atlas UV for tileindex. -
toMaterial(
) → PhysicallyBasedMaterial - Builds a PhysicallyBasedMaterial bound to this atlas's maps. The factors are left at their identity defaults so the textures drive the result; the caller picks alpha mode, vertex-color weight, and so on.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited