@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.
Files changed (70) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/skills/bt-blender/SKILL.md +448 -0
  4. package/skills/bt-blender/THIRD_PARTY_NOTICES.md +141 -0
  5. package/skills/bt-blender/references/art-style-and-genre.md +173 -0
  6. package/skills/bt-blender/references/characters-and-creatures.md +644 -0
  7. package/skills/bt-blender/references/environments.md +478 -0
  8. package/skills/bt-blender/references/game-engine-export.md +284 -0
  9. package/skills/bt-blender/references/geometry-nodes.md +447 -0
  10. package/skills/bt-blender/references/hard-surface.md +724 -0
  11. package/skills/bt-blender/references/procedural-generation.md +358 -0
  12. package/skills/bt-blender/references/rigging-and-animation.md +1080 -0
  13. package/skills/bt-blender/references/sculpting-and-retopology.md +544 -0
  14. package/skills/bt-blender/references/uv-and-pbr-materials.md +381 -0
  15. package/skills/bt-blender/references/vehicles.md +637 -0
  16. package/skills/bt-blender/scripts/blender/__pycache__/construction_kit.cpython-313.pyc +0 -0
  17. package/skills/bt-blender/scripts/blender/__pycache__/geometry_nodes_builders.cpython-313.pyc +0 -0
  18. package/skills/bt-blender/scripts/blender/__pycache__/image_measure.cpython-313.pyc +0 -0
  19. package/skills/bt-blender/scripts/blender/__pycache__/reference_traces.cpython-313.pyc +0 -0
  20. package/skills/bt-blender/scripts/blender/assembly_check.py +420 -0
  21. package/skills/bt-blender/scripts/blender/blueprint.py +293 -0
  22. package/skills/bt-blender/scripts/blender/character_blockout.py +462 -0
  23. package/skills/bt-blender/scripts/blender/construction_kit.py +1770 -0
  24. package/skills/bt-blender/scripts/blender/coverage_check.py +221 -0
  25. package/skills/bt-blender/scripts/blender/environment_kit.py +525 -0
  26. package/skills/bt-blender/scripts/blender/evidence_sheet.py +243 -0
  27. package/skills/bt-blender/scripts/blender/export_asset.py +623 -0
  28. package/skills/bt-blender/scripts/blender/geometry_nodes_builders.py +575 -0
  29. package/skills/bt-blender/scripts/blender/hard_surface_panels.py +374 -0
  30. package/skills/bt-blender/scripts/blender/hard_surface_trims.py +200 -0
  31. package/skills/bt-blender/scripts/blender/image_measure.py +917 -0
  32. package/skills/bt-blender/scripts/blender/materials_pbr.py +439 -0
  33. package/skills/bt-blender/scripts/blender/measure_stations.py +496 -0
  34. package/skills/bt-blender/scripts/blender/ortho_views.py +309 -0
  35. package/skills/bt-blender/scripts/blender/overlay_sheet.py +238 -0
  36. package/skills/bt-blender/scripts/blender/procedural_game_ready.py +258 -0
  37. package/skills/bt-blender/scripts/blender/procedural_generators.py +842 -0
  38. package/skills/bt-blender/scripts/blender/qa_check.py +729 -0
  39. package/skills/bt-blender/scripts/blender/reference_traces.py +344 -0
  40. package/skills/bt-blender/scripts/blender/retopology_tools.py +781 -0
  41. package/skills/bt-blender/scripts/blender/review_render.py +358 -0
  42. package/skills/bt-blender/scripts/blender/rigging_tools.py +1170 -0
  43. package/skills/bt-blender/scripts/blender/style_palette.py +190 -0
  44. package/skills/bt-blender/scripts/blender/tool_common.py +289 -0
  45. package/skills/bt-blender/scripts/blender/trace.py +283 -0
  46. package/skills/bt-blender/scripts/blender/uv_layout.py +555 -0
  47. package/skills/bt-blender/scripts/blender/vehicle_parts.py +370 -0
  48. package/skills/bt-blender/scripts/blender/view_consistency.py +133 -0
  49. package/skills/bt-blender/scripts/blender/world_gate.py +231 -0
  50. package/skills/bt-blender/scripts/bt-blender.mjs +333 -0
  51. package/skills/bt-blender/scripts/validate_gltf.mjs +204 -0
  52. package/skills/bt-execute/SKILL.md +2 -1
  53. package/skills/bt-gauntlet/SKILL.md +30 -20
  54. package/skills/bt-gauntlet/references/critic-rubrics.md +106 -7
  55. package/skills/bt-gauntlet/references/loop-templates.md +23 -3
  56. package/skills/bt-gauntlet/references/spec-composition.md +20 -1
  57. package/skills/bt-gauntlet/references/target-images.md +27 -0
  58. package/skills/bt-gauntlet/references/unity-pipeline.md +41 -4
  59. package/skills/bt-gauntlet/references/workspace.md +90 -6
  60. package/skills/bt-unwrap/scripts/blender/__pycache__/bt_unwrap.cpython-313.pyc +0 -0
  61. package/skills/bt-unwrap/scripts/blender/__pycache__/image_utils.cpython-313.pyc +0 -0
  62. package/skills/bt-unwrap/scripts/blender/__pycache__/mesh_tools.cpython-313.pyc +0 -0
  63. package/skills/bt-unwrap/scripts/blender/__pycache__/model_io.cpython-313.pyc +0 -0
  64. package/skills/bt-unwrap/scripts/blender/__pycache__/previews.cpython-313.pyc +0 -0
  65. package/skills/bt-unwrap/scripts/blender/__pycache__/rasterizer.cpython-313.pyc +0 -0
  66. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_views.cpython-313.pyc +0 -0
  67. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_warp.cpython-313.pyc +0 -0
  68. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_bake.cpython-313.pyc +0 -0
  69. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_compose.cpython-313.pyc +0 -0
  70. package/skills/bt-unwrap/scripts/blender/__pycache__/uv_layout.cpython-313.pyc +0 -0
