103 lines
3.2 KiB
C#
103 lines
3.2 KiB
C#
using DotRecast.Core.Numerics;
|
||
using DotRecast.Recast;
|
||
using DotRecast.Recast.Geom;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
|
||
namespace XNet.Business
|
||
{
|
||
// 1. 定义一个简单的几何输入类,适配 DotRecast 接口
|
||
public class SimpleInputGeomProvider : IInputGeomProvider
|
||
{
|
||
private readonly float[] _vertices;
|
||
private readonly int[] _faces;
|
||
private readonly RcVec3f _bmin;
|
||
private readonly RcVec3f _bmax;
|
||
private readonly RcTriMesh _triMesh;
|
||
|
||
// [关键] 定义数据存储列表
|
||
private readonly List<RcOffMeshConnection> _offMeshConnections = new List<RcOffMeshConnection>();
|
||
private readonly List<RcConvexVolume> _convexVolumes = new List<RcConvexVolume>();
|
||
|
||
public SimpleInputGeomProvider(float[] vertices, int[] faces)
|
||
{
|
||
_vertices = vertices;
|
||
_faces = faces;
|
||
_triMesh = new RcTriMesh(_vertices, _faces);
|
||
|
||
_bmin = new RcVec3f(float.MaxValue, float.MaxValue, float.MaxValue);
|
||
_bmax = new RcVec3f(float.MinValue, float.MinValue, float.MinValue);
|
||
|
||
for (int i = 0; i < vertices.Length; i += 3)
|
||
{
|
||
float x = vertices[i];
|
||
float y = vertices[i + 1];
|
||
float z = vertices[i + 2];
|
||
|
||
_bmin.X = Math.Min(_bmin.X, x);
|
||
_bmin.Y = Math.Min(_bmin.Y, y);
|
||
_bmin.Z = Math.Min(_bmin.Z, z);
|
||
|
||
_bmax.X = Math.Max(_bmax.X, x);
|
||
_bmax.Y = Math.Max(_bmax.Y, y);
|
||
_bmax.Z = Math.Max(_bmax.Z, z);
|
||
}
|
||
}
|
||
|
||
public RcVec3f GetMeshBoundsMin() => _bmin;
|
||
public RcVec3f GetMeshBoundsMax() => _bmax;
|
||
|
||
public RcTriMesh GetMesh() => _triMesh;
|
||
|
||
public IEnumerable<RcTriMesh> Meshes()
|
||
{
|
||
yield return _triMesh;
|
||
}
|
||
|
||
// --- 接口实现:Off-Mesh Connections ---
|
||
|
||
public void AddOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags)
|
||
{
|
||
_offMeshConnections.Add(new RcOffMeshConnection(start, end, radius, bidir, area, flags));
|
||
}
|
||
|
||
public void RemoveOffMeshConnections(Predicate<RcOffMeshConnection> filter)
|
||
{
|
||
_offMeshConnections.RemoveAll(filter);
|
||
}
|
||
|
||
// [这里是你报错的地方,已修复]
|
||
// 显式接口实现,返回内部列表
|
||
List<RcOffMeshConnection> IInputGeomProvider.GetOffMeshConnections()
|
||
{
|
||
return _offMeshConnections;
|
||
}
|
||
|
||
// 如果外部也需要访问,可以保留这个公共方法
|
||
public IList<RcOffMeshConnection> GetOffMeshConnections()
|
||
{
|
||
return _offMeshConnections;
|
||
}
|
||
|
||
// --- 接口实现:Convex Volumes ---
|
||
|
||
public void AddConvexVolume(RcConvexVolume convexVolume)
|
||
{
|
||
_convexVolumes.Add(convexVolume);
|
||
}
|
||
|
||
// 显式接口实现
|
||
IList<RcConvexVolume> IInputGeomProvider.ConvexVolumes()
|
||
{
|
||
return _convexVolumes;
|
||
}
|
||
|
||
// 公共方法
|
||
public IEnumerable<RcConvexVolume> ConvexVolumes()
|
||
{
|
||
return _convexVolumes;
|
||
}
|
||
}
|
||
}
|