/// 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); }
public void Serialize() { // Get transform in canvas space, and write to scene. TrTransform xf_CS = Coords.AsCanvas[transform]; var basisMat = Matrix4x4.identity; if (m_UnitsInMeters) { basisMat[0, 0] *= App.UNITS_TO_METERS; basisMat[1, 1] *= App.UNITS_TO_METERS; basisMat[2, 2] *= -1 * App.UNITS_TO_METERS; } m_UsdCamera.transform = ExportUtils.ChangeBasis(xf_CS.ToMatrix4x4(), basisMat, basisMat.inverse); m_UsdCamera.fov = m_RecordingCamera.fieldOfView; m_Scene.Write(m_xformName, m_UsdCamera); }