using OpenTK.Mathematics;
|
|
namespace Yw.WinFrmUI.Hydro
|
{
|
/// <summary>
|
/// 三维点缓存辅助类
|
/// </summary>
|
internal class Vector3CacheHelper
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public Vector3CacheHelper(NetworkL3d nw)
|
{
|
_nw = nw;
|
Initial();
|
}
|
|
private NetworkL3d _nw = null;
|
private Dictionary<string, List<Vector3>> _dict = new();
|
|
/// <summary>
|
/// 是否初始化
|
/// </summary>
|
public bool Initialized
|
{
|
get
|
{
|
if (_nw == null)
|
{
|
return false;
|
}
|
if (_dict.Count < 1)
|
{
|
return false;
|
}
|
return true;
|
}
|
}
|
|
//初始化
|
private void Initial()
|
{
|
if (_nw == null)
|
{
|
return;
|
}
|
foreach (var visual in _nw.Visuals)
|
{
|
var pts = visual.GetPositions();
|
var vpts = pts.Select(x => new Vector3(x.X, x.Y, x.Z)).ToList();
|
_dict.Add(visual.Id, vpts);
|
}
|
}
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
/// <returns></returns>
|
public List<Vector3> GetAll()
|
{
|
if (!Initialized)
|
{
|
return default;
|
}
|
return _dict.SelectMany(x => x.Value).Distinct().ToList();
|
}
|
|
/// <summary>
|
/// 通过 Id 获取
|
/// </summary>
|
public List<Vector3> GetById(string Id)
|
{
|
if (string.IsNullOrEmpty(Id))
|
{
|
return default;
|
}
|
if (_dict.ContainsKey(Id))
|
{
|
return _dict[Id];
|
}
|
return default;
|
}
|
|
|
|
|
}
|
}
|