mirror of
https://github.com/4sval/FModel.git
synced 2026-03-21 17:24:26 -05:00
socket support for instanced models
This commit is contained in:
parent
4eb220168e
commit
0db81b8456
|
|
@ -248,6 +248,7 @@ public class Model : IDisposable
|
|||
|
||||
public void AddInstance(Transform transform)
|
||||
{
|
||||
SelectedInstance = TransformsCount;
|
||||
TransformsCount++;
|
||||
Transforms.Add(transform);
|
||||
}
|
||||
|
|
@ -262,27 +263,30 @@ public class Model : IDisposable
|
|||
boneMatrix = Skeleton.GetBoneMatrix(boneIndices);
|
||||
|
||||
var socketRelation = boneMatrix * worldMatrix;
|
||||
foreach (var attached in socket.AttachedModels)
|
||||
foreach (var info in socket.AttachedModels)
|
||||
{
|
||||
if (!options.TryGetModel(attached, out var attachedModel))
|
||||
if (!options.TryGetModel(info.Guid, out var attachedModel))
|
||||
continue;
|
||||
|
||||
attachedModel.Transforms[attachedModel.SelectedInstance].Relation = socket.Transform.LocalMatrix * socketRelation;
|
||||
attachedModel.Transforms[info.Instance].Relation = socket.Transform.LocalMatrix * socketRelation;
|
||||
attachedModel.UpdateMatrices(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Matrix4x4 UpdateMatrices()
|
||||
{
|
||||
var matrix = Transforms[SelectedInstance].Matrix;
|
||||
if (matrix == _previousMatrix) return matrix;
|
||||
for (int instance = 0; instance < TransformsCount; instance++)
|
||||
{
|
||||
var matrix = Transforms[instance].Matrix;
|
||||
if (matrix == _previousMatrix) return matrix;
|
||||
|
||||
_matrixVbo.Bind();
|
||||
_matrixVbo.Update(SelectedInstance, matrix);
|
||||
_matrixVbo.Unbind();
|
||||
_matrixVbo.Bind();
|
||||
_matrixVbo.Update(instance, matrix);
|
||||
_matrixVbo.Unbind();
|
||||
|
||||
_previousMatrix = matrix;
|
||||
return matrix;
|
||||
_previousMatrix = matrix;
|
||||
}
|
||||
return _previousMatrix;
|
||||
}
|
||||
|
||||
public void UpdateMorph(int index)
|
||||
|
|
@ -294,7 +298,7 @@ public class Model : IDisposable
|
|||
|
||||
public void AttachModel(Model attachedTo, Socket socket)
|
||||
{
|
||||
socket.AttachedModels.Add(Guid);
|
||||
socket.AttachedModels.Add(new SocketAttachementInfo { Guid = Guid, Instance = SelectedInstance });
|
||||
|
||||
_attachedTo = $"'{socket.Name}' from '{attachedTo.Name}'{(!socket.BoneName.IsNone ? $" at '{socket.BoneName}'" : "")}";
|
||||
attachedTo._attachedFor.Add($"'{Name}'");
|
||||
|
|
@ -306,7 +310,7 @@ public class Model : IDisposable
|
|||
|
||||
public void DetachModel(Model attachedTo, Socket socket)
|
||||
{
|
||||
socket.AttachedModels.Remove(Guid);
|
||||
socket.AttachedModels.Remove(new SocketAttachementInfo { Guid = Guid, Instance = SelectedInstance });
|
||||
SafeDetachModel(attachedTo);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,18 +7,24 @@ using CUE4Parse.UE4.Objects.UObject;
|
|||
|
||||
namespace FModel.Views.Snooper.Models;
|
||||
|
||||
public struct SocketAttachementInfo
|
||||
{
|
||||
public FGuid Guid;
|
||||
public int Instance;
|
||||
}
|
||||
|
||||
public class Socket : IDisposable
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly FName BoneName;
|
||||
public readonly Transform Transform;
|
||||
|
||||
public readonly List<FGuid> AttachedModels;
|
||||
public readonly List<SocketAttachementInfo> AttachedModels;
|
||||
|
||||
private Socket()
|
||||
{
|
||||
Transform = Transform.Identity;
|
||||
AttachedModels = new List<FGuid>();
|
||||
AttachedModels = new List<SocketAttachementInfo>();
|
||||
}
|
||||
|
||||
public Socket(string name, FName boneName, Transform transform) : this()
|
||||
|
|
|
|||
|
|
@ -107,12 +107,12 @@ public class Options
|
|||
{
|
||||
foreach (var socket in model.Sockets)
|
||||
{
|
||||
foreach (var guid in socket.AttachedModels)
|
||||
foreach (var info in socket.AttachedModels)
|
||||
{
|
||||
if (!TryGetModel(guid, out var attachedModel)) continue;
|
||||
if (!TryGetModel(info.Guid, out var attachedModel)) continue;
|
||||
|
||||
attachedModel.SafeDetachModel(model);
|
||||
RemoveModel(guid);
|
||||
RemoveModel(info.Guid);
|
||||
}
|
||||
socket.Dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ public class Renderer : IDisposable
|
|||
if (Options.TryGetModel(guid, out var model))
|
||||
{
|
||||
model.AddInstance(Transform.Identity);
|
||||
Application.Current.Dispatcher.Invoke(() => model.SetupInstances());
|
||||
if (select) Application.Current.Dispatcher.Invoke(() => model.SetupInstances());
|
||||
return guid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ Snooper aims to give an accurate preview of models, materials, skeletal animatio
|
|||
var i = 0;
|
||||
foreach (var socket in model.Sockets)
|
||||
{
|
||||
var isAttached = socket.AttachedModels.Contains(selectedModel.Guid);
|
||||
var isAttached = socket.AttachedModels.Contains(new SocketAttachementInfo { Guid = selectedModel.Guid, Instance = selectedModel.SelectedInstance });
|
||||
ImGui.PushID(i);
|
||||
ImGui.BeginDisabled(selectedModel.IsAttached && !isAttached);
|
||||
switch (isAttached)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user