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,349 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Attachment Anchor Gate: does every worn/held item actually relate to what it hangs from?
|
|
3
|
+
|
|
4
|
+
Two production defects share one root cause. A conical hat that should sit behind the
|
|
5
|
+
character's shoulders rendered at hip height, off to one side. A charm that should hang from
|
|
6
|
+
the butt of a staff rendered detached, four units away and below the ground plane. Measured:
|
|
7
|
+
the hat's bounding box spanned y 1.107-4.064 while the shoulder joint sat at y 3.829; the charm
|
|
8
|
+
sat 0.389 from the staff surface with no connecting geometry at all. Both were authored as
|
|
9
|
+
children of the model ROOT rather than of the thing they are attached to, so nothing tied
|
|
10
|
+
their world position to their anchor, and nothing checked it afterward. No gate in this repo
|
|
11
|
+
relates a worn or held item to what it is worn on or held by -- `ATTACHMENT_ROLES` in
|
|
12
|
+
validate_sculpt_spec.py is a DIFFERENT contract (limbs/branches/handles that must EMBED into
|
|
13
|
+
their parent's geometry, via `attachment.parentSocket`/`localStart`/`localEnd`); it has nothing
|
|
14
|
+
to say about a rigid item that merely has to sit near a bone or component it is not welded to.
|
|
15
|
+
|
|
16
|
+
Five checks. The first four run over the spec alone; the fifth only runs when the caller
|
|
17
|
+
supplies measured world positions (e.g. from a runtime parts manifest), because that is the
|
|
18
|
+
only way to catch a hat that is correctly *declared* but wrongly *placed*.
|
|
19
|
+
|
|
20
|
+
ANCHOR_DECLARED every worn/held/hung component must name an anchor.
|
|
21
|
+
ANCHOR_RESOLVES the named anchor must be a real component, or (with a rig) a real bone.
|
|
22
|
+
ANCHOR_NOT_ROOT the anchor must not be the model ROOT -- the literal bug both defects
|
|
23
|
+
shared: parenting to root means the item's transform carries no
|
|
24
|
+
relationship at all to the body part it belongs to.
|
|
25
|
+
ANCHOR_NOT_CYCLIC following anchors must not loop, and an item must not anchor to itself.
|
|
26
|
+
ANCHOR_PROXIMITY (measured positions only) the item's measured position must sit within
|
|
27
|
+
its anchor's declared or defaulted `maxOffset`.
|
|
28
|
+
|
|
29
|
+
A component missing from the measured positions is never silently treated as passing --
|
|
30
|
+
it is reported in `unmeasuredAttachments`, because "0 violations" from a check that never
|
|
31
|
+
ran on anything is the exact failure mode that let both defects ship.
|
|
32
|
+
|
|
33
|
+
Pure Python 3.10+ stdlib. No pip installs.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
import argparse
|
|
39
|
+
import json
|
|
40
|
+
import sys
|
|
41
|
+
from pathlib import Path
|
|
42
|
+
from typing import Any
|
|
43
|
+
|
|
44
|
+
# Vocabulary for "this component IS a worn/held/hung attachment" -- deliberately small and
|
|
45
|
+
# disjoint from ATTACHMENT_ROLES in validate_sculpt_spec.py, which flags a component that
|
|
46
|
+
# needs an EMBEDDING contract (a limb welding into its parent's geometry). This gate is about
|
|
47
|
+
# an item's world-position relationship to what it hangs from, not about a geometry weld, so
|
|
48
|
+
# the vocabularies must not collide: "arm"/"leg"/"branch" belong to the other gate, not here.
|
|
49
|
+
ANCHOR_ATTACHMENT_TOKENS = {"attachment", "accessory", "worn", "held", "prop", "equipment"}
|
|
50
|
+
|
|
51
|
+
# ANCHOR_PROXIMITY default #1: when the anchor is a component with a `dimensions` block, the
|
|
52
|
+
# allowed drift is a fraction of the anchor's own largest declared extent -- a small anchor
|
|
53
|
+
# (a staff) tolerates only a small absolute offset, a large one (a torso) tolerates more. This
|
|
54
|
+
# is what makes the charm regression fire without an authored `maxOffset`: a 0.1-wide staff
|
|
55
|
+
# caps drift at 0.025, far under the charm's real 0.389 detachment.
|
|
56
|
+
ANCHOR_PROXIMITY_SIZE_FRACTION = 0.25
|
|
57
|
+
_EXTENT_FIELDS = ("width", "height", "depth", "length")
|
|
58
|
+
|
|
59
|
+
# ANCHOR_PROXIMITY default #2: when the anchor supplies no extents at all (a bone, or a
|
|
60
|
+
# component with no `dimensions`), fall back to this constant. Chosen to be small relative to
|
|
61
|
+
# the unit-scale specs this repo authors (compare PROPORTION_LIMIT_FRACTION in
|
|
62
|
+
# validate_sculpt_spec.py, which reasons the same way over a different quantity).
|
|
63
|
+
DEFAULT_MAX_OFFSET = 0.3
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _is_number(value: Any) -> bool:
|
|
67
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _is_xyz(value: Any) -> bool:
|
|
71
|
+
return isinstance(value, (list, tuple)) and len(value) == 3 and all(_is_number(v) for v in value)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _distance(a: list[float], b: list[float]) -> float:
|
|
75
|
+
return sum((float(a[i]) - float(b[i])) ** 2 for i in range(3)) ** 0.5
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _is_attachment_component(component: dict[str, Any]) -> bool:
|
|
79
|
+
"""A component counts as a worn/held/hung attachment when it already declares
|
|
80
|
+
`attachment.anchor`, or when role/category/kind names it with the small vocabulary above.
|
|
81
|
+
The second path exists so ANCHOR_DECLARED has something to fire on: a component authored
|
|
82
|
+
as `role: "worn"` with no anchor at all must still be caught, not silently ignored because
|
|
83
|
+
it never reached the "has an anchor" branch."""
|
|
84
|
+
attachment = component.get("attachment")
|
|
85
|
+
if isinstance(attachment, dict) and isinstance(attachment.get("anchor"), str) and attachment["anchor"].strip():
|
|
86
|
+
return True
|
|
87
|
+
for field in ("role", "category", "kind"):
|
|
88
|
+
value = component.get(field)
|
|
89
|
+
if isinstance(value, str) and value.strip().lower() in ANCHOR_ATTACHMENT_TOKENS:
|
|
90
|
+
return True
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _anchor_id(component: dict[str, Any]) -> str | None:
|
|
95
|
+
attachment = component.get("attachment")
|
|
96
|
+
if isinstance(attachment, dict):
|
|
97
|
+
anchor = attachment.get("anchor")
|
|
98
|
+
if isinstance(anchor, str) and anchor.strip():
|
|
99
|
+
return anchor
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _find_cycle(start: str, anchor_of: dict[str, str]) -> list[str] | None:
|
|
104
|
+
"""Walk the anchor-of-anchor chain from `start`. Returns the cyclic segment (in order,
|
|
105
|
+
NOT including the repeated closing node) the first time a node repeats, or None if the
|
|
106
|
+
chain runs off the edge of the attachment graph (into a bone, a plain component, or a
|
|
107
|
+
dangling id -- none of which are keys in `anchor_of`, so the `while` below simply stops)."""
|
|
108
|
+
path: list[str] = []
|
|
109
|
+
current = start
|
|
110
|
+
while current in anchor_of:
|
|
111
|
+
if current in path:
|
|
112
|
+
return path[path.index(current):]
|
|
113
|
+
path.append(current)
|
|
114
|
+
current = anchor_of[current]
|
|
115
|
+
return None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _anchor_extent(anchor_component: dict[str, Any] | None) -> float | None:
|
|
119
|
+
"""Largest declared extent on the anchor's `dimensions` block, or None if it has none.
|
|
120
|
+
`radius` is doubled to a diameter so it is comparable to width/height/depth/length."""
|
|
121
|
+
if not isinstance(anchor_component, dict):
|
|
122
|
+
return None
|
|
123
|
+
dimensions = anchor_component.get("dimensions")
|
|
124
|
+
if not isinstance(dimensions, dict):
|
|
125
|
+
return None
|
|
126
|
+
values = [float(dimensions[f]) for f in _EXTENT_FIELDS if _is_number(dimensions.get(f))]
|
|
127
|
+
if _is_number(dimensions.get("radius")):
|
|
128
|
+
values.append(float(dimensions["radius"]) * 2.0)
|
|
129
|
+
return max(values) if values else None
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _max_offset_for(component: dict[str, Any], anchor_component: dict[str, Any] | None) -> tuple[float, str]:
|
|
133
|
+
"""Return (limit, rule) so a proximity failure can say WHICH rule produced the number
|
|
134
|
+
instead of a bare threshold. Priority: declared `maxOffset` > anchor-size default >
|
|
135
|
+
constant fallback."""
|
|
136
|
+
attachment = component.get("attachment") if isinstance(component.get("attachment"), dict) else {}
|
|
137
|
+
declared = attachment.get("maxOffset")
|
|
138
|
+
if _is_number(declared):
|
|
139
|
+
return float(declared), "declared attachment.maxOffset"
|
|
140
|
+
extent = _anchor_extent(anchor_component)
|
|
141
|
+
if extent is not None:
|
|
142
|
+
limit = extent * ANCHOR_PROXIMITY_SIZE_FRACTION
|
|
143
|
+
return limit, (
|
|
144
|
+
f"default: {ANCHOR_PROXIMITY_SIZE_FRACTION:.0%} of anchor's largest declared extent "
|
|
145
|
+
f"({extent:.4f})"
|
|
146
|
+
)
|
|
147
|
+
return DEFAULT_MAX_OFFSET, f"default: constant fallback ({DEFAULT_MAX_OFFSET}); anchor declares no extents"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def analyze_attachments(spec: dict[str, Any], *, measured: dict[str, list[float]] | None = None) -> dict[str, Any]:
|
|
151
|
+
"""Run the attachment-anchor gate over `spec`'s component tree, optionally cross-checked
|
|
152
|
+
against `measured` (world positions keyed by component or bone id, e.g. from a runtime
|
|
153
|
+
parts manifest). See module docstring for the five checks.
|
|
154
|
+
|
|
155
|
+
Returns a dict with `errors`, `warnings`, per-attachment `attachments` records (component,
|
|
156
|
+
anchor, anchorKind, distance, maxOffset, offsetRule, withinLimit -- the last four are None
|
|
157
|
+
until a measured position resolves them), `unmeasuredAttachments`, `attachmentCount`, and
|
|
158
|
+
`passed` (True iff `errors` is empty).
|
|
159
|
+
"""
|
|
160
|
+
errors: list[str] = []
|
|
161
|
+
warnings: list[str] = []
|
|
162
|
+
|
|
163
|
+
components = [
|
|
164
|
+
c for c in (spec.get("componentTree") or []) if isinstance(c, dict) and isinstance(c.get("id"), str)
|
|
165
|
+
]
|
|
166
|
+
by_id = {c["id"]: c for c in components}
|
|
167
|
+
rig = spec.get("rig")
|
|
168
|
+
bones = (
|
|
169
|
+
[b for b in (rig.get("bones") or []) if isinstance(b, dict) and isinstance(b.get("id"), str)]
|
|
170
|
+
if isinstance(rig, dict) else []
|
|
171
|
+
)
|
|
172
|
+
bones_by_id = {b["id"]: b for b in bones}
|
|
173
|
+
|
|
174
|
+
# Root identity, both trees. A malformed multi-root component tree is
|
|
175
|
+
# validate_sculpt_spec.py's problem (NAME_UNIQUENESS), not this gate's -- we only need
|
|
176
|
+
# SOME root id to test ANCHOR_NOT_ROOT against, so ambiguity does not stop the gate.
|
|
177
|
+
tree_roots = [c["id"] for c in components if not c.get("parent")]
|
|
178
|
+
tree_root_id = tree_roots[0] if tree_roots else None
|
|
179
|
+
rig_roots = [b["id"] for b in bones if not b.get("parent")]
|
|
180
|
+
rig_root_id = rig_roots[0] if rig_roots else None
|
|
181
|
+
|
|
182
|
+
attachment_components = [c for c in components if _is_attachment_component(c)]
|
|
183
|
+
anchor_of: dict[str, str] = {}
|
|
184
|
+
records: list[dict[str, Any]] = []
|
|
185
|
+
|
|
186
|
+
for component in attachment_components:
|
|
187
|
+
cid = component["id"]
|
|
188
|
+
anchor = _anchor_id(component)
|
|
189
|
+
record: dict[str, Any] = {
|
|
190
|
+
"component": cid,
|
|
191
|
+
"anchor": anchor,
|
|
192
|
+
"anchorKind": None,
|
|
193
|
+
"distance": None,
|
|
194
|
+
"maxOffset": None,
|
|
195
|
+
"offsetRule": None,
|
|
196
|
+
"withinLimit": None,
|
|
197
|
+
}
|
|
198
|
+
if anchor is None:
|
|
199
|
+
errors.append(
|
|
200
|
+
f"ANCHOR_DECLARED: attachment {cid!r} is worn/held/hung but declares no attachment.anchor"
|
|
201
|
+
)
|
|
202
|
+
records.append(record)
|
|
203
|
+
continue
|
|
204
|
+
|
|
205
|
+
anchor_of[cid] = anchor
|
|
206
|
+
if anchor in by_id:
|
|
207
|
+
record["anchorKind"] = "component"
|
|
208
|
+
elif anchor in bones_by_id:
|
|
209
|
+
record["anchorKind"] = "bone"
|
|
210
|
+
else:
|
|
211
|
+
errors.append(
|
|
212
|
+
f"ANCHOR_RESOLVES: attachment {cid!r} anchors to {anchor!r}, which matches no "
|
|
213
|
+
f"existing component" + (" or bone" if isinstance(rig, dict) else "") + " in this spec"
|
|
214
|
+
)
|
|
215
|
+
records.append(record)
|
|
216
|
+
continue
|
|
217
|
+
|
|
218
|
+
is_root = (
|
|
219
|
+
(record["anchorKind"] == "component" and anchor == tree_root_id)
|
|
220
|
+
or (record["anchorKind"] == "bone" and anchor == rig_root_id)
|
|
221
|
+
)
|
|
222
|
+
if is_root:
|
|
223
|
+
errors.append(
|
|
224
|
+
f"ANCHOR_NOT_ROOT: attachment {cid!r} anchors directly to the model ROOT ({anchor!r}) "
|
|
225
|
+
f"-- parenting a worn/held item to root leaves its transform unrelated to the body "
|
|
226
|
+
f"part it belongs to; this is the exact defect behind both the misplaced hat and "
|
|
227
|
+
f"the detached charm"
|
|
228
|
+
)
|
|
229
|
+
records.append(record)
|
|
230
|
+
|
|
231
|
+
# ---- ANCHOR_NOT_CYCLIC -- self-anchor is the length-1 case of this same walk. ----
|
|
232
|
+
reported_cycles: set[frozenset[str]] = set()
|
|
233
|
+
for start in anchor_of:
|
|
234
|
+
cycle = _find_cycle(start, anchor_of)
|
|
235
|
+
if not cycle:
|
|
236
|
+
continue
|
|
237
|
+
key = frozenset(cycle)
|
|
238
|
+
if key in reported_cycles:
|
|
239
|
+
continue
|
|
240
|
+
reported_cycles.add(key)
|
|
241
|
+
if len(cycle) == 1:
|
|
242
|
+
errors.append(f"ANCHOR_NOT_CYCLIC: attachment {cycle[0]!r} anchors to itself")
|
|
243
|
+
else:
|
|
244
|
+
chain = " -> ".join([*cycle, cycle[0]])
|
|
245
|
+
errors.append(f"ANCHOR_NOT_CYCLIC: attachment anchor cycle detected: {chain}")
|
|
246
|
+
|
|
247
|
+
# ---- ANCHOR_PROXIMITY -- only when the caller supplies measured world positions. ----
|
|
248
|
+
unmeasured: list[str] = []
|
|
249
|
+
if measured is not None:
|
|
250
|
+
for record in records:
|
|
251
|
+
if record["anchorKind"] is None:
|
|
252
|
+
continue # ANCHOR_DECLARED/ANCHOR_RESOLVES already failed; no anchor to measure against
|
|
253
|
+
cid = record["component"]
|
|
254
|
+
anchor = record["anchor"]
|
|
255
|
+
item_pos = measured.get(cid)
|
|
256
|
+
anchor_pos = measured.get(anchor)
|
|
257
|
+
if not _is_xyz(item_pos) or not _is_xyz(anchor_pos):
|
|
258
|
+
# Never silently skip: a component the caller forgot to measure is reported,
|
|
259
|
+
# not swept into "0 violations" the way both real defects went unnoticed.
|
|
260
|
+
unmeasured.append(cid)
|
|
261
|
+
warnings.append(
|
|
262
|
+
f"ANCHOR_PROXIMITY: attachment {cid!r} has no measured world position (or its "
|
|
263
|
+
f"anchor {anchor!r} has none); proximity was not verified"
|
|
264
|
+
)
|
|
265
|
+
continue
|
|
266
|
+
anchor_component = by_id.get(anchor) if record["anchorKind"] == "component" else None
|
|
267
|
+
max_offset, rule = _max_offset_for(by_id[cid], anchor_component)
|
|
268
|
+
distance = _distance(item_pos, anchor_pos)
|
|
269
|
+
record["distance"] = distance
|
|
270
|
+
record["maxOffset"] = max_offset
|
|
271
|
+
record["offsetRule"] = rule
|
|
272
|
+
record["withinLimit"] = distance <= max_offset
|
|
273
|
+
if distance > max_offset:
|
|
274
|
+
errors.append(
|
|
275
|
+
f"ANCHOR_PROXIMITY: attachment {cid!r} measures {distance:.4f} from anchor "
|
|
276
|
+
f"{anchor!r}, exceeding maxOffset {max_offset:.4f} ({rule})"
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
"errors": errors,
|
|
281
|
+
"warnings": warnings,
|
|
282
|
+
"attachments": records,
|
|
283
|
+
"unmeasuredAttachments": unmeasured,
|
|
284
|
+
"attachmentCount": len(attachment_components),
|
|
285
|
+
"passed": not errors,
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _load_json(path: Path) -> dict[str, Any]:
|
|
290
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _parse_measured(raw: str) -> dict[str, list[float]]:
|
|
294
|
+
"""`--measured` accepts either inline JSON text or a path to a JSON file: a handful of
|
|
295
|
+
positions is convenient to type inline, but a real runtime parts manifest is a file."""
|
|
296
|
+
candidate = Path(raw)
|
|
297
|
+
text = candidate.read_text(encoding="utf-8") if candidate.is_file() else raw
|
|
298
|
+
data = json.loads(text)
|
|
299
|
+
if not isinstance(data, dict):
|
|
300
|
+
raise ValueError("--measured must decode to a JSON object of id -> [x, y, z]")
|
|
301
|
+
return data
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _format_summary(result: dict[str, Any]) -> str:
|
|
305
|
+
lines = [f"attachments: {result['attachmentCount']}"]
|
|
306
|
+
for record in result["attachments"]:
|
|
307
|
+
bits = [f"component={record['component']!r}", f"anchor={record['anchor']!r}"]
|
|
308
|
+
if record["distance"] is not None:
|
|
309
|
+
bits.append(f"distance={record['distance']:.4f}")
|
|
310
|
+
bits.append(f"maxOffset={record['maxOffset']:.4f}")
|
|
311
|
+
bits.append(f"rule={record['offsetRule']}")
|
|
312
|
+
bits.append("within-limit" if record["withinLimit"] else "OVER-LIMIT")
|
|
313
|
+
lines.append(" " + " ".join(bits))
|
|
314
|
+
if result["unmeasuredAttachments"]:
|
|
315
|
+
lines.append(f"unmeasured: {', '.join(result['unmeasuredAttachments'])}")
|
|
316
|
+
for message in result["errors"]:
|
|
317
|
+
lines.append(f"ERROR: {message}")
|
|
318
|
+
for message in result["warnings"]:
|
|
319
|
+
lines.append(f"WARNING: {message}")
|
|
320
|
+
lines.append("verdict: " + ("PASS" if result["passed"] else "FAIL"))
|
|
321
|
+
return "\n".join(lines)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def main(argv: list[str]) -> int:
|
|
325
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
326
|
+
parser.add_argument("spec", type=Path, help="sculpt-spec JSON path")
|
|
327
|
+
parser.add_argument(
|
|
328
|
+
"--measured",
|
|
329
|
+
help="JSON object (inline text or a file path) of id -> [x, y, z] world positions",
|
|
330
|
+
)
|
|
331
|
+
parser.add_argument("--json", action="store_true", help="print JSON instead of a summary")
|
|
332
|
+
args = parser.parse_args(argv)
|
|
333
|
+
|
|
334
|
+
try:
|
|
335
|
+
spec = _load_json(args.spec)
|
|
336
|
+
measured = _parse_measured(args.measured) if args.measured is not None else None
|
|
337
|
+
result = analyze_attachments(spec, measured=measured)
|
|
338
|
+
if args.json:
|
|
339
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
340
|
+
else:
|
|
341
|
+
print(_format_summary(result))
|
|
342
|
+
return 0 if result["passed"] else 1
|
|
343
|
+
except Exception as exc:
|
|
344
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
345
|
+
return 2
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
if __name__ == "__main__":
|
|
349
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Divine Eye calibration harness (Plan 1.3 §5) — fit/validate the Eye on a labeled corpus.
|
|
3
|
+
|
|
4
|
+
Before the Eye is allowed to HARD-GATE anything, it runs in report-only mode over a
|
|
5
|
+
corpus of labeled (reference, render) pairs — known-good (the render should pass) and
|
|
6
|
+
known-bad (it must be rejected). This harness runs divine_eye.evaluate on each pair,
|
|
7
|
+
tabulates every signal per label class, and checks that the fidelity score cleanly
|
|
8
|
+
SEPARATES good from bad. A corpus needs BOTH classes or it only measures false-rejects.
|
|
9
|
+
|
|
10
|
+
Acceptance (absolute, on the corpus): every known-good pair passes AND every known-bad
|
|
11
|
+
pair is rejected. Only then may report-only be flipped to hard-gate. Percentage targets
|
|
12
|
+
(Q1/Q4/Q5) apply to a rolling window of ≥20 real builds, not this small corpus.
|
|
13
|
+
|
|
14
|
+
Note: producing real RENDERS of the showcase demos needs a browser (deferred to the
|
|
15
|
+
end-to-end infra). This harness is the deterministic, render-agnostic scaffold: give it
|
|
16
|
+
whatever (reference, render) PNG pairs exist and it reports the separation + suggests a
|
|
17
|
+
threshold. Pure stdlib + reuses divine_eye. Zero token.
|
|
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))
|
|
29
|
+
from divine_eye import evaluate # noqa: E402
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def run_corpus(pairs: list[dict]) -> dict[str, Any]:
|
|
33
|
+
"""pairs: [{"reference": path, "render": path, "label": "good"|"bad"}, ...].
|
|
34
|
+
Runs the Eye on each and aggregates per-signal stats per label class."""
|
|
35
|
+
rows: list[dict[str, Any]] = []
|
|
36
|
+
for pair in pairs:
|
|
37
|
+
result = evaluate(Path(pair["reference"]), Path(pair["render"]))
|
|
38
|
+
rows.append({
|
|
39
|
+
"label": pair.get("label", "unlabeled"),
|
|
40
|
+
"fidelity": result["fidelity"],
|
|
41
|
+
"verdict": result["verdict"],
|
|
42
|
+
"hardGateFailures": result["hardGateFailures"],
|
|
43
|
+
"signals": result["signals"],
|
|
44
|
+
"reference": pair["reference"],
|
|
45
|
+
"render": pair["render"],
|
|
46
|
+
})
|
|
47
|
+
return {"rows": rows, "signalStats": _signal_stats(rows)}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _signal_stats(rows: list[dict]) -> dict[str, Any]:
|
|
51
|
+
stats: dict[str, Any] = {}
|
|
52
|
+
for label in ("good", "bad"):
|
|
53
|
+
labelled = [r for r in rows if r["label"] == label]
|
|
54
|
+
if not labelled:
|
|
55
|
+
continue
|
|
56
|
+
fids = [r["fidelity"] for r in labelled]
|
|
57
|
+
stats[label] = {
|
|
58
|
+
"count": len(labelled),
|
|
59
|
+
"fidelityMin": round(min(fids), 4),
|
|
60
|
+
"fidelityMax": round(max(fids), 4),
|
|
61
|
+
"fidelityMean": round(sum(fids) / len(fids), 4),
|
|
62
|
+
}
|
|
63
|
+
return stats
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def separation(rows: list[dict]) -> dict[str, Any]:
|
|
67
|
+
"""Does fidelity cleanly separate good from bad? A clean split exists when the
|
|
68
|
+
worst good fidelity is strictly above the best bad fidelity; the suggested
|
|
69
|
+
threshold sits between them."""
|
|
70
|
+
good = [r["fidelity"] for r in rows if r["label"] == "good"]
|
|
71
|
+
bad = [r["fidelity"] for r in rows if r["label"] == "bad"]
|
|
72
|
+
result: dict[str, Any] = {
|
|
73
|
+
"hasGood": bool(good),
|
|
74
|
+
"hasBad": bool(bad),
|
|
75
|
+
"minGoodFidelity": round(min(good), 4) if good else None,
|
|
76
|
+
"maxBadFidelity": round(max(bad), 4) if bad else None,
|
|
77
|
+
}
|
|
78
|
+
if good and bad:
|
|
79
|
+
min_good, max_bad = min(good), max(bad)
|
|
80
|
+
clean = min_good > max_bad
|
|
81
|
+
result["cleanSeparation"] = clean
|
|
82
|
+
result["suggestedThreshold"] = round((min_good + max_bad) / 2, 4) if clean else None
|
|
83
|
+
# absolute acceptance: every good passes at the current target, every bad rejected
|
|
84
|
+
result["allGoodPass"] = all(
|
|
85
|
+
r["verdict"] == "pass" for r in rows if r["label"] == "good"
|
|
86
|
+
)
|
|
87
|
+
result["allBadRejected"] = all(
|
|
88
|
+
r["verdict"] != "pass" for r in rows if r["label"] == "bad"
|
|
89
|
+
)
|
|
90
|
+
result["corpusAcceptable"] = result["allGoodPass"] and result["allBadRejected"]
|
|
91
|
+
else:
|
|
92
|
+
result["cleanSeparation"] = None
|
|
93
|
+
result["corpusAcceptable"] = False
|
|
94
|
+
result["warning"] = "corpus needs BOTH good and bad pairs (else it only measures false-rejects)"
|
|
95
|
+
return result
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def calibrate(pairs: list[dict]) -> dict[str, Any]:
|
|
99
|
+
corpus = run_corpus(pairs)
|
|
100
|
+
corpus["separation"] = separation(corpus["rows"])
|
|
101
|
+
corpus["reportOnly"] = True
|
|
102
|
+
corpus["note"] = ("report-only — flip to hard-gate ONLY when corpusAcceptable is true "
|
|
103
|
+
"(all good pass, all bad rejected)")
|
|
104
|
+
return corpus
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def main(argv: list[str]) -> int:
|
|
108
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
109
|
+
parser.add_argument("--corpus", required=True, type=Path,
|
|
110
|
+
help="JSON list of {reference, render, label} pairs")
|
|
111
|
+
parser.add_argument("--json", action="store_true")
|
|
112
|
+
args = parser.parse_args(argv)
|
|
113
|
+
try:
|
|
114
|
+
pairs = json.loads(args.corpus.read_text(encoding="utf-8"))
|
|
115
|
+
result = calibrate(pairs)
|
|
116
|
+
except Exception as exc: # noqa: BLE001
|
|
117
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
118
|
+
return 2
|
|
119
|
+
if args.json:
|
|
120
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
121
|
+
else:
|
|
122
|
+
sep = result["separation"]
|
|
123
|
+
print(f"corpus: {result['signalStats']}")
|
|
124
|
+
print(f"separation: clean={sep.get('cleanSeparation')} acceptable={sep.get('corpusAcceptable')} "
|
|
125
|
+
f"suggestedThreshold={sep.get('suggestedThreshold')}")
|
|
126
|
+
# exit 0 only when the corpus cleanly validates the Eye
|
|
127
|
+
return 0 if result["separation"].get("corpusAcceptable") else 1
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
if __name__ == "__main__":
|
|
131
|
+
raise SystemExit(main(sys.argv[1:]))
|