PuppetModel draws any number of bodies: MaxBones is gone, with the rule that dropped a puppet past 32 bodies; the skin takes whatever count the shape has, and PuppetChecks builds and skins a crowd of 40
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8186d4b859
commit
79ddc1c82c
3 changed files with 13 additions and 18 deletions
|
|
@ -143,12 +143,7 @@ public partial class Puppet : Node3D
|
|||
/// <summary>Takes up the model's new shape: the carriers that are its bones, their inverse bind, the skin's buffers and the mesh layout.</summary>
|
||||
private void Rebuild()
|
||||
{
|
||||
if (_model.Shape is not { } shape)
|
||||
{
|
||||
GD.PushError($"BadDay: the puppet has more than {PuppetModel.MaxBones} shape bodies, which is the most it draws; drawing no puppet.");
|
||||
_mesh = null; _surface = null; _skin.Mesh = null;
|
||||
return;
|
||||
}
|
||||
var shape = _model.Shape!;
|
||||
_boneNodes = new Node3D[shape.Ids.Length]; _inverseBind = new Transform3D[shape.Ids.Length]; _bones = new Rigid[shape.Ids.Length];
|
||||
for (int i = 0; i < shape.Ids.Length; i++) { _boneNodes[i] = _nodes[shape.Ids[i]]; _inverseBind[i] = ToTransform(shape.SpreadBind[i].Inverse()); }
|
||||
_surface = new PuppetSkin(shape);
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ public readonly record struct PuppetJointLane(Box3DSoaJointKind Kind, ulong A, u
|
|||
/// </summary>
|
||||
public sealed class PuppetModel
|
||||
{
|
||||
/// <summary>The most shape bodies the puppet draws; past it nothing is drawn.</summary>
|
||||
public const int MaxBones = 32;
|
||||
|
||||
private readonly float _smin, _ballScale, _boxRound;
|
||||
private readonly Dictionary<ulong, Rigid> _bind = new();
|
||||
private readonly Dictionary<(Box3DSoaJointKind, ulong, ulong), float3> _originLocal = new();
|
||||
|
|
@ -33,7 +30,7 @@ public sealed class PuppetModel
|
|||
|
||||
public PuppetModel(float smin, float ballScale, float boxRound) { _smin = smin; _ballScale = ballScale; _boxRound = boxRound; }
|
||||
|
||||
/// <summary>The shape built from the current signature, or null before the first update or while there are more than <see cref="MaxBones"/> shape bodies.</summary>
|
||||
/// <summary>The shape built from the current signature, or null before the first update.</summary>
|
||||
public PuppetShape? Shape { get; private set; }
|
||||
|
||||
/// <summary>Reads the shape bodies and qualifying joints of the lanes and updates.</summary>
|
||||
|
|
@ -64,7 +61,7 @@ public sealed class PuppetModel
|
|||
|
||||
/// <summary>
|
||||
/// <paramref name="bodies"/> carry their pose now in <see cref="PuppetBody.Bind"/>; the model keeps the first one it saw.
|
||||
/// Returns whether the signature changed, which is whether the shape was rebuilt (or dropped, past the bone cap).
|
||||
/// Returns whether the signature changed, which is whether the shape was rebuilt.
|
||||
/// </summary>
|
||||
public bool Update(IReadOnlyList<PuppetBody> bodies, IReadOnlyList<PuppetJointLane> joints)
|
||||
{
|
||||
|
|
@ -91,7 +88,6 @@ public sealed class PuppetModel
|
|||
}
|
||||
_signed = true;
|
||||
|
||||
if (bound.Count > MaxBones) { Shape = null; return true; }
|
||||
Shape = PuppetField.Build(bound, built, _smin, _ballScale, _boxRound);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,13 +70,17 @@ public static class PuppetChecks
|
|||
Changes("a joint's kind changed", (b, j) => j[0] = j[0] with { Kind = Box3DSoaJointKind.Weld });
|
||||
Changes("a body's identity changed", (b, j) => { b[1] = b[1] with { Id = 21 }; j[0] = j[0] with { B = 21 }; j[1] = j[1] with { A = 21 }; });
|
||||
|
||||
// Past the skin's bone count nothing is drawn, once, and the signature still decides.
|
||||
// Any number of bodies is drawn: a crowd of 40 (no cap, however many the skin has to carry) builds a shape whose every body owns a
|
||||
// vertex, and skins to a surface with a facet for every triangle.
|
||||
var many = Fresh();
|
||||
var crowd = Enumerable.Range(0, PuppetModel.MaxBones + 1).Select(i => Body((ulong)(100 + i), Box3DSoaKind.Sphere, 0.05f, 0f, i * 0.2f)).ToList();
|
||||
Check(many.Update(crowd, new List<PuppetJointLane>()) && many.Shape is null, "more shape bodies than bones was drawn");
|
||||
Check(!many.Update(crowd, new List<PuppetJointLane>()), "an over-full puppet reported a change with none");
|
||||
crowd.RemoveAt(0);
|
||||
Check(many.Update(crowd, new List<PuppetJointLane>()) && many.Shape is not null, "the puppet did not come back once it fit the skin");
|
||||
var crowd = Enumerable.Range(0, 40).Select(i => Body((ulong)(100 + i), Box3DSoaKind.Sphere, 0.05f, 0f, i * 0.2f)).ToList();
|
||||
Check(many.Update(crowd, new List<PuppetJointLane>()) && many.Shape is { Corners.Length: > 0 }, "a puppet of 40 bodies was not built");
|
||||
var crowdShape = many.Shape!;
|
||||
Check(crowdShape.Ids.Length == 40, $"the crowd's shape carries {crowdShape.Ids.Length} bodies, not 40");
|
||||
Check(!many.Update(crowd, new List<PuppetJointLane>()), "a crowd reported a change with none");
|
||||
var crowdSkin = new PuppetSkin(crowdShape);
|
||||
crowdSkin.Update(Enumerable.Repeat(Identity, crowdShape.Ids.Length).ToArray());
|
||||
Check(crowdSkin.Facet.Length * 3 == crowdShape.Corners.Length && crowdSkin.Facet.All(f => math.length(f) > 0.99f), "the crowd's skin has no unit facet for every triangle");
|
||||
|
||||
// The real puppet at its creation pose: the grid cell is the coarsest that resolves its limbs, and bent every which way
|
||||
// no skinned edge is a web.
|
||||
|
|
|
|||
Loading…
Reference in a new issue