This commit is contained in:
CortexCore
2025-03-09 13:38:23 +08:00
parent 8261a458e2
commit 18239a5ae4
67 changed files with 8573 additions and 831 deletions

View File

@@ -27,22 +27,31 @@ namespace BITKit.Physics
var vertices = _mesh.vertices;
if (vertices.Length > 2048) return false;
if (vertices.Length > 256) return false;
var minPos = new Vector3(64, 64, 64);
var minDistance = 64f;
for (var index = 0; index < _mesh.triangles.Length; index+=3)
{
var x = vertices[_mesh.triangles[index]];
if (Vector3.Distance(x, _position) > minDistance)
{
continue;
}
var y = vertices[_mesh.triangles[index + 1]];
var z = vertices[_mesh.triangles[index + 2]];
var pos = GeometryUtils.GetPosInTriangle(x, y, z, _position);
if (Vector3.Distance(pos, _position) < Vector3.Distance(minPos, _position))
{
minPos = pos;
}
var distance = Vector3.Distance(pos, _position);
if (!(distance < minDistance)) continue;
minPos = pos;
minDistance = distance;
}
position = minPos;