SpringRigVerify.VerifyGlbCases: pin the file path on edited Synth GLBs (unknown required extension, joint past bones, skin off by a known amount, vacuous mesh)
CheckGlb is the one FromGlb-then-compare path; VerifyGlb and the cases share it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b48cdbf752
commit
ef31edc90c
1 changed files with 72 additions and 11 deletions
|
|
@ -24,6 +24,7 @@ namespace Aetheria.EditorTools
|
|||
/// Unity -batchmode -projectPath <repo> -executeMethod Aetheria.EditorTools.SpringRigVerify.Run -logFile <path>
|
||||
/// VerifyGlb runs the rig contract's own parse (SpringRigData.FromGlb) and the glTFast skin comparison on the GLB at
|
||||
/// SPRINGRIG_GLB (same flags, method VerifyGlb); it adds no rule of its own.
|
||||
/// VerifyGlbCases pins its verdicts on edited Synth GLBs (same flags); its exit code is pinned by running VerifyGlb on a refused GLB (exit 1).
|
||||
/// Capture renders a short swim to PNG frames in SPRINGRIG_CAPTURE_OUT (same flags, method Capture).
|
||||
/// </summary>
|
||||
public static class SpringRigVerify
|
||||
|
|
@ -698,27 +699,82 @@ namespace Aetheria.EditorTools
|
|||
EditorApplication.Exit(1);
|
||||
return;
|
||||
}
|
||||
SpringRigData data;
|
||||
byte[] glb;
|
||||
try { glb = File.ReadAllBytes(path); data = SpringRigData.FromGlb(glb); }
|
||||
try { glb = File.ReadAllBytes(path); }
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"{Tag} FAIL glb: {e.Message}");
|
||||
EditorApplication.Exit(1);
|
||||
return;
|
||||
}
|
||||
Debug.Log($"{Tag} glb {path}: bones {data.BoneCount}, bodies {data.BodyCount}, chains {data.ChainCount}, spring joints {data.SpringJointCount}, max chain length {data.MaxChainLength}, colliders {data.Colliders.Count}");
|
||||
ImportAndCompare(glb, data, verdict =>
|
||||
CheckGlb(glb, verdict =>
|
||||
{
|
||||
foreach (var go in Scrap) if (go != null) UnityEngine.Object.DestroyImmediate(go);
|
||||
Scrap.Clear();
|
||||
if (verdict == null) Debug.Log($"{Tag} PASS glb");
|
||||
else Debug.LogError($"{Tag} FAIL glb: {verdict}");
|
||||
EditorApplication.Exit(verdict == null ? 0 : 1);
|
||||
});
|
||||
}
|
||||
|
||||
static void ImportAndCompare(byte[] glb, SpringRigData data, Action<string> done)
|
||||
// FromGlb, then the glTFast comparison: null is a pass, else the owner's refusal or the comparison's verdict.
|
||||
static void CheckGlb(byte[] glb, Action<string> done, Action<SkinnedMeshRenderer> disturb = null)
|
||||
{
|
||||
SpringRigData data;
|
||||
try { data = SpringRigData.FromGlb(glb); }
|
||||
catch (Exception e) { done(e.Message); return; }
|
||||
Debug.Log($"{Tag} glb: bones {data.BoneCount}, bodies {data.BodyCount}, chains {data.ChainCount}, spring joints {data.SpringJointCount}, max chain length {data.MaxChainLength}, colliders {data.Colliders.Count}");
|
||||
ImportAndCompare(glb, data, verdict =>
|
||||
{
|
||||
foreach (var go in Scrap) if (go != null) UnityEngine.Object.DestroyImmediate(go);
|
||||
Scrap.Clear();
|
||||
done(verdict);
|
||||
}, disturb);
|
||||
}
|
||||
|
||||
// VerifyGlb's own pins: each GLB is a Synth rig edited one way; the verdict must be the expected one (null a pass, else a
|
||||
// substring of the refusal). Kills a VerifyGlb that exits 0 after FAIL, reads a failed import as PASS, compares the wrong
|
||||
// GLB, swallows the comparison's exception, drops the vacuity guard or widens the tolerance.
|
||||
// ... -executeMethod Aetheria.EditorTools.SpringRigVerify.VerifyGlbCases
|
||||
public static void VerifyGlbCases()
|
||||
{
|
||||
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null)
|
||||
{
|
||||
Debug.LogError($"{Tag} FAIL: no graphics device in this session; rerun batchmode without -nographics.");
|
||||
EditorApplication.Exit(1);
|
||||
return;
|
||||
}
|
||||
Synth Base() => new Synth { Spine = 4, Chains = 3, Joints = 4, Rot = true };
|
||||
var cases = new (string name, Synth rig, string expect, Action<SkinnedMeshRenderer> disturb)[]
|
||||
{
|
||||
("accepts-synth", Base(), null, null),
|
||||
("refuses-by-owner", new Synth { Spine = 4, Chains = 3, Joints = 4, Rot = true, Edit = j => j["nodes"][1]["scale"] = new JArray(2, 1, 1) }, "non-unit scale", null),
|
||||
("refuses-unknown-required-extension", new Synth { Spine = 4, Chains = 3, Joints = 4, Rot = true, Edit = j => j["extensionsRequired"] = new JArray("KHR_not_a_real_extension") }, "glTFast did not import", null),
|
||||
("refuses-joint-past-bones", new Synth { Spine = 4, Chains = 3, Joints = 4, Rot = true, BadJoint = true }, "exception", null),
|
||||
("refuses-skin-off-by-a-known-amount", new Synth { Spine = 4, Chains = 3, Joints = 4, Rot = true }, "Unity skins a vertex 0.02", smr => smr.bones[1].position += new Vector3(0.02f, 0, 0)),
|
||||
("refuses-vacuous-mesh", new Synth { Spine = 4, Chains = 3, Joints = 4, Rot = true, Tiny = true }, "vacuous", null),
|
||||
};
|
||||
int failed = 0, at = 0;
|
||||
void Next()
|
||||
{
|
||||
if (at == cases.Length)
|
||||
{
|
||||
Debug.Log(failed == 0 ? $"{Tag} PASS all glb cases" : $"{Tag} FAIL {failed} glb case(s)");
|
||||
EditorApplication.Exit(failed == 0 ? 0 : 1);
|
||||
return;
|
||||
}
|
||||
var (name, rig, expect, disturb) = cases[at++];
|
||||
CheckGlb(rig.Glb(), verdict =>
|
||||
{
|
||||
bool ok = expect == null ? verdict == null : verdict != null && verdict.Contains(expect);
|
||||
if (ok) Debug.Log($"{Tag} PASS glb case {name}: {verdict ?? "accepted"}");
|
||||
else { Debug.LogError($"{Tag} FAIL glb case {name}: expected {expect ?? "accept"}, got {verdict ?? "accept"}"); failed++; }
|
||||
Next();
|
||||
}, disturb);
|
||||
}
|
||||
Next();
|
||||
}
|
||||
|
||||
// disturb moves the imported skeleton after it is posed: only VerifyGlbCases passes one, to give the comparison a known skin error.
|
||||
static void ImportAndCompare(byte[] glb, SpringRigData data, Action<string> done, Action<SkinnedMeshRenderer> disturb = null)
|
||||
{
|
||||
var root = new GameObject("imported");
|
||||
Scrap.Add(root);
|
||||
|
|
@ -735,14 +791,14 @@ namespace Aetheria.EditorTools
|
|||
if (!failed && (instantiate == null || !instantiate.IsCompleted)) return;
|
||||
EditorApplication.update -= poll;
|
||||
string verdict;
|
||||
try { verdict = failed ? "glTFast did not import the GLB" : HandednessCompare(data, root, instantiate.Result); }
|
||||
try { verdict = failed ? "glTFast did not import the GLB" : HandednessCompare(data, root, instantiate.Result, disturb); }
|
||||
catch (Exception e) { verdict = "exception: " + e; }
|
||||
done(verdict);
|
||||
};
|
||||
EditorApplication.update += poll;
|
||||
}
|
||||
|
||||
static string HandednessCompare(SpringRigData data, GameObject root, bool instantiated)
|
||||
static string HandednessCompare(SpringRigData data, GameObject root, bool instantiated, Action<SkinnedMeshRenderer> disturb)
|
||||
{
|
||||
if (!instantiated) return "glTFast did not instantiate the scene";
|
||||
var smr = root.GetComponentInChildren<SkinnedMeshRenderer>();
|
||||
|
|
@ -767,6 +823,7 @@ namespace Aetheria.EditorTools
|
|||
rig.Initialize(data, mesh.bounds);
|
||||
for (int f = 0; f < 90; f++) rig.Present(f * Dt, Vector3.zero, Quaternion.identity, 1);
|
||||
for (int i = 0; i < data.BoneCount; i++) smr.bones[i].SetPositionAndRotation((Vector3)rig.BonePosition(i), (Quaternion)rig.BoneRotation(i));
|
||||
disturb?.Invoke(smr);
|
||||
var baked = new Mesh();
|
||||
smr.BakeMesh(baked, true);
|
||||
var bakedVerts = baked.vertices; var vertices = mesh.vertices; var weights = mesh.boneWeights;
|
||||
|
|
@ -852,6 +909,8 @@ namespace Aetheria.EditorTools
|
|||
public Vector3 Seg = new Vector3(0, -0.1f, -0.3f);
|
||||
public float3 GravityDir = new float3(0, -1, 0);
|
||||
public bool Rot;
|
||||
public Action<JObject> Edit; // Glb(): edits the glTF JSON last (cases of VerifyGlbCases)
|
||||
public bool BadJoint, Tiny; // Glb(): a joint index past the bones; the whole mesh a speck at the root bone
|
||||
public JArray Colliders; // null: a sphere on every spine bone but the root
|
||||
|
||||
public float3[] World; // rest world position and rotation per node, glTF space, set by Build
|
||||
|
|
@ -929,9 +988,10 @@ namespace Aetheria.EditorTools
|
|||
for (int i = 0; i < n; i++)
|
||||
foreach (var o in new[] { new float3(0, 0.12f, 0), new float3(0, -0.12f, 0), new float3(0, 0, 0.3f) })
|
||||
{
|
||||
var p = World[i] + math.mul(WorldRot[i], o);
|
||||
var p = Tiny ? World[0] + o * 0.01f : World[i] + math.mul(WorldRot[i], o);
|
||||
positions.AddRange(new[] { p.x, p.y, p.z }); normals.AddRange(new[] { 1f, 0, 0 });
|
||||
joints.AddRange(new[] { (byte)i, (byte)(ParentOf[i] >= 0 ? ParentOf[i] : i), (byte)0, (byte)0 }); weights.AddRange(new[] { 0.6f, 0.4f, 0, 0 });
|
||||
if (Tiny) { joints.AddRange(new byte[4]); weights.AddRange(new[] { 1f, 0, 0, 0 }); }
|
||||
else { joints.AddRange(new[] { (byte)(BadJoint && i == 0 ? 200 : i), (byte)(ParentOf[i] >= 0 ? ParentOf[i] : i), (byte)0, (byte)0 }); weights.AddRange(new[] { 0.6f, 0.4f, 0, 0 }); }
|
||||
}
|
||||
var chunks = new[] { ibm, Bytes(positions), Bytes(normals), joints.ToArray(), Bytes(weights), Bytes(Enumerable.Range(0, v).ToArray()) };
|
||||
var views = (JArray)json["bufferViews"]; var accessors = (JArray)json["accessors"];
|
||||
|
|
@ -954,6 +1014,7 @@ namespace Aetheria.EditorTools
|
|||
((JArray)json["nodes"]).Add(new JObject { ["name"] = "mesh", ["mesh"] = 0, ["skin"] = 0 });
|
||||
json["scenes"] = new JArray(new JObject { ["nodes"] = new JArray(0, n) });
|
||||
json["scene"] = 0;
|
||||
Edit?.Invoke(json);
|
||||
var jsonBytes = Pad(System.Text.Encoding.UTF8.GetBytes(json.ToString(Newtonsoft.Json.Formatting.None)), 32);
|
||||
var bin = Pad(chunks.SelectMany(c => c).ToArray(), 0);
|
||||
var glb = new List<byte>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue