@babylonjs/addons 8.22.2 → 8.23.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/lottie/index.d.ts +1 -0
- package/lottie/index.js +3 -0
- package/lottie/index.js.map +1 -0
- package/lottie/lottie/animationParser.d.ts +47 -0
- package/lottie/lottie/animationParser.js +368 -0
- package/lottie/lottie/animationParser.js.map +1 -0
- package/lottie/lottie/parsedTypes.d.ts +140 -0
- package/lottie/lottie/parsedTypes.js +2 -0
- package/lottie/lottie/parsedTypes.js.map +1 -0
- package/lottie/lottie/rawTypes.d.ts +152 -0
- package/lottie/lottie/rawTypes.js +4 -0
- package/lottie/lottie/rawTypes.js.map +1 -0
- package/lottie/lottiePlayer.d.ts +92 -0
- package/lottie/lottiePlayer.js +101 -0
- package/lottie/lottiePlayer.js.map +1 -0
- package/lottie/maths/bezier.d.ts +44 -0
- package/lottie/maths/bezier.js +53 -0
- package/lottie/maths/bezier.js.map +1 -0
- package/lottie/maths/boundingBox.d.ts +28 -0
- package/lottie/maths/boundingBox.js +155 -0
- package/lottie/maths/boundingBox.js.map +1 -0
- package/lottie/maths/matrix.d.ts +91 -0
- package/lottie/maths/matrix.js +174 -0
- package/lottie/maths/matrix.js.map +1 -0
- package/lottie/rendering/animationController.d.ts +72 -0
- package/lottie/rendering/animationController.js +210 -0
- package/lottie/rendering/animationController.js.map +1 -0
- package/lottie/rendering/controlNode.d.ts +32 -0
- package/lottie/rendering/controlNode.js +39 -0
- package/lottie/rendering/controlNode.js.map +1 -0
- package/lottie/rendering/node.d.ts +97 -0
- package/lottie/rendering/node.js +331 -0
- package/lottie/rendering/node.js.map +1 -0
- package/lottie/rendering/renderingManager.d.ts +45 -0
- package/lottie/rendering/renderingManager.js +61 -0
- package/lottie/rendering/renderingManager.js.map +1 -0
- package/lottie/sprites/spriteNode.d.ts +32 -0
- package/lottie/sprites/spriteNode.js +52 -0
- package/lottie/sprites/spriteNode.js.map +1 -0
- package/lottie/sprites/spritePacker.d.ts +101 -0
- package/lottie/sprites/spritePacker.js +237 -0
- package/lottie/sprites/spritePacker.js.map +1 -0
- package/lottie/worker.d.ts +1 -0
- package/lottie/worker.js +39 -0
- package/lottie/worker.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the bounding box for a group shape in a Lottie animation.
|
|
3
|
+
* @param rawGroup The raw group shape to calculate the bounding box for
|
|
4
|
+
* @returns The bounding box for the group shape
|
|
5
|
+
*/
|
|
6
|
+
export function GetBoundingBox(rawGroup) {
|
|
7
|
+
const boxCorners = {
|
|
8
|
+
minX: Infinity,
|
|
9
|
+
minY: Infinity,
|
|
10
|
+
maxX: -Infinity,
|
|
11
|
+
maxY: -Infinity,
|
|
12
|
+
};
|
|
13
|
+
if (rawGroup.it !== undefined) {
|
|
14
|
+
for (let i = 0; i < rawGroup.it.length; i++) {
|
|
15
|
+
if (rawGroup.it[i].ty === "rc") {
|
|
16
|
+
GetRectangleVertices(boxCorners, rawGroup.it[i]);
|
|
17
|
+
}
|
|
18
|
+
else if (rawGroup.it[i].ty === "sh") {
|
|
19
|
+
GetPathVertices(boxCorners, rawGroup.it[i]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
width: Math.ceil(boxCorners.maxX - boxCorners.minX),
|
|
25
|
+
height: Math.ceil(boxCorners.maxY - boxCorners.minY),
|
|
26
|
+
centerX: Math.ceil((boxCorners.maxX + boxCorners.minX) / 2),
|
|
27
|
+
centerY: Math.ceil((boxCorners.maxY + boxCorners.minY) / 2),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function GetRectangleVertices(boxCorners, rect) {
|
|
31
|
+
const size = rect.s.k;
|
|
32
|
+
const position = rect.p.k;
|
|
33
|
+
// Calculate the four corners of the rectangle
|
|
34
|
+
UpdateBoxCorners(boxCorners, position[0] - size[0] / 2, position[1] - size[1] / 2);
|
|
35
|
+
UpdateBoxCorners(boxCorners, position[0] + size[0] / 2, position[1] - size[1] / 2);
|
|
36
|
+
UpdateBoxCorners(boxCorners, position[0] + size[0] / 2, position[1] + size[1] / 2);
|
|
37
|
+
UpdateBoxCorners(boxCorners, position[0] - size[0] / 2, position[1] + size[1] / 2);
|
|
38
|
+
}
|
|
39
|
+
function GetPathVertices(boxCorners, path) {
|
|
40
|
+
const bezier = path.ks.k;
|
|
41
|
+
const vertices = bezier.v;
|
|
42
|
+
const inTangents = bezier.i;
|
|
43
|
+
const outTangents = bezier.o;
|
|
44
|
+
// Check the control points of the path
|
|
45
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
46
|
+
UpdateBoxCorners(boxCorners, vertices[i][0], vertices[i][1]);
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
49
|
+
// Skip last point if the path is not closed
|
|
50
|
+
if (!bezier.c && i === vertices.length - 1) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const start = vertices[i];
|
|
54
|
+
const end = i === vertices.length - 1 ? vertices[0] : vertices[i + 1];
|
|
55
|
+
const outTangent = outTangents[i];
|
|
56
|
+
const inTangent = i === vertices.length - 1 ? inTangents[0] : inTangents[i + 1];
|
|
57
|
+
// Calculate the points where the tangent is zero
|
|
58
|
+
CalculatePointsWithTangentZero(boxCorners, start[0], start[1], end[0], end[1], start[0] + outTangent[0], start[1] + outTangent[1], end[0] + inTangent[0], end[1] + inTangent[1]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function CalculatePointsWithTangentZero(boxCorners, startX, startY, endX, endY, controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y) {
|
|
62
|
+
// Calculate the derivative of the bezier formula for X and Y components
|
|
63
|
+
// For X component:
|
|
64
|
+
const ax = 3 * (endX - 3 * controlPoint2X + 3 * controlPoint1X - startX);
|
|
65
|
+
const bx = 6 * (controlPoint2X - 2 * controlPoint1X + startX);
|
|
66
|
+
const cx = 3 * (controlPoint1X - startX);
|
|
67
|
+
// For Y component:
|
|
68
|
+
const ay = 3 * (endY - 3 * controlPoint2Y + 3 * controlPoint1Y - startY);
|
|
69
|
+
const by = 6 * (controlPoint2Y - 2 * controlPoint1Y + startY);
|
|
70
|
+
const cy = 3 * (controlPoint1Y - startY);
|
|
71
|
+
// Solve the quadratic equation where dt/dt = 0 (tangent is zero)
|
|
72
|
+
const rootsX = SolveQuadratic(ax, bx, cx);
|
|
73
|
+
const rootsY = SolveQuadratic(ay, by, cy);
|
|
74
|
+
// Merge + dedupe (roots arrays are tiny: <=2 each)
|
|
75
|
+
const candidateTs = rootsX.slice(); // copy
|
|
76
|
+
for (let i = 0; i < rootsY.length; i++) {
|
|
77
|
+
const ty = rootsY[i];
|
|
78
|
+
let exists = false;
|
|
79
|
+
for (let j = 0; j < candidateTs.length; j++) {
|
|
80
|
+
if (candidateTs[j] === ty) {
|
|
81
|
+
exists = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!exists) {
|
|
86
|
+
candidateTs.push(ty);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Evaluate the bezier at the calculated t values to find the points of the curve where the tangent is zero
|
|
90
|
+
for (let i = 0; i < candidateTs.length; i++) {
|
|
91
|
+
const t = candidateTs[i];
|
|
92
|
+
if (t >= 0 && t <= 1) {
|
|
93
|
+
const x = BezierPoint(t, startX, controlPoint1X, controlPoint2X, endX);
|
|
94
|
+
const y = BezierPoint(t, startY, controlPoint1Y, controlPoint2Y, endY);
|
|
95
|
+
UpdateBoxCorners(boxCorners, x, y);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Alternative implementation for bounding box calculation using sampling of the bezier curve instead of finding points where the tangent is zero.
|
|
100
|
+
// function bezierBoundingBoxSampled(boxCorners: Corners, start:IVector2Like, outTangent:IVector2Like, inTangent:IVector2Like, end:IVector2Like) {
|
|
101
|
+
// for (let i = 0; i <= SamplingSteps; i++) {
|
|
102
|
+
// const t = i / SamplingSteps;
|
|
103
|
+
// const x = bezierPoint(t, start.x, outTangent.x, inTangent.x, end.x);
|
|
104
|
+
// const y = bezierPoint(t, start.y, outTangent.y, inTangent.y, end.y);
|
|
105
|
+
// updateBoxCorners(boxCorners, x, y);
|
|
106
|
+
// }
|
|
107
|
+
// }
|
|
108
|
+
function SolveQuadratic(a, b, c) {
|
|
109
|
+
const roots = [];
|
|
110
|
+
// Handle the case where a is zero (linear equation)
|
|
111
|
+
// Linear equation: bx + c = 0 => x = -c / b
|
|
112
|
+
if (Math.abs(a) < 1e-10) {
|
|
113
|
+
if (Math.abs(b) > 1e-10) {
|
|
114
|
+
const root = -c / b;
|
|
115
|
+
roots.push(root);
|
|
116
|
+
}
|
|
117
|
+
return roots;
|
|
118
|
+
}
|
|
119
|
+
// Solve the quadratic equation ax^2 + bx + c = 0
|
|
120
|
+
const discriminant = b * b - 4 * a * c;
|
|
121
|
+
if (discriminant < 0) {
|
|
122
|
+
return roots; // No real roots
|
|
123
|
+
}
|
|
124
|
+
if (Math.abs(discriminant) < 1e-10) {
|
|
125
|
+
const root = -b / (2 * a);
|
|
126
|
+
roots.push(root);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const sqrtD = Math.sqrt(discriminant);
|
|
130
|
+
const root1 = (-b + sqrtD) / (2 * a);
|
|
131
|
+
const root2 = (-b - sqrtD) / (2 * a);
|
|
132
|
+
roots.push(root1);
|
|
133
|
+
roots.push(root2);
|
|
134
|
+
}
|
|
135
|
+
return roots;
|
|
136
|
+
}
|
|
137
|
+
function BezierPoint(t, p0, p1, p2, p3) {
|
|
138
|
+
const mt = 1 - t;
|
|
139
|
+
return mt * mt * mt * p0 + 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t * p3;
|
|
140
|
+
}
|
|
141
|
+
function UpdateBoxCorners(boxCorners, x, y) {
|
|
142
|
+
if (x < boxCorners.minX) {
|
|
143
|
+
boxCorners.minX = x;
|
|
144
|
+
}
|
|
145
|
+
if (x > boxCorners.maxX) {
|
|
146
|
+
boxCorners.maxX = x;
|
|
147
|
+
}
|
|
148
|
+
if (y < boxCorners.minY) {
|
|
149
|
+
boxCorners.minY = y;
|
|
150
|
+
}
|
|
151
|
+
if (y > boxCorners.maxY) {
|
|
152
|
+
boxCorners.maxY = y;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=boundingBox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundingBox.js","sourceRoot":"","sources":["../../../../../dev/addons/src/lottie/maths/boundingBox.ts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAuB;IAClD,MAAM,UAAU,GAAY;QACxB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,CAAC,QAAQ;QACf,IAAI,EAAE,CAAC,QAAQ;KAClB,CAAC;IAEF,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;gBAC7B,oBAAoB,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAsB,CAAC,CAAC;YAC1E,CAAC;iBAAM,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;gBACpC,eAAe,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAiB,CAAC,CAAC;YAChE,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO;QACH,KAAK,EAAE,IAAI,CAAC,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ents a bounding box for a shape in the animation.\r\n */\r\nexport type BoundingBox = {\r\n /**\r\n * Height of the bounding box\r\n */\r\n height: number;\r\n /**\r\n * Width of the bounding box\r\n */\r\n width: number;\r\n /**\r\n * X coordinate of the center of the bounding box\r\n */\r\n centerX: number;\r\n /**\r\n * Y coordinate of the center of the bounding box\r\n */\r\n centerY: number;\r\n};\r\n\r\n// Corners of the bounding box\r\ntype Corners = {\r\n minX: number;\r\n minY: number;\r\n maxX: number;\r\n maxY: number;\r\n};\r\n\r\n/**\r\n * Calculates the bounding box for a group shape in a Lottie animation.\r\n * @param rawGroup The raw group shape to calculate the bounding box for\r\n * @returns The bounding box for the group shape\r\n */\r\nexport function GetBoundingBox(rawGroup: RawGroupShape): BoundingBox {\r\n const boxCorners: Corners = {\r\n minX: Infinity,\r\n minY: Infinity,\r\n maxX: -Infinity,\r\n maxY: -Infinity,\r\n };\r\n\r\n if (rawGroup.it !== undefined) {\r\n for (let i = 0; i < rawGroup.it.length; i++) {\r\n if (rawGroup.it[i].ty === \"rc\") {\r\n GetRectangleVertices(boxCorners, rawGroup.it[i] as RawRectangleShape);\r\n } else if (rawGroup.it[i].ty === \"sh\") {\r\n GetPathVertices(boxCorners, rawGroup.it[i] as RawPathShape);\r\n }\r\n }\r\n }\r\n\r\n return {\r\n width: Math.ceil(boxCorners.maxX - boxCorners.minX),\r\n height: Math.ceil(boxCorners.maxY - boxCorners.minY),\r\n centerX: Math.ceil((boxCorners.maxX + boxCorners.minX) / 2),\r\n centerY: Math.ceil((boxCorners.maxY + boxCorners.minY) / 2),\r\n };\r\n}\r\n\r\nfunction GetRectangleVertices(boxCorners: Corners, rect: RawRectangleShape): void {\r\n const size = rect.s.k as number[];\r\n const position = rect.p.k as number[];\r\n\r\n // Calculate the four corners of the rectangle\r\n UpdateBoxCorners(boxCorners, position[0] - size[0] / 2, position[1] - size[1] / 2);\r\n UpdateBoxCorners(boxCorners, position[0] + size[0] / 2, position[1] - size[1] / 2);\r\n UpdateBoxCorners(boxCorners, position[0] + size[0] / 2, position[1] + size[1] / 2);\r\n UpdateBoxCorners(boxCorners, position[0] - size[0] / 2, position[1] + size[1] / 2);\r\n}\r\n\r\nfunction GetPathVertices(boxCorners: Corners, path: RawPathShape): void {\r\n const bezier = path.ks.k as RawBezier;\r\n const vertices = bezier.v;\r\n const inTangents = bezier.i;\r\n const outTangents = bezier.o;\r\n\r\n // Check the control points of the path\r\n for (let i = 0; i < vertices.length; i++) {\r\n UpdateBoxCorners(boxCorners, vertices[i][0], vertices[i][1]);\r\n }\r\n\r\n for (let i = 0; i < vertices.length; i++) {\r\n // Skip last point if the path is not closed\r\n if (!bezier.c && i === vertices.length - 1) {\r\n continue;\r\n }\r\n\r\n const start = vertices[i];\r\n const end = i === vertices.length - 1 ? vertices[0] : vertices[i + 1];\r\n const outTangent = outTangents[i];\r\n const inTangent = i === vertices.length - 1 ? inTangents[0] : inTangents[i + 1];\r\n\r\n // Calculate the points where the tangent is zero\r\n CalculatePointsWithTangentZero(\r\n boxCorners,\r\n start[0],\r\n start[1],\r\n end[0],\r\n end[1],\r\n start[0] + outTangent[0],\r\n start[1] + outTangent[1],\r\n end[0] + inTangent[0],\r\n end[1] + inTangent[1]\r\n );\r\n }\r\n}\r\n\r\nfunction CalculatePointsWithTangentZero(\r\n boxCorners: Corners,\r\n startX: number,\r\n startY: number,\r\n endX: number,\r\n endY: number,\r\n controlPoint1X: number,\r\n controlPoint1Y: number,\r\n controlPoint2X: number,\r\n controlPoint2Y: number\r\n): void {\r\n // Calculate the derivative of the bezier formula for X and Y components\r\n // For X component:\r\n const ax = 3 * (endX - 3 * controlPoint2X + 3 * controlPoint1X - startX);\r\n const bx = 6 * (controlPoint2X - 2 * controlPoint1X + startX);\r\n const cx = 3 * (controlPoint1X - startX);\r\n\r\n // For Y component:\r\n const ay = 3 * (endY - 3 * controlPoint2Y + 3 * controlPoint1Y - startY);\r\n const by = 6 * (controlPoint2Y - 2 * controlPoint1Y + startY);\r\n const cy = 3 * (controlPoint1Y - startY);\r\n\r\n // Solve the quadratic equation where dt/dt = 0 (tangent is zero)\r\n const rootsX = SolveQuadratic(ax, bx, cx);\r\n const rootsY = SolveQuadratic(ay, by, cy);\r\n\r\n // Merge + dedupe (roots arrays are tiny: <=2 each)\r\n const candidateTs = rootsX.slice(); // copy\r\n for (let i = 0; i < rootsY.length; i++) {\r\n const ty = rootsY[i];\r\n let exists = false;\r\n for (let j = 0; j < candidateTs.length; j++) {\r\n if (candidateTs[j] === ty) {\r\n exists = true;\r\n break;\r\n }\r\n }\r\n if (!exists) {\r\n candidateTs.push(ty);\r\n }\r\n }\r\n\r\n // Evaluate the bezier at the calculated t values to find the points of the curve where the tangent is zero\r\n for (let i = 0; i < candidateTs.length; i++) {\r\n const t = candidateTs[i];\r\n if (t >= 0 && t <= 1) {\r\n const x = BezierPoint(t, startX, controlPoint1X, controlPoint2X, endX);\r\n const y = BezierPoint(t, startY, controlPoint1Y, controlPoint2Y, endY);\r\n UpdateBoxCorners(boxCorners, x, y);\r\n }\r\n }\r\n}\r\n\r\n// Alternative implementation for bounding box calculation using sampling of the bezier curve instead of finding points where the tangent is zero.\r\n// function bezierBoundingBoxSampled(boxCorners: Corners, start:IVector2Like, outTangent:IVector2Like, inTangent:IVector2Like, end:IVector2Like) {\r\n// for (let i = 0; i <= SamplingSteps; i++) {\r\n// const t = i / SamplingSteps;\r\n\r\n// const x = bezierPoint(t, start.x, outTangent.x, inTangent.x, end.x);\r\n// const y = bezierPoint(t, start.y, outTangent.y, inTangent.y, end.y);\r\n// updateBoxCorners(boxCorners, x, y);\r\n// }\r\n// }\r\n\r\nfunction SolveQuadratic(a: number, b: number, c: number): number[] {\r\n const roots: number[] = [];\r\n\r\n // Handle the case where a is zero (linear equation)\r\n // Linear equation: bx + c = 0 => x = -c / b\r\n if (Math.abs(a) < 1e-10) {\r\n if (Math.abs(b) > 1e-10) {\r\n const root = -c / b;\r\n roots.push(root);\r\n }\r\n\r\n return roots;\r\n }\r\n\r\n // Solve the quadratic equation ax^2 + bx + c = 0\r\n const discriminant = b * b - 4 * a * c;\r\n if (discriminant < 0) {\r\n return roots; // No real roots\r\n }\r\n\r\n if (Math.abs(discriminant) < 1e-10) {\r\n const root = -b / (2 * a);\r\n roots.push(root);\r\n } else {\r\n const sqrtD = Math.sqrt(discriminant);\r\n const root1 = (-b + sqrtD) / (2 * a);\r\n const root2 = (-b - sqrtD) / (2 * a);\r\n roots.push(root1);\r\n roots.push(root2);\r\n }\r\n\r\n return roots;\r\n}\r\n\r\nfunction BezierPoint(t: number, p0: number, p1: number, p2: number, p3: number): number {\r\n const mt = 1 - t;\r\n return mt * mt * mt * p0 + 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t * p3;\r\n}\r\n\r\nfunction UpdateBoxCorners(boxCorners: Corners, x: number, y: number): void {\r\n if (x < boxCorners.minX) {\r\n boxCorners.minX = x;\r\n }\r\n if (x > boxCorners.maxX) {\r\n boxCorners.maxX = x;\r\n }\r\n if (y < boxCorners.minY) {\r\n boxCorners.minY = y;\r\n }\r\n if (y > boxCorners.maxY) {\r\n boxCorners.maxY = y;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { IMatrixLike, IVector2Like } from "@babylonjs/core/Maths/math.like.js";
|
|
2
|
+
import type { Tuple } from "@babylonjs/core/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Babylon.js thin version of a Matrix
|
|
5
|
+
* We are only exposing what we truly need in the scope of
|
|
6
|
+
* the Lottie Renderer project preventing the dependency on the full
|
|
7
|
+
* Babylon.js math system.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ThinMatrix implements IMatrixLike {
|
|
10
|
+
/**
|
|
11
|
+
* Prevents global conflicts on update as shader programs are shared.
|
|
12
|
+
*/
|
|
13
|
+
private static _UPDATE_FLAG_SEED;
|
|
14
|
+
/**
|
|
15
|
+
* Current update flag used to know whether a Matrix has changed since previous render or not.
|
|
16
|
+
* This helps identifying if a Matrix needs to be
|
|
17
|
+
* uploaded to a shader program.
|
|
18
|
+
*/
|
|
19
|
+
updateFlag: number;
|
|
20
|
+
private readonly _data;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new ThinMatrix instance.
|
|
23
|
+
*/
|
|
24
|
+
constructor();
|
|
25
|
+
/**
|
|
26
|
+
* Set the matrix values.
|
|
27
|
+
* @param m11 Value for row 1, column 1
|
|
28
|
+
* @param m12 Value for row 1, column 2
|
|
29
|
+
* @param m13 Value for row 1, column 3
|
|
30
|
+
* @param m14 Value for row 1, column 4
|
|
31
|
+
* @param m21 Value for row 2, column 1
|
|
32
|
+
* @param m22 Value for row 2, column 2
|
|
33
|
+
* @param m23 Value for row 2, column 3
|
|
34
|
+
* @param m24 Value for row 2, column 4
|
|
35
|
+
* @param m31 Value for row 3, column 1
|
|
36
|
+
* @param m32 Value for row 3, column 2
|
|
37
|
+
* @param m33 Value for row 3, column 3
|
|
38
|
+
* @param m34 Value for row 3, column 4
|
|
39
|
+
* @param m41 Value for row 4, column 1
|
|
40
|
+
* @param m42 Value for row 4, column 2
|
|
41
|
+
* @param m43 Value for row 4, column 3
|
|
42
|
+
* @param m44 Value for row 4, column 4
|
|
43
|
+
* @returns The updated ThinMatrix instance
|
|
44
|
+
*/
|
|
45
|
+
setValues(m11: number, m12: number, m13: number, m14: number, m21: number, m22: number, m23: number, m24: number, m31: number, m32: number, m33: number, m34: number, m41: number, m42: number, m43: number, m44: number): ThinMatrix;
|
|
46
|
+
/**
|
|
47
|
+
* Set the matrix to an identity matrix.
|
|
48
|
+
* @returns The updated ThinMatrix instance
|
|
49
|
+
*/
|
|
50
|
+
identity(): ThinMatrix;
|
|
51
|
+
/**
|
|
52
|
+
* Stores a left-handed orthographic projection into a given matrix
|
|
53
|
+
* @param left defines the viewport left coordinate
|
|
54
|
+
* @param right defines the viewport right coordinate
|
|
55
|
+
* @param bottom defines the viewport bottom coordinate
|
|
56
|
+
* @param top defines the viewport top coordinate
|
|
57
|
+
* @param znear defines the near clip plane
|
|
58
|
+
* @param zfar defines the far clip plane
|
|
59
|
+
* @returns The updated ThinMatrix instance
|
|
60
|
+
*/
|
|
61
|
+
orthoOffCenterLeftHanded(left: number, right: number, bottom: number, top: number, znear: number, zfar: number): ThinMatrix;
|
|
62
|
+
/**
|
|
63
|
+
* Sets a matrix to a value composed by merging scale (vector2), rotation (roll around z) and translation (vector2)
|
|
64
|
+
* This only updates the parts of the matrix that are used for 2D transformations.
|
|
65
|
+
* @param scale defines the scale vector
|
|
66
|
+
* @param roll defines the rotation around z
|
|
67
|
+
* @param translation defines the translation vector
|
|
68
|
+
* @returns the updated ThinMatrix instance
|
|
69
|
+
*/
|
|
70
|
+
compose(scale: IVector2Like, roll: number, translation: IVector2Like): ThinMatrix;
|
|
71
|
+
/**
|
|
72
|
+
* Sets the current matrix with the multiplication result of the current Matrix and the given one
|
|
73
|
+
* This only updates the parts of the matrix that are used for 2D transformations.
|
|
74
|
+
* @param other defines the second operand
|
|
75
|
+
* @param output the matrix to store the result in
|
|
76
|
+
* @returns the current matrix
|
|
77
|
+
*/
|
|
78
|
+
multiplyToRef(other: ThinMatrix, output: ThinMatrix): ThinMatrix;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the matrix data array.
|
|
81
|
+
* @returns The matrix data
|
|
82
|
+
*/
|
|
83
|
+
asArray(): Tuple<number, 16>;
|
|
84
|
+
/**
|
|
85
|
+
* Decomposes the matrix into scale, rotation, and translation.
|
|
86
|
+
* @param scale Scale vector to store the scale values
|
|
87
|
+
* @param translation Translation vector to store the translation values
|
|
88
|
+
* @returns The rotation in radians
|
|
89
|
+
*/
|
|
90
|
+
decompose(scale: IVector2Like, translation: IVector2Like): number;
|
|
91
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Babylon.js thin version of a Matrix
|
|
3
|
+
* We are only exposing what we truly need in the scope of
|
|
4
|
+
* the Lottie Renderer project preventing the dependency on the full
|
|
5
|
+
* Babylon.js math system.
|
|
6
|
+
*/
|
|
7
|
+
export class ThinMatrix {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new ThinMatrix instance.
|
|
10
|
+
*/
|
|
11
|
+
constructor() {
|
|
12
|
+
/**
|
|
13
|
+
* Current update flag used to know whether a Matrix has changed since previous render or not.
|
|
14
|
+
* This helps identifying if a Matrix needs to be
|
|
15
|
+
* uploaded to a shader program.
|
|
16
|
+
*/
|
|
17
|
+
this.updateFlag = -1;
|
|
18
|
+
this._data = new Float32Array(16);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set the matrix values.
|
|
22
|
+
* @param m11 Value for row 1, column 1
|
|
23
|
+
* @param m12 Value for row 1, column 2
|
|
24
|
+
* @param m13 Value for row 1, column 3
|
|
25
|
+
* @param m14 Value for row 1, column 4
|
|
26
|
+
* @param m21 Value for row 2, column 1
|
|
27
|
+
* @param m22 Value for row 2, column 2
|
|
28
|
+
* @param m23 Value for row 2, column 3
|
|
29
|
+
* @param m24 Value for row 2, column 4
|
|
30
|
+
* @param m31 Value for row 3, column 1
|
|
31
|
+
* @param m32 Value for row 3, column 2
|
|
32
|
+
* @param m33 Value for row 3, column 3
|
|
33
|
+
* @param m34 Value for row 3, column 4
|
|
34
|
+
* @param m41 Value for row 4, column 1
|
|
35
|
+
* @param m42 Value for row 4, column 2
|
|
36
|
+
* @param m43 Value for row 4, column 3
|
|
37
|
+
* @param m44 Value for row 4, column 4
|
|
38
|
+
* @returns The updated ThinMatrix instance
|
|
39
|
+
*/
|
|
40
|
+
setValues(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
|
41
|
+
const m = this._data;
|
|
42
|
+
m[0] = m11;
|
|
43
|
+
m[1] = m12;
|
|
44
|
+
m[2] = m13;
|
|
45
|
+
m[3] = m14;
|
|
46
|
+
m[4] = m21;
|
|
47
|
+
m[5] = m22;
|
|
48
|
+
m[6] = m23;
|
|
49
|
+
m[7] = m24;
|
|
50
|
+
m[8] = m31;
|
|
51
|
+
m[9] = m32;
|
|
52
|
+
m[10] = m33;
|
|
53
|
+
m[11] = m34;
|
|
54
|
+
m[12] = m41;
|
|
55
|
+
m[13] = m42;
|
|
56
|
+
m[14] = m43;
|
|
57
|
+
m[15] = m44;
|
|
58
|
+
this.updateFlag = ThinMatrix._UPDATE_FLAG_SEED++;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Set the matrix to an identity matrix.
|
|
63
|
+
* @returns The updated ThinMatrix instance
|
|
64
|
+
*/
|
|
65
|
+
identity() {
|
|
66
|
+
this.setValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Stores a left-handed orthographic projection into a given matrix
|
|
71
|
+
* @param left defines the viewport left coordinate
|
|
72
|
+
* @param right defines the viewport right coordinate
|
|
73
|
+
* @param bottom defines the viewport bottom coordinate
|
|
74
|
+
* @param top defines the viewport top coordinate
|
|
75
|
+
* @param znear defines the near clip plane
|
|
76
|
+
* @param zfar defines the far clip plane
|
|
77
|
+
* @returns The updated ThinMatrix instance
|
|
78
|
+
*/
|
|
79
|
+
orthoOffCenterLeftHanded(left, right, bottom, top, znear, zfar) {
|
|
80
|
+
const n = znear;
|
|
81
|
+
const f = zfar;
|
|
82
|
+
const a = 2.0 / (right - left);
|
|
83
|
+
const b = 2.0 / (top - bottom);
|
|
84
|
+
const c = 2.0 / (f - n);
|
|
85
|
+
const d = -(f + n) / (f - n);
|
|
86
|
+
const i0 = (left + right) / (left - right);
|
|
87
|
+
const i1 = (top + bottom) / (bottom - top);
|
|
88
|
+
this.setValues(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, i0, i1, d, 1.0);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Sets a matrix to a value composed by merging scale (vector2), rotation (roll around z) and translation (vector2)
|
|
93
|
+
* This only updates the parts of the matrix that are used for 2D transformations.
|
|
94
|
+
* @param scale defines the scale vector
|
|
95
|
+
* @param roll defines the rotation around z
|
|
96
|
+
* @param translation defines the translation vector
|
|
97
|
+
* @returns the updated ThinMatrix instance
|
|
98
|
+
*/
|
|
99
|
+
compose(scale, roll, translation) {
|
|
100
|
+
// Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)
|
|
101
|
+
const halfRoll = roll * 0.5;
|
|
102
|
+
const z = Math.sin(halfRoll), w = Math.cos(halfRoll);
|
|
103
|
+
const z2 = z + z;
|
|
104
|
+
const zz = z * z2;
|
|
105
|
+
const wz = w * z2;
|
|
106
|
+
const sx = scale.x, sy = scale.y;
|
|
107
|
+
const m = this._data;
|
|
108
|
+
m[0] = (1 - zz) * sx;
|
|
109
|
+
m[1] = wz * sx;
|
|
110
|
+
m[4] = -wz * sy;
|
|
111
|
+
m[5] = (1 - zz) * sy;
|
|
112
|
+
m[12] = translation.x;
|
|
113
|
+
m[13] = translation.y;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Sets the current matrix with the multiplication result of the current Matrix and the given one
|
|
118
|
+
* This only updates the parts of the matrix that are used for 2D transformations.
|
|
119
|
+
* @param other defines the second operand
|
|
120
|
+
* @param output the matrix to store the result in
|
|
121
|
+
* @returns the current matrix
|
|
122
|
+
*/
|
|
123
|
+
multiplyToRef(other, output) {
|
|
124
|
+
const m = this._data;
|
|
125
|
+
const otherM = other._data;
|
|
126
|
+
// Only calculate the values we actually use (2D transform)
|
|
127
|
+
const tm0 = m[0], tm1 = m[1], tm4 = m[4], tm5 = m[5];
|
|
128
|
+
const tm12 = m[12], tm13 = m[13];
|
|
129
|
+
const om0 = otherM[0], om1 = otherM[1];
|
|
130
|
+
const om4 = otherM[4], om5 = otherM[5];
|
|
131
|
+
const om12 = otherM[12], om13 = otherM[13];
|
|
132
|
+
// Only update the 2D transformation parts
|
|
133
|
+
output._data[0] = tm0 * om0 + tm1 * om4;
|
|
134
|
+
output._data[1] = tm0 * om1 + tm1 * om5;
|
|
135
|
+
output._data[4] = tm4 * om0 + tm5 * om4;
|
|
136
|
+
output._data[5] = tm4 * om1 + tm5 * om5;
|
|
137
|
+
output._data[12] = tm12 * om0 + tm13 * om4 + om12;
|
|
138
|
+
output._data[13] = tm12 * om1 + tm13 * om5 + om13;
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns the matrix data array.
|
|
143
|
+
* @returns The matrix data
|
|
144
|
+
*/
|
|
145
|
+
asArray() {
|
|
146
|
+
return this._data;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Decomposes the matrix into scale, rotation, and translation.
|
|
150
|
+
* @param scale Scale vector to store the scale values
|
|
151
|
+
* @param translation Translation vector to store the translation values
|
|
152
|
+
* @returns The rotation in radians
|
|
153
|
+
*/
|
|
154
|
+
decompose(scale, translation) {
|
|
155
|
+
const m00 = this._data[0]; // scaleX * cos(θ)
|
|
156
|
+
const m01 = this._data[1]; // -scaleY * sin(θ)
|
|
157
|
+
const m10 = this._data[4]; // scaleX * sin(θ)
|
|
158
|
+
const m11 = this._data[5]; // scaleY * cos(θ)
|
|
159
|
+
// Extract scale
|
|
160
|
+
scale.x = Math.hypot(m00, m10); // sqrt(m00² + m10²)
|
|
161
|
+
scale.y = Math.hypot(m01, m11); // sqrt(m01² + m11²)
|
|
162
|
+
// Extract rotation (assumes uniform scaling or affine 2D)
|
|
163
|
+
const rotation = Math.atan2(m10, m00); // θ from the first column
|
|
164
|
+
// Extract the translation
|
|
165
|
+
translation.x = this._data[12];
|
|
166
|
+
translation.y = this._data[13];
|
|
167
|
+
return rotation;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Prevents global conflicts on update as shader programs are shared.
|
|
172
|
+
*/
|
|
173
|
+
ThinMatrix._UPDATE_FLAG_SEED = 0;
|
|
174
|
+
//# sourceMappingURL=matrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../../../../../dev/addons/src/lottie/maths/matrix.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IAenB;;OAEG;IACH;QAZA;;;;WAIG;QACI,eAAU,GAAG,CAAC,CAAC,CAAC;QAQnB,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACI,SAAS,CACZ,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW;QAEX,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACrB,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACX,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QACZ,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QACZ,CAAC,CAAC,EAAE,CAAC,GAAG,GAA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ector2Like } from \"core/Maths/math.like\";\r\nimport type { Tuple } from \"core/types\";\r\n\r\n/**\r\n * Represents a Babylon.js thin version of a Matrix\r\n * We are only exposing what we truly need in the scope of\r\n * the Lottie Renderer project preventing the dependency on the full\r\n * Babylon.js math system.\r\n */\r\nexport class ThinMatrix implements IMatrixLike {\r\n /**\r\n * Prevents global conflicts on update as shader programs are shared.\r\n */\r\n private static _UPDATE_FLAG_SEED = 0;\r\n\r\n /**\r\n * Current update flag used to know whether a Matrix has changed since previous render or not.\r\n * This helps identifying if a Matrix needs to be\r\n * uploaded to a shader program.\r\n */\r\n public updateFlag = -1;\r\n\r\n private readonly _data: Float32Array;\r\n\r\n /**\r\n * Creates a new ThinMatrix instance.\r\n */\r\n public constructor() {\r\n this._data = new Float32Array(16);\r\n }\r\n\r\n /**\r\n * Set the matrix values.\r\n * @param m11 Value for row 1, column 1\r\n * @param m12 Value for row 1, column 2\r\n * @param m13 Value for row 1, column 3\r\n * @param m14 Value for row 1, column 4\r\n * @param m21 Value for row 2, column 1\r\n * @param m22 Value for row 2, column 2\r\n * @param m23 Value for row 2, column 3\r\n * @param m24 Value for row 2, column 4\r\n * @param m31 Value for row 3, column 1\r\n * @param m32 Value for row 3, column 2\r\n * @param m33 Value for row 3, column 3\r\n * @param m34 Value for row 3, column 4\r\n * @param m41 Value for row 4, column 1\r\n * @param m42 Value for row 4, column 2\r\n * @param m43 Value for row 4, column 3\r\n * @param m44 Value for row 4, column 4\r\n * @returns The updated ThinMatrix instance\r\n */\r\n public setValues(\r\n m11: number,\r\n m12: number,\r\n m13: number,\r\n m14: number,\r\n m21: number,\r\n m22: number,\r\n m23: number,\r\n m24: number,\r\n m31: number,\r\n m32: number,\r\n m33: number,\r\n m34: number,\r\n m41: number,\r\n m42: number,\r\n m43: number,\r\n m44: number\r\n ): ThinMatrix {\r\n const m = this._data;\r\n m[0] = m11;\r\n m[1] = m12;\r\n m[2] = m13;\r\n m[3] = m14;\r\n m[4] = m21;\r\n m[5] = m22;\r\n m[6] = m23;\r\n m[7] = m24;\r\n m[8] = m31;\r\n m[9] = m32;\r\n m[10] = m33;\r\n m[11] = m34;\r\n m[12] = m41;\r\n m[13] = m42;\r\n m[14] = m43;\r\n m[15] = m44;\r\n\r\n this.updateFlag = ThinMatrix._UPDATE_FLAG_SEED++;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the matrix to an identity matrix.\r\n * @returns The updated ThinMatrix instance\r\n */\r\n public identity(): ThinMatrix {\r\n this.setValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Stores a left-handed orthographic projection into a given matrix\r\n * @param left defines the viewport left coordinate\r\n * @param right defines the viewport right coordinate\r\n * @param bottom defines the viewport bottom coordinate\r\n * @param top defines the viewport top coordinate\r\n * @param znear defines the near clip plane\r\n * @param zfar defines the far clip plane\r\n * @returns The updated ThinMatrix instance\r\n */\r\n public orthoOffCenterLeftHanded(left: number, right: number, bottom: number, top: number, znear: number, zfar: number): ThinMatrix {\r\n const n = znear;\r\n const f = zfar;\r\n\r\n const a = 2.0 / (right - left);\r\n const b = 2.0 / (top - bottom);\r\n const c = 2.0 / (f - n);\r\n const d = -(f + n) / (f - n);\r\n const i0 = (left + right) / (left - right);\r\n const i1 = (top + bottom) / (bottom - top);\r\n\r\n this.setValues(a, 0.0, 0.0, 0.0, 0.0, b, 0.0, 0.0, 0.0, 0.0, c, 0.0, i0, i1, d, 1.0);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets a matrix to a value composed by merging scale (vector2), rotation (roll around z) and translation (vector2)\r\n * This only updates the parts of the matrix that are used for 2D transformations.\r\n * @param scale defines the scale vector\r\n * @param roll defines the rotation around z\r\n * @param translation defines the translation vector\r\n * @returns the updated ThinMatrix instance\r\n */\r\n public compose(scale: IVector2Like, roll: number, translation: IVector2Like): ThinMatrix {\r\n // Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)\r\n const halfRoll = roll * 0.5;\r\n const z = Math.sin(halfRoll),\r\n w = Math.cos(halfRoll);\r\n\r\n const z2 = z + z;\r\n const zz = z * z2;\r\n const wz = w * z2;\r\n\r\n const sx = scale.x,\r\n sy = scale.y;\r\n\r\n const m = this._data;\r\n m[0] = (1 - zz) * sx;\r\n m[1] = wz * sx;\r\n\r\n m[4] = -wz * sy;\r\n m[5] = (1 - zz) * sy;\r\n\r\n m[12] = translation.x;\r\n m[13] = translation.y;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the current matrix with the multiplication result of the current Matrix and the given one\r\n * This only updates the parts of the matrix that are used for 2D transformations.\r\n * @param other defines the second operand\r\n * @param output the matrix to store the result in\r\n * @returns the current matrix\r\n */\r\n public multiplyToRef(other: ThinMatrix, output: ThinMatrix): ThinMatrix {\r\n const m = this._data;\r\n const otherM = other._data;\r\n\r\n // Only calculate the values we actually use (2D transform)\r\n const tm0 = m[0],\r\n tm1 = m[1],\r\n tm4 = m[4],\r\n tm5 = m[5];\r\n const tm12 = m[12],\r\n tm13 = m[13];\r\n\r\n const om0 = otherM[0],\r\n om1 = otherM[1];\r\n const om4 = otherM[4],\r\n om5 = otherM[5];\r\n const om12 = otherM[12],\r\n om13 = otherM[13];\r\n\r\n // Only update the 2D transformation parts\r\n output._data[0] = tm0 * om0 + tm1 * om4;\r\n output._data[1] = tm0 * om1 + tm1 * om5;\r\n output._data[4] = tm4 * om0 + tm5 * om4;\r\n output._data[5] = tm4 * om1 + tm5 * om5;\r\n output._data[12] = tm12 * om0 + tm13 * om4 + om12;\r\n output._data[13] = tm12 * om1 + tm13 * om5 + om13;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the matrix data array.\r\n * @returns The matrix data\r\n */\r\n public asArray(): Tuple<number, 16> {\r\n return this._data as any as Tuple<number, 16>;\r\n }\r\n\r\n /**\r\n * Decomposes the matrix into scale, rotation, and translation.\r\n * @param scale Scale vector to store the scale values\r\n * @param translation Translation vector to store the translation values\r\n * @returns The rotation in radians\r\n */\r\n public decompose(scale: IVector2Like, translation: IVector2Like): number {\r\n const m00 = this._data[0]; // scaleX * cos(θ)\r\n const m01 = this._data[1]; // -scaleY * sin(θ)\r\n const m10 = this._data[4]; // scaleX * sin(θ)\r\n const m11 = this._data[5]; // scaleY * cos(θ)\r\n\r\n // Extract scale\r\n scale.x = Math.hypot(m00, m10); // sqrt(m00² + m10²)\r\n scale.y = Math.hypot(m01, m11); // sqrt(m01² + m11²)\r\n\r\n // Extract rotation (assumes uniform scaling or affine 2D)\r\n const rotation = Math.atan2(m10, m00); // θ from the first column\r\n\r\n // Extract the translation\r\n translation.x = this._data[12];\r\n translation.y = this._data[13];\r\n\r\n return rotation;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { AnimationConfiguration } from "../lottiePlayer.js";
|
|
5
|
+
/**
|
|
6
|
+
* Class that controls the playing of lottie animations using Babylon.js
|
|
7
|
+
*/
|
|
8
|
+
export declare class AnimationController {
|
|
9
|
+
private _isReady;
|
|
10
|
+
private readonly _canvas;
|
|
11
|
+
private readonly _configuration;
|
|
12
|
+
private readonly _engine;
|
|
13
|
+
private readonly _spritePacker;
|
|
14
|
+
private _animation?;
|
|
15
|
+
private readonly _viewport;
|
|
16
|
+
private readonly _projectionMatrix;
|
|
17
|
+
private readonly _worldMatrix;
|
|
18
|
+
private _frameDuration;
|
|
19
|
+
private _currentFrame;
|
|
20
|
+
private _isPlaying;
|
|
21
|
+
private _animationFrameId;
|
|
22
|
+
private _lastFrameTime;
|
|
23
|
+
private _deltaTime;
|
|
24
|
+
private _loop;
|
|
25
|
+
private _accumulatedTime;
|
|
26
|
+
private _framesToAdvance;
|
|
27
|
+
private readonly _renderingManager;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the canvas used for rendering the animation.
|
|
30
|
+
* @returns The canvas element used for rendering.
|
|
31
|
+
*/
|
|
32
|
+
get view(): HTMLCanvasElement;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the height of the animation in pixels.
|
|
35
|
+
* @returns The height of the animation in pixels.
|
|
36
|
+
*/
|
|
37
|
+
get animationHeight(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the width of the animation in pixels.
|
|
40
|
+
* @returns The width of the animation in pixels.
|
|
41
|
+
*/
|
|
42
|
+
get animationWidth(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new instance of the Player.
|
|
45
|
+
* @param canvas The canvas element to render the animation on.
|
|
46
|
+
* @param animationJson The JSON string of the Lottie animation to be played.
|
|
47
|
+
* @param configuration The configuration for the animation player.
|
|
48
|
+
*/
|
|
49
|
+
constructor(canvas: HTMLCanvasElement, animationJson: string, configuration: AnimationConfiguration);
|
|
50
|
+
/**
|
|
51
|
+
* Plays the animation.
|
|
52
|
+
* @param loop If true, the animation will loop when it reaches the end.
|
|
53
|
+
*/
|
|
54
|
+
playAnimation(loop?: boolean): void;
|
|
55
|
+
/**
|
|
56
|
+
* Stops the animation playback.
|
|
57
|
+
*/
|
|
58
|
+
stopAnimation(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Sets the rendering size for the engine
|
|
61
|
+
* @param width Width of the rendering canvas
|
|
62
|
+
* @param height Height of the rendering canvas
|
|
63
|
+
*/
|
|
64
|
+
setSize(width: number, height: number): void;
|
|
65
|
+
/**
|
|
66
|
+
* Disposes the player and releases all resources.
|
|
67
|
+
*/
|
|
68
|
+
dispose(): void;
|
|
69
|
+
private _cleanTree;
|
|
70
|
+
private _startRenderLoop;
|
|
71
|
+
private _render;
|
|
72
|
+
}
|