From 46d640bcd06956c9067a030b3d7f2e730b93e5a2 Mon Sep 17 00:00:00 2001 From: bd_ Date: Sun, 18 Aug 2024 12:55:38 -0700 Subject: [PATCH] feat: skip preview on most scene cameras (#335) This avoids O(n^2) preview costs when avatars have cameras attached. Closes: #331 --- CHANGELOG.md | 1 + Editor/PreviewSystem/ProxyManager.cs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d59cb0..b55d667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#330] Preview objects are now hidden by placing them in a hidden subscene, instead of harmony patching the hierarchy. This should improve stability in general. +- [#335] Skip preview rendering on all cameras except the scene view camera and the VRCSDK thumbnail camera. ### Removed diff --git a/Editor/PreviewSystem/ProxyManager.cs b/Editor/PreviewSystem/ProxyManager.cs index 6c9824c..8408da9 100644 --- a/Editor/PreviewSystem/ProxyManager.cs +++ b/Editor/PreviewSystem/ProxyManager.cs @@ -25,6 +25,14 @@ private static void Initialize() private static List<(Renderer, bool)> _resetActions = new(); + private static bool ShouldHookCamera(Camera cam) + { + if (cam.name == "SceneCamera" && cam.gameObject.hideFlags == HideFlags.HideAndDontSave) return true; + if (cam.name == "TempCamera" && cam.targetTexture?.name == "ThumbnailCapture") return true; + + return false; + } + private static void OnPostRender(Camera cam) { ResetStates(); @@ -34,6 +42,8 @@ private static void OnPreCull(Camera cam) { ResetStates(); + if (!ShouldHookCamera(cam)) return; + if (EditorApplication.isPlayingOrWillChangePlaymode) return; // TODO: fully support prefab isolation view