// 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.VertexFittingUtil
using System.Collections.Generic;
using System.Diagnostics;
using Eden.AutoMorpher;
using UnityEngine;

public class VertexFittingUtil
{
	private struct Node
	{
		public int index;

		public int depth;
	}

	public void ExpandClothes_World_Test(List<ClothInstance> clothInstances, MeshMatcher meshMatcher, EdenAutoMorpherConfig config, ClothInstanceTotal clothInstanceTotal)
	{
		using (AutoMorpherDev.Profile("[Expand] BVH Mesh Matching time"))
		{
			foreach (ClothInstance clothInstance in clothInstances)
			{
				clothInstance.deltas = meshMatcher.ExpandVertexMatch(clothInstance, config.minMargin, config.skipFootFitting);
			}
		}
		foreach (ClothInstance clothInstance2 in clothInstances)
		{
			clothInstance2.deltasLocal = clothInstance2.deltas;
		}
		Vector3[] deltas = clothInstanceTotal.GlobalDeltas;
		clothInstanceTotal.UpdateGlobalBuffersFromClothInstances();
		SmoothDeltasByDistance(clothInstanceTotal.GlobalPositions, ref deltas, clothInstanceTotal.GlobalAdjacencyMerged, config.worldRadius, 1, config.smoothingIteration, 0.5f, config.sigma);
		clothInstanceTotal.SetGlobalDeltas(deltas);
		clothInstanceTotal.ApplyGlobalDeltasToClothInstances();
		foreach (ClothInstance clothInstance3 in clothInstances)
		{
			for (int i = 0; i < clothInstance3.worldVertices.Length; i++)
			{
				if (!clothInstance3.excludedVertices[i] || !clothInstance3.isInsideVertex[i])
				{
					clothInstance3.worldVertices[i] += clothInstance3.deltasLocal[i];
				}
				clothInstance3.deltasLocal[i] = Vector3.zero;
			}
			foreach (List<int> equivalentVertex in clothInstance3.equivalentVertices)
			{
				Vector3 zero = Vector3.zero;
				for (int j = 0; j < equivalentVertex.Count; j++)
				{
					zero += clothInstance3.worldVertices[equivalentVertex[j]];
				}
				zero /= (float)equivalentVertex.Count;
				for (int k = 0; k < equivalentVertex.Count; k++)
				{
					clothInstance3.worldVertices[equivalentVertex[k]] = zero;
				}
			}
		}
	}

	public void ShrinkClothes_World_Test(List<ClothInstance> clothInstances, MeshMatcher meshMatcher, EdenAutoMorpherConfig config, ClothInstanceTotal clothInstanceTotal)
	{
		using (AutoMorpherDev.Profile("[Expand] BVH Mesh Matching time"))
		{
			foreach (ClothInstance clothInstance in clothInstances)
			{
				clothInstance.deltas = meshMatcher.ShrinkVertexMatch(clothInstance, config.minMargin);
			}
		}
		foreach (ClothInstance clothInstance2 in clothInstances)
		{
			clothInstance2.deltasLocal = clothInstance2.deltas;
		}
		Vector3[] deltas = clothInstanceTotal.GlobalDeltas;
		clothInstanceTotal.UpdateGlobalBuffersFromClothInstances();
		SmoothDeltasByDistance(clothInstanceTotal.GlobalPositions, ref deltas, clothInstanceTotal.GlobalAdjacencyMerged, config.worldRadius, 3, config.smoothingIteration, 0.5f, config.sigma);
		clothInstanceTotal.SetGlobalDeltas(deltas);
		clothInstanceTotal.ApplyGlobalDeltasToClothInstances();
		SmoothAllClothesDeltasByDistance(clothInstances, config.worldRadius, config.smoothingIteration, config.sigma);
		foreach (ClothInstance clothInstance3 in clothInstances)
		{
			for (int i = 0; i < clothInstance3.worldVertices.Length; i++)
			{
				if (!clothInstance3.excludedVertices[i] || !clothInstance3.isInsideVertex[i])
				{
					clothInstance3.worldVertices[i] += clothInstance3.deltasLocal[i];
				}
				clothInstance3.deltasLocal[i] = Vector3.zero;
			}
			foreach (List<int> equivalentVertex in clothInstance3.equivalentVertices)
			{
				Vector3 zero = Vector3.zero;
				for (int j = 0; j < equivalentVertex.Count; j++)
				{
					zero += clothInstance3.worldVertices[equivalentVertex[j]];
				}
				zero /= (float)equivalentVertex.Count;
				for (int k = 0; k < equivalentVertex.Count; k++)
				{
					clothInstance3.worldVertices[equivalentVertex[k]] = zero;
				}
			}
		}
	}

