1014 lines
49 KiB
C#
1014 lines
49 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.BvhTriangleMesh
|
|
using System.Collections.Generic;
|
|
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()
|
|
{
|
|
this.humanBones = new HumanBodyBones[34]
|
|
{
|
|
HumanBodyBones.Hips,
|
|
HumanBodyBones.LeftUpperLeg,
|
|
HumanBodyBones.RightUpperLeg,
|
|
HumanBodyBones.LeftLowerLeg,
|
|
HumanBodyBones.RightLowerLeg,
|
|
HumanBodyBones.LeftFoot,
|
|
HumanBodyBones.RightFoot,
|
|
HumanBodyBones.Spine,
|
|
HumanBodyBones.Chest,
|
|
HumanBodyBones.Neck,
|
|
HumanBodyBones.Head,
|
|
HumanBodyBones.LeftShoulder,
|
|
HumanBodyBones.RightShoulder,
|
|
HumanBodyBones.LeftUpperArm,
|
|
HumanBodyBones.RightUpperArm,
|
|
HumanBodyBones.LeftLowerArm,
|
|
HumanBodyBones.RightLowerArm,
|
|
HumanBodyBones.LeftHand,
|
|
HumanBodyBones.RightHand,
|
|
HumanBodyBones.LeftToes,
|
|
HumanBodyBones.RightToes,
|
|
HumanBodyBones.LeftEye,
|
|
HumanBodyBones.RightEye,
|
|
HumanBodyBones.Jaw,
|
|
HumanBodyBones.LeftThumbProximal,
|
|
HumanBodyBones.LeftIndexProximal,
|
|
HumanBodyBones.LeftMiddleProximal,
|
|
HumanBodyBones.LeftRingProximal,
|
|
HumanBodyBones.RightThumbProximal,
|
|
HumanBodyBones.RightIndexProximal,
|
|
HumanBodyBones.RightMiddleProximal,
|
|
HumanBodyBones.RightRingProximal,
|
|
HumanBodyBones.LeftLittleProximal,
|
|
HumanBodyBones.RightLittleProximal
|
|
};
|
|
this.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 = this.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(val.boneIndex0, val.weight0);
|
|
Try(val.boneIndex1, val.weight1);
|
|
Try(val.boneIndex2, val.weight2);
|
|
Try(val.boneIndex3, 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<SkinnedMeshRenderer> 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 (!(renderer == null) && !(renderer.sharedMesh == 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 (!(renderer2 == null) && !(renderer2.sharedMesh == null))
|
|
{
|
|
val.Clear();
|
|
renderer2.BakeMesh(val);
|
|
Vector3[] vertices = val.vertices;
|
|
int[] array = renderer2.sharedMesh.triangles;
|
|
BoneWeight[] boneWeights = renderer2.sharedMesh.boneWeights;
|
|
int[] boneToBodyIndex = this.BuildBoneToBodyIndexMap(renderer2, animator, this.humanBones);
|
|
int num3 = array.Length / 3;
|
|
Transform transform = ((Component)renderer2).transform;
|
|
Vector3 lossyScale = transform.lossyScale;
|
|
val2 = new Vector3(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 = val3.MultiplyPoint3x4(vertices[num4]);
|
|
Vector3 val5 = val3.MultiplyPoint3x4(vertices[num5]);
|
|
Vector3 val6 = val3.MultiplyPoint3x4(vertices[num6]);
|
|
Vector3 val7 = Vector3.Cross(val5 - val4, val6 - val4);
|
|
float magnitude = val7.magnitude;
|
|
val7 = ((!(magnitude > 1E-08f)) ? Vector3.up : (val7 / magnitude));
|
|
int num7 = this.ComputeTriangleMainHumanBoneIndex(num4, num5, num6, boneWeights, boneToBodyIndex, this.humanBones.Length);
|
|
HumanBodyBones mainHumanBone = (HumanBodyBones)((num7 >= 0) ? ((int)this.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<BvhNode> list = new List<BvhNode>();
|
|
this.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 (animator == null || bodyBones == null || bones == null)
|
|
{
|
|
return array;
|
|
}
|
|
Dictionary<Transform, int> dictionary = new Dictionary<Transform, int>();
|
|
for (int j = 0; j < bones.Length; j++)
|
|
{
|
|
if (!(bones[j] == null) && !dictionary.ContainsKey(bones[j]))
|
|
{
|
|
dictionary.Add(bones[j], j);
|
|
}
|
|
}
|
|
Dictionary<HumanBodyBones, HashSet<Transform>> dictionary2 = new MeshClassifier().MeshHumanoidBoneMatcher(animator, (IReadOnlyList<SkinnedMeshRenderer>)(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 (!(item == 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 (val == null)
|
|
{
|
|
continue;
|
|
}
|
|
Transform parent = val.parent;
|
|
if (!(parent == 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(val.boneIndex0, val.weight0);
|
|
Add(val.boneIndex1, val.weight1);
|
|
Add(val.boneIndex2, val.weight2);
|
|
Add(val.boneIndex3, 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<SkinnedMeshRenderer> 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 (!(renderer == null) && !(renderer.sharedMesh == 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 (!(renderer2 == null) && !(renderer2.sharedMesh == 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 = 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<BvhNode> list = new List<BvhNode>();
|
|
this.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 = 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<BvhNode> list = new List<BvhNode>();
|
|
this.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<BvhNode> 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 = new Bounds(bvhTriangle.a, Vector3.zero);
|
|
bounds.Encapsulate(bvhTriangle.b);
|
|
bounds.Encapsulate(bvhTriangle.c);
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
bounds.Encapsulate(bvhTriangle.a);
|
|
bounds.Encapsulate(bvhTriangle.b);
|
|
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.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 += val[num];
|
|
}
|
|
num2 /= (float)count;
|
|
int num3 = this.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 = this.BuildRecursive(tris, triIndices, start, num3 - start, outNodes);
|
|
int rightChild = this.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 = (bvhTriangle.a[axis] + bvhTriangle.b[axis] + bvhTriangle.c[axis]) / 3f;
|
|
_ = (bvhTriangle2.a[axis] + bvhTriangle2.b[axis] + 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 (this.nodes == null || this.nodes.Length == 0)
|
|
{
|
|
return best;
|
|
}
|
|
this.QueryClosestRecursive(0, point, ref best);
|
|
return best;
|
|
}
|
|
|
|
public ClosestHit QueryClosest(Vector3 point, HashSet<HumanBodyBones> 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 (this.nodes == null || this.nodes.Length == 0)
|
|
{
|
|
return best;
|
|
}
|
|
if (allowedBones == null || allowedBones.Count == 0)
|
|
{
|
|
this.QueryClosestRecursive(0, point, ref best);
|
|
}
|
|
else
|
|
{
|
|
this.QueryClosestRecursiveFiltered(0, point, ref best, allowedBones);
|
|
}
|
|
return best;
|
|
}
|
|
|
|
private void QueryClosestRecursiveFiltered(int nodeIndex, Vector3 p, ref ClosestHit best, HashSet<HumanBodyBones> 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 = this.nodes[nodeIndex];
|
|
if (this.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 = this.triIndices[i];
|
|
BvhTriangle bvhTriangle = this.triangles[num2];
|
|
if (allowedBones.Contains(bvhTriangle.mainHumanBone))
|
|
{
|
|
Vector3 val = this.triangleUtil.ClosestPointOnTriangle(p, bvhTriangle.a, bvhTriangle.b, bvhTriangle.c);
|
|
Vector3 val2 = p - val;
|
|
float sqrMagnitude = 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 = this.DistanceSqPointAABB(p, this.nodes[leftChild].bounds);
|
|
float num4 = this.DistanceSqPointAABB(p, this.nodes[rightChild].bounds);
|
|
if (num3 < num4)
|
|
{
|
|
this.QueryClosestRecursiveFiltered(leftChild, p, ref best, allowedBones);
|
|
this.QueryClosestRecursiveFiltered(rightChild, p, ref best, allowedBones);
|
|
}
|
|
else
|
|
{
|
|
this.QueryClosestRecursiveFiltered(rightChild, p, ref best, allowedBones);
|
|
this.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 = this.nodes[nodeIndex];
|
|
if (this.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 = this.triIndices[i];
|
|
BvhTriangle bvhTriangle = this.triangles[num2];
|
|
Vector3 val = this.triangleUtil.ClosestPointOnTriangle(p, bvhTriangle.a, bvhTriangle.b, bvhTriangle.c);
|
|
Vector3 val2 = p - val;
|
|
float sqrMagnitude = 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 = this.DistanceSqPointAABB(p, this.nodes[leftChild].bounds);
|
|
float num4 = this.DistanceSqPointAABB(p, this.nodes[rightChild].bounds);
|
|
if (num3 < num4)
|
|
{
|
|
this.QueryClosestRecursive(leftChild, p, ref best);
|
|
this.QueryClosestRecursive(rightChild, p, ref best);
|
|
}
|
|
else
|
|
{
|
|
this.QueryClosestRecursive(rightChild, p, ref best);
|
|
this.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]
|
|
{
|
|
b.min.x - p.x,
|
|
0f,
|
|
p.x - b.max.x
|
|
});
|
|
float num2 = Mathf.Max(new float[3]
|
|
{
|
|
b.min.y - p.y,
|
|
0f,
|
|
p.y - b.max.y
|
|
});
|
|
float num3 = Mathf.Max(new float[3]
|
|
{
|
|
b.min.z - p.z,
|
|
0f,
|
|
p.z - b.max.z
|
|
});
|
|
return num * num + num2 * num2 + num3 * num3;
|
|
}
|
|
|
|
public int QueryClosestN(Vector3 point, int maxCount, float maxDistance, List<ClosestHit> results)
|
|
{
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
|
results.Clear();
|
|
if (this.nodes == null || this.nodes.Length == 0 || maxCount <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
float num = maxDistance * maxDistance;
|
|
float currentMaxSq = num;
|
|
this.QueryClosestNRecursive(0, point, maxCount, num, results, ref currentMaxSq);
|
|
return results.Count;
|
|
}
|
|
|
|
private void QueryClosestNRecursive(int nodeIndex, Vector3 p, int maxCount, float maxDistanceSq, List<ClosestHit> 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 = this.nodes[nodeIndex];
|
|
if (this.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 = this.triIndices[i];
|
|
BvhTriangle bvhTriangle = this.triangles[num2];
|
|
Vector3 val = this.triangleUtil.ClosestPointOnTriangle(p, bvhTriangle.a, bvhTriangle.b, bvhTriangle.c);
|
|
Vector3 val2 = p - val;
|
|
float sqrMagnitude = 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 = this.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 = this.GetMaxSqrDistance(bestHits, maxDistanceSq);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int leftChild = bvhNode.leftChild;
|
|
int rightChild = bvhNode.rightChild;
|
|
float num3 = this.DistanceSqPointAABB(p, this.nodes[leftChild].bounds);
|
|
float num4 = this.DistanceSqPointAABB(p, this.nodes[rightChild].bounds);
|
|
if (num3 < num4)
|
|
{
|
|
this.QueryClosestNRecursive(leftChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq);
|
|
this.QueryClosestNRecursive(rightChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq);
|
|
}
|
|
else
|
|
{
|
|
this.QueryClosestNRecursive(rightChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq);
|
|
this.QueryClosestNRecursive(leftChild, p, maxCount, maxDistanceSq, bestHits, ref currentMaxSq);
|
|
}
|
|
}
|
|
}
|
|
|
|
private float GetMaxSqrDistance(List<ClosestHit> 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 = this.QueryClosest(p);
|
|
if (closestHit.triangleIndex < 0)
|
|
{
|
|
return Vector3.zero;
|
|
}
|
|
Vector3 val = closestHit.closestPoint - p;
|
|
if (targetGap > 0f)
|
|
{
|
|
val += closestHit.normal.normalized * targetGap;
|
|
}
|
|
return val;
|
|
}
|
|
}
|