/// Starts recording the transform to a named transform in a new usd file given by the path. public bool StartRecording(string path, string sketchName = "/Sketch", string xformName = "/VideoCamera") { m_xformName = sketchName + xformName; if (!InitUsd.Initialize() || string.IsNullOrEmpty(path)) { return(false); } // Find the active camera. m_RecordingCamera = null; foreach (var c in GetComponentsInChildren <Camera>()) { if (c.gameObject.activeInHierarchy && c.isActiveAndEnabled) { m_RecordingCamera = c; } } if (m_RecordingCamera == null) { return(false); } var sketchRoot = ExportUsd.CreateSketchRoot(); m_UsdCamera = new UsdCameraXformSample(); try { m_Scene = USD.NET.Scene.Create(path); } catch (ApplicationException /*e*/) { Debug.LogError("Error creating usda file!"); return(false); } m_Scene.Write(sketchName, sketchRoot); // The time code of the recording is in seconds. m_Scene.Stage.SetTimeCodesPerSecond(1); // CameraSample constructor converts the Unity Camera to USD. // Write the fallback camera parameters. var cameraSample = new UsdCameraSample(m_RecordingCamera); // Convert camera params to meters. cameraSample.clippingRange *= App.UNITS_TO_METERS; m_Scene.Write(m_xformName, cameraSample); m_Scene.Time = 0; m_Scene.StartTime = 0; m_Scene.EndTime = 0; m_IsRecording = true; return(true); }
/// 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>(); }