@defold-typescript/types 0.19.4 → 0.20.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 (86) hide show
  1. package/api-availability.json +2755 -0
  2. package/api-migrations.json +31 -0
  3. package/api-signatures.json +2324 -0
  4. package/api-targets.json +493 -45
  5. package/generated/b2d.d.ts +6 -0
  6. package/generated/b2d_body.d.ts +329 -1
  7. package/generated/b2d_chain.d.ts +106 -0
  8. package/generated/b2d_fixture.d.ts +155 -0
  9. package/generated/b2d_joint.d.ts +823 -0
  10. package/generated/b2d_shape.d.ts +215 -0
  11. package/generated/b2d_world.d.ts +314 -0
  12. package/generated/builtin-messages.d.ts +18 -0
  13. package/generated/camera.d.ts +62 -5
  14. package/generated/compute.d.ts +306 -0
  15. package/generated/go.d.ts +29 -4
  16. package/generated/graphics.d.ts +95 -0
  17. package/generated/gui.d.ts +1 -3
  18. package/generated/json.d.ts +2 -2
  19. package/generated/kinds/gui-script.d.ts +7 -0
  20. package/generated/kinds/render-script.d.ts +7 -0
  21. package/generated/kinds/script.d.ts +7 -0
  22. package/generated/label.d.ts +1 -1
  23. package/generated/liveupdate.d.ts +22 -4
  24. package/generated/material.d.ts +444 -0
  25. package/generated/model.d.ts +46 -5
  26. package/generated/physics.d.ts +1 -3
  27. package/generated/profiler.d.ts +2 -3
  28. package/generated/render.d.ts +25 -9
  29. package/generated/resource.d.ts +2 -2
  30. package/generated/sprite.d.ts +15 -1
  31. package/generated/tilemap.d.ts +14 -0
  32. package/generated/versions/defold-1.12.4/b2d.d.ts +27 -0
  33. package/generated/versions/defold-1.12.4/b2d_body.d.ts +348 -0
  34. package/generated/versions/defold-1.12.4/buffer.d.ts +176 -0
  35. package/generated/versions/defold-1.12.4/camera.d.ts +245 -0
  36. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +146 -0
  37. package/generated/versions/defold-1.12.4/collectionproxy.d.ts +71 -0
  38. package/generated/versions/defold-1.12.4/crash.d.ts +143 -0
  39. package/generated/versions/defold-1.12.4/factory.d.ts +123 -0
  40. package/generated/versions/defold-1.12.4/font.d.ts +81 -0
  41. package/generated/versions/defold-1.12.4/go.d.ts +1029 -0
  42. package/generated/versions/defold-1.12.4/graphics.d.ts +226 -0
  43. package/generated/versions/defold-1.12.4/gui.d.ts +2372 -0
  44. package/generated/versions/defold-1.12.4/html5.d.ts +53 -0
  45. package/generated/versions/defold-1.12.4/http.d.ts +84 -0
  46. package/generated/versions/defold-1.12.4/iac.d.ts +18 -0
  47. package/generated/versions/defold-1.12.4/iap.d.ts +60 -0
  48. package/generated/versions/defold-1.12.4/image.d.ts +139 -0
  49. package/generated/versions/defold-1.12.4/index.d.ts +41 -0
  50. package/generated/versions/defold-1.12.4/json.d.ts +76 -0
  51. package/generated/versions/defold-1.12.4/label.d.ts +94 -0
  52. package/generated/versions/defold-1.12.4/liveupdate.d.ts +122 -0
  53. package/generated/versions/defold-1.12.4/model.d.ts +205 -0
  54. package/generated/versions/defold-1.12.4/msg.d.ts +10 -0
  55. package/generated/versions/defold-1.12.4/particlefx.d.ts +166 -0
  56. package/generated/versions/defold-1.12.4/physics.d.ts +547 -0
  57. package/generated/versions/defold-1.12.4/profiler.d.ts +234 -0
  58. package/generated/versions/defold-1.12.4/push.d.ts +66 -0
  59. package/generated/versions/defold-1.12.4/render.d.ts +1149 -0
  60. package/generated/versions/defold-1.12.4/resource.d.ts +1518 -0
  61. package/generated/versions/defold-1.12.4/socket.d.ts +795 -0
  62. package/generated/versions/defold-1.12.4/sound.d.ts +291 -0
  63. package/generated/versions/defold-1.12.4/sprite.d.ts +143 -0
  64. package/generated/versions/defold-1.12.4/sys.d.ts +695 -0
  65. package/generated/versions/defold-1.12.4/tilemap.d.ts +181 -0
  66. package/generated/versions/defold-1.12.4/timer.d.ts +114 -0
  67. package/generated/versions/defold-1.12.4/types.d.ts +61 -0
  68. package/generated/versions/defold-1.12.4/vmath.d.ts +806 -0
  69. package/generated/versions/defold-1.12.4/webview.d.ts +68 -0
  70. package/generated/versions/defold-1.12.4/window.d.ts +198 -0
  71. package/generated/versions/defold-1.12.4/zlib.d.ts +40 -0
  72. package/index.d.ts +22 -0
  73. package/package.json +8 -1
  74. package/scripts/fidelity-audit.ts +69 -12
  75. package/scripts/fidelity-baseline.json +56 -0
  76. package/scripts/generate-api-availability.ts +139 -0
  77. package/scripts/generate-api-signatures.ts +66 -0
  78. package/scripts/import-defold-release.ts +480 -0
  79. package/scripts/regen.ts +53 -6
  80. package/scripts/sync-api-docs.ts +89 -41
  81. package/src/api-availability.ts +0 -0
  82. package/src/core-types.ts +9 -0
  83. package/src/emit-dts.ts +674 -17
  84. package/src/emit-messages.ts +72 -2
  85. package/src/index.ts +26 -1
  86. package/src/lifecycle.ts +43 -2
