vibedgames 0.10.0 → 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-FXXVXDTW.js → chunk-24TITAFS.js} +1 -1
- package/dist/{chunk-OGX4DKIS.js → chunk-2C5PG2QO.js} +1 -1
- package/dist/{chunk-HYOXGNWS.js → chunk-2DEVOKI7.js} +1 -1
- package/dist/{chunk-RRI23NK2.js → chunk-2GHPYT2P.js} +1 -1
- package/dist/{chunk-S7HYWITX.js → chunk-2HXGMXGC.js} +1 -1
- package/dist/{chunk-N2UHAQXC.js → chunk-36FORP7T.js} +0 -1
- package/dist/{chunk-VB4WLJR2.js → chunk-3IXRQTRF.js} +1 -1
- package/dist/{chunk-2KVQJKIZ.js → chunk-4ENHS32B.js} +23 -36
- package/dist/{chunk-SXYQL4GK.js → chunk-4YHA32OE.js} +1 -1
- package/dist/{chunk-4FJXCS3K.js → chunk-4ZGQKPK5.js} +1 -1
- package/dist/{chunk-SBXCK2I2.js → chunk-6CLUPFQA.js} +2 -2
- package/dist/{chunk-TXOE5UY5.js → chunk-7WTF2BA4.js} +1 -1
- package/dist/{chunk-R2WVORGD.js → chunk-AAXZNK4Z.js} +1 -1
- package/dist/{chunk-DOOQUFPG.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-SUSX3QIA.js → chunk-E72TFJZP.js} +1 -1
- package/dist/{chunk-E3FJUPLT.js → chunk-EUAAQMUA.js} +2 -0
- package/dist/{chunk-U6DTE5IX.js → chunk-F7LYJSZE.js} +1 -1
- package/dist/{chunk-MEAO33XW.js → chunk-FMON3C74.js} +8 -8
- package/dist/{chunk-GLEW7VJQ.js → chunk-FPILHRLZ.js} +1 -1
- package/dist/{chunk-OPUCUUID.js → chunk-G63MXDX2.js} +4 -0
- 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-RKS7SI5L.js → chunk-NO6KPV64.js} +1 -1
- package/dist/{chunk-KJK5CB6E.js → chunk-NXW3Z4Y4.js} +1 -1
- package/dist/{chunk-7RPLQWR2.js → chunk-OHOAZGO4.js} +1 -1
- package/dist/chunk-PYJNI5WD.js +83 -0
- package/dist/{chunk-NCX6LYNJ.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-HX5Q63UA.js → chunk-T777EXAO.js} +1 -1
- package/dist/{chunk-UQ7VO6B3.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-ZHLPE6LI.js → chunk-UIKYK7KI.js} +1 -1
- package/dist/{chunk-KAGVI3CE.js → chunk-UJRSQO2B.js} +1 -1
- package/dist/{chunk-Q2QC6KAZ.js → chunk-V7LEYVXB.js} +29 -25
- package/dist/{chunk-DB7WVFS7.js → chunk-WRMQEXUC.js} +1 -1
- package/dist/{chunk-HSMG6U7J.js → chunk-WXSBNC67.js} +3 -9
- package/dist/{chunk-QLCVLCPM.js → chunk-X4QIOXNQ.js} +1 -1
- package/dist/{chunk-5YPLKGY3.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-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,356 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Tier-1 cheap, deterministic diagnostics — run BEFORE any expensive AI-vision
|
|
3
|
+
comparison-sheet review (Plan 1.3 Workstream B). Pure Python 3.10+ standard
|
|
4
|
+
library only, no PIL/numpy, matching the rest of forge/.
|
|
5
|
+
|
|
6
|
+
Output is a machine-checked pass/fail plus numbers — no visual judgment, no
|
|
7
|
+
AI-vision call. `orchestrate_passes.py` refuses to unlock the comparison-sheet
|
|
8
|
+
step until a passing tier1Result exists for the current render's hash
|
|
9
|
+
(Workstream D).
|
|
10
|
+
|
|
11
|
+
Known scope limitation: per_part_color_delta compares the render's OVERALL
|
|
12
|
+
dominant color clusters against each component's colorMaterialRecipe, not a
|
|
13
|
+
true per-component cropped region (that would need per-component render-crop
|
|
14
|
+
coordinates, which the pipeline does not yet track). This is a coarser signal
|
|
15
|
+
than the plan's ideal, but per Risk R7, Tier 1 only needs to be discriminative
|
|
16
|
+
enough to catch gross mismatches, not pixel-perfect — documented here rather
|
|
17
|
+
than silently overclaimed.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import hashlib
|
|
24
|
+
import json
|
|
25
|
+
import sys
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "stage1_intake"))
|
|
30
|
+
from extract_pbr_evidence import build_foreground_mask, load_image # noqa: E402
|
|
31
|
+
from extract_part_color_recipe import lab_distance, lab_kmeans_palette, srgb_to_lab # noqa: E402
|
|
32
|
+
|
|
33
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "stage3_build"))
|
|
34
|
+
from orchestrate_passes import DEFAULT_PASS_ORDER, load_spec # noqa: E402
|
|
35
|
+
from geometry_integrity import measure_geometry_integrity # noqa: E402
|
|
36
|
+
from status_banner import emit_status, load_optional_spec # noqa: E402
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def color_is_gated(pass_id: str | None) -> bool:
|
|
40
|
+
"""Per-part color fidelity is a hard criterion only from `material-pass` onward.
|
|
41
|
+
|
|
42
|
+
Blockout / structural / form-refinement passes render the model with clay
|
|
43
|
+
(materials deliberately stripped) so the silhouette can be judged on shape
|
|
44
|
+
alone — comparing their per-part color against a colored reference always
|
|
45
|
+
fails and says nothing about those passes' goals. Before material-pass (or
|
|
46
|
+
when the pass is unknown) the color delta is recorded as informational, never
|
|
47
|
+
a failure. This mirrors the skill doctrine: "blockout: silhouette reads
|
|
48
|
+
correctly WITHOUT materials".
|
|
49
|
+
"""
|
|
50
|
+
if pass_id is None:
|
|
51
|
+
return False
|
|
52
|
+
try:
|
|
53
|
+
return DEFAULT_PASS_ORDER.index(pass_id) >= DEFAULT_PASS_ORDER.index("material-pass")
|
|
54
|
+
except ValueError:
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
SILHOUETTE_IOU_THRESHOLD = 0.85
|
|
59
|
+
ASPECT_RATIO_DELTA_THRESHOLD = 0.05
|
|
60
|
+
SCALE_DELTA_THRESHOLD = 0.08
|
|
61
|
+
SYMMETRY_ERROR_THRESHOLD = 0.10
|
|
62
|
+
COLOR_DELTA_E_THRESHOLD = 20.0 # generous vs. the JND (~2-3) to tolerate render/photo lighting gaps
|
|
63
|
+
MASK_GRID_SIZE = 224
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def mask_is_inverted(warnings: list[str]) -> bool:
|
|
67
|
+
"""Return whether foreground extraction fell back to whole-frame coverage."""
|
|
68
|
+
return any("tiny" in str(warning).lower() for warning in warnings)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def largest_component(mask: list[bool], size: int) -> tuple[list[bool], float]:
|
|
72
|
+
"""Keep the largest 4-connected blob; return it and the fraction of cells discarded.
|
|
73
|
+
|
|
74
|
+
WHY. `bbox_of` is an EXTREMAL statistic: one stray foreground cell in a corner moves the
|
|
75
|
+
bounding box to the frame edge, and every proportion derived from it with it. Measured on a
|
|
76
|
+
real review plate, a subject filling 24% of the grid reported a bbox of the entire 224x224
|
|
77
|
+
grid, so `aspectRatioDelta` and `scaleDelta` were describing the render's background gradient
|
|
78
|
+
and did not move at all when the camera did.
|
|
79
|
+
|
|
80
|
+
The discarded fraction is returned rather than swallowed: a subject with genuinely separated
|
|
81
|
+
parts in projection -- a floating accessory, a detached prop -- would lose them here, and that
|
|
82
|
+
has to be visible instead of quietly improving the numbers.
|
|
83
|
+
"""
|
|
84
|
+
seen = [False] * len(mask)
|
|
85
|
+
best: list[int] = []
|
|
86
|
+
total = sum(1 for value in mask if value)
|
|
87
|
+
for start in range(len(mask)):
|
|
88
|
+
if not mask[start] or seen[start]:
|
|
89
|
+
continue
|
|
90
|
+
stack = [start]
|
|
91
|
+
seen[start] = True
|
|
92
|
+
blob = []
|
|
93
|
+
while stack:
|
|
94
|
+
index = stack.pop()
|
|
95
|
+
blob.append(index)
|
|
96
|
+
y, x = divmod(index, size)
|
|
97
|
+
for nx, ny in ((x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)):
|
|
98
|
+
if 0 <= nx < size and 0 <= ny < size:
|
|
99
|
+
neighbour = ny * size + nx
|
|
100
|
+
if mask[neighbour] and not seen[neighbour]:
|
|
101
|
+
seen[neighbour] = True
|
|
102
|
+
stack.append(neighbour)
|
|
103
|
+
if len(blob) > len(best):
|
|
104
|
+
best = blob
|
|
105
|
+
filtered = [False] * len(mask)
|
|
106
|
+
for index in best:
|
|
107
|
+
filtered[index] = True
|
|
108
|
+
discarded = (total - len(best)) / total if total else 0.0
|
|
109
|
+
return filtered, discarded
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def load_mask(png_path: Path, size: int = MASK_GRID_SIZE) -> tuple[list[bool], list[str]]:
|
|
113
|
+
"""Return the resized foreground mask and extraction warnings."""
|
|
114
|
+
width, height, pixels, _warnings = load_image(png_path)
|
|
115
|
+
mask, _diag, mask_warnings = build_foreground_mask(width, height, pixels)
|
|
116
|
+
resized: list[bool] = []
|
|
117
|
+
for y in range(size):
|
|
118
|
+
sy = min(height - 1, int(y * height / size))
|
|
119
|
+
for x in range(size):
|
|
120
|
+
sx = min(width - 1, int(x * width / size))
|
|
121
|
+
resized.append(mask[sy * width + sx])
|
|
122
|
+
filtered, discarded = largest_component(resized, size)
|
|
123
|
+
if discarded > 0.02:
|
|
124
|
+
mask_warnings = list(mask_warnings) + [
|
|
125
|
+
f"{discarded:.1%} of foreground cells lie outside the largest connected blob and were "
|
|
126
|
+
"excluded from the bounding box; if the subject really has separated parts in this "
|
|
127
|
+
"projection, they are not being measured"
|
|
128
|
+
]
|
|
129
|
+
return filtered, mask_warnings
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def silhouette_iou(reference_mask: list[bool], render_mask: list[bool]) -> float:
|
|
133
|
+
intersection = 0
|
|
134
|
+
union = 0
|
|
135
|
+
for ref, render in zip(reference_mask, render_mask):
|
|
136
|
+
if ref or render:
|
|
137
|
+
union += 1
|
|
138
|
+
if ref and render:
|
|
139
|
+
intersection += 1
|
|
140
|
+
return intersection / union if union else 0.0
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def bbox_of(mask: list[bool], size: int = MASK_GRID_SIZE) -> tuple[int, int, int, int]:
|
|
144
|
+
xs: list[int] = []
|
|
145
|
+
ys: list[int] = []
|
|
146
|
+
for index, value in enumerate(mask):
|
|
147
|
+
if value:
|
|
148
|
+
xs.append(index % size)
|
|
149
|
+
ys.append(index // size)
|
|
150
|
+
if not xs:
|
|
151
|
+
return (0, 0, 0, 0)
|
|
152
|
+
x0, x1 = min(xs), max(xs)
|
|
153
|
+
y0, y1 = min(ys), max(ys)
|
|
154
|
+
return (x0, y0, x1 - x0 + 1, y1 - y0 + 1)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def proportion_delta(
|
|
158
|
+
reference_bbox: tuple[int, int, int, int],
|
|
159
|
+
render_bbox: tuple[int, int, int, int],
|
|
160
|
+
) -> dict[str, float]:
|
|
161
|
+
_rx, _ry, rw, rh = reference_bbox
|
|
162
|
+
_dx, _dy, dw, dh = render_bbox
|
|
163
|
+
ref_ar = rw / rh if rh else 0.0
|
|
164
|
+
render_ar = dw / dh if dh else 0.0
|
|
165
|
+
aspect_ratio_delta = abs(ref_ar - render_ar) / ref_ar if ref_ar else (0.0 if render_ar == 0 else 1.0)
|
|
166
|
+
ref_area = rw * rh
|
|
167
|
+
render_area = dw * dh
|
|
168
|
+
scale_delta = abs(ref_area - render_area) / ref_area if ref_area else (0.0 if render_area == 0 else 1.0)
|
|
169
|
+
return {"aspect_ratio_delta": round(aspect_ratio_delta, 4), "scale_delta": round(scale_delta, 4)}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def bilateral_symmetry_error(mask: list[bool], size: int = MASK_GRID_SIZE) -> float:
|
|
173
|
+
total = 0
|
|
174
|
+
mismatches = 0
|
|
175
|
+
for y in range(size):
|
|
176
|
+
row_offset = y * size
|
|
177
|
+
for x in range(size):
|
|
178
|
+
mirrored_x = size - 1 - x
|
|
179
|
+
total += 1
|
|
180
|
+
if mask[row_offset + x] != mask[row_offset + mirrored_x]:
|
|
181
|
+
mismatches += 1
|
|
182
|
+
return mismatches / total if total else 0.0
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def per_part_color_delta(recipes: list[dict[str, Any]], render_path: Path) -> dict[str, Any]:
|
|
186
|
+
"""Compares each component's colorMaterialRecipe against the render's overall
|
|
187
|
+
dominant Lab-space color clusters (see module docstring for the per-component-
|
|
188
|
+
region scope limitation). Returns per-recipe delta-E and a pass/fail summary."""
|
|
189
|
+
if not recipes:
|
|
190
|
+
return {"checked": 0, "maxDeltaE": 0.0, "perComponent": []}
|
|
191
|
+
width, height, pixels, _warnings = load_image(render_path)
|
|
192
|
+
mask, _diag, _warn = build_foreground_mask(width, height, pixels)
|
|
193
|
+
foreground_lab = [srgb_to_lab((r, g, b)) for (r, g, b, _a), keep in zip(pixels, mask) if keep]
|
|
194
|
+
clusters = lab_kmeans_palette(foreground_lab, k=min(5, max(1, len(recipes))))
|
|
195
|
+
results = []
|
|
196
|
+
for recipe in recipes:
|
|
197
|
+
dominant = recipe.get("dominantAlbedo")
|
|
198
|
+
if not isinstance(dominant, str):
|
|
199
|
+
continue
|
|
200
|
+
try:
|
|
201
|
+
rgb_text = dominant[dominant.index("(") + 1 : dominant.index(")")]
|
|
202
|
+
r, g, b = (int(float(part.strip())) for part in rgb_text.split(",")[:3])
|
|
203
|
+
except (ValueError, IndexError):
|
|
204
|
+
continue
|
|
205
|
+
expected_lab = srgb_to_lab((r, g, b))
|
|
206
|
+
best_delta = min((lab_distance(expected_lab, c["center"]) for c in clusters), default=999.0)
|
|
207
|
+
results.append({"componentId": recipe.get("componentId"), "deltaE": round(best_delta, 2)})
|
|
208
|
+
max_delta = max((entry["deltaE"] for entry in results), default=0.0)
|
|
209
|
+
return {"checked": len(results), "maxDeltaE": round(max_delta, 2), "perComponent": results}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def render_hash(render_path: Path) -> str:
|
|
213
|
+
return hashlib.sha256(render_path.read_bytes()).hexdigest()[:16]
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def strip_material_maps(scene: object) -> object:
|
|
217
|
+
if isinstance(scene, list):
|
|
218
|
+
return [strip_material_maps(item) for item in scene]
|
|
219
|
+
if not isinstance(scene, dict):
|
|
220
|
+
return scene
|
|
221
|
+
result = {key: strip_material_maps(value) for key, value in scene.items()}
|
|
222
|
+
for key in ("map", "normalMap", "roughnessMap", "metalnessMap", "aoMap"):
|
|
223
|
+
if key in result:
|
|
224
|
+
result[key] = None
|
|
225
|
+
return result
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def run_tier1(
|
|
229
|
+
reference_path: Path,
|
|
230
|
+
render_path: Path,
|
|
231
|
+
spec_path: Path | None = None,
|
|
232
|
+
pass_id: str | None = None,
|
|
233
|
+
) -> dict[str, Any]:
|
|
234
|
+
reference_mask, reference_mask_warnings = load_mask(reference_path)
|
|
235
|
+
render_mask, render_mask_warnings = load_mask(render_path)
|
|
236
|
+
mask_warnings = (
|
|
237
|
+
[f"reference: {w}" for w in reference_mask_warnings]
|
|
238
|
+
+ [f"render: {w}" for w in render_mask_warnings]
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
iou = silhouette_iou(reference_mask, render_mask)
|
|
242
|
+
reference_bbox = bbox_of(reference_mask)
|
|
243
|
+
render_bbox = bbox_of(render_mask)
|
|
244
|
+
proportions = proportion_delta(reference_bbox, render_bbox)
|
|
245
|
+
symmetry = bilateral_symmetry_error(render_mask)
|
|
246
|
+
|
|
247
|
+
checks: dict[str, Any] = {
|
|
248
|
+
"silhouetteIoU": round(iou, 4),
|
|
249
|
+
"aspectRatioDelta": proportions["aspect_ratio_delta"],
|
|
250
|
+
"scaleDelta": proportions["scale_delta"],
|
|
251
|
+
"bilateralSymmetryError": round(symmetry, 4),
|
|
252
|
+
}
|
|
253
|
+
failures: list[str] = []
|
|
254
|
+
if mask_is_inverted(reference_mask_warnings) or mask_is_inverted(render_mask_warnings):
|
|
255
|
+
failures.append(
|
|
256
|
+
"silhouette evidence is unusable: the foreground mask fell back to whole-frame "
|
|
257
|
+
"coverage (subject under 3.5% of the frame), so IoU and proportion are not "
|
|
258
|
+
"measuring the subject; re-capture with the subject filling more of the frame"
|
|
259
|
+
)
|
|
260
|
+
if iou < SILHOUETTE_IOU_THRESHOLD:
|
|
261
|
+
failures.append(f"silhouette IoU {iou:.3f} is below threshold {SILHOUETTE_IOU_THRESHOLD}")
|
|
262
|
+
if proportions["aspect_ratio_delta"] > ASPECT_RATIO_DELTA_THRESHOLD:
|
|
263
|
+
failures.append(
|
|
264
|
+
f"aspect-ratio delta {proportions['aspect_ratio_delta']:.3f} exceeds "
|
|
265
|
+
f"threshold {ASPECT_RATIO_DELTA_THRESHOLD}"
|
|
266
|
+
)
|
|
267
|
+
if proportions["scale_delta"] > SCALE_DELTA_THRESHOLD:
|
|
268
|
+
failures.append(f"scale delta {proportions['scale_delta']:.3f} exceeds threshold {SCALE_DELTA_THRESHOLD}")
|
|
269
|
+
|
|
270
|
+
if spec_path is not None:
|
|
271
|
+
spec = load_spec(spec_path)
|
|
272
|
+
recipes = [
|
|
273
|
+
component["colorMaterialRecipe"]
|
|
274
|
+
for component in spec.get("componentTree", [])
|
|
275
|
+
if isinstance(component, dict) and isinstance(component.get("colorMaterialRecipe"), dict)
|
|
276
|
+
]
|
|
277
|
+
color_report = per_part_color_delta(recipes, render_path)
|
|
278
|
+
gated = color_is_gated(pass_id)
|
|
279
|
+
color_report["gated"] = gated
|
|
280
|
+
checks["colorDelta"] = color_report
|
|
281
|
+
if gated and color_report["maxDeltaE"] > COLOR_DELTA_E_THRESHOLD:
|
|
282
|
+
failures.append(
|
|
283
|
+
f"max per-part color delta-E {color_report['maxDeltaE']} exceeds "
|
|
284
|
+
f"threshold {COLOR_DELTA_E_THRESHOLD}"
|
|
285
|
+
)
|
|
286
|
+
geometry = spec.get("builtGeometry") or spec.get("geometry")
|
|
287
|
+
if isinstance(geometry, dict):
|
|
288
|
+
structural = measure_geometry_integrity(geometry)
|
|
289
|
+
checks["geometryIntegrity"] = structural
|
|
290
|
+
failures.extend(structural["failures"])
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
"passed": not failures,
|
|
294
|
+
"checks": checks,
|
|
295
|
+
"failures": failures,
|
|
296
|
+
"maskWarnings": mask_warnings,
|
|
297
|
+
"renderHash": render_hash(render_path),
|
|
298
|
+
"passId": pass_id,
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def record_tier1_result(spec: dict[str, Any], result: dict[str, Any]) -> None:
|
|
303
|
+
"""Appends to spec['tier1Results'] so orchestrate_passes.py (Workstream D) can
|
|
304
|
+
refuse to unlock the Tier-2 comparison-sheet step until a passing entry exists
|
|
305
|
+
for the current pass/render hash."""
|
|
306
|
+
results = spec.setdefault("tier1Results", [])
|
|
307
|
+
if isinstance(results, list):
|
|
308
|
+
results.append(result)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def main(argv: list[str]) -> int:
|
|
312
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
313
|
+
parser.add_argument("--reference", type=Path, required=True)
|
|
314
|
+
parser.add_argument("--render", type=Path, required=True)
|
|
315
|
+
parser.add_argument("--spec", type=Path, help="ObjectSculptSpec JSON (for per-part color delta + recording the result)")
|
|
316
|
+
parser.add_argument("--pass-id")
|
|
317
|
+
parser.add_argument("--in-place", action="store_true", help="Record the result into --spec")
|
|
318
|
+
parser.add_argument("--out-spec", type=Path, help="Write the spec with the recorded result to this path")
|
|
319
|
+
parser.add_argument("--map-stripped-scene", type=Path, help="Write a scene JSON with material maps disabled")
|
|
320
|
+
parser.add_argument("--map-stripped-render", type=Path, help="Existing unlit/map-stripped render evidence")
|
|
321
|
+
parser.add_argument("--json", action="store_true")
|
|
322
|
+
args = parser.parse_args(argv)
|
|
323
|
+
|
|
324
|
+
try:
|
|
325
|
+
emit_status(load_optional_spec(args.spec), next_command="diagnose_render.py", stream=sys.stderr if args.json else sys.stdout)
|
|
326
|
+
if args.map_stripped_scene:
|
|
327
|
+
scene = json.loads(args.map_stripped_scene.read_text(encoding="utf-8"))
|
|
328
|
+
args.map_stripped_scene.write_text(json.dumps(strip_material_maps(scene), indent=2) + "\n", encoding="utf-8")
|
|
329
|
+
spec_path = args.spec.expanduser().resolve() if args.spec else None
|
|
330
|
+
result = run_tier1(
|
|
331
|
+
args.reference.expanduser().resolve(),
|
|
332
|
+
args.render.expanduser().resolve(),
|
|
333
|
+
spec_path,
|
|
334
|
+
args.pass_id,
|
|
335
|
+
)
|
|
336
|
+
if args.pass_id == "blockout":
|
|
337
|
+
if not args.map_stripped_render:
|
|
338
|
+
result.setdefault("failures", []).append("blockout requires --map-stripped-render evidence")
|
|
339
|
+
result["passed"] = False
|
|
340
|
+
else:
|
|
341
|
+
result["mapStrippedRender"] = str(args.map_stripped_render)
|
|
342
|
+
if spec_path and (args.in_place or args.out_spec):
|
|
343
|
+
spec = json.loads(spec_path.read_text(encoding="utf-8"))
|
|
344
|
+
record_tier1_result(spec, result)
|
|
345
|
+
output = spec_path if args.in_place else args.out_spec.expanduser().resolve()
|
|
346
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
347
|
+
output.write_text(json.dumps(spec, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
348
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
349
|
+
return 0 if result["passed"] else 1
|
|
350
|
+
except Exception as exc:
|
|
351
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
352
|
+
return 1
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
if __name__ == "__main__":
|
|
356
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic Phase-3 §3.2 multi-angle "degenerate-view" check.
|
|
3
|
+
|
|
4
|
+
A flat plane faking a 3D volume looks convincing from the single reference
|
|
5
|
+
camera angle, but its silhouette AREA collapses when the camera orbits: a
|
|
6
|
+
billboard seen edge-on nearly vanishes. This module exploits that. Given a set
|
|
7
|
+
of already-rendered PNGs of the SAME object from different camera angles, it
|
|
8
|
+
measures each frame's foreground silhouette area (as a fraction of the frame)
|
|
9
|
+
and flags "degenerate-view" when a non-reference angle's area collapses far
|
|
10
|
+
below the reference angle's area.
|
|
11
|
+
|
|
12
|
+
This check is deterministic and costs zero tokens: it is pure pixel arithmetic
|
|
13
|
+
over foreground masks, reusing the stage1 intake loader/segmenter.
|
|
14
|
+
|
|
15
|
+
Scope: this module only ANALYZES already-captured PNGs. Driving an actual
|
|
16
|
+
browser / renderer to PRODUCE the orbit PNGs is a separate concern handled
|
|
17
|
+
elsewhere in the pipeline.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import json
|
|
24
|
+
import sys
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typing import Any
|
|
27
|
+
|
|
28
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "stage1_intake"))
|
|
29
|
+
from extract_pbr_evidence import load_image, build_foreground_mask, mask_bbox # noqa: E402
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def silhouette_area_fraction(png_path: Path) -> float:
|
|
33
|
+
"""Return the fraction of the frame occupied by the object's silhouette.
|
|
34
|
+
|
|
35
|
+
Loads the image, segments the foreground from the background, and returns
|
|
36
|
+
(foreground pixel count / total pixels). ``mask_bbox`` is imported and kept
|
|
37
|
+
available for callers/tests that want the tight silhouette box, but the area
|
|
38
|
+
fraction itself is computed from the full mask so a small-but-wide sliver
|
|
39
|
+
is scored purely by how much of the frame it actually fills.
|
|
40
|
+
"""
|
|
41
|
+
path = Path(png_path)
|
|
42
|
+
width, height, pixels, _warnings = load_image(path)
|
|
43
|
+
mask, _diag, mask_warnings = build_foreground_mask(width, height, pixels)
|
|
44
|
+
total = len(mask)
|
|
45
|
+
if total <= 0:
|
|
46
|
+
return 0.0
|
|
47
|
+
# HARDENING (lead, from the multiangle worker's finding): build_foreground_mask has
|
|
48
|
+
# a <3.5%-coverage safety fallback that INVERTS a tiny mask to "all opaque pixels"
|
|
49
|
+
# (coverage → ~1.0). For degenerate-view detection that is exactly backwards — a plane
|
|
50
|
+
# orbited edge-on yields a near-zero silhouette that MUST read as collapsed, not full.
|
|
51
|
+
# So when the fallback fired, report near-zero (the true, pre-inversion silhouette).
|
|
52
|
+
if any("tiny" in str(w).lower() for w in mask_warnings):
|
|
53
|
+
return 0.0
|
|
54
|
+
foreground = sum(1 for value in mask if value)
|
|
55
|
+
return foreground / total
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def analyze_angles(
|
|
59
|
+
reference_png: Path,
|
|
60
|
+
orbit_pngs: list[Path],
|
|
61
|
+
collapse_ratio: float = 0.15,
|
|
62
|
+
) -> dict[str, Any]:
|
|
63
|
+
"""Compare each orbit angle's silhouette area against the reference angle.
|
|
64
|
+
|
|
65
|
+
For every orbit angle, ``ratio = orbit_area / reference_area``. When the
|
|
66
|
+
reference area is 0 the ratio is treated as 0.0 (divide-by-zero guard). Any
|
|
67
|
+
orbit angle whose ratio is below ``collapse_ratio`` is flagged degenerate:
|
|
68
|
+
the object nearly vanished from that viewpoint, which is what a flat plane
|
|
69
|
+
faking a volume does when orbited.
|
|
70
|
+
"""
|
|
71
|
+
reference_area = silhouette_area_fraction(Path(reference_png))
|
|
72
|
+
angles: list[dict[str, Any]] = []
|
|
73
|
+
any_degenerate = False
|
|
74
|
+
for orbit in orbit_pngs:
|
|
75
|
+
orbit_area = silhouette_area_fraction(Path(orbit))
|
|
76
|
+
ratio = 0.0 if reference_area <= 0.0 else orbit_area / reference_area
|
|
77
|
+
degenerate = ratio < collapse_ratio
|
|
78
|
+
if degenerate:
|
|
79
|
+
any_degenerate = True
|
|
80
|
+
angles.append(
|
|
81
|
+
{
|
|
82
|
+
"path": str(orbit),
|
|
83
|
+
"areaFraction": orbit_area,
|
|
84
|
+
"ratio": ratio,
|
|
85
|
+
"degenerate": degenerate,
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
return {
|
|
89
|
+
"referenceAreaFraction": reference_area,
|
|
90
|
+
"angles": angles,
|
|
91
|
+
"degenerate": any_degenerate,
|
|
92
|
+
"collapseRatio": collapse_ratio,
|
|
93
|
+
"note": (
|
|
94
|
+
"deterministic; zero token; a flat-plane-faking-a-volume collapses "
|
|
95
|
+
"in silhouette area when orbited"
|
|
96
|
+
),
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _format_summary(result: dict[str, Any]) -> str:
|
|
101
|
+
lines = [
|
|
102
|
+
f"reference area fraction: {result['referenceAreaFraction']:.4f}",
|
|
103
|
+
f"collapse ratio threshold: {result['collapseRatio']}",
|
|
104
|
+
]
|
|
105
|
+
for angle in result["angles"]:
|
|
106
|
+
flag = "DEGENERATE" if angle["degenerate"] else "ok"
|
|
107
|
+
lines.append(
|
|
108
|
+
f" [{flag}] {angle['path']} "
|
|
109
|
+
f"area={angle['areaFraction']:.4f} ratio={angle['ratio']:.4f}"
|
|
110
|
+
)
|
|
111
|
+
verdict = "DEGENERATE-VIEW DETECTED" if result["degenerate"] else "no degenerate view"
|
|
112
|
+
lines.append(f"verdict: {verdict}")
|
|
113
|
+
return "\n".join(lines)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def main(argv: list[str]) -> int:
|
|
117
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
118
|
+
parser.add_argument("--reference", type=Path, required=True, help="reference-angle PNG")
|
|
119
|
+
parser.add_argument(
|
|
120
|
+
"--orbit",
|
|
121
|
+
type=Path,
|
|
122
|
+
action="append",
|
|
123
|
+
default=[],
|
|
124
|
+
help="orbit-angle PNG (repeat for each angle)",
|
|
125
|
+
)
|
|
126
|
+
parser.add_argument("--collapse-ratio", type=float, default=0.15)
|
|
127
|
+
parser.add_argument("--json", action="store_true", help="print JSON instead of a summary")
|
|
128
|
+
args = parser.parse_args(argv)
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
result = analyze_angles(args.reference, args.orbit, args.collapse_ratio)
|
|
132
|
+
if args.json:
|
|
133
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
134
|
+
else:
|
|
135
|
+
print(_format_summary(result))
|
|
136
|
+
return 1 if result["degenerate"] else 0
|
|
137
|
+
except Exception as exc:
|
|
138
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
139
|
+
return 2
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if __name__ == "__main__":
|
|
143
|
+
raise SystemExit(main(sys.argv[1:]))
|