using Godot; namespace EvilEngine.Shared.World; public sealed partial class WorldFrames : Node { private int[]? _shown; private double _time; public IReadOnlyList Frames { get; init; } = []; public IReadOnlyList Scrolls { get; init; } = []; public override void _Process(double delta) { _time += delta; if (_shown is null) { _shown = new int[Frames.Count]; Array.Fill(_shown, -1); } for (var i = 0; i < Frames.Count; i++) { var frame = Frames[i]; var index = frame.Frames <= 1 ? 0 : (int)(Math.Floor(_time * frame.Rate) % frame.Frames); if (_shown[i] == index) continue; _shown[i] = index; frame.Material.SetShaderParameter(frame.Parameter, index); } foreach (var scroll in Scrolls) { var radians = scroll.Angle * Math.PI / 180; var u = (float)(Math.Cos(radians) * scroll.Rate * _time % 1.0); var v = (float)(Math.Sin(radians) * scroll.Rate * _time % 1.0); var scale = (float)scroll.Scale; scroll.Material.SetShaderParameter(scroll.Parameter, new Projection(new Vector4(scale, 0, 0, 0), new Vector4(0, scale, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(u, v, 0, 1))); } } }