baddaysim plan prints the seated puppet's body plan as JSON; SeatedPuppet.PartOf is the one rule from stable id to part
The mesh build's only source for the skeleton is the plan, not coordinates copied into a script; BodyRenderer and FellaSkin will both ask PartOf which bodies are Fella's parts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e58345f7c4
commit
d211f0c301
3 changed files with 37 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ public static class Program
|
|||
private const string Usage = """
|
||||
baddaysim: the Synaptic Induction Chamber (the pain box)
|
||||
|
||||
baddaysim plan the seated puppet's body plan as JSON: parts and joints in their creation pose (the mesh build's skeleton)
|
||||
baddaysim run --seed N [options] one run, full timeline
|
||||
baddaysim run --seed N --body [options] the same run on the Ymir ragdoll, with the hand-out time
|
||||
baddaysim sweep --seed N --count M [options] seeds N..N+M-1, break-time summary
|
||||
|
|
@ -52,6 +53,7 @@ public static class Program
|
|||
|
||||
public static int Execute(string[] args, System.IO.TextWriter output)
|
||||
{
|
||||
if (args.Length == 1 && args[0] == "plan") { output.Write(PlanJson()); return 0; }
|
||||
if (args.Length == 0 || (args[0] != "run" && args[0] != "sweep" && args[0] != "office" && args[0] != "office-sweep"))
|
||||
throw new ArgumentException("expected 'run', 'sweep', 'office' or 'office-sweep'");
|
||||
var opts = ParseOptions(args);
|
||||
|
|
@ -98,6 +100,17 @@ public static class Program
|
|||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>SeatedPuppet.Plan as JSON, floats in round-trip form: per part label, side, creation position and rotation (x, y, z, w); per joint label, side, parent and child part ordinals and anchor.</summary>
|
||||
private static string PlanJson()
|
||||
{
|
||||
string F(float v) => v.ToString("R", CultureInfo.InvariantCulture);
|
||||
string V((float X, float Y, float Z) v) => $"[{F(v.X)}, {F(v.Y)}, {F(v.Z)}]";
|
||||
var plan = SeatedPuppet.Plan;
|
||||
var parts = plan.Parts.Select(p => $" {{\"label\": \"{p.Label}\", \"side\": \"{p.Side}\", \"position\": {V(p.Position)}, \"rotation\": [{F(p.Rotation.X)}, {F(p.Rotation.Y)}, {F(p.Rotation.Z)}, {F(p.Rotation.W)}]}}");
|
||||
var joints = plan.Joints.Select(j => $" {{\"label\": \"{j.Label}\", \"side\": \"{j.Side}\", \"parent\": {j.Parent}, \"child\": {j.Child}, \"anchor\": {V(j.Anchor)}}}");
|
||||
return "{\n \"parts\": [\n" + string.Join(",\n", parts) + "\n ],\n \"joints\": [\n" + string.Join(",\n", joints) + "\n ]\n}\n";
|
||||
}
|
||||
|
||||
private static int ExecuteOffice(bool sweep, ulong seed, Dictionary<string, string> opts, System.IO.TextWriter output)
|
||||
{
|
||||
if (opts.ContainsKey("body") && sweep) throw new ArgumentException("--body applies to run and office");
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ public static class SeatedPuppet
|
|||
/// <summary>The stable id of the first of Fella's parts: a part's stable id is this plus its ordinal. The ground is 1 and the stool 2.</summary>
|
||||
public const ulong FirstStableId = 100;
|
||||
|
||||
/// <summary>The part ordinal of Fella's body with this stable id (<see cref="FirstStableId"/> plus the ordinal), or null for any other body: the one rule from stable id to part.</summary>
|
||||
public static int? PartOf(ulong stableId) =>
|
||||
stableId >= FirstStableId && stableId - FirstStableId < (ulong)Plan.Parts.Count ? (int)(stableId - FirstStableId) : null;
|
||||
|
||||
/// <summary>Bodies, joints and sensors a world needs for <see cref="Build"/>: the ragdoll, the ground and the stool, the weld, and the airway sensors (the world must also have a particle system for them).</summary>
|
||||
public static (int Bodies, int Joints, int Sensors) Needs => (Ragdoll.Needs(Plan).Bodies + 2, Ragdoll.Needs(Plan).Joints + 1, Ragdoll.Needs(Plan).Sensors);
|
||||
|
||||
|
|
|
|||
|
|
@ -590,6 +590,26 @@ public static class Program
|
|||
Check(Run("run", "--seed", "5", "--pay", "20") != Run("run", "--seed", "5", "--pay", "400"), "--pay changed nothing");
|
||||
}),
|
||||
|
||||
("plan prints the seated puppet's 19 parts and 18 joints as JSON, and PartOf claims exactly the parts' stable ids", () =>
|
||||
{
|
||||
var w = new StringWriter();
|
||||
Check(BadDay.Cli.Program.Execute(new[] { "plan" }, w) == 0, "plan did not succeed");
|
||||
using var json = System.Text.Json.JsonDocument.Parse(w.ToString());
|
||||
var plan = SeatedPuppet.Plan;
|
||||
var parts = json.RootElement.GetProperty("parts");
|
||||
var joints = json.RootElement.GetProperty("joints");
|
||||
Check(parts.GetArrayLength() == 19 && joints.GetArrayLength() == 18, $"plan has {parts.GetArrayLength()} parts and {joints.GetArrayLength()} joints");
|
||||
var neck = joints.EnumerateArray().Single(j => j.GetProperty("label").GetString() == "Neck").GetProperty("anchor");
|
||||
var want = plan.Joints[plan.JointIndex("Neck")].Anchor;
|
||||
Check(neck[1].GetSingle() == want.Y && neck[0].GetSingle() == want.X && neck[2].GetSingle() == want.Z, "the neck anchor is not the plan's");
|
||||
for (ulong id = 0; id < SeatedPuppet.FirstStableId + 25; id++)
|
||||
{
|
||||
bool part = id >= SeatedPuppet.FirstStableId && id < SeatedPuppet.FirstStableId + 19;
|
||||
var owner = SeatedPuppet.PartOf(id);
|
||||
Check(part ? owner == (int)(id - SeatedPuppet.FirstStableId) : owner is null, $"PartOf({id}) is {owner}");
|
||||
}
|
||||
}),
|
||||
|
||||
("office: a stressor is silent before its onset, on for its duration, and back every period", () =>
|
||||
{
|
||||
var printer = Cause.Office.Stressors.Single(s => s.Id == "printer"); // 5 s on, 8 s period, 1 s long, 0.25
|
||||
|
|
|
|||
Loading…
Reference in a new issue