Skip to content

Commit 0dbefa0

Browse files
committed
fix: do not reuse identity
1 parent ee215a8 commit 0dbefa0

File tree

1 file changed

+8
-67
lines changed

1 file changed

+8
-67
lines changed

src/core/CoreNode.ts

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ CoreNodeRenderStateMap.set(CoreNodeRenderState.OutOfBounds, 'outOfBounds');
7070
CoreNodeRenderStateMap.set(CoreNodeRenderState.InBounds, 'inBounds');
7171
CoreNodeRenderStateMap.set(CoreNodeRenderState.InViewport, 'inViewport');
7272

73-
const IDENTITY = Matrix3d.identity();
74-
7573
export enum UpdateType {
7674
/**
7775
* Child updates
@@ -1026,8 +1024,7 @@ export class CoreNode extends EventEmitter {
10261024
const texture = props.texture;
10271025
const textureOptions = props.textureOptions;
10281026

1029-
// this.localTransform = this.localTransform || IDENTITY;
1030-
let lt = this.localTransform || IDENTITY;
1027+
let lt = this.localTransform || Matrix3d.identity();
10311028

10321029
if (options?.scaleRotate === true) {
10331030
if (rotation === 0 && scaleX === 1 && scaleY === 1) {
@@ -1044,12 +1041,8 @@ export class CoreNode extends EventEmitter {
10441041
Matrix3d.translate(x + px, y + py, lt)
10451042
.multiply(scaleRotateTransform)
10461043
.translate(-px, -py);
1047-
// this.localTransform = Matrix3d.translate(x + px, y + py, this.localTransform)
1048-
// .multiply(scaleRotateTransform)
1049-
// .translate(-px, -py);
10501044
}
10511045
} else {
1052-
// this.localTransform = Matrix3d.translate(x, y, this.localTransform);
10531046
Matrix3d.translate(x, y, lt);
10541047
}
10551048

@@ -1062,56 +1055,6 @@ export class CoreNode extends EventEmitter {
10621055
}
10631056

10641057
this.localTransform = lt;
1065-
1066-
// const props = this.props;
1067-
// const width = props.width;
1068-
// const height = props.height;
1069-
// const x = props.x - props.mountX * width;
1070-
// const y = props.y - props.mountY * height;
1071-
1072-
// const lt = this.localTransform || IDENTITY;
1073-
1074-
// if (this.scaleRotateTransform !== undefined) {
1075-
// const px = props.pivotX * width;
1076-
// const py = props.pivotY * height;
1077-
1078-
// this.localTransform = Matrix3d.translate(x + px, y + py, lt)
1079-
// .multiply(this.scaleRotateTransform)
1080-
// .translate(-px, -py);
1081-
// } else {
1082-
// this.localTransform = Matrix3d.translate(x, y, lt);
1083-
// }
1084-
1085-
// const texture = props.texture;
1086-
// const options = props.textureOptions;
1087-
// if (
1088-
// texture !== null &&
1089-
// texture.dimensions !== null &&
1090-
// options.resizeMode?.type === 'contain'
1091-
// ) {
1092-
// const tw = texture.dimensions.width;
1093-
// const th = texture.dimensions.height;
1094-
// const ta = width / tw;
1095-
// const tb = height / th;
1096-
// let sx = 1,
1097-
// sy = 1,
1098-
// dx = 0,
1099-
// dy = 0;
1100-
1101-
// if (tw / th > width / height) {
1102-
// const sh = th * ta;
1103-
// sy = sh / height;
1104-
// dy = (height - sh) * 0.5;
1105-
// } else {
1106-
// const sw = tw * tb;
1107-
// sx = sw / width;
1108-
// dx = (width - sw) * 0.5;
1109-
// }
1110-
1111-
// this.localTransform = Matrix3d.translate(dx, dy).scale(sx, sy);
1112-
// }
1113-
1114-
// this.setUpdateType(UpdateType.Global);
11151058
}
11161059

11171060
/**
@@ -1139,19 +1082,19 @@ export class CoreNode extends EventEmitter {
11391082
this.updateLocalTransform({
11401083
scaleRotate: (updateType & UpdateType.ScaleRotate) !== 0,
11411084
});
1085+
11421086
// this.setUpdateType(UpdateType.Global);
11431087
updateType |= UpdateType.Global;
11441088
}
11451089

11461090
if (updateType & UpdateType.Global) {
11471091
// global
1148-
// this.globalTransform = this.globalTransform || IDENTITY;
1149-
let gt = this.globalTransform || IDENTITY;
1150-
let lt = this.localTransform || IDENTITY;
1092+
let lt = this.localTransform || Matrix3d.identity();
1093+
let gt = this.globalTransform || Matrix3d.identity();
11511094

11521095
if (parentHasRenderTexture === true) {
11531096
if (parent?.rtt === true) {
1154-
// this.globalTransform = IDENTITY;
1097+
this.globalTransform = Matrix3d.identity();
11551098

11561099
// Maintain a full scene global transform for bounds detection
11571100
this.sceneGlobalTransform = Matrix3d.copy(
@@ -1163,15 +1106,13 @@ export class CoreNode extends EventEmitter {
11631106
// to maintain a full scene global transform for bounds detection
11641107
this.sceneGlobalTransform = Matrix3d.copy(
11651108
parent?.sceneGlobalTransform || lt,
1109+
this.sceneGlobalTransform,
11661110
).multiply(lt);
11671111

1168-
gt = Matrix3d.copy(
1169-
parent?.globalTransform || lt,
1170-
this.globalTransform,
1171-
);
1112+
gt = Matrix3d.copy(parent?.globalTransform || lt, gt);
11721113
}
11731114
} else {
1174-
gt = Matrix3d.copy(parent?.globalTransform || lt, this.globalTransform);
1115+
Matrix3d.copy(parent?.globalTransform || gt, gt);
11751116
}
11761117

11771118
if (parent !== null) {

0 commit comments

Comments
 (0)