mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-16 21:08:28 +00:00
load night colors
This commit is contained in:
parent
b27bcac9a3
commit
25c3954256
5 changed files with 81 additions and 10 deletions
|
@ -158,12 +158,22 @@ namespace SanAndreasUnity.Behaviours.World
|
|||
|
||||
Profiler.BeginSample ("Add mesh", this);
|
||||
|
||||
var nightColors = geoms.Geometry[0].RwGeometry.ExtraVertColor;
|
||||
bool hasNightColors = nightColors != null && nightColors.Colors != null;
|
||||
|
||||
var mf = gameObject.AddComponent<MeshFilter>();
|
||||
var mr = gameObject.AddComponent<MeshRenderer>();
|
||||
|
||||
mf.sharedMesh = geoms.Geometry[0].Mesh;
|
||||
mr.sharedMaterials = geoms.Geometry[0].GetMaterials(Instance.Object.Flags,
|
||||
mat => mat.SetTexture(NoiseTexId, NoiseTex));
|
||||
mr.sharedMaterials = geoms.Geometry[0].GetMaterials(
|
||||
Instance.Object.Flags,
|
||||
hasNightColors,
|
||||
mat =>
|
||||
{
|
||||
mat.SetTexture(NoiseTexId, NoiseTex);
|
||||
if (hasNightColors)
|
||||
mat.SetColorArray(Geometry.NightColorsPropertyId, nightColors.Colors);
|
||||
});
|
||||
|
||||
Profiler.EndSample ();
|
||||
|
||||
|
@ -198,9 +208,10 @@ namespace SanAndreasUnity.Behaviours.World
|
|||
|
||||
foreach (var geometry in geometryParts.Geometry)
|
||||
{
|
||||
if (geometry.TwoDEffect != null && geometry.TwoDEffect.Lights != null)
|
||||
var twoDEffect = geometry.RwGeometry.TwoDEffect;
|
||||
if (twoDEffect != null && twoDEffect.Lights != null)
|
||||
{
|
||||
foreach (var lightInfo in geometry.TwoDEffect.Lights)
|
||||
foreach (var lightInfo in twoDEffect.Lights)
|
||||
{
|
||||
LightSource.Create(tr, lightInfo);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace SanAndreasUnity.Importing.Conversion
|
|||
NoBackCull = 1,
|
||||
Alpha = 2,
|
||||
Vehicle = 4,
|
||||
OverrideAlpha = 8
|
||||
OverrideAlpha = 8,
|
||||
NightColors = 16,
|
||||
}
|
||||
|
||||
public class Geometry
|
||||
|
@ -58,6 +59,10 @@ namespace SanAndreasUnity.Importing.Conversion
|
|||
get { return _sCarColorIndexId == -1 ? _sCarColorIndexId = Shader.PropertyToID("_CarColorIndex") : _sCarColorIndexId; }
|
||||
}
|
||||
|
||||
private static int _sNightColorsPropertyId = -1;
|
||||
|
||||
public static int NightColorsPropertyId => _sNightColorsPropertyId == -1 ? _sNightColorsPropertyId = Shader.PropertyToID("_NightColors") : _sNightColorsPropertyId;
|
||||
|
||||
private static int[] FromTriangleStrip(IList<int> indices)
|
||||
{
|
||||
var dst = new List<int>((indices.Count - 2) * 3);
|
||||
|
@ -604,8 +609,10 @@ namespace SanAndreasUnity.Importing.Conversion
|
|||
public readonly Mesh Mesh;
|
||||
|
||||
private readonly RenderWareStream.Geometry _geom;
|
||||
public readonly TwoDEffect TwoDEffect;
|
||||
public RenderWareStream.Geometry RwGeometry => _geom;
|
||||
|
||||
public readonly TextureDictionary[] _textureDictionaries;
|
||||
|
||||
private readonly Dictionary<MaterialFlags, UnityEngine.Material[]> _materials;
|
||||
|
||||
public readonly UnityEngine.Matrix4x4[] SkinToBoneMatrices;
|
||||
|
@ -621,17 +628,20 @@ namespace SanAndreasUnity.Importing.Conversion
|
|||
}
|
||||
|
||||
_geom = geom;
|
||||
TwoDEffect = geom.TwoDEffect;
|
||||
_textureDictionaries = textureDictionaries;
|
||||
_materials = new Dictionary<MaterialFlags, UnityEngine.Material[]>();
|
||||
}
|
||||
|
||||
public UnityEngine.Material[] GetMaterials(ObjectFlag flags)
|
||||
public UnityEngine.Material[] GetMaterials(
|
||||
ObjectFlag flags,
|
||||
bool hasNightColors)
|
||||
{
|
||||
return GetMaterials(flags, x => { });
|
||||
return GetMaterials(flags, hasNightColors, x => { });
|
||||
}
|
||||
|
||||
public UnityEngine.Material[] GetMaterials(ObjectFlag flags,
|
||||
public UnityEngine.Material[] GetMaterials(
|
||||
ObjectFlag flags,
|
||||
bool hasNightColors,
|
||||
Action<UnityEngine.Material> setupMaterial)
|
||||
{
|
||||
var matFlags = MaterialFlags.Default | MaterialFlags.OverrideAlpha;
|
||||
|
@ -647,6 +657,11 @@ namespace SanAndreasUnity.Importing.Conversion
|
|||
matFlags |= MaterialFlags.Alpha;
|
||||
}
|
||||
|
||||
if (hasNightColors)
|
||||
{
|
||||
matFlags |= MaterialFlags.NightColors;
|
||||
}
|
||||
|
||||
return GetMaterials(matFlags, setupMaterial);
|
||||
}
|
||||
|
||||
|
|
31
Assets/Scripts/Importing/RenderWareStream/ExtraVertColor.cs
Normal file
31
Assets/Scripts/Importing/RenderWareStream/ExtraVertColor.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System.IO;
|
||||
using Types = SanAndreasUnity.Importing.Conversion.Types;
|
||||
|
||||
namespace SanAndreasUnity.Importing.RenderWareStream
|
||||
{
|
||||
[SectionType(0x0253F2F9)]
|
||||
public class ExtraVertColor : SectionData
|
||||
{
|
||||
public readonly UnityEngine.Color[] Colors;
|
||||
|
||||
public ExtraVertColor(SectionHeader header, Stream stream)
|
||||
: base(header, stream)
|
||||
{
|
||||
var reader = new BinaryReader(stream);
|
||||
|
||||
uint magicNumber = reader.ReadUInt32();
|
||||
|
||||
if (0 == magicNumber)
|
||||
return;
|
||||
|
||||
var geometry = header.GetParent<Geometry>();
|
||||
|
||||
Colors = new UnityEngine.Color[geometry.VertexCount];
|
||||
|
||||
for (int i = 0; i < geometry.VertexCount; i++)
|
||||
{
|
||||
Colors[i] = Types.Convert(new Color4(reader));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fc237b311e2edce4a94e479a86ab9fac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -76,6 +76,8 @@ namespace SanAndreasUnity.Importing.RenderWareStream
|
|||
|
||||
public readonly TwoDEffect TwoDEffect;
|
||||
|
||||
public readonly ExtraVertColor ExtraVertColor;
|
||||
|
||||
public Geometry(SectionHeader header, Stream stream)
|
||||
: base(header, stream)
|
||||
{
|
||||
|
@ -159,6 +161,7 @@ namespace SanAndreasUnity.Importing.RenderWareStream
|
|||
MaterialSplits = extensions.FirstOrDefault<MaterialSplitList>().MaterialSplits;
|
||||
Skinning = extensions.FirstOrDefault<Skin>();
|
||||
TwoDEffect = extensions.FirstOrDefault<TwoDEffect>();
|
||||
ExtraVertColor = extensions.FirstOrDefault<ExtraVertColor>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue