This commit is contained in:
CortexCore
2025-03-04 16:34:27 +08:00
parent c29bf0d12f
commit 42eb7b00d9
16 changed files with 64 additions and 245 deletions

View File

@@ -27,22 +27,31 @@ namespace BITKit.Physics
var vertices = _mesh.vertices;
if (vertices.Length > 256) return false;
if (vertices.Length > 2048) 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;