just misc
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Lumina.Data.Parsing;
|
||||
using Lumina.Extensions;
|
||||
using MeshDecimator;
|
||||
using MeshDecimator.Algorithms;
|
||||
using MeshDecimator.Math;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Penumbra.GameData.Files.ModelStructs;
|
||||
@@ -94,6 +95,8 @@ internal static class MdlDecimator
|
||||
var newVertexBuffer = new List<byte>(mdl.VertexBufferSize[lodIndex] > 0 ? (int)mdl.VertexBufferSize[lodIndex] : 0);
|
||||
var newIndexBuffer = new List<ushort>(mdl.IndexBufferSize[lodIndex] > 0 ? (int)(mdl.IndexBufferSize[lodIndex] / sizeof(ushort)) : 0);
|
||||
var subMeshCursor = 0;
|
||||
DecimationAlgorithm? decimationAlgorithm = null;
|
||||
int? decimationUvChannelCount = null;
|
||||
|
||||
for (var meshIndex = 0; meshIndex < meshes.Length; meshIndex++)
|
||||
{
|
||||
@@ -119,6 +122,8 @@ internal static class MdlDecimator
|
||||
out vertexStreams,
|
||||
out indices,
|
||||
out decimated,
|
||||
ref decimationAlgorithm,
|
||||
ref decimationUvChannelCount,
|
||||
logger))
|
||||
{
|
||||
updatedSubMeshes = OffsetSubMeshes(updatedSubMeshes, meshIndexBase);
|
||||
@@ -309,6 +314,8 @@ internal static class MdlDecimator
|
||||
out byte[][] vertexStreams,
|
||||
out int[] indices,
|
||||
out bool decimated,
|
||||
ref DecimationAlgorithm? decimationAlgorithm,
|
||||
ref int? decimationUvChannelCount,
|
||||
MsLogger logger)
|
||||
{
|
||||
updatedMesh = mesh;
|
||||
@@ -352,8 +359,7 @@ internal static class MdlDecimator
|
||||
}
|
||||
|
||||
var meshDecimatorMesh = BuildMesh(decoded, subMeshIndices);
|
||||
var algorithm = MeshDecimation.CreateAlgorithm(Algorithm.Default);
|
||||
algorithm.Logger = logger;
|
||||
var algorithm = GetOrCreateAlgorithm(format, ref decimationAlgorithm, ref decimationUvChannelCount, logger);
|
||||
algorithm.Initialize(meshDecimatorMesh);
|
||||
algorithm.DecimateMesh(targetTriangles);
|
||||
var decimatedMesh = algorithm.ToMesh();
|
||||
@@ -374,6 +380,23 @@ internal static class MdlDecimator
|
||||
return true;
|
||||
}
|
||||
|
||||
private static DecimationAlgorithm GetOrCreateAlgorithm(
|
||||
VertexFormat format,
|
||||
ref DecimationAlgorithm? decimationAlgorithm,
|
||||
ref int? decimationUvChannelCount,
|
||||
MsLogger logger)
|
||||
{
|
||||
var uvChannelCount = format.UvChannelCount;
|
||||
if (decimationAlgorithm == null || decimationUvChannelCount != uvChannelCount)
|
||||
{
|
||||
decimationAlgorithm = MeshDecimation.CreateAlgorithm(Algorithm.Default);
|
||||
decimationAlgorithm.Logger = logger;
|
||||
decimationUvChannelCount = uvChannelCount;
|
||||
}
|
||||
|
||||
return decimationAlgorithm;
|
||||
}
|
||||
|
||||
private static Mesh BuildMesh(DecodedMeshData decoded, int[][] subMeshIndices)
|
||||
{
|
||||
var mesh = new Mesh(decoded.Positions, subMeshIndices);
|
||||
|
||||
Reference in New Issue
Block a user