agent-manifesto-kit 1.8.1 → 1.8.2

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.
Files changed (38) hide show
  1. package/README.md +18 -0
  2. package/collection/skills/concept-asset-builder/SKILL.md +124 -0
  3. package/collection/skills/concept-asset-builder/agents/openai.yaml +4 -0
  4. package/collection/skills/concept-asset-builder/assets/templates/agent_brief.md +56 -0
  5. package/collection/skills/concept-asset-builder/assets/templates/rubric.json +50 -0
  6. package/collection/skills/concept-asset-builder/assets/templates/rubric_example_vending.json +14 -0
  7. package/collection/skills/concept-asset-builder/assets/templates/scene_style_example.md +30 -0
  8. package/collection/skills/concept-asset-builder/assets/templates/wear_description_example.md +50 -0
  9. package/collection/skills/concept-asset-builder/assets/templates/zones.json +10 -0
  10. package/collection/skills/concept-asset-builder/assets/templates/zones_example_vending.json +69 -0
  11. package/collection/skills/concept-asset-builder/references/examples/postbox_blender.py +1112 -0
  12. package/collection/skills/concept-asset-builder/references/examples/postbox_wear_three.js +742 -0
  13. package/collection/skills/concept-asset-builder/references/examples/vending_materials_blender.py +487 -0
  14. package/collection/skills/concept-asset-builder/references/examples/vending_wear_three.js +798 -0
  15. package/collection/skills/concept-asset-builder/references/field-lessons.md +36 -0
  16. package/collection/skills/concept-asset-builder/references/wear-language.md +36 -0
  17. package/collection/skills/concept-asset-builder/scripts/blender/bake_export.py +174 -0
  18. package/collection/skills/concept-asset-builder/scripts/blender/render_views.py +100 -0
  19. package/collection/skills/concept-asset-builder/scripts/blender/studio.py +73 -0
  20. package/collection/skills/concept-asset-builder/scripts/capture.mjs +44 -0
  21. package/collection/skills/concept-asset-builder/scripts/codex_review.sh +88 -0
  22. package/collection/skills/concept-asset-builder/scripts/compare_to.py +24 -0
  23. package/collection/skills/concept-asset-builder/scripts/composite_godot.py +13 -0
  24. package/collection/skills/concept-asset-builder/scripts/crop.py +9 -0
  25. package/collection/skills/concept-asset-builder/scripts/gen_texture.sh +18 -0
  26. package/collection/skills/concept-asset-builder/scripts/godot/capture.gd +122 -0
  27. package/collection/skills/concept-asset-builder/scripts/godot/project.godot +18 -0
  28. package/collection/skills/concept-asset-builder/scripts/init_workspace.sh +17 -0
  29. package/collection/skills/concept-asset-builder/scripts/measure_silhouette.py +40 -0
  30. package/collection/skills/concept-asset-builder/scripts/metrics.py +144 -0
  31. package/collection/skills/concept-asset-builder/scripts/sheet.py +19 -0
  32. package/collection/skills/concept-asset-builder/scripts/test_tools.py +121 -0
  33. package/collection/skills/concept-asset-builder/scripts/threejs/index.html +23 -0
  34. package/collection/skills/concept-asset-builder/scripts/threejs/model.js +9 -0
  35. package/collection/skills/concept-asset-builder/scripts/threejs/studio.js +178 -0
  36. package/collection/skills/concept-asset-builder/scripts/wear_stats.py +130 -0
  37. package/collection/skills/concept-scene-builder/SKILL.md +16 -3
  38. package/package.json +1 -1
