1
0
mirror of synced 2024-09-24 11:38:22 +02:00

Convert triangle strip primitive types for DAE.

This commit is contained in:
KillzXGaming 2019-11-16 14:08:27 -05:00
parent e7246fb79f
commit 76ff237935
3 changed files with 68 additions and 5 deletions

View File

@ -25,6 +25,10 @@ namespace Toolbox.Library
public bool CanCompress { get; } = false;
//Algorithm from
//https://github.com/Daniel-McCarthy/Mr-Peeps-Compressor/blob/master/PeepsCompress/PeepsCompress/Algorithm%20Classes/YAY0.cs
//License https://github.com/Daniel-McCarthy/Mr-Peeps-Compressor/blob/master/LICENSE
public Stream Decompress(Stream stream)
{
return new MemoryStream(Decompress(stream.ToArray()));
@ -44,7 +48,7 @@ namespace Toolbox.Library
while (output.Count < decompressedSize)
{
break;
}
}

View File

@ -323,8 +323,15 @@ namespace Toolbox.Library
triangleLists.Add(triangleList);
var lodMesh = mesh.lodMeshes[mesh.DisplayLODIndex];
for (int i = 0; i < lodMesh.faces.Count; i++)
triangleList.Indices.Add((uint)lodMesh.faces[i]);
List<int> faces = new List<int>();
if (lodMesh.PrimativeType == STPrimativeType.TrangleStrips)
faces = STGenericObject.ConvertTriangleStripsToTriangles(lodMesh.faces);
else
faces = lodMesh.faces;
for (int i = 0; i < faces.Count; i++)
triangleList.Indices.Add((uint)faces[i]);
}
if (mesh.PolygonGroups.Count > 0)
{
@ -337,8 +344,14 @@ namespace Toolbox.Library
if (group.MaterialIndex != -1)
triangleList.Material = Materials[group.MaterialIndex].Text;
for (int i = 0; i < group.faces.Count; i++)
triangleList.Indices.Add((uint)group.faces[i]);
List<int> faces = new List<int>();
if (group.PrimativeType == STPrimativeType.TrangleStrips)
faces = STGenericObject.ConvertTriangleStripsToTriangles(group.faces);
else
faces = group.faces;
for (int i = 0; i < faces.Count; i++)
triangleList.Indices.Add((uint)faces[i]);
}
}

View File

@ -180,6 +180,52 @@ namespace Toolbox.Library
#region Methods
public static List<int> ConvertTriangleStripsToTriangles(List<int> faces)
{
List<int> f = new List<int>();
int startDirection = 1;
int p = 0;
int f1 = faces[p++];
int f2 = faces[p++];
int faceDirection = startDirection;
int f3;
do
{
f3 = faces[p++];
if (f3 == 0xFFFF)
{
f1 = faces[p++];
f2 = faces[p++];
faceDirection = startDirection;
}
else
{
faceDirection *= -1;
if ((f1 != f2) && (f2 != f3) && (f3 != f1))
{
if (faceDirection > 0)
{
f.Add(f3);
f.Add(f2);
f.Add(f1);
}
else
{
f.Add(f2);
f.Add(f3);
f.Add(f1);
}
}
f1 = f2;
f2 = f3;
}
} while (p < faces.Count);
return f;
}
public void TransformPosition(Vector3 Position, Vector3 Rotation, Vector3 Scale)
{
Matrix4 positionMat = Matrix4.CreateTranslation(Position);