namespace Yw.WpfUI.Hydro
{
///
/// 抽象水流动画辅助类
///
internal class LogicalFlowEffectHelper
{
///
///
///
public LogicalFlowEffectHelper(HelixViewport3D viewport, LogicalMaterialHelper materialHelper)
{
_viewport = viewport;
_materialHelper = materialHelper;
}
private readonly HelixViewport3D _viewport;//三维组件
private readonly LogicalMaterialHelper _materialHelper;//材质辅助类
private readonly Dictionary _cache = new();//缓存
public void Load()
{
}
public void Unload()
{
}
public void Update()
{
}
public void Clear()
{
}
///
/// 设置流速
///
public void SetFlowRate(LogicalLink3D link, double flowRate)
{
if (link.Vmo.Id == "918437")
{
if (_cache.TryGetValue(link, out var flowEffect))
{
flowEffect.FlowRate = Math.Clamp(flowRate, 0, 2);
flowEffect.Turbulence = 0.2 + flowRate * 0.15;
}
else
{
flowEffect = new LogicalFlowEffect3D(link, _materialHelper);
flowEffect.FlowRate = Math.Clamp(flowRate, 0, 2);
flowEffect.Turbulence = 0.2 + flowRate * 0.15;
_viewport.Children.Add(flowEffect);
flowEffect.Play();
}
}
}
public void StartAllAnimations()
{
foreach (var system in _cache.Values)
{
system.Play();
}
}
}
}