Files
zhengte.babylonjs-sdk/test-rotation.js
2026-05-13 11:28:49 +08:00

24 lines
769 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 测试不同的旋转方案
// 方案1只旋转Y轴当前方案
plane.rotation.y = angle;
// 方案2先X轴90度再Y轴
plane.rotation.x = Math.PI / 2;
plane.rotation.y = angle;
// 方案3使用lookAt
plane.lookAt(center.add(normal));
// 方案4使用四元数旋转
const forward = new Vector3(0, 0, -1); // 平面默认法线
const targetNormal = normal.normalize();
const quaternion = Quaternion.FromUnitVectorsToRef(forward, targetNormal, new Quaternion());
plane.rotationQuaternion = quaternion;
// 方案5手动设置旋转根据墙面方向
// 前墙 (Z负方向): rotation.y = 0
// 后墙 (Z正方向): rotation.y = Math.PI
// 左墙 (X负方向): rotation.y = Math.PI / 2
// 右墙 (X正方向): rotation.y = -Math.PI / 2