From 84c8feaf9038197f9db37fad7b0e2ff4d6e18d6b Mon Sep 17 00:00:00 2001 From: SDraw Date: Sun, 4 Jun 2023 23:01:37 +0300 Subject: [PATCH] RenderSettings and Color defs --- CVRLua/CVRLua.csproj | 3 + CVRLua/Lua/LuaArgReader.cs | 9 + CVRLua/Lua/LuaDefs/ColorDefs.cs | 480 +++++++++++++++++++++++ CVRLua/Lua/LuaDefs/MathfDefs.cs | 16 +- CVRLua/Lua/LuaDefs/RandomDefs.cs | 30 +- CVRLua/Lua/LuaDefs/RenderSettingsDefs.cs | 411 +++++++++++++++++++ CVRLua/LuaHandler.cs | 4 + CVRLua/Main.cs | 2 + CVRLua/Wrappers/Color.cs | 18 + 9 files changed, 967 insertions(+), 6 deletions(-) create mode 100644 CVRLua/Lua/LuaDefs/ColorDefs.cs create mode 100644 CVRLua/Lua/LuaDefs/RenderSettingsDefs.cs create mode 100644 CVRLua/Wrappers/Color.cs diff --git a/CVRLua/CVRLua.csproj b/CVRLua/CVRLua.csproj index e016187..1278ef5 100644 --- a/CVRLua/CVRLua.csproj +++ b/CVRLua/CVRLua.csproj @@ -101,6 +101,7 @@ + @@ -113,6 +114,7 @@ + @@ -150,6 +152,7 @@ + diff --git a/CVRLua/Lua/LuaArgReader.cs b/CVRLua/Lua/LuaArgReader.cs index a020f33..08beff7 100644 --- a/CVRLua/Lua/LuaArgReader.cs +++ b/CVRLua/Lua/LuaArgReader.cs @@ -269,6 +269,15 @@ public void ReadNextEnum(ref T p_enum) where T : struct } } + public void ReadValue(ref object p_obj) + { + if((m_vm != null) && !m_hasErrors && (m_currentArgument <= m_argumentsCount)) + { + p_obj = m_vm.ReadValue(m_currentArgument); + m_currentArgument++; + } + } + public void ReadArguments(List p_args) { if((m_vm != null) && !m_hasErrors) diff --git a/CVRLua/Lua/LuaDefs/ColorDefs.cs b/CVRLua/Lua/LuaDefs/ColorDefs.cs new file mode 100644 index 0000000..221dfde --- /dev/null +++ b/CVRLua/Lua/LuaDefs/ColorDefs.cs @@ -0,0 +1,480 @@ +using System; +using System.Collections.Generic; + +namespace CVRLua.Lua.LuaDefs +{ + static class ColorDefs + { + static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>(); + static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>(); + static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>(); + static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>(); + internal static void Init() + { + ms_staticProperties.Add(("black", (GetBlack, null))); + ms_staticProperties.Add(("blue", (GetBlue, null))); + ms_staticProperties.Add(("clear", (GetClear, null))); + ms_staticProperties.Add(("gray", (GetGray, null))); + ms_staticProperties.Add(("green", (GetGreen, null))); + ms_staticProperties.Add(("grey", (GetGray, null))); + ms_staticProperties.Add(("magenta", (GetMagenta, null))); + ms_staticProperties.Add(("red", (GetRed, null))); + ms_staticProperties.Add(("white", (GetWhite, null))); + ms_staticProperties.Add(("yellow", (GetYellow, null))); + + ms_staticMethods.Add((nameof(IsColor), IsColor)); + ms_staticMethods.Add((nameof(HSVToRGB), HSVToRGB)); + ms_staticMethods.Add((nameof(Lerp), Lerp)); + ms_staticMethods.Add((nameof(LerpUnclamped), LerpUnclamped)); + ms_staticMethods.Add((nameof(RGBToHSV), RGBToHSV)); + + ms_metaMethods.Add(("__eq", Equal)); + ms_metaMethods.Add(("__tostring", ToString)); + ms_metaMethods.Add(("__add", Add)); + ms_metaMethods.Add(("__sub", Subtract)); + ms_metaMethods.Add(("__mul", Multiply)); + ms_metaMethods.Add(("__div", Divide)); + ms_metaMethods.Add(("__tostring", ToString)); + + ms_instanceProperties.Add(("r", (GetR, SetR))); + ms_instanceProperties.Add(("g", (GetG, SetG))); + ms_instanceProperties.Add(("b", (GetB, SetB))); + ms_instanceProperties.Add(("a", (GetA, SetA))); + ms_instanceProperties.Add(("gamma", (GetGamma, null))); + ms_instanceProperties.Add(("grayscale", (GetGrayscale, null))); + ms_instanceProperties.Add(("linear", (GetLinear, null))); + ms_instanceProperties.Add(("maxColorComponent", (GetMaxColorComponent, null))); + } + + internal static void RegisterInVM(LuaVM p_vm) + { + p_vm.RegisterClass(typeof(Wrappers.Color), Create, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, null); + } + + // Constructor + static int Create(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_colorR = 0f; + float l_colorG = 0f; + float l_colorB = 0f; + float l_colorA = 1f; + l_argReader.Skip(); // Metatable first + l_argReader.ReadNextNumber(ref l_colorR); + l_argReader.ReadNextNumber(ref l_colorG); + l_argReader.ReadNextNumber(ref l_colorB); + l_argReader.ReadNextNumber(ref l_colorA); + l_argReader.PushObject(new Wrappers.Color(new UnityEngine.Color(l_colorR, l_colorG, l_colorB, l_colorA))); + return l_argReader.GetReturnValue(); + } + + // Static properties + static int GetBlack(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.black)); + return 1; + } + + static int GetBlue(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.blue)); + return 1; + } + + static int GetClear(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.clear)); + return 1; + } + + static int GetGray(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.gray)); + return 1; + } + + static int GetGreen(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.green)); + return 1; + } + + static int GetMagenta(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.magenta)); + return 1; + } + + static int GetRed(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.red)); + return 1; + } + + static int GetWhite(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.white)); + return 1; + } + + static int GetYellow(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.yellow)); + return 1; + } + + // Static methods + static int IsColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_obj = null; + l_argReader.ReadNextObject(ref l_obj); + l_argReader.PushBoolean(l_obj != null); + return l_argReader.GetReturnValue(); + } + + static int HSVToRGB(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_valueH = 0f; + float l_valueS = 0f; + float l_valueV = 0f; + bool l_hdr = true; + l_argReader.ReadNumber(ref l_valueH); + l_argReader.ReadNumber(ref l_valueS); + l_argReader.ReadNumber(ref l_valueV); + l_argReader.ReadNextBoolean(ref l_hdr); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.HSVToRGB(l_valueH, l_valueS, l_valueV, l_hdr))); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return l_argReader.GetReturnValue(); + } + + static int Lerp(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_colorA = null; + Wrappers.Color l_colorB = null; + float l_alpha = 0f; + l_argReader.ReadObject(ref l_colorA); + l_argReader.ReadObject(ref l_colorB); + l_argReader.ReadNumber(ref l_alpha); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.Lerp(l_colorA.m_color, l_colorB.m_color, l_alpha))); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return l_argReader.GetReturnValue(); + } + + static int LerpUnclamped(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_colorA = null; + Wrappers.Color l_colorB = null; + float l_alpha = 0f; + l_argReader.ReadObject(ref l_colorA); + l_argReader.ReadObject(ref l_colorB); + l_argReader.ReadNumber(ref l_alpha); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Color.LerpUnclamped(l_colorA.m_color, l_colorB.m_color, l_alpha))); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return l_argReader.GetReturnValue(); + } + + static int RGBToHSV(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + { + UnityEngine.Color.RGBToHSV(l_color.m_color, out float l_valueH, out float l_valueS, out float l_valueV); + l_argReader.PushNumber(l_valueH); + l_argReader.PushNumber(l_valueS); + l_argReader.PushNumber(l_valueV); + } + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return l_argReader.GetReturnValue(); + } + + // Metamethods + static int Equal(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_colorA = null; + Wrappers.Color l_colorB = null; + l_argReader.ReadObject(ref l_colorA); + l_argReader.ReadObject(ref l_colorB); + if(!l_argReader.HasErrors()) + l_argReader.PushBoolean(l_colorA.m_color == l_colorB.m_color); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int ToString(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushString(l_color.m_color.ToString()); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int Add(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_colorA = null; + Wrappers.Color l_colorB = null; + l_argReader.ReadObject(ref l_colorA); + l_argReader.ReadObject(ref l_colorB); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(l_colorA.m_color + l_colorB.m_color)); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int Subtract(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_colorA = null; + Wrappers.Color l_colorB = null; + l_argReader.ReadObject(ref l_colorA); + l_argReader.ReadObject(ref l_colorB); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(l_colorA.m_color - l_colorB.m_color)); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int Multiply(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_colorA = null; + Wrappers.Color l_colorB = null; + l_argReader.ReadObject(ref l_colorA); + l_argReader.ReadObject(ref l_colorB); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(l_colorA.m_color * l_colorB.m_color)); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int Divide(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + float l_value = 0f; + l_argReader.ReadObject(ref l_color); + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(l_color.m_color / l_value)); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + // Instance properties + static int GetR(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_color.m_color.r); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + static int SetR(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + float l_value = 0f; + l_argReader.ReadObject(ref l_color); + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + l_color.m_color.r = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetG(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_color.m_color.g); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + static int SetG(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + float l_value = 0f; + l_argReader.ReadObject(ref l_color); + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + l_color.m_color.g = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetB(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_color.m_color.b); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + static int SetB(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + float l_value = 0f; + l_argReader.ReadObject(ref l_color); + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + l_color.m_color.b = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetA(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_color.m_color.a); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + static int SetA(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + float l_value = 0f; + l_argReader.ReadObject(ref l_color); + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + l_color.m_color.a = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetGamma(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(l_color.m_color.gamma)); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int GetGrayscale(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_color.m_color.grayscale); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int GetLinear(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(l_color.m_color.linear)); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + + static int GetMaxColorComponent(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + l_argReader.PushNumber(l_color.m_color.maxColorComponent); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return 1; + } + } +} diff --git a/CVRLua/Lua/LuaDefs/MathfDefs.cs b/CVRLua/Lua/LuaDefs/MathfDefs.cs index a3ed860..c66624f 100644 --- a/CVRLua/Lua/LuaDefs/MathfDefs.cs +++ b/CVRLua/Lua/LuaDefs/MathfDefs.cs @@ -20,7 +20,7 @@ internal static void Init() ms_staticMethods.Add((nameof(Clamp), Clamp)); ms_staticMethods.Add((nameof(Clamp01), Clamp01)); ms_staticMethods.Add((nameof(ClosestPowerOfTwo), ClosestPowerOfTwo)); - //ms_staticMethods.Add((nameof(CorrelatedColorTemperatureToRGB), CorrelatedColorTemperatureToRGB)); // Needs Color defs + ms_staticMethods.Add((nameof(CorrelatedColorTemperatureToRGB), CorrelatedColorTemperatureToRGB)); ms_staticMethods.Add((nameof(DeltaAngle), DeltaAngle)); ms_staticMethods.Add((nameof(FloorToInt), FloorToInt)); ms_staticMethods.Add((nameof(GammaToLinearSpace), GammaToLinearSpace)); @@ -147,6 +147,20 @@ static int ClosestPowerOfTwo(IntPtr p_state) return l_argReader.GetReturnValue(); } + static int CorrelatedColorTemperatureToRGB(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + l_argReader.PushObject(new Wrappers.Color(Mathf.CorrelatedColorTemperatureToRGB(l_value))); + else + l_argReader.PushBoolean(false); + + l_argReader.LogError(); + return l_argReader.GetReturnValue(); + } + static int DeltaAngle(IntPtr p_state) { var l_argReader = new LuaArgReader(p_state); diff --git a/CVRLua/Lua/LuaDefs/RandomDefs.cs b/CVRLua/Lua/LuaDefs/RandomDefs.cs index dab16df..c444ac8 100644 --- a/CVRLua/Lua/LuaDefs/RandomDefs.cs +++ b/CVRLua/Lua/LuaDefs/RandomDefs.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CVRLua.Lua.LuaDefs { @@ -21,7 +18,7 @@ internal static void Init() //ms_staticProperties.Add(("state", (?, ?))); ms_staticProperties.Add(("value", (GetValue, null))); - //ms_staticMethods.Add((nameof(ColorHSV), ColorHSV)); + ms_staticMethods.Add((nameof(ColorHSV), ColorHSV)); ms_staticMethods.Add((nameof(InitState), InitState)); ms_staticMethods.Add((nameof(Range), Range)); } @@ -75,6 +72,29 @@ static int GetValue(IntPtr p_state) } // Static methods + static int ColorHSV(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_hMin = 0f; + float l_hMax = 1f; + float l_sMin = 0f; + float l_sMax = 1f; + float l_vMin = 0f; + float l_vMax = 1f; + float l_aMin = 1f; + float l_aMax = 1f; + l_argReader.ReadNextNumber(ref l_hMin); + l_argReader.ReadNextNumber(ref l_hMax); + l_argReader.ReadNextNumber(ref l_sMin); + l_argReader.ReadNextNumber(ref l_sMax); + l_argReader.ReadNextNumber(ref l_vMin); + l_argReader.ReadNextNumber(ref l_vMax); + l_argReader.ReadNextNumber(ref l_aMin); + l_argReader.ReadNextNumber(ref l_aMax); + l_argReader.PushObject(new Wrappers.Color(UnityEngine.Random.ColorHSV(l_hMin, l_hMax, l_sMin, l_sMax, l_vMin, l_vMax, l_aMin, l_aMax))); + return l_argReader.GetReturnValue(); + } + static int InitState(IntPtr p_state) { var l_argReader = new LuaArgReader(p_state); @@ -100,7 +120,7 @@ static int Range(IntPtr p_state) l_argReader.ReadNumber(ref l_min); l_argReader.ReadNumber(ref l_max); if(!l_argReader.HasErrors()) - l_argReader.PushNumber(UnityEngine.Random.Range(l_min,l_max)); + l_argReader.PushNumber(UnityEngine.Random.Range(l_min, l_max)); else l_argReader.PushBoolean(false); diff --git a/CVRLua/Lua/LuaDefs/RenderSettingsDefs.cs b/CVRLua/Lua/LuaDefs/RenderSettingsDefs.cs new file mode 100644 index 0000000..cd9ee90 --- /dev/null +++ b/CVRLua/Lua/LuaDefs/RenderSettingsDefs.cs @@ -0,0 +1,411 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace CVRLua.Lua.LuaDefs +{ + static class RenderSettingsDefs + { + static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>(); + static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>(); + static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>(); + static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>(); + static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>(); + + internal static void Init() + { + ms_staticProperties.Add(("ambientEquatorColor", (GetAmbientEquatorColor, SetAmbientEquatorColor))); + ms_staticProperties.Add(("ambientGroundColor", (GetAmbientGroundColor, SetAmbientGroundColor))); + ms_staticProperties.Add(("ambientIntensity", (GetAmbientIntensity, SetAmbientIntensity))); + ms_staticProperties.Add(("ambientLight", (GetAmbientLight, SetAmbientLight))); + ms_staticProperties.Add(("ambientMode", (GetAmbientMode, SetAmbientMode))); + //ms_staticProperties.Add(("ambientProbe", (GetAmbientProbe, SetAmbientProbe))); + ms_staticProperties.Add(("ambientSkyColor", (GetAmbientSkyColor, SetAmbientSkyColor))); + //ms_staticProperties.Add(("customReflection", (?, ?))); + ms_staticProperties.Add(("defaultReflectionMode", (GetDefaultReflectionMode, SetDefaultReflectionMode))); + ms_staticProperties.Add(("defaultReflectionResolution", (GetDefaultReflectionResolution, SetDefaultReflectionResolution))); + ms_staticProperties.Add(("flareFadeSpeed", (GetFlareFadeSpeed, SetFlareFadeSpeed))); + ms_staticProperties.Add(("flareStrength", (GetFlareStrength, SetFlareStrength))); + ms_staticProperties.Add(("fog", (GetFog, SetFog))); + ms_staticProperties.Add(("fogColor", (GetFogColor, SetFogColor))); + ms_staticProperties.Add(("fogDensity", (GetFogDensity, SetFogDensity))); + ms_staticProperties.Add(("fogEndDistance", (GetFogEndDistance, SetFogEndDistance))); + ms_staticProperties.Add(("fogMode", (GetFogMode, SetFogMode))); + ms_staticProperties.Add(("fogStartDistance", (GetFogStartDistance, SetFogStartDistance))); + ms_staticProperties.Add(("haloStrength", (GetHaloStrength, SetHaloStrength))); + ms_staticProperties.Add(("reflectionBounces", (GetReflectionBounces, SetReflectionBounces))); + ms_staticProperties.Add(("reflectionIntensity", (GetReflectionIntensity, SetReflectionIntensity))); + //ms_staticProperties.Add(("skybox", (GetSkybox, SetSkybox))); // Require Material defs + ms_staticProperties.Add(("subtractiveShadowColor", (GetSubtractiveShadowColor, SetSubtractiveShadowColor))); + //ms_staticProperties.Add(("sun", (?, ?))); // Require Light defs + + ObjectDefs.InheritTo(ms_metaMethods, ms_staticProperties, ms_staticMethods, ms_instanceProperties, ms_instanceMethods); + } + + internal static void RegisterInVM(LuaVM p_vm) + { + p_vm.RegisterClass(typeof(RenderSettings), null, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods); + } + + // Static properties + static int GetAmbientEquatorColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(RenderSettings.ambientEquatorColor)); + return 1; + } + static int SetAmbientEquatorColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + RenderSettings.ambientEquatorColor = l_color.m_color; + + l_argReader.LogError(); + return 0; + } + + static int GetAmbientGroundColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(RenderSettings.ambientGroundColor)); + return 1; + } + static int SetAmbientGroundColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + RenderSettings.ambientGroundColor = l_color.m_color; + + l_argReader.LogError(); + return 0; + } + + static int GetAmbientIntensity(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.ambientIntensity); + return 1; + } + static int SetAmbientIntensity(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0f; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.ambientIntensity = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetAmbientLight(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(RenderSettings.ambientLight)); + return 1; + } + static int SetAmbientLight(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + RenderSettings.ambientLight = l_color.m_color; + + l_argReader.LogError(); + return 0; + } + + static int GetAmbientMode(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushString(RenderSettings.ambientMode.ToString()); + return 1; + } + static int SetAmbientMode(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + UnityEngine.Rendering.AmbientMode l_value = UnityEngine.Rendering.AmbientMode.Skybox; + l_argReader.ReadEnum(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.ambientMode = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetAmbientSkyColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(RenderSettings.ambientSkyColor)); + return 1; + } + static int SetAmbientSkyColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + RenderSettings.ambientSkyColor = l_color.m_color; + + l_argReader.LogError(); + return 0; + } + + static int GetDefaultReflectionMode(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushString(RenderSettings.defaultReflectionMode.ToString()); + return 1; + } + static int SetDefaultReflectionMode(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + UnityEngine.Rendering.DefaultReflectionMode l_value = UnityEngine.Rendering.DefaultReflectionMode.Skybox; + l_argReader.ReadEnum(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.defaultReflectionMode = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetDefaultReflectionResolution(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushInteger(RenderSettings.defaultReflectionResolution); + return 1; + } + static int SetDefaultReflectionResolution(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + int l_value = 0; + l_argReader.ReadInteger(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.defaultReflectionResolution = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetFlareFadeSpeed(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.flareFadeSpeed); + return 1; + } + static int SetFlareFadeSpeed(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.flareFadeSpeed = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetFlareStrength(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.flareStrength); + return 1; + } + static int SetFlareStrength(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.flareStrength = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetFog(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushBoolean(RenderSettings.fog); + return 1; + } + static int SetFog(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + bool l_value = false; + l_argReader.ReadBoolean(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.fog = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetFogColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(RenderSettings.fogColor)); + return 1; + } + static int SetFogColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + RenderSettings.fogColor = l_color.m_color; + + l_argReader.LogError(); + return 0; + } + + static int GetFogDensity(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.fogDensity); + return 1; + } + static int SetFogDensity(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.fogDensity = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetFogEndDistance(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.fogEndDistance); + return 1; + } + static int SetFogEndDistance(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.fogEndDistance = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetFogMode(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushString(RenderSettings.fogMode.ToString()); + return 1; + } + static int SetFogMode(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + FogMode l_value = FogMode.Linear; + l_argReader.ReadEnum(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.fogMode = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetFogStartDistance(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.fogStartDistance); + return 1; + } + static int SetFogStartDistance(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.fogStartDistance = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetHaloStrength(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.haloStrength); + return 1; + } + static int SetHaloStrength(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.haloStrength = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetReflectionBounces(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushInteger(RenderSettings.reflectionBounces); + return 1; + } + static int SetReflectionBounces(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + int l_value = 0; + l_argReader.ReadInteger(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.reflectionBounces = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetReflectionIntensity(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushNumber(RenderSettings.reflectionIntensity); + return 1; + } + static int SetReflectionIntensity(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + float l_value = 0; + l_argReader.ReadNumber(ref l_value); + if(!l_argReader.HasErrors()) + RenderSettings.reflectionIntensity = l_value; + + l_argReader.LogError(); + return 0; + } + + static int GetSubtractiveShadowColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + l_argReader.PushObject(new Wrappers.Color(RenderSettings.subtractiveShadowColor)); + return 1; + } + static int SetSubtractiveShadowColor(IntPtr p_state) + { + var l_argReader = new LuaArgReader(p_state); + Wrappers.Color l_color = null; + l_argReader.ReadObject(ref l_color); + if(!l_argReader.HasErrors()) + RenderSettings.subtractiveShadowColor = l_color.m_color; + + l_argReader.LogError(); + return 0; + } + } +} diff --git a/CVRLua/LuaHandler.cs b/CVRLua/LuaHandler.cs index a64c477..5a061dd 100644 --- a/CVRLua/LuaHandler.cs +++ b/CVRLua/LuaHandler.cs @@ -49,6 +49,7 @@ internal static void Init() Lua.LuaDefs.AudioSourceDefs.Init(); Lua.LuaDefs.BoundsDefs.Init(); Lua.LuaDefs.CollisionDefs.Init(); + Lua.LuaDefs.ColorDefs.Init(); Lua.LuaDefs.ContactPointDefs.Init(); Lua.LuaDefs.GameObjectDefs.Init(); Lua.LuaDefs.MathfDefs.Init(); @@ -62,6 +63,7 @@ internal static void Init() Lua.LuaDefs.RandomDefs.Init(); Lua.LuaDefs.RayDefs.Init(); Lua.LuaDefs.RaycastHitDefs.Init(); + Lua.LuaDefs.RenderSettingsDefs.Init(); Lua.LuaDefs.RigidbodyDefs.Init(); Lua.LuaDefs.TimeDefs.Init(); Lua.LuaDefs.TransformDefs.Init(); @@ -107,6 +109,7 @@ internal LuaHandler(string p_name = "") Lua.LuaDefs.AudioSourceDefs.RegisterInVM(m_vm); Lua.LuaDefs.BoundsDefs.RegisterInVM(m_vm); Lua.LuaDefs.CollisionDefs.RegisterInVM(m_vm); + Lua.LuaDefs.ColorDefs.RegisterInVM(m_vm); Lua.LuaDefs.ContactPointDefs.RegisterInVM(m_vm); Lua.LuaDefs.GameObjectDefs.RegisterInVM(m_vm); Lua.LuaDefs.MathfDefs.RegisterInVM(m_vm); @@ -120,6 +123,7 @@ internal LuaHandler(string p_name = "") Lua.LuaDefs.RandomDefs.RegisterInVM(m_vm); Lua.LuaDefs.RayDefs.RegisterInVM(m_vm); Lua.LuaDefs.RaycastHitDefs.RegisterInVM(m_vm); + Lua.LuaDefs.RenderSettingsDefs.RegisterInVM(m_vm); Lua.LuaDefs.RigidbodyDefs.RegisterInVM(m_vm); Lua.LuaDefs.TimeDefs.RegisterInVM(m_vm); Lua.LuaDefs.TransformDefs.RegisterInVM(m_vm); diff --git a/CVRLua/Main.cs b/CVRLua/Main.cs index 6e76037..aad4aad 100644 --- a/CVRLua/Main.cs +++ b/CVRLua/Main.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using UnityEngine; +using ABI_RC.Core.Savior; namespace CVRLua { @@ -176,6 +177,7 @@ void OnInteractableGazeExit(CVRInteractable p_interact) } } + // Playeres managment static void OnPuppetMasterStart_Postfix(ref PuppetMaster __instance) => Instance?.OnPuppetMasterStart(__instance.gameObject); void OnPuppetMasterStart(GameObject p_obj) { diff --git a/CVRLua/Wrappers/Color.cs b/CVRLua/Wrappers/Color.cs new file mode 100644 index 0000000..218893c --- /dev/null +++ b/CVRLua/Wrappers/Color.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CVRLua.Wrappers +{ + class Color + { + public UnityEngine.Color m_color; + + public Color(UnityEngine.Color p_color) + { + m_color = p_color; + } + } +}