melonjs 20.12.0 → 20.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -22
- package/build/application/application.d.ts +6 -1
- package/build/application/application.d.ts.map +1 -1
- package/build/application/header.d.ts.map +1 -1
- package/build/application/resize.d.ts.map +1 -1
- package/build/application/settings.d.ts +13 -8
- package/build/application/settings.d.ts.map +1 -1
- package/build/audio/audio.d.ts +8 -4
- package/build/audio/audio.d.ts.map +1 -1
- package/build/audio/backend/engine.d.ts.map +1 -1
- package/build/audio/playback.d.ts +2 -2
- package/build/audio/playback.d.ts.map +1 -1
- package/build/audio/spatial.d.ts.map +1 -1
- package/build/audio/types.d.ts +15 -5
- package/build/audio/types.d.ts.map +1 -1
- package/build/camera/camera2d.d.ts +12 -9
- package/build/camera/camera2d.d.ts.map +1 -1
- package/build/camera/camera3d.d.ts +11 -8
- package/build/camera/camera3d.d.ts.map +1 -1
- package/build/camera/effects/fade_effect.d.ts.map +1 -1
- package/build/geometries/ellipse.d.ts +3 -0
- package/build/geometries/ellipse.d.ts.map +1 -1
- package/build/geometries/line.d.ts.map +1 -1
- package/build/geometries/path2d.d.ts +9 -8
- package/build/geometries/path2d.d.ts.map +1 -1
- package/build/geometries/polygon.d.ts +2 -1
- package/build/geometries/polygon.d.ts.map +1 -1
- package/build/index.d.ts +14 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +50215 -45051
- package/build/index.js.map +4 -4
- package/build/input/gamepad.d.ts.map +1 -1
- package/build/input/keyboard.d.ts.map +1 -1
- package/build/input/pointerevent.d.ts.map +1 -1
- package/build/level/gltf/GLTFModel.d.ts.map +1 -1
- package/build/level/level.d.ts.map +1 -1
- package/build/level/tiled/TMXLayer.d.ts +50 -15
- package/build/level/tiled/TMXLayer.d.ts.map +1 -1
- package/build/level/tiled/TMXTileMap.d.ts +14 -4
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/level/tiled/TMXTileset.d.ts.map +1 -1
- package/build/level/tiled/TMXUtils.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts +1 -0
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXRenderer.d.ts +7 -3
- package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXStaggeredRenderer.d.ts.map +1 -1
- package/build/lighting/light3d.d.ts +55 -0
- package/build/lighting/light3d.d.ts.map +1 -1
- package/build/loader/cache.d.ts +146 -97
- package/build/loader/cache.d.ts.map +1 -1
- package/build/loader/internal-types.d.ts +69 -0
- package/build/loader/internal-types.d.ts.map +1 -0
- package/build/loader/loader.d.ts +589 -253
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/parsers/audio.d.ts.map +1 -1
- package/build/loader/parsers/fontface.d.ts.map +1 -1
- package/build/loader/parsers/gltf.d.ts.map +1 -1
- package/build/loader/parsers/tmx.d.ts.map +1 -1
- package/build/math/color.d.ts +4 -0
- package/build/math/color.d.ts.map +1 -1
- package/build/math/math.d.ts +6 -1
- package/build/math/math.d.ts.map +1 -1
- package/build/math/noise.d.ts +16 -16
- package/build/math/noise.d.ts.map +1 -1
- package/build/math/observableVector2d.d.ts +6 -6
- package/build/math/observableVector2d.d.ts.map +1 -1
- package/build/math/observableVector3d.d.ts +8 -8
- package/build/math/observableVector3d.d.ts.map +1 -1
- package/build/particles/emitter.d.ts +15 -3
- package/build/particles/emitter.d.ts.map +1 -1
- package/build/particles/particle.d.ts +6 -0
- package/build/particles/particle.d.ts.map +1 -1
- package/build/particles/settings.d.ts +22 -5
- package/build/particles/settings.d.ts.map +1 -1
- package/build/physics/adapter.d.ts +64 -25
- package/build/physics/adapter.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +23 -4
- package/build/physics/builtin/body.d.ts.map +1 -1
- package/build/physics/builtin/builtin-adapter.d.ts +25 -3
- package/build/physics/builtin/builtin-adapter.d.ts.map +1 -1
- package/build/physics/builtin/detector.d.ts.map +1 -1
- package/build/physics/builtin/raycast.d.ts.map +1 -1
- package/build/physics/world.d.ts +40 -10
- package/build/physics/world.d.ts.map +1 -1
- package/build/renderable/container.d.ts +41 -6
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/draggable.d.ts.map +1 -1
- package/build/renderable/frameAnimation.d.ts.map +1 -1
- package/build/renderable/instanced_mesh.d.ts +16 -14
- package/build/renderable/instanced_mesh.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +62 -5
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +4 -2
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/text/bitmaptext.d.ts +12 -3
- package/build/renderable/text/bitmaptext.d.ts.map +1 -1
- package/build/renderable/text/text.d.ts +147 -4
- package/build/renderable/text/text.d.ts.map +1 -1
- package/build/renderable/text/textmetrics.d.ts +10 -2
- package/build/renderable/text/textmetrics.d.ts.map +1 -1
- package/build/renderable/text/textstyle.d.ts.map +1 -1
- package/build/renderable/trigger.d.ts +5 -0
- package/build/renderable/trigger.d.ts.map +1 -1
- package/build/renderable/ui/panelpaint.d.ts +5 -1
- package/build/renderable/ui/panelpaint.d.ts.map +1 -1
- package/build/renderable/ui/progressbar.d.ts +267 -95
- package/build/renderable/ui/progressbar.d.ts.map +1 -1
- package/build/renderable/ui/uibaseelement.d.ts +443 -50
- package/build/renderable/ui/uibaseelement.d.ts.map +1 -1
- package/build/renderable/ui/uicheckbox.d.ts +383 -0
- package/build/renderable/ui/uicheckbox.d.ts.map +1 -0
- package/build/renderable/ui/uifocus.d.ts +6 -0
- package/build/renderable/ui/uifocus.d.ts.map +1 -0
- package/build/renderable/ui/uilabel.d.ts +31 -0
- package/build/renderable/ui/uilabel.d.ts.map +1 -0
- package/build/renderable/ui/uipanel.d.ts +589 -116
- package/build/renderable/ui/uipanel.d.ts.map +1 -1
- package/build/renderable/ui/uiskin.d.ts +25 -0
- package/build/renderable/ui/uiskin.d.ts.map +1 -0
- package/build/renderable/ui/uislider.d.ts +518 -0
- package/build/renderable/ui/uislider.d.ts.map +1 -0
- package/build/renderable/ui/uispriteelement.d.ts +161 -85
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
- package/build/renderable/ui/uitextbutton.d.ts +369 -63
- package/build/renderable/ui/uitextbutton.d.ts.map +1 -1
- package/build/state/stage.d.ts.map +1 -1
- package/build/system/device.d.ts +11 -2
- package/build/system/device.d.ts.map +1 -1
- package/build/system/fullscreen.d.ts.map +1 -1
- package/build/system/pool.d.ts.map +1 -1
- package/build/system/save.d.ts +2 -1
- package/build/system/save.d.ts.map +1 -1
- package/build/tweens/tween.d.ts +5 -2
- package/build/tweens/tween.d.ts.map +1 -1
- package/build/utils/fetchdata.d.ts.map +1 -1
- package/build/utils/utils.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +16 -19
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/canvas_factory.d.ts.map +1 -1
- package/build/video/effects/shadereffect.d.ts +127 -0
- package/build/video/effects/shadereffect.d.ts.map +1 -1
- package/build/video/renderer.d.ts +20 -4
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/renderstate.d.ts +26 -3
- package/build/video/renderstate.d.ts.map +1 -1
- package/build/video/utils/tessellation.d.ts +11 -0
- package/build/video/utils/tessellation.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +3 -6
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/build/video/webgpu/batchers/lit_mesh_batcher.d.ts.map +1 -1
- package/build/video/webgpu/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgpu/webgpu_renderer.d.ts +3 -6
- package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/melonjs/SKILL.md +41 -17
- package/skills/melonjs-20-migration/SKILL.md +50 -7
- package/skills/melonjs-3d/SKILL.md +138 -38
- package/skills/melonjs-3d-assets/SKILL.md +83 -33
- package/skills/melonjs-audio/SKILL.md +62 -19
- package/skills/melonjs-camera-and-drawing/SKILL.md +135 -8
- package/skills/melonjs-deployment/SKILL.md +92 -14
- package/skills/melonjs-display-and-scaling/SKILL.md +8 -3
- package/skills/melonjs-effects-and-shaders/SKILL.md +47 -15
- package/skills/melonjs-events/SKILL.md +6 -3
- package/skills/melonjs-getting-started/SKILL.md +6 -2
- package/skills/melonjs-input/SKILL.md +102 -16
- package/skills/melonjs-lighting/SKILL.md +13 -1
- package/skills/melonjs-loading-assets/SKILL.md +255 -39
- package/skills/melonjs-math/SKILL.md +26 -8
- package/skills/melonjs-particles-and-trails/SKILL.md +77 -9
- package/skills/melonjs-performance/SKILL.md +18 -8
- package/skills/melonjs-physics/SKILL.md +435 -128
- package/skills/melonjs-plugins/SKILL.md +50 -11
- package/skills/melonjs-renderables/SKILL.md +31 -7
- package/skills/melonjs-renderer-backends/SKILL.md +38 -17
- package/skills/melonjs-scenes-and-state/SKILL.md +45 -5
- package/skills/melonjs-sprites-and-animation/SKILL.md +37 -2
- package/skills/melonjs-tilemaps/SKILL.md +149 -17
- package/skills/melonjs-ui-and-text/SKILL.md +674 -42
package/build/loader/cache.d.ts
CHANGED
|
@@ -1,64 +1,92 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Get a loaded Tiled map or tileset (a `"tmx"` or `"tsx"` asset) as parsed
|
|
4
|
+
* data: the map's JSON structure, whether it was loaded from XML or JSON.
|
|
5
|
+
* Most code never needs it: `level.load(name)` builds the level from it.
|
|
6
|
+
* @param {string} elt - the asset name
|
|
7
|
+
* @returns {object} the parsed map or tileset, or `null` if none is loaded
|
|
8
|
+
* under that name
|
|
9
|
+
* @example
|
|
10
|
+
* const map = loader.getTMX("map1");
|
|
11
|
+
* console.log(map.width, map.height, map.layers.length);
|
|
6
12
|
* @category Assets
|
|
7
13
|
*/
|
|
8
14
|
export function getTMX(elt: string): object;
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
16
|
+
* Get the content of a loaded `"binary"` asset, decoded as UTF-8 text: what
|
|
17
|
+
* a bitmap font's `.fnt` descriptor, for one, is loaded as.
|
|
18
|
+
* @param {string} elt - the asset name
|
|
19
|
+
* @returns {object} the file's content, as a string, or `null` if none is
|
|
20
|
+
* loaded under that name
|
|
21
|
+
* @example
|
|
22
|
+
* // a bitmap font: its image, and its descriptor as "binary"
|
|
23
|
+
* await loader.preload([
|
|
24
|
+
* { name: "PressStart2P", type: "image", src: "data/fnt/PressStart2P.png" },
|
|
25
|
+
* { name: "PressStart2P", type: "binary", src: "data/fnt/PressStart2P.fnt" },
|
|
26
|
+
* ]);
|
|
27
|
+
* const fnt = loader.getBinary("PressStart2P");
|
|
13
28
|
* @category Assets
|
|
14
29
|
*/
|
|
15
30
|
export function getBinary(elt: string): object;
|
|
16
31
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
32
|
+
* Get a loaded image (an `"image"` asset, or the image of an `"aseprite"`
|
|
33
|
+
* one). Given a path, its directory and extension are ignored, so
|
|
34
|
+
* `getImage("data/img/player.png")` finds the image named `"player"`.
|
|
35
|
+
* Most engine classes take the name instead, and look it up themselves:
|
|
36
|
+
* `new Sprite(0, 0, { image: "player" })`.
|
|
37
|
+
* @param {string} image - the asset name
|
|
38
|
+
* @returns {HTMLImageElement|CompressedImage|null} the image, or `null` if
|
|
39
|
+
* none is loaded under that name
|
|
40
|
+
* @example
|
|
41
|
+
* const player = loader.getImage("player");
|
|
42
|
+
* console.log(player.width, player.height);
|
|
20
43
|
* @category Assets
|
|
21
44
|
*/
|
|
22
45
|
export function getImage(image: string): HTMLImageElement | CompressedImage | null;
|
|
23
46
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
47
|
+
* Get a loaded JSON file (a `"json"` asset, or the descriptor of an
|
|
48
|
+
* `"aseprite"` one), parsed.
|
|
49
|
+
* @param {string} elt - the asset name
|
|
50
|
+
* @returns {JSON} the parsed content, or `null` if none is loaded under that
|
|
51
|
+
* name
|
|
52
|
+
* @example
|
|
53
|
+
* // a texture atlas: its image and its JSON descriptor share a name
|
|
54
|
+
* const atlas = new TextureAtlas(loader.getJSON("texture"), loader.getImage("texture"));
|
|
27
55
|
* @category Assets
|
|
28
56
|
*/
|
|
29
57
|
export function getJSON(elt: string): JSON;
|
|
30
58
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
59
|
+
* Get a loaded Wavefront OBJ model (an `"obj"` asset), parsed. Most code
|
|
60
|
+
* never needs it: a `Mesh` takes the model's name.
|
|
61
|
+
* @param {string} elt - the asset name
|
|
62
|
+
* @returns {object} the parsed model: `vertices` (Float32Array of x, y, z),
|
|
63
|
+
* `uvs` (Float32Array of u, v), `indices` (Uint16Array of triangle vertex
|
|
64
|
+
* indices), `vertexCount`, and `groups` (the `usemtl` material groups, as
|
|
65
|
+
* `{materialName, start, count}` index ranges); or `null` if none is loaded
|
|
66
|
+
* under that name
|
|
34
67
|
* @category Assets
|
|
35
68
|
* @example
|
|
36
69
|
* // 1. preload the OBJ model and its texture
|
|
37
|
-
*
|
|
38
|
-
* { name: "cube", type: "obj",
|
|
70
|
+
* await loader.preload([
|
|
71
|
+
* { name: "cube", type: "obj", src: "models/cube.obj" },
|
|
39
72
|
* { name: "cube", type: "image", src: "models/cube_texture.png" },
|
|
40
|
-
* ]
|
|
41
|
-
* // 2. create a Mesh using the preloaded model name
|
|
42
|
-
* const mesh = new me.Mesh(400, 300, {
|
|
43
|
-
* model: "cube", // references the preloaded OBJ
|
|
44
|
-
* texture: "cube", // references the preloaded image
|
|
45
|
-
* width: 200,
|
|
46
|
-
* height: 200,
|
|
47
|
-
* });
|
|
48
|
-
* me.game.world.addChild(mesh);
|
|
73
|
+
* ]);
|
|
49
74
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* // data.groups — usemtl material groups ({materialName, start, count} index ranges)
|
|
75
|
+
* // 2. a Mesh takes the model and the texture by name
|
|
76
|
+
* const mesh = new Mesh(400, 300, {
|
|
77
|
+
* model: "cube",
|
|
78
|
+
* texture: "cube",
|
|
79
|
+
* width: 200,
|
|
80
|
+
* height: 200,
|
|
57
81
|
* });
|
|
82
|
+
* app.world.addChild(mesh);
|
|
83
|
+
*
|
|
84
|
+
* // 3. or read the parsed data directly
|
|
85
|
+
* const { vertices, uvs, indices, vertexCount } = loader.getOBJ("cube");
|
|
58
86
|
*/
|
|
59
87
|
export function getOBJ(elt: string): object;
|
|
60
88
|
/**
|
|
61
|
-
*
|
|
89
|
+
* Get a loaded glTF/GLB scene (a `"gltf"` or `"glb"` asset), parsed.
|
|
62
90
|
*
|
|
63
91
|
* The descriptor is `{ nodes, cameras, lights, bounds, graph, animations }`:
|
|
64
92
|
* - `nodes` — one entry per mesh primitive, each carrying its accumulated
|
|
@@ -74,32 +102,30 @@ export function getOBJ(elt: string): object;
|
|
|
74
102
|
* automatically (see {@link level.load} options).
|
|
75
103
|
* - `bounds` — world-space `{ min, max }` (glTF units), handy for framing.
|
|
76
104
|
*
|
|
77
|
-
* Most code never needs this: a
|
|
105
|
+
* Most code never needs this: a loaded glTF/GLB registers with the
|
|
78
106
|
* {@link level} director, so the whole scene loads into a container in one
|
|
79
|
-
* call
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* @param {string} elt -
|
|
83
|
-
* @returns {GLTFData|null} the parsed scene descriptor, or `null` if
|
|
107
|
+
* call, `level.load(name)`, exactly like a Tiled map. Reach for `getGLTF`
|
|
108
|
+
* only to inspect the raw descriptor (to frame a `Camera3d` from the
|
|
109
|
+
* embedded camera, say).
|
|
110
|
+
* @param {string} elt - the asset name
|
|
111
|
+
* @returns {GLTFData|null} the parsed scene descriptor, or `null` if none is
|
|
112
|
+
* loaded under that name
|
|
84
113
|
* @category Assets
|
|
85
114
|
* @example
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
115
|
+
* await loader.preload([
|
|
116
|
+
* { name: "diorama", type: "glb", src: "scenes/diorama.glb" },
|
|
117
|
+
* ]);
|
|
118
|
+
*
|
|
119
|
+
* // load the whole scene into the world (view it under a Camera3d)
|
|
120
|
+
* level.load("diorama", { scale: 32 });
|
|
91
121
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* const { min, max } = scene.bounds;
|
|
95
|
-
* },
|
|
96
|
-
* );
|
|
122
|
+
* // ...or inspect the raw descriptor for custom framing
|
|
123
|
+
* const { min, max } = loader.getGLTF("diorama").bounds;
|
|
97
124
|
*/
|
|
98
125
|
export function getGLTF(elt: string): GLTFData | null;
|
|
99
126
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* camera `shader` property.
|
|
127
|
+
* Get the shader compiled from a loaded `"shader"` asset — compiled once,
|
|
128
|
+
* at load time, ready to add to a renderable or a camera as a post effect.
|
|
103
129
|
*
|
|
104
130
|
* **This returns a SHARED instance**: the *same* `ShaderEffect` object on
|
|
105
131
|
* every call, owned by the loader (its `shared` flag is `true`). That means:
|
|
@@ -122,6 +148,11 @@ export function getGLTF(elt: string): GLTFData | null;
|
|
|
122
148
|
* `renderer.customShader`, a custom batcher). Same shared-instance
|
|
123
149
|
* semantics, and `GLShader.clone()` likewise yields a caller-owned copy.
|
|
124
150
|
*
|
|
151
|
+
* Unloading the asset destroys the shared instance, under whatever still
|
|
152
|
+
* draws with it: with bundles, an effect that outlives a level (a HUD's, a
|
|
153
|
+
* camera's) belongs in a bundle that outlives that level, such as
|
|
154
|
+
* `"common"`. A `clone()` is the caller's own and is not destroyed with it.
|
|
155
|
+
*
|
|
125
156
|
* Degradation is never fatal: a fragment-body asset without a body in the
|
|
126
157
|
* active renderer's language (or on Canvas) is an inert `ShaderEffect`
|
|
127
158
|
* stub, and a complete-program asset without a realization for the active
|
|
@@ -129,77 +160,95 @@ export function getGLTF(elt: string): GLTFData | null;
|
|
|
129
160
|
* built-in rendering. Note that shader assets require an initialized
|
|
130
161
|
* Application (`await app.init()`) — an inherent precondition of the
|
|
131
162
|
* preload flow, since the loading screen itself needs the renderer.
|
|
132
|
-
* @param {string} elt -
|
|
133
|
-
* @returns {ShaderEffect|GLShader|null} the shared, precompiled shader, or
|
|
163
|
+
* @param {string} elt - the asset name
|
|
164
|
+
* @returns {ShaderEffect|GLShader|null} the shared, precompiled shader, or
|
|
165
|
+
* `null` if none is loaded under that name
|
|
134
166
|
* @category Assets
|
|
135
167
|
* @example
|
|
136
|
-
*
|
|
137
|
-
* // from a file (or data: URI)
|
|
168
|
+
* await loader.preload([
|
|
169
|
+
* // from a file (or a data: URI)
|
|
138
170
|
* { name: "waterRipple", type: "shader", src: "shaders/waterRipple.frag" },
|
|
139
|
-
* // or inline GLSL
|
|
171
|
+
* // or inline GLSL, through the `data` field
|
|
140
172
|
* { name: "flash", type: "shader", data: `
|
|
141
173
|
* uniform float uIntensity;
|
|
142
174
|
* vec4 apply(vec4 color, vec2 uv) { return mix(color, vec4(1.0), uIntensity); }
|
|
143
175
|
* ` },
|
|
144
|
-
* // or a complete program
|
|
145
|
-
* //
|
|
146
|
-
* //
|
|
176
|
+
* // or a complete program: a {vertex, fragment} GLSL pair and/or a full
|
|
177
|
+
* // WGSL module, compiled into one GLShader; the active renderer hosts
|
|
178
|
+
* // the one it speaks
|
|
147
179
|
* { name: "toonMesh", type: "shader", src: {
|
|
148
180
|
* vertex: "shaders/toon.vert",
|
|
149
181
|
* fragment: "shaders/toon.frag",
|
|
150
182
|
* wgsl: "shaders/toon.wgsl",
|
|
151
183
|
* } },
|
|
152
|
-
* ]
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
184
|
+
* ]);
|
|
185
|
+
*
|
|
186
|
+
* // one shared program: the same uniform values for every user
|
|
187
|
+
* mySprite.addPostEffect(loader.getShader("waterRipple"));
|
|
188
|
+
* // a private copy with its own uniforms (caller-owned, shared = false)
|
|
189
|
+
* boss.addPostEffect(loader.getShader("flash").clone());
|
|
190
|
+
* // a complete program hosts on a mesh, replacing the built-in shading
|
|
191
|
+
* myMesh.addPostEffect(loader.getShader("toonMesh"));
|
|
160
192
|
*/
|
|
161
193
|
export function getShader(elt: string): ShaderEffect | GLShader | null;
|
|
162
194
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
195
|
+
* Get a loaded Wavefront MTL material library (an `"mtl"` asset), parsed.
|
|
196
|
+
* Most code never needs it: a `Mesh` takes the library's name as its
|
|
197
|
+
* `material`.
|
|
198
|
+
* @param {string} elt - the asset name
|
|
199
|
+
* @returns {object} the materials by name, each with its properties (`Kd`,
|
|
200
|
+
* `d`, `Ke`, `map_Kd`...), or `null` if none is loaded under that name
|
|
166
201
|
* @category Assets
|
|
167
202
|
* @example
|
|
168
|
-
* // 1. preload
|
|
169
|
-
*
|
|
170
|
-
* { name: "fox",
|
|
171
|
-
* { name: "fox",
|
|
203
|
+
* // 1. preload the model, its materials and their texture
|
|
204
|
+
* await loader.preload([
|
|
205
|
+
* { name: "fox", type: "obj", src: "models/fox.obj" },
|
|
206
|
+
* { name: "fox", type: "mtl", src: "models/fox.mtl" },
|
|
172
207
|
* { name: "colormap", type: "image", src: "models/colormap.png" },
|
|
173
|
-
* ]
|
|
174
|
-
* // 2. create a Mesh with material — texture, tint, opacity auto-applied
|
|
175
|
-
* const mesh = new me.Mesh(400, 300, {
|
|
176
|
-
* model: "fox",
|
|
177
|
-
* material: "fox",
|
|
178
|
-
* texture: "colormap",
|
|
179
|
-
* width: 200,
|
|
180
|
-
* height: 200,
|
|
181
|
-
* });
|
|
208
|
+
* ]);
|
|
182
209
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
210
|
+
* // 2. a Mesh with a material: texture, tint and opacity applied for you
|
|
211
|
+
* const mesh = new Mesh(400, 300, {
|
|
212
|
+
* model: "fox",
|
|
213
|
+
* material: "fox",
|
|
214
|
+
* texture: "colormap",
|
|
215
|
+
* width: 200,
|
|
216
|
+
* height: 200,
|
|
189
217
|
* });
|
|
218
|
+
*
|
|
219
|
+
* // 3. or read the materials directly
|
|
220
|
+
* const materials = loader.getMTL("fox");
|
|
221
|
+
* // materials["colormap"].Kd — [r, g, b] diffuse color (0-1 range)
|
|
222
|
+
* // materials["colormap"].d — opacity (0-1)
|
|
223
|
+
* // materials["colormap"].Ke — [r, g, b] emissive color (applied as Mesh.emissive)
|
|
224
|
+
* // materials["colormap"].map_Kd — resolved texture URL
|
|
190
225
|
*/
|
|
191
226
|
export function getMTL(elt: string): object;
|
|
192
227
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* @
|
|
228
|
+
* Get a loaded video (a `"video"` asset): the `<video>` element the loader
|
|
229
|
+
* created for it.
|
|
230
|
+
* @param {string} elt - the asset name
|
|
231
|
+
* @returns {HTMLVideoElement} the video element, or `null` if none is loaded
|
|
232
|
+
* under that name
|
|
233
|
+
* @example
|
|
234
|
+
* await loader.preload([{ name: "intro", type: "video", src: "data/video/intro.mp4" }]);
|
|
235
|
+
* const intro = loader.getVideo("intro");
|
|
236
|
+
* intro.play();
|
|
196
237
|
* @category Assets
|
|
197
238
|
*/
|
|
198
239
|
export function getVideo(elt: string): HTMLVideoElement;
|
|
199
240
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* @
|
|
241
|
+
* Get a loaded web font (a `"fontface"` asset): the `FontFace` the loader
|
|
242
|
+
* added to `document.fonts`. Text uses it by its name, as a CSS font family.
|
|
243
|
+
* @param {string} elt - the asset name
|
|
244
|
+
* @returns {FontFace} the font face, or `null` if none is loaded under that
|
|
245
|
+
* name
|
|
246
|
+
* @example
|
|
247
|
+
* await loader.preload([
|
|
248
|
+
* { name: "kenpixel", type: "fontface", src: "data/font/kenvector_future.woff2" },
|
|
249
|
+
* ]);
|
|
250
|
+
* const label = new Text(10, 10, { font: "kenpixel", size: 16, text: "Score" });
|
|
251
|
+
* console.log(loader.getFont("kenpixel").status); // "loaded"
|
|
203
252
|
* @category Assets
|
|
204
253
|
*/
|
|
205
254
|
export function getFont(elt: string): FontFace;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/loader/cache.js"],"names":[],"mappings":"AAsFA;;;;;;;;;;GAUG;AACH,+BANW,MAAM,QACN,MAAM,GACJ,OAAO,CAOnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,kCANW,MAAM,QACN,MAAM,GACJ,OAAO,CAWnB;AAED;;;;;;;;;GASG;AACH,iCALW,MAAM,GACJ,MAAM,EAAE,CAOpB;AAeD
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/loader/cache.js"],"names":[],"mappings":"AAsFA;;;;;;;;;;GAUG;AACH,+BANW,MAAM,QACN,MAAM,GACJ,OAAO,CAOnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,kCANW,MAAM,QACN,MAAM,GACJ,OAAO,CAWnB;AAED;;;;;;;;;GASG;AACH,iCALW,MAAM,GACJ,MAAM,EAAE,CAOpB;AAeD;;;;;;;;;;;GAWG;AACH,4BARW,MAAM,GACJ,MAAM,CAclB;AAED;;;;;;;;;;;;;;GAcG;AACH,+BAZW,MAAM,GACJ,MAAM,CAkBlB;AAED;;;;;;;;;;;;;GAaG;AACH,gCARW,MAAM,GACJ,gBAAgB,GAAC,eAAe,GAAC,IAAI,CAejD;AAED;;;;;;;;;;GAUG;AACH,6BARW,MAAM,GACJ,IAAI,CAchB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,4BA1BW,MAAM,GACJ,MAAM,CAgClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,6BAfW,MAAM,GACJ,QAAQ,GAAC,IAAI,CAoBzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,+BA9BW,MAAM,GACJ,YAAY,GAAC,QAAQ,GAAC,IAAI,CAmCtC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,4BA5BW,MAAM,GACJ,MAAM,CAiClB;AAED;;;;;;;;;;;GAWG;AACH,8BATW,MAAM,GACJ,gBAAgB,CAe5B;AAED;;;;;;;;;;;;;GAaG;AACH,6BAXW,MAAM,GACJ,QAAQ,CAiBpB;AAneD;;;;;;;;;;GAUG;AAEH;;GAEG;AAGH,yBAA0B;AAG1B,yBAA0B;AAG1B,yBAA0B;AAG1B,0BAA2B;AAG3B,2BAA4B;AAG5B,0BAA2B;AAG3B,yBAA0B;AAG1B,yBAA0B;AAG1B,0BAA2B;AAK3B,4BAA6B;AAyB7B;;;;;;;;;;GAUG;AACH,2BAJU,SAAS,MAAM,EAAE,CAIyC;qCA5ElC,mDAAmD;8BAC1D,mBAAmB;8BAEjB,kCAAkC;0BADtC,4BAA4B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The progress `loader.preload` reports through `LOADER_PROGRESS`: the
|
|
3
|
+
* assets asked for and how many of them have loaded.
|
|
4
|
+
*
|
|
5
|
+
* One tally for every preload in flight, so that a second preload started
|
|
6
|
+
* before the first has settled joins it and the one progress bar keeps
|
|
7
|
+
* counting, rather than two calls taking turns to move it back and forth. Once
|
|
8
|
+
* every asset in it has settled (loaded or failed), the next preload starts a
|
|
9
|
+
* fresh tally from zero. These counters used to live for the whole session, so
|
|
10
|
+
* a second preload of two assets reported `0.75, 1` instead of `0.5, 1`, and
|
|
11
|
+
* after one failed asset no later preload reached `1` at all.
|
|
12
|
+
*/
|
|
13
|
+
export interface PreloadTally {
|
|
14
|
+
/** assets asked for */
|
|
15
|
+
total: number;
|
|
16
|
+
/** assets that loaded */
|
|
17
|
+
loaded: number;
|
|
18
|
+
/** assets that loaded or failed */
|
|
19
|
+
settled: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A bundle declared with `loader.setBundle`: a named list of assets with a
|
|
23
|
+
* lifetime of its own, over the same caches as every other asset.
|
|
24
|
+
*
|
|
25
|
+
* `state` is what `setBundle` checks: a bundle is `"loading"` from a
|
|
26
|
+
* `load(id)` / `preload([id])` until every asset of that call has settled,
|
|
27
|
+
* `"loaded"` after that (even when one failed: it keeps the ones that did
|
|
28
|
+
* load), and `"unloaded"` again after `unload(id)` or `unloadAll()`.
|
|
29
|
+
* `epoch` changes on every unload, so a load still in flight from before
|
|
30
|
+
* cannot hand its assets to a bundle that has since been released.
|
|
31
|
+
*/
|
|
32
|
+
export interface Bundle {
|
|
33
|
+
/** the bundle's asset descriptors */
|
|
34
|
+
assets: Asset[];
|
|
35
|
+
/** see above */
|
|
36
|
+
state: "unloaded" | "loading" | "loaded";
|
|
37
|
+
/** bumped on every unload of the bundle */
|
|
38
|
+
epoch: number;
|
|
39
|
+
/** calls loading it that have not settled yet */
|
|
40
|
+
loads: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A registered parser, normalized by `loader.setParser`.
|
|
44
|
+
*
|
|
45
|
+
* Every type gets the same shape whether or not it needs the src hooks, so
|
|
46
|
+
* `load()` can treat all of them alike. The alternative — a bare function that
|
|
47
|
+
* some types decorate with extra properties — puts the knowledge of which
|
|
48
|
+
* types are special back into the caller, which is what moving it out was for.
|
|
49
|
+
*/
|
|
50
|
+
export interface AssetParser {
|
|
51
|
+
/**
|
|
52
|
+
* preloads the asset and returns how many resources it will load (0 when
|
|
53
|
+
* already cached)
|
|
54
|
+
*/
|
|
55
|
+
parse: (asset: Asset, onload?: (...args: unknown[]) => void, onerror?: (...args: unknown[]) => void, settings?: object) => number;
|
|
56
|
+
/**
|
|
57
|
+
* turns a type-specific descriptor into a bare path, before any base URL
|
|
58
|
+
* is applied. Identity unless the type overrides it
|
|
59
|
+
*/
|
|
60
|
+
normalizeSrc: (src: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* whether the normalized src is relative to this type's base URL. Declares
|
|
63
|
+
* only this type's own exceptions, such as a `local()` font naming an
|
|
64
|
+
* installed family — data URIs are excluded for every type before this is
|
|
65
|
+
* consulted
|
|
66
|
+
*/
|
|
67
|
+
needsBaseURL: (src: string) => boolean;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=internal-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-types.d.ts","sourceRoot":"","sources":["../../src/loader/internal-types.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC5B,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM;IACtB,qCAAqC;IACrC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,gBAAgB;IAChB,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IACzC,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC3B;;;OAGG;IACH,KAAK,EAAE,CACN,KAAK,EAAE,KAAK,EACZ,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACrC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EACtC,QAAQ,CAAC,EAAE,MAAM,KACb,MAAM,CAAC;IACZ;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACtC;;;;;OAKG;IACH,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC"}
|