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,257 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Find bald patches before anything is rendered.
|
|
3
|
+
|
|
4
|
+
WHY THIS GATE EXISTS. Three review signals already look at hair and none of them can see this
|
|
5
|
+
failure:
|
|
6
|
+
|
|
7
|
+
silhouette_iou blind by construction -- only about 11% of a figure's cells lie on the
|
|
8
|
+
outline, and a bald crown is interior
|
|
9
|
+
interior_difference sees it, but only AFTER a browser capture, and only as a number that could
|
|
10
|
+
equally mean a colour shift
|
|
11
|
+
the human eye sees it instantly, and was the only thing that caught it the last three times
|
|
12
|
+
|
|
13
|
+
The failure is specific and repeatable. Widening the hair side masses by hand took closure from
|
|
14
|
+
42.2% to 40.9%, worse on all six views, and dark coverage went DOWN. The widened mass had slid off
|
|
15
|
+
the skull: the loft's spine is straight while the skull is convex, so thickening the section moved
|
|
16
|
+
the surface sideways rather than outward, the skull ended up proud of the hair, and the render grew
|
|
17
|
+
a bare strip. The invariant it broke was already written down in the demo:
|
|
18
|
+
|
|
19
|
+
EVERY piece must stand proud of the skull at its own height. Where the skull is proud of the
|
|
20
|
+
hair, the head renders bald there.
|
|
21
|
+
|
|
22
|
+
This gate is that sentence as arithmetic. It runs on points, so it works on any hair
|
|
23
|
+
representation -- shell, masses or locks -- and it needs no browser, no GPU and no capture.
|
|
24
|
+
|
|
25
|
+
HAIR INSIDE THE SKULL IS NOT COVERAGE. That is the whole point. A naive "is there a hair vertex near
|
|
26
|
+
this patch of scalp" test would have passed the widened build, because the vertices were still
|
|
27
|
+
nearby -- they had merely sunk below the surface. Only points on the outside of the skull count.
|
|
28
|
+
|
|
29
|
+
Pure Python 3.10+ standard library.
|
|
30
|
+
"""
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import argparse
|
|
34
|
+
import json
|
|
35
|
+
import math
|
|
36
|
+
import sys
|
|
37
|
+
from pathlib import Path
|
|
38
|
+
from typing import Any, Iterable, Sequence
|
|
39
|
+
|
|
40
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "_shared"))
|
|
41
|
+
|
|
42
|
+
from scalp_field import ScalpField # noqa: E402
|
|
43
|
+
|
|
44
|
+
Point = tuple[float, float, float]
|
|
45
|
+
|
|
46
|
+
# A patch of scalp counts as covered when hair sits within this far along its outward normal,
|
|
47
|
+
# measured as a fraction of the skull's own height. Hair further out than this is a separate mass
|
|
48
|
+
# floating clear of the head rather than the layer that covers it.
|
|
49
|
+
DEFAULT_REACH_FRACTION = 0.22
|
|
50
|
+
# ... and within this far off that normal, laterally, again as a fraction of skull height. This is
|
|
51
|
+
# the sampling radius, not a physical property: it must be a little wider than the gap between
|
|
52
|
+
# adjacent scalp samples or the test reports stripes of exposure between the samples themselves.
|
|
53
|
+
DEFAULT_LATERAL_FRACTION = 0.075
|
|
54
|
+
# Azimuth and height sampling of the scalp. 32x16 is 512 patches over a head, which resolves a strip
|
|
55
|
+
# roughly a finger wide -- finer than the failure being caught and coarse enough to stay instant.
|
|
56
|
+
DEFAULT_U_SAMPLES = 32
|
|
57
|
+
DEFAULT_V_SAMPLES = 16
|
|
58
|
+
# Anything above this fraction of scalp area uncovered is a hard failure rather than a soft signal.
|
|
59
|
+
# Not calibrated against a reference: no multipart hair reference exists yet, so this is a
|
|
60
|
+
# deliberately loose bound chosen to catch the recorded failure and flagged as uncalibrated in the
|
|
61
|
+
# report rather than presented as a measurement.
|
|
62
|
+
DEFAULT_HARD_MAX = 0.05
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class _PointGrid:
|
|
66
|
+
"""Uniform bucket grid, so the gate stays linear in hair points rather than quadratic."""
|
|
67
|
+
|
|
68
|
+
def __init__(self, points: Sequence[Point], cell: float) -> None:
|
|
69
|
+
self.cell = max(cell, 1e-6)
|
|
70
|
+
self.buckets: dict[tuple[int, int, int], list[Point]] = {}
|
|
71
|
+
for point in points:
|
|
72
|
+
self.buckets.setdefault(self._key(point), []).append(point)
|
|
73
|
+
|
|
74
|
+
def _key(self, point: Point) -> tuple[int, int, int]:
|
|
75
|
+
return (
|
|
76
|
+
int(math.floor(point[0] / self.cell)),
|
|
77
|
+
int(math.floor(point[1] / self.cell)),
|
|
78
|
+
int(math.floor(point[2] / self.cell)),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
def near(self, point: Point) -> Iterable[Point]:
|
|
82
|
+
cx, cy, cz = self._key(point)
|
|
83
|
+
for dx in (-1, 0, 1):
|
|
84
|
+
for dy in (-1, 0, 1):
|
|
85
|
+
for dz in (-1, 0, 1):
|
|
86
|
+
bucket = self.buckets.get((cx + dx, cy + dy, cz + dz))
|
|
87
|
+
if bucket:
|
|
88
|
+
yield from bucket
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def scalp_exposure(
|
|
92
|
+
field: ScalpField,
|
|
93
|
+
hair_points: Sequence[Point],
|
|
94
|
+
*,
|
|
95
|
+
reach: float | None = None,
|
|
96
|
+
lateral: float | None = None,
|
|
97
|
+
u_samples: int = DEFAULT_U_SAMPLES,
|
|
98
|
+
v_samples: int = DEFAULT_V_SAMPLES,
|
|
99
|
+
hard_max: float = DEFAULT_HARD_MAX,
|
|
100
|
+
v_range: tuple[float, float] = (0.0, 1.0),
|
|
101
|
+
) -> dict[str, Any]:
|
|
102
|
+
"""What fraction of the scalp has no hair standing over it.
|
|
103
|
+
|
|
104
|
+
`v_range` restricts the test to a band of the skull. The face is scalp by geometry and not by
|
|
105
|
+
anatomy, so a full-head sweep would report the forehead, nose and chin as bald and drown the
|
|
106
|
+
signal; callers pass the band above the hairline.
|
|
107
|
+
|
|
108
|
+
The returned fraction is AREA-weighted, not sample-weighted: rings near the crown are far
|
|
109
|
+
shorter in circumference than rings at the temples, and counting samples would let a small bare
|
|
110
|
+
crown hide behind a large well-covered band.
|
|
111
|
+
"""
|
|
112
|
+
height = field.y_max - field.y_min
|
|
113
|
+
if height <= 0.0:
|
|
114
|
+
raise ValueError("the scalp field has no height")
|
|
115
|
+
reach_distance = reach if reach is not None else DEFAULT_REACH_FRACTION * height
|
|
116
|
+
lateral_distance = lateral if lateral is not None else DEFAULT_LATERAL_FRACTION * height
|
|
117
|
+
if reach_distance <= 0.0 or lateral_distance <= 0.0:
|
|
118
|
+
raise ValueError("reach and lateral must both be positive")
|
|
119
|
+
low, high = v_range
|
|
120
|
+
if not 0.0 <= low < high <= 1.0:
|
|
121
|
+
raise ValueError(f"v_range must be an ascending band inside [0,1], got {v_range}")
|
|
122
|
+
|
|
123
|
+
# Only hair OUTSIDE the skull can cover it. This single filter is the difference between a gate
|
|
124
|
+
# that catches the recorded failure and one that waves it through.
|
|
125
|
+
outside = [p for p in hair_points if field.distance(*p) > 0.0]
|
|
126
|
+
sunk = len(hair_points) - len(outside)
|
|
127
|
+
grid = _PointGrid(outside, lateral_distance)
|
|
128
|
+
|
|
129
|
+
march_steps = max(2, int(math.ceil(reach_distance / lateral_distance)) + 1)
|
|
130
|
+
|
|
131
|
+
total_area = 0.0
|
|
132
|
+
exposed_area = 0.0
|
|
133
|
+
exposed: list[dict[str, float]] = []
|
|
134
|
+
walked = 0
|
|
135
|
+
|
|
136
|
+
# The band and the cap disc used to be two near-identical loops here. They are one now, because
|
|
137
|
+
# `ScalpField.surface_samples` already knows how to walk both -- and the duplicate was worse
|
|
138
|
+
# than untidy: the cap loop was added later to close a defect, and having a second copy of the
|
|
139
|
+
# march is precisely how the two would drift apart the next time one of them is fixed.
|
|
140
|
+
for sample in field.surface_samples(u_samples, v_samples, v_range=(low, high)):
|
|
141
|
+
px, py, pz = sample["point"]
|
|
142
|
+
nx, ny, nz = sample["normal"]
|
|
143
|
+
weight = sample["weight"]
|
|
144
|
+
total_area += weight
|
|
145
|
+
walked += 1
|
|
146
|
+
|
|
147
|
+
covered = False
|
|
148
|
+
for step in range(march_steps + 1):
|
|
149
|
+
t = reach_distance * step / march_steps
|
|
150
|
+
qx, qy, qz = px + nx * t, py + ny * t, pz + nz * t
|
|
151
|
+
for hx, hy, hz in grid.near((qx, qy, qz)):
|
|
152
|
+
if (hx - qx) ** 2 + (hy - qy) ** 2 + (hz - qz) ** 2 <= lateral_distance ** 2:
|
|
153
|
+
covered = True
|
|
154
|
+
break
|
|
155
|
+
if covered:
|
|
156
|
+
break
|
|
157
|
+
|
|
158
|
+
if not covered:
|
|
159
|
+
exposed_area += weight
|
|
160
|
+
entry = {"u": round(sample["u"], 4), "v": round(sample["v"], 4),
|
|
161
|
+
"x": round(px, 5), "y": round(py, 5), "z": round(pz, 5)}
|
|
162
|
+
if sample["cap"]:
|
|
163
|
+
entry["cap"] = True
|
|
164
|
+
entry["capRing"] = sample["capRing"]
|
|
165
|
+
exposed.append(entry)
|
|
166
|
+
|
|
167
|
+
fraction = exposed_area / total_area if total_area > 0.0 else 0.0
|
|
168
|
+
return {
|
|
169
|
+
"schemaVersion": 1,
|
|
170
|
+
"kind": "scalp-exposure",
|
|
171
|
+
"exposedFraction": round(fraction, 6),
|
|
172
|
+
"exposedSamples": exposed,
|
|
173
|
+
# What was actually walked, not u*v: the cap disc adds its own annuli, so the product
|
|
174
|
+
# under-reported by 128 of 640 and a caller sizing anything off it would be wrong.
|
|
175
|
+
"sampleCount": walked,
|
|
176
|
+
"hairPointCount": len(hair_points),
|
|
177
|
+
"hairPointsInsideSkull": sunk,
|
|
178
|
+
"reach": round(reach_distance, 6),
|
|
179
|
+
"lateral": round(lateral_distance, 6),
|
|
180
|
+
"vRange": [low, high],
|
|
181
|
+
"hardMax": hard_max,
|
|
182
|
+
"hardMaxUncalibrated": True,
|
|
183
|
+
"verdict": "fail" if fraction > hard_max else "pass",
|
|
184
|
+
"note": (
|
|
185
|
+
"Area-weighted fraction of scalp with no hair standing outside the skull above it. "
|
|
186
|
+
"Hair points inside the skull are excluded from coverage by design: the recorded "
|
|
187
|
+
"failure was a mass that slid off the skull while staying nearby."
|
|
188
|
+
),
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def largest_exposed_run(result: dict[str, Any], u_samples: int = DEFAULT_U_SAMPLES) -> int:
|
|
193
|
+
"""Longest unbroken azimuth run of exposed samples at any one height.
|
|
194
|
+
|
|
195
|
+
A scatter of isolated exposed samples is sampling noise. A RUN is a strip, and a strip is what
|
|
196
|
+
a viewer reads as a parting or a bald line -- the recorded failure showed exactly that, a bare
|
|
197
|
+
band down the centre of the crown.
|
|
198
|
+
"""
|
|
199
|
+
# Keyed by (v, capRing), not by v. Every cap annulus reports v = 1.0, so keying on v alone
|
|
200
|
+
# merged the whole disc into a single row and let one bare annulus read as a full-circle run.
|
|
201
|
+
by_row: dict[tuple[float, int], set[int]] = {}
|
|
202
|
+
for sample in result.get("exposedSamples", []):
|
|
203
|
+
column = int(round(sample["u"] * u_samples)) % u_samples
|
|
204
|
+
by_row.setdefault((sample["v"], sample.get("capRing", -1)), set()).add(column)
|
|
205
|
+
|
|
206
|
+
longest = 0
|
|
207
|
+
for columns in by_row.values():
|
|
208
|
+
# A fully exposed ring has NO first column -- every column's predecessor is also exposed --
|
|
209
|
+
# so the run-start scan below finds no start and falls through reporting zero. That is the
|
|
210
|
+
# worst case reporting as the best, on a head with no hair on it at all.
|
|
211
|
+
if len(columns) >= u_samples:
|
|
212
|
+
return u_samples
|
|
213
|
+
for start in columns:
|
|
214
|
+
if (start - 1) % u_samples in columns:
|
|
215
|
+
continue # not the beginning of a run
|
|
216
|
+
run = 1
|
|
217
|
+
while (start + run) % u_samples in columns and run < u_samples:
|
|
218
|
+
run += 1
|
|
219
|
+
longest = max(longest, run)
|
|
220
|
+
return longest
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _load_points(path: Path) -> list[Point]:
|
|
224
|
+
payload = json.loads(path.read_text())
|
|
225
|
+
raw = payload.get("points", payload) if isinstance(payload, dict) else payload
|
|
226
|
+
if not isinstance(raw, list):
|
|
227
|
+
raise ValueError("expected a JSON array of [x,y,z] points, or {\"points\": [...]}")
|
|
228
|
+
return [(float(p[0]), float(p[1]), float(p[2])) for p in raw]
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
232
|
+
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
|
233
|
+
parser.add_argument("--rings", required=True, help="JSON file: [[y,rx,rz,(zc)], ...]")
|
|
234
|
+
parser.add_argument("--hair-points", required=True, help="JSON file: [[x,y,z], ...]")
|
|
235
|
+
parser.add_argument("--v-low", type=float, default=0.0)
|
|
236
|
+
parser.add_argument("--v-high", type=float, default=1.0)
|
|
237
|
+
parser.add_argument("--hard-max", type=float, default=DEFAULT_HARD_MAX)
|
|
238
|
+
parser.add_argument("--out", help="also write the report here")
|
|
239
|
+
args = parser.parse_args(argv)
|
|
240
|
+
|
|
241
|
+
field = ScalpField(json.loads(Path(args.rings).read_text()))
|
|
242
|
+
report = scalp_exposure(
|
|
243
|
+
field,
|
|
244
|
+
_load_points(Path(args.hair_points)),
|
|
245
|
+
hard_max=args.hard_max,
|
|
246
|
+
v_range=(args.v_low, args.v_high),
|
|
247
|
+
)
|
|
248
|
+
report["largestExposedRun"] = largest_exposed_run(report)
|
|
249
|
+
text = json.dumps(report, indent=2)
|
|
250
|
+
if args.out:
|
|
251
|
+
Path(args.out).write_text(text + "\n")
|
|
252
|
+
print(text)
|
|
253
|
+
return 0 if report["verdict"] == "pass" else 1
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
if __name__ == "__main__":
|
|
257
|
+
raise SystemExit(main())
|