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.
- package/README.md +18 -6
- package/build/application/defaultApplicationSettings.d.ts +1 -0
- package/build/application/defaultApplicationSettings.d.ts.map +1 -1
- package/build/application/settings.d.ts +34 -0
- package/build/application/settings.d.ts.map +1 -1
- package/build/camera/camera3d.d.ts +49 -0
- package/build/camera/camera3d.d.ts.map +1 -1
- package/build/index.d.ts +7 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +17392 -14529
- package/build/index.js.map +4 -4
- package/build/level/gltf/GLTFModel.d.ts +173 -0
- package/build/level/gltf/GLTFModel.d.ts.map +1 -0
- package/build/level/gltf/GLTFScene.d.ts +84 -0
- package/build/level/gltf/GLTFScene.d.ts.map +1 -0
- package/build/level/gltf/gltf_sampler.d.ts +49 -0
- package/build/level/gltf/gltf_sampler.d.ts.map +1 -0
- package/build/level/level.d.ts +7 -3
- package/build/level/level.d.ts.map +1 -1
- package/build/level/tiled/TMXTileMap.d.ts +5 -0
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/{renderable → lighting}/light2d.d.ts +79 -78
- package/build/lighting/light2d.d.ts.map +1 -0
- package/build/lighting/light3d.d.ts +86 -0
- package/build/lighting/light3d.d.ts.map +1 -0
- package/build/loader/cache.d.ts +1 -0
- package/build/loader/cache.d.ts.map +1 -1
- package/build/loader/loader.d.ts +95 -5
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/parsers/gltf.d.ts +71 -0
- package/build/loader/parsers/gltf.d.ts.map +1 -0
- package/build/loader/parsers/mtl.d.ts.map +1 -1
- package/build/math/math.d.ts +2 -2
- package/build/math/vertex.d.ts +25 -0
- package/build/math/vertex.d.ts.map +1 -1
- package/build/physics/broadphase/aabb3d.d.ts +23 -2
- package/build/physics/broadphase/aabb3d.d.ts.map +1 -1
- package/build/renderable/animation.d.ts +41 -0
- package/build/renderable/animation.d.ts.map +1 -0
- package/build/renderable/container.d.ts +0 -1
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/frameAnimation.d.ts +154 -0
- package/build/renderable/frameAnimation.d.ts.map +1 -0
- package/build/renderable/mesh.d.ts +151 -6
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +22 -0
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +74 -28
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/sprite3d.d.ts +314 -0
- package/build/renderable/sprite3d.d.ts.map +1 -0
- package/build/state/stage.d.ts +20 -1
- package/build/state/stage.d.ts.map +1 -1
- package/build/video/buffer/vertex.d.ts +7 -0
- package/build/video/buffer/vertex.d.ts.map +1 -1
- package/build/video/renderer.d.ts +21 -0
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/texture/atlas.d.ts +1 -1
- package/build/video/webgl/batchers/lit_mesh_batcher.d.ts +18 -0
- package/build/video/webgl/batchers/lit_mesh_batcher.d.ts.map +1 -0
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts +52 -11
- package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/effects/shine.d.ts +1 -1
- package/build/video/webgl/lighting/pack3d.d.ts +32 -0
- package/build/video/webgl/lighting/pack3d.d.ts.map +1 -0
- package/build/video/webgl/webgl_renderer.d.ts +18 -0
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/build/renderable/light2d.d.ts.map +0 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* additional import for TypeScript
|
|
3
|
+
* @import { TextureAtlas } from "../video/texture/atlas.js";
|
|
4
|
+
* @import { Vector2d } from "../math/vector2d.js";
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The shared **frame-animation engine** behind {@link Sprite} (2D) and
|
|
8
|
+
* {@link Sprite3d} (3D billboards). It *owns* the animation state — definitions,
|
|
9
|
+
* the current frame, timing, looping and chaining — everything independent of
|
|
10
|
+
* how a frame is ultimately *drawn*, and drives its host renderable through a
|
|
11
|
+
* small contract:
|
|
12
|
+
*
|
|
13
|
+
* - it reads the host's resolved texture (`host.source`, `host.textureAtlas`,
|
|
14
|
+
* `host.atlasIndices`) to turn a frame index/name into a region;
|
|
15
|
+
* - it calls the `applyFrame(region)` callback passed to the constructor whenever
|
|
16
|
+
* the frame changes — the host applies it to its own geometry ({@link Sprite}
|
|
17
|
+
* swaps its source sub-texture, size and anchor; {@link Sprite3d} maps the
|
|
18
|
+
* region onto its quad's UVs + vertices) **and marks itself dirty there**;
|
|
19
|
+
* - it fires `host.onended()` at each cycle end.
|
|
20
|
+
*
|
|
21
|
+
* The engine owns no dirty flag: a frame change flows through `applyFrame`, where
|
|
22
|
+
* the host sets its own `isDirty`. Callers read dirtiness from the host (the
|
|
23
|
+
* host's `update()` returns `super.update()` → `isDirty`).
|
|
24
|
+
*
|
|
25
|
+
* Hosts expose the public-facing state (`anim`, `current`, `animationspeed`,
|
|
26
|
+
* `animationpause`, …) as thin accessors onto this engine, so 2D and 3D frame
|
|
27
|
+
* animation share one implementation with no behavioral fork.
|
|
28
|
+
* @category Animation
|
|
29
|
+
*/
|
|
30
|
+
export default class FrameAnimation {
|
|
31
|
+
/**
|
|
32
|
+
* @param {object} host - the renderable this engine drives. Read for the
|
|
33
|
+
* texture it animates (`source` / `textureAtlas` / `atlasIndices`) and the
|
|
34
|
+
* mutable cycle-end callback (`onended`). These are read lazily (the texture is
|
|
35
|
+
* usually resolved after the engine is constructed), which is why they live on
|
|
36
|
+
* the host rather than being passed in. The engine does not touch `isDirty` —
|
|
37
|
+
* the host marks itself dirty inside `applyFrame`.
|
|
38
|
+
* @param {(region: object) => void} applyFrame - called whenever the frame
|
|
39
|
+
* changes, with the selected texture region; the host applies it to its own
|
|
40
|
+
* geometry (a {@link Sprite} swaps its sub-texture / size / anchor, a
|
|
41
|
+
* {@link Sprite3d} remaps its quad's UVs + vertices).
|
|
42
|
+
*/
|
|
43
|
+
constructor(host: object, applyFrame: (region: object) => void);
|
|
44
|
+
/**
|
|
45
|
+
* the host renderable this engine draws through.
|
|
46
|
+
* @type {object}
|
|
47
|
+
* @ignore
|
|
48
|
+
*/
|
|
49
|
+
host: object;
|
|
50
|
+
/**
|
|
51
|
+
* geometry hook invoked on every frame change (see constructor).
|
|
52
|
+
* @type {(region: object) => void}
|
|
53
|
+
* @ignore
|
|
54
|
+
*/
|
|
55
|
+
_applyFrame: (region: object) => void;
|
|
56
|
+
/** defined animations, keyed by id @type {object} */
|
|
57
|
+
anim: object;
|
|
58
|
+
/** animation to chain to / completion callback on cycle end @ignore */
|
|
59
|
+
resetAnim: (() => unknown) | (() => void) | (() => boolean) | (() => void) | undefined;
|
|
60
|
+
/** current frame info @type {object} */
|
|
61
|
+
current: object;
|
|
62
|
+
/** elapsed time within the current frame, in ms @type {number} */
|
|
63
|
+
dt: number;
|
|
64
|
+
/** default frame cycling speed (ms between frames) @type {number} */
|
|
65
|
+
animationspeed: number;
|
|
66
|
+
/** pause flag — freezes the current frame @type {boolean} */
|
|
67
|
+
animationpause: boolean;
|
|
68
|
+
/** per-play speed multiplier (1 = authored speed) @ignore */
|
|
69
|
+
_animSpeed: number;
|
|
70
|
+
/** set once a `loop:false` animation has finished its single cycle @ignore */
|
|
71
|
+
_animDone: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* add an animation definition (see {@link Sprite#addAnimation}).
|
|
74
|
+
* @param {string} name - animation id
|
|
75
|
+
* @param {number[]|string[]|object[]} index - frame indices / names / objects
|
|
76
|
+
* @param {number} [animationspeed] - cycling speed in ms
|
|
77
|
+
* @returns {number} number of frames added (0 if no texture atlas)
|
|
78
|
+
*/
|
|
79
|
+
addAnimation(name: string, index: number[] | string[] | object[], animationspeed?: number): number;
|
|
80
|
+
/**
|
|
81
|
+
* select the active animation (see {@link Sprite#setCurrentAnimation}).
|
|
82
|
+
* @param {string} name - animation id
|
|
83
|
+
* @param {string|Function|object} [resetAnim] - loop / chain / completion behavior
|
|
84
|
+
* @param {boolean} [preserve_dt=false] - keep the elapsed-frame timer
|
|
85
|
+
* @returns {object} the host (for method chaining)
|
|
86
|
+
*/
|
|
87
|
+
setCurrentAnimation(name: string, resetAnim?: string | Function | object, preserve_dt?: boolean): object;
|
|
88
|
+
/**
|
|
89
|
+
* reverse the given (or current) animation in place (see {@link Sprite#reverseAnimation}).
|
|
90
|
+
* The host marks itself dirty (this path doesn't re-apply a frame, so it's the
|
|
91
|
+
* one place a host's `reverseAnimation` wrapper sets `isDirty`).
|
|
92
|
+
* @param {string} [name] - animation id
|
|
93
|
+
*/
|
|
94
|
+
reverseAnimation(name?: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* @param {string} name - animation id
|
|
97
|
+
* @returns {boolean} true if `name` is the current animation
|
|
98
|
+
*/
|
|
99
|
+
isCurrentAnimation(name: string): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* @returns {string[]} the names of every defined animation
|
|
102
|
+
*/
|
|
103
|
+
getAnimationNames(): string[];
|
|
104
|
+
/**
|
|
105
|
+
* apply a texture region as the current frame: store its geometry into
|
|
106
|
+
* `current` and hand it to the host to draw (see {@link Sprite#setRegion}).
|
|
107
|
+
* @param {object} region - the texture region object
|
|
108
|
+
* @returns {object} the host (for method chaining)
|
|
109
|
+
*/
|
|
110
|
+
setRegion(region: object): object;
|
|
111
|
+
/**
|
|
112
|
+
* force the current animation frame index (see {@link Sprite#setAnimationFrame}).
|
|
113
|
+
* @param {number} [index=0] - animation frame index
|
|
114
|
+
* @returns {object} the host (for method chaining)
|
|
115
|
+
*/
|
|
116
|
+
setAnimationFrame(index?: number): object;
|
|
117
|
+
/**
|
|
118
|
+
* @returns {number} the current animation frame index
|
|
119
|
+
*/
|
|
120
|
+
getCurrentAnimationFrame(): number;
|
|
121
|
+
/**
|
|
122
|
+
* the frame object for the given index within the current animation.
|
|
123
|
+
* @param {number} id - the frame id
|
|
124
|
+
* @returns {object} the frame data
|
|
125
|
+
*/
|
|
126
|
+
getAnimationFrameObjectByIndex(id: number): object;
|
|
127
|
+
/**
|
|
128
|
+
* clear the frame timer and the play-once "done" hold, without changing the
|
|
129
|
+
* current frame (the timer half of a stop, used by the video path which has
|
|
130
|
+
* no frame to rewind to).
|
|
131
|
+
*/
|
|
132
|
+
resetTimer(): void;
|
|
133
|
+
/**
|
|
134
|
+
* reset the current animation to its first frame (the frame-animation half of
|
|
135
|
+
* {@link Sprite#stop} — the host still handles any video / pause concerns).
|
|
136
|
+
*/
|
|
137
|
+
rewind(): void;
|
|
138
|
+
/**
|
|
139
|
+
* advance the frame animation by `dt` milliseconds, stepping frames, looping
|
|
140
|
+
* and chaining as configured (see {@link Sprite#update}). On a frame change the
|
|
141
|
+
* host marks itself dirty via `_applyFrame` (the engine owns no dirty flag);
|
|
142
|
+
* this returns whether a frame actually changed this tick — a finer-grained
|
|
143
|
+
* signal than the host's `isDirty` (which means "needs redraw for any reason").
|
|
144
|
+
* @param {number} dt - elapsed time since the last update, in milliseconds
|
|
145
|
+
* @returns {boolean} true if a frame changed this tick
|
|
146
|
+
*/
|
|
147
|
+
update(dt: number): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* release engine-held resources — returns the pooled `current.offset`
|
|
150
|
+
* Vector2d to the pool. Call from the host's `destroy()`.
|
|
151
|
+
*/
|
|
152
|
+
destroy(): void;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=frameAnimation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameAnimation.d.ts","sourceRoot":"","sources":["../../src/renderable/frameAnimation.js"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IACC;;;;;;;;;;;OAWG;IACH,kBAXW,MAAM,cAMN,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EA2DlC;IArDA;;;;OAIG;IACH,MAHU,MAAM,CAGA;IAEhB;;;;OAIG;IACH,aAHU,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAGL;IAE7B,qDAAqD;IACrD,MAD2C,MAAM,CACnC;IAEd,uEAAuE;IACvE,uFAA0B;IAE1B,wCAAwC;IACxC,SAD8B,MAAM,CAiBnC;IAED,kEAAkE;IAClE,IADwD,MAAM,CACnD;IAEX,qEAAqE;IACrE,gBAD2D,MAAM,CACxC;IAEzB,6DAA6D;IAC7D,gBADkD,OAAO,CAC9B;IAE3B,6DAA6D;IAC7D,mBAAmB;IAEnB,8EAA8E;IAC9E,mBAAsB;IAGvB;;;;;;OAMG;IACH,mBALW,MAAM,SACN,MAAM,EAAE,GAAC,MAAM,EAAE,GAAC,MAAM,EAAE,mBAC1B,MAAM,GACJ,MAAM,CAoElB;IAED;;;;;;OAMG;IACH,0BALW,MAAM,cACN,MAAM,cAAU,MAAM,gBACtB,OAAO,GACL,MAAM,CAuDlB;IAED;;;;;OAKG;IACH,wBAFW,MAAM,QAQhB;IAED;;;OAGG;IACH,yBAHW,MAAM,GACJ,OAAO,CAInB;IAED;;OAEG;IACH,qBAFa,MAAM,EAAE,CAIpB;IAED;;;;;OAKG;IACH,kBAHW,MAAM,GACJ,MAAM,CAiBlB;IAED;;;;OAIG;IACH,0BAHW,MAAM,GACJ,MAAM,CAOlB;IAED;;OAEG;IACH,4BAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,mCAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;OAIG;IACH,mBAGC;IAED;;;OAGG;IACH,eAKC;IAED;;;;;;;;OAQG;IACH,WAHW,MAAM,GACJ,OAAO,CAyCnB;IAED;;;OAGG;IACH,gBAOC;CACD"}
|
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* Includes a built-in perspective projection and supports 3D transforms
|
|
6
6
|
* through the standard Renderable API (`rotate`, `scale`, `translate`).
|
|
7
7
|
* Works on both WebGL (hardware depth testing) and Canvas (painter's algorithm) renderers.
|
|
8
|
+
*
|
|
9
|
+
* **Pivot — transforms are applied about the mesh's local origin `(0, 0, 0)`,
|
|
10
|
+
* NOT a normalized anchor point.** Unlike a {@link Sprite} (whose
|
|
11
|
+
* {@link Renderable#anchorPoint} recenters a `width`×`height` box), a mesh has
|
|
12
|
+
* real vertex coordinates, so rotation and scale pivot around the model origin
|
|
13
|
+
* the geometry is authored against — the standard convention for 3D meshes.
|
|
14
|
+
* Place the origin where you want the pivot at authoring time (or nest the
|
|
15
|
+
* mesh under a transformed parent to pivot elsewhere). Consequently, on the
|
|
16
|
+
* `Camera3d` world-space path the mesh opts out of the anchor offset entirely
|
|
17
|
+
* (see {@link Renderable#applyAnchorTransform}); the legacy 2D path still
|
|
18
|
+
* honors `anchorPoint` for backward compatibility.
|
|
8
19
|
* @category Game Objects
|
|
9
20
|
*/
|
|
10
21
|
export default class Mesh extends Renderable {
|
|
@@ -18,9 +29,16 @@ export default class Mesh extends Renderable {
|
|
|
18
29
|
* @param {Uint16Array|number[]} [settings.indices] - triangle vertex indices (alternative to settings.model)
|
|
19
30
|
* @param {HTMLImageElement|TextureAtlas|string} [settings.texture] - the texture to apply (image name, HTMLImageElement, or TextureAtlas). If omitted and settings.material is provided, the texture is resolved from the MTL material's map_Kd.
|
|
20
31
|
* @param {string} [settings.material] - name of a preloaded MTL material (via loader.preload with type "mtl"). When provided, the diffuse texture (map_Kd), tint color (Kd), and opacity (d) are automatically applied.
|
|
21
|
-
* @param {number} settings.width - display width in pixels (the
|
|
22
|
-
* @param {number} settings.height - display height in pixels (
|
|
32
|
+
* @param {number} settings.width - display width in pixels. With normalization on (the default) the model is scaled to fit this size; with `normalize: false` this is the uniform pixels-per-unit scale applied to the raw geometry.
|
|
33
|
+
* @param {number} [settings.height] - display height in pixels (normalized models only; ignored when `normalize: false`)
|
|
23
34
|
* @param {boolean} [settings.cullBackFaces=true] - enable backface culling
|
|
35
|
+
* @param {boolean} [settings.normalize=true] - fit the source geometry into a `[-0.5, 0.5]` unit cube before scaling, so `width`/`height` behave like a Sprite. Set `false` to keep the geometry's real-world coordinates — required when several meshes share one coordinate space (e.g. nodes of an imported glTF scene) so their relative scale and layout are preserved.
|
|
36
|
+
* @param {number} [settings.scale] - world-space scale (pixels per source unit) for the Camera3d path; defaults to `width`. Set this when `width`/`height` describe the renderable's world bounds (frustum culling) rather than the geometry scale — see {@link Mesh#meshScale}.
|
|
37
|
+
* @param {boolean} [settings.rightHanded=false] - treat the source as right-handed (Y-up, e.g. glTF) under the `Camera3d` world path. The default Y-up→Y-down bridge negates Y only (a reflection, which mirrors the scene left/right); `true` negates Y **and** Z (a rotation) so chirality is preserved and the result matches the authoring tool. See {@link Mesh#rightHanded}.
|
|
38
|
+
* @param {string} [settings.textureRepeat] - texture wrap mode (`"repeat"` / `"repeat-x"` / `"repeat-y"` / `"no-repeat"`) applied to the resolved texture. Use `"repeat"` when the geometry's UVs fall outside the `[0, 1]` range and rely on the texture tiling (e.g. glTF assets, whose default sampler wrap is REPEAT) — otherwise the texture clamps to its edge texels and looks flat. Ignored for the white-pixel fallback. Note: REPEAT on a non-power-of-two texture requires WebGL 2.
|
|
39
|
+
* @param {string} [settings.textureFilter] - texture magnification filter (`"nearest"` for crisp pixel-art upscaling, `"linear"` for smooth) applied to the resolved texture. Omit to keep the renderer's global `antiAlias` default. WebGL only (ignored by the Canvas renderer).
|
|
40
|
+
* @param {number} [settings.alphaCutoff=0] - alpha cutout threshold. Fragments whose final alpha is below this value are discarded (hard-edged cutout — foliage, fences, decals — with no blending or sorting). `0` disables the cutout. Set automatically by the glTF loader from a material's `alphaMode: "MASK"`. WebGL mesh path only.
|
|
41
|
+
* @param {number[]|Float32Array} [settings.emissive] - emissive (self-illumination) color `[r, g, b]` (0..1, may exceed 1 for HDR glow) added on top of the lit/unlit color so the surface glows regardless of scene lights (neon, lava, screens). Omit / all-zero for no emission. Set automatically by the glTF loader (`emissiveFactor`) and OBJ loader (MTL `Ke`). WebGL mesh path only.
|
|
24
42
|
* @example
|
|
25
43
|
* // create from OBJ + MTL (texture auto-resolved from material)
|
|
26
44
|
* let mesh = new me.Mesh(0, 0, {
|
|
@@ -38,6 +56,28 @@ export default class Mesh extends Renderable {
|
|
|
38
56
|
* height: 200,
|
|
39
57
|
* });
|
|
40
58
|
*
|
|
59
|
+
* // create from raw geometry that already carries its own world scale
|
|
60
|
+
* // (e.g. a glTF scene node) — keep real coordinates, no mirror
|
|
61
|
+
* let node = new me.Mesh(0, 0, {
|
|
62
|
+
* vertices: positions, // Float32Array of x,y,z triplets
|
|
63
|
+
* uvs: texcoords, // Float32Array of u,v pairs
|
|
64
|
+
* indices: tris, // Uint16Array of triangle indices
|
|
65
|
+
* texture: baseColorImage,
|
|
66
|
+
* width: 32, // pixels per unit
|
|
67
|
+
* normalize: false,
|
|
68
|
+
* rightHanded: true,
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* // material settings (WebGL) — usually set for you by the glTF/OBJ loader,
|
|
72
|
+
* // but available directly on a hand-built mesh too
|
|
73
|
+
* let sign = new me.Mesh(0, 0, {
|
|
74
|
+
* vertices, uvs, indices, texture: "neon-sign",
|
|
75
|
+
* width: 64, normalize: false,
|
|
76
|
+
* textureFilter: "nearest", // crisp pixel-art upscaling
|
|
77
|
+
* alphaCutoff: 0.5, // discard texels below 0.5 alpha (cutout)
|
|
78
|
+
* emissive: [0.9, 0.2, 0.6], // glow, independent of scene lights
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
41
81
|
* // 3D rotation using the standard rotate() API
|
|
42
82
|
* mesh.rotate(Math.PI / 4, new me.Vector3d(0, 1, 0)); // rotate around Y axis
|
|
43
83
|
*
|
|
@@ -52,8 +92,15 @@ export default class Mesh extends Renderable {
|
|
|
52
92
|
texture?: string | HTMLImageElement | TextureAtlas | undefined;
|
|
53
93
|
material?: string | undefined;
|
|
54
94
|
width: number;
|
|
55
|
-
height
|
|
95
|
+
height?: number | undefined;
|
|
56
96
|
cullBackFaces?: boolean | undefined;
|
|
97
|
+
normalize?: boolean | undefined;
|
|
98
|
+
scale?: number | undefined;
|
|
99
|
+
rightHanded?: boolean | undefined;
|
|
100
|
+
textureRepeat?: string | undefined;
|
|
101
|
+
textureFilter?: string | undefined;
|
|
102
|
+
alphaCutoff?: number | undefined;
|
|
103
|
+
emissive?: number[] | Float32Array<ArrayBufferLike> | undefined;
|
|
57
104
|
});
|
|
58
105
|
/**
|
|
59
106
|
* the original (untransformed) vertex positions as x,y,z triplets
|
|
@@ -76,12 +123,75 @@ export default class Mesh extends Renderable {
|
|
|
76
123
|
* @type {Float32Array}
|
|
77
124
|
*/
|
|
78
125
|
vertices: Float32Array;
|
|
126
|
+
/**
|
|
127
|
+
* the source per-vertex normals (x,y,z triplets), or `undefined` if the
|
|
128
|
+
* mesh was built without them. Supplied by the glTF loader; used for
|
|
129
|
+
* lit shading under a `Camera3d` (see {@link Light3d}).
|
|
130
|
+
* @type {Float32Array|undefined}
|
|
131
|
+
*/
|
|
132
|
+
originalNormals: Float32Array | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Whether this mesh is lit by the active stage's {@link Light3d} lights.
|
|
135
|
+
* When `true` it renders through the lit mesh batcher (diffuse shading
|
|
136
|
+
* from the scene's lights, using {@link Mesh#originalNormals}); when
|
|
137
|
+
* `false` (the default) it uses the lean unlit path and pays no lighting
|
|
138
|
+
* cost. The glTF loader sets this on scene meshes when the scene has
|
|
139
|
+
* lights. Only meaningful under a `Camera3d` + WebGL.
|
|
140
|
+
* @type {boolean}
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
lit: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Alpha cutout threshold. A fragment whose final alpha is below this
|
|
146
|
+
* value is discarded — a hard-edged cutout (foliage, fences, chain-link,
|
|
147
|
+
* decals) that needs no blending or back-to-front sorting. `0` (the
|
|
148
|
+
* default) disables the cutout and the mesh renders fully opaque. Set by
|
|
149
|
+
* the glTF loader from a material's `alphaMode: "MASK"` / `alphaCutoff`.
|
|
150
|
+
* WebGL mesh path only (the Canvas renderer ignores it).
|
|
151
|
+
* @type {number}
|
|
152
|
+
* @default 0
|
|
153
|
+
*/
|
|
154
|
+
alphaCutoff: number;
|
|
155
|
+
/**
|
|
156
|
+
* Emissive (self-illumination) color as an `[r, g, b]` `Float32Array`
|
|
157
|
+
* (0..1, may exceed 1 for HDR glow), added on top of the lit/unlit color
|
|
158
|
+
* so the surface glows independently of the scene lights (neon, lava,
|
|
159
|
+
* screens, glowing eyes). `undefined` (the default) means no emission and
|
|
160
|
+
* keeps the mesh on the lean path. Set by the glTF loader from a material's
|
|
161
|
+
* `emissiveFactor` (× `KHR_materials_emissive_strength`) and by the OBJ
|
|
162
|
+
* loader from an MTL's `Ke`. WebGL mesh path only.
|
|
163
|
+
* @type {Float32Array|undefined}
|
|
164
|
+
*/
|
|
165
|
+
emissive: Float32Array | undefined;
|
|
79
166
|
/**
|
|
80
167
|
* whether to cull back-facing triangles
|
|
81
168
|
* @type {boolean}
|
|
82
169
|
* @default true
|
|
83
170
|
*/
|
|
84
171
|
cullBackFaces: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Treat the source geometry as right-handed (Y-up, e.g. glTF) under
|
|
174
|
+
* the Camera3d world path. The default (`false`) Y-up→Y-down bridge
|
|
175
|
+
* negates Y only — a reflection, which mirrors the scene left/right.
|
|
176
|
+
* When `true`, the bridge negates Y **and** Z (a 180° rotation about
|
|
177
|
+
* X, determinant +1) so chirality is preserved and the result matches
|
|
178
|
+
* the authoring tool (no mirror); triangle winding is left untouched
|
|
179
|
+
* since a rotation doesn't invert it.
|
|
180
|
+
* @type {boolean}
|
|
181
|
+
* @default false
|
|
182
|
+
*/
|
|
183
|
+
rightHanded: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Uniform world-space scale (pixels per source unit) applied along the
|
|
186
|
+
* Camera3d world path. Defaults to `width`. Scene loaders (e.g. glTF)
|
|
187
|
+
* set this independently of `width` / `height` so those can describe
|
|
188
|
+
* the renderable's world-space bounds (used for frustum culling) while
|
|
189
|
+
* the geometry is still scaled by this factor — `width` alone can't
|
|
190
|
+
* serve both roles for a non-normalized scene mesh.
|
|
191
|
+
* @type {number}
|
|
192
|
+
* @default settings.width
|
|
193
|
+
*/
|
|
194
|
+
meshScale: number;
|
|
85
195
|
/**
|
|
86
196
|
* Per-material submesh groups, populated when the OBJ
|
|
87
197
|
* contains multiple `usemtl` directives AND a matching MTL
|
|
@@ -157,8 +267,9 @@ export default class Mesh extends Renderable {
|
|
|
157
267
|
* view + projection matrices, the same way it does for Sprites.
|
|
158
268
|
*
|
|
159
269
|
* Per-vertex math: `currentTransform × originalVertex`, then a uniform
|
|
160
|
-
* scale by `this.width`,
|
|
161
|
-
*
|
|
270
|
+
* scale by `this.width`, the Y-up→Y-down bridge (negate Y, and also Z when
|
|
271
|
+
* {@link Mesh#rightHanded} is set so the bridge is a rotation rather than a
|
|
272
|
+
* mirror), and a translate to `(offsetX, offsetY, offsetZ)`.
|
|
162
273
|
*
|
|
163
274
|
* @param {number} offsetX - world X to place the mesh center at
|
|
164
275
|
* @param {number} offsetY - world Y to place the mesh center at
|
|
@@ -166,6 +277,20 @@ export default class Mesh extends Renderable {
|
|
|
166
277
|
* @ignore
|
|
167
278
|
*/
|
|
168
279
|
_projectVerticesWorld(offsetX: number, offsetY: number, offsetZ: number): void;
|
|
280
|
+
/**
|
|
281
|
+
* Project {@link Mesh#originalNormals} into world space for lit shading,
|
|
282
|
+
* storing the result in {@link Mesh#normals}. Applies the rotation/scale of
|
|
283
|
+
* {@link Renderable#currentTransform} (no translation), the same Y-down /
|
|
284
|
+
* `rightHanded` Y/Z bridge as {@link Mesh#_projectVerticesWorld}, then
|
|
285
|
+
* renormalizes. No-op when the mesh has no source normals.
|
|
286
|
+
*
|
|
287
|
+
* Note: uses the transform's rotation/scale columns directly rather than
|
|
288
|
+
* the inverse-transpose, so normals are exact under rotation + uniform
|
|
289
|
+
* scale (the common case); a strongly non-uniform scale would skew them
|
|
290
|
+
* slightly — acceptable for the diffuse lighting path.
|
|
291
|
+
* @ignore
|
|
292
|
+
*/
|
|
293
|
+
_projectNormalsWorld(): void;
|
|
169
294
|
/**
|
|
170
295
|
* Build the winding-reversed indices buffer used by the Camera3d
|
|
171
296
|
* world-space path. Called once, lazily, the first time the mesh
|
|
@@ -186,9 +311,28 @@ export default class Mesh extends Renderable {
|
|
|
186
311
|
* @ignore
|
|
187
312
|
*/
|
|
188
313
|
_setupWorldSpace(): void;
|
|
189
|
-
_indicesReversed:
|
|
314
|
+
_indicesReversed: any;
|
|
190
315
|
_worldSpace: boolean | undefined;
|
|
191
316
|
_useWorldSpace: boolean | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* The mesh's world-space 3D axis-aligned bounding box, as projected by the
|
|
319
|
+
* most recent draw. This is the 3D analog of {@link Renderable#getBounds}
|
|
320
|
+
* (which returns a flat 2D box from `width`/`height` and so cannot describe
|
|
321
|
+
* a mesh's real extent).
|
|
322
|
+
*
|
|
323
|
+
* Under a `Camera3d` the mesh projects its vertices into world space every
|
|
324
|
+
* frame (see {@link Mesh#_projectVerticesWorld}), so the returned box tracks
|
|
325
|
+
* the live transform / animation. Under the 2D path the projected vertices
|
|
326
|
+
* are screen-space, so the box is only meaningful after a Camera3d draw —
|
|
327
|
+
* use {@link Renderable#getBounds} for the 2D case.
|
|
328
|
+
*
|
|
329
|
+
* The same {@link AABB3d} instance is returned each call (recomputed in
|
|
330
|
+
* place), so copy it (`.clone()`) if you need to keep it.
|
|
331
|
+
* @returns {AABB3d} the world-space bounding box (reused instance)
|
|
332
|
+
*/
|
|
333
|
+
getBounds3d(): AABB3d;
|
|
334
|
+
/** @ignore */
|
|
335
|
+
_bounds3d: AABB3d | undefined;
|
|
192
336
|
/**
|
|
193
337
|
* Render the mesh at its current state (transforms, projection, tint) to an offscreen canvas.
|
|
194
338
|
* The returned canvas can be used with `renderer.drawImage()`, as a `Sprite` image source,
|
|
@@ -218,5 +362,6 @@ import { Color } from "../math/color.ts";
|
|
|
218
362
|
import { Matrix3d } from "../math/matrix3d.ts";
|
|
219
363
|
import { Vector2d } from "../math/vector2d.ts";
|
|
220
364
|
import { Polygon } from "../geometries/polygon.ts";
|
|
365
|
+
import { AABB3d } from "../physics/broadphase/aabb3d.ts";
|
|
221
366
|
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
222
367
|
//# sourceMappingURL=mesh.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../src/renderable/mesh.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../src/renderable/mesh.js"],"names":[],"mappings":"AAyGA;;;;;;;;;;;;;;;;;;;GAmBG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgEG;IACH,eAhEW,MAAM,KACN,MAAM,YAEd;QAA0B,KAAK;QACU,QAAQ;QACR,GAAG;QACJ,OAAO;QACS,OAAO;QACrC,QAAQ;QACT,KAAK,EAAtB,MAAM;QACY,MAAM;QACL,aAAa;QACb,SAAS;QACV,KAAK;QACJ,WAAW;QACZ,aAAa;QACb,aAAa;QACb,WAAW;QACI,QAAQ;KACjD,EAoaF;IA7WC;;;OAGG;IACH,kBAFU,YAAY,CAEkB;IAExC;;;OAGG;IACH,KAFU,YAAY,CAEA;IAQtB;;;OAGG;IACH,aAFU,MAAM,CAEsB;IAmCvC,2BAAoC;IAGpC;;;OAGG;IACH,UAFU,YAAY,CAEgC;IAEtD;;;;;OAKG;IACH,iBAFU,YAAY,GAAC,SAAS,CAOnB;IAUb;;;;;;;;;OASG;IACH,KAHU,OAAO,CAGe;IAEhC;;;;;;;;;OASG;IACH,aAHU,MAAM,CAIoD;IAEpE;;;;;;;;;OASG;IACH,UAFU,YAAY,GAAC,SAAS,CAEa;IAE7C;;;;OAIG;IACH,eAHU,OAAO,CAIoD;IAErE;;;;;;;;;;OAUG;IACH,aAHU,OAAO,CAG+B;IAEhD;;;;;;;;;OASG;IACH,WAHU,MAAM,CAIiD;IAsBhE;;;;;;;;;;;;;;;;;OAiBG;IACH,QAHU,KAAK,CAAC;QAAC,YAAY,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QACrD,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,KAAK,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC,CAAC,CAIhD;IAsBF;;;;;;;;;;;;;;;;;;OAkBG;IACH,cAFU,WAAW,CAEgC;IAuDtD,aAIC;IAkCD;;;;;;OAMG;IACH,kBAFU,QAAQ,CAEoB;IAoBtC,cAAc;IACd,wBAEE;IACF,cAAc;IACd,6BAAwB;IAGzB;;;;;;;OAOG;IACH,2BALW,MAAM,YACN,MAAM,WACN,MAAM,QAiBhB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,+BALW,MAAM,WACN,MAAM,WACN,MAAM,QAqChB;IAED;;;;;;;;;;;;OAYG;IACH,6BA8BC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,yBAqBC;IAHC,sBAA2B;IAE5B,iCAAuB;IAoBvB,oCAAuD;IAGxD;;;;;;;;;;;;;;;OAeG;IACH,eAFa,MAAM,CAWlB;IAPC,cAAc;IACd,8BAA6B;IA4H/B;;;;;;;;;;;;OAYG;IACH,YATa,iBAAiB,CAoH7B;IAED;;;;;;;OAOG;IACH,iBALa,OAAO,CAAC,WAAW,CAAC,CAOhC;CACD;uBAr/BsB,iBAAiB;sBAXlB,kBAAkB;yBACf,qBAAqB;yBACrB,qBAAqB;wBAJtB,0BAA0B;uBAU3B,iCAAiC;6BAE3B,6BAA6B"}
|
|
@@ -173,6 +173,28 @@ export default class Renderable extends Rect {
|
|
|
173
173
|
* }
|
|
174
174
|
*/
|
|
175
175
|
autoTransform: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Whether {@link Renderable#preDraw} applies the
|
|
178
|
+
* {@link Renderable#anchorPoint} offset to the renderer transform.
|
|
179
|
+
*
|
|
180
|
+
* When `true` (the default), the renderable is shifted by
|
|
181
|
+
* `-anchorPoint × (width, height)` so its anchor — not its top-left
|
|
182
|
+
* corner — aligns with its position. Correct for sprites and other 2D
|
|
183
|
+
* renderables.
|
|
184
|
+
*
|
|
185
|
+
* Set to `false` for a renderable that emits its own final world
|
|
186
|
+
* coordinates and takes its origin from geometry rather than a bounds
|
|
187
|
+
* box — e.g. a {@link Mesh} on the `Camera3d` world-space path (a 3D
|
|
188
|
+
* mesh is positioned by its transform and has no anchor). The WebGL mesh
|
|
189
|
+
* batcher reuses this same renderer transform as its **view matrix**,
|
|
190
|
+
* so applying the normalized anchor there would shift every mesh by
|
|
191
|
+
* half its OWN bounds box; because scene meshes size that box per node,
|
|
192
|
+
* props and the platforms they rest on would drift apart and overlap.
|
|
193
|
+
* @type {boolean}
|
|
194
|
+
* @default true
|
|
195
|
+
* @see Mesh#preDraw
|
|
196
|
+
*/
|
|
197
|
+
applyAnchorTransform: boolean;
|
|
176
198
|
/**
|
|
177
199
|
* Define the renderable opacity<br>
|
|
178
200
|
* Set to zero if you do not wish an object to be drawn
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderable.d.ts","sourceRoot":"","sources":["../../src/renderable/renderable.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;IAaI;AAEJ;;;GAGG;AACH;IAkBG,iBAAmB;IAGpB;;;;;;;;;;OAUG;IACH,aAHU,eAAe,CAMvB;IAGD;;;;;;;OAOG;IACH,kBAFU,QAAQ,CAEoB;IAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,MAlCU,WAAW,CAkCA;IAErB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAHU,MAAM,GAAC,SAAS,CAGF;IAExB;;;;;OAKG;IACH,MAFU,MAAM,CAEK;IAErB;;;;;;;;;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0BAF7B,yBAAyB;6BACtB,4BAA4B;6BAG1B,iCAAiC;gCAC9B,sCAAsC;+BACvC,oCAAoC"}
|
|
@@ -63,17 +63,7 @@ export default class Sprite extends Renderable {
|
|
|
63
63
|
anchorPoint?: Vector2d | undefined;
|
|
64
64
|
normalMap?: string | ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | undefined;
|
|
65
65
|
});
|
|
66
|
-
|
|
67
|
-
* @type {boolean}
|
|
68
|
-
* @default false
|
|
69
|
-
*/
|
|
70
|
-
animationpause: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* animation cycling speed (delay between frame in ms)
|
|
73
|
-
* @type {number}
|
|
74
|
-
* @default 100
|
|
75
|
-
*/
|
|
76
|
-
animationspeed: number;
|
|
66
|
+
_frameAnim: FrameAnimation;
|
|
77
67
|
/**
|
|
78
68
|
* global offset for the position to draw from on the source image.
|
|
79
69
|
* @type {Vector2d}
|
|
@@ -102,19 +92,6 @@ export default class Sprite extends Renderable {
|
|
|
102
92
|
* @ignore
|
|
103
93
|
*/
|
|
104
94
|
_normalMap: ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | null;
|
|
105
|
-
anim: {};
|
|
106
|
-
resetAnim: Function | (() => Sprite) | undefined;
|
|
107
|
-
current: {
|
|
108
|
-
name: undefined;
|
|
109
|
-
length: number;
|
|
110
|
-
offset: Vector2d;
|
|
111
|
-
width: number;
|
|
112
|
-
height: number;
|
|
113
|
-
angle: number;
|
|
114
|
-
idx: number;
|
|
115
|
-
trim: null;
|
|
116
|
-
};
|
|
117
|
-
dt: number;
|
|
118
95
|
/**
|
|
119
96
|
* flicker settings
|
|
120
97
|
* @ignore
|
|
@@ -129,6 +106,13 @@ export default class Sprite extends Renderable {
|
|
|
129
106
|
textureAtlas: any;
|
|
130
107
|
width: any;
|
|
131
108
|
height: any;
|
|
109
|
+
set animationpause(value: boolean);
|
|
110
|
+
/**
|
|
111
|
+
* pause the frame animation, freezing the current frame.
|
|
112
|
+
* @type {boolean}
|
|
113
|
+
* @default false
|
|
114
|
+
*/
|
|
115
|
+
get animationpause(): boolean;
|
|
132
116
|
/**
|
|
133
117
|
* pause the video when losing focus
|
|
134
118
|
* @ignore
|
|
@@ -148,19 +132,62 @@ export default class Sprite extends Renderable {
|
|
|
148
132
|
*/
|
|
149
133
|
get normalMap(): HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap | null;
|
|
150
134
|
atlasIndices: any;
|
|
135
|
+
/**
|
|
136
|
+
* defined animations, keyed by id (see {@link Sprite#addAnimation}).
|
|
137
|
+
* @type {object}
|
|
138
|
+
*/
|
|
139
|
+
get anim(): object;
|
|
140
|
+
/**
|
|
141
|
+
* current frame information (name / index / texture offset & size / trim).
|
|
142
|
+
* @type {object}
|
|
143
|
+
*/
|
|
144
|
+
get current(): object;
|
|
145
|
+
set dt(value: number);
|
|
146
|
+
/**
|
|
147
|
+
* elapsed time within the current animation frame, in milliseconds.
|
|
148
|
+
* @type {number}
|
|
149
|
+
*/
|
|
150
|
+
get dt(): number;
|
|
151
|
+
set animationspeed(value: number);
|
|
152
|
+
/**
|
|
153
|
+
* animation cycling speed (delay between frames in ms).
|
|
154
|
+
* @type {number}
|
|
155
|
+
* @default 100
|
|
156
|
+
*/
|
|
157
|
+
get animationspeed(): number;
|
|
151
158
|
/**
|
|
152
159
|
* return the flickering state of the object
|
|
153
160
|
* @returns {boolean}
|
|
154
161
|
*/
|
|
155
162
|
isFlickering(): boolean;
|
|
156
163
|
/**
|
|
157
|
-
*
|
|
164
|
+
* Play an animation, or resume the current animation / video. A shorthand:
|
|
165
|
+
* call with an animation id to switch to (and start) it, or with no argument
|
|
166
|
+
* to resume after {@link Sprite#pause}. Always clears the paused state. The
|
|
167
|
+
* options mirror {@link Sprite#setCurrentAnimation} and the 3D
|
|
168
|
+
* {@link GLTFModel#play}, so 2D and 3D animation share one API.
|
|
169
|
+
* @param {string} [name] - animation id to play; omit to just resume
|
|
170
|
+
* @param {string|Function|object} [options] - loop / chain / completion behavior (see {@link Sprite#setCurrentAnimation})
|
|
171
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
172
|
+
* @example
|
|
173
|
+
* sprite.play("walk"); // switch to + play "walk"
|
|
174
|
+
* sprite.play("die", { loop: false }); // play once, hold the last frame
|
|
175
|
+
* sprite.pause();
|
|
176
|
+
* sprite.play(); // resume
|
|
177
|
+
*/
|
|
178
|
+
play(name?: string, options?: string | Function | object): Sprite;
|
|
179
|
+
/**
|
|
180
|
+
* Pause the current animation or video, freezing the current frame. Resume
|
|
181
|
+
* with {@link Sprite#play}.
|
|
182
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
158
183
|
*/
|
|
159
|
-
|
|
184
|
+
pause(): Sprite;
|
|
160
185
|
/**
|
|
161
|
-
*
|
|
186
|
+
* Stop the current animation or video and reset it to the first frame
|
|
187
|
+
* (paused). (Use {@link Sprite#pause} instead to freeze in place.)
|
|
188
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
162
189
|
*/
|
|
163
|
-
|
|
190
|
+
stop(): Sprite;
|
|
164
191
|
/**
|
|
165
192
|
* make the object flicker
|
|
166
193
|
* @param {number} duration - expressed in milliseconds
|
|
@@ -260,6 +287,16 @@ export default class Sprite extends Renderable {
|
|
|
260
287
|
* }
|
|
261
288
|
*/
|
|
262
289
|
isCurrentAnimation(name: string): boolean;
|
|
290
|
+
/**
|
|
291
|
+
* the names of every animation defined on this sprite (via
|
|
292
|
+
* {@link Sprite#addAnimation}).
|
|
293
|
+
* @returns {string[]} the defined animation names
|
|
294
|
+
* @example
|
|
295
|
+
* sprite.addAnimation("walk", [0, 1, 2, 3]);
|
|
296
|
+
* sprite.addAnimation("idle", [4, 5]);
|
|
297
|
+
* sprite.getAnimationNames(); // ["walk", "idle"]
|
|
298
|
+
*/
|
|
299
|
+
getAnimationNames(): string[];
|
|
263
300
|
/**
|
|
264
301
|
* change the current texture atlas region for this sprite
|
|
265
302
|
* @see Texture.getRegion
|
|
@@ -270,6 +307,14 @@ export default class Sprite extends Renderable {
|
|
|
270
307
|
* mySprite.setRegion(mytexture.getRegion("shadedDark13.png"));
|
|
271
308
|
*/
|
|
272
309
|
setRegion(region: object): Sprite;
|
|
310
|
+
/**
|
|
311
|
+
* Apply the current frame's texture region to this sprite's geometry: swap
|
|
312
|
+
* the source sub-texture, then resolve size / anchor (honoring trimming).
|
|
313
|
+
* Invoked by the shared {@link FrameAnimation} engine via `setRegion`.
|
|
314
|
+
* @param {object} region - the texture region object
|
|
315
|
+
* @ignore
|
|
316
|
+
*/
|
|
317
|
+
_applyFrame(region: object): void;
|
|
273
318
|
/**
|
|
274
319
|
* force the current animation frame index.
|
|
275
320
|
* @param {number} [index=0] - animation frame index
|
|
@@ -317,6 +362,7 @@ export default class Sprite extends Renderable {
|
|
|
317
362
|
destroy(): void;
|
|
318
363
|
}
|
|
319
364
|
import Renderable from "./renderable.js";
|
|
365
|
+
import FrameAnimation from "./frameAnimation.js";
|
|
320
366
|
import type { Vector2d } from "../math/vector2d.js";
|
|
321
367
|
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
322
368
|
import type Renderer from "./../video/renderer.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../src/renderable/sprite.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../src/renderable/sprite.js"],"names":[],"mappings":"AAYA;;;;GAIG;AAEH;;;GAGG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;IACH,eA1CW,MAAM,KACN,MAAM,YAEd;QAA0G,KAAK,EAAvG,gBAAgB,GAAC,iBAAiB,GAAC,gBAAgB,GAAC,YAAY,GAAC,eAAe,GAAC,MAAM;QACrE,IAAI;QACJ,MAAM;QACN,UAAU;QACV,WAAW;QACL,IAAI;QACV,KAAK;QACL,KAAK;QACH,WAAW;QACkD,SAAS;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