Add editor placement snapping and aspect lock
This commit is contained in:
parent
dfbc97872b
commit
e9b76f1724
7 changed files with 134 additions and 30 deletions
|
|
@ -301,7 +301,9 @@ a named invariant that the native runtime cannot protect yet.
|
|||
The center preview now asks Fensalir's CultUI preview contract to blit the
|
||||
current renderer output buffer behind Mimir's normalized placement overlays,
|
||||
so the app preview is a live program-surface witness rather than a symbolic
|
||||
rectangle diagram.
|
||||
rectangle diagram. Placement commits keep video layers inside the program
|
||||
frame, snap near edges/center, and preserve the source aspect ratio while
|
||||
resizing through sliders or the scale gizmo.
|
||||
See [[scene-editor-control-surface|Mimir Scene Editor Control Surface]].
|
||||
`Mimir.BufferSmoke --scene-editor-smoke` proves the graph/control/gizmo owner
|
||||
path. World SDF text glyph rendering, ASSIMP-style mesh import/upload, and
|
||||
|
|
|
|||
|
|
@ -546,7 +546,9 @@ the Fensalir camera plus derived spline outlines, selection handles, and the
|
|||
`Mimir Editor` hierarchy/transform panel. The center preview requests a
|
||||
Fensalir-owned blit of the current output buffer, then draws Mimir's normalized
|
||||
placement overlays on top. This editor is not the OBS program output authority;
|
||||
it is a live program-surface witness. World SDF glyph rendering, ASSIMP-style
|
||||
it is a live program-surface witness. The placement commit primitive keeps
|
||||
layers inside the program frame, snaps near edges/center, and preserves source
|
||||
aspect while resizing through sliders or the scale gizmo. World SDF glyph rendering, ASSIMP-style
|
||||
mesh decoding/upload, and pixel-accurate gizmo hit-testing are explicit
|
||||
Fensalir renderer cuts, mapped in
|
||||
[[docs/scene-editor-control-surface|Mimir Scene Editor Control Surface]].
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ Get-Content .\state\evidence.jsonl -Tail 8
|
|||
canvas, and a Unity-style Inspector on the right for the selected layer's
|
||||
properties. The center preview requests Fensalir's current output-buffer blit
|
||||
as its background and overlays Mimir's normalized layer placements on top.
|
||||
Placement commits snap near frame edges/center and preserve source aspect
|
||||
while resizing.
|
||||
Camera/SDF/model editor affordances have no live UI authority, and editor
|
||||
camera/SDF/spline output no longer contributes to the runtime frame. Smoke
|
||||
with `--scene-editor-smoke`.
|
||||
|
|
|
|||
|
|
@ -4227,6 +4227,15 @@ static int RunSceneEditorSmoke()
|
|||
editor.SetSelectedProgramY(0.45f);
|
||||
editor.SetSelectedProgramWidth(0.36f);
|
||||
editor.SetSelectedProgramHeight(0.28f);
|
||||
var aspectPlacement = editor.PlacementForSource("raven-display");
|
||||
var aspectLocked = aspectPlacement.HasValue &&
|
||||
Math.Abs(aspectPlacement.Value.Width - aspectPlacement.Value.Height) < 0.001f;
|
||||
editor.SetSelectedProgramX(0.006f);
|
||||
editor.SetSelectedProgramY(0.994f);
|
||||
var snappedPlacement = editor.PlacementForSource("raven-display");
|
||||
var snappedToBounds = snappedPlacement.HasValue &&
|
||||
Math.Abs(snappedPlacement.Value.CenterX - snappedPlacement.Value.Width * 0.5f) < 0.001f &&
|
||||
Math.Abs(snappedPlacement.Value.CenterY - (1.0f - snappedPlacement.Value.Height * 0.5f)) < 0.001f;
|
||||
editor.CenterSelectedProgramLayer();
|
||||
editor.MoveSelectedLayer(-1);
|
||||
|
||||
|
|
@ -4241,13 +4250,15 @@ static int RunSceneEditorSmoke()
|
|||
Console.WriteLine(
|
||||
$"scene-editor-smoke nodes={editor.Nodes.Count} feeds={editor.Nodes.Count(node => node.Kind == MimirSceneEditorNodeKind.SensorFeedPanel)} " +
|
||||
$"preview={previewItems.Count} selected={editor.SelectedNode?.DisplayName} hasDisplay={hasDisplay} cameraPreview={hasCameraPreview} " +
|
||||
$"placement={placement?.CenterX:0.000},{placement?.CenterY:0.000} programCentered={programCentered}");
|
||||
$"placement={placement?.CenterX:0.000},{placement?.CenterY:0.000} programCentered={programCentered} aspectLocked={aspectLocked} snapped={snappedToBounds}");
|
||||
|
||||
return editor.Nodes.Count == 3 &&
|
||||
hasDisplay &&
|
||||
hasOnlyVideoPreview &&
|
||||
!hasCameraPreview &&
|
||||
programCentered
|
||||
programCentered &&
|
||||
aspectLocked &&
|
||||
snappedToBounds
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ public sealed class MimirSceneEditorState
|
|||
{
|
||||
private const float ProgramWorldWidth = 12.8f;
|
||||
private const float ProgramWorldHeight = 7.2f;
|
||||
private const float ProgramAspect = ProgramWorldWidth / ProgramWorldHeight;
|
||||
private const float MinProgramExtent = 0.01f;
|
||||
private const float ProgramSnapThreshold = 0.015f;
|
||||
private readonly List<MimirSceneEditorNode> nodes = [];
|
||||
private readonly HashSet<string> configuredProgramSources = new(StringComparer.Ordinal);
|
||||
private bool selectedConfiguredSource;
|
||||
|
|
@ -97,6 +100,7 @@ public sealed class MimirSceneEditorState
|
|||
{
|
||||
Layer = index,
|
||||
SourceId = buffer.Descriptor.SourceId,
|
||||
ProgramAspectRatio = ProgramAspectRatioFor(buffer),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +307,7 @@ public sealed class MimirSceneEditorState
|
|||
{
|
||||
if (SelectedNode is { } selected)
|
||||
{
|
||||
SetNodeProgramPlacement(selected, PlacementForNode(selected) with { Width = value });
|
||||
SetNodeProgramPlacement(selected, ResizeProgramPlacement(selected, PlacementForNode(selected), value, resizeWidth: true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +315,7 @@ public sealed class MimirSceneEditorState
|
|||
{
|
||||
if (SelectedNode is { } selected)
|
||||
{
|
||||
SetNodeProgramPlacement(selected, PlacementForNode(selected) with { Height = value });
|
||||
SetNodeProgramPlacement(selected, ResizeProgramPlacement(selected, PlacementForNode(selected), value, resizeWidth: false));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -331,17 +335,16 @@ public sealed class MimirSceneEditorState
|
|||
}
|
||||
|
||||
var placement = PlacementForNode(selected);
|
||||
var aspect = Math.Clamp(placement.Width / Math.Max(placement.Height, 0.001f), 0.05f, 32.0f);
|
||||
const float programAspect = 16.0f / 9.0f;
|
||||
var aspect = ProgramPlacementAspectFor(selected);
|
||||
var width = 1.0f;
|
||||
var height = 1.0f;
|
||||
if (aspect > programAspect)
|
||||
if (aspect > 1.0f)
|
||||
{
|
||||
height = programAspect / aspect;
|
||||
height = 1.0f / aspect;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = aspect / programAspect;
|
||||
width = aspect;
|
||||
}
|
||||
|
||||
SetNodeProgramPlacement(selected, placement with
|
||||
|
|
@ -361,8 +364,8 @@ public sealed class MimirSceneEditorState
|
|||
{
|
||||
CenterX = 0.5f,
|
||||
CenterY = 0.5f,
|
||||
Width = 1.0f,
|
||||
Height = 1.0f,
|
||||
Width = ProgramPlacementAspectFor(selected) >= 1.0f ? 1.0f : ProgramPlacementAspectFor(selected),
|
||||
Height = ProgramPlacementAspectFor(selected) >= 1.0f ? 1.0f / ProgramPlacementAspectFor(selected) : 1.0f,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -551,10 +554,12 @@ public sealed class MimirSceneEditorState
|
|||
switch (GizmoMode)
|
||||
{
|
||||
case MimirSceneEditorGizmoMode.Translate:
|
||||
selected.Transform = selected.Transform with
|
||||
var placement = PlacementForNode(selected);
|
||||
SetNodeProgramPlacement(selected, placement with
|
||||
{
|
||||
Position = selected.Transform.Position + new Vector3(worldDelta, 0.0f),
|
||||
};
|
||||
CenterX = placement.CenterX + worldDelta.X / ProgramWorldWidth,
|
||||
CenterY = placement.CenterY - worldDelta.Y / ProgramWorldHeight,
|
||||
});
|
||||
break;
|
||||
case MimirSceneEditorGizmoMode.Rotate:
|
||||
selected.Transform = selected.Transform with
|
||||
|
|
@ -564,10 +569,8 @@ public sealed class MimirSceneEditorState
|
|||
break;
|
||||
case MimirSceneEditorGizmoMode.Scale:
|
||||
var scaleDelta = MathF.Exp((screenDelta.X - screenDelta.Y) * 0.006f);
|
||||
selected.Transform = selected.Transform with
|
||||
{
|
||||
Scale = Vector2.Clamp(selected.Transform.Scale * scaleDelta, new Vector2(0.05f), new Vector2(8.0f)),
|
||||
};
|
||||
var current = PlacementForNode(selected);
|
||||
SetNodeProgramPlacement(selected, ResizeProgramPlacement(selected, current, current.Width * scaleDelta, resizeWidth: true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -651,6 +654,49 @@ public sealed class MimirSceneEditorState
|
|||
private static string FeedNodeId(string sourceId) =>
|
||||
$"feed:{sourceId}";
|
||||
|
||||
private static float ProgramAspectRatioFor(MimirRollingStreamBuffer buffer)
|
||||
{
|
||||
var frame = buffer.Latest?.VideoFrame;
|
||||
if (frame is { Width: > 0, Height: > 0 })
|
||||
{
|
||||
return Math.Clamp(frame.Width / (float)frame.Height / ProgramAspect, 0.05f, 32.0f);
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
private static float ProgramPlacementAspectFor(MimirSceneEditorNode node) =>
|
||||
Math.Clamp(node.ProgramAspectRatio, 0.05f, 32.0f);
|
||||
|
||||
private static MimirCompositorPlacement ResizeProgramPlacement(MimirSceneEditorNode node, MimirCompositorPlacement placement, float value, bool resizeWidth)
|
||||
{
|
||||
var aspect = ProgramPlacementAspectFor(node);
|
||||
var width = placement.Width;
|
||||
var height = placement.Height;
|
||||
if (resizeWidth)
|
||||
{
|
||||
width = Math.Clamp(value, MinProgramExtent, 1.0f);
|
||||
height = width / aspect;
|
||||
if (height > 1.0f)
|
||||
{
|
||||
height = 1.0f;
|
||||
width = height * aspect;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
height = Math.Clamp(value, MinProgramExtent, 1.0f);
|
||||
width = height * aspect;
|
||||
if (width > 1.0f)
|
||||
{
|
||||
width = 1.0f;
|
||||
height = width / aspect;
|
||||
}
|
||||
}
|
||||
|
||||
return placement with { Width = width, Height = height };
|
||||
}
|
||||
|
||||
private MimirSceneEditorNode? NodeForSource(string sourceId) =>
|
||||
nodes.FirstOrDefault(node =>
|
||||
node.Kind == MimirSceneEditorNodeKind.SensorFeedPanel &&
|
||||
|
|
@ -662,8 +708,8 @@ public sealed class MimirSceneEditorState
|
|||
return new MimirCompositorPlacement(
|
||||
CenterX: Math.Clamp(0.5f + transform.Position.X / ProgramWorldWidth, 0.0f, 1.0f),
|
||||
CenterY: Math.Clamp(0.5f - transform.Position.Y / ProgramWorldHeight, 0.0f, 1.0f),
|
||||
Width: Math.Clamp(transform.Scale.X / ProgramWorldWidth, 0.01f, 1.0f),
|
||||
Height: Math.Clamp(transform.Scale.Y / ProgramWorldHeight, 0.01f, 1.0f),
|
||||
Width: Math.Clamp(transform.Scale.X / ProgramWorldWidth, MinProgramExtent, 1.0f),
|
||||
Height: Math.Clamp(transform.Scale.Y / ProgramWorldHeight, MinProgramExtent, 1.0f),
|
||||
RotationRadians: transform.RotationRadians,
|
||||
Layer: node.Layer);
|
||||
}
|
||||
|
|
@ -675,17 +721,53 @@ public sealed class MimirSceneEditorState
|
|||
return;
|
||||
}
|
||||
|
||||
var centerX = Math.Clamp(placement.CenterX, 0.0f, 1.0f);
|
||||
var centerY = Math.Clamp(placement.CenterY, 0.0f, 1.0f);
|
||||
var width = Math.Clamp(placement.Width, 0.01f, 1.0f);
|
||||
var height = Math.Clamp(placement.Height, 0.01f, 1.0f);
|
||||
var normalized = NormalizeProgramPlacement(placement);
|
||||
node.Transform = node.Transform with
|
||||
{
|
||||
Position = new Vector3((centerX - 0.5f) * ProgramWorldWidth, (0.5f - centerY) * ProgramWorldHeight, node.Transform.Position.Z),
|
||||
Scale = new Vector2(width * ProgramWorldWidth, height * ProgramWorldHeight),
|
||||
RotationRadians = placement.RotationRadians,
|
||||
Position = new Vector3((normalized.CenterX - 0.5f) * ProgramWorldWidth, (0.5f - normalized.CenterY) * ProgramWorldHeight, node.Transform.Position.Z),
|
||||
Scale = new Vector2(normalized.Width * ProgramWorldWidth, normalized.Height * ProgramWorldHeight),
|
||||
RotationRadians = normalized.RotationRadians,
|
||||
};
|
||||
}
|
||||
|
||||
private static MimirCompositorPlacement NormalizeProgramPlacement(MimirCompositorPlacement placement)
|
||||
{
|
||||
var width = SnapExtent(Math.Clamp(placement.Width, MinProgramExtent, 1.0f));
|
||||
var height = SnapExtent(Math.Clamp(placement.Height, MinProgramExtent, 1.0f));
|
||||
var centerX = SnapCenter(Math.Clamp(placement.CenterX, width * 0.5f, 1.0f - width * 0.5f), width);
|
||||
var centerY = SnapCenter(Math.Clamp(placement.CenterY, height * 0.5f, 1.0f - height * 0.5f), height);
|
||||
return placement with
|
||||
{
|
||||
CenterX = centerX,
|
||||
CenterY = centerY,
|
||||
Width = width,
|
||||
Height = height,
|
||||
};
|
||||
}
|
||||
|
||||
private static float SnapExtent(float value) =>
|
||||
MathF.Abs(1.0f - value) <= ProgramSnapThreshold ? 1.0f : value;
|
||||
|
||||
private static float SnapCenter(float center, float extent)
|
||||
{
|
||||
var half = extent * 0.5f;
|
||||
if (MathF.Abs(center - 0.5f) <= ProgramSnapThreshold)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
if (MathF.Abs(center - half) <= ProgramSnapThreshold)
|
||||
{
|
||||
return half;
|
||||
}
|
||||
|
||||
if (MathF.Abs(1.0f - half - center) <= ProgramSnapThreshold)
|
||||
{
|
||||
return 1.0f - half;
|
||||
}
|
||||
|
||||
return center;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MimirSceneEditorNode(
|
||||
|
|
@ -715,6 +797,8 @@ public sealed class MimirSceneEditorNode(
|
|||
|
||||
public string SourceId { get; init; } = "";
|
||||
|
||||
public float ProgramAspectRatio { get; init; } = Math.Clamp(defaultTransform.Scale.X / Math.Max(defaultTransform.Scale.Y, 0.001f), 0.05f, 32.0f);
|
||||
|
||||
public string Text { get; set; } = "";
|
||||
|
||||
public string ModelPath { get; init; } = "";
|
||||
|
|
|
|||
|
|
@ -327,3 +327,4 @@
|
|||
{"ts": "2026-06-01T12:19:43+01:00", "type": "implementation", "status": "ok", "note": "Added MimirProgramRecorder as the first app-owned recording feature. MimirRuntime now exposes Record/Stop in the Video Sources rail, tracks child-process status/output path, and stops the process tree. The current actuator delegates to scripts/record-kiyo-dual-mic-composite.ps1 so app recording produces the known Kiyo + Scarlett/Faust receipt under artifacts/runtime/mimir-app-recordings/ without making the script a second operator surface. Native program-output recording should replace that actuator behind the same owner."}
|
||||
{"ts": "2026-06-01T12:25:06+01:00", "type": "correction", "status": "ok", "note": "Corrected the app recording feature ownership after user rejected the isolated Kiyo/Faust mic receipt as half-assed. MimirProgramRecorder now delegates to scripts/record-stream-proof-output.ps1, writes artifacts/runtime/stream-proof/mimir-program-record-latest.mp4, and records the same Raven + Kiyo PIP + Starfire Scarlett NVENC/AAC composite used for Yggdrasil/public stream judgment. MIMIR_RECORD_START_RAVEN=1 asks the app recorder to launch Raven's sender; otherwise it records from an already-running feed. The earlier record-kiyo-dual-mic-composite delegate is no longer the app recorder actuator."}
|
||||
{"ts": "2026-06-01T12:46:47+01:00", "type": "decision", "status": "ok", "note": "Mimir center preview now requests Fensalir's UI preview output-buffer blit and overlays MimirSceneEditorState placement items on top; Fensalir owns the backbuffer snapshot/draw, Mimir owns only preview intent and layer geometry."}
|
||||
{"ts": "2026-06-01T13:22:54+01:00", "type": "implementation", "status": "ok", "note": "Added MimirSceneEditorState program-placement affordances: one placement commit path clamps layers inside the program frame, snaps centers/edges near boundaries, and preserves the source aspect ratio for width/height slider edits plus scale-gizmo resizing. --scene-editor-smoke now asserts aspect locking and boundary snapping."}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ invariants:
|
|||
runtime frame. The center preview requests a Fensalir-owned blit of the
|
||||
current output buffer, then draws those normalized placement items on top;
|
||||
the preview observes the program surface without becoming composition
|
||||
authority.
|
||||
authority. Placement commits keep layers inside the frame, snap near
|
||||
edges/center, and preserve source aspect while resizing through sliders or
|
||||
the scale gizmo.
|
||||
- `MimirProgramRecorder` owns the first app-level recording control. The Video
|
||||
Sources rail exposes `Record` / `Stop`, status text, latest output path, and
|
||||
process-tree shutdown. Its current actuator delegates to
|
||||
|
|
|
|||
Loading…
Reference in a new issue