@defold-typescript/types 0.39.0 → 0.40.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/api-availability.json +117 -0
- package/api-signatures.json +262 -237
- package/examples/translations.json +81 -81
- package/generated/b2d_shape.d.ts +23 -1
- package/generated/buffer.d.ts +18 -15
- package/generated/camera.d.ts +2 -2
- package/generated/collectionfactory.d.ts +12 -10
- package/generated/collectionproxy.d.ts +1 -1
- package/generated/compute.d.ts +1 -1
- package/generated/go.d.ts +9 -5
- package/generated/graphics.d.ts +52 -0
- package/generated/gui.d.ts +53 -32
- package/generated/html5.d.ts +3 -1
- package/generated/http.d.ts +4 -2
- package/generated/image.d.ts +24 -15
- package/generated/kinds/gui-script.d.ts +1 -0
- package/generated/kinds/render-script.d.ts +1 -0
- package/generated/kinds/script.d.ts +1 -0
- package/generated/material.d.ts +1 -1
- package/generated/model.d.ts +32 -3
- package/generated/physics.d.ts +13 -11
- package/generated/profiler.d.ts +1 -1
- package/generated/render.d.ts +72 -15
- package/generated/resource.d.ts +100 -69
- package/generated/socket.d.ts +23 -13
- package/generated/sound.d.ts +3 -3
- package/generated/sprite.d.ts +9 -1
- package/generated/sys.d.ts +34 -23
- package/generated/versions/defold-1.12.4/buffer.d.ts +18 -15
- package/generated/versions/defold-1.12.4/camera.d.ts +2 -2
- package/generated/versions/defold-1.12.4/collectionfactory.d.ts +12 -10
- package/generated/versions/defold-1.12.4/go.d.ts +9 -5
- package/generated/versions/defold-1.12.4/gui.d.ts +47 -31
- package/generated/versions/defold-1.12.4/html5.d.ts +3 -1
- package/generated/versions/defold-1.12.4/http.d.ts +4 -2
- package/generated/versions/defold-1.12.4/image.d.ts +24 -15
- package/generated/versions/defold-1.12.4/index.d.ts +1 -0
- package/generated/versions/defold-1.12.4/model.d.ts +32 -3
- package/generated/versions/defold-1.12.4/physics.d.ts +13 -11
- package/generated/versions/defold-1.12.4/profiler.d.ts +1 -1
- package/generated/versions/defold-1.12.4/render.d.ts +72 -15
- package/generated/versions/defold-1.12.4/resource.d.ts +100 -69
- package/generated/versions/defold-1.12.4/socket.d.ts +23 -13
- package/generated/versions/defold-1.12.4/sound.d.ts +3 -3
- package/generated/versions/defold-1.12.4/sprite.d.ts +9 -1
- package/generated/versions/defold-1.12.4/sys.d.ts +34 -23
- package/generated/versions/defold-1.12.4/vmath.d.ts +5 -5
- package/generated/versions/defold-1.13.0/b2d_shape.d.ts +23 -1
- package/generated/versions/defold-1.13.0/buffer.d.ts +18 -15
- package/generated/versions/defold-1.13.0/camera.d.ts +2 -2
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +12 -10
- package/generated/versions/defold-1.13.0/compute.d.ts +1 -1
- package/generated/versions/defold-1.13.0/go.d.ts +9 -5
- package/generated/versions/defold-1.13.0/graphics.d.ts +48 -0
- package/generated/versions/defold-1.13.0/gui.d.ts +47 -31
- package/generated/versions/defold-1.13.0/html5.d.ts +3 -1
- package/generated/versions/defold-1.13.0/http.d.ts +4 -2
- package/generated/versions/defold-1.13.0/image.d.ts +24 -15
- package/generated/versions/defold-1.13.0/index.d.ts +1 -0
- package/generated/versions/defold-1.13.0/material.d.ts +1 -1
- package/generated/versions/defold-1.13.0/model.d.ts +32 -3
- package/generated/versions/defold-1.13.0/physics.d.ts +13 -11
- package/generated/versions/defold-1.13.0/profiler.d.ts +1 -1
- package/generated/versions/defold-1.13.0/render.d.ts +72 -15
- package/generated/versions/defold-1.13.0/resource.d.ts +100 -69
- package/generated/versions/defold-1.13.0/socket.d.ts +23 -13
- package/generated/versions/defold-1.13.0/sound.d.ts +3 -3
- package/generated/versions/defold-1.13.0/sprite.d.ts +9 -1
- package/generated/versions/defold-1.13.0/sys.d.ts +34 -23
- package/generated/versions/defold-1.13.0/vmath.d.ts +5 -5
- package/generated/vmath.d.ts +5 -5
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/scripts/generate-api-signatures.ts +2 -1
- package/scripts/prose-constants.ts +96 -0
- package/scripts/regen.ts +6 -2
- package/src/component-properties.d.ts +33 -0
- package/src/core-types.ts +4 -2
- package/src/custom-messages.d.ts +4 -3
- package/src/doc-comment.ts +35 -12
- package/src/emit-dts.ts +457 -47
- package/src/engine-globals.d.ts +2 -2
- package/src/go-overloads.d.ts +11 -10
- package/src/index.ts +4 -0
- package/src/param-correction-provenance.ts +67 -0
- package/src/render-overloads.d.ts +15 -0
- package/src/script-api.ts +3 -1
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"buffer.copy_stream": [
|
|
33
33
|
{
|
|
34
34
|
"sourceHash": "359ea94639622db5",
|
|
35
|
-
"ts": "// How to update a texture of a sprite:\nconst srcbuffer = resource.get_buffer(\"/src.bufferc\");\nconst dstbuffer = resource.get_buffer(\"/dst.bufferc\");\n\n// copy entire stream\nconst srcstream = buffer.get_stream(srcbuffer, hash(\"xyz\"));\nconst dststream = buffer.get_stream(dstbuffer, hash(\"xyz\"));\nbuffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length);"
|
|
35
|
+
"ts": "// How to update a texture of a sprite:\nconst srcbuffer = resource.get_buffer(\"/src.bufferc\");\nconst dstbuffer = resource.get_buffer(\"/dst.bufferc\");\n\n// copy entire stream\nconst srcstream = buffer.get_stream(srcbuffer, hash(\"xyz\"));\nconst dststream = buffer.get_stream(dstbuffer, hash(\"xyz\"));\nbuffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length());"
|
|
36
36
|
}
|
|
37
37
|
],
|
|
38
38
|
"buffer.create": [
|
|
39
39
|
{
|
|
40
40
|
"sourceHash": "d83315970921bbc7",
|
|
41
|
-
"ts": "// How to create and initialize a buffer\nexport default defineScript({\n init(
|
|
41
|
+
"ts": "// How to create and initialize a buffer\nexport default defineScript({\n init() {\n const size = 128;\n const [width, height] = [size, size];\n const [r, g, b] = [0xff, 0x80, 0x10];\n const image = buffer.create(size * size, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n const imagestream = buffer.get_stream(image, hash(\"rgb\"));\n\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const index = y * width * 3 + x * 3;\n imagestream[index + 0] = r;\n imagestream[index + 1] = g;\n imagestream[index + 2] = b;\n }\n }\n return { image, imagestream };\n },\n});"
|
|
42
42
|
}
|
|
43
43
|
],
|
|
44
44
|
"buffer.get_metadata": [
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"camera.screen_to_world": [
|
|
63
63
|
{
|
|
64
64
|
"sourceHash": "0738c074908495cb",
|
|
65
|
-
"ts": "// Place objects at the touch point with a random Z position, keeping them\n// within the visible view zone.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed) {\n const perspective_camera = msg.url(\"#perspective_camera\");\n const random_z = math.random(\n camera.get_near_z(perspective_camera) + 0.01,\n camera.get_far_z(perspective_camera) - 0.01,\n );\n const world_position = camera.screen_to_world(\n vmath.vector3(action.screen_x, action.screen_y, random_z),\n perspective_camera,\n );\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
65
|
+
"ts": "// Place objects at the touch point with a random Z position, keeping them\n// within the visible view zone.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {\n const perspective_camera = msg.url(\"#perspective_camera\");\n const random_z = math.random(\n camera.get_near_z(perspective_camera) + 0.01,\n camera.get_far_z(perspective_camera) - 0.01,\n );\n const world_position = camera.screen_to_world(\n vmath.vector3(action.screen_x, action.screen_y, random_z),\n perspective_camera,\n );\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
66
66
|
}
|
|
67
67
|
],
|
|
68
68
|
"camera.screen_xy_to_world": [
|
|
69
69
|
{
|
|
70
70
|
"sourceHash": "ff65335713fc5698",
|
|
71
|
-
"ts": "// Place objects at the touch point.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed) {\n const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
71
|
+
"ts": "// Place objects at the touch point.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed && action.screen_x !== undefined && action.screen_y !== undefined) {\n const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
72
72
|
}
|
|
73
73
|
],
|
|
74
74
|
"camera.world_to_screen": [
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"collectionfactory.create": [
|
|
81
81
|
{
|
|
82
82
|
"sourceHash": "5a49721288808772",
|
|
83
|
-
"ts": "// How to spawn a collection of game objects:\nexport default defineScript({\n init(
|
|
83
|
+
"ts": "// How to spawn a collection of game objects:\nexport default defineScript({\n init() {\n // Spawn a small group of enemies.\n const pos = vmath.vector3(100, 12.5, 0);\n const rot = vmath.quat_rotation_z(Math.PI / 2);\n const scale = 0.5;\n const props = new LuaMap<Hash, Record<string, unknown>>();\n props.set(hash(\"/enemy_leader\"), { health: 1000.0 });\n props.set(hash(\"/enemy_1\"), { health: 200.0 });\n props.set(hash(\"/enemy_2\"), { health: 400.0, color: hash(\"green\") });\n\n const enemy_ids = collectionfactory.create(\"#enemyfactory\", pos, rot, props, scale);\n // enemy_ids now map to the spawned instance ids:\n //\n // pprint(self.enemy_ids)\n //\n // DEBUG:SCRIPT:\n // {\n // hash: [/enemy_leader] = hash: [/collection0/enemy_leader],\n // hash: [/enemy_1] = hash: [/collection0/enemy_1],\n // hash: [/enemy_2] = hash: [/collection0/enemy_2]\n // }\n\n // Send \"attack\" message to the leader. First look up its instance id.\n const leader_id = enemy_ids.get(hash(\"/enemy_leader\"));\n if (leader_id !== undefined) {\n msg.post(leader_id, \"attack\");\n }\n return { enemy_ids };\n },\n});\n\n// How to delete a spawned collection:\nfunction delete_enemies(self: { enemy_ids: Hash[] }) {\n go.delete(self.enemy_ids);\n}"
|
|
84
84
|
}
|
|
85
85
|
],
|
|
86
86
|
"collectionfactory.load": [
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
"editor.command": [
|
|
165
165
|
{
|
|
166
166
|
"sourceHash": "41caebab7bdd6774",
|
|
167
|
-
"ts": "// Print Git history for a file:\neditor.command({\n label: \"Git History\",\n query: { selection: { type: \"resource\", cardinality: \"one\" } },\n run: (opts) => {\n editor.execute(\"git\", \"log\", \"--follow\", `.${editor.get(opts.selection, \"path\")}`, {\n reload_resources: false,\n });\n },\n});"
|
|
167
|
+
"ts": "// Print Git history for a file:\neditor.command({\n label: \"Git History\",\n locations: [\"Assets\"],\n query: { selection: { type: \"resource\", cardinality: \"one\" } },\n run: (opts) => {\n editor.execute(\"git\", \"log\", \"--follow\", `.${editor.get(opts.selection, \"path\")}`, {\n reload_resources: false,\n });\n },\n});"
|
|
168
168
|
}
|
|
169
169
|
],
|
|
170
170
|
"editor.create_directory": [
|
|
@@ -230,7 +230,7 @@
|
|
|
230
230
|
"final": [
|
|
231
231
|
{
|
|
232
232
|
"sourceHash": "ebc3cae218af001a",
|
|
233
|
-
"ts": "export default defineScript({\n final(self) {\n // report finalization\n msg.post(\"my_friend_instance\", \"im_dead\", { my_stats: self.some_value });\n },\n});"
|
|
233
|
+
"ts": "export default defineScript({\n init() {\n return { some_value: 0 };\n },\n\n final(self) {\n // report finalization\n msg.post(\"my_friend_instance\", \"im_dead\", { my_stats: self.some_value });\n },\n});"
|
|
234
234
|
}
|
|
235
235
|
],
|
|
236
236
|
"font.add_font": [
|
|
@@ -298,7 +298,7 @@
|
|
|
298
298
|
"go.get": [
|
|
299
299
|
{
|
|
300
300
|
"sourceHash": "7cac2203eda50a5e",
|
|
301
|
-
"ts": "// Get a property \"speed\" from a script \"player\"; the property must be declared\n// in the player script:\ngo.property(\"speed\", 50);\n\n// Then in the calling script (assumed to belong to the same game object, but it\n// does not have to):\nconst speed = go.get(\"#player\", \"speed\");\n\n// Get a value in a material property array (the glsl indices are 0-based):\nconst url = msg.url(\"#mesh\");\ngo.get(url, \"example\", { index:
|
|
301
|
+
"ts": "// Get a property \"speed\" from a script \"player\"; the property must be declared\n// in the player script:\ngo.property(\"speed\", 50);\n\n// Then in the calling script (assumed to belong to the same game object, but it\n// does not have to):\nconst speed = go.get(\"#player\", \"speed\");\n\n// Get a value in a material property array (the glsl indices are 0-based):\nconst url = msg.url(\"#mesh\");\ngo.get(url, \"example\", { index: 0 }); // the first vector4 in the array: example[0]\ngo.get(url, \"example\", { index: 15 }); // the last vector4 in the array: example[15]\ngo.get(url, \"example.x\", { index: 0 }); // an element of a vector4: example[0].x\n\n// Get all values in a material property array as a table:\ngo.get(url, \"example\"); // => [vector4, vector4, ...]\ngo.get(url, \"example.x\"); // => [number1, number2, ...]\n\n// Get a named property (the resource of a certain gui font):\nconst font_hash = go.get(\"#gui\", \"fonts\", { key: \"system_font_BIG\" });\n\n// Get a property from a sub-component, using the \"keys\" options table\n// (addressing the first level of a component):\ngo.get(\"#particlefx\", \"material\", { keys: [\"cone_emitter\"] });\n\n// Get a property in a deeper sub-hierarchy (if the component supports it).\n// Note: no built-in component supports this yet, but a custom one could.\ngo.get(\"#my_component\", \"some_property\", { keys: [\"root\", \"child_node\"] });"
|
|
302
302
|
}
|
|
303
303
|
],
|
|
304
304
|
"go.get_id": [
|
|
@@ -416,7 +416,7 @@
|
|
|
416
416
|
"go.set": [
|
|
417
417
|
{
|
|
418
418
|
"sourceHash": "2ca1763ad71c1232",
|
|
419
|
-
"ts": "// Set a property \"speed\" of a script \"player\"; the property must be declared in\n// the player script:\ngo.property(\"speed\", 50);\n\n// Then in the calling script (assumed to belong to the same game object, but it\n// does not have to):\ngo.set(\"#player\", \"speed\", 100);\n\n// Set a vector4 in a material property array (the glsl indices are 0-based):\nconst url = msg.url(\"#mesh\");\ngo.set(url, \"example\", vmath.vector4(1, 1, 1, 1), { index:
|
|
419
|
+
"ts": "// Set a property \"speed\" of a script \"player\"; the property must be declared in\n// the player script:\ngo.property(\"speed\", 50);\n\n// Then in the calling script (assumed to belong to the same game object, but it\n// does not have to):\ngo.set(\"#player\", \"speed\", 100);\n\n// Set a vector4 in a material property array (the glsl indices are 0-based):\nconst url = msg.url(\"#mesh\");\ngo.set(url, \"example\", vmath.vector4(1, 1, 1, 1), { index: 0 }); // example[0] = v\ngo.set(url, \"example\", vmath.vector4(2, 2, 2, 2), { index: 15 }); // example[15] = v\ngo.set(url, \"example.x\", 7, { index: 0 }); // example[0].x = 7\n\n// Set a material property array by a table of vector4 (only the first two are\n// set; extra array elements are ignored):\ngo.set(url, \"example\", [vmath.vector4(1, 1, 1, 1), vmath.vector4(2, 2, 2, 2)]);\n\n// Set a named property (inside init(self)):\ngo.property(\"big_font\", resource.font());\n\nfunction set_named_font(self: { big_font: Hash }) {\n go.set(\"#gui\", \"fonts\", self.big_font, { key: \"system_font_BIG\" });\n}\n\n// Set a property on a sub-component, using the \"keys\" options table (inside\n// init(self)):\ngo.property(\"my_material\", resource.material());\n\nfunction set_sub_component_material(self: { my_material: Hash }) {\n go.set(\"#particlefx\", \"material\", self.my_material, { keys: [\"cone_emitter\"] });\n}\n\n// Set a property in a deeper sub-hierarchy (if the component supports it).\n// Note: no built-in component supports this yet, but a custom one could.\nconst some_value = 1;\ngo.set(\"#my_component\", \"some_property\", some_value, { keys: [\"root\", \"child_node\"] });"
|
|
420
420
|
}
|
|
421
421
|
],
|
|
422
422
|
"go.set_parent": [
|
|
@@ -512,7 +512,7 @@
|
|
|
512
512
|
"gui.cancel_animations": [
|
|
513
513
|
{
|
|
514
514
|
"sourceHash": "ac678b79b816b54d",
|
|
515
|
-
"ts": "// Start an animation of the position property of a node, then cancel parts of\n// the animation:\nconst node = gui.get_node(\"my_node\");\n// animate to new position\nconst pos = vmath.vector3(100, 100, 0);\ngui.animate(node, \"position\", pos,
|
|
515
|
+
"ts": "// Start an animation of the position property of a node, then cancel parts of\n// the animation:\nconst node = gui.get_node(\"my_node\");\n// animate to new position\nconst pos = vmath.vector3(100, 100, 0);\ngui.animate(node, \"position\", pos, gui.EASING_LINEAR, 2);\n// ...\n// cancel animation of the x component.\ngui.cancel_animations(node, \"position.x\");\n\n// Cancels all property animations on a node in a single call:\n// animate to new position and scale\ngui.animate(node, \"position\", vmath.vector3(100, 100, 0), gui.EASING_LINEAR, 5);\ngui.animate(node, \"scale\", vmath.vector3(0.5), gui.EASING_LINEAR, 5);\n// ...\n// cancel positioning and scaling at once\ngui.cancel_animations(node);"
|
|
516
516
|
}
|
|
517
517
|
],
|
|
518
518
|
"gui.cancel_flipbook": [
|
|
@@ -572,7 +572,7 @@
|
|
|
572
572
|
"gui.new_texture": [
|
|
573
573
|
{
|
|
574
574
|
"sourceHash": "192ba6f4b864704a",
|
|
575
|
-
"ts": "// How to create a texture and apply it to a new box node:\nexport default defineGuiScript({\n init(self) {\n const w = 200;\n const h = 300;\n\n // A nice orange. String with the RGB values.\n const orange = String.fromCharCode(0xff, 0x80, 0x10);\n\n // Create the texture. Repeat the color string for each pixel.\n const [ok, reason] = gui.new_texture(\"orange_tx\", w, h, \"rgb\", orange.repeat(w * h));\n if (ok) {\n // Create a box node and apply the texture to it.\n const n = gui.new_box_node(vmath.vector3(200, 200, 0), vmath.vector3(w, h, 0));\n gui.set_texture(n, \"orange_tx\");\n } else {\n // Could not create texture for some reason...\n if (reason === gui.RESULT_TEXTURE_ALREADY_EXISTS) {\n // ...\n } else {\n // ...\n }\n }\n },\n});\n\n// How to create a texture using .astc format\nconst size = 4;\nconst pos = vmath.vector3(200, 200, 0);\nconst path = \"/assets/images/logo_4x4.astc\";\nconst
|
|
575
|
+
"ts": "// How to create a texture and apply it to a new box node:\nexport default defineGuiScript({\n init(self) {\n const w = 200;\n const h = 300;\n\n // A nice orange. String with the RGB values.\n const orange = String.fromCharCode(0xff, 0x80, 0x10);\n\n // Create the texture. Repeat the color string for each pixel.\n const [ok, reason] = gui.new_texture(\"orange_tx\", w, h, \"rgb\", orange.repeat(w * h));\n if (ok) {\n // Create a box node and apply the texture to it.\n const n = gui.new_box_node(vmath.vector3(200, 200, 0), vmath.vector3(w, h, 0));\n gui.set_texture(n, \"orange_tx\");\n } else {\n // Could not create texture for some reason...\n if (reason === gui.RESULT_TEXTURE_ALREADY_EXISTS) {\n // ...\n } else {\n // ...\n }\n }\n },\n});\n\n// How to create a texture using .astc format\nconst size = 4;\nconst pos = vmath.vector3(200, 200, 0);\nconst path = \"/assets/images/logo_4x4.astc\";\nconst [data] = sys.load_resource(path);\nif (data !== undefined) {\n const n = gui.new_box_node(pos, vmath.vector3(size, size, 0));\n // size is read from the .astc buffer\n // flip is not supported\n gui.new_texture(path, 0, 0, \"astc\", data, false);\n gui.set_texture(n, path);\n}"
|
|
576
576
|
}
|
|
577
577
|
],
|
|
578
578
|
"gui.play_flipbook": [
|
|
@@ -596,17 +596,17 @@
|
|
|
596
596
|
"gui.screen_to_local": [
|
|
597
597
|
{
|
|
598
598
|
"sourceHash": "3e442324e48a7f04",
|
|
599
|
-
"ts": "// Animate a node to the pressed pointer position:\nexport default defineGuiScript({\n init() {\n msg.post(\".\", \"acquire_input_focus\");\n return { marker: gui.get_node(\"marker\") };\n },\n\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")
|
|
599
|
+
"ts": "// Animate a node to the pressed pointer position:\nexport default defineGuiScript({\n init() {\n msg.post(\".\", \"acquire_input_focus\");\n return { marker: gui.get_node(\"marker\") };\n },\n\n on_input(self, action_id, action) {\n if (\n action_id === hash(\"touch\") &&\n action.pressed &&\n action.screen_x !== undefined &&\n action.screen_y !== undefined\n ) {\n const screen_position = vmath.vector3(action.screen_x, action.screen_y, 0);\n const target_position = gui.screen_to_local(self.marker, screen_position);\n gui.animate(self.marker, gui.PROP_POSITION, target_position, gui.EASING_OUTQUAD, 0.2);\n return true;\n }\n },\n});"
|
|
600
600
|
}
|
|
601
601
|
],
|
|
602
602
|
"gui.set": [
|
|
603
603
|
{
|
|
604
604
|
"sourceHash": "a609fdbcee772fac",
|
|
605
|
-
"ts": "// Updates the position property on an existing node:\nconst node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\");\ngui.set(node, \"position.x\", node_position.x + 128);\n\n// Updates the rotation property on an existing node:\ngui.set(node, \"rotation\", vmath.quat_rotation_z(math.rad(45)));\n// this is equivalent to:\ngui.set(node, \"euler.z\", 45);\n// or using the entire vector:\ngui.set(node, \"euler\", vmath.vector3(0, 0, 45));\n// or using the set_rotation\ngui.set_rotation(node, vmath.vector3(0, 0, 45));\n\n// Sets various material constants for a node:\ngui.set(node, \"tint\", vmath.vector4(1, 0, 0, 1));\n// matrix4 is also supported\ngui.set(node, \"light_matrix\", vmath.matrix4());\n// update a constant in an array at position 4. the array is specified in the shader as:\n// uniform vec4 tint_array[4]; //
|
|
605
|
+
"ts": "// Updates the position property on an existing node:\nconst node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\") as Vector3;\ngui.set(node, \"position.x\", node_position.x + 128);\n\n// Updates the rotation property on an existing node:\ngui.set(node, \"rotation\", vmath.quat_rotation_z(math.rad(45)));\n// this is equivalent to:\ngui.set(node, \"euler.z\", 45);\n// or using the entire vector:\ngui.set(node, \"euler\", vmath.vector3(0, 0, 45));\n// or using the set_rotation\ngui.set_rotation(node, vmath.vector3(0, 0, 45));\n\n// Sets various material constants for a node:\ngui.set(node, \"tint\", vmath.vector4(1, 0, 0, 1));\n// matrix4 is also supported\ngui.set(node, \"light_matrix\", vmath.matrix4());\n// update a constant in an array at position 4. the array is specified in the shader as:\n// uniform vec4 tint_array[4]; // TypeScript and the shader are both 0 based\ngui.set(node, \"tint_array\", vmath.vector4(1, 0, 0, 1), { index: 3 });\n// update a matrix constant in an array at position 4. the array is specified in the shader as:\n// uniform mat4 light_matrix_array[4];\ngui.set(node, \"light_matrix_array\", vmath.matrix4(), { index: 3 });\n// update a sub-element in a constant\ngui.set(node, \"tint.x\", 1);\n// update a sub-element in an array constant at position 4\ngui.set(node, \"tint_array.x\", 1, { index: 3 });\n\n// Set a named property\nexport default defineGuiScript({\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_font\") && types.is_hash(message.font)) {\n gui.set(msg.url(), \"fonts\", message.font, { key: \"my_font_name\" });\n gui.set_font(gui.get_node(\"text\"), \"my_font_name\");\n } else if (message_id === hash(\"set_texture\") && types.is_hash(message.texture)) {\n gui.set(msg.url(), \"textures\", message.texture, { key: \"my_texture\" });\n gui.set_texture(gui.get_node(\"box\"), \"my_texture\");\n gui.play_flipbook(gui.get_node(\"box\"), \"logo_256\");\n }\n },\n});\n\n// Remove a named runtime texture resource mapping:\nconst atlas_params = { texture: \"/runtime.texturec\", animations: [], geometries: [] };\nconst atlas_id = resource.create_atlas(\"/runtime.texturesetc\", atlas_params);\ngui.set(msg.url(), \"textures\", atlas_id, { key: \"runtime_texture\" });\ngui.set_texture(gui.get_node(\"box\"), \"runtime_texture\");\n\n// Later, remove the GUI mapping before releasing the atlas resource.\ngui.set(msg.url(), \"textures\", undefined, { key: \"runtime_texture\" });\nresource.release(atlas_id);"
|
|
606
606
|
},
|
|
607
607
|
{
|
|
608
608
|
"sourceHash": "d195edde0a9fd170",
|
|
609
|
-
"ts": "// Updates the position property on an existing node:\nconst node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\");\ngui.set(node, \"position.x\", node_position.x + 128);\n\n// Updates the rotation property on an existing node:\ngui.set(node, \"rotation\", vmath.quat_rotation_z(math.rad(45)));\n// this is equivalent to:\ngui.set(node, \"euler.z\", 45);\n// or using the entire vector:\ngui.set(node, \"euler\", vmath.vector3(0, 0, 45));\n// or using the set_rotation\ngui.set_rotation(node, vmath.vector3(0, 0, 45));\n\n// Sets various material constants for a node:\ngui.set(node, \"tint\", vmath.vector4(1, 0, 0, 1));\n// matrix4 is also supported\ngui.set(node, \"light_matrix\", vmath.matrix4());\n// update a constant in an array at position 4. the array is specified in the shader as:\n// uniform vec4 tint_array[4]; //
|
|
609
|
+
"ts": "// Updates the position property on an existing node:\nconst node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\") as Vector3;\ngui.set(node, \"position.x\", node_position.x + 128);\n\n// Updates the rotation property on an existing node:\ngui.set(node, \"rotation\", vmath.quat_rotation_z(math.rad(45)));\n// this is equivalent to:\ngui.set(node, \"euler.z\", 45);\n// or using the entire vector:\ngui.set(node, \"euler\", vmath.vector3(0, 0, 45));\n// or using the set_rotation\ngui.set_rotation(node, vmath.vector3(0, 0, 45));\n\n// Sets various material constants for a node:\ngui.set(node, \"tint\", vmath.vector4(1, 0, 0, 1));\n// matrix4 is also supported\ngui.set(node, \"light_matrix\", vmath.matrix4());\n// update a constant in an array at position 4. the array is specified in the shader as:\n// uniform vec4 tint_array[4]; // TypeScript and the shader are both 0 based\ngui.set(node, \"tint_array\", vmath.vector4(1, 0, 0, 1), { index: 3 });\n// update a matrix constant in an array at position 4. the array is specified in the shader as:\n// uniform mat4 light_matrix_array[4];\ngui.set(node, \"light_matrix_array\", vmath.matrix4(), { index: 3 });\n// update a sub-element in a constant\ngui.set(node, \"tint.x\", 1);\n// update a sub-element in an array constant at position 4\ngui.set(node, \"tint_array.x\", 1, { index: 3 });\n\n// Set a named property\nexport default defineGuiScript({\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_font\") && types.is_hash(message.font)) {\n gui.set(msg.url(), \"fonts\", message.font, { key: \"my_font_name\" });\n gui.set_font(gui.get_node(\"text\"), \"my_font_name\");\n } else if (message_id === hash(\"set_texture\") && types.is_hash(message.texture)) {\n gui.set(msg.url(), \"textures\", message.texture, { key: \"my_texture\" });\n gui.set_texture(gui.get_node(\"box\"), \"my_texture\");\n gui.play_flipbook(gui.get_node(\"box\"), \"logo_256\");\n }\n },\n});"
|
|
610
610
|
}
|
|
611
611
|
],
|
|
612
612
|
"gui.set_id": [
|
|
@@ -636,7 +636,7 @@
|
|
|
636
636
|
"html5.run": [
|
|
637
637
|
{
|
|
638
638
|
"sourceHash": "03f87c9fc915512f",
|
|
639
|
-
"ts": "const res = html5.run(\"10 + 20\"); // returns the string \"30\"\nprint(res);\nconst res_num = tonumber(res); // convert to number\
|
|
639
|
+
"ts": "const res = html5.run(\"10 + 20\"); // returns the string \"30\"\nprint(res);\nconst res_num = tonumber(res); // convert to number\nif (res_num !== undefined) {\n print(res_num - 20); // prints 10\n}"
|
|
640
640
|
}
|
|
641
641
|
],
|
|
642
642
|
"html5.set_interaction_listener": [
|
|
@@ -648,25 +648,25 @@
|
|
|
648
648
|
"http.request": [
|
|
649
649
|
{
|
|
650
650
|
"sourceHash": "170c94c250c1ce49",
|
|
651
|
-
"ts": "function update_my_progress_bar(self: unknown, fraction: number) {\n // draw the progress bar at the given fraction\n}\n\n// Basic HTTP-GET request. The callback receives a table with the response\n// in the fields status, the response (the data) and headers (a table).\nexport default defineScript({\n init() {\n http.request(\n \"http://www.google.com\",\n \"GET\",\n (self, _id, response) => {\n if (response.bytes_total !== undefined) {\n update_my_progress_bar(self, response.bytes_received / response.bytes_total);\n } else {\n print(response.status);\n print(response.response);\n pprint(response.headers);\n }\n },\n undefined,\n undefined,\n { report_progress: true },\n );\n },\n});"
|
|
651
|
+
"ts": "function update_my_progress_bar(self: unknown, fraction: number) {\n // draw the progress bar at the given fraction\n}\n\n// Basic HTTP-GET request. The callback receives a table with the response\n// in the fields status, the response (the data) and headers (a table).\nexport default defineScript({\n init() {\n http.request(\n \"http://www.google.com\",\n \"GET\",\n (self, _id, response) => {\n if (response.bytes_received !== undefined && response.bytes_total !== undefined) {\n update_my_progress_bar(self, response.bytes_received / response.bytes_total);\n } else {\n print(response.status);\n print(response.response);\n pprint(response.headers);\n }\n },\n undefined,\n undefined,\n { report_progress: true },\n );\n },\n});"
|
|
652
652
|
}
|
|
653
653
|
],
|
|
654
654
|
"image.get_astc_header": [
|
|
655
655
|
{
|
|
656
656
|
"sourceHash": "adae89354a89050a",
|
|
657
|
-
"ts": "// How to get the block size and dimensions from a .astc file\nconst [s] = sys.load_resource(\"/assets/cat.astc\");\
|
|
657
|
+
"ts": "// How to get the block size and dimensions from a .astc file\nconst [s] = sys.load_resource(\"/assets/cat.astc\");\nif (s !== undefined) {\n const header = image.get_astc_header(s);\n pprint(s);\n}"
|
|
658
658
|
}
|
|
659
659
|
],
|
|
660
660
|
"image.load": [
|
|
661
661
|
{
|
|
662
662
|
"sourceHash": "d7c6b4708bd86c99",
|
|
663
|
-
"ts": "// How to load an image from an URL and create a GUI texture from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img = image.load(response.response);\n const tx = gui.new_texture(\"image_node\", img.width, img.height, img.type, img.buffer);\n});"
|
|
663
|
+
"ts": "// How to load an image from an URL and create a GUI texture from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img = response.response !== undefined ? image.load(response.response) : undefined;\n if (img !== undefined) {\n const tx = gui.new_texture(\"image_node\", img.width, img.height, img.type, img.buffer);\n }\n});"
|
|
664
664
|
}
|
|
665
665
|
],
|
|
666
666
|
"image.load_buffer": [
|
|
667
667
|
{
|
|
668
668
|
"sourceHash": "55649cadc660e25e",
|
|
669
|
-
"ts": "// Load an image from an URL as a buffer and create a texture resource from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img
|
|
669
|
+
"ts": "// Load an image from an URL as a buffer and create a texture resource from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img =\n response.response !== undefined\n ? image.load_buffer(response.response, { flip_vertically: true })\n : undefined;\n if (img !== undefined) {\n const tparams = {\n width: img.width,\n height: img.height,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams, img.buffer);\n // Apply the texture to a model\n go.set(\"/go1#model\", \"texture0\", my_texture_id);\n }\n});"
|
|
670
670
|
}
|
|
671
671
|
],
|
|
672
672
|
"init": [
|
|
@@ -806,7 +806,7 @@
|
|
|
806
806
|
"model.get_mesh_enabled": [
|
|
807
807
|
{
|
|
808
808
|
"sourceHash": "b2f9e47a91bc3f12",
|
|
809
|
-
"ts": "// shared weapon data, e.g. required from your own module\nconst game = { data: { weapons: { Sword: { damage: 10 } } } };\n\nexport default defineScript({\n init(
|
|
809
|
+
"ts": "// shared weapon data, e.g. required from your own module\nconst game = { data: { weapons: { Sword: { damage: 10 } } } };\n\nexport default defineScript({\n init() {\n if (model.get_mesh_enabled(\"#model\", \"Sword\")) {\n // set properties specific for the sword\n return { weapon_properties: game.data.weapons[\"Sword\"] };\n }\n return { weapon_properties: undefined };\n },\n});"
|
|
810
810
|
}
|
|
811
811
|
],
|
|
812
812
|
"model.play_anim": [
|
|
@@ -856,11 +856,11 @@
|
|
|
856
856
|
"on_input": [
|
|
857
857
|
{
|
|
858
858
|
"sourceHash": "86c70cf4ccb7381e",
|
|
859
|
-
"ts": "// This example demonstrates how a game object instance can be moved as a response to user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);\n }\n }\n },\n});"
|
|
859
|
+
"ts": "// This example demonstrates how a game object instance can be moved as a response to user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);\n }\n }\n },\n});"
|
|
860
860
|
},
|
|
861
861
|
{
|
|
862
862
|
"sourceHash": "cc835ea429adc693",
|
|
863
|
-
"ts": "export default defineGuiScript({\n on_input(self, action_id, action) {\n // check for input\n if (action_id === hash(\"my_action\")) {\n // take appropriate action\n self.my_value = action.value;\n }\n // consume input\n return true;\n },\n});"
|
|
863
|
+
"ts": "export default defineGuiScript({\n init(): { my_value: number | undefined } {\n return { my_value: undefined };\n },\n\n on_input(self, action_id, action) {\n // check for input\n if (action_id === hash(\"my_action\")) {\n // take appropriate action\n self.my_value = action.value;\n }\n // consume input\n return true;\n },\n});"
|
|
864
864
|
}
|
|
865
865
|
],
|
|
866
866
|
"on_message": [
|
|
@@ -870,17 +870,17 @@
|
|
|
870
870
|
},
|
|
871
871
|
{
|
|
872
872
|
"sourceHash": "9f37896589565629",
|
|
873
|
-
"ts": "// b.script — Script of instance \"b\":\nexport default defineScript({\n init() {\n // store the url of instance \"a\" for later use, by specifying undefined as socket we\n // automatically use our own socket\n return { a_url: msg.url(undefined, go.get_id(\"a\"), \"script\") };\n },\n\n on_message(self, message_id, message, sender) {\n // check message and sender\n if (message_id === hash(\"my_data\") && sender === self.a_url) {\n // use the data in some way\n self.important_value = message.important_value;\n }\n },\n});"
|
|
873
|
+
"ts": "// b.script — Script of instance \"b\":\nexport default defineScript({\n init() {\n // store the url of instance \"a\" for later use, by specifying undefined as socket we\n // automatically use our own socket\n return { a_url: msg.url(undefined, go.get_id(\"a\"), \"script\"), important_value: 0 };\n },\n\n on_message(self, message_id, message, sender) {\n // check message and sender\n if (message_id === hash(\"my_data\") && sender === self.a_url && typeof message.important_value === \"number\") {\n // use the data in some way\n self.important_value = message.important_value;\n }\n },\n});"
|
|
874
874
|
}
|
|
875
875
|
],
|
|
876
876
|
"on_reload": [
|
|
877
877
|
{
|
|
878
878
|
"sourceHash": "ba39c0b0d5170ccb",
|
|
879
|
-
"ts": "// This example demonstrates how to tweak the speed of a game object instance that is moved on user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved, this value is tweaked in the on_reload function below\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);\n }\n }\n },\n\n on_reload(self) {\n // edit this value and reload the script component\n self.max_speed = 100;\n },\n});"
|
|
879
|
+
"ts": "// This example demonstrates how to tweak the speed of a game object instance that is moved on user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved, this value is tweaked in the on_reload function below\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3((action.value ?? 0) * self.max_speed, 0, 0);\n }\n }\n },\n\n on_reload(self) {\n // edit this value and reload the script component\n self.max_speed = 100;\n },\n});"
|
|
880
880
|
},
|
|
881
881
|
{
|
|
882
882
|
"sourceHash": "e89fe0d0bd51ed98",
|
|
883
|
-
"ts": "export default defineGuiScript({\n on_reload(self) {\n // restore some color (or similar)\n gui.set_color(gui.get_node(\"my_node\"), self.my_original_color);\n },\n});"
|
|
883
|
+
"ts": "export default defineGuiScript({\n init() {\n return { my_original_color: gui.get_color(gui.get_node(\"my_node\")) };\n },\n\n on_reload(self) {\n // restore some color (or similar)\n gui.set_color(gui.get_node(\"my_node\"), self.my_original_color);\n },\n});"
|
|
884
884
|
}
|
|
885
885
|
],
|
|
886
886
|
"particlefx.play": [
|
|
@@ -910,19 +910,19 @@
|
|
|
910
910
|
"physics.get_gravity": [
|
|
911
911
|
{
|
|
912
912
|
"sourceHash": "b2b339f1ddd89a38",
|
|
913
|
-
"ts": "export default defineScript({\n init(self) {\n let gravity = physics.get_gravity();\n // Inverse gravity!\n gravity = -gravity;\n physics.set_gravity(gravity);\n },\n});"
|
|
913
|
+
"ts": "export default defineScript({\n init(self) {\n let gravity = physics.get_gravity();\n // Inverse gravity!\n gravity = vmath.vector3(-gravity.x, -gravity.y, -gravity.z);\n physics.set_gravity(gravity);\n },\n});"
|
|
914
914
|
}
|
|
915
915
|
],
|
|
916
916
|
"physics.raycast": [
|
|
917
917
|
{
|
|
918
918
|
"sourceHash": "3e0c534d741f0120",
|
|
919
|
-
"ts": "function handle_result(hit: { fraction: number; position: Vector3; normal: Vector3; id: Hash; group: Hash; request_id: number }) {\n // act on the hit (see 'ray_cast_response')\n}\n\n// How to perform a ray cast synchronously:\nexport default defineScript({\n init(
|
|
919
|
+
"ts": "function handle_result(hit: { fraction: number; position: Vector3; normal: Vector3; id: Hash; group: Hash; request_id: number }) {\n // act on the hit (see 'ray_cast_response')\n}\n\n// How to perform a ray cast synchronously:\nexport default defineScript({\n init() {\n return { groups: [hash(\"world\"), hash(\"enemy\")] };\n },\n\n update(self, dt) {\n // request ray cast\n const from = go.get_world_position();\n const to = vmath.vector3(from.x, from.y - 100, from.z);\n const results = physics.raycast(from, to, self.groups, { all: true });\n if (results !== undefined) {\n for (const result of results) {\n handle_result(result);\n }\n }\n },\n});"
|
|
920
920
|
}
|
|
921
921
|
],
|
|
922
922
|
"physics.raycast_async": [
|
|
923
923
|
{
|
|
924
924
|
"sourceHash": "746b7900ebaa1f10",
|
|
925
|
-
"ts": "// How to perform a ray cast asynchronously:\nexport default defineScript({\n init(
|
|
925
|
+
"ts": "// How to perform a ray cast asynchronously:\nexport default defineScript({\n init() {\n return { my_groups: [hash(\"my_group1\"), hash(\"my_group2\")] };\n },\n\n update(self, dt) {\n // request ray cast\n const my_start = go.get_world_position();\n const my_end = vmath.vector3(my_start.x, my_start.y - 100, my_start.z);\n physics.raycast_async(my_start, my_end, self.my_groups);\n },\n\n on_message(self, message_id, message, sender) {\n // check for the response\n if (message_id === hash(\"ray_cast_response\")) {\n // act on the hit\n } else if (message_id === hash(\"ray_cast_missed\")) {\n // act on the miss\n }\n },\n});"
|
|
926
926
|
}
|
|
927
927
|
],
|
|
928
928
|
"physics.set_event_listener": [
|
|
@@ -944,13 +944,13 @@
|
|
|
944
944
|
"physics.set_hflip": [
|
|
945
945
|
{
|
|
946
946
|
"sourceHash": "71a627e46d2e651e",
|
|
947
|
-
"ts": "export default defineScript({\n init(
|
|
947
|
+
"ts": "export default defineScript({\n init() {\n const fliph = true; // set on some condition\n physics.set_hflip(\"#collisionobject\", fliph);\n return { fliph };\n },\n});"
|
|
948
948
|
}
|
|
949
949
|
],
|
|
950
950
|
"physics.set_vflip": [
|
|
951
951
|
{
|
|
952
952
|
"sourceHash": "7b5832955ec6635c",
|
|
953
|
-
"ts": "export default defineScript({\n init(
|
|
953
|
+
"ts": "export default defineScript({\n init() {\n const flipv = true; // set on some condition\n physics.set_vflip(\"#collisionobject\", flipv);\n return { flipv };\n },\n});"
|
|
954
954
|
}
|
|
955
955
|
],
|
|
956
956
|
"physics.update_mass": [
|
|
@@ -992,7 +992,7 @@
|
|
|
992
992
|
"profiler.recorded_frame_count": [
|
|
993
993
|
{
|
|
994
994
|
"sourceHash": "9d55df4a00c36560",
|
|
995
|
-
"ts": "// Show the last recorded frame\nconst recorded_frame_count = profiler.recorded_frame_count();\nprofiler.view_recorded_frame(recorded_frame_count);"
|
|
995
|
+
"ts": "// Show the last recorded frame\nconst recorded_frame_count = profiler.recorded_frame_count();\nprofiler.view_recorded_frame({ frame: recorded_frame_count });"
|
|
996
996
|
}
|
|
997
997
|
],
|
|
998
998
|
"profiler.scope_begin": [
|
|
@@ -1058,19 +1058,19 @@
|
|
|
1058
1058
|
"render.disable_texture": [
|
|
1059
1059
|
{
|
|
1060
1060
|
"sourceHash": "77eefc5b608dd2e6",
|
|
1061
|
-
"ts": "export default defineRenderScript({\n update(self, dt) {\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n // done, disable the texture\n render.disable_texture(0);\n },\n});"
|
|
1061
|
+
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n // done, disable the texture\n render.disable_texture(0);\n },\n});"
|
|
1062
1062
|
}
|
|
1063
1063
|
],
|
|
1064
1064
|
"render.dispatch_compute": [
|
|
1065
1065
|
{
|
|
1066
1066
|
"sourceHash": "af76607a05354da7",
|
|
1067
|
-
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n };\n },\n\n update(self, dt) {\n render.set_compute(\"bloom\");\n render.enable_texture(0, self.backing_texture);\n render.enable_texture(1, self.scene_rt);\n render.dispatch_compute(128, 128, 1);\n render.set_compute();\n },\n});\n\n// Dispatch a compute program with a constant buffer:\nconst constants = render.constant_buffer();\nconstants.tint = vmath.vector4(1, 1, 1, 1);\nrender.dispatch_compute(32, 32, 32, { constants });"
|
|
1067
|
+
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n backing_texture: resource.get_texture_info(\"/main/backing.texturec\").handle,\n scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n };\n },\n\n update(self, dt) {\n render.set_compute(\"bloom\");\n render.enable_texture(0, self.backing_texture);\n render.enable_texture(1, self.scene_rt);\n render.dispatch_compute(128, 128, 1);\n render.set_compute();\n },\n});\n\n// Dispatch a compute program with a constant buffer:\nconst constants = render.constant_buffer();\nconstants.tint = vmath.vector4(1, 1, 1, 1);\nrender.dispatch_compute(32, 32, 32, { constants });"
|
|
1068
1068
|
}
|
|
1069
1069
|
],
|
|
1070
1070
|
"render.draw": [
|
|
1071
1071
|
{
|
|
1072
1072
|
"sourceHash": "47232b75e7b74189",
|
|
1073
|
-
"ts": "export default defineRenderScript({\n init() {\n // define a predicate matching anything with material tag \"my_tag\"\n
|
|
1073
|
+
"ts": "export default defineRenderScript({\n init() {\n return {\n // define a predicate matching anything with material tag \"my_tag\"\n my_pred: render.predicate([hash(\"my_tag\")]),\n proj: vmath.matrix4_perspective(math.rad(45), render.get_window_width() / render.get_window_height(), 0.1, 1000),\n view: vmath.matrix4_look_at(vmath.vector3(0, 0, 10), vmath.vector3(0, 0, 0), vmath.vector3(0, 1, 0)),\n };\n },\n\n update(self, dt) {\n // draw everything in the my_pred predicate\n render.draw(self.my_pred);\n\n // Draw predicate with constants:\n const constants = render.constant_buffer();\n constants.tint = vmath.vector4(1, 1, 1, 1);\n render.draw(self.my_pred, { constants });\n\n // Draw with predicate and frustum culling (without near+far planes):\n const frustum = self.proj.mul(self.view);\n render.draw(self.my_pred, { frustum });\n\n // Draw with predicate and frustum culling (with near+far planes):\n const frustum2 = self.proj.mul(self.view);\n render.draw(self.my_pred, { frustum: frustum2, frustum_planes: render.FRUSTUM_PLANES_ALL });\n },\n});"
|
|
1074
1074
|
}
|
|
1075
1075
|
],
|
|
1076
1076
|
"render.draw_debug3d": [
|
|
@@ -1094,15 +1094,15 @@
|
|
|
1094
1094
|
"render.enable_texture": [
|
|
1095
1095
|
{
|
|
1096
1096
|
"sourceHash": "410c8dd98e44842a",
|
|
1097
|
-
"ts": "export default defineRenderScript({\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // disable target\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1097
|
+
"ts": "export default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // disable target\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1098
1098
|
},
|
|
1099
1099
|
{
|
|
1100
1100
|
"sourceHash": "dc0ea083dbea5fe1",
|
|
1101
|
-
"ts": "// Or enable a render target by resource id:\nexport default defineRenderScript({\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n render.draw(self.my_pred);\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, \"my_rt_resource\", graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1101
|
+
"ts": "// Or enable a render target by resource id:\nexport default defineRenderScript({\n init() {\n return { my_pred: render.predicate([hash(\"my_tag\")]) };\n },\n\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n render.draw(self.my_pred);\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, \"my_rt_resource\", graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});"
|
|
1102
1102
|
},
|
|
1103
1103
|
{
|
|
1104
1104
|
"sourceHash": "49503c29f0de95f3",
|
|
1105
|
-
"ts": "// Or bind a texture handle directly:\nexport default defineRenderScript({\n update(self, dt) {\n // bind a texture to the texture unit 0\n render.enable_texture(0, self.my_texture_handle);\n // bind the same texture to a named sampler\n render.enable_texture(\"my_texture_sampler\", self.my_texture_handle);\n },\n});"
|
|
1105
|
+
"ts": "// Or bind a texture handle directly:\nexport default defineRenderScript({\n init() {\n return { my_texture_handle: resource.get_texture_info(\"/main/my_texture.texturec\").handle };\n },\n\n update(self, dt) {\n // bind a texture to the texture unit 0\n render.enable_texture(0, self.my_texture_handle);\n // bind the same texture to a named sampler\n render.enable_texture(\"my_texture_sampler\", self.my_texture_handle);\n },\n});"
|
|
1106
1106
|
}
|
|
1107
1107
|
],
|
|
1108
1108
|
"render.get_height": [
|
|
@@ -1150,15 +1150,15 @@
|
|
|
1150
1150
|
"render.render_target": [
|
|
1151
1151
|
{
|
|
1152
1152
|
"sourceHash": "0c72f5142a3a57da",
|
|
1153
|
-
"ts": "// How to create a new render target and draw to it:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const depth_params = {\n format: graphics.TEXTURE_FORMAT_DEPTH,\n width: render.get_window_width(),\n height: render.get_window_height(),\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,\n [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1153
|
+
"ts": "// How to create a new render target and draw to it:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const depth_params = {\n format: graphics.TEXTURE_FORMAT_DEPTH,\n width: render.get_window_width(),\n height: render.get_window_height(),\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,\n [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,\n }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1154
1154
|
},
|
|
1155
1155
|
{
|
|
1156
1156
|
"sourceHash": "271ca31f05e103b5",
|
|
1157
|
-
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.
|
|
1157
|
+
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1158
1158
|
},
|
|
1159
1159
|
{
|
|
1160
1160
|
"sourceHash": "e39f13af5d65d01d",
|
|
1161
|
-
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.
|
|
1161
|
+
"ts": "// How to create a render target with multiple outputs:\nexport default defineRenderScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1162
1162
|
}
|
|
1163
1163
|
],
|
|
1164
1164
|
"render.set_blend_equation_separate": [
|
|
@@ -1236,11 +1236,11 @@
|
|
|
1236
1236
|
"render.set_render_target": [
|
|
1237
1237
|
{
|
|
1238
1238
|
"sourceHash": "c6e25f5038d19bee",
|
|
1239
|
-
"ts": "// How to set a render target and draw to it and then switch back to the default render target\n// The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support\nexport default defineRenderScript({\n update(self, dt) {\n // set render target so all drawing is done to it\n render.set_render_target(self.my_render_target, {\n transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],\n });\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)\n // which can be an optimisation on some hardware\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1239
|
+
"ts": "// How to set a render target and draw to it and then switch back to the default render target\n// The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support\nexport default defineRenderScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n my_render_target: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n my_pred: render.predicate([hash(\"my_tag\")]),\n };\n },\n\n update(self, dt) {\n // set render target so all drawing is done to it\n render.set_render_target(self.my_render_target, {\n transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],\n });\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)\n // which can be an optimisation on some hardware\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1240
1240
|
},
|
|
1241
1241
|
{
|
|
1242
1242
|
"sourceHash": "bb08db5e232c5b5e",
|
|
1243
|
-
"ts": "// Or set the render target by a render target resource identifier:\nexport default defineRenderScript({\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // reset the render target to the default backbuffer\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1243
|
+
"ts": "// Or set the render target by a render target resource identifier:\nexport default defineRenderScript({\n init() {\n return { my_pred: render.predicate([hash(\"my_tag\")]) };\n },\n\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // reset the render target to the default backbuffer\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1244
1244
|
}
|
|
1245
1245
|
],
|
|
1246
1246
|
"render.set_render_target_size": [
|
|
@@ -1270,7 +1270,7 @@
|
|
|
1270
1270
|
"render.set_view": [
|
|
1271
1271
|
{
|
|
1272
1272
|
"sourceHash": "7a30b4955abb3844",
|
|
1273
|
-
"ts": "// How to set the view and projection matrices according to\n// the values supplied by a camera.\nexport default defineRenderScript({\n init() {\n return {\n view: vmath.matrix4(),\n projection: vmath.matrix4(),\n };\n },\n\n update(self, dt) {\n // set the view to the stored view value\n render.set_view(self.view);\n // now we can draw with this view\n },\n\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_view_projection\")) {\n // camera view and projection arrives here.\n self.view = message.view;\n self.projection = message.projection;\n }\n },\n});"
|
|
1273
|
+
"ts": "// How to set the view and projection matrices according to\n// the values supplied by a camera.\nexport default defineRenderScript({\n init() {\n return {\n view: vmath.matrix4(),\n projection: vmath.matrix4(),\n };\n },\n\n update(self, dt) {\n // set the view to the stored view value\n render.set_view(self.view);\n // now we can draw with this view\n },\n\n on_message(self, message_id, message) {\n if (\n message_id === hash(\"set_view_projection\") &&\n types.is_matrix4(message.view) &&\n types.is_matrix4(message.projection)\n ) {\n // camera view and projection arrives here.\n self.view = message.view;\n self.projection = message.projection;\n }\n },\n});"
|
|
1274
1274
|
}
|
|
1275
1275
|
],
|
|
1276
1276
|
"render.set_viewport": [
|
|
@@ -1282,17 +1282,17 @@
|
|
|
1282
1282
|
"resource.atlas": [
|
|
1283
1283
|
{
|
|
1284
1284
|
"sourceHash": "10e8e4948751ccc8",
|
|
1285
|
-
"ts": "// Load an atlas and set it to a sprite:\
|
|
1285
|
+
"ts": "// Load an atlas and set it to a sprite:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_atlas: resource.atlas(\"/atlas.atlas\") },\n\n init(self) {\n go.set(\"#sprite\", \"image\", self.my_atlas);\n },\n});"
|
|
1286
1286
|
},
|
|
1287
1287
|
{
|
|
1288
1288
|
"sourceHash": "46638db8e246e1ed",
|
|
1289
|
-
"ts": "// Load an atlas and set it to a gui:\
|
|
1289
|
+
"ts": "// Load an atlas and set it to a gui:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_atlas: resource.atlas(\"/atlas.atlas\") },\n\n init(self) {\n go.set(\"#gui\", \"textures\", self.my_atlas, { key: \"my_atlas\" });\n },\n});"
|
|
1290
1290
|
}
|
|
1291
1291
|
],
|
|
1292
1292
|
"resource.buffer": [
|
|
1293
1293
|
{
|
|
1294
1294
|
"sourceHash": "4353a4d474ea70b6",
|
|
1295
|
-
"ts": "// Set a unique buffer it to a sprite:\
|
|
1295
|
+
"ts": "// Set a unique buffer it to a sprite:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_buffer: resource.buffer(\"/cube.buffer\") },\n\n init(self) {\n go.set(\"#mesh\", \"vertices\", self.my_buffer);\n },\n});"
|
|
1296
1296
|
}
|
|
1297
1297
|
],
|
|
1298
1298
|
"resource.create_atlas": [
|
|
@@ -1304,7 +1304,7 @@
|
|
|
1304
1304
|
"resource.create_buffer": [
|
|
1305
1305
|
{
|
|
1306
1306
|
"sourceHash": "a4804ebe744d930a",
|
|
1307
|
-
"ts": "// Create a buffer object and bind it to a buffer resource\nexport default defineScript({\n init() {\n const size = 1;\n const positions = [\n // triangle 1\n size, size, 0,\n -size, -size, 0,\n size, -size, 0,\n // triangle 2\n size, size, 0,\n -size, size, 0,\n -size, -size, 0,\n ];\n\n const buffer_handle = buffer.create(positions.length, [\n {\n name: hash(\"position\"),\n type: buffer.VALUE_TYPE_FLOAT32,\n count: 3,\n },\n ]);\n\n const stream = buffer.get_stream(buffer_handle, hash(\"position\"));\n\n // transfer vertex data to buffer\n
|
|
1307
|
+
"ts": "// Create a buffer object and bind it to a buffer resource\nexport default defineScript({\n init() {\n const size = 1;\n const positions = [\n // triangle 1\n size, size, 0,\n -size, -size, 0,\n size, -size, 0,\n // triangle 2\n size, size, 0,\n -size, size, 0,\n -size, -size, 0,\n ];\n\n const buffer_handle = buffer.create(positions.length, [\n {\n name: hash(\"position\"),\n type: buffer.VALUE_TYPE_FLOAT32,\n count: 3,\n },\n ]);\n\n const stream = buffer.get_stream(buffer_handle, hash(\"position\"));\n\n // transfer vertex data to buffer\n positions.forEach((value, k) => {\n stream[k] = value;\n });\n\n const my_buffer = resource.create_buffer(\"/my_buffer.bufferc\", { buffer: buffer_handle });\n go.set(\"/go#mesh\", \"vertices\", my_buffer);\n },\n});"
|
|
1308
1308
|
},
|
|
1309
1309
|
{
|
|
1310
1310
|
"sourceHash": "eef45bf7aae2047d",
|
|
@@ -1314,7 +1314,7 @@
|
|
|
1314
1314
|
"resource.create_sound_data": [
|
|
1315
1315
|
{
|
|
1316
1316
|
"sourceHash": "19e6f6ab7a317fa1",
|
|
1317
|
-
"ts": "export default defineScript({\n init() {\n // create a new sound resource, given the initial chunk of the file\n const relative_path = \"/a/unique/resource/name.oggc\";\n const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });\n go.set(\"#music\", \"sound\", hash); // override the previous sound resource\n sound.play(\"#music\"); // start the playing\n },\n});"
|
|
1317
|
+
"ts": "export default defineScript({\n init() {\n // create a new sound resource, given the initial chunk of the file\n const [data] = sys.load_resource(\"/sounds/music_header.oggc\");\n if (data === undefined) {\n return;\n }\n const filesize = 1048576;\n const relative_path = \"/a/unique/resource/name.oggc\";\n const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });\n go.set(\"#music\", \"sound\", hash); // override the previous sound resource\n sound.play(\"#music\"); // start the playing\n },\n});"
|
|
1318
1318
|
}
|
|
1319
1319
|
],
|
|
1320
1320
|
"resource.create_texture": [
|
|
@@ -1328,7 +1328,7 @@
|
|
|
1328
1328
|
},
|
|
1329
1329
|
{
|
|
1330
1330
|
"sourceHash": "be4f6e903c862a52",
|
|
1331
|
-
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format:
|
|
1331
|
+
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n flags: graphics.TEXTURE_USAGE_FLAG_STORAGE + graphics.TEXTURE_USAGE_FLAG_SAMPLE,\n });\n\n // pass the backing texture to the render script\n msg.post(\"@render:\", \"add_textures\", [t_volume]);\n },\n});"
|
|
1332
1332
|
},
|
|
1333
1333
|
{
|
|
1334
1334
|
"sourceHash": "b1535ccf9e09d259",
|
|
@@ -1336,7 +1336,7 @@
|
|
|
1336
1336
|
},
|
|
1337
1337
|
{
|
|
1338
1338
|
"sourceHash": "54a85cf9f38f2521",
|
|
1339
|
-
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format:
|
|
1339
|
+
"ts": "// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n flags: graphics.TEXTURE_USAGE_FLAG_STORAGE + graphics.TEXTURE_USAGE_FLAG_SAMPLE,\n });\n\n // pass the backing texture to the render script\n msg.post(\"@render:\", \"add_textures\", [t_volume]);\n },\n});"
|
|
1340
1340
|
}
|
|
1341
1341
|
],
|
|
1342
1342
|
"resource.create_texture_async": [
|
|
@@ -1352,17 +1352,17 @@
|
|
|
1352
1352
|
"resource.font": [
|
|
1353
1353
|
{
|
|
1354
1354
|
"sourceHash": "3e41babc3620a985",
|
|
1355
|
-
"ts": "// Load a font and set it to a label:\
|
|
1355
|
+
"ts": "// Load a font and set it to a label:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_font: resource.font(\"/font.font\") },\n\n init(self) {\n go.set(\"#label\", \"font\", self.my_font);\n },\n});"
|
|
1356
1356
|
},
|
|
1357
1357
|
{
|
|
1358
1358
|
"sourceHash": "8eb5018038b320d3",
|
|
1359
|
-
"ts": "// Load a font and set it to a gui:\
|
|
1359
|
+
"ts": "// Load a font and set it to a gui:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_font: resource.font(\"/font.font\") },\n\n init(self) {\n go.set(\"#gui\", \"fonts\", self.my_font, { key: \"my_font\" });\n },\n});"
|
|
1360
1360
|
}
|
|
1361
1361
|
],
|
|
1362
1362
|
"resource.get_buffer": [
|
|
1363
1363
|
{
|
|
1364
1364
|
"sourceHash": "ed7d361c7f5d2e35",
|
|
1365
|
-
"ts": "// How to get the data from a buffer\nexport default defineScript({\n init() {\n const res_path = go.get(\"#mesh\", \"vertices\");\n const buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n for (let i = 0; i < stream_positions.length; i++) {\n print(i, stream_positions[i]);\n }\n },\n});"
|
|
1365
|
+
"ts": "// How to get the data from a buffer\nexport default defineScript({\n init() {\n const res_path = go.get<mesh.properties>()(\"#mesh\", \"vertices\");\n const buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n for (let i = 0; i < stream_positions.length(); i++) {\n print(i, stream_positions[i]);\n }\n },\n});"
|
|
1366
1366
|
}
|
|
1367
1367
|
],
|
|
1368
1368
|
"resource.get_render_target_info": [
|
|
@@ -1378,7 +1378,7 @@
|
|
|
1378
1378
|
"resource.get_text_metrics": [
|
|
1379
1379
|
{
|
|
1380
1380
|
"sourceHash": "d63156dd59513358",
|
|
1381
|
-
"ts": "export default defineScript({\n init() {\n const font = go.get(\"#label\", \"font\");\n const metrics = resource.get_text_metrics(font, \"The quick brown fox\\n jumps over the lazy dog\");\n pprint(metrics);\n },\n});"
|
|
1381
|
+
"ts": "export default defineScript({\n init() {\n const font = go.get<label.properties>()(\"#label\", \"font\");\n const metrics = resource.get_text_metrics(font, \"The quick brown fox\\n jumps over the lazy dog\");\n pprint(metrics);\n },\n});"
|
|
1382
1382
|
}
|
|
1383
1383
|
],
|
|
1384
1384
|
"resource.get_texture_info": [
|
|
@@ -1400,29 +1400,29 @@
|
|
|
1400
1400
|
"resource.material": [
|
|
1401
1401
|
{
|
|
1402
1402
|
"sourceHash": "444ac3e37fe7401e",
|
|
1403
|
-
"ts": "// Load a material and set it to a sprite:\
|
|
1403
|
+
"ts": "// Load a material and set it to a sprite:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_material: resource.material(\"/material.material\") },\n\n init(self) {\n go.set(\"#sprite\", \"material\", self.my_material);\n },\n});"
|
|
1404
1404
|
},
|
|
1405
1405
|
{
|
|
1406
1406
|
"sourceHash": "7de09b2a13f4e657",
|
|
1407
|
-
"ts": "// Load a material resource and update a named material with the resource:\
|
|
1407
|
+
"ts": "// Load a material resource and update a named material with the resource:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_material: resource.material(\"/material.material\") },\n\n init(self) {\n go.set(\"#gui\", \"materials\", self.my_material, { key: \"my_material\" });\n },\n});"
|
|
1408
1408
|
}
|
|
1409
1409
|
],
|
|
1410
1410
|
"resource.render_target": [
|
|
1411
1411
|
{
|
|
1412
1412
|
"sourceHash": "87231742204d2351",
|
|
1413
|
-
"ts": "// Set a render target color attachment as a model texture:\
|
|
1413
|
+
"ts": "// Set a render target color attachment as a model texture:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_render_target: resource.render_target(\"/rt.render_target\") },\n\n init(self) {\n const rt_info = resource.get_render_target_info(self.my_render_target);\n go.set(\"#model\", \"texture0\", rt_info.attachments[0]!.texture!);\n },\n});"
|
|
1414
1414
|
}
|
|
1415
1415
|
],
|
|
1416
1416
|
"resource.set": [
|
|
1417
1417
|
{
|
|
1418
1418
|
"sourceHash": "fd3445f93ecdd85e",
|
|
1419
|
-
"ts": "// Assuming the folder \"/res\" is added to the project custom resources:\n// load a texture resource and set it on a sprite\nconst buffer = resource.load(\"/res/new.texturec\");\nresource.set(go.get(\"#sprite\", \"texture0\"), buffer);"
|
|
1419
|
+
"ts": "// Assuming the folder \"/res\" is added to the project custom resources:\n// load a texture resource and set it on a sprite\nconst buffer = resource.load(\"/res/new.texturec\");\nresource.set(go.get<sprite.properties>()(\"#sprite\", \"texture0\"), buffer);"
|
|
1420
1420
|
}
|
|
1421
1421
|
],
|
|
1422
1422
|
"resource.set_atlas": [
|
|
1423
1423
|
{
|
|
1424
1424
|
"sourceHash": "58ec7c40c31875a4",
|
|
1425
|
-
"ts": "// Add a new animation to an existing atlas\nexport default defineScript({\n init() {\n const data = resource.get_atlas(\"/main/my_atlas.a.texturesetc\");\n const my_animation = {\n id: \"my_new_animation\",\n width: 128,\n height: 128,\n frame_start: 1,\n frame_end: 6,\n playback: go.PLAYBACK_LOOP_PINGPONG,\n fps: 8,\n };\n data.animations.push(my_animation);\n resource.set_atlas(\"/main/my_atlas.a.texturesetc\", data);\n },\n});"
|
|
1425
|
+
"ts": "// Add a new animation to an existing atlas\nexport default defineScript({\n init() {\n const data = resource.get_atlas(\"/main/my_atlas.a.texturesetc\");\n const my_animation = {\n id: \"my_new_animation\",\n width: 128,\n height: 128,\n frame_start: 1,\n frame_end: 6,\n playback: go.PLAYBACK_LOOP_PINGPONG,\n fps: 8,\n flip_vertical: false,\n flip_horizontal: false,\n };\n data.animations.push(my_animation);\n resource.set_atlas(\"/main/my_atlas.a.texturesetc\", data);\n },\n});"
|
|
1426
1426
|
},
|
|
1427
1427
|
{
|
|
1428
1428
|
"sourceHash": "c672fd8c9d921f68",
|
|
@@ -1432,25 +1432,25 @@
|
|
|
1432
1432
|
"resource.set_buffer": [
|
|
1433
1433
|
{
|
|
1434
1434
|
"sourceHash": "a52fd8ac7453f601",
|
|
1435
|
-
"ts": "// How to set the data from a buffer\nfunction fill_stream(stream: { [index: number]: number }, verts: number[]) {\n verts.forEach((value, key) => {\n stream[key] = value;\n });\n}\n\nexport default defineScript({\n init() {\n const res_path = go.get(\"#mesh\", \"vertices\");\n\n const positions = [\n 1, -1, 0,\n 1, 1, 0,\n -1, -1, 0,\n ];\n\n const num_verts = positions.length / 3;\n\n // create a new buffer\n let buf = buffer.create(num_verts, [{ name: hash(\"position\"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);\n\n buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n fill_stream(stream_positions, positions);\n\n resource.set_buffer(res_path, buf);\n },\n});"
|
|
1435
|
+
"ts": "// How to set the data from a buffer\nfunction fill_stream(stream: { [index: number]: number }, verts: number[]) {\n verts.forEach((value, key) => {\n stream[key] = value;\n });\n}\n\nexport default defineScript({\n init() {\n const res_path = go.get<mesh.properties>()(\"#mesh\", \"vertices\");\n\n const positions = [\n 1, -1, 0,\n 1, 1, 0,\n -1, -1, 0,\n ];\n\n const num_verts = positions.length / 3;\n\n // create a new buffer\n let buf = buffer.create(num_verts, [{ name: hash(\"position\"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);\n\n buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n fill_stream(stream_positions, positions);\n\n resource.set_buffer(res_path, buf);\n },\n});"
|
|
1436
1436
|
}
|
|
1437
1437
|
],
|
|
1438
1438
|
"resource.set_texture": [
|
|
1439
1439
|
{
|
|
1440
1440
|
"sourceHash": "fe312c35ef2ab0f4",
|
|
1441
|
-
"ts": "// How to set all pixels of an atlas\nexport default defineScript({\n init(
|
|
1441
|
+
"ts": "// How to set all pixels of an atlas\nexport default defineScript({\n init() {\n const height = 128;\n const width = 128;\n const buf = buffer.create(width * height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n const stream = buffer.get_stream(buf, hash(\"rgb\"));\n\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n const index = y * width * 3 + x * 3;\n stream[index + 0] = 0xff;\n stream[index + 1] = 0x80;\n stream[index + 2] = 0x10;\n }\n }\n\n const resource_path = go.get<model.properties>()(\"#model\", \"texture0\");\n const args = { width, height, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, buf);\n return { buffer: buf, stream };\n },\n});"
|
|
1442
1442
|
},
|
|
1443
1443
|
{
|
|
1444
1444
|
"sourceHash": "b4098f0f37b9c1d0",
|
|
1445
|
-
"ts": "// How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.\nexport default defineScript({\n init(
|
|
1445
|
+
"ts": "// How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.\nexport default defineScript({\n init() {\n const x = 16;\n const y = 16;\n const height = 128 - x * 2;\n const width = 128 - y * 2;\n const buf = buffer.create(width * height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n const stream = buffer.get_stream(buf, hash(\"rgb\"));\n\n for (let row = 0; row < height; row++) {\n for (let col = 0; col < width; col++) {\n const index = row * width * 3 + col * 3;\n stream[index + 0] = 0xff;\n stream[index + 1] = 0x80;\n stream[index + 2] = 0x10;\n }\n }\n\n const resource_path = go.get<model.properties>()(\"#model\", \"texture0\");\n const args = { width, height, x, y, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, buf);\n return { buffer: buf, stream };\n },\n});"
|
|
1446
1446
|
},
|
|
1447
1447
|
{
|
|
1448
1448
|
"sourceHash": "02d7f2ec29971bf1",
|
|
1449
|
-
"ts": "// Update a texture from a buffer resource\
|
|
1449
|
+
"ts": "// Update a texture from a buffer resource\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_buffer: resource.buffer(\"/my_default_buffer.buffer\") },\n\n init(self) {\n const resource_path = go.get<model.properties>()(\"#model\", \"texture0\");\n // the \"my_buffer\" resource is expected to hold 128 * 128 * 3 bytes!\n const args = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGB,\n };\n // Note that the extra resource.get_buffer call is a requirement here\n // since the \"self.my_buffer\" is just pointing to a buffer resource path\n // and not an actual buffer object or buffer resource.\n resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));\n },\n});"
|
|
1450
1450
|
},
|
|
1451
1451
|
{
|
|
1452
1452
|
"sourceHash": "15829bfe1b186bc3",
|
|
1453
|
-
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format:
|
|
1453
|
+
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n };\n\n // This expects that the texture resource \"/my_3d_texture.texturec\" already exists\n // and is a 3D texture resource. To create a dynamic 3D texture resource\n // use the \"resource.create_texture\" function.\n resource.set_texture(\"/my_3d_texture.texturec\", t_args, tbuffer);\n },\n});"
|
|
1454
1454
|
},
|
|
1455
1455
|
{
|
|
1456
1456
|
"sourceHash": "f9b616092f8c1b6a",
|
|
@@ -1458,19 +1458,19 @@
|
|
|
1458
1458
|
},
|
|
1459
1459
|
{
|
|
1460
1460
|
"sourceHash": "34dce6f8362c0e92",
|
|
1461
|
-
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format:
|
|
1461
|
+
"ts": "// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n };\n\n // This expects that the texture resource \"/my_3d_texture.texturec\" already exists\n // and is a 3D texture resource. To create a dynamic 3D texture resource\n // use the \"resource.create_texture\" function.\n resource.set_texture(\"/my_3d_texture.texturec\", t_args, tbuffer);\n },\n});"
|
|
1462
1462
|
}
|
|
1463
1463
|
],
|
|
1464
1464
|
"resource.texture": [
|
|
1465
1465
|
{
|
|
1466
1466
|
"sourceHash": "8cd63a7393c8a799",
|
|
1467
|
-
"ts": "// Load a texture and set it to a model:\
|
|
1467
|
+
"ts": "// Load a texture and set it to a model:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_texture: resource.texture(\"/texture.png\") },\n\n init(self) {\n go.set(\"#model\", \"texture0\", self.my_texture);\n },\n});"
|
|
1468
1468
|
}
|
|
1469
1469
|
],
|
|
1470
1470
|
"resource.tile_source": [
|
|
1471
1471
|
{
|
|
1472
1472
|
"sourceHash": "517b23c5ce0e56c6",
|
|
1473
|
-
"ts": "// Load tile source and set it to a tile map:\
|
|
1473
|
+
"ts": "// Load tile source and set it to a tile map:\nexport default defineScript({\n // Never call `go.property` yourself: the transpiler emits the chunk-scope\n // registration from this field, and only this field types the property onto `self`.\n properties: { my_tile_source: resource.tile_source(\"/tilesource.tilesource\") },\n\n init(self) {\n go.set(\"#tilemap\", \"tile_source\", self.my_tile_source);\n },\n});"
|
|
1474
1474
|
}
|
|
1475
1475
|
],
|
|
1476
1476
|
"socket.gettime": [
|
|
@@ -1482,19 +1482,19 @@
|
|
|
1482
1482
|
"socket.newtry": [
|
|
1483
1483
|
{
|
|
1484
1484
|
"sourceHash": "38a669dbf612b327",
|
|
1485
|
-
"ts": "// Perform operations on an open socket c:\nconst [c] = socket.connect(\"localhost\", 80);\nif (c !== undefined) {\n // create a try function that closes 'c' on error\n const try_ = socket.newtry(() => c.close());\n // do everything reassured c will be closed\n
|
|
1485
|
+
"ts": "// Perform operations on an open socket c:\nconst [c] = socket.connect(\"localhost\", 80);\nif (c !== undefined) {\n // create a try function that closes 'c' on error\n const try_ = socket.newtry(() => c.close());\n // do everything reassured c will be closed\n const [sent, sendError, lastByte] = c.send(\"hello there?\\r\\n\");\n try_(sent, sendError, lastByte);\n const [line, receiveError, partial] = c.receive();\n const answer = try_(line, receiveError, partial);\n // ...\n const [byeSent, byeError, byeLastByte] = c.send(\"good bye\\r\\n\");\n try_(byeSent, byeError, byeLastByte);\n c.close();\n}"
|
|
1486
1486
|
}
|
|
1487
1487
|
],
|
|
1488
1488
|
"socket.protect": [
|
|
1489
1489
|
{
|
|
1490
1490
|
"sourceHash": "478d4974b491bda9",
|
|
1491
|
-
"ts": "const dostuff = socket.protect(() => {\n let try_ = socket.newtry();\n const
|
|
1491
|
+
"ts": "const dostuff = socket.protect(() => {\n let try_ = socket.newtry();\n const [conn, connectError] = socket.connect(\"myserver.com\", 80);\n const c = try_(conn, connectError);\n try_ = socket.newtry(() => c.close());\n const [sent, sendError, lastByte] = c.send(\"hello?\\r\\n\");\n try_(sent, sendError, lastByte);\n const [line, receiveError, partial] = c.receive();\n const answer = try_(line, receiveError, partial);\n c.close();\n});\n\nconst [n, error] = dostuff();"
|
|
1492
1492
|
}
|
|
1493
1493
|
],
|
|
1494
1494
|
"socket.skip": [
|
|
1495
1495
|
{
|
|
1496
1496
|
"sourceHash": "3a75c35a80c48e9e",
|
|
1497
|
-
"ts": "const line = \"250 OK\";\n\n// Instead of doing the following with dummy variables:\n// get the status code and separator from SMTP server reply\
|
|
1497
|
+
"ts": "const line = \"250 OK\";\n\n// Instead of doing the following with dummy variables:\n{\n // get the status code and separator from SMTP server reply\n const [dummy1, dummy2, code, sep] = string.find(line, \"^(%d%d%d)(.?)\");\n}\n\n// You can skip a number of variables:\n{\n // get the status code and separator from SMTP server reply\n const [code, sep] = socket.skip(2, string.find(line, \"^(%d%d%d)(.?)\"));\n}"
|
|
1498
1498
|
}
|
|
1499
1499
|
],
|
|
1500
1500
|
"sound.get_group_gain": [
|
|
@@ -1548,7 +1548,7 @@
|
|
|
1548
1548
|
"sound.play": [
|
|
1549
1549
|
{
|
|
1550
1550
|
"sourceHash": "fcfbfd341c41ec59",
|
|
1551
|
-
"ts": "// Assuming the script belongs to an instance with a sound-component with id\n// \"sound\", this will make the component play its sound after 1 second:\nsound.play(\"#sound\", { delay: 1, gain: 0.9, pan: -1.0 });\n\n// Using the callback argument, you can chain several sounds together:\nfunction sound_done(self: unknown, message_id: unknown, message: unknown, sender: unknown) {\n // play 'boom' sound fx when the countdown has completed\n const { play_id } = message as { play_id: number };\n if (message_id === hash(\"sound_done\") && play_id === (self as { countdown_id: number }).countdown_id) {\n sound.play(\"#boom\", undefined, sound_done);\n }\n}\n\nexport default defineScript({\n init(
|
|
1551
|
+
"ts": "// Assuming the script belongs to an instance with a sound-component with id\n// \"sound\", this will make the component play its sound after 1 second:\nsound.play(\"#sound\", { delay: 1, gain: 0.9, pan: -1.0 });\n\n// Using the callback argument, you can chain several sounds together:\nfunction sound_done(self: unknown, message_id: unknown, message: unknown, sender: unknown) {\n // play 'boom' sound fx when the countdown has completed\n const { play_id } = message as { play_id: number };\n if (message_id === hash(\"sound_done\") && play_id === (self as { countdown_id: number }).countdown_id) {\n sound.play(\"#boom\", undefined, sound_done);\n }\n}\n\nexport default defineScript({\n init() {\n return { countdown_id: sound.play(\"#countdown\", undefined, sound_done) };\n },\n});"
|
|
1552
1552
|
}
|
|
1553
1553
|
],
|
|
1554
1554
|
"sound.set_gain": [
|
|
@@ -1590,13 +1590,13 @@
|
|
|
1590
1590
|
"sprite.set_hflip": [
|
|
1591
1591
|
{
|
|
1592
1592
|
"sourceHash": "2d067cdccd1fb269",
|
|
1593
|
-
"ts": "// How to flip a sprite so it faces the horizontal movement (it is assumed that\n// the sprite component has id \"sprite\" and the original animation faces right):\nexport default defineScript({\n update(self, dt) {\n // calculate self.velocity somehow\n sprite.set_hflip(\"#sprite\", self.velocity.x < 0);\n },\n});"
|
|
1593
|
+
"ts": "// How to flip a sprite so it faces the horizontal movement (it is assumed that\n// the sprite component has id \"sprite\" and the original animation faces right):\nexport default defineScript({\n init() {\n return { velocity: vmath.vector3() };\n },\n\n update(self, dt) {\n // calculate self.velocity somehow\n sprite.set_hflip(\"#sprite\", self.velocity.x < 0);\n },\n});"
|
|
1594
1594
|
}
|
|
1595
1595
|
],
|
|
1596
1596
|
"sprite.set_vflip": [
|
|
1597
1597
|
{
|
|
1598
1598
|
"sourceHash": "89dcc94c14d785e2",
|
|
1599
|
-
"ts": "// How to flip a sprite in a game which negates gravity as a game mechanic (it is\n// assumed that the sprite component has id \"sprite\" and the original animation\n// is up-right):\nexport default defineScript({\n update(self, dt) {\n // calculate self.up_side_down somehow, then:\n sprite.set_vflip(\"#sprite\", self.up_side_down);\n },\n});"
|
|
1599
|
+
"ts": "// How to flip a sprite in a game which negates gravity as a game mechanic (it is\n// assumed that the sprite component has id \"sprite\" and the original animation\n// is up-right):\nexport default defineScript({\n init() {\n return { up_side_down: false };\n },\n\n update(self, dt) {\n // calculate self.up_side_down somehow, then:\n sprite.set_vflip(\"#sprite\", self.up_side_down);\n },\n});"
|
|
1600
1600
|
}
|
|
1601
1601
|
],
|
|
1602
1602
|
"sys.deserialize": [
|
|
@@ -1608,7 +1608,7 @@
|
|
|
1608
1608
|
"sys.exists": [
|
|
1609
1609
|
{
|
|
1610
1610
|
"sourceHash": "7e98945102ff1ab7",
|
|
1611
|
-
"ts": "// Load data but return nil if path didn't exist\
|
|
1611
|
+
"ts": "// Load data but return nil if path didn't exist\nfunction load_data(path: string) {\n if (!sys.exists(path)) {\n return undefined;\n }\n return sys.load(path); // returns {} if it failed\n}"
|
|
1612
1612
|
}
|
|
1613
1613
|
],
|
|
1614
1614
|
"sys.exit": [
|
|
@@ -1620,7 +1620,7 @@
|
|
|
1620
1620
|
"sys.get_application_info": [
|
|
1621
1621
|
{
|
|
1622
1622
|
"sourceHash": "e13c2cc712709832",
|
|
1623
|
-
"ts": "// Check if twitter is installed:\nconst sysinfo = sys.get_sys_info();\nlet twitter = {};\n\nif (sysinfo.system_name === \"Android\") {\n twitter = sys.get_application_info(\"com.twitter.android\");\n} else if (sysinfo.system_name === \"iPhone OS\") {\n twitter = sys.get_application_info(\"twitter:\");\n}\n\nif (twitter.installed) {\n // twitter is installed!\n}\n\n// Info.plist for the iOS app needs to list the schemes that are queried:\n// ...\n// <key>LSApplicationQueriesSchemes</key>\n// <array>\n// <string>twitter</string>\n// </array>\n// ..."
|
|
1623
|
+
"ts": "// Check if twitter is installed:\nconst sysinfo = sys.get_sys_info();\nlet twitter: { installed?: boolean } = {};\n\nif (sysinfo.system_name === \"Android\") {\n twitter = sys.get_application_info(\"com.twitter.android\");\n} else if (sysinfo.system_name === \"iPhone OS\") {\n twitter = sys.get_application_info(\"twitter:\");\n}\n\nif (twitter.installed) {\n // twitter is installed!\n}\n\n// Info.plist for the iOS app needs to list the schemes that are queried:\n// ...\n// <key>LSApplicationQueriesSchemes</key>\n// <array>\n// <string>twitter</string>\n// </array>\n// ..."
|
|
1624
1624
|
}
|
|
1625
1625
|
],
|
|
1626
1626
|
"sys.get_application_path": [
|
|
@@ -1668,7 +1668,7 @@
|
|
|
1668
1668
|
"sys.get_host_path": [
|
|
1669
1669
|
{
|
|
1670
1670
|
"sourceHash": "a059ecb3d55d5c22",
|
|
1671
|
-
"ts": "// Save data on the host\
|
|
1671
|
+
"ts": "// Save data on the host\n{\n const mytable = { score: 100, level: 3 };\n const host_path = sys.get_host_path(\"logs/test.txt\");\n sys.save(host_path, mytable);\n}\n\n// Load data from the host\n{\n const host_path = sys.get_host_path(\"logs/test.txt\");\n const table = sys.load(host_path);\n}"
|
|
1672
1672
|
}
|
|
1673
1673
|
],
|
|
1674
1674
|
"sys.get_ifaddrs": [
|
|
@@ -1704,7 +1704,7 @@
|
|
|
1704
1704
|
"sys.load_buffer_async": [
|
|
1705
1705
|
{
|
|
1706
1706
|
"sourceHash": "6a383bca91cf11eb",
|
|
1707
|
-
"ts": "// Load binary data from a custom project resource and update a texture resource:\
|
|
1707
|
+
"ts": "// Load binary data from a custom project resource and update a texture resource:\n{\n function my_callback(self: unknown, request_id: unknown, result: unknown) {\n const { status, buf } = result as { status: number; buf: Opaque<\"buffer\"> };\n if (status === sys.REQUEST_STATUS_FINISHED) {\n resource.set_texture(\"/my_texture\", {}, buf); // texture args\n }\n }\n\n const my_request = sys.load_buffer_async(\"/assets/my_level_data.bin\", my_callback);\n}\n\n// Load binary data from non-custom resource files on disk:\nfunction my_callback(self: unknown, request_id: unknown, result: unknown) {\n const { first_asset, second_asset } = self as { first_asset: Hash; second_asset: Hash };\n if ((result as { status: number }).status !== sys.REQUEST_STATUS_FINISHED) {\n // uh oh! File could not be found, do something graceful\n } else if (request_id === first_asset) {\n // result.buffer contains data from my_level_asset.bin\n } else if (request_id === second_asset) {\n // result.buffer contains data from 'my_level.bin'\n }\n}\n\nexport default defineScript({\n init() {\n const first_path = \"folder_next_to_binary/my_level_asset.bin\";\n const second_path = \"/some_absolute_path/my_level.bin\";\n return {\n first_asset: hash(first_path),\n second_asset: hash(second_path),\n first_request: sys.load_buffer_async(first_path, my_callback),\n second_request: sys.load_buffer_async(second_path, my_callback),\n };\n },\n});"
|
|
1708
1708
|
}
|
|
1709
1709
|
],
|
|
1710
1710
|
"sys.load_resource": [
|
|
@@ -1846,7 +1846,7 @@
|
|
|
1846
1846
|
},
|
|
1847
1847
|
{
|
|
1848
1848
|
"sourceHash": "f4f87939dbdd5fc3",
|
|
1849
|
-
"ts": "// This example demonstrates how to update a text node that displays game score\n// in a counting fashion. It is assumed that the gui component receives messages\n// from the game when a new score is to be shown.\nexport default defineGuiScript({\n init(
|
|
1849
|
+
"ts": "// This example demonstrates how to update a text node that displays game score\n// in a counting fashion. It is assumed that the gui component receives messages\n// from the game when a new score is to be shown.\nexport default defineGuiScript({\n init() {\n return {\n // fetch the score text node for later use (assumes it is called \"score\")\n score_node: gui.get_node(\"score\"),\n // keep track of the current score counted up so far\n current_score: 0,\n // keep track of the target score we should count up to\n target_score: 0,\n // how fast we will update the score, in score/second\n score_update_speed: 1,\n };\n },\n\n update(self, dt) {\n // check if target score is more than current score\n if (self.current_score < self.target_score) {\n // increment current score according to the speed\n self.current_score = self.current_score + dt * self.score_update_speed;\n // check if we went past the target score, clamp current score in that case\n if (self.current_score > self.target_score) {\n self.current_score = self.target_score;\n }\n // update the score text node\n gui.set_text(self.score_node, \"\" + math.floor(self.current_score));\n }\n },\n\n on_message(self, message_id, message) {\n // check the message\n if (message_id === hash(\"set_score\") && typeof message.score === \"number\") {\n self.target_score = message.score;\n }\n },\n});"
|
|
1850
1850
|
}
|
|
1851
1851
|
],
|
|
1852
1852
|
"vmath.clamp": [
|
|
@@ -1904,11 +1904,11 @@
|
|
|
1904
1904
|
},
|
|
1905
1905
|
{
|
|
1906
1906
|
"sourceHash": "7cf8c0c1679ab05b",
|
|
1907
|
-
"ts": "export default defineScript({\n init(
|
|
1907
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startrot = vmath.quat_rotation_z(0);\n const endrot = vmath.quat_rotation_z(3.141592653);\n const rot = vmath.lerp(self.t, startrot, endrot);\n go.set_rotation(rot, \"go\");\n }\n },\n});"
|
|
1908
1908
|
},
|
|
1909
1909
|
{
|
|
1910
1910
|
"sourceHash": "0f4fdfe7a9a39df7",
|
|
1911
|
-
"ts": "export default defineScript({\n init(
|
|
1911
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startx = 0;\n const endx = 600;\n const x = vmath.lerp(self.t, startx, endx);\n go.set_position(vmath.vector3(x, 100, 0), \"go\");\n }\n },\n});"
|
|
1912
1912
|
}
|
|
1913
1913
|
],
|
|
1914
1914
|
"vmath.matrix4": [
|
|
@@ -2094,7 +2094,7 @@
|
|
|
2094
2094
|
},
|
|
2095
2095
|
{
|
|
2096
2096
|
"sourceHash": "858acbd524dfe896",
|
|
2097
|
-
"ts": "export default defineScript({\n init(
|
|
2097
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startrot = vmath.quat_rotation_z(0);\n const endrot = vmath.quat_rotation_z(3.141592653);\n const rot = vmath.slerp(self.t, startrot, endrot);\n go.set_rotation(rot, \"go\");\n }\n },\n});"
|
|
2098
2098
|
}
|
|
2099
2099
|
],
|
|
2100
2100
|
"vmath.vector": [
|