-
Notifications
You must be signed in to change notification settings - Fork 8
/
textures.d.ts
412 lines (392 loc) · 11.7 KB
/
textures.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/// <reference path="./blockbench.d.ts"/>
interface TextureData {
path?: string
name?: string
folder?: string
namespace?: string
id?: string
particle?: boolean
visible?: boolean
mode?: string
saved?: boolean
keep_size?: boolean
source?: string
width?: number
height?: number
standalone?: boolean
}
interface TextureEditOptions {
/**
* Edit method. 'canvas' is default
*/
method?: 'canvas' | 'jimp'
/**
* Name of the undo entry that is created
*/
edit_name?: string
/**
* Whether to use the cached canvas/jimp instance
*/
use_cache?: boolean
/**
* If true, no undo point is created. Default is false
*/
no_undo?: boolean
/**
* If true, the texture is not updated visually
*/
no_update?: boolean
no_undo_init?: boolean
no_undo_finish?: boolean
}
/**
* 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.
*/
declare class Texture {
constructor(data: TextureData, uuid?: string)
readonly frameCount: number | undefined
readonly display_height: number
readonly ratio: number
path?: string
name: string
/** Relative path to the file's directory, used by some formats such as Java Block/Item*/
folder: string
namespace: string
/** Texture ID or key, used by some formats. By default this is a number that increases with every texture that is added */
id: string
/** Whether the texture is used for the models particle system. Used by some formats such as Java Block/Item */
particle: boolean
render_mode: 'default' | 'emissive' | 'additive' | 'layered' | string
render_sides: 'auto' | 'front' | 'double' | string
/** Texture animation frame time */
frame_time: number
frame_order_type: 'custom' | 'loop' | 'backwards' | 'back_and_forth'
/** Custom frame order */
frame_order: string
/** Interpolate between frames */
frame_interpolate: boolean
/** HTML-style source of the texture's displayed data. Can be a path (desktop app only), or a base64 data URL */
source: string
selected?: boolean
show_icon: boolean
error: number
/** Whether the texture is visible. Used for layered textures mode */
visible: boolean
width: number
height: number
uv_width: number
uv_height: number
currentFrame: number
saved: boolean
/**
* 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
* @deprecated Use texture.internal instead
*/
mode: 'link' | 'bitmap'
/**
* If true, the texture is loaded internally. If false, the texture is loaded directly from a file
*/
internal: boolean
uuid: UUID
/**
* Texture selection in paint mode
*/
selection: IntMatrix
layers: TextureLayer[]
layers_enabled: boolean
/**
* The UUID of the project to sync the texture to
*/
sync_to_project: UUID | ''
/**
* The texture's associated canvas. Since 4.9, this is the main source of truth for textures in internal mode.
*/
canvas: HTMLCanvasElement
/**
* The 2D context of the texture's associated canvas.
*/
ctx: CanvasRenderingContext2D
/**
* Texture image element
*/
img: HTMLImageElement
relative_path?: string
getErrorMessage(): string
extend(data: TextureData): this
/**
* Get the UV width of the texture if the format uses per texture UV size, otherwise get the project texture width
*/
getUVWidth(): number
/**
* Get the UV height of the texture if the format uses per texture UV size, otherwise get the project texture height
*/
getUVHeight(): number
getUndoCopy(bitmap?: boolean): any
getSaveCopy(bitmap?: boolean): any
/**
* Start listening for changes to the linked file. Desktop only
*/
startWatcher(): void
/**
* Stop listening for changes to the linked file. Desktop only
*/
stopWatcher(): void
/**
* Generate the Java Block/Item folder property from the file path
*/
generateFolder(): void
/**
* Loads the texture from it's current source
* @param cb Callback function
*/
load(cb?: () => {}): this
fromJavaLink(link: string, path_array: string[]): this
fromFile(file: { name: string; content?: string; path: string }): this
fromPath(path: string): this
fromDataURL(data_url: string): this
fromDefaultPack(): true | undefined
/**
* Loads the default white error texture
* @param error_id Sets the error ID of the texture
*/
loadEmpty(error_id?: number): this
updateSource(dataUrl: string): this
updateMaterial(): this
/**
* Opens a dialog to replace the texture with another file
* @param force If true, no warning appears of the texture has unsaved changes
*/
reopen(force: boolean): void
/**
* Reloads the texture. Only works in the desktop app
*/
reloadTexture(): void
getMaterial(): THREE.MeshLambertMaterial
select(event?: Event): this
/**
* Adds texture to the textures list and initializes it
* @param undo If true, an undo point is created
*/
add(undo?: boolean): Texture
/**
* Removes the texture
* @param no_update If true, the texture is silently removed. The interface is not updated, no undo point is created
*/
remove(no_update?: boolean): void
toggleVisibility(): this
enableParticle(): this
/**
* Enables 'particle' on this texture if it is not enabled on any other texture
*/
fillParticle(): this
/**
* Applies the texture to the selected elements
* @param all If true, the texture is applied to all faces of the elements. If 'blank', the texture is only applied to blank faces
*/
apply(all: true | false | 'blank'): this
/**
* Shows the texture file in the file explorer
*/
openFolder(): this
/**
* Opens the texture in the configured image editor
*/
openEditor(): this
showContextMenu(event: MouseEvent): void
openMenu(): void
resizeDialog(): this
/**
* Scroll the texture list to this texture
*/
scrollTo(): void
save(as: any): this
/**
* Returns the content of the texture as PNG as a base64 encoded string
*/
getBase64(): string
/**
* Returns the content of the texture as PNG as a base64 encoded data URL
*/
getDataURL(): string
/**
* Wrapper to do edits to the texture.
* @param callback
* @param options Editing options
*/
edit(
callback: (instance: HTMLCanvasElement | any) => void | HTMLCanvasElement,
options: TextureEditOptions
): void
menu: Menu
/**
* Get the selected layer. If no layer is selected, returns the bottom layer
*/
getActiveLayer(): TextureLayer
activateLayers(undo?: boolean): void
/**
* Turns the texture selection into a layer
* @param undo Whether to create an undo entry
* @param clone When true, the selection is copied into the new layer and also left on the original layer
*/
selectionToLayer(undo?: boolean, clone?: boolean): void
javaTextureLink(): string
getMCMetaContent(): {
animation?: {
frametime: number
width?: number
height?: number
interpolate?: boolean
frames?: number[]
}
}
getAnimationFrameIndices(): number[]
exportEmissionMap(): void
convertToInternal(data_url?: string): this
/**
* Redraws the texture content from the layers
* @param update_data_url 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
*/
updateLayerChanges(update_data_url?: boolean): void
/**
* 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
*/
updateChangesAfterEdit(): void
/**
* Update the attached img element with the content from the texture's canvas
*/
updateImageFromCanvas(): void
/**
* 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
*/
getActiveCanvas(): Texture | TextureLayer
/**
* When editing the same texture in different tabs (via Edit In Blockbench option), sync changes that were made to the texture to other projects
*/
syncToOtherProject(): this
getUndoCopy(): Texture
static all: Texture[]
static getDefault(): Texture
}
/**
* Saves all textures
* @param lazy If true, the texture isn't saved if it doesn't have a local file to save to
*/
declare function saveTextures(lazy?: boolean): void
/**
* Update the draggable/sortable functionality of the texture list
*/
declare function loadTextureDraggable(): void
/**
* Unselect all textures
*/
declare function unselectTextures(): void
/**
* 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.
*/
declare class IntMatrix {
constructor(width: number, height: number)
width: number
height: number
array: null | Int8Array
/**
* 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
*/
override: boolean | null
/**
* True if there is a custom selection
*/
readonly is_custom: boolean
/**
* The array does not exist by default to save memory, this activates it.
*/
activate(): void
/**
* Get the value at the specified pixel
* @param x X coordinate
* @param y Y coordinate
* @returns The value of the targeted pixel
*/
get(x: number, y: number): number | boolean
/**
* Test whether painting is allowed at a specific pixel
* @param x X coordinate
* @param y Y coordinate
* @returns Boolean or value of the pixel
*/
allow(x: number, y: number): number | boolean
/**
* Get the value at the specified pixel directly without override and bounds check
* @param x X coordinate
* @param y Y coordinate
* @returns
*/
getDirect(x: number, y: number): number
/**
* Return the smallest possible rectangle that contains all of the selection
* @param respect_empty If true, if there is no selection, the bounding box will still cover the entire area
*/
getBoundingRect(respect_empty: boolean): Rectangle
/**
* Checks whether a selection is present and contains selected pixels
*/
hasSelection(): boolean
/**
* Set the value at a specified pixel
* @param {*} x X coordinate
* @param {*} y Y coordinate
* @param {number} value
*/
set(x: number, y: number, value: number): void
/**
* If there was a selection, whether override or not, clear it
*/
clear(): void
/**
* Change override mode
* @param {true|false|null} value
* @returns
*/
setOverride(value: boolean | null): void
/**
* Change the size of the matrix. Unless using overrides, the selection gets lost.
* @param {number} width
* @param {number} height
* @returns {boolean} Whether the size had to be changed
*/
changeSize(width: number, height: number): void
/**
* Run a method on each pixel, whether selected or not
* @param callback Function to run per pixel
*/
forEachPixel(callback: (x: number, y: number, value: number, index: number) => void): void
/**
* Shift custom selections by a specified offset
* @param offset_x
* @param offset_y
*/
translate(offset_x: number, offset_y: number): void
/**
* Return the selection simplified into non-overlapping boxes. Boxes are [x, y, width, height].
*/
toBoxes(): [number, number, number, number][]
/**
* Mask the provided canvas using the selection
* @param ctx Canvas 2D context
* @param offset Position offset of the canvas, e. g. when using a layer
*/
maskCanvas(ctx: CanvasRenderingContext2D, offset: ArrayVector2): void
}
/**
* Handles playback of animated textures
*/
declare namespace TextureAnimator {
const isPlaying: boolean
const interval: any
function start(): void
function stop(): void
function toggle(): void
function updateSpeed(): void
function nextFrame(): void
function reset(): void
function updateButton(): void
}