From ac9f024d8e065d07e770b3ffdde1a5230341647a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Fri, 28 Jun 2019 18:05:42 +0200 Subject: [PATCH] Add LOD light support --- .../PC/Meta/Structures/MCDistantLODLight.cs | 40 ++++++--- .../PC/Meta/Structures/MCLODLight.cs | 86 +++++++++++++------ .../PC/Meta/Structures/MVECTOR3.cs | 7 +- 3 files changed, 95 insertions(+), 38 deletions(-) diff --git a/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCDistantLODLight.cs b/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCDistantLODLight.cs index 4f914449..9c3cb756 100644 --- a/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCDistantLODLight.cs +++ b/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCDistantLODLight.cs @@ -9,12 +9,14 @@ public class MCDistantLODLight : MetaStructureWrapper { public static MetaName _MetaName = MetaName.CDistantLODLight; public MetaFile Meta; - public List Position; - public Array_uint RGBI; - public ushort NumStreetLights; + public List Position { get { return this.Entries.Select(e => e.Position).ToList(); }} + public List RGBI { get { return this.Entries.Select(e => e.RGBI).ToList(); } } + public ushort NumStreetLights; public ushort Category; - public MCDistantLODLight() + public List Entries = new List(); + + public MCDistantLODLight() { this.MetaName = MetaName.CDistantLODLight; this.MetaStructure = new CDistantLODLight(); @@ -37,11 +39,23 @@ public override void Parse(MetaFile meta, CDistantLODLight CDistantLODLight) this.Meta = meta; this.MetaStructure = CDistantLODLight; - var position = MetaUtils.ConvertDataArray(meta, CDistantLODLight.position); - this.Position = position?.Select(e => { var msw = new MVECTOR3(); msw.Parse(meta, e); return msw; }).ToList(); + var _position = MetaUtils.ConvertDataArray(meta, CDistantLODLight.position); + List position = _position?.Select(e => { var msw = new MVECTOR3(); msw.Parse(meta, e); return msw; }).ToList(); + + uint[] rgbi = MetaUtils.ConvertDataArray(meta, CDistantLODLight.RGBI.Pointer, CDistantLODLight.RGBI.Count1).ToArray(); + + Entries.Clear(); - // this.RGBI = CDistantLODLight.RGBI; - this.NumStreetLights = CDistantLODLight.numStreetLights; + for (int i = 0; i < position.Count; i++) + { + Entries.Add(new DistantLODLightEntry() + { + Position = position[i], + RGBI = rgbi[i], + }); + } + + this.NumStreetLights = CDistantLODLight.numStreetLights; this.Category = CDistantLODLight.category; } @@ -51,8 +65,8 @@ public override void Build(MetaBuilder mb, bool isRoot = false) this.MetaStructure.position = mb.AddItemArrayPtr(MetaName.VECTOR3, this.Position.Select(e => { e.Build(mb); return e.MetaStructure; }).ToArray()); MVECTOR3.AddEnumAndStructureInfo(mb); - // this.MetaStructure.RGBI = this.RGBI; - this.MetaStructure.numStreetLights = this.NumStreetLights; + this.MetaStructure.RGBI = mb.AddUintArrayPtr(this.RGBI.ToArray()); + this.MetaStructure.numStreetLights = this.NumStreetLights; this.MetaStructure.category = this.Category; MCDistantLODLight.AddEnumAndStructureInfo(mb); @@ -65,4 +79,10 @@ public override void Build(MetaBuilder mb, bool isRoot = false) } } } + + public struct DistantLODLightEntry + { + public MVECTOR3 Position; + public uint RGBI; + } } diff --git a/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCLODLight.cs b/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCLODLight.cs index 47f47120..f095a4b9 100644 --- a/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCLODLight.cs +++ b/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCLODLight.cs @@ -9,14 +9,16 @@ public class MCLODLight : MetaStructureWrapper { public static MetaName _MetaName = MetaName.CLODLight; public MetaFile Meta; - public List Direction = new List(); - public Array_float Falloff; - public Array_float FalloffExponent; - public Array_uint TimeAndStateFlags; - public Array_uint Hash; - public Array_byte ConeInnerAngle; - public Array_byte ConeOuterAngleOrCapExt; - public Array_byte CoronaIntensity; + public List Direction { get { return this.Entries.Select(e => e.Direction).ToList(); } } + public List Falloff { get { return this.Entries.Select(e => e.FallOff).ToList(); } } + public List FalloffExponent { get { return this.Entries.Select(e => e.FalloffExponent).ToList(); } } + public List TimeAndStateFlags { get { return this.Entries.Select(e => e.TimeAndStateFlags).ToList(); } } + public List Hash { get { return this.Entries.Select(e => e.Hash).ToList(); } } + public List ConeInnerAngle { get { return this.Entries.Select(e => e.ConeInnerAngle).ToList(); } } + public List ConeOuterAngleOrCapExt { get { return this.Entries.Select(e => e.ConeOuterAngleOrCapExt).ToList(); } } + public List CoronaIntensity { get { return this.Entries.Select(e => e.CoronaIntensity).ToList(); } } + + public List Entries = new List(); public MCLODLight() { @@ -41,33 +43,51 @@ public override void Parse(MetaFile meta, CLODLight CLODLight) this.Meta = meta; this.MetaStructure = CLODLight; - var direction = MetaUtils.ConvertDataArray(meta, CLODLight.direction); - this.Direction = direction?.Select(e => { var msw = new MVECTOR3(); msw.Parse(meta, e); return msw; }).ToList(); + var _direction = MetaUtils.ConvertDataArray(meta, CLODLight.direction); + List direction = _direction?.Select(e => { var msw = new MVECTOR3(); msw.Parse(meta, e); return msw; }).ToList(); - // this.Falloff = CLODLight.falloff; - // this.FalloffExponent = CLODLight.falloffExponent; - // this.TimeAndStateFlags = CLODLight.timeAndStateFlags; - // this.Hash = CLODLight.hash; - // this.ConeInnerAngle = CLODLight.coneInnerAngle; - // this.ConeOuterAngleOrCapExt = CLODLight.coneOuterAngleOrCapExt; - // this.CoronaIntensity = CLODLight.coronaIntensity; - } + float[] falloff = MetaUtils.ConvertDataArray(meta, CLODLight.falloff.Pointer, CLODLight.falloff.Count1).ToArray(); + float[] falloffExponent = MetaUtils.ConvertDataArray(meta, CLODLight.falloffExponent.Pointer, CLODLight.falloffExponent.Count1).ToArray(); + uint[] timeAndStateFlags = MetaUtils.ConvertDataArray(meta, CLODLight.timeAndStateFlags.Pointer, CLODLight.timeAndStateFlags.Count1).ToArray(); + uint[] hash = MetaUtils.ConvertDataArray(meta, CLODLight.hash.Pointer, CLODLight.hash.Count1).ToArray(); + byte[] coneInnerAngle = MetaUtils.ConvertDataArray(meta, CLODLight.coneInnerAngle.Pointer, CLODLight.coneInnerAngle.Count1).ToArray(); + byte[] coneOuterAngleOrCapExt = MetaUtils.ConvertDataArray(meta, CLODLight.coneOuterAngleOrCapExt.Pointer, CLODLight.coneOuterAngleOrCapExt.Count1).ToArray(); + byte[] coronaIntensity = MetaUtils.ConvertDataArray(meta, CLODLight.coronaIntensity.Pointer, CLODLight.coronaIntensity.Count1).ToArray(); + + Entries.Clear(); + + for(int i = 0; i < hash.Length; i++) + { + Entries.Add(new LODLightEntry() + { + Direction = direction[i], + FallOff = falloff[i], + FalloffExponent = falloffExponent[i], + TimeAndStateFlags = timeAndStateFlags[i], + Hash = hash[i], + ConeInnerAngle = coneInnerAngle[i], + ConeOuterAngleOrCapExt = coneOuterAngleOrCapExt[i], + CoronaIntensity = coronaIntensity[i] + }); + } + } public override void Build(MetaBuilder mb, bool isRoot = false) { if(this.Direction != null) this.MetaStructure.direction = mb.AddItemArrayPtr(MetaName.VECTOR3, this.Direction.Select(e => { e.Build(mb); return e.MetaStructure; }).ToArray()); - MVECTOR3.AddEnumAndStructureInfo(mb); - // this.MetaStructure.falloff = this.Falloff; - // this.MetaStructure.falloffExponent = this.FalloffExponent; - // this.MetaStructure.timeAndStateFlags = this.TimeAndStateFlags; - // this.MetaStructure.hash = this.Hash; - // this.MetaStructure.coneInnerAngle = this.ConeInnerAngle; - // this.MetaStructure.coneOuterAngleOrCapExt = this.ConeOuterAngleOrCapExt; - // this.MetaStructure.coronaIntensity = this.CoronaIntensity; + MVECTOR3.AddEnumAndStructureInfo(mb); + + this.MetaStructure.falloff = mb.AddFloatArrayPtr(this.Falloff.ToArray()); + this.MetaStructure.falloffExponent = mb.AddFloatArrayPtr(this.FalloffExponent.ToArray()); + this.MetaStructure.timeAndStateFlags = mb.AddUintArrayPtr(this.TimeAndStateFlags.ToArray()); + this.MetaStructure.hash = mb.AddUintArrayPtr(this.Hash.ToArray()); + this.MetaStructure.coneInnerAngle = mb.AddByteArrayPtr(this.ConeInnerAngle.ToArray()); + this.MetaStructure.coneOuterAngleOrCapExt = mb.AddByteArrayPtr(this.ConeOuterAngleOrCapExt.ToArray()); + this.MetaStructure.coronaIntensity = mb.AddByteArrayPtr(this.CoronaIntensity.ToArray()); - MCLODLight.AddEnumAndStructureInfo(mb); + MCLODLight.AddEnumAndStructureInfo(mb); if(isRoot) { @@ -77,4 +97,16 @@ public override void Build(MetaBuilder mb, bool isRoot = false) } } } + + public struct LODLightEntry + { + public MVECTOR3 Direction; + public float FallOff; + public float FalloffExponent; + public uint TimeAndStateFlags; + public uint Hash; + public byte ConeInnerAngle; + public byte ConeOuterAngleOrCapExt; + public byte CoronaIntensity; + } } diff --git a/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MVECTOR3.cs b/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MVECTOR3.cs index eafb425b..2b124288 100644 --- a/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MVECTOR3.cs +++ b/RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MVECTOR3.cs @@ -55,5 +55,10 @@ public override void Build(MetaBuilder mb, bool isRoot = false) this.Meta = mb.GetMeta(); } } - } + + public static implicit operator Vector3(MVECTOR3 mvec) + { + return new Vector3(mvec.X, mvec.Y, mvec.Z); + } + } }