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