From 50c4d06f192d75d6cc36d88832d7c5a8388d1823 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Thu, 1 Aug 2024 18:29:10 +0100 Subject: [PATCH] Use a constant inverse scale when converting to godot vec3 --- project/code/LGS/Utils.cs | 5 +++-- project/code/Mission.cs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/project/code/LGS/Utils.cs b/project/code/LGS/Utils.cs index 9268dac..9bb61b5 100644 --- a/project/code/LGS/Utils.cs +++ b/project/code/LGS/Utils.cs @@ -5,8 +5,9 @@ namespace KeepersCompound.LGS; public static class Utils { - public static Godot.Vector3 ToGodotVec3(this Vector3 vec, float inverseScale) + const float InverseScale = 4.0f; + public static Godot.Vector3 ToGodotVec3(this Vector3 vec) { - return new Godot.Vector3(vec.Y, vec.Z, vec.X) / inverseScale; + return new Godot.Vector3(vec.Y, vec.Z, vec.X) / InverseScale; } } \ No newline at end of file diff --git a/project/code/Mission.cs b/project/code/Mission.cs index 629875e..9cb9025 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -103,12 +103,12 @@ public partial class Mission : Node3D var poly = cell.Polys[i]; var meshIdxOffset = vertices.Count; - var normal = cell.Planes[poly.PlaneId].Normal.ToGodotVec3(4.0f); + var normal = cell.Planes[poly.PlaneId].Normal.ToGodotVec3(); var numPolyVertices = poly.VertexCount; for (var j = 0; j < numPolyVertices; j++) { var vertex = cell.Vertices[cell.Indices[cellIdxOffset + j]]; - vertices.Add(vertex.ToGodotVec3(4.0f)); + vertices.Add(vertex.ToGodotVec3()); normals.Add(normal); } @@ -216,7 +216,7 @@ public partial class Mission : Node3D { var light = new OmniLight3D { - Position = cell.SphereCenter.ToGodotVec3(4.0f), + Position = cell.SphereCenter.ToGodotVec3(), OmniRange = cell.SphereRadius * (r.NextSingle() + 1.0f) * 0.5f, }; // cellNode.AddChild(light); @@ -235,8 +235,8 @@ public partial class Mission : Node3D { // TODO: This is slightly hardcoded for ND. Check other stuff at some point. Should be handled in LG side imo // TODO: This is a mess lol - var texU = renderPoly.TextureVectors.Item1.ToGodotVec3(4.0f); - var texV = renderPoly.TextureVectors.Item2.ToGodotVec3(4.0f); + var texU = renderPoly.TextureVectors.Item1.ToGodotVec3(); + var texV = renderPoly.TextureVectors.Item2.ToGodotVec3(); var uu = texU.Dot(texU); var vv = texV.Dot(texV); @@ -248,7 +248,7 @@ public partial class Mission : Node3D var baseV = renderPoly.TextureBases.Item2; var lmUBase = lmUScale * (baseU + (0.5f - light.Bases.Item1) / 4.0f); var lmVBase = lmVScale * (baseV + (0.5f - light.Bases.Item2) / 4.0f); - var anchor = cell.Vertices[cell.Indices[cellIdxOffset + 0]].ToGodotVec3(4.0f); // TODO: This probably shouldn't be hardcoded idx 0 + var anchor = cell.Vertices[cell.Indices[cellIdxOffset + 0]].ToGodotVec3(); // TODO: This probably shouldn't be hardcoded idx 0 var uvIdxs = new int[poly.VertexCount]; if (uv == 0.0) @@ -259,7 +259,7 @@ public partial class Mission : Node3D { uvIdxs[i] = lightmapUvs.Count; - var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(4.0f); + var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(); var delta = new Vector3(v.X - anchor.X, v.Y - anchor.Y, v.Z - anchor.Z); var lmUV = new Vector2(delta.Dot(lmUVec) + lmUBase, delta.Dot(lmVVec) + lmVBase); lightmapUvs.Add(lmUV); @@ -276,7 +276,7 @@ public partial class Mission : Node3D { uvIdxs[i] = lightmapUvs.Count; - var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(4.0f); + var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(); var delta = new Vector3(v.X - anchor.X, v.Y - anchor.Y, v.Z - anchor.Z); var du = delta.Dot(texU); var dv = delta.Dot(texV);