IsAttachment

This commit is contained in:
4sval 2023-01-09 19:53:28 +01:00
parent 8d986c4dc6
commit 835d5f9d40
5 changed files with 43 additions and 48 deletions

View File

@ -229,6 +229,7 @@
<Resource Include="Resources\spotlight.png" />
<Resource Include="Resources\link_on.png" />
<Resource Include="Resources\link_off.png" />
<Resource Include="Resources\link_has.png" />
</ItemGroup>
<ItemGroup>

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

View File

@ -54,8 +54,13 @@ public class Model : IDisposable
public bool HasSockets => Sockets.Length > 0;
public readonly Socket[] Sockets;
public bool IsAttached { get; private set; }
public string AttachedTo { get; private set; }
private string _attachedTo = string.Empty;
private readonly List<string> _attachedFor = new ();
public bool IsAttached => _attachedTo.Length > 0;
public bool IsAttachment => _attachedFor.Count > 0;
public string AttachIcon => IsAttachment ? "link_has" : IsAttached ? "link_on" : "link_off";
public string AttachTooltip => IsAttachment ? $"Is Attachment For:\n{string.Join("\n", _attachedFor)}" : IsAttached ? $"Is Attached To {_attachedTo}" : "Not Attached To Any Socket Nor Attachment For Any Model";
public int TransformsCount;
public readonly List<Transform> Transforms;
@ -271,18 +276,18 @@ public class Model : IDisposable
public void AttachModel(Model attachedTo, Socket socket)
{
IsAttached = true;
AttachedTo = $"'{socket.Name}' from '{attachedTo.Name}'{(socket.Bone.HasValue ? $" at '{socket.Bone}'" : "")}";
_attachedTo = $"'{socket.Name}' from '{attachedTo.Name}'{(socket.Bone.HasValue ? $" at '{socket.Bone}'" : "")}";
attachedTo._attachedFor.Add($"'{Name}'");
// reset PRS to 0 so it's attached to the actual position (can be transformed relative to the socket later by the user)
Transforms[SelectedInstance].Position = FVector.ZeroVector;
Transforms[SelectedInstance].Rotation = FQuat.Identity;
Transforms[SelectedInstance].Scale = FVector.OneVector;
}
public void DetachModel()
public void DetachModel(Model attachedTo)
{
IsAttached = false;
AttachedTo = null;
_attachedTo = string.Empty;
attachedTo._attachedFor.Remove($"'{Name}'");
Transforms[SelectedInstance].Relation = _previousMatrix;
}

View File

@ -38,6 +38,7 @@ public class Options
["spotlight"] = new ("spotlight"),
["link_on"] = new ("link_on"),
["link_off"] = new ("link_off"),
["link_has"] = new ("link_has"),
};
_platform = UserSettings.Default.OverridedPlatform;

View File

@ -74,8 +74,8 @@ public class SnimGui
// Window("Timeline", () => {});
Window("World", () => DrawWorld(s), false);
Window("Sockets", () => DrawSockets(s));
DrawSockets(s);
DrawOuliner(s);
DrawDetails(s);
Draw3DViewport(s);
@ -316,7 +316,9 @@ Snooper aims to give an accurate preview of models, materials, skeletal animatio
ImGui.TableNextColumn();
if (!model.Show)
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg0, ImGui.GetColorU32(new Vector4(1, 0, 0, .5f)));
if (model.IsAttached)
else if (model.IsAttachment)
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg0, ImGui.GetColorU32(new Vector4(0, .75f, 0, .5f)));
else if (model.IsAttached)
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg0, ImGui.GetColorU32(new Vector4(1, 1, 0, .5f)));
ImGui.Text(model.TransformsCount.ToString("D"));
@ -360,8 +362,8 @@ Snooper aims to give an accurate preview of models, materials, skeletal animatio
});
ImGui.TableNextColumn();
ImGui.Image(s.Renderer.Options.Icons[model.IsAttached ? "link_on" : "link_off"].GetPointer(), new Vector2(_tableWidth));
if (model.IsAttached) TooltipCopy($"Attached To {model.AttachedTo}");
ImGui.Image(s.Renderer.Options.Icons[model.AttachIcon].GetPointer(), new Vector2(_tableWidth));
TooltipCopy(model.AttachTooltip);
ImGui.PopID();
i++;
@ -399,50 +401,36 @@ Snooper aims to give an accurate preview of models, materials, skeletal animatio
private void DrawSockets(Snooper s)
{
var selectedGuid = s.Renderer.Options.SelectedModel;
if (!s.Renderer.Options.TryGetModel(out var selectedModel))
return;
foreach (var model in s.Renderer.Options.Models.Values)
MeshWindow("Sockets", s.Renderer, (icons, selectedModel) =>
{
if (!model.HasSockets || model.IsSelected) continue;
if (ImGui.TreeNode($"{model.Name} [{model.Sockets.Length}]"))
var selectedGuid = s.Renderer.Options.SelectedModel;
foreach (var model in s.Renderer.Options.Models.Values)
{
var i = 0;
foreach (var socket in model.Sockets)
if (!model.HasSockets || model.IsSelected) continue;
if (ImGui.TreeNode($"{model.Name} [{model.Sockets.Length}]"))
{
ImGui.PushID(i);
switch (socket.AttachedModels.Contains(selectedGuid))
var i = 0;
foreach (var socket in model.Sockets)
{
case false when ImGui.Button($"Attach to '{socket.Name}'"):
socket.AttachedModels.Add(selectedGuid);
selectedModel.AttachModel(model, socket);
break;
case true when ImGui.Button($"Detach from '{socket.Name}'"):
socket.AttachedModels.Remove(selectedGuid);
selectedModel.DetachModel();
break;
ImGui.PushID(i);
switch (socket.AttachedModels.Contains(selectedGuid))
{
case false when ImGui.Button($"Attach to '{socket.Name}'"):
socket.AttachedModels.Add(selectedGuid);
selectedModel.AttachModel(model, socket);
break;
case true when ImGui.Button($"Detach from '{socket.Name}'"):
socket.AttachedModels.Remove(selectedGuid);
selectedModel.DetachModel(model);
break;
}
ImGui.PopID();
i++;
}
ImGui.PopID();
i++;
ImGui.TreePop();
}
ImGui.TreePop();
}
}
// if (ImGui.BeginTable("socket_editor", 2))
// {
// Layout("Models");
// ImGui.PushID(1);
// ImGui.Combo("", ref m, "Fly Cam\0Arcball\0");
// ImGui.PopID();
//
// Layout("Attach To");ImGui.PushID(2);
// ImGui.Combo("world_mode", ref m, "Fly Cam\0Arcball\0");
// ImGui.PopID();
//
// ImGui.EndTable();
// }
});
}
private void DrawDetails(Snooper s)