Skip to main content

Class: AtlasTexture

A texture atlas is a collection of textures that are packed into a single texture. This is useful for reducing the number of draw calls required to render a scene, since all block textures can be rendered with a single draw call.

By default, the texture atlas creates an additional border around each texture to prevent texture bleeding.

Texture bleeding

Hierarchy​

  • CanvasTexture

    ↳ AtlasTexture

Constructors​

constructor​

• new AtlasTexture(countPerSide?, dimension?, canvas?, filtering?): AtlasTexture

Create a new texture this.

Parameters​

NameTypeDefault value
countPerSidenumber1
dimensionnumber1
canvasHTMLCanvasElementundefined
filteringAtlasFilteringMode"nearest"

Returns​

AtlasTexture

The texture atlas generated.

Overrides​

CanvasTexture.constructor

Properties​

animationClock​

• animationClock: () => number

Seconds the animated faces read their frame from. The world points it at its shared shader clock, so every client shows the same frame of the same water at the same moment; on its own it runs on local time.

Type declaration​

▸ (): number

Returns​

number


animations​

• animations: { animation: FaceAnimation ; drawnFrame: number ; durationsMs: number[] ; patch: AtlasAnimationPatch ; timer: null }[] = []

The list of block animations that are being used by this texture atlas.


atlasMargin​

• atlasMargin: number = 0

The margin between each block texture in the this.


atlasOffset​

• atlasOffset: number = 0

The offset of each block's texture to the end of its border.


atlasRatio​

• atlasRatio: number = 0

The ratio of the texture on the atlas to the original texture.


canvas​

• canvas: HTMLCanvasElement

The canvas that is used to generate the texture this.


countPerSide​

• countPerSide: number

The number of textures per side of the texture atlas


dimension​

• dimension: number

Since the texture atlas is a square, the dimension is the length of one side.

Methods​

applyFiltering​

▸ applyFiltering(mode): void

Switches how this atlas samples at glancing angles. Safe to call on a live atlas already bound to chunk materials (sets needsUpdate so the next upload carries the new filter/mip settings) — an A/B run can flip this without rebuilding the world. See WorldOptions.blockTextureFiltering.

Parameters​

NameType
modeAtlasFilteringMode

Returns​

void


copy​

▸ copy(source): this

Carries the atlas geometry so clone() yields a faithful atlas view sharing the source's pixels, with independently settable repeat/offset (how the held torch windows its flame strip). Animations deliberately do not transfer: their timers drive the source's own offsets, and a clone inheriting them would be fought over by two drivers.

Parameters​

NameType
sourcethis

Returns​

this

Overrides​

CanvasTexture.copy


drawImageToRange​

▸ drawImageToRange(range, image, clearRect?, opacity?): void

Draw a texture to a range on the texture atlas.

Parameters​

NameTypeDefault valueDescription
rangeUVundefinedThe range on the texture atlas to draw the texture to.
imageColor | Texture<unknown> | HTMLCanvasElement | HTMLImageElement | (width?: number, height?: number) => HTMLImageElementundefinedThe texture to draw to the range.
clearRectbooleantrue-
opacitynumber1.0-

Returns​

void


fillRangeAsFallback​

▸ fillRangeAsFallback(range, color): void

Paint range with a stand-in colour and remember that it is one, so a later census still lists the slot as unpainted by its own art.

Parameters​

NameType
rangeUV
colorColor

Returns​

void


flushAnimationPatches​

▸ flushAnimationPatches(renderer): void

Parameters​

NameType
rendererWebGLRenderer

Returns​

void


isRangeFallback​

▸ isRangeFallback(range): boolean

Whether range wears a fallback fill instead of its own texture.

Parameters​

NameType
rangeUV

Returns​

boolean


isRangePainted​

▸ isRangePainted(range): boolean

Whether anything has been drawn into range since the atlas was built.

Parameters​

NameType
rangeUV

Returns​

boolean


makeUnknownImage​

▸ makeUnknownImage(dimension, color1?, color2?): HTMLCanvasElement

Parameters​

NameTypeDefault value
dimensionnumberundefined
color1string"#FF00FF"
color2string"#000000"

Returns​

HTMLCanvasElement


makeUnknownTexture​

▸ makeUnknownTexture(dimension): AtlasTexture

The magenta-and-black checker every surface with no texture yet is given. One instance serves all of them, so treat it as read-only: painting into it or disposing it reaches every one of those surfaces at once.

Parameters​

NameType
dimensionnumber

Returns​

AtlasTexture


paintColor​

▸ paintColor(color): void

Paints the entire canvas with a specified color using Three.js Color.

Parameters​

NameTypeDescription
colorColorA Three.js Color instance to use for painting.

Returns​

void


rangeTexelClasses​

▸ rangeTexelClasses(range, cuts): TexelClasses

Whether range holds solid or translucent texels (see classifyTexels): its painted pixels, every keyframe of an animation playing there, or the opaque unknown checker while nothing is painted.

Parameters​

NameType
rangeUV
cutsTexelAlphaCuts

Returns​

TexelClasses


readRangePixels​

▸ readRangePixels(range): Uint8ClampedArray<ArrayBufferLike>

The RGBA8 pixels painted inside range (its texture, without the margin around it), or null while nothing has been painted there. One small read of the atlas canvas.

Parameters​

NameType
rangeUV

Returns​

Uint8ClampedArray<ArrayBufferLike>


registerAnimation​

▸ registerAnimation(range, keyframes, fadeFrames?): void

Parameters​

NameTypeDefault value
rangeUVundefined
keyframes[number, Color | HTMLImageElement][]undefined
fadeFramesnumber0

Returns​

void


tickAnimations​

▸ tickAnimations(seconds?): void

Draws whichever animated faces changed frame since the last call, read off animationClock. Called once a frame by the world; a face whose frame has not changed costs a lookup and nothing else.

Parameters​

NameType
secondsnumber

Returns​

void