@babylonjs/lottie-player 8.24.1

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 (75) hide show
  1. package/animationConfiguration.d.ts +80 -0
  2. package/animationConfiguration.d.ts.map +1 -0
  3. package/animationConfiguration.js +16 -0
  4. package/animationConfiguration.js.map +1 -0
  5. package/index.d.ts +4 -0
  6. package/index.d.ts.map +1 -0
  7. package/index.js +3 -0
  8. package/index.js.map +1 -0
  9. package/license.md +21 -0
  10. package/localPlayer.d.ts +38 -0
  11. package/localPlayer.d.ts.map +1 -0
  12. package/localPlayer.js +100 -0
  13. package/localPlayer.js.map +1 -0
  14. package/maths/bezier.d.ts +45 -0
  15. package/maths/bezier.d.ts.map +1 -0
  16. package/maths/bezier.js +53 -0
  17. package/maths/bezier.js.map +1 -0
  18. package/maths/boundingBox.d.ts +39 -0
  19. package/maths/boundingBox.d.ts.map +1 -0
  20. package/maths/boundingBox.js +204 -0
  21. package/maths/boundingBox.js.map +1 -0
  22. package/maths/matrix.d.ts +92 -0
  23. package/maths/matrix.d.ts.map +1 -0
  24. package/maths/matrix.js +174 -0
  25. package/maths/matrix.js.map +1 -0
  26. package/messageTypes.d.ts +88 -0
  27. package/messageTypes.d.ts.map +1 -0
  28. package/messageTypes.js +2 -0
  29. package/messageTypes.js.map +1 -0
  30. package/nodes/controlNode.d.ts +32 -0
  31. package/nodes/controlNode.d.ts.map +1 -0
  32. package/nodes/controlNode.js +38 -0
  33. package/nodes/controlNode.js.map +1 -0
  34. package/nodes/node.d.ts +121 -0
  35. package/nodes/node.d.ts.map +1 -0
  36. package/nodes/node.js +357 -0
  37. package/nodes/node.js.map +1 -0
  38. package/nodes/spriteNode.d.ts +32 -0
  39. package/nodes/spriteNode.d.ts.map +1 -0
  40. package/nodes/spriteNode.js +51 -0
  41. package/nodes/spriteNode.js.map +1 -0
  42. package/package.json +48 -0
  43. package/parsing/parsedTypes.d.ts +141 -0
  44. package/parsing/parsedTypes.d.ts.map +1 -0
  45. package/parsing/parsedTypes.js +2 -0
  46. package/parsing/parsedTypes.js.map +1 -0
  47. package/parsing/parser.d.ts +59 -0
  48. package/parsing/parser.d.ts.map +1 -0
  49. package/parsing/parser.js +500 -0
  50. package/parsing/parser.js.map +1 -0
  51. package/parsing/rawTypes.d.ts +238 -0
  52. package/parsing/rawTypes.d.ts.map +1 -0
  53. package/parsing/rawTypes.js +4 -0
  54. package/parsing/rawTypes.js.map +1 -0
  55. package/parsing/spritePacker.d.ts +122 -0
  56. package/parsing/spritePacker.d.ts.map +1 -0
  57. package/parsing/spritePacker.js +409 -0
  58. package/parsing/spritePacker.js.map +1 -0
  59. package/player.d.ts +42 -0
  60. package/player.d.ts.map +1 -0
  61. package/player.js +146 -0
  62. package/player.js.map +1 -0
  63. package/readme.md +44 -0
  64. package/rendering/animationController.d.ts +93 -0
  65. package/rendering/animationController.d.ts.map +1 -0
  66. package/rendering/animationController.js +246 -0
  67. package/rendering/animationController.js.map +1 -0
  68. package/rendering/renderingManager.d.ts +46 -0
  69. package/rendering/renderingManager.d.ts.map +1 -0
  70. package/rendering/renderingManager.js +61 -0
  71. package/rendering/renderingManager.js.map +1 -0
  72. package/worker.d.ts +2 -0
  73. package/worker.d.ts.map +1 -0
  74. package/worker.js +62 -0
  75. package/worker.js.map +1 -0
