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

352 lines
19 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.MeshMatcher
using Eden.AutoMorpher;
using System.Collections.Generic;
using UnityEngine;
public class MeshMatcher
{
public struct ClosestHit
{
public Vector3 closestP;
public Vector3 direction;
public Vector3 moveVector;
public float distance;
}
public BvhTriangleMesh bodyBVH;
private readonly HashSet<HumanBodyBones> LeftLegBones = new HashSet<HumanBodyBones>
{
(HumanBodyBones)1,
(HumanBodyBones)3,
(HumanBodyBones)5,
(HumanBodyBones)19
};
private readonly HashSet<HumanBodyBones> RightLegBones = new HashSet<HumanBodyBones>
{
(HumanBodyBones)2,
(HumanBodyBones)4,
(HumanBodyBones)6,
(HumanBodyBones)20
};
public BvhTriangleMesh BuildBvhMulti(IReadOnlyList<SkinnedMeshRenderer> bodies, Animator bodyAnimator)
{
if (bodies == null || bodies.Count == 0)
{
throw new AutoMorpherException("Body Meshes are Missing", "[BuildBvhMulti] BuildBvhMulti\n - bodies is null or empty");
}
BvhTriangleMesh bvhTriangleMesh = new BvhTriangleMesh().BuildFromSkinnedMeshes(bodies, bodyAnimator);
if (bvhTriangleMesh == null || bvhTriangleMesh.triangles == null)
{
Debug.LogError((object)"Failed to build multi-body BVH (no triangles).");
throw new AutoMorpherException(LanguageManager.Get("UI.Exception.title.BodyBVHFail"), LanguageManager.GetFormat("UI.Exception.message.BodyBVHFail", new object[3]
{
((Object)((Component)bodyAnimator).gameObject).name,
bvhTriangleMesh == null,
bvhTriangleMesh.triangles == null
}));
}
return bvhTriangleMesh;
}
public Vector3[] ExpandVertexMatch(ClothInstance clothInstance, float defaultMinDist = 0.005f, bool skipFootFitting = false, float maxMatchDistance = 0.1f)
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Invalid comparison between Unknown and I4
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: 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_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Invalid comparison between Unknown and I4
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Invalid comparison between Unknown and I4
//IL_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Invalid comparison between Unknown and I4
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
Vector3[] worldVertices = clothInstance.worldVertices;
float[] minDistance = clothInstance.minDistance;
if (this.bodyBVH == null)
{
throw new AutoMorpherException("Body BVH is Missing", "[ExpandVertexMatch] ExpandVertexMatch\n - bodyBVH is null");
}
if (worldVertices == null)
{
throw new AutoMorpherException("Cloth World Vertices are Missing", "[ExpandVertexMatch] ExpandVertexMatch\n - clothInstance.worldVertices is null");
}
if (worldVertices.Length == 0)
{
Debug.LogWarning((object)"clothes mesh has no vertices");
return null;
}
if (minDistance == null)
{
Debug.LogWarning((object)"minDists is null");
}
if (minDistance.Length != worldVertices.Length)
{
Debug.LogWarning((object)"minDists.Length != worldVertexs.Length");
}
Vector3[] array = (Vector3[])(object)new Vector3[worldVertices.Length];
float num = maxMatchDistance * maxMatchDistance;
for (int i = 0; i < worldVertices.Length; i++)
{
if (clothInstance.excludedVertices[i])
{
array[i] = Vector3.zero;
continue;
}
if (clothInstance.isInsideVertex[i])
{
array[i] = Vector3.zero;
continue;
}
float num2 = minDistance[i] + defaultMinDist;
BvhTriangleMesh.ClosestHit closestHit = (clothInstance.isLeftLegVertex[i] ? this.bodyBVH.QueryClosest(worldVertices[i], this.LeftLegBones) : ((!clothInstance.isRightLegVertex[i]) ? this.bodyBVH.QueryClosest(worldVertices[i]) : this.bodyBVH.QueryClosest(worldVertices[i], this.RightLegBones)));
if (skipFootFitting && ((int)closestHit.mainHumanBone == 5 || (int)closestHit.mainHumanBone == 6 || (int)closestHit.mainHumanBone == 20 || (int)closestHit.mainHumanBone == 19))
{
array[i] = Vector3.zero;
continue;
}
if (closestHit.sqrDistance > num)
{
array[i] = Vector3.zero;
continue;
}
Vector3 val = closestHit.closestPoint - worldVertices[i];
Vector3 normalized = val.normalized;
float num3 = Vector3.Dot(normalized, closestHit.normal.normalized);
if (num3 > 0.7f)
{
array[i] = closestHit.closestPoint + normalized * num2 - worldVertices[i];
}
else if (num3 < -0.7f)
{
if (closestHit.sqrDistance < num2 * num2)
{
array[i] = closestHit.closestPoint - normalized * num2 - worldVertices[i];
}
}
else
{
array[i] = Vector3.zero;
}
}
return array;
}
public Vector3[] ShrinkVertexMatch(ClothInstance clothInstance, float defaultMinDist = 0.005f, float maxMatchDistance = 0.1f)
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Invalid comparison between Unknown and I4
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Invalid comparison between Unknown and I4
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Invalid comparison between Unknown and I4
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Invalid comparison between Unknown and I4
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
Vector3[] worldVertices = clothInstance.worldVertices;
float[] minDistance = clothInstance.minDistance;
if (this.bodyBVH == null)
{
throw new AutoMorpherException("Body BVH is Missing", "[ShrinkVertexMatch] ShrinkVertexMatch\n - bodyBVH is null");
}
if (worldVertices == null)
{
throw new AutoMorpherException("Cloth World Vertices are Missing", "[ShrinkVertexMatch] ShrinkVertexMatch\n - clothInstance.worldVertices is null");
}
if (worldVertices.Length == 0)
{
Debug.LogWarning((object)"clothes mesh has no vertices");
return null;
}
if (minDistance == null)
{
Debug.LogWarning((object)"minDists is null");
}
if (minDistance.Length != worldVertices.Length)
{
Debug.LogWarning((object)"minDists.Length != worldVertexs.Length");
}
Vector3[] array = (Vector3[])(object)new Vector3[worldVertices.Length];
float num = maxMatchDistance * maxMatchDistance;
_ = clothInstance.isLeftLegVertex;
_ = clothInstance.isRightLegVertex;
for (int i = 0; i < worldVertices.Length; i++)
{
if (clothInstance.excludedVertices[i])
{
array[i] = Vector3.zero;
continue;
}
if (clothInstance.isInsideVertex[i])
{
array[i] = Vector3.zero;
continue;
}
float num2 = minDistance[i] + defaultMinDist;
BvhTriangleMesh.ClosestHit closestHit = (clothInstance.isLeftLegVertex[i] ? this.bodyBVH.QueryClosest(worldVertices[i], this.LeftLegBones) : ((!clothInstance.isRightLegVertex[i]) ? this.bodyBVH.QueryClosest(worldVertices[i]) : this.bodyBVH.QueryClosest(worldVertices[i], this.RightLegBones)));
if (closestHit.sqrDistance > num)
{
array[i] = Vector3.zero;
continue;
}
if ((int)closestHit.mainHumanBone == 5 || (int)closestHit.mainHumanBone == 6 || (int)closestHit.mainHumanBone == 20 || (int)closestHit.mainHumanBone == 19)
{
array[i] = Vector3.zero;
continue;
}
Vector3 val = closestHit.closestPoint - worldVertices[i];
Vector3 normalized = val.normalized;
float num3 = Vector3.Dot(normalized, closestHit.normal.normalized);
if (num3 < -0.7f)
{
array[i] = closestHit.closestPoint - normalized * num2 - worldVertices[i];
}
else if (num3 < -0.7f)
{
if (closestHit.sqrDistance < num2 * num2)
{
array[i] = closestHit.closestPoint + normalized * num2 - worldVertices[i];
}
}
else
{
array[i] = Vector3.zero;
}
}
return array;
}
public Vector3[] GetMinDistanceToBody(Vector3[] clothesVertices)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
if (this.bodyBVH == null)
{
throw new AutoMorpherException("sourceBodyBVH is null", "[MeshMatcher] GetMinDistanceToBodysourceBodyBVH is null");
}
if (clothesVertices == null || clothesVertices.Length == 0)
{
throw new AutoMorpherException("Source Vertices is null", "[MeshMatcher] GetMinDistanceToBodySource Vertices is null or no vertices");
}
Vector3[] array = (Vector3[])(object)new Vector3[clothesVertices.Length];
for (int i = 0; i < clothesVertices.Length; i++)
{
Vector3 val = clothesVertices[i];
Vector3 val2 = this.bodyBVH.QueryClosest(val).closestPoint - val;
array[i] = val2;
}
return array;
}
public bool[] GetBodyInsideFlags(Vector3[] worldVertices)
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
if (this.bodyBVH == null)
{
throw new AutoMorpherException("sourceBodyBVH is null", "[MeshMatcher] GetBodyInsideFlagssourceBodyBVH is null");
}
if (worldVertices == null || worldVertices.Length == 0)
{
Debug.LogError((object)"clothes is null");
throw new AutoMorpherException("Source Vertices is null", "[MeshMatcher] GetMinDistanceToBodySource Vertices is null or no vertices");
}
bool[] array = new bool[worldVertices.Length];
for (int i = 0; i < worldVertices.Length; i++)
{
BvhTriangleMesh.ClosestHit closestHit = this.bodyBVH.QueryClosest(worldVertices[i]);
Vector3 val = closestHit.closestPoint - worldVertices[i];
float num = Vector3.Dot(val.normalized, closestHit.normal.normalized);
array[i] = num > 0f;
}
return array;
}
}