SpringRig: a return to Full mid-ease continues from the drawn pose; ease 0.75 s; bounds checked at both scales

Findings of cut-whale-rig-s1.s3 (ease-reentry-pops, ease-moves-fast, bounds-scale-one-sided).
- Present keeps a copy of the bone positions it drew and seeds the solver from it when the level returns to Full while the ease is
  part way (_restWeight < 1); a first Initialize, a fully eased return and a root jump still reset to rest.
- BlendSeconds 0.25 -> 0.75.
- SpringRig gets a serialized TextAsset Rig: Awake (and an Initialize() for editor code, where Awake does not run) builds the rig from it
  and the object's mesh.
- reentry-is-continuous: leave Full for 3 and for 8 frames and return; the returning frame's tip motion beyond rigid is under 0.41 of the
  chain. Margin rule: shipped worst 0.172, reset-to-rest mutant 0.970 (3 frames) and 1.207 (8), geometric mean 0.41.
- bounds-follow-the-swim runs at scale 1.5 and 0.6; a BoundsJob that ignores scale puts a vertex 1.24 outside at 0.6.
- freeze-and-reset derives its ease frame count from BlendSeconds.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nibu-hands 2026-12-01 11:00:32 +01:00 • committed by soul
commit c24f76f47a
3 changed files with 79 additions and 11 deletions

View file

@ -62,6 +62,7 @@ namespace Aetheria.EditorTools
int failed = 0;
foreach (var (name, body) in checks)
{
("reentry-is-continuous", ReentryIsContinuous),
string verdict;
try { verdict = body(); }
catch (Exception e) { verdict = "exception: " + e; }
@ -302,7 +303,7 @@ namespace Aetheria.EditorTools
if (snap > 0.15) return $"the first frozen frame moved a tip {snap:P0} of its chain (a snap, not an ease)";
t += Dt;
w.Swim.AmplitudeDegrees = 15;
for (int i = 0; i < 30; i++, t += Dt) w.Present(t, new Vector3(Mathf.Sin((float)t * 5), 0, 0), Quaternion.identity, 1); // the ease ends at BlendSeconds
for (int i = 0, eased = (int)math.ceil(w.BlendSeconds / Dt) + 2; i < eased; i++, t += Dt) w.Present(t, new Vector3(Mathf.Sin((float)t * 5), 0, 0), Quaternion.identity, 1); // the ease ends at BlendSeconds
int jobs = w.SolveJobsScheduled;
double rest = 0;
for (int i = 0; i < 10; i++, t += Dt)
@ -619,8 +620,11 @@ namespace Aetheria.EditorTools
return jumped.Resets == 3 ? null : $"a jump of 500 u at scale 4 reset {jumped.Resets - 1} extra times, expected 2 (out and back)";
}
// Bounds follow the pose: every skinned vertex stays inside the renderer's bounds at a swim amplitude that moves the body.
static string BoundsFollowTheSwim()
// Bounds follow the pose: every skinned vertex stays inside the renderer's bounds at a swim amplitude that moves the body, at a
// scale above 1 (a bounds job that ignores scale is too large, which still holds every vertex) and below it (too small).
static string BoundsFollowTheSwim() => BoundsCase(1.5f) ?? BoundsCase(0.6f);
static string BoundsCase(float scale)
{
var s = new Synth { Gravity = 0.5f, Stiffness = 2, Colliders = new JArray() };
var go = new GameObject("boundsTest");
@ -636,7 +640,7 @@ namespace Aetheria.EditorTools
double worst = 0; Bounds first = default, last = default;
for (int f = 0; f < 300; f++)
{
rig.Present(f * Dt, new Vector3(0, 0, f * 0.05f), Quaternion.Euler(0, f * 0.5f, 0), 1.5f);
rig.Present(f * Dt, new Vector3(0, 0, f * 0.05f), Quaternion.Euler(0, f * 0.5f, 0), scale);
var b = rig.Renderer.localBounds;
if (f == 0) first = b; last = b;
for (int v = 0; v < verts.Count; v++)
@ -647,8 +651,52 @@ namespace Aetheria.EditorTools
worst = math.max(worst, math.cmax(outside));
}
}
if (worst > 1e-3) return $"a skinned vertex lies {worst} outside the bounds";
return first.size != last.size ? null : "the bounds never changed (vacuous)";
if (worst > 1e-3) return $"at scale {scale} a skinned vertex lies {worst} outside the bounds";
return first.size != last.size ? null : $"at scale {scale} the bounds never changed (vacuous)";
}
// Returning to Full part way through the ease continues from the pose last drawn: the returning frame moves a tip, relative to its
// chain root, a small part of the chain; a reset to rest moves it by nearly all of the distance the tip had left (Soul read 96% of
// the chain after 3 frames out with the old quarter-second ease). Readings with the 0.75 s ease, the largest over the two cases
// (3 and 8 frames out): shipped 0.172; the reset-to-rest mutant least 0.970 (0.970 and 1.207). The bound is
// lodur:ruling:deterministic-bound-margin's geometric mean sqrt(0.172 x 0.970) = 0.41, a separation of 2.4 on each side.
const double ReentryBound = 0.41;
static string ReentryIsContinuous()
{
var shortOut = ReentryCase(3);
var longOut = ReentryCase(8); // both run, so both readings are logged
return shortOut ?? longOut;
}
static string ReentryCase(int framesOut)
{
var cam = new GameObject("lodCam").AddComponent<Camera>();
Scrap.Add(cam.gameObject);
cam.fieldOfView = 60;
var s = new Synth { Gravity = 0, Stiffness = 4 };
var w = Whale(s, out var data);
w.LodCamera = cam;
w.Swim.AmplitudeDegrees = 0;
var chains = Enumerable.Range(0, data.ChainCount).Select(c => data.ChainBones(c)).ToArray();
float3[] Rel() => chains.Select(b => w.BonePosition(b[b.Count - 1]) - w.BonePosition(b[0])).ToArray();
double chainLength = (s.Joints - 1) * math.length(s.Seg);
cam.transform.position = new Vector3(0, 0, -50);
double t = 0;
Vector3 At() => new Vector3(Mathf.Sin((float)t * 5) * 3.2f, 0, 0);
for (; t < 3; t += Dt) w.Present(t, At(), Quaternion.identity, 1);
if (w.Level != SpringLod.Full) return "near whale is not Full";
cam.transform.position = new Vector3(0, 0, -300);
for (int i = 0; i < framesOut; i++, t += Dt) w.Present(t, At(), Quaternion.identity, 1);
if (w.Level != SpringLod.Frozen) return "far whale is not Frozen";
var drawn = Rel();
cam.transform.position = new Vector3(0, 0, -50);
if (w.Present(t, At(), Quaternion.identity, 1) != SpringLod.Full) return "near whale did not return to Full";
var back = Rel();
double moved = 0;
for (int c = 0; c < drawn.Length; c++) moved = math.max(moved, math.distance(back[c], drawn[c]) / chainLength);
Debug.Log($"{Tag} reentry after {framesOut} frames out: the returning frame moved a tip {moved:P1} of its chain (bound {ReentryBound:P1})");
return moved <= ReentryBound ? null : $"returning after {framesOut} frames out moved a tip {moved:P0} of its chain in one frame (a reset to rest, not a continuation)";
}
// Hovering at the Full threshold must not flip the level every frame.

