load lights info

This commit is contained in:
in0finite 2021-04-17 22:15:07 +02:00
parent 8be99cb5b8
commit 91491a19f1
5 changed files with 186 additions and 0 deletions

View file

@ -167,6 +167,8 @@ namespace SanAndreasUnity.Behaviours.World
Profiler.EndSample ();
CreateLights(this.transform, geoms);
geoms.AttachCollisionModel(transform);
Profiler.BeginSample ("Set layer", this);
@ -188,6 +190,28 @@ namespace SanAndreasUnity.Behaviours.World
}
public static void CreateLights(
Transform tr,
Geometry.GeometryParts geometryParts)
{
Profiler.BeginSample("CreateLights()", tr);
foreach (var geometry in geometryParts.Geometry)
{
if (geometry.TwoDEffect != null && geometry.TwoDEffect.Lights != null)
{
foreach (var lightInfo in geometry.TwoDEffect.Lights)
{
var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
go.transform.SetParent(tr);
go.transform.localPosition = lightInfo.Position;
}
}
}
Profiler.EndSample();
}
protected override void OnShow()
{
Profiler.BeginSample ("StaticGeometry.OnShow");

View file

@ -604,6 +604,7 @@ namespace SanAndreasUnity.Importing.Conversion
public readonly Mesh Mesh;
private readonly RenderWareStream.Geometry _geom;
public readonly TwoDEffect TwoDEffect;
public readonly TextureDictionary[] _textureDictionaries;
private readonly Dictionary<MaterialFlags, UnityEngine.Material[]> _materials;
@ -620,6 +621,7 @@ namespace SanAndreasUnity.Importing.Conversion
}
_geom = geom;
TwoDEffect = geom.TwoDEffect;
_textureDictionaries = textureDictionaries;
_materials = new Dictionary<MaterialFlags, UnityEngine.Material[]>();
}

View file

@ -74,6 +74,8 @@ namespace SanAndreasUnity.Importing.RenderWareStream
public readonly Skin Skinning;
public readonly TwoDEffect TwoDEffect;
public Geometry(SectionHeader header, Stream stream)
: base(header, stream)
{
@ -156,6 +158,7 @@ namespace SanAndreasUnity.Importing.RenderWareStream
MaterialSplits = extensions.FirstOrDefault<MaterialSplitList>().MaterialSplits;
Skinning = extensions.FirstOrDefault<Skin>();
TwoDEffect = extensions.FirstOrDefault<TwoDEffect>();
}
}
}

View file

@ -0,0 +1,146 @@
using System.Collections.Generic;
using System.IO;
using SanAndreasUnity.Importing.Conversion;
using SanAndreasUnity.Utilities;
namespace SanAndreasUnity.Importing.RenderWareStream
{
[SectionType(0x0253F2F8)]
public class TwoDEffect : SectionData
{
public readonly uint NumEntries;
public readonly List<Light> Lights;
public TwoDEffect(SectionHeader header, Stream stream)
: base(header, stream)
{
var reader = new BinaryReader(stream);
NumEntries = reader.ReadUInt32();
for (int i = 0; i < NumEntries; i++)
{
Vector3 position = new Vector3(reader);
uint dataType = reader.ReadUInt32();
uint dataSize = reader.ReadUInt32();
long nextEntryPosition = stream.Position + dataSize;
if (0 == dataType)
{
// light
if (null == Lights)
Lights = new List<Light>(1);
Lights.Add(new Light(position, dataSize, reader));
}
stream.Position = nextEntryPosition;
}
}
public readonly struct Light
{
public readonly UnityEngine.Vector3 Position;
public readonly Color4 Color;
public readonly float CoronaFarClip;
public readonly float PointlightRange;
public readonly float CoronaSize;
public readonly float ShadowSize;
public readonly CoronaShowMode CoronaShowModeFlags;
public readonly byte CoronaEnableReflection;
public readonly byte CoronaFlareType;
public readonly byte ShadowColorMultiplier;
public readonly Flags1 Flags_1;
public readonly string CoronaTexName;
public readonly string ShadowTexName;
public readonly byte ShadowZDistance;
public readonly Flags2 Flags_2;
public readonly byte LookDirectionX;
public readonly byte LookDirectionY;
public readonly byte LookDirectionZ;
public enum CoronaShowMode : byte
{
DEFAULT = 0,
RANDOM_FLASHING,
RANDOM_FLASHIN_ALWAYS_AT_WET_WEATHER,
LIGHTS_ANIM_SPEED_4X,
LIGHTS_ANIM_SPEED_2X,
LIGHTS_ANIM_SPEED_1X,
TRAFFICLIGHT = 7,
TRAINCROSSLIGHT,
ALWAYS_DISABLED,
AT_RAIN_ONLY,
ON_5S_OFF_5S,
ON_6S_OFF_4S,
ON_6S_OFF_4S_2,
}
[System.Flags]
public enum Flags1 : byte
{
CORONA_CHECK_OBSTACLES = 1,
FOG_TYPE = 2,
FOG_TYPE_2 = 4,
WITHOUT_CORONA = 8,
CORONA_ONLY_AT_LONG_DISTANCE = 16,
AT_DAY = 32,
AT_NIGHT = 64,
BLINKING1 = 128,
}
[System.Flags]
public enum Flags2 : byte
{
CORONA_ONLY_FROM_BELOW = 1,
BLINKING2 = 2,
UDPDATE_HEIGHT_ABOVE_GROUND = 4,
CHECK_DIRECTION = 8,
BLINKING3 = 16,
}
public Light(
Vector3 position,
uint dataSize,
BinaryReader reader)
{
if (dataSize != 76 && dataSize != 80)
throw new System.Exception($"Size of data for light 2d effect must be 76 or 80, found {dataSize}");
Position = Types.Convert(position);
Color = new Color4(reader);
CoronaFarClip = reader.ReadSingle();
PointlightRange = reader.ReadSingle();
CoronaSize = reader.ReadSingle();
ShadowSize = reader.ReadSingle();
CoronaShowModeFlags = (CoronaShowMode) reader.ReadByte();
CoronaEnableReflection = reader.ReadByte();
CoronaFlareType = reader.ReadByte();
ShadowColorMultiplier = reader.ReadByte();
Flags_1 = (Flags1) reader.ReadByte();
CoronaTexName = reader.ReadString(24);
ShadowTexName = reader.ReadString(24);
ShadowZDistance = reader.ReadByte();
Flags_2 = (Flags2) reader.ReadByte();
if (dataSize == 76)
{
LookDirectionX = 0;
LookDirectionY = 0;
LookDirectionZ = 0;
}
else
{
LookDirectionX = reader.ReadByte();
LookDirectionY = reader.ReadByte();
LookDirectionZ = reader.ReadByte();
}
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fdda9b81ecc389349b4506600a937258
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: