agent-manifesto-kit 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -1
- package/collection/bundles/blender-3d/README.md +138 -0
- package/collection/bundles/blender-3d/agents/visual-reviewer.md +58 -0
- package/collection/bundles/blender-3d/skills/blender-asset/SKILL.md +75 -0
- package/collection/bundles/blender-3d/skills/blender-asset/scripts/record_run.py +175 -0
- package/collection/bundles/blender-3d/skills/blender-asset/scripts/task_state.py +199 -0
- package/collection/bundles/blender-3d/skills/blender-asset/workflows/asset.yml +105 -0
- package/collection/bundles/blender-3d/skills/blender-mocap-retarget/SKILL.md +115 -0
- package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/check_motion.py +244 -0
- package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/export_gltf_clip.py +71 -0
- package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/godot_verify.py +87 -0
- package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/inspect_motion_source.py +107 -0
- package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/render_frames.py +117 -0
- package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/verify_gltf.py +117 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/SKILL.md +110 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/colors.py +50 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/compare.py +77 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/contact_sheet.py +51 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/diff_renders.py +58 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/edges.py +54 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/measure_ref.py +137 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/mesh_report.py +67 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/refspec.py +91 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/render_views.py +99 -0
- package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/zoom.py +47 -0
- package/collection/bundles/kit-adopt/README.md +1 -1
- package/collection/bundles/kit-adopt/skills/kit-adopt/SKILL.md +2 -2
- package/collection/bundles/session-retro/README.md +64 -0
- package/collection/bundles/session-retro/agents/retro-analyst.md +77 -0
- package/collection/bundles/session-retro/skills/session-retro/SKILL.md +74 -0
- package/collection/bundles/session-retro/skills/session-retro/scripts/install_hooks.py +114 -0
- package/collection/bundles/session-retro/skills/session-retro/scripts/retro_hook.py +117 -0
- package/collection/bundles/session-retro/skills/session-retro/scripts/session_digest.py +457 -0
- package/dist/agent-format.js +218 -0
- package/dist/catalog.js +13 -13
- package/dist/cli.js +95 -4
- package/dist/commands/adopt.js +13 -3
- package/dist/commands/ingest.js +120 -0
- package/dist/commands/sync.js +201 -0
- package/dist/commands/update.js +36 -0
- package/dist/portability.js +19 -2
- package/dist/providers.js +12 -2
- package/package.json +1 -1
package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/export_gltf_clip.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Export a rigged character to glTF/GLB with exactly one clip per named action.
|
|
2
|
+
|
|
3
|
+
blender -b model.blend --python export_gltf_clip.py -- OUT.glb --rig Armature --actions Walk[,Run] \
|
|
4
|
+
[--collection Character]
|
|
5
|
+
|
|
6
|
+
Why: exported clip time counts from scene frame 0, so an action starting at frame 1 arrives
|
|
7
|
+
offset by a frame. Each action is placed on its own NLA track, named
|
|
8
|
+
after the action, with its strip starting at frame 0, and exported in NLA_TRACKS mode. That gives
|
|
9
|
+
clips named exactly after the actions, starting at clip time 0 with no duplicated frame.
|
|
10
|
+
(ACTIVE_ACTIONS names the clip "Animation"; ACTIONS also exports unrelated actions such as an
|
|
11
|
+
imported source clip.) The NLA edits exist only in this process: the .blend is never saved.
|
|
12
|
+
Without --actions the model exports static. Only the given collection (default: all visible
|
|
13
|
+
objects) is exported, so keep motion-source imports in another collection.
|
|
14
|
+
"""
|
|
15
|
+
import argparse
|
|
16
|
+
import os
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
import bpy
|
|
20
|
+
|
|
21
|
+
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
22
|
+
p = argparse.ArgumentParser()
|
|
23
|
+
p.add_argument("out")
|
|
24
|
+
p.add_argument("--rig")
|
|
25
|
+
p.add_argument("--actions", default="")
|
|
26
|
+
p.add_argument("--collection")
|
|
27
|
+
p.add_argument("--no-yup", action="store_true", help="keep Blender Z-up instead of glTF Y-up")
|
|
28
|
+
args = p.parse_args(argv)
|
|
29
|
+
|
|
30
|
+
if args.collection:
|
|
31
|
+
col = bpy.data.collections.get(args.collection)
|
|
32
|
+
if col is None:
|
|
33
|
+
raise SystemExit(f"no collection named {args.collection}")
|
|
34
|
+
export_objects = list(col.all_objects)
|
|
35
|
+
else:
|
|
36
|
+
export_objects = [o for o in bpy.context.scene.objects if o.visible_get()]
|
|
37
|
+
|
|
38
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
39
|
+
for ob in export_objects:
|
|
40
|
+
ob.hide_set(False)
|
|
41
|
+
ob.select_set(True)
|
|
42
|
+
|
|
43
|
+
kw = dict(filepath=os.path.abspath(args.out), export_format="GLB" if args.out.lower().endswith(".glb") else "GLTF_SEPARATE",
|
|
44
|
+
use_selection=True, export_apply=False, export_yup=not args.no_yup, export_materials="EXPORT")
|
|
45
|
+
|
|
46
|
+
actions = [a for a in args.actions.split(",") if a]
|
|
47
|
+
if actions:
|
|
48
|
+
rig = bpy.data.objects.get(args.rig or "")
|
|
49
|
+
if rig is None or rig.type != "ARMATURE":
|
|
50
|
+
raise SystemExit("--actions needs --rig with an armature object")
|
|
51
|
+
if rig not in export_objects:
|
|
52
|
+
raise SystemExit(f"rig {rig.name} is not among the exported objects")
|
|
53
|
+
ad = rig.animation_data or rig.animation_data_create()
|
|
54
|
+
for track in list(ad.nla_tracks):
|
|
55
|
+
ad.nla_tracks.remove(track)
|
|
56
|
+
for name in actions:
|
|
57
|
+
act = bpy.data.actions.get(name)
|
|
58
|
+
if act is None:
|
|
59
|
+
raise SystemExit(f"no action named {name}")
|
|
60
|
+
track = ad.nla_tracks.new()
|
|
61
|
+
track.name = name
|
|
62
|
+
track.strips.new(name, 0, act)
|
|
63
|
+
ad.action = None
|
|
64
|
+
kw.update(export_animations=True, export_animation_mode="NLA_TRACKS", export_skins=True,
|
|
65
|
+
export_def_bones=False, export_frame_range=False)
|
|
66
|
+
else:
|
|
67
|
+
kw.update(export_animations=False)
|
|
68
|
+
|
|
69
|
+
os.makedirs(os.path.dirname(os.path.abspath(args.out)), exist_ok=True)
|
|
70
|
+
bpy.ops.export_scene.gltf(**kw)
|
|
71
|
+
print(f"EXPORTED {len(export_objects)} object(s), clips {actions or 'none'} -> {args.out}")
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Import a GLB into a throwaway Godot 4 project headlessly and report what the engine sees.
|
|
2
|
+
|
|
3
|
+
python3 godot_verify.py OUT.glb [--godot godot] [--expect-clips Walk] [--keep]
|
|
4
|
+
|
|
5
|
+
Prints mesh and skinned-mesh counts, bone count, animation names with length, track count and
|
|
6
|
+
first/last key time. Exits non-zero when Godot fails, an expected clip is missing, or a clip's
|
|
7
|
+
first key is not at time 0. The project lives in a temporary directory, never in your game.
|
|
8
|
+
"""
|
|
9
|
+
import argparse
|
|
10
|
+
import os
|
|
11
|
+
import shutil
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import tempfile
|
|
15
|
+
|
|
16
|
+
SCRIPT = r'''
|
|
17
|
+
extends SceneTree
|
|
18
|
+
func _init():
|
|
19
|
+
var scene = load("res://asset.glb")
|
|
20
|
+
if scene == null:
|
|
21
|
+
print("RESULT_ERROR cannot load asset.glb")
|
|
22
|
+
quit(1)
|
|
23
|
+
return
|
|
24
|
+
var root_node = scene.instantiate()
|
|
25
|
+
var meshes = root_node.find_children("*", "MeshInstance3D", true, false)
|
|
26
|
+
var skinned = meshes.filter(func(m): return m.skin != null)
|
|
27
|
+
var skels = root_node.find_children("*", "Skeleton3D", true, false)
|
|
28
|
+
print("RESULT_MESHES %d skinned=%d" % [meshes.size(), skinned.size()])
|
|
29
|
+
print("RESULT_BONES %d" % (skels[0].get_bone_count() if skels.size() > 0 else 0))
|
|
30
|
+
for ap in root_node.find_children("*", "AnimationPlayer", true, false):
|
|
31
|
+
for name in ap.get_animation_list():
|
|
32
|
+
var a = ap.get_animation(name)
|
|
33
|
+
var first = 1e9
|
|
34
|
+
var last = 0.0
|
|
35
|
+
for i in a.get_track_count():
|
|
36
|
+
if a.track_get_key_count(i) > 0:
|
|
37
|
+
first = min(first, a.track_get_key_time(i, 0))
|
|
38
|
+
last = max(last, a.track_get_key_time(i, a.track_get_key_count(i) - 1))
|
|
39
|
+
print("RESULT_CLIP %s length=%.4f tracks=%d first_key=%.4f last_key=%.4f" % [name, a.length, a.get_track_count(), first, last])
|
|
40
|
+
quit()
|
|
41
|
+
'''
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def main():
|
|
45
|
+
p = argparse.ArgumentParser()
|
|
46
|
+
p.add_argument("glb")
|
|
47
|
+
p.add_argument("--godot", default=os.environ.get("GODOT", "godot"))
|
|
48
|
+
p.add_argument("--expect-clips", default="")
|
|
49
|
+
p.add_argument("--keep", action="store_true", help="keep the temporary project and print its path")
|
|
50
|
+
args = p.parse_args()
|
|
51
|
+
if shutil.which(args.godot) is None:
|
|
52
|
+
raise SystemExit(f"Godot executable '{args.godot}' not found; pass --godot or set GODOT")
|
|
53
|
+
tmp = tempfile.mkdtemp(prefix="godot-verify-")
|
|
54
|
+
try:
|
|
55
|
+
shutil.copy(args.glb, os.path.join(tmp, "asset.glb"))
|
|
56
|
+
with open(os.path.join(tmp, "project.godot"), "w") as f:
|
|
57
|
+
f.write('config_version=5\n[application]\nconfig/name="verify"\n')
|
|
58
|
+
with open(os.path.join(tmp, "verify.gd"), "w") as f:
|
|
59
|
+
f.write(SCRIPT)
|
|
60
|
+
subprocess.run([args.godot, "--headless", "--import"], cwd=tmp, capture_output=True, text=True, timeout=300)
|
|
61
|
+
run = subprocess.run([args.godot, "--headless", "-s", "verify.gd"], cwd=tmp, capture_output=True, text=True, timeout=300)
|
|
62
|
+
lines = [line for line in run.stdout.splitlines() if line.startswith("RESULT_")]
|
|
63
|
+
for line in lines:
|
|
64
|
+
print(line[len("RESULT_"):])
|
|
65
|
+
problems = [line for line in lines if line.startswith("RESULT_ERROR")]
|
|
66
|
+
if run.returncode != 0 or not lines:
|
|
67
|
+
problems.append(f"godot exited {run.returncode}: {run.stderr.strip()[-400:]}")
|
|
68
|
+
clips = {line.split()[1]: line for line in lines if line.startswith("RESULT_CLIP")}
|
|
69
|
+
for want in filter(None, args.expect_clips.split(",")):
|
|
70
|
+
if want not in clips:
|
|
71
|
+
problems.append(f"expected clip {want} not found (have {sorted(clips)})")
|
|
72
|
+
for name, line in clips.items():
|
|
73
|
+
first = float(line.split("first_key=")[1].split()[0])
|
|
74
|
+
if first > 1e-3:
|
|
75
|
+
problems.append(f"clip {name} first key at {first:.4f}s, not 0")
|
|
76
|
+
for problem in problems:
|
|
77
|
+
print("PROBLEM", problem)
|
|
78
|
+
if args.keep:
|
|
79
|
+
print("project:", tmp)
|
|
80
|
+
sys.exit(1 if problems else 0)
|
|
81
|
+
finally:
|
|
82
|
+
if not args.keep:
|
|
83
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
main()
|
package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/inspect_motion_source.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Inspect a motion source (FBX or glTF) before designing a retarget.
|
|
2
|
+
|
|
3
|
+
blender -b --factory-startup --python inspect_motion_source.py -- source.fbx [--json out.json]
|
|
4
|
+
|
|
5
|
+
Reports the skeleton (bone count, roots, finger bones), armature object scale, frame range and
|
|
6
|
+
fps, rest-pose arm angle (T- or A-pose), root motion of the hips over the clip, per-foot lowest
|
|
7
|
+
height relative to the rest pose, and the loop seam: how far the last frame's pose is from the
|
|
8
|
+
first, ignoring root translation. Works in an empty scene; nothing is saved.
|
|
9
|
+
"""
|
|
10
|
+
import argparse
|
|
11
|
+
import json
|
|
12
|
+
import math
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
import bpy
|
|
16
|
+
|
|
17
|
+
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
18
|
+
p = argparse.ArgumentParser()
|
|
19
|
+
p.add_argument("source")
|
|
20
|
+
p.add_argument("--json")
|
|
21
|
+
args = p.parse_args(argv)
|
|
22
|
+
|
|
23
|
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
24
|
+
if args.source.lower().endswith(".fbx"):
|
|
25
|
+
bpy.ops.import_scene.fbx(filepath=args.source, use_anim=True)
|
|
26
|
+
else:
|
|
27
|
+
bpy.ops.import_scene.gltf(filepath=args.source)
|
|
28
|
+
scene = bpy.context.scene
|
|
29
|
+
arms = [o for o in scene.objects if o.type == "ARMATURE"]
|
|
30
|
+
if not arms:
|
|
31
|
+
raise SystemExit("no armature in source")
|
|
32
|
+
arm = max(arms, key=lambda a: len(a.data.bones))
|
|
33
|
+
act = arm.animation_data.action if arm.animation_data else None
|
|
34
|
+
if act is None:
|
|
35
|
+
raise SystemExit(f"armature {arm.name} has no action")
|
|
36
|
+
f0, f1 = (int(round(v)) for v in act.frame_range)
|
|
37
|
+
names = [b.name for b in arm.data.bones]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def find(*keys, exclude=()):
|
|
41
|
+
for n in names:
|
|
42
|
+
low = n.lower()
|
|
43
|
+
if all(k in low for k in keys) and not any(x in low for x in exclude):
|
|
44
|
+
return n
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
hips = find("hips") or next(b.name for b in arm.data.bones if b.parent is None)
|
|
49
|
+
feet = {side: find(side, "foot") for side in ("left", "right")}
|
|
50
|
+
upper_arm = find("left", "arm", exclude=("fore", "shoulder", "hand"))
|
|
51
|
+
fingers = [n for n in names if any(k in n.lower() for k in ("index", "middle", "ring", "pinky", "thumb"))]
|
|
52
|
+
mw = arm.matrix_world
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def head(bone, frame=None):
|
|
56
|
+
if frame is None:
|
|
57
|
+
return mw @ arm.data.bones[bone].head_local
|
|
58
|
+
scene.frame_set(frame)
|
|
59
|
+
return mw @ arm.pose.bones[bone].head
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
rest_pose = None
|
|
63
|
+
if upper_arm:
|
|
64
|
+
b = arm.data.bones[upper_arm]
|
|
65
|
+
d = (mw.to_3x3() @ (b.tail_local - b.head_local)).normalized()
|
|
66
|
+
rest_pose = round(math.degrees(math.asin(max(-1.0, min(1.0, -d.z)))), 1)
|
|
67
|
+
|
|
68
|
+
report = {
|
|
69
|
+
"armature": arm.name,
|
|
70
|
+
"object_scale": [round(s, 4) for s in arm.scale],
|
|
71
|
+
"bones": len(names),
|
|
72
|
+
"roots": [b.name for b in arm.data.bones if b.parent is None],
|
|
73
|
+
"finger_bones": len(fingers),
|
|
74
|
+
"fps": scene.render.fps / scene.render.fps_base,
|
|
75
|
+
"frame_range": [f0, f1],
|
|
76
|
+
"hips": hips,
|
|
77
|
+
"upper_arm_below_horizontal_deg": rest_pose,
|
|
78
|
+
}
|
|
79
|
+
h0, h1 = head(hips, f0), head(hips, f1)
|
|
80
|
+
report["hips_root_motion_m"] = [round(v, 4) for v in (h1 - h0)]
|
|
81
|
+
report["hips_height_rest_m"] = round(head(hips).z, 4)
|
|
82
|
+
report["hips_height_range_m"] = [round(min(head(hips, f).z for f in range(f0, f1 + 1)), 4),
|
|
83
|
+
round(max(head(hips, f).z for f in range(f0, f1 + 1)), 4)]
|
|
84
|
+
report["feet"] = {}
|
|
85
|
+
for side, foot in feet.items():
|
|
86
|
+
if foot:
|
|
87
|
+
zs = [(head(foot, f).z, f) for f in range(f0, f1 + 1)]
|
|
88
|
+
low, frame = min(zs)
|
|
89
|
+
report["feet"][foot] = {"rest_z": round(head(foot).z, 4), "lowest_z": round(low, 4),
|
|
90
|
+
"lowest_minus_rest_m": round(low - head(foot).z, 4), "lowest_frame": frame}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def pose_rotations(frame):
|
|
94
|
+
scene.frame_set(frame)
|
|
95
|
+
return {pb.name: pb.matrix_basis.to_quaternion() for pb in arm.pose.bones}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
a, b = pose_rotations(f0), pose_rotations(f1)
|
|
99
|
+
worst = max(a, key=lambda n: a[n].rotation_difference(b[n]).angle)
|
|
100
|
+
report["loop_seam"] = {"max_rotation_diff_deg": round(math.degrees(a[worst].rotation_difference(b[worst]).angle), 3),
|
|
101
|
+
"worst_bone": worst,
|
|
102
|
+
"note": "near 0 with nonzero root motion means the last frame repeats the first plus one stride"}
|
|
103
|
+
|
|
104
|
+
print(json.dumps(report, indent=2))
|
|
105
|
+
if args.json:
|
|
106
|
+
with open(args.json, "w") as f:
|
|
107
|
+
json.dump(report, f, indent=2)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Render animation frames from several angles with cameras that follow the character.
|
|
2
|
+
|
|
3
|
+
blender -b model.blend --python render_frames.py -- OUTDIR --rig Armature \
|
|
4
|
+
[--views front,side,q34,back,feet] [--frames all|1,5,9|1-41:4] [--res 520] [--follow Hips]
|
|
5
|
+
|
|
6
|
+
A checker floor makes foot sliding visible; cameras track the --follow bone horizontally so root
|
|
7
|
+
motion stays in frame. Writes OUTDIR/<view>_<frame>.png; tile them with contact_sheet.py from the
|
|
8
|
+
sibling skill (../blender-reference-model/scripts/ relative to this skill's folder). Never saves the .blend.
|
|
9
|
+
Views: front, back, side (character's right), left, q34, q34b, feet, hipL, hipR, shoulderL, shoulderR.
|
|
10
|
+
"""
|
|
11
|
+
import argparse
|
|
12
|
+
import math
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
import bpy
|
|
17
|
+
from mathutils import Vector
|
|
18
|
+
|
|
19
|
+
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
20
|
+
p = argparse.ArgumentParser()
|
|
21
|
+
p.add_argument("outdir")
|
|
22
|
+
p.add_argument("--rig", required=True)
|
|
23
|
+
p.add_argument("--views", default="front,side,q34")
|
|
24
|
+
p.add_argument("--frames", default="all")
|
|
25
|
+
p.add_argument("--res", type=int, default=520)
|
|
26
|
+
p.add_argument("--follow", default="Hips", help="bone whose ground position the cameras track")
|
|
27
|
+
p.add_argument("--height", type=float, default=1.8, help="character height, scales camera distances")
|
|
28
|
+
args = p.parse_args(argv)
|
|
29
|
+
|
|
30
|
+
scene = bpy.context.scene
|
|
31
|
+
rig = bpy.data.objects.get(args.rig)
|
|
32
|
+
if rig is None or args.follow not in rig.pose.bones:
|
|
33
|
+
raise SystemExit(f"need armature {args.rig} with bone {args.follow}")
|
|
34
|
+
if args.frames == "all":
|
|
35
|
+
frames = list(range(scene.frame_start, scene.frame_end + 1))
|
|
36
|
+
elif "-" in args.frames:
|
|
37
|
+
span, _, step = args.frames.partition(":")
|
|
38
|
+
a, b = (int(x) for x in span.split("-"))
|
|
39
|
+
frames = list(range(a, b + 1, int(step or 1)))
|
|
40
|
+
else:
|
|
41
|
+
frames = [int(x) for x in args.frames.split(",")]
|
|
42
|
+
os.makedirs(args.outdir, exist_ok=True)
|
|
43
|
+
|
|
44
|
+
k = args.height / 1.8
|
|
45
|
+
# view: (camera offset from the tracked ground point, look-at offset, ortho scale or None, lens)
|
|
46
|
+
SETUPS = {
|
|
47
|
+
"front": ((0, -6, 0.95), (0, 0, 0.95), 2.2, None),
|
|
48
|
+
"back": ((0, 6, 0.95), (0, 0, 0.95), 2.2, None),
|
|
49
|
+
"side": ((-6, 0, 0.95), (0, 0, 0.95), 2.2, None),
|
|
50
|
+
"left": ((6, 0, 0.95), (0, 0, 0.95), 2.2, None),
|
|
51
|
+
"q34": ((2.4, -3.6, 1.5), (0, 0, 0.9), None, 45),
|
|
52
|
+
"q34b": ((-2.6, 3.4, 1.5), (0, 0, 0.9), None, 45),
|
|
53
|
+
"feet": ((1.4, -2.0, 0.6), (0, 0, 0.18), None, 45),
|
|
54
|
+
"hipL": ((1.3, -0.9, 1.05), (0.25, 0, 0.85), None, 40),
|
|
55
|
+
"hipR": ((-1.3, -0.9, 1.05), (-0.25, 0, 0.85), None, 40),
|
|
56
|
+
"shoulderL": ((1.2, -1.2, 1.55), (0.3, 0, 1.2), None, 40),
|
|
57
|
+
"shoulderR": ((-1.2, -1.2, 1.55), (-0.3, 0, 1.2), None, 40),
|
|
58
|
+
}
|
|
59
|
+
views = args.views.split(",")
|
|
60
|
+
unknown = [v for v in views if v not in SETUPS]
|
|
61
|
+
if unknown:
|
|
62
|
+
raise SystemExit(f"unknown views {unknown}; choose from {sorted(SETUPS)}")
|
|
63
|
+
|
|
64
|
+
engines = {i.identifier for i in scene.render.bl_rna.properties["engine"].enum_items}
|
|
65
|
+
scene.render.engine = next(e for e in ("BLENDER_EEVEE", "BLENDER_EEVEE_NEXT", "BLENDER_WORKBENCH") if e in engines)
|
|
66
|
+
scene.render.film_transparent = False
|
|
67
|
+
scene.view_settings.view_transform = "Standard"
|
|
68
|
+
world = bpy.data.worlds.new("FramesWorld")
|
|
69
|
+
scene.world = world
|
|
70
|
+
world.use_nodes = True
|
|
71
|
+
world.node_tree.nodes["Background"].inputs["Color"].default_value = (0.16, 0.16, 0.16, 1)
|
|
72
|
+
for name, rot, energy in (("FramesKey", (50, 0, -30), 3.0), ("FramesFill", (70, 0, 150), 0.8)):
|
|
73
|
+
light = bpy.data.lights.new(name, "SUN")
|
|
74
|
+
light.energy = energy
|
|
75
|
+
ob = bpy.data.objects.new(name, light)
|
|
76
|
+
ob.rotation_euler = [math.radians(a) for a in rot]
|
|
77
|
+
scene.collection.objects.link(ob)
|
|
78
|
+
|
|
79
|
+
mesh = bpy.data.meshes.new("FramesFloor")
|
|
80
|
+
size = 20.0
|
|
81
|
+
mesh.from_pydata([(-size, -size, 0), (size, -size, 0), (size, size, 0), (-size, size, 0)], [], [(0, 1, 2, 3)])
|
|
82
|
+
floor = bpy.data.objects.new("FramesFloor", mesh)
|
|
83
|
+
scene.collection.objects.link(floor)
|
|
84
|
+
mat = bpy.data.materials.new("FramesChecker")
|
|
85
|
+
mat.use_nodes = True
|
|
86
|
+
nodes = mat.node_tree.nodes
|
|
87
|
+
checker = nodes.new("ShaderNodeTexChecker")
|
|
88
|
+
checker.inputs["Scale"].default_value = 2 # object coords: 0.5 m tiles
|
|
89
|
+
checker.inputs["Color1"].default_value = (0.42, 0.42, 0.42, 1)
|
|
90
|
+
checker.inputs["Color2"].default_value = (0.36, 0.36, 0.36, 1)
|
|
91
|
+
coords = nodes.new("ShaderNodeTexCoord")
|
|
92
|
+
mat.node_tree.links.new(coords.outputs["Object"], checker.inputs["Vector"])
|
|
93
|
+
mat.node_tree.links.new(checker.outputs["Color"], nodes["Principled BSDF"].inputs["Base Color"])
|
|
94
|
+
mesh.materials.append(mat)
|
|
95
|
+
|
|
96
|
+
cam_data = bpy.data.cameras.new("FramesCam")
|
|
97
|
+
cam = bpy.data.objects.new("FramesCam", cam_data)
|
|
98
|
+
scene.collection.objects.link(cam)
|
|
99
|
+
scene.camera = cam
|
|
100
|
+
|
|
101
|
+
for view in views:
|
|
102
|
+
offset, target, ortho, lens = SETUPS[view]
|
|
103
|
+
for frame in frames:
|
|
104
|
+
scene.frame_set(frame)
|
|
105
|
+
hp = rig.matrix_world @ rig.pose.bones[args.follow].head
|
|
106
|
+
base = Vector((hp.x, hp.y, 0))
|
|
107
|
+
cam.location = base + Vector(offset) * k
|
|
108
|
+
cam.rotation_euler = ((base + Vector(target) * k) - cam.location).to_track_quat("-Z", "Y").to_euler()
|
|
109
|
+
if ortho:
|
|
110
|
+
cam_data.type, cam_data.ortho_scale = "ORTHO", ortho * k
|
|
111
|
+
scene.render.resolution_x, scene.render.resolution_y = int(args.res * 0.8), args.res
|
|
112
|
+
else:
|
|
113
|
+
cam_data.type, cam_data.lens = "PERSP", lens
|
|
114
|
+
scene.render.resolution_x = scene.render.resolution_y = args.res
|
|
115
|
+
scene.render.filepath = os.path.join(args.outdir, f"{view}_{frame:03d}.png")
|
|
116
|
+
bpy.ops.render.render(write_still=True)
|
|
117
|
+
print(f"RENDERED {len(views) * len(frames)} frame(s) -> {args.outdir}")
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Re-import an exported glTF/GLB into an empty scene and verify what arrived.
|
|
2
|
+
|
|
3
|
+
blender -b --factory-startup --python-exit-code 1 --python verify_gltf.py -- OUT.glb \
|
|
4
|
+
--expect-clips Walk,Run --exact-clips --require-mesh --require-skin --require-rig
|
|
5
|
+
|
|
6
|
+
Legacy --expect-clips matches imported action prefixes. --exact-clips compares the
|
|
7
|
+
original glTF animation names as an exact set, including unexpected exports; this
|
|
8
|
+
avoids ambiguity from Blender's action renaming. Structural requirements check
|
|
9
|
+
imported usable geometry, weighted skinned geometry, and an armature with bones.
|
|
10
|
+
Without requirements the script remains diagnostic, apart from expected missing
|
|
11
|
+
clips and nonzero clip start frames. --json writes a machine-readable summary.
|
|
12
|
+
"""
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import math
|
|
16
|
+
import struct
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
import bpy
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def fps_value(value):
|
|
23
|
+
fps = float(value)
|
|
24
|
+
if not math.isfinite(fps) or fps < 1 or fps > 32767:
|
|
25
|
+
raise argparse.ArgumentTypeError("must be finite and between 1 and 32767")
|
|
26
|
+
return fps
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def read_gltf(path):
|
|
30
|
+
"""Read the export's JSON, without depending on Blender action name suffixes."""
|
|
31
|
+
with open(path, "rb") as stream:
|
|
32
|
+
data = stream.read()
|
|
33
|
+
if data[:4] != b"glTF":
|
|
34
|
+
return json.loads(data.decode("utf-8-sig"))
|
|
35
|
+
if len(data) < 20:
|
|
36
|
+
raise ValueError("truncated GLB header")
|
|
37
|
+
magic, version, length = struct.unpack_from("<4sII", data)
|
|
38
|
+
if version != 2 or length != len(data):
|
|
39
|
+
raise ValueError("invalid GLB version or length")
|
|
40
|
+
chunk_length, chunk_type = struct.unpack_from("<II", data, 12)
|
|
41
|
+
if chunk_type != 0x4E4F534A or 20 + chunk_length > len(data):
|
|
42
|
+
raise ValueError("missing or truncated GLB JSON chunk")
|
|
43
|
+
return json.loads(data[20:20 + chunk_length].decode("utf-8"))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
47
|
+
p = argparse.ArgumentParser()
|
|
48
|
+
p.add_argument("path")
|
|
49
|
+
p.add_argument("--expect-clips", default="")
|
|
50
|
+
p.add_argument("--exact-clips", action="store_true", help="require exactly --expect-clips using original exported animation names")
|
|
51
|
+
p.add_argument("--require-mesh", action="store_true")
|
|
52
|
+
p.add_argument("--require-skin", action="store_true")
|
|
53
|
+
p.add_argument("--require-rig", action="store_true")
|
|
54
|
+
p.add_argument("--fps", type=fps_value, default=30.0)
|
|
55
|
+
p.add_argument("--json")
|
|
56
|
+
args = p.parse_args(argv)
|
|
57
|
+
expected = [name.strip() for name in args.expect_clips.split(",") if name.strip()]
|
|
58
|
+
if len(expected) != len(set(expected)):
|
|
59
|
+
p.error("--expect-clips contains duplicate names")
|
|
60
|
+
source = read_gltf(args.path)
|
|
61
|
+
source_clips = [animation.get("name") for animation in source.get("animations", [])]
|
|
62
|
+
|
|
63
|
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
64
|
+
bpy.context.scene.render.fps = int(args.fps)
|
|
65
|
+
bpy.context.scene.render.fps_base = int(args.fps) / args.fps
|
|
66
|
+
bpy.ops.import_scene.gltf(filepath=args.path)
|
|
67
|
+
objects = bpy.context.scene.objects
|
|
68
|
+
meshes = [o for o in objects if o.type == "MESH"]
|
|
69
|
+
skinned = [o for o in meshes if any(m.type == "ARMATURE" for m in o.modifiers)]
|
|
70
|
+
arms = [o for o in objects if o.type == "ARMATURE"]
|
|
71
|
+
geometry = [o for o in meshes if o.data.vertices and o.data.polygons]
|
|
72
|
+
usable_skin = [o for o in geometry
|
|
73
|
+
if any(m.type == "ARMATURE" and m.object and m.object.type == "ARMATURE" and m.object.data.bones
|
|
74
|
+
for m in o.modifiers)
|
|
75
|
+
and any(g.weight > 0 for vertex in o.data.vertices for g in vertex.groups)]
|
|
76
|
+
rigs = [a for a in arms if a.data.bones]
|
|
77
|
+
print(f"MESHES {len(meshes)} (skinned {len(skinned)}) ARMATURES {len(arms)} BONES {sum(len(a.data.bones) for a in arms)}")
|
|
78
|
+
|
|
79
|
+
problems = []
|
|
80
|
+
clips = {}
|
|
81
|
+
for act in bpy.data.actions:
|
|
82
|
+
f0, f1 = act.frame_range
|
|
83
|
+
clips[act.name] = [float(f0), float(f1)]
|
|
84
|
+
print(f"CLIP {act.name}: frames {f0:g}-{f1:g} duration {(f1 - f0) / args.fps:.3f} s")
|
|
85
|
+
if abs(f0) > 1e-3:
|
|
86
|
+
problems.append(f"clip {act.name} starts at frame {f0:g}, not 0")
|
|
87
|
+
for want in expected:
|
|
88
|
+
if not any(name == want or name.startswith(want + "_") or name.startswith(want + ".") for name in clips):
|
|
89
|
+
problems.append(f"expected clip {want} not found after import (have {sorted(clips)})")
|
|
90
|
+
if args.exact_clips:
|
|
91
|
+
named = [name for name in source_clips if isinstance(name, str) and name]
|
|
92
|
+
if len(named) != len(source_clips):
|
|
93
|
+
problems.append("export contains unnamed animation clips")
|
|
94
|
+
if len(named) != len(set(named)):
|
|
95
|
+
problems.append("export contains duplicate animation clip names")
|
|
96
|
+
missing, extra = sorted(set(expected) - set(named)), sorted(set(named) - set(expected))
|
|
97
|
+
if missing:
|
|
98
|
+
problems.append(f"expected exported clips missing: {missing}")
|
|
99
|
+
if extra:
|
|
100
|
+
problems.append(f"unexpected exported clips: {extra}")
|
|
101
|
+
if args.require_mesh and not geometry:
|
|
102
|
+
problems.append("required mesh with vertices and polygons not found")
|
|
103
|
+
if args.require_skin and not usable_skin:
|
|
104
|
+
problems.append("required weighted skinned mesh with geometry and a bone rig not found")
|
|
105
|
+
if args.require_rig and not rigs:
|
|
106
|
+
problems.append("required armature with bones not found")
|
|
107
|
+
report = {"status": "fail" if problems else "pass", "meshes": len(meshes), "skinned_meshes": len(skinned),
|
|
108
|
+
"armatures": len(arms), "bones": sum(len(a.data.bones) for a in arms),
|
|
109
|
+
"clips": clips, "exported_clips": source_clips, "problems": problems,
|
|
110
|
+
"requirements": {"exact_clips": args.exact_clips, "expected_clips": expected,
|
|
111
|
+
"mesh": args.require_mesh, "skin": args.require_skin, "rig": args.require_rig}}
|
|
112
|
+
for problem in problems:
|
|
113
|
+
print("PROBLEM", problem)
|
|
114
|
+
if args.json:
|
|
115
|
+
with open(args.json, "w") as stream:
|
|
116
|
+
json.dump(report, stream, indent=2)
|
|
117
|
+
sys.exit(1 if problems else 0)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: blender-reference-model
|
|
3
|
+
description: Build or revise a game-ready low-poly Blender model that must match a supplied reference image (turnaround or orthographic views) as closely as possible. Use for scripted Blender modeling from a reference sheet; not for rigging or animation, and not for free concept design.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Blender Reference Model
|
|
7
|
+
|
|
8
|
+
## Scope
|
|
9
|
+
|
|
10
|
+
Build or revise a model against supplied reference views. The reference is authoritative except
|
|
11
|
+
for explicit requested deviations. Return editable source and evidence for the task contract;
|
|
12
|
+
profile selection, review and bounded repair are owned by the companion
|
|
13
|
+
`../blender-asset/workflows/asset.yml`. A direct invocation needs the same explicit acceptance
|
|
14
|
+
criteria and required evidence; do not invent a universal quality target.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
- Install the complete `blender-3d` bundle; its sibling skills and workflow are required context.
|
|
19
|
+
- Install [Blender](https://www.blender.org/download/); verify `blender --version`.
|
|
20
|
+
- Install [Python 3](https://www.python.org/downloads/), then `python3 -m pip install Pillow numpy`;
|
|
21
|
+
verify `python3 -c "import PIL, numpy"`. [Pillow](https://pillow.readthedocs.io/) and
|
|
22
|
+
[NumPy](https://numpy.org/) run with system Python, outside Blender.
|
|
23
|
+
- Store executable paths and project conventions in the consumer project.
|
|
24
|
+
|
|
25
|
+
## Invariants
|
|
26
|
+
|
|
27
|
+
- Build through a persisted Python builder run with `blender -b`; no unrecorded manual edits.
|
|
28
|
+
Rebuilding must reproduce the model. If the user edits the `.blend` by hand, that file becomes
|
|
29
|
+
authoritative: never rebuild over it; build into a new file and reconcile.
|
|
30
|
+
- Preserve project units, axes and origins. For a new character with no conventions, record
|
|
31
|
+
metres, Z up, facing -Y and ground origin as defaults before building.
|
|
32
|
+
- Each removable or separately animated part (clothing, boots, belt, pouches, props, hair) is its
|
|
33
|
+
own object, named for its role, with a deliberate origin (attachment point or joint).
|
|
34
|
+
- Measure before modeling. Take proportions from the reference in pixels, not from generic anatomy.
|
|
35
|
+
- Silhouette overlap is a floor, not the target. It cannot see faces, hands, colours or details
|
|
36
|
+
inside the outline. Those need magnified side-by-side inspection.
|
|
37
|
+
- Keep machine paths (Blender and engine executables) in the project's own instructions, not in
|
|
38
|
+
builders.
|
|
39
|
+
|
|
40
|
+
## Tools
|
|
41
|
+
|
|
42
|
+
Scripts in this skill's `scripts/` folder. Image scripts run with system Python 3 plus Pillow and
|
|
43
|
+
numpy. Blender's bundled Python has neither, so run them outside Blender.
|
|
44
|
+
|
|
45
|
+
| Script | Purpose |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `measure_ref.py` | Draft `ref_spec.json` (view crops, cameras, ground row, metres per pixel) and print a view's silhouette profile in metres |
|
|
48
|
+
| `render_views.py` | Blender: orthographic renders at the reference's pixel scale, transparent background, armatures in rest pose |
|
|
49
|
+
| `compare.py` | IoU per view, red/blue overlay sheet, height difference; writes `compare.png` and `compare.json` |
|
|
50
|
+
| `edges.py` | Row-by-row edge differences in mm for one view: turns the overlay into concrete corrections |
|
|
51
|
+
| `zoom.py` | Magnified reference and render side by side for one region (face, hands, belt, boots) |
|
|
52
|
+
| `colors.py` | Sampled colour ratios between the reference and the render |
|
|
53
|
+
| `diff_renders.py` | Pixel diff of two render folders, e.g. before and after rigging; exits non-zero on change |
|
|
54
|
+
| `contact_sheet.py` | Tile renders into one image for review |
|
|
55
|
+
| `mesh_report.py` | Blender: per-object triangles, non-manifold edges, degenerate faces, loose vertices, empty slots |
|
|
56
|
+
|
|
57
|
+
`refspec.py` documents the spec format. Drafted view names and cameras are guesses: confirm them
|
|
58
|
+
against the sheet's labels before building.
|
|
59
|
+
|
|
60
|
+
## Procedure
|
|
61
|
+
|
|
62
|
+
Apply Stop Conditions immediately during every step; return the blocked work and evidence gaps.
|
|
63
|
+
|
|
64
|
+
1. Confirm task criteria, reference priorities and requested deviations. Draft and confirm the
|
|
65
|
+
spec; set `meters_per_px` from the intended dimensions. View names/cameras are guesses until
|
|
66
|
+
checked against the sheet labels. Record conflicting views instead of averaging silently.
|
|
67
|
+
2. Measure silhouettes and primary forms before adding detail. For a revision, preserve accepted
|
|
68
|
+
geometry and start from the authoritative asset; edit only the scoped region.
|
|
69
|
+
3. Render selected views at the reference scale. Use `compare.py` and `edges.py` to identify
|
|
70
|
+
differences, and report per-view IoU as a diagnostic. Acceptance uses the task's tolerances,
|
|
71
|
+
identity features and intended display size; no fixed IoU score guarantees completion.
|
|
72
|
+
4. Inspect relevant interior details with `zoom.py` (for example a prop latch, face or equipment
|
|
73
|
+
attachment). Inspect colours when colour fidelity is required, respecting requested changes.
|
|
74
|
+
5. Render additional angles only where needed to test required visibility, construction or
|
|
75
|
+
changed dependencies. Check for floating parts, poke-through and unfinished surfaces.
|
|
76
|
+
6. Run `mesh_report.py` for the agreed object scope and assess the task's topology/material/size
|
|
77
|
+
constraints. Explain intentional open edges. Export and re-import only when export is a
|
|
78
|
+
deliverable; record unrun required checks as `not_tested`.
|
|
79
|
+
7. Return current evidence and concrete remaining differences after this build or repair stage.
|
|
80
|
+
The companion workflow owns further repairs and independent-review gates.
|
|
81
|
+
|
|
82
|
+
## Stop Conditions
|
|
83
|
+
|
|
84
|
+
Missing essential references, unresolved priority conflicts or an overwrite of authoritative
|
|
85
|
+
hand edits block the affected work. Missing required evidence blocks acceptance. Return the
|
|
86
|
+
specific gap; do not quietly weaken criteria or keep iterating past the reserved repair stage.
|
|
87
|
+
|
|
88
|
+
## Known Pitfalls
|
|
89
|
+
|
|
90
|
+
- A flat plate placed on a lofted, curved surface gets swallowed by the bulge. Make pockets,
|
|
91
|
+
flaps and patches follow the surface.
|
|
92
|
+
- Colours sampled from the reference are display (sRGB) values, and Blender's Base Color is
|
|
93
|
+
linear: convert before use. Lighting then shifts the rendered value either way, so treat the
|
|
94
|
+
first material colours as a starting point. Judge `colors.py` ratios against the task's
|
|
95
|
+
colour tolerances within the reserved stage. Preserve agreed colour management; Standard
|
|
96
|
+
can help untonemapped comparisons, while Filmic/AgX changes the displayed colour response.
|
|
97
|
+
- AI-generated turnaround sheets often disagree slightly between views (head height, prop side).
|
|
98
|
+
Match the priority the user set, and report the conflict instead of averaging silently.
|
|
99
|
+
- A rigged model renders in its animated pose unless the armature is set to rest.
|
|
100
|
+
`render_views.py` does this by default.
|
|
101
|
+
|
|
102
|
+
## Output Contract
|
|
103
|
+
|
|
104
|
+
`Skill: blender-reference-model - output below`
|
|
105
|
+
|
|
106
|
+
Report the editable `.blend` and persisted builder/edit script; selected comparison views with
|
|
107
|
+
per-view IoU; relevant detail/extra-angle evidence; scoped mesh/check statuses (`pass`, `fail`,
|
|
108
|
+
`not_tested`); requested export evidence; intentional deviations and unresolved differences.
|
|
109
|
+
List required evidence that is missing. Do not imply unrendered views or untested engine imports
|
|
110
|
+
passed. Evidence paths feed the companion workflow's review and completion gates.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Compare sampled colours between the reference and the renders.
|
|
2
|
+
|
|
3
|
+
python3 colors.py ref_spec.json RENDERDIR points.json
|
|
4
|
+
|
|
5
|
+
points.json maps a label to [view, x, y] in reference image pixels, for example
|
|
6
|
+
{"skin_cheek": ["front", 278, 85], "trousers": ["front", 260, 330]}
|
|
7
|
+
Each sample averages a 5x5 patch. ratio = reference / render per channel: values above 1 mean the
|
|
8
|
+
render is too dark. Reference samples are display (sRGB) values while Blender's Base Color is
|
|
9
|
+
linear, so convert before use, then adjust until the ratios are close to 1.
|
|
10
|
+
"""
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
from PIL import Image
|
|
18
|
+
|
|
19
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
20
|
+
from refspec import background_colour, composite, load_reference, load_spec # noqa: E402
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
p = argparse.ArgumentParser()
|
|
25
|
+
p.add_argument("spec")
|
|
26
|
+
p.add_argument("render_dir")
|
|
27
|
+
p.add_argument("points")
|
|
28
|
+
args = p.parse_args()
|
|
29
|
+
spec = load_spec(args.spec)
|
|
30
|
+
_, arr = load_reference(spec)
|
|
31
|
+
bg = background_colour(arr)
|
|
32
|
+
with open(args.points) as f:
|
|
33
|
+
points = json.load(f)
|
|
34
|
+
renders = {}
|
|
35
|
+
print(f"{'label':16s} {'reference':>15s} {'render':>15s} ratio")
|
|
36
|
+
for label, (view, x, y) in points.items():
|
|
37
|
+
cx0, cy0, cx1, cy1 = spec["views"][view]["crop"]
|
|
38
|
+
if view not in renders:
|
|
39
|
+
img = composite(Image.open(os.path.join(args.render_dir, f"{view}.png")).convert("RGBA"), bg)
|
|
40
|
+
renders[view] = (np.asarray(img).astype(float), img.size[0] / (cx1 - cx0), img.size[1] / (cy1 - cy0))
|
|
41
|
+
ren, sx, sy = renders[view]
|
|
42
|
+
rx, ry = round((x - cx0) * sx), round((y - cy0) * sy)
|
|
43
|
+
a = arr[y - 2:y + 3, x - 2:x + 3].reshape(-1, 3).mean(0)
|
|
44
|
+
b = ren[max(ry - 2, 0):ry + 3, max(rx - 2, 0):rx + 3].reshape(-1, 3).mean(0)
|
|
45
|
+
ratio = np.round(a / np.maximum(b, 1), 2)
|
|
46
|
+
print(f"{label:16s} {str(a.astype(int).tolist()):>15s} {str(b.astype(int).tolist()):>15s} {ratio.tolist()}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
main()
|