0.2.0-dev Download ZIP
56 lines ·2.2 KB Raw
| 1 | using System.Reflection; |
| 2 | using EvilEngine.Conversion; |
| 3 | using EvilEngine.Formats; |
| 4 | using EvilEngine.Formats.Textures; |
| 5 | |
| 6 | namespace EvilEngine.Host.Tests; |
| 7 | |
| 8 | public sealed class SourceTextureTests |
| 9 | { |
| 10 | private static readonly string Installed = typeof(SourceTextureTests).Assembly |
| 11 | .GetCustomAttributes<AssemblyMetadataAttribute>() |
| 12 | .Single(attribute => attribute.Key == "AdapterOutputRoot").Value!; |
| 13 | |
| 14 | private static (Texture Texture, byte[] Bytes) Convert(string id) |
| 15 | { |
| 16 | var path = Environment.GetEnvironmentVariable("EVIL_GMOD"); |
| 17 | Assert.SkipWhen(path is null, "Set EVIL_GMOD to a Garry's Mod install to convert its textures."); |
| 18 | var host = new EngineHost(); |
| 19 | host.Adapters.LoadAll([Installed]); |
| 20 | var mount = host.Mounts.Open(Assert.Single(host.Mounts.Probe(path!))); |
| 21 | host.Conversion.AddNamespace(ContentNamespace.For(mount)); |
| 22 | var result = host.Conversion.Get(ContentKind.Texture, ContentId.Parse(id)); |
| 23 | Assert.True(result.Succeeded, string.Join('\n', result.Diagnostics)); |
| 24 | Assert.Equal("source.vtf", result.Content!.Converter); |
| 25 | return (TextureFile.Read(result.Content.Data, id), result.Content.Data.ToArray()); |
| 26 | } |
| 27 | |
| 28 | [Fact] |
| 29 | public void ConvertsTheOilDrumTheSameEachTime() |
| 30 | { |
| 31 | var (texture, bytes) = Convert("gmod:materials/models/props_c17/oil_drum001h"); |
| 32 | |
| 33 | Assert.Equal(bytes, Convert("gmod:materials/models/props_c17/oil_drum001h").Bytes); |
| 34 | Assert.Equal((TextureFormat.Bc1RgbaUnorm, 512, 512, 1, 10), |
| 35 | (texture.Format, texture.Width, texture.Height, texture.Layers, texture.Levels.Count)); |
| 36 | } |
| 37 | |
| 38 | [Fact] |
| 39 | public void ConvertsGarrysModsDefaultCubeMapWithoutItsSphereMap() |
| 40 | { |
| 41 | var (texture, _) = Convert("gmod:materials/engine/defaultcubemap"); |
| 42 | |
| 43 | Assert.True(texture.Cube); |
| 44 | Assert.Equal(TextureMipFilter.None, texture.Sampling.Mips); |
| 45 | Assert.Equal((TextureWrap.Clamp, TextureWrap.Clamp), (texture.Sampling.WrapU, texture.Sampling.WrapV)); |
| 46 | } |
| 47 | |
| 48 | [Fact] |
| 49 | public void ConvertsAParticleSheetWithItsSequences() |
| 50 | { |
| 51 | var (texture, _) = Convert("gmod:materials/particle/smoke1/smoke1"); |
| 52 | |
| 53 | Assert.NotNull(texture.Sheet); |
| 54 | Assert.All(texture.Sheet, sequence => Assert.True(sequence.Clamp)); |
| 55 | } |
| 56 | } |