Esempio n. 1
0
        static public Transform AdvanceAndDeserializeUsd()
        {
#if USD_SUPPORTED
            if (m_UsdPathSerializer != null)
            {
                m_UsdPathSerializer.Time += Time.deltaTime;
                m_UsdPathSerializer.Deserialize();
                return(m_UsdPathSerializer.transform);
            }
#endif
            return(null);
        }
Esempio n. 2
0
        public void BeginRender()
        {
            IsRendering = true;

            // Turn off shadows, until depth disparity can be fixed.
            // See http://b/68952256 for details
            UnityEngine.QualitySettings.shadows = ShadowQuality.Disable;
            for (int i = 0; i < App.Scene.GetNumLights(); i++)
            {
                App.Scene.GetLight(i).shadows = LightShadows.None;
            }

            for (int i = 0; ; ++i)
            {
                string o      = string.Format("{0}_{1:00}", m_outputBasename, i);
                string outVid = Path.Combine(m_outputFolder, o + ".mp4");
                string outDir = Path.Combine(m_outputFolder, o + "/");

                if (!File.Exists(outVid) && !File.Exists(outDir))
                {
                    m_videoPath  = outVid;
                    m_imagesPath = outDir + m_outputBasename;

                    m_odsCamera.outputFolder = outDir;
                    m_odsCamera.basename     = m_outputBasename;

                    // Touch the destination folder.
                    Directory.CreateDirectory(outDir);

                    // Touch the destination file.
                    FileStream fs = File.Open(m_videoPath, FileMode.OpenOrCreate,
                                              FileAccess.Write, FileShare.ReadWrite);
                    fs.Close();
                    fs.Dispose();
                    File.SetLastWriteTimeUtc(m_videoPath, System.DateTime.UtcNow);
                    break;
                }
            }

            if (!string.IsNullOrEmpty(CameraPath) && File.Exists(CameraPath))
            {
#if USD_SUPPORTED
                m_PathSerializer = gameObject.AddComponent <UsdPathSerializer>();
                if (m_PathSerializer.Load(CameraPath))
                {
                    m_PathSerializer.StartPlayback("/Sketch", "/VideoCamera");
                    FramesToCapture       = Mathf.FloorToInt((float)(m_PathSerializer.Duration) * m_fps);
                    m_PathSerializer.Time = 0;
                    m_PathSerializer.Deserialize();
                }
                else
                {
                    Destroy(m_PathSerializer);
                    m_PathSerializer = null;
                }
#else
                throw new System.NotImplementedException("CameraPath requires USD support");
#endif
            }

            Debug.LogFormat("ODS Output Video: {0}" + System.Environment.NewLine +
                            "ODS Output Path: {1}" + System.Environment.NewLine +
                            "ODS Basename: {2}"
                            , m_videoPath, m_odsCamera.outputFolder, m_odsCamera.basename);

            Shader.SetGlobalFloat("ODS_PoleCollapseAmount", App.UserConfig.Video.OdsPoleCollapsing);


            gameObject.SetActive(true);

            App.Instance.FrameCountDisplay.gameObject.SetActive(true);
        }
Esempio n. 3
0
        void Update()
        {
            if (m_odsCamera.FrameCount >= m_framesToCapture)
            {
                if (m_framesToCapture > 0)
                {
                    // We rendered everything.
                    if ((Application.platform == RuntimePlatform.WindowsPlayer) ||
                        (Application.platform == RuntimePlatform.WindowsEditor))
                    {
                        System.Diagnostics.Process.Start("explorer.exe", "/open," + m_outputFolder);
                    }

                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo.FileName  = Path.GetFullPath(TiltBrush.FfmpegPipe.GetFfmpegExe());
                    proc.StartInfo.Arguments = System.String.Format(
                        @"-y -framerate {0} -f image2 -i ""{1}_%06d.png"" " +
                        @"-c:v " + FfmpegPipe.GetVideoEncoder() + @" -r {0} -pix_fmt yuv420p ""{2}""",
                        m_fps,
                        m_imagesPath,
                        m_videoPath);
                    Debug.LogFormat("{0} {1}", proc.StartInfo.FileName, proc.StartInfo.Arguments);
                    proc.StartInfo.CreateNoWindow        = false;
                    proc.StartInfo.ErrorDialog           = true;
                    proc.StartInfo.UseShellExecute       = false;
                    proc.StartInfo.RedirectStandardError = true;
                    proc.Start();

                    UnityEngine.Debug.Log(proc.StandardError.ReadToEnd());

#if USD_SUPPORTED
                    if (m_PathSerializer != null)
                    {
                        m_PathSerializer.Stop();
                    }
#endif

                    proc.Close();
                    Application.Quit();
                    Debug.Break();
                }
                return;
            }

            if (m_odsCamera.IsRendering)
            {
                return;
            }

            if (m_frameTick)
            {
                if (m_frameTimer.ElapsedMilliseconds < 1000.0f / m_fps)
                {
                    return;
                }
                m_frameTimer.Stop();
            }

            if (m_renderTimer.IsRunning)
            {
                m_renderTimer.Stop();

                Debug.LogFormat("ODS Frame Time: {0}", m_renderTimer.ElapsedMilliseconds / 1000.0f);
            }

            m_frameTick = !m_frameTick;

            if (m_frameTick)
            {
                Time.timeScale = 1.0f;
                m_frameTimer.Reset();
                m_frameTimer.Start();
                return;
            }

            Time.timeScale = 0.0f;

            if (!HaveCameraPath)
            {
                float progress = m_odsCamera.FrameCount / (float)m_framesToCapture;
                App.Scene.Pose = GetScenePose(progress);

                if (m_turnTableRotation > 0)
                {
                    TiltBrush.TrTransform sc = App.Scene.Pose;
                    sc.rotation    = Quaternion.AngleAxis(progress * m_turnTableRotation, Vector3.up);
                    App.Scene.Pose = sc;
                }
            }
            else
            {
#if USD_SUPPORTED
                m_PathSerializer.Time = m_odsCamera.FrameCount / m_fps;
                m_PathSerializer.Deserialize();
#endif
            }

            Camera cam       = OdsCamera.GetComponent <Camera>();
            Camera parentCam = TiltBrush.App.VrSdk.GetVrCamera();
            cam.clearFlags      = parentCam.clearFlags;
            cam.backgroundColor = parentCam.backgroundColor;

            // Copy back the culling mask so the preview window looks like the final render.
            parentCam.cullingMask = cam.cullingMask;

            if (m_odsCamera.FrameCount == 0 && m_framesToCapture > 0)
            {
                if (QualitySettings.GetQualityLevel() != 3)
                {
                    QualitySettings.SetQualityLevel(3);
                }
            }
            App.Instance.FrameCountDisplay.SetCurrentFrame(m_odsCamera.FrameCount);

            // Move the viewer camera, so the user can see what's going on.
            Transform viewerXform = App.VrSdk.GetVrCamera().transform;
            viewerXform.position   = transform.position;
            viewerXform.rotation   = transform.rotation;
            viewerXform.localScale = transform.localScale;

            m_renderTimer.Reset();
            m_renderTimer.Start();
            StartCoroutine(m_odsCamera.Render(transform));
        }