Textures

Texture

A texture combines the functionality of material, texture, and image, in one. Textures can be linked to files on the local hard drive, or hold the information in RAM.

new Texture( data[, uuid] )

Creates a new Texture

Arguments:
  • data: TextureData
    • path: string (Optional)
    • name: string (Optional)
    • folder: string (Optional)
    • namespace: string (Optional)
    • id: string (Optional)
    • particle: boolean (Optional)
    • visible: boolean (Optional)
    • mode: string (Optional)
    • saved: boolean (Optional)
    • keep_size: boolean (Optional)
    • source: string (Optional)
    • width: number (Optional)
    • height: number (Optional)
    • standalone: boolean (Optional)
  • uuid: string (Optional)
PropertyTypeDescription
frameCountundefined or number
display_heightnumber
rationumber
pathstring
namestring
folderstringRelative path to the file's directory, used by some formats such as Java Block/Item
namespacestring
idstringTexture ID or key, used by some formats. By default this is a number that increases with every texture that is added
particlebooleanWhether the texture is used for the models particle system. Used by some formats such as Java Block/Item
render_modestring
render_sidesstring
frame_timenumberTexture animation frame time
frame_order_type"backwards" or "custom" or "loop" or "back_and_forth"
frame_orderstringCustom frame order
frame_interpolatebooleanInterpolate between frames
sourcestringHTML-style source of the texture's displayed data. Can be a path (desktop app only), or a base64 data URL
selectedboolean
show_iconboolean
errornumber
visiblebooleanWhether the texture is visible. Used for layered textures mode
widthnumber
heightnumber
uv_widthnumber
uv_heightnumber
currentFramenumber
savedboolean
mode"link" or "bitmap"Whether the latest version of the texture is currently loaded from and linked to a file on disk, or held in memory as bitmap data
internalbooleanIf true, the texture is loaded internally. If false, the texture is loaded directly from a file
uuidstring
selectionIntMatrixTexture selection in paint mode
layersArray of TextureLayer
layers_enabledboolean
sync_to_projectstringThe UUID of the project to sync the texture to
canvasHTMLCanvasElementThe texture's associated canvas. Since 4.9, this is the main source of truth for textures in internal mode.
ctxCanvasRenderingContext2DThe 2D context of the texture's associated canvas.
imgHTMLImageElementTexture image element
relative_pathstring
menuMenu

getErrorMessage()

Returns: string

extend( data )

Arguments:
  • data: TextureData
    • path: string (Optional)
    • name: string (Optional)
    • folder: string (Optional)
    • namespace: string (Optional)
    • id: string (Optional)
    • particle: boolean (Optional)
    • visible: boolean (Optional)
    • mode: string (Optional)
    • saved: boolean (Optional)
    • keep_size: boolean (Optional)
    • source: string (Optional)
    • width: number (Optional)
    • height: number (Optional)
    • standalone: boolean (Optional)

Returns: Texture

getUVWidth()

Get the UV width of the texture if the format uses per texture UV size, otherwise get the project texture width

Returns: number

getUVHeight()

Get the UV height of the texture if the format uses per texture UV size, otherwise get the project texture height

Returns: number

getUndoCopy( [bitmap] )

Arguments:
  • bitmap: boolean (Optional)

Returns: any

getUndoCopy()

Returns: Texture

getSaveCopy( [bitmap] )

Arguments:
  • bitmap: boolean (Optional)

Returns: any

startWatcher()

Start listening for changes to the linked file. Desktop only

stopWatcher()

Stop listening for changes to the linked file. Desktop only

generateFolder()

Generate the Java Block/Item folder property from the file path

load( [cb] )

Loads the texture from it's current source

Arguments:
  • cb: See types (Optional) - Callback function

Returns: Texture

Arguments:
  • link: string
  • path_array: Array of string

Returns: Texture

fromFile( file )

Arguments:

Returns: Texture

fromPath( path )

Arguments:
  • path: string

Returns: Texture

fromDataURL( data_url )

Arguments:
  • data_url: string

Returns: Texture

fromDefaultPack()

Returns: undefined or true

loadEmpty( [error_id] )

Loads the default white error texture

Arguments:
  • error_id: number (Optional) - Sets the error ID of the texture

Returns: Texture

updateSource( dataUrl )

Arguments:
  • dataUrl: string

Returns: Texture

updateMaterial()

Returns: Texture

reopen( force )

Opens a dialog to replace the texture with another file

Arguments:
  • force: boolean - If true, no warning appears of the texture has unsaved changes

reloadTexture()

Reloads the texture. Only works in the desktop app

getMaterial()

Returns: MeshLambertMaterial

select( [event] )

Arguments:
  • event: Event (Optional)

Returns: Texture

add( [undo] )

Adds texture to the textures list and initializes it

Arguments:
  • undo: boolean (Optional) - If true, an undo point is created

Returns: Texture

remove( [no_update] )

Removes the texture

Arguments:
  • no_update: boolean (Optional) - If true, the texture is silently removed. The interface is not updated, no undo point is created

toggleVisibility()

Returns: Texture

enableParticle()

Returns: Texture

fillParticle()

Enables 'particle' on this texture if it is not enabled on any other texture

Returns: Texture

apply( all )

Applies the texture to the selected elements

Arguments:
  • all: boolean or "blank" - If true, the texture is applied to all faces of the elements. If 'blank', the texture is only applied to blank faces

Returns: Texture

openFolder()

Shows the texture file in the file explorer

Returns: Texture

openEditor()

