2017-09-15 08:22:51 -07:00
|
|
|
using System.Collections.Generic;
|
2018-01-31 21:09:08 -06:00
|
|
|
using System.IO;
|
2018-08-10 19:56:25 -04:00
|
|
|
using ACE.Entity.Enum;
|
2017-09-15 08:22:51 -07:00
|
|
|
|
|
|
|
|
namespace ACE.DatLoader.Entity
|
|
|
|
|
{
|
2018-01-31 21:09:08 -06:00
|
|
|
public class Polygon : IUnpackable
|
2017-09-15 08:22:51 -07:00
|
|
|
{
|
2018-01-31 21:09:08 -06:00
|
|
|
public byte NumPts { get; private set; }
|
2018-08-10 19:56:25 -04:00
|
|
|
public StipplingType Stippling { get; private set; } // Whether it has that textured/bumpiness to it
|
2018-01-31 21:09:08 -06:00
|
|
|
|
2018-08-10 19:56:25 -04:00
|
|
|
public CullMode SidesType { get; private set; }
|
2018-01-31 21:09:08 -06:00
|
|
|
public short PosSurface { get; private set; }
|
|
|
|
|
public short NegSurface { get; private set; }
|
|
|
|
|
|
|
|
|
|
public List<short> VertexIds { get; } = new List<short>();
|
|
|
|
|
|
|
|
|
|
public List<byte> PosUVIndices { get; } = new List<byte>();
|
|
|
|
|
public List<byte> NegUVIndices { get; private set; } = new List<byte>();
|
|
|
|
|
|
2018-03-25 00:33:24 -04:00
|
|
|
public List<SWVertex> Vertices;
|
|
|
|
|
|
2018-01-31 21:09:08 -06:00
|
|
|
public void Unpack(BinaryReader reader)
|
2017-09-15 08:22:51 -07:00
|
|
|
{
|
2018-01-31 21:09:08 -06:00
|
|
|
NumPts = reader.ReadByte();
|
2018-08-10 19:56:25 -04:00
|
|
|
Stippling = (StipplingType)reader.ReadByte();
|
2017-09-15 08:22:51 -07:00
|
|
|
|
2018-08-10 19:56:25 -04:00
|
|
|
SidesType = (CullMode)reader.ReadInt32();
|
2018-01-31 21:09:08 -06:00
|
|
|
PosSurface = reader.ReadInt16();
|
|
|
|
|
NegSurface = reader.ReadInt16();
|
2017-09-15 08:22:51 -07:00
|
|
|
|
2018-01-31 21:09:08 -06:00
|
|
|
for (short i = 0; i < NumPts; i++)
|
|
|
|
|
VertexIds.Add(reader.ReadInt16());
|
2017-09-15 08:22:51 -07:00
|
|
|
|
2018-08-10 19:56:25 -04:00
|
|
|
if (!Stippling.HasFlag(StipplingType.NoPos))
|
2017-09-15 08:22:51 -07:00
|
|
|
{
|
2018-01-31 21:09:08 -06:00
|
|
|
for (short i = 0; i < NumPts; i++)
|
|
|
|
|
PosUVIndices.Add(reader.ReadByte());
|
2017-09-15 08:22:51 -07:00
|
|
|
}
|
|
|
|
|
|
2018-08-10 19:56:25 -04:00
|
|
|
if (SidesType == CullMode.Clockwise && !Stippling.HasFlag(StipplingType.NoNeg))
|
2017-09-15 08:22:51 -07:00
|
|
|
{
|
2018-01-31 21:09:08 -06:00
|
|
|
for (short i = 0; i < NumPts; i++)
|
|
|
|
|
NegUVIndices.Add(reader.ReadByte());
|
2017-09-15 08:22:51 -07:00
|
|
|
}
|
|
|
|
|
|
2018-08-10 19:56:25 -04:00
|
|
|
if (SidesType == CullMode.None)
|
2017-09-15 08:22:51 -07:00
|
|
|
{
|
2018-01-31 21:09:08 -06:00
|
|
|
NegSurface = PosSurface;
|
|
|
|
|
NegUVIndices = PosUVIndices;
|
2017-09-15 08:22:51 -07:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-25 00:33:24 -04:00
|
|
|
|
|
|
|
|
public void LoadVertices(CVertexArray vertexArray)
|
|
|
|
|
{
|
|
|
|
|
Vertices = new List<SWVertex>();
|
|
|
|
|
|
|
|
|
|
foreach (var id in VertexIds)
|
|
|
|
|
Vertices.Add(vertexArray.Vertices[(ushort)id]);
|
|
|
|
|
}
|
2017-09-15 08:22:51 -07:00
|
|
|
}
|
|
|
|
|
}
|