BodyPlan: refuse fields a shape cannot carry, drop the unreachable root clause; pin sense-point offset, box depth, rotation finiteness; docs name BodyPlan and Ragdoll

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-25 00:22:51 +01:00
commit 30aefa8da7
5 changed files with 84 additions and 14 deletions

View file

@ -86,11 +86,11 @@ against Ymir's pinned Box3D, sphere r 0.1 m, density 1000, 1/120 s, 4 substeps,
spin -5.0 rad/s: an off-centre poke turns the part, which the force lanes (centre of mass only, soa.c:593-626)
cannot do.
8. **Lodur today.** Perception senses named box volumes at points only (`Perception.cs:82-113`); regions are two
hand points (`HumanoidRagdoll.cs:12-16`, 148-170); one reflex kind (`WithdrawalReflex.cs`); drive is pain,
sense points read by `Ragdoll.ReadSensePoints`; one reflex kind (`WithdrawalReflex.cs`); drive is pain,
strain, resolve, `WillBroken` (`DriveState.cs`); behaviour blends two poses by leak and shake
(`PoseBehaviour.cs:87-115`); the body takes 12 strengths and 12 joint-space targets
(`HumanoidRagdoll.cs:120-146`). No IK, no clips, no physiology, no grip, no part tree beyond the `Limb` and
`Muscle` enums. Rung 3 adds emitters and arousal; rung 4 the goal flip and `PoseBehaviour`.
(`Ragdoll.Drive`). No IK, no clips, no physiology, no grip; the part tree is `BodyPlan` (parts, joints that are the tree,
sense points), without HP, coverage or vital flags. Rung 3 adds emitters and arousal; rung 4 the goal flip and `PoseBehaviour`.
9. **BDS today.** Headless and body pain box only (`src/BadDay.Ymir/BodyPainBox.cs`); the world is built per run
with capacity 15 (58); the puppet is welded to a stool because the PD ragdoll cannot balance for 15 s (59-62).
No session type survives beyond a run, no commands, no level content.
@ -118,13 +118,13 @@ against Ymir's pinned Box3D, sphere r 0.1 m, density 1000, 1/120 s, 4 substeps,
| System | Layer | State | Cut |
|---|---|---|---|
| Part tree: the body plan as content (parts, parent, side, max HP, coverage, vital flags, muscles, Ymir lane binding) | 3 data + 5 binding | new; today `Limb`/`Muscle` enums | `lodur-physiology` |
| Part tree: the body plan as content (parts, parent, side, max HP, coverage, vital flags, muscles, Ymir lane binding) | 3 data + 5 binding | `BodyPlan` holds parts, joints as the tree and sense points; HP, coverage and vital flags are new | `lodur-physiology` |
| Touch perception per part: pressure (contact force), impact (hit speed, material), external-joint pull (grab, strap) | 1 (+5 reads Ymir) | new | `lodur-touch` |
| Reflexes: withdrawal (exists), startle on sensory and touch onsets, flinch-from-touch, brace on impact | 2 | withdrawal exists `WithdrawalReflex.cs` and reads `Will`; rest new | `lodur-startle-attention`, `lodur-reflex-set` |
| Physiology as drive state: per-part HP and injuries, body blood fraction, bleeding, pain sum, shock, consciousness, capacities scaling muscle strength, death | 3 | new | `lodur-physiology` |
| Will economy: resolve (exists) times attention (new, startle drains it) is the budget every voluntary layer draws on; reflexes act against it | 3/4 | landed except attention: `Will` = min(resolve x attention, consciousness) in `DriveState`, read by the reflex and the will mix; the Attention and Consciousness slots read 1 until startle and physiology write them | `lodur-startle-attention` (open), `lodur-will-mix` (landed `afb8df3`) |
| Voluntary motor layers: hold pose (exists as `PoseBehaviour`), clip player, IK goals (reach, look, aim), grip; mixed by will | 4 | hold exists, weighted by `Will^WillCurve` (`PoseBehaviour.Write`; an involuntary goal onset writes at weight 1); rest new | `lodur-will-mix`, `lodur-ik-goals`, `lodur-clips` |
| Body interface: strengths + joint targets (exists) + IK goals with weights | 5 | partial `HumanoidRagdoll.Drive` | `lodur-ik-goals` |
| Body interface: strengths + joint targets (exists) + IK goals with weights | 5 | partial `Ragdoll.Drive` | `lodur-ik-goals` |
| Severing: physiology decides; binding removes the joint in Ymir; impairment states derived per part, mirror-symmetric | 3 decides, 5 executes | new | `lodur-sever-impair` |
| Grip: hand holds an object by a breakable weld whose threshold follows grip strength; drop on pain, overload, unconsciousness; the tool frame is an IK end effector | 4/5 | new | `lodur-grip` |
@ -274,8 +274,8 @@ leg is a behaviour keyed on the state, not a re-learned controller).
- **Facts, not callbacks.** Ymir fills fixed-capacity fact buffers per step and the caller reads spans, like
lanes; no managed callback crosses the ABI, overflow is counted, never silent (bounded-tick).
- **Tombstones, not compaction.** Lodur and the client cache lane indices (`HumanoidRagdoll._bodyLane`,
`HumanoidRagdoll.cs:44`). Swap-remove, as the planar session does (`ymir_box3d.c:1435-1436`), would move a
- **Tombstones, not compaction.** Lodur and the client cache lane indices (`Ragdoll._bodyLane`,
`Ragdoll.cs:16`). Swap-remove, as the planar session does (`ymir_box3d.c:1435-1436`), would move a
live body's lane under them. A removed lane keeps its last state and a `Removed` kind; reuse waits for a
completed step so end facts still name the old id.
- **Grab is felt.** A motor joint is not a contact, so a grab produces no contact fact. The binding treats every