View file

@ -26,6 +26,8 @@ namespace Aetheria.FaunaDisplay
public const int SubstepRate = 120;
public const int MaxSubsteps = 4;
[Tooltip("The rig's GLB (a .springrig the importer wraps). Awake initializes from it when set; callers that Initialize by hand leave it null.")]
public TextAsset Rig;
public MeshRenderer Renderer;
public SwimSettings Swim = SwimSettings.Default;
[Tooltip("Projected height of the whale as a fraction of the viewport at or above which the tendrils are solved.")]
@ -34,8 +36,8 @@ namespace Aetheria.FaunaDisplay
public float FrozenAbove = 0.015f;
[Tooltip("A level is left only once the projected height is this fraction below the threshold that entered it.")]
[Range(0f, 0.5f)] public float Hysteresis = 0.15f;
[Tooltip("Drawn seconds over which the tendrils ease to rest when the level leaves Full.")]
public float BlendSeconds = 0.25f;
[Tooltip("Drawn seconds over which the tendrils ease to rest when the level leaves Full: 0.5 to 1 reads as settling, a quarter second as a flare.")]
public float BlendSeconds = 0.75f;
public Camera LodCamera;
public SpringRigData Data { get; private set; }
@ -49,7 +51,7 @@ namespace Aetheria.FaunaDisplay
public quaternion BoneRotation(int bone) => _boneRot[bone];
NativeArray<int> _order, _parent, _spine, _chainStart, _chainLen, _chainBone, _chainColStart, _chainColLen, _chainCol;
NativeArray<float3> _restPos, _bonePos, _simPos, _simPrev;
NativeArray<float3> _restPos, _bonePos, _simPos, _simPrev, _drawn;
NativeArray<quaternion> _restRot, _boneRot;
NativeArray<float4x4> _bind, _skin;
NativeArray<SpringJointParams> _param;
@ -90,6 +92,7 @@ namespace Aetheria.FaunaDisplay
_bonePos = Own<float3>(n);
_simPos = Own<float3>(n);
_simPrev = Own<float3>(n);
_drawn = Own<float3>(n);
_boneRot = Own<quaternion>(n);
_skin = Own<float4x4>(n);
_minMax = Own<float3>(2);
@ -133,11 +136,14 @@ namespace Aetheria.FaunaDisplay
// Leaving Full the tendrils ease to rest over BlendSeconds of drawn time (no snap); the solver still draws, with no steps.
double dt = _started ? math.max(drawnTime - _lastTime, 0) : 0;
_lastTime = drawnTime;
bool midEase = _everFull && _restWeight < 1f; // a return to Full from here starts from the pose last drawn, not from rest
if (full) { _restWeight = 0f; _everFull = true; _lastFrac = frac; }
else if (_everFull) _restWeight = (float)math.min(1.0, _restWeight + dt / math.max(BlendSeconds, 1e-4f));
bool easing = !full && _everFull && _restWeight < 1f;
bool reset = !_started || (full && !_wasFull) || math.distance(_lastPosition, position) > Data.MaxChainLength * scale;
bool jumped = math.distance(_lastPosition, position) > Data.MaxChainLength * scale;
bool reset = !_started || (full && !_wasFull) || jumped;
bool seedDrawn = reset && _started && !jumped && full && !_wasFull && midEase;
_started = true;
_wasFull = full;
_lastPosition = position;
@ -159,6 +165,7 @@ namespace Aetheria.FaunaDisplay
chainStart = _chainStart, chainLen = _chainLen, chainBone = _chainBone, chainColStart = _chainColStart, chainColLen = _chainColLen,
chainCol = _chainCol, restPos = _restPos, restRot = _restRot, param = _param, colliders = _colliders,
bonePos = _bonePos, boneRot = _boneRot, simPos = _simPos, simPrev = _simPrev,
drawn = _drawn, seedDrawn = seedDrawn,
substeps = steps, step = 1f / SubstepRate, scale = scale, frac = full ? frac : _lastFrac, blend = full ? 0f : _restWeight, reset = reset,
}.Schedule(Data.ChainCount, 4, pose);
}
@ -168,6 +175,7 @@ namespace Aetheria.FaunaDisplay
}.Schedule(Data.BoneCount, 64, pose);
new BoundsJob { bonePos = _bonePos, rootPos = pos, rootRot = rot, scale = scale, minMax = _minMax }.Schedule(skinned).Complete();
SkinBuffer.SetData(_skin);
_drawn.CopyFrom(_bonePos);
var t = Renderer.transform;
t.SetPositionAndRotation(position, rotation);
@ -199,6 +207,15 @@ namespace Aetheria.FaunaDisplay
SkinBuffer = null;
}
// From the serialized Rig and this object's mesh. Awake calls it in play; an editor tool that instantiates the asset outside play
// (Awake does not run there) calls it itself.
public void Initialize() => Initialize(SpringRigData.FromGlb(Rig.bytes), GetComponent<MeshFilter>().sharedMesh.bounds);
void Awake()
{
if (Rig != null && Data == null) Initialize();
}
void OnDestroy() => Release();
}
}

View file

@ -50,6 +50,9 @@ namespace Aetheria.FaunaDisplay
[ReadOnly] public NativeArray<quaternion> restRot;
[ReadOnly] public NativeArray<SpringJointParams> param;
[ReadOnly] public NativeArray<SpringCollider> colliders;
// The bone positions drawn last frame; a reset seeds from them when seedDrawn (a return to Full part way through the ease), from rest otherwise.
[ReadOnly] public NativeArray<float3> drawn;
public bool seedDrawn;
// Bone-indexed. A chain writes only its own bones; colliders read body bones only.
[NativeDisableParallelForRestriction] public NativeArray<float3> bonePos, simPos, simPrev;
[NativeDisableParallelForRestriction] public NativeArray<quaternion> boneRot;
@ -64,7 +67,7 @@ namespace Aetheria.FaunaDisplay
for (int k = 0; k < len; k++)
{
int bone = chainBone[start + k];
simPos[bone] = simPrev[bone] = bonePos[bone];
simPos[bone] = simPrev[bone] = seedDrawn ? drawn[bone] : bonePos[bone];
}
int root = chainBone[start];
float3 headPos0 = bonePos[root];