@@ -0,0 +1,1518 @@
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 wether 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
+ * ```lua
454
+ * How to create an 128x128 RGBA texture resource and assign it to a model
455
+ * function init(self)
456
+ * local tparams = {
457
+ * width = 128,
458
+ * height = 128,
459
+ * type = graphics.TEXTURE_TYPE_2D,
460
+ * format = graphics.TEXTURE_FORMAT_RGBA,
461
+ * }
462
+ * local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams)
463
+ * go.set("#model", "texture0", my_texture_id)
464
+ * end
465
+ * ```How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
466
+ *
467
+ * ```lua
468
+ * function init(self)
469
+ * -- Create a new buffer with 4 components and FLOAT32 type
470
+ * local tbuffer = buffer.create(128 * 128, { {name=hash("rgba"), type=buffer.VALUE_TYPE_FLOAT32, count=4} } )
471
+ * local tstream = buffer.get_stream(tbuffer, hash("rgba"))
472
+ *
473
+ * -- Fill the buffer stream with some float values
474
+ * for y=1,128 do
475
+ * for x=1,128 do
476
+ * local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
477
+ * tstream[index + 0] = 999.0
478
+ * tstream[index + 1] = -1.0
479
+ * tstream[index + 2] = 0.5
480
+ * tstream[index + 3] = 1.0
481
+ * end
482
+ * end
483
+ *
484
+ * -- Create a 2D Texture with a RGBA23F format
485
+ * local tparams = {
486
+ * width = 128,
487
+ * height = 128,
488
+ * type = graphics.TEXTURE_TYPE_2D,
489
+ * format = graphics.TEXTURE_FORMAT_RGBA32F,
490
+ * }
491
+ *
492
+ * -- Note that we pass the buffer as the last argument here!
493
+ * local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer)
494
+ *
495
+ * -- assign the texture to a model
496
+ * go.set("#model", "texture0", my_texture_id)
497
+ * end
498
+ * ```How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
499
+ *
500
+ * ```lua
501
+ * function init(self)
502
+ * local t_volume = resource.create_texture("/my_backing_texture.texturec", {
503
+ * type = graphics.TEXTURE_TYPE_IMAGE_3D,
504
+ * width = 32,
505
+ * height = 32,
506
+ * depth = 32,
507
+ * format = resource.TEXTURE_FORMAT_RGBA32F,
508
+ * flags = resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
509
+ * })
510
+ *
511
+ * -- pass the backing texture to the render script
512
+ * msg.post("@render:", "add_textures", { t_volume })
513
+ * end
514
+ * ```How to create 512x512 texture array with 5 pages.
515
+ *
516
+ * ```lua
517
+ * local new_tex = resource.create_texture("/runtime/example_array.texturec", {
518
+ * type = graphics.TEXTURE_TYPE_2D_ARRAY,
519
+ * width = 512,
520
+ * height = 512,
521
+ * page_count = 5,
522
+ * format = graphics.TEXTURE_FORMAT_RGB,
523
+ * })
524
+ * ```
525
+ */
526
+ 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;
527
+ /**
528
+ * Creates a new texture resource that can be used in the same way as any texture created during build time.
529
+ * The path used for creating the texture must be unique, trying to create a resource at a path that is already
530
+ * registered will trigger an error. If the intention is to instead modify an existing texture, use the resource.set_texture
531
+ * function. Also note that the path to the new texture resource must have a '.texturec' extension,
532
+ * meaning "/path/my_texture" is not a valid path but "/path/my_texture.texturec" is.
533
+ * If the texture is created without a buffer, the pixel data will be blank.
534
+ * The difference between the async version and resource.create_texture is that the texture data will be uploaded
535
+ * in a graphics worker thread. The function will return a resource immediately that contains a 1x1 blank texture which can be used
536
+ * immediately after the function call. When the new texture has been uploaded, the initial blank texture will be deleted and replaced with the
537
+ * new texture. Be careful when using the initial texture handle handle as it will not be valid after the upload has finished.
538
+ *
539
+ * @param path - The path to the resource.
540
+ * @param table - A table containing info about how to create the texture. Supported entries:
541
+ * `type`
542
+ * number The texture type. Supported values:
543
+ *
544
+ * - `graphics.TEXTURE_TYPE_2D`
545
+ *
546
+ * - `graphics.TEXTURE_TYPE_IMAGE_2D`
547
+ *
548
+ * - `graphics.TEXTURE_TYPE_3D`
549
+ *
550
+ * - `graphics.TEXTURE_TYPE_IMAGE_3D`
551
+ *
552
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
553
+ *
554
+ * `width`
555
+ * number The width of the texture (in pixels). Must be larger than 0.
556
+ * `height`
557
+ * number The width of the texture (in pixels). Must be larger than 0.
558
+ * `depth`
559
+ * 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`.
560
+ * `format`
561
+ * number The texture format, note that some of these formats might not be supported by the running device. Supported values:
562
+ *
563
+ * - `graphics.TEXTURE_FORMAT_LUMINANCE`
564
+ *
565
+ * - `graphics.TEXTURE_FORMAT_RGB`
566
+ *
567
+ * - `graphics.TEXTURE_FORMAT_RGBA`
568
+ *
569
+ * These constants might not be available on the device:
570
+ *
571
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
572
+ *
573
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
574
+ *
575
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
576
+ *
577
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
578
+ *
579
+ * - `graphics.TEXTURE_FORMAT_RGB_ETC1`
580
+ *
581
+ * - `graphics.TEXTURE_FORMAT_RGBA_ETC2`
582
+ *
583
+ * - `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
584
+ *
585
+ * - `graphics.TEXTURE_FORMAT_RGB_BC1`
586
+ *
587
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC3`
588
+ *
589
+ * - `graphics.TEXTURE_FORMAT_R_BC4`
590
+ *
591
+ * - `graphics.TEXTURE_FORMAT_RG_BC5`
592
+ *
593
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC7`
594
+ *
595
+ * - `graphics.TEXTURE_FORMAT_RGB16F`
596
+ *
597
+ * - `graphics.TEXTURE_FORMAT_RGB32F`
598
+ *
599
+ * - `graphics.TEXTURE_FORMAT_RGBA16F`
600
+ *
601
+ * - `graphics.TEXTURE_FORMAT_RGBA32F`
602
+ *
603
+ * - `graphics.TEXTURE_FORMAT_R16F`
604
+ *
605
+ * - `graphics.TEXTURE_FORMAT_RG16F`
606
+ *
607
+ * - `graphics.TEXTURE_FORMAT_R32F`
608
+ *
609
+ * - `graphics.TEXTURE_FORMAT_RG32F`
610
+ *
611
+ * You can test if the device supports these values by checking if a specific enum is nil or not:
612
+ *
613
+ * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
614
+ * -- it is safe to use this format
615
+ * end
616
+ * `
617
+ *
618
+ * `flags`
619
+ * number Texture creation flags that can be used to dictate how the texture is created. Supported values:
620
+ *
621
+ * - `graphics.TEXTURE_USAGE_FLAG_SAMPLE` - The texture can be sampled from a shader (default)
622
+ *
623
+ * - `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
624
+ *
625
+ * - `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
626
+ *
627
+ * `max_mipmaps`
628
+ * number optional max number of mipmaps. Defaults to zero, i.e no mipmap support
629
+ * `compression_type`
630
+ * 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.
631
+ * 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:
632
+ *
633
+ * - `COMPRESSION_TYPE_DEFAULT`
634
+ *
635
+ * - `COMPRESSION_TYPE_BASIS_UASTC`
636
+ * @param buffer - optional buffer of precreated pixel data
637
+ * @param callback - callback function when texture is created (self, request_id, resource)
638
+ * @example
639
+ * ```ts
640
+ * // Create a texture resource asyncronously with a buffer and a callback
641
+ * function callback(self, request_id, resource) {
642
+ * // The resource has been updated with a new texture,
643
+ * // so we can update other systems with the new handle,
644
+ * // or update components to use the resource if we want
645
+ * const tinfo = resource.get_texture_info(resource);
646
+ * msg.post("@render:", "set_backing_texture", tinfo.handle);
647
+ * }
648
+ *
649
+ * export default defineScript({
650
+ * init() {
651
+ * // Create a texture resource async
652
+ * const tparams = {
653
+ * width: 128,
654
+ * height: 128,
655
+ * type: graphics.TEXTURE_TYPE_2D,
656
+ * format: graphics.TEXTURE_FORMAT_RGBA,
657
+ * };
658
+ *
659
+ * // Create a new buffer with 4 components
660
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
661
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
662
+ *
663
+ * // Fill the buffer stream with some float values
664
+ * for (let y = 0; y < tparams.width; y++) {
665
+ * for (let x = 0; x < tparams.height; x++) {
666
+ * const index = y * 128 * 4 + x * 4;
667
+ * tstream[index + 0] = 255;
668
+ * tstream[index + 1] = 0;
669
+ * tstream[index + 2] = 255;
670
+ * tstream[index + 3] = 255;
671
+ * }
672
+ * }
673
+ * // create the texture
674
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, callback);
675
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
676
+ * // that will be removed once the new texture has been updated
677
+ * go.set("#model", "texture0", tpath);
678
+ * },
679
+ * });
680
+ *
681
+ * // Create a texture resource asyncronously without a callback
682
+ * export default defineScript({
683
+ * init() {
684
+ * // Create a texture resource async
685
+ * const tparams = {
686
+ * width: 128,
687
+ * height: 128,
688
+ * type: graphics.TEXTURE_TYPE_2D,
689
+ * format: graphics.TEXTURE_FORMAT_RGBA,
690
+ * };
691
+ *
692
+ * // Create a new buffer with 4 components
693
+ * const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
694
+ * const tstream = buffer.get_stream(tbuffer, hash("rgba"));
695
+ *
696
+ * // Fill the buffer stream with some float values
697
+ * for (let y = 0; y < tparams.width; y++) {
698
+ * for (let x = 0; x < tparams.height; x++) {
699
+ * const index = y * 128 * 4 + x * 4;
700
+ * tstream[index + 0] = 255;
701
+ * tstream[index + 1] = 0;
702
+ * tstream[index + 2] = 255;
703
+ * tstream[index + 3] = 255;
704
+ * }
705
+ * }
706
+ * // create the texture
707
+ * const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer);
708
+ * // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
709
+ * // that will be removed once the new texture has been updated
710
+ * go.set("#model", "texture0", tpath);
711
+ * },
712
+ * });
713
+ * ```
714
+ */
715
+ 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]>;
716
+ /**
717
+ * Constructor-like function with two purposes:
718
+ *
719
+ * - Load the specified resource as part of loading the script
720
+ *
721
+ * - Return a hash to the run-time version of the resource
722
+ *
723
+ * This function can only be called within go.property function calls.
724
+ *
725
+ * @param path - optional resource path string to the resource
726
+ * @returns a path hash to the binary version of the resource
727
+ * @example
728
+ * ```ts
729
+ * // Load a font and set it to a label:
730
+ * go.property("my_font", resource.font("/font.font"));
731
+ *
732
+ * export default defineScript({
733
+ * init(self) {
734
+ * go.set("#label", "font", self.my_font);
735
+ * },
736
+ * });
737
+ *
738
+ * // Load a font and set it to a gui:
739
+ * go.property("my_font", resource.font("/font.font"));
740
+ *
741
+ * export default defineScript({
742
+ * init(self) {
743
+ * go.set("#gui", "fonts", self.my_font, { key: "my_font" });
744
+ * },
745
+ * });
746
+ * ```
747
+ */
748
+ function font(path?: string): Hash;
749
+ /**
750
+ * Returns the atlas data for an atlas
751
+ *
752
+ * @param path - The path to the atlas resource
753
+ * @returns A table with the following entries:
754
+ *
755
+ * - texture
756
+ *
757
+ * - geometries
758
+ *
759
+ * - animations
760
+ *
761
+ * Each animation entry also contains a `frames` table with indices into
762
+ * `geometries`, preserving the frame-to-geometry mapping used by the atlas.
763
+ * See resource.set_atlas for a detailed description of each field
764
+ */
765
+ 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[] }[] };
766
+ /**
767
+ * gets the buffer from a resource
768
+ *
769
+ * @param path - The path to the resource
770
+ * @returns The resource buffer
771
+ * @example
772
+ * ```ts
773
+ * // How to get the data from a buffer
774
+ * export default defineScript({
775
+ * init() {
776
+ * const res_path = go.get("#mesh", "vertices");
777
+ * const buf = resource.get_buffer(res_path);
778
+ * const stream_positions = buffer.get_stream(buf, "position");
779
+ *
780
+ * for (let i = 0; i < stream_positions.length; i++) {
781
+ * print(i, stream_positions[i]);
782
+ * }
783
+ * },
784
+ * });
785
+ * ```
786
+ */
787
+ function get_buffer(path: Hash | string): Opaque<"buffer">;
788
+ /**
789
+ * Gets render target info from a render target resource path or a render target handle
790
+ *
791
+ * @param path - The path to the resource or a render target handle
792
+ * @returns A table containing info about the render target:
793
+ *
794
+ * `handle`
795
+ * number the opaque handle to the texture resource
796
+ * 'attachments'
797
+ * table a table of attachments, where each attachment contains the following entries:
798
+ * `width`
799
+ * number width of the texture
800
+ * `height`
801
+ * number height of the texture
802
+ * `depth`
803
+ * number depth of the texture (i.e 1 for a 2D texture and 6 for a cube map)
804
+ * `mipmaps`
805
+ * number number of mipmaps of the texture
806
+ * `type`
807
+ * number The texture type. Supported values:
808
+ *
809
+ * - `graphics.TEXTURE_TYPE_2D`
810
+ *
811
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
812
+ *
813
+ * - `graphics.TEXTURE_TYPE_2D_ARRAY`
814
+ *
815
+ * `buffer_type`
816
+ * number The attachment buffer type. Supported values:
817
+ *
818
+ * - `resource.BUFFER_TYPE_COLOR0`
819
+ *
820
+ * - `resource.BUFFER_TYPE_COLOR1`
821
+ *
822
+ * - `resource.BUFFER_TYPE_COLOR2`
823
+ *
824
+ * - `resource.BUFFER_TYPE_COLOR3`
825
+ *
826
+ * - `resource.BUFFER_TYPE_DEPTH`
827
+ *
828
+ * -
829
+ * `resource.BUFFER_TYPE_STENCIL`
830
+ *
831
+ * -
832
+ *
833
+ * `texture`
834
+ * hash The hashed path to the attachment texture resource. This field is only available if the render target passed in is a resource.
835
+ * @example
836
+ * ```ts
837
+ * // Get the metadata from a render target resource
838
+ * export default defineScript({
839
+ * init() {
840
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
841
+ * // the info table contains meta data about all the render target attachments
842
+ * // so it's not necessary to use resource.get_texture here, but we do it here
843
+ * // just to show that it's possible:
844
+ * const info_attachment_1 = resource.get_texture_info(info.attachments[0].handle);
845
+ * },
846
+ * });
847
+ *
848
+ * // Get a texture attachment from a render target and set it on a model component
849
+ * export default defineScript({
850
+ * init() {
851
+ * const info = resource.get_render_target_info("/my_render_target.render_targetc");
852
+ * const attachment = info.attachments[0].texture;
853
+ * // you can also get texture info from the 'texture' field, since it's a resource hash
854
+ * const texture_info = resource.get_texture_info(attachment);
855
+ * go.set("#model", "texture0", attachment);
856
+ * },
857
+ * });
858
+ * ```
859
+ */
860
+ 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 };
861
+ /**
862
+ * Gets the text metrics from a font
863
+ *
864
+ * @param url - the font to get the (unscaled) metrics from
865
+ * @param text - text to measure
866
+ * @param options - A table containing parameters for the text. Supported entries:
867
+ *
868
+ * `width`
869
+ * number The width of the text field. Not used if `line_break` is false.
870
+ * `leading`
871
+ * number The leading (default 1.0)
872
+ * `tracking`
873
+ * number The tracking (default 0.0)
874
+ * `line_break`
875
+ * boolean If the calculation should consider line breaks (default false)
876
+ * @returns a table with the following fields:
877
+ *
878
+ * - width
879
+ *
880
+ * - height
881
+ *
882
+ * - max_ascent
883
+ *
884
+ * - max_descent
885
+ * @example
886
+ * ```ts
887
+ * export default defineScript({
888
+ * init() {
889
+ * const font = go.get("#label", "font");
890
+ * const metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog");
891
+ * pprint(metrics);
892
+ * },
893
+ * });
894
+ * ```
895
+ */
896
+ 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 };
897
+ /**
898
+ * Gets texture info from a texture resource path or a texture handle
899
+ *
900
+ * @param path - The path to the resource or a texture handle
901
+ * @returns A table containing info about the texture:
902
+ *
903
+ * `handle`
904
+ * number the opaque handle to the texture resource
905
+ * `width`
906
+ * number width of the texture
907
+ * `height`
908
+ * number height of the texture
909
+ * `depth`
910
+ * number depth of the texture (i.e 1 for a 2D texture, 6 for a cube map, the actual depth of a 3D texture)
911
+ * `page_count`
912
+ * number number of pages of the texture array. For 2D texture value is 1. For cube map - 6
913
+ * `mipmaps`
914
+ * number number of mipmaps of the texture
915
+ * `flags`
916
+ * number usage hints of the texture.
917
+ * `type`
918
+ * number The texture type. Supported values:
919
+ *
920
+ * - `graphics.TEXTURE_TYPE_2D`
921
+ *
922
+ * - `graphics.TEXTURE_TYPE_2D_ARRAY`
923
+ *
924
+ * - `graphics.TEXTURE_TYPE_IMAGE_2D`
925
+ *
926
+ * - `graphics.TEXTURE_TYPE_3D`
927
+ *
928
+ * - `graphics.TEXTURE_TYPE_IMAGE_3D`
929
+ *
930
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
931
+ * @example
932
+ * ```ts
933
+ * // Create a new texture and get the metadata from it
934
+ * export default defineScript({
935
+ * init() {
936
+ * // create an empty texture
937
+ * const tparams = {
938
+ * width: 128,
939
+ * height: 128,
940
+ * type: graphics.TEXTURE_TYPE_2D,
941
+ * format: graphics.TEXTURE_FORMAT_RGBA,
942
+ * };
943
+ *
944
+ * const my_texture_path = resource.create_texture("/my_texture.texturec", tparams);
945
+ * const my_texture_info = resource.get_texture_info(my_texture_path);
946
+ *
947
+ * // my_texture_info now contains
948
+ * // {
949
+ * // handle = <the-numeric-handle>,
950
+ * // width = 128,
951
+ * // height = 128,
952
+ * // depth = 1
953
+ * // mipmaps = 1,
954
+ * // page_count = 1,
955
+ * // type = graphics.TEXTURE_TYPE_2D,
956
+ * // flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE
957
+ * // }
958
+ * },
959
+ * });
960
+ *
961
+ * // Get the meta data from an atlas resource
962
+ * export default defineScript({
963
+ * init() {
964
+ * const my_atlas_info = resource.get_atlas("/my_atlas.a.texturesetc");
965
+ * const my_texture_info = resource.get_texture_info(my_atlas_info.texture);
966
+ *
967
+ * // my_texture_info now contains the information about the texture that is backing the atlas
968
+ * },
969
+ * });
970
+ * ```
971
+ */
972
+ 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 };
973
+ /**
974
+ * Loads the resource data for a specific resource.
975
+ *
976
+ * @param path - The path to the resource
977
+ * @returns Returns the buffer stored on disc
978
+ * @example
979
+ * ```ts
980
+ * // read custom resource data into buffer
981
+ * const buffer = resource.load("/resources/datafile");
982
+ *
983
+ * // In order for the engine to include custom resources in the build process, you
984
+ * // need to specify them in the "game.project" settings file:
985
+ * // [project]
986
+ * // title = My project
987
+ * // version = 0.1
988
+ * // custom_resources = resources/,assets/level_data.json
989
+ * ```
990
+ */
991
+ function load(path: string): Opaque<"buffer">;
992
+ /**
993
+ * Constructor-like function with two purposes:
994
+ *
995
+ * - Load the specified resource as part of loading the script
996
+ *
997
+ * - Return a hash to the run-time version of the resource
998
+ *
999
+ * This function can only be called within go.property function calls.
1000
+ *
1001
+ * @param path - optional resource path string to the resource
1002
+ * @returns a path hash to the binary version of the resource
1003
+ * @example
1004
+ * ```ts
1005
+ * // Load a material and set it to a sprite:
1006
+ * go.property("my_material", resource.material("/material.material"));
1007
+ *
1008
+ * export default defineScript({
1009
+ * init(self) {
1010
+ * go.set("#sprite", "material", self.my_material);
1011
+ * },
1012
+ * });
1013
+ *
1014
+ * // Load a material resource and update a named material with the resource:
1015
+ * go.property("my_material", resource.material("/material.material"));
1016
+ *
1017
+ * export default defineScript({
1018
+ * init(self) {
1019
+ * go.set("#gui", "materials", self.my_material, { key: "my_material" });
1020
+ * },
1021
+ * });
1022
+ * ```
1023
+ */
1024
+ function material(path?: string): Hash;
1025
+ /**
1026
+ * Release a resource.
1027
+ * This is a potentially dangerous operation, releasing resources currently being used can cause unexpected behaviour.
1028
+ *
1029
+ * @param path - The path to the resource.
1030
+ */
1031
+ function release(path: Hash | string): void;
1032
+ /**
1033
+ * Constructor-like function with two purposes:
1034
+ *
1035
+ * - Load the specified resource as part of loading the script
1036
+ *
1037
+ * - Return a hash to the run-time version of the resource
1038
+ *
1039
+ * This function can only be called within go.property function calls.
1040
+ *
1041
+ * @param path - optional resource path string to the resource
1042
+ * @returns a path hash to the binary version of the resource
1043
+ * @example
1044
+ * ```ts
1045
+ * // Set a render target color attachment as a model texture:
1046
+ * go.property("my_render_target", resource.render_target("/rt.render_target"));
1047
+ *
1048
+ * export default defineScript({
1049
+ * init(self) {
1050
+ * const rt_info = resource.get_render_target_info(self.my_render_target);
1051
+ * go.set("#model", "texture0", rt_info.attachments[0].texture);
1052
+ * },
1053
+ * });
1054
+ * ```
1055
+ */
1056
+ function render_target(path?: string): Hash;
1057
+ /**
1058
+ * Sets the resource data for a specific resource
1059
+ *
1060
+ * @param path - The path to the resource
1061
+ * @param buffer - The buffer of precreated data, suitable for the intended resource type
1062
+ * @example
1063
+ * ```ts
1064
+ * // Assuming the folder "/res" is added to the project custom resources:
1065
+ * // load a texture resource and set it on a sprite
1066
+ * const buffer = resource.load("/res/new.texturec");
1067
+ * resource.set(go.get("#sprite", "texture0"), buffer);
1068
+ * ```
1069
+ */
1070
+ function set(path: string | Hash, buffer: Opaque<"buffer">): void;
1071
+ /**
1072
+ * Sets the data for a specific atlas resource. Setting new atlas data is specified by passing in
1073
+ * a texture path for the backing texture of the atlas, a list of geometries and a list of animations
1074
+ * that map to the entries in the geometry list. The geometry entries are represented by three lists:
1075
+ * vertices, uvs and indices that together represent triangles that are used in other parts of the
1076
+ * engine to produce render objects from.
1077
+ * Vertex and uv coordinates for the geometries are expected to be
1078
+ * in pixel coordinates where 0,0 is the top left corner of the texture.
1079
+ * There is no automatic padding or margin support when setting custom data,
1080
+ * which could potentially cause filtering artifacts if used with a material sampler that has linear filtering.
1081
+ * If that is an issue, you need to calculate padding and margins manually before passing in the geometry data to
1082
+ * this function.
1083
+ *
1084
+ * @param path - The path to the atlas resource
1085
+ * @param table - A table containing info about the atlas. Supported entries:
1086
+ *
1087
+ * -
1088
+ *
1089
+ * `texture`
1090
+ * string | hash the path to the texture resource, e.g "/main/my_texture.texturec"
1091
+ *
1092
+ * -
1093
+ *
1094
+ * `animations`
1095
+ * table a list of the animations in the atlas. Supports the following fields:
1096
+ *
1097
+ * -
1098
+ *
1099
+ * `id`
1100
+ * string the id of the animation, used in e.g sprite.play_animation
1101
+ *
1102
+ * -
1103
+ *
1104
+ * `width`
1105
+ * number the width of the animation
1106
+ *
1107
+ * -
1108
+ *
1109
+ * `height`
1110
+ * number the height of the animation
1111
+ *
1112
+ * -
1113
+ *
1114
+ * `frame_start`
1115
+ * number index to the first geometry of the animation. Indices are lua based and must be in the range of 1 .. in atlas.
1116
+ *
1117
+ * -
1118
+ *
1119
+ * `frame_end`
1120
+ * 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.
1121
+ *
1122
+ * -
1123
+ *
1124
+ * `playback`
1125
+ * constant optional playback mode of the animation, the default value is go.PLAYBACK_ONCE_FORWARD
1126
+ *
1127
+ * -
1128
+ *
1129
+ * `fps`
1130
+ * number optional fps of the animation, the default value is 30
1131
+ *
1132
+ * -
1133
+ *
1134
+ * `flip_vertical`
1135
+ * boolean optional flip the animation vertically, the default value is false
1136
+ *
1137
+ * -
1138
+ *
1139
+ * `flip_horizontal`
1140
+ * boolean optional flip the animation horizontally, the default value is false
1141
+ *
1142
+ * -
1143
+ *
1144
+ * `geometries`
1145
+ * table A list of the geometries that should map to the texture data. Supports the following fields:
1146
+ *
1147
+ * -
1148
+ *
1149
+ * `vertices`
1150
+ * table a list of the vertices in texture space of the geometry in the form {px0, py0, px1, py1, ..., pxn, pyn}
1151
+ *
1152
+ * -
1153
+ *
1154
+ * `uvs`
1155
+ * table a list of the uv coordinates in texture space of the geometry in the form of {u0, v0, u1, v1, ..., un, vn}
1156
+ *
1157
+ * -
1158
+ *
1159
+ * `indices`
1160
+ * table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
1161
+ * @example
1162
+ * ```ts
1163
+ * // Add a new animation to an existing atlas
1164
+ * export default defineScript({
1165
+ * init() {
1166
+ * const data = resource.get_atlas("/main/my_atlas.a.texturesetc");
1167
+ * const my_animation = {
1168
+ * id: "my_new_animation",
1169
+ * width: 128,
1170
+ * height: 128,
1171
+ * frame_start: 1,
1172
+ * frame_end: 6,
1173
+ * playback: go.PLAYBACK_LOOP_PINGPONG,
1174
+ * fps: 8,
1175
+ * };
1176
+ * data.animations.push(my_animation);
1177
+ * resource.set_atlas("/main/my_atlas.a.texturesetc", data);
1178
+ * },
1179
+ * });
1180
+ *
1181
+ * // Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
1182
+ * export default defineScript({
1183
+ * init() {
1184
+ * const params = {
1185
+ * texture: "/main/my_256x256_texture.texturec",
1186
+ * animations: [
1187
+ * {
1188
+ * id: "my_animation",
1189
+ * width: 256,
1190
+ * height: 256,
1191
+ * frames: [1],
1192
+ * },
1193
+ * ],
1194
+ * geometries: [
1195
+ * {
1196
+ * vertices: [0, 0, 0, 256, 256, 256, 256, 0],
1197
+ * uvs: [0, 0, 0, 256, 256, 256, 256, 0],
1198
+ * indices: [0, 1, 2, 0, 2, 3],
1199
+ * },
1200
+ * ],
1201
+ * };
1202
+ * resource.set_atlas("/main/test.a.texturesetc", params);
1203
+ * },
1204
+ * });
1205
+ * ```
1206
+ */
1207
+ 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;
1208
+ /**
1209
+ * Sets the buffer of a resource. By default, setting the resource buffer will either copy the data from the incoming buffer object
1210
+ * 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
1211
+ * 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.
1212
+ * 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
1213
+ * 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
1214
+ * when the lua reference to the buffer is garbage collected.
1215
+ * Note: When setting a buffer with `transfer_ownership = true`, the currently bound buffer in the resource will be destroyed.
1216
+ *
1217
+ * @param path - The path to the resource
1218
+ * @param buffer - The resource buffer
1219
+ * @param table - A table containing info about how to set the buffer. Supported entries:
1220
+ *
1221
+ * -
1222
+ *
1223
+ * `transfer_ownership`
1224
+ * boolean optional flag to determine wether or not the resource should take over ownership of the buffer object (default false)
1225
+ * @example
1226
+ * ```ts
1227
+ * // How to set the data from a buffer
1228
+ * function fill_stream(stream, verts) {
1229
+ * verts.forEach((value, key) => {
1230
+ * stream[key] = verts[key];
1231
+ * });
1232
+ * }
1233
+ *
1234
+ * export default defineScript({
1235
+ * init() {
1236
+ * const res_path = go.get("#mesh", "vertices");
1237
+ *
1238
+ * const positions = [
1239
+ * 1, -1, 0,
1240
+ * 1, 1, 0,
1241
+ * -1, -1, 0,
1242
+ * ];
1243
+ *
1244
+ * const num_verts = positions.length / 3;
1245
+ *
1246
+ * // create a new buffer
1247
+ * let buf = buffer.create(num_verts, [{ name: hash("position"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);
1248
+ *
1249
+ * buf = resource.get_buffer(res_path);
1250
+ * const stream_positions = buffer.get_stream(buf, "position");
1251
+ *
1252
+ * fill_stream(stream_positions, positions);
1253
+ *
1254
+ * resource.set_buffer(res_path, buf);
1255
+ * },
1256
+ * });
1257
+ * ```
1258
+ */
1259
+ function set_buffer(path: Hash | string, buffer: Opaque<"buffer">, table?: { transfer_ownership?: boolean }): void;
1260
+ /**
1261
+ * Update internal sound resource (wavc/oggc/opusc) with new data
1262
+ *
1263
+ * @param path - The path to the resource
1264
+ * @param buffer - A lua string containing the binary sound data
1265
+ */
1266
+ function set_sound(path: Hash | string, buffer: string): void;
1267
+ /**
1268
+ * Sets the pixel data for a specific texture.
1269
+ *
1270
+ * @param path - The path to the resource
1271
+ * @param table - A table containing info about the texture. Supported entries:
1272
+ *
1273
+ * `type`
1274
+ * number The texture type. Supported values:
1275
+ *
1276
+ * - `graphics.TEXTURE_TYPE_2D`
1277
+ *
1278
+ * - `graphics.TEXTURE_TYPE_IMAGE_2D`
1279
+ *
1280
+ * - `graphics.TEXTURE_TYPE_3D`
1281
+ *
1282
+ * - `graphics.TEXTURE_TYPE_IMAGE_3D`
1283
+ *
1284
+ * - `graphics.TEXTURE_TYPE_CUBE_MAP`
1285
+ *
1286
+ * `width`
1287
+ * number The width of the texture (in pixels)
1288
+ * `height`
1289
+ * number The width of the texture (in pixels)
1290
+ * `format`
1291
+ * number The texture format, note that some of these formats are platform specific. Supported values:
1292
+ *
1293
+ * - `graphics.TEXTURE_FORMAT_LUMINANCE`
1294
+ *
1295
+ * - `graphics.TEXTURE_FORMAT_RGB`
1296
+ *
1297
+ * - `graphics.TEXTURE_FORMAT_RGBA`
1298
+ *
1299
+ * These constants might not be available on the device:
1300
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1`
1301
+ * - `graphics.TEXTURE_FORMAT_RGB_PVRTC_4BPPV1`
1302
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1`
1303
+ * - `graphics.TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1`
1304
+ * - `graphics.TEXTURE_FORMAT_RGB_ETC1`
1305
+ * - `graphics.TEXTURE_FORMAT_RGBA_ETC2`
1306
+ * - `graphics.TEXTURE_FORMAT_RGBA_ASTC_4X4`
1307
+ * - `graphics.TEXTURE_FORMAT_RGB_BC1`
1308
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC3`
1309
+ * - `graphics.TEXTURE_FORMAT_R_BC4`
1310
+ * - `graphics.TEXTURE_FORMAT_RG_BC5`
1311
+ * - `graphics.TEXTURE_FORMAT_RGBA_BC7`
1312
+ * - `graphics.TEXTURE_FORMAT_RGB16F`
1313
+ * - `graphics.TEXTURE_FORMAT_RGB32F`
1314
+ * - `graphics.TEXTURE_FORMAT_RGBA16F`
1315
+ * - `graphics.TEXTURE_FORMAT_RGBA32F`
1316
+ * - `graphics.TEXTURE_FORMAT_R16F`
1317
+ * - `graphics.TEXTURE_FORMAT_RG16F`
1318
+ * - `graphics.TEXTURE_FORMAT_R32F`
1319
+ * - `graphics.TEXTURE_FORMAT_RG32F`
1320
+ * You can test if the device supports these values by checking if a specific enum is nil or not:
1321
+ *
1322
+ * `if graphics.TEXTURE_FORMAT_RGBA16F ~= nil then
1323
+ * -- it is safe to use this format
1324
+ * end
1325
+ * `
1326
+ *
1327
+ * `x`
1328
+ * number optional x offset of the texture (in pixels)
1329
+ * `y`
1330
+ * number optional y offset of the texture (in pixels)
1331
+ * `z`
1332
+ * number optional z offset of the texture (in pixels). Only applies to 3D textures
1333
+ * `page`
1334
+ * number optional slice of the array texture. Only applies to 2D texture arrays. Zero-based
1335
+ * `mipmap`
1336
+ * number optional mipmap to upload the data to
1337
+ * `compression_type`
1338
+ * 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:
1339
+ *
1340
+ * - `COMPRESSION_TYPE_DEFAULT`
1341
+ *
1342
+ * - `COMPRESSION_TYPE_BASIS_UASTC`
1343
+ * @param buffer - The buffer of precreated pixel data
1344
+ * 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!
1345
+ * 3D Textures are currently only supported on OpenGL and Vulkan adapters. To check if your device supports 3D textures, use:
1346
+ * ```lua
1347
+ * if graphics.TEXTURE_TYPE_3D ~= nil then
1348
+ * -- Device and graphics adapter support 3D textures
1349
+ * end
1350
+ * @example
1351
+ * ```lua
1352
+ * How to set all pixels of an atlas
1353
+ * function init(self)
1354
+ * self.height = 128
1355
+ * self.width = 128
1356
+ * self.buffer = buffer.create(self.width * self.height, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
1357
+ * self.stream = buffer.get_stream(self.buffer, hash("rgb"))
1358
+ *
1359
+ * for y=1,self.height do
1360
+ * for x=1,self.width do
1361
+ * local index = (y-1) * self.width * 3 + (x-1) * 3 + 1
1362
+ * self.stream[index + 0] = 0xff
1363
+ * self.stream[index + 1] = 0x80
1364
+ * self.stream[index + 2] = 0x10
1365
+ * end
1366
+ * end
1367
+ *
1368
+ * local resource_path = go.get("#model", "texture0")
1369
+ * local args = { width=self.width, height=self.height, type=graphics.TEXTURE_TYPE_2D, format=graphics.TEXTURE_FORMAT_RGB, num_mip_maps=1 }
1370
+ * resource.set_texture( resource_path, args, self.buffer )
1371
+ * end
1372
+ * ```How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
1373
+ *
1374
+ * ```lua
1375
+ * function init(self)
1376
+ * self.x = 16
1377
+ * self.y = 16
1378
+ * self.height = 128 - self.x * 2
1379
+ * self.width = 128 - self.y * 2
1380
+ * self.buffer = buffer.create(self.width * self.height, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
1381
+ * self.stream = buffer.get_stream(self.buffer, hash("rgb"))
1382
+ *
1383
+ * for y=1,self.height do
1384
+ * for x=1,self.width do
1385
+ * local index = (y-1) * self.width * 3 + (x-1) * 3 + 1
1386
+ * self.stream[index + 0] = 0xff
1387
+ * self.stream[index + 1] = 0x80
1388
+ * self.stream[index + 2] = 0x10
1389
+ * end
1390
+ * end
1391
+ *
1392
+ * local resource_path = go.get("#model", "texture0")
1393
+ * local 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 }
1394
+ * resource.set_texture(resource_path, args, self.buffer )
1395
+ * end
1396
+ * ```Update a texture from a buffer resource
1397
+ * ```lua
1398
+ * go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"))
1399
+ *
1400
+ * function init(self)
1401
+ * local resource_path = go.get("#model", "texture0")
1402
+ * -- the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
1403
+ * local args = {
1404
+ * width = 128,
1405
+ * height = 128,
1406
+ * type = graphics.TEXTURE_TYPE_2D,
1407
+ * format = graphics.TEXTURE_FORMAT_RGB
1408
+ * }
1409
+ * -- Note that the extra resource.get_buffer call is a requirement here
1410
+ * -- since the "self.my_buffer" is just pointing to a buffer resource path
1411
+ * -- and not an actual buffer object or buffer resource.
1412
+ * resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer))
1413
+ * end
1414
+ * ```Update an existing 3D texture from a lua buffer
1415
+ *
1416
+ * ```lua
1417
+ *
1418
+ * function init(self)
1419
+ * -- create a buffer that can hold the data of a 8x8x8 texture
1420
+ * local tbuffer = buffer.create(8 * 8 * 8, { {name=hash("rgba"), type=buffer.VALUE_TYPE_FLOAT32, count=4} } )
1421
+ * local tstream = buffer.get_stream(tbuffer, hash("rgba"))
1422
+ *
1423
+ * -- populate the buffer with some data
1424
+ * local index = 1
1425
+ * for z=1,8 do
1426
+ * for y=1,8 do
1427
+ * for x=1,8 do
1428
+ * tstream[index + 0] = x
1429
+ * tstream[index + 1] = y
1430
+ * tstream[index + 2] = z
1431
+ * tstream[index + 3] = 1.0
1432
+ * index = index + 4
1433
+ * end
1434
+ * end
1435
+ * end
1436
+ *
1437
+ * local t_args = {
1438
+ * type = graphics.TEXTURE_TYPE_IMAGE_3D,
1439
+ * width = 8,
1440
+ * height = 8,
1441
+ * depth = 8,
1442
+ * format = resource.TEXTURE_FORMAT_RGBA32F
1443
+ * }
1444
+ *
1445
+ * -- This expects that the texture resource "/my_3d_texture.texturec" already exists
1446
+ * -- and is a 3D texture resource. To create a dynamic 3D texture resource
1447
+ * -- use the "resource.create_texture" function.
1448
+ * resource.set_texture("/my_3d_texture.texturec", t_args, tbuffer)
1449
+ * endUpdate texture 2nd array page with loaded texture from png
1450
+ *
1451
+ * ```lua
1452
+ * -- new_tex is resource handle of texture which was created via resource.create_resource
1453
+ * local tex_path = "/bundle_resources/page_02.png"
1454
+ * local data = sys.load_resource(tex_path)
1455
+ * local buf = image.load_buffer(data)
1456
+ * resource.set_texture(new_tex, {
1457
+ * type = graphics.TEXTURE_TYPE_2D_ARRAY,
1458
+ * width = buf.width,
1459
+ * height = buf.height,
1460
+ * page = 1,
1461
+ * format = graphics.TEXTURE_FORMAT_RGB
1462
+ * }, buf.buffer)
1463
+ * go.set("#mesh", "texture0", new_tex)
1464
+ * ```
1465
+ */
1466
+ 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;
1467
+ /**
1468
+ * Constructor-like function with two purposes:
1469
+ *
1470
+ * - Load the specified resource as part of loading the script
1471
+ *
1472
+ * - Return a hash to the run-time version of the resource
1473
+ *
1474
+ * This function can only be called within go.property function calls.
1475
+ *
1476
+ * @param path - optional resource path string to the resource
1477
+ * @returns a path hash to the binary version of the resource
1478
+ * @example
1479
+ * ```ts
1480
+ * // Load a texture and set it to a model:
1481
+ * go.property("my_texture", resource.texture("/texture.png"));
1482
+ *
1483
+ * export default defineScript({
1484
+ * init(self) {
1485
+ * go.set("#model", "texture0", self.my_texture);
1486
+ * },
1487
+ * });
1488
+ * ```
1489
+ */
1490
+ function texture(path?: string): Hash;
1491
+ /**
1492
+ * Constructor-like function with two purposes:
1493
+ *
1494
+ * - Load the specified resource as part of loading the script
1495
+ *
1496
+ * - Return a hash to the run-time version of the resource
1497
+ *
1498
+ * This function can only be called within go.property function calls.
1499
+ *
1500
+ * @param path - optional resource path string to the resource
1501
+ * @returns a path hash to the binary version of the resource
1502
+ * @example
1503
+ * ```ts
1504
+ * // Load tile source and set it to a tile map:
1505
+ * go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"));
1506
+ *
1507
+ * export default defineScript({
1508
+ * init(self) {
1509
+ * go.set("#tilemap", "tile_source", self.my_tile_source);
1510
+ * },
1511
+ * });
1512
+ * ```
1513
+ */
1514
+ function tile_source(path?: string): Hash;
1515
+ }
1516
+ }
1517
+
1518
+ export {};