// 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.BvhTriangleMesh using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using Eden.AutoMorpher; using UnityEngine; public class BvhTriangleMesh { public struct ClosestHit { public int triangleIndex; public Vector3 closestPoint; public Vector3 normal; public float sqrDistance; public HumanBodyBones mainHumanBone; } private TriangleUtil triangleUtil; private HumanBodyBones[] humanBones; public BvhTriangle[] triangles; public BvhNode[] nodes; public int[] triIndices; private const int LeafMaxTriangles = 4; public BvhTriangleMesh() { HumanBodyBones[] array = new HumanBodyBones[34]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); humanBones = (HumanBodyBones[])(object)array; base._002Ector(); triangleUtil = new TriangleUtil(); } private HumanBodyBones[] BuildVertexMainHumanBone(SkinnedMeshRenderer smr, Animator animator, HumanBodyBones[] bodyBones) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) Mesh sharedMesh = smr.sharedMesh; BoneWeight[] boneWeights = sharedMesh.boneWeights; int[] boneToBodyIndex = BuildBoneToBodyIndexMap(smr, animator, bodyBones); HumanBodyBones[] array = (HumanBodyBones[])(object)new HumanBodyBones[sharedMesh.vertexCount]; for (int i = 0; i < sharedMesh.vertexCount; i++) { BoneWeight val = boneWeights[i]; int bestBodyIdx = -1; float bestWeight = 0f; Try(((BoneWeight)(ref val)).boneIndex0, ((BoneWeight)(ref val)).weight0); Try(((BoneWeight)(ref val)).boneIndex1, ((BoneWeight)(ref val)).weight1); Try(((BoneWeight)(ref val)).boneIndex2, ((BoneWeight)(ref val)).weight2); Try(((BoneWeight)(ref val)).boneIndex3, ((BoneWeight)(ref val)).weight3); array[i] = (HumanBodyBones)((bestBodyIdx >= 0) ? ((int)bodyBones[bestBodyIdx]) : 55); void Try(int boneIdx, float w) { if (!(w <= 0f) && boneIdx >= 0 && boneIdx < boneToBodyIndex.Length) { int num = boneToBodyIndex[boneIdx]; if (num >= 0 && w > bestWeight) { bestWeight = w; bestBodyIdx = num; } } } } return array; } public BvhTriangleMesh BuildFromSkinnedMeshes(IReadOnlyList renderers, Animator animator) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown //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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: 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_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //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_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: 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_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: 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_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: 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_0203: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) if (renderers == null || renderers.Count == 0) { return null; } BvhTriangleMesh bvhTriangleMesh = new BvhTriangleMesh(); int num = 0; foreach (SkinnedMeshRenderer renderer in renderers) { if (!((Object)(object)renderer == (Object)null) && !((Object)(object)renderer.sharedMesh == (Object)null)) { num += renderer.sharedMesh.triangles.Length / 3; } } if (num == 0) { return null; } bvhTriangleMesh.triangles = new BvhTriangle[num]; int num2 = 0; Mesh val = new Mesh(); Vector3 val2 = default(Vector3); foreach (SkinnedMeshRenderer renderer2 in renderers) { if (!((Object)(object)renderer2 == (Object)null) && !((Object)(object)renderer2.sharedMesh == (Object)null)) { val.Clear(); renderer2.BakeMesh(val); Vector3[] vertices = val.vertices; int[] array = renderer2.sharedMesh.triangles; BoneWeight[] boneWeights = renderer2.sharedMesh.boneWeights; int[] boneToBodyIndex = BuildBoneToBodyIndexMap(renderer2, animator, humanBones); int num3 = array.Length / 3; Transform transform = ((Component)renderer2).transform; Vector3 lossyScale = transform.lossyScale; ((Vector3)(ref val2))._002Ector(1f / Mathf.Max(lossyScale.x, 1E-08f), 1f / Mathf.Max(lossyScale.y, 1E-08f), 1f / Mathf.Max(lossyScale.z, 1E-08f)); Matrix4x4 val3 = transform.localToWorldMatrix * Matrix4x4.Scale(val2); for (int i = 0; i < num3; i++) { int num4 = array[i * 3]; int num5 = array[i * 3 + 1]; int num6 = array[i * 3 + 2]; Vector3 val4 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(vertices[num4]); Vector3 val5 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(vertices[num5]); Vector3 val6 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(vertices[num6]); Vector3 val7 = Vector3.Cross(val5 - val4, val6 - val4); float magnitude = ((Vector3)(ref val7)).magnitude; val7 = ((!(magnitude > 1E-08f)) ? Vector3.up : (val7 / magnitude)); int num7 = ComputeTriangleMainHumanBoneIndex(num4, num5, num6, boneWeights, boneToBodyIndex, humanBones.Length); HumanBodyBones mainHumanBone = (HumanBodyBones)((num7 >= 0) ? ((int)humanBones[num7]) : 55); bvhTriangleMesh.triangles[num2++] = new BvhTriangle { a = val4, b = val5, c = val6, normal = val7, mainHumanBone = mainHumanBone }; val.Clear(); } } } int num8 = num; int[] array2 = new int[num8]; for (int j = 0; j < num8; j++) { array2[j] = j; } bvhTriangleMesh.triIndices = array2; List list = new List(); BuildRecursive(bvhTriangleMesh.triangles, array2, 0, num8, list); bvhTriangleMesh.nodes = list.ToArray(); return bvhTriangleMesh; } private int[] BuildBoneToBodyIndexMap(SkinnedMeshRenderer smr, Animator animator, HumanBodyBones[] bodyBones) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) Transform[] bones = smr.bones; int[] array = new int[bones.Length]; for (int i = 0; i < array.Length; i++) { array[i] = -1; } if ((Object)(object)animator == (Object)null || bodyBones == null || bones == null) { return array; } Dictionary dictionary = new Dictionary(); for (int j = 0; j < bones.Length; j++) { if (!((Object)(object)bones[j] == (Object)null) && !dictionary.ContainsKey(bones[j])) { dictionary.Add(bones[j], j); } } Dictionary> dictionary2 = new MeshClassifier().MeshHumanoidBoneMatcher(animator, (IReadOnlyList)(object)new SkinnedMeshRenderer[1] { smr }); for (int k = 0; k < bodyBones.Length; k++) { HumanBodyBones key = bodyBones[k]; if (!dictionary2.TryGetValue(key, out var value) || value == null) { continue; } foreach (Transform item in value) { if (!((Object)(object)item == (Object)null) && dictionary.TryGetValue(item, out var value2)) { array[value2] = k; } } } for (int l = 0; l < bones.Length; l++) { if (array[l] != -1) { continue; } Transform val = bones[l]; if ((Object)(object)val == (Object)null) { continue; } Transform parent = val.parent; if (!((Object)(object)parent == (Object)null) && dictionary.TryGetValue(parent, out var value3)) { int num = array[value3]; if (num != -1) { array[l] = num; } } } return array; } private int ComputeTriangleMainHumanBoneIndex(int vi0, int vi1, int vi2, BoneWeight[] weights, int[] boneToBodyIndex, int bodyBonesCount) { if (weights == null || weights.Length == 0 || boneToBodyIndex == null || boneToBodyIndex.Length == 0) { return -1; } float[] scores = new float[bodyBonesCount]; Accumulate(vi0); Accumulate(vi1); Accumulate(vi2); int result = -1; float num = 0f; for (int i = 0; i < scores.Length; i++) { if (scores[i] > num) { num = scores[i]; result = i; } } return result; void Accumulate(int v) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if (v >= 0 && v < weights.Length) { BoneWeight val = weights[v]; Add(((BoneWeight)(ref val)).boneIndex0, ((BoneWeight)(ref val)).weight0); Add(((BoneWeight)(ref val)).boneIndex1, ((BoneWeight)(ref val)).weight1); Add(((BoneWeight)(ref val)).boneIndex2, ((BoneWeight)(ref val)).weight2); Add(((BoneWeight)(ref val)).boneIndex3, ((BoneWeight)(ref val)).weight3); } } void Add(int boneIdx, float w) { if (!(w <= 0f) && boneIdx >= 0 && boneIdx < boneToBodyIndex.Length) { int num2 = boneToBodyIndex[boneIdx]; if (num2 >= 0) { scores[num2] += w; } } } } public BvhTriangleMesh BuildFromSkinnedMeshes(IList renderers) { //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_013d: 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_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0148: 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_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0168: 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_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0191: 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_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) if (renderers == null || renderers.Count == 0) { return null; } BvhTriangleMesh bvhTriangleMesh = new BvhTriangleMesh(); int num = 0; foreach (SkinnedMeshRenderer renderer in renderers) { if (!((Object)(object)renderer == (Object)null) && !((Object)(object)renderer.sharedMesh == (Object)null)) { num += renderer.sharedMesh.triangles.Length / 3; } } if (num == 0) { return null; } bvhTriangleMesh.triangles = new BvhTriangle[num]; int num2 = 0; foreach (SkinnedMeshRenderer renderer2 in renderers) { if (!((Object)(object)renderer2 == (Object)null) && !((Object)(object)renderer2.sharedMesh == (Object)null)) { Mesh sharedMesh = renderer2.sharedMesh; Vector3[] vertices = sharedMesh.vertices; int[] array = sharedMesh.triangles; int num3 = array.Length / 3; for (int i = 0; i < num3; i++) { int num4 = array[i * 3]; int num5 = array[i * 3 + 1]; int num6 = array[i * 3 + 2]; Vector3 val = ((Component)renderer2).transform.TransformPoint(vertices[num4]); Vector3 val2 = ((Component)renderer2).transform.TransformPoint(vertices[num5]); Vector3 val3 = ((Component)renderer2).transform.TransformPoint(vertices[num6]); Vector3 val4 = Vector3.Cross(val2 - val, val3 - val); float magnitude = ((Vector3)(ref val4)).magnitude; val4 = ((!(magnitude > 1E-08f)) ? Vector3.up : (val4 / magnitude)); bvhTriangleMesh.triangles[num2++] = new BvhTriangle { a = val, b = val2, c = val3, normal = val4 }; } } } int num7 = num; int[] array2 = new int[num7]; for (int j = 0; j < num7; j++) { array2[j] = j; } bvhTriangleMesh.triIndices = array2; List list = new List(); BuildRecursive(bvhTriangleMesh.triangles, array2, 0, num7, list); bvhTriangleMesh.nodes = list.ToArray(); return bvhTriangleMesh; } public BvhTriangleMesh BuildFromMesh(Mesh mesh, Transform transform) { //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_0058: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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_0085: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00a5: 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_00cb: 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_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) BvhTriangleMesh bvhTriangleMesh = new BvhTriangleMesh(); Vector3[] vertices = mesh.vertices; int[] array = mesh.triangles; int num = array.Length / 3; bvhTriangleMesh.triangles = new BvhTriangle[num]; for (int i = 0; i < num; i++) { int num2 = array[i * 3]; int num3 = array[i * 3 + 1]; int num4 = array[i * 3 + 2]; Vector3 val = transform.TransformPoint(vertices[num2]); Vector3 val2 = transform.TransformPoint(vertices[num3]); Vector3 val3 = transform.TransformPoint(vertices[num4]); Vector3 val4 = Vector3.Cross(val2 - val, val3 - val); float magnitude = ((Vector3)(ref val4)).magnitude; val4 = ((!(magnitude > 1E-08f)) ? Vector3.up : (val4 / magnitude)); bvhTriangleMesh.triangles[i] = new BvhTriangle { a = val, b = val2, c = val3, normal = val4 }; } int[] array2 = new int[num]; for (int j = 0; j < num; j++) { array2[j] = j; } bvhTriangleMesh.triIndices = array2; List list = new List(); BuildRecursive(bvhTriangleMesh.triangles, array2, 0, num, list); bvhTriangleMesh.nodes = list.ToArray(); return bvhTriangleMesh; } private int BuildRecursive(BvhTriangle[] tris, int[] triIndices, int start, int count, List outNodes) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: 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) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_010a: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: 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_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: 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) int count2 = outNodes.Count; BvhNode bvhNode = default(BvhNode); Bounds bounds = default(Bounds); bool flag = true; for (int i = start; i < start + count; i++) { BvhTriangle bvhTriangle = tris[triIndices[i]]; if (flag) { ((Bounds)(ref bounds))._002Ector(bvhTriangle.a, Vector3.zero); ((Bounds)(ref bounds)).Encapsulate(bvhTriangle.b); ((Bounds)(ref bounds)).Encapsulate(bvhTriangle.c); flag = false; } else { ((Bounds)(ref bounds)).Encapsulate(bvhTriangle.a); ((Bounds)(ref bounds)).Encapsulate(bvhTriangle.b); ((Bounds)(ref bounds)).Encapsulate(bvhTriangle.c); } } bvhNode.bounds = bounds; if (count <= 4) { bvhNode.isLeaf = true; bvhNode.start = start; bvhNode.count = count; bvhNode.leftChild = -1; bvhNode.rightChild = -1; outNodes.Add(bvhNode); return count2; } Vector3 size = ((Bounds)(ref bounds)).size; int num = 0; if (size.y > size.x && size.y > size.z) { num = 1; } else if (size.z > size.x && size.z > size.y) { num = 2; } float num2 = 0f; for (int j = start; j < start + count; j++) { BvhTriangle bvhTriangle2 = tris[triIndices[j]]; Vector3 val = (bvhTriangle2.a + bvhTriangle2.b + bvhTriangle2.c) / 3f; num2 += ((Vector3)(ref val))[num]; } num2 /= (float)count; int num3 = Partition(tris, triIndices, start, count, num, num2); if (num3 == start || num3 == start + count) { num3 = start + count / 2; } bvhNode.isLeaf = false; bvhNode.start = -1; bvhNode.count = 0; outNodes.Add(bvhNode); int leftChild = BuildRecursive(tris, triIndices, start, num3 - start, outNodes); int rightChild = BuildRecursive(tris, triIndices, num3, start + count - num3, outNodes); bvhNode.leftChild = leftChild; bvhNode.rightChild = rightChild; outNodes[count2] = bvhNode; return count2; } private int Partition(BvhTriangle[] tris, int[] triIndices, int start, int count, int axis, float splitPos) { int num = start; int num2 = start + count - 1; while (num <= num2) { BvhTriangle bvhTriangle = tris[triIndices[num]]; BvhTriangle bvhTriangle2 = tris[triIndices[num2]]; float num3 = (((Vector3)(ref bvhTriangle.a))[axis] + ((Vector3)(ref bvhTriangle.b))[axis] + ((Vector3)(ref bvhTriangle.c))[axis]) / 3f; _ = (((Vector3)(ref bvhTriangle2.a))[axis] + ((Vector3)(ref bvhTriangle2.b))[axis] + ((Vector3)(ref bvhTriangle2.c))[axis]) / 3f; if (num3 < splitPos) { num++; continue; } int num4 = triIndices[num]; triIndices[num] = triIndices[num2]; triIndices[num2] = num4; num2--; } return num; } public ClosestHit QueryClosest(Vector3 point) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) ClosestHit best = new ClosestHit { triangleIndex = -1, sqrDistance = float.MaxValue }; if (nodes == null || nodes.Length == 0) { return best; } QueryClosestRecursive(0, point, ref best); return best; } public ClosestHit QueryClosest(Vector3 point, HashSet allowedBones) { //IL_003e: 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) ClosestHit best = new ClosestHit { triangleIndex = -1, sqrDistance = float.MaxValue }; if (nodes == null || nodes.Length == 0) { return best; } if (allowedBones == null || allowedBones.Count == 0) { QueryClosestRecursive(0, point, ref best); } else { QueryClosestRecursiveFiltered(0, point, ref best, allowedBones); } return best; } private void QueryClosestRecursiveFiltered(int nodeIndex, Vector3 p, ref ClosestHit best, HashSet allowedBones) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0124: 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_015c: 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_0143: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) BvhNode bvhNode = nodes[nodeIndex]; if (DistanceSqPointAABB(p, bvhNode.bounds) > best.sqrDistance) { return; } if (bvhNode.isLeaf) { int num = bvhNode.start + bvhNode.count; for (int i = bvhNode.start; i < num; i++) { int num2 = triIndices[i]; BvhTriangle bvhTriangle = triangles[num2]; if (allowedBones.Contains(bvhTriangle.mainHumanBone)) { Vector3 val = triangleUtil.ClosestPointOnTriangle(p, bvhTriangle.a, bvhTriangle.b, bvhTriangle.c); Vector3 val2 = p - val; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude < best.sqrDistance) { best.sqrDistance = sqrMagnitude; best.triangleIndex = num2; best.closestPoint = val; best.normal = bvhTriangle.normal; best.mainHumanBone = bvhTriangle.mainHumanBone; } } } } else { int leftChild = bvhNode.leftChild; int rightChild = bvhNode.rightChild; float num3 = DistanceSqPointAABB(p, nodes[leftChild].bounds); float num4 = DistanceSqPointAABB(p, nodes[rightChild].bounds); if (num3 < num4) { QueryClosestRecursiveFiltered(leftChild, p, ref best, allowedBones); QueryClosestRecursiveFiltered(rightChild, p, ref best, allowedBones); } else { QueryClosestRecursiveFiltered(rightChild, p, ref best, allowedBones); QueryClosestRecursiveFiltered(leftChild, p, ref best, allowedBones); } } } private void QueryClosestRecursive(int nodeIndex, Vector3 p, ref ClosestHit best) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0131: 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) //IL_0068: 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_0076: 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) //IL_0080: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_00b1: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) BvhNode bvhNode = nodes[nodeIndex]; if (DistanceSqPointAABB(p, bvhNode.bounds) > best.sqrDistance) { return; } if (bvhNode.isLeaf) { int num = bvhNode.start + bvhNode.count; for (int i = bvhNode.start; i < num; i++) { int num2 = triIndices[i]; BvhTriangle bvhTriangle = triangles[num2]; Vector3 val = triangleUtil.ClosestPointOnTriangle(p, bvhTriangle.a, bvhTriangle.b, bvhTriangle.c); Vector3 val2 = p - val; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude < best.sqrDistance) { best.sqrDistance = sqrMagnitude; best.triangleIndex = num2; best.closestPoint = val; best.normal = bvhTriangle.normal; best.mainHumanBone = bvhTriangle.mainHumanBone; } } } else { int leftChild = bvhNode.leftChild; int rightChild = bvhNode.rightChild; float num3 = DistanceSqPointAABB(p, nodes[leftChild].bounds); float num4 = DistanceSqPointAABB(p, nodes[rightChild].bounds); if (num3 < num4) { QueryClosestRecursive(leftChild, p, ref best); QueryClosestRecursive(rightChild, p, ref best); } else { QueryClosestRecursive(rightChild, p, ref best); QueryClosestRecursive(leftChild, p, ref best); } } } private float DistanceSqPointAABB(Vector3 p, Bounds b) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_0096: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Max(new float[3] { ((Bounds)(ref b)).min.x - p.x, 0f, p.x - ((Bounds)(ref b)).max.x }); float num2 = Mathf.Max(new float[3] { ((Bounds)(ref b)).min.y - p.y, 0f, p.y - ((Bounds)(ref b)).max.y }); float num3 = Mathf.Max(new float[3] { ((Bounds)(ref b)).min.z - p.z, 0f, p.z - ((Bounds)(ref b)).max.z }); return num * num + num2 * num2 + num3 * num3; } public int QueryClosestN(Vector3 point, int maxCount, float maxDistance, List results) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) results.Clear(); if (nodes == null || nodes.Length == 0 || maxCount <= 0) { return 0; } float num = maxDistance * maxDistance; float currentMaxSq = num; QueryClosestNRecursive(0, point, maxCount, num, results, ref currentMaxSq); return results.Count; } private void QueryClosestNRecursive(int nodeIndex, Vector3 p, int maxCount, float maxDistanceSq, List bestHits, ref float currentMaxSq) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_0223: 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_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_0087: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0179: 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_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) BvhNode bvhNode = nodes[nodeIndex]; if (DistanceSqPointAABB(p, bvhNode.bounds) > currentMaxSq) { return; } if (bvhNode.isLeaf) { int num = bvhNode.start + bvhNode.count; for (int i = bvhNode.start; i < num; i++) { int num2 = triIndices[i]; BvhTriangle bvhTriangle = triangles[num2]; Vector3 val = triangleUtil.ClosestPointOnTriangle(p, bvhTriangle.a, bvhTriangle.b, bvhTriangle.c); Vector3 val2 = p - val; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude > maxDistanceSq) { continue; } if (bestHits.Count < maxCount) { bestHits.Add(new ClosestHit { triangleIndex = num2, closestPoint = val, normal = bvhTriangle.normal, sqrDistance = sqrMagnitude, mainHumanBone = bvhTriangle.mainHumanBone }); if (bestHits.Count == maxCount) { currentMaxSq = GetMaxSqrDistance(bestHits, maxDistanceSq); } } else { if (sqrMagnitude >= currentMaxSq) { continue; } int index = 0; float sqrDistance = bestHits[0].sqrDistance; for (int j = 1; j < bestHits.Count; j++) { if (bestHits[j].sqrDistance > sqrDistance) { sqrDistance = bestHits[j].sqrDistance; index = j; } } bestHits[index] = new ClosestHit { triangleIndex = num2, closestPoint = val, normal = bvhTriangle.normal, sqrDistance = sqrMagnitude }; currentMaxSq = GetMaxSqrDistance(bestHits, maxDistanceSq); } } } else { int leftChild = bvhNode.leftChild; int rightChild = bvhNode.rightChild; float num3 = DistanceSqPointAABB(p, nodes[leftChild].bounds); float num4 = DistanceSqPointAABB(p, nodes[rightChild].bounds); if (num3 < num4) { QueryClosestNRecursive(leftChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq); QueryClosestNRecursive(rightChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq); } else { QueryClosestNRecursive(rightChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq); QueryClosestNRecursive(leftChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq); } } } private float GetMaxSqrDistance(List bestHits, float maxDistanceSq) { if (bestHits.Count == 0) { return maxDistanceSq; } float sqrDistance = bestHits[0].sqrDistance; for (int i = 1; i < bestHits.Count; i++) { if (bestHits[i].sqrDistance > sqrDistance) { sqrDistance = bestHits[i].sqrDistance; } } return Mathf.Min(sqrDistance, maxDistanceSq); } public Vector3 ComputeMoveVectorToSurface(Vector3 p, float targetGap = 0f) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) ClosestHit closestHit = QueryClosest(p); if (closestHit.triangleIndex < 0) { return Vector3.zero; } Vector3 val = closestHit.closestPoint - p; if (targetGap > 0f) { val += ((Vector3)(ref closestHit.normal)).normalized * targetGap; } return val; } }