blockbench-types 4.4.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+
2
+
3
+ declare class Deletable {
4
+ delete: () => void
5
+ }
6
+ type UUID = string
7
+
8
+ /**
9
+ * True if Blockbench runs as a native app
10
+ */
11
+ declare const isApp: boolean
12
+
13
+ type EventName = 'remove_animation'
14
+ | 'display_animation_frame'
15
+ | 'before_closing'
16
+ | 'create_session'
17
+ | 'join_session'
18
+ | 'quit_session'
19
+ | 'send_session_data'
20
+ | 'receive_session_data'
21
+ | 'user_joins_session'
22
+ | 'user_leaves_session'
23
+ | 'process_chat_message'
24
+ | 'update_settings'
25
+ | 'update_project_settings'
26
+ | 'save_project'
27
+ | 'load_project'
28
+ | 'new_project'
29
+ | 'reset_project'
30
+ | 'close_project'
31
+ | 'saved_state_changed'
32
+ | 'add_cube'
33
+ | 'add_mesh'
34
+ | 'add_group'
35
+ | 'add_texture_mesh'
36
+ | 'group_elements'
37
+ | 'update_selection'
38
+ | 'update_keyframe_selection'
39
+ | 'select_all'
40
+ | 'added_to_selection'
41
+ | 'invert_selection'
42
+ | 'canvas_select'
43
+ | 'canvas_click'
44
+ | 'change_texture_path'
45
+ | 'add_texture'
46
+ | 'finish_edit'
47
+ | 'finished_edit'
48
+ | 'undo'
49
+ | 'redo'
50
+ | 'load_undo_save'
51
+ | 'change_color'
52
+ | 'select_mode'
53
+ | 'unselect_mode'
54
+ | 'change_active_panel'
55
+ | 'resize_window'
56
+ | 'press_key'
57
+ | 'select_format'
58
+ | 'convert_format'
59
+ | 'construct_format'
60
+ | 'delete_format'
61
+ | 'select_project'
62
+ | 'unselect_project'
63
+ | 'setup_project'
64
+ | 'update_project_resolution'
65
+ | 'merge_project'
66
+ | 'update_view'
67
+ | 'update_camera_position'
68
+ | 'render_frame'
69
+ | 'construct_model_loader'
70
+ | 'delete_model_loader'
71
+ | 'update_recent_project_data'
72
+ | 'update_recent_project_thumbnail'
73
+ | 'load_from_recent_project_data'
74
+ | 'edit_animation_properties'
75
+ | 'select_preview_scene'
76
+ | 'unselect_preview_scene'
77
+
78
+ type IconString = string;
79
+
80
+ interface MessageBoxOptions {
81
+ /**
82
+ * Index of the confirm button within the buttons array
83
+ */
84
+ confirm: number
85
+ /**
86
+ * Index of the cancel button within the buttons array
87
+ */
88
+ cancel: number
89
+ buttons: string[]
90
+ translateKey?: string
91
+ title?: string
92
+ message?: string
93
+ icon?: string
94
+ width: number
95
+ /**
96
+ * Display a list of actions to do in the dialog. When clicked, the message box closes with the string ID of the command as first argument.
97
+ */
98
+ commands?: {
99
+ [id: string]: string | {text: string}
100
+ }
101
+ }
102
+
103
+
104
+
105
+ interface PropertyOptions {
106
+ default?: any
107
+ condition?: any
108
+ exposed?: boolean
109
+ label?: string
110
+ /**
111
+ * Options used for select types
112
+ */
113
+ options?: object
114
+ merge?: (instance: any, data: object) => void
115
+ reset?: (instance: any) => void
116
+ merge_validation?: (value: any) => boolean
117
+ }
118
+ /**
119
+ * Creates a new property on the specified target class
120
+ */
121
+ declare class Property extends Deletable {
122
+ constructor(target_class: any, type: string, name: string, options?: PropertyOptions);
123
+ class: any;
124
+ name: string;
125
+ type: string;
126
+ default: any;
127
+
128
+ isString: boolean;
129
+ isMolang: boolean;
130
+ isNumber: boolean;
131
+ isBoolean: boolean;
132
+ isArray: boolean;
133
+ isVector: boolean;
134
+ isVector2: boolean;
135
+
136
+ merge_validation: undefined | ((value: any) => boolean);
137
+ condition: any;
138
+ exposed: boolean;
139
+ label: any;
140
+ merge: (instance: any, data: object) => void
141
+ reset: (instance: any) => void
142
+ getDefault(instance: any): any;
143
+ copy(instance: any, target: any): void;
144
+ }
145
+
146
+ declare function updateSelection(): void
147
+
148
+ /**
149
+ * Returns a translated string in the current language
150
+ * @param key Translation key
151
+ * @param arguments Array of arguments that replace anchors (%0, etc.) in the translation. Items can be strings or anything that can be converted to strings
152
+ */
153
+ declare function tl(key: string, arguments?: any[]): string
154
+
155
+ declare namespace Language {
156
+ /**
157
+ * Translation data for the current language
158
+ */
159
+ const data: {
160
+ [key: string]: string
161
+ }
162
+ /**
163
+ * Two letter code indicating the currently selected language
164
+ */
165
+ const code: string
166
+ /**
167
+ * Add translations for custom translation strings
168
+ * @param language Two letter language code, e. G. 'en'
169
+ * @param strings Object listing the translation keys and values
170
+ */
171
+ function addTranslations(language: string, strings: {[key: string]: string})
172
+ }
@@ -0,0 +1,34 @@
1
+ interface ModeOptions {
2
+ name: string
3
+ default_tool?: string
4
+ selectElements?: boolean
5
+ /**
6
+ * Hide certain types of nodes in the outliner, like cubes and meshes in animation mode
7
+ */
8
+ hidden_node_types?: string[]
9
+ hide_toolbars?: boolean
10
+ hide_sidebars?: boolean
11
+ hide_status_bar?: boolean
12
+ condition?: ConditionResolvable
13
+ component?: Vue.Component
14
+ onSelect?: () => void
15
+ onUnselect?: () => void
16
+ }
17
+ declare class Mode extends KeybindItem {
18
+ constructor(id: string, options: ModeOptions)
19
+
20
+ /**Selects the mode */
21
+ select: () => void
22
+ /**Unselects the mode */
23
+ unselect: () => void
24
+ /**Activates the mode */
25
+ trigger: () => void
26
+
27
+ static selected: Mode
28
+ }
29
+
30
+ declare namespace Modes {
31
+ const options: {
32
+ [id: string]: Mode
33
+ }
34
+ }
@@ -58,6 +58,8 @@ declare class OutlinerNode {
58
58
  declare class OutlinerElement extends OutlinerNode {
59
59
  constructor ()
60
60
  selected: boolean
61
+ readonly mesh: THREE.Object3D | THREE.Mesh
62
+ getMesh: () => THREE.Object3D | THREE.Mesh
61
63
  static fromSave: (data: object, keep_uuid?: boolean) => OutlinerElement
62
64
  static isParent: false
63
65
  }
@@ -90,6 +92,8 @@ declare class Group extends OutlinerNode {
90
92
 
91
93
  name: string
92
94
  children: OutlinerNode[]
95
+ origin: ArrayVector3
96
+ rotation: ArrayVector3
93
97
  reset: boolean
94
98
  shade: boolean
95
99
  selected: boolean
@@ -135,51 +139,12 @@ declare class Group extends OutlinerNode {
135
139
  forEachChild(callback: (object: OutlinerNode) => void, type?: any, for_self?: boolean)
136
140
  }
137
141
 
138
- interface CubeOptions {
139
- name: string
140
- autouv: 1 | 2 | 3
141
- shade: boolean
142
- mirror_uv: boolean
143
- inflate: number
144
- color: number
145
- visibility: boolean
146
- from: ArrayVector3
147
- to: ArrayVector3
148
- rotation: ArrayVector3
149
- origin: ArrayVector3
150
- /**
151
- * UV position for box UV mode
152
- */
153
- uv_offset: ArrayVector2
154
- }
155
- declare class Cube extends OutlinerElement {
156
- constructor (options: Partial<CubeOptions>, uuid?: string)
157
- autouv: 1 | 2 | 3
158
- shade: boolean
159
- mirror_uv: boolean
160
- inflate: number
161
- visibility: boolean
162
- from: ArrayVector3
163
- to: ArrayVector3
164
- rotation: ArrayVector3
165
- origin: ArrayVector3
166
- /**
167
- * UV position for box UV mode
168
- */
169
- uv_offset: ArrayVector2
170
- extend(options: Partial<CubeOptions>): this
171
-
172
- static all: Cube[]
173
- static selected: Cube[]
174
- }
175
-
176
142
 
177
143
  interface LocatorOptions {
178
144
  name: string
179
145
  from: ArrayVector3
180
146
 
181
147
  }
182
-
183
148
  declare class Locator extends OutlinerElement {
184
149
  constructor (options: Partial<LocatorOptions>, uuid?: string)
185
150
 
@@ -192,6 +157,52 @@ declare class Locator extends OutlinerElement {
192
157
  }
193
158
 
194
159
 
160
+ interface NullObjectOptions {
161
+ name?: string
162
+ position?: ArrayVector3
163
+ ik_target?: string
164
+ lock_ik_target_rotation?: boolean
165
+
166
+ }
167
+ declare class NullObject extends OutlinerElement {
168
+ constructor (options: Partial<NullObjectOptions>, uuid?: string)
169
+ position: ArrayVector3
170
+ ik_target: string
171
+ lock_ik_target_rotation: boolean
172
+
173
+ extend(options: Partial<NullObjectOptions>)
174
+ flip(axis: number, center: number): this
175
+ getWorldCenter(): THREE.Vector3
176
+
177
+ static all: NullObject[]
178
+ static selected: NullObject[]
179
+ }
180
+
181
+
182
+ interface TextureMeshOptions {
183
+ name?: string
184
+ texture_name?: string
185
+ origin?: ArrayVector3
186
+ local_pivot?: ArrayVector3
187
+ rotation?: ArrayVector3
188
+ scale?: ArrayVector3
189
+ }
190
+ declare class TextureMesh extends OutlinerElement {
191
+ constructor (options: Partial<TextureMeshOptions>, uuid?: string)
192
+ texture_name: string
193
+ local_pivot: ArrayVector3
194
+ scale: ArrayVector3
195
+
196
+ extend(options: Partial<TextureMeshOptions>)
197
+ flip(axis: number, center: number): this
198
+ getWorldCenter(): THREE.Vector3
199
+ moveVector(offset: ArrayVector3 | THREE.Vector3, axis: number, update?: boolean): void
200
+
201
+ static all: TextureMesh[]
202
+ static selected: TextureMesh[]
203
+ }
204
+
205
+
195
206
 
196
207
  declare namespace Outliner {
197
208
  const root: OutlinerNode[]
@@ -0,0 +1,29 @@
1
+
2
+ declare namespace Painter {
3
+ const currentPixel: ArrayVector2
4
+ const brushChanges: boolean
5
+ const current: object
6
+ const selection: object
7
+ const mirror_painting: boolean
8
+ const lock_alpha: boolean
9
+ const erase_mode: boolean
10
+ const default_brush_presets: object[]
11
+
12
+ function edit(texture: Texture, callback: (canvas: HTMLCanvasElement) => void, options: TextureEditOptions)
13
+ function setAlphaMatrix(texture: Texture, x, y, val)
14
+ function getAlphaMatrix(texture: Texture, x, y)
15
+
16
+ function combineColors(base: RGBAColor, added: RGBAColor, opacity: number): RGBAColor
17
+ function blendColors(base: RGBAColor, added: RGBAColor, opacity: number, blend_mode: string): RGBAColor
18
+ function getMirrorElement(element: OutlinerElement, symmetry_axes: number[]): void
19
+ function updateNslideValues(): void
20
+ function getBlendModeCompositeOperation(): string
21
+ function getCanvas(texture: Texture): HTMLCanvasElement
22
+ function scanCanvas(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, cb: () => void): void
23
+ function getPixelColor(ctx: CanvasRenderingContext2D, x: number, y: number): void
24
+ function modifyCanvasSection(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, cb: () => void): void
25
+ function editCircle(ctx: CanvasRenderingContext2D, x: number, y: number, r: number, softness: number, editPx: (RGBAColor, opacity: number, px: number, py: number) => RGBAColor): void
26
+ function editSquare(ctx: CanvasRenderingContext2D, x: number, y: number, r: number, softness: number, editPx: (RGBAColor, opacity: number, px: number, py: number) => RGBAColor): void
27
+ function openBrushOptions(): void
28
+ function loadBrushPreset(preset: object): void
29
+ }
package/types/panel.d.ts CHANGED
@@ -5,8 +5,8 @@ interface PanelOptions {
5
5
  menu?: any
6
6
  growable?: boolean
7
7
  selection_only?: boolean
8
- condition?: Condition
9
- display_condition?: Condition
8
+ condition?: ConditionResolvable
9
+ display_condition?: ConditionResolvable
10
10
  expand_button: boolean
11
11
  toolbars: {
12
12
  [id: string]: Toolbar
@@ -14,7 +14,7 @@ interface PreviewModelCubeTemplate {
14
14
  }
15
15
 
16
16
  interface PreviewModelOptions {
17
- condition?: Condition
17
+ condition?: ConditionResolvable
18
18
  cubes: PreviewModelCubeTemplate[]
19
19
  /**
20
20
  * Source of the model's texture
@@ -75,7 +75,7 @@ interface PreviewSceneOptions {
75
75
  description?: string
76
76
  light_color?: string
77
77
  light_side?: number
78
- condition?: Condition
78
+ condition?: ConditionResolvable
79
79
  preview_models?: string[]
80
80
  }
81
81
 
@@ -95,7 +95,7 @@ declare class PreviewScene extends Deletable {
95
95
  description: string
96
96
  light_color: string
97
97
  light_side: number
98
- condition?: Condition
98
+ condition?: ConditionResolvable
99
99
  preview_models: string[]
100
100
 
101
101
  /**
@@ -41,9 +41,13 @@ declare class ModelProject {
41
41
  elements: OutlinerElement[]
42
42
  groups: Group[]
43
43
  selected_elements: OutlinerElement[]
44
- selected_group: Group | null;
45
- selected_vertices: {
46
- [element_key: string]: string[]
44
+ selected_group: Group | null
45
+ mesh_selection: {
46
+ [element_key: string]: {
47
+ vertices: string[]
48
+ edges: string[]
49
+ faces: string[]
50
+ }
47
51
  };
48
52
  selected_faces: []
49
53
  textures: Texture[]
@@ -0,0 +1,58 @@
1
+ interface ScreenshotOptions {
2
+ crop?: boolean
3
+ width?: number
4
+ height?: number
5
+ }
6
+ interface RecordGIFOptions {
7
+ fps: number
8
+ format?: 'gif' | 'apng' | 'png_sequence'
9
+ length_mode?: 'seconds' | 'frames' | 'turntable' | 'animation'
10
+ length?: number
11
+ pixelate?: number
12
+ quality?: number
13
+ background: string
14
+ background_image?: string
15
+ turnspeed?: string
16
+ /** Start playing the selected animation when the animation starts */
17
+ play?: boolean
18
+ repeat?: any
19
+ /** Disable all UI feedback about GIF recording */
20
+ silent?: boolean
21
+ }
22
+ interface RecordTimelapseOptions {
23
+ /** Destination oath */
24
+ destination: string
25
+ source: 'preview' | 'locked' | 'interface'
26
+ /** Interval between frames in seconds */
27
+ interval: number
28
+ }
29
+ type ScreenshotReturn = (dataURL: string) => void
30
+
31
+ declare namespace Screencam {
32
+ /**
33
+ * Provided preview with anti aliasing disabled that can be used for screenshots
34
+ */
35
+ const NoAAPreview: Preview
36
+ /**
37
+ * Whether a timelapse is currently being recorded
38
+ */
39
+ const recording_timelapse: boolean
40
+ const gif_options_dialog: Dialog
41
+ const gif_crop: {top: number, left: number, right: number, bottom: number}
42
+
43
+ function screenshotPreview(preview: Preview, options: ScreenshotOptions, cb: ScreenshotReturn): void
44
+
45
+ function fullScreen(options: ScreenshotOptions, cb: ScreenshotReturn): void
46
+
47
+ function screenshot2DEditor(options: ScreenshotOptions, cb: ScreenshotReturn): void
48
+
49
+ function returnScreenshot(dataUrl, cb: ScreenshotReturn, blob): void
50
+
51
+ function cleanCanvas(options, cb: ScreenshotReturn): void
52
+
53
+ function createGif(options: RecordGIFOptions, cb: ScreenshotReturn): void
54
+
55
+ function recordTimelapse(options: RecordTimelapseOptions): void
56
+
57
+ function stopTimelapse(): void
58
+ }
@@ -34,6 +34,8 @@ interface TextureEditOptions {
34
34
  * If true, the texture is not updated visually
35
35
  */
36
36
  no_update?: boolean
37
+ no_undo_init?: boolean
38
+ no_undo_finish?: boolean
37
39
  }
38
40
 
39
41
  declare class Texture {
package/types/undo.d.ts CHANGED
@@ -40,21 +40,70 @@ type UndoEntry = {
40
40
  action: string
41
41
  time: number
42
42
  }
43
+ interface AmendEditForm {
44
+ condition?: ConditionResolvable
45
+ type?: 'number'
46
+ label: string
47
+ interval_type: 'position' | 'rotation'
48
+ getInterval?: (Event) => number
49
+ value?: number | string,
50
+ min?: number,
51
+ max?: number,
52
+ step?: number,
53
+ }
43
54
 
44
55
  declare class UndoSystem {
45
56
  constructor();
57
+ /**
58
+ * Starts an edit to the current project by saving the state of the provided aspects
59
+ * @param aspects Aspects to save
60
+ */
46
61
  initEdit(aspects: UndoAspects): any;
62
+ /**
63
+ * Finishes an edit by saving the state of the project after it was changed
64
+ * @param action Description of the edit
65
+ */
47
66
  finishEdit(action: string, aspects?: UndoAspects): {
48
67
  before: any;
49
68
  post: any;
50
69
  action: any;
51
70
  time: number;
52
71
  };
72
+ /**
73
+ * Cancels an event before it was finished and reset the project to the state before
74
+ */
53
75
  cancelEdit(): void;
76
+ /**
77
+ * Add keyframes to the current edit that were indirectly removed by moving other keyframes to their position
78
+ * @param keyframes
79
+ */
54
80
  addKeyframeCasualties(keyframes: Keyframe[]): void;
81
+ /**
82
+ * Undoes the latest edit
83
+ */
55
84
  undo(remote?: boolean): void;
85
+ /**
86
+ * Redoes the latest edit
87
+ */
88
+ redo(remote?: boolean): void;
89
+ /**
90
+ * Redoes the latest edit
91
+ */
56
92
  redo(remote?: boolean): void;
57
- remoteEdit(entry: UndoEntry): void;
58
- loadSave(save: UndoSave, reference: UndoSave, mode?: string): void;
93
+ /**
94
+ * Provides a menu to amend the latest edit with slightly changed values
95
+ */
96
+ amendEdit(form: AmendEditForm, callback: (values: {}, form: {}) => void)
97
+
98
+ /**
99
+ * Loads a specific undo save
100
+ * @param save The undo save to load
101
+ * @param reference The current undo save for reference
102
+ * @param mode The load save modes
103
+ */
104
+ loadSave(save: UndoSave, reference: UndoSave, mode?: 'session'): void;
59
105
  }
106
+ /**
107
+ * Blockbench's system to register edits to the project and switch between them
108
+ */
60
109
  declare let Undo: UndoSystem;
package/types/util.d.ts CHANGED
@@ -1,7 +1,24 @@
1
- type ConditionType = undefined | boolean | number | Partial<{
1
+ type ConditionResolvable = undefined | boolean | ((context) => boolean) | Partial<{
2
2
  modes: string[]
3
3
  formats: string[]
4
4
  tools: string[]
5
+ features: string[]
6
+ selected: {
7
+ animation?: boolean
8
+ animation_controller?: boolean
9
+ animation_controller_state?: boolean
10
+ keyframe?: boolean
11
+ group?: boolean
12
+ texture?: boolean
13
+ element?: boolean
14
+ cube?: boolean
15
+ mesh?: boolean
16
+ locator?: boolean
17
+ null_object?: boolean
18
+ texture_mesh?: boolean
19
+ outliner?: boolean
20
+ }
21
+ project: boolean
5
22
  method: (context: any) => boolean
6
23
  }>
7
24
 
@@ -37,3 +54,19 @@ declare function addEventListeners(element: HTMLElement, events: string, func: (
37
54
  declare function trimFloatNumber(value: number): string
38
55
  declare function getAxisLetter(axisNumber: number): string
39
56
  declare function getAxisNumber(axisLetter: string): number
57
+
58
+
59
+ declare namespace Reusable {
60
+ const vec1: THREE.Vector3
61
+ const vec2: THREE.Vector3
62
+ const vec3: THREE.Vector3
63
+ const vec4: THREE.Vector3
64
+ const vec5: THREE.Vector3
65
+ const vec6: THREE.Vector3
66
+ const vec7: THREE.Vector3
67
+ const vec8: THREE.Vector3
68
+ const quat1: THREE.Quaternion
69
+ const quat2: THREE.Quaternion
70
+ const euler1: THREE.Euler
71
+ const euler2: THREE.Euler
72
+ }
@@ -32,7 +32,7 @@ interface ValidatorCheckOptions {
32
32
  * Names of events that automatically trigger this check
33
33
  */
34
34
  update_triggers?: EventName[]
35
- condition?: Condition
35
+ condition?: ConditionResolvable
36
36
  }
37
37
  interface WarningOrError {
38
38
  message: string