diff options
Diffstat (limited to 'LUT.cs')
| -rw-r--r-- | LUT.cs | 61 |
1 files changed, 21 insertions, 40 deletions
@@ -11,11 +11,13 @@ using SharpPluginLoader.Core.IO; namespace WorldTuningTool { - public class WorldLUTs + using static Plugin; + + public class LUT { private const string addPath = "nativePC/plugins/CSharp/LUT"; - public WorldLUTs() { } + public LUT() { } // https://github.com/AsteriskAmpersand/CrappyLUTStudio--CLUTS-/blob/5af10daaa5f295b106cc5db09530a6fe5a4320d4/LUT.py#L35 private byte[]? parseWorldLUT(BinaryReader reader) @@ -57,7 +59,7 @@ namespace WorldTuningTool { string? line; Vector3[]? parsed = null; - int dim = 0, idx = 0; + int dim = 0, i = 0; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("LUT_3D_SIZE")) @@ -66,18 +68,8 @@ namespace WorldTuningTool { dim = Convert.ToInt32(line.Split(' ').Last()); } - catch (FormatException) - { - return null; - } - catch (OverflowException) - { - return null; - } - if (dim != 32) - { - return null; - } + catch (Exception) { return null; } + if (dim != 32) return null; parsed = new Vector3[dim * dim * dim]; while ((line = reader.ReadLine()) != null) { @@ -87,26 +79,15 @@ namespace WorldTuningTool break; } } - if (line == null) - { - break; - } + if (line == null) break; } if (parsed != null) { try { - parsed[idx] = Plugin.StringToVector3(line, ' '); - } - catch (FormatException) - { - return null; - } - catch (OverflowException) - { - return null; + parsed[i++] = StringToVector3(line, ' '); } - idx++; + catch (Exception) { return null; } } } if (parsed == null) @@ -116,24 +97,24 @@ namespace WorldTuningTool const int lutDataSize = 32 * 32 * 32 * 8; byte[] data = new byte[lutDataSize]; float scale = MathF.Pow(2, 14) - 1; - for (idx = 0; idx < lutDataSize; idx+=8) + for (i = 0; i < lutDataSize; i += 8) { - Vector3 v = parsed[idx/8]; + Vector3 v = parsed[i / 8]; ushort normX = (ushort)Math.Round(v.X * scale); ushort normY = (ushort)Math.Round(v.Y * scale); ushort normZ = (ushort)Math.Round(v.Z * scale); byte[] bytes = BitConverter.GetBytes(normX); - data[idx] = bytes[0]; - data[idx + 1] = bytes[1]; + data[i] = bytes[0]; + data[i + 1] = bytes[1]; bytes = BitConverter.GetBytes(normY); - data[idx + 2] = bytes[0]; - data[idx + 3] = bytes[1]; + data[i + 2] = bytes[0]; + data[i + 3] = bytes[1]; bytes = BitConverter.GetBytes(normZ); - data[idx + 4] = bytes[0]; - data[idx + 5] = bytes[1]; + data[i + 4] = bytes[0]; + data[i + 5] = bytes[1]; bytes = BitConverter.GetBytes(0x2B88); // Alpha constant. - data[idx + 6] = bytes[0]; - data[idx + 7] = bytes[1]; + data[i + 6] = bytes[0]; + data[i + 7] = bytes[1]; } return data; } @@ -189,7 +170,7 @@ namespace WorldTuningTool private static bool[] selectionStarted = [ false, false ]; private static bool[] selectedInvalid = [ false, false ]; - public void DrawLUT(nint texture, nint lightingObject, int i, float width) + public void DrawUI(nint texture, nint lightingObject, int i, float width) { ImGui.PushID(i); string lutPath = Marshal.PtrToStringAnsi(texture + 0xC)!; |