melonjs 19.7.1 → 19.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +18 -6
  2. package/build/application/defaultApplicationSettings.d.ts +1 -0
  3. package/build/application/defaultApplicationSettings.d.ts.map +1 -1
  4. package/build/application/settings.d.ts +34 -0
  5. package/build/application/settings.d.ts.map +1 -1
  6. package/build/camera/camera3d.d.ts +49 -0
  7. package/build/camera/camera3d.d.ts.map +1 -1
  8. package/build/index.d.ts +7 -2
  9. package/build/index.d.ts.map +1 -1
  10. package/build/index.js +17392 -14529
  11. package/build/index.js.map +4 -4
  12. package/build/level/gltf/GLTFModel.d.ts +173 -0
  13. package/build/level/gltf/GLTFModel.d.ts.map +1 -0
  14. package/build/level/gltf/GLTFScene.d.ts +84 -0
  15. package/build/level/gltf/GLTFScene.d.ts.map +1 -0
  16. package/build/level/gltf/gltf_sampler.d.ts +49 -0
  17. package/build/level/gltf/gltf_sampler.d.ts.map +1 -0
  18. package/build/level/level.d.ts +7 -3
  19. package/build/level/level.d.ts.map +1 -1
  20. package/build/level/tiled/TMXTileMap.d.ts +5 -0
  21. package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
  22. package/build/{renderable → lighting}/light2d.d.ts +79 -78
  23. package/build/lighting/light2d.d.ts.map +1 -0
  24. package/build/lighting/light3d.d.ts +86 -0
  25. package/build/lighting/light3d.d.ts.map +1 -0
  26. package/build/loader/cache.d.ts +1 -0
  27. package/build/loader/cache.d.ts.map +1 -1
  28. package/build/loader/loader.d.ts +95 -5
  29. package/build/loader/loader.d.ts.map +1 -1
  30. package/build/loader/parsers/gltf.d.ts +71 -0
  31. package/build/loader/parsers/gltf.d.ts.map +1 -0
  32. package/build/loader/parsers/mtl.d.ts.map +1 -1
  33. package/build/math/math.d.ts +2 -2
  34. package/build/math/vertex.d.ts +25 -0
  35. package/build/math/vertex.d.ts.map +1 -1
  36. package/build/physics/broadphase/aabb3d.d.ts +23 -2
  37. package/build/physics/broadphase/aabb3d.d.ts.map +1 -1
  38. package/build/renderable/animation.d.ts +41 -0
  39. package/build/renderable/animation.d.ts.map +1 -0
  40. package/build/renderable/container.d.ts +0 -1
  41. package/build/renderable/container.d.ts.map +1 -1
  42. package/build/renderable/frameAnimation.d.ts +154 -0
  43. package/build/renderable/frameAnimation.d.ts.map +1 -0
  44. package/build/renderable/mesh.d.ts +151 -6
  45. package/build/renderable/mesh.d.ts.map +1 -1
  46. package/build/renderable/renderable.d.ts +22 -0
  47. package/build/renderable/renderable.d.ts.map +1 -1
  48. package/build/renderable/sprite.d.ts +74 -28
  49. package/build/renderable/sprite.d.ts.map +1 -1
  50. package/build/renderable/sprite3d.d.ts +314 -0
  51. package/build/renderable/sprite3d.d.ts.map +1 -0
  52. package/build/state/stage.d.ts +20 -1
  53. package/build/state/stage.d.ts.map +1 -1
  54. package/build/video/buffer/vertex.d.ts +7 -0
  55. package/build/video/buffer/vertex.d.ts.map +1 -1
  56. package/build/video/renderer.d.ts +21 -0
  57. package/build/video/renderer.d.ts.map +1 -1
  58. package/build/video/texture/atlas.d.ts +1 -1
  59. package/build/video/webgl/batchers/lit_mesh_batcher.d.ts +18 -0
  60. package/build/video/webgl/batchers/lit_mesh_batcher.d.ts.map +1 -0
  61. package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
  62. package/build/video/webgl/batchers/mesh_batcher.d.ts +52 -11
  63. package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
  64. package/build/video/webgl/effects/shine.d.ts +1 -1
  65. package/build/video/webgl/lighting/pack3d.d.ts +32 -0
  66. package/build/video/webgl/lighting/pack3d.d.ts.map +1 -0
  67. package/build/video/webgl/webgl_renderer.d.ts +18 -0
  68. package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
  69. package/package.json +1 -1
  70. package/build/renderable/light2d.d.ts.map +0 -1
