Skip to content

Commit 22f09f8

Browse files
Fixing test positioning Y issue (#17071)
Text was positioned incorrectly because the Y=0 of the text is at the baseline of the text (at the bottom), and then it goes upwards. This is different from other shapes like vector paths or rectangles. Confirmed the behavior with After Effects: <img width="3810" height="2034" alt="image" src="https://github.com/user-attachments/assets/36c73ca5-c441-4e40-b257-c1128148dac7" /> Also removing the flag to ignore transparency animations as transparency needs to be calculated even without animations (as layers visibility affects transparency).
1 parent 1fbd1fc commit 22f09f8

File tree

6 files changed

+9
-69
lines changed

6 files changed

+9
-69
lines changed

packages/dev/lottiePlayer/src/animationConfiguration.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ export type AnimationConfiguration = {
4646
* Default is 4.
4747
*/
4848
easingSteps: number;
49-
/**
50-
* Whether to ignore opacity animations for performance.
51-
* Default is true.
52-
*/
53-
ignoreOpacityAnimations: boolean;
5449
/**
5550
* Whether to support device lost events for WebGL contexts.
5651
* Default is false.
@@ -71,6 +66,5 @@ export const DefaultConfiguration = {
7166
scaleMultiplier: 5, // Minimum scale factor to prevent too small sprites,
7267
devicePixelRatio: 1, // Scale factor,
7368
easingSteps: 4, // Number of steps to sample easing functions for animations - Less than 4 causes issues with some interpolations
74-
ignoreOpacityAnimations: true, // Whether to ignore opacity animations for performance
7569
supportDeviceLost: false, // Whether to support device lost events for WebGL contexts,
7670
} as const satisfies AnimationConfiguration;

packages/dev/lottiePlayer/src/nodes/controlNode.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class ControlNode extends Node {
1212
/**
1313
* Constructs a new control node.
1414
* @param id Unique identifier for the node.
15-
* @param ignoreOpacityAnimations If there are no animations on opacity, mark this as true to ignore and optimize CPU usage.
1615
* @param inFrame Frame at which the node becomes active.
1716
* @param outFrame Frame at which the node becomes inactive.
1817
* @param position Position of the node in the scene.
@@ -23,7 +22,6 @@ export class ControlNode extends Node {
2322
*/
2423
public constructor(
2524
id: string,
26-
ignoreOpacityAnimations: boolean,
2725
inFrame: number,
2826
outFrame: number,
2927
position?: Vector2Property,
@@ -32,7 +30,7 @@ export class ControlNode extends Node {
3230
opacity?: ScalarProperty,
3331
parent?: Node
3432
) {
35-
super(id, ignoreOpacityAnimations, position, rotation, scale, opacity, parent);
33+
super(id, position, rotation, scale, opacity, parent);
3634
this._inFrame = inFrame;
3735
this._outFrame = outFrame;
3836

packages/dev/lottiePlayer/src/nodes/node.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ThinMatrix } from "../maths/matrix";
99
*/
1010
export class Node {
1111
private readonly _id: string;
12-
private readonly _ignoreOpacityAnimations: boolean;
1312
private readonly _position: Vector2Property;
1413
private readonly _rotation: ScalarProperty;
1514
private readonly _scale: Vector2Property;
@@ -165,26 +164,16 @@ export class Node {
165164
/**
166165
* Constructs a new node.
167166
* @param id Unique identifier for the node.
168-
* @param ignoreOpacityAnimations If there are no animations on opacity, mark this as true to ignore and optimize CPU usage.
169167
* @param position Position of the node in the scene.
170168
* @param rotation Rotation of the node in degrees.
171169
* @param scale Scale of the node in the scene.
172170
* @param opacity Opacity of the node, from 0 to 1.
173171
* @param parent Parent node in the scenegraph.
174172
*/
175-
public constructor(
176-
id: string,
177-
ignoreOpacityAnimations: boolean,
178-
position?: Vector2Property,
179-
rotation?: ScalarProperty,
180-
scale?: Vector2Property,
181-
opacity?: ScalarProperty,
182-
parent?: Node
183-
) {
173+
public constructor(id: string, position?: Vector2Property, rotation?: ScalarProperty, scale?: Vector2Property, opacity?: ScalarProperty, parent?: Node) {
184174
this._isVisible = false;
185175

186176
this._id = id;
187-
this._ignoreOpacityAnimations = ignoreOpacityAnimations;
188177

189178
this._position = position || { startValue: { x: 0, y: 0 }, currentValue: { x: 0, y: 0 }, currentKeyframeIndex: 0 };
190179
this._rotation = rotation || { startValue: 0, currentValue: 0, currentKeyframeIndex: 0 };
@@ -224,19 +213,9 @@ export class Node {
224213
if (parent) {
225214
this._worldMatrix = this._globalMatrix;
226215

227-
// if (parent.isAnimated || !parent.parent || this.isAnimated || parent._isControl) {
228216
this._parent = parent;
229217
parent._children.push(this);
230218
this._localMatrix.multiplyToRef(parent._worldMatrix, this._globalMatrix);
231-
// } else {
232-
// // We can merge them
233-
// this._localMatrix.multiplyToRef(parent._localMatrix, this._localMatrix);
234-
235-
// // New parent
236-
// this._parent = parent.parent;
237-
// this._localMatrix.multiplyToRef(this._parent._worldMatrix, this._globalMatrix);
238-
// parent.parent._children.push(this);
239-
// }
240219
} else {
241220
this._worldMatrix = this._localMatrix;
242221
}
@@ -304,9 +283,7 @@ export class Node {
304283
}
305284
}
306285

307-
if (!this._ignoreOpacityAnimations) {
308-
this._updateOpacity(frame);
309-
}
286+
this._updateOpacity(frame);
310287

311288
for (let i = 0; i < this._children.length; i++) {
312289
this._children[i].update(frame, isUpdated || isParentUpdated);

packages/dev/lottiePlayer/src/nodes/spriteNode.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,15 @@ export class SpriteNode extends Node {
2222
/**
2323
* Creates a new SpriteNode instance.
2424
* @param id Unique identifier for the sprite node.
25-
* @param ignoreOpacityAnimations If there are no animations on opacity, mark this as true to ignore and optimize CPU usage.
2625
* @param sprite The sprite associated with this node.
2726
* @param position The position of the sprite in the scene.
2827
* @param rotation The rotation of the sprite in degrees.
2928
* @param scale The scale of the sprite in the scene.
3029
* @param opacity The opacity of the sprite.
3130
* @param parent The parent node in the scene graph.
3231
*/
33-
public constructor(
34-
id: string,
35-
ignoreOpacityAnimations: boolean,
36-
sprite: ThinSprite,
37-
position?: Vector2Property,
38-
rotation?: ScalarProperty,
39-
scale?: Vector2Property,
40-
opacity?: ScalarProperty,
41-
parent?: Node
42-
) {
43-
super(id, ignoreOpacityAnimations, position, rotation, scale, opacity, parent);
32+
public constructor(id: string, sprite: ThinSprite, position?: Vector2Property, rotation?: ScalarProperty, scale?: Vector2Property, opacity?: ScalarProperty, parent?: Node) {
33+
super(id, position, rotation, scale, opacity, parent);
4434

4535
this._sprite = sprite;
4636
this._originalWidth = sprite.width;

packages/dev/lottiePlayer/src/parsing/parser.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ export class Parser {
271271

272272
const trsNode = new ControlNode(
273273
`ControlNode (TRS) - ${layer.nm}`,
274-
this._configuration.ignoreOpacityAnimations,
275274
layer.ip,
276275
layer.op,
277276
transform.position,
@@ -314,7 +313,6 @@ export class Parser {
314313
private _parseNullLayer(layer: RawLottieLayer, transform: Transform, parent: Node): Node {
315314
return new Node(
316315
`Node (Anchor) - ${layer.nm}`,
317-
this._configuration.ignoreOpacityAnimations,
318316
transform.anchorPoint,
319317
undefined, // Rotation is not used for anchor point
320318
undefined, // Scale is not used for anchor point
@@ -364,20 +362,14 @@ export class Parser {
364362
};
365363

366364
positionProperty.startValue.x += spriteInfo.centerX;
367-
positionProperty.startValue.y -= spriteInfo.centerY; // Invert Y
368365
positionProperty.currentValue.x += spriteInfo.centerX;
369-
positionProperty.currentValue.y -= spriteInfo.centerY; // Invert Y
370366

371-
// if (this._rawFonts) {
372-
// // If we have raw fonts, we can set the font information on the sprite
373-
// const font = this._rawFonts.get(layer.t.d.k[0].s.f);
374-
// positionProperty.startValue.y += font!.ascent! / 2;
375-
// positionProperty.currentValue.y += font!.ascent! / 2;
376-
// }
367+
// For text, its Y position is at the baseline, so we need to offset it by half the height of the text upwards
368+
positionProperty.startValue.y += spriteInfo.centerY;
369+
positionProperty.currentValue.y += spriteInfo.centerY;
377370

378371
return new SpriteNode(
379372
"Sprite",
380-
this._configuration.ignoreOpacityAnimations,
381373
sprite,
382374
positionProperty,
383375
undefined, // Rotation is not used for sprites final transform
@@ -427,19 +419,10 @@ export class Parser {
427419
}
428420

429421
// Create the nodes on the scenegraph for this group
430-
const trsNode = new Node(
431-
`Node (TRS)- ${group.nm}`,
432-
this._configuration.ignoreOpacityAnimations,
433-
transform.position,
434-
transform.rotation,
435-
transform.scale,
436-
transform.opacity,
437-
parent
438-
);
422+
const trsNode = new Node(`Node (TRS)- ${group.nm}`, transform.position, transform.rotation, transform.scale, transform.opacity, parent);
439423

440424
const anchorNode = new Node(
441425
`Node (Anchor) - ${group.nm}`,
442-
this._configuration.ignoreOpacityAnimations,
443426
transform.anchorPoint,
444427
undefined, // Rotation is not used for anchor point
445428
undefined, // Scale is not used for anchor point
@@ -482,7 +465,6 @@ export class Parser {
482465

483466
new SpriteNode(
484467
"Sprite",
485-
this._configuration.ignoreOpacityAnimations,
486468
sprite,
487469
positionProperty,
488470
undefined, // Rotation is not used for sprites final transform

packages/tools/devHost/src/lottie/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export async function Main(): Promise<void> {
2929
scaleMultiplier: 5, // Minimum scale factor to prevent too small sprites,
3030
devicePixelRatio: 1, // Scale factor,
3131
easingSteps: 4, // Number of steps to sample easing functions for animations - Less than 4 causes issues with some interpolations
32-
ignoreOpacityAnimations: true, // Whether to ignore opacity animations for performance
3332
supportDeviceLost: false, // Whether to support device lost events for WebGL contexts,
3433
};
3534

0 commit comments

Comments
 (0)