@defold-typescript/types 0.5.5 → 0.7.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.
- package/README.md +2 -2
- package/api-targets.json +1 -1
- package/generated/b2d.d.ts +3 -0
- package/generated/buffer.d.ts +44 -38
- package/generated/builtin-messages.d.ts +1 -1
- package/generated/camera.d.ts +3 -0
- package/generated/collectionfactory.d.ts +47 -40
- package/generated/collectionproxy.d.ts +23 -18
- package/generated/crash.d.ts +3 -0
- package/generated/factory.d.ts +32 -24
- package/generated/go.d.ts +123 -124
- package/generated/graphics.d.ts +3 -0
- package/generated/gui.d.ts +303 -283
- package/generated/http.d.ts +26 -16
- package/generated/iac.d.ts +3 -0
- package/generated/iap.d.ts +6 -3
- package/generated/image.d.ts +30 -26
- package/generated/json.d.ts +36 -32
- package/generated/kinds/gui-script.d.ts +7 -5
- package/generated/kinds/render-script.d.ts +7 -5
- package/generated/kinds/script.d.ts +7 -5
- package/generated/label.d.ts +16 -9
- package/generated/liveupdate.d.ts +29 -26
- package/generated/model.d.ts +57 -45
- package/generated/msg.d.ts +3 -0
- package/generated/particlefx.d.ts +50 -34
- package/generated/physics.d.ts +153 -133
- package/generated/profiler.d.ts +45 -41
- package/generated/push.d.ts +5 -2
- package/generated/render.d.ts +410 -349
- package/generated/resource.d.ts +619 -572
- package/generated/socket.d.ts +49 -33
- package/generated/sound.d.ts +83 -72
- package/generated/sprite.d.ts +3 -0
- package/generated/sys.d.ts +198 -189
- package/generated/tilemap.d.ts +43 -39
- package/generated/timer.d.ts +42 -36
- package/generated/vmath.d.ts +22 -0
- package/generated/webview.d.ts +3 -0
- package/generated/window.d.ts +23 -17
- package/generated/zlib.d.ts +15 -12
- package/index.d.ts +3 -1
- package/package.json +13 -2
- package/scripts/fidelity-audit.ts +61 -1
- package/scripts/fidelity-baseline.json +10 -10
- package/scripts/ref-doc-delta.ts +143 -0
- package/scripts/regen.ts +18 -9
- package/src/core-types.ts +14 -0
- package/src/emit-dts.ts +219 -13
- package/src/engine-globals.d.ts +2 -0
- package/src/go-overloads.d.ts +43 -0
- package/src/index.ts +5 -0
- package/src/lifecycle.ts +157 -16
- package/src/publish-dts.ts +1 -1
package/generated/resource.d.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import type { Hash, Opaque } from "../src/core-types";
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Functions and constants to access resources.
|
|
7
|
+
*/
|
|
5
8
|
namespace resource {
|
|
6
9
|
/**
|
|
7
10
|
* Constructor-like function with two purposes:
|
|
@@ -12,18 +15,24 @@ declare global {
|
|
|
12
15
|
* @param path - optional resource path string to the resource
|
|
13
16
|
* @returns a path hash to the binary version of the resource
|
|
14
17
|
* @example
|
|
15
|
-
* ```
|
|
16
|
-
* Load an atlas and set it to a sprite:
|
|
17
|
-
* go.property("my_atlas", resource.atlas("/atlas.atlas"))
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Load an atlas and set it to a sprite:
|
|
20
|
+
* go.property("my_atlas", resource.atlas("/atlas.atlas"));
|
|
21
|
+
*
|
|
22
|
+
* export default defineScript({
|
|
23
|
+
* init(self) {
|
|
24
|
+
* go.set("#sprite", "image", self.my_atlas);
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Load an atlas and set it to a gui:
|
|
29
|
+
* go.property("my_atlas", resource.atlas("/atlas.atlas"));
|
|
30
|
+
*
|
|
31
|
+
* export default defineScript({
|
|
32
|
+
* init(self) {
|
|
33
|
+
* go.set("#gui", "textures", self.my_atlas, { key: "my_atlas" });
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
27
36
|
* ```
|
|
28
37
|
*/
|
|
29
38
|
function atlas(path?: string): Hash;
|
|
@@ -36,12 +45,15 @@ declare global {
|
|
|
36
45
|
* @param path - optional resource path string to the resource
|
|
37
46
|
* @returns a path hash to the binary version of the resource
|
|
38
47
|
* @example
|
|
39
|
-
* ```
|
|
40
|
-
* Set a unique buffer it to a sprite:
|
|
41
|
-
* go.property("my_buffer", resource.buffer("/cube.buffer"))
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Set a unique buffer it to a sprite:
|
|
50
|
+
* go.property("my_buffer", resource.buffer("/cube.buffer"));
|
|
51
|
+
*
|
|
52
|
+
* export default defineScript({
|
|
53
|
+
* init(self) {
|
|
54
|
+
* go.set("#mesh", "vertices", self.my_buffer);
|
|
55
|
+
* },
|
|
56
|
+
* });
|
|
45
57
|
* ```
|
|
46
58
|
*/
|
|
47
59
|
function buffer(path?: string): Hash;
|
|
@@ -124,61 +136,53 @@ declare global {
|
|
|
124
136
|
* table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
|
|
125
137
|
* @returns Returns the atlas resource path
|
|
126
138
|
* @example
|
|
127
|
-
* ```
|
|
128
|
-
* Create a backing texture and an atlas
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* // Create a backing texture and an atlas
|
|
141
|
+
* export default defineScript({
|
|
142
|
+
* init() {
|
|
143
|
+
* // create an empty texture
|
|
144
|
+
* const tparams = {
|
|
145
|
+
* width: 128,
|
|
146
|
+
* height: 128,
|
|
147
|
+
* type: graphics.TEXTURE_TYPE_2D,
|
|
148
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
149
|
+
* };
|
|
150
|
+
* const my_texture_id = resource.create_texture("/my_texture.texturec", tparams);
|
|
151
|
+
*
|
|
152
|
+
* // optionally use resource.set_texture to upload data to texture
|
|
153
|
+
*
|
|
154
|
+
* // create an atlas with one animation and one square geometry
|
|
155
|
+
* // note that the function doesn't support hashes for the texture,
|
|
156
|
+
* // you need to use a string for the texture path here aswell
|
|
157
|
+
* const aparams = {
|
|
158
|
+
* texture: "/my_texture.texturec",
|
|
159
|
+
* animations: [
|
|
160
|
+
* {
|
|
161
|
+
* id: "my_animation",
|
|
162
|
+
* width: 128,
|
|
163
|
+
* height: 128,
|
|
164
|
+
* frames: [1],
|
|
153
165
|
* },
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* }
|
|
175
|
-
* }
|
|
176
|
-
* }
|
|
177
|
-
* local my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams)
|
|
178
|
-
*
|
|
179
|
-
* -- assign the atlas to the 'sprite' component on the same go
|
|
180
|
-
* go.set("#sprite", "image", my_atlas_id)
|
|
181
|
-
* end
|
|
166
|
+
* ],
|
|
167
|
+
* geometries: [
|
|
168
|
+
* {
|
|
169
|
+
* id: "idle0",
|
|
170
|
+
* width: 128,
|
|
171
|
+
* height: 128,
|
|
172
|
+
* pivot_x: 0.5,
|
|
173
|
+
* pivot_y: 0.5,
|
|
174
|
+
* vertices: [0, 0, 0, 128, 128, 128, 128, 0],
|
|
175
|
+
* uvs: [0, 0, 0, 128, 128, 128, 128, 0],
|
|
176
|
+
* indices: [0, 1, 2, 0, 2, 3],
|
|
177
|
+
* },
|
|
178
|
+
* ],
|
|
179
|
+
* };
|
|
180
|
+
* const my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", aparams);
|
|
181
|
+
*
|
|
182
|
+
* // assign the atlas to the 'sprite' component on the same go
|
|
183
|
+
* go.set("#sprite", "image", my_atlas_id);
|
|
184
|
+
* },
|
|
185
|
+
* });
|
|
182
186
|
* ```
|
|
183
187
|
*/
|
|
184
188
|
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;
|
|
@@ -202,49 +206,52 @@ declare global {
|
|
|
202
206
|
* boolean optional flag to determine wether or not the resource should take over ownership of the buffer object (default true)
|
|
203
207
|
* @returns Returns the buffer resource path
|
|
204
208
|
* @example
|
|
205
|
-
* ```
|
|
206
|
-
* Create a buffer object and bind it to a buffer resource
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* // Create a buffer object and bind it to a buffer resource
|
|
211
|
+
* export default defineScript({
|
|
212
|
+
* init() {
|
|
213
|
+
* const size = 1;
|
|
214
|
+
* const positions = [
|
|
215
|
+
* // triangle 1
|
|
216
|
+
* size, size, 0,
|
|
217
|
+
* -size, -size, 0,
|
|
218
|
+
* size, -size, 0,
|
|
219
|
+
* // triangle 2
|
|
220
|
+
* size, size, 0,
|
|
221
|
+
* -size, size, 0,
|
|
222
|
+
* -size, -size, 0,
|
|
223
|
+
* ];
|
|
224
|
+
*
|
|
225
|
+
* const buffer_handle = buffer.create(positions.length, [
|
|
226
|
+
* {
|
|
227
|
+
* name: hash("position"),
|
|
228
|
+
* type: buffer.VALUE_TYPE_FLOAT32,
|
|
229
|
+
* count: 3,
|
|
230
|
+
* },
|
|
231
|
+
* ]);
|
|
232
|
+
*
|
|
233
|
+
* const stream = buffer.get_stream(buffer_handle, hash("position"));
|
|
234
|
+
*
|
|
235
|
+
* // transfer vertex data to buffer
|
|
236
|
+
* for (let k = 0; k < positions.length; k++) {
|
|
237
|
+
* stream[k] = positions[k];
|
|
218
238
|
* }
|
|
219
239
|
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* local my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer = buffer_handle })
|
|
236
|
-
* go.set("/go#mesh", "vertices", my_buffer)
|
|
237
|
-
* end
|
|
238
|
-
* ```Create a buffer resource from existing resource
|
|
239
|
-
*
|
|
240
|
-
* ```lua
|
|
241
|
-
* function init(self)
|
|
242
|
-
* local res = resource.get_buffer("/my_buffer_path.bufferc")
|
|
243
|
-
* -- create a cloned buffer resource from another resource buffer
|
|
244
|
-
* local buf = reource.create_buffer("/my_cloned_buffer.bufferc", { buffer = res })
|
|
245
|
-
* -- assign cloned buffer to a mesh component
|
|
246
|
-
* go.set("/go#mesh", "vertices", buf)
|
|
247
|
-
* end
|
|
240
|
+
* const my_buffer = resource.create_buffer("/my_buffer.bufferc", { buffer: buffer_handle });
|
|
241
|
+
* go.set("/go#mesh", "vertices", my_buffer);
|
|
242
|
+
* },
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* // Create a buffer resource from existing resource
|
|
246
|
+
* export default defineScript({
|
|
247
|
+
* init() {
|
|
248
|
+
* const res = resource.get_buffer("/my_buffer_path.bufferc");
|
|
249
|
+
* // create a cloned buffer resource from another resource buffer
|
|
250
|
+
* const buf = resource.create_buffer("/my_cloned_buffer.bufferc", { buffer: res });
|
|
251
|
+
* // assign cloned buffer to a mesh component
|
|
252
|
+
* go.set("/go#mesh", "vertices", buf);
|
|
253
|
+
* },
|
|
254
|
+
* });
|
|
248
255
|
* ```
|
|
249
256
|
*/
|
|
250
257
|
function create_buffer(path: string, table?: { buffer?: Opaque<"buffer">; transfer_ownership?: boolean }): Hash;
|
|
@@ -262,14 +269,16 @@ declare global {
|
|
|
262
269
|
* boolean Is the data not representing the full file, but just the initial chunk?
|
|
263
270
|
* @returns the resulting path hash to the resource
|
|
264
271
|
* @example
|
|
265
|
-
* ```
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
272
|
+
* ```ts
|
|
273
|
+
* export default defineScript({
|
|
274
|
+
* init() {
|
|
275
|
+
* // create a new sound resource, given the initial chunk of the file
|
|
276
|
+
* const relative_path = "/a/unique/resource/name.oggc";
|
|
277
|
+
* const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });
|
|
278
|
+
* go.set("#music", "sound", hash); // override the previous sound resource
|
|
279
|
+
* sound.play("#music"); // start the playing
|
|
280
|
+
* },
|
|
281
|
+
* });
|
|
273
282
|
* ```
|
|
274
283
|
*/
|
|
275
284
|
function create_sound_data(path: string, options?: { data?: string; filesize?: number; partial?: boolean }): Hash;
|
|
@@ -348,77 +357,80 @@ declare global {
|
|
|
348
357
|
* -- Device and graphics adapter support 3D textures
|
|
349
358
|
* end
|
|
350
359
|
* @example
|
|
351
|
-
* ```
|
|
352
|
-
* How to create an 128x128 RGBA texture resource and assign it to a model
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* local tparams = {
|
|
384
|
-
* width = 128,
|
|
385
|
-
* height = 128,
|
|
386
|
-
* type = graphics.TEXTURE_TYPE_2D,
|
|
387
|
-
* format = graphics.TEXTURE_FORMAT_RGBA32F,
|
|
388
|
-
* }
|
|
389
|
-
*
|
|
390
|
-
* -- Note that we pass the buffer as the last argument here!
|
|
391
|
-
* local my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer)
|
|
392
|
-
*
|
|
393
|
-
* -- assign the texture to a model
|
|
394
|
-
* go.set("#model", "texture0", my_texture_id)
|
|
395
|
-
* end
|
|
396
|
-
* ```How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
|
|
397
|
-
*
|
|
398
|
-
* ```lua
|
|
399
|
-
* function init(self)
|
|
400
|
-
* local t_volume = resource.create_texture("/my_backing_texture.texturec", {
|
|
401
|
-
* type = graphics.TEXTURE_TYPE_IMAGE_3D,
|
|
402
|
-
* width = 32,
|
|
403
|
-
* height = 32,
|
|
404
|
-
* depth = 32,
|
|
405
|
-
* format = resource.TEXTURE_FORMAT_RGBA32F,
|
|
406
|
-
* flags = resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
|
|
407
|
-
* })
|
|
408
|
-
*
|
|
409
|
-
* -- pass the backing texture to the render script
|
|
410
|
-
* msg.post("@render:", "add_textures", { t_volume })
|
|
411
|
-
* end
|
|
412
|
-
* ```How to create 512x512 texture array with 5 pages.
|
|
360
|
+
* ```ts
|
|
361
|
+
* // How to create an 128x128 RGBA texture resource and assign it to a model
|
|
362
|
+
* export default defineScript({
|
|
363
|
+
* init() {
|
|
364
|
+
* const tparams = {
|
|
365
|
+
* width: 128,
|
|
366
|
+
* height: 128,
|
|
367
|
+
* type: graphics.TEXTURE_TYPE_2D,
|
|
368
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
369
|
+
* };
|
|
370
|
+
* const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams);
|
|
371
|
+
* go.set("#model", "texture0", my_texture_id);
|
|
372
|
+
* },
|
|
373
|
+
* });
|
|
374
|
+
*
|
|
375
|
+
* // How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object
|
|
376
|
+
* export default defineScript({
|
|
377
|
+
* init() {
|
|
378
|
+
* // Create a new buffer with 4 components and FLOAT32 type
|
|
379
|
+
* const tbuffer = buffer.create(128 * 128, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
|
|
380
|
+
* const tstream = buffer.get_stream(tbuffer, hash("rgba"));
|
|
381
|
+
*
|
|
382
|
+
* // Fill the buffer stream with some float values
|
|
383
|
+
* for (let y = 0; y < 128; y++) {
|
|
384
|
+
* for (let x = 0; x < 128; x++) {
|
|
385
|
+
* const index = y * 128 * 4 + x * 4;
|
|
386
|
+
* tstream[index + 0] = 999.0;
|
|
387
|
+
* tstream[index + 1] = -1.0;
|
|
388
|
+
* tstream[index + 2] = 0.5;
|
|
389
|
+
* tstream[index + 3] = 1.0;
|
|
390
|
+
* }
|
|
391
|
+
* }
|
|
413
392
|
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
393
|
+
* // Create a 2D Texture with a RGBA23F format
|
|
394
|
+
* const tparams = {
|
|
395
|
+
* width: 128,
|
|
396
|
+
* height: 128,
|
|
397
|
+
* type: graphics.TEXTURE_TYPE_2D,
|
|
398
|
+
* format: graphics.TEXTURE_FORMAT_RGBA32F,
|
|
399
|
+
* };
|
|
400
|
+
*
|
|
401
|
+
* // Note that we pass the buffer as the last argument here!
|
|
402
|
+
* const my_texture_id = resource.create_texture("/my_custom_texture.texturec", tparams, tbuffer);
|
|
403
|
+
*
|
|
404
|
+
* // assign the texture to a model
|
|
405
|
+
* go.set("#model", "texture0", my_texture_id);
|
|
406
|
+
* },
|
|
407
|
+
* });
|
|
408
|
+
*
|
|
409
|
+
* // How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader
|
|
410
|
+
* export default defineScript({
|
|
411
|
+
* init() {
|
|
412
|
+
* const t_volume = resource.create_texture("/my_backing_texture.texturec", {
|
|
413
|
+
* type: graphics.TEXTURE_TYPE_IMAGE_3D,
|
|
414
|
+
* width: 32,
|
|
415
|
+
* height: 32,
|
|
416
|
+
* depth: 32,
|
|
417
|
+
* format: resource.TEXTURE_FORMAT_RGBA32F,
|
|
418
|
+
* flags: resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,
|
|
419
|
+
* });
|
|
420
|
+
*
|
|
421
|
+
* // pass the backing texture to the render script
|
|
422
|
+
* msg.post("@render:", "add_textures", [t_volume]);
|
|
423
|
+
* },
|
|
424
|
+
* });
|
|
425
|
+
*
|
|
426
|
+
* // How to create 512x512 texture array with 5 pages.
|
|
427
|
+
* const new_tex = resource.create_texture("/runtime/example_array.texturec", {
|
|
428
|
+
* type: graphics.TEXTURE_TYPE_2D_ARRAY,
|
|
429
|
+
* width: 512,
|
|
430
|
+
* height: 512,
|
|
431
|
+
* page_count: 5,
|
|
432
|
+
* format: graphics.TEXTURE_FORMAT_RGB,
|
|
433
|
+
* });
|
|
422
434
|
* ```
|
|
423
435
|
*/
|
|
424
436
|
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;
|
|
@@ -495,76 +507,80 @@ declare global {
|
|
|
495
507
|
* @param buffer - optional buffer of precreated pixel data
|
|
496
508
|
* @param callback - callback function when texture is created (self, request_id, resource)
|
|
497
509
|
* @example
|
|
498
|
-
* ```
|
|
499
|
-
* Create a texture resource asyncronously with a buffer and a callback
|
|
500
|
-
* function callback(self, request_id, resource)
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
510
|
+
* ```ts
|
|
511
|
+
* // Create a texture resource asyncronously with a buffer and a callback
|
|
512
|
+
* function callback(self, request_id, resource) {
|
|
513
|
+
* // The resource has been updated with a new texture,
|
|
514
|
+
* // so we can update other systems with the new handle,
|
|
515
|
+
* // or update components to use the resource if we want
|
|
516
|
+
* const tinfo = resource.get_texture_info(resource);
|
|
517
|
+
* msg.post("@render:", "set_backing_texture", tinfo.handle);
|
|
518
|
+
* }
|
|
519
|
+
*
|
|
520
|
+
* export default defineScript({
|
|
521
|
+
* init() {
|
|
522
|
+
* // Create a texture resource async
|
|
523
|
+
* const tparams = {
|
|
524
|
+
* width: 128,
|
|
525
|
+
* height: 128,
|
|
526
|
+
* type: graphics.TEXTURE_TYPE_2D,
|
|
527
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
528
|
+
* };
|
|
529
|
+
*
|
|
530
|
+
* // Create a new buffer with 4 components
|
|
531
|
+
* const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
|
|
532
|
+
* const tstream = buffer.get_stream(tbuffer, hash("rgba"));
|
|
533
|
+
*
|
|
534
|
+
* // Fill the buffer stream with some float values
|
|
535
|
+
* for (let y = 0; y < tparams.width; y++) {
|
|
536
|
+
* for (let x = 0; x < tparams.height; x++) {
|
|
537
|
+
* const index = y * 128 * 4 + x * 4;
|
|
538
|
+
* tstream[index + 0] = 255;
|
|
539
|
+
* tstream[index + 1] = 0;
|
|
540
|
+
* tstream[index + 2] = 255;
|
|
541
|
+
* tstream[index + 3] = 255;
|
|
542
|
+
* }
|
|
514
543
|
* }
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
544
|
+
* // create the texture
|
|
545
|
+
* const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer, callback);
|
|
546
|
+
* // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
|
|
547
|
+
* // that will be removed once the new texture has been updated
|
|
548
|
+
* go.set("#model", "texture0", tpath);
|
|
549
|
+
* },
|
|
550
|
+
* });
|
|
551
|
+
*
|
|
552
|
+
* // Create a texture resource asyncronously without a callback
|
|
553
|
+
* export default defineScript({
|
|
554
|
+
* init() {
|
|
555
|
+
* // Create a texture resource async
|
|
556
|
+
* const tparams = {
|
|
557
|
+
* width: 128,
|
|
558
|
+
* height: 128,
|
|
559
|
+
* type: graphics.TEXTURE_TYPE_2D,
|
|
560
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
561
|
+
* };
|
|
562
|
+
*
|
|
563
|
+
* // Create a new buffer with 4 components
|
|
564
|
+
* const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);
|
|
565
|
+
* const tstream = buffer.get_stream(tbuffer, hash("rgba"));
|
|
566
|
+
*
|
|
567
|
+
* // Fill the buffer stream with some float values
|
|
568
|
+
* for (let y = 0; y < tparams.width; y++) {
|
|
569
|
+
* for (let x = 0; x < tparams.height; x++) {
|
|
570
|
+
* const index = y * 128 * 4 + x * 4;
|
|
571
|
+
* tstream[index + 0] = 255;
|
|
572
|
+
* tstream[index + 1] = 0;
|
|
573
|
+
* tstream[index + 2] = 255;
|
|
574
|
+
* tstream[index + 3] = 255;
|
|
575
|
+
* }
|
|
546
576
|
* }
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* for x=1,tparams.height do
|
|
555
|
-
* local index = (y-1) * 128 * 4 + (x-1) * 4 + 1
|
|
556
|
-
* tstream[index + 0] = 255
|
|
557
|
-
* tstream[index + 1] = 0
|
|
558
|
-
* tstream[index + 2] = 255
|
|
559
|
-
* tstream[index + 3] = 255
|
|
560
|
-
* end
|
|
561
|
-
* end
|
|
562
|
-
* -- create the texture
|
|
563
|
-
* local tpath, request_id = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer)
|
|
564
|
-
* -- at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
|
|
565
|
-
* -- that will be removed once the new texture has been updated
|
|
566
|
-
* go.set("#model", "texture0", tpath)
|
|
567
|
-
* end
|
|
577
|
+
* // create the texture
|
|
578
|
+
* const [tpath, request_id] = resource.create_texture_async("/my_texture.texturec", tparams, tbuffer);
|
|
579
|
+
* // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture
|
|
580
|
+
* // that will be removed once the new texture has been updated
|
|
581
|
+
* go.set("#model", "texture0", tpath);
|
|
582
|
+
* },
|
|
583
|
+
* });
|
|
568
584
|
* ```
|
|
569
585
|
*/
|
|
570
586
|
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]>;
|
|
@@ -577,18 +593,24 @@ declare global {
|
|
|
577
593
|
* @param path - optional resource path string to the resource
|
|
578
594
|
* @returns a path hash to the binary version of the resource
|
|
579
595
|
* @example
|
|
580
|
-
* ```
|
|
581
|
-
* Load a font and set it to a label:
|
|
582
|
-
* go.property("my_font", resource.font("/font.font"))
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
596
|
+
* ```ts
|
|
597
|
+
* // Load a font and set it to a label:
|
|
598
|
+
* go.property("my_font", resource.font("/font.font"));
|
|
599
|
+
*
|
|
600
|
+
* export default defineScript({
|
|
601
|
+
* init(self) {
|
|
602
|
+
* go.set("#label", "font", self.my_font);
|
|
603
|
+
* },
|
|
604
|
+
* });
|
|
605
|
+
*
|
|
606
|
+
* // Load a font and set it to a gui:
|
|
607
|
+
* go.property("my_font", resource.font("/font.font"));
|
|
608
|
+
*
|
|
609
|
+
* export default defineScript({
|
|
610
|
+
* init(self) {
|
|
611
|
+
* go.set("#gui", "fonts", self.my_font, { key: "my_font" });
|
|
612
|
+
* },
|
|
613
|
+
* });
|
|
592
614
|
* ```
|
|
593
615
|
*/
|
|
594
616
|
function font(path?: string): Hash;
|
|
@@ -611,18 +633,19 @@ declare global {
|
|
|
611
633
|
* @param path - The path to the resource
|
|
612
634
|
* @returns The resource buffer
|
|
613
635
|
* @example
|
|
614
|
-
* ```
|
|
615
|
-
* How to get the data from a buffer
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
* for i=
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
636
|
+
* ```ts
|
|
637
|
+
* // How to get the data from a buffer
|
|
638
|
+
* export default defineScript({
|
|
639
|
+
* init() {
|
|
640
|
+
* const res_path = go.get("#mesh", "vertices");
|
|
641
|
+
* const buf = resource.get_buffer(res_path);
|
|
642
|
+
* const stream_positions = buffer.get_stream(buf, "position");
|
|
643
|
+
*
|
|
644
|
+
* for (let i = 0; i < stream_positions.length; i++) {
|
|
645
|
+
* print(i, stream_positions[i]);
|
|
646
|
+
* }
|
|
647
|
+
* },
|
|
648
|
+
* });
|
|
626
649
|
* ```
|
|
627
650
|
*/
|
|
628
651
|
function get_buffer(path: Hash | string): Opaque<"buffer">;
|
|
@@ -661,25 +684,28 @@ declare global {
|
|
|
661
684
|
* `texture`
|
|
662
685
|
* hash The hashed path to the attachment texture resource. This field is only available if the render target passed in is a resource.
|
|
663
686
|
* @example
|
|
664
|
-
* ```
|
|
665
|
-
* Get the metadata from a render target resource
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
687
|
+
* ```ts
|
|
688
|
+
* // Get the metadata from a render target resource
|
|
689
|
+
* export default defineScript({
|
|
690
|
+
* init() {
|
|
691
|
+
* const info = resource.get_render_target_info("/my_render_target.render_targetc");
|
|
692
|
+
* // the info table contains meta data about all the render target attachments
|
|
693
|
+
* // so it's not necessary to use resource.get_texture here, but we do it here
|
|
694
|
+
* // just to show that it's possible:
|
|
695
|
+
* const info_attachment_1 = resource.get_texture_info(info.attachments[0].handle);
|
|
696
|
+
* },
|
|
697
|
+
* });
|
|
698
|
+
*
|
|
699
|
+
* // Get a texture attachment from a render target and set it on a model component
|
|
700
|
+
* export default defineScript({
|
|
701
|
+
* init() {
|
|
702
|
+
* const info = resource.get_render_target_info("/my_render_target.render_targetc");
|
|
703
|
+
* const attachment = info.attachments[0].texture;
|
|
704
|
+
* // you can also get texture info from the 'texture' field, since it's a resource hash
|
|
705
|
+
* const texture_info = resource.get_texture_info(attachment);
|
|
706
|
+
* go.set("#model", "texture0", attachment);
|
|
707
|
+
* },
|
|
708
|
+
* });
|
|
683
709
|
* ```
|
|
684
710
|
*/
|
|
685
711
|
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 };
|
|
@@ -703,12 +729,14 @@ declare global {
|
|
|
703
729
|
* - max_ascent
|
|
704
730
|
* - max_descent
|
|
705
731
|
* @example
|
|
706
|
-
* ```
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
732
|
+
* ```ts
|
|
733
|
+
* export default defineScript({
|
|
734
|
+
* init() {
|
|
735
|
+
* const font = go.get("#label", "font");
|
|
736
|
+
* const metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog");
|
|
737
|
+
* pprint(metrics);
|
|
738
|
+
* },
|
|
739
|
+
* });
|
|
712
740
|
* ```
|
|
713
741
|
*/
|
|
714
742
|
function get_text_metrics(url: Hash, text: string, options?: { width?: number; leading?: number; tracking?: number; line_break?: boolean }): Record<string | number, unknown>;
|
|
@@ -740,41 +768,44 @@ declare global {
|
|
|
740
768
|
* - `graphics.TEXTURE_TYPE_IMAGE_3D`
|
|
741
769
|
* - `graphics.TEXTURE_TYPE_CUBE_MAP`
|
|
742
770
|
* @example
|
|
743
|
-
* ```
|
|
744
|
-
* Create a new texture and get the metadata from it
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
*
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
771
|
+
* ```ts
|
|
772
|
+
* // Create a new texture and get the metadata from it
|
|
773
|
+
* export default defineScript({
|
|
774
|
+
* init() {
|
|
775
|
+
* // create an empty texture
|
|
776
|
+
* const tparams = {
|
|
777
|
+
* width: 128,
|
|
778
|
+
* height: 128,
|
|
779
|
+
* type: graphics.TEXTURE_TYPE_2D,
|
|
780
|
+
* format: graphics.TEXTURE_FORMAT_RGBA,
|
|
781
|
+
* };
|
|
782
|
+
*
|
|
783
|
+
* const my_texture_path = resource.create_texture("/my_texture.texturec", tparams);
|
|
784
|
+
* const my_texture_info = resource.get_texture_info(my_texture_path);
|
|
785
|
+
*
|
|
786
|
+
* // my_texture_info now contains
|
|
787
|
+
* // {
|
|
788
|
+
* // handle = <the-numeric-handle>,
|
|
789
|
+
* // width = 128,
|
|
790
|
+
* // height = 128,
|
|
791
|
+
* // depth = 1
|
|
792
|
+
* // mipmaps = 1,
|
|
793
|
+
* // page_count = 1,
|
|
794
|
+
* // type = graphics.TEXTURE_TYPE_2D,
|
|
795
|
+
* // flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE
|
|
796
|
+
* // }
|
|
797
|
+
* },
|
|
798
|
+
* });
|
|
799
|
+
*
|
|
800
|
+
* // Get the meta data from an atlas resource
|
|
801
|
+
* export default defineScript({
|
|
802
|
+
* init() {
|
|
803
|
+
* const my_atlas_info = resource.get_atlas("/my_atlas.a.texturesetc");
|
|
804
|
+
* const my_texture_info = resource.get_texture_info(my_atlas_info.texture);
|
|
805
|
+
*
|
|
806
|
+
* // my_texture_info now contains the information about the texture that is backing the atlas
|
|
807
|
+
* },
|
|
808
|
+
* });
|
|
778
809
|
* ```
|
|
779
810
|
*/
|
|
780
811
|
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 };
|
|
@@ -784,16 +815,16 @@ declare global {
|
|
|
784
815
|
* @param path - The path to the resource
|
|
785
816
|
* @returns Returns the buffer stored on disc
|
|
786
817
|
* @example
|
|
787
|
-
* ```
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
* In order for the engine to include custom resources in the build process, you
|
|
792
|
-
* to specify them in the "game.project" settings file:
|
|
793
|
-
* [project]
|
|
794
|
-
* title = My project
|
|
795
|
-
* version = 0.1
|
|
796
|
-
* custom_resources = resources/,assets/level_data.json
|
|
818
|
+
* ```ts
|
|
819
|
+
* // read custom resource data into buffer
|
|
820
|
+
* const buffer = resource.load("/resources/datafile");
|
|
821
|
+
*
|
|
822
|
+
* // In order for the engine to include custom resources in the build process, you
|
|
823
|
+
* // need to specify them in the "game.project" settings file:
|
|
824
|
+
* // [project]
|
|
825
|
+
* // title = My project
|
|
826
|
+
* // version = 0.1
|
|
827
|
+
* // custom_resources = resources/,assets/level_data.json
|
|
797
828
|
* ```
|
|
798
829
|
*/
|
|
799
830
|
function load(path: string): Opaque<"buffer">;
|
|
@@ -806,18 +837,24 @@ declare global {
|
|
|
806
837
|
* @param path - optional resource path string to the resource
|
|
807
838
|
* @returns a path hash to the binary version of the resource
|
|
808
839
|
* @example
|
|
809
|
-
* ```
|
|
810
|
-
* Load a material and set it to a sprite:
|
|
811
|
-
* go.property("my_material", resource.material("/material.material"))
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
840
|
+
* ```ts
|
|
841
|
+
* // Load a material and set it to a sprite:
|
|
842
|
+
* go.property("my_material", resource.material("/material.material"));
|
|
843
|
+
*
|
|
844
|
+
* export default defineScript({
|
|
845
|
+
* init(self) {
|
|
846
|
+
* go.set("#sprite", "material", self.my_material);
|
|
847
|
+
* },
|
|
848
|
+
* });
|
|
849
|
+
*
|
|
850
|
+
* // Load a material resource and update a named material with the resource:
|
|
851
|
+
* go.property("my_material", resource.material("/material.material"));
|
|
852
|
+
*
|
|
853
|
+
* export default defineScript({
|
|
854
|
+
* init(self) {
|
|
855
|
+
* go.set("#gui", "materials", self.my_material, { key: "my_material" });
|
|
856
|
+
* },
|
|
857
|
+
* });
|
|
821
858
|
* ```
|
|
822
859
|
*/
|
|
823
860
|
function material(path?: string): Hash;
|
|
@@ -837,13 +874,16 @@ declare global {
|
|
|
837
874
|
* @param path - optional resource path string to the resource
|
|
838
875
|
* @returns a path hash to the binary version of the resource
|
|
839
876
|
* @example
|
|
840
|
-
* ```
|
|
841
|
-
* Set a render target color attachment as a model texture:
|
|
842
|
-
* go.property("my_render_target", resource.render_target("/rt.render_target"))
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
877
|
+
* ```ts
|
|
878
|
+
* // Set a render target color attachment as a model texture:
|
|
879
|
+
* go.property("my_render_target", resource.render_target("/rt.render_target"));
|
|
880
|
+
*
|
|
881
|
+
* export default defineScript({
|
|
882
|
+
* init(self) {
|
|
883
|
+
* const rt_info = resource.get_render_target_info(self.my_render_target);
|
|
884
|
+
* go.set("#model", "texture0", rt_info.attachments[0].texture);
|
|
885
|
+
* },
|
|
886
|
+
* });
|
|
847
887
|
* ```
|
|
848
888
|
*/
|
|
849
889
|
function render_target(path?: string): Hash;
|
|
@@ -853,11 +893,11 @@ declare global {
|
|
|
853
893
|
* @param path - The path to the resource
|
|
854
894
|
* @param buffer - The buffer of precreated data, suitable for the intended resource type
|
|
855
895
|
* @example
|
|
856
|
-
* ```
|
|
857
|
-
* Assuming the folder "/res" is added to the project custom resources:
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
* resource.set(go.get("#sprite", "texture0"), buffer)
|
|
896
|
+
* ```ts
|
|
897
|
+
* // Assuming the folder "/res" is added to the project custom resources:
|
|
898
|
+
* // load a texture resource and set it on a sprite
|
|
899
|
+
* const buffer = resource.load("/res/new.texturec");
|
|
900
|
+
* resource.set(go.get("#sprite", "texture0"), buffer);
|
|
861
901
|
* ```
|
|
862
902
|
*/
|
|
863
903
|
function set(path: string | Hash, buffer: Opaque<"buffer">): void;
|
|
@@ -922,56 +962,49 @@ declare global {
|
|
|
922
962
|
* `indices`
|
|
923
963
|
* table a list of the indices of the geometry in the form {i0, i1, i2, ..., in}. Each tripe in the list represents a triangle.
|
|
924
964
|
* @example
|
|
925
|
-
* ```
|
|
926
|
-
* Add a new animation to an existing atlas
|
|
927
|
-
*
|
|
928
|
-
*
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
*
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
*
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
965
|
+
* ```ts
|
|
966
|
+
* // Add a new animation to an existing atlas
|
|
967
|
+
* export default defineScript({
|
|
968
|
+
* init() {
|
|
969
|
+
* const data = resource.get_atlas("/main/my_atlas.a.texturesetc");
|
|
970
|
+
* const my_animation = {
|
|
971
|
+
* id: "my_new_animation",
|
|
972
|
+
* width: 128,
|
|
973
|
+
* height: 128,
|
|
974
|
+
* frame_start: 1,
|
|
975
|
+
* frame_end: 6,
|
|
976
|
+
* playback: go.PLAYBACK_LOOP_PINGPONG,
|
|
977
|
+
* fps: 8,
|
|
978
|
+
* };
|
|
979
|
+
* data.animations.push(my_animation);
|
|
980
|
+
* resource.set_atlas("/main/my_atlas.a.texturesetc", data);
|
|
981
|
+
* },
|
|
982
|
+
* });
|
|
983
|
+
*
|
|
984
|
+
* // Sets atlas data for a 256x256 texture with a single animation being rendered as a quad
|
|
985
|
+
* export default defineScript({
|
|
986
|
+
* init() {
|
|
987
|
+
* const params = {
|
|
988
|
+
* texture: "/main/my_256x256_texture.texturec",
|
|
989
|
+
* animations: [
|
|
990
|
+
* {
|
|
991
|
+
* id: "my_animation",
|
|
992
|
+
* width: 256,
|
|
993
|
+
* height: 256,
|
|
994
|
+
* frames: [1],
|
|
954
995
|
* },
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
*
|
|
961
|
-
*
|
|
962
|
-
*
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
* 256, 0
|
|
968
|
-
* },
|
|
969
|
-
* indices = { 0,1,2,0,2,3 }
|
|
970
|
-
* }
|
|
971
|
-
* }
|
|
972
|
-
* }
|
|
973
|
-
* resource.set_atlas("/main/test.a.texturesetc", params)
|
|
974
|
-
* end
|
|
996
|
+
* ],
|
|
997
|
+
* geometries: [
|
|
998
|
+
* {
|
|
999
|
+
* vertices: [0, 0, 0, 256, 256, 256, 256, 0],
|
|
1000
|
+
* uvs: [0, 0, 0, 256, 256, 256, 256, 0],
|
|
1001
|
+
* indices: [0, 1, 2, 0, 2, 3],
|
|
1002
|
+
* },
|
|
1003
|
+
* ],
|
|
1004
|
+
* };
|
|
1005
|
+
* resource.set_atlas("/main/test.a.texturesetc", params);
|
|
1006
|
+
* },
|
|
1007
|
+
* });
|
|
975
1008
|
* ```
|
|
976
1009
|
*/
|
|
977
1010
|
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?: Record<string | number, unknown>; vertices?: number[]; uvs?: number[]; indices?: number[] }): void;
|
|
@@ -991,38 +1024,37 @@ declare global {
|
|
|
991
1024
|
* `transfer_ownership`
|
|
992
1025
|
* boolean optional flag to determine wether or not the resource should take over ownership of the buffer object (default false)
|
|
993
1026
|
* @example
|
|
994
|
-
* ```
|
|
995
|
-
* How to set the data from a buffer
|
|
996
|
-
*
|
|
997
|
-
*
|
|
998
|
-
*
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1027
|
+
* ```ts
|
|
1028
|
+
* // How to set the data from a buffer
|
|
1029
|
+
* function fill_stream(stream, verts) {
|
|
1030
|
+
* verts.forEach((value, key) => {
|
|
1031
|
+
* stream[key] = verts[key];
|
|
1032
|
+
* });
|
|
1033
|
+
* }
|
|
1001
1034
|
*
|
|
1002
|
-
*
|
|
1035
|
+
* export default defineScript({
|
|
1036
|
+
* init() {
|
|
1037
|
+
* const res_path = go.get("#mesh", "vertices");
|
|
1003
1038
|
*
|
|
1004
|
-
*
|
|
1039
|
+
* const positions = [
|
|
1040
|
+
* 1, -1, 0,
|
|
1041
|
+
* 1, 1, 0,
|
|
1042
|
+
* -1, -1, 0,
|
|
1043
|
+
* ];
|
|
1005
1044
|
*
|
|
1006
|
-
*
|
|
1007
|
-
* 1, -1, 0,
|
|
1008
|
-
* 1, 1, 0,
|
|
1009
|
-
* -1, -1, 0
|
|
1010
|
-
* }
|
|
1011
|
-
*
|
|
1012
|
-
* local num_verts = #positions / 3
|
|
1045
|
+
* const num_verts = positions.length / 3;
|
|
1013
1046
|
*
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
* { name = hash("position"), type=buffer.VALUE_TYPE_FLOAT32, count = 3 }
|
|
1017
|
-
* })
|
|
1047
|
+
* // create a new buffer
|
|
1048
|
+
* let buf = buffer.create(num_verts, [{ name: hash("position"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);
|
|
1018
1049
|
*
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
1050
|
+
* buf = resource.get_buffer(res_path);
|
|
1051
|
+
* const stream_positions = buffer.get_stream(buf, "position");
|
|
1021
1052
|
*
|
|
1022
|
-
* fill_stream(stream_positions, positions)
|
|
1053
|
+
* fill_stream(stream_positions, positions);
|
|
1023
1054
|
*
|
|
1024
|
-
* resource.set_buffer(res_path, buf)
|
|
1025
|
-
*
|
|
1055
|
+
* resource.set_buffer(res_path, buf);
|
|
1056
|
+
* },
|
|
1057
|
+
* });
|
|
1026
1058
|
* ```
|
|
1027
1059
|
*/
|
|
1028
1060
|
function set_buffer(path: Hash | string, buffer: Opaque<"buffer">, table?: { transfer_ownership?: boolean }): void;
|
|
@@ -1102,119 +1134,128 @@ declare global {
|
|
|
1102
1134
|
* -- Device and graphics adapter support 3D textures
|
|
1103
1135
|
* end
|
|
1104
1136
|
* @example
|
|
1105
|
-
* ```
|
|
1106
|
-
* How to set all pixels of an atlas
|
|
1107
|
-
*
|
|
1108
|
-
* self
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1112
|
-
*
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1118
|
-
*
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
* local resource_path = go.get("#model", "texture0")
|
|
1123
|
-
* local args = { width=self.width, height=self.height, type=graphics.TEXTURE_TYPE_2D, format=graphics.TEXTURE_FORMAT_RGB, num_mip_maps=1 }
|
|
1124
|
-
* resource.set_texture( resource_path, args, self.buffer )
|
|
1125
|
-
* end
|
|
1126
|
-
* ```How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
|
|
1127
|
-
*
|
|
1128
|
-
* ```lua
|
|
1129
|
-
* function init(self)
|
|
1130
|
-
* self.x = 16
|
|
1131
|
-
* self.y = 16
|
|
1132
|
-
* self.height = 128 - self.x * 2
|
|
1133
|
-
* self.width = 128 - self.y * 2
|
|
1134
|
-
* self.buffer = buffer.create(self.width * self.height, { {name=hash("rgb"), type=buffer.VALUE_TYPE_UINT8, count=3} } )
|
|
1135
|
-
* self.stream = buffer.get_stream(self.buffer, hash("rgb"))
|
|
1136
|
-
*
|
|
1137
|
-
* for y=1,self.height do
|
|
1138
|
-
* for x=1,self.width do
|
|
1139
|
-
* local index = (y-1) * self.width * 3 + (x-1) * 3 + 1
|
|
1140
|
-
* self.stream[index + 0] = 0xff
|
|
1141
|
-
* self.stream[index + 1] = 0x80
|
|
1142
|
-
* self.stream[index + 2] = 0x10
|
|
1143
|
-
* end
|
|
1144
|
-
* end
|
|
1145
|
-
*
|
|
1146
|
-
* local resource_path = go.get("#model", "texture0")
|
|
1147
|
-
* 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 }
|
|
1148
|
-
* resource.set_texture(resource_path, args, self.buffer )
|
|
1149
|
-
* end
|
|
1150
|
-
* ```Update a texture from a buffer resource
|
|
1151
|
-
* ```lua
|
|
1152
|
-
* go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"))
|
|
1153
|
-
*
|
|
1154
|
-
* function init(self)
|
|
1155
|
-
* local resource_path = go.get("#model", "texture0")
|
|
1156
|
-
* -- the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
|
|
1157
|
-
* local args = {
|
|
1158
|
-
* width = 128,
|
|
1159
|
-
* height = 128,
|
|
1160
|
-
* type = graphics.TEXTURE_TYPE_2D,
|
|
1161
|
-
* format = graphics.TEXTURE_FORMAT_RGB
|
|
1162
|
-
* }
|
|
1163
|
-
* -- Note that the extra resource.get_buffer call is a requirement here
|
|
1164
|
-
* -- since the "self.my_buffer" is just pointing to a buffer resource path
|
|
1165
|
-
* -- and not an actual buffer object or buffer resource.
|
|
1166
|
-
* resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer))
|
|
1167
|
-
* end
|
|
1168
|
-
* ```Update an existing 3D texture from a lua buffer
|
|
1169
|
-
*
|
|
1170
|
-
* ```lua
|
|
1137
|
+
* ```ts
|
|
1138
|
+
* // How to set all pixels of an atlas
|
|
1139
|
+
* export default defineScript({
|
|
1140
|
+
* init(self) {
|
|
1141
|
+
* self.height = 128;
|
|
1142
|
+
* self.width = 128;
|
|
1143
|
+
* self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
|
|
1144
|
+
* self.stream = buffer.get_stream(self.buffer, hash("rgb"));
|
|
1145
|
+
*
|
|
1146
|
+
* for (let y = 0; y < self.height; y++) {
|
|
1147
|
+
* for (let x = 0; x < self.width; x++) {
|
|
1148
|
+
* const index = y * self.width * 3 + x * 3;
|
|
1149
|
+
* self.stream[index + 0] = 0xff;
|
|
1150
|
+
* self.stream[index + 1] = 0x80;
|
|
1151
|
+
* self.stream[index + 2] = 0x10;
|
|
1152
|
+
* }
|
|
1153
|
+
* }
|
|
1171
1154
|
*
|
|
1172
|
-
*
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1193
|
-
*
|
|
1194
|
-
*
|
|
1195
|
-
* depth = 8,
|
|
1196
|
-
* format = resource.TEXTURE_FORMAT_RGBA32F
|
|
1155
|
+
* const resource_path = go.get("#model", "texture0");
|
|
1156
|
+
* const args = { width: self.width, height: self.height, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
|
|
1157
|
+
* resource.set_texture(resource_path, args, self.buffer);
|
|
1158
|
+
* },
|
|
1159
|
+
* });
|
|
1160
|
+
*
|
|
1161
|
+
* // How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.
|
|
1162
|
+
* export default defineScript({
|
|
1163
|
+
* init(self) {
|
|
1164
|
+
* self.x = 16;
|
|
1165
|
+
* self.y = 16;
|
|
1166
|
+
* self.height = 128 - self.x * 2;
|
|
1167
|
+
* self.width = 128 - self.y * 2;
|
|
1168
|
+
* self.buffer = buffer.create(self.width * self.height, [{ name: hash("rgb"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);
|
|
1169
|
+
* self.stream = buffer.get_stream(self.buffer, hash("rgb"));
|
|
1170
|
+
*
|
|
1171
|
+
* for (let y = 0; y < self.height; y++) {
|
|
1172
|
+
* for (let x = 0; x < self.width; x++) {
|
|
1173
|
+
* const index = y * self.width * 3 + x * 3;
|
|
1174
|
+
* self.stream[index + 0] = 0xff;
|
|
1175
|
+
* self.stream[index + 1] = 0x80;
|
|
1176
|
+
* self.stream[index + 2] = 0x10;
|
|
1177
|
+
* }
|
|
1197
1178
|
* }
|
|
1198
1179
|
*
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1203
|
-
*
|
|
1180
|
+
* const resource_path = go.get("#model", "texture0");
|
|
1181
|
+
* const args = { width: self.width, height: self.height, x: self.x, y: self.y, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };
|
|
1182
|
+
* resource.set_texture(resource_path, args, self.buffer);
|
|
1183
|
+
* },
|
|
1184
|
+
* });
|
|
1185
|
+
*
|
|
1186
|
+
* // Update a texture from a buffer resource
|
|
1187
|
+
* go.property("my_buffer", resource.buffer("/my_default_buffer.buffer"));
|
|
1188
|
+
*
|
|
1189
|
+
* export default defineScript({
|
|
1190
|
+
* init(self) {
|
|
1191
|
+
* const resource_path = go.get("#model", "texture0");
|
|
1192
|
+
* // the "my_buffer" resource is expected to hold 128 * 128 * 3 bytes!
|
|
1193
|
+
* const args = {
|
|
1194
|
+
* width: 128,
|
|
1195
|
+
* height: 128,
|
|
1196
|
+
* type: graphics.TEXTURE_TYPE_2D,
|
|
1197
|
+
* format: graphics.TEXTURE_FORMAT_RGB,
|
|
1198
|
+
* };
|
|
1199
|
+
* // Note that the extra resource.get_buffer call is a requirement here
|
|
1200
|
+
* // since the "self.my_buffer" is just pointing to a buffer resource path
|
|
1201
|
+
* // and not an actual buffer object or buffer resource.
|
|
1202
|
+
* resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));
|
|
1203
|
+
* },
|
|
1204
|
+
* });
|
|
1205
|
+
*
|
|
1206
|
+
* // Update an existing 3D texture from a buffer
|
|
1207
|
+
* export default defineScript({
|
|
1208
|
+
* init() {
|
|
1209
|
+
* // create a buffer that can hold the data of a 8x8x8 texture
|
|
1210
|
+
* const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash("rgba"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);
|
|
1211
|
+
* const tstream = buffer.get_stream(tbuffer, hash("rgba"));
|
|
1212
|
+
*
|
|
1213
|
+
* // populate the buffer with some data
|
|
1214
|
+
* let index = 0;
|
|
1215
|
+
* for (let z = 0; z < 8; z++) {
|
|
1216
|
+
* for (let y = 0; y < 8; y++) {
|
|
1217
|
+
* for (let x = 0; x < 8; x++) {
|
|
1218
|
+
* tstream[index + 0] = x;
|
|
1219
|
+
* tstream[index + 1] = y;
|
|
1220
|
+
* tstream[index + 2] = z;
|
|
1221
|
+
* tstream[index + 3] = 1.0;
|
|
1222
|
+
* index = index + 4;
|
|
1223
|
+
* }
|
|
1224
|
+
* }
|
|
1225
|
+
* }
|
|
1204
1226
|
*
|
|
1205
|
-
*
|
|
1206
|
-
*
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1227
|
+
* const t_args = {
|
|
1228
|
+
* type: graphics.TEXTURE_TYPE_IMAGE_3D,
|
|
1229
|
+
* width: 8,
|
|
1230
|
+
* height: 8,
|
|
1231
|
+
* depth: 8,
|
|
1232
|
+
* format: resource.TEXTURE_FORMAT_RGBA32F,
|
|
1233
|
+
* };
|
|
1234
|
+
*
|
|
1235
|
+
* // This expects that the texture resource "/my_3d_texture.texturec" already exists
|
|
1236
|
+
* // and is a 3D texture resource. To create a dynamic 3D texture resource
|
|
1237
|
+
* // use the "resource.create_texture" function.
|
|
1238
|
+
* resource.set_texture("/my_3d_texture.texturec", t_args, tbuffer);
|
|
1239
|
+
* },
|
|
1240
|
+
* });
|
|
1241
|
+
*
|
|
1242
|
+
* // Update texture 2nd array page with loaded texture from png
|
|
1243
|
+
* // new_tex is resource handle of texture which was created via resource.create_resource
|
|
1244
|
+
* const tex_path = "/bundle_resources/page_02.png";
|
|
1245
|
+
* const [data] = sys.load_resource(tex_path);
|
|
1246
|
+
* const buf = image.load_buffer(data);
|
|
1247
|
+
* resource.set_texture(
|
|
1248
|
+
* new_tex,
|
|
1249
|
+
* {
|
|
1250
|
+
* type: graphics.TEXTURE_TYPE_2D_ARRAY,
|
|
1251
|
+
* width: buf.width,
|
|
1252
|
+
* height: buf.height,
|
|
1253
|
+
* page: 1,
|
|
1254
|
+
* format: graphics.TEXTURE_FORMAT_RGB,
|
|
1255
|
+
* },
|
|
1256
|
+
* buf.buffer,
|
|
1257
|
+
* );
|
|
1258
|
+
* go.set("#mesh", "texture0", new_tex);
|
|
1218
1259
|
* ```
|
|
1219
1260
|
*/
|
|
1220
1261
|
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;
|
|
@@ -1227,12 +1268,15 @@ declare global {
|
|
|
1227
1268
|
* @param path - optional resource path string to the resource
|
|
1228
1269
|
* @returns a path hash to the binary version of the resource
|
|
1229
1270
|
* @example
|
|
1230
|
-
* ```
|
|
1231
|
-
* Load a texture and set it to a model:
|
|
1232
|
-
* go.property("my_texture", resource.texture("/texture.png"))
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1271
|
+
* ```ts
|
|
1272
|
+
* // Load a texture and set it to a model:
|
|
1273
|
+
* go.property("my_texture", resource.texture("/texture.png"));
|
|
1274
|
+
*
|
|
1275
|
+
* export default defineScript({
|
|
1276
|
+
* init(self) {
|
|
1277
|
+
* go.set("#model", "texture0", self.my_texture);
|
|
1278
|
+
* },
|
|
1279
|
+
* });
|
|
1236
1280
|
* ```
|
|
1237
1281
|
*/
|
|
1238
1282
|
function texture(path?: string): Hash;
|
|
@@ -1245,12 +1289,15 @@ declare global {
|
|
|
1245
1289
|
* @param path - optional resource path string to the resource
|
|
1246
1290
|
* @returns a path hash to the binary version of the resource
|
|
1247
1291
|
* @example
|
|
1248
|
-
* ```
|
|
1249
|
-
* Load tile source and set it to a tile map:
|
|
1250
|
-
* go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"))
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1292
|
+
* ```ts
|
|
1293
|
+
* // Load tile source and set it to a tile map:
|
|
1294
|
+
* go.property("my_tile_source", resource.tile_source("/tilesource.tilesource"));
|
|
1295
|
+
*
|
|
1296
|
+
* export default defineScript({
|
|
1297
|
+
* init(self) {
|
|
1298
|
+
* go.set("#tilemap", "tile_source", self.my_tile_source);
|
|
1299
|
+
* },
|
|
1300
|
+
* });
|
|
1254
1301
|
* ```
|
|
1255
1302
|
*/
|
|
1256
1303
|
function tile_source(path?: string): Hash;
|