Skip to content

Commit

Permalink
feat: skip preview on most scene cameras (#335)
Browse files Browse the repository at this point in the history
This avoids O(n^2) preview costs when avatars have cameras attached.

Closes: #331
  • Loading branch information
bdunderscore authored Aug 18, 2024
1 parent e724e63 commit 46d640b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions Editor/PreviewSystem/ProxyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 46d640b

Please sign in to comment.