2024-03-05 16:19:54 +08:00
|
|
|
|
#region
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2024-02-18 19:21:26 +08:00
|
|
|
|
using nadena.dev.ndmf;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2024-03-05 16:19:54 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2024-02-18 19:21:26 +08:00
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor
|
|
|
|
|
{
|
|
|
|
|
internal class ScaleAdjusterPass : Pass<ScaleAdjusterPass>
|
|
|
|
|
{
|
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<Transform, Transform> boneMappings = new Dictionary<Transform, Transform>();
|
2024-03-05 16:19:54 +08:00
|
|
|
|
|
|
|
|
|
foreach (var adjuster in context.AvatarRootObject.GetComponentsInChildren<ModularAvatarScaleAdjuster>(true))
|
2024-02-18 19:21:26 +08:00
|
|
|
|
{
|
2024-03-05 16:19:54 +08:00
|
|
|
|
var proxyObject = new GameObject("ScaleProxy");
|
|
|
|
|
var proxyTransform = proxyObject.transform;
|
|
|
|
|
|
|
|
|
|
proxyTransform.SetParent(adjuster.transform, false);
|
|
|
|
|
proxyTransform.localPosition = Vector3.zero;
|
|
|
|
|
proxyTransform.localRotation = Quaternion.identity;
|
|
|
|
|
proxyTransform.localScale = adjuster.Scale;
|
|
|
|
|
|
|
|
|
|
boneMappings.Add(adjuster.transform, proxyTransform);
|
|
|
|
|
|
|
|
|
|
Object.DestroyImmediate(adjuster);
|
2024-02-18 19:21:26 +08:00
|
|
|
|
}
|
2024-03-05 16:19:54 +08:00
|
|
|
|
|
|
|
|
|
// Legacy cleanup
|
2024-06-03 08:52:08 +08:00
|
|
|
|
/*foreach (var sar in context.AvatarRootObject.GetComponentsInChildren<ScaleAdjusterRenderer>())
|
2024-02-18 19:21:26 +08:00
|
|
|
|
{
|
2024-03-05 16:19:54 +08:00
|
|
|
|
Object.DestroyImmediate(sar.gameObject);
|
|
|
|
|
}
|
|
|
|
|
foreach (var sar in context.AvatarRootObject.GetComponentsInChildren<ScaleProxy>())
|
|
|
|
|
{
|
|
|
|
|
Object.DestroyImmediate(sar.gameObject);
|
2024-06-03 08:52:08 +08:00
|
|
|
|
}*/
|
2024-02-18 19:21:26 +08:00
|
|
|
|
|
2024-02-19 16:27:36 +08:00
|
|
|
|
if (boneMappings.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 16:22:47 +08:00
|
|
|
|
foreach (var smr in context.AvatarRootObject.GetComponentsInChildren<SkinnedMeshRenderer>(true))
|
2024-02-18 19:21:26 +08:00
|
|
|
|
{
|
|
|
|
|
var bones = smr.bones;
|
|
|
|
|
for (int i = 0; i < bones.Length; i++)
|
|
|
|
|
{
|
2024-02-19 16:27:36 +08:00
|
|
|
|
if (bones[i] != null && boneMappings.TryGetValue(bones[i], out var newBone))
|
2024-02-18 19:21:26 +08:00
|
|
|
|
{
|
|
|
|
|
bones[i] = newBone;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
smr.bones = bones;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|