package/readme.md ADDED
@@ -0,0 +1,44 @@
1
+ **- This is a highly experimental feature, use it at your own risk :)**
2
+
3
+ # Lottie (Experimental)
4
+
5
+ Play Lottie JSON animations on a lightweight Babylon ThinEngine using an OffscreenCanvas + Worker.
6
+
7
+ ## Usage
8
+
9
+ ```ts
10
+ import { Player } from "@babylonjs/lottie-player";
11
+
12
+ const container = document.getElementById("myDiv") as HTMLDivElement;
13
+ const player = new Player(container, "/animations/hero.json");
14
+ player.playAnimation();
15
+ ```
16
+
17
+ ## Important Notes
18
+
19
+ The public API of this package is formed by Player, LocalPlayer and AnimationConfiguration. All other files are internal implementation details.
20
+
21
+ Future updates could move or rename files and require you to update your references if you take dependencies on those files. Do not depend on the paths of those files either as they could be moved or renamed as part of the internal implementation.
22
+
23
+ ## Options
24
+
25
+ You can pass a variables map in the constructor of Player. These variables will be used in:
26
+
27
+ - Text from a text layer to be localized.
28
+ - Text fill from a text layer to use a particular color.
29
+
30
+ You can use the AnimationConfiguration to change certain parameters of the parser/player. For example, loopAnimation to loop the animation, or ignoreOpacityAnimation for performance if you know your animation doesn't modify opacity.
31
+
32
+ ## Remarks
33
+
34
+ - Prefer to use the class Player that uses an Offscreen canvas and the worker thread. If for some reason that is not available to you, you can use LocalPlayer and call playAnimationAsync which renders in the main JS thread.
35
+
36
+ - Only certain features of the Lottie format are currently supported.
37
+ - Layers: null, shape, text
38
+ - Animations: translation, rotation, scale, opacity on layers (no animations supported on shapes/fills/text themselves)
39
+ - Shapes: rectangle, rounded corner rectangle, vector path
40
+ - Fills: regular fill, gradient fill, radial fill, stroke fill
41
+ - Text: each text layer should contain a single line of text, and the same styling and animations should be applying to the whole line
42
+ - More features may be added in the future but there is no timeline for them.
43
+
44
+ **- This is a highly experimental feature, use it at your own risk :)**
@@ -0,0 +1,93 @@
1
+ import "@babylonjs/core/Engines/Extensions/engine.alpha.js";
2
+ import "@babylonjs/core/Shaders/sprites.vertex.js";
3
+ import "@babylonjs/core/Shaders/sprites.fragment.js";
4
+ import type { RawLottieAnimation } from "../parsing/rawTypes.js";
5
+ import type { AnimationConfiguration } from "../animationConfiguration.js";
6
+ /**
7
+ * Calculates the scale factor between a container and the animation it is playing
8
+ * @param animationWidth Width of the animaiton
9
+ * @param animationHeight Height of the animation
10
+ * @param container The container where the animation is getting played
11
+ * @returns The scale factor that will modify the size of the animation rendering to adjust to the container
12
+ */
13
+ export declare function CalculateScaleFactor(animationWidth: number | undefined, animationHeight: number | undefined, container: HTMLElement): number;
14
+ /**
15
+ * Class that controls the playing of lottie animations using Babylon.js
16
+ */
17
+ export declare class AnimationController {
18
+ private _isReady;
19
+ private readonly _canvas;
20
+ private _scaleFactor;
21
+ private readonly _variables;
22
+ private readonly _configuration;
23
+ private readonly _engine;
24
+ private readonly _spritePacker;
25
+ private _animation?;
26
+ private readonly _viewport;
27
+ private readonly _projectionMatrix;
28
+ private readonly _worldMatrix;
29
+ private _firstRun;
30
+ private _frameDuration;
31
+ private _currentFrame;
32
+ private _isPlaying;
33
+ private _animationFrameId;
34
+ private _lastFrameTime;
35
+ private _deltaTime;
36
+ private _loop;
37
+ private _accumulatedTime;
38
+ private _framesToAdvance;
39
+ private readonly _renderingManager;
40
+ /**
41
+ * Gets the canvas used for rendering the animation.
42
+ * @returns The canvas element used for rendering.
43
+ */
44
+ get view(): HTMLCanvasElement;
45
+ /**
46
+ * Gets the height of the animation in pixels.
47
+ * @returns The height of the animation in pixels.
48
+ */
49
+ get animationHeight(): number;
50
+ /**
51
+ * Gets the width of the animation in pixels.
52
+ * @returns The width of the animation in pixels.
53
+ */
54
+ get animationWidth(): number;
55
+ /**
56
+ * Creates a new instance of the Player.
57
+ * @param canvas The canvas element to render the animation on.
58
+ * @param animationData The raw lottie animation as a JSON object.
59
+ * @param scaleFactor The scale factor between the animation and the container, it will modify the sprites size in the atlas
60
+ * @param variables Map of variables to replace in the animation file.
61
+ * @param configuration The configuration for the animation player.
62
+ */
63
+ constructor(canvas: HTMLCanvasElement | OffscreenCanvas, animationData: RawLottieAnimation, scaleFactor: number, variables: Map<string, string>, configuration: AnimationConfiguration);
64
+ /**
65
+ * Plays the animation.
66
+ */
67
+ playAnimation(): void;
68
+ /**
69
+ * Stops the animation playback.
70
+ */
71
+ stopAnimation(): void;
72
+ /**
73
+ * Sets a new scale factor for the animation and updates the rendering size.
74
+ * @param scale The new scale factor to apply to the animation.
75
+ */
76
+ setScale(scale: number): void;
77
+ /**
78
+ * Disposes the player and releases all resources.
79
+ */
80
+ dispose(): void;
81
+ /**
82
+ * Sets the rendering size for the engine
83
+ * @param width Width of the rendering canvas
84
+ * @param height Height of the rendering canvas
85
+ * @param scale Scale ratio between the container and the animation
86
+ */
87
+ private _setSize;
88
+ private _isHtmlCanvas;
89
+ private _cleanTree;
90
+ private _startRenderLoop;
91
+ private _render;
92
+ }
93
+ //# sourceMappingURL=animationController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animationController.d.ts","sourceRoot":"","sources":["../../../../dev/lottiePlayer/src/rendering/animationController.ts"],"names":[],"mappings":"AAAA,4DAA8C;AAC9C,mDAAqC;AACrC,qDAAuC;AAOvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAS9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAOxE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,WAAW,GAAG,MAAM,CAS5I;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,QAAQ,CAAU;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAC9D,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IACjD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAE7C,OAAO,CAAC,UAAU,CAAC,CAAgB;IAEnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAa;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAa;IAE1C,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAU;IAEvB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,gBAAgB,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD;;;OAGG;IACH,IAAW,IAAI,IAAI,iBAAiB,CAEnC;IAED;;;OAGG;IACH,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;;OAGG;IACH,IAAW,cAAc,IAAI,MAAM,CAElC;IAED;;;;;;;OAOG;gBAEC,MAAM,EAAE,iBAAiB,GAAG,eAAe,EAC3C,aAAa,EAAE,kBAAkB,EACjC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,aAAa,EAAE,sBAAsB;IAiEzC;;OAEG;IACI,aAAa,IAAI,IAAI;IAe5B;;OAEG;IACI,aAAa,IAAI,IAAI;IAU5B;;;OAGG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IASpC;;OAEG;IACI,OAAO,IAAI,IAAI;IAQtB;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,OAAO;CA0ClB"}
@@ -0,0 +1,246 @@
1
+ import "@babylonjs/core/Engines/Extensions/engine.alpha.js";
2
+ import "@babylonjs/core/Shaders/sprites.vertex.js";
3
+ import "@babylonjs/core/Shaders/sprites.fragment.js";
4
+ import { ThinEngine } from "@babylonjs/core/Engines/thinEngine.js";
5
+ import { Viewport } from "@babylonjs/core/Maths/math.viewport.js";
6
+ import { RenderingManager } from "./renderingManager.js";
7
+ import { Parser } from "../parsing/parser.js";
8
+ import { SpritePacker } from "../parsing/spritePacker.js";
9
+ import { ThinMatrix } from "../maths/matrix.js";
10
+ /**
11
+ * Defines the babylon combine alpha value to prevent a large import.
12
+ */
13
+ const AlphaCombine = 2;
14
+ /**
15
+ * Calculates the scale factor between a container and the animation it is playing
16
+ * @param animationWidth Width of the animaiton
17
+ * @param animationHeight Height of the animation
18
+ * @param container The container where the animation is getting played
19
+ * @returns The scale factor that will modify the size of the animation rendering to adjust to the container
20
+ */
21
+ export function CalculateScaleFactor(animationWidth, animationHeight, container) {
22
+ if (animationWidth === undefined || animationHeight === undefined) {
23
+ return 1;
24
+ }
25
+ // The size of the canvas is the relation between the size of the container div and the size of the animation
26
+ const horizontalScale = container.clientWidth / animationWidth;
27
+ const verticalScale = container.clientHeight / animationHeight;
28
+ return Math.min(verticalScale, horizontalScale);
29
+ }
30
+ /**
31
+ * Class that controls the playing of lottie animations using Babylon.js
32
+ */
33
+ export class AnimationController {
34
+ /**
35
+ * Gets the canvas used for rendering the animation.
36
+ * @returns The canvas element used for rendering.
37
+ */
38
+ get view() {
39
+ return this._engine.getRenderingCanvas();
40
+ }
41
+ /**
42
+ * Gets the height of the animation in pixels.
43
+ * @returns The height of the animation in pixels.
44
+ */
45
+ get animationHeight() {
46
+ return this._animation ? this._animation.heightPx : 0;
47
+ }
48
+ /**
49
+ * Gets the width of the animation in pixels.
50
+ * @returns The width of the animation in pixels.
51
+ */
52
+ get animationWidth() {
53
+ return this._animation ? this._animation.widthPx : 0;
54
+ }
55
+ /**
56
+ * Creates a new instance of the Player.
57
+ * @param canvas The canvas element to render the animation on.
58
+ * @param animationData The raw lottie animation as a JSON object.
59
+ * @param scaleFactor The scale factor between the animation and the container, it will modify the sprites size in the atlas
60
+ * @param variables Map of variables to replace in the animation file.
61
+ * @param configuration The configuration for the animation player.
62
+ */
63
+ constructor(canvas, animationData, scaleFactor, variables, configuration) {
64
+ this._isReady = false;
65
+ this._canvas = canvas;
66
+ this._scaleFactor = scaleFactor;
67
+ this._variables = variables;
68
+ this._configuration = configuration;
69
+ this._currentFrame = 0;
70
+ this._isPlaying = false;
71
+ this._animationFrameId = null;
72
+ this._lastFrameTime = 0;
73
+ this._deltaTime = 0;
74
+ this._accumulatedTime = 0;
75
+ this._framesToAdvance = 0;
76
+ this._loop = this._configuration.loopAnimation;
77
+ this._frameDuration = 1000 / 30; // Default to 30 FPS
78
+ this._firstRun = true;
79
+ this._engine = new ThinEngine(this._canvas, false, // Antialias
80
+ {
81
+ alpha: true,
82
+ stencil: false,
83
+ antialias: false,
84
+ audioEngine: false,
85
+ depth: false,
86
+ // Important to allow skip frame and tiled optimizations
87
+ preserveDrawingBuffer: false,
88
+ premultipliedAlpha: false,
89
+ doNotHandleContextLost: this._configuration.supportDeviceLost,
90
+ // Usefull during debug to simulate WebGL1 devices (Safari)
91
+ // disableWebGL2Support: true,
92
+ }, false);
93
+ // Prevent parallel shader compilation to simplify the boot sequence
94
+ // Only a couple of fast compile shaders.
95
+ this._engine.getCaps().parallelShaderCompile = undefined;
96
+ this._engine.depthCullingState.depthTest = false;
97
+ this._engine.stencilState.stencilTest = false;
98
+ this._engine.setAlphaMode(AlphaCombine);
99
+ this._spritePacker = new SpritePacker(this._engine, this._isHtmlCanvas(canvas), this._scaleFactor, this._variables, this._configuration);
100
+ this._renderingManager = new RenderingManager(this._engine, this._spritePacker.texture, this._configuration);
101
+ this._projectionMatrix = new ThinMatrix();
102
+ this._worldMatrix = new ThinMatrix();
103
+ this._worldMatrix.identity();
104
+ this._viewport = new Viewport(0, 0, 1, 1);
105
+ // Parse the animation
106
+ const parser = new Parser(this._spritePacker, animationData, this._configuration, this._renderingManager);
107
+ this._animation = parser.animationInfo;
108
+ this._frameDuration = 1000 / this._animation.frameRate;
109
+ this._cleanTree(this._animation.nodes);
110
+ this._setSize(animationData.w, animationData.h, this._scaleFactor);
111
+ this._isReady = true;
112
+ }
113
+ /**
114
+ * Plays the animation.
115
+ */
116
+ playAnimation() {
117
+ if (this._animation === undefined || !this._isReady) {
118
+ return;
119
+ }
120
+ this._currentFrame = 0;
121
+ this._accumulatedTime = 0;
122
+ this._framesToAdvance = 0;
123
+ this._isPlaying = true;
124
+ this._lastFrameTime = 0;
125
+ // Start the render loop
126
+ this._startRenderLoop();
127
+ }
128
+ /**
129
+ * Stops the animation playback.
130
+ */
131
+ stopAnimation() {
132
+ this._accumulatedTime = 0;
133
+ this._framesToAdvance = 0;
134
+ this._isPlaying = false;
135
+ if (this._animationFrameId !== null) {
136
+ cancelAnimationFrame(this._animationFrameId);
137
+ this._animationFrameId = null;
138
+ }
139
+ }
140
+ /**
141
+ * Sets a new scale factor for the animation and updates the rendering size.
142
+ * @param scale The new scale factor to apply to the animation.
143
+ */
144
+ setScale(scale) {
145
+ if (scale <= 0 || this._animation === undefined) {
146
+ return;
147
+ }
148
+ this._scaleFactor = scale;
149
+ this._setSize(this._animation.widthPx, this._animation.heightPx, this._scaleFactor);
150
+ }
151
+ /**
152
+ * Disposes the player and releases all resources.
153
+ */
154
+ dispose() {
155
+ this.stopAnimation();
156
+ this._engine.getRenderingCanvas()?.remove();
157
+ this._engine.dispose();
158
+ this._renderingManager.dispose();
159
+ this._spritePacker.texture.dispose();
160
+ }
161
+ /**
162
+ * Sets the rendering size for the engine
163
+ * @param width Width of the rendering canvas
164
+ * @param height Height of the rendering canvas
165
+ * @param scale Scale ratio between the container and the animation
166
+ */
167
+ _setSize(width, height, scale) {
168
+ const { _engine, _projectionMatrix, _worldMatrix } = this;
169
+ const devicePixelRatio = this._configuration.devicePixelRatio;
170
+ _engine.setSize(width * scale * devicePixelRatio, height * scale * devicePixelRatio);
171
+ const world = _worldMatrix.asArray();
172
+ world[5] = -1; // we are upside down with Lottie
173
+ _projectionMatrix.orthoOffCenterLeftHanded(0, _engine.getRenderWidth() / (devicePixelRatio * scale), _engine.getRenderHeight() / (devicePixelRatio * scale), 0, -100, 100);
174
+ }
175
+ _isHtmlCanvas(canvas) {
176
+ return typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement;
177
+ }
178
+ _cleanTree(nodes) {
179
+ // Remove non shape nodes
180
+ for (let i = 0; i < nodes.length; i++) {
181
+ const node = nodes[i];
182
+ if (node.children.length === 0 && !node.isShape) {
183
+ nodes.splice(i, 1);
184
+ i--;
185
+ continue;
186
+ }
187
+ this._cleanTree(node.children);
188
+ }
189
+ }
190
+ _startRenderLoop() {
191
+ if (!this._isPlaying) {
192
+ return;
193
+ }
194
+ this._animationFrameId = requestAnimationFrame((currentTime) => {
195
+ // The first time we render, we set the last frame time
196
+ // to the current time to sync with the page startup time
197
+ if (this._firstRun) {
198
+ this._lastFrameTime = currentTime;
199
+ this._firstRun = false;
200
+ }
201
+ this._deltaTime = currentTime - this._lastFrameTime;
202
+ this._lastFrameTime = currentTime;
203
+ this._render();
204
+ this._lastFrameTime = performance.now();
205
+ // Continue the loop if still playing
206
+ if (this._isPlaying) {
207
+ this._startRenderLoop();
208
+ }
209
+ });
210
+ }
211
+ _render() {
212
+ if (!this._animation || !this._isPlaying) {
213
+ return;
214
+ }
215
+ this._engine.setViewport(this._viewport);
216
+ // Calculate the new frame based on time
217
+ this._accumulatedTime += this._deltaTime;
218
+ this._framesToAdvance = Math.floor(this._accumulatedTime / this._frameDuration);
219
+ if (this._framesToAdvance <= 0) {
220
+ return;
221
+ }
222
+ this._accumulatedTime -= this._framesToAdvance * this._frameDuration;
223
+ this._currentFrame += this._framesToAdvance;
224
+ if (this._currentFrame < this._animation.startFrame) {
225
+ return;
226
+ }
227
+ if (this._currentFrame > this._animation.endFrame) {
228
+ if (this._loop) {
229
+ this._currentFrame = (this._currentFrame % (this._animation.endFrame - this._animation.startFrame)) + this._animation.startFrame;
230
+ for (let i = 0; i < this._animation.nodes.length; i++) {
231
+ this._animation.nodes[i].reset();
232
+ }
233
+ }
234
+ else {
235
+ this._isPlaying = false;
236
+ return;
237
+ }
238
+ }
239
+ for (let i = 0; i < this._animation.nodes.length; i++) {
240
+ this._animation.nodes[i].update(this._currentFrame);
241
+ }
242
+ // Render all layers of the animation
243
+ this._renderingManager.render(this._worldMatrix, this._projectionMatrix);
244
+ }
245
+ }
246
+ //# sourceMappingURL=animationController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animationController.js","sourceRoot":"","sources":["../../../../dev/lottiePlayer/src/rendering/animationController.ts"],"names":[],"mappings":"AAAA,4DAA8C;AAC9C,mDAAqC;AACrC,qDAAuC;AAEvC,OAAO,EAAE,UAAU,EAAE,8CAAgC;AACrD,OAAO,EAAE,QAAQ,EAAE,+CAAiC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,cAAkC,EAAE,eAAmC,EAAE,SAAsB;IAChI,IAAI,cAAc,KAAK,SAAS,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAChE,OAAO,CAAC,CAAC;IACb,CAAC;IAED,6GAA6G;IAC7G,MAAM,eAAe,GAAG,SAAS,CAAC,WAAW,GAAG,cAAc,CAAC;IAC/D,MAAM,aAAa,GAAG,SAAS,CAAC,YAAY,GAAG,eAAe,CAAC;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,mBAAmB;IA8B5B;;;OAGG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAG,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc;QACrB,OAAO,IA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GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACxD,CAAC;QAED,qCAAqC;QACrC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC7E,CAAC;CACJ"}
@@ -0,0 +1,46 @@
1
+ import "@babylonjs/core/Engines/Extensions/engine.dynamicBuffer.js";
2
+ import "@babylonjs/core/Shaders/sprites.vertex.js";
3
+ import "@babylonjs/core/Shaders/sprites.fragment.js";
4
+ import type { ThinEngine } from "@babylonjs/core/Engines/thinEngine.js";
5
+ import type { ThinTexture } from "@babylonjs/core/Materials/Textures/thinTexture.js";
6
+ import type { ThinSprite } from "@babylonjs/core/Sprites/thinSprite.js";
7
+ import type { ThinMatrix } from "../maths/matrix.js";
8
+ import type { AnimationConfiguration } from "../animationConfiguration.js";
9
+ /**
10
+ * Represents all the sprites from the animation and manages their rendering.
11
+ */
12
+ export declare class RenderingManager {
13
+ private readonly _engine;
14
+ private readonly _spritesRenderer;
15
+ private readonly _spritesTexture;
16
+ private _sprites;
17
+ private readonly _configuration;
18
+ /**
19
+ * Creates a new instance of the RenderingManager.
20
+ * @param engine ThinEngine instance used for rendering.
21
+ * @param spriteTexture The texture atlas containing the sprites.
22
+ * @param configuration Configuration options for the rendering manager.
23
+ */
24
+ constructor(engine: ThinEngine, spriteTexture: ThinTexture, configuration: AnimationConfiguration);
25
+ /**
26
+ * Adds a sprite to the rendering manager.
27
+ * @param sprite Sprite to add to the rendering manager.
28
+ */
29
+ addSprite(sprite: ThinSprite): void;
30
+ /**
31
+ * Prepares the rendering manager for rendering.
32
+ */
33
+ ready(): void;
34
+ /**
35
+ * Renders all the sprites in the rendering manager.
36
+ * @param worldMatrix World matrix to apply to the sprites.
37
+ * @param projectionMatrix Projection matrix to apply to the sprites.
38
+ */
39
+ render(worldMatrix: ThinMatrix, projectionMatrix: ThinMatrix): void;
40
+ /**
41
+ * Disposes the rendering manager and its resources.
42
+ */
43
+ dispose(): void;
44
+ private _customSpriteUpdate;
45
+ }
46
+ //# sourceMappingURL=renderingManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderingManager.d.ts","sourceRoot":"","sources":["../../../../dev/lottiePlayer/src/rendering/renderingManager.ts"],"names":[],"mappings":"AAAA,oEAAsD;AACtD,mDAAqC;AACrC,qDAAuC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,8CAAgC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,0DAA4C;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,8CAAgC;AAG1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE;;GAEG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAiB;IAClD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAc;IAC9C,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;IAExD;;;;;OAKG;gBACgB,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,sBAAsB;IAaxG;;;OAGG;IACI,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAI1C;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB;;;;OAIG;IACI,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,GAAG,IAAI;IAK1E;;OAEG;IACI,OAAO,IAAI,IAAI;IAMtB,OAAO,CAAC,mBAAmB,CAGzB;CACL"}
@@ -0,0 +1,61 @@
1
+ import "@babylonjs/core/Engines/Extensions/engine.dynamicBuffer.js";
2
+ import "@babylonjs/core/Shaders/sprites.vertex.js";
3
+ import "@babylonjs/core/Shaders/sprites.fragment.js";
4
+ import { SpriteRenderer } from "@babylonjs/core/Sprites/spriteRenderer.js";
5
+ /**
6
+ * Represents all the sprites from the animation and manages their rendering.
7
+ */
8
+ export class RenderingManager {
9
+ /**
10
+ * Creates a new instance of the RenderingManager.
11
+ * @param engine ThinEngine instance used for rendering.
12
+ * @param spriteTexture The texture atlas containing the sprites.
13
+ * @param configuration Configuration options for the rendering manager.
14
+ */
15
+ constructor(engine, spriteTexture, configuration) {
16
+ this._customSpriteUpdate = () => {
17
+ // All the work is done upfront within the sprite render
18
+ // so that we do not need babylon to update back the information
19
+ };
20
+ this._engine = engine;
21
+ this._spritesTexture = spriteTexture;
22
+ this._sprites = [];
23
+ this._configuration = configuration;
24
+ this._spritesRenderer = new SpriteRenderer(this._engine, this._configuration.spritesCapacity, 0);
25
+ this._spritesRenderer.disableDepthWrite = true;
26
+ this._spritesRenderer.autoResetAlpha = false;
27
+ this._spritesRenderer.fogEnabled = false;
28
+ this._spritesRenderer.texture = this._spritesTexture;
29
+ }
30
+ /**
31
+ * Adds a sprite to the rendering manager.
32
+ * @param sprite Sprite to add to the rendering manager.
33
+ */
34
+ addSprite(sprite) {
35
+ this._sprites.push(sprite);
36
+ }
37
+ /**
38
+ * Prepares the rendering manager for rendering.
39
+ */
40
+ ready() {
41
+ this._sprites = this._sprites.reverse();
42
+ }
43
+ /**
44
+ * Renders all the sprites in the rendering manager.
45
+ * @param worldMatrix World matrix to apply to the sprites.
46
+ * @param projectionMatrix Projection matrix to apply to the sprites.
47
+ */
48
+ render(worldMatrix, projectionMatrix) {
49
+ this._engine.clear(this._configuration.backgroundColor, true, false, false);
50
+ this._spritesRenderer.render(this._sprites, 0, worldMatrix, projectionMatrix, this._customSpriteUpdate);
51
+ }
52
+ /**
53
+ * Disposes the rendering manager and its resources.
54
+ */
55
+ dispose() {
56
+ this._sprites.length = 0;
57
+ this._spritesRenderer.texture = null; // Prevent disposal of the shared texture atlas.
58
+ this._spritesRenderer.dispose();
59
+ }
60
+ }
61
+ //# sourceMappingURL=renderingManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderingManager.js","sourceRoot":"","sources":["../../../../dev/lottiePlayer/src/rendering/renderingManager.ts"],"names":[],"mappings":"AAAA,oEAAsD;AACtD,mDAAqC;AACrC,qDAAuC;AAKvC,OAAO,EAAE,cAAc,EAAE,kDAAoC;AAM7D;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAOzB;;;;;OAKG;IACH,YAAmB,MAAkB,EAAE,aAA0B,EAAE,aAAqC;QA+ChG,wBAAmB,GAAG,GAAS,EAAE;YACrC,wDAAwD;YACxD,gEAAgE;QACpE,CAAC,CAAC;QAjDE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,eAAe,GAAG,aAAa,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QAEpC,IAAI,CAAC,gBAAgB,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;QACjG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC/C,IAAI,CAAC,gBAAgB,CAAC,cAAc,GAAG,KAAK,CAAC;QAC7C,IAAI,CAAC,gBAAgB,CAAC,UAAU,GAAG,KAAK,CAAC;QACzC,IAAI,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC;IACzD,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,MAAkB;QAC/B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,KAAK;QACR,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAuB,EAAE,gBAA4B;QAC/D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5E,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC5G,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,gDAAgD;QACtF,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC;CAMJ"}
package/worker.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/worker.ts"],"names":[],"mappings":""}
package/worker.js ADDED
@@ -0,0 +1,62 @@
1
+ let RawAnimation = null;
2
+ // Use any type to avoid importing the class at module scope
3
+ // eslint-disable @typescript-eslint/no-explicit-any
4
+ let Controller = null;
5
+ let AnimationPromises = null;
6
+ // eslint-enable @typescript-eslint/no-explicit-any
7
+ onmessage = async function (evt) {
8
+ const message = evt.data;
9
+ if (message === undefined) {
10
+ return;
11
+ }
12
+ switch (message.type) {
13
+ case "animationUrl": {
14
+ const payload = message.payload;
15
+ const { GetRawAnimationDataAsync } = await import("./parsing/parser.js");
16
+ // Fire the promises to load the code so we can do it while we fetch the file and go back to the main thread
17
+ AnimationPromises = Promise.all([import("./animationConfiguration.js"), import("./rendering/animationController.js")]);
18
+ RawAnimation = await GetRawAnimationDataAsync(payload.url);
19
+ // Send this information back to the main thread so it can size the canvas correctly
20
+ const sizeMessage = {
21
+ type: "animationSize",
22
+ payload: {
23
+ width: RawAnimation.w,
24
+ height: RawAnimation.h,
25
+ },
26
+ };
27
+ postMessage(sizeMessage);
28
+ break;
29
+ }
30
+ case "startAnimation": {
31
+ if (RawAnimation === null) {
32
+ return;
33
+ }
34
+ const payload = message.payload;
35
+ const [{ DefaultConfiguration }, { AnimationController }] = await AnimationPromises;
36
+ const canvas = payload.canvas;
37
+ const scaleFactor = payload.scaleFactor;
38
+ const variables = payload.variables ?? new Map();
39
+ const originalConfig = payload.configuration ?? {};
40
+ const finalConfig = {
41
+ ...DefaultConfiguration,
42
+ ...originalConfig,
43
+ };
44
+ Controller = new AnimationController(canvas, RawAnimation, scaleFactor, variables, finalConfig);
45
+ Controller.playAnimation();
46
+ break;
47
+ }
48
+ case "containerResize": {
49
+ if (Controller === null) {
50
+ return;
51
+ }
52
+ const payload = message.payload;
53
+ const scaleFactor = payload.scaleFactor;
54
+ Controller.setScale(scaleFactor);
55
+ break;
56
+ }
57
+ default:
58
+ return;
59
+ }
60
+ };
61
+ export {};
62
+ //# sourceMappingURL=worker.js.map
package/worker.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/worker.ts"],"names":[],"mappings":"AAMA,IAAI,YAAY,GAAiC,IAAI,CAAC;AACtD,4DAA4D;AAC5D,oDAAoD;AACpD,IAAI,UAAU,GAAkB,IAAI,CAAC;AACrC,IAAI,iBAAiB,GAAQ,IAAI,CAAC;AAClC,mDAAmD;AAEnD,SAAS,GAAG,KAAK,WAAW,GAAG;IAC3B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAe,CAAC;IACpC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO;IACX,C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