The seated world is built with a particle system and its blood material: FirstStableId, sensors in Needs, BloodParameters; the stepped bytes do not move (81/81)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f26ec57b90
commit
e940b2fd4b
3 changed files with 54 additions and 6 deletions
41
src/BadDay.Ymir/Blood.cs
Normal file
41
src/BadDay.Ymir/Blood.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using Lodur;
|
||||
using Lodur.Body.Ymir;
|
||||
using Ymir.Box3D;
|
||||
|
||||
namespace BadDay.Ymir;
|
||||
|
||||
/// <summary>
|
||||
/// Content for the blood of a seated body: every number is a balance knob (ruling economy-numbers-are-sim-tuned-knobs).
|
||||
/// <see cref="Gain"/> is how many times the real volume is drawn and spilled (ruling bds-blood-gain-simulated); the
|
||||
/// drops are fluid particles of one size, <see cref="DropVolume"/> each.
|
||||
/// </summary>
|
||||
public sealed record BloodParameters
|
||||
{
|
||||
/// <summary>Visible volume per real volume bled; the physiology's own blood volume is never scaled.</summary>
|
||||
public double Gain { get; init; } = 10.0;
|
||||
/// <summary>Drop radius in m; a drop's volume is (2 r)^3, as Ymir's Settle reads it (0.0125 m: 15.625 mL).</summary>
|
||||
public float DropRadius { get; init; } = 0.0125f;
|
||||
/// <summary>kg/m^3; a drop's mass is this times <see cref="DropVolume"/>.</summary>
|
||||
public double Density { get; init; } = 1060.0;
|
||||
/// <summary>m/s along the wound's normal, over the part's own velocity.</summary>
|
||||
public float ExitSpeed { get; init; } = 0.5f;
|
||||
/// <summary>m/s: a supported drop slower than this is calm.</summary>
|
||||
public float SettleSpeed { get; init; } = 0.05f;
|
||||
/// <summary>Consecutive calm ticks before a drop settles into a wet patch.</summary>
|
||||
public int SettleTicks { get; init; } = 30;
|
||||
/// <summary>Fluid particle lanes: the most drops that are live at once (ruling ymir-fluid-live-cap-512).</summary>
|
||||
public int LiveCap { get; init; } = 512;
|
||||
/// <summary>Drops emitted over all wounds in one tick; the rest of the volume waits as backlog.</summary>
|
||||
public int MaxDropsPerTick { get; init; } = 8;
|
||||
/// <summary>Wet patch lanes.</summary>
|
||||
public int WetLanes { get; init; } = 256;
|
||||
/// <summary>The blood material's table index and its friction, viscosity and wet friction.</summary>
|
||||
public int Material { get; init; } = 1;
|
||||
public float Friction { get; init; } = 0.3f;
|
||||
public float Viscosity { get; init; } = 0.01f;
|
||||
public float WetFriction { get; init; } = 0.1f;
|
||||
|
||||
/// <summary>One drop's volume in m^3.</summary>
|
||||
public double DropVolume => Math.Pow(2.0 * DropRadius, 3.0);
|
||||
}
|
||||
|
|
@ -27,12 +27,16 @@ public sealed class SeatedBody : IDisposable
|
|||
private readonly Queue<BodyEvent> _events = new();
|
||||
private bool _disposed;
|
||||
|
||||
public SeatedBody()
|
||||
public SeatedBody(BloodParameters? blood = null)
|
||||
{
|
||||
blood ??= new BloodParameters();
|
||||
var needs = SeatedPuppet.Needs;
|
||||
_world = new Box3DSoaWorld(capacity: needs.Bodies, jointCapacity: needs.Joints);
|
||||
_world = new Box3DSoaWorld(capacity: needs.Bodies, jointCapacity: needs.Joints,
|
||||
particles: new Box3DSoaParticleCapacities(Particles: blood.LiveCap, 0, 0, 0, 0, Materials: blood.Material + 1,
|
||||
Fluid: blood.LiveCap, Wets: blood.WetLanes, Sensors: needs.Sensors));
|
||||
try
|
||||
{
|
||||
_world.SetMaterial(blood.Material, blood.Friction, viscosity: blood.Viscosity, wetFriction: blood.WetFriction);
|
||||
_ragdoll = SeatedPuppet.Build(_world);
|
||||
var plan = _ragdoll.Plan;
|
||||
_x = new float[plan.SensePoints.Count];
|
||||
|
|
|
|||
|
|
@ -14,18 +14,21 @@ public static class SeatedPuppet
|
|||
/// <summary>Physics substeps per 1/120 s step. The ragdoll gains were tuned against 4; the behaviour tests, not this number, are the rule.</summary>
|
||||
public const int Substeps = 4;
|
||||
|
||||
/// <summary>Bodies and joints a world needs for <see cref="Build"/>: the ragdoll, the ground and the stool, and the weld.</summary>
|
||||
public static (int Bodies, int Joints) Needs => (Ragdoll.Needs(Plan).Bodies + 2, Ragdoll.Needs(Plan).Joints + 1);
|
||||
/// <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>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);
|
||||
|
||||
/// <summary>The humanoid plan every BDS body is built from; classes resolve their labels against it once.</summary>
|
||||
public static BodyPlan Plan { get; } = BodyPlans.Humanoid();
|
||||
|
||||
/// <summary>Adds the ground, the stool, the ragdoll (stable ids from 100) and the pelvis weld to <paramref name="world"/>, which must be sized by <see cref="Needs"/>.</summary>
|
||||
/// <summary>Adds the ground, the stool, the ragdoll (stable ids from <see cref="FirstStableId"/>) and the pelvis weld to <paramref name="world"/>, which must be sized by <see cref="Needs"/>.</summary>
|
||||
public static Ragdoll Build(Box3DSoaWorld world)
|
||||
{
|
||||
world.AddStaticBox(1, (0f, -0.5f, 0f), (20f, 0.5f, 20f), friction: 0.8f);
|
||||
var stool = world.AddStaticBox(2, (0f, 1.11f, -0.115f), (0.05f, 0.05f, 0.025f), friction: 0.8f);
|
||||
var ragdoll = Ragdoll.Build(world, Plan, (0f, 0f), firstStableId: 100);
|
||||
var ragdoll = Ragdoll.Build(world, Plan, (0f, 0f), firstStableId: FirstStableId);
|
||||
world.AddJoint(Box3DSoaJointKind.Weld, stool, ragdoll.BodyLane(Plan.PartIndex("Pelvis")), (0f, 1.11f, -0.09f), (0f, 1f, 0f));
|
||||
return ragdoll;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue