mirror of
https://github.com/motion-canvas/motion-canvas.git
synced 2026-01-11 14:57:56 -05:00
fix: previous scene being rendered twice (#97)
This commit is contained in:
@@ -308,12 +308,12 @@ export class Node implements Promisable<Node> {
|
||||
public readonly key: string;
|
||||
|
||||
public constructor({children, key, ...rest}: NodeProps) {
|
||||
this.key = use2DView()?.registerNode(this, key) ?? key ?? '';
|
||||
initialize(this, {defaults: rest});
|
||||
for (const {signal} of this) {
|
||||
signal.reset();
|
||||
}
|
||||
this.add(children);
|
||||
this.key = use2DView()?.registerNode(this, key) ?? key ?? '';
|
||||
}
|
||||
|
||||
@computed()
|
||||
|
||||
@@ -52,43 +52,11 @@ export class View2D extends Layout {
|
||||
}
|
||||
|
||||
public override render(context: CanvasRenderingContext2D) {
|
||||
const currentMatrix = this.localToParent();
|
||||
const customMatrix = context.getTransform();
|
||||
if (
|
||||
customMatrix.a !== currentMatrix.a ||
|
||||
customMatrix.b !== currentMatrix.b ||
|
||||
customMatrix.c !== currentMatrix.c ||
|
||||
customMatrix.d !== currentMatrix.d ||
|
||||
customMatrix.e !== currentMatrix.e ||
|
||||
customMatrix.f !== currentMatrix.f
|
||||
) {
|
||||
this.position
|
||||
.x(customMatrix.m41)
|
||||
.position.y(customMatrix.m42)
|
||||
.scale.x(
|
||||
Math.sqrt(
|
||||
customMatrix.m11 * customMatrix.m11 +
|
||||
customMatrix.m12 * customMatrix.m12,
|
||||
),
|
||||
)
|
||||
.scale.y(
|
||||
Math.sqrt(
|
||||
customMatrix.m21 * customMatrix.m21 +
|
||||
customMatrix.m22 * customMatrix.m22,
|
||||
),
|
||||
)
|
||||
.rotation(Math.atan2(customMatrix.m12, customMatrix.m11));
|
||||
}
|
||||
|
||||
this.computedSize();
|
||||
this.computedPosition();
|
||||
super.render(context);
|
||||
}
|
||||
|
||||
protected override transformContext() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
protected override requestLayoutUpdate() {
|
||||
this.updateLayout();
|
||||
}
|
||||
|
||||
@@ -20,8 +20,13 @@ export function addInitializer<T>(target: any, initializer: Initializer<T>) {
|
||||
|
||||
export function initialize(target: any, context: any) {
|
||||
if (target[INITIALIZERS]) {
|
||||
target[INITIALIZERS].forEach((initializer: Initializer<any>) =>
|
||||
initializer(target, context),
|
||||
);
|
||||
try {
|
||||
target[INITIALIZERS].forEach((initializer: Initializer<any>) =>
|
||||
initializer(target, context),
|
||||
);
|
||||
} catch (e: any) {
|
||||
e.inspect ??= target.key;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,9 @@ export class Project {
|
||||
} else {
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
}
|
||||
this.context.drawImage(this.previousBuffer.canvas, 0, 0);
|
||||
if (this.previousScene) {
|
||||
this.context.drawImage(this.previousBuffer.canvas, 0, 0);
|
||||
}
|
||||
this.context.drawImage(this.buffer.canvas, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user