Table of Contents

Interface ITextureAtlasAPI

Namespace
Vintagestory.API.Client
Assembly
VintagestoryAPI.dll

Entity texture Atlas.

public interface ITextureAtlasAPI

Properties

AtlasTextures

Returns the list of currently loaded texture atlas ids

List<LoadedTexture> AtlasTextures { get; }

Property Value

List<LoadedTexture>

this[AssetLocation]

TextureAtlasPosition this[AssetLocation textureLocation] { get; }

Parameters

textureLocation AssetLocation

Property Value

TextureAtlasPosition

Positions

Returns the default texture atlas position for all blocks, referenced by the texturesubid

TextureAtlasPosition[] Positions { get; }

Property Value

TextureAtlasPosition[]

Size

Size of one block texture atlas

Size2i Size { get; }

Property Value

Size2i

SubPixelPaddingX

As configured in the clientsettings.json divided by the texture atlas size

float SubPixelPaddingX { get; }

Property Value

float

SubPixelPaddingY

float SubPixelPaddingY { get; }

Property Value

float

UnknownTexturePosition

The texture atlas position of the "unknown.png" texture

TextureAtlasPosition UnknownTexturePosition { get; }

Property Value

TextureAtlasPosition

Methods

AllocateTextureSpace(int, int, out int, out TextureAtlasPosition)

Reserves a spot on the texture atlas. Returns true if allocation was successful. Can be used to render onto it through the Render API

bool AllocateTextureSpace(int width, int height, out int textureSubId, out TextureAtlasPosition texPos)

Parameters

width int
height int
textureSubId int
texPos TextureAtlasPosition

Returns

bool

FreeTextureSpace(int)

Deallocates a previously allocated texture space

void FreeTextureSpace(int textureSubId)

Parameters

textureSubId int

GetAverageColor(int)

Returns you an average rgba value picked inside the texture subid

int GetAverageColor(int textureSubId)

Parameters

textureSubId int

Returns

int

GetOrInsertTexture(AssetLocation, out int, out TextureAtlasPosition, CreateTextureDelegate, float)

Same as InsertTexture(IBitmap, out int, out TextureAtlasPosition, float) but this method remembers the inserted texure, which you can access using capi.TextureAtlas[path] A subsequent call to this method will update the texture, but retain the same texPos. Also a run-time texture reload will reload this texture automatically.

bool GetOrInsertTexture(AssetLocation path, out int textureSubId, out TextureAtlasPosition texPos, CreateTextureDelegate onCreate = null, float alphaTest = 0)

Parameters

path AssetLocation

Used as reference for caching

textureSubId int
texPos TextureAtlasPosition
onCreate CreateTextureDelegate

The method that should load the bitmap, if required. Can be left null to simply attempt to load the bmp from path using method LoadCompositeBitmap(AssetLocation)

alphaTest float

Returns

bool

False if the file was not found or the insert failed

GetRandomColor(int)

Returns an rgba value picked randomly inside the given texture (defined by its sub-id)

int GetRandomColor(int textureSubId)

Parameters

textureSubId int

Returns

int

GetRandomColor(int, int)

Returns one of 30 random rgba values inside the given texture (defined by its sub-id)

int GetRandomColor(int textureSubId, int rndIndex)

Parameters

textureSubId int
rndIndex int

0..29 for a specific random pixel, or -1 to randomize, which is the same as calling GetRandomColor without the rndIndex argument

Returns

int

GetRandomColor(TextureAtlasPosition, int)

Returns one of 30 random rgba values inside the given texture (defined by its sub-id)

int GetRandomColor(TextureAtlasPosition texPos, int rndIndex)

Parameters

texPos TextureAtlasPosition
rndIndex int

0..29 for a specific random pixel, or -1 to randomize, which is the same as calling GetRandomColor without the rndIndex argument

Returns

int

GetRandomColors(TextureAtlasPosition)

Get the random colors array for the specified TextureAtlasPosition, creating it if necessary

int[] GetRandomColors(TextureAtlasPosition texPos)

Parameters

texPos TextureAtlasPosition

Returns

int[]

