A 3D model pipeline, pushed by Fable 5.2
agent
+1:20:26The new design also holds up in the project's old painted frame (a like-for-like after). Now adding multi-frame rendering to my renderer so the attack can be shown as a moving clip, not only stills.
Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/stage/stage.html"; s=open(p).read() # keep mixers, allow re-posing; allocate targets once; frames loop R=[ (''' const mixer = new THREE.AnimationMixer(gltf.scene); const [clip, t] = cs.clip || ["ref", 0]; const src = gltf.animations.find(a => a.name === clip); if (src) { const a = mixer.clipAction(src); a.play(); a.time = t; mixer.update(0); } scene.updateMatrixWorld(true);''', ''' const mixer = new THREE.AnimationMixer(gltf.scene); const skel = meshes.find(m => m.isSkinnedMesh)?.skeleton; const pose = (clip, t) => { // hold one moment of one clip ("ref": the pose as built) mixer.stopAllAction(); if (skel) skel.pose(); const src = gltf.animations.find(a => a.name === clip); if (src) { const a = mixer.clipAction(src); a.reset(); a.play(); a.time = Math.min(t, src.duration - 1e-4); mixer.update(0); } scene.updateMatrixWorld(true); }; pose(...(cs.clip || ["ref", 0]));'''), (''' chars.push({ ...cs, gltf, turn, meshes, V });''',''' chars.push({ ...cs, gltf, turn, meshes, V, pose });'''), ('''function renderAll() { const g = R.getContext();''','''let T = null; // render targets, made once function renderAll() { if (!T) { const mk = () => new THREE.WebGLRenderTarget(W, H, { depthTexture: new THREE.DepthTexture(W, H, THREE.UnsignedIntType), minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }); const bw = Math.round(S.w / 4), bh = Math.round(S.h / 4); T = { color: mk(), info: mk(), pic: new THREE.WebGLRenderTarget(W, H, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }), a: new THREE.WebGLRenderTarget(bw, bh, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }), bw, bh, mats: {} }; T.b = T.a.clone(); T.info.texture.minFilter = T.info.texture.magFilter = THREE.NearestFilter; T.quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2)); T.qs = new THREE.Scene(); T.qc = new THREE.Camera(); T.qs.add(T.quad); }'''), (''' const mk = () => { const rt = new THREE.WebGLRenderTarget(W, H, { depthTexture: new THREE.DepthTexture(W, H, THREE.UnsignedIntType), minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }); return rt; }; const rtColor = mk(), rtInfo = mk(); rtInfo.texture.minFilter = rtInfo.texture.magFilter = THREE.NearestFilter; ''',''' const rtColor = T.color, rtInfo = T.info; '''), (''' const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2)), qs = new THREE.Scene(), qc = new THREE.Camera(); qs.add(quad); ''',''' const quad = T.quad, qs = T.qs, qc = T.qc; '''), (''' quad.material = new THREE.ShaderMaterial({ vertexShader: QUAD_VS, fragmentShader: COMP_FS, uniforms: {''',''' quad.material = T.mats.comp = T.mats.comp || new THREE.ShaderMaterial({ vertexShader: QUAD_VS, fragmentShader: COMP_FS, uniforms: {'''), (''' const rtPic = new THREE.WebGLRenderTarget(W, H, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }); ''',''' const rtPic = T.pic; '''), (''' const bw = Math.round(S.w / 4), bh = Math.round(S.h / 4); const rtA = new THREE.WebGLRenderTarget(bw, bh, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }), rtB = rtA.clone(); const blur = (src, dst, dir, th) => { quad.material = new THREE.ShaderMaterial({ vertexShader: QUAD_VS, fragmentShader: BLUR_FS, uniforms: { tSrc: { value: src }, uDir: { value: dir }, uThresh: { value: th } } }); R.setRenderTarget(dst); R.render(qs, qc); };''', ''' const bw = T.bw, bh = T.bh, rtA = T.a, rtB = T.b; T.mats.blur = T.mats.blur || new THREE.ShaderMaterial({ vertexShader: QUAD_VS, fragmentShader: BLUR_FS, uniforms: { tSrc: { value: null }, uDir: { value: new THREE.Vector2() }, uThresh: { value: 0 } } }); const blur = (src, dst, dir, th) => { quad.material = T.mats.blur; const bu = T.mats.blur.uniforms; bu.tSrc.value = src; bu.uDir.value.copy(dir); bu.uThresh.value = th; R.setRenderTarget(dst); R.render(qs, qc); };'''), (''' quad.material = new THREE.ShaderMaterial({ vertexShader: QUAD_VS, fragmentShader: FINAL_FS, uniforms: {''',''' quad.material = T.mats.fin = T.mats.fin || new THREE.ShaderMaterial({ vertexShader: QUAD_VS, fragmentShader: FINAL_FS, uniforms: {'''), (''' R.setRenderTarget(null); R.render(qs, qc); void g; } try { renderAll(); $("out").textContent = R.domElement.toDataURL("image/png"); document.title = "stage ready";''',''' R.setRenderTarget(null); R.render(qs, qc); } try { if (S.frames) { // a clip: [{clips: {name: [clip, t]}, wind: [x, y, z]}, ...] const shots = []; for (const f of S.frames) { for (const c of chars) if (f.clips && f.clips[c.name]) c.pose(...f.clips[c.name]); if (f.wind) G.uWind.value.set(...f.wind); renderAll(); shots.push(R.domElement.toDataURL("image/jpeg", 0.95)); } $("out").textContent = shots.join("|"); } else { renderAll(); $("out").textContent = R.domElement.toDataURL("image/png"); } document.title = "stage ready";'''), ] for a,b in R: assert a in s, a[:70]; s=s.replace(a,b,1) open(p,"w").write(s) p="tools/whole/stage_shot.py"; s=open(p).read() old=''' m = re.search(r'id="out"[^>]*>[redacted: data-URI prefix]([A-Za-z0-9+/=]+)<', r.stdout) if not m:''' new=''' if spec.get("frames"): # a clip: OUT is a folder of numbered JPEGs fr = re.findall(r'[redacted: data-URI prefix]([A-Za-z0-9+/=]+)', r.stdout) if fr: os.makedirs(out, exist_ok=True) for k, b in enumerate(fr): open(os.path.join(out, f"f{k:04d}.jpg"), "wb").write(base64.b64decode(b)) return m = re.search(r'id="out"[^>]*>[redacted: data-URI prefix]([A-Za-z0-9+/=]+)<', r.stdout) if not m:''' assert old in s; s=s.replace(old,new) s=s.replace(''' sky, ground (0 or 1), bloom, line (ink width scale)''',''' sky, ground (0 or 1), bloom, line (ink width scale) frames [{clips {name: [clip, seconds]}, wind}]: a clip; OUT is then a folder of numbered JPEGs (ffmpeg joins them)''') open(p,"w").write(s) E cd review/out/stage && python3 - <<'E' import json, math base=json.load(open("b1.json")) base.update(w=960,h=540,ss=1.5) fr=[] for k in range(8): t=k*1.5/8 fr.append({"clips":{"wren":["attack",t],"mob_soldier":["idle",(t)%2.0]},"wind":[-0.16-0.05*math.sin(t*6),0,-0.03]}) base["frames"]=fr json.dump(base,open("clip_test.json","w")) E R=~/Projects/lowmarch-fable52; time python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site clip_test.json clip_test 2>&1 | tail -4; ls clip_test | head; python3 -c " from PIL import Image ims=[Image.open(f'clip_test/f{k:04d}.jpg').resize((480,270)) for k in range(8)] W=Image.new('RGB',(1920,540)); [W.paste(im,(480*(i%4),270*(i//4))) for i,im in enumerate(ims)]; W.save('clip_test.png')"result, 13 lines
clip_test 30s real 0m30.058s user 0m1.099s sys 0m1.143s f0000.jpg f0001.jpg f0002.jpg f0003.jpg f0004.jpg f0005.jpg f0006.jpg f0007.jpg
Read~/Projects/lowmarch-fable52/review/out/stage/clip_test.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/clip_test.png" }result
no output
Bashcd ~/Projects/lowmarch-fable52 && sed -n 1,45p tools/whole/export_model.py; (time OMP_NUM_THREADS=1 python3 tools/whole/export_model.py review/out/whole2/site wren review/out/stage/wren.glb) 2>&1 | tail -25
command
cd ~/Projects/lowmarch-fable52 && sed -n 1,45p tools/whole/export_model.py; (time OMP_NUM_THREADS=1 python3 tools/whole/export_model.py review/out/whole2/site wren review/out/stage/wren.glb) 2>&1 | tail -25
result, 57 lines
"""Export one built character as a standalone rigged model: a binary glTF 2.0 that a stock loader opens (three.js GLTFLoader, Blender's importer) with no knowledge of this project. python3 tools/whole/export_model.py SITE_DIR NAME OUT.glb [--check PNG [CLIP [SECONDS]]] Reads SITE_DIR/NAME.glb.json (tools/export_glb.py export_skinned, base64-wrapped by review/vroid-02/build.py) and the character's scene_info in SITE_DIR/camera.json. Geometry, skin weights, joints and clips pass through as built. Materials are rewritten per role (the node's extras.role) from the paint the painted page would use, as plain metallic-roughness materials: sRGB hex turned linear (export_skinned writes hex as is, so colours read pale), hair and iris textures recoloured to the character's own (the VRoid sample's textures are navy and blue), lashes and brows inked in their flat colour, the eye highlight blended (its alpha is mostly under 0.5, so a mask cut it all), shadow cards (the nose) a faint blend of the skin's shade, steel and gold half metallic, everything else 0. Duplicate materials are merged; textures nothing uses are dropped. Kept for the painted shader: each node's extras (group, role, material), each material's extras (role, kind, base, ramp), the _PLATE attribute, and the root node's extras.lowmarch: the whole scene_info (roles and their bands, paint, lights, capsules, cloth grids, mouth curve, face marks) plus a VRM humanoid map (VRoid's J_Bip names are fixed). Axes are glTF's: +Y up, metres, facing +Z, feet at y 0, in the reference pose the site was built in. --check: shoot the file in headless Chromium with three.js GLTFLoader, a PerspectiveCamera, its own materials and a plain light, posed at CLIP (default attack) and SECONDS (default its middle), beside the reference pose from the front with the face close in an inset. """ import base64 import io import json import os import re import shutil import socket import struct import subprocess import sys import time import numpy as np from PIL import Image ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # VRM 0.x humanoid bone -> VRoid's joint name (the same on every VRoid export) HUMANOID = dict(hips="C_Hips", spine="C_Spine", chest="C_Chest", upperChest="C_UpperChest", neck="C_Neck", head="C_Head", leftEye="L_FaceEye", rightEye="R_FaceEye") for s, side in (("L", "left"), ("R", "right")): HUMANOID.update({f"{side}Shoulder": f"{s}_Shoulder", f"{side}UpperArm": f"{s}_UpperArm", f"{side}LowerArm": f"{s}_LowerArm", f"{side}Hand": f"{s}_Hand", f"{side}UpperLeg": f"{s}_UpperLeg", f"{side}LowerLeg": f"{s}_LowerLeg", f"{side}Foot": f"{s}_Foot", f"{side}Toes": f"{s}_ToeBase"}) export 0.5s review/out/stage/wren.glb: 5.36 MB (JSON 210772 B, binary 5146148 B) meshes 125, primitives 125, triangles 115448, nodes 185 materials 32 (4 mask, 2 blend, 10 metallic), textures 10, images 10 skin: 59 joints, skeleton root Root, rest pose against bind matrices: 5.9e-08 off humanoid map in extras: 54 bones animations: idle 2.00 s (48 channels), attack 1.50 s (48 channels), apose 1.00 s (4 channels) bounds (m): x -0.310..0.310 y -0.009..1.758 z -0.258..1.020; height 1.768; face toward +Z real 0m0.696s user 0m0.552s sys 0m0.144sBashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'error
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/stage/stage.html"; s=open(p).read() old=''' const def = CAMJ.characters.find(c => c.name === cs.name), V = def.info; const gltf = await loadGlb(`${S.site}/${cs.file || cs.name + ".glb.json"}`);''' new=''' const gltf = await loadGlb(`${S.site}/${cs.file || cs.name + ".glb.json"}`); // an exported model (tools/whole/export_model.py) carries what the shader needs in its root's extras; a site's // model keeps it beside it in camera.json let V = null; gltf.scene.traverse(o => { if (!V && o.userData && o.userData.lowmarch) V = o.userData.lowmarch; }); if (!V) V = CAMJ.characters.find(c => c.name === cs.name).info;''' assert old in s; s=s.replace(old,new) old='''const CAMJ = await (await fetch(`${S.site}/camera.json`)).json();''' new='''const CAMJ = await fetch(`${S.site}/camera.json`).then(r => r.ok ? r.json() : { characters: [] }).catch(() => ({ characters: [] }));''' assert old in s; s=s.replace(old,new) open(p,"w").write(s) E cp review/out/stage/wren.glb review/out/whole2/site/wren.glb && cd review/out/stage && python3 - <<'E' import json a=json.load(open("s2.json")); a["chars"][0]["clip"]=["idle",0.0]; a["chars"][0]["yaw"]=40 json.dump(a,open("g_site.json","w")) a["chars"][0]["file"]="wren.glb"; json.dump(a,open("g_glb.json","w")) E R=~/Projects/lowmarch-fable52; (python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site g_site.json g_site.png & python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site g_glb.json g_glb.png & wait) 2>&1 | tail -4; python3 -c " from PIL import Image a=Image.open('g_site.png'); b=Image.open('g_glb.png') W=Image.new('RGB',(1920,720)); W.paste(a,(0,0)); W.paste(b,(960,0)); W.save('g_cmp.png')"result, error, 9 lines
Exit code 1 FAILED [86713:86713:1110/195443.110069:INFO:CONSOLE:380] "Uncaught TypeError: Cannot read properties of undefined (reading 'mouth')", g_site.png 15s Traceback (most recent call last): File "<string>", line 3, in <module> File "[redacted: private path]/PIL/Image.py", line 3465, in open fp = builtins.open(filename, "rb") FileNotFoundError: [Errno 2] No such file or directory: 'g_glb.png'Read~/Projects/lowmarch-fable52/review/out/stage/g_cmp.pngerror
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/g_cmp.png" }result, error, 1 line
File does not exist. Note: your current working directory is ~/Projects/lowmarch-fable52.
agent
+1:22:04Exported model file works (5.4 MB, rigged, 3 clips). Fixing how my renderer reads the model's embedded data so the final shots come from the file itself.
Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' import json,struct b=open("review/out/stage/wren.glb","rb").read() n=struct.unpack("<I",b[12:16])[0]; j=json.loads(b[20:20+n]) for nd in j["nodes"]: if "extras" in nd and "lowmarch" in nd["extras"]: L=nd["extras"]["lowmarch"]; print(nd["name"], list(L.keys())); for k,v in L.items(): print(" ",k, list(v.keys())[:12] if isinstance(v,dict) else type(v).__name__) break print(j["materials"][0]) Eresult, 10 lines
wren ['name', 'label', 'source', 'units', 'up', 'front', 'humanoid', 'scene_info'] name str label str source str units str up str front str humanoid ['hips', 'spine', 'chest', 'upperChest', 'neck', 'head', 'leftEye', 'rightEye', 'leftShoulder', 'leftUpperArm', 'leftLowerArm', 'leftHand'] scene_info ['roles', 'light', 'sun', 'capsules', 'cloth', 'face_marks', 'paint', 'mouth_curve', 'mouth_bone', 'ink', 'skin', 'depth_gap'] {'name': 'body:mouth', 'doubleSided': True, 'pbrMetallicRoughness': {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorTexture': {'index': 0}}, 'extras': {'role': 'mouth', 'kind': 'flat', 'base': '#6e4247'}}Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/stage/stage.html"; s=open(p).read() old='''if (!V && o.userData && o.userData.lowmarch) V = o.userData.lowmarch; });''' new='''if (!V && o.userData && o.userData.lowmarch) V = o.userData.lowmarch.scene_info || o.userData.lowmarch; });''' assert old in s; open(p,"w").write(s.replace(old,new)) E cd review/out/stage && R=~/Projects/lowmarch-fable52; python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site g_glb.json g_glb.png 2>&1 | tail -4; python3 -c " from PIL import Image a=Image.open('g_site.png'); b=Image.open('g_glb.png') W=Image.new('RGB',(1920,720)); W.paste(a,(0,0)); W.paste(b,(960,0)); W.save('g_cmp.png')"result, 1 line
g_glb.png 13s
Read~/Projects/lowmarch-fable52/review/out/stage/g_cmp.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/g_cmp.png" }result
no output
Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' import json,struct b=open("review/out/stage/wren.glb","rb").read() n=struct.unpack("<I",b[12:16])[0]; j=json.loads(b[20:20+n]) for m in j["materials"]: if any(k in m["name"] for k in ("face","steel","hair","iris","line","brow")) or "baseColorTexture" in m["pbrMetallicRoughness"]: print(m["name"], {k:v for k,v in m["pbrMetallicRoughness"].items()}, m.get("alphaMode"), m.get("extras")) E grep -n "decal\|def _face\|skin_ref\|SKIN_REF\|face" tools/whole/export_model.py | head -40result, 25 lines
body:mouth {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorTexture': {'index': 0}} None {'role': 'mouth', 'kind': 'flat', 'base': '#6e4247'} body:iris {'metallicFactor': 0.0, 'roughnessFactor': 0.4, 'baseColorTexture': {'index': 1}} MASK {'role': 'iris', 'kind': 'iris'} body:highlight {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorTexture': {'index': 2}} BLEND {'role': 'highlight', 'kind': 'flat', 'base': '#f4fbff'} body:face {'metallicFactor': 0.0, 'roughnessFactor': 0.75, 'baseColorTexture': {'index': 3}} None {'role': 'face', 'kind': 'skin', 'base': '#f4d3bd', 'ramp': ['#f4d3bd', '#c39885', '#7a544a'], 'bands': [[0.8, '#fff6d8'], [0.62, '#fbd99c'], [0.38, '#eca067'], [-9, '#b06e4b']]} body:white {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorTexture': {'index': 4}} None {'role': 'white', 'kind': 'flat', 'base': '#f4fbff'} body:brow {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorTexture': {'index': 5}} MASK {'role': 'brow', 'kind': 'flat', 'base': '#2e1610'} body:line {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorTexture': {'index': 6}} MASK {'role': 'line', 'kind': 'flat', 'base': '#2f1e3c'} body:line {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorTexture': {'index': 7}} MASK {'role': 'line', 'kind': 'flat', 'base': '#2f1e3c'} plate:steel {'metallicFactor': 0.5, 'roughnessFactor': 0.4, 'baseColorFactor': [0.5647, 0.5841, 0.624, 1.0]} None {'role': 'steel', 'kind': 'steel', 'base': '#c6c9cf', 'bands': [[0.9, '#eef2fa'], [0.7, '#a8b0c8'], [0.4, '#6a7090'], [-9, '#3a3e58']], 'decal': True, 'decal_texture': 8} plate:steel {'metallicFactor': 0.5, 'roughnessFactor': 0.4, 'baseColorFactor': [0.5647, 0.5841, 0.624, 1.0]} None {'role': 'steel', 'kind': 'steel', 'base': '#c6c9cf', 'bands': [[0.9, '#eef2fa'], [0.7, '#a8b0c8'], [0.4, '#6a7090'], [-9, '#3a3e58']]} sword:steel {'metallicFactor': 0.5, 'roughnessFactor': 0.4, 'baseColorFactor': [0.5647, 0.5841, 0.624, 1.0]} None {'role': 'steel', 'kind': 'steel', 'base': '#c6c9cf', 'bands': [[0.9, '#eef2fa'], [0.7, '#a8b0c8'], [0.4, '#6a7090'], [-9, '#3a3e58']]} hair:hair {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorFactor': [0.1946, 0.0482, 0.0194, 1.0]} None {'role': 'hair', 'kind': 'hair', 'base': '#7a3e26', 'bands': [[0.86, '#c88a62'], [0.66, '#a05a3a'], [0.42, '#7a3e26'], [-9, '#52281a']]} hair:heraldry {'metallicFactor': 0.0, 'roughnessFactor': 0.85, 'baseColorFactor': [0.8632, 0.7913, 0.6445, 1.0]} None {'role': 'heraldry', 'kind': 'cloth', 'base': '#efe6d2', 'bands': [[0.85, '#f1f2f5'], [0.6, '#d4d7de'], [0.35, '#a4a8b4'], [-9, '#6a6e7c']]} 16:lights, capsules, cloth grids, mouth curve, face marks) plus a VRM humanoid map (VRoid's J_Bip names are fixed). 20:with the face close in an inset. 102: """The face texture moved so its skin (the median of its opaque texels) lands on the paint's skin.""" 141: decal = bool((old.get("extras") or {}).get("decal")) 156: if tex is not None and decal: # a design mask (tools/plates.py), not a colour: kept aside 157: m["extras"].update(decal=True, decal_texture=tex_of(tex, None)) 165: elif tex is not None and role == "face" and base: 339: face = [k for k, nd in enumerate(nodes) if (nd.get("extras") or {}).get("role") == "face"] 341: if face and head is not None: 342: fp = acc(j["meshes"][nodes[face[0]]["mesh"]]["primitives"][0]["attributes"]["POSITION"]) 361: f"height {hi[1] - lo[1]:.3f}; face toward {front}") 400: const head = gltf.scene.getObjectByName("J_Bip_C_Head"); // an inset: the face, closeBashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/stage/stage.html"; s=open(p).read() R=[ (''' let map = m0.map || null; if (map) { map = map.clone(); map.colorSpace = THREE.NoColorSpace; map.needsUpdate = true; } const decal = !!(m0.userData && m0.userData.decal);''', ''' // an exported model's materials are plain ones (tools/whole/export_model.py): its face texture is already in her skin // tone, its iris in her eye colour, its lashes inked, and a plate's design mask is kept aside in extras const X = m0.userData || {}, exported = X.kind !== undefined; let map = mesh.userData.decalMap || m0.map || null; if (map) { map = map.clone(); map.colorSpace = THREE.NoColorSpace; map.needsUpdate = true; } const decal = !!X.decal;'''), (''' if (role === "iris") { kind = 7; u.uAlpha.value = 1; u.uRecv.value = 2; u.uId.value.y = 0; }''', ''' if (role === "iris") { kind = exported ? 8 : 7; u.uAlpha.value = 1; u.uRecv.value = 2; u.uId.value.y = 0; }'''), ('''if (map) u.uAlpha.value = role === "line" ? 2 : 1; u.uId.value.y = 0; }''', '''if (map) u.uAlpha.value = role === "line" && !exported ? 2 : 1; u.uId.value.y = 0; }'''), ('''if (role === "face") { u.uRecv.value = 2; u.uId.value.y = 0.3; if (map) u.uFaceTex.value = 1; } }''', '''if (role === "face") { u.uRecv.value = 2; u.uId.value.y = 0.3; if (map) u.uFaceTex.value = 1; if (exported && X.base) { const c = hex(X.base); u.uSkinRef.value.set(c.r, c.g, c.b); } } }'''), (''' const meshes = []; gltf.scene.traverse(o => { if (o.isMesh) { o.material = material(V, o); o.frustumCulled = false; meshes.push(o); } });''', ''' const meshes = [], found = []; gltf.scene.traverse(o => { if (o.isMesh) found.push(o); }); for (const o of found) { const dt = o.material.userData && o.material.userData.decal_texture; if (dt !== undefined) o.userData.decalMap = await gltf.parser.getDependency("texture", dt); o.material = material(V, o); o.frustumCulled = false; meshes.push(o); }'''), ] for a,b in R: assert a in s, a[:70]; s=s.replace(a,b,1) open(p,"w").write(s) E cd review/out/stage && R=~/Projects/lowmarch-fable52; python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site g_glb.json g_glb.png 2>&1 | tail -4; python3 -c " from PIL import Image a=Image.open('g_site.png'); b=Image.open('g_glb.png') W=Image.new('RGB',(1920,720)); W.paste(a,(0,0)); W.paste(b,(960,0)); W.save('g_cmp.png')"result, 1 line
g_glb.png 13s
Read~/Projects/lowmarch-fable52/review/out/stage/g_cmp.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/g_cmp.png" }result
no output
Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/stage/stage.html"; s=open(p).read() old=''' if (map) { map = map.clone(); map.colorSpace = THREE.NoColorSpace; map.needsUpdate = true; } const decal = !!X.decal;''' new=''' if (map) { map = map.clone(); map.colorSpace = THREE.NoColorSpace; if (mesh.userData.decalMap) map.flipY = !map.flipY; map.needsUpdate = true; } const decal = !!X.decal;''' assert old in s; open(p,"w").write(s.replace(old,new)) E date +%H:%M:%S; ls -la --time-style=+%H:%M tools/whole/*.py review/out/whole-clips/shots | tail -22result, 23 lines
19:56:25 -rw------- 1 severian severian 198019 19:52 b_idle_0.0.png -rw------- 1 severian severian 476 19:52 b_idle_1.0.json -rw------- 1 severian severian 198090 19:52 b_idle_1.0.png -rw------- 1 severian severian 594869 19:53 b_sheet.png -rw------- 1 severian severian 478 19:55 c_attack_0.20.json -rw------- 1 severian severian 197030 19:55 c_attack_0.20.png -rw------- 1 severian severian 479 19:55 c_attack_0.38.json -rw------- 1 severian severian 199218 19:55 c_attack_0.38.png -rw------- 1 severian severian 479 19:55 c_attack_0.56.json -rw------- 1 severian severian 195765 19:55 c_attack_0.56.png -rw------- 1 severian severian 479 19:55 c_attack_0.68.json -rw------- 1 severian severian 195190 19:55 c_attack_0.68.png -rw------- 1 severian severian 478 19:55 c_attack_0.90.json -rw------- 1 severian severian 195262 19:55 c_attack_0.90.png -rw------- 1 severian severian 478 19:55 c_attack_1.30.json -rw------- 1 severian severian 199499 19:55 c_attack_1.30.png -rw------- 1 severian severian 476 19:55 c_idle_0.0.json -rw------- 1 severian severian 198019 19:55 c_idle_0.0.png -rw------- 1 severian severian 476 19:55 c_idle_1.0.json -rw------- 1 severian severian 198090 19:55 c_idle_1.0.png -rw------- 1 severian severian 599332 19:55 c_sheet.png -rw------- 1 severian severian 75389 19:49 viz.png
Bashcd ~/Projects/lowmarch-fable52 && rmdir tools/whole/notes 2>/dev/null; git add tools/whole/wren.py tools/whole/hairdo.py tools/whole/stage tools/whole/stage_shot.py tools/whole/build.py && git commit -q -m "Wren: her own design, hair built from nothing, and a perspective cel renderer
command
cd ~/Projects/lowmarch-fable52 && rmdir tools/whole/notes 2>/dev/null; git add tools/whole/wren.py tools/whole/hairdo.py tools/whole/stage tools/whole/stage_shot.py tools/whole/build.py && git commit -q -m "Wren: her own design, hair built from nothing, and a perspective cel renderer wren.py: a border knight designed for the side-view frame (uneven pauldrons, a keeled cuirass cut at the natural waist over a leather waist, tassets, a split surcoat with a long tail, a longsword for two hands), on restyled proportions (larger head and eyes, longer legs, slimmer neck, arms and waist). hairdo.py: hair that is neither VRoid's nor the kit's: a cap combed to a tie and a few solid clumps (fringe cut above the eyes, cheek locks, a ponytail), placed in head coordinates so it fits another head. stage/: a renderer of my own for the built model: perspective camera, a shadow map, two tones with turned hues, one highlight band across the hair, ink lines, a rim light, a painted sky and ground, Flattice, clips. build.py: WHOLE_DESIGN, WHOLE_STANCE, and the slow plate check off unless asked for. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: [redacted: session link]" && git log --oneline -1result, 1 line
b82a55a Wren: her own design, hair built from nothing, and a perspective cel renderer
Bashcd ~/Projects/lowmarch-fable52/review/out/stage && cat > d1.json <<'E'error
command
cd ~/Projects/lowmarch-fable52/review/out/stage && cat > d1.json <<'E' {"w": 900, "h": 1200, "ss": 2, "chars": [{"name": "wren", "file": "wren.glb", "clip": ["idle", 0.0], "pos": [0,0,0], "yaw": 35}], "cam": {"lens": 60, "pos": [0.5, 1.0, 4.4], "target": [0.0, 0.92, 0]}, "wind": [-0.15, 0.0, -0.05], "grass": 0} E cat > d2.json <<'E' {"w": 900, "h": 1200, "ss": 2, "chars": [{"name": "wren", "file": "wren.glb", "clip": ["idle", 0.0], "pos": [0,0,0], "yaw": 205}], "cam": {"lens": 60, "pos": [0.5, 1.0, 4.4], "target": [0.0, 0.92, 0]}, "wind": [-0.15, 0.0, -0.05], "grass": 0} E R=~/Projects/lowmarch-fable52; (python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site d1.json d1.png & python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site d2.json d2.png & wait) 2>&1 | tail -3; python3 -c " from PIL import Image a=Image.open('d1.png'); b=Image.open('d2.png') W=Image.new('RGB',(1800,1200)); W.paste(a,(0,0)); W.paste(b,(900,0)); W.save('d12.png')"result, error, 9 lines
Exit code 1 FAILED d1.png 11s Traceback (most recent call last): File "<string>", line 3, in <module> File "[redacted: private path]/PIL/Image.py", line 3465, in open fp = builtins.open(filename, "rb") FileNotFoundError: [Errno 2] No such file or directory: 'd2.png'Read~/Projects/lowmarch-fable52/review/out/stage/d12.pngerror
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/d12.png" }result, error, 1 line
File does not exist. Note: your current working directory is ~/Projects/lowmarch-fable52.
Bashcd ~/Projects/lowmarch-fable52/review/out/stage && R=~/Projects/lowmarch-fable52; python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site d2.json d2.png 2>&1 | tail -3; python3 -c "
command
cd ~/Projects/lowmarch-fable52/review/out/stage && R=~/Projects/lowmarch-fable52; python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site d2.json d2.png 2>&1 | tail -3; python3 -c " from PIL import Image a=Image.open('d1.png'); b=Image.open('d2.png') W=Image.new('RGB',(1800,1200)); W.paste(a,(0,0)); W.paste(b,(900,0)); W.save('d12.png')"result, 1 line
d2.png 11s
Read~/Projects/lowmarch-fable52/review/out/stage/d12.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/d12.png" }result
no output
Bashcd ~/Projects/lowmarch-fable52 && sed -i 's/float k = sw \* sw \* (uSway == 2 ? 0.45 : 1.0);/float k = sw * sw * (uSway == 2 ? 0.22 : 1.0);/' tools/whole/stage/stage.html && cat > tools/whole/stage_clip.py <<'E'
command
cd ~/Projects/lowmarch-fable52 && sed -i 's/float k = sw \* sw \* (uSway == 2 ? 0.45 : 1.0);/float k = sw * sw * (uSway == 2 ? 0.22 : 1.0);/' tools/whole/stage/stage.html && cat > tools/whole/stage_clip.py <<'E' """A short clip from the stage renderer: frames shot in one page load, joined by ffmpeg. python3 tools/whole/stage_clip.py SITE_DIR SPEC.json OUT.mp4 SPEC is a stage spec (tools/whole/stage_shot.py) plus fps (24) and timeline: [{"dur": seconds, "<name>": [clip, from_seconds, to_seconds], ...}, ...] Each character holds its last pose through a segment that doesn't name it. The wind gusts a little all the time, and whips back while "whip": [from, to] (seconds on the whole timeline) lasts: hair has no physics here, so a lunge's drag on it is drawn by hand. """ import json import math import os import shutil import subprocess import sys import tempfile import time sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import stage_shot # noqa: E402 def frames(spec): fps = spec.get("fps", 24) base = spec.get("wind", [-0.16, 0.0, -0.03]) whip = spec.get("whip") out, T, last = [], 0.0, {} for seg in spec["timeline"]: n = max(1, round(seg["dur"] * fps)) for k in range(n): u = k / n for name, v in seg.items(): if name != "dur": last[name] = [v[0], v[1] + (v[2] - v[1]) * u] g = 1.0 + 0.30 * math.sin(2 * math.pi * 0.9 * T) + 0.12 * math.sin(2 * math.pi * 2.3 * T + 1.0) w = [base[0] * g, base[1], base[2] * g] if whip and whip[0] <= T <= whip[1] + 0.5: e = 1.0 if T <= whip[1] else math.exp(-(T - whip[1]) / 0.14) w[0] += base[0] * 1.6 * e w[1] += 0.05 * e out.append(dict(clips={k_: list(v_) for k_, v_ in last.items()}, wind=w)) T += 1 / fps return out if __name__ == "__main__": site, spec, out = sys.argv[1], json.load(open(sys.argv[2])), sys.argv[3] t0 = time.time() fr = frames(spec) d = tempfile.mkdtemp(prefix="clip_", dir=os.path.dirname(os.path.abspath(out))) try: for a in range(0, len(fr), 24): # a page load per second of clip keeps each page's output small s = {k: v for k, v in spec.items() if k not in ("timeline", "whip", "fps")} s["frames"] = fr[a:a + 24] part = os.path.join(d, f"p{a:05d}") stage_shot.shoot(site, s, part) for k, f in enumerate(sorted(os.listdir(part))): os.rename(os.path.join(part, f), os.path.join(d, f"f{a + k:05d}.jpg")) subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-framerate", str(spec.get("fps", 24)), "-i", os.path.join(d, "f%05d.jpg"), "-c:v", "libx264", "-pix_fmt", "yuv420p", "-crf", "17", "-movflags", "+faststart", out], check=True) finally: shutil.rmtree(d, ignore_errors=True) print(out, f"{len(fr)} frames, {time.time() - t0:.0f}s") E python3 -c "import ast;ast.parse(open('tools/whole/stage_clip.py').read())"; ffmpeg -hide_banner -encoders 2>/dev/null | grep -c libx264; date +%H:%M:%Sresult, 3 lines
2 19:57:50 [This command modified 1 file you've previously read: tools/whole/stage/stage.html. Call Read before editing.]
Bashmkdir -p ~/Projects/lowmarch-fable52/tools/whole/shots && cd ~/Projects/lowmarch-fable52/tools/whole/shots && cat > hero.json <<'E'
command
mkdir -p ~/Projects/lowmarch-fable52/tools/whole/shots && cd ~/Projects/lowmarch-fable52/tools/whole/shots && cat > hero.json <<'E' {"w": 1920, "h": 1080, "ss": 2, "chars": [{"name": "wren", "file": "wren.glb", "clip": ["idle", 0.0], "pos": [0, 0, 0], "yaw": 50}], "cam": {"lens": 50, "pos": [1.75, 0.80, 3.55], "target": [0.22, 1.10, 0]}, "key": [0.6, 0.62, 0.5], "rim": [-0.8, 0.25, -0.55], "wind": [-0.22, 0.0, -0.05], "flat": 0.6} E cat > battle.json <<'E' {"w": 1920, "h": 1080, "ss": 2, "chars": [{"name": "wren", "file": "wren.glb", "clip": ["idle", 0.0], "pos": [-1.1, 0, 0], "yaw": 62}, {"name": "mob_soldier", "clip": ["idle", 0.0], "pos": [1.35, 0, 0], "yaw": -70}], "cam": {"lens": 90, "pos": [0.2, 1.15, 10.5], "target": [0.1, 1.0, 0]}, "key": [0.45, 0.70, 0.55], "rim": [-0.8, 0.25, -0.55], "wind": [-0.16, 0.0, -0.03]} E cd ~/Projects/lowmarch-fable52/review/out/stage && R=~/Projects/lowmarch-fable52; (time python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site $R/tools/whole/shots/hero.json hero.png) 2>&1 | grep -E "hero|real|FAILED|CONSOLE"result, 2 lines
hero.png 23s real 0m23.473s
Read~/Projects/lowmarch-fable52/review/out/stage/hero.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/hero.png" }result
no output
agent
+1:25:42Hero frame renders from the exported model in 23 s and holds up at 1080p. Checking on the refit two-handed clips before the final shots.
Bashcd ~/Projects/lowmarch-fable52 && date +%H:%M:%S; ls -la --time-style=+%H:%M review/out/whole-clips/shots/*sheet* tools/whole/clips2h.py; ls --time-style=+%H:%M -la review/out/whole-lens/*.png | tail -6
command
cd ~/Projects/lowmarch-fable52 && date +%H:%M:%S; ls -la --time-style=+%H:%M review/out/whole-clips/shots/*sheet* tools/whole/clips2h.py; ls --time-style=+%H:%M -la review/out/whole-lens/*.png | tail -6
result, 12 lines
19:58:37 -rw------- 1 severian severian 595981 19:30 review/out/whole-clips/shots/a_sheet.png -rw------- 1 severian severian 594869 19:53 review/out/whole-clips/shots/b_sheet.png -rw------- 1 severian severian 599332 19:55 review/out/whole-clips/shots/c_sheet.png -rw------- 1 severian severian 597350 19:58 review/out/whole-clips/shots/d_sheet.png -rw------- 1 severian severian 15569 19:56 tools/whole/clips2h.py -rw------- 1 severian severian 492573 19:24 review/out/whole-lens/lens_flat.png -rw------- 1 severian severian 534891 19:25 review/out/whole-lens/lens_noflat_castortho.png -rw------- 1 severian severian 534602 19:24 review/out/whole-lens/lens_noflat.png -rw------- 1 severian severian 385153 19:18 review/out/whole-lens/model_check.png -rw------- 1 severian severian 335774 19:18 review/out/whole-lens/model_check_soldier.png -rw------- 1 severian severian 623647 19:21 review/out/whole-lens/ortho_ref.png
Read~/Projects/lowmarch-fable52/review/out/whole-lens/lens_flat.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/whole-lens/lens_flat.png" }result
no output
Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/stage/stage.html"; s=open(p).read() R=[(''' const N = 9000, inst''',''' const N = 22000, inst'''), (''' const r = 0.4 + 16 * Math.pow(rnd(), 1.6), a = rnd() * Math.PI * 2, k = 0.7 + rnd() * 1.3;''', ''' const r = 0.3 + 15 * Math.pow(rnd(), 1.9), a = rnd() * Math.PI * 2, k = 0.8 + rnd() * 1.5;''')] for a,b in R: assert a in s, a[:50]; s=s.replace(a,b,1) open(p,"w").write(s) E sed -n 150,200p tools/vroid_portrait.py | head -5; grep -n "Fcl_EYE_Angry\|Fcl_MTH" art/cast/expressions.txt | headresult, 13 lines
def smooth(t): t = np.clip(t, 0, 1) return t * t * (3 - 2 * t) 5:joy|Fcl_BRW_Joy:1;Fcl_EYE_Joy:1;Fcl_MTH_Joy:1 6:smile|Fcl_BRW_Fun:1;Fcl_EYE_Fun:0.75;Fcl_MTH_Fun:1 7:angry|Fcl_BRW_Angry:1.4;Fcl_EYE_Angry:1;Fcl_MTH_Angry:1 8:sad|Fcl_BRW_Sorrow:1.4;Fcl_EYE_Sorrow:1.3;Fcl_MTH_Sorrow:1;Fcl_MTH_Angry:0.6 9:surprised|Fcl_BRW_Surprised:1.3;Fcl_EYE_Surprised:1.5;Fcl_MTH_O:1.1;Fcl_MTH_A:0.15 10:shout|Fcl_BRW_Angry:1.6;Fcl_EYE_Angry:0.9;Fcl_MTH_A:1.5;Fcl_MTH_Large:0.5 11:wink|Fcl_EYE_Close_R:1;Fcl_BRW_Fun:0.6;Fcl_MTH_Fun:1 12:smug|Fcl_EYE_Close@L:0.45;Fcl_EYE_Close@R:0.35;Fcl_BRW_Angry@L:0.5;Fcl_BRW_Surprised@R:0.5;Fcl_MTH_Fun:0.4;Fcl_MTH_Fun@R:1.2;Fcl_MTH_Up@R:0.6 13:lip_A|Fcl_MTH_A:1 14:lip_I|Fcl_MTH_I:1Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/wren.py"; s=open(p).read() old=''' rest={"Fcl_BRW_Angry": 0.3})''' new=''' rest={"Fcl_BRW_Angry": 0.55, "Fcl_EYE_Angry": 0.35, "Fcl_MTH_Angry": 0.3})''' assert old in s; open(p,"w").write(s.replace(old,new)) E (time LOWMARCH_SITE=whole2 WHOLE_DESIGN=wren WHOLE_STANCE=longsword OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 tools/whole/build.py arm_f_slender wren) 2>&1 | grep -E "Error|Traceback|File|line|real|wren|!" | tail -14result, 3 lines
wren.glb 5.4 MB, 178s wren: 34 keyframes checked; no arm through the body, 24 with an arm resting on it real 2m58.167s
agent
+1:29:21Refit clips are in: 34 keys, no arm through the body. Re-exporting the model and shooting the attack sequence to pick final frames.
Bashcd ~/Projects/lowmarch-fable52 && OMP_NUM_THREADS=1 python3 tools/whole/export_model.py review/out/whole2/site wren review/out/whole2/site/wren.glb | tail -6 && cd review/out/stage && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && OMP_NUM_THREADS=1 python3 tools/whole/export_model.py review/out/whole2/site wren review/out/whole2/site/wren.glb | tail -6 && cd review/out/stage && python3 - <<'E' import json base=json.load(open("~/Projects/lowmarch-fable52/tools/whole/shots/battle.json")) base.update(w=960,h=540,ss=1.5) ts=[("idle",0.0),("idle",1.0),("attack",0.20),("attack",0.38),("attack",0.50),("attack",0.56),("attack",0.62),("attack",0.70),("attack",0.90),("attack",1.10),("attack",1.30),("attack",1.45)] base["frames"]=[{"clips":{"wren":[c,t],"mob_soldier":["idle",0.0]}} for c,t in ts] json.dump(base,open("seq.json","w")) E R=~/Projects/lowmarch-fable52; python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site seq.json seq 2>&1 | tail -3; python3 -c " from PIL import Image, ImageDraw ts=['idle 0.0','idle 1.0','atk 0.20','atk 0.38','atk 0.50','atk 0.56','atk 0.62','atk 0.70','atk 0.90','atk 1.10','atk 1.30','atk 1.45'] W=Image.new('RGB',(640*4,360*3)) for i,t in enumerate(ts): im=Image.open(f'seq/f{i:04d}.jpg').resize((640,360)); ImageDraw.Draw(im).text((8,6),t,fill=(0,0,0)); W.paste(im,(640*(i%4),360*(i//4))) W.save('seq.png')"result, 7 lines
meshes 125, primitives 125, triangles 115448, nodes 185 materials 32 (4 mask, 2 blend, 10 metallic), textures 10, images 10 skin: 59 joints, skeleton root Root, rest pose against bind matrices: 5.9e-08 off humanoid map in extras: 54 bones animations: idle 2.00 s (48 channels), attack 1.50 s (48 channels), apose 1.00 s (4 channels) bounds (m): x -0.310..0.310 y -0.009..1.758 z -0.258..1.020; height 1.768; face toward +Z seq 79s
Read~/Projects/lowmarch-fable52/review/out/stage/seq.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/seq.png" }result
no output
Bashcd ~/Projects/lowmarch-fable52/review/out/stage && R=~/Projects/lowmarch-fable52; python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site $R/tools/whole/shots/battle.json battle.png 2>&1 | tail -2
command
cd ~/Projects/lowmarch-fable52/review/out/stage && R=~/Projects/lowmarch-fable52; python3 $R/tools/whole/stage_shot.py $R/review/out/whole2/site $R/tools/whole/shots/battle.json battle.png 2>&1 | tail -2
result, 1 line
battle.png 46s
Read~/Projects/lowmarch-fable52/review/out/stage/battle.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/stage/battle.png" }result
no output







