Esempio n. 1
0
        public IEnumerator StreamingPerformanceTest(string modelPath, int loadTimeoutSeconds)
        {
            if (k_IsRunningUnderUtr)
            {
                yield break;
            }

            m_ModelBounds   = default;
            m_IsModelLoaded = default;

            var runWithMovement = true;

            yield return(StartLoadingModel(modelPath, TimeSpan.FromSeconds(loadTimeoutSeconds)));

            var camera = Camera.main;

            if (runWithMovement)
            {
                camera.transform.position = m_ModelBounds.center - new Vector3(0.0f, 0.0f, -m_ModelBounds.extents.z);
                camera.transform.rotation = Quaternion.identity;
            }
            else
            {
                var fitPosition = FreeFlyCamera.CalculateViewFitPosition(m_ModelBounds, 20.0f, 0.75f, camera.fieldOfView, camera.aspect);
                camera.transform.rotation = Quaternion.Euler(fitPosition.rotation);
                camera.transform.position = fitPosition.position;
            }

            var posFromOrigin = new Vector3(0.0f, 0.0f, -Mathf.Max(m_ModelBounds.extents.z, m_ModelBounds.extents.x));
            var yAngle        = 0.0f;

            var bridge = m_ViewerReflectBootstrapper.Bridge;

            bridge.Subscribe <StreamingProgressed>(ctx =>
            {
                m_IsModelLoaded = ctx.Data.NbStreamed >= ctx.Data.Total * 0.99f;
            });

            using (Measure.Frames().Scope())
            {
                while (!m_IsModelLoaded)
                {
                    if (runWithMovement)
                    {
                        yAngle += 1.0f;

                        var pos      = Quaternion.Euler(0.0f, yAngle, 0.0f) * posFromOrigin * 1.1f;
                        var finalPos = pos + m_ModelBounds.center;

                        camera.transform.position = finalPos;
                        camera.transform.LookAt(m_ModelBounds.center);
                    }

                    yield return(null);
                }
            }
        }
        public Sprite CaptureActiveProjectThumbnail(UIProjectStateData projectStateData)
        {
            if (m_Camera == null || !m_Camera.gameObject.activeInHierarchy)
            {
                m_Camera = Camera.main;
            }

            if (m_Camera != null)
            {
                var thumbnailPositionRotation = FreeFlyCamera.CalculateViewFitPosition(projectStateData.rootBounds, 20.0f, 0.90f, m_Camera.fieldOfView, m_Camera.aspect);
                var thumbnailTexture          = CaptureCameraFrame(
                    m_Camera,
                    k_ThumbnailDimension, k_ThumbnailDimension,
                    thumbnailPositionRotation,
                    m_ThumbnailMask);

                var imageData = thumbnailTexture.EncodeToPNG();
                var path      = GetProjectThumbnailSavePath(m_ActiveProjectGetter.GetValue());
                File.WriteAllBytes(path, imageData);
                return(Sprite.Create(thumbnailTexture, new Rect(0, 0, thumbnailTexture.width, thumbnailTexture.height), new Vector2(0.5f, 0.5f), 100.0f));
            }
            return(null);
        }
        public Sprite CaptureActiveProjectThumbnail(UIProjectStateData projectStateData)
        {
            if (m_Camera == null || !m_Camera.gameObject.activeInHierarchy)
            {
                m_Camera = Camera.main;
            }

            if (m_Camera != null)
            {
                var thumbnailPositionRotation = FreeFlyCamera.CalculateViewFitPosition(projectStateData.rootBounds, 20.0f, 0.75f, m_Camera.fieldOfView);
                var thumbnailTexture          = CaptureCameraFrame(
                    m_Camera,
                    k_ThumbnailDimension, k_ThumbnailDimension,
                    thumbnailPositionRotation,
                    m_ThumbnailMask,
                    m_CameraFeaturesToDisable); // There are some issue with SSAO, needs to disable it before Rendering or everything comes black

                var imageData = thumbnailTexture.EncodeToPNG();
                var path      = GetProjectThumbnailSavePath(projectStateData.activeProject);
                File.WriteAllBytes(path, imageData);
                return(Sprite.Create(thumbnailTexture, new Rect(0, 0, thumbnailTexture.width, thumbnailTexture.height), new Vector2(0.5f, 0.5f), 100.0f));
            }
            return(null);
        }