bump and improving MorphTarget data generation for Snooper
Some checks are pending
FModel QA Builder / build (push) Waiting to run

This commit is contained in:
LongerWarrior 2024-09-08 21:10:18 +03:00
parent aa41224d57
commit b6d67741e7
3 changed files with 42 additions and 2 deletions

@ -1 +1 @@
Subproject commit 33ba4d6886212e244ec0a32bfc8183db85f2a398
Subproject commit 1692f1e6c3bdc7a0af4e926cfbcdfc52e5ad424e

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using CUE4Parse.UE4.Assets.Exports.Animation;
using CUE4Parse.UE4.Objects.Core.Math;
using OpenTK.Graphics.OpenGL4;
@ -60,6 +61,27 @@ public class Morph : IDisposable
}
}
public Morph(float[] vertices, Dictionary<uint, int> dict, UMorphTarget morphTarget)
{
Name = morphTarget.Name;
Vertices = new float[vertices.Length];
Array.Copy(vertices, Vertices, vertices.Length);
foreach (var vert in morphTarget.MorphLODModels[0].Vertices)
{
var count = 0;
if (dict.TryGetValue(vert.SourceIdx, out var baseIndex))
{
Vertices[baseIndex + count++] += vert.PositionDelta.X * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] += vert.PositionDelta.Z * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] += vert.PositionDelta.Y * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] += vert.TangentZDelta.X;
Vertices[baseIndex + count++] += vert.TangentZDelta.Z;
Vertices[baseIndex + count++] += vert.TangentZDelta.Y;
}
}
}
public void Setup()
{
_handle = GL.CreateProgram();

View File

@ -79,13 +79,31 @@ public class SkeletalModel : UModel
export.PopulateMorphTargetVerticesData();
var verticesCount = Vertices.Length / VertexSize;
var cachedVertices = new float[verticesCount * Morph.VertexSize];
var vertexLookup = new Dictionary<uint, int>(verticesCount);
for (int i = 0; i < Vertices.Length; i += VertexSize)
{
var count = 0;
var baseIndex = i / VertexSize * Morph.VertexSize;
vertexLookup[(uint) Vertices[i]] = baseIndex;
{
cachedVertices[baseIndex + count++] = Vertices[i + 1];
cachedVertices[baseIndex + count++] = Vertices[i + 2];
cachedVertices[baseIndex + count++] = Vertices[i + 3];
cachedVertices[baseIndex + count++] = Vertices[i + 7];
cachedVertices[baseIndex + count++] = Vertices[i + 8];
cachedVertices[baseIndex + count++] = Vertices[i + 9];
}
}
foreach (var morph in export.MorphTargets)
{
if (!morph.TryLoad(out UMorphTarget morphTarget) || morphTarget.MorphLODModels.Length < 1 ||
morphTarget.MorphLODModels[0].Vertices.Length < 1)
continue;
Morphs.Add(new Morph(Vertices, VertexSize, morphTarget));
Morphs.Add(new Morph(cachedVertices, vertexLookup, morphTarget));
}
}