@@ -0,0 +1,173 @@
1
+ /**
2
+ * @classdesc
3
+ * A rig-driven 3D model loaded from an animated glTF/GLB asset. Unlike a static
4
+ * {@link GLTFScene} (which flattens each node into an independent {@link Mesh}),
5
+ * a `GLTFModel` keeps the node **hierarchy** intact so a parent transform
6
+ * carries its children — e.g. rotating a character's `torso` moves the attached
7
+ * `arm` and `head`. Each frame, the active animation clip is sampled, world
8
+ * matrices are propagated down the tree, and every part mesh's placement is
9
+ * re-derived.
10
+ *
11
+ * The animation API mirrors {@link Sprite} for familiarity — `setCurrentAnimation`,
12
+ * `isCurrentAnimation`, `getAnimationNames`, `play`/`pause`, `animationpause` —
13
+ * but uses the cleaner options form everywhere: `setCurrentAnimation(name, {
14
+ * loop, speed, onComplete, next })`. Here `animationspeed` is a **playback
15
+ * multiplier** (1 = authored speed), not a per-frame delay.
16
+ *
17
+ * Instances are created automatically by {@link GLTFScene} when the asset
18
+ * defines animation channels; you usually obtain one via `level.load(...)`
19
+ * rather than constructing it directly.
20
+ * @augments Container
21
+ */
22
+ export default class GLTFModel extends Container {
23
+ /**
24
+ * @param {object} data - the parsed glTF descriptor (`{ graph, animations, bounds, ... }`)
25
+ * @param {object} [options]
26
+ * @param {number} [options.scale=1] - pixels per glTF unit (uniform scene scale)
27
+ * @param {boolean} [options.rightHanded=true] - glTF Y-up → engine Y-down via a rotation (no mirror)
28
+ * @param {boolean} [options.lit=false] - render the part meshes through the lit batcher
29
+ */
30
+ constructor(data: object, options?: {
31
+ scale?: number | undefined;
32
+ rightHanded?: boolean | undefined;
33
+ lit?: boolean | undefined;
34
+ });
35
+ _zSign: number;
36
+ /** the node hierarchy keyed by glTF node index @ignore */
37
+ _nodes: any;
38
+ /** root node indices @ignore */
39
+ _roots: any;
40
+ /** glTF node index → its part Mesh instances (one per primitive) @ignore */
41
+ _meshByNode: {};
42
+ /** glTF node index → cached rest (bind-pose) local matrix @ignore */
43
+ _restMatrix: {};
44
+ /**
45
+ * glTF node index → its world matrix, a persistent 16-element buffer
46
+ * recomputed in place every pose (a child reads its parent's buffer
47
+ * during the DFS, so each node needs its own). Preallocated here so the
48
+ * per-frame pose path allocates nothing.
49
+ * @ignore
50
+ */
51
+ _world: {};
52
+ /** name → clip `{ name, duration, channelsByNode, animatedNodes }` @ignore */
53
+ anim: {};
54
+ /**
55
+ * playback multiplier for the current animation (1 = authored speed).
56
+ * @type {number}
57
+ * @default 1
58
+ */
59
+ animationspeed: number;
60
+ /**
61
+ * pause/resume the current animation without losing its pose or time.
62
+ * @type {boolean}
63
+ * @default false
64
+ */
65
+ animationpause: boolean;
66
+ /**
67
+ * a callback fired each time the current animation completes a cycle.
68
+ * @type {Function}
69
+ * @default undefined
70
+ */
71
+ /** @ignore */
72
+ current: {
73
+ name: undefined;
74
+ time: number;
75
+ length: number;
76
+ };
77
+ /** loop-completion callback (built from the options) @ignore */
78
+ resetAnim: (() => unknown) | (() => void) | (() => boolean) | (() => void) | undefined;
79
+ /** set when a `loop:false` clip has finished its single cycle @ignore */
80
+ _animDone: boolean;
81
+ /**
82
+ * the names of every animation clip defined by the source asset.
83
+ * @returns {string[]}
84
+ * @example
85
+ * model.getAnimationNames(); // ["idle", "walk", "sprint", ...]
86
+ */
87
+ getAnimationNames(): string[];
88
+ /**
89
+ * return true if `name` is the currently playing animation.
90
+ * @param {string} name - animation clip id
91
+ * @returns {boolean}
92
+ */
93
+ isCurrentAnimation(name: string): boolean;
94
+ /**
95
+ * play the given animation clip. The second argument mirrors {@link Sprite}
96
+ * and accepts the same forms: omit to loop forever, a `string` to chain to
97
+ * another clip when this one ends, a `function` legacy completion callback
98
+ * (return `false` to hold the final pose), or an options object.
99
+ * @param {string} name - animation clip id (see {@link GLTFModel#getAnimationNames})
100
+ * @param {string|Function|AnimationOptions} [options] - loop / chain / completion behavior
101
+ * @param {boolean} [preserveTime=false] - keep the current playback time instead of restarting at 0
102
+ * @returns {GLTFModel} this, for chaining
103
+ * @example
104
+ * model.setCurrentAnimation("walk"); // loop forever
105
+ * model.setCurrentAnimation("die", { loop: false }); // play once, hold last pose
106
+ * model.setCurrentAnimation("jump", { next: "idle" }); // jump, then idle
107
+ * model.setCurrentAnimation("walk", { speed: 2 }); // twice as fast
108
+ * model.setCurrentAnimation("emote-yes", () => spawnFx()); // legacy callback
109
+ */
110
+ setCurrentAnimation(name: string, options?: string | Function | AnimationOptions, preserveTime?: boolean): GLTFModel;
111
+ /**
112
+ * Play an animation clip, or resume the current one. A shorthand for
113
+ * {@link GLTFModel#setCurrentAnimation}: call with a clip name to switch to
114
+ * (and start) it, or with no argument to resume after {@link GLTFModel#pause}.
115
+ * Always clears the paused state.
116
+ * @param {string} [name] - clip id to play; omit to just resume
117
+ * @param {string|Function|AnimationOptions} [options] - loop / chain / completion behavior (see {@link GLTFModel#setCurrentAnimation})
118
+ * @returns {GLTFModel} this, for chaining
119
+ * @example
120
+ * model.play("walk"); // switch to + play "walk"
121
+ * model.play("die", { loop: false }); // play once, hold the last pose
122
+ * model.pause();
123
+ * model.play(); // resume
124
+ */
125
+ play(name?: string, options?: string | Function | AnimationOptions): GLTFModel;
126
+ /**
127
+ * Pause the current animation, freezing it at its current pose. Resume with
128
+ * {@link GLTFModel#play}.
129
+ * @returns {GLTFModel} this, for chaining
130
+ */
131
+ pause(): GLTFModel;
132
+ /**
133
+ * Stop playback and reset the rig to its bind/rest pose (no clip active).
134
+ * After this {@link GLTFModel#isCurrentAnimation} is false for every clip;
135
+ * call {@link GLTFModel#play} to start again. (Use {@link GLTFModel#pause}
136
+ * instead to freeze in place.)
137
+ * @returns {GLTFModel} this, for chaining
138
+ */
139
+ stop(): GLTFModel;
140
+ /**
141
+ * Sample the active clip (if any) and propagate world transforms down the
142
+ * node tree, writing each part mesh's placement. Nodes the current clip does
143
+ * not animate use their cached rest matrix.
144
+ * @ignore
145
+ */
146
+ _pose(): void;
147
+ /**
148
+ * DFS one node: compose its local matrix, multiply by the parent world,
149
+ * apply to its meshes, recurse into children.
150
+ * @ignore
151
+ */
152
+ _visit(idx: any, parentWorld: any, clip: any, t: any): void;
153
+ /**
154
+ * The node's local matrix: sampled TRS when the active clip animates it
155
+ * (starting from the rest pose, overriding only the animated components),
156
+ * otherwise the cached rest matrix.
157
+ * @returns {number[]} 16-element column-major matrix
158
+ * @ignore
159
+ */
160
+ _localMatrix(idx: any, clip: any, t: any): number[];
161
+ /**
162
+ * Split a node's world matrix into the renderable placement a {@link Mesh}'s
163
+ * Camera3d path expects: the translation (scaled, Y/Z-bridged) becomes
164
+ * `pos`/`depth`, the rotation+scale becomes `currentTransform` (translation
165
+ * zeroed). Mirrors the static {@link GLTFScene} center-split, recomputed per
166
+ * frame.
167
+ * @ignore
168
+ */
169
+ _applyWorldToMesh(mesh: any, world: any): void;
170
+ }
171
+ import Container from "../../renderable/container.js";
172
+ import type { AnimationOptions } from "../../renderable/animation.ts";
173
+ //# sourceMappingURL=GLTFModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GLTFModel.d.ts","sourceRoot":"","sources":["../../../src/level/gltf/GLTFModel.js"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;IACC;;;;;;OAMG;IACH,kBANW,MAAM,YAEd;QAAyB,KAAK;QACJ,WAAW;QACX,GAAG;KAC/B,EAkKA;IAtJA,eAAoD;IAepD,0DAA0D;IAC1D,YAA8B;IAC9B,gCAAgC;IAChC,YAA8B;IAC9B,4EAA4E;IAC5E,gBAAqB;IACrB,qEAAqE;IACrE,gBAAqB;IACrB;;;;;;OAMG;IACH,WAAgB;IAsEhB,8EAA8E;IAC9E,SAAc;IAiBd;;;;OAIG;IACH,gBAHU,MAAM,CAGO;IAEvB;;;;OAIG;IACH,gBAHU,OAAO,CAGU;IAE3B;;;;OAIG;IAIH,cAAc;IACd;;;;MAAsD;IACtD,gEAAgE;IAChE,uFAA0B;IAC1B,yEAAyE;IACzE,mBAAsB;IAOvB;;;;;OAKG;IACH,qBAJa,MAAM,EAAE,CAMpB;IAED;;;;OAIG;IACH,yBAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;;;;;;;;;;;;OAeG;IACH,0BAXW,MAAM,YACN,MAAM,cAAU,gBAAgB,iBAChC,OAAO,GACL,SAAS,CAsDrB;IAED;;;;;;;;;;;;;OAaG;IACH,YATW,MAAM,YACN,MAAM,cAAU,gBAAgB,GAC9B,SAAS,CAarB;IAED;;;;OAIG;IACH,SAFa,SAAS,CAKrB;IAED;;;;;;OAMG;IACH,QAFa,SAAS,CAarB;IAyCD;;;;;OAKG;IACH,cAMC;IAED;;;;OAIG;IACH,4DAqBC;IAED;;;;;;OAMG;IACH,2CAHa,MAAM,EAAE,CAwCpB;IAED;;;;;;;OAOG;IACH,+CASC;CACD;sBA9eqB,+BAA+B;sCAMhB,+BAA+B"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @classdesc
3
+ * A loadable 3D scene parsed from a glTF / GLB asset. Instances are created
4
+ * and registered with the {@link level} director (usually automatically by
5
+ * the preloader), so a glTF scene loads with the same one-call ergonomics as
6
+ * a Tiled map: `level.load("myScene")`.
7
+ *
8
+ * Each glTF mesh node is instantiated as a {@link Mesh} carrying its own
9
+ * world transform, so the scene's relative scale and layout are preserved.
10
+ * View the result under a `Camera3d` for a coherent perspective.
11
+ */
12
+ export default class GLTFScene {
13
+ /**
14
+ * @param {string} levelId - the glTF/GLB asset name (as preloaded)
15
+ */
16
+ constructor(levelId: string);
17
+ /**
18
+ * the level/asset name
19
+ * @type {string}
20
+ */
21
+ name: string;
22
+ /**
23
+ * level format discriminator used by the level director's dispatch
24
+ * @type {string}
25
+ */
26
+ format: string;
27
+ /**
28
+ * the parsed scene descriptor (`{ nodes, cameras, lights, bounds }`)
29
+ * @type {object}
30
+ */
31
+ data: object;
32
+ /**
33
+ * the world-space bounds of the scene (`{ min, max }` in glTF units), or
34
+ * undefined if the scene failed to load. Handy for framing a `Camera3d`.
35
+ * @returns {object|undefined}
36
+ */
37
+ get bounds(): object | undefined;
38
+ /**
39
+ * the cameras parsed from the glTF scene (each with a world matrix +
40
+ * perspective parameters), or an empty array.
41
+ * @returns {Array}
42
+ */
43
+ get cameras(): any[];
44
+ /**
45
+ * Instantiate every glTF mesh node as a `Mesh` in the given container.
46
+ * Called by the level director on `level.load(...)`.
47
+ * @param {Container} container - the target container (e.g. `game.world`)
48
+ * @param {object} [options]
49
+ * @param {number} [options.scale=1] - pixels per glTF unit (uniform scene scale)
50
+ * @param {boolean} [options.rightHanded=true] - convert glTF Y-up right-handed
51
+ * geometry to the engine's Y-down via a rotation (no mirror). See the wiki.
52
+ * @param {boolean} [options.lights=true] - add the scene's authored
53
+ * `KHR_lights_punctual` directional lights (plus a soft ambient fill) to the
54
+ * world as {@link Light3d} renderables, so the meshes are lit by the sun set
55
+ * up in the authoring tool. Set false to keep the meshes unlit / manage
56
+ * lighting yourself with `world.addChild(new Light3d(...))`.
57
+ */
58
+ addTo(container: Container, options?: {
59
+ scale?: number | undefined;
60
+ rightHanded?: boolean | undefined;
61
+ lights?: boolean | undefined;
62
+ }): void;
63
+ /**
64
+ * Add the scene's authored directional lights (plus a soft ambient fill) to
65
+ * the world as {@link Light3d} renderables, so the meshes are lit by the
66
+ * same sun set up in the authoring tool (Blender etc.). Shared by the static
67
+ * and animated paths. The lights are ordinary world children — the level
68
+ * director's `container.reset()` removes them on the next load, exactly like
69
+ * {@link Light2d}, so there's nothing to track or tear down here.
70
+ * @param {Container} container - the target container the lights are added to
71
+ * @param {number} zSign - the Y-up→Y-down Z bridge sign (rightHanded → -1)
72
+ * @param {object} options - the `addTo` options (`lights` toggle)
73
+ * @ignore
74
+ */
75
+ _addLights(container: Container, zSign: number, options: object): void;
76
+ /**
77
+ * Director cleanup hook (parity with `TMXTileMap.destroy`). Nothing to do —
78
+ * the meshes and lights are ordinary world children, removed by the
79
+ * director's `container.reset()` on the next load.
80
+ * @ignore
81
+ */
82
+ destroy(): void;
83
+ }
84
+ //# sourceMappingURL=GLTFScene.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GLTFScene.d.ts","sourceRoot":"","sources":["../../../src/level/gltf/GLTFScene.js"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH;IACC;;OAEG;IACH,qBAFW,MAAM,EAkBhB;IAfA;;;OAGG;IACH,MAFU,MAAM,CAEG;IACnB;;;OAGG;IACH,QAFU,MAAM,CAEI;IACpB;;;OAGG;IACH,MAFU,MAAM,CAEY;IAG7B;;;;OAIG;IACH,cAFa,MAAM,GAAC,SAAS,CAI5B;IAED;;;;OAIG;IACH,qBAEC;IAED;;;;;;;;;;;;;OAaG;IACH,iBAXW,SAAS,YAEjB;QAAyB,KAAK;QACJ,WAAW;QAEX,MAAM;KAKlC,QA4HA;IAED;;;;;;;;;;;OAWG;IACH,sBALW,SAAS,SACT,MAAM,WACN,MAAM,QAsChB;IAED;;;;;OAKG;IACH,gBAAY;CACZ"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Locate the keyframe interval for time `t` in the (ascending) `times` array.
3
+ * Clamps to the endpoints — glTF animations do not extrapolate beyond their
4
+ * first/last keyframe. Returns the bracketing indices and the 0..1 blend factor.
5
+ *
6
+ * The returned object is **reused** across calls (read/copy its fields
7
+ * immediately; don't retain the reference).
8
+ * @param {ArrayLike<number>} times - keyframe times, ascending
9
+ * @param {number} t - sample time (same units as `times`, i.e. seconds)
10
+ * @returns {{ i0: number, i1: number, alpha: number }} reused result object
11
+ * @ignore
12
+ */
13
+ export function findKeyframe(times: ArrayLike<number>, t: number): {
14
+ i0: number;
15
+ i1: number;
16
+ alpha: number;
17
+ };
18
+ /**
19
+ * Spherical-linear interpolation between two quaternions stored in `values` at
20
+ * component offsets `o0` and `o1`. Picks the shortest arc (sign-flips the second
21
+ * quaternion when the dot is negative) and falls back to normalized-lerp for
22
+ * nearly-parallel inputs (where `sin(theta)` underflows). Result is normalized.
23
+ * @param {ArrayLike<number>} values - flat quaternion buffer (xyzw per key)
24
+ * @param {number} o0 - offset of the first quaternion
25
+ * @param {number} o1 - offset of the second quaternion
26
+ * @param {number} t - blend factor 0..1
27
+ * @param {number[]} out - 4-element [x,y,z,w] result
28
+ * @ignore
29
+ */
30
+ export function slerpQuat(values: ArrayLike<number>, o0: number, o1: number, t: number, out: number[]): number[];
31
+ /**
32
+ * Sample one animation channel at time `t`, writing `channel.stride` components
33
+ * into `out`. Rotation channels (stride 4) use {@link slerpQuat}; translation /
34
+ * scale (stride 3) use component-wise linear interpolation. `STEP` holds the
35
+ * lower keyframe; `CUBICSPLINE` uses the keyframe value (its tangents are
36
+ * ignored — a deliberate Tier-1 approximation, not full spline evaluation).
37
+ * @param {{times: ArrayLike<number>, values: ArrayLike<number>, stride: number, interpolation: string}} channel
38
+ * @param {number} t - sample time in seconds
39
+ * @param {number[]} out - destination, at least `channel.stride` long
40
+ * @returns {number[]} `out`
41
+ * @ignore
42
+ */
43
+ export function sampleChannel(channel: {
44
+ times: ArrayLike<number>;
45
+ values: ArrayLike<number>;
46
+ stride: number;
47
+ interpolation: string;
48
+ }, t: number, out: number[]): number[];
49
+ //# sourceMappingURL=gltf_sampler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gltf_sampler.d.ts","sourceRoot":"","sources":["../../../src/level/gltf/gltf_sampler.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;GAWG;AACH,oCALW,SAAS,CAAC,MAAM,CAAC,KACjB,MAAM,GACJ;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAkCrD;AAED;;;;;;;;;;;GAWG;AACH,kCAPW,SAAS,CAAC,MAAM,CAAC,MACjB,MAAM,MACN,MAAM,KACN,MAAM,OACN,MAAM,EAAE,YA+ClB;AAED;;;;;;;;;;;GAWG;AACH,uCANW;IAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAC,KAC5F,MAAM,OACN,MAAM,EAAE,GACN,MAAM,EAAE,CAwBpB"}
@@ -4,7 +4,7 @@ export namespace level {
4
4
  * @name add
5
5
  * @memberof level
6
6
  * @public
7
- * @param {string} format - level format (only "tmx" supported)
7
+ * @param {string} format - level format ("tmx" for Tiled maps, "gltf" / "glb" for 3D scenes)
8
8
  * @param {string} levelId - the level id (or name)
9
9
  * @param {Function} [callback] - a function to be called once the level is loaded
10
10
  * @returns {boolean} true if the level was loaded
@@ -20,8 +20,10 @@ export namespace level {
20
20
  * @param {object} [options] - additional optional parameters
21
21
  * @param {Container} [options.container=game.world] - container in which to load the specified level
22
22
  * @param {Function} [options.onLoaded=game.onLevelLoaded] - callback for when the level is fully loaded
23
- * @param {boolean} [options.flatten=game.mergeGroup] - if true, flatten all objects into the given container
24
- * @param {boolean} [options.setViewportBounds=true] - if true, set the viewport bounds to the map size
23
+ * @param {boolean} [options.flatten=game.mergeGroup] - (TMX only) if true, flatten all objects into the given container
24
+ * @param {boolean} [options.setViewportBounds=true] - (TMX only) if true, set the viewport bounds to the map size
25
+ * @param {number} [options.scale=1] - (glTF/GLB only) pixels per glTF unit applied to the whole scene
26
+ * @param {boolean} [options.rightHanded=true] - (glTF/GLB only) convert the right-handed (Y-up) source to the engine's Y-down via a rotation rather than a mirror
25
27
  * @returns {boolean} true if the level was successfully loaded
26
28
  * @example
27
29
  * // the game assets to be be preloaded
@@ -54,6 +56,8 @@ export namespace level {
54
56
  onLoaded?: Function | undefined;
55
57
  flatten?: boolean | undefined;
56
58
  setViewportBounds?: boolean | undefined;
59
+ scale?: number | undefined;
60
+ rightHanded?: boolean | undefined;
57
61
  }): boolean;
58
62
  /**
59
63
  * return the current level id<br>
@@ -1 +1 @@
1
- {"version":3,"file":"level.d.ts","sourceRoot":"","sources":["../../src/level/level.js"],"names":[],"mappings":";IAkFC;;;;;;;;;OASG;IACH,qBALW,MAAM,WACN,MAAM,wBAEJ,OAAO,CAuBnB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,uBAjCW,MAAM,YAEd;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;QACP,iBAAiB;KAC3C,GAAU,OAAO,CA8DnB;IAED;;;;;;OAMG;IACH,8BAFa,MAAM,CAIlB;IAED;;;;;;;;OAQG;IACH,4BAFa,UAAU,CAItB;IAED;;;;;;;;;;OAUG;IACH,0BALG;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;KACjC,GAAU,MAAM,CAMlB;IAED;;;;;;;;;;OAUG;IACH,wBALG;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;KACjC,GAAU,OAAO,CASnB;IAED;;;;;;;;;;OAUG;IACH,4BALG;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;KACjC,GAAU,OAAO,CASnB;IAED;;;;;;OAMG;IACH,uBAFa,MAAM,CAIlB;;uBApRqB,uBAAuB"}
1
+ {"version":3,"file":"level.d.ts","sourceRoot":"","sources":["../../src/level/level.js"],"names":[],"mappings":";IA4FC;;;;;;;;;OASG;IACH,qBALW,MAAM,WACN,MAAM,wBAEJ,OAAO,CAkCnB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,uBAnCW,MAAM,YAEd;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;QACP,iBAAiB;QAClB,KAAK;QACJ,WAAW;KACrC,GAAU,OAAO,CA0DnB;IAED;;;;;;OAMG;IACH,8BAFa,MAAM,CAIlB;IAED;;;;;;;;OAQG;IACH,4BAFa,UAAU,CAItB;IAED;;;;;;;;;;OAUG;IACH,0BALG;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;KACjC,GAAU,MAAM,CAMlB;IAED;;;;;;;;;;OAUG;IACH,wBALG;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;KACjC,GAAU,OAAO,CASnB;IAED;;;;;;;;;;OAUG;IACH,4BALG;QAA4B,SAAS;QACV,QAAQ;QACT,OAAO;KACjC,GAAU,OAAO,CASnB;IAED;;;;;;OAMG;IACH,uBAFa,MAAM,CAIlB;;uBAtSqB,uBAAuB"}
@@ -24,6 +24,11 @@ export default class TMXTileMap {
24
24
  * @type {string}
25
25
  */
26
26
  name: string;
27
+ /**
28
+ * level format discriminator used by the level director's dispatch
29
+ * @type {string}
30
+ */
31
+ format: string;
27
32
  /**
28
33
  * width of the tilemap in tiles
29
34
  * @type {number}
@@ -1 +1 @@
1
- {"version":3,"file":"TMXTileMap.d.ts","sourceRoot":"","sources":["../../../src/level/tiled/TMXTileMap.js"],"names":[],"mappings":"AAsIA;;;;GAIG;AACH;IACC;;;;;;;;OAQG;IACH,qBARW,MAAM,QACN,MAAM,EA0JhB;IAlJA;;;OAGG;IACH,aAAgB;IAEhB;;;OAGG;IACH,MAFU,MAAM,CAEG;IAEnB;;;OAGG;IACH,MAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,MAFU,MAAM,CAEQ;IAExB;;;OAGG;IACH,WAFU,MAAM,CAEgB;IAEhC;;;OAGG;IACH,YAFU,MAAM,CAEkB;IAElC;;;;OAIG;IACH,UAHU,MAAM,CAGmB;IAEnC;;;;OAIG;IACH,aAHU,MAAM,CAGmB;IAEnC;;;;OAIG;IACH,OAHU,MAAM,CAGe;IAE/B;;;;OAIG;IACH,OAHU,MAAM,CAGe;IAE/B;;;;;OAKG;IACH,aAHU,MAAM,CAGmC;IAEnD;;;OAGG;IACH,SAFU,MAAM,CAEgB;IAEhC;;;OAGG;IACH,cAFU,MAAM,CAE0B;IAE1C;;;OAGG;IACH,OAFU,MAAM,CAEO;IAGvB,6CAAoB;IAInB,cAAgB;IAIhB,oBAAsB;IAIvB,kBAA8C;IAG9C,iCAAmD;IAGnD,sBAAwC;IACxC,iBAAmC;IACnC,kBAAqC;IAGrC,YAAoD;IAGpD,WAA8B;IAC9B,YAAgC;IAGhC,qBAA2C;IAwB3C,qBAAwB;IAGzB;;;OAGG;IACH,eAFa,WAAW,CAUvB;IAHC,+OAAuC;IAKzC;;;OAGG;IACH,aAFa,MAAM,CAKlB;IAED;;;OAGG;IACH,gCA2DC;IAED;;;;;;;;;;;OAWG;IACH,iBATW,SAAS,YACT,OAAO,sBACP,OAAO,QA+EjB;IAED;;;;;;;;;OASG;IACH,qBAJW,OAAO,GAEL,UAAU,EAAE,CA4GxB;IAED;;;OAGG;IACH,aAFa,QAAQ,EAAE,CAMtB;IAED;;OAEG;IACH,gBAKC;CACD;4BAplB2B,sBAAsB;sBAV5B,+BAA+B;qBAOhC,eAAe"}
1
+ {"version":3,"file":"TMXTileMap.d.ts","sourceRoot":"","sources":["../../../src/level/tiled/TMXTileMap.js"],"names":[],"mappings":"AAsIA;;;;GAIG;AACH;IACC;;;;;;;;OAQG;IACH,qBARW,MAAM,QACN,MAAM,EAgKhB;IAxJA;;;OAGG;IACH,aAAgB;IAEhB;;;OAGG;IACH,MAFU,MAAM,CAEG;IAEnB;;;OAGG;IACH,QAFU,MAAM,CAEG;IAEnB;;;OAGG;IACH,MAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,MAFU,MAAM,CAEQ;IAExB;;;OAGG;IACH,WAFU,MAAM,CAEgB;IAEhC;;;OAGG;IACH,YAFU,MAAM,CAEkB;IAElC;;;;OAIG;IACH,UAHU,MAAM,CAGmB;IAEnC;;;;OAIG;IACH,aAHU,MAAM,CAGmB;IAEnC;;;;OAIG;IACH,OAHU,MAAM,CAGe;IAE/B;;;;OAIG;IACH,OAHU,MAAM,CAGe;IAE/B;;;;;OAKG;IACH,aAHU,MAAM,CAGmC;IAEnD;;;OAGG;IACH,SAFU,MAAM,CAEgB;IAEhC;;;OAGG;IACH,cAFU,MAAM,CAE0B;IAE1C;;;OAGG;IACH,OAFU,MAAM,CAEO;IAGvB,6CAAoB;IAInB,cAAgB;IAIhB,oBAAsB;IAIvB,kBAA8C;IAG9C,iCAAmD;IAGnD,sBAAwC;IACxC,iBAAmC;IACnC,kBAAqC;IAGrC,YAAoD;IAGpD,WAA8B;IAC9B,YAAgC;IAGhC,qBAA2C;IAwB3C,qBAAwB;IAGzB;;;OAGG;IACH,eAFa,WAAW,CAUvB;IAHC,+OAAuC;IAKzC;;;OAGG;IACH,aAFa,MAAM,CAKlB;IAED;;;OAGG;IACH,gCA2DC;IAED;;;;;;;;;;;OAWG;IACH,iBATW,SAAS,YACT,OAAO,sBACP,OAAO,QA+EjB;IAED;;;;;;;;;OASG;IACH,qBAJW,OAAO,GAEL,UAAU,EAAE,CA4GxB;IAED;;;OAGG;IACH,aAFa,QAAQ,EAAE,CAMtB;IAED;;OAEG;IACH,gBAKC;CACD;4BA1lB2B,sBAAsB;sBAV5B,+BAA+B;qBAOhC,eAAe"}
@@ -1,9 +1,8 @@
1
- /**
2
- * additional import for TypeScript
3
- * @import {Color} from "./../math/color.ts";
4
- * @import {Ellipse} from "./../geometries/ellipse.ts";
5
- * @import Renderer from "./../video/renderer.js";
6
- */
1
+ import { Ellipse } from "../geometries/ellipse.ts";
2
+ import { Color } from "../math/color.ts";
3
+ import Renderable from "../renderable/renderable.js";
4
+ import type CanvasRenderer from "../video/canvas/canvas_renderer.js";
5
+ import type WebGLRenderer from "../video/webgl/webgl_renderer.js";
7
6
  /**
8
7
  * A 2D point light.
9
8
  *
@@ -23,9 +22,58 @@
23
22
  *
24
23
  * Light2d itself is renderer-agnostic — no shader knowledge, no canvas
25
24
  * allocation, no renderer reference held.
25
+ * @category Lighting
26
26
  * @see stage.lights
27
27
  */
28
28
  export default class Light2d extends Renderable {
29
+ /**
30
+ * the color of the light
31
+ * @default "#FFF"
32
+ */
33
+ color: Color;
34
+ /** The horizontal radius of the light */
35
+ radiusX: number;
36
+ /** The vertical radius of the light */
37
+ radiusY: number;
38
+ /**
39
+ * The intensity of the light
40
+ * @default 0.7
41
+ */
42
+ intensity: number;
43
+ /**
44
+ * the world-space geometry of the light's visible area, rewritten each
45
+ * frame by {@link Light2d#getVisibleArea} from transform-aware bounds.
46
+ * @ignore
47
+ */
48
+ visibleArea: Ellipse;
49
+ /**
50
+ * When `true`, this light acts as a pure illumination source — the
51
+ * gradient texture isn't drawn. The light still feeds the `Stage`
52
+ * ambient-cutout pass and the WebGL lit-sprite pipeline's per-frame
53
+ * uniforms, so normal-mapped sprites still get shaded by it. Use this for
54
+ * SpriteIlluminator-style demos where the light should be invisible (only
55
+ * its effect on normal-mapped surfaces is what you want to see).
56
+ *
57
+ * Default `false`, preserving the legacy "soft glowing spot" behavior.
58
+ * @default false
59
+ */
60
+ illuminationOnly: boolean;
61
+ /**
62
+ * Light height above the sprite plane (Z axis), in the same units as
63
+ * `radiusX`/`radiusY`. Used by the WebGL lit-sprite pipeline as the Z
64
+ * component of the light direction in the `dot(normal, lightDir)`
65
+ * calculation: a low height makes the lighting graze across the surface
66
+ * (long visible shadows on normal-map detail), a high height makes it
67
+ * head-on (more uniform brightness on the lit hemisphere).
68
+ *
69
+ * Default is `max(radiusX, radiusY) * 0.075` — a balanced look at the
70
+ * asset's native scale that prevents lights at the sprite's center from
71
+ * producing degenerate flat shading.
72
+ *
73
+ * Named `lightHeight` (not just `height`) to avoid colliding with the
74
+ * bbox-height getter Light2d inherits from `Rect`.
75
+ */
76
+ lightHeight: number;
29
77
  /**
30
78
  * Create a 2D point light.
31
79
  *
@@ -46,71 +94,28 @@ export default class Light2d extends Renderable {
46
94
  * inner alpha; the `Stage.ambientLight` color and alpha control how
47
95
  * dark the unlit areas are. Use `light.blendMode` to override the
48
96
  * default additive blend if needed.
49
- * @param {number} x - The horizontal position of the light's center (matches `Ellipse(x, y, w, h)` conventions).
50
- * @param {number} y - The vertical position of the light's center.
51
- * @param {number} radiusX - The horizontal radius of the light.
52
- * @param {number} [radiusY=radiusX] - The vertical radius of the light.
53
- * @param {Color|string} [color="#FFF"] - The color of the light at full intensity.
54
- * @param {number} [intensity=0.7] - The peak alpha of the radial gradient at the light's center (0–1).
97
+ * @param x - The horizontal position of the light's center (matches `Ellipse(x, y, w, h)` conventions).
98
+ * @param y - The vertical position of the light's center.
99
+ * @param radiusX - The horizontal radius of the light.
100
+ * @param [radiusY=radiusX] - The vertical radius of the light.
101
+ * @param [color="#FFF"] - The color of the light at full intensity.
102
+ * @param [intensity=0.7] - The peak alpha of the radial gradient at the light's center (0–1).
55
103
  */
56
104
  constructor(x: number, y: number, radiusX: number, radiusY?: number, color?: Color | string, intensity?: number);
57
105
  /**
58
- * the color of the light
59
- * @type {Color}
60
- * @default "#FFF"
106
+ * the horizontal coordinate of this light's center.
107
+ * Overrides Rect's getter, which assumes `pos` is the bbox top-left and
108
+ * returns `pos.x + width/2`. Light2d uses `anchorPoint = (0.5, 0.5)`, so
109
+ * `pos` already IS the center.
61
110
  */
62
- color: Color;
111
+ get centerX(): number;
112
+ set centerX(value: number);
63
113
  /**
64
- * The horizontal radius of the light
65
- * @type {number}
66
- */
67
- radiusX: number;
68
- /**
69
- * The vertical radius of the light
70
- * @type {number}
71
- */
72
- radiusY: number;
73
- /**
74
- * The intensity of the light
75
- * @type {number}
76
- * @default 0.7
114
+ * the vertical coordinate of this light's center.
115
+ * @see Light2d#centerX
77
116
  */
78
- intensity: number;
79
- /** @ignore */
80
- visibleArea: Ellipse;
81
- /**
82
- * When `true`, this light acts as a pure illumination source —
83
- * the gradient texture isn't drawn. The light still feeds the
84
- * `Stage` ambient-cutout pass and the WebGL lit-sprite
85
- * pipeline's per-frame uniforms, so normal-mapped sprites still
86
- * get shaded by it. Use this for SpriteIlluminator-style demos
87
- * where the light should be invisible (only its effect on
88
- * normal-mapped surfaces is what you want to see).
89
- *
90
- * Default `false`, preserving the legacy "soft glowing spot"
91
- * behavior.
92
- * @type {boolean}
93
- * @default false
94
- */
95
- illuminationOnly: boolean;
96
- /**
97
- * Light height above the sprite plane (Z axis), in the same
98
- * units as `radiusX`/`radiusY`. Used by the WebGL lit-sprite
99
- * pipeline as the Z component of the light direction in the
100
- * `dot(normal, lightDir)` calculation: a low height makes the
101
- * lighting graze across the surface (long visible shadows on
102
- * normal-map detail), a high height makes it head-on (more
103
- * uniform brightness on the lit hemisphere).
104
- *
105
- * Default is `max(radiusX, radiusY) * 0.075` — a balanced look
106
- * at the asset's native scale that prevents lights at the
107
- * sprite's center from producing degenerate flat shading.
108
- *
109
- * Named `lightHeight` (not just `height`) to avoid colliding
110
- * with the bbox-height getter Light2d inherits from `Rect`.
111
- * @type {number}
112
- */
113
- lightHeight: number;
117
+ get centerY(): number;
118
+ set centerY(value: number);
114
119
  /**
115
120
  * Set new radii for this light.
116
121
  *
@@ -125,27 +130,27 @@ export default class Light2d extends Renderable {
125
130
  * `Renderable.resize(width, height)` — code that operates on a
126
131
  * generic `Renderable` and calls `.resize(w, h)` keeps working when
127
132
  * the instance happens to be a `Light2d`.
128
- * @param {number} radiusX - new horizontal radius
129
- * @param {number} [radiusY=radiusX] - new vertical radius
133
+ * @param radiusX - new horizontal radius
134
+ * @param [radiusY=radiusX] - new vertical radius
130
135
  */
131
136
  setRadii(radiusX: number, radiusY?: number): void;
132
137
  /**
133
138
  * returns a geometry representing the visible area of this light, in
134
139
  * world-space coordinates (so it aligns with the rendered gradient
135
140
  * regardless of camera scroll or container parenting).
136
- * @returns {Ellipse} the light visible mask
141
+ * @returns the light visible mask
137
142
  */
138
143
  getVisibleArea(): Ellipse;
139
144
  /**
140
145
  * update function
141
- * @returns {boolean} true if dirty
146
+ * @returns true if dirty
142
147
  */
143
148
  update(): boolean;
144
149
  /**
145
150
  * preDraw this Light2d (automatically called by melonJS)
146
- * @param {Renderer} renderer - a renderer instance
151
+ * @param renderer - a renderer instance
147
152
  */
148
- preDraw(renderer: Renderer): void;
153
+ preDraw(renderer: CanvasRenderer | WebGLRenderer): void;
149
154
  /**
150
155
  * draw this Light2d (automatically called by melonJS).
151
156
  *
@@ -153,9 +158,9 @@ export default class Light2d extends Renderable {
153
158
  * own implementation (procedural shader on WebGL; cached `Gradient`
154
159
  * rasterized into a shared `CanvasRenderTarget` on Canvas). Light2d
155
160
  * itself doesn't know which path is used.
156
- * @param {Renderer} renderer - a renderer instance
161
+ * @param renderer - a renderer instance
157
162
  */
158
- draw(renderer: Renderer): void;
163
+ draw(renderer: CanvasRenderer | WebGLRenderer): void;
159
164
  /**
160
165
  * Auto-register this light with the active Stage's lighting set when
161
166
  * added to a container. The Stage uses that set to build the ambient
@@ -171,13 +176,9 @@ export default class Light2d extends Renderable {
171
176
  */
172
177
  onDeactivateEvent(): void;
173
178
  /**
174
- * Destroy function<br>
179
+ * Destroy function
175
180
  * @ignore
176
181
  */
177
182
  destroy(): void;
178
183
  }
179
- import Renderable from "./renderable.js";
180
- import type { Color } from "./../math/color.ts";
181
- import type { Ellipse } from "./../geometries/ellipse.ts";
182
- import type Renderer from "./../video/renderer.js";
183
184
  //# sourceMappingURL=light2d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light2d.d.ts","sourceRoot":"","sources":["../../src/lighting/light2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AACpD,OAAO,UAAU,MAAM,6BAA6B,CAAC;AAErD,OAAO,KAAK,cAAc,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,aAAa,MAAM,kCAAkC,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,UAAU;IAC9C;;;OAGG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAEhB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;;;;;;;;;OAUG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;;;;;;;;;;;;;OAcG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;gBAEF,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAAgB,EACzB,KAAK,GAAE,KAAK,GAAG,MAAe,EAC9B,SAAS,GAAE,MAAY;IAyCxB;;;;;OAKG;IACH,IAAa,OAAO,IAAI,MAAM,CAE7B;IACD,IAAa,OAAO,CAAC,KAAK,EAAE,MAAM,EAIjC;IAED;;;OAGG;IACH,IAAa,OAAO,IAAI,MAAM,CAE7B;IACD,IAAa,OAAO,CAAC,KAAK,EAAE,MAAM,EAIjC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAgB;IAMnD;;;;;OAKG;IACH,cAAc,IAAI,OAAO;IAOzB;;;OAGG;IACM,MAAM,IAAI,OAAO;IAI1B;;;OAGG;IACM,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa;IAKzD;;;;;;;;OAQG;IACM,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa;IAOtD;;;;;;OAMG;IACM,eAAe;IAIxB;;;;OAIG;IACM,iBAAiB;IAI1B;;;OAGG;IACM,OAAO;CAOhB"}