Puppet: one build counter, at the Godot mesh build; the model's and the shape's counters are gone, and the smoke asserts it
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
154f333fc7
commit
fa29d1256f
6 changed files with 18 additions and 16 deletions
|
|
@ -22,6 +22,9 @@ public partial class BodyRenderer : Node3D
|
|||
/// <summary>What the puppet's mesh is made of now, or null while it draws none.</summary>
|
||||
public PuppetShape? PuppetShape => _puppet.Shape;
|
||||
|
||||
/// <summary>How many times the puppet's Godot mesh has been built.</summary>
|
||||
public int PuppetMeshBuilds => _puppet.MeshBuilds;
|
||||
|
||||
public BaseMaterial3D SceneryMaterial => _material;
|
||||
|
||||
/// <summary>Where body <paramref name="stableId"/> is drawn now, or null if it is not drawn.</summary>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ public partial class Puppet : Node3D
|
|||
|
||||
public int BodyCount => _nodes.Count;
|
||||
|
||||
/// <summary>How many times the Godot mesh has been made from a shape: the one build counter, which the smoke asserts.</summary>
|
||||
public int MeshBuilds { get; private set; }
|
||||
|
||||
/// <summary>The colour the puppet is drawn in: the shader's albedo.</summary>
|
||||
public Color Color => _material.GetShaderParameter("albedo").AsColor();
|
||||
|
||||
|
|
@ -142,6 +145,7 @@ public partial class Puppet : Node3D
|
|||
_boneNodes = new Node3D[shape.Ids.Length]; _inverseBind = new Transform3D[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()); }
|
||||
_mesh = MeshOf(shape);
|
||||
MeshBuilds++;
|
||||
_skin.Mesh = _mesh;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,9 +66,6 @@ public sealed class PuppetShape
|
|||
/// <summary>How far a skinned vertex can lie from its bone's origin.</summary>
|
||||
public required float Reach { get; init; }
|
||||
|
||||
/// <summary>How many times the mesh has been built; Puppet counts.</summary>
|
||||
public int Builds { get; internal set; }
|
||||
|
||||
public int Triangles => Positions.Length / 3;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@ public sealed class PuppetModel
|
|||
/// <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>
|
||||
public PuppetShape? Shape { get; private set; }
|
||||
|
||||
/// <summary>How many meshes have been built.</summary>
|
||||
public int Builds { get; private set; }
|
||||
|
||||
/// <summary>Reads the shape bodies and qualifying joints of the lanes and updates.</summary>
|
||||
public bool Update(in Box3DSoaView view)
|
||||
{
|
||||
|
|
@ -96,7 +93,6 @@ public sealed class PuppetModel
|
|||
|
||||
if (bound.Count > MaxBones) { Shape = null; return true; }
|
||||
Shape = PuppetField.Build(bound, built, _smin, _ballScale, _boxRound);
|
||||
Shape.Builds = ++Builds;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,16 +39,16 @@ public static class PuppetChecks
|
|||
// The first update builds; the same signature again, even from new lists, never does.
|
||||
var m = Fresh();
|
||||
var (bodies, joints) = Chain();
|
||||
Check(m.Update(bodies, joints) && m.Builds == 1 && m.Shape is not null, "the first update did not build the puppet once");
|
||||
Check(m.Update(bodies, joints) && m.Shape is not null, "the first update did not build the puppet");
|
||||
var first = m.Shape;
|
||||
var (again, againJoints) = Chain();
|
||||
Check(!m.Update(again, againJoints) && m.Builds == 1, "an unchanged signature rebuilt the puppet");
|
||||
Check(!m.Update(again, againJoints) && ReferenceEquals(m.Shape, first), "an unchanged signature rebuilt the puppet");
|
||||
|
||||
// Poses and joint origins alone are not topology: the bind is the first sight.
|
||||
var moved = Chain();
|
||||
for (int i = 0; i < moved.Bodies.Count; i++) moved.Bodies[i] = moved.Bodies[i] with { Bind = Rigid.FromQuaternion(0, 0, 0, 1, new float3(0.5f, 2f + i, 0)) };
|
||||
moved.Joints[0] = moved.Joints[0] with { Origin = new float3(9, 9, 9) };
|
||||
var before = m.Shape;
|
||||
Check(!m.Update(moved.Bodies, moved.Joints) && m.Builds == 1 && ReferenceEquals(m.Shape, before), "bodies that only moved rebuilt the puppet");
|
||||
Check(!m.Update(moved.Bodies, moved.Joints) && ReferenceEquals(m.Shape, first), "bodies that only moved rebuilt the puppet");
|
||||
|
||||
// Each change of topology rebuilds exactly once, and then holds.
|
||||
void Changes(string what, Action<List<PuppetBody>, List<PuppetJointLane>> edit)
|
||||
|
|
@ -56,9 +56,11 @@ public static class PuppetChecks
|
|||
var model = Fresh();
|
||||
var (b, j) = Chain();
|
||||
model.Update(b, j);
|
||||
var built = model.Shape;
|
||||
edit(b, j);
|
||||
Check(model.Update(b, j) && model.Builds == 2, $"{what}: the signature changed and the puppet was not rebuilt once");
|
||||
Check(!model.Update(b, j) && model.Builds == 2, $"{what}: the new signature rebuilt again");
|
||||
Check(model.Update(b, j) && !ReferenceEquals(model.Shape, built), $"{what}: the signature changed and the puppet was not rebuilt");
|
||||
var rebuilt = model.Shape;
|
||||
Check(!model.Update(b, j) && ReferenceEquals(model.Shape, rebuilt), $"{what}: the new signature rebuilt again");
|
||||
}
|
||||
Changes("a joint removed", (b, j) => j.RemoveAt(1));
|
||||
Changes("a body added", (b, j) => b.Add(Body(13, Box3DSoaKind.Sphere, 0.05f, 0f, 1.3f)));
|
||||
|
|
@ -71,7 +73,7 @@ public static class PuppetChecks
|
|||
// Past the skin's bone count nothing is drawn, once, and the signature still decides.
|
||||
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 && many.Builds == 0, "more shape bodies than bones was drawn");
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public partial class Smoke : Node
|
|||
// A Reset is not a topology change: the mesh stays the one built at startup. Checked after three resets so a rebuild per
|
||||
// Reset fails here, not after hundreds.
|
||||
for (ulong seed = 1; seed <= 3; seed++) { PressReset(seed); await Frame(); }
|
||||
Check(_main.Bodies.PuppetShape?.Builds == 1, $"the puppet mesh was built {_main.Bodies.PuppetShape?.Builds} times by the third Reset; the signature never changed, so once");
|
||||
Check(_main.Bodies.PuppetMeshBuilds == 1, $"the puppet mesh was built {_main.Bodies.PuppetMeshBuilds} times by the third Reset; the signature never changed, so once");
|
||||
if (_failures.Count > 0) return;
|
||||
|
||||
// Seed 1 at the default intensity against the headless run: events, and the hand at ticks 240 and 1500.
|
||||
|
|
@ -130,7 +130,7 @@ public partial class Smoke : Node
|
|||
await Frame();
|
||||
}
|
||||
Check(_main.Seed == 1399, $"after 400 resets the seed is {_main.Seed}");
|
||||
Check(_main.Bodies.PuppetShape?.Builds == 1, $"the puppet mesh was built {_main.Bodies.PuppetShape?.Builds} times; the signature never changed, so once");
|
||||
Check(_main.Bodies.PuppetMeshBuilds == 1, $"the puppet mesh was built {_main.Bodies.PuppetMeshBuilds} times; the signature never changed, so once");
|
||||
|
||||
// Box off, through the HUD button, at tick 600: the run ends with the will intact and the screen shows the box off.
|
||||
PressReset(Seed);
|
||||
|
|
|
|||
Loading…
Reference in a new issue