// 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.ClothInstanceTotal using System.Collections.Generic; using UnityEngine; public class ClothInstanceTotal { private readonly List clothInstances; public int TotalVertexCount { get; private set; } public Vector3[] GlobalPositions { get; private set; } public Vector3[] GlobalDeltas { get; private set; } public List[] GlobalAdjacencyTopology { get; private set; } public List[] GlobalAdjacencyDistance { get; private set; } public List[] GlobalAdjacencyMerged { get; private set; } public int[] VertexOffsets { get; private set; } public ClothInstanceTotal(List clothInstances, float distanceBuildRadius, int maxNeighborsPerVertex = 0) { if (clothInstances == null || clothInstances.Count == 0) { throw new AutoMorpherException("Cloth Instances are Missing", "[ClothInstanceTotal] ClothInstanceTotal\n - clothInstances is null or empty"); } if (distanceBuildRadius <= 0f) { throw new AutoMorpherException("Distance Build Radius is Invalid", "[ClothInstanceTotal] ClothInstanceTotal\n - distanceBuildRadius must be > 0"); } this.clothInstances = clothInstances; this.BuildTopologyCache(); this.BuildDistanceAdjacencyCandidates(distanceBuildRadius, maxNeighborsPerVertex); this.BuildMergedAdjacency(); } public void SetGlobalDeltas(Vector3[] globalDeltas) { if (globalDeltas == null || globalDeltas.Length != this.TotalVertexCount) { throw new AutoMorpherException("Global Deltas are Invalid", "[ClothInstanceTotal] SetGlobalDeltas\n - globalDeltas is null or length mismatch"); } this.GlobalDeltas = globalDeltas; } public void UpdateGlobalBuffersFromClothInstances() { //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) this.ValidateGlobalBufferReady("[ClothInstanceTotal] UpdateGlobalBuffersFromClothInstances"); for (int i = 0; i < this.clothInstances.Count; i++) { ClothInstance clothInstance = this.clothInstances[i]; if (clothInstance != null) { if (clothInstance.worldVertices == null || clothInstance.deltasLocal == null) { throw new AutoMorpherException("Cloth Instance Data is Missing", "[ClothInstanceTotal] UpdateGlobalBuffersFromClothInstances\n - worldVertices or deltasLocal is null"); } int num = this.VertexOffsets[i]; int num2 = clothInstance.worldVertices.Length; if (num2 != clothInstance.deltasLocal.Length) { throw new AutoMorpherException("Cloth Instance Array Length Mismatch", "[ClothInstanceTotal] UpdateGlobalBuffersFromClothInstances\n - worldVertices.Length != deltasLocal.Length"); } for (int j = 0; j < num2; j++) { this.GlobalPositions[num + j] = clothInstance.worldVertices[j]; this.GlobalDeltas[num + j] = clothInstance.deltasLocal[j]; } } } } public void ApplyGlobalDeltasToClothInstances() { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) this.ValidateGlobalBufferReady("[ClothInstanceTotal] ApplyGlobalDeltasToClothInstances"); for (int i = 0; i < this.clothInstances.Count; i++) { ClothInstance clothInstance = this.clothInstances[i]; if (clothInstance != null) { if (clothInstance.deltasLocal == null) { throw new AutoMorpherException("Cloth Deltas are Missing", "[ClothInstanceTotal] ApplyGlobalDeltasToClothInstances\n - deltasLocal is null"); } int num = this.VertexOffsets[i]; int num2 = clothInstance.deltasLocal.Length; for (int j = 0; j < num2; j++) { clothInstance.deltasLocal[j] = this.GlobalDeltas[num + j]; } } } } private void ValidateGlobalBufferReady(string functionContext) { if (this.clothInstances == null || this.clothInstances.Count == 0) { throw new AutoMorpherException("Cloth Instances are Missing", functionContext + "\n - clothInstances is null or empty"); } if (this.TotalVertexCount <= 0 || this.GlobalPositions == null || this.GlobalDeltas == null || this.VertexOffsets == null || this.GlobalAdjacencyMerged == null) { throw new AutoMorpherException("Cloth Instance Total Cache is Not Ready", functionContext + "\n - total/global buffers/merged adjacency are not initialized"); } } private void BuildTopologyCache() { //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_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) this.TotalVertexCount = this.CalculateTotalVertexCount(this.clothInstances); if (this.TotalVertexCount <= 0) { throw new AutoMorpherException("Total Vertex Count is Zero", "[ClothInstanceTotal] BuildTopologyCache\n - TotalVertexCount <= 0"); } this.GlobalPositions = (Vector3[])(object)new Vector3[this.TotalVertexCount]; this.GlobalDeltas = (Vector3[])(object)new Vector3[this.TotalVertexCount]; this.GlobalAdjacencyTopology = new List[this.TotalVertexCount]; this.VertexOffsets = new int[this.clothInstances.Count]; int num = 0; for (int i = 0; i < this.clothInstances.Count; i++) { ClothInstance clothInstance = this.clothInstances[i]; this.VertexOffsets[i] = num; if (clothInstance == null) { continue; } if (clothInstance.worldVertices == null || clothInstance.deltasLocal == null || clothInstance.vertexAdjacency == null) { throw new AutoMorpherException("Cloth Instance Data is Missing", "[ClothInstanceTotal] BuildTopologyCache\n - worldVertices/deltasLocal/vertexAdjacency is null"); } int num2 = clothInstance.worldVertices.Length; if (num2 != clothInstance.deltasLocal.Length || num2 != clothInstance.vertexAdjacency.Length) { throw new AutoMorpherException("Cloth Instance Array Length Mismatch", "[ClothInstanceTotal] BuildTopologyCache\n - worldVertices/deltasLocal/vertexAdjacency lengths differ"); } for (int j = 0; j < num2; j++) { this.GlobalPositions[num + j] = clothInstance.worldVertices[j]; this.GlobalDeltas[num + j] = clothInstance.deltasLocal[j]; int capacity = clothInstance.vertexAdjacency[j]?.Count ?? 0; this.GlobalAdjacencyTopology[num + j] = new List(capacity); } for (int k = 0; k < num2; k++) { List list = clothInstance.vertexAdjacency[k]; if (list == null) { continue; } int num3 = num + k; List list2 = this.GlobalAdjacencyTopology[num3]; for (int l = 0; l < list.Count; l++) { int num4 = list[l]; if ((uint)num4 >= (uint)num2) { throw new AutoMorpherException("Vertex Adjacency Index is Out of Range", "[ClothInstanceTotal] BuildTopologyCache\n - vertexAdjacency contains invalid neighbor index"); } list2.Add(num + num4); } } num += num2; } } private void BuildDistanceAdjacencyCandidates(float radius, int maxNeighborsPerVertex) { if (this.GlobalPositions == null || this.GlobalPositions.Length == 0) { throw new AutoMorpherException("Reference Positions are Missing", "[ClothInstanceTotal] BuildDistanceAdjacencyCandidates\n - GlobalPositions is null or empty"); } this.GlobalAdjacencyDistance = this.BuildDistanceAdjacencyCandidatesInternal(this.GlobalPositions, radius, maxNeighborsPerVertex); } private void BuildMergedAdjacency() { if (this.GlobalAdjacencyTopology == null || this.GlobalAdjacencyDistance == null) { throw new AutoMorpherException("Adjacency Inputs are Missing", "[ClothInstanceTotal] BuildMergedAdjacency\n - GlobalAdjacencyTopology or GlobalAdjacencyDistance is null"); } if (this.GlobalAdjacencyTopology.Length != this.GlobalAdjacencyDistance.Length) { throw new AutoMorpherException("Adjacency Length Mismatch", "[ClothInstanceTotal] BuildMergedAdjacency\n - topology and distance adjacency length differ"); } int num = this.GlobalAdjacencyTopology.Length; this.GlobalAdjacencyMerged = new List[num]; for (int i = 0; i < num; i++) { List list = new List((this.GlobalAdjacencyTopology[i]?.Count ?? 0) + (this.GlobalAdjacencyDistance[i]?.Count ?? 0)); HashSet hashSet = new HashSet(); List list2 = this.GlobalAdjacencyTopology[i]; if (list2 != null) { for (int j = 0; j < list2.Count; j++) { int num2 = list2[j]; if (num2 != i && hashSet.Add(num2)) { list.Add(num2); } } } List list3 = this.GlobalAdjacencyDistance[i]; if (list3 != null) { for (int k = 0; k < list3.Count; k++) { int num3 = list3[k]; if (num3 != i && hashSet.Add(num3)) { list.Add(num3); } } } this.GlobalAdjacencyMerged[i] = list; } } private int CalculateTotalVertexCount(List clothInstances) { int num = 0; for (int i = 0; i < clothInstances.Count; i++) { ClothInstance clothInstance = clothInstances[i]; if (clothInstance != null && clothInstance.worldVertices != null) { num += clothInstance.worldVertices.Length; } } return num; } private List[] BuildDistanceAdjacencyCandidatesInternal(Vector3[] referencePositions, float radius, int maxNeighborsPerVertex) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: 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_010c: 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_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_019d: 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) if (referencePositions == null || referencePositions.Length == 0) { throw new AutoMorpherException("Reference Positions are Missing", "[ClothInstanceTotal] BuildDistanceAdjacencyCandidatesInternal\n - referencePositions is null or empty"); } if (radius <= 0f) { throw new AutoMorpherException("Radius is Invalid", "[ClothInstanceTotal] BuildDistanceAdjacencyCandidatesInternal\n - radius must be > 0"); } int num = referencePositions.Length; List[] array = new List[num]; for (int i = 0; i < num; i++) { array[i] = new List(8); } float num2 = 1f / Mathf.Max(radius, 1E-12f); float num3 = radius * radius; Dictionary> dictionary = new Dictionary>(num); Vector3Int key = default(Vector3Int); for (int j = 0; j < num; j++) { Vector3 val = referencePositions[j]; key = new Vector3Int(Mathf.FloorToInt(val.x * num2), Mathf.FloorToInt(val.y * num2), Mathf.FloorToInt(val.z * num2)); if (!dictionary.TryGetValue(key, out var value)) { value = new List(16); dictionary.Add(key, value); } value.Add(j); } Vector3Int val3 = default(Vector3Int); Vector3Int key2 = default(Vector3Int); for (int k = 0; k < num; k++) { Vector3 val2 = referencePositions[k]; val3 = new Vector3Int(Mathf.FloorToInt(val2.x * num2), Mathf.FloorToInt(val2.y * num2), Mathf.FloorToInt(val2.z * num2)); List list = array[k]; for (int l = -1; l <= 1; l++) { for (int m = -1; m <= 1; m++) { for (int n = -1; n <= 1; n++) { key2 = new Vector3Int(val3.x + l, val3.y + m, val3.z + n); if (!dictionary.TryGetValue(key2, out var value2)) { continue; } for (int num4 = 0; num4 < value2.Count; num4++) { int num5 = value2[num4]; if (num5 == k) { continue; } Vector3 val4 = referencePositions[num5] - val2; if (!(val4.sqrMagnitude > num3)) { list.Add(num5); if (maxNeighborsPerVertex > 0 && list.Count >= maxNeighborsPerVertex) { break; } } } if (maxNeighborsPerVertex > 0 && list.Count >= maxNeighborsPerVertex) { break; } } } } } return array; } }