View file

@ -36,7 +36,7 @@ All probes in detached worktrees `F:\aeth-wt\connect\{Ymir,Lodur,BadDaySimulator
3. **The SoA world is internal.** `Box3DSoaWorld`, `Box3DSoaView` and the kind enums are `internal`, visible to
`Ymir.Core`, `Ymir.Box3D.Soa.Tests`, `Lodur.Body.Ymir` and `Lodur.Tests` by `InternalsVisibleTo`
(`src/Ymir.Box3D/Properties/AssemblyInfo.cs:3-6`, commit 0227636 "until Ymir.Core has a public surface").
`HumanoidRagdoll`, `Muscle` and `Limb` are `internal` in Lodur.Body.Ymir. **Bad Day Simulator cannot name the
`Ragdoll` (Lodur.Body.Ymir) builds a `BodyPlan` into a caller-owned `Box3DSoaWorld`. **Bad Day Simulator cannot name the
world today**, so it cannot own its one physics world without a Ymir change.
4. **A pelvis weld to a static body holds the ragdoll upright for 20 s.** `AddJoint(Weld, staticBox, pelvis)`
is accepted (native refuses only out-of-range or equal indices). Full-strength ragdoll, pelvis welded to a
@ -77,7 +77,7 @@ so `content-is-cultcache` is not engaged yet (follow-up `lodur:follow_up:drive-p
|---|---|---|---|
| Nerve, reflex and drive parameters (`NerveParameters`, `WithdrawalParameters`, `DriveParameters`) | Nothing persistent: C# records with defaults in Lodur.Core; a per-actor instance is a value | Built once when the consumer creates an actor (per-seed traits folded in as `Gain`, `DrainTrait`), immutable for the actor's life | Lodur owns the schema and defaults; the consumer (BDS scenario) owns per-actor values and the trait draw |
| Actor (nervous state: afferent rings, drive state, goal) | The consumer's handle; no id inside Lodur | Created with the scenario, ticked once per physics step, never persisted, dies with the scenario | Lodur.Core alone writes it; nothing else writes drive state |
| Puppet definition (the 19-body humanoid: shapes, joints, gains, regions) | Code in Lodur.Body.Ymir; world stable ids `firstStableId..+18` passed by the caller | Built into the caller's world once; no removal (Ymir has none) | Lodur.Body.Ymir owns geometry and gains; BDS owns placement and stable-id allocation |
| Puppet definition (the 19-body humanoid: shapes, joints, gains, regions) | `BodyPlan` data in Lodur.Core (`BodyPlans.Humanoid`), built by `Ragdoll` in Lodur.Body.Ymir; world stable ids `firstStableId..+18` passed by the caller | Built into the caller's world once; no removal (Ymir has none) | `BodyPlan` owns geometry, joints and gains, `Ragdoll` builds them; BDS owns placement and stable-id allocation |
| Stimulus source (the pain box) | BDS object, scenario-local; not a world body | Placed by the scenario; intensity written every tick from its schedule (ramp, noise, disable time) | BDS writes intensity and on/off; Lodur perception only reads it and decides containment and transduction |
| Restraint (stool weld) | BDS scene object: one static box + one weld joint in the world | Created with the scenario | BDS (a game object acting on the body through the world, like a grab; not a layer above Lodur) |
| Scenario run | (seed, parameters) | One run, headless or on the body | BDS; the timeline is output, not content |