@@ -0,0 +1,122 @@
1
+ # Pipeline D capture: godot --path godot --script capture.gd -- [view ...] [--interactive]
2
+ # Loads res://object.glb (baked Blender asset), builds a neutral studio that mirrors the Blender rig
3
+ # (camera-relative key/fill/rim area-like lights + soft white sky light), renders each concept view with a
4
+ # transparent background and saves ../out/godot/raw/<view>.png. Compositing onto the page background is done by
5
+ # tools/composite_godot.py so the background colour is never tone-mapped.
6
+ extends SceneTree
7
+
8
+ const CAL := {
9
+ "exposure": 0.58, "sky_energy": 0.55, "key": 2.2, "fill": 0.9, "rim": 0.7,
10
+ }
11
+ var spec: Dictionary
12
+ var cam: Camera3D
13
+ var rig: Node3D
14
+ var corners: Array = []
15
+
16
+ func _initialize() -> void:
17
+ spec = JSON.parse_string(FileAccess.get_file_as_string(ProjectSettings.globalize_path("res://").path_join("../spec/object.json")))
18
+ var root3d := Node3D.new()
19
+ root.add_child(root3d)
20
+ var env := Environment.new()
21
+ env.background_mode = Environment.BG_SKY
22
+ var sky := Sky.new()
23
+ var sm := ProceduralSkyMaterial.new()
24
+ sm.sky_top_color = Color(0.72, 0.72, 0.72); sm.sky_horizon_color = Color(1, 1, 1)
25
+ sm.ground_bottom_color = Color(0.6, 0.6, 0.6); sm.ground_horizon_color = Color(0.9, 0.9, 0.9)
26
+ sm.sun_angle_max = 0.0
27
+ sky.sky_material = sm
28
+ env.sky = sky
29
+ env.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
30
+ env.reflected_light_source = Environment.REFLECTION_SOURCE_SKY
31
+ env.ambient_light_sky_contribution = 1.0
32
+ env.background_energy_multiplier = CAL.sky_energy
33
+ env.tonemap_mode = Environment.TONE_MAPPER_LINEAR # mirrors Blender "Standard"
34
+ env.tonemap_exposure = CAL.exposure
35
+ env.ssao_enabled = false # AO is baked into the base colour
36
+ var we := WorldEnvironment.new()
37
+ we.environment = env
38
+ root3d.add_child(we)
39
+
40
+ var scene: PackedScene = load("res://object.glb")
41
+ var box: Node3D = scene.instantiate()
42
+ root3d.add_child(box)
43
+ self.set_meta("box", box)
44
+
45
+ rig = Node3D.new()
46
+ root3d.add_child(rig)
47
+ _add_light("key", -40, 38, CAL.key, true)
48
+ _add_light("fill", 55, 15, CAL.fill, false)
49
+ _add_light("rim", 170, 35, CAL.rim, false)
50
+
51
+ cam = Camera3D.new()
52
+ cam.fov = spec.cameras.fov_deg
53
+ cam.keep_aspect = Camera3D.KEEP_HEIGHT
54
+ root3d.add_child(cam)
55
+ cam.current = true
56
+ root.transparent_bg = true
57
+ _run.call_deferred()
58
+
59
+ func _add_light(name: String, az: float, el: float, energy: float, shadow: bool) -> void:
60
+ var l := DirectionalLight3D.new()
61
+ l.name = name
62
+ l.light_energy = energy
63
+ l.shadow_enabled = shadow
64
+ l.light_angular_distance = 8.0 # soft, like Blender's 3 m area lights at 4 m
65
+ var a := deg_to_rad(az); var e := deg_to_rad(el)
66
+ var dir := Vector3(sin(a) * cos(e), sin(e), cos(a) * cos(e))
67
+ rig.add_child(l)
68
+ l.look_at_from_position(dir, Vector3.ZERO, Vector3.UP)
69
+
70
+ func _collect_corners(n: Node) -> void:
71
+ if n is MeshInstance3D:
72
+ var aabb: AABB = n.get_aabb()
73
+ var xf: Transform3D = n.global_transform
74
+ for i in 8:
75
+ corners.append(xf * aabb.get_endpoint(i))
76
+ for c in n.get_children():
77
+ _collect_corners(c)
78
+
79
+ func _place(az_deg: float, el_deg: float, d: float, target: Vector3) -> void:
80
+ var a := deg_to_rad(az_deg); var e := deg_to_rad(el_deg)
81
+ var off := Vector3(sin(a) * cos(e), sin(e), cos(a) * cos(e)) * d
82
+ cam.look_at_from_position(target + off, target, Vector3.UP)
83
+
84
+ func _run() -> void:
85
+ var args := OS.get_cmdline_user_args()
86
+ var views: Array = []
87
+ for v in args:
88
+ if not v.begins_with("--"):
89
+ views.append(v)
90
+ if views.is_empty():
91
+ views = spec.cameras.views.keys()
92
+ await process_frame
93
+ _collect_corners(get_meta("box"))
94
+ var lo := Vector3(INF, INF, INF); var hi := -lo
95
+ for p in corners:
96
+ lo = lo.min(p); hi = hi.max(p)
97
+ var target := (lo + hi) * 0.5
98
+ var fill: float = spec.cameras.get("fill", 0.92)
99
+ var size := root.get_visible_rect().size
100
+ DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path("res://").path_join("../out/godot/raw"))
101
+ for v in views:
102
+ var az: float = spec.cameras.views[v]
103
+ var el: float = spec.cameras.get("elevation_overrides", {}).get(v, spec.cameras.elevation_deg)
104
+ rig.rotation = Vector3(0, deg_to_rad(az), 0)
105
+ var d := 5.0
106
+ for i in 6:
107
+ _place(az, el, d, target)
108
+ var ys: Array = []
109
+ for p in corners:
110
+ ys.append(cam.unproject_position(p).y)
111
+ var ext: float = (ys.max() - ys.min()) / size.y
112
+ d *= ext / fill
113
+ _place(az, el, d, target)
114
+ for i in 4:
115
+ await process_frame
116
+ await RenderingServer.frame_post_draw
117
+ var img := root.get_texture().get_image()
118
+ var path := ProjectSettings.globalize_path("res://").path_join("../out/godot/raw/%s.png" % v)
119
+ img.save_png(path)
120
+ print("saved ", path)
121
+ if not "--interactive" in args:
122
+ quit()
@@ -0,0 +1,18 @@
1
+ ; Pipeline D: the baked Blender GLB in Godot 4 with a studio light rig.
2
+ config_version=5
3
+
4
+ [application]
5
+ config/name="object_d"
6
+ config/features=PackedStringArray("4.7", "Forward Plus")
7
+
8
+ [display]
9
+ window/size/viewport_width=560
10
+ window/size/viewport_height=1100
11
+ window/size/resizable=false
12
+ window/per_pixel_transparency/allowed=true
13
+
14
+ [rendering]
15
+ anti_aliasing/quality/msaa_3d=2
16
+ anti_aliasing/quality/screen_space_aa=0
17
+ textures/default_filters/anisotropic_filtering_level=4
18
+ viewport/transparent_background=true
@@ -0,0 +1,17 @@
1
+ #!/bin/bash
2
+ # Create an object workspace with the standard layout and copy the skill's tools into it.
3
+ # Usage: init_workspace.sh <workspace_dir> <concept_sheet.png> [scene_style.md]
4
+ set -eu
5
+ SK="$(cd "$(dirname "$0")" && pwd)"
6
+ W="$1"; C="$2"; STYLE="${3:-}"
7
+ mkdir -p "$W"/{reference/crops,spec,brief,tools,blender,threejs,out,reviews,reports,textures}
8
+ cp "$C" "$W/reference/concept.png"
9
+ cp "$SK"/{metrics.py,sheet.py,wear_stats.py,codex_review.sh,gen_texture.sh,capture.mjs,crop.py,measure_silhouette.py,compare_to.py,composite_godot.py} "$W/tools/"
10
+ chmod +x "$W/tools/"*.sh
11
+ cp "$SK/blender/"{studio.py,render_views.py,bake_export.py} "$W/blender/"
12
+ cp "$SK/threejs/"{studio.js,index.html,model.js} "$W/threejs/"
13
+ T="$SK/../assets/templates"
14
+ [ -f "$W/brief/rubric.json" ] || cp "$T/rubric.json" "$W/brief/rubric.json"
15
+ [ -f "$W/reference/zones.json" ] || cp "$T/zones.json" "$W/reference/zones.json"
16
+ [ -n "$STYLE" ] && cp "$STYLE" "$W/brief/scene_style.md"
17
+ echo "workspace ready: $W"
@@ -0,0 +1,40 @@
1
+ """Measure a concept view to draft spec/object.json (geometry is measured, not eyeballed).
2
+
3
+ Usage: python3 tools/measure_silhouette.py <view> --height <m> [--rows 24] [--dark 80] [--bright 215]
4
+ <view>: front|back|left|right|3q (reference/crops/<view>.png)
5
+ Prints: silhouette bbox, metres per pixel, the width profile (row by row, metres from the ground),
6
+ and the largest dark / bright components (openings, panels, glowing windows, buttons) in metres:
7
+ height range from the ground and x range from the silhouette centre. Read them, then LOOK at the crop
8
+ and decide what each component is. Watch out: a contact shadow under the object belongs to the silhouette
9
+ (subtract it from heights), and the top surface seen from the camera adds a little to the height.
10
+ """
11
+ import argparse, pathlib, sys
12
+ import numpy as np
13
+ from PIL import Image
14
+ from scipy import ndimage as ndi
15
+ sys.path.insert(0, str(pathlib.Path(__file__).parent))
16
+ import metrics as M
17
+
18
+ ap = argparse.ArgumentParser()
19
+ ap.add_argument("view"); ap.add_argument("--height", type=float, required=True)
20
+ ap.add_argument("--rows", type=int, default=24); ap.add_argument("--dark", type=float, default=80)
21
+ ap.add_argument("--bright", type=float, default=215)
22
+ a = ap.parse_args()
23
+ img = M.load(M.ROOT / f"reference/crops/{a.view}.png")
24
+ m = M.mask_of(img)
25
+ y0, y1, x0, x1 = M.bbox(m)
26
+ mpp = a.height / (y1 - y0); cx = (x0 + x1) / 2
27
+ print(f"bbox y {y0}-{y1} x {x0}-{x1}; {mpp * 1000:.2f} mm/px; width {(x1 - x0) * mpp:.3f} m; aspect {(x1 - x0) / (y1 - y0):.3f}")
28
+ print("width profile (height from ground m: width m, x-range from centre):")
29
+ for y in np.linspace(y0, y1 - 1, a.rows).astype(int):
30
+ r = np.where(m[y])[0]
31
+ if len(r):
32
+ print(f" {(y1 - y) * mpp:6.3f}: {(r.max() - r.min()) * mpp:.3f} [{(r.min() - cx) * mpp:+.3f}, {(r.max() - cx) * mpp:+.3f}]")
33
+ L = img.mean(2)
34
+ for name, mask in (("dark", (L < a.dark) & m), ("bright", (img[..., 1] > a.bright) & (img[..., 2] > a.bright) & m)):
35
+ lab, n = ndi.label(ndi.binary_closing(mask, iterations=2))
36
+ comps = sorted([sl for sl in ndi.find_objects(lab) if (sl[0].stop - sl[0].start) * (sl[1].stop - sl[1].start) > 40],
37
+ key=lambda s: -(s[0].stop - s[0].start) * (s[1].stop - s[1].start))[:8]
38
+ print(f"{name} components (largest first):")
39
+ for s in comps:
40
+ print(f" y {(y1 - s[0].stop) * mpp:.3f}-{(y1 - s[0].start) * mpp:.3f} m x {(s[1].start - cx) * mpp:+.3f}..{(s[1].stop - cx) * mpp:+.3f} m")
@@ -0,0 +1,144 @@
1
+ """Compare renders with concept crops: silhouette IoU and zone colour (CIELAB). Wear is measured by wear_stats.py.
2
+
3
+ Usage: python3 tools/metrics.py [pipeline ...] (default: threejs blender glb_in_three)
4
+ For each view: silhouette mask (distance from background colour), bbox-normalised IoU,
5
+ width profile error, and colour stats per zone (cap / body / base) in CIELAB.
6
+ Writes out/metrics.json and prints a table.
7
+ """
8
+ import json, sys, pathlib
9
+ import numpy as np
10
+ from PIL import Image
11
+
12
+ ROOT = pathlib.Path(__file__).resolve().parent.parent
13
+ VIEWS = ["3q", "front", "back", "left", "right"]
14
+ N = 256 # normalised mask size
15
+
16
+
17
+ def load(p):
18
+ return np.asarray(Image.open(p).convert("RGB")).astype(np.float32)
19
+
20
+
21
+ def mask_of(img):
22
+ bg = np.median(np.concatenate([img[:6].reshape(-1, 3), img[:, :6].reshape(-1, 3), img[:, -6:].reshape(-1, 3)]), axis=0)
23
+ d = np.abs(img - bg).sum(2)
24
+ m = d > 45
25
+ # ground shadow = background scaled by a near-constant factor (neutral darkening): not part of the object
26
+ ratio = img / np.maximum(bg, 1)
27
+ spread = ratio.max(2) - ratio.min(2)
28
+ shadow = (spread < 0.03) & (ratio.mean(2) > 0.6) & (ratio.mean(2) < 0.97)
29
+ m &= ~shadow
30
+ # remove isolated leftovers: keep columns/rows with enough support
31
+ # drop the soft ground shadow: low-saturation, darker-than-bg pixels in the bottom rows outside the core
32
+ return m
33
+
34
+
35
+ def bbox(m):
36
+ ys, xs = np.where(m)
37
+ # robust bbox: ignore tiny stray pixels
38
+ rows = np.where(m.sum(1) > 3)[0]
39
+ cols = np.where(m.sum(0) > 3)[0]
40
+ return rows.min(), rows.max() + 1, cols.min(), cols.max() + 1
41
+
42
+
43
+ def norm_mask(m, box):
44
+ y0, y1, x0, x1 = box
45
+ h = y1 - y0
46
+ # keep aspect: normalise by height, centre horizontally in an N x N canvas
47
+ crop = Image.fromarray((m[y0:y1, x0:x1] * 255).astype(np.uint8))
48
+ w = max(1, round((x1 - x0) * N / h))
49
+ crop = crop.resize((w, N), Image.BILINEAR)
50
+ canvas = np.zeros((N, N), np.float32)
51
+ off = (N - w) // 2
52
+ a, b = max(0, off), min(N, off + w)
53
+ canvas[:, a:b] = np.asarray(crop, np.float32)[:, a - off:b - off] / 255
54
+ return canvas > 0.5
55
+
56
+
57
+ def srgb_to_lab(rgb):
58
+ c = rgb / 255.0
59
+ c = np.where(c <= 0.04045, c / 12.92, ((c + 0.055) / 1.055) ** 2.4)
60
+ M = np.array([[0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722], [0.0193, 0.1192, 0.9505]])
61
+ xyz = c @ M.T / np.array([0.95047, 1.0, 1.08883])
62
+ f = np.where(xyz > 0.008856, np.cbrt(xyz), 7.787 * xyz + 16 / 116)
63
+ return np.stack([116 * f[..., 1] - 16, 500 * (f[..., 0] - f[..., 1]), 200 * (f[..., 1] - f[..., 2])], -1)
64
+
65
+
66
+ # zones as fractions of the silhouette height (from top), measured on the concept front view
67
+ ZONES = {"cap": (0.02, 0.15), "body": (0.22, 0.78), "base": (0.88, 0.98)}
68
+
69
+
70
+ def zone_stats(img, m, box):
71
+ y0, y1, x0, x1 = box
72
+ h = y1 - y0
73
+ out = {}
74
+ for z, (a, b) in ZONES.items():
75
+ ya, yb = y0 + int(a * h), y0 + int(b * h)
76
+ # central 60% of the width at those rows to avoid edges/background
77
+ xs = np.where(m[ya:yb].any(0))[0]
78
+ cx0, cx1 = xs.min(), xs.max()
79
+ pad = int((cx1 - cx0) * 0.2)
80
+ reg = img[ya:yb, cx0 + pad:cx1 - pad]
81
+ mm = m[ya:yb, cx0 + pad:cx1 - pad]
82
+ px = reg[mm]
83
+ lab = srgb_to_lab(px)
84
+ out[z] = {
85
+ "rgb_median": np.median(px, 0).round().astype(int).tolist(),
86
+ "lab_median": np.median(lab, 0).round(1).tolist(),
87
+ "L_p10_p90": np.percentile(lab[:, 0], [10, 90]).round(1).tolist(),
88
+ "chroma_median": float(np.median(np.hypot(lab[:, 1], lab[:, 2])).round(1)),
89
+ # exposed cream undercoat (chips) and dark rust streaks, as share of zone pixels
90
+ "chip_share": float(((lab[:, 0] > 62) & (np.hypot(lab[:, 1], lab[:, 2]) < 32)).mean().round(3)),
91
+ "rust_share": float(((lab[:, 0] < 40) & (lab[:, 2] > 18)).mean().round(3)),
92
+ }
93
+ return out
94
+
95
+
96
+ def width_profile(nm):
97
+ w = nm.sum(1).astype(np.float32) / N
98
+ return w
99
+
100
+
101
+ def compare(view, pipe):
102
+ c_img = load(ROOT / f"reference/crops/{view}.png")
103
+ r_path = ROOT / f"out/{pipe}/{view}.png"
104
+ if not r_path.exists():
105
+ return None
106
+ r_img = load(r_path)
107
+ cm, rm = mask_of(c_img), mask_of(r_img)
108
+ cb, rb = bbox(cm), bbox(rm)
109
+ cn, rn = norm_mask(cm, cb), norm_mask(rm, rb)
110
+ iou = float((cn & rn).sum() / max(1, (cn | rn).sum()))
111
+ prof_err = float(np.abs(width_profile(cn) - width_profile(rn)).mean())
112
+ aspect_c = (cb[3] - cb[2]) / (cb[1] - cb[0])
113
+ aspect_r = (rb[3] - rb[2]) / (rb[1] - rb[0])
114
+ cz, rz = zone_stats(c_img, cm, cb), zone_stats(r_img, rm, rb)
115
+ de = {z: float(np.linalg.norm(np.array(cz[z]["lab_median"]) - np.array(rz[z]["lab_median"])).round(1)) for z in ZONES}
116
+ return {"iou": round(iou, 3), "profile_err": round(prof_err, 3), "aspect": [round(aspect_c, 3), round(aspect_r, 3)],
117
+ "deltaE_median": de, "concept": cz, "render": rz}
118
+
119
+
120
+ def main():
121
+ pipes = sys.argv[1:] or ["threejs", "blender", "glb_in_three", "godot"]
122
+ res = {}
123
+ for p in pipes:
124
+ res[p] = {}
125
+ for v in VIEWS:
126
+ r = compare(v, p)
127
+ if r:
128
+ res[p][v] = r
129
+ path = ROOT / "out/metrics.json"
130
+ old = json.loads(path.read_text()) if path.exists() else {}
131
+ old.update(res)
132
+ path.write_text(json.dumps(old, indent=1))
133
+ for p, vs in res.items():
134
+ print(f"\n[{p}] view IoU prof aspect(c/r) dE top/middle/bottom L p10-p90 middle (c | r) chroma middle (c|r)")
135
+ for v, r in vs.items():
136
+ d = r["deltaE_median"]
137
+ print(f" {v:6s} {r['iou']:.3f} {r['profile_err']:.3f} {r['aspect'][0]:.2f}/{r['aspect'][1]:.2f} "
138
+ f"{d['cap']:5.1f}/{d['body']:5.1f}/{d['base']:5.1f} {r['concept']['body']['L_p10_p90']} | {r['render']['body']['L_p10_p90']}"
139
+ f" {r['concept']['body']['chroma_median']}|{r['render']['body']['chroma_median']}")
140
+ print("\n(zones: top 2-15%, middle 22-78%, bottom 88-98% of the silhouette height; for wear use tools/wear_stats.py)")
141
+
142
+
143
+ if __name__ == "__main__":
144
+ main()
@@ -0,0 +1,19 @@
1
+ """Contact sheet: concept | three.js | blender | glb_in_three for given views -> path"""
2
+ import sys, pathlib
3
+ from PIL import Image
4
+ ROOT = pathlib.Path(__file__).resolve().parent.parent
5
+ out, views = sys.argv[1], sys.argv[2].split(",")
6
+ pipes = sys.argv[3].split(",") if len(sys.argv) > 3 else ["threejs", "blender", "glb_in_three"]
7
+ H = 1100
8
+ rows = []
9
+ for v in views:
10
+ c = Image.open(ROOT / f"reference/crops/{v}.png"); c = c.resize((round(c.width * H / c.height), H))
11
+ ims = [c] + [Image.open(ROOT / f"out/{p}/{v}.png") for p in pipes]
12
+ W = sum(i.width for i in ims) + 10 * (len(ims) - 1)
13
+ r = Image.new("RGB", (W, H), "black"); x = 0
14
+ for i in ims: r.paste(i, (x, 0)); x += i.width + 10
15
+ rows.append(r)
16
+ W = max(r.width for r in rows); s = Image.new("RGB", (W, H * len(rows) + 10 * (len(rows) - 1)), "black")
17
+ for k, r in enumerate(rows): s.paste(r, (0, k * (H + 10)))
18
+ scale = float(sys.argv[4]) if len(sys.argv) > 4 else 0.5
19
+ s.resize((int(s.width * scale), int(s.height * scale))).save(out)
@@ -0,0 +1,121 @@
1
+ """Model-free tests for the concept-asset-builder tools. Skipped when Pillow or numpy (or scipy, for wear_stats)
2
+ is missing. The tools resolve paths from their own location (<workspace>/tools), so every test builds a real
3
+ workspace with init_workspace.sh and a synthetic concept sheet."""
4
+ import json
5
+ import pathlib
6
+ import subprocess
7
+ import sys
8
+ import tempfile
9
+ import unittest
10
+
11
+ HERE = pathlib.Path(__file__).resolve().parent
12
+ SKILL = HERE.parent
13
+
14
+ try:
15
+ import numpy as np
16
+ from PIL import Image
17
+ HAVE_DEPS = True
18
+ except ImportError:
19
+ HAVE_DEPS = False
20
+ try:
21
+ import scipy # noqa: F401
22
+ HAVE_SCIPY = True
23
+ except ImportError:
24
+ HAVE_SCIPY = False
25
+
26
+ BG = (237, 229, 225)
27
+ PAINT = (175, 86, 55)
28
+ VIEWS = ["3q", "front", "back", "left", "right"]
29
+
30
+
31
+ def run(*args, cwd=None):
32
+ return subprocess.run([*args], cwd=cwd, capture_output=True, text=True, check=True,
33
+ env={"PYTHONDONTWRITEBYTECODE": "1", "PATH": "/usr/bin:/bin:/usr/local/bin:/opt/homebrew/bin"})
34
+
35
+
36
+ @unittest.skipUnless(HAVE_DEPS, "Pillow and numpy are required")
37
+ class ToolsTest(unittest.TestCase):
38
+ def setUp(self):
39
+ self.tmp = tempfile.TemporaryDirectory()
40
+ self.dir = pathlib.Path(self.tmp.name)
41
+ # sheet: five 100x200 px objects (a painted box with a cream chip) on the page background
42
+ sheet = Image.new("RGB", (700, 300), BG)
43
+ px = sheet.load()
44
+ self.boxes = {}
45
+ for i, v in enumerate(VIEWS):
46
+ x0 = 20 + i * 135
47
+ for x in range(x0 + 10, x0 + 90):
48
+ for y in range(40, 240):
49
+ px[x, y] = PAINT
50
+ for x in range(x0 + 40, x0 + 52):
51
+ for y in range(100, 116):
52
+ px[x, y] = (226, 205, 176)
53
+ self.boxes[v] = [x0, 20, x0 + 100, 260]
54
+ self.concept = self.dir / "sheet.png"
55
+ sheet.save(self.concept)
56
+ self.ws = self.dir / "ws"
57
+ run("bash", str(SKILL / "scripts/init_workspace.sh"), str(self.ws), str(self.concept))
58
+ (self.ws / "reference/boxes.json").write_text(json.dumps(self.boxes))
59
+ run(sys.executable, "-B", "tools/crop.py", cwd=self.ws)
60
+
61
+ def tearDown(self):
62
+ self.tmp.cleanup()
63
+
64
+ def test_workspace_layout_and_crops(self):
65
+ for d in ["reference/crops", "spec", "brief", "tools", "blender", "threejs", "out", "reviews", "reports", "textures"]:
66
+ self.assertTrue((self.ws / d).is_dir(), d)
67
+ for f in ["blender/studio.py", "blender/render_views.py", "threejs/studio.js", "threejs/index.html",
68
+ "brief/rubric.json", "reference/zones.json", "tools/wear_stats.py", "tools/codex_review.sh"]:
69
+ self.assertTrue((self.ws / f).is_file(), f)
70
+ for v in VIEWS:
71
+ self.assertEqual(Image.open(self.ws / f"reference/crops/{v}.png").size, (100, 240))
72
+
73
+ def test_measure_silhouette_reports_metres(self):
74
+ out = run(sys.executable, "-B", "tools/measure_silhouette.py", "front", "--height", "2.0", "--rows", "4", cwd=self.ws).stdout
75
+ # the box is 200 px tall and 80 px wide -> 10 mm/px, 0.8 m wide
76
+ self.assertIn("10.00 mm/px", out)
77
+ self.assertIn("width 0.800 m", out)
78
+
79
+ def test_metrics_mask_and_lab(self):
80
+ sys.path.insert(0, str(self.ws / "tools"))
81
+ try:
82
+ import metrics
83
+ img = metrics.load(self.ws / "reference/crops/front.png")
84
+ y0, y1, x0, x1 = metrics.bbox(metrics.mask_of(img))
85
+ self.assertEqual((y1 - y0, x1 - x0), (200, 80))
86
+ white = metrics.srgb_to_lab(np.array([[255.0, 255.0, 255.0]]))[0]
87
+ self.assertAlmostEqual(float(white[0]), 100.0, delta=0.5)
88
+ finally:
89
+ sys.path.remove(str(self.ws / "tools"))
90
+ sys.modules.pop("metrics", None)
91
+
92
+ @unittest.skipUnless(HAVE_SCIPY, "scipy is required")
93
+ def test_wear_stats_finds_the_chip(self):
94
+ zones = json.loads((self.ws / "reference/zones.json").read_text())
95
+ zones["height_m"] = 2.0
96
+ zones["bands"] = {"all": [0.0, 2.0]}
97
+ # the synthetic chip is ~12x16 cm: the chip window must be wider than the chips (see SKILL.md Phase 3 traps)
98
+ zones["chip"]["window_m"] = 0.3
99
+ (self.ws / "reference/zones.json").write_text(json.dumps(zones))
100
+ run(sys.executable, "-B", "tools/wear_stats.py", cwd=self.ws)
101
+ res = json.loads((self.ws / "out/wear_stats_concept.json").read_text())
102
+ self.assertGreater(res["front"]["all"]["chip_pct"], 0.5)
103
+ self.assertEqual(res["front"]["all"]["chips"]["count"], 1)
104
+
105
+ def test_sheet_builds_concept_render_pairs(self):
106
+ (self.ws / "out/blender").mkdir(parents=True)
107
+ for v in VIEWS:
108
+ Image.open(self.ws / f"reference/crops/{v}.png").save(self.ws / f"out/blender/{v}.png")
109
+ run(sys.executable, "-B", "tools/sheet.py", "out/s.png", "front,back", "blender", "0.5", cwd=self.ws)
110
+ self.assertTrue((self.ws / "out/s.png").is_file())
111
+
112
+ def test_shell_scripts_parse_and_rubric_weights_sum_to_one(self):
113
+ for s in ["codex_review.sh", "gen_texture.sh", "init_workspace.sh"]:
114
+ run("bash", "-n", str(SKILL / "scripts" / s))
115
+ for name in ["rubric.json", "rubric_example_vending.json"]:
116
+ crit = json.loads((SKILL / "assets/templates" / name).read_text())["criteria"]
117
+ self.assertAlmostEqual(sum(c["weight"] for c in crit), 1.0, places=6)
118
+
119
+
120
+ if __name__ == "__main__":
121
+ unittest.main()
@@ -0,0 +1,23 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Object — three.js</title>
6
+ <style>html,body{margin:0;height:100%;overflow:hidden;background:#EDE5E1}canvas{display:block}</style>
7
+ </head>
8
+ <body>
9
+ <script type="module">
10
+ // Frozen entry point: the studio (camera, light, tone mapping, background) is shared by all objects of the scene.
11
+ // The builder implements threejs/model.js: export async function buildModel(spec) -> THREE.Object3D
12
+ import { loadSpec, createStudio, label } from './studio.js';
13
+ import { buildModel } from './model.js';
14
+ const spec = await loadSpec();
15
+ const studio = createStudio(spec);
16
+ const obj = await buildModel(spec);
17
+ studio.scene.add(obj);
18
+ studio.frame(obj);
19
+ label(`${spec.name} · three.js`, studio.view);
20
+ studio.start();
21
+ </script>
22
+ </body>
23
+ </html>
@@ -0,0 +1,9 @@
1
+ // STUB — replace with the real model. Contract: export async function buildModel(spec) -> THREE.Object3D
2
+ // (Y up, front faces +Z, ground at y = 0, metres, built from spec/object.json).
3
+ import * as THREE from 'three';
4
+ export async function buildModel(spec) {
5
+ const h = spec.height, w = spec.width ?? h * 0.45, d = spec.depth ?? w * 0.7;
6
+ const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), new THREE.MeshStandardMaterial({ color: '#999999', roughness: 0.7 }));
7
+ m.position.y = h / 2; m.castShadow = true;
8
+ return m;
9
+ }