Skip to content

Commit

Permalink
Fix incorrect loading of texture rotation and shift values for pre-2.…
Browse files Browse the repository at this point in the history
…2 RMF files

Fixes #39
  • Loading branch information
LogicAndTrick committed Dec 21, 2024
1 parent 0f71864 commit f4b0ef4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
36 changes: 33 additions & 3 deletions Sledge.Formats.Map.Tests/Formats/TestWorldcraftFormat.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sledge.Formats.Map.Formats;
using Sledge.Formats.Map.Objects;
using Path = System.IO.Path;

namespace Sledge.Formats.Map.Tests.Formats;

Expand Down Expand Up @@ -37,4 +34,37 @@ public void TestRmf08Visgroups()
var format = new WorldcraftRmfFormat();
var map = format.Read(file);
}

[TestMethod]
public void TestRmfQuakeToValveTextureConversion()
{
var format = new WorldcraftRmfFormat();

using var file16 = typeof(TestWorldcraftFormat).Assembly.GetManifestResourceStream($"Sledge.Formats.Map.Tests.Resources.rmf.test-cube-1.6.rmf");
using var file22 = typeof(TestWorldcraftFormat).Assembly.GetManifestResourceStream($"Sledge.Formats.Map.Tests.Resources.rmf.test-cube-2.2.rmf");

var map16 = format.Read(file16);
var map22 = format.Read(file22);

var solid16 = (Solid)map16.Worldspawn.Children[0];
var solid22 = (Solid)map22.Worldspawn.Children[0];

foreach (var face22 in solid22.Faces)
{
var face16 = solid16.Faces.Single(x => x.Plane.Equals(face22.Plane));

Assert.AreEqual(face22.UAxis, face16.UAxis);
Assert.AreEqual(face22.VAxis, face16.VAxis);
Assert.AreEqual(face22.XScale, face16.XScale);
Assert.AreEqual(face22.YScale, face16.YScale);
Assert.AreEqual(face22.XShift, face16.XShift);
Assert.AreEqual(face22.YShift, face16.YShift);
Assert.AreEqual(face22.Rotation, face16.Rotation);
Assert.AreEqual(face22.ContentFlags, face16.ContentFlags);
Assert.AreEqual(face22.SurfaceFlags, face16.SurfaceFlags);
Assert.AreEqual(face22.Value, face16.Value);
Assert.AreEqual(face22.LightmapScale, face16.LightmapScale);
Assert.AreEqual(face22.SmoothingGroups, face16.SmoothingGroups);
}
}
}
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions Sledge.Formats.Map.Tests/Sledge.Formats.Map.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<None Remove="Resources\rmf\16.rmf" />
<None Remove="Resources\rmf\18.rmf" />
<None Remove="Resources\rmf\22.rmf" />
<None Remove="Resources\rmf\test-cube-1.6.rmf" />
<None Remove="Resources\rmf\test-cube-2.2.rmf" />
</ItemGroup>

<ItemGroup>
Expand All @@ -33,6 +35,8 @@
<EmbeddedResource Include="Resources\rmf\16.rmf" />
<EmbeddedResource Include="Resources\rmf\18.rmf" />
<EmbeddedResource Include="Resources\rmf\22.rmf" />
<EmbeddedResource Include="Resources\rmf\test-cube-1.6.rmf" />
<EmbeddedResource Include="Resources\rmf\test-cube-2.2.rmf" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Sledge.Formats.Map/Formats/WorldcraftRmfFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ private static Face ReadFace(RmfVersion version, BinaryReader br)
if (version <= RmfVersion.Version18)
{
// We need to use quake editor logic to work out the texture axes, for that we need the plane data - see below
face.Rotation = br.ReadSingle();
face.XShift = br.ReadSingle();
face.YShift = br.ReadSingle();
face.Rotation = br.ReadSingle();
}
else // if (version == RmfVersion.Version22)
{
Expand Down
4 changes: 2 additions & 2 deletions Sledge.Formats.Map/Sledge.Formats.Map.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<RepositoryUrl>https://github.com/LogicAndTrick/sledge-formats</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageTags>half-life quake valve hammer worldcraft jackhammer jack rmf vmf map jmf</PackageTags>
<PackageReleaseNotes>Add some basic factory classes to create known solid types</PackageReleaseNotes>
<Version>1.2.3</Version>
<PackageReleaseNotes>Fix incorrect loading of texture rotation and shift values for pre-2.2 RMF files</PackageReleaseNotes>
<Version>1.2.4</Version>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
Expand Down

0 comments on commit f4b0ef4

Please sign in to comment.