Skip to content

Commit

Permalink
IsAttachment
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Jan 9, 2023
1 parent 8d986c4 commit 835d5f9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 48 deletions.
1 change: 1 addition & 0 deletions FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Binary file added FModel/Resources/link_has.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions FModel/Views/Snooper/Models/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -271,18 +276,18 @@ public void UpdateMorph(int index)

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;
}

Expand Down
1 change: 1 addition & 0 deletions FModel/Views/Snooper/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public Options()
["spotlight"] = new ("spotlight"),
["link_on"] = new ("link_on"),
["link_off"] = new ("link_off"),
["link_has"] = new ("link_has"),
};

_platform = UserSettings.Default.OverridedPlatform;
Expand Down
70 changes: 29 additions & 41 deletions FModel/Views/Snooper/SnimGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void Render(Snooper s)

// Window("Timeline", () => {});
Window("World", () => DrawWorld(s), false);
Window("Sockets", () => DrawSockets(s));

DrawSockets(s);
DrawOuliner(s);
DrawDetails(s);
Draw3DViewport(s);
Expand Down Expand Up @@ -316,7 +316,9 @@ private void DrawOuliner(Snooper s)
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"));
Expand Down Expand Up @@ -360,8 +362,8 @@ private void DrawOuliner(Snooper s)
});
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++;
Expand Down Expand Up @@ -399,50 +401,36 @@ private void DrawOuliner(Snooper s)

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)
Expand Down

0 comments on commit 835d5f9

Please sign in to comment.