Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
GMatrixGames 2023-01-07 23:26:18 -05:00
commit ac0e11ea39
No known key found for this signature in database
GPG Key ID: E9F4FDECB669C64F
6 changed files with 57 additions and 24 deletions

View File

@ -68,7 +68,7 @@ public class PickingTexture : IDisposable
_shader.SetUniform("uD", guid.D); _shader.SetUniform("uD", guid.D);
if (!model.Show) continue; if (!model.Show) continue;
model.SimpleRender(_shader); model.PickingRender(_shader);
} }
Bind(0); Bind(0);

View File

@ -1,10 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics;
using CUE4Parse_Conversion.Animations; using CUE4Parse_Conversion.Animations;
using CUE4Parse.UE4.Assets.Exports.Animation; using CUE4Parse.UE4.Assets.Exports.Animation;
using CUE4Parse.UE4.Assets.Exports.SkeletalMesh; using CUE4Parse.UE4.Assets.Exports.SkeletalMesh;
using CUE4Parse.UE4.Objects.Core.Math;
using CUE4Parse.UE4.Objects.UObject; using CUE4Parse.UE4.Objects.UObject;
using FModel.Views.Snooper.Shading; using FModel.Views.Snooper.Shading;
using Serilog;
namespace FModel.Views.Snooper.Models.Animations; namespace FModel.Views.Snooper.Models.Animations;
@ -19,7 +22,9 @@ public class Skeleton : IDisposable
public Animation Anim; public Animation Anim;
public Skeleton(FPackageIndex package) private FVector _previousMatrix;
public Skeleton(FPackageIndex package, Transform transform)
{ {
UnrealSkeleton = package.Load<USkeleton>(); UnrealSkeleton = package.Load<USkeleton>();
if (UnrealSkeleton == null) return; if (UnrealSkeleton == null) return;
@ -38,6 +43,7 @@ public class Skeleton : IDisposable
var bone = UnrealSkeleton.ReferenceSkeleton.FinalRefBonePose[parentBoneIndex]; var bone = UnrealSkeleton.ReferenceSkeleton.FinalRefBonePose[parentBoneIndex];
boneTransform = new Transform boneTransform = new Transform
{ {
Relation = transform.Matrix,
Rotation = bone.Rotation, Rotation = bone.Rotation,
Position = bone.Translation * Constants.SCALE_DOWN_RATIO, Position = bone.Translation * Constants.SCALE_DOWN_RATIO,
Scale = bone.Scale3D Scale = bone.Scale3D
@ -81,6 +87,22 @@ public class Skeleton : IDisposable
Anim = new Animation(anim, BonesIndexByName, BonesTransformByIndex); Anim = new Animation(anim, BonesIndexByName, BonesTransformByIndex);
} }
public void UpdateSocketsMatrix(Transform t)
{
var m = t.Position;
if (m == _previousMatrix) return;
var delta = _previousMatrix - m;
Log.Logger.Information("Update {0}", delta);
// BonesTransformByIndex[0].Relation.Translation += delta;
foreach (var socket in Sockets)
{
socket.Transform.Relation.Translation += delta;
}
_previousMatrix = m;
}
public void SetUniform(Shader shader) public void SetUniform(Shader shader)
{ {
if (!IsLoaded) return; if (!IsLoaded) return;

View File

@ -105,6 +105,7 @@ public class Model : IDisposable
private Model(UObject export, ResolvedObject[] materials, FPackageIndex skeleton, int numLods, CBaseMeshLod lod, CMeshVertex[] vertices, Transform transform = null) : this(export) private Model(UObject export, ResolvedObject[] materials, FPackageIndex skeleton, int numLods, CBaseMeshLod lod, CMeshVertex[] vertices, Transform transform = null) : this(export)
{ {
var t = transform ?? Transform.Identity;
var hasCustomUvs = lod.ExtraUV.IsValueCreated; var hasCustomUvs = lod.ExtraUV.IsValueCreated;
UvCount = hasCustomUvs ? Math.Max(lod.NumTexCoords, numLods) : lod.NumTexCoords; UvCount = hasCustomUvs ? Math.Max(lod.NumTexCoords, numLods) : lod.NumTexCoords;
TwoSided = lod.IsTwoSided; TwoSided = lod.IsTwoSided;
@ -124,7 +125,7 @@ public class Model : IDisposable
if (skeleton != null) if (skeleton != null)
{ {
Skeleton = new Skeleton(skeleton); Skeleton = new Skeleton(skeleton, t);
VertexSize += 8; // + BoneIds + BoneWeights VertexSize += 8; // + BoneIds + BoneWeights
} }
@ -186,7 +187,7 @@ public class Model : IDisposable
if (section.IsValid) Sections[s].SetupMaterial(Materials[section.MaterialIndex]); if (section.IsValid) Sections[s].SetupMaterial(Materials[section.MaterialIndex]);
} }
AddInstance(transform ?? Transform.Identity); AddInstance(t);
} }
public void AddInstance(Transform transform) public void AddInstance(Transform transform)
@ -195,6 +196,13 @@ public class Model : IDisposable
Transforms.Add(transform); Transforms.Add(transform);
} }
public void UpdateMatrix() => UpdateMatrix(SelectedInstance);
public void UpdateMatrix(Transform transform) => UpdateMatrix(SelectedInstance, transform);
public void UpdateMatrix(int instance, Transform transform)
{
Transforms[instance] = transform;
UpdateMatrix(instance);
}
public void UpdateMatrix(int instance) public void UpdateMatrix(int instance)
{ {
_matrixVbo.Bind(); _matrixVbo.Bind();
@ -304,7 +312,7 @@ public class Model : IDisposable
if (outline) GL.Enable(EnableCap.DepthTest); if (outline) GL.Enable(EnableCap.DepthTest);
} }
public void SimpleRender(Shader shader) public void PickingRender(Shader shader)
{ {
if (TwoSided) GL.Disable(EnableCap.CullFace); if (TwoSided) GL.Disable(EnableCap.CullFace);

View File

@ -1,5 +1,6 @@
using System; using System;
using CUE4Parse.UE4.Assets.Exports.SkeletalMesh; using CUE4Parse.UE4.Assets.Exports.SkeletalMesh;
using CUE4Parse.UE4.Objects.Core.Misc;
namespace FModel.Views.Snooper.Models; namespace FModel.Views.Snooper.Models;
@ -9,6 +10,8 @@ public class Socket : IDisposable
public readonly string Bone; public readonly string Bone;
public readonly Transform Transform; public readonly Transform Transform;
public FGuid AttachedModel;
public Socket(USkeletalMeshSocket socket) public Socket(USkeletalMeshSocket socket)
{ {
Name = socket.SocketName.Text; Name = socket.SocketName.Text;

View File

@ -7,6 +7,7 @@ using ImGuiNET;
using OpenTK.Windowing.Common; using OpenTK.Windowing.Common;
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
using CUE4Parse.UE4.Objects.Core.Math;
using FModel.Settings; using FModel.Settings;
using FModel.Views.Snooper.Models; using FModel.Views.Snooper.Models;
using FModel.Views.Snooper.Shading; using FModel.Views.Snooper.Shading;
@ -402,14 +403,18 @@ Snooper aims to give an accurate preview of models, materials, skeletal animatio
foreach (var socket in model.Skeleton.Sockets) foreach (var socket in model.Skeleton.Sockets)
{ {
ImGui.PushID(i); ImGui.PushID(i);
ImGui.Text($"{socket.Name} attached to {socket.Bone}"); ImGui.Text($"'{socket.Name}' attached to '{socket.Bone}'");
ImGui.Text($"P: {socket.Transform.Matrix.M41} | {socket.Transform.Matrix.M42} | {socket.Transform.Matrix.M43}"); ImGui.Text($"P: {socket.Transform.Matrix.Translation.X} | {socket.Transform.Matrix.Translation.Y} | {socket.Transform.Matrix.Translation.Z}");
// ImGui.Text($"R: {socket.Transform.Rotation}");
// ImGui.Text($"S: {socket.Transform.Scale}");
if (ImGui.Button("Attach") && s.Renderer.Options.TryGetModel(out var selected)) if (ImGui.Button("Attach") && s.Renderer.Options.TryGetModel(out var selected))
{ {
selected.Transforms[selected.SelectedInstance] = socket.Transform; socket.AttachedModel = s.Renderer.Options.SelectedModel;
selected.UpdateMatrix(selected.SelectedInstance); selected.UpdateMatrix(new Transform
{
Relation = socket.Transform.Matrix,
Position = FVector.ZeroVector,
Rotation = new FQuat(0),
Scale = FVector.OneVector
});
} }
ImGui.PopID(); ImGui.PopID();
i++; i++;
@ -527,7 +532,8 @@ Snooper aims to give an accurate preview of models, materials, skeletal animatio
ImGui.EndDisabled(); ImGui.PopID(); ImGui.EndDisabled(); ImGui.PopID();
model.Transforms[model.SelectedInstance].ImGuiTransform(s.Renderer.CameraOp.Speed / 100f); model.Transforms[model.SelectedInstance].ImGuiTransform(s.Renderer.CameraOp.Speed / 100f);
model.UpdateMatrix(model.SelectedInstance); model.UpdateMatrix();
ImGui.EndTabItem(); ImGui.EndTabItem();
} }

View File

@ -18,18 +18,17 @@ public class Transform
public Matrix4x4 Matrix => public Matrix4x4 Matrix =>
Matrix4x4.CreateScale(Scale.X, Scale.Z, Scale.Y) * Matrix4x4.CreateScale(Scale.X, Scale.Z, Scale.Y) *
Matrix4x4.CreateFromQuaternion(new Quaternion(Rotation.X, Rotation.Z, Rotation.Y, -Rotation.W)) * Matrix4x4.CreateFromQuaternion(Quaternion.Normalize(new Quaternion(Rotation.X, Rotation.Z, Rotation.Y, -Rotation.W))) *
Matrix4x4.CreateTranslation(Position.X, Position.Z, Position.Y) Matrix4x4.CreateTranslation(Position.X, Position.Z, Position.Y)
* Relation; * Relation;
public void ImGuiTransform(float speed) public void ImGuiTransform(float speed)
{ {
const int width = 100; const float width = 100f;
ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); ImGui.SetNextItemOpen(true, ImGuiCond.Appearing);
if (ImGui.TreeNode("Location")) if (ImGui.TreeNode("Location"))
{ {
ImGui.PushID(1);
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("X", ref Position.X, speed, 0f, 0f, "%.2f m"); ImGui.DragFloat("X", ref Position.X, speed, 0f, 0f, "%.2f m");
@ -39,33 +38,29 @@ public class Transform
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Z", ref Position.Y, speed, 0f, 0f, "%.2f m"); ImGui.DragFloat("Z", ref Position.Y, speed, 0f, 0f, "%.2f m");
ImGui.PopID();
ImGui.TreePop(); ImGui.TreePop();
} }
ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); ImGui.SetNextItemOpen(true, ImGuiCond.Appearing);
if (ImGui.TreeNode("Rotation")) if (ImGui.TreeNode("Rotation"))
{ {
ImGui.PushID(2);
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("X", ref Rotation.X, .5f, 0f, 0f, "%.1f°"); ImGui.DragFloat("W", ref Rotation.W, .005f, 0f, 0f, "%.3f rad");
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Y", ref Rotation.Z, .5f, 0f, 0f, "%.1f°"); ImGui.DragFloat("X", ref Rotation.X, .005f, 0f, 0f, "%.3f rad");
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Z", ref Rotation.Y, .5f, 0f, 0f, "%.1f°"); ImGui.DragFloat("Y", ref Rotation.Z, .005f, 0f, 0f, "%.3f rad");
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("W", ref Rotation.W, .5f, 0f, 0f, "%.1f°"); ImGui.DragFloat("Z", ref Rotation.Y, .005f, 0f, 0f, "%.3f rad");
ImGui.PopID();
ImGui.TreePop(); ImGui.TreePop();
} }
if (ImGui.TreeNode("Scale")) if (ImGui.TreeNode("Scale"))
{ {
ImGui.PushID(3);
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("X", ref Scale.X, speed, 0f, 0f, "%.3f"); ImGui.DragFloat("X", ref Scale.X, speed, 0f, 0f, "%.3f");
@ -75,7 +70,6 @@ public class Transform
ImGui.SetNextItemWidth(width); ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Z", ref Scale.Y, speed, 0f, 0f, "%.3f"); ImGui.DragFloat("Z", ref Scale.Y, speed, 0f, 0f, "%.3f");
ImGui.PopID();
ImGui.TreePop(); ImGui.TreePop();
} }
} }