// Instance API static VrAssetService() { Matrix4x4 polyFromUnity = AxisConvention.GetFromUnity(AxisConvention.kGltfAccordingToPoly); // Provably non-lossy: the mat4 is purely TRS, and the S is uniform kPolyFromUnity = TrTransform.FromMatrix4x4(polyFromUnity); }
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()); }
/// Plays back a named transform onto the current transform from a usd path. /// The transform can optionally be smoothed using exponential smoothing. /// Smoothing will be clamped between 0 - 1. public void StartPlayback(string sketchName = "/Sketch", string xformName = "/VideoCamera", float smoothing = 0) { m_xformName = xformName; m_Smoothing = Mathf.Clamp01(smoothing); m_IsRecording = false; // Older versions of Tilt Brush exported usda camera paths in decimeters. We now // export in meters to match USD geometry export. Older versions also didn't export any sketch // data so we check here for the presence of sketch data to decide how to treat the camera // path units. bool hasSketchRoot = m_Scene.Stage.GetPrimAtPath(new pxr.SdfPath(sketchName)); m_xformName = hasSketchRoot ? sketchName + xformName : xformName; float scale = hasSketchRoot ? App.UNITS_TO_METERS : 1; m_UnitsInMeters = hasSketchRoot; m_Scene.Time = null; m_UsdCameraInfo = new UsdCameraSample(); m_UsdCameraInfo.shutter = new USD.NET.Unity.CameraSample.Shutter(); m_Scene.Read(m_xformName, m_UsdCameraInfo); m_UsdCamera = new UsdCameraXformSample(); m_Scene.Time = 0; m_Scene.Read(m_xformName, m_UsdCamera); var basisMat = AxisConvention.GetFromUnity(AxisConvention.kUsd) * Matrix4x4.Scale(Vector3.one * scale); m_UsdCamera.transform = ExportUtils.ChangeBasis(m_UsdCamera.transform, basisMat, basisMat.inverse); TrTransform xf_WS = UsdXformToWorldSpaceXform(m_UsdCamera); xf_WS.ToTransform(transform); m_PlaybackCameras = FindObjectsOfType <Camera>(); }
// Populates glTF metadata and scene extras fields. private void SetExtras( GlTF_ScriptableExporter exporter, ExportUtils.SceneStatePayload payload) { Color skyColorA = payload.env.skyColorA; Color skyColorB = payload.env.skyColorB; Vector3 skyGradientDir = payload.env.skyGradientDir; // Scene-level extras: exporter.G.extras["TB_EnvironmentGuid"] = payload.env.guid.ToString("D"); exporter.G.extras["TB_Environment"] = payload.env.description; exporter.G.extras["TB_UseGradient"] = payload.env.useGradient ? "true" : "false"; exporter.G.extras["TB_SkyColorA"] = CommaFormattedFloatRGB(skyColorA); exporter.G.extras["TB_SkyColorB"] = CommaFormattedFloatRGB(skyColorB); Matrix4x4 exportFromUnity = AxisConvention.GetFromUnity(payload.axes); exporter.G.extras["TB_SkyGradientDirection"] = CommaFormattedVector3( exportFromUnity * skyGradientDir); exporter.G.extras["TB_FogColor"] = CommaFormattedFloatRGB(payload.env.fogColor); exporter.G.extras["TB_FogDensity"] = payload.env.fogDensity.ToString(); // TODO: remove when Poly starts using the new color data exporter.G.extras["TB_SkyColorHorizon"] = CommaFormattedFloatRGB(skyColorA); exporter.G.extras["TB_SkyColorZenith"] = CommaFormattedFloatRGB(skyColorB); }
/// Returns a basis-change matrix that transforms from Unity axis conventions to /// the conventions specified in the payload. /// /// Does *not* perform unit conversion, hence the name. public static Matrix4x4 GetFromUnity_Axes(SceneStatePayload payload) { return(AxisConvention.GetFromUnity(payload.axes)); }