using System; using System.IO; using System.Linq; using System.Collections.Generic; using GameCult.Eve.PluginFields; using GameCult.Eve.UnityScene.Fields; using NUnit.Framework; using UnityEngine; namespace GameCult.Eve.UnityScene.Tests { public sealed class EveFieldsUnitySceneProjectionTests { [Test] public void RasterizerConsumesPluginOwnedDocumentContract() { var render = typeof(EveFieldsSplatRasterizer).GetMethod( "Render", new[] { typeof(IEveFieldsSplatsDocument), typeof(int), typeof(int) }); Assert.That(render, Is.Not.Null); Assert.That(typeof(EveFieldsSplatRasterizer).Assembly.GetReferencedAssemblies().Any(assembly => assembly.Name?.Contains("Aetheria", StringComparison.OrdinalIgnoreCase) == true), Is.False); } [Test] public void PackageContainsGenericFieldsShader() { Assert.That(Shader.Find("Eve/Fields/Splats"), Is.Not.Null); Assert.That(File.Exists("Packages/org.gamecult.eve.unity-scene/Runtime/Fields/EveFieldsSplatsCore.hlsl"), Is.True); } [Test] public void LayerRendererConsumesPluginContractsWithoutProviderBindings() { var render = typeof(EveFieldsSplatLayerRenderer).GetMethod("Render"); Assert.That(render, Is.Not.Null); Assert.That(render.GetParameters()[0].ParameterType, Is.EqualTo(typeof(IEveFieldsSplatsDocument))); Assert.That(typeof(EveFieldsSplatLayerRenderer).GetField("GlobalTextureName"), Is.Null); } [Test] public void RasterizerProducesProviderIndependentFieldsCapture() { var host = new GameObject("eve-fields-capture"); var rasterizer = host.AddComponent(); var output = rasterizer.Render(new CaptureDocument(), 64, 64); Assert.That(output, Is.Not.Null); var previous = RenderTexture.active; RenderTexture.active = output; var readback = new Texture2D(64, 64, TextureFormat.RGBAFloat, false, true); readback.ReadPixels(new Rect(0, 0, 64, 64), 0, 0); readback.Apply(); RenderTexture.active = previous; Assert.That(readback.GetPixels().Any(pixel => pixel.r > 0.01f), Is.True); var outputPath = Path.GetFullPath(Path.Combine(Application.dataPath, "../../artifacts/fields-surface/latest/unity-fields.png")); Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); File.WriteAllBytes(outputPath, readback.EncodeToPNG()); UnityEngine.Object.DestroyImmediate(readback); UnityEngine.Object.DestroyImmediate(host); } private sealed class CaptureDocument : IEveFieldsSplatsDocument { public string Schema => EveFieldsSchemas.Splats; public long FrameId => 1; public double SimulationTimeSeconds => 0; public IEveFieldsViewport Viewport { get; } = new CaptureViewport(); public IReadOnlyList Layers { get; } = Array.Empty(); public IEveFieldsSplatSoa Splats { get; } = new CaptureSplats(); } private sealed class CaptureViewport : IEveFieldsViewport { public double MinX => -1; public double MinY => -1; public double MaxX => 1; public double MaxY => 1; } private sealed class CaptureSplats : IEveFieldsSplatSoa { private static readonly double[] One = { 1d }; private static readonly double[] Zero = { 0d }; private static readonly int[] ZeroInt = { 0 }; public int Count => 1; public IReadOnlyList CenterX => Zero; public IReadOnlyList CenterY => Zero; public IReadOnlyList HalfExtentX => One; public IReadOnlyList HalfExtentY => One; public IReadOnlyList RotationCos => One; public IReadOnlyList RotationSin => Zero; public IReadOnlyList Channel => ZeroInt; public IReadOnlyList Falloff => ZeroInt; public IReadOnlyList ValueR => One; public IReadOnlyList ValueG => Zero; public IReadOnlyList ValueB => Zero; public IReadOnlyList ValueA => One; public IReadOnlyList SourceKey { get; } = new[] { "capture" }; public IReadOnlyList LayerIndex => ZeroInt; public IReadOnlyList SourceKind => ZeroInt; public IReadOnlyList FrequencyX => One; public IReadOnlyList FrequencyY => One; public IReadOnlyList PhaseX => Zero; public IReadOnlyList PhaseY => Zero; public IReadOnlyList AnimationSpeed => Zero; public IReadOnlyList SourceFlags => Zero; } } }