@babylonjs-toolkit/agent 1.2.16 → 1.2.21
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 +3 -2
- package/package.json +1 -1
- package/skills/bt-blender/SKILL.md +448 -0
- package/skills/bt-blender/THIRD_PARTY_NOTICES.md +141 -0
- package/skills/bt-blender/references/art-style-and-genre.md +173 -0
- package/skills/bt-blender/references/characters-and-creatures.md +644 -0
- package/skills/bt-blender/references/environments.md +478 -0
- package/skills/bt-blender/references/game-engine-export.md +284 -0
- package/skills/bt-blender/references/geometry-nodes.md +447 -0
- package/skills/bt-blender/references/hard-surface.md +724 -0
- package/skills/bt-blender/references/procedural-generation.md +358 -0
- package/skills/bt-blender/references/rigging-and-animation.md +1080 -0
- package/skills/bt-blender/references/sculpting-and-retopology.md +544 -0
- package/skills/bt-blender/references/uv-and-pbr-materials.md +381 -0
- package/skills/bt-blender/references/vehicles.md +637 -0
- package/skills/bt-blender/scripts/blender/__pycache__/construction_kit.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/geometry_nodes_builders.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/image_measure.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/__pycache__/reference_traces.cpython-313.pyc +0 -0
- package/skills/bt-blender/scripts/blender/assembly_check.py +420 -0
- package/skills/bt-blender/scripts/blender/blueprint.py +293 -0
- package/skills/bt-blender/scripts/blender/character_blockout.py +462 -0
- package/skills/bt-blender/scripts/blender/construction_kit.py +1770 -0
- package/skills/bt-blender/scripts/blender/coverage_check.py +221 -0
- package/skills/bt-blender/scripts/blender/environment_kit.py +525 -0
- package/skills/bt-blender/scripts/blender/evidence_sheet.py +243 -0
- package/skills/bt-blender/scripts/blender/export_asset.py +623 -0
- package/skills/bt-blender/scripts/blender/geometry_nodes_builders.py +575 -0
- package/skills/bt-blender/scripts/blender/hard_surface_panels.py +374 -0
- package/skills/bt-blender/scripts/blender/hard_surface_trims.py +200 -0
- package/skills/bt-blender/scripts/blender/image_measure.py +917 -0
- package/skills/bt-blender/scripts/blender/materials_pbr.py +439 -0
- package/skills/bt-blender/scripts/blender/measure_stations.py +496 -0
- package/skills/bt-blender/scripts/blender/ortho_views.py +309 -0
- package/skills/bt-blender/scripts/blender/overlay_sheet.py +238 -0
- package/skills/bt-blender/scripts/blender/procedural_game_ready.py +258 -0
- package/skills/bt-blender/scripts/blender/procedural_generators.py +842 -0
- package/skills/bt-blender/scripts/blender/qa_check.py +729 -0
- package/skills/bt-blender/scripts/blender/reference_traces.py +344 -0
- package/skills/bt-blender/scripts/blender/retopology_tools.py +781 -0
- package/skills/bt-blender/scripts/blender/review_render.py +358 -0
- package/skills/bt-blender/scripts/blender/rigging_tools.py +1170 -0
- package/skills/bt-blender/scripts/blender/style_palette.py +190 -0
- package/skills/bt-blender/scripts/blender/tool_common.py +289 -0
- package/skills/bt-blender/scripts/blender/trace.py +283 -0
- package/skills/bt-blender/scripts/blender/uv_layout.py +555 -0
- package/skills/bt-blender/scripts/blender/vehicle_parts.py +370 -0
- package/skills/bt-blender/scripts/blender/view_consistency.py +133 -0
- package/skills/bt-blender/scripts/blender/world_gate.py +231 -0
- package/skills/bt-blender/scripts/bt-blender.mjs +333 -0
- package/skills/bt-blender/scripts/validate_gltf.mjs +204 -0
- package/skills/bt-execute/SKILL.md +2 -1
- package/skills/bt-gauntlet/SKILL.md +30 -20
- package/skills/bt-gauntlet/references/critic-rubrics.md +106 -7
- package/skills/bt-gauntlet/references/loop-templates.md +23 -3
- package/skills/bt-gauntlet/references/spec-composition.md +20 -1
- package/skills/bt-gauntlet/references/target-images.md +27 -0
- package/skills/bt-gauntlet/references/unity-pipeline.md +41 -4
- package/skills/bt-gauntlet/references/workspace.md +90 -6
- package/skills/bt-unwrap/scripts/blender/__pycache__/bt_unwrap.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/image_utils.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/mesh_tools.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/model_io.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/previews.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/rasterizer.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/reference_views.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/reference_warp.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/texture_bake.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/texture_compose.cpython-313.pyc +0 -0
- package/skills/bt-unwrap/scripts/blender/__pycache__/uv_layout.cpython-313.pyc +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"""
|
|
2
|
+
coverage_check -- prove that every region of the reference silhouette belongs to a part before building.
|
|
3
|
+
|
|
4
|
+
When an asset is split into parts (a body, a nose, flanks, pods), each part's region is drawn on the whole-
|
|
5
|
+
asset reference images in coverage.json. The union of the part regions must cover the subject's silhouette
|
|
6
|
+
(--min-coverage, 99 % of its pixels by default). Every UNCLAIMED region (a connected piece of silhouette no
|
|
7
|
+
part owns, above --min-region-percent of the silhouette) is listed with its bounding box and area, and so
|
|
8
|
+
is every overlap between two parts, so a region that belongs to no part (an unassigned flank) is found
|
|
9
|
+
before anyone builds, not after.
|
|
10
|
+
|
|
11
|
+
coverage.json (pixel coordinates of each reference image, row 0 at the top):
|
|
12
|
+
{"views": {"<reference name, file name or stem>": {"parts": {
|
|
13
|
+
"<part name>": [x0, y0, x1, y1] a box (right / bottom exclusive)
|
|
14
|
+
| [[x, y], [x, y], [x, y], ...] a polygon
|
|
15
|
+
| [<box or polygon>, ...] several regions
|
|
16
|
+
}}}}
|
|
17
|
+
|
|
18
|
+
node bt-blender.mjs coverage-check --reference refs/left.png [--reference top=refs/top.png ...]
|
|
19
|
+
--parts coverage.json --out coverage.png [--crop left=x0,y0,x1,y1] [--min-coverage 99]
|
|
20
|
+
[--background-tolerance 0.08] [--min-region-percent 0.1] [--tile 480]
|
|
21
|
+
|
|
22
|
+
The picture shows each part's region in its own colour, overlaps in white and unclaimed silhouette in solid
|
|
23
|
+
red; <out>.json has the numbers. Exits 1 while any view's coverage is below --min-coverage.
|
|
24
|
+
"""
|
|
25
|
+
import itertools
|
|
26
|
+
import os
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
sys.dont_write_bytecode = True
|
|
30
|
+
SCRIPT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
|
31
|
+
if SCRIPT_DIRECTORY not in sys.path:
|
|
32
|
+
sys.path.insert(0, SCRIPT_DIRECTORY)
|
|
33
|
+
|
|
34
|
+
import numpy as np # noqa: E402
|
|
35
|
+
|
|
36
|
+
import evidence_sheet # noqa: E402
|
|
37
|
+
import image_measure # noqa: E402
|
|
38
|
+
import overlay_sheet # noqa: E402
|
|
39
|
+
import tool_common # noqa: E402
|
|
40
|
+
|
|
41
|
+
TOOL_NAME = "coverage-check"
|
|
42
|
+
|
|
43
|
+
DEFAULT_MINIMUM_COVERAGE_PERCENT = 99.0
|
|
44
|
+
DEFAULT_MINIMUM_REGION_PERCENT = 0.1
|
|
45
|
+
DEFAULT_TILE_PIXELS = 480
|
|
46
|
+
|
|
47
|
+
# Values in a box region, and per polygon point.
|
|
48
|
+
BOX_VALUES = 4
|
|
49
|
+
POINT_VALUES = 2
|
|
50
|
+
MINIMUM_POLYGON_POINTS = 3
|
|
51
|
+
|
|
52
|
+
# Drawing: part colours in order (red is kept for unclaimed silhouette), and how strongly each is laid on.
|
|
53
|
+
PART_COLORS = ((0.3, 0.7, 1.0), (0.4, 0.9, 0.4), (1.0, 0.8, 0.2), (0.8, 0.5, 1.0), (0.2, 0.9, 0.85),
|
|
54
|
+
(1.0, 0.55, 0.2), (0.6, 0.8, 0.3), (0.95, 0.5, 0.8), (0.5, 0.6, 1.0), (0.85, 0.85, 0.5))
|
|
55
|
+
UNCLAIMED_COLOR = (1.0, 0.1, 0.1)
|
|
56
|
+
OVERLAP_COLOR = (1.0, 1.0, 1.0)
|
|
57
|
+
PART_STRENGTH = 0.45
|
|
58
|
+
UNCLAIMED_STRENGTH = 0.9
|
|
59
|
+
OVERLAP_STRENGTH = 0.5
|
|
60
|
+
OUTLINE_PIXELS = 2
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def build_parser() -> tool_common.ToolArgumentParser:
|
|
64
|
+
"""The tool's command-line options."""
|
|
65
|
+
parser = tool_common.ToolArgumentParser(prog=TOOL_NAME, description=__doc__.strip().splitlines()[0])
|
|
66
|
+
parser.add_argument("--reference", action="append", required=True, metavar="[NAME=]IMAGE",
|
|
67
|
+
help="a whole-asset reference image (repeatable)")
|
|
68
|
+
parser.add_argument("--parts", required=True, help="coverage.json: each part's region per reference")
|
|
69
|
+
parser.add_argument("--out", required=True, help="picture to write (PNG); the JSON goes beside it")
|
|
70
|
+
parser.add_argument("--crop", action="append", default=[], metavar="NAME=X0,Y0,X1,Y1",
|
|
71
|
+
help="crop box (pixels) for a named reference")
|
|
72
|
+
parser.add_argument("--min-coverage", type=float, default=DEFAULT_MINIMUM_COVERAGE_PERCENT,
|
|
73
|
+
help="percent of the silhouette the parts must cover")
|
|
74
|
+
parser.add_argument("--min-region-percent", type=float, default=DEFAULT_MINIMUM_REGION_PERCENT,
|
|
75
|
+
help="smallest unclaimed region listed, percent of the silhouette")
|
|
76
|
+
parser.add_argument("--background-tolerance", type=float, default=image_measure.DEFAULT_BACKGROUND_TOLERANCE)
|
|
77
|
+
parser.add_argument("--tile", type=int, default=DEFAULT_TILE_PIXELS, help="longest side of each tile, pixels")
|
|
78
|
+
return parser
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def region_polygons(region) -> list:
|
|
82
|
+
"""
|
|
83
|
+
A part's region as polygons.
|
|
84
|
+
|
|
85
|
+
:param region: A box [x0, y0, x1, y1], a polygon [[x, y], ...], or a list of those.
|
|
86
|
+
:returns: [(N, 2) arrays].
|
|
87
|
+
:raises ValueError: for anything else.
|
|
88
|
+
"""
|
|
89
|
+
if isinstance(region, list) and len(region) == BOX_VALUES and all(isinstance(value, (int, float)) for value in region):
|
|
90
|
+
left, top, right, bottom = (float(value) for value in region)
|
|
91
|
+
return [np.array([[left, top], [right, top], [right, bottom], [left, bottom]])]
|
|
92
|
+
if (isinstance(region, list) and len(region) >= MINIMUM_POLYGON_POINTS
|
|
93
|
+
and all(isinstance(point, list) and len(point) == POINT_VALUES
|
|
94
|
+
and all(isinstance(value, (int, float)) for value in point) for point in region)):
|
|
95
|
+
return [np.array(region, dtype=np.float64)]
|
|
96
|
+
if isinstance(region, list) and region and all(isinstance(item, list) for item in region):
|
|
97
|
+
return [polygon for item in region for polygon in region_polygons(item)]
|
|
98
|
+
raise ValueError(f"a part region must be a box [x0, y0, x1, y1], a polygon [[x, y], ...] or a list of them: {region}")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _references(entries: list) -> list:
|
|
102
|
+
"""--reference entries as (name, path, the keys a coverage.json view may use for it)."""
|
|
103
|
+
references = []
|
|
104
|
+
for entry in entries:
|
|
105
|
+
name, separator, path = entry.partition("=")
|
|
106
|
+
if not separator:
|
|
107
|
+
name, path = os.path.splitext(os.path.basename(entry))[0], entry
|
|
108
|
+
keys = {name, path, os.path.basename(path), os.path.splitext(os.path.basename(path))[0]}
|
|
109
|
+
references.append((name, os.path.abspath(path), keys))
|
|
110
|
+
return references
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def check_view(name: str, rgba: np.ndarray, parts: dict, crop, options) -> tuple:
|
|
114
|
+
"""
|
|
115
|
+
Checks one reference: coverage, unclaimed regions, overlaps, and its picture.
|
|
116
|
+
|
|
117
|
+
:returns: (the view's result, its tile picture).
|
|
118
|
+
"""
|
|
119
|
+
height, width = rgba.shape[:2]
|
|
120
|
+
silhouette = overlay_sheet.subject(rgba, options.background_tolerance, crop)
|
|
121
|
+
area = float(silhouette.sum())
|
|
122
|
+
if area == 0:
|
|
123
|
+
raise ValueError(f"reference '{name}' holds no subject")
|
|
124
|
+
masks = {}
|
|
125
|
+
for part, region in parts.items():
|
|
126
|
+
mask = np.zeros((height, width), dtype=bool)
|
|
127
|
+
for polygon in region_polygons(region):
|
|
128
|
+
mask |= image_measure.fill_polygon(height, width, polygon)
|
|
129
|
+
masks[part] = mask
|
|
130
|
+
claimed = np.zeros((height, width), dtype=bool)
|
|
131
|
+
for mask in masks.values():
|
|
132
|
+
claimed |= mask
|
|
133
|
+
unclaimed = silhouette & ~claimed
|
|
134
|
+
minimum_pixels = max(1, int(np.ceil(options.min_region_percent / 100.0 * area)))
|
|
135
|
+
unclaimed_regions = [{"bbox": region["bbox"], "centroid": region["centroid"], "area_px": region["area_px"],
|
|
136
|
+
"area_percent": round(100.0 * region["area_px"] / area, 2)}
|
|
137
|
+
for region in image_measure.component_regions(unclaimed, minimum_pixels)]
|
|
138
|
+
overlaps = []
|
|
139
|
+
for first, second in itertools.combinations(masks, 2):
|
|
140
|
+
shared = int((masks[first] & masks[second] & silhouette).sum())
|
|
141
|
+
if shared:
|
|
142
|
+
overlaps.append({"parts": [first, second], "area_px": shared, "area_percent": round(100.0 * shared / area, 2)})
|
|
143
|
+
part_reports = {part: {"silhouette_percent": round(100.0 * float((mask & silhouette).sum()) / area, 2),
|
|
144
|
+
"outside_silhouette_percent": round(100.0 * float((mask & ~silhouette).sum()) / max(1.0, float(mask.sum())), 2)}
|
|
145
|
+
for part, mask in masks.items()}
|
|
146
|
+
coverage = round(100.0 * float((silhouette & claimed).sum()) / area, 2)
|
|
147
|
+
passed = coverage >= options.min_coverage
|
|
148
|
+
result = {"name": name, "coverage_percent": coverage, "unclaimed_percent": round(100.0 - coverage, 2),
|
|
149
|
+
"pass": passed, "unclaimed_regions": unclaimed_regions, "overlaps": overlaps, "parts": part_reports}
|
|
150
|
+
return result, draw_tile(rgba, silhouette, masks, unclaimed, parts, options.tile)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def draw_tile(rgba: np.ndarray, silhouette: np.ndarray, masks: dict, unclaimed: np.ndarray, parts: dict,
|
|
154
|
+
tile_pixels: int) -> np.ndarray:
|
|
155
|
+
"""Each part's region in its colour, overlaps in white, unclaimed silhouette in red, part names on top."""
|
|
156
|
+
height, width = silhouette.shape
|
|
157
|
+
scale = evidence_sheet.fit_scale(height, width, tile_pixels)
|
|
158
|
+
tile_height, tile_width = max(1, round(height * scale)), max(1, round(width * scale))
|
|
159
|
+
picture = evidence_sheet.dimmed(evidence_sheet.resize(rgba, tile_height, tile_width))
|
|
160
|
+
small_silhouette = evidence_sheet.resize_mask(silhouette, tile_height, tile_width)
|
|
161
|
+
coverage_count = np.zeros((tile_height, tile_width), dtype=np.int32)
|
|
162
|
+
for index, (part, mask) in enumerate(masks.items()):
|
|
163
|
+
small = evidence_sheet.resize_mask(mask, tile_height, tile_width)
|
|
164
|
+
coverage_count += small
|
|
165
|
+
color = PART_COLORS[index % len(PART_COLORS)]
|
|
166
|
+
evidence_sheet.tint(picture, small & small_silhouette, color, PART_STRENGTH)
|
|
167
|
+
for polygon in region_polygons(parts[part]):
|
|
168
|
+
image_measure.draw_polyline(picture, polygon * scale, color, OUTLINE_PIXELS)
|
|
169
|
+
evidence_sheet.tint(picture, (coverage_count > 1) & small_silhouette, OVERLAP_COLOR, OVERLAP_STRENGTH)
|
|
170
|
+
evidence_sheet.tint(picture, evidence_sheet.resize_mask(unclaimed, tile_height, tile_width), UNCLAIMED_COLOR,
|
|
171
|
+
UNCLAIMED_STRENGTH)
|
|
172
|
+
for index, part in enumerate(masks):
|
|
173
|
+
polygons = region_polygons(parts[part])
|
|
174
|
+
center = np.concatenate(polygons).mean(axis=0) * scale
|
|
175
|
+
text_width, text_height = evidence_sheet.text_size(part)
|
|
176
|
+
evidence_sheet.draw_text(picture, part, int(center[0] - text_width / 2), int(center[1] - text_height / 2),
|
|
177
|
+
PART_COLORS[index % len(PART_COLORS)])
|
|
178
|
+
return picture
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def run(options) -> dict:
|
|
182
|
+
"""
|
|
183
|
+
Checks every reference against its parts and writes the picture and the JSON.
|
|
184
|
+
|
|
185
|
+
:param options: Parsed options.
|
|
186
|
+
:returns: The tool result.
|
|
187
|
+
"""
|
|
188
|
+
crops = overlay_sheet.parse_crops(options.crop)
|
|
189
|
+
views = (tool_common.load_json(options.parts).get("views") or {})
|
|
190
|
+
if not views:
|
|
191
|
+
raise ValueError(f"{options.parts} has no views")
|
|
192
|
+
results, tiles, matched = [], [], set()
|
|
193
|
+
for name, path, keys in _references(options.reference):
|
|
194
|
+
key = next((candidate for candidate in views if candidate in keys), None)
|
|
195
|
+
if key is None:
|
|
196
|
+
raise ValueError(f"coverage.json has no parts for reference '{name}' (use one of {sorted(keys)} as its key)")
|
|
197
|
+
matched.add(key)
|
|
198
|
+
parts = views[key].get("parts") or {}
|
|
199
|
+
if not parts:
|
|
200
|
+
raise ValueError(f"coverage.json view '{key}' has no parts")
|
|
201
|
+
result, tile = check_view(name, tool_common.load_image(path), parts, crops.get(name), options)
|
|
202
|
+
result["reference"] = path
|
|
203
|
+
results.append(result)
|
|
204
|
+
unclaimed = result["unclaimed_regions"]
|
|
205
|
+
lines = [name, f"COVERAGE {result['coverage_percent']:.1f}% UNCLAIMED {result['unclaimed_percent']:.1f}% "
|
|
206
|
+
f"OVERLAPS {len(result['overlaps'])}", evidence_sheet.verdict(result["pass"])]
|
|
207
|
+
if unclaimed:
|
|
208
|
+
lines.append((f"LARGEST UNCLAIMED {unclaimed[0]['area_percent']:.1f}% AT {unclaimed[0]['bbox']}", UNCLAIMED_COLOR))
|
|
209
|
+
tiles.append((lines, tile))
|
|
210
|
+
unused = sorted(set(views) - matched)
|
|
211
|
+
out_path = os.path.abspath(options.out)
|
|
212
|
+
report = {"pass": all(result["pass"] for result in results), "min_coverage_percent": options.min_coverage,
|
|
213
|
+
"views": results, "unused_coverage_views": unused,
|
|
214
|
+
"picture": tool_common.save_image(out_path, evidence_sheet.compose_sheet(
|
|
215
|
+
tiles, title_lines=["EACH PART IN ITS COLOUR WHITE OVERLAP RED UNCLAIMED"]))}
|
|
216
|
+
report["report_json"] = tool_common.write_json(os.path.splitext(out_path)[0] + ".json", report)
|
|
217
|
+
return report
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
if __name__ == "__main__":
|
|
221
|
+
tool_common.run_tool(TOOL_NAME, build_parser(), run)
|