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
: TextureDatapath
: 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)
Property | Type | Description |
---|---|---|
frameCount | undefined or number | |
display_height | number | |
ratio | number | |
path | string | |
name | string | |
folder | string | Relative path to the file's directory, used by some formats such as Java Block/Item |
namespace | string | |
id | string | Texture ID or key, used by some formats. By default this is a number that increases with every texture that is added |
particle | boolean | Whether the texture is used for the models particle system. Used by some formats such as Java Block/Item |
render_mode | string | |
render_sides | string | |
frame_time | number | Texture animation frame time |
frame_order_type | "backwards" or "custom" or "loop" or "back_and_forth" | |
frame_order | string | Custom frame order |
frame_interpolate | boolean | Interpolate between frames |
source | string | HTML-style source of the texture's displayed data. Can be a path (desktop app only), or a base64 data URL |
selected | boolean | |
show_icon | boolean | |
error | number | |
visible | boolean | Whether the texture is visible. Used for layered textures mode |
width | number | |
height | number | |
uv_width | number | |
uv_height | number | |
currentFrame | number | |
saved | boolean | |
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 |
internal | boolean | If true, the texture is loaded internally. If false, the texture is loaded directly from a file |
uuid | string | |
selection | IntMatrix | Texture selection in paint mode |
layers | Array of TextureLayer | |
layers_enabled | boolean | |
sync_to_project | string | The UUID of the project to sync the texture to |
canvas | HTMLCanvasElement | The texture's associated canvas. Since 4.9, this is the main source of truth for textures in internal mode. |
ctx | CanvasRenderingContext2D | The 2D context of the texture's associated canvas. |
img | HTMLImageElement | Texture image element |
relative_path | string | |
menu | Menu |
getErrorMessage()
Returns: string
extend( data )
Arguments:
data
: TextureDatapath
: 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
fromJavaLink( link, path_array )
Arguments:
link
: stringpath_array
: Array of string
Returns: Texture
fromFile( file )
Arguments:
file
: See types
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:
event
: MouseEvent
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 optionsmethod
:"canvas"
or"jimp"
(Optional) - Edit method. 'canvas' is defaultedit_name
: string (Optional) - Name of the undo entry that is createduse_cache
: boolean (Optional) - Whether to use the cached canvas/jimp instanceno_undo
: boolean (Optional) - If true, no undo point is created. Default is falseno_update
: boolean (Optional) - If true, the texture is not updated visuallyno_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 entryclone
: boolean (Optional) - When true, the selection is copied into the new layer and also left on the original layer
javaTextureLink()
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
: numberheight
: number
Property | Type | Description |
---|---|---|
width | number | |
height | number | |
array | null or Int8Array | |
override | null or boolean | The 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_custom | boolean | True 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 coordinatey
: number - Y coordinate
Returns: number or boolean
allow( x, y )
Test whether painting is allowed at a specific pixel
Arguments:
x
: number - X coordinatey
: 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 coordinatey
: 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 coordinatey
: number - Y coordinatevalue
: 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:
ctx
: CanvasRenderingContext2D - Canvas 2D contextoffset
: ArrayVector2 - Position offset of the canvas, e. g. when using a layer
TextureAnimator
Namespace
Handles playback of animated textures
Property | Type | Description |
---|---|---|
isPlaying | boolean | |
interval | any |