@defold-typescript/types 0.25.0 → 0.27.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.
Files changed (80) hide show
  1. package/api-availability.json +333 -306
  2. package/api-signatures.json +1312 -0
  3. package/api-targets.json +351 -2
  4. package/examples/translations.json +1984 -0
  5. package/fixtures/messages_doc.json +880 -0
  6. package/generated/collectionproxy.d.ts +22 -0
  7. package/generated/editor-vm/http.d.ts +2 -2
  8. package/generated/editor-vm/image.d.ts +48 -0
  9. package/generated/editor.d.ts +27 -8
  10. package/generated/gui.d.ts +35 -6
  11. package/generated/kinds/editor-script.d.ts +1 -0
  12. package/generated/material.d.ts +4 -0
  13. package/generated/versions/defold-1.12.4/liveupdate.d.ts +22 -22
  14. package/generated/versions/defold-1.12.4/physics.d.ts +78 -75
  15. package/generated/versions/defold-1.12.4/render.d.ts +75 -55
  16. package/generated/versions/defold-1.12.4/resource.d.ts +187 -175
  17. package/generated/versions/defold-1.13.0/b2d.d.ts +33 -0
  18. package/generated/versions/defold-1.13.0/b2d_body.d.ts +676 -0
  19. package/generated/versions/defold-1.13.0/b2d_chain.d.ts +106 -0
  20. package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +155 -0
  21. package/generated/versions/defold-1.13.0/b2d_joint.d.ts +823 -0
  22. package/generated/versions/defold-1.13.0/b2d_shape.d.ts +215 -0
  23. package/generated/versions/defold-1.13.0/b2d_world.d.ts +314 -0
  24. package/generated/versions/defold-1.13.0/buffer.d.ts +176 -0
  25. package/generated/versions/defold-1.13.0/camera.d.ts +302 -0
  26. package/generated/versions/defold-1.13.0/collectionfactory.d.ts +146 -0
  27. package/generated/versions/defold-1.13.0/collectionproxy.d.ts +71 -0
  28. package/generated/versions/defold-1.13.0/compute.d.ts +306 -0
  29. package/generated/versions/defold-1.13.0/crash.d.ts +143 -0
  30. package/generated/versions/defold-1.13.0/editor-vm/http.d.ts +56 -0
  31. package/generated/versions/defold-1.13.0/editor-vm/json.d.ts +10 -0
  32. package/generated/versions/defold-1.13.0/editor-vm/localization.d.ts +42 -0
  33. package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +80 -0
  34. package/generated/versions/defold-1.13.0/editor-vm/zip.d.ts +10 -0
  35. package/generated/versions/defold-1.13.0/editor-vm/zlib.d.ts +24 -0
  36. package/generated/versions/defold-1.13.0/editor.d.ts +1092 -0
  37. package/generated/versions/defold-1.13.0/factory.d.ts +123 -0
  38. package/generated/versions/defold-1.13.0/font.d.ts +81 -0
  39. package/generated/versions/defold-1.13.0/go.d.ts +1054 -0
  40. package/generated/versions/defold-1.13.0/graphics.d.ts +321 -0
  41. package/generated/versions/defold-1.13.0/gui.d.ts +2370 -0
  42. package/generated/versions/defold-1.13.0/html5.d.ts +53 -0
  43. package/generated/versions/defold-1.13.0/http.d.ts +84 -0
  44. package/generated/versions/defold-1.13.0/iac.d.ts +18 -0
  45. package/generated/versions/defold-1.13.0/iap.d.ts +60 -0
  46. package/generated/versions/defold-1.13.0/image.d.ts +139 -0
  47. package/generated/versions/defold-1.13.0/index.d.ts +48 -0
  48. package/generated/versions/defold-1.13.0/json.d.ts +76 -0
  49. package/generated/versions/defold-1.13.0/kinds/editor-script.d.ts +13 -0
  50. package/generated/versions/defold-1.13.0/label.d.ts +94 -0
  51. package/generated/versions/defold-1.13.0/liveupdate.d.ts +140 -0
  52. package/generated/versions/defold-1.13.0/material.d.ts +444 -0
  53. package/generated/versions/defold-1.13.0/model.d.ts +246 -0
  54. package/generated/versions/defold-1.13.0/msg.d.ts +10 -0
  55. package/generated/versions/defold-1.13.0/particlefx.d.ts +166 -0
  56. package/generated/versions/defold-1.13.0/physics.d.ts +548 -0
  57. package/generated/versions/defold-1.13.0/profiler.d.ts +233 -0
  58. package/generated/versions/defold-1.13.0/push.d.ts +66 -0
  59. package/generated/versions/defold-1.13.0/render.d.ts +1185 -0
  60. package/generated/versions/defold-1.13.0/resource.d.ts +1530 -0
  61. package/generated/versions/defold-1.13.0/socket.d.ts +795 -0
  62. package/generated/versions/defold-1.13.0/sound.d.ts +291 -0
  63. package/generated/versions/defold-1.13.0/sprite.d.ts +157 -0
  64. package/generated/versions/defold-1.13.0/sys.d.ts +695 -0
  65. package/generated/versions/defold-1.13.0/tilemap.d.ts +195 -0
  66. package/generated/versions/defold-1.13.0/timer.d.ts +114 -0
  67. package/generated/versions/defold-1.13.0/types.d.ts +61 -0
  68. package/generated/versions/defold-1.13.0/vmath.d.ts +806 -0
  69. package/generated/versions/defold-1.13.0/webview.d.ts +68 -0
  70. package/generated/versions/defold-1.13.0/window.d.ts +198 -0
  71. package/generated/versions/defold-1.13.0/zlib.d.ts +40 -0
  72. package/index.d.ts +4 -81
  73. package/package.json +11 -3
  74. package/scripts/import-defold-release.ts +28 -1
  75. package/scripts/sync-api-docs.ts +4 -3
  76. package/src/api-availability.ts +0 -0
  77. package/src/emit-dts.ts +6 -0
  78. package/src/example-store.ts +5 -0
  79. package/src/index.ts +3 -0
  80. package/scripts/lua-types-signature-index.ts +0 -151