InsertTexture(byte[], out int, out TextureAtlasPosition, float)

Inserts a texture into the texture atlas after the atlas has been generated. Updates the in-ram texture atlas as well as the in-gpu-ram texture atlas. The textureSubId can be used to find the TextureAtlasPosition again in case you loose it ;-)

bool InsertTexture(byte[] pngBytes, out int textureSubId, out TextureAtlasPosition texPos, float alphaTest = 0)

Parameters

pngBytes byte[]
textureSubId int
texPos TextureAtlasPosition
alphaTest float

Returns

bool

InsertTexture(IBitmap, out int, out TextureAtlasPosition, float)

Inserts a texture into the texture atlas after the atlas has been generated. Updates the in-ram texture atlas as well as the in-gpu-ram texture atlas. The textureSubId can be used to find the TextureAtlasPosition again in case you loose it ;-)

bool InsertTexture(IBitmap bmp, out int textureSubId, out TextureAtlasPosition texPos, float alphaTest = 0)

Parameters

bmp IBitmap
textureSubId int
texPos TextureAtlasPosition
alphaTest float

Returns

bool

InsertTextureCached(CompositeTexture, out int, out TextureAtlasPosition, float)

[Obsolete("Use GetOrInsertTexture() instead. It's more efficient to load the bmp only if the texture was not found in the cache")]
bool InsertTextureCached(CompositeTexture texture, out int textureSubId, out TextureAtlasPosition texPos, float alphaTest = 0)

Parameters

texture CompositeTexture
textureSubId int
texPos TextureAtlasPosition
alphaTest float

Returns

bool

InsertTextureCached(AssetLocation, byte[], out int, out TextureAtlasPosition, float)

Same as InsertTexture(IBitmap, out int, out TextureAtlasPosition, float) but this method remembers the inserted texure, which you can access using capi.TextureAtlas[path] A subsequent call to this method will update the texture, but retain the same texPos. Also a run-time texture reload will reload this texture automatically.

bool InsertTextureCached(AssetLocation path, byte[] pngBytes, out int textureSubId, out TextureAtlasPosition texPos, float alphaTest = 0)

Parameters

path AssetLocation
pngBytes byte[]
textureSubId int
texPos TextureAtlasPosition
alphaTest float

Returns

bool

InsertTextureCached(AssetLocation, IBitmap, out int, out TextureAtlasPosition, float)

Same as InsertTexture(IBitmap, out int, out TextureAtlasPosition, float) but this method remembers the inserted texure, which you can access using capi.TextureAtlas[path] A subsequent call to this method will update the texture, but retain the same texPos. Also a run-time texture reload will reload this texture automatically.

[Obsolete("Use GetOrInsertTexture() instead. It's more efficient to load the bmp only if the texture was not found in the cache")]
bool InsertTextureCached(AssetLocation path, IBitmap bmp, out int textureSubId, out TextureAtlasPosition texPos, float alphaTest = 0)

Parameters

path AssetLocation
bmp IBitmap
textureSubId int
texPos TextureAtlasPosition
alphaTest float

Returns

bool

LoadCompositeBitmap(AssetLocation)

Loads a bitmap from given asset. Can use ++ syntax for texture overlay and @[int] for texture rotation

IBitmap LoadCompositeBitmap(AssetLocation path)

Parameters

path AssetLocation

Returns

IBitmap

RegenMipMaps(int)

Regenerates the mipmaps for one of the atlas textures, given by its array index

void RegenMipMaps(int atlasIndex)

Parameters

atlasIndex int

RenderTextureIntoAtlas(int, LoadedTexture, float, float, float, float, float, float, float)

Renders given texture into the texture atlas at given location

void RenderTextureIntoAtlas(int intoAtlasTextureId, LoadedTexture fromTexture, float sourceX, float sourceY, float sourceWidth, float sourceHeight, float targetX, float targetY, float alphaTest = 0.005)

Parameters

intoAtlasTextureId int
fromTexture LoadedTexture
sourceX float
sourceY float
sourceWidth float
sourceHeight float
targetX float
targetY float
alphaTest float