public void TestAxisConvention() { AxisConvention[] acs = { AxisConvention.kUnity, AxisConvention.kGltf2, AxisConvention.kUsd, AxisConvention.kStl, AxisConvention.kUnreal }; foreach (var ac1 in acs) { foreach (var ac2 in acs) { Matrix4x4 ac1FromAc2 = AxisConvention.GetToDstFromSrc(ac1, ac2); Assert.AreEqual(ac1.forward, ac1FromAc2.MultiplyVector(ac2.forward)); Assert.AreEqual(ac1.right, ac1FromAc2.MultiplyVector(ac2.right)); Assert.AreEqual(ac1.up, ac1FromAc2.MultiplyVector(ac2.up)); } } foreach (var ac in acs) { Matrix4x4 fromUnity = AxisConvention.GetFromUnity(ac); Assert.AreEqual(ac.forward, fromUnity.MultiplyVector(Vector3.forward)); Assert.AreEqual(ac.right, fromUnity.MultiplyVector(Vector3.right)); Assert.AreEqual(ac.up, fromUnity.MultiplyVector(Vector3.up)); Matrix4x4 toUnity = AxisConvention.GetToUnity(ac); Assert.AreEqual(Vector3.forward, toUnity.MultiplyVector(ac.forward)); Assert.AreEqual(Vector3.right, toUnity.MultiplyVector(ac.right)); Assert.AreEqual(Vector3.up, toUnity.MultiplyVector(ac.up)); } }
/// Given a transform, returns that transform in another basis. /// Since it's a Transform, xfInput is in Global (Room) space, Unity axes, decimeters. /// The new basis is: Scene space, with the Payload's axes and units. public static Matrix4x4 ChangeBasis( Transform xfInput, SceneStatePayload payload) { Matrix4x4 basis = AxisConvention.GetFromUnity(payload.axes); Matrix4x4 basisInverse = AxisConvention.GetToUnity(payload.axes); return(ChangeBasis(App.Scene.AsScene[xfInput], basis, basisInverse) .TransformBy(TrTransform.S(payload.exportUnitsFromAppUnits)) .ToMatrix4x4()); }