Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Version numbers follow `MAJOR.MINOR.PATCH`; the 0.x series is under active devel

## 0.12.1 — Unreleased

- AI networks in RECOIL and MW3 use clickable circular node markers and directed triangles.

- zStudio is built on .NET 11 (included in `zStudio.exe`; nothing to install).

## 0.12.0 — 2026-11-08
Expand Down
93 changes: 73 additions & 20 deletions src/zStudio.Rendering/SceneViewport.Ai.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ private sealed class AiOverlayGroup : GroupNode;
/// <summary>The network a selection emphasises (the others are drawn faint), or null.</summary>
public string? AiEmphasizedNetwork { get; private set; }
public string? SelectedAiNode { get; private set; }
private IReadOnlyDictionary<string, bool>? valveRouteStates;
public void SetValveRouteStates(IReadOnlyDictionary<string, bool>? states)
{
if (states == null && valveRouteStates == null || states != null && valveRouteStates != null && states.Count == valveRouteStates.Count &&
states.All(p => valveRouteStates.TryGetValue(p.Key, out bool value) && value == p.Value)) return;
valveRouteStates = states; RebuildAiOverlay();
}
public event Action<string?>? AiNodeSelected;
public event Action? AiPropertiesRequested;
public event Action<string?>? AiLabelChanged;
Expand All @@ -43,6 +50,7 @@ public void SetAiNetworks(AiNetworkSnapshot snapshot)
{
if (AiNetworks.Id == snapshot.Id) return;
SetAiPathEditing(null);
valveRouteStates = null;
AiNetworks = snapshot; AiNetworkFilter = null; SelectedAiNode = null; hoveredAiNode = null; ValveFilter = null;
RebuildAiOverlay();
}
Expand Down Expand Up @@ -98,37 +106,60 @@ private void RebuildAiOverlay()
if (nodes.Length < network.Nodes.Count) AiRenderTruncated = true;
if (nodes.Length == 0) continue;
RenderedAiNodes += nodes.Length; aiRendered.AddRange(nodes);
var markers = AiMesh(AiOctahedron(), color);
aiMarkers.Add((markers, nodes, strong ? 5 : 4));
var markers = AiMesh(AiCircle(), color);
aiMarkers.Add((markers, nodes, strong ? 7 : 6));
var byId = nodes.ToDictionary(n => n.Id);
List<(AiNode Start, AiNode End)> edges = [];
List<(AiNode Start, AiNode End, int Slot)> edges = [];
foreach (var node in nodes)
foreach (string target in node.PreviewLinks.Where(l => l.Target != null).Select(l => l.Target!).Distinct())
foreach (var link in node.PreviewLinks.Where(l => l.Target != null))
{
if (!byId.TryGetValue(target, out var end)) { AiRenderTruncated = true; continue; }
if (!byId.TryGetValue(link.Target!, out var end)) { AiRenderTruncated = true; continue; }
if (RenderedAiLinks == MaximumRenderedAiLinks) { AiRenderTruncated = true; break; }
edges.Add((node, end)); RenderedAiLinks++;
edges.Add((node, end, link.Slot)); RenderedAiLinks++;
}
var lines = AiMesh(BuildLinks(false), color); aiLinks.Add(lines, () => BuildLinks(false));
if (valveRouteStates != null)
{
var blocked = AiMesh(BuildLinks(true), new(color.Red, color.Green, color.Blue, color.Alpha * .35f));
aiLinks.Add(blocked, () => BuildLinks(true));
}
var lines = AiMesh(BuildLinks(), color); aiLinks.Add(lines, BuildLinks);
MeshData BuildLinks()
MeshData BuildLinks(bool blockedOnly)
{
List<Vector3> positions = []; List<int> indices = [];
var pose = CaptureView(); Vector3 forward = Vector3.Normalize(new((float)pose.LookDirection.X, (float)pose.LookDirection.Y, (float)pose.LookDirection.Z));
foreach (var (startNode, endNode) in edges)
foreach (var (startNode, endNode, slot) in edges)
{
bool blocked = valveRouteStates?.GetValueOrDefault(startNode.Id + "|" + slot, true) == false;
if (blocked != blockedOnly) continue;
var start = AiPosition(startNode); var end = AiPosition(endNode);
if ((end - start).LengthSquared() < 1e-8f)
{
const int steps = 16; float radius = 3;
int occurrence = startNode.PreviewLinks.Count(l => l.Slot < slot && l.Target == endNode.Id);
const int steps = 24; float radius = AiScale(start, 12 + occurrence * 12);
var up = Vector3.Normalize(new((float)pose.UpDirection.X, (float)pose.UpDirection.Y, (float)pose.UpDirection.Z));
var right = Vector3.Normalize(Vector3.Cross(forward, up)); up = Vector3.Cross(right, forward);
if (string.CompareOrdinal(startNode.Id, endNode.Id) > 0) right = -right;
for (int i = 0; i < steps; i++)
{
var a = start + new Vector3(radius + radius * MathF.Cos(MathF.PI + i * MathF.Tau / steps), 0, radius * MathF.Sin(MathF.PI + i * MathF.Tau / steps));
var b = start + new Vector3(radius + radius * MathF.Cos(MathF.PI + (i + 1) * MathF.Tau / steps), 0, radius * MathF.Sin(MathF.PI + (i + 1) * MathF.Tau / steps));
Segment(a, b);
if (i == 11) Arrow(a, b, 1.4f);
var a = start + right * (radius + radius * MathF.Cos(MathF.PI + i * MathF.Tau / steps)) + up * (radius * MathF.Sin(MathF.PI + i * MathF.Tau / steps));
var b = start + right * (radius + radius * MathF.Cos(MathF.PI + (i + 1) * MathF.Tau / steps)) + up * (radius * MathF.Sin(MathF.PI + (i + 1) * MathF.Tau / steps));
if (!blocked || i % 4 < 2) Segment(a, b);
if (i == 11) Arrow(a, b, AiScale(a, 9));
}
}
else
{
// Reciprocal directions lie on opposite sides; each remains visible.
int occurrence = startNode.PreviewLinks.Count(l => l.Slot < slot && l.Target == endNode.Id);
var offset = Side(Vector3.Normalize(end - start)) * AiScale(Vector3.Lerp(start, end, .5f), 6 + occurrence * 12);
if (blocked)
{
for (int dash = 0; dash < 12; dash += 2)
Segment(Vector3.Lerp(start, end, dash / 12f) + offset, Vector3.Lerp(start, end, (dash + 1) / 12f) + offset);
}
else Segment(start + offset, end + offset);
Arrow(start + offset, end + offset, (end - start).Length() * .18f);
}
else { Segment(start, end); Arrow(start, end, (end - start).Length() * .18f); }
}
return new([.. positions], [.. indices], [.. positions.Select(_ => Vector3.UnitY)]);
Vector3 Side(Vector3 direction)
Expand All @@ -153,7 +184,7 @@ void Arrow(Vector3 from, Vector3 to, float size)
}
}
BuildValveOverlay();
aiSelectionMarker = AiMesh(AiOctahedron(), new(1, 1, 1, 1), twin: false);
aiSelectionMarker = AiMesh(AiCircle(), new(1, 1, 1, 1), twin: false);
RefreshAiSelection(); UpdateAiMarkers(); view.InvalidateRender();
}
/// <summary>How strongly the overlay shows through geometry that hides it.</summary>
Expand Down Expand Up @@ -182,6 +213,28 @@ MeshNode Mesh(Color4 tint, bool through)
[Vector3.UnitX, -Vector3.UnitX, Vector3.UnitY, -Vector3.UnitY, Vector3.UnitZ, -Vector3.UnitZ],
[0, 2, 4, 4, 2, 1, 1, 2, 5, 5, 2, 0, 0, 4, 3, 4, 1, 3, 1, 5, 3, 5, 0, 3],
[Vector3.UnitX, -Vector3.UnitX, Vector3.UnitY, -Vector3.UnitY, Vector3.UnitZ, -Vector3.UnitZ]);
private static MeshData AiCircle()
{
const int segments = 32;
List<Vector3> p = []; List<int> indices = [];
for (int i = 0; i < segments; i++)
{
float a = i * MathF.Tau / segments, b = (i + 1) * MathF.Tau / segments;
var x = new Vector3(MathF.Cos(a), MathF.Sin(a), 0); var y = new Vector3(MathF.Cos(b), MathF.Sin(b), 0);
int n = p.Count; p.AddRange([x, y, y * .65f, x * .65f]);
indices.AddRange([n, n + 1, n + 2, n, n + 2, n + 3]);
}
return new([.. p], [.. indices], [.. p.Select(_ => Vector3.UnitZ)]);
}
private Matrix4x4 AiMarkerTransform(Vector3 point, double radius)
{
var pose = CaptureView();
var forward = Vector3.Normalize(new((float)pose.LookDirection.X, (float)pose.LookDirection.Y, (float)pose.LookDirection.Z));
var up = Vector3.Normalize(new((float)pose.UpDirection.X, (float)pose.UpDirection.Y, (float)pose.UpDirection.Z));
var right = Vector3.Normalize(Vector3.Cross(forward, up)); up = Vector3.Cross(right, forward);
var basis = new Matrix4x4(right.X, right.Y, right.Z, 0, up.X, up.Y, up.Z, 0, -forward.X, -forward.Y, -forward.Z, 0, 0, 0, 0, 1);
return Matrix4x4.CreateScale(AiScale(point, radius)) * basis * Matrix4x4.CreateTranslation(point);
}
private float AiScale(Vector3 point, double pixels)
{
var pose = CaptureView(); var forward = pose.LookDirection; forward.Normalize();
Expand All @@ -197,7 +250,7 @@ private void UpdateAiMarkers()
aiMarkerPose = pose; aiMarkerWidth = viewport.ActualWidth; aiMarkerHeight = viewport.ActualHeight;
foreach (var (mesh, nodes, pixels) in aiMarkers)
{
var instances = nodes.Select(n => Matrix4x4.CreateScale(AiScale(AiPosition(n), pixels)) * Matrix4x4.CreateTranslation(AiPosition(n))).ToArray();
var instances = nodes.Select(n => AiMarkerTransform(AiPosition(n), pixels)).ToArray();
mesh.Instances = instances;
if (aiBehind.TryGetValue(mesh, out var behind)) behind.Instances = instances;
}
Expand All @@ -217,13 +270,13 @@ private void RefreshAiSelection()
{
aiSelectionMarker.Visibility = PlacementEditingEnabled && aiPathSelection.Count != 0 ? Visibility.Visible : Visibility.Collapsed;
aiSelectionMarker.Instances = AiNetworks.Networks.Single(n => n.Id == network).Nodes.Where(n => aiPathSelection.Contains(n.Id))
.Select(n => Matrix4x4.CreateScale(AiScale(AiPosition(n), 5.5)) * Matrix4x4.CreateTranslation(AiPosition(n))).ToArray();
.Select(n => AiMarkerTransform(AiPosition(n), 8)).ToArray();
}
else
{
var selected = SelectedAiNode == null ? null : AiNetworks.Find(SelectedAiNode);
aiSelectionMarker.Visibility = selected == null ? Visibility.Collapsed : Visibility.Visible;
if (selected is { } target) aiSelectionMarker.Instances = [Matrix4x4.CreateScale(AiScale(target.Node.Position, 5.5)) * Matrix4x4.CreateTranslation(target.Node.Position)];
if (selected is { } target) aiSelectionMarker.Instances = [AiMarkerTransform(target.Node.Position, 8)];
}
}
PublishAiLabel(); view.InvalidateRender();
Expand Down Expand Up @@ -257,7 +310,7 @@ private bool TryProjectAiNode(AiNode node, out Point screen, out double depth)
var position = AiPosition(node); var pose = CaptureView(); var forward = pose.LookDirection; forward.Normalize();
Point3D point = new(position.X, position.Y, position.Z);
depth = Vector3D.DotProduct(point - pose.Position, forward);
if (!double.IsFinite(depth) || depth <= 0) return false;
if (!double.IsFinite(depth) || pose.Projection != "orthographic" && depth <= 0) return false;
screen = view.Project(point);
if (!double.IsFinite(screen.X) || !double.IsFinite(screen.Y) || !IsInsidePickupViewport(screen)) return false;
return AiThroughGeometry || view.Camera is not RenderCamera camera || depth >= camera.NearPlaneDistance && depth <= camera.FarPlaneDistance;
Expand Down
5 changes: 3 additions & 2 deletions src/zStudio.Rendering/SceneViewport.Inspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void RegisterInspectionMesh(MeshNode mesh, int material, long? runtime =
}
private SceneInspection? InspectAi(string id)
{
if (!AiVisible || AiNetworks.Find(id) is not { } item || AiNetworkFilter != null && item.Network.Id != AiNetworkFilter) return null;
if (!AiVisible || AiNetworks.Find(id) is not { } item || AiNetworkFilter != null && item.Network.Id != AiNetworkFilter || aiHiddenNetworks.Contains(item.Network.Id)) return null;
return new("ai:" + AiNetworks.Id + ":" + id, -1, -1, -1, null, id, null, null, item.Node.Position, true, null);
}
private SceneInspection? InspectHit(RenderHit hit)
Expand Down Expand Up @@ -144,10 +144,11 @@ public bool SelectInspection(string? target, bool guard = true, int? exactNode =
{
var next = target == null ? null : InspectTarget(target);
if (target != null && next == null || IsFlyActive || IsPickupDragging || guard && CanChangeInspection?.Invoke() == false) return false;
// AI admission can also refuse path-edit mode or a pending draft. Publish only after it succeeds.
if (next?.AiNode is { } ai) return SelectAiNode(ai);
if (next != null && exactNode is int exact) next = next with { OwnerNode = exact, ExactSelection = true };
SelectedInspection = next;
if (next == null) { SelectAiNode(null); SelectPickup(null); FramingSelection = null; InspectionSelectionCleared?.Invoke(); }
else if (next.AiNode is { } ai) SelectAiNode(ai);
else if (next is { Node: >= 0 } node) { SelectFramingNode(PickupAt(node.SelectionNode)?.Root ?? node.SelectionNode); NodeSelected?.Invoke(node.SelectionNode); }
RefreshPickupSelection(); InspectionChanged?.Invoke(); return true;
}
Expand Down
8 changes: 6 additions & 2 deletions src/zStudio.Rendering/SceneViewport.Pickups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ private ScenePlacement AdjustPickupPlacement(ScenePlacement p)
private void RefreshPickupSelection()
{
if (selectionBox == null || pickupManipulator == null || pickupTarget == null) return;
// AI nodes own a camera-facing selection ring; a world-space box hides its rim.
if (SelectedInspection?.AiNode != null)
{
selectionBox.Visibility = pickupManipulator.Visibility = Visibility.Collapsed;
pickupManipulator.Target = null; SetPickupHover(false); return;
}
bool selected = worldInspection && SelectedInspection is { Active: true };
selectionBox.Visibility = selected ? Visibility.Visible : Visibility.Collapsed;
pickupManipulator.Visibility = CanManipulate ? Visibility.Visible : Visibility.Collapsed;
Expand All @@ -216,8 +222,6 @@ private void RefreshPickupSelection()
}
var selectionFrame = SelectionBoundsFrame(selectedNodes);
var inverseFrame = selectionFrame; inverseFrame.Invert();
if (SelectedInspection?.AiNode is { } ai && AiNetworks.Find(ai) is { } node)
{ float radius = AiScale(node.Node.Position, 5.5); min = node.Node.Position - new Vector3(radius); max = node.Node.Position + new Vector3(radius); }
long selectedRuntimeOwner = (SelectedInspection?.RuntimeInstance ?? 0) >> 32;
foreach (var (mesh, items) in visiblePlacements)
{
Expand Down
9 changes: 8 additions & 1 deletion tests/zStudio.Desktop.Tests/SceneInspectionMcpChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ internal static async Task Run()
await Call("ai_selection", new() { ["preview"] = preview, ["snapshot"] = graph.Id, ["action"] = "select", ["node"] = aiId });
Assert.Equal(aiId, viewport.SelectedAiNode); Assert.NotNull(viewport.SelectedInspection);
await Card("select", new() { ["target"] = target });
Assert.True(viewport.SelectionBoundsVisible); Assert.False(viewport.TransformHandlesVisible);
// AI selection uses the circular marker (verified by presented pixels in AiNetworkCheck), not a world box.
Assert.False(viewport.SelectionBoundsVisible); Assert.False(viewport.TransformHandlesVisible);
var inspectionCard = (SceneInspectionCard)viewport.InspectionContent!;
inspectionCard.Measure(new(800, 600)); inspectionCard.Arrange(new Rect(0, 0, 800, 600)); inspectionCard.UpdateLayout();
var panel = (Border)typeof(SceneInspectionCard).GetField("panel", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(inspectionCard)!;
Expand Down Expand Up @@ -150,6 +151,12 @@ internal static async Task Run()
Assert.DoesNotContain(strategyReadout, Fields(inspectionCard));
Assert.Null((await Call("scene_inspect", new() { ["preview"] = preview }))["attackStrategy"]);
Assert.True(viewport.SelectionBoundsVisible); Assert.False(viewport.TransformHandlesVisible);
// A retained target must not resurrect a hidden AI card or replace the current pickup selection.
var beforeHiddenTarget = viewport.SelectedInspection;
viewport.SetAiNetworkPresentation(new HashSet<string> { graph.Networks[0].Id }, null);
await Card("select", new() { ["target"] = target }, "stale_record");
Assert.Same(beforeHiddenTarget, viewport.SelectedInspection); Assert.Null(viewport.SelectedAiNode);
viewport.SetAiNetworkPresentation(new HashSet<string>(), null);
var box = viewport.SelectionBox!;
AssertSelectionBox(ownerTransform, new(-2, 0, 0), new(9, 3, 0));
// The same two parts can belong to a reconstructed synthetic owner.
Expand Down
Loading