From 2efcc670dffb457d1179338603aa0bb766d9085b Mon Sep 17 00:00:00 2001 From: bd_ Date: Wed, 3 Jul 2024 12:00:27 +0900 Subject: [PATCH] fix: performance issues with Scale Adjuster Preview (#912) * fix: performance issues with Scale Adjuster Preview * chore: update .gitignore --- .gitignore | 3 ++- Editor/ScaleAdjuster/ScaleAdjusterPreview.cs | 27 +++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5e97fe2c..5cdaa9c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -UnitTests/ +UnitTests UnitTests.meta +/UnitTests/ diff --git a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs index 5177a872..b983aafb 100644 --- a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs +++ b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs @@ -65,7 +65,7 @@ namespace nadena.dev.modular_avatar.core.editor public Task Instantiate(RenderGroup group, IEnumerable<(Renderer, Renderer)> proxyPairs, ComputeContext context) { - return Task.FromResult((IRenderFilterNode)new ScaleAdjusterPreviewNode()); + return new ScaleAdjusterPreviewNode().Refresh(proxyPairs, context, 0); } } @@ -83,6 +83,9 @@ namespace nadena.dev.modular_avatar.core.editor // blendshapes themselves. public RenderAspects WhatChanged => 0; + private readonly Dictionary _boneOverrides + = new(new ObjectIdentityComparer()); + public Task Refresh ( IEnumerable<(Renderer, Renderer)> proxyPairs, @@ -90,6 +93,23 @@ namespace nadena.dev.modular_avatar.core.editor RenderAspects updatedAspects ) { + var pair = proxyPairs.First(); + Renderer original = pair.Item1; + Renderer proxy = pair.Item2; + + if (original != null && proxy != null && original is SkinnedMeshRenderer smr) + { + _boneOverrides.Clear(); + + foreach (var bone in smr.bones) + { + var sa = bone?.GetComponent(); + if (sa != null) { + _boneOverrides.Add(bone, sa); + } + } + } + return Task.FromResult((IRenderFilterNode)this); } @@ -100,8 +120,9 @@ namespace nadena.dev.modular_avatar.core.editor p_smr.rootBone = _bones.GetBone(o_smr.rootBone)?.proxy ?? o_smr.rootBone; p_smr.bones = o_smr.bones.Select(b => { - var sa = (Component)b?.GetComponent(); - return _bones.GetBone(sa ?? b, true)?.proxy ?? b; + _boneOverrides.TryGetValue(b, out var sa); + + return _bones.GetBone(sa, true)?.proxy ?? b; }).ToArray(); }