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
2
.gitattributes
vendored
2
.gitattributes
vendored
|
|
@ -55,6 +55,8 @@
|
|||
GameData/*.cc filter=lfs diff=lfs merge=lfs -text
|
||||
GameData/Mods/**/*.cc filter=lfs diff=lfs merge=lfs -text
|
||||
GameData/Mods/**/*.glb filter=lfs diff=lfs merge=lfs -text
|
||||
Assets/Content/**/*.springrig filter=lfs diff=lfs merge=lfs -text
|
||||
"Asset Sources/**/*.glb" filter=lfs diff=lfs merge=lfs -text
|
||||
tests/fixtures/mods/**/*.cc filter=lfs diff=lfs merge=lfs -text
|
||||
tests/fixtures/mods/**/*.glb filter=lfs diff=lfs merge=lfs -text
|
||||
tools/blender/tests/fixtures/*.glb filter=lfs diff=lfs merge=lfs -text
|
||||
|
|
|
|||
12
Asset Sources/Fauna/leviathan.intents.json
Normal file
12
Asset Sources/Fauna/leviathan.intents.json
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
{"action": "importGltf", "filepath": "leviathan.source.glb"},
|
||||
{"action": "brokkr_mesh_polish.repair", "object_name": "d10f161a_8820_489f_9754_0aa0ebd51d44"},
|
||||
{"action": "brokkr_mesh_polish.orient", "object_name": "RootNode", "length": 1.0, "flip_forward": true},
|
||||
{"action": "brokkr_mesh_polish.delight", "object_name": "d10f161a_8820_489f_9754_0aa0ebd51d44", "clusters": 3},
|
||||
{"action": "brokkr_rig.body", "object_name": "d10f161a_8820_489f_9754_0aa0ebd51d44", "spine_bones": 8, "head": "-y",
|
||||
"seeds": "jaw=-0.2323,-0.39,0; sac_a=-0.2498,-0.026,0.0519; sac_b=-0.2597,-0.234,0.0364; fin=-0.1845,0.221,0.1037"},
|
||||
{"action": "brokkr_rig.tendrils", "object_name": "d10f161a_8820_489f_9754_0aa0ebd51d44", "tau": 0.04, "band": 0.04, "dilate": 0.04,
|
||||
"stiffness": 1.5, "stiffness_tip_ratio": 0.3, "drag": 0.08},
|
||||
{"action": "brokkr_rig.colliders", "object_name": "d10f161a_8820_489f_9754_0aa0ebd51d44"},
|
||||
{"action": "exportGltf", "filepath": "leviathan.glb"}
|
||||
]
|
||||
BIN
Asset Sources/Fauna/leviathan.source.glb
(Stored with Git LFS)
Normal file
BIN
Asset Sources/Fauna/leviathan.source.glb
(Stored with Git LFS)
Normal file
Binary file not shown.
8
Assets/Content/Fauna.meta
Normal file
8
Assets/Content/Fauna.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2f7f18edd4c10644ca54e15ecd169c9e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Content/Fauna/Leviathan.meta
Normal file
8
Assets/Content/Fauna/Leviathan.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d522d55aeee549429eeafd12b894a91
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Content/Fauna/Leviathan/leviathan.springrig
(Stored with Git LFS)
Normal file
BIN
Assets/Content/Fauna/Leviathan/leviathan.springrig
(Stored with Git LFS)
Normal file
Binary file not shown.
19
Assets/Content/Fauna/Leviathan/leviathan.springrig.meta
Normal file
19
Assets/Content/Fauna/Leviathan/leviathan.springrig.meta
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3c31de84cff91c419b3d8e5f848b0d2
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 467b0d4c17afeb24e8a27b9be8f80f59, type: 3}
|
||||
Swim:
|
||||
AmplitudeDegrees: 9
|
||||
PeriodSeconds: 3.2
|
||||
PhasePerBone: 0.1
|
||||
Axis:
|
||||
x: 1
|
||||
y: 0
|
||||
z: 0
|
||||
MaxTextureSize: 4096
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
56
tools/blender/fauna/rig.ps1
Normal file
56
tools/blender/fauna/rig.ps1
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# rig.ps1 -Source <glb> -Intents <intents.json> -Out <dir> -Brokkr <checkout> -Dest <file.springrig> [-Blender <exe>]
|
||||
# Rigs a generated creature: runs Brokkr's run_intents.py over <Intents> (a JSON array of intents; the first is
|
||||
# importGltf of <Source>'s file name, the last exportGltf of "leviathan.glb") and copies the export to <Dest>.
|
||||
# This is how a look ruling becomes a rerun: edit the intents (drop delight, change the tendril knobs), run again, and
|
||||
# commit the new <Dest>. Unity import never runs Blender; the .springrig is the committed product.
|
||||
# Blender runs with private BLENDER_USER_CONFIG, BLENDER_USER_EXTENSIONS and BLENDER_USER_SCRIPTS under <Out>\user, so
|
||||
# a person's own Blender folders are never read or written. <Brokkr> is a checkout of GameCult/Brokkr (running Blender
|
||||
# writes __pycache__ into it: use a worktree). <Out> is emptied first; every path Blender sees is absolute.
|
||||
# Launch detached; it logs to <Out>\rig.log and exits 0 when Blender accepted every intent:
|
||||
# Start-Process powershell -ArgumentList '-NoProfile','-File','tools\blender\fauna\rig.ps1','-Source',...
|
||||
param(
|
||||
[Parameter(Mandatory)] [string]$Source,
|
||||
[Parameter(Mandatory)] [string]$Intents,
|
||||
[Parameter(Mandatory)] [string]$Out,
|
||||
[Parameter(Mandatory)] [string]$Brokkr,
|
||||
[Parameter(Mandatory)] [string]$Dest,
|
||||
[string]$Blender = "C:\Program Files (x86)\Steam\steamapps\common\Blender\blender.exe"
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Source = (Resolve-Path $Source).Path
|
||||
$Intents = (Resolve-Path $Intents).Path
|
||||
$Brokkr = (Resolve-Path $Brokkr).Path
|
||||
$Out = [IO.Path]::GetFullPath($Out)
|
||||
$Dest = [IO.Path]::GetFullPath($Dest)
|
||||
if ([IO.Path]::GetPathRoot($Out) -eq $Out) { throw "-Out is a drive root" }
|
||||
if (Test-Path $Out) { Remove-Item -Recurse -Force $Out }
|
||||
$user = "$Out\user"
|
||||
foreach ($kind in "config", "extensions", "scripts") { New-Item -ItemType Directory -Force "$user\$kind" | Out-Null }
|
||||
New-Item -ItemType Directory -Force "$Out\out" | Out-Null
|
||||
$Log = "$Out\rig.log"
|
||||
|
||||
# The intents are spliced in as text, never parsed and re-serialised (Windows PowerShell 5.1 unrolls arrays).
|
||||
$head = [ordered]@{
|
||||
requestedBy = "fauna/rig.ps1"
|
||||
importDir = (Split-Path $Source -Parent)
|
||||
outputDir = "$Out\out"
|
||||
hostAddons = @("brokkr_mesh_polish", "brokkr_rig")
|
||||
saveBlend = "$Out\out\rig.blend"
|
||||
} | ConvertTo-Json -Compress
|
||||
$recipePath = "$Out\recipe.json"
|
||||
$text = $head.TrimEnd("}") + ',"intents":' + (Get-Content $Intents -Raw) + "}"
|
||||
[IO.File]::WriteAllText($recipePath, $text, (New-Object Text.UTF8Encoding $false))
|
||||
|
||||
$env:BLENDER_USER_CONFIG = "$user\config"
|
||||
$env:BLENDER_USER_EXTENSIONS = "$user\extensions"
|
||||
$env:BLENDER_USER_SCRIPTS = "$user\scripts"
|
||||
$runner = "$Brokkr\surfaces\blender\tools\run_intents.py"
|
||||
$run = Start-Process -FilePath $Blender -Wait -PassThru -NoNewWindow -RedirectStandardOutput $Log -RedirectStandardError "$Out\rig.err" `
|
||||
-ArgumentList "--background", "--factory-startup", "--python", "`"$runner`"", "--", "`"$recipePath`"", "`"$Out\receipts.json`""
|
||||
$code = $run.ExitCode
|
||||
if ($code -ne 0) { throw "run_intents exited $code (see $Log and $Out\receipts.json)" }
|
||||
$export = Get-ChildItem "$Out\out" -Filter "*.glb" | Select-Object -First 1
|
||||
if (-not $export) { throw "the recipe exported no .glb" }
|
||||
New-Item -ItemType Directory -Force (Split-Path $Dest -Parent) | Out-Null
|
||||
Copy-Item $export.FullName $Dest -Force
|
||||
"{0} {1}" -f (Get-FileHash $Dest -Algorithm SHA256).Hash, $Dest
|
||||
Loading…
Reference in a new issue