236 lines
12 KiB
C#
236 lines
12 KiB
C#
// Warning: Some assembly references could not be resolved automatically. This might lead to incorrect decompilation of some parts,
|
|
// for ex. property getter/setter access. To get optimal decompilation results, please manually add the missing references to the list of loaded assemblies.
|
|
// EdenAutoMorpherScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
|
// Eden.AutoMorpher.BodyPoseMatchSetupUtil
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class BodyPoseMatchSetupUtil
|
|
{
|
|
public void AdjustAvatarScaleByNeck(Transform avatarRoot, Dictionary<HumanBodyBones, HashSet<Transform>> humanBoneMap, float targetHeight)
|
|
{
|
|
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((Object)(object)avatarRoot == (Object)null)
|
|
{
|
|
Debug.LogWarning((object)"[AvatarBodyMatchUtil] NormalizeAvatarScaleByNeck: avatar == null");
|
|
return;
|
|
}
|
|
Transform boneFromBoneMap = new BodyPoseMatch_CommonUtil().GetBoneFromBoneMap(humanBoneMap, (HumanBodyBones)9);
|
|
if ((Object)(object)boneFromBoneMap == (Object)null)
|
|
{
|
|
Debug.LogWarning((object)("[AvatarBodyMatchUtil] " + ((Object)avatarRoot).name + " 에서 Neck 본을 찾지 못했습니다. 스케일 정규화를 건너뜁니다."));
|
|
return;
|
|
}
|
|
Transform transform = ((Component)avatarRoot).transform;
|
|
float num = boneFromBoneMap.position.y - transform.position.y;
|
|
if (Mathf.Approximately(num, 0f))
|
|
{
|
|
Debug.LogWarning((object)$"[AvatarBodyMatchUtil] {((Object)avatarRoot).name} Neck Y가 0에 가까워 스케일 계산을 건너뜁니다. (neckY = {num})");
|
|
return;
|
|
}
|
|
float num2 = targetHeight / num;
|
|
Vector3 localScale = transform.localScale;
|
|
localScale *= num2;
|
|
transform.localScale = localScale;
|
|
}
|
|
|
|
public GameObject CreateBodyProxy(Animator sourceAvatar, IReadOnlyList<SkinnedMeshRenderer> sourceBodyMeshes, out List<SkinnedMeshRenderer> proxyBodyMeshes, out Dictionary<Transform, Transform> sourceToProxy)
|
|
{
|
|
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
|
|
proxyBodyMeshes = null;
|
|
if ((Object)(object)sourceAvatar == (Object)null)
|
|
{
|
|
Debug.LogError((object)"[AvatarBodyMatchUtil] CreateSourceBodyProxy: sourceAvatar == null");
|
|
sourceToProxy = new Dictionary<Transform, Transform>();
|
|
return null;
|
|
}
|
|
GameObject clone = Object.Instantiate<GameObject>(((Component)sourceAvatar).gameObject);
|
|
((Object)clone).name = ((Object)sourceAvatar).name + "_BodyProxy";
|
|
HashSet<Transform> remainTransforms = new HashSet<Transform>();
|
|
remainTransforms.Add(clone.transform);
|
|
Animator component = clone.GetComponent<Animator>();
|
|
if ((Object)(object)component != (Object)null)
|
|
{
|
|
((Behaviour)component).enabled = false;
|
|
remainTransforms.Add(((Component)component).transform);
|
|
}
|
|
if ((Object)(object)component != (Object)null && (Object)(object)component.avatar != (Object)null && component.avatar.isHuman)
|
|
{
|
|
for (int i = 0; i < 55; i++)
|
|
{
|
|
HumanBodyBones val = (HumanBodyBones)i;
|
|
Transform boneTransform = component.GetBoneTransform(val);
|
|
if ((Object)(object)boneTransform != (Object)null)
|
|
{
|
|
remainTransforms.Add(boneTransform);
|
|
}
|
|
}
|
|
}
|
|
HashSet<Mesh> hashSet = new HashSet<Mesh>();
|
|
if (sourceBodyMeshes != null)
|
|
{
|
|
foreach (SkinnedMeshRenderer sourceBodyMesh in sourceBodyMeshes)
|
|
{
|
|
if (!((Object)(object)sourceBodyMesh == (Object)null) && !((Object)(object)sourceBodyMesh.sharedMesh == (Object)null))
|
|
{
|
|
hashSet.Add(sourceBodyMesh.sharedMesh);
|
|
}
|
|
}
|
|
}
|
|
SkinnedMeshRenderer[] componentsInChildren = clone.GetComponentsInChildren<SkinnedMeshRenderer>(true);
|
|
List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>();
|
|
SkinnedMeshRenderer[] array = componentsInChildren;
|
|
foreach (SkinnedMeshRenderer val2 in array)
|
|
{
|
|
if (!((Object)(object)val2 == (Object)null))
|
|
{
|
|
Mesh sharedMesh = val2.sharedMesh;
|
|
if (!((Object)(object)sharedMesh == (Object)null) && hashSet.Contains(sharedMesh))
|
|
{
|
|
list.Add(val2);
|
|
}
|
|
}
|
|
}
|
|
if (list.Count == 0)
|
|
{
|
|
Debug.LogWarning((object)"[AvatarBodyMatchUtil] CreateSourceBodyProxy: clone에서 동일 sharedMesh를 가진 BodyMesh를 찾지 못했습니다.");
|
|
}
|
|
if (list.Count > 0)
|
|
{
|
|
MeshClassifier meshClassifier = new MeshClassifier();
|
|
foreach (SkinnedMeshRenderer item in list)
|
|
{
|
|
if ((Object)(object)item == (Object)null)
|
|
{
|
|
continue;
|
|
}
|
|
remainTransforms.Add(((Component)item).transform);
|
|
HashSet<Transform> activeBones = meshClassifier.GetActiveBones(item);
|
|
if (activeBones == null)
|
|
{
|
|
string[] obj = new string[5]
|
|
{
|
|
"[AvatarBodyMatchUtil] CreateSourceBodyProxy: clone smr '",
|
|
((Object)item).name,
|
|
"' has null bones array (mesh='",
|
|
null,
|
|
null
|
|
};
|
|
Mesh sharedMesh2 = item.sharedMesh;
|
|
obj[3] = ((sharedMesh2 != null) ? ((Object)sharedMesh2).name : null);
|
|
obj[4] = "')";
|
|
Debug.LogWarning((object)string.Concat(obj));
|
|
continue;
|
|
}
|
|
foreach (Transform item2 in activeBones)
|
|
{
|
|
if (!((Object)(object)item2 == (Object)null))
|
|
{
|
|
remainTransforms.Add(item2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
foreach (Transform item3 in remainTransforms.ToList())
|
|
{
|
|
AddWithParents(item3);
|
|
}
|
|
Transform[] componentsInChildren2 = clone.GetComponentsInChildren<Transform>(true);
|
|
for (int num = componentsInChildren2.Length - 1; num >= 0; num--)
|
|
{
|
|
Transform val3 = componentsInChildren2[num];
|
|
if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3 == (Object)(object)clone.transform) && !remainTransforms.Contains(val3))
|
|
{
|
|
Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
|
|
}
|
|
}
|
|
proxyBodyMeshes = list;
|
|
new BoneMatchUtil().BuildSourceToProxyBoneMap(sourceAvatar, component, out sourceToProxy);
|
|
return clone;
|
|
void AddWithParents(Transform t)
|
|
{
|
|
while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)clone.transform)
|
|
{
|
|
remainTransforms.Add(t);
|
|
t = t.parent;
|
|
}
|
|
}
|
|
}
|
|
|
|
public Vector3 GetComprehensiveScale(Transform rootT, Dictionary<HumanBodyBones, HashSet<Transform>> clothHumanoidBoneMap, ProfileData profileData)
|
|
{
|
|
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((Object)(object)rootT == (Object)null)
|
|
{
|
|
throw new AutoMorpherException("Root Transform is Missing", "[BodyPoseMatch_CommonUtil] GetComprehensiveScale\n - rootT is null");
|
|
}
|
|
if (profileData.bones == null || profileData.bones.Count == 0)
|
|
{
|
|
throw new AutoMorpherException("Profile Bones are Missing", "[BodyPoseMatch_CommonUtil] GetComprehensiveScale\n - profileData.bones is null or empty");
|
|
}
|
|
Transform val = null;
|
|
if (clothHumanoidBoneMap.TryGetValue((HumanBodyBones)0, out var value) && value != null && value.Count > 0)
|
|
{
|
|
foreach (Transform item in value)
|
|
{
|
|
if ((Object)(object)item != (Object)null)
|
|
{
|
|
val = item;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ((Object)(object)val == (Object)null)
|
|
{
|
|
throw new AutoMorpherException("Hip Transform is Missing", "[BodyPoseMatch_CommonUtil] GetComprehensiveScale\n - failed to get [hip] transform from clothHumanoidBoneMap");
|
|
}
|
|
BoneData val2 = null;
|
|
for (int i = 0; i < profileData.bones.Count; i++)
|
|
{
|
|
BoneData val3 = profileData.bones[i];
|
|
if (val3 != null && (int)val3.hBone == 0)
|
|
{
|
|
val2 = val3;
|
|
break;
|
|
}
|
|
}
|
|
if (val2 == null)
|
|
{
|
|
throw new AutoMorpherException("Hip Bone Data is Missing in Profile", "[BodyPoseMatch_CommonUtil] GetComprehensiveScale\n - profileData bones does not contain Hips");
|
|
}
|
|
Vector3 rootLocalScale = val2.rootLocalScale;
|
|
Vector3 lossyScale = rootT.lossyScale;
|
|
Vector3 lossyScale2 = val.lossyScale;
|
|
Vector3 val4 = new Vector3(lossyScale2.x / lossyScale.x, lossyScale2.y / lossyScale.y, lossyScale2.z / lossyScale.z);
|
|
return new Vector3(val4.x / rootLocalScale.x, val4.y / rootLocalScale.y, val4.z / rootLocalScale.z);
|
|
}
|
|
}
|