@@ -0,0 +1,283 @@
1
+ """
2
+ trace -- trace every reference view's subject outline, and named design curves, into world coordinates.
3
+
4
+ For each view of a stations spec the subject is separated from the border background colour (the view's
5
+ crop and background_tolerance apply) and the largest region is kept (stray specks, labels and shadows fall
6
+ away). Enclosed holes (transparent or background-coloured regions inside the subject) are filled for the
7
+ outer outline and traced on their own. The outline is followed along pixel edges, so its extent is exactly
8
+ the subject's, then simplified (--simplify-px). Every outline is written in image pixels AND in world metres
9
+ on the view's plane (its two image axes, e.g. y and z for a side view), with the subject's world extent per
10
+ axis.
11
+
12
+ --curves adds hand-picked design curves (a top line, a shoulder line, a plan edge):
13
+ {"curves": [{"name": "side_top_line", "view": "left", "points_px": [[x, y], ...],
14
+ "depth": 0.0, optional: coordinate on the view's depth axis
15
+ "pair_view": "top", optional: read the depth axis from another view
16
+ "pair_curve": "top_edge", optional: ... from this curve picked in the pair view
17
+ "pair_side": "max"}]} optional: ... else from the pair view's outline, max / min
18
+ Pairing convention: a curve picked in one view fixes the two axes that view shows; the axis it cannot see
19
+ (its depth axis) is read from the pair view, which must show that axis. The pair view shares one axis with
20
+ the curve's view: at every curve point the shared coordinate is kept, and the depth coordinate is read from
21
+ the pair curve (interpolated along the shared axis) or from the pair view's outline boundary at that shared
22
+ coordinate. Example: a side-view top line (y, z) paired with the top view's outline max side gets x = the
23
+ plan half-width at each y. Points beyond the pair source's range are clamped to its ends and counted.
24
+
25
+ Writes traces.json (read in a build script with construction_kit.load_traces; stamp the parts built on it
26
+ with construction_kit.stamp_traces) and trace_<view>.png previews: outline (green), holes (orange), design
27
+ curves (magenta) and the crop box (blue) on the dimmed reference.
28
+
29
+ node bt-blender.mjs trace --spec refs/spec.json --out refs/traces.json [--curves refs/curves.json]
30
+ [--simplify-px 1.5] [--preview-dir dir]
31
+ """
32
+ import os
33
+ import sys
34
+
35
+ sys.dont_write_bytecode = True
36
+ SCRIPT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
37
+ if SCRIPT_DIRECTORY not in sys.path:
38
+ sys.path.insert(0, SCRIPT_DIRECTORY)
39
+
40
+ import numpy as np # noqa: E402
41
+
42
+ import evidence_sheet # noqa: E402
43
+ import image_measure # noqa: E402
44
+ import ortho_views # noqa: E402
45
+ import reference_traces # noqa: E402
46
+ import tool_common # noqa: E402
47
+
48
+ TOOL_NAME = "trace"
49
+
50
+ DEFAULT_SIMPLIFY_PIXELS = 1.5
51
+
52
+ # Holes smaller than this share of the subject's area are not traced (anti-aliasing specks).
53
+ MINIMUM_HOLE_SHARE = 0.001
54
+
55
+ # Preview colours and sizes.
56
+ OUTLINE_COLOR = (0.2, 0.95, 0.4)
57
+ HOLE_COLOR = (1.0, 0.6, 0.1)
58
+ CURVE_COLOR = (1.0, 0.25, 0.85)
59
+ CROP_COLOR = (0.3, 0.6, 1.0)
60
+ LINE_PIXELS = 2
61
+ CURVE_POINT_RADIUS = 3
62
+
63
+ # Decimal places kept for pixel and metre coordinates in traces.json.
64
+ PIXEL_DECIMALS = 2
65
+ METRE_DECIMALS = 5
66
+
67
+
68
+ def build_parser() -> tool_common.ToolArgumentParser:
69
+ """The tool's command-line options."""
70
+ parser = tool_common.ToolArgumentParser(prog=TOOL_NAME, description=__doc__.strip().splitlines()[0])
71
+ parser.add_argument("--spec", required=True, help="stations spec JSON: registered straight views")
72
+ parser.add_argument("--out", required=True, help="traces JSON to write")
73
+ parser.add_argument("--curves", help="named design curves picked in image pixels (JSON)")
74
+ parser.add_argument("--simplify-px", type=float, default=DEFAULT_SIMPLIFY_PIXELS,
75
+ help="largest deviation of the simplified outline from the pixel outline, pixels")
76
+ parser.add_argument("--preview-dir", help="folder for trace_<view>.png (default: the --out folder)")
77
+ return parser
78
+
79
+
80
+ def image_axes(view: str) -> dict:
81
+ """The view's image axes as world axis names and signs: {"right": (axis, sign), "up": (axis, sign)}."""
82
+ basis = ortho_views.view_basis(view)
83
+ return {"right": ortho_views.axis_of(basis.right), "up": ortho_views.axis_of(basis.up),
84
+ "depth": ortho_views.axis_of(basis.forward)}
85
+
86
+
87
+ def pixels_to_plane(points_px: np.ndarray, frame: ortho_views.PixelFrame, axes: dict) -> np.ndarray:
88
+ """
89
+ Converts (column, row) pixels into world coordinates on the view plane.
90
+
91
+ :param points_px: (N, 2) continuous pixel coordinates.
92
+ :param frame: The view's pixel frame.
93
+ :param axes: image_axes() of the view.
94
+ :returns: (N, 2) metres along (right axis, up axis).
95
+ """
96
+ right = ortho_views.pixel_to_coordinate(points_px[:, 0], "right", frame, axes["right"][1])
97
+ up = ortho_views.pixel_to_coordinate(points_px[:, 1], "up", frame, axes["up"][1])
98
+ return np.column_stack((right, up))
99
+
100
+
101
+ def subject_regions(view_spec: dict, rgba: np.ndarray) -> tuple:
102
+ """
103
+ The view's subject: the largest region of the cropped background-separated mask, and its holes: regions
104
+ enclosed by the subject that are transparent or background-coloured (openings, or light details the same
105
+ colour as the background; the outline stays filled either way).
106
+
107
+ :returns: (subject mask with holes filled, hole mask, number of smaller regions left out).
108
+ :raises ValueError: when the view holds no subject.
109
+ """
110
+ tolerance = float(view_spec.get("background_tolerance", image_measure.DEFAULT_BACKGROUND_TOLERANCE))
111
+ mask = image_measure.apply_crop(image_measure.subject_mask(rgba, tolerance, remove_specks=False), view_spec.get("crop"))
112
+ if not mask.any():
113
+ raise ValueError(f"view '{view_spec['name']}': no subject found in {view_spec['image']}")
114
+ subject = image_measure.largest_component(mask)
115
+ dropped = len(image_measure.component_regions(mask & ~subject))
116
+ filled = subject | image_measure.hole_mask(subject)
117
+ holes = filled & image_measure.background_like(rgba, tolerance)
118
+ return filled, holes, dropped
119
+
120
+
121
+ def trace_view(view_spec: dict, spec_directory: str, simplify_pixels: float) -> dict:
122
+ """
123
+ Traces one view.
124
+
125
+ :returns: The view's traces record, plus "_reference" (the image) and "_frame" for the caller's use.
126
+ """
127
+ image_path = os.path.normpath(os.path.join(spec_directory, view_spec["image"]))
128
+ rgba = tool_common.load_image(image_path)
129
+ height, width = rgba.shape[:2]
130
+ frame = ortho_views.frame_from_spec(view_spec, width, height)
131
+ axes = image_axes(view_spec["view"])
132
+ filled, holes, dropped = subject_regions({**view_spec, "image": image_path}, rgba)
133
+ outer = image_measure.outline_loops(filled)[0]
134
+ outline_px = image_measure.simplify_polyline(outer, simplify_pixels)
135
+ minimum_hole_area = MINIMUM_HOLE_SHARE * float(filled.sum())
136
+ hole_records = []
137
+ for loop in image_measure.outline_loops(holes):
138
+ area = image_measure.signed_area(loop)
139
+ if area < minimum_hole_area:
140
+ continue # a speck, or an island inside a hole (traced counter-clockwise, negative area)
141
+ simplified = image_measure.simplify_polyline(loop, simplify_pixels)
142
+ hole_records.append({"area_px": round(area, 1), "outline_px": np.round(simplified, PIXEL_DECIMALS).tolist(),
143
+ "outline_world": np.round(pixels_to_plane(simplified, frame, axes), METRE_DECIMALS).tolist()})
144
+ left, top = outer.min(axis=0)
145
+ right, bottom = outer.max(axis=0)
146
+ corners = pixels_to_plane(np.array([[left, top], [right, bottom]]), frame, axes)
147
+ extent = {axes["right"][0]: sorted(np.round(corners[:, 0], METRE_DECIMALS).tolist()),
148
+ axes["up"][0]: sorted(np.round(corners[:, 1], METRE_DECIMALS).tolist())}
149
+ return {"view": view_spec["view"], "image": image_path, "image_size_px": [width, height],
150
+ "pixels_per_metre": frame.pixels_per_metre, "origin_pixel": [frame.origin_column, frame.origin_row],
151
+ "crop": view_spec.get("crop"),
152
+ "image_axes": {key: {"axis": axis, "sign": sign} for key, (axis, sign) in axes.items()},
153
+ "plane_axes": [axes["right"][0], axes["up"][0]], "depth_axis": axes["depth"][0],
154
+ "bounds_px": [float(left), float(top), float(right), float(bottom)], "extent_m": extent,
155
+ "area_px": int(filled.sum()), "regions_left_out": dropped,
156
+ "outline_px": np.round(outline_px, PIXEL_DECIMALS).tolist(),
157
+ "outline_world": np.round(pixels_to_plane(outline_px, frame, axes), METRE_DECIMALS).tolist(),
158
+ "holes": hole_records, "_reference": rgba, "_frame": frame, "_axes": axes}
159
+
160
+
161
+ def _pair_depths(curve: dict, shared_axis: str, shared_values: np.ndarray, depth_axis: str, records: dict,
162
+ curve_specs: dict, trace_set: reference_traces.TraceSet) -> tuple:
163
+ """The depth coordinate of every curve point read from the pair view: (depths, clamped point count)."""
164
+ pair = records[curve["pair_view"]]
165
+ pair_axes = pair["plane_axes"]
166
+ if curve.get("pair_curve"):
167
+ source = curve_specs.get(curve["pair_curve"])
168
+ if source is None or source["view"] != curve["pair_view"]:
169
+ raise ValueError(f"curve '{curve['name']}': pair_curve '{curve['pair_curve']}' must be a curve picked in "
170
+ f"view '{curve['pair_view']}'")
171
+ plane = pixels_to_plane(np.array(source["points_px"], dtype=np.float64), pair["_frame"], pair["_axes"])
172
+ along, across = plane[:, pair_axes.index(shared_axis)], plane[:, pair_axes.index(depth_axis)]
173
+ order = np.argsort(along)
174
+ clamped = int(((shared_values < along.min()) | (shared_values > along.max())).sum())
175
+ return np.interp(shared_values, along[order], across[order]), clamped
176
+ side = curve.get("pair_side", "max")
177
+ low, high = trace_set.extent(curve["pair_view"])[shared_axis]
178
+ inside = np.clip(shared_values, low, high)
179
+ depths = [trace_set.outline_boundary(curve["pair_view"], shared_axis, value, side) for value in inside]
180
+ return np.array(depths, dtype=np.float64), int((inside != shared_values).sum())
181
+
182
+
183
+ def trace_curve(curve: dict, records: dict, curve_specs: dict, trace_set: reference_traces.TraceSet) -> dict:
184
+ """
185
+ Converts one picked design curve into world points.
186
+
187
+ :param curve: {"name", "view", "points_px", optional "depth", "pair_view", "pair_curve", "pair_side"}.
188
+ :param records: Traced views by name.
189
+ :param curve_specs: Every curve spec by name (pair curves are read from here).
190
+ :param trace_set: The traced views, for outline lookups.
191
+ :returns: The curve's traces record.
192
+ """
193
+ name = curve["name"]
194
+ if curve.get("view") not in records:
195
+ raise ValueError(f"curve '{name}': unknown view '{curve.get('view')}'")
196
+ points_px = np.array(curve.get("points_px") or [], dtype=np.float64).reshape(-1, 2)
197
+ if len(points_px) < 2:
198
+ raise ValueError(f"curve '{name}' needs at least two points_px")
199
+ record = records[curve["view"]]
200
+ plane_axes, depth_axis = record["plane_axes"], record["depth_axis"]
201
+ plane = pixels_to_plane(points_px, record["_frame"], record["_axes"])
202
+ world = np.zeros((len(plane), 3))
203
+ for column, axis in enumerate(plane_axes):
204
+ world[:, ortho_views.AXIS_NAMES.index(axis)] = plane[:, column]
205
+ clamped = 0
206
+ result = {"view": curve["view"], "points_px": points_px.round(PIXEL_DECIMALS).tolist()}
207
+ if curve.get("pair_view"):
208
+ if curve["pair_view"] not in records:
209
+ raise ValueError(f"curve '{name}': unknown pair_view '{curve['pair_view']}'")
210
+ pair_axes = records[curve["pair_view"]]["plane_axes"]
211
+ if depth_axis not in pair_axes:
212
+ raise ValueError(f"curve '{name}': pair_view '{curve['pair_view']}' shows {pair_axes}, not the "
213
+ f"{depth_axis} axis view '{curve['view']}' cannot see")
214
+ shared_axis = next(axis for axis in pair_axes if axis != depth_axis)
215
+ shared_values = plane[:, plane_axes.index(shared_axis)]
216
+ depths, clamped = _pair_depths({**curve, "name": name}, shared_axis, shared_values, depth_axis, records,
217
+ curve_specs, trace_set)
218
+ result.update({"pair_view": curve["pair_view"], "shared_axis": shared_axis,
219
+ "pair_source": f"curve {curve['pair_curve']}" if curve.get("pair_curve")
220
+ else f"outline {curve.get('pair_side', 'max')}"})
221
+ else:
222
+ depths = np.full(len(plane), float(curve.get("depth", 0.0)))
223
+ world[:, ortho_views.AXIS_NAMES.index(depth_axis)] = depths
224
+ result.update({"depth_axis": depth_axis, "points_world": world.round(METRE_DECIMALS).tolist(),
225
+ "clamped_points": clamped})
226
+ return result
227
+
228
+
229
+ def write_preview(name: str, record: dict, curves: dict, directory: str) -> str:
230
+ """Draws the traced outline, holes, curves and crop box on the dimmed reference; returns the file."""
231
+ picture = evidence_sheet.dimmed(record["_reference"])
232
+ if record["crop"]:
233
+ evidence_sheet.draw_box(picture, record["crop"], CROP_COLOR, 1)
234
+ image_measure.draw_polyline(picture, np.array(record["outline_px"]), OUTLINE_COLOR, LINE_PIXELS)
235
+ for hole in record["holes"]:
236
+ image_measure.draw_polyline(picture, np.array(hole["outline_px"]), HOLE_COLOR, LINE_PIXELS)
237
+ for curve_name, curve in curves.items():
238
+ if curve["view"] != name:
239
+ continue
240
+ points = np.array(curve["points_px"])
241
+ image_measure.draw_polyline(picture, points, CURVE_COLOR, LINE_PIXELS, closed=False)
242
+ for point in points:
243
+ image_measure.draw_circle(picture, point, CURVE_POINT_RADIUS, CURVE_COLOR)
244
+ evidence_sheet.draw_text(picture, curve_name, int(points[0][0]) + 4, int(points[0][1]) + 4, CURVE_COLOR)
245
+ evidence_sheet.draw_text(picture, f"{name} ({record['view']})", 6, 6, OUTLINE_COLOR)
246
+ return tool_common.save_image(os.path.join(directory, f"trace_{name}.png"), picture)
247
+
248
+
249
+ def run(options) -> dict:
250
+ """
251
+ Traces every view and curve and writes traces.json and the previews.
252
+
253
+ :param options: Parsed options.
254
+ :returns: The tool result.
255
+ """
256
+ spec_path = os.path.abspath(options.spec)
257
+ spec_directory = os.path.dirname(spec_path)
258
+ spec = tool_common.load_json(spec_path)
259
+ views = spec.get("views") or []
260
+ if not views:
261
+ raise ValueError("the spec has no views")
262
+ records = {view["name"]: trace_view(view, spec_directory, options.simplify_px) for view in views}
263
+ public = {name: {key: value for key, value in record.items() if not key.startswith("_")}
264
+ for name, record in records.items()}
265
+ trace_set = reference_traces.TraceSet({"views": public})
266
+ curve_list = tool_common.load_json(options.curves).get("curves", []) if options.curves else []
267
+ curve_specs = {curve["name"]: curve for curve in curve_list}
268
+ curves = {curve["name"]: trace_curve(curve, records, curve_specs, trace_set) for curve in curve_list}
269
+ out_path = os.path.abspath(options.out)
270
+ preview_directory = os.path.abspath(options.preview_dir or os.path.dirname(out_path))
271
+ previews = {name: write_preview(name, record, curves, preview_directory) for name, record in records.items()}
272
+ traces = {"spec": spec_path, "simplify_px": options.simplify_px, "views": public, "curves": curves}
273
+ tool_common.write_json(out_path, traces)
274
+ return {"pass": True, "traces": out_path, "sha256": reference_traces.file_sha256(out_path),
275
+ "views": {name: {"extent_m": record["extent_m"], "outline_points": len(record["outline_px"]),
276
+ "holes": len(record["holes"]), "regions_left_out": record["regions_left_out"],
277
+ "preview": previews[name]} for name, record in public.items()},
278
+ "curves": {name: {"points": len(curve["points_world"]), "clamped_points": curve["clamped_points"]}
279
+ for name, curve in curves.items()}}
280
+
281
+
282
+ if __name__ == "__main__":
283
+ tool_common.run_tool(TOOL_NAME, build_parser(), run)