Parse decal effects

This commit is contained in:
Ammar Askar 2023-08-01 23:30:31 -04:00
parent 2bbda81f43
commit d55f2c1bd2
6 changed files with 87 additions and 6 deletions

View file

@ -1,7 +1,18 @@
namespace OpenTS2.Content.DBPF.Effects
{
public readonly struct DecalEffect
{
using UnityEngine;
namespace OpenTS2.Content.DBPF.Effects
{
public readonly struct DecalEffect : IBaseEffect
{
public readonly string TextureName;
public readonly float Life;
public readonly Vector2 TextureOffset;
public DecalEffect(string textureName, float life, Vector2 textureOffset)
{
TextureName = textureName;
Life = life;
TextureOffset = textureOffset;
}
}
}

View file

@ -0,0 +1,10 @@
namespace OpenTS2.Content.DBPF.Effects
{
/// <summary>
/// Plays a bunch of effects in a sequence.
/// </summary>
public readonly struct SequenceEffect : IBaseEffect
{
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ef4690a55e1741ec9a3c21a3e6f0234c
timeCreated: 1690946890

View file

@ -38,11 +38,15 @@ namespace OpenTS2.Content.DBPF
public DecalEffect[] DecalEffects { get; }
public EffectsAsset(ParticleEffect[] particles, MetaParticle[] metaParticles, DecalEffect[] decalEffects)
public SequenceEffect[] SequenceEffects { get; }
public EffectsAsset(ParticleEffect[] particles, MetaParticle[] metaParticles, DecalEffect[] decalEffects,
SequenceEffect[] sequenceEffects)
{
Particles = particles;
MetaParticles = metaParticles;
DecalEffects = decalEffects;
SequenceEffects = sequenceEffects;
}
}
}

View file

@ -35,8 +35,20 @@ namespace OpenTS2.Files.Formats.DBPF
}
var decals = new DecalEffect[reader.ReadUInt32()];
for (var i = 0; i < decals.Length; i++)
{
decals[i] = ReadDecalEffect(reader);
}
return new EffectsAsset(particleEffects, metaParticles, decals);
var numBrushes = reader.ReadUInt32();
Debug.Assert(numBrushes == 0, "There shouldn't be any brush effects in Sims2");
var numScrubbers = reader.ReadUInt32();
Debug.Assert(numScrubbers == 0, "There shouldn't be any brush effects in Sims2");
var sequences = new SequenceEffect[reader.ReadUInt32()];
return new EffectsAsset(particleEffects, metaParticles, decals, sequences);
}
private static Vector3[] ReadMultipleVectors(IoBuffer reader)
@ -215,5 +227,33 @@ namespace OpenTS2.Files.Formats.DBPF
return new MetaParticle(flags, life, emission, size, color, baseEffect);
}
private static DecalEffect ReadDecalEffect(IoBuffer reader)
{
var version = reader.ReadUInt16();
Debug.Assert(version == 1);
var flags = reader.ReadUInt32();
var textureName = reader.ReadUint32PrefixedString();
var decalDrawType = reader.ReadByte();
var lifeType = reader.ReadByte();
var life = reader.ReadFloat();
var rotateCurve = FloatCurve.Deserialize(reader);
var sizeCurve = FloatCurve.Deserialize(reader);
var alphaCurve = FloatCurve.Deserialize(reader);
var colors = ReadMultipleVectors(reader);
var aspectCurve = FloatCurve.Deserialize(reader);
var alphaVary = reader.ReadFloat();
var sizeVary = reader.ReadFloat();
var rotateVary = reader.ReadFloat();
var textureRepeat = reader.ReadFloat();
var textureOffset = Vector2Serializer.Deserialize(reader);
return new DecalEffect(textureName, life, textureOffset);
}
}
}

View file

@ -24,6 +24,7 @@ public class EffectsCodecTest
Assert.That(effectsAsset.Particles.Length, Is.EqualTo(1792));
Assert.That(effectsAsset.MetaParticles.Length, Is.EqualTo(302));
Assert.That(effectsAsset.DecalEffects.Length, Is.EqualTo(23));
Assert.That(effectsAsset.SequenceEffects.Length, Is.EqualTo(82));
}
[Test]
@ -77,4 +78,16 @@ public class EffectsCodecTest
Assert.That(meta.Color.AlphaCurve.Curve, Is.EquivalentTo(new[] { 1.0f }));
}
[Test]
public void TestFirstDecalIsCorrect()
{
var effectsAsset = ContentProvider.Get()
.GetAsset<EffectsAsset>(new ResourceKey(instanceID: 1, groupID: GroupIDs.Effects, typeID: TypeIDs.EFFECTS));
var decal = effectsAsset.DecalEffects[0];
Assert.That(decal.Life, Is.EqualTo(0.1).Within(0.05));
Assert.That(decal.TextureName, Is.EqualTo("terrain_edit_ring"));
Assert.That(decal.TextureOffset, Is.EqualTo(new Vector2(0, 0)));
}
}