vibedgames 0.10.1 → 0.10.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.
- package/assets/rebuild-object/.cache/spec-search/core_3d.json +1 -0
- package/assets/rebuild-object/.cache/spec-search/cs2.json +1 -0
- package/assets/rebuild-object/LICENSE +201 -0
- package/assets/rebuild-object/NOTICE +7 -0
- package/assets/rebuild-object/docs/materials/material-reference.json +2324 -0
- package/assets/rebuild-object/docs/specs/render-profile.v2.example.json +63 -0
- package/assets/rebuild-object/docs/specs/render-profile.v2.schema.json +56 -0
- package/assets/rebuild-object/docs/specs/vocabulary/README.md +86 -0
- package/assets/rebuild-object/docs/specs/vocabulary/core_3d.jsonl +12 -0
- package/assets/rebuild-object/docs/specs/vocabulary/core_3d_reconstruction.jsonl +37 -0
- package/assets/rebuild-object/docs/specs/vocabulary/cs2.jsonl +8 -0
- package/assets/rebuild-object/docs/specs/vocabulary/cs2_reconstruction.jsonl +62 -0
- package/assets/rebuild-object/forge/_shared/artifact_cache.py +54 -0
- package/assets/rebuild-object/forge/_shared/chirality.py +272 -0
- package/assets/rebuild-object/forge/_shared/color_metrics.py +107 -0
- package/assets/rebuild-object/forge/_shared/feature_acceptance_policy.py +113 -0
- package/assets/rebuild-object/forge/_shared/image_hash.py +113 -0
- package/assets/rebuild-object/forge/_shared/jpeg.py +448 -0
- package/assets/rebuild-object/forge/_shared/material_physics.py +253 -0
- package/assets/rebuild-object/forge/_shared/pipeline_routing.py +177 -0
- package/assets/rebuild-object/forge/_shared/scalp_field.py +302 -0
- package/assets/rebuild-object/forge/_shared/sdf_primitives.py +172 -0
- package/assets/rebuild-object/forge/_shared/spec_search.py +1792 -0
- package/assets/rebuild-object/forge/_shared/spec_search_profiles.json +58 -0
- package/assets/rebuild-object/forge/_shared/status_banner.py +35 -0
- package/assets/rebuild-object/forge/_shared/subdivision.py +232 -0
- package/assets/rebuild-object/forge/_shared/vertex_paint.py +236 -0
- package/assets/rebuild-object/forge/_shared/workflow_state.py +406 -0
- package/assets/rebuild-object/forge/materials/__init__.py +17 -0
- package/assets/rebuild-object/forge/materials/compatibility.py +106 -0
- package/assets/rebuild-object/forge/materials/reference.py +240 -0
- package/assets/rebuild-object/forge/next.py +116 -0
- package/assets/rebuild-object/forge/report.py +38 -0
- package/assets/rebuild-object/forge/requirements.txt +6 -0
- package/assets/rebuild-object/forge/stage1_intake/analyze_texture.py +255 -0
- package/assets/rebuild-object/forge/stage1_intake/bind_detail_properties.py +99 -0
- package/assets/rebuild-object/forge/stage1_intake/build_detail_inventory.py +349 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_math.py +133 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_solver.py +197 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_fitting_types.py +291 -0
- package/assets/rebuild-object/forge/stage1_intake/camera_image_helpers.py +133 -0
- package/assets/rebuild-object/forge/stage1_intake/check_intake_correctness.py +116 -0
- package/assets/rebuild-object/forge/stage1_intake/check_reference_admission.py +203 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_foundation.py +139 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_manifest.py +230 -0
- package/assets/rebuild-object/forge/stage1_intake/cs2_review_contract.py +42 -0
- package/assets/rebuild-object/forge/stage1_intake/delight_albedo.py +352 -0
- package/assets/rebuild-object/forge/stage1_intake/detect_cs2.py +276 -0
- package/assets/rebuild-object/forge/stage1_intake/detect_reference_effects.py +275 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_cs2_textures.py +126 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_gradient_stops.py +149 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_hair_evidence.py +385 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_landmarks.py +456 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_part_color_recipe.py +496 -0
- package/assets/rebuild-object/forge/stage1_intake/extract_pbr_evidence.py +843 -0
- package/assets/rebuild-object/forge/stage1_intake/fetch_cs2_metadata.py +147 -0
- package/assets/rebuild-object/forge/stage1_intake/label_glb_nodes.py +318 -0
- package/assets/rebuild-object/forge/stage1_intake/locate_cs2_vpk.py +73 -0
- package/assets/rebuild-object/forge/stage1_intake/material_region_analysis.py +227 -0
- package/assets/rebuild-object/forge/stage1_intake/probe_glb.py +357 -0
- package/assets/rebuild-object/forge/stage1_intake/probe_image.py +168 -0
- package/assets/rebuild-object/forge/stage1_intake/run_vision_adapter.py +45 -0
- package/assets/rebuild-object/forge/stage1_intake/search_specs.py +258 -0
- package/assets/rebuild-object/forge/stage1_intake/semantic_decomposition.py +119 -0
- package/assets/rebuild-object/forge/stage1_intake/solve_camera_pose.py +254 -0
- package/assets/rebuild-object/forge/stage2_spec/apply_material_analysis.py +192 -0
- package/assets/rebuild-object/forge/stage2_spec/cs2_adapters.py +62 -0
- package/assets/rebuild-object/forge/stage2_spec/derive_geometry.py +118 -0
- package/assets/rebuild-object/forge/stage2_spec/hair_profile.py +306 -0
- package/assets/rebuild-object/forge/stage2_spec/humanoid_proportions.py +214 -0
- package/assets/rebuild-object/forge/stage2_spec/new_pre_spec_assessment.py +343 -0
- package/assets/rebuild-object/forge/stage2_spec/new_sculpt_spec.py +2396 -0
- package/assets/rebuild-object/forge/stage2_spec/validate_sculpt_spec.py +2871 -0
- package/assets/rebuild-object/forge/stage3_build/bake_projected_texture.py +181 -0
- package/assets/rebuild-object/forge/stage3_build/decimate.py +272 -0
- package/assets/rebuild-object/forge/stage3_build/generate_threejs_factory.py +4099 -0
- package/assets/rebuild-object/forge/stage3_build/module_cache.py +155 -0
- package/assets/rebuild-object/forge/stage3_build/morph_targets.py +178 -0
- package/assets/rebuild-object/forge/stage3_build/orchestrate_passes.py +653 -0
- package/assets/rebuild-object/forge/stage3_build/uv_unwrap.py +622 -0
- package/assets/rebuild-object/forge/stage3_build/visual_hull.py +357 -0
- package/assets/rebuild-object/forge/stage4_review/_fit_divine_eye.py +64 -0
- package/assets/rebuild-object/forge/stage4_review/append_review.py +453 -0
- package/assets/rebuild-object/forge/stage4_review/attachment_anchor.py +349 -0
- package/assets/rebuild-object/forge/stage4_review/calibrate_eye.py +131 -0
- package/assets/rebuild-object/forge/stage4_review/check_part_coverage.py +298 -0
- package/assets/rebuild-object/forge/stage4_review/compare_region_passes.py +169 -0
- package/assets/rebuild-object/forge/stage4_review/correction_loop.py +258 -0
- package/assets/rebuild-object/forge/stage4_review/cs2_review.py +224 -0
- package/assets/rebuild-object/forge/stage4_review/diagnose_render.py +356 -0
- package/assets/rebuild-object/forge/stage4_review/diagnose_render_multi_angle.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/divine_eye.py +461 -0
- package/assets/rebuild-object/forge/stage4_review/fit_params.py +381 -0
- package/assets/rebuild-object/forge/stage4_review/geometry_integrity.py +294 -0
- package/assets/rebuild-object/forge/stage4_review/hair_gate.py +216 -0
- package/assets/rebuild-object/forge/stage4_review/interior_difference.py +188 -0
- package/assets/rebuild-object/forge/stage4_review/joint_loops.py +209 -0
- package/assets/rebuild-object/forge/stage4_review/make_comparison_sheet.py +292 -0
- package/assets/rebuild-object/forge/stage4_review/material_comparator.py +181 -0
- package/assets/rebuild-object/forge/stage4_review/material_feedback.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/material_gate.py +126 -0
- package/assets/rebuild-object/forge/stage4_review/material_views.py +184 -0
- package/assets/rebuild-object/forge/stage4_review/mesh_reference_compare.py +362 -0
- package/assets/rebuild-object/forge/stage4_review/multi_pass.py +102 -0
- package/assets/rebuild-object/forge/stage4_review/objectness.py +143 -0
- package/assets/rebuild-object/forge/stage4_review/pairwise_penetration.py +376 -0
- package/assets/rebuild-object/forge/stage4_review/per_feature.py +215 -0
- package/assets/rebuild-object/forge/stage4_review/render_bridge.py +556 -0
- package/assets/rebuild-object/forge/stage4_review/scalp_exposure.py +257 -0
- package/assets/rebuild-object/forge/stage4_review/self_intersection.py +592 -0
- package/assets/rebuild-object/forge/stage4_review/swept_arc_gate.py +336 -0
- package/assets/rebuild-object/forge/stage4_review/turntable_gate.py +415 -0
- package/assets/rebuild-object/forge/stage4_review/validate_render_profile.py +182 -0
- package/assets/rebuild-object/forge/stage4_review/vertex_region_gate.py +456 -0
- package/assets/rebuild-object/forge/stage4_review/vlm_gate.py +196 -0
- package/assets/rebuild-object/forge/stage5_rig/NOTES.md +149 -0
- package/assets/rebuild-object/forge/stage5_rig/__init__.py +6 -0
- package/assets/rebuild-object/forge/stage5_rig/emit_rig.py +420 -0
- package/assets/rebuild-object/forge/stage5_rig/geodesic_skinning.py +508 -0
- package/assets/rebuild-object/forge/stage5_rig/rig_spec.py +174 -0
- package/assets/rebuild-object/forge/stage5_rig/validate_rig_payload.py +195 -0
- package/assets/rebuild-object/forge/state.py +98 -0
- package/assets/rebuild-object/steps.json +381 -0
- package/dist/{chunk-FB3UDZAV.js → chunk-24TITAFS.js} +1 -1
- package/dist/{chunk-QNWCBPVO.js → chunk-2C5PG2QO.js} +1 -1
- package/dist/{chunk-4RYTTD4D.js → chunk-2DEVOKI7.js} +1 -1
- package/dist/{chunk-RRI23NK2.js → chunk-2GHPYT2P.js} +1 -1
- package/dist/{chunk-QEKVZ7BX.js → chunk-2HXGMXGC.js} +1 -1
- package/dist/{chunk-N2UHAQXC.js → chunk-36FORP7T.js} +0 -1
- package/dist/{chunk-DH6WPL3X.js → chunk-3IXRQTRF.js} +1 -1
- package/dist/{chunk-SXYQL4GK.js → chunk-4YHA32OE.js} +1 -1
- package/dist/{chunk-V5ADM3WC.js → chunk-4ZGQKPK5.js} +1 -1
- package/dist/{chunk-BJAN3RMY.js → chunk-6CLUPFQA.js} +1 -1
- package/dist/{chunk-52E6EKZV.js → chunk-7WTF2BA4.js} +1 -1
- package/dist/{chunk-P74GTK23.js → chunk-AAXZNK4Z.js} +1 -1
- package/dist/{chunk-F4J6XCHT.js → chunk-ALLBT4FB.js} +1 -1
- package/dist/{chunk-HRKVAXNN.js → chunk-BAZDPPIG.js} +5 -5
- package/dist/{chunk-RPJR3S5S.js → chunk-CYDENLZ4.js} +5 -8
- package/dist/{chunk-I5LELJSK.js → chunk-DKSUD44G.js} +1 -1
- package/dist/{chunk-43P4U7CB.js → chunk-DWWSJKTE.js} +1 -1
- package/dist/{chunk-6IUFHPMV.js → chunk-E72TFJZP.js} +1 -1
- package/dist/{chunk-E3FJUPLT.js → chunk-EUAAQMUA.js} +2 -0
- package/dist/{chunk-37LLKM73.js → chunk-F7LYJSZE.js} +1 -1
- package/dist/{chunk-MEAO33XW.js → chunk-FMON3C74.js} +8 -8
- package/dist/{chunk-YLUB6252.js → chunk-FPILHRLZ.js} +1 -1
- package/dist/{chunk-4UU622RK.js → chunk-GGO6ZYYI.js} +1 -3
- package/dist/{chunk-2ZKS7V72.js → chunk-GZCRYYS6.js} +5 -5
- package/dist/{chunk-E7NDOZ27.js → chunk-LE4GVTYI.js} +8 -8
- package/dist/{chunk-UTSSDFQL.js → chunk-NO6KPV64.js} +1 -1
- package/dist/{chunk-W2QPNAZ3.js → chunk-NXW3Z4Y4.js} +1 -1
- package/dist/{chunk-NG2X3SMF.js → chunk-OHOAZGO4.js} +1 -1
- package/dist/chunk-PYJNI5WD.js +83 -0
- package/dist/{chunk-VUV5U4J5.js → chunk-Q4XAGTFX.js} +1 -1
- package/dist/{chunk-3UGGMFJJ.js → chunk-QMZBSVKF.js} +1 -1
- package/dist/{chunk-ABTUEIRC.js → chunk-QO66UBOS.js} +2 -2
- package/dist/{chunk-LONQWRTR.js → chunk-S4KVGQQO.js} +8 -8
- package/dist/{chunk-FJXPMA63.js → chunk-T777EXAO.js} +1 -1
- package/dist/{chunk-YXOGRERG.js → chunk-TZZNRA3S.js} +1 -1
- package/dist/{chunk-CTY2WZQK.js → chunk-UC3QLWMQ.js} +1 -1
- package/dist/{chunk-MR5KIFI7.js → chunk-UDJH2RED.js} +3 -3
- package/dist/{chunk-FNJL6Z5C.js → chunk-UIKYK7KI.js} +1 -1
- package/dist/{chunk-PKM3JOKQ.js → chunk-UJRSQO2B.js} +1 -1
- package/dist/{chunk-ALPTHSUT.js → chunk-V7LEYVXB.js} +28 -24
- package/dist/{chunk-DPLFCKXP.js → chunk-WRMQEXUC.js} +1 -1
- package/dist/{chunk-HSMG6U7J.js → chunk-WXSBNC67.js} +3 -9
- package/dist/{chunk-HSCTPDEU.js → chunk-X4QIOXNQ.js} +1 -1
- package/dist/{chunk-72KHWZMN.js → chunk-Y6WHUK2O.js} +1 -1
- package/dist/{chunk-VZEJ2ZHE.js → chunk-Z3E7ORGQ.js} +5 -5
- package/dist/index.js +20 -20
- package/package.json +32 -22
- package/dist/{chunk-OFJIG4K3.js → chunk-4ENHS32B.js} +0 -0
- package/dist/{chunk-Q3XQPNF6.js → chunk-BN7TR6OR.js} +3 -3
- package/dist/{chunk-LORGE2NB.js → chunk-U2NCN5RO.js} +3 -3
- package/dist/{chunk-UPHB5HWO.js → chunk-VQTTSPA3.js} +3 -3
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Mandatory turntable coverage gate with interior-hole (background-enclosure) detection.
|
|
3
|
+
|
|
4
|
+
``diagnose_render_multi_angle`` is reference-free and checks exactly one thing:
|
|
5
|
+
does the silhouette AREA collapse when the object is orbited (the billboard
|
|
6
|
+
test). That leaves two holes an area-only check cannot see through:
|
|
7
|
+
|
|
8
|
+
1. **Coverage was never mandatory.** Reviews were historically captured from
|
|
9
|
+
the front only, so defects that exist solely off-axis survived multiple
|
|
10
|
+
review rounds -- a conical hat mounted at hip height instead of behind the
|
|
11
|
+
shoulders, a weapon passing through the body, a charm floating detached
|
|
12
|
+
below the ground plane. None of those are visible from the front. This
|
|
13
|
+
module makes a minimum set of orbit azimuths (front/right/back/left by
|
|
14
|
+
default) MANDATORY: a missing required angle is a gate FAILURE, not a
|
|
15
|
+
warning, because making the turntable mandatory is the entire point.
|
|
16
|
+
|
|
17
|
+
2. **A hole through the model is invisible to an area test.** A character's
|
|
18
|
+
eye socket was pushed clean through the back of its skull; viewed from
|
|
19
|
+
behind there is a hole through the head. Silhouette AREA barely changes
|
|
20
|
+
(the head is still roughly the same size), so the existing area-collapse
|
|
21
|
+
check passes. But that hole is an enclosed BACKGROUND region trapped
|
|
22
|
+
INSIDE the silhouette -- trivially detectable with a flood fill, at zero
|
|
23
|
+
token cost. This module flood-fills the background from the image border
|
|
24
|
+
and flags any background pixel the fill never reaches: it is enclosed by
|
|
25
|
+
the foreground, i.e. a hole through the object.
|
|
26
|
+
|
|
27
|
+
Important caveat: a legitimately holed subject exists (a ring, a door
|
|
28
|
+
handle, the negative space between an arm and a torso). "holed" here means
|
|
29
|
+
only "the silhouette encloses background at this angle" -- it is a defect
|
|
30
|
+
just when the subject is NOT supposed to have a through-hole there. Callers
|
|
31
|
+
that expect legitimate holes must pass ``allow_holes=True`` /
|
|
32
|
+
``--allow-holes`` to keep that signal from failing the gate.
|
|
33
|
+
|
|
34
|
+
Scope: like its sibling, this module only ANALYZES already-captured PNGs.
|
|
35
|
+
Driving a renderer to produce the orbit captures is handled elsewhere.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
import argparse
|
|
41
|
+
import json
|
|
42
|
+
import sys
|
|
43
|
+
from pathlib import Path
|
|
44
|
+
from typing import Any
|
|
45
|
+
|
|
46
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "stage1_intake"))
|
|
47
|
+
from extract_pbr_evidence import load_image, build_foreground_mask # noqa: E402
|
|
48
|
+
|
|
49
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
50
|
+
from diagnose_render_multi_angle import analyze_angles, silhouette_area_fraction # noqa: E402
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Front/right/back/left: the minimum orbit that can catch an off-axis-only
|
|
54
|
+
# defect. Overridable by callers with unusual rigs (e.g. no rear access).
|
|
55
|
+
REQUIRED_AZIMUTHS: tuple[float, ...] = (0.0, 90.0, 180.0, 270.0)
|
|
56
|
+
DEFAULT_AZIMUTH_TOLERANCE = 5.0
|
|
57
|
+
DEFAULT_COLLAPSE_RATIO = 0.15
|
|
58
|
+
|
|
59
|
+
# A hole must clear BOTH floors to trip the gate: an absolute pixel count
|
|
60
|
+
# (absorbs anti-aliasing speckle around edges -- a stray 1-2px background
|
|
61
|
+
# pixel next to a jagged silhouette edge is not a hole through the model)
|
|
62
|
+
# and a fraction of the silhouette area (so a huge, legitimate silhouette
|
|
63
|
+
# with a tiny enclosed pocket of background isn't over-flagged either).
|
|
64
|
+
INTERIOR_HOLE_PIXEL_FLOOR = 4
|
|
65
|
+
INTERIOR_HOLE_FRACTION_THRESHOLD = 0.01
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _normalize_azimuth(degrees: float) -> float:
|
|
69
|
+
"""Map an azimuth in degrees onto [0, 360). Python's ``%`` already returns
|
|
70
|
+
a non-negative result against a positive divisor, so this also handles
|
|
71
|
+
negative input (e.g. -10 -> 350)."""
|
|
72
|
+
return degrees % 360.0
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _circular_distance(a: float, b: float) -> float:
|
|
76
|
+
"""Shortest distance in degrees between two azimuths around the circle,
|
|
77
|
+
so 359.5 and 0 are 0.5 degrees apart, not 359.5."""
|
|
78
|
+
diff = abs(_normalize_azimuth(a) - _normalize_azimuth(b)) % 360.0
|
|
79
|
+
return min(diff, 360.0 - diff)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _load_mask(png_path: Path) -> tuple[int, int, list[bool], bool]:
|
|
83
|
+
"""Load a capture and build its foreground mask, reusing the same stage1
|
|
84
|
+
loader/segmenter ``silhouette_area_fraction`` uses, so area and hole
|
|
85
|
+
numbers are computed from the identical mask.
|
|
86
|
+
|
|
87
|
+
The fourth return value says whether the segmenter could actually isolate
|
|
88
|
+
the subject. ``build_foreground_mask`` has a documented fallback: when the
|
|
89
|
+
subject is not clearly separable from its background it warns "image is not
|
|
90
|
+
clearly isolated from background" and returns MOST PIXELS as foreground.
|
|
91
|
+
That is the right answer for its original caller, which wants a broad pixel
|
|
92
|
+
sample for material evidence, and completely wrong here — a mask covering
|
|
93
|
+
the whole frame makes the silhouette meaningless, the area ratio ~1.0 for
|
|
94
|
+
every angle, and the enclosed-background holes pure noise.
|
|
95
|
+
|
|
96
|
+
This is not hypothetical. Run against a real review turntable rendered on a
|
|
97
|
+
dark gradient background, the gate reported ``area=0.9966`` per angle and a
|
|
98
|
+
confident PASS while never once measuring the character. A gate that cannot
|
|
99
|
+
see its subject must say so, not pass. Its sibling module already hardens
|
|
100
|
+
the opposite fallback (a tiny mask being inverted to "all opaque"); this is
|
|
101
|
+
the same bug wearing the other face.
|
|
102
|
+
"""
|
|
103
|
+
width, height, pixels, _warnings = load_image(Path(png_path))
|
|
104
|
+
mask, _diagnostics, mask_warnings = build_foreground_mask(width, height, pixels)
|
|
105
|
+
segmented = not any("not clearly isolated" in str(w).lower() for w in mask_warnings)
|
|
106
|
+
return width, height, mask, segmented
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _analyze_holes(width: int, height: int, mask: list[bool]) -> dict[str, Any]:
|
|
110
|
+
"""Flood-fill the BACKGROUND (mask == False) starting from every border
|
|
111
|
+
pixel, iteratively (an explicit stack, not recursion -- these are large
|
|
112
|
+
images and Python's recursion limit would blow on a recursive flood fill).
|
|
113
|
+
Any background pixel the fill never reaches is enclosed by the
|
|
114
|
+
foreground: an interior hole. A second iterative pass then walks the
|
|
115
|
+
unreached background pixels to size each individual hole component and
|
|
116
|
+
find the largest one's bounding box.
|
|
117
|
+
"""
|
|
118
|
+
total = width * height
|
|
119
|
+
foreground_count = sum(1 for value in mask if value)
|
|
120
|
+
|
|
121
|
+
def index(x: int, y: int) -> int:
|
|
122
|
+
return y * width + x
|
|
123
|
+
|
|
124
|
+
# Pass 1: flood-fill background reachable from the border.
|
|
125
|
+
reached = [False] * total
|
|
126
|
+
stack: list[int] = []
|
|
127
|
+
for x in range(width):
|
|
128
|
+
for y in (0, height - 1):
|
|
129
|
+
i = index(x, y)
|
|
130
|
+
if not mask[i] and not reached[i]:
|
|
131
|
+
reached[i] = True
|
|
132
|
+
stack.append(i)
|
|
133
|
+
for y in range(height):
|
|
134
|
+
for x in (0, width - 1):
|
|
135
|
+
i = index(x, y)
|
|
136
|
+
if not mask[i] and not reached[i]:
|
|
137
|
+
reached[i] = True
|
|
138
|
+
stack.append(i)
|
|
139
|
+
while stack:
|
|
140
|
+
i = stack.pop()
|
|
141
|
+
x, y = i % width, i // width
|
|
142
|
+
for nx, ny in ((x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)):
|
|
143
|
+
if 0 <= nx < width and 0 <= ny < height:
|
|
144
|
+
ni = index(nx, ny)
|
|
145
|
+
if not mask[ni] and not reached[ni]:
|
|
146
|
+
reached[ni] = True
|
|
147
|
+
stack.append(ni)
|
|
148
|
+
|
|
149
|
+
# Pass 2: every background pixel not reached from the border is part of
|
|
150
|
+
# some enclosed hole. Walk each connected component to size it and find
|
|
151
|
+
# the largest one's bounding box.
|
|
152
|
+
visited = [False] * total
|
|
153
|
+
total_hole_pixels = 0
|
|
154
|
+
largest_size = 0
|
|
155
|
+
largest_bbox = {"x": 0, "y": 0, "width": 0, "height": 0}
|
|
156
|
+
for start in range(total):
|
|
157
|
+
if mask[start] or reached[start] or visited[start]:
|
|
158
|
+
continue
|
|
159
|
+
comp_stack = [start]
|
|
160
|
+
visited[start] = True
|
|
161
|
+
size = 0
|
|
162
|
+
min_x = max_x = start % width
|
|
163
|
+
min_y = max_y = start // width
|
|
164
|
+
while comp_stack:
|
|
165
|
+
i = comp_stack.pop()
|
|
166
|
+
x, y = i % width, i // width
|
|
167
|
+
size += 1
|
|
168
|
+
min_x, max_x = min(min_x, x), max(max_x, x)
|
|
169
|
+
min_y, max_y = min(min_y, y), max(max_y, y)
|
|
170
|
+
for nx, ny in ((x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)):
|
|
171
|
+
if 0 <= nx < width and 0 <= ny < height:
|
|
172
|
+
ni = index(nx, ny)
|
|
173
|
+
if not mask[ni] and not reached[ni] and not visited[ni]:
|
|
174
|
+
visited[ni] = True
|
|
175
|
+
comp_stack.append(ni)
|
|
176
|
+
total_hole_pixels += size
|
|
177
|
+
if size > largest_size:
|
|
178
|
+
largest_size = size
|
|
179
|
+
largest_bbox = {
|
|
180
|
+
"x": min_x,
|
|
181
|
+
"y": min_y,
|
|
182
|
+
"width": max_x - min_x + 1,
|
|
183
|
+
"height": max_y - min_y + 1,
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interior_fraction = (total_hole_pixels / foreground_count) if foreground_count > 0 else 0.0
|
|
187
|
+
return {
|
|
188
|
+
"interiorHolePixelCount": total_hole_pixels,
|
|
189
|
+
"interiorHoleFraction": interior_fraction,
|
|
190
|
+
"largestHolePixelCount": largest_size,
|
|
191
|
+
"largestHoleBBox": largest_bbox,
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def analyze_turntable(
|
|
196
|
+
captures: list[tuple[float, Path]],
|
|
197
|
+
*,
|
|
198
|
+
required_azimuths: tuple[float, ...] = REQUIRED_AZIMUTHS,
|
|
199
|
+
azimuth_tolerance: float = DEFAULT_AZIMUTH_TOLERANCE,
|
|
200
|
+
collapse_ratio: float = DEFAULT_COLLAPSE_RATIO,
|
|
201
|
+
allow_holes: bool = False,
|
|
202
|
+
) -> dict[str, Any]:
|
|
203
|
+
"""Run the mandatory-coverage + interior-hole turntable gate.
|
|
204
|
+
|
|
205
|
+
``captures`` is a list of ``(azimuth_degrees, png_path)`` pairs. Azimuths
|
|
206
|
+
are normalized into [0, 360) and matched to ``required_azimuths`` within
|
|
207
|
+
``azimuth_tolerance`` degrees (circular, so 359.5 matches a required 0).
|
|
208
|
+
A required azimuth with no matching capture is a gate FAILURE.
|
|
209
|
+
|
|
210
|
+
The capture closest to azimuth 0 is used as the reference frame for the
|
|
211
|
+
area-collapse check (delegated to ``diagnose_render_multi_angle
|
|
212
|
+
.analyze_angles``); every other capture is an orbit angle compared
|
|
213
|
+
against it, mirroring that module's single-reference model.
|
|
214
|
+
|
|
215
|
+
Every capture, including the reference, is independently checked for an
|
|
216
|
+
interior hole (background enclosed by the silhouette).
|
|
217
|
+
|
|
218
|
+
``holed`` (per-capture and top-level) always reports the raw detection
|
|
219
|
+
signal, regardless of ``allow_holes`` -- it documents what was actually
|
|
220
|
+
found. ``allow_holes`` only affects the final ``passed`` gate, per the
|
|
221
|
+
module docstring's caveat that an enclosed-background signal is a defect
|
|
222
|
+
only when the subject is not supposed to have a through-hole there.
|
|
223
|
+
"""
|
|
224
|
+
if not captures:
|
|
225
|
+
raise ValueError("analyze_turntable requires at least one capture")
|
|
226
|
+
|
|
227
|
+
ordered = sorted(captures, key=lambda capture: _normalize_azimuth(capture[0]))
|
|
228
|
+
|
|
229
|
+
# Reference = capture closest to azimuth 0 ("front"). Found by index (not
|
|
230
|
+
# by tuple identity/equality) so duplicate (azimuth, path) pairs can't
|
|
231
|
+
# accidentally exclude the wrong entry.
|
|
232
|
+
reference_index = min(
|
|
233
|
+
range(len(ordered)), key=lambda i: _circular_distance(ordered[i][0], 0.0)
|
|
234
|
+
)
|
|
235
|
+
reference_azimuth, reference_path = ordered[reference_index]
|
|
236
|
+
orbit_captures = [capture for i, capture in enumerate(ordered) if i != reference_index]
|
|
237
|
+
orbit_paths = [path for _azimuth, path in orbit_captures]
|
|
238
|
+
|
|
239
|
+
area_result = analyze_angles(reference_path, orbit_paths, collapse_ratio)
|
|
240
|
+
|
|
241
|
+
# Stitch analyze_angles' per-orbit-angle results back onto their azimuths
|
|
242
|
+
# (same order as orbit_paths, since that's exactly what was passed in).
|
|
243
|
+
per_azimuth: dict[int, dict[str, Any]] = {
|
|
244
|
+
reference_index: {
|
|
245
|
+
"areaFraction": area_result["referenceAreaFraction"],
|
|
246
|
+
"ratio": 1.0,
|
|
247
|
+
"degenerate": False,
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
for i, orbit_result in zip((i for i in range(len(ordered)) if i != reference_index), area_result["angles"]):
|
|
251
|
+
per_azimuth[i] = {
|
|
252
|
+
"areaFraction": orbit_result["areaFraction"],
|
|
253
|
+
"ratio": orbit_result["ratio"],
|
|
254
|
+
"degenerate": orbit_result["degenerate"],
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
angles: list[dict[str, Any]] = []
|
|
258
|
+
any_holed = False
|
|
259
|
+
unsegmented: list[float] = []
|
|
260
|
+
for i, (azimuth, path) in enumerate(ordered):
|
|
261
|
+
width, height, mask, segmented = _load_mask(path)
|
|
262
|
+
hole_info = _analyze_holes(width, height, mask)
|
|
263
|
+
# Hole numbers computed over a whole-frame fallback mask are noise, so they are not allowed to
|
|
264
|
+
# set `holed` either way -- neither to fail the gate on garbage nor, worse, to pass it.
|
|
265
|
+
holed = segmented and (
|
|
266
|
+
hole_info["largestHolePixelCount"] > INTERIOR_HOLE_PIXEL_FLOOR
|
|
267
|
+
and hole_info["interiorHoleFraction"] > INTERIOR_HOLE_FRACTION_THRESHOLD
|
|
268
|
+
)
|
|
269
|
+
if holed:
|
|
270
|
+
any_holed = True
|
|
271
|
+
if not segmented:
|
|
272
|
+
unsegmented.append(azimuth)
|
|
273
|
+
record = {
|
|
274
|
+
"azimuth": azimuth,
|
|
275
|
+
"path": str(path),
|
|
276
|
+
"isReference": i == reference_index,
|
|
277
|
+
"segmented": segmented,
|
|
278
|
+
"holed": holed,
|
|
279
|
+
**hole_info,
|
|
280
|
+
**per_azimuth[i],
|
|
281
|
+
}
|
|
282
|
+
angles.append(record)
|
|
283
|
+
|
|
284
|
+
missing_azimuths: list[float] = []
|
|
285
|
+
for required in required_azimuths:
|
|
286
|
+
matched = any(
|
|
287
|
+
_circular_distance(azimuth, required) <= azimuth_tolerance
|
|
288
|
+
for azimuth, _path in captures
|
|
289
|
+
)
|
|
290
|
+
if not matched:
|
|
291
|
+
missing_azimuths.append(_normalize_azimuth(required))
|
|
292
|
+
|
|
293
|
+
covered = not missing_azimuths
|
|
294
|
+
degenerate = area_result["degenerate"]
|
|
295
|
+
# An unsegmentable capture blocks the gate regardless of `allow_holes`. `allow_holes` says "this
|
|
296
|
+
# subject is allowed to have a through-hole"; it does not say "evaluate this render blind". Passing
|
|
297
|
+
# here would be the exact defect this module was written to end, one layer further down.
|
|
298
|
+
passed = (
|
|
299
|
+
covered
|
|
300
|
+
and not degenerate
|
|
301
|
+
and not unsegmented
|
|
302
|
+
and (allow_holes or not any_holed)
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
"angles": angles,
|
|
307
|
+
"referenceAzimuth": reference_azimuth,
|
|
308
|
+
"requiredAzimuths": list(required_azimuths),
|
|
309
|
+
"azimuthTolerance": azimuth_tolerance,
|
|
310
|
+
"missingAzimuths": missing_azimuths,
|
|
311
|
+
"covered": covered,
|
|
312
|
+
"collapseRatio": collapse_ratio,
|
|
313
|
+
"degenerate": degenerate,
|
|
314
|
+
"allowHoles": allow_holes,
|
|
315
|
+
"holed": any_holed,
|
|
316
|
+
"unsegmentedAzimuths": unsegmented,
|
|
317
|
+
"segmentationReliable": not unsegmented,
|
|
318
|
+
"passed": passed,
|
|
319
|
+
"note": (
|
|
320
|
+
"deterministic; zero token; mandatory azimuth coverage catches "
|
|
321
|
+
"off-axis-only defects, interior-hole flood fill catches "
|
|
322
|
+
"silhouette-enclosed background that an area-only check misses"
|
|
323
|
+
),
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def _format_summary(result: dict[str, Any]) -> str:
|
|
328
|
+
lines = [
|
|
329
|
+
f"reference azimuth: {result['referenceAzimuth']}",
|
|
330
|
+
f"required azimuths: {result['requiredAzimuths']} "
|
|
331
|
+
f"(tolerance {result['azimuthTolerance']} deg)",
|
|
332
|
+
f"collapse ratio threshold: {result['collapseRatio']}",
|
|
333
|
+
f"allow holes: {result['allowHoles']}",
|
|
334
|
+
]
|
|
335
|
+
if result["missingAzimuths"]:
|
|
336
|
+
lines.append(f"MISSING required azimuths: {result['missingAzimuths']}")
|
|
337
|
+
if result.get("unsegmentedAzimuths"):
|
|
338
|
+
lines.append(
|
|
339
|
+
f"UNSEGMENTED azimuths {result['unsegmentedAzimuths']}: the subject could not be "
|
|
340
|
+
"isolated from its background, so area and hole numbers on those frames are "
|
|
341
|
+
"meaningless. Re-render the turntable against a high-contrast or transparent "
|
|
342
|
+
"background before reading this gate's verdict."
|
|
343
|
+
)
|
|
344
|
+
for angle in result["angles"]:
|
|
345
|
+
flags = []
|
|
346
|
+
if not angle.get("segmented", True):
|
|
347
|
+
flags.append("UNSEGMENTED")
|
|
348
|
+
if angle["degenerate"]:
|
|
349
|
+
flags.append("DEGENERATE")
|
|
350
|
+
if angle["holed"]:
|
|
351
|
+
flags.append("HOLED")
|
|
352
|
+
flag = ",".join(flags) if flags else "ok"
|
|
353
|
+
tag = " (reference)" if angle["isReference"] else ""
|
|
354
|
+
lines.append(
|
|
355
|
+
f" [{flag}] azimuth={angle['azimuth']}{tag} {angle['path']} "
|
|
356
|
+
f"area={angle['areaFraction']:.4f} ratio={angle['ratio']:.4f} "
|
|
357
|
+
f"holePixels={angle['interiorHolePixelCount']} "
|
|
358
|
+
f"largestHole={angle['largestHolePixelCount']}"
|
|
359
|
+
)
|
|
360
|
+
verdict = "PASS" if result["passed"] else "GATE FAILURE"
|
|
361
|
+
lines.append(f"verdict: {verdict}")
|
|
362
|
+
return "\n".join(lines)
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _parse_capture(raw: str) -> tuple[float, Path]:
|
|
366
|
+
if "=" not in raw:
|
|
367
|
+
raise ValueError(f"--capture expects azimuth=path, got {raw!r}")
|
|
368
|
+
azimuth_str, path_str = raw.split("=", 1)
|
|
369
|
+
return float(azimuth_str), Path(path_str)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def main(argv: list[str]) -> int:
|
|
373
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
374
|
+
parser.add_argument(
|
|
375
|
+
"--capture",
|
|
376
|
+
type=str,
|
|
377
|
+
action="append",
|
|
378
|
+
default=[],
|
|
379
|
+
help="azimuth=path.png (repeat for each turntable capture)",
|
|
380
|
+
)
|
|
381
|
+
parser.add_argument(
|
|
382
|
+
"--required",
|
|
383
|
+
type=float,
|
|
384
|
+
action="append",
|
|
385
|
+
default=None,
|
|
386
|
+
help=f"required azimuth in degrees (repeat; default {REQUIRED_AZIMUTHS})",
|
|
387
|
+
)
|
|
388
|
+
parser.add_argument("--azimuth-tolerance", type=float, default=DEFAULT_AZIMUTH_TOLERANCE)
|
|
389
|
+
parser.add_argument("--collapse-ratio", type=float, default=DEFAULT_COLLAPSE_RATIO)
|
|
390
|
+
parser.add_argument("--allow-holes", action="store_true")
|
|
391
|
+
parser.add_argument("--json", action="store_true", help="print JSON instead of a summary")
|
|
392
|
+
args = parser.parse_args(argv)
|
|
393
|
+
|
|
394
|
+
try:
|
|
395
|
+
captures = [_parse_capture(raw) for raw in args.capture]
|
|
396
|
+
required_azimuths = tuple(args.required) if args.required else REQUIRED_AZIMUTHS
|
|
397
|
+
result = analyze_turntable(
|
|
398
|
+
captures,
|
|
399
|
+
required_azimuths=required_azimuths,
|
|
400
|
+
azimuth_tolerance=args.azimuth_tolerance,
|
|
401
|
+
collapse_ratio=args.collapse_ratio,
|
|
402
|
+
allow_holes=args.allow_holes,
|
|
403
|
+
)
|
|
404
|
+
if args.json:
|
|
405
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
406
|
+
else:
|
|
407
|
+
print(_format_summary(result))
|
|
408
|
+
return 0 if result["passed"] else 1
|
|
409
|
+
except Exception as exc:
|
|
410
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
411
|
+
return 2
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
if __name__ == "__main__":
|
|
415
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Validate the shared GLB/procedural browser render profile.
|
|
3
|
+
|
|
4
|
+
The validator is intentionally dependency-free and stricter than the descriptive
|
|
5
|
+
JSON Schema: the same profile must be usable by both routes, and the six diagnostic
|
|
6
|
+
passes plus the one-feedback-group ordering are mandatory for v2.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
PASS_IDS = (
|
|
18
|
+
"beauty",
|
|
19
|
+
"alpha-silhouette",
|
|
20
|
+
"semantic-id",
|
|
21
|
+
"depth",
|
|
22
|
+
"normal",
|
|
23
|
+
"roughness-material-id",
|
|
24
|
+
)
|
|
25
|
+
FEEDBACK_GROUPS = ("camera", "silhouette", "face", "clothing", "accessory", "materials", "lighting")
|
|
26
|
+
TONE_MAPPINGS = {"NoToneMapping", "ACESFilmicToneMapping", "AgXToneMapping", "NeutralToneMapping"}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _is_vec(value: Any, length: int) -> bool:
|
|
30
|
+
return isinstance(value, list) and len(value) == length and all(isinstance(item, (int, float)) for item in value)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def validate_profile(profile: dict[str, Any]) -> dict[str, Any]:
|
|
34
|
+
errors: list[str] = []
|
|
35
|
+
warnings: list[str] = []
|
|
36
|
+
if profile.get("schemaVersion") != "render-profile.v2":
|
|
37
|
+
errors.append("schemaVersion must be render-profile.v2")
|
|
38
|
+
if profile.get("kind") != "threejs-render-profile":
|
|
39
|
+
errors.append("kind must be threejs-render-profile")
|
|
40
|
+
if profile.get("authority") != "browser-threejs":
|
|
41
|
+
errors.append("authority must be browser-threejs")
|
|
42
|
+
|
|
43
|
+
renderer = profile.get("renderer")
|
|
44
|
+
if not isinstance(renderer, dict):
|
|
45
|
+
errors.append("renderer must be an object")
|
|
46
|
+
else:
|
|
47
|
+
required = {
|
|
48
|
+
"backend",
|
|
49
|
+
"colorManagementEnabled",
|
|
50
|
+
"workingColorSpace",
|
|
51
|
+
"outputColorSpace",
|
|
52
|
+
"toneMapping",
|
|
53
|
+
"toneMappingExposure",
|
|
54
|
+
"viewport",
|
|
55
|
+
"devicePixelRatio",
|
|
56
|
+
"antialias",
|
|
57
|
+
}
|
|
58
|
+
for key in sorted(required - renderer.keys()):
|
|
59
|
+
errors.append(f"renderer.{key} is required")
|
|
60
|
+
if renderer.get("backend") != "WebGLRenderer":
|
|
61
|
+
errors.append("renderer.backend must be WebGLRenderer")
|
|
62
|
+
if renderer.get("colorManagementEnabled") is not True:
|
|
63
|
+
errors.append("renderer.colorManagementEnabled must be true")
|
|
64
|
+
if renderer.get("workingColorSpace") != "Linear-sRGB":
|
|
65
|
+
errors.append("renderer.workingColorSpace must be Linear-sRGB")
|
|
66
|
+
if renderer.get("outputColorSpace") != "SRGBColorSpace":
|
|
67
|
+
errors.append("renderer.outputColorSpace must be SRGBColorSpace")
|
|
68
|
+
if renderer.get("toneMapping") not in TONE_MAPPINGS:
|
|
69
|
+
errors.append("renderer.toneMapping is not a supported Three.js profile value")
|
|
70
|
+
if not isinstance(renderer.get("toneMappingExposure"), (int, float)) or renderer.get("toneMappingExposure", 0) <= 0:
|
|
71
|
+
errors.append("renderer.toneMappingExposure must be > 0")
|
|
72
|
+
viewport = renderer.get("viewport")
|
|
73
|
+
if not _is_vec(viewport, 2) or any(int(value) != value or value <= 0 for value in viewport):
|
|
74
|
+
errors.append("renderer.viewport must be [positive integer width, positive integer height]")
|
|
75
|
+
if not isinstance(renderer.get("devicePixelRatio"), (int, float)) or renderer.get("devicePixelRatio", 0) <= 0:
|
|
76
|
+
errors.append("renderer.devicePixelRatio must be > 0")
|
|
77
|
+
if not isinstance(renderer.get("antialias"), bool):
|
|
78
|
+
errors.append("renderer.antialias must be boolean")
|
|
79
|
+
|
|
80
|
+
environment = profile.get("environment")
|
|
81
|
+
if not isinstance(environment, dict):
|
|
82
|
+
errors.append("environment must be an object")
|
|
83
|
+
else:
|
|
84
|
+
if environment.get("kind") not in {"none", "pmrem-hdr", "pmrem-equirectangular", "pmrem-cubemap"}:
|
|
85
|
+
errors.append("environment.kind must identify a PMREM or none")
|
|
86
|
+
if not isinstance(environment.get("source"), str):
|
|
87
|
+
errors.append("environment.source is required")
|
|
88
|
+
if not isinstance(environment.get("intensity"), (int, float)) or environment.get("intensity", -1) < 0:
|
|
89
|
+
errors.append("environment.intensity must be >= 0")
|
|
90
|
+
if environment.get("kind", "").startswith("pmrem") and environment.get("prefilter") != "PMREMGenerator":
|
|
91
|
+
warnings.append("PMREM environment should record prefilter=PMREMGenerator")
|
|
92
|
+
|
|
93
|
+
camera = profile.get("camera")
|
|
94
|
+
if not isinstance(camera, dict):
|
|
95
|
+
errors.append("camera must be an object")
|
|
96
|
+
else:
|
|
97
|
+
if camera.get("projection") not in {"perspective", "orthographic"}:
|
|
98
|
+
errors.append("camera.projection must be perspective or orthographic")
|
|
99
|
+
for key in ("position", "target"):
|
|
100
|
+
if not _is_vec(camera.get(key), 3):
|
|
101
|
+
errors.append(f"camera.{key} must be a numeric vec3")
|
|
102
|
+
if not isinstance(camera.get("near"), (int, float)) or camera.get("near", 0) <= 0:
|
|
103
|
+
errors.append("camera.near must be > 0")
|
|
104
|
+
if not isinstance(camera.get("far"), (int, float)) or camera.get("far", 0) <= camera.get("near", 0):
|
|
105
|
+
errors.append("camera.far must be greater than camera.near")
|
|
106
|
+
|
|
107
|
+
background = profile.get("background")
|
|
108
|
+
if not isinstance(background, dict) or background.get("kind") not in {"solid", "transparent", "scene"}:
|
|
109
|
+
errors.append("background.kind must be solid, transparent, or scene")
|
|
110
|
+
|
|
111
|
+
passes = profile.get("passes")
|
|
112
|
+
pass_ids = [item.get("id") for item in passes] if isinstance(passes, list) and all(isinstance(item, dict) for item in passes) else []
|
|
113
|
+
if set(pass_ids) != set(PASS_IDS) or len(pass_ids) != len(PASS_IDS):
|
|
114
|
+
errors.append(f"passes must contain exactly: {', '.join(PASS_IDS)}")
|
|
115
|
+
else:
|
|
116
|
+
for item in passes:
|
|
117
|
+
if item.get("required") is not True:
|
|
118
|
+
errors.append(f"pass {item.get('id')} must be required")
|
|
119
|
+
if item.get("id") == "beauty" and item.get("colorSpace") != "SRGBColorSpace":
|
|
120
|
+
errors.append("beauty pass must use SRGBColorSpace")
|
|
121
|
+
if item.get("id") != "beauty" and item.get("colorSpace") != "NoColorSpace":
|
|
122
|
+
errors.append(f"diagnostic pass {item.get('id')} must use NoColorSpace")
|
|
123
|
+
|
|
124
|
+
regions = profile.get("regions")
|
|
125
|
+
region_ids = [item.get("id") for item in regions] if isinstance(regions, list) and all(isinstance(item, dict) for item in regions) else []
|
|
126
|
+
if not region_ids:
|
|
127
|
+
errors.append("regions must contain at least one subject-specific semantic region")
|
|
128
|
+
if any(not isinstance(region_id, str) or not region_id.strip() for region_id in region_ids):
|
|
129
|
+
errors.append("every region.id must be a non-empty string")
|
|
130
|
+
if len(set(region_ids)) != len(region_ids):
|
|
131
|
+
errors.append("region IDs must be unique")
|
|
132
|
+
|
|
133
|
+
extensions = profile.get("extensions")
|
|
134
|
+
required_regions = extensions.get("requiredSemanticRegions") if isinstance(extensions, dict) else None
|
|
135
|
+
if (
|
|
136
|
+
not isinstance(required_regions, list)
|
|
137
|
+
or not required_regions
|
|
138
|
+
or any(not isinstance(region_id, str) or not region_id.strip() for region_id in required_regions)
|
|
139
|
+
):
|
|
140
|
+
errors.append("extensions.requiredSemanticRegions must be a non-empty array of non-empty strings")
|
|
141
|
+
required_regions = []
|
|
142
|
+
elif len(set(required_regions)) != len(required_regions):
|
|
143
|
+
errors.append("extensions.requiredSemanticRegions must contain unique IDs")
|
|
144
|
+
missing_regions = [region for region in required_regions if region not in region_ids]
|
|
145
|
+
if missing_regions:
|
|
146
|
+
errors.append(f"regions missing declared required IDs: {', '.join(missing_regions)}")
|
|
147
|
+
|
|
148
|
+
feedback = profile.get("feedbackGroups")
|
|
149
|
+
feedback_ids = [item.get("id") for item in feedback] if isinstance(feedback, list) and all(isinstance(item, dict) for item in feedback) else []
|
|
150
|
+
if feedback_ids != list(FEEDBACK_GROUPS):
|
|
151
|
+
errors.append("feedbackGroups must be ordered camera, silhouette, face, clothing, accessory, materials, lighting")
|
|
152
|
+
else:
|
|
153
|
+
for index, item in enumerate(feedback, start=1):
|
|
154
|
+
if item.get("order") != index:
|
|
155
|
+
errors.append(f"feedback group {item.get('id')} must have order {index}")
|
|
156
|
+
|
|
157
|
+
return {"passed": not errors, "errors": errors, "warnings": warnings, "passIds": pass_ids, "regionIds": region_ids, "feedbackGroups": feedback_ids}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def validate_file(path: Path) -> dict[str, Any]:
|
|
161
|
+
try:
|
|
162
|
+
value = json.loads(path.read_text(encoding="utf-8"))
|
|
163
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
164
|
+
return {"passed": False, "errors": [f"cannot read JSON: {exc}"], "warnings": []}
|
|
165
|
+
if not isinstance(value, dict):
|
|
166
|
+
return {"passed": False, "errors": ["profile root must be an object"], "warnings": []}
|
|
167
|
+
result = validate_profile(value)
|
|
168
|
+
result["path"] = str(path.resolve())
|
|
169
|
+
return result
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def main(argv: list[str]) -> int:
|
|
173
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
174
|
+
parser.add_argument("profile", type=Path)
|
|
175
|
+
args = parser.parse_args(argv)
|
|
176
|
+
result = validate_file(args.profile.expanduser().resolve())
|
|
177
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
178
|
+
return 0 if result["passed"] else 1
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
if __name__ == "__main__":
|
|
182
|
+
raise SystemExit(main(__import__("sys").argv[1:]))
|