Skip to content

Commit

Permalink
Add LOD light support
Browse files Browse the repository at this point in the history
  • Loading branch information
indilo53 committed Jun 28, 2019
1 parent adfca39 commit ac9f024
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public class MCDistantLODLight : MetaStructureWrapper<CDistantLODLight>
{
public static MetaName _MetaName = MetaName.CDistantLODLight;
public MetaFile Meta;
public List<MVECTOR3> Position;
public Array_uint RGBI;
public ushort NumStreetLights;
public List<MVECTOR3> Position { get { return this.Entries.Select(e => e.Position).ToList(); }}
public List<uint> RGBI { get { return this.Entries.Select(e => e.RGBI).ToList(); } }
public ushort NumStreetLights;
public ushort Category;

public MCDistantLODLight()
public List<DistantLODLightEntry> Entries = new List<DistantLODLightEntry>();

public MCDistantLODLight()
{
this.MetaName = MetaName.CDistantLODLight;
this.MetaStructure = new CDistantLODLight();
Expand All @@ -37,11 +39,23 @@ public override void Parse(MetaFile meta, CDistantLODLight CDistantLODLight)
this.Meta = meta;
this.MetaStructure = CDistantLODLight;

var position = MetaUtils.ConvertDataArray<VECTOR3>(meta, CDistantLODLight.position);
this.Position = position?.Select(e => { var msw = new MVECTOR3(); msw.Parse(meta, e); return msw; }).ToList();
var _position = MetaUtils.ConvertDataArray<VECTOR3>(meta, CDistantLODLight.position);
List<MVECTOR3> position = _position?.Select(e => { var msw = new MVECTOR3(); msw.Parse(meta, e); return msw; }).ToList();

uint[] rgbi = MetaUtils.ConvertDataArray<uint>(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;
}

Expand All @@ -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);
Expand All @@ -65,4 +79,10 @@ public override void Build(MetaBuilder mb, bool isRoot = false)
}
}
}

public struct DistantLODLightEntry
{
public MVECTOR3 Position;
public uint RGBI;
}
}
86 changes: 59 additions & 27 deletions RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MCLODLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ public class MCLODLight : MetaStructureWrapper<CLODLight>
{
public static MetaName _MetaName = MetaName.CLODLight;
public MetaFile Meta;
public List<MVECTOR3> Direction = new List<MVECTOR3>();
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<MVECTOR3> Direction { get { return this.Entries.Select(e => e.Direction).ToList(); } }
public List<float> Falloff { get { return this.Entries.Select(e => e.FallOff).ToList(); } }
public List<float> FalloffExponent { get { return this.Entries.Select(e => e.FalloffExponent).ToList(); } }
public List<uint> TimeAndStateFlags { get { return this.Entries.Select(e => e.TimeAndStateFlags).ToList(); } }
public List<uint> Hash { get { return this.Entries.Select(e => e.Hash).ToList(); } }
public List<byte> ConeInnerAngle { get { return this.Entries.Select(e => e.ConeInnerAngle).ToList(); } }
public List<byte> ConeOuterAngleOrCapExt { get { return this.Entries.Select(e => e.ConeOuterAngleOrCapExt).ToList(); } }
public List<byte> CoronaIntensity { get { return this.Entries.Select(e => e.CoronaIntensity).ToList(); } }

public List<LODLightEntry> Entries = new List<LODLightEntry>();

public MCLODLight()
{
Expand All @@ -41,33 +43,51 @@ public override void Parse(MetaFile meta, CLODLight CLODLight)
this.Meta = meta;
this.MetaStructure = CLODLight;

var direction = MetaUtils.ConvertDataArray<VECTOR3>(meta, CLODLight.direction);
this.Direction = direction?.Select(e => { var msw = new MVECTOR3(); msw.Parse(meta, e); return msw; }).ToList();
var _direction = MetaUtils.ConvertDataArray<VECTOR3>(meta, CLODLight.direction);
List<MVECTOR3> 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<float>(meta, CLODLight.falloff.Pointer, CLODLight.falloff.Count1).ToArray();
float[] falloffExponent = MetaUtils.ConvertDataArray<float>(meta, CLODLight.falloffExponent.Pointer, CLODLight.falloffExponent.Count1).ToArray();
uint[] timeAndStateFlags = MetaUtils.ConvertDataArray<uint>(meta, CLODLight.timeAndStateFlags.Pointer, CLODLight.timeAndStateFlags.Count1).ToArray();
uint[] hash = MetaUtils.ConvertDataArray<uint>(meta, CLODLight.hash.Pointer, CLODLight.hash.Count1).ToArray();
byte[] coneInnerAngle = MetaUtils.ConvertDataArray<byte>(meta, CLODLight.coneInnerAngle.Pointer, CLODLight.coneInnerAngle.Count1).ToArray();
byte[] coneOuterAngleOrCapExt = MetaUtils.ConvertDataArray<byte>(meta, CLODLight.coneOuterAngleOrCapExt.Pointer, CLODLight.coneOuterAngleOrCapExt.Count1).ToArray();
byte[] coronaIntensity = MetaUtils.ConvertDataArray<byte>(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)
{
Expand All @@ -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;
}
}
7 changes: 6 additions & 1 deletion RageLib.GTA5/ResourceWrappers/PC/Meta/Structures/MVECTOR3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit ac9f024

Please sign in to comment.