Skip to content

Commit c58a823

Browse files
deltakoshDavid Catuhe
authored andcommitted
Fix rh issue with billboard (BabylonJS#16832)
Co-authored-by: David Catuhe <[email protected]>
1 parent d7dc6ca commit c58a823

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

packages/dev/core/src/Meshes/transformNode.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class TransformNode extends Node {
5050
private static _TmpRotation = Quaternion.Zero();
5151
private static _TmpScaling = Vector3.Zero();
5252
private static _TmpTranslation = Vector3.Zero();
53+
// eslint-disable-next-line @typescript-eslint/naming-convention
54+
private static _TmpRHRestore = Matrix.Scaling(1, 1, -1);
5355

5456
private _forward = new Vector3(0, 0, 1);
5557
private _up = new Vector3(0, 1, 0);
@@ -1206,9 +1208,16 @@ export class TransformNode extends Node {
12061208
const storedTranslation = TmpVectors.Vector3[0];
12071209
this._worldMatrix.getTranslationToRef(storedTranslation); // Save translation
12081210

1209-
// Cancel camera rotation
1211+
// Get camera view matrix
12101212
TmpVectors.Matrix[1].copyFrom(camera.getViewMatrix());
12111213

1214+
if (this.getScene().useRightHandedSystem) {
1215+
// This operation is necessary to cancel out the scaling component of the matrix without decomposing it.
1216+
// It's a trick to extract only the rotation part.
1217+
TmpVectors.Matrix[1].multiplyToRef(TransformNode._TmpRHRestore, TmpVectors.Matrix[1]);
1218+
}
1219+
1220+
// This will cancel the camera rotation
12121221
TmpVectors.Matrix[1].setTranslationFromFloats(0, 0, 0);
12131222
TmpVectors.Matrix[1].invertToRef(TmpVectors.Matrix[0]);
12141223

@@ -1238,7 +1247,7 @@ export class TransformNode extends Node {
12381247
this._worldMatrix.setTranslation(TmpVectors.Vector3[0]);
12391248
}
12401249
// Billboarding based on camera position
1241-
else if (cache.useBillboardPosition) {
1250+
else {
12421251
const storedTranslation = TmpVectors.Vector3[0];
12431252
// Save translation
12441253
this._worldMatrix.getTranslationToRef(storedTranslation);
-35 Bytes
Loading
3.13 KB
Loading

packages/tools/tests/test/visualization/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"playgroundId": "#PDO1L6#1",
77
"referenceImage": "rh-billboard.png"
88
},
9+
{
10+
"title": "RH billboard2",
11+
"playgroundId": "#QDVYS4#4",
12+
"referenceImage": "rh-billboard2.png"
13+
},
914
{
1015
"title": "MSDF",
1116
"playgroundId": "#6RLCWP#20",

0 commit comments

Comments
 (0)