	public void ExpandClothes_World(ClothInstance clothInstance, List<ClothInstance> clothInstances, MeshMatcher meshMatcher, EdenAutoMorpherConfig config, float fittingRadius)
	{
		if (AutoMorpherDev.isDeveloperMode)
		{
			UnityEngine.Debug.Log("[Expand] Start " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
		}
		Stopwatch stopwatch = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
		Stopwatch.StartNew();
		using (AutoMorpherDev.Profile("[Expand] BVH Mesh Matching time"))
		{
			clothInstance.deltas = meshMatcher.ExpandVertexMatch(clothInstance, config.minMargin, config.skipFootFitting);
		}
		List<int> list = null;
		using (AutoMorpherDev.Profile("[Expand] Select Anchors time"))
		{
			list = SelectAnchors(clothInstance, fittingRadius);
		}
		if (AutoMorpherDev.isDeveloperMode)
		{
			UnityEngine.Debug.Log($"[Expand] Anchor Count {list.Count}");
		}
		if (list.Count == 0)
		{
			if (AutoMorpherDev.isDeveloperMode)
			{
				stopwatch.Stop();
				UnityEngine.Debug.Log($"[Expand] TOTAL ShrinkClothes time: {stopwatch.ElapsedMilliseconds} ms");
				UnityEngine.Debug.Log("[Expand] End " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
			}
			return;
		}
		Stopwatch stopwatch2 = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
		float num = 0f;
		float num2 = 0f;
		VertexMoverUtil vertexMoverUtil = new VertexMoverUtil();
		foreach (int item in list)
		{
			if (clothInstance.excludedVertices[item])
			{
				continue;
			}
			Stopwatch stopwatch3 = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
			if (AutoMorpherDev.isDeveloperMode)
			{
				UnityEngine.Debug.Log($"[Expand] Selected Expand Vertes: {clothInstance.smr.gameObject.name} / {item}");
				UnityEngine.Debug.Log($"[Expand] SelectedCEnter {item} {clothInstance.deltas[item]} {clothInstance.worldVertices[item]}");
			}
			Vector3[] array = vertexMoverUtil.MoveVertices(clothInstance, item, clothInstance.isLeftLegVertex[item], clothInstance.isRightLegVertex[item], fittingRadius, config.sigma, clothInstance.deltas[item]);
			if (array == null)
			{
				if (AutoMorpherDev.isDeveloperMode)
				{
					stopwatch3.Stop();
					num += (float)stopwatch3.ElapsedMilliseconds;
				}
				continue;
			}
			for (int i = 0; i < clothInstance.worldVertices.Length && i < array.Length; i++)
			{
				if (array[i] != Vector3.zero)
				{
					clothInstance.deltasLocal[i] += array[i];
				}
			}
			if (AutoMorpherDev.isDeveloperMode)
			{
				stopwatch3.Stop();
				num += (float)stopwatch3.ElapsedMilliseconds;
			}
			Stopwatch stopwatch4 = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
			foreach (ClothInstance clothInstance2 in clothInstances)
			{
				if (clothInstance2 == clothInstance)
				{
					continue;
				}
				Vector3[] array2 = vertexMoverUtil.MoveVertices(clothInstance2, clothInstance.worldVertices[item], clothInstance.isLeftLegVertex[item], clothInstance.isRightLegVertex[item], fittingRadius, config.sigma, clothInstance.deltas[item]);
				if (array2 == null)
				{
					continue;
				}
				for (int j = 0; j < clothInstance2.worldVertices.Length && j < array2.Length; j++)
				{
					if (array2[j] != Vector3.zero)
					{
						clothInstance2.deltasLocal[j] += array2[j];
					}
				}
			}
			if (AutoMorpherDev.isDeveloperMode)
			{
				stopwatch4.Stop();
				num2 += (float)stopwatch4.ElapsedMilliseconds;
			}
		}
		SmoothAllClothesDeltasByDistance(clothInstances, fittingRadius, config.smoothingIteration, config.sigma);
		foreach (ClothInstance clothInstance3 in clothInstances)
		{
			for (int k = 0; k < clothInstance3.worldVertices.Length; k++)
			{
				if (!clothInstance3.excludedVertices[k])
				{
					clothInstance3.worldVertices[k] += clothInstance3.deltasLocal[k];
				}
				clothInstance3.deltasLocal[k] = Vector3.zero;
			}
			foreach (List<int> equivalentVertex in clothInstance3.equivalentVertices)
			{
				Vector3 zero = Vector3.zero;
				for (int l = 0; l < equivalentVertex.Count; l++)
				{
					zero += clothInstance3.worldVertices[equivalentVertex[l]];
				}
				zero /= (float)equivalentVertex.Count;
				for (int m = 0; m < equivalentVertex.Count; m++)
				{
					clothInstance3.worldVertices[equivalentVertex[m]] = zero;
				}
			}
		}
		if (AutoMorpherDev.isDeveloperMode)
		{
			stopwatch2.Stop();
			UnityEngine.Debug.Log($"[Expand] Renderer Move Vector Calculate: {clothInstance.smr.gameObject.name} : {num}");
			UnityEngine.Debug.Log($"[Expand] Other Renderer Move Vector Calculate: {clothInstance.smr.gameObject.name} : {num2}");
			UnityEngine.Debug.Log($"[Expand] Total Move Vector Calculate: {clothInstance.smr.gameObject.name} : {stopwatch2.ElapsedMilliseconds}");
			stopwatch.Stop();
			UnityEngine.Debug.Log($"[Expand] TOTAL ShrinkClothes time: {stopwatch.ElapsedMilliseconds} ms");
			UnityEngine.Debug.Log("[Expand] End " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
		}
	}

	public void ShrinkClothes_World(ClothInstance clothInstance, List<ClothInstance> clothInstances, MeshMatcher meshMatcher, EdenAutoMorpherConfig config, float fittingRadius)
	{
		if (AutoMorpherDev.isDeveloperMode)
		{
			UnityEngine.Debug.Log("[Shrink] Start " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
		}
		Stopwatch stopwatch = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
		using (AutoMorpherDev.Profile("[Shrink] BVH Mesh Matching time"))
		{
			clothInstance.deltas = meshMatcher.ShrinkVertexMatch(clothInstance, config.minMargin);
		}
		List<int> list = null;
		using (AutoMorpherDev.Profile("[Shrink] Select Anchors time"))
		{
			list = SelectAnchors(clothInstance, fittingRadius);
		}
		if (AutoMorpherDev.isDeveloperMode)
		{
			UnityEngine.Debug.Log($"[Shrink] Anchor Count {list.Count}");
		}
		if (list.Count == 0)
		{
			if (AutoMorpherDev.isDeveloperMode)
			{
				stopwatch.Stop();
				UnityEngine.Debug.Log($"[Shrink] TOTAL ShrinkClothes time: {stopwatch.ElapsedMilliseconds} ms");
				UnityEngine.Debug.Log("[Shrink] End " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
			}
			return;
		}
		Stopwatch stopwatch2 = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
		float num = 0f;
		float num2 = 0f;
		VertexMoverUtil vertexMoverUtil = new VertexMoverUtil();
		foreach (int item in list)
		{
			if (clothInstance.excludedVertices[item])
			{
				continue;
			}
			Stopwatch stopwatch3 = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
			if (AutoMorpherDev.isDeveloperMode)
			{
				UnityEngine.Debug.Log($"[Shrink] Selected Expand Vertes: {clothInstance.smr.gameObject.name} / {item}");
				UnityEngine.Debug.Log($"[Shrink] SelectedCEnter {item} {clothInstance.deltas[item]} {clothInstance.worldVertices[item]}");
			}
			Vector3[] array = vertexMoverUtil.MoveVertices(clothInstance, item, clothInstance.isLeftLegVertex[item], clothInstance.isRightLegVertex[item], fittingRadius, config.sigma, clothInstance.deltas[item]);
			if (array == null)
			{
				stopwatch3.Stop();
				num += (float)stopwatch3.ElapsedMilliseconds;
				continue;
			}
			for (int i = 0; i < clothInstance.worldVertices.Length && i < array.Length; i++)
			{
				if (array[i] != Vector3.zero)
				{
					clothInstance.deltasLocal[i] += array[i];
				}
			}
			if (AutoMorpherDev.isDeveloperMode)
			{
				stopwatch3.Stop();
				num += (float)stopwatch3.ElapsedMilliseconds;
			}
			Stopwatch stopwatch4 = (AutoMorpherDev.isDeveloperMode ? Stopwatch.StartNew() : null);
			foreach (ClothInstance clothInstance2 in clothInstances)
			{
				if (clothInstance2 == clothInstance)
				{
					continue;
				}
				Vector3[] array2 = vertexMoverUtil.MoveVertices(clothInstance2, clothInstance.worldVertices[item], clothInstance.isLeftLegVertex[item], clothInstance.isRightLegVertex[item], fittingRadius, config.sigma, clothInstance.deltas[item]);
				if (array2 == null)
				{
					continue;
				}
				for (int j = 0; j < clothInstance2.worldVertices.Length && j < array2.Length; j++)
				{
					if (array2[j] != Vector3.zero)
					{
						clothInstance2.deltasLocal[j] += array2[j];
					}
				}
			}
			if (AutoMorpherDev.isDeveloperMode)
			{
				stopwatch4.Stop();
				num2 += (float)stopwatch4.ElapsedMilliseconds;
			}
		}
		SmoothAllClothesDeltasByDistance(clothInstances, fittingRadius, config.smoothingIteration, config.sigma);
		foreach (ClothInstance clothInstance3 in clothInstances)
		{
			for (int k = 0; k < clothInstance3.worldVertices.Length; k++)
			{
				if (!clothInstance3.excludedVertices[k])
				{
					clothInstance3.worldVertices[k] += clothInstance3.deltasLocal[k];
				}
				clothInstance3.deltasLocal[k] = Vector3.zero;
			}
			foreach (List<int> equivalentVertex in clothInstance3.equivalentVertices)
			{
				Vector3 zero = Vector3.zero;
				for (int l = 0; l < equivalentVertex.Count; l++)
				{
					zero += clothInstance3.worldVertices[equivalentVertex[l]];
				}
				zero /= (float)equivalentVertex.Count;
				for (int m = 0; m < equivalentVertex.Count; m++)
				{
					clothInstance3.worldVertices[equivalentVertex[m]] = zero;
				}
			}
		}
		if (AutoMorpherDev.isDeveloperMode)
		{
			stopwatch2.Stop();
			UnityEngine.Debug.Log($"[Shrink] Renderer Move Vector Calculate: {clothInstance.smr.gameObject.name} : {num}");
			UnityEngine.Debug.Log($"[Shrink] Other Renderer Move Vector Calculate: {clothInstance.smr.gameObject.name} : {num2}");
			UnityEngine.Debug.Log($"[Shrink] Total Move Vector Calculate: {clothInstance.smr.gameObject.name} : {stopwatch2.ElapsedMilliseconds}");
			stopwatch.Stop();
			UnityEngine.Debug.Log($"[Shrink] TOTAL ShrinkClothes time: {stopwatch.ElapsedMilliseconds} ms");
			UnityEngine.Debug.Log("[Shrink] End " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
		}
	}

	public void ExpandFitClothes_World(ClothInstance clothInstance, List<ClothInstance> clothInstances, MeshMatcher meshMatcher, float worldRadius, float sigma, float minMargin)
	{
		UnityEngine.Debug.Log("[Expand] " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
		Stopwatch stopwatch = Stopwatch.StartNew();
		Stopwatch stopwatch2 = Stopwatch.StartNew();
		clothInstance.deltas = meshMatcher.ExpandVertexMatch(clothInstance, minMargin);
		stopwatch2.Stop();
		UnityEngine.Debug.Log($"[Expand] BVH Mesh Matching time: {stopwatch2.ElapsedMilliseconds} ms");
		for (int i = 0; i < clothInstance.worldVertices.Length; i++)
		{
			clothInstance.worldVertices[i] += clothInstance.deltas[i];
			clothInstance.deltasLocal[i] = Vector3.zero;
		}
		foreach (List<int> equivalentVertex in clothInstance.equivalentVertices)
		{
			Vector3 zero = Vector3.zero;
			for (int j = 0; j < equivalentVertex.Count; j++)
			{
				zero += clothInstance.worldVertices[equivalentVertex[j]];
			}
			zero /= (float)equivalentVertex.Count;
			for (int k = 0; k < equivalentVertex.Count; k++)
			{
				clothInstance.worldVertices[equivalentVertex[k]] = zero;
			}
		}
		stopwatch.Stop();
		UnityEngine.Debug.Log($"[Expand] TOTAL ShrinkClothes time: {stopwatch.ElapsedMilliseconds} ms");
		UnityEngine.Debug.Log("[Expand] " + clothInstance.smr.gameObject.name + "//===============================================================================================================");
	}

	private List<int> SelectAnchors(ClothInstance clothInstance, float worldRadius, float minDeltaSq = 1E-05f, float maxDelta = 0.1f)
	{
		List<int> list = new List<int>();
		List<int> list2 = new List<int>();
		int num = clothInstance.worldVertices.Length;
		for (int i = 0; i < num; i++)
		{
			if (!clothInstance.isInsideVertex[i] && clothInstance.deltas[i].sqrMagnitude > minDeltaSq)
			{
				list2.Add(i);
			}
		}
		if (list2.Count == 0)
		{
			return list;
		}
		list2.Sort(delegate(int a, int b)
		{
			float sqrMagnitude = clothInstance.deltas[a].sqrMagnitude;
			float num9 = clothInstance.deltas[b].sqrMagnitude - sqrMagnitude;
			if (Mathf.Abs(num9) > 1E-06f)
			{
				if (!(num9 > 0f))
				{
					return -1;
				}
				return 1;
			}
			float num10 = clothInstance.minDistance[a];
			float value3 = clothInstance.minDistance[b];
			return num10.CompareTo(value3);
		});
		float num2 = worldRadius * 2f;
		float num3 = num2 * num2;
		float cellSize = num2;
		Dictionary<Vector3Int, List<int>> dictionary = new Dictionary<Vector3Int, List<int>>();
		foreach (int item in list2)
		{
			Vector3 p = clothInstance.worldVertices[item];
			Vector3Int key = GetCellIndex(p);
			bool flag = false;
			for (int num4 = -1; num4 <= 1; num4++)
			{
				if (flag)
				{
					break;
				}
				for (int num5 = -1; num5 <= 1; num5++)
				{
					if (flag)
					{
						break;
					}
					for (int num6 = -1; num6 <= 1; num6++)
					{
						if (flag)
						{
							break;
						}
						Vector3Int key2 = new Vector3Int(key.x + num4, key.y + num5, key.z + num6);
						if (!dictionary.TryGetValue(key2, out var value))
						{
							continue;
						}
						for (int num7 = 0; num7 < value.Count; num7++)
						{
							int num8 = value[num7];
							if ((clothInstance.worldVertices[item] - clothInstance.worldVertices[num8]).sqrMagnitude < num3)
							{
								flag = true;
								break;
							}
						}
					}
				}
			}
			if (!flag)
			{
				list.Add(item);
				if (!dictionary.TryGetValue(key, out var value2))
				{
					value2 = (dictionary[key] = new List<int>());
				}
				value2.Add(item);
			}
		}
		return list;
		Vector3Int GetCellIndex(Vector3 vector)
		{
			return new Vector3Int(Mathf.FloorToInt(vector.x / cellSize), Mathf.FloorToInt(vector.y / cellSize), Mathf.FloorToInt(vector.z / cellSize));
		}
	}

	public void SmoothDeltasByDistance(Vector3[] positions, ref Vector3[] deltas, List<int>[] adjacency, float radius, int maxDepth = 3, int iterations = 1, float smoothFactor = 0.5f, float gaussianSigma = -1f)
	{
		if (positions == null || deltas == null || adjacency == null || positions.Length != deltas.Length || positions.Length != adjacency.Length)
		{
			return;
		}
		int num = positions.Length;
		if (num == 0)
		{
			return;
		}
		if (gaussianSigma <= 0f)
		{
			gaussianSigma = radius * 0.5f;
		}
		float num2 = radius * radius;
		float num3 = 2f * gaussianSigma * gaussianSigma;
		Vector3[] array = new Vector3[num];
		Queue<Node> queue = new Queue<Node>();
		List<int> list = new List<int>(32);
		int[] array2 = new int[num];
		int num4 = 1;
		for (int i = 0; i < iterations; i++)
		{
			for (int j = 0; j < num; j++)
			{
				if (deltas[j] == Vector3.zero)
				{
					array[j] = Vector3.zero;
					continue;
				}
				list.Clear();
				queue.Clear();
				num4 = (array2[j] = num4 + 1);
				queue.Enqueue(new Node
				{
					index = j,
					depth = 0
				});
				Vector3 vector = positions[j];
				while (queue.Count > 0)
				{
					Node node = queue.Dequeue();
					int index = node.index;
					int depth = node.depth;
					Vector3 vector2 = positions[index];
					float sqrMagnitude = (vector2 - vector).sqrMagnitude;
					if (index != j && sqrMagnitude <= num2)
					{
						list.Add(index);
					}
					if (depth >= maxDepth)
					{
						continue;
					}
					List<int> list2 = adjacency[index];
					if (list2 == null)
					{
						continue;
					}
					for (int k = 0; k < list2.Count; k++)
					{
						int num5 = list2[k];
						if (array2[num5] != num4 && !((positions[num5] - vector2).sqrMagnitude > num2))
						{
							array2[num5] = num4;
							queue.Enqueue(new Node
							{
								index = num5,
								depth = depth + 1
							});
						}
					}
				}
				if (list.Count == 0)
				{
					array[j] = deltas[j];
					continue;
				}
				Vector3 zero = Vector3.zero;
				float num6 = 0f;
				for (int l = 0; l < list.Count; l++)
				{
					int num7 = list[l];
					float sqrMagnitude2 = (positions[num7] - vector).sqrMagnitude;
					if (!(sqrMagnitude2 > num2))
					{
						float num8 = Mathf.Exp((0f - sqrMagnitude2) / num3);
						zero += deltas[num7] * num8;
						num6 += num8;
					}
				}
				if (num6 > 1E-08f)
				{
					Vector3 b = zero / num6;
					array[j] = Vector3.Lerp(deltas[j], b, smoothFactor);
				}
				else
				{
					array[j] = deltas[j];
				}
			}
			for (int m = 0; m < num; m++)
			{
				deltas[m] = array[m];
			}
		}
	}

	public void SmoothAllClothesDeltasByDistance(List<ClothInstance> clothesInstances, float radius, int iterations = 1, float gaussianSigma = -1f, int maxDepth = 3, float smoothFactor = 0.5f)
	{
		if (clothesInstances == null || clothesInstances.Count == 0)
		{
			return;
		}
		int num = 0;
		for (int i = 0; i < clothesInstances.Count; i++)
		{
			ClothInstance clothInstance = clothesInstances[i];
			if (clothInstance != null && clothInstance.worldVertices != null)
			{
				num += clothInstance.worldVertices.Length;
			}
		}
		if (num == 0)
		{
			return;
		}
		Vector3[] array = new Vector3[num];
		Vector3[] deltas = new Vector3[num];
		List<int>[] array2 = new List<int>[num];
		int[] array3 = new int[clothesInstances.Count];
		int num2 = 0;
		for (int j = 0; j < clothesInstances.Count; j++)
		{
			ClothInstance clothInstance2 = clothesInstances[j];
			if (clothInstance2 == null)
			{
				continue;
			}
			array3[j] = num2;
			Vector3[] worldVertices = clothInstance2.worldVertices;
			Vector3[] deltasLocal = clothInstance2.deltasLocal;
			List<int>[] vertexAdjacency = clothInstance2.vertexAdjacency;
			int num3 = worldVertices.Length;
			for (int k = 0; k < num3; k++)
			{
				array[num2 + k] = worldVertices[k];
				deltas[num2 + k] = deltasLocal[k];
				array2[num2 + k] = new List<int>();
			}
			for (int l = 0; l < num3; l++)
			{
				List<int> list = vertexAdjacency[l];
				if (list != null)
				{
					int num4 = num2 + l;
					List<int> list2 = array2[num4];
					for (int m = 0; m < list.Count; m++)
					{
						int num5 = list[m];
						int item = num2 + num5;
						list2.Add(item);
					}
				}
			}
			num2 += num3;
		}
		SmoothDeltasByDistance(array, ref deltas, array2, radius, maxDepth, iterations, smoothFactor, gaussianSigma);
		for (int n = 0; n < clothesInstances.Count; n++)
		{
			ClothInstance clothInstance3 = clothesInstances[n];
			if (clothInstance3 != null)
			{
				int num6 = array3[n];
				int num7 = clothInstance3.deltasLocal.Length;
				for (int num8 = 0; num8 < num7; num8++)
				{
					clothInstance3.deltasLocal[num8] = deltas[num6 + num8];
				}
			}
		}
	}
}
