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

703 lines
28 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.ClothInstance
using System;
using System.Collections.Generic;
using Eden.AutoMorpher;
using UnityEngine;
[Serializable]
public class ClothInstance
{
public SkinnedMeshRenderer smr;
public Mesh editableMesh;
public Mesh bakedMesh;
public Matrix4x4 worldNoScale;
public Vector3[] worldVertices;
public Vector3[] minDistanceVector;
public float[] minDistance;
public Vector3[] deltas;
public Vector3[] deltasLocal;
public List<int>[] vertexAdjacency;
public List<List<int>> equivalentVertices;
public bool[] isInsideVertex;
public bool[] excludedVertices;
public bool[] isLeftLegVertex;
public bool[] isRightLegVertex;
public Vector3[] bakedWorldNormals;
public Vector4[] bakedWorldTangents;
public Dictionary<HumanBodyBones, HashSet<Transform>> humanoidMatchedBones;
public ClothInstance(SkinnedMeshRenderer clotheSMR, bool duplicateMesh = true)
{
smr = clotheSMR;
if (duplicateMesh)
{
string name = ((Object)smr.sharedMesh).name;
editableMesh = Object.Instantiate<Mesh>(clotheSMR.sharedMesh);
((Object)editableMesh).name = name + "_EditableMesh";
smr.sharedMesh = editableMesh;
}
else
{
editableMesh = smr.sharedMesh;
}
UpdateWorldVertices();
int vertexCount = editableMesh.vertexCount;
minDistanceVector = (Vector3[])(object)new Vector3[vertexCount];
deltas = (Vector3[])(object)new Vector3[vertexCount];
minDistance = new float[vertexCount];
isInsideVertex = new bool[vertexCount];
excludedVertices = new bool[vertexCount];
isLeftLegVertex = new bool[vertexCount];
isRightLegVertex = new bool[vertexCount];
humanoidMatchedBones = new Dictionary<HumanBodyBones, HashSet<Transform>>();
vertexAdjacency = BuildVertexAdjacency(editableMesh);
BuildEquivalentVerticesFromWorld();
}
public void UpdateWorldVertices()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: 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_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)bakedMesh == (Object)null)
{
bakedMesh = new Mesh();
}
else
{
bakedMesh.Clear();
}
smr.BakeMesh(bakedMesh);
int vertexCount = editableMesh.vertexCount;
Vector3 lossyScale = ((Component)smr).transform.lossyScale;
Vector3 val = default(Vector3);
((Vector3)(ref val))._002Ector(1f / Mathf.Max(lossyScale.x, 1E-08f), 1f / Mathf.Max(lossyScale.y, 1E-08f), 1f / Mathf.Max(lossyScale.z, 1E-08f));
worldNoScale = ((Component)smr).transform.localToWorldMatrix * Matrix4x4.Scale(val);
worldVertices = (Vector3[])(object)new Vector3[vertexCount];
deltasLocal = (Vector3[])(object)new Vector3[vertexCount];
for (int i = 0; i < vertexCount; i++)
{
worldVertices[i] = ((Matrix4x4)(ref worldNoScale)).MultiplyPoint3x4(bakedMesh.vertices[i]);
deltasLocal[i] = Vector3.zero;
}
Vector3[] normals = bakedMesh.normals;
Vector4[] tangents = bakedMesh.tangents;
bakedWorldNormals = (Vector3[])(object)new Vector3[vertexCount];
if (tangents != null && tangents.Length == vertexCount)
{
bakedWorldTangents = (Vector4[])(object)new Vector4[vertexCount];
}
else
{
bakedWorldTangents = null;
}
for (int j = 0; j < vertexCount; j++)
{
Vector3[] array = bakedWorldNormals;
int num = j;
Vector3 val2 = ((Component)smr).transform.TransformDirection(normals[j]);
array[num] = ((Vector3)(ref val2)).normalized;
if (bakedWorldTangents != null)
{
val2 = ((Component)smr).transform.TransformDirection(new Vector3(tangents[j].x, tangents[j].y, tangents[j].z));
Vector3 normalized = ((Vector3)(ref val2)).normalized;
bakedWorldTangents[j] = new Vector4(normalized.x, normalized.y, normalized.z, tangents[j].w);
}
}
}
public List<int>[] BuildVertexAdjacency(Mesh mesh, float seamThreshold = 0.0001f, float proximityThreshold = 0f)
{
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: 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_0367: Unknown result type (might be due to invalid IL or missing references)
//IL_036c: Unknown result type (might be due to invalid IL or missing references)
//IL_0370: Unknown result type (might be due to invalid IL or missing references)
//IL_037f: Unknown result type (might be due to invalid IL or missing references)
//IL_038e: Unknown result type (might be due to invalid IL or missing references)
//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: 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_03ee: Unknown result type (might be due to invalid IL or missing references)
//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0461: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_046f: Unknown result type (might be due to invalid IL or missing references)
//IL_0471: Unknown result type (might be due to invalid IL or missing references)
//IL_0290: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: 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_0511: Unknown result type (might be due to invalid IL or missing references)
//IL_0516: Unknown result type (might be due to invalid IL or missing references)
//IL_0490: Unknown result type (might be due to invalid IL or missing references)
//IL_0495: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_052b: Unknown result type (might be due to invalid IL or missing references)
//IL_0530: Unknown result type (might be due to invalid IL or missing references)
//IL_0532: Unknown result type (might be due to invalid IL or missing references)
//IL_0537: Unknown result type (might be due to invalid IL or missing references)
//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)mesh == (Object)null)
{
throw new AutoMorpherException("Mesh is Missing", "[VertexAdjacencyUtil] BuildVertexAdjacency\n - mesh is null");
}
int vertexCount = mesh.vertexCount;
int[] triangles = mesh.triangles;
Vector3[] vertices = mesh.vertices;
List<int>[] array = new List<int>[vertexCount];
for (int i = 0; i < vertexCount; i++)
{
array[i] = new List<int>();
}
int num = triangles.Length / 3;
for (int j = 0; j < num; j++)
{
int num2 = triangles[j * 3];
int num3 = triangles[j * 3 + 1];
int num4 = triangles[j * 3 + 2];
AddNeighbor(array, num2, num3);
AddNeighbor(array, num3, num2);
AddNeighbor(array, num3, num4);
AddNeighbor(array, num4, num3);
AddNeighbor(array, num4, num2);
AddNeighbor(array, num2, num4);
}
Vector3 val4;
if (seamThreshold > 0f)
{
float num5 = seamThreshold * 2f;
float num6 = seamThreshold * seamThreshold;
Dictionary<Vector3Int, List<int>> dictionary = new Dictionary<Vector3Int, List<int>>();
Vector3Int key = default(Vector3Int);
for (int k = 0; k < vertexCount; k++)
{
Vector3 val = vertices[k];
((Vector3Int)(ref key))._002Ector(Mathf.FloorToInt(val.x / num5), Mathf.FloorToInt(val.y / num5), Mathf.FloorToInt(val.z / num5));
if (!dictionary.TryGetValue(key, out var value))
{
value = (dictionary[key] = new List<int>());
}
value.Add(k);
}
Vector3Int val2 = default(Vector3Int);
foreach (KeyValuePair<Vector3Int, List<int>> item in dictionary)
{
Vector3Int key2 = item.Key;
List<int> value2 = item.Value;
for (int l = -1; l <= 1; l++)
{
for (int m = -1; m <= 1; m++)
{
for (int n = -1; n <= 1; n++)
{
if (l < 0 || (l == 0 && m < 0) || (l == 0 && m == 0 && n < 0))
{
continue;
}
((Vector3Int)(ref val2))._002Ector(((Vector3Int)(ref key2)).x + l, ((Vector3Int)(ref key2)).y + m, ((Vector3Int)(ref key2)).z + n);
if (!dictionary.TryGetValue(val2, out var value3))
{
continue;
}
if (val2 == key2)
{
for (int num7 = 0; num7 < value2.Count; num7++)
{
int num8 = value2[num7];
Vector3 val3 = vertices[num8];
for (int num9 = num7 + 1; num9 < value2.Count; num9++)
{
int num10 = value2[num9];
val4 = vertices[num10] - val3;
if (((Vector3)(ref val4)).sqrMagnitude <= num6)
{
AddNeighbor(array, num8, num10);
AddNeighbor(array, num10, num8);
}
}
}
continue;
}
for (int num11 = 0; num11 < value2.Count; num11++)
{
int num12 = value2[num11];
Vector3 val5 = vertices[num12];
for (int num13 = 0; num13 < value3.Count; num13++)
{
int num14 = value3[num13];
val4 = vertices[num14] - val5;
if (((Vector3)(ref val4)).sqrMagnitude <= num6)
{
AddNeighbor(array, num12, num14);
AddNeighbor(array, num14, num12);
}
}
}
}
}
}
}
}
if (proximityThreshold > 0f)
{
float num15 = proximityThreshold * 2f;
float num16 = proximityThreshold * proximityThreshold;
Dictionary<Vector3Int, List<int>> dictionary2 = new Dictionary<Vector3Int, List<int>>();
Vector3Int key3 = default(Vector3Int);
for (int num17 = 0; num17 < vertexCount; num17++)
{
Vector3 val6 = vertices[num17];
((Vector3Int)(ref key3))._002Ector(Mathf.FloorToInt(val6.x / num15), Mathf.FloorToInt(val6.y / num15), Mathf.FloorToInt(val6.z / num15));
if (!dictionary2.TryGetValue(key3, out var value4))
{
value4 = (dictionary2[key3] = new List<int>());
}
value4.Add(num17);
}
Vector3Int val7 = default(Vector3Int);
foreach (KeyValuePair<Vector3Int, List<int>> item2 in dictionary2)
{
Vector3Int key4 = item2.Key;
List<int> value5 = item2.Value;
for (int num18 = -1; num18 <= 1; num18++)
{
for (int num19 = -1; num19 <= 1; num19++)
{
for (int num20 = -1; num20 <= 1; num20++)
{
if (num18 < 0 || (num18 == 0 && num19 < 0) || (num18 == 0 && num19 == 0 && num20 < 0))
{
continue;
}
((Vector3Int)(ref val7))._002Ector(((Vector3Int)(ref key4)).x + num18, ((Vector3Int)(ref key4)).y + num19, ((Vector3Int)(ref key4)).z + num20);
if (!dictionary2.TryGetValue(val7, out var value6))
{
continue;
}
if (val7 == key4)
{
for (int num21 = 0; num21 < value5.Count; num21++)
{
int num22 = value5[num21];
Vector3 val8 = vertices[num22];
for (int num23 = num21 + 1; num23 < value5.Count; num23++)
{
int num24 = value5[num23];
val4 = vertices[num24] - val8;
if (((Vector3)(ref val4)).sqrMagnitude <= num16)
{
AddNeighbor(array, num22, num24);
AddNeighbor(array, num24, num22);
}
}
}
continue;
}
for (int num25 = 0; num25 < value5.Count; num25++)
{
int num26 = value5[num25];
Vector3 val9 = vertices[num26];
for (int num27 = 0; num27 < value6.Count; num27++)
{
int num28 = value6[num27];
val4 = vertices[num28] - val9;
if (((Vector3)(ref val4)).sqrMagnitude <= num16)
{
AddNeighbor(array, num26, num28);
AddNeighbor(array, num28, num26);
}
}
}
}
}
}
}
}
return array;
void AddNeighbor(List<int>[] adj, int from, int to)
{
List<int> list3 = adj[from];
if (!list3.Contains(to))
{
list3.Add(to);
}
}
}
public void ApplyWorldVerticesToMesh()
{
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: 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_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0303: Unknown result type (might be due to invalid IL or missing references)
//IL_0308: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_0259: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_0271: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
//IL_0326: Unknown result type (might be due to invalid IL or missing references)
//IL_032b: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0314: Unknown result type (might be due to invalid IL or missing references)
//IL_0319: Unknown result type (might be due to invalid IL or missing references)
//IL_031e: Unknown result type (might be due to invalid IL or missing references)
//IL_037e: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_039f: Unknown result type (might be due to invalid IL or missing references)
//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
//IL_038b: Unknown result type (might be due to invalid IL or missing references)
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_0396: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)editableMesh == (Object)null || (Object)(object)smr == (Object)null || worldVertices == null)
{
return;
}
Mesh val = editableMesh;
int vertexCount = val.vertexCount;
Vector3[] vertices = val.vertices;
SkinningUtil skinningUtil = new SkinningUtil();
Vector3[] array = null;
int blendShapeCount = val.blendShapeCount;
if (blendShapeCount > 0)
{
array = (Vector3[])(object)new Vector3[vertexCount];
Vector3[] array2 = (Vector3[])(object)new Vector3[vertexCount];
Vector3[] array3 = (Vector3[])(object)new Vector3[vertexCount];
Vector3[] array4 = (Vector3[])(object)new Vector3[vertexCount];
for (int i = 0; i < blendShapeCount; i++)
{
float blendShapeWeight = smr.GetBlendShapeWeight(i);
if (Mathf.Approximately(blendShapeWeight, 0f))
{
continue;
}
int num = val.GetBlendShapeFrameCount(i) - 1;
float blendShapeFrameWeight = val.GetBlendShapeFrameWeight(i, num);
val.GetBlendShapeFrameVertices(i, num, array2, array3, array4);
float num2 = ((blendShapeFrameWeight != 0f) ? (blendShapeWeight / blendShapeFrameWeight) : 0f);
if (!Mathf.Approximately(num2, 0f))
{
for (int j = 0; j < vertexCount; j++)
{
ref Vector3 reference = ref array[j];
reference += array2[j] * num2;
}
}
}
}
for (int k = 0; k < vertexCount; k++)
{
Vector3 val2 = skinningUtil.WorldPosToBindPos_Full(smr, val, k, worldVertices[k]);
if (array != null)
{
val2 -= array[k];
}
vertices[k] = val2;
}
val.vertices = vertices;
Vector3[] array5 = null;
Vector3[] array6 = null;
if (blendShapeCount > 0)
{
array5 = (Vector3[])(object)new Vector3[vertexCount];
array6 = (Vector3[])(object)new Vector3[vertexCount];
Vector3[] array7 = (Vector3[])(object)new Vector3[vertexCount];
Vector3[] array8 = (Vector3[])(object)new Vector3[vertexCount];
Vector3[] array9 = (Vector3[])(object)new Vector3[vertexCount];
for (int l = 0; l < blendShapeCount; l++)
{
float blendShapeWeight2 = smr.GetBlendShapeWeight(l);
if (Mathf.Approximately(blendShapeWeight2, 0f))
{
continue;
}
int num3 = val.GetBlendShapeFrameCount(l) - 1;
float blendShapeFrameWeight2 = val.GetBlendShapeFrameWeight(l, num3);
val.GetBlendShapeFrameVertices(l, num3, array7, array8, array9);
float num4 = ((blendShapeFrameWeight2 != 0f) ? (blendShapeWeight2 / blendShapeFrameWeight2) : 0f);
if (!Mathf.Approximately(num4, 0f))
{
for (int m = 0; m < vertexCount; m++)
{
ref Vector3 reference2 = ref array5[m];
reference2 += array8[m] * num4;
ref Vector3 reference3 = ref array6[m];
reference3 += array9[m] * num4;
}
}
}
}
if (bakedWorldNormals == null || bakedWorldNormals.Length != vertexCount)
{
return;
}
Vector3[] array10 = (Vector3[])(object)new Vector3[vertexCount];
bool flag = bakedWorldTangents != null && bakedWorldTangents.Length == vertexCount;
Vector4[] array11 = (Vector4[])(object)(flag ? new Vector4[vertexCount] : null);
Vector3 targetWorldDir = default(Vector3);
for (int n = 0; n < vertexCount; n++)
{
Vector3 val3 = skinningUtil.WorldDirToBindDir_Full(smr, val, n, bakedWorldNormals[n]);
if (array5 != null)
{
val3 -= array5[n];
}
array10[n] = ((Vector3)(ref val3)).normalized;
if (flag)
{
((Vector3)(ref targetWorldDir))._002Ector(bakedWorldTangents[n].x, bakedWorldTangents[n].y, bakedWorldTangents[n].z);
Vector3 val4 = skinningUtil.WorldDirToBindDir_Full(smr, val, n, targetWorldDir);
if (array6 != null)
{
val4 -= array6[n];
}
val4 = ((Vector3)(ref val4)).normalized;
array11[n] = new Vector4(val4.x, val4.y, val4.z, bakedWorldTangents[n].w);
}
}
val.normals = array10;
if (array11 != null)
{
val.tangents = array11;
}
}
public void BuildEquivalentVerticesFromWorld(float maxDistance = 1E-05f)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: 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_013a: 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_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
if (worldVertices == null || worldVertices.Length == 0)
{
Debug.LogWarning((object)"[ClothInstance] BuildEquivalentVerticesFromWorld: worldVertices is null or empty. Call UpdateWorldVertices() first.");
return;
}
int num = worldVertices.Length;
if (equivalentVertices == null)
{
equivalentVertices = new List<List<int>>();
}
else
{
equivalentVertices.Clear();
}
float num2 = maxDistance * maxDistance;
Dictionary<Vector3Int, List<int>> dictionary = new Dictionary<Vector3Int, List<int>>();
Vector3Int key = default(Vector3Int);
for (int i = 0; i < num; i++)
{
Vector3 val = worldVertices[i];
((Vector3Int)(ref key))._002Ector(Mathf.FloorToInt(val.x / maxDistance), Mathf.FloorToInt(val.y / maxDistance), Mathf.FloorToInt(val.z / maxDistance));
if (!dictionary.TryGetValue(key, out var value))
{
value = (dictionary[key] = new List<int>());
}
value.Add(i);
}
foreach (KeyValuePair<Vector3Int, List<int>> item in dictionary)
{
List<int> value2 = item.Value;
int count = value2.Count;
if (count < 2)
{
continue;
}
int[] parent = new int[count];
for (int j = 0; j < count; j++)
{
parent[j] = j;
}
for (int k = 0; k < count; k++)
{
int num3 = value2[k];
Vector3 val2 = worldVertices[num3];
for (int l = k + 1; l < count; l++)
{
int num4 = value2[l];
Vector3 val3 = worldVertices[num4];
Vector3 val4 = val2 - val3;
if (((Vector3)(ref val4)).sqrMagnitude <= num2)
{
Union(k, l);
}
}
}
Dictionary<int, List<int>> dictionary2 = new Dictionary<int, List<int>>();
for (int m = 0; m < count; m++)
{
int key2 = Find(m);
if (!dictionary2.TryGetValue(key2, out var value3))
{
value3 = (dictionary2[key2] = new List<int>());
}
value3.Add(value2[m]);
}
foreach (List<int> value4 in dictionary2.Values)
{
if (value4.Count >= 2)
{
equivalentVertices.Add(value4);
}
}
int Find(int x)
{
if (parent[x] != x)
{
parent[x] = Find(parent[x]);
}
return parent[x];
}
void Union(int a, int b)
{
int num5 = Find(a);
int num6 = Find(b);
if (num5 != num6)
{
parent[num6] = num5;
}
}
}
}
~ClothInstance()
{
Dispose();
}
public void Dispose()
{
if ((Object)(object)bakedMesh != (Object)null)
{
Object.DestroyImmediate((Object)(object)bakedMesh);
bakedMesh = null;
}
worldVertices = null;
minDistanceVector = null;
minDistance = null;
deltas = null;
deltasLocal = null;
isInsideVertex = null;
excludedVertices = null;
isLeftLegVertex = null;
isRightLegVertex = null;
vertexAdjacency = null;
if (equivalentVertices != null)
{
for (int i = 0; i < equivalentVertices.Count; i++)
{
equivalentVertices[i]?.Clear();
}
equivalentVertices.Clear();
equivalentVertices = null;
}
humanoidMatchedBones = null;
smr = null;
editableMesh = null;
}
}