Ejemplo n.º 1
0
        /// 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);
        }