Files
AutoMorpherDecompiled/Assets/@Eden_Tools/Eden_AutoMorpher/Script/ClothHumanoidMaskUtil.cs

306 lines
11 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.ClothHumanoidMaskUtil
using System.Collections.Generic;
using UnityEngine;
public class ClothHumanoidMaskUtil
{
public void BuildExcludedVertexMaskForHandsAndHead(ClothInstance clothInstance, bool excludeHandRoot = false, bool excludeThumbRoot = false)
{
//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
if (clothInstance == null || (Object)(object)clothInstance.smr == (Object)null)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] clothInstance / smr 가 null");
return;
}
SkinnedMeshRenderer smr = clothInstance.smr;
Mesh val = clothInstance.editableMesh ?? smr.sharedMesh;
if ((Object)(object)val == (Object)null)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] mesh 가 null");
return;
}
BoneWeight[] boneWeights = val.boneWeights;
Transform[] bones = smr.bones;
if (boneWeights == null || boneWeights.Length == 0 || bones == null || bones.Length == 0)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] boneWeights 또는 bones 비어있음");
return;
}
if (clothInstance.humanoidMatchedBones == null || clothInstance.humanoidMatchedBones.Count == 0)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] humanoidMatchedBones 가 비어있음 (BodyToClothPoseApplier에서 매칭 안 되었을 가능성)");
return;
}
int num = val.vertexCount;
if (boneWeights.Length != num)
{
num = Mathf.Min(num, boneWeights.Length);
}
HashSet<Transform> excludedBones = new HashSet<Transform>();
Dictionary<HumanBodyBones, HashSet<Transform>> humanoidMatchedBones = clothInstance.humanoidMatchedBones;
if (humanoidMatchedBones.TryGetValue((HumanBodyBones)10, out var value) && value != null)
{
foreach (Transform item in value)
{
if (!((Object)(object)item == (Object)null))
{
AddHierarchy(item, includeRoot: true);
}
}
}
if (humanoidMatchedBones.TryGetValue((HumanBodyBones)17, out var value2) && value2 != null)
{
foreach (Transform item2 in value2)
{
if (!((Object)(object)item2 == (Object)null))
{
AddHierarchy(item2, excludeHandRoot);
}
}
}
if (humanoidMatchedBones.TryGetValue((HumanBodyBones)18, out var value3) && value3 != null)
{
foreach (Transform item3 in value3)
{
if (!((Object)(object)item3 == (Object)null))
{
AddHierarchy(item3, excludeHandRoot);
}
}
}
if (humanoidMatchedBones.TryGetValue((HumanBodyBones)24, out var value4) && value4 != null)
{
foreach (Transform item4 in value4)
{
if (!((Object)(object)item4 == (Object)null))
{
if (excludeThumbRoot)
{
excludedBones.Add(item4);
}
else
{
excludedBones.Remove(item4);
}
}
}
}
if (humanoidMatchedBones.TryGetValue((HumanBodyBones)39, out var value5) && value5 != null)
{
foreach (Transform item5 in value5)
{
if (!((Object)(object)item5 == (Object)null))
{
if (excludeThumbRoot)
{
excludedBones.Add(item5);
}
else
{
excludedBones.Remove(item5);
}
}
}
}
bool[] boneIndexExcluded = new bool[bones.Length];
for (int i = 0; i < bones.Length; i++)
{
Transform val2 = bones[i];
if ((Object)(object)val2 != (Object)null && excludedBones.Contains(val2))
{
boneIndexExcluded[i] = true;
}
}
bool[] array = new bool[num];
for (int j = 0; j < num; j++)
{
BoneWeight val3 = boneWeights[j];
float excludedWeightSum = 0f;
AddExcludedWeight(val3.weight0, val3.boneIndex0);
AddExcludedWeight(val3.weight1, val3.boneIndex1);
AddExcludedWeight(val3.weight2, val3.boneIndex2);
AddExcludedWeight(val3.weight3, val3.boneIndex3);
array[j] = excludedWeightSum >= 0.8f;
void AddExcludedWeight(float w, int bi)
{
if (!(w <= 0f) && bi >= 0 && bi < boneIndexExcluded.Length && boneIndexExcluded[bi])
{
excludedWeightSum += w;
}
}
}
clothInstance.excludedVertices = array;
this.BuildLegVertexMasks(clothInstance);
void AddHierarchy(Transform root, bool includeRoot)
{
if (!((Object)(object)root == (Object)null))
{
Stack<Transform> stack = new Stack<Transform>();
if (includeRoot)
{
stack.Push(root);
}
else
{
for (int k = 0; k < root.childCount; k++)
{
stack.Push(root.GetChild(k));
}
}
while (stack.Count > 0)
{
Transform val4 = stack.Pop();
if (!((Object)(object)val4 == (Object)null) && excludedBones.Add(val4))
{
for (int l = 0; l < val4.childCount; l++)
{
stack.Push(val4.GetChild(l));
}
}
}
}
}
}
public void BuildLegVertexMasks(ClothInstance clothInstance)
{
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
if (clothInstance == null || (Object)(object)clothInstance.smr == (Object)null)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] clothInstance / smr 가 null");
return;
}
SkinnedMeshRenderer smr = clothInstance.smr;
Mesh val = clothInstance.editableMesh ?? smr.sharedMesh;
if ((Object)(object)val == (Object)null)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] mesh 가 null");
return;
}
BoneWeight[] boneWeights = val.boneWeights;
Transform[] bones = smr.bones;
if (boneWeights == null || boneWeights.Length == 0 || bones == null || bones.Length == 0)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] boneWeights 또는 bones 비어있음");
return;
}
if (clothInstance.humanoidMatchedBones == null || clothInstance.humanoidMatchedBones.Count == 0)
{
Debug.LogWarning((object)"[ClothHumanoidMaskUtil] humanoidMatchedBones 가 비어있음 (BodyToClothPoseApplier에서 매칭 필요)");
return;
}
int num = val.vertexCount;
if (boneWeights.Length != num)
{
num = Mathf.Min(num, boneWeights.Length);
}
Dictionary<HumanBodyBones, HashSet<Transform>> humanoidMatchedBones = clothInstance.humanoidMatchedBones;
HashSet<Transform> hashSet = new HashSet<Transform>();
HashSet<Transform> hashSet2 = new HashSet<Transform>();
if (humanoidMatchedBones.TryGetValue((HumanBodyBones)1, out var value) && value != null)
{
foreach (Transform item in value)
{
if (!((Object)(object)item == (Object)null))
{
CollectHierarchy(item, hashSet);
}
}
}
if (humanoidMatchedBones.TryGetValue((HumanBodyBones)2, out var value2) && value2 != null)
{
foreach (Transform item2 in value2)
{
if (!((Object)(object)item2 == (Object)null))
{
CollectHierarchy(item2, hashSet2);
}
}
}
bool[] boneIsLeftLeg = new bool[bones.Length];
bool[] boneIsRightLeg = new bool[bones.Length];
for (int i = 0; i < bones.Length; i++)
{
Transform val2 = bones[i];
if (!((Object)(object)val2 == (Object)null))
{
if (hashSet.Contains(val2))
{
boneIsLeftLeg[i] = true;
}
if (hashSet2.Contains(val2))
{
boneIsRightLeg[i] = true;
}
}
}
bool[] array = new bool[num];
bool[] array2 = new bool[num];
for (int j = 0; j < num; j++)
{
BoneWeight val3 = boneWeights[j];
float leftWeight = 0f;
float rightWeight = 0f;
Check(val3.boneIndex0, val3.weight0);
Check(val3.boneIndex1, val3.weight1);
Check(val3.boneIndex2, val3.weight2);
Check(val3.boneIndex3, val3.weight3);
if (leftWeight > 0.8f)
{
array[j] = true;
array2[j] = false;
}
else if (rightWeight > 0.8f)
{
array[j] = false;
array2[j] = true;
}
else
{
array[j] = false;
array2[j] = false;
}
void Check(int bi, float w)
{
if (bi >= 0 && bi < bones.Length && !(w <= 0f))
{
if (boneIsLeftLeg[bi])
{
leftWeight += w;
}
if (boneIsRightLeg[bi])
{
rightWeight += w;
}
}
}
}
clothInstance.isLeftLegVertex = array;
clothInstance.isRightLegVertex = array2;
void CollectHierarchy(Transform root, HashSet<Transform> set)
{
if (!((Object)(object)root == (Object)null))
{
Stack<Transform> stack = new Stack<Transform>();
stack.Push(root);
while (stack.Count > 0)
{
Transform val4 = stack.Pop();
if (!((Object)(object)val4 == (Object)null) && set.Add(val4))
{
for (int k = 0; k < val4.childCount; k++)
{
stack.Push(val4.GetChild(k));
}
}
}
}
}
}
}