prendy
Version:
Make games with prerendered backdrops using babylonjs and repond
21 lines (14 loc) • 716 B
text/typescript
import { Quaternion, TransformNode, Vector3 } from "@babylonjs/core";
const addToHelpFixRotationVector = new Vector3(0, Math.PI, Math.PI); // Math.PI same as toRadians(180)?
const multiplyToHelpFixRotationVector = new Vector3(-1, 1, -1);
export function getAbsoluteRotation(child: TransformNode) {
var scale = new Vector3(0, 0, 0);
var rotation = new Quaternion();
var position = new Vector3(0, 0, 0);
const combinedMatrix = child.getWorldMatrix();
combinedMatrix.decompose(scale, rotation, position);
const eulerRotation = rotation.toEulerAngles();
eulerRotation.addInPlace(addToHelpFixRotationVector);
eulerRotation.multiplyInPlace(multiplyToHelpFixRotationVector);
return eulerRotation;
}