The leviathan as a rigged asset: Brokkr recipe, source, rig.ps1 runner, the committed .springrig, importer and file checks
- Asset Sources/Fauna/leviathan.source.glb (Deru's source, LFS) and leviathan.intents.json (the recipe's intents alone): importGltf, brokkr_mesh_polish.repair, .orient (length 1, flip_forward so the head lands at Blender -Y, glTF and Unity +Z), .delight (clusters 3), brokkr_rig.body (spine_bones 8, head -y, Soul's seeds jaw, sac_a, sac_b, fin with x and y negated through the half turn: the receipt names all four parts), .tendrils (tau .04, band .04, dilate .04, stiffness 1.5, stiffness_tip_ratio 0.3, drag 0.08), .colliders, exportGltf. These are the recommended options of questions leviathan-delight (delit) and leviathan-tendril-feel (supple); another ruling is an edit to the intents and a rerun. - tools/blender/fauna/rig.ps1: makes private BLENDER_USER_* directories under -Out, writes the recipe with absolute directories, runs Brokkr's run_intents.py, copies the export to -Dest. Rerun from the source and intents it gave a byte-identical file (sha256 23800FEEC4ADF1A2075A224FB2F8832C89BFF775D93C147A5B88E188040A8ECF). - Assets/Content/Fauna/Leviathan/leviathan.springrig (LFS) and its .meta, whose importer fields carry the swim (amplitude 9, period 3.2 s, 0.1 phase per bone, axis x). Assets/Content is the Addressables folder entry, so the whale is addressable by GUID. - .gitattributes: the .springrig and Asset Sources .glb files are LFS. - SpringRigVerify: importer-builds (the main object, Rig, the mesh's streams and vertex count against glTFast's, BC7 with mips, the Addressables entry, Awake) is the last check of Run; VerifyGlbCases adds the committed asset (exit 0, head at +Z: the spine root rests past the mesh's centre along Z). glTFast's import is one function, Import, for the comparison and the importer check. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67120a0236
commit
d8267e5d09
9 changed files with 184 additions and 14 deletions
|
|
@ -80,8 +80,15 @@ namespace Aetheria.EditorTools
|
|||
Scrap.Clear();
|
||||
if (verdict == null) Debug.Log($"{Tag} PASS handedness");
|
||||
else { Debug.LogError($"{Tag} FAIL handedness: {verdict}"); failed++; }
|
||||
Debug.Log(failed == 0 ? $"{Tag} PASS all" : $"{Tag} FAIL {failed} check(s)");
|
||||
EditorApplication.Exit(failed == 0 ? 0 : 1);
|
||||
ImporterBuilds(built =>
|
||||
{
|
||||
foreach (var go in Scrap) if (go != null) UnityEngine.Object.DestroyImmediate(go);
|
||||
Scrap.Clear();
|
||||
if (built == null) Debug.Log($"{Tag} PASS importer-builds");
|
||||
else { Debug.LogError($"{Tag} FAIL importer-builds: {built}"); failed++; }
|
||||
Debug.Log(failed == 0 ? $"{Tag} PASS all" : $"{Tag} FAIL {failed} check(s)");
|
||||
EditorApplication.Exit(failed == 0 ? 0 : 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -809,12 +816,12 @@ namespace Aetheria.EditorTools
|
|||
("refuses-vacuous-mesh", new Synth { Spine = 4, Chains = 3, Joints = 4, Rot = true, Tiny = true }, "vacuous", null),
|
||||
};
|
||||
int failed = 0, at = 0;
|
||||
// The file run itself, by path: a text file named .springrig and a missing path are exit 1.
|
||||
// The file run itself, by path: the committed asset passes with its head at +Z, a text file named .springrig and a missing path are exit 1.
|
||||
var text = Path.Combine(Path.GetTempPath(), "springrig-not-a-glb.springrig");
|
||||
File.WriteAllText(text, "this is not a GLB");
|
||||
var files = new (string name, string path, int code)[]
|
||||
{
|
||||
("refuses-a-text-file", text, 1), ("refuses-a-missing-path", Path.Combine(Path.GetTempPath(), "springrig-missing.springrig"), 1),
|
||||
("accepts-the-committed-leviathan", AssetFile, 0), ("refuses-a-text-file", text, 1), ("refuses-a-missing-path", Path.Combine(Path.GetTempPath(), "springrig-missing.springrig"), 1),
|
||||
};
|
||||
int fileAt = 0;
|
||||
void Next()
|
||||
|
|
@ -824,8 +831,9 @@ namespace Aetheria.EditorTools
|
|||
var (fileName, path, code) = files[fileAt++];
|
||||
GlbFile(path, (got, verdict) =>
|
||||
{
|
||||
if (got == code) Debug.Log($"{Tag} PASS glb file {fileName}: exit {got}");
|
||||
else { Debug.LogError($"{Tag} FAIL glb file {fileName}: expected exit {code}, got {got} ({verdict})"); failed++; }
|
||||
string head = got == 0 && code == 0 ? HeadForward(path) : null;
|
||||
if (got == code && head == null) Debug.Log($"{Tag} PASS glb file {fileName}: exit {got}");
|
||||
else { Debug.LogError($"{Tag} FAIL glb file {fileName}: expected exit {code}, got {got} ({verdict ?? head})"); failed++; }
|
||||
foreach (var go in Scrap) if (go != null) UnityEngine.Object.DestroyImmediate(go);
|
||||
Scrap.Clear();
|
||||
Next();
|
||||
|
|
@ -851,6 +859,51 @@ namespace Aetheria.EditorTools
|
|||
Next();
|
||||
}
|
||||
|
||||
// The committed leviathan, by the path the importer and the checks share.
|
||||
const string AssetPath = "Assets/Content/Fauna/Leviathan/leviathan.springrig";
|
||||
static string AssetFile => Path.GetFullPath(AssetPath);
|
||||
|
||||
// The importer's product for the committed leviathan: a main object with SpringRig (Rig set; Awake initializes it), the mesh in
|
||||
// SpringSkin's streams with as many vertices as glTFast makes of the same file, a BC7 base colour with mips on the material, and an
|
||||
// Addressables entry (the folder entry Assets/Content covers it).
|
||||
static void ImporterBuilds(Action<string> done)
|
||||
{
|
||||
var main = AssetDatabase.LoadAssetAtPath<GameObject>(AssetPath);
|
||||
if (main == null) { done($"{AssetPath} imported no main object (see the import errors above)"); return; }
|
||||
var spring = main.GetComponent<SpringRig>();
|
||||
if (spring == null || spring.Rig == null) { done("the main object has no SpringRig with a Rig"); return; }
|
||||
var mesh = AssetDatabase.LoadAssetAtPath<Mesh>(AssetPath);
|
||||
if (mesh == null || main.GetComponent<MeshFilter>().sharedMesh != mesh) { done("the main object's mesh is not the asset's mesh"); return; }
|
||||
if (mesh.GetVertexAttributeFormat(VertexAttribute.BlendWeight) != VertexAttributeFormat.Float32 || mesh.GetVertexAttributeDimension(VertexAttribute.BlendWeight) != 4
|
||||
|| mesh.GetVertexAttributeFormat(VertexAttribute.BlendIndices) != VertexAttributeFormat.UInt32 || mesh.GetVertexAttributeDimension(VertexAttribute.BlendIndices) != 4)
|
||||
{ done("the mesh does not carry BlendWeight Float32x4 and BlendIndices UInt32x4"); return; }
|
||||
var texture = main.GetComponent<MeshRenderer>().sharedMaterial.GetTexture("_MainTex") as Texture2D;
|
||||
if (texture == null || texture.format != TextureFormat.BC7 || texture.mipmapCount < 2) { done($"the base colour is {(texture == null ? "missing" : texture.format + " with " + texture.mipmapCount + " mips")}, not BC7 with mips"); return; }
|
||||
var entry = UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(AssetDatabase.AssetPathToGUID(AssetPath), true);
|
||||
if (entry == null) { done("Addressables has no entry for the asset (Assets/Content is the folder entry)"); return; }
|
||||
var clone = UnityEngine.Object.Instantiate(main);
|
||||
Scrap.Add(clone);
|
||||
typeof(SpringRig).GetMethod("Awake", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(clone.GetComponent<SpringRig>(), null);
|
||||
if (clone.GetComponent<SpringRig>().Data == null) { done("Awake did not initialize the rig from Rig"); return; }
|
||||
Import(File.ReadAllBytes(AssetFile), (root, why) =>
|
||||
{
|
||||
var smr = root.GetComponentInChildren<SkinnedMeshRenderer>();
|
||||
done(why ?? (smr == null ? "glTFast made no skinned mesh" : smr.sharedMesh.vertexCount == mesh.vertexCount ? null : $"the imported mesh has {mesh.vertexCount} vertices, glTFast's has {smr.sharedMesh.vertexCount}"));
|
||||
});
|
||||
}
|
||||
|
||||
// The head is at +Z: the spine's root bone sits, at rest, past the centre of the imported mesh's bounds along Z, which is where SpringRig's
|
||||
// heading (its rotation) points the whale. A recipe whose head lands at -Z fails here.
|
||||
static string HeadForward(string path)
|
||||
{
|
||||
var data = SpringRigData.FromGlb(File.ReadAllBytes(path));
|
||||
var mesh = AssetDatabase.LoadAssetAtPath<Mesh>(AssetPath);
|
||||
if (mesh == null) return $"{AssetPath} imported no mesh";
|
||||
int root = Enumerable.Range(0, data.BoneCount).First(i => data.Parent[i] < 0);
|
||||
Fk(data, 0, NoSwim, default, quaternion.identity, 1, out var rest, out _);
|
||||
return rest[root].z > mesh.bounds.center.z ? null : $"the spine root sits at z {rest[root].z}, not past the mesh's centre {mesh.bounds.center.z}: the whale faces -Z";
|
||||
}
|
||||
|
||||
// A Disturbance moves what glTFast imported at a named point of the comparison: only VerifyGlbCases passes one, to give a check a
|
||||
// known error. Imported: before the bind and rest poses are compared (a bind pose or a rest node moved). Posed: after the rig
|
||||
// posed the bones and before Unity bakes the skin (a bone moved).
|
||||
|
|
@ -869,12 +922,13 @@ namespace Aetheria.EditorTools
|
|||
const double BindTolerance = 7.8e-5, PoseTolerance = 7.8e-5;
|
||||
|
||||
// disturb moves the imported skeleton: only VerifyGlbCases passes one.
|
||||
static void ImportAndCompare(byte[] glb, SpringRigData data, Action<string> done, Disturbance? disturb = null)
|
||||
// glTFast imports and instantiates the GLB into a scratch root, driven by the editor's update loop (it resumes on the main thread, so
|
||||
// it is not waited on). done gets the root and null, or the root and why there is no scene.
|
||||
static void Import(byte[] glb, Action<GameObject, string> done)
|
||||
{
|
||||
var root = new GameObject("imported");
|
||||
Scrap.Add(root);
|
||||
var gltf = new GLTFast.GltfImport(deferAgent: new GLTFast.UninterruptedDeferAgent());
|
||||
// glTFast resumes on the main thread, so the import is driven by the editor's update loop, not waited on.
|
||||
var load = gltf.LoadGltfBinary(glb, new Uri("file:///spring-rig.glb"));
|
||||
System.Threading.Tasks.Task<bool> instantiate = null;
|
||||
var clock = Stopwatch.StartNew();
|
||||
|
|
@ -885,17 +939,22 @@ namespace Aetheria.EditorTools
|
|||
bool failed = (load.IsCompleted && !load.Result) || clock.Elapsed.TotalSeconds > 120;
|
||||
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, disturb); }
|
||||
catch (Exception e) { verdict = "exception: " + e; }
|
||||
done(verdict);
|
||||
done(root, failed ? "glTFast did not import the GLB" : instantiate.Result ? null : "glTFast did not instantiate the scene");
|
||||
};
|
||||
EditorApplication.update += poll;
|
||||
}
|
||||
|
||||
static string HandednessCompare(SpringRigData data, GameObject root, bool instantiated, Disturbance? disturb)
|
||||
static void ImportAndCompare(byte[] glb, SpringRigData data, Action<string> done, Disturbance? disturb = null) =>
|
||||
Import(glb, (root, why) =>
|
||||
{
|
||||
string verdict;
|
||||
try { verdict = why ?? HandednessCompare(data, root, disturb); }
|
||||
catch (Exception e) { verdict = "exception: " + e; }
|
||||
done(verdict);
|
||||
});
|
||||
|
||||
static string HandednessCompare(SpringRigData data, GameObject root, Disturbance? disturb)
|
||||
{
|
||||
if (!instantiated) return "glTFast did not instantiate the scene";
|
||||
var smr = root.GetComponentInChildren<SkinnedMeshRenderer>();
|
||||
if (smr == null || smr.bones.Length != data.BoneCount) return "glTFast made no skinned mesh with the rig's bones";
|
||||
if (disturb is { When: Phase.Imported } early) early.Act(smr);
|
||||
|
|
|
|||
Loading…
Reference in a new issue