View file

@ -86,7 +86,7 @@ namespace Lodur
}
}
// 3. Part 0 is the root and the child of no joint; every other part is the child of exactly one joint.
// 3. Part 0 is the root (rule 2 already leaves it no joint to be the child of); every other part is the child of exactly one joint.
if (Parts.Count == 0) throw new ArgumentException("a body plan needs a root part.");
var parentOf = new int[Parts.Count];
var attached = new int[Parts.Count];
@ -97,12 +97,11 @@ namespace Lodur
attached[d.Child]++;
}
for (var p = 0; p < attached.Length; p++)
for (var p = 1; p < attached.Length; p++)
{
var want = p == 0 ? 0 : 1;
if (attached[p] != want)
if (attached[p] != 1)
{
throw new ArgumentException($"part '{Parts[p].Label}' {Parts[p].Side} is the child of {attached[p]} joints, needs {want}.");
throw new ArgumentException($"part '{Parts[p].Label}' {Parts[p].Side} is the child of {attached[p]} joints, needs 1.");
}
}
@ -123,6 +122,17 @@ namespace Lodur
var sized = p.Shape == PartShape.Box ? sz.X > 0f && sz.Y > 0f && sz.Z > 0f
: p.Shape == PartShape.Capsule ? sz.X > 0f && sz.Y > 0f : sz.X > 0f;
if (!sized) throw new ArgumentException($"part '{p.Label}' {p.Side}: a size its shape uses is not positive.");
// A binding has no destination for what the shape cannot carry (sphere rotation, box rolling resistance, size components
// beyond the shape's own), so the plan may not say it.
var spare = p.Shape == PartShape.Box ? 0f : p.Shape == PartShape.Capsule ? sz.Z : Math.Abs(sz.Y) + Math.Abs(sz.Z);
if (spare != 0f) throw new ArgumentException($"part '{p.Label}' {p.Side}: a size its shape does not use is not zero.");
if (p.Shape == PartShape.Sphere && (r.X != 0f || r.Y != 0f || r.Z != 0f || r.W != 1f))
{
throw new ArgumentException($"part '{p.Label}' {p.Side}: a sphere carries no rotation.");
}
if (p.Shape == PartShape.Box && p.RollingResistance != 0f) throw new ArgumentException($"part '{p.Label}' {p.Side}: a box carries no rolling resistance.");
if (!(p.Density > 0f)) throw new ArgumentException($"part '{p.Label}' {p.Side}: density is not positive.");
}

View file

@ -113,6 +113,42 @@ public sealed class BodyPlanTests
Assert.Equal(2, capsule.Parts.Count);
}
[Fact]
public void Rule5_a_box_depth_that_is_not_positive_is_refused()
{
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Size = (0.1f, 0.1f, 0f) } }, new[] { Joint("J", 0, 1) }), "size its shape uses");
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Size = (0.1f, 0.1f, -0.1f) } }, new[] { Joint("J", 0, 1) }), "size its shape uses");
}
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
public void Rule5_a_non_finite_rotation_component_is_refused(int component)
{
var q = new[] { 0f, 0f, 0f, 1f };
q[component] = float.NaN;
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Rotation = new Quat(q[0], q[1], q[2], q[3]) } }, new[] { Joint("J", 0, 1) }), "non-finite");
q[component] = float.PositiveInfinity;
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Rotation = new Quat(q[0], q[1], q[2], q[3]) } }, new[] { Joint("J", 0, 1) }), "non-finite");
}
[Fact]
public void Rule5_a_field_the_shape_cannot_carry_is_refused()
{
var turned = Quat.FromAxisAngle(0f, 0f, 1f, 0.5f);
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Shape = PartShape.Sphere, Size = (0.1f, 0f, 0f), Rotation = turned } }, new[] { Joint("J", 0, 1) }), "sphere carries no rotation");
Refuses(() => Plan(new[] { Box("A"), Box("B") with { RollingResistance = 0.1f } }, new[] { Joint("J", 0, 1) }), "box carries no rolling resistance");
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Shape = PartShape.Capsule, Size = (0.1f, 0.2f, 0.3f) } }, new[] { Joint("J", 0, 1) }), "does not use is not zero");
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Shape = PartShape.Sphere, Size = (0.1f, 0.2f, 0f) } }, new[] { Joint("J", 0, 1) }), "does not use is not zero");
Refuses(() => Plan(new[] { Box("A"), Box("B") with { Shape = PartShape.Sphere, Size = (0.1f, 0f, 0.3f) } }, new[] { Joint("J", 0, 1) }), "does not use is not zero");
// what each shape does carry is accepted
var ok = Plan(new[] { Box("A") with { Rotation = turned }, Box("B") with { Shape = PartShape.Capsule, Size = (0.1f, 0.2f, 0f), Rotation = turned, RollingResistance = 0.1f },
Box("C") with { Shape = PartShape.Sphere, Size = (0.1f, 0f, 0f), RollingResistance = 0.1f } }, new[] { Joint("J", 0, 1), Joint("K", 0, 2) });
Assert.Equal(3, ok.Parts.Count);
}
[Fact]
public void Rule5_a_density_that_is_not_positive_is_refused()
{

View file

@ -93,4 +93,28 @@ public sealed class QuadrupedPlanTests
Assert.Throws<ArgumentException>(() => quad.ReadSensePoints(new float[3], new float[3], new float[3]));
Assert.Throws<ArgumentException>(() => quad.Drive(new float[3], quadTarget));
}
private const float SenseTolerance = 3.6e-4f; // geometric mean of the shipped worst (one float ulp at 3, 2.4e-7) and the weakest mutant (0.54)
[Fact]
public void A_sense_point_reads_its_parts_position_plus_the_parts_rotation_applied_to_its_offset()
{
// Root turned 90 degrees about z: the offset (0.5, 0.2, 0.1) lands at (-0.2, 0.5, 0.1) from the part, not at (0.5, 0.2, 0.1) and not at 0.
var turned = Quat.FromAxisAngle(0f, 0f, 1f, MathF.PI / 2f);
var parts = new[]
{
new PartDef("Root", Side.Center, PartShape.Box, (0.2f, 0.1f, 0.1f), (0f, 1f, 0f), turned, 1000f, 0.8f, 0f),
new PartDef("Tip", Side.Center, PartShape.Sphere, (0.05f, 0f, 0f), (0f, 1.5f, 0f), Quat.Identity, 1000f, 0.8f, 0f),
};
var joints = new[] { new JointDef("J", Side.Center, JointKind.Spherical, 0, 1, (0f, 1.2f, 0f), (0f, 1f, 0f), -1f, 1f, 0.5f, new MuscleGains(1f, 1f, 1f, 1f)) };
var plan = new BodyPlan(parts, joints, new[] { new SensePointDef("Probe", Side.Center, 0, (0.5f, 0.2f, 0.1f)) });
var (bodies, jointCount) = Ragdoll.Needs(plan);
using var world = new Box3DSoaWorld(capacity: bodies, jointCapacity: jointCount);
var ragdoll = Ragdoll.Build(world, plan, (3f, 0f), firstStableId: 1);
var x = new float[1]; var y = new float[1]; var z = new float[1];
ragdoll.ReadSensePoints(x, y, z);
var error = MathF.Max(MathF.Abs(x[0] - 2.8f), MathF.Max(MathF.Abs(y[0] - 1.5f), MathF.Abs(z[0] - 0.1f)));
Assert.True(error < SenseTolerance, $"sense point ({x[0]}, {y[0]}, {z[0]}) is {error} from (2.8, 1.5, 0.1)");
}
}