mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-01 20:25:07 +08:00
chore: reduce allocations in ScaleAdjusterPreview (#1015)
This commit is contained in:
parent
e5af635bd9
commit
b70727076c
@ -100,6 +100,8 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
private readonly Dictionary<Transform, ModularAvatarScaleAdjuster> _boneOverrides
|
private readonly Dictionary<Transform, ModularAvatarScaleAdjuster> _boneOverrides
|
||||||
= new(new ObjectIdentityComparer<Transform>());
|
= new(new ObjectIdentityComparer<Transform>());
|
||||||
|
|
||||||
|
private Transform[] _boneArray, _newBoneArray;
|
||||||
|
|
||||||
public Task<IRenderFilterNode> Refresh
|
public Task<IRenderFilterNode> Refresh
|
||||||
(
|
(
|
||||||
IEnumerable<(Renderer, Renderer)> proxyPairs,
|
IEnumerable<(Renderer, Renderer)> proxyPairs,
|
||||||
@ -122,6 +124,9 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
_boneOverrides.Add(bone, sa);
|
_boneOverrides.Add(bone, sa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_boneArray = context.Observe(smr, s => s.bones, Enumerable.SequenceEqual);
|
||||||
|
_newBoneArray = new Transform[_boneArray.Length];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult((IRenderFilterNode)this);
|
return Task.FromResult((IRenderFilterNode)this);
|
||||||
@ -129,16 +134,19 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
public void OnFrame(Renderer original, Renderer proxy)
|
public void OnFrame(Renderer original, Renderer proxy)
|
||||||
{
|
{
|
||||||
if (proxy is SkinnedMeshRenderer p_smr && original is SkinnedMeshRenderer o_smr)
|
if (_boneArray != null)
|
||||||
{
|
{
|
||||||
p_smr.rootBone = _bones.GetBone(o_smr.rootBone)?.proxy ?? o_smr.rootBone;
|
for (int i = 0; i < _boneArray.Length; i++)
|
||||||
p_smr.bones = o_smr.bones.Select(b =>
|
|
||||||
{
|
{
|
||||||
|
var b = _boneArray[i];
|
||||||
|
|
||||||
ModularAvatarScaleAdjuster sa = null;
|
ModularAvatarScaleAdjuster sa = null;
|
||||||
if (b != null) _boneOverrides.TryGetValue(b, out sa);
|
if (b != null) _boneOverrides.TryGetValue(b, out sa);
|
||||||
|
|
||||||
return _bones.GetBone(sa, true)?.proxy ?? b;
|
_newBoneArray[i] = _bones.GetBone(sa, true)?.proxy ?? b;
|
||||||
}).ToArray();
|
}
|
||||||
|
|
||||||
|
((SkinnedMeshRenderer)proxy).bones = _newBoneArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
_bones.Update();
|
_bones.Update();
|
||||||
|
Loading…
Reference in New Issue
Block a user