Opens the texture in the configured image editor

Returns: Texture

showContextMenu( event )

Arguments:

openMenu()

resizeDialog()

Returns: Texture

scrollTo()

Scroll the texture list to this texture

save( as )

Arguments:
  • as: any

Returns: Texture

getBase64()

Returns the content of the texture as PNG as a base64 encoded string

Returns: string

getDataURL()

Returns the content of the texture as PNG as a base64 encoded data URL

Returns: string

edit( callback, options )

Wrapper to do edits to the texture.

Arguments:
  • callback: See types -
  • options: TextureEditOptions - Editing options
    • method: "canvas" or "jimp" (Optional) - Edit method. 'canvas' is default
    • edit_name: string (Optional) - Name of the undo entry that is created
    • use_cache: boolean (Optional) - Whether to use the cached canvas/jimp instance
    • no_undo: boolean (Optional) - If true, no undo point is created. Default is false
    • no_update: boolean (Optional) - If true, the texture is not updated visually
    • no_undo_init: boolean (Optional)
    • no_undo_finish: boolean (Optional)

getActiveLayer()

Get the selected layer. If no layer is selected, returns the bottom layer

Returns: TextureLayer

activateLayers( [undo] )

Arguments:
  • undo: boolean (Optional)

selectionToLayer( [undo, clone] )

Turns the texture selection into a layer

Arguments:
  • undo: boolean (Optional) - Whether to create an undo entry
  • clone: boolean (Optional) - When true, the selection is copied into the new layer and also left on the original layer

Returns: string

getMCMetaContent()

Returns: See types

getAnimationFrameIndices()

Returns: Array of number

exportEmissionMap()

convertToInternal( [data_url] )

Arguments:
  • data_url: string (Optional)

Returns: Texture

updateLayerChanges( [update_data_url] )

Redraws the texture content from the layers

Arguments:
  • update_data_url: boolean (Optional) - If true, the texture source gets updated as well. This is slower, but is necessary at the end of an edit. During an edit, to preview changes, this can be false

updateChangesAfterEdit()

Update everything after a content edit to the texture or one of the layers. Updates the material, the layers, marks the texture as unsaved, syncs changes to other projects

updateImageFromCanvas()

Update the attached img element with the content from the texture's canvas

getActiveCanvas()

If layers are enabled, returns the active layer, otherwise returns the texture. Either way, the 'canvas', 'ctx', and 'offset' properties can be used from the returned object

Returns: TextureLayer or Texture

syncToOtherProject()

When editing the same texture in different tabs (via Edit In Blockbench option), sync changes that were made to the texture to other projects

Returns: Texture

Texture.getDefault()

Returns: Texture

all

Static Property

Type: Array of Texture

saveTextures( [lazy] )

Global Function

Saves all textures

Arguments:
  • lazy: boolean (Optional) - If true, the texture isn't saved if it doesn't have a local file to save to

loadTextureDraggable()

Global Function

Update the draggable/sortable functionality of the texture list

unselectTextures()

Global Function

Unselect all textures

IntMatrix

An Int Matrix holds an int (unsigned 8 bit) for each pixel in a matrix, via array. The override property can be used to set an override value for the entire area. This is used for texture selections.

new IntMatrix( width, height )

Creates a new IntMatrix

Arguments:
  • width: number
  • height: number
PropertyTypeDescription
widthnumber
heightnumber
arraynull or Int8Array
overridenull or booleanThe override can be set to true to indicate that the whole texture is selected, or false, which indicates that nothing is selected. Null indicates a custom selection
is_custombooleanTrue if there is a custom selection

activate()

The array does not exist by default to save memory, this activates it.

get( x, y )

Get the value at the specified pixel

Arguments:
  • x: number - X coordinate
  • y: number - Y coordinate

Returns: number or boolean

allow( x, y )

Test whether painting is allowed at a specific pixel

Arguments:
  • x: number - X coordinate
  • y: number - Y coordinate

Returns: number or boolean

getDirect( x, y )

Get the value at the specified pixel directly without override and bounds check

Arguments:
  • x: number - X coordinate
  • y: number - Y coordinate

Returns: number

getBoundingRect( respect_empty )

Return the smallest possible rectangle that contains all of the selection

Arguments:
  • respect_empty: boolean - If true, if there is no selection, the bounding box will still cover the entire area

Returns: Rectangle

hasSelection()

Checks whether a selection is present and contains selected pixels

Returns: boolean

set( x, y, value )

Set the value at a specified pixel

Arguments:
  • x: number - X coordinate
  • y: number - Y coordinate
  • value: number -

clear()

If there was a selection, whether override or not, clear it

setOverride( value )

Change override mode

Arguments:
  • value: null or boolean -

changeSize( width, height )

Change the size of the matrix. Unless using overrides, the selection gets lost.

Arguments:
  • width: number -
  • height: number -

forEachPixel( callback )

Run a method on each pixel, whether selected or not

Arguments:
  • callback: See types - Function to run per pixel

translate( offset_x, offset_y )

Shift custom selections by a specified offset

Arguments:
  • offset_x: number -
  • offset_y: number -

toBoxes()

Return the selection simplified into non-overlapping boxes. Boxes are [x, y, width, height].

Returns: Array of Array

maskCanvas( ctx, offset )

Mask the provided canvas using the selection

Arguments:

TextureAnimator

Namespace

Handles playback of animated textures

PropertyTypeDescription
isPlayingboolean
intervalany

start()

stop()

toggle()

updateSpeed()

nextFrame()

reset()

updateButton()