@@ -0,0 +1,1530 @@
1
+ /** @noSelfInFile */
2
+ import type { Hash, Opaque } from "../../../src/core-types";
3
+
4
+ declare global {
5
+ /**
6
+ * Functions and constants to access resources.
7
+ */
8
+ namespace resource {
9
+ /**
10
+ * Constructor-like function with two purposes:
11
+ *
12
+ * - Load the specified resource as part of loading the script
13
+ *
14
+ * - Return a hash to the run-time version of the resource
15
+ *
16
+ * This function can only be called within go.property function calls.
17
+ *
18
+ * @param path - optional resource path string to the resource
19
+ * @returns a path hash to the binary version of the resource
20
+ * @example
21
+ * ```ts
22
+ * // Load an atlas and set it to a sprite:
23
+ * go.property("my_atlas", resource.atlas("/atlas.atlas"));
24
+ *
25
+ * export default defineScript({
26
+ * init(self) {
27
+ * go.set("#sprite", "image", self.my_atlas);
28
+ * },
29
+ * });
30
+ *
31
+ * // Load an atlas and set it to a gui:
32
+ * go.property("my_atlas", resource.atlas("/atlas.atlas"));
33
+ *
34
+ * export default defineScript({
35
+ * init(self) {
36
+ * go.set("#gui", "textures", self.my_atlas, { key: "my_atlas" });
37
+ * },
38
+ * });
39
+ * ```
40
+ */
41
+ function atlas(path?: string): Hash;
42
+ /**
43
+ * Constructor-like function with two purposes:
44
+ *
45
+ * - Load the specified resource as part of loading the script
46
+ *
47
+ * - Return a hash to the run-time version of the resource
48
+ *
49
+ * This function can only be called within go.property function calls.
50
+ *
51
+ * @param path - optional resource path string to the resource
52
+ * @returns a path hash to the binary version of the resource
53
+ * @example
54
+ * ```ts
55
+ * // Set a unique buffer it to a sprite:
56
+ * go.property("my_buffer", resource.buffer("/cube.buffer"));
57
+ *
58
+ * export default defineScript({
59
+ * init(self) {
60
+ * go.set("#mesh", "vertices", self.my_buffer);
61
+ * },
62
+ * });
63
+ * ```
64
+ */
65
+ function buffer(path?: string): Hash;
66
+ /**
67
+ * This function creates a new atlas resource that can be used in the same way as any atlas created during build time.
68
+ * The path used for creating the atlas must be unique, trying to create a resource at a path that is already
69
+ * registered will trigger an error. If the intention is to instead modify an existing atlas, use the resource.set_atlas
70
+ * function. Also note that the path to the new atlas resource must have a '.texturesetc' extension,
71
+ * meaning "/path/my_atlas" is not a valid path but "/path/my_atlas.texturesetc" is.
72
+ * When creating the atlas, at least one geometry and one animation is required, and an error will be
73
+ * raised if these requirements are not met. A reference to the resource will be held by the collection
74
+ * that created the resource and will automatically be released when that collection is destroyed.
75
+ * Note that releasing a resource essentially means decreasing the reference count of that resource,
76
+ * and not necessarily that it will be deleted.
77
+ *
78
+ * @param path - The path to the resource.
79
+ * @param table - A table containing info about how to create the atlas. Supported entries:
80
+ *
81
+ * -
82
+ *
83
+ * `texture`
84
+ * string | hash the path to the texture resource, e.g "/main/my_texture.texturec"
85
+ *
86
+ * -
87
+ *
88
+ * `animations`
89
+ * table a list of the animations in the atlas. Supports the following fields:
90
+ *
91
+ * -
92
+ *
93
+ * `id`
94
+ * string the id of the animation, used in e.g sprite.play_animation
95
+ *
96
+ * -
97
+ *
98
+ * `width`
99
+ * number the width of the animation
100
+ *
101
+ * -
102
+ *
103
+ * `height`
104
+ * number the height of the animation
105
+ *
106
+ * -
107
+ *
108
+ * `frame_start`
109
+ * number index to the first geometry of the animation. Indices are lua based and must be in the range of 1 .. in atlas.
110
+ *
111
+ * -
112
+ *
113
+ * `frame_end`
114
+ * number index to the last geometry of the animation (non-inclusive). Indices are lua based and must be in the range of 1 .. in atlas.
115
+ *
116
+ * -
117
+ *
118
+ * `playback`
119
+ * constant optional playback mode of the animation, the default value is go.PLAYBACK_ONCE_FORWARD
120
+ *
121
+ * -
122
+ *
123
+ * `fps`
124
+ * number optional fps of the animation, the default value is 30
125
+ *
126
+ * -
127
+ *
128
+ * `flip_vertical`
129
+ * boolean optional flip the animation vertically, the default value is false
130
+ *
131
+ * -
132
+ *
133
+ * `flip_horizontal`
134
+ * boolean optional flip the animation horizontally, the default value is false
135
+ *
136
+ * -
137
+ *
138
+ * `geometries`
139
+ * table A list of the geometries that should map to the texture data. Supports the following fields:
140
+ *
141
+ * -
142
+ *
143
+ * `id`
144
+ * string The name of the geometry. Used when matching animations between multiple atlases
145
+ *
146
+ * -
147
+ *
148
+ * `width`
149
+ * number The width of the image the sprite geometry represents
150
+ *
151
+ * -
152
+ *
153
+ * `height`
154
+ * number The height of the image the sprite geometry represents
155
+ *
156
+ * -
157
+ *
158
+ * `pivot_x`
159
+ * number The pivot x value of the image in unit coords. (0,0) is upper left corner, (1,1) is bottom right. Default is 0.5.
160
+ *
161
+ * -
162
+ *
163
+ * `pivot_y`
164
+ * number The pivot y value of the image in unit coords. (0,0) is upper left corner, (1,1) is bottom right. Default is 0.5.
165
+ *
166
+ * -
167
+ *
168
+ * `rotated`
169
+ * boolean Whether the image is rotated 90 degrees counter-clockwise in the atlas. This affects UV coordinate generation for proper rendering. Default is false.
170
+ *
171
+ * -
172
+ *
173
+ * `vertices`
174
+ * table a list of the vertices in image space of the geometry in the form {px0, py0, px1, py1, ..., pxn, pyn}
175
+ *
176
+ * -
177
+ *
178
+ * `uvs`
179
+ * table a list of the uv coordinates in image space of the geometry in the form of {u0, v0, u1, v1, ..., un, vn}.
180
+ *
181
+ * -
182
+ *
183
+ * `indices`
184
+ * table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
185
+ * @returns Returns the atlas resource path
186
+ * @example
187
+ * ```ts
188
+ * // Create a backing texture and an atlas
189
+ * export default defineScript({
190
+ * init() {
191
+ * // create an empty texture
192
+ * const tparams = {
193
+ * width: 128,
194
+ * height: 128,
195
+ * type: graphics.TEXTURE_TYPE_2D,
196
+ * format: graphics.TEXTURE_FORMAT_RGBA,
197
+ * };
198
+ * const my_texture_id = resource.create_texture("/my_texture.texturec", tparams);
199
+ *
200
+ * // optionally use resource.set_texture to upload data to texture
201
+ *
202
+ * // create an atlas with one animation and one square geometry
203
+ * // note that the function doesn't support hashes for the texture,
204
+ * // you need to use a string for the texture path here aswell
205
+ * const aparams = {
206
+ * texture: "/my_texture.texturec",
207
+ * animations: [
208
+ * {
209
+ * id: "my_animation",
210
+ * width: 128,
211
+ * height: 128,
212
+ * frames: [1],
213
+ * },
214
+ * ],
215
+ * geometries: [
216
+ * {
217
+ * id: "idle0",
218
+ * width: 128,
219
+ * height: 128,
220
+ * pivot_x: 0.5,
221
+ * pivot_y: 0.5,
222
+ * vertices: [0, 0, 0, 128, 128, 128, 128, 0],
223
+ * uvs: [0, 0, 0, 128, 128, 128, 128, 0],
224
+ * indices: [0, 1, 2, 0, 2, 3],
225
+ * },
226
+ * ],
227
+ * };
228
+ * const my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams);
229
+ *
230
+ * // assign the atlas to the 'sprite' component on the same go
231
+ * go.set("#sprite", "image", my_atlas_id);
232
+ * },
233
+ * });
234
+ * ```
235
+ */
236
+ function create_atlas(path: string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: { id?: string; width?: number; height?: number; pivot_x?: number; pivot_y?: number; rotated?: boolean }[]; vertices?: number[]; uvs?: number[]; indices?: number[] }): Hash;
237
+ /**
238
+ * This function creates a new buffer resource that can be used in the same way as any buffer created during build time.
239
+ * The function requires a valid buffer created from either buffer.create or another pre-existing buffer resource.
240
+ * By default, the new resource will take ownership of the buffer lua reference, meaning the buffer will not automatically be removed
241
+ * when the lua reference to the buffer is garbage collected. This behaviour can be overruled by specifying 'transfer_ownership = false'
242
+ * in the argument table. If the new buffer resource is created from a buffer object that is created by another resource,
243
+ * the buffer object will be copied and the new resource will effectively own a copy of the buffer instead.
244
+ * Note that the path to the new resource must have the '.bufferc' extension, "/path/my_buffer" is not a valid path but "/path/my_buffer.bufferc" is.
245
+ * The path must also be unique, attempting to create a buffer with the same name as an existing resource will raise an error.
246
+ *
247
+ * @param path - The path to the resource.
248
+ * @param table - A table containing info about how to create the buffer. Supported entries:
249
+ *
250
+ * -
251
+ *
252
+ * `buffer`
253
+ * buffer the buffer to bind to this resource
254
+ *
255
+ * -
256
+ *
257
+ * `transfer_ownership`
258
+ * boolean optional flag to determine whether or not the resource should take over ownership of the buffer object (default true)
259
+ * @returns Returns the buffer resource path
260
+ * @example
261
+ * ```ts
262
+ * // Create a buffer object and bind it to a buffer resource
263
+ * export default defineScript({
264
+ * init() {
265
+ * const size = 1;
266
+ * const positions = [
267
+ * // triangle 1
268
+ * size, size, 0,
269
+ * -size, -size, 0,
270
+ * size, -size, 0,
271
+ * // triangle 2
272
+ * size, size, 0,
273
+ * -size, size, 0,
274
+ * -size, -size, 0,
275
+ * ];
276
+ *
277
+ * const buffer_handle = buffer.create(positions.length, [
278
+ * {
279
+ * name: hash("position"),
280
+ * type: buffer.VALUE_TYPE_FLOAT32,
281
+ * count: 3,
282
+ * },
283
+ * ]);
284
+ *
285
+ * const stream = buffer.get_stream(buffer_handle, hash("position"));
286
+ *
287
+ * // transfer vertex data to buffer
288
+ * for (let k = 0; k < positions.length; k++) {
289
+ * stream[k] = positions[k];
290
+ * }
291
+ *
292
+ * const my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer: buffer_handle });
293
+ * go.set("/go#mesh", "vertices", my_buffer);
294
+ * },
295
+ * });
296
+ *
297
+ * // Create a buffer resource from existing resource
298
+ * export default defineScript({
299
+ * init() {
300
+ * const res = resource.get_buffer("/my_buffer_path.bufferc");
301
+ * // create a cloned buffer resource from another resource buffer
302
+ * const buf = resource.create_buffer("/my_cloned_buffer.bufferc", { buffer: res });
303
+ * // assign cloned buffer to a mesh component
304
+ * go.set("/go#mesh", "vertices", buf);
305
+ * },
306
+ * });
307
+ * ```
308
+ */
309
+ function create_buffer(path: string, table?: { buffer?: Opaque<"buffer">; transfer_ownership?: boolean }): Hash;
310
+ /**
311
+ * Creates a sound data resource
312
+ * Supported formats are .oggc, .opusc and .wavc
313
+ *
314
+ * @param path - the path to the resource. Must not already exist.
315
+ * @param options - A table containing parameters for the text. Supported entries:
316
+ *
317
+ * `data`
318
+ * string The raw data of the file. May be partial, but must include the header of the file
319
+ * `filesize`
320
+ * number If the file is partial, it must also specify the full size of the complete file.
321
+ * `partial`
322
+ * boolean Is the data not representing the full file, but just the initial chunk?
323
+ * @returns the resulting path hash to the resource
324
+ * @example
325
+ * ```ts
326
+ * export default defineScript({
327
+ * init() {
328
+ * // create a new sound resource, given the initial chunk of the file
329
+ * const relative_path = "/a/unique/resource/name.oggc";
330
+ * const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });
331
+ * go.set("#music", "sound", hash); // override the previous sound resource
332
+ * sound.play("#music"); // start the playing
333
+ * },
334
+ * });
335
+ * ```
336
+ */
337
+ function create_sound_data(path: string, options?: { data?: string; filesize?: number; partial?: boolean }): Hash;
338
+ /**
339
+ * Creates a new texture resource that can be used in the same way as any texture created during build time.
340
+ * The path used for creating the texture must be unique, trying to create a resource at a path that is already
341
+ * registered will trigger an error. If the intention is to instead modify an existing texture, use the resource.set_texture
342
+ * function. Also note that the path to the new texture resource must have a '.texturec' extension,
343
+ * meaning "/path/my_texture" is not a valid path but "/path/my_texture.texturec" is.
344
+ * If the texture is created without a buffer, the pixel data will be blank.
345
+ *
346
+ * @param path - The path to the resource.
347
+ * @param table - A table containing info about how to create the texture. Supported entries:
348
+ *
349
+ * `type`
350
+ * number The texture type. Supported values:
351
+ *
352
+ * - `graphics.TEXTURE_TYPE_2D`
353
+ *
354
+ * - `graphics.TEXTURE_TYPE_IMAGE_2D`
355
+ *
356
+ * - `graphics.TEXTURE_TYPE_3D`
357
+ *
358
+ * - `graphics.TEXTURE_TYPE_IMAGE_3D`
359
+ *
360
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
361
+ *
362
+ * `width`
363
+ * number The width of the texture (in pixels). Must be larger than 0.
364
+ * `height`
365
+ * number The width of the texture (in pixels). Must be larger than 0.
366
+ * `depth`
367
+ * number The depth of the texture (in pixels). Must be larger than 0. Only used when `type` is `graphics.TEXTURE_TYPE_3D` or `graphics.TEXTURE_TYPE_IMAGE_3D`.
368
+ * `format`
369
+ * number The texture format, note that some of these formats might not be supported by the running device. Supported values:
370
+ *
371
+ * - `graphics.TEXTURE_FORMAT_LUMINANCE`
372
+ *
373
+ * - `graphics.TEXTURE_FORMAT_RGB`
374
+ *
375
+ * - `graphics.TEXTURE_FORMAT_RGBA`
376
+ *
377
+ * These constants might not be available on the device:
378
+ *
379
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
380
+ *
381
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
382
+ *
383
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
384
+ *
385
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
386
+ *
387
+ * - `graphics.TEXTURE_FORMAT_RGB_ETC1`
388
+ *
389
+ * - `graphics.TEXTURE_FORMAT_RGBA_ETC2`
390
+ *
391
+ * - `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
392
+ *
393
+ * - `graphics.TEXTURE_FORMAT_RGB_BC1`
394
+ *
395
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC3`
396
+ *
397
+ * - `graphics.TEXTURE_FORMAT_R_BC4`
398
+ *
399
+ * - `graphics.TEXTURE_FORMAT_RG_BC5`
400
+ *
401
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC7`
402
+ *
403
+ * - `graphics.TEXTURE_FORMAT_RGB16F`
404
+ *
405
+ * - `graphics.TEXTURE_FORMAT_RGB32F`
406
+ *
407
+ * - `graphics.TEXTURE_FORMAT_RGBA16F`
408
+ *
409
+ * - `graphics.TEXTURE_FORMAT_RGBA32F`
410
+ *
411
+ * - `graphics.TEXTURE_FORMAT_R16F`
412
+ *
413
+ * - `graphics.TEXTURE_FORMAT_RG16F`
414
+ *
415
+ * - `graphics.TEXTURE_FORMAT_R32F`
416
+ *
417
+ * - `graphics.TEXTURE_FORMAT_RG32F`
418
+ *
419
+ * You can test if the device supports these values by checking if a specific enum is nil or not:
420
+ *
421
+ * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
422
+ * -- it is safe to use this format
423
+ * end
424
+ * `
425
+ *
426
+ * `flags`
427
+ * number Texture creation flags that can be used to dictate how the texture is created. The default value is graphics.TEXTURE_USAGE_FLAG_SAMPLE, which means that the texture can be sampled from a shader.
428
+ * These flags may or may not be supported on the running device and/or the underlying graphics API and is simply used internally as a 'hint' when creating the texture. There is no guarantee that any of these will have any effect. Supported values:
429
+ *
430
+ * - `graphics.TEXTURE_USAGE_FLAG_SAMPLE` - The texture can be sampled from a shader (default)
431
+ *
432
+ * - `graphics.TEXTURE_USAGE_FLAG_MEMORYLESS` - The texture can be used as a memoryless texture, i.e only transient memory for the texture is used during rendering
433
+ *
434
+ * - `graphics.TEXTURE_USAGE_FLAG_STORAGE` - The texture can be used as a storage texture, which is required for a shader to write to the texture
435
+ *
436
+ * `max_mipmaps`
437
+ * number optional max number of mipmaps. Defaults to zero, i.e no mipmap support
438
+ * `compression_type`
439
+ * number optional specify the compression type for the data in the buffer object that holds the texture data. Will only be used when a compressed buffer has been passed into the function.
440
+ * Creating an empty texture with no buffer data is not supported as a core feature. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
441
+ *
442
+ * - `COMPRESSION_TYPE_DEFAULT`
443
+ *
444
+ * - `COMPRESSION_TYPE_BASIS_UASTC`
445
+ * @param buffer - optional buffer of precreated pixel data
446
+ * @returns The path to the resource.
447
+ * 3D Textures are currently only supported on OpenGL and Vulkan adapters. To check if your device supports 3D textures, use:
448
+ * ```lua
449
+ * if graphics.TEXTURE_TYPE_3D ~= nil then
450
+ * -- Device and graphics adapter support 3D textures
451
+ * end
452
+ * @example
453
+ * ```ts
454
+ * // How to create an 128x128 RGBA texture resource and assign it to a model
455
+ * export default defineScript({
456
+ * init() {
457
+ * const tparams = {
458
+ * width: 128,
459
+ * height: 128,
460
+ * type: graphics.TEXTURE_TYPE_2D,
461
+ * format: graphics.TEXTURE_FORMAT_RGBA,
462
+ * };
463
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams);
464
+ * go.set("#model", "texture0", my_texture_id);
465
+ * },
466
+ * });
467
+ *
468
+ * // How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
469
+ * export default defineScript({
470
+ * init() {
471
+ * // Create a new buffer with 4 components and FLOAT32 type
472
+ * const tbuffer = buffer.create(128 * 128, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
473
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
474
+ *
475
+ * // Fill the buffer stream with some float values
476
+ * for (let y = 0; y < 128; y++) {
477
+ * for (let x = 0; x < 128; x++) {
478
+ * const index = y * 128 * 4 + x * 4;
479
+ * tstream[index + 0] = 999.0;
480
+ * tstream[index + 1] = -1.0;
481
+ * tstream[index + 2] = 0.5;
482
+ * tstream[index + 3] = 1.0;
483
+ * }
484
+ * }
485
+ *
486
+ * // Create a 2D Texture with a RGBA23F format
487
+ * const tparams = {
488
+ * width: 128,
489
+ * height: 128,
490
+ * type: graphics.TEXTURE_TYPE_2D,
491
+ * format: graphics.TEXTURE_FORMAT_RGBA32F,
492
+ * };
493
+ *
494
+ * // Note that we pass the buffer as the last argument here!
495
+ * const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer);
496
+ *
497
+ * // assign the texture to a model
498
+ * go.set("#model", "texture0", my_texture_id);
499
+ * },
500
+ * });
501
+ *
502
+ * // How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
503
+ * export default defineScript({
504
+ * init() {
505
+ * const t_volume = resource.create_texture("/my_backing_texture.texturec", {
506
+ * type: graphics.TEXTURE_TYPE_IMAGE_3D,
507
+ * width: 32,
508
+ * height: 32,
509
+ * depth: 32,
510
+ * format: resource.TEXTURE_FORMAT_RGBA32F,
511
+ * flags: resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
512
+ * });
513
+ *
514
+ * // pass the backing texture to the render script
515
+ * msg.post("@render:", "add_textures", [t_volume]);
516
+ * },
517
+ * });
518
+ *
519
+ * // How to create 512x512 texture array with 5 pages.
520
+ * const new_tex = resource.create_texture("/runtime/example_array.texturec", {
521
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
522
+ * width: 512,
523
+ * height: 512,
524
+ * page_count: 5,
525
+ * format: graphics.TEXTURE_FORMAT_RGB,
526
+ * });
527
+ * ```
528
+ */
529
+ function create_texture(path: string, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer: Opaque<"buffer">): Hash;
530
+ /**
531
+ * Creates a new texture resource that can be used in the same way as any texture created during build time.
532
+ * The path used for creating the texture must be unique, trying to create a resource at a path that is already
533
+ * registered will trigger an error. If the intention is to instead modify an existing texture, use the resource.set_texture
534
+ * function. Also note that the path to the new texture resource must have a '.texturec' extension,
535
+ * meaning "/path/my_texture" is not a valid path but "/path/my_texture.texturec" is.
536
+ * If the texture is created without a buffer, the pixel data will be blank.
537
+ * The difference between the async version and resource.create_texture is that the texture data will be uploaded
538
+ * in a graphics worker thread. The function will return a resource immediately that contains a 1x1 blank texture which can be used
539
+ * immediately after the function call. When the new texture has been uploaded, the initial blank texture will be deleted and replaced with the
540
+ * new texture. Be careful when using the initial texture handle handle as it will not be valid after the upload has finished.
541
+ *
542
+ * @param path - The path to the resource.
543
+ * @param table - A table containing info about how to create the texture. Supported entries:
544
+ * `type`
545
+ * number The texture type. Supported values:
546
+ *
547
+ * - `graphics.TEXTURE_TYPE_2D`
548
+ *
549
+ * - `graphics.TEXTURE_TYPE_IMAGE_2D`
550
+ *
551
+ * - `graphics.TEXTURE_TYPE_3D`
552
+ *
553
+ * - `graphics.TEXTURE_TYPE_IMAGE_3D`
554
+ *
555
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
556
+ *
557
+ * `width`
558
+ * number The width of the texture (in pixels). Must be larger than 0.
559
+ * `height`
560
+ * number The width of the texture (in pixels). Must be larger than 0.
561
+ * `depth`
562
+ * number The depth of the texture (in pixels). Must be larger than 0. Only used when `type` is `graphics.TEXTURE_TYPE_3D` or `graphics.TEXTURE_TYPE_IMAGE_3D`.
563
+ * `format`
564
+ * number The texture format, note that some of these formats might not be supported by the running device. Supported values:
565
+ *
566
+ * - `graphics.TEXTURE_FORMAT_LUMINANCE`
567
+ *
568
+ * - `graphics.TEXTURE_FORMAT_RGB`
569
+ *
570
+ * - `graphics.TEXTURE_FORMAT_RGBA`
571
+ *
572
+ * These constants might not be available on the device:
573
+ *
574
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
575
+ *
576
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
577
+ *
578
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
579
+ *
580
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
581
+ *
582
+ * - `graphics.TEXTURE_FORMAT_RGB_ETC1`
583
+ *
584
+ * - `graphics.TEXTURE_FORMAT_RGBA_ETC2`
585
+ *
586
+ * - `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
587
+ *
588
+ * - `graphics.TEXTURE_FORMAT_RGB_BC1`
589
+ *
590
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC3`
591
+ *
592
+ * - `graphics.TEXTURE_FORMAT_R_BC4`
593
+ *
594
+ * - `graphics.TEXTURE_FORMAT_RG_BC5`
595
+ *
596
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC7`
597
+ *
598
+ * - `graphics.TEXTURE_FORMAT_RGB16F`
599
+ *
600
+ * - `graphics.TEXTURE_FORMAT_RGB32F`
601
+ *
602
+ * - `graphics.TEXTURE_FORMAT_RGBA16F`
603
+ *
604
+ * - `graphics.TEXTURE_FORMAT_RGBA32F`
605
+ *
606
+ * - `graphics.TEXTURE_FORMAT_R16F`
607
+ *
608
+ * - `graphics.TEXTURE_FORMAT_RG16F`
609
+ *
610
+ * - `graphics.TEXTURE_FORMAT_R32F`
611
+ *
612
+ * - `graphics.TEXTURE_FORMAT_RG32F`
613
+ *
614
+ * You can test if the device supports these values by checking if a specific enum is nil or not:
615
+ *
616
+ * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
617
+ * -- it is safe to use this format
618
+ * end
619
+ * `
620
+ *
621
+ * `flags`
622
+ * number Texture creation flags that can be used to dictate how the texture is created. Supported values:
623
+ *
624
+ * - `graphics.TEXTURE_USAGE_FLAG_SAMPLE` - The texture can be sampled from a shader (default)
625
+ *
626
+ * - `graphics.TEXTURE_USAGE_FLAG_MEMORYLESS` - The texture can be used as a memoryless texture, i.e only transient memory for the texture is used during rendering
627
+ *
628
+ * - `graphics.TEXTURE_USAGE_FLAG_STORAGE` - The texture can be used as a storage texture, which is required for a shader to write to the texture
629
+ *
630
+ * `max_mipmaps`
631
+ * number optional max number of mipmaps. Defaults to zero, i.e no mipmap support
632
+ * `compression_type`
633
+ * number optional specify the compression type for the data in the buffer object that holds the texture data. Will only be used when a compressed buffer has been passed into the function.
634
+ * Creating an empty texture with no buffer data is not supported as a core feature. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
635
+ *
636
+ * - `COMPRESSION_TYPE_DEFAULT`
637
+ *
638
+ * - `COMPRESSION_TYPE_BASIS_UASTC`
639
+ * @param buffer - optional buffer of precreated pixel data
640
+ * @param callback - callback function when texture is created (self, request_id, resource)
641
+ * @example
642
+ * ```ts
643
+ * // Create a texture resource asyncronously with a buffer and a callback
644
+ * function callback(self, request_id, resource) {
645
+ * // The resource has been updated with a new texture,
646
+ * // so we can update other systems with the new handle,
647
+ * // or update components to use the resource if we want
648
+ * const tinfo = resource.get_texture_info(resource);
649
+ * msg.post("@render:", "set_backing_texture", tinfo.handle);
650
+ * }
651
+ *
652
+ * export default defineScript({
653
+ * init() {
654
+ * // Create a texture resource async
655
+ * const tparams = {
656
+ * width: 128,
657
+ * height: 128,
658
+ * type: graphics.TEXTURE_TYPE_2D,
659
+ * format: graphics.TEXTURE_FORMAT_RGBA,
660
+ * };
661
+ *
662
+ * // Create a new buffer with 4 components
663
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
664
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
665
+ *
666
+ * // Fill the buffer stream with some float values
667
+ * for (let y = 0; y < tparams.width; y++) {
668
+ * for (let x = 0; x < tparams.height; x++) {
669
+ * const index = y * 128 * 4 + x * 4;
670
+ * tstream[index + 0] = 255;
671
+ * tstream[index + 1] = 0;
672
+ * tstream[index + 2] = 255;
673
+ * tstream[index + 3] = 255;
674
+ * }
675
+ * }
676
+ * // create the texture
677
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, callback);
678
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
679
+ * // that will be removed once the new texture has been updated
680
+ * go.set("#model", "texture0", tpath);
681
+ * },
682
+ * });
683
+ *
684
+ * // Create a texture resource asyncronously without a callback
685
+ * export default defineScript({
686
+ * init() {
687
+ * // Create a texture resource async
688
+ * const tparams = {
689
+ * width: 128,
690
+ * height: 128,
691
+ * type: graphics.TEXTURE_TYPE_2D,
692
+ * format: graphics.TEXTURE_FORMAT_RGBA,
693
+ * };
694
+ *
695
+ * // Create a new buffer with 4 components
696
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
697
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
698
+ *
699
+ * // Fill the buffer stream with some float values
700
+ * for (let y = 0; y < tparams.width; y++) {
701
+ * for (let x = 0; x < tparams.height; x++) {
702
+ * const index = y * 128 * 4 + x * 4;
703
+ * tstream[index + 0] = 255;
704
+ * tstream[index + 1] = 0;
705
+ * tstream[index + 2] = 255;
706
+ * tstream[index + 3] = 255;
707
+ * }
708
+ * }
709
+ * // create the texture
710
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer);
711
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
712
+ * // that will be removed once the new texture has been updated
713
+ * go.set("#model", "texture0", tpath);
714
+ * },
715
+ * });
716
+ * ```
717
+ */
718
+ function create_texture_async(path: string | Hash, table: { type?: number; width?: number; height?: number; depth?: number; format?: number; flags?: number; max_mipmaps?: number; compression_type?: number }, buffer: Opaque<"buffer">, callback: (...args: unknown[]) => unknown): LuaMultiReturn<[Hash, number]>;
719
+ /**
720
+ * Constructor-like function with two purposes:
721
+ *
722
+ * - Load the specified resource as part of loading the script
723
+ *
724
+ * - Return a hash to the run-time version of the resource
725
+ *
726
+ * This function can only be called within go.property function calls.
727
+ *
728
+ * @param path - optional resource path string to the resource
729
+ * @returns a path hash to the binary version of the resource
730
+ * @example
731
+ * ```ts
732
+ * // Load a font and set it to a label:
733
+ * go.property("my_font", resource.font("/font.font"));
734
+ *
735
+ * export default defineScript({
736
+ * init(self) {
737
+ * go.set("#label", "font", self.my_font);
738
+ * },
739
+ * });
740
+ *
741
+ * // Load a font and set it to a gui:
742
+ * go.property("my_font", resource.font("/font.font"));
743
+ *
744
+ * export default defineScript({
745
+ * init(self) {
746
+ * go.set("#gui", "fonts", self.my_font, { key: "my_font" });
747
+ * },
748
+ * });
749
+ * ```
750
+ */
751
+ function font(path?: string): Hash;
752
+ /**
753
+ * Returns the atlas data for an atlas
754
+ *
755
+ * @param path - The path to the atlas resource
756
+ * @returns A table with the following entries:
757
+ *
758
+ * - texture
759
+ *
760
+ * - geometries
761
+ *
762
+ * - animations
763
+ *
764
+ * Each animation entry also contains a `frames` table with indices into
765
+ * `geometries`, preserving the frame-to-geometry mapping used by the atlas.
766
+ * See resource.set_atlas for a detailed description of each field
767
+ */
768
+ function get_atlas(path: Hash | string): { texture: string | Hash; animations: { id: string; width: number; height: number; frame_start: number; frame_end: number; playback: Opaque<"constant">; fps: number; flip_vertical: boolean; flip_horizontal: boolean }[]; geometries: { vertices: number[]; uvs: number[]; indices: number[] }[] };
769
+ /**
770
+ * gets the buffer from a resource
771
+ *
772
+ * @param path - The path to the resource
773
+ * @returns The resource buffer
774
+ * @example
775
+ * ```ts
776
+ * // How to get the data from a buffer
777
+ * export default defineScript({
778
+ * init() {
779
+ * const res_path = go.get("#mesh", "vertices");
780
+ * const buf = resource.get_buffer(res_path);
781
+ * const stream_positions = buffer.get_stream(buf, "position");
782
+ *
783
+ * for (let i = 0; i < stream_positions.length; i++) {
784
+ * print(i, stream_positions[i]);
785
+ * }
786
+ * },
787
+ * });
788
+ * ```
789
+ */
790
+ function get_buffer(path: Hash | string): Opaque<"buffer">;
791
+ /**
792
+ * Gets render target info from a render target resource path or a render target handle
793
+ *
794
+ * @param path - The path to the resource or a render target handle
795
+ * @returns A table containing info about the render target:
796
+ *
797
+ * `handle`
798
+ * number the opaque handle to the texture resource
799
+ * 'attachments'
800
+ * table a table of attachments, where each attachment contains the following entries:
801
+ * `width`
802
+ * number width of the texture
803
+ * `height`
804
+ * number height of the texture
805
+ * `depth`
806
+ * number depth of the texture (i.e 1 for a 2D texture and 6 for a cube map)
807
+ * `mipmaps`
808
+ * number number of mipmaps of the texture
809
+ * `type`
810
+ * number The texture type. Supported values:
811
+ *
812
+ * - `graphics.TEXTURE_TYPE_2D`
813
+ *
814
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
815
+ *
816
+ * - `graphics.TEXTURE_TYPE_2D_ARRAY`
817
+ *
818
+ * `buffer_type`
819
+ * number The attachment buffer type. Supported values:
820
+ *
821
+ * - `resource.BUFFER_TYPE_COLOR0`
822
+ *
823
+ * - `resource.BUFFER_TYPE_COLOR1`
824
+ *
825
+ * - `resource.BUFFER_TYPE_COLOR2`
826
+ *
827
+ * - `resource.BUFFER_TYPE_COLOR3`
828
+ *
829
+ * - `resource.BUFFER_TYPE_DEPTH`
830
+ *
831
+ * -
832
+ * `resource.BUFFER_TYPE_STENCIL`
833
+ *
834
+ * -
835
+ *
836
+ * `texture`
837
+ * hash The hashed path to the attachment texture resource. This field is only available if the render target passed in is a resource.
838
+ * @example
839
+ * ```ts
840
+ * // Get the metadata from a render target resource
841
+ * export default defineScript({
842
+ * init() {
843
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
844
+ * // the info table contains meta data about all the render target attachments
845
+ * // so it's not necessary to use resource.get_texture here, but we do it here
846
+ * // just to show that it's possible:
847
+ * const info_attachment_1 = resource.get_texture_info(info.attachments[0].handle);
848
+ * },
849
+ * });
850
+ *
851
+ * // Get a texture attachment from a render target and set it on a model component
852
+ * export default defineScript({
853
+ * init() {
854
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
855
+ * const attachment = info.attachments[0].texture;
856
+ * // you can also get texture info from the 'texture' field, since it's a resource hash
857
+ * const texture_info = resource.get_texture_info(attachment);
858
+ * go.set("#model", "texture0", attachment);
859
+ * },
860
+ * });
861
+ * ```
862
+ */
863
+ function get_render_target_info(path: Hash | string | number): { handle: number; width: number; height: number; depth: number; mipmaps: number; type: number; buffer_type: number; texture: Hash };
864
+ /**
865
+ * Gets the text metrics from a font
866
+ *
867
+ * @param url - the font to get the (unscaled) metrics from
868
+ * @param text - text to measure
869
+ * @param options - A table containing parameters for the text. Supported entries:
870
+ *
871
+ * `width`
872
+ * number The width of the text field. Not used if `line_break` is false.
873
+ * `leading`
874
+ * number The leading (default 1.0)
875
+ * `tracking`
876
+ * number The tracking (default 0.0)
877
+ * `line_break`
878
+ * boolean If the calculation should consider line breaks (default false)
879
+ * @returns a table with the following fields:
880
+ *
881
+ * - width
882
+ *
883
+ * - height
884
+ *
885
+ * - max_ascent
886
+ *
887
+ * - max_descent
888
+ * @example
889
+ * ```ts
890
+ * export default defineScript({
891
+ * init() {
892
+ * const font = go.get("#label", "font");
893
+ * const metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog");
894
+ * pprint(metrics);
895
+ * },
896
+ * });
897
+ * ```
898
+ */
899
+ function get_text_metrics(url: Hash, text: string, options?: { width?: number; leading?: number; tracking?: number; line_break?: boolean }): { width: number; height: number; max_ascent: number; max_descent: number };
900
+ /**
901
+ * Gets texture info from a texture resource path or a texture handle
902
+ *
903
+ * @param path - The path to the resource or a texture handle
904
+ * @returns A table containing info about the texture:
905
+ *
906
+ * `handle`
907
+ * number the opaque handle to the texture resource
908
+ * `width`
909
+ * number width of the texture
910
+ * `height`
911
+ * number height of the texture
912
+ * `depth`
913
+ * number depth of the texture (i.e 1 for a 2D texture, 6 for a cube map, the actual depth of a 3D texture)
914
+ * `page_count`
915
+ * number number of pages of the texture array. For 2D texture value is 1. For cube map - 6
916
+ * `mipmaps`
917
+ * number number of mipmaps of the texture
918
+ * `flags`
919
+ * number usage hints of the texture.
920
+ * `type`
921
+ * number The texture type. Supported values:
922
+ *
923
+ * - `graphics.TEXTURE_TYPE_2D`
924
+ *
925
+ * - `graphics.TEXTURE_TYPE_2D_ARRAY`
926
+ *
927
+ * - `graphics.TEXTURE_TYPE_IMAGE_2D`
928
+ *
929
+ * - `graphics.TEXTURE_TYPE_3D`
930
+ *
931
+ * - `graphics.TEXTURE_TYPE_IMAGE_3D`
932
+ *
933
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
934
+ * @example
935
+ * ```ts
936
+ * // Create a new texture and get the metadata from it
937
+ * export default defineScript({
938
+ * init() {
939
+ * // create an empty texture
940
+ * const tparams = {
941
+ * width: 128,
942
+ * height: 128,
943
+ * type: graphics.TEXTURE_TYPE_2D,
944
+ * format: graphics.TEXTURE_FORMAT_RGBA,
945
+ * };
946
+ *
947
+ * const my_texture_path = resource.create_texture("/my_texture.texturec", tparams);
948
+ * const my_texture_info = resource.get_texture_info(my_texture_path);
949
+ *
950
+ * // my_texture_info now contains
951
+ * // {
952
+ * // handle = <the-numeric-handle>,
953
+ * // width = 128,
954
+ * // height = 128,
955
+ * // depth = 1
956
+ * // mipmaps = 1,
957
+ * // page_count = 1,
958
+ * // type = graphics.TEXTURE_TYPE_2D,
959
+ * // flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE
960
+ * // }
961
+ * },
962
+ * });
963
+ *
964
+ * // Get the meta data from an atlas resource
965
+ * export default defineScript({
966
+ * init() {
967
+ * const my_atlas_info = resource.get_atlas("/my_atlas.a.texturesetc");
968
+ * const my_texture_info = resource.get_texture_info(my_atlas_info.texture);
969
+ *
970
+ * // my_texture_info now contains the information about the texture that is backing the atlas
971
+ * },
972
+ * });
973
+ * ```
974
+ */
975
+ function get_texture_info(path: Hash | string | number): { handle: number; width: number; height: number; depth: number; page_count: number; mipmaps: number; flags: number; type: number };
976
+ /**
977
+ * Loads the resource data for a specific resource.
978
+ *
979
+ * @param path - The path to the resource
980
+ * @returns Returns the buffer stored on disc
981
+ * @example
982
+ * ```ts
983
+ * // read custom resource data into buffer
984
+ * const buffer = resource.load("/resources/datafile");
985
+ *
986
+ * // In order for the engine to include custom resources in the build process, you
987
+ * // need to specify them in the "game.project" settings file:
988
+ * // [project]
989
+ * // title = My project
990
+ * // version = 0.1
991
+ * // custom_resources = resources/,assets/level_data.json
992
+ * ```
993
+ */
994
+ function load(path: string): Opaque<"buffer">;
995
+ /**
996
+ * Constructor-like function with two purposes:
997
+ *
998
+ * - Load the specified resource as part of loading the script
999
+ *
1000
+ * - Return a hash to the run-time version of the resource
1001
+ *
1002
+ * This function can only be called within go.property function calls.
1003
+ *
1004
+ * @param path - optional resource path string to the resource
1005
+ * @returns a path hash to the binary version of the resource
1006
+ * @example
1007
+ * ```ts
1008
+ * // Load a material and set it to a sprite:
1009
+ * go.property("my_material", resource.material("/material.material"));
1010
+ *
1011
+ * export default defineScript({
1012
+ * init(self) {
1013
+ * go.set("#sprite", "material", self.my_material);
1014
+ * },
1015
+ * });
1016
+ *
1017
+ * // Load a material resource and update a named material with the resource:
1018
+ * go.property("my_material", resource.material("/material.material"));
1019
+ *
1020
+ * export default defineScript({
1021
+ * init(self) {
1022
+ * go.set("#gui", "materials", self.my_material, { key: "my_material" });
1023
+ * },
1024
+ * });
1025
+ * ```
1026
+ */
1027
+ function material(path?: string): Hash;
1028
+ /**
1029
+ * Release a resource.
1030
+ * This is a potentially dangerous operation, releasing resources currently being used can cause unexpected behaviour.
1031
+ *
1032
+ * @param path - The path to the resource.
1033
+ */
1034
+ function release(path: Hash | string): void;
1035
+ /**
1036
+ * Constructor-like function with two purposes:
1037
+ *
1038
+ * - Load the specified resource as part of loading the script
1039
+ *
1040
+ * - Return a hash to the run-time version of the resource
1041
+ *
1042
+ * This function can only be called within go.property function calls.
1043
+ *
1044
+ * @param path - optional resource path string to the resource
1045
+ * @returns a path hash to the binary version of the resource
1046
+ * @example
1047
+ * ```ts
1048
+ * // Set a render target color attachment as a model texture:
1049
+ * go.property("my_render_target", resource.render_target("/rt.render_target"));
1050
+ *
1051
+ * export default defineScript({
1052
+ * init(self) {
1053
+ * const rt_info = resource.get_render_target_info(self.my_render_target);
1054
+ * go.set("#model", "texture0", rt_info.attachments[0].texture);
1055
+ * },
1056
+ * });
1057
+ * ```
1058
+ */
1059
+ function render_target(path?: string): Hash;
1060
+ /**
1061
+ * Sets the resource data for a specific resource
1062
+ *
1063
+ * @param path - The path to the resource
1064
+ * @param buffer - The buffer of precreated data, suitable for the intended resource type
1065
+ * @example
1066
+ * ```ts
1067
+ * // Assuming the folder "/res" is added to the project custom resources:
1068
+ * // load a texture resource and set it on a sprite
1069
+ * const buffer = resource.load("/res/new.texturec");
1070
+ * resource.set(go.get("#sprite", "texture0"), buffer);
1071
+ * ```
1072
+ */
1073
+ function set(path: string | Hash, buffer: Opaque<"buffer">): void;
1074
+ /**
1075
+ * Sets the data for a specific atlas resource. Setting new atlas data is specified by passing in
1076
+ * a texture path for the backing texture of the atlas, a list of geometries and a list of animations
1077
+ * that map to the entries in the geometry list. The geometry entries are represented by three lists:
1078
+ * vertices, uvs and indices that together represent triangles that are used in other parts of the
1079
+ * engine to produce render objects from.
1080
+ * Vertex and uv coordinates for the geometries are expected to be
1081
+ * in pixel coordinates where 0,0 is the top left corner of the texture.
1082
+ * There is no automatic padding or margin support when setting custom data,
1083
+ * which could potentially cause filtering artifacts if used with a material sampler that has linear filtering.
1084
+ * If that is an issue, you need to calculate padding and margins manually before passing in the geometry data to
1085
+ * this function.
1086
+ *
1087
+ * @param path - The path to the atlas resource
1088
+ * @param table - A table containing info about the atlas. Supported entries:
1089
+ *
1090
+ * -
1091
+ *
1092
+ * `texture`
1093
+ * string | hash the path to the texture resource, e.g "/main/my_texture.texturec"
1094
+ *
1095
+ * -
1096
+ *
1097
+ * `animations`
1098
+ * table a list of the animations in the atlas. Supports the following fields:
1099
+ *
1100
+ * -
1101
+ *
1102
+ * `id`
1103
+ * string the id of the animation, used in e.g sprite.play_animation
1104
+ *
1105
+ * -
1106
+ *
1107
+ * `width`
1108
+ * number the width of the animation
1109
+ *
1110
+ * -
1111
+ *
1112
+ * `height`
1113
+ * number the height of the animation
1114
+ *
1115
+ * -
1116
+ *
1117
+ * `frame_start`
1118
+ * number index to the first geometry of the animation. Indices are lua based and must be in the range of 1 .. in atlas.
1119
+ *
1120
+ * -
1121
+ *
1122
+ * `frame_end`
1123
+ * number index to the last geometry of the animation (non-inclusive). Indices are lua based and must be in the range of 1 .. in atlas.
1124
+ *
1125
+ * -
1126
+ *
1127
+ * `playback`
1128
+ * constant optional playback mode of the animation, the default value is go.PLAYBACK_ONCE_FORWARD
1129
+ *
1130
+ * -
1131
+ *
1132
+ * `fps`
1133
+ * number optional fps of the animation, the default value is 30
1134
+ *
1135
+ * -
1136
+ *
1137
+ * `flip_vertical`
1138
+ * boolean optional flip the animation vertically, the default value is false
1139
+ *
1140
+ * -
1141
+ *
1142
+ * `flip_horizontal`
1143
+ * boolean optional flip the animation horizontally, the default value is false
1144
+ *
1145
+ * -
1146
+ *
1147
+ * `geometries`
1148
+ * table A list of the geometries that should map to the texture data. Supports the following fields:
1149
+ *
1150
+ * -
1151
+ *
1152
+ * `vertices`
1153
+ * table a list of the vertices in texture space of the geometry in the form {px0, py0, px1, py1, ..., pxn, pyn}
1154
+ *
1155
+ * -
1156
+ *
1157
+ * `uvs`
1158
+ * table a list of the uv coordinates in texture space of the geometry in the form of {u0, v0, u1, v1, ..., un, vn}
1159
+ *
1160
+ * -
1161
+ *
1162
+ * `indices`
1163
+ * table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
1164
+ * @example
1165
+ * ```ts
1166
+ * // Add a new animation to an existing atlas
1167
+ * export default defineScript({
1168
+ * init() {
1169
+ * const data = resource.get_atlas("/main/my_atlas.a.texturesetc");
1170
+ * const my_animation = {
1171
+ * id: "my_new_animation",
1172
+ * width: 128,
1173
+ * height: 128,
1174
+ * frame_start: 1,
1175
+ * frame_end: 6,
1176
+ * playback: go.PLAYBACK_LOOP_PINGPONG,
1177
+ * fps: 8,
1178
+ * };
1179
+ * data.animations.push(my_animation);
1180
+ * resource.set_atlas("/main/my_atlas.a.texturesetc", data);
1181
+ * },
1182
+ * });
1183
+ *
1184
+ * // Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
1185
+ * export default defineScript({
1186
+ * init() {
1187
+ * const params = {
1188
+ * texture: "/main/my_256x256_texture.texturec",
1189
+ * animations: [
1190
+ * {
1191
+ * id: "my_animation",
1192
+ * width: 256,
1193
+ * height: 256,
1194
+ * frames: [1],
1195
+ * },
1196
+ * ],
1197
+ * geometries: [
1198
+ * {
1199
+ * vertices: [0, 0, 0, 256, 256, 256, 256, 0],
1200
+ * uvs: [0, 0, 0, 256, 256, 256, 256, 0],
1201
+ * indices: [0, 1, 2, 0, 2, 3],
1202
+ * },
1203
+ * ],
1204
+ * };
1205
+ * resource.set_atlas("/main/test.a.texturesetc", params);
1206
+ * },
1207
+ * });
1208
+ * ```
1209
+ */
1210
+ function set_atlas(path: Hash | string, table: { texture?: string | Hash; animations?: { id?: string; width?: number; height?: number; frame_start?: number; frame_end?: number; playback?: Opaque<"constant">; fps?: number; flip_vertical?: boolean; flip_horizontal?: boolean }[]; geometries?: { vertices?: number[]; uvs?: number[]; indices?: number[] }[]; vertices?: number[]; uvs?: number[]; indices?: number[] }): void;
1211
+ /**
1212
+ * Sets the buffer of a resource. By default, setting the resource buffer will either copy the data from the incoming buffer object
1213
+ * to the buffer stored in the destination resource, or make a new buffer object if the sizes between the source buffer and the destination buffer
1214
+ * stored in the resource differs. In some cases, e.g performance reasons, it might be beneficial to just set the buffer object on the resource without copying or cloning.
1215
+ * To achieve this, set the `transfer_ownership` flag to true in the argument table. Transferring ownership from a lua buffer to a resource with this function
1216
+ * works exactly the same as resource.create_buffer: the destination resource will take ownership of the buffer held by the lua reference, i.e the buffer will not automatically be removed
1217
+ * when the lua reference to the buffer is garbage collected.
1218
+ * Note: When setting a buffer with `transfer_ownership = true`, the currently bound buffer in the resource will be destroyed.
1219
+ *
1220
+ * @param path - The path to the resource
1221
+ * @param buffer - The resource buffer
1222
+ * @param table - A table containing info about how to set the buffer. Supported entries:
1223
+ *
1224
+ * -
1225
+ *
1226
+ * `transfer_ownership`
1227
+ * boolean optional flag to determine whether or not the resource should take over ownership of the buffer object (default false)
1228
+ * @example
1229
+ * ```ts
1230
+ * // How to set the data from a buffer
1231
+ * function fill_stream(stream, verts) {
1232
+ * verts.forEach((value, key) => {
1233
+ * stream[key] = verts[key];
1234
+ * });
1235
+ * }
1236
+ *
1237
+ * export default defineScript({
1238
+ * init() {
1239
+ * const res_path = go.get("#mesh", "vertices");
1240
+ *
1241
+ * const positions = [
1242
+ * 1, -1, 0,
1243
+ * 1, 1, 0,
1244
+ * -1, -1, 0,
1245
+ * ];
1246
+ *
1247
+ * const num_verts = positions.length / 3;
1248
+ *
1249
+ * // create a new buffer
1250
+ * let buf = buffer.create(num_verts, [{ name: hash("position"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);
1251
+ *
1252
+ * buf = resource.get_buffer(res_path);
1253
+ * const stream_positions = buffer.get_stream(buf, "position");
1254
+ *
1255
+ * fill_stream(stream_positions, positions);
1256
+ *
1257
+ * resource.set_buffer(res_path, buf);
1258
+ * },
1259
+ * });
1260
+ * ```
1261
+ */
1262
+ function set_buffer(path: Hash | string, buffer: Opaque<"buffer">, table?: { transfer_ownership?: boolean }): void;
1263
+ /**
1264
+ * Update internal sound resource (wavc/oggc/opusc) with new data
1265
+ *
1266
+ * @param path - The path to the resource
1267
+ * @param buffer - A lua string containing the binary sound data
1268
+ */
1269
+ function set_sound(path: Hash | string, buffer: string): void;
1270
+ /**
1271
+ * Sets the pixel data for a specific texture.
1272
+ *
1273
+ * @param path - The path to the resource
1274
+ * @param table - A table containing info about the texture. Supported entries:
1275
+ *
1276
+ * `type`
1277
+ * number The texture type. Supported values:
1278
+ *
1279
+ * - `graphics.TEXTURE_TYPE_2D`
1280
+ *
1281
+ * - `graphics.TEXTURE_TYPE_IMAGE_2D`
1282
+ *
1283
+ * - `graphics.TEXTURE_TYPE_3D`
1284
+ *
1285
+ * - `graphics.TEXTURE_TYPE_IMAGE_3D`
1286
+ *
1287
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
1288
+ *
1289
+ * `width`
1290
+ * number The width of the texture (in pixels)
1291
+ * `height`
1292
+ * number The width of the texture (in pixels)
1293
+ * `format`
1294
+ * number The texture format, note that some of these formats are platform specific. Supported values:
1295
+ *
1296
+ * - `graphics.TEXTURE_FORMAT_LUMINANCE`
1297
+ *
1298
+ * - `graphics.TEXTURE_FORMAT_RGB`
1299
+ *
1300
+ * - `graphics.TEXTURE_FORMAT_RGBA`
1301
+ *
1302
+ * These constants might not be available on the device:
1303
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
1304
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
1305
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
1306
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
1307
+ * - `graphics.TEXTURE_FORMAT_RGB_ETC1`
1308
+ * - `graphics.TEXTURE_FORMAT_RGBA_ETC2`
1309
+ * - `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
1310
+ * - `graphics.TEXTURE_FORMAT_RGB_BC1`
1311
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC3`
1312
+ * - `graphics.TEXTURE_FORMAT_R_BC4`
1313
+ * - `graphics.TEXTURE_FORMAT_RG_BC5`
1314
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC7`
1315
+ * - `graphics.TEXTURE_FORMAT_RGB16F`
1316
+ * - `graphics.TEXTURE_FORMAT_RGB32F`
1317
+ * - `graphics.TEXTURE_FORMAT_RGBA16F`
1318
+ * - `graphics.TEXTURE_FORMAT_RGBA32F`
1319
+ * - `graphics.TEXTURE_FORMAT_R16F`
1320
+ * - `graphics.TEXTURE_FORMAT_RG16F`
1321
+ * - `graphics.TEXTURE_FORMAT_R32F`
1322
+ * - `graphics.TEXTURE_FORMAT_RG32F`
1323
+ * You can test if the device supports these values by checking if a specific enum is nil or not:
1324
+ *
1325
+ * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
1326
+ * -- it is safe to use this format
1327
+ * end
1328
+ * `
1329
+ *
1330
+ * `x`
1331
+ * number optional x offset of the texture (in pixels)
1332
+ * `y`
1333
+ * number optional y offset of the texture (in pixels)
1334
+ * `z`
1335
+ * number optional z offset of the texture (in pixels). Only applies to 3D textures
1336
+ * `page`
1337
+ * number optional slice of the array texture. Only applies to 2D texture arrays. Zero-based
1338
+ * `mipmap`
1339
+ * number optional mipmap to upload the data to
1340
+ * `compression_type`
1341
+ * number optional specify the compression type for the data in the buffer object that holds the texture data. Defaults to graphics.COMPRESSION_TYPE_DEFAULT, i.e no compression. Supported values:
1342
+ *
1343
+ * - `COMPRESSION_TYPE_DEFAULT`
1344
+ *
1345
+ * - `COMPRESSION_TYPE_BASIS_UASTC`
1346
+ * @param buffer - The buffer of precreated pixel data
1347
+ * To update a cube map texture you need to pass in six times the amount of data via the buffer, since a cube map has six sides!
1348
+ * 3D Textures are currently only supported on OpenGL and Vulkan adapters. To check if your device supports 3D textures, use:
1349
+ * ```lua
1350
+ * if graphics.TEXTURE_TYPE_3D ~= nil then
1351
+ * -- Device and graphics adapter support 3D textures
1352
+ * end
1353
+ * @example
1354
+ * ```ts
1355
+ * // How to set all pixels of an atlas
1356
+ * export default defineScript({
1357
+ * init(self) {
1358
+ * self.height = 128;
1359
+ * self.width = 128;
1360
+ * self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1361
+ * self.stream = buffer.get_stream(self.buffer, hash("rgb"));
1362
+ *
1363
+ * for (let y = 0; y < self.height; y++) {
1364
+ * for (let x = 0; x < self.width; x++) {
1365
+ * const index = y * self.width * 3 + x * 3;
1366
+ * self.stream[index + 0] = 0xff;
1367
+ * self.stream[index + 1] = 0x80;
1368
+ * self.stream[index + 2] = 0x10;
1369
+ * }
1370
+ * }
1371
+ *
1372
+ * const resource_path = go.get("#model", "texture0");
1373
+ * const args = { width: self.width, height: self.height, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
1374
+ * resource.set_texture(resource_path, args, self.buffer);
1375
+ * },
1376
+ * });
1377
+ *
1378
+ * // How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
1379
+ * export default defineScript({
1380
+ * init(self) {
1381
+ * self.x = 16;
1382
+ * self.y = 16;
1383
+ * self.height = 128 - self.x * 2;
1384
+ * self.width = 128 - self.y * 2;
1385
+ * self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
1386
+ * self.stream = buffer.get_stream(self.buffer, hash("rgb"));
1387
+ *
1388
+ * for (let y = 0; y < self.height; y++) {
1389
+ * for (let x = 0; x < self.width; x++) {
1390
+ * const index = y * self.width * 3 + x * 3;
1391
+ * self.stream[index + 0] = 0xff;
1392
+ * self.stream[index + 1] = 0x80;
1393
+ * self.stream[index + 2] = 0x10;
1394
+ * }
1395
+ * }
1396
+ *
1397
+ * const resource_path = go.get("#model", "texture0");
1398
+ * const args = { width: self.width, height: self.height, x: self.x, y: self.y, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
1399
+ * resource.set_texture(resource_path, args, self.buffer);
1400
+ * },
1401
+ * });
1402
+ *
1403
+ * // Update a texture from a buffer resource
1404
+ * go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"));
1405
+ *
1406
+ * export default defineScript({
1407
+ * init(self) {
1408
+ * const resource_path = go.get("#model", "texture0");
1409
+ * // the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
1410
+ * const args = {
1411
+ * width: 128,
1412
+ * height: 128,
1413
+ * type: graphics.TEXTURE_TYPE_2D,
1414
+ * format: graphics.TEXTURE_FORMAT_RGB,
1415
+ * };
1416
+ * // Note that the extra resource.get_buffer call is a requirement here
1417
+ * // since the "self.my_buffer" is just pointing to a buffer resource path
1418
+ * // and not an actual buffer object or buffer resource.
1419
+ * resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));
1420
+ * },
1421
+ * });
1422
+ *
1423
+ * // Update an existing 3D texture from a buffer
1424
+ * export default defineScript({
1425
+ * init() {
1426
+ * // create a buffer that can hold the data of a 8x8x8 texture
1427
+ * const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
1428
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
1429
+ *
1430
+ * // populate the buffer with some data
1431
+ * let index = 0;
1432
+ * for (let z = 0; z < 8; z++) {
1433
+ * for (let y = 0; y < 8; y++) {
1434
+ * for (let x = 0; x < 8; x++) {
1435
+ * tstream[index + 0] = x;
1436
+ * tstream[index + 1] = y;
1437
+ * tstream[index + 2] = z;
1438
+ * tstream[index + 3] = 1.0;
1439
+ * index = index + 4;
1440
+ * }
1441
+ * }
1442
+ * }
1443
+ *
1444
+ * const t_args = {
1445
+ * type: graphics.TEXTURE_TYPE_IMAGE_3D,
1446
+ * width: 8,
1447
+ * height: 8,
1448
+ * depth: 8,
1449
+ * format: resource.TEXTURE_FORMAT_RGBA32F,
1450
+ * };
1451
+ *
1452
+ * // This expects that the texture resource "/my_3d_texture.texturec" already exists
1453
+ * // and is a 3D texture resource. To create a dynamic 3D texture resource
1454
+ * // use the "resource.create_texture" function.
1455
+ * resource.set_texture("/my_3d_texture.texturec", t_args, tbuffer);
1456
+ * },
1457
+ * });
1458
+ *
1459
+ * // Update texture 2nd array page with loaded texture from png
1460
+ * // new_tex is resource handle of texture which was created via resource.create_resource
1461
+ * const tex_path = "/bundle_resources/page_02.png";
1462
+ * const [data] = sys.load_resource(tex_path);
1463
+ * const buf = image.load_buffer(data);
1464
+ * resource.set_texture(
1465
+ * new_tex,
1466
+ * {
1467
+ * type: graphics.TEXTURE_TYPE_2D_ARRAY,
1468
+ * width: buf.width,
1469
+ * height: buf.height,
1470
+ * page: 1,
1471
+ * format: graphics.TEXTURE_FORMAT_RGB,
1472
+ * },
1473
+ * buf.buffer,
1474
+ * );
1475
+ * go.set("#mesh", "texture0", new_tex);
1476
+ * ```
1477
+ */
1478
+ function set_texture(path: Hash | string, table: { type?: number; width?: number; height?: number; format?: number; x?: number; y?: number; z?: number; page?: number; mipmap?: number; compression_type?: number }, buffer: Opaque<"buffer">): void;
1479
+ /**
1480
+ * Constructor-like function with two purposes:
1481
+ *
1482
+ * - Load the specified resource as part of loading the script
1483
+ *
1484
+ * - Return a hash to the run-time version of the resource
1485
+ *
1486
+ * This function can only be called within go.property function calls.
1487
+ *
1488
+ * @param path - optional resource path string to the resource
1489
+ * @returns a path hash to the binary version of the resource
1490
+ * @example
1491
+ * ```ts
1492
+ * // Load a texture and set it to a model:
1493
+ * go.property("my_texture", resource.texture("/texture.png"));
1494
+ *
1495
+ * export default defineScript({
1496
+ * init(self) {
1497
+ * go.set("#model", "texture0", self.my_texture);
1498
+ * },
1499
+ * });
1500
+ * ```
1501
+ */
1502
+ function texture(path?: string): Hash;
1503
+ /**
1504
+ * Constructor-like function with two purposes:
1505
+ *
1506
+ * - Load the specified resource as part of loading the script
1507
+ *
1508
+ * - Return a hash to the run-time version of the resource
1509
+ *
1510
+ * This function can only be called within go.property function calls.
1511
+ *
1512
+ * @param path - optional resource path string to the resource
1513
+ * @returns a path hash to the binary version of the resource
1514
+ * @example
1515
+ * ```ts
1516
+ * // Load tile source and set it to a tile map:
1517
+ * go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"));
1518
+ *
1519
+ * export default defineScript({
1520
+ * init(self) {
1521
+ * go.set("#tilemap", "tile_source", self.my_tile_source);
1522
+ * },
1523
+ * });
1524
+ * ```
1525
+ */
1526
+ function tile_source(path?: string): Hash;
1527
+ }
1528
+ }
1529
+
1530
+ export {};