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,302 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Signed distance to a skull built as a stack of ellipse rings.
|
|
3
|
+
|
|
4
|
+
WHY THIS EXISTS. Hair was being held off the skull by a comment. The low-poly humanoid demo carries
|
|
5
|
+
this invariant in prose:
|
|
6
|
+
|
|
7
|
+
EVERY piece must stand proud of the skull at its own height. Where the skull is proud of the
|
|
8
|
+
hair, the head renders bald there.
|
|
9
|
+
|
|
10
|
+
The garment in the same file is held off the body by a MEASUREMENT instead -- `sectionedLoft`'s `hug`
|
|
11
|
+
marches every vertex outward along its own spoke until a signed distance field reads at least
|
|
12
|
+
`clearance`. Its docstring records why authoring the numbers by hand does not work:
|
|
13
|
+
|
|
14
|
+
Five rounds of widening these sections by hand still left the body poking through 0.09 H of the
|
|
15
|
+
front ... Any single ellipse that clears the widest point is loose at the narrowest and vice
|
|
16
|
+
versa, so the error moves rather than shrinks.
|
|
17
|
+
|
|
18
|
+
That is exactly what happened when the hair side-masses were widened by hand: closure went 42.2% to
|
|
19
|
+
40.9%, worse on all six views, and dark coverage went DOWN because the widened mass slid off the
|
|
20
|
+
skull instead of growing on it. The error moved rather than shrank. This module is the field the
|
|
21
|
+
hair never had.
|
|
22
|
+
|
|
23
|
+
The skull is already a ring stack in every character spec -- the humanoid's head is eight rows of
|
|
24
|
+
`[y, radiusX, radiusZ]` plus a per-row z offset -- so the field is derived, never authored twice.
|
|
25
|
+
|
|
26
|
+
SIGN IS EXACT, MAGNITUDE IS AN ESTIMATE. Inside/outside comes from the sign of the ellipse function,
|
|
27
|
+
which is exact. The distance magnitude uses the first-order estimate `f / |grad f|`, which is the
|
|
28
|
+
standard Newton step for an ellipse and is not the true Euclidean distance. Every gate built on this
|
|
29
|
+
must therefore treat the sign as authoritative and the magnitude as approximate.
|
|
30
|
+
|
|
31
|
+
Pure Python 3.10+ standard library. No numpy, no PIL.
|
|
32
|
+
"""
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
import math
|
|
36
|
+
from typing import Any, Iterable, Sequence
|
|
37
|
+
|
|
38
|
+
Ring = tuple[float, float, float, float]
|
|
39
|
+
"""One ring: (y, radiusX, radiusZ, zCentre)."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _finite(value: object, label: str) -> float:
|
|
43
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
44
|
+
raise ValueError(f"{label} must be a number, got {value!r}")
|
|
45
|
+
number = float(value)
|
|
46
|
+
if not math.isfinite(number):
|
|
47
|
+
raise ValueError(f"{label} must be finite, got {number!r}")
|
|
48
|
+
return number
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def normalise_rings(rings: Iterable[Sequence[float] | dict[str, float]]) -> list[Ring]:
|
|
52
|
+
"""Accept the shapes a spec actually carries and return sorted, validated rings.
|
|
53
|
+
|
|
54
|
+
A ring may arrive as `(y, rx, rz)`, `(y, rx, rz, zc)`, or a mapping with those keys. The demo's
|
|
55
|
+
head table is the three-tuple form with the z offsets held in a parallel array, so both are real.
|
|
56
|
+
"""
|
|
57
|
+
out: list[Ring] = []
|
|
58
|
+
for index, ring in enumerate(rings):
|
|
59
|
+
label = f"ring[{index}]"
|
|
60
|
+
if isinstance(ring, dict):
|
|
61
|
+
y = _finite(ring.get("y"), f"{label}.y")
|
|
62
|
+
rx = _finite(ring.get("rx", ring.get("radiusX")), f"{label}.rx")
|
|
63
|
+
rz = _finite(ring.get("rz", ring.get("radiusZ")), f"{label}.rz")
|
|
64
|
+
zc = _finite(ring.get("zc", ring.get("zCentre", 0.0)), f"{label}.zc")
|
|
65
|
+
else:
|
|
66
|
+
values = list(ring)
|
|
67
|
+
if len(values) not in (3, 4):
|
|
68
|
+
raise ValueError(f"{label} must have 3 or 4 values, got {len(values)}")
|
|
69
|
+
y = _finite(values[0], f"{label}.y")
|
|
70
|
+
rx = _finite(values[1], f"{label}.rx")
|
|
71
|
+
rz = _finite(values[2], f"{label}.rz")
|
|
72
|
+
zc = _finite(values[3], f"{label}.zc") if len(values) == 4 else 0.0
|
|
73
|
+
if rx <= 0.0 or rz <= 0.0:
|
|
74
|
+
raise ValueError(f"{label} radii must be positive, got rx={rx} rz={rz}")
|
|
75
|
+
out.append((y, rx, rz, zc))
|
|
76
|
+
|
|
77
|
+
if len(out) < 2:
|
|
78
|
+
raise ValueError("a scalp field needs at least 2 rings")
|
|
79
|
+
out.sort(key=lambda r: r[0])
|
|
80
|
+
for lower, upper in zip(out, out[1:]):
|
|
81
|
+
if upper[0] - lower[0] <= 1e-9:
|
|
82
|
+
raise ValueError(f"rings must have distinct y values, found two at y={lower[0]}")
|
|
83
|
+
return out
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class ScalpField:
|
|
87
|
+
"""The skull as a lofted ellipse stack, queryable as a signed distance field.
|
|
88
|
+
|
|
89
|
+
Negative inside, positive outside, zero on the surface.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
def __init__(self, rings: Iterable[Sequence[float] | dict[str, float]]) -> None:
|
|
93
|
+
self.rings: list[Ring] = normalise_rings(rings)
|
|
94
|
+
self.y_min: float = self.rings[0][0]
|
|
95
|
+
self.y_max: float = self.rings[-1][0]
|
|
96
|
+
|
|
97
|
+
# ---- interpolation -------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
def section(self, y: float) -> tuple[float, float, float]:
|
|
100
|
+
"""Interpolated (rx, rz, zCentre) at height `y`, clamped to the stack's own extent."""
|
|
101
|
+
if y <= self.y_min:
|
|
102
|
+
_, rx, rz, zc = self.rings[0]
|
|
103
|
+
return rx, rz, zc
|
|
104
|
+
if y >= self.y_max:
|
|
105
|
+
_, rx, rz, zc = self.rings[-1]
|
|
106
|
+
return rx, rz, zc
|
|
107
|
+
for lower, upper in zip(self.rings, self.rings[1:]):
|
|
108
|
+
if lower[0] <= y <= upper[0]:
|
|
109
|
+
span = upper[0] - lower[0]
|
|
110
|
+
t = (y - lower[0]) / span
|
|
111
|
+
return (
|
|
112
|
+
lower[1] + (upper[1] - lower[1]) * t,
|
|
113
|
+
lower[2] + (upper[2] - lower[2]) * t,
|
|
114
|
+
lower[3] + (upper[3] - lower[3]) * t,
|
|
115
|
+
)
|
|
116
|
+
# Unreachable given the clamps above, but a silent wrong answer here would be a bald patch.
|
|
117
|
+
raise AssertionError(f"no ring interval contains y={y}")
|
|
118
|
+
|
|
119
|
+
# ---- the field -----------------------------------------------------------------------
|
|
120
|
+
|
|
121
|
+
def radial_distance(self, x: float, y: float, z: float) -> float:
|
|
122
|
+
"""Signed distance to the ellipse at this height, ignoring the caps.
|
|
123
|
+
|
|
124
|
+
The sign is exact. The magnitude is the first-order estimate `f / |grad f|`.
|
|
125
|
+
"""
|
|
126
|
+
rx, rz, zc = self.section(y)
|
|
127
|
+
dx = x / rx
|
|
128
|
+
dz = (z - zc) / rz
|
|
129
|
+
f = dx * dx + dz * dz - 1.0
|
|
130
|
+
# grad f = (2x/rx^2, 2z'/rz^2). At the axis the gradient vanishes and the estimate blows up;
|
|
131
|
+
# the point is then as deep inside as the section is wide, which is the honest answer.
|
|
132
|
+
gx = 2.0 * x / (rx * rx)
|
|
133
|
+
gz = 2.0 * (z - zc) / (rz * rz)
|
|
134
|
+
grad = math.hypot(gx, gz)
|
|
135
|
+
if grad < 1e-12:
|
|
136
|
+
return -min(rx, rz)
|
|
137
|
+
return f / grad
|
|
138
|
+
|
|
139
|
+
def distance(self, x: float, y: float, z: float) -> float:
|
|
140
|
+
"""Signed distance to the capped ring stack. Negative inside.
|
|
141
|
+
|
|
142
|
+
This is the canonical capped-extrusion composition: outside contributions combine by
|
|
143
|
+
Pythagoras, inside contributions take the least-negative (nearest) surface.
|
|
144
|
+
"""
|
|
145
|
+
radial = self.radial_distance(x, y, z)
|
|
146
|
+
axial = max(self.y_min - y, y - self.y_max)
|
|
147
|
+
outside = math.hypot(max(radial, 0.0), max(axial, 0.0))
|
|
148
|
+
inside = min(max(radial, axial), 0.0)
|
|
149
|
+
return outside + inside
|
|
150
|
+
|
|
151
|
+
# ---- the surface ---------------------------------------------------------------------
|
|
152
|
+
|
|
153
|
+
def sample(self, u: float, v: float) -> tuple[float, float, float]:
|
|
154
|
+
"""A point on the skull. `u` is azimuth in [0,1), `v` is height in [0,1] bottom to top.
|
|
155
|
+
|
|
156
|
+
This is the parametrisation hair roots bind to. A root held as (u,v) cannot slide off the
|
|
157
|
+
skull when its mass is widened, which is the whole reason the binding exists -- the failure
|
|
158
|
+
it prevents is a measured one, not a hypothetical.
|
|
159
|
+
"""
|
|
160
|
+
theta = 2.0 * math.pi * u
|
|
161
|
+
y = self.y_min + (self.y_max - self.y_min) * v
|
|
162
|
+
rx, rz, zc = self.section(y)
|
|
163
|
+
return (rx * math.cos(theta), y, zc + rz * math.sin(theta))
|
|
164
|
+
|
|
165
|
+
def normal(self, u: float, v: float) -> tuple[float, float, float]:
|
|
166
|
+
"""Outward unit normal at `sample(u, v)`.
|
|
167
|
+
|
|
168
|
+
Taken as the cross product of the surface's own partial derivatives rather than as the
|
|
169
|
+
horizontal radial direction: the skull's radius changes with height, so near the crown the
|
|
170
|
+
true normal tilts upward substantially and a radial approximation would push hair sideways
|
|
171
|
+
off the top of the head.
|
|
172
|
+
"""
|
|
173
|
+
theta = 2.0 * math.pi * u
|
|
174
|
+
cos_t = math.cos(theta)
|
|
175
|
+
sin_t = math.sin(theta)
|
|
176
|
+
height = self.y_max - self.y_min
|
|
177
|
+
y = self.y_min + height * v
|
|
178
|
+
rx, rz, _ = self.section(y)
|
|
179
|
+
|
|
180
|
+
# d/dv of the section, by central difference -- the stack is piecewise linear, so the
|
|
181
|
+
# derivative is undefined exactly at a ring and a central difference is the sane reading.
|
|
182
|
+
step = max(height * 1e-4, 1e-9)
|
|
183
|
+
rx_hi, rz_hi, zc_hi = self.section(min(y + step, self.y_max))
|
|
184
|
+
rx_lo, rz_lo, zc_lo = self.section(max(y - step, self.y_min))
|
|
185
|
+
actual = min(y + step, self.y_max) - max(y - step, self.y_min)
|
|
186
|
+
if actual <= 0.0:
|
|
187
|
+
d_rx = d_rz = d_zc = 0.0
|
|
188
|
+
else:
|
|
189
|
+
d_rx = (rx_hi - rx_lo) / actual
|
|
190
|
+
d_rz = (rz_hi - rz_lo) / actual
|
|
191
|
+
d_zc = (zc_hi - zc_lo) / actual
|
|
192
|
+
|
|
193
|
+
# dS/du and dS/dv, with y parametrised by v so dy/dv = height.
|
|
194
|
+
du = (-rx * sin_t, 0.0, rz * cos_t)
|
|
195
|
+
dv = (d_rx * cos_t * height, height, (d_zc + d_rz * sin_t) * height)
|
|
196
|
+
|
|
197
|
+
# dv x du points outward; verified against a cylinder, where it reduces to (cos, 0, sin).
|
|
198
|
+
nx = dv[1] * du[2] - dv[2] * du[1]
|
|
199
|
+
ny = dv[2] * du[0] - dv[0] * du[2]
|
|
200
|
+
nz = dv[0] * du[1] - dv[1] * du[0]
|
|
201
|
+
length = math.sqrt(nx * nx + ny * ny + nz * nz)
|
|
202
|
+
if length < 1e-12:
|
|
203
|
+
return (cos_t, 0.0, sin_t)
|
|
204
|
+
return (nx / length, ny / length, nz / length)
|
|
205
|
+
|
|
206
|
+
# ---- convenience ---------------------------------------------------------------------
|
|
207
|
+
|
|
208
|
+
def surface_samples(
|
|
209
|
+
self,
|
|
210
|
+
u_count: int,
|
|
211
|
+
v_count: int,
|
|
212
|
+
v_range: tuple[float, float] = (0.0, 1.0),
|
|
213
|
+
) -> list[dict[str, Any]]:
|
|
214
|
+
"""Area-weighted samples over the surface, for gates that integrate over the scalp.
|
|
215
|
+
|
|
216
|
+
Each entry is `{weight, point, normal, u, v, cap}`. The weight is the local patch area, so a
|
|
217
|
+
gate reporting an exposed FRACTION reports area and not sample count -- rings near the crown
|
|
218
|
+
are far shorter in circumference than rings at the temples, and counting samples would let a
|
|
219
|
+
small bare crown hide behind a large well-covered band.
|
|
220
|
+
|
|
221
|
+
THE CAP IS INCLUDED, and that is the part worth stating. The (u, v) parametrisation walks v
|
|
222
|
+
from the bottom ring to the top and samples the ELLIPSE at each height, so the flat disc
|
|
223
|
+
closing the stack at `y_max` belongs to no (u, v) and was invisible to a caller that only
|
|
224
|
+
iterated the band. On a skull whose top ring still has real radius that disc IS the crown,
|
|
225
|
+
and a completely bare crown measured as fully covered.
|
|
226
|
+
"""
|
|
227
|
+
if u_count < 3 or v_count < 2:
|
|
228
|
+
raise ValueError("need at least 3 azimuth and 2 height samples")
|
|
229
|
+
low, high = v_range
|
|
230
|
+
if not 0.0 <= low < high <= 1.0:
|
|
231
|
+
raise ValueError(f"v_range must be an ascending band inside [0,1], got {v_range}")
|
|
232
|
+
|
|
233
|
+
out: list[dict[str, Any]] = []
|
|
234
|
+
height = self.y_max - self.y_min
|
|
235
|
+
band = high - low
|
|
236
|
+
for j in range(v_count):
|
|
237
|
+
v = low + band * (j + 0.5) / v_count
|
|
238
|
+
y = self.y_min + height * v
|
|
239
|
+
rx, rz, _ = self.section(y)
|
|
240
|
+
# Ramanujan's first approximation to the ellipse perimeter; the exact value needs an
|
|
241
|
+
# elliptic integral and the weights only need to be right relative to each other.
|
|
242
|
+
circumference = math.pi * (3.0 * (rx + rz) - math.sqrt((3.0 * rx + rz) * (rx + 3.0 * rz)))
|
|
243
|
+
weight = (circumference / u_count) * (height * band / v_count)
|
|
244
|
+
for i in range(u_count):
|
|
245
|
+
u = i / u_count
|
|
246
|
+
out.append({"weight": weight, "point": self.sample(u, v),
|
|
247
|
+
"normal": self.normal(u, v), "u": u, "v": v, "cap": False})
|
|
248
|
+
|
|
249
|
+
if high >= 1.0 - 1e-9:
|
|
250
|
+
top_rx, top_rz, top_zc = self.section(self.y_max)
|
|
251
|
+
cap_rings = max(1, v_count // 4)
|
|
252
|
+
for ring_index in range(cap_rings):
|
|
253
|
+
# Mid-radius of an annulus, so a sample stands for the area around it, not a line.
|
|
254
|
+
middle = (ring_index + 0.5) / cap_rings
|
|
255
|
+
outer = (ring_index + 1) / cap_rings
|
|
256
|
+
inner = ring_index / cap_rings
|
|
257
|
+
annulus = math.pi * top_rx * top_rz * (outer * outer - inner * inner)
|
|
258
|
+
weight = annulus / u_count
|
|
259
|
+
for i in range(u_count):
|
|
260
|
+
u = i / u_count
|
|
261
|
+
angle = 2.0 * math.pi * u
|
|
262
|
+
point = (top_rx * middle * math.cos(angle), self.y_max,
|
|
263
|
+
top_zc + top_rz * middle * math.sin(angle))
|
|
264
|
+
# `capRing` distinguishes the annuli. They all share v = 1.0 by construction,
|
|
265
|
+
# and a consumer that buckets rows by v alone collapses the whole disc into one
|
|
266
|
+
# row -- `largest_exposed_run` then reports a full-circle run the moment any
|
|
267
|
+
# single annulus is bare.
|
|
268
|
+
out.append({"weight": weight, "point": point, "normal": (0.0, 1.0, 0.0),
|
|
269
|
+
"u": u, "v": 1.0, "cap": True, "capRing": ring_index})
|
|
270
|
+
return out
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def field_from_component(component: dict) -> ScalpField:
|
|
274
|
+
"""Build the field from a spec component that carries a ring stack.
|
|
275
|
+
|
|
276
|
+
Accepts the two shapes the pipeline produces: `geometryDescriptor.ringStack.rings`, and the
|
|
277
|
+
parallel-array form `{rings: [[y, rx, rz], ...], zOffsets: [...]}` that the humanoid head uses.
|
|
278
|
+
"""
|
|
279
|
+
descriptor = component.get("geometryDescriptor") if isinstance(component, dict) else None
|
|
280
|
+
if not isinstance(descriptor, dict):
|
|
281
|
+
raise ValueError("component has no geometryDescriptor")
|
|
282
|
+
stack = descriptor.get("ringStack")
|
|
283
|
+
if not isinstance(stack, dict):
|
|
284
|
+
raise ValueError("component.geometryDescriptor has no ringStack")
|
|
285
|
+
rings = stack.get("rings")
|
|
286
|
+
if not isinstance(rings, list) or not rings:
|
|
287
|
+
raise ValueError("ringStack.rings must be a non-empty array")
|
|
288
|
+
|
|
289
|
+
offsets = stack.get("zOffsets")
|
|
290
|
+
if isinstance(offsets, list) and offsets:
|
|
291
|
+
if len(offsets) != len(rings):
|
|
292
|
+
raise ValueError(
|
|
293
|
+
f"ringStack.zOffsets has {len(offsets)} entries for {len(rings)} rings"
|
|
294
|
+
)
|
|
295
|
+
merged: list[Sequence[float]] = []
|
|
296
|
+
for ring, offset in zip(rings, offsets):
|
|
297
|
+
values = list(ring)
|
|
298
|
+
if len(values) < 3:
|
|
299
|
+
raise ValueError("each ring needs at least [y, rx, rz]")
|
|
300
|
+
merged.append([values[0], values[1], values[2], offset])
|
|
301
|
+
return ScalpField(merged)
|
|
302
|
+
return ScalpField(rings)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""Validation for opt-in implicit signed-distance-field descriptors."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
VALID_SDF_PRIMITIVES = {"sphere", "capsule", "box", "cone", "ellipsoid"}
|
|
10
|
+
VALID_SDF_OPERATIONS = {"smooth-union", "subtract", "intersect"}
|
|
11
|
+
MAX_SDF_PRIMITIVES = 64
|
|
12
|
+
MAX_SDF_OPERATIONS = 128
|
|
13
|
+
_PRIMITIVE_FIELDS = {"id", "type", "center", "radius", "height", "size", "dimensions", "radii", "transform"}
|
|
14
|
+
_VECTOR_FIELDS = {"center", "size", "radii"}
|
|
15
|
+
_TRANSFORM_FIELDS = {"position", "translation", "rotation", "scale"}
|
|
16
|
+
_OPERATION_FIELDS = {"id", "output", "type", "left", "right", "radius"}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _is_number(value: Any) -> bool:
|
|
20
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _validate_finite(value: Any, label: str, errors: list[str]) -> None:
|
|
24
|
+
if _is_number(value):
|
|
25
|
+
if not math.isfinite(float(value)):
|
|
26
|
+
errors.append(f"{label} must be finite")
|
|
27
|
+
return
|
|
28
|
+
if isinstance(value, list):
|
|
29
|
+
for index, item in enumerate(value):
|
|
30
|
+
_validate_finite(item, f"{label}[{index}]", errors)
|
|
31
|
+
elif isinstance(value, dict):
|
|
32
|
+
for key, item in value.items():
|
|
33
|
+
_validate_finite(item, f"{label}.{key}", errors)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _validate_vector(value: Any, label: str, errors: list[str], positive: bool = False) -> None:
|
|
37
|
+
if not isinstance(value, list) or len(value) != 3:
|
|
38
|
+
errors.append(f"{label} must be [number, number, number]")
|
|
39
|
+
return
|
|
40
|
+
for index, item in enumerate(value):
|
|
41
|
+
if not _is_number(item):
|
|
42
|
+
errors.append(f"{label}[{index}] must be numeric")
|
|
43
|
+
elif positive and float(item) <= 0:
|
|
44
|
+
errors.append(f"{label}[{index}] must be greater than 0")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _validate_positive(value: Any, label: str, errors: list[str], allow_zero: bool = False) -> None:
|
|
48
|
+
if not _is_number(value):
|
|
49
|
+
errors.append(f"{label} must be numeric")
|
|
50
|
+
elif float(value) < 0 or (not allow_zero and float(value) == 0):
|
|
51
|
+
errors.append(f"{label} must be greater than {0 if allow_zero else 0}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _validate_primitive(primitive: Any, index: int, ids: set[str], errors: list[str]) -> None:
|
|
55
|
+
label = f"geometryDescriptor.sdf.primitives[{index}]"
|
|
56
|
+
if not isinstance(primitive, dict):
|
|
57
|
+
errors.append(f"{label} must be an object")
|
|
58
|
+
return
|
|
59
|
+
primitive_id = primitive.get("id")
|
|
60
|
+
if not isinstance(primitive_id, str) or not primitive_id.strip():
|
|
61
|
+
errors.append(f"{label}.id is required")
|
|
62
|
+
elif primitive_id in ids:
|
|
63
|
+
errors.append(f"{label}.id duplicates {primitive_id!r}")
|
|
64
|
+
else:
|
|
65
|
+
ids.add(primitive_id)
|
|
66
|
+
primitive_type = primitive.get("type")
|
|
67
|
+
if primitive_type not in VALID_SDF_PRIMITIVES:
|
|
68
|
+
errors.append(f"{label}.type must be one of: {', '.join(sorted(VALID_SDF_PRIMITIVES))}")
|
|
69
|
+
for field in primitive:
|
|
70
|
+
if field not in _PRIMITIVE_FIELDS:
|
|
71
|
+
errors.append(f"{label}.{field} is not supported")
|
|
72
|
+
for field in _VECTOR_FIELDS & set(primitive):
|
|
73
|
+
_validate_vector(primitive[field], f"{label}.{field}", errors, positive=field in {"size", "radii"})
|
|
74
|
+
transform = primitive.get("transform")
|
|
75
|
+
if transform is not None:
|
|
76
|
+
if not isinstance(transform, dict):
|
|
77
|
+
errors.append(f"{label}.transform must be an object")
|
|
78
|
+
else:
|
|
79
|
+
for field in transform:
|
|
80
|
+
if field not in _TRANSFORM_FIELDS:
|
|
81
|
+
errors.append(f"{label}.transform.{field} is not supported")
|
|
82
|
+
for field in _TRANSFORM_FIELDS & set(transform):
|
|
83
|
+
_validate_vector(
|
|
84
|
+
transform[field], f"{label}.transform.{field}", errors, positive=field == "scale"
|
|
85
|
+
)
|
|
86
|
+
if primitive_type in {"sphere", "capsule", "cone"}:
|
|
87
|
+
_validate_positive(primitive.get("radius"), f"{label}.radius", errors)
|
|
88
|
+
if primitive_type == "capsule":
|
|
89
|
+
_validate_positive(primitive.get("height"), f"{label}.height", errors, allow_zero=True)
|
|
90
|
+
if primitive_type == "cone":
|
|
91
|
+
_validate_positive(primitive.get("height"), f"{label}.height", errors)
|
|
92
|
+
if primitive_type == "box" and "size" not in primitive:
|
|
93
|
+
_validate_vector(primitive.get("dimensions"), f"{label}.dimensions", errors, positive=True)
|
|
94
|
+
if primitive_type == "ellipsoid" and "radii" not in primitive:
|
|
95
|
+
_validate_vector(primitive.get("radius"), f"{label}.radius", errors, positive=True)
|
|
96
|
+
_validate_finite(primitive, label, errors)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _validate_operation(operation: Any, index: int, known_ids: set[str], errors: list[str]) -> None:
|
|
100
|
+
label = f"geometryDescriptor.sdf.operations[{index}]"
|
|
101
|
+
if not isinstance(operation, dict):
|
|
102
|
+
errors.append(f"{label} must be an object")
|
|
103
|
+
return
|
|
104
|
+
for field in operation:
|
|
105
|
+
if field not in _OPERATION_FIELDS:
|
|
106
|
+
errors.append(f"{label}.{field} is not supported")
|
|
107
|
+
operation_type = operation.get("type")
|
|
108
|
+
if operation_type not in VALID_SDF_OPERATIONS:
|
|
109
|
+
errors.append(f"{label}.type must be one of: {', '.join(sorted(VALID_SDF_OPERATIONS))}")
|
|
110
|
+
for side in ("left", "right"):
|
|
111
|
+
value = operation.get(side)
|
|
112
|
+
if not isinstance(value, str) or not value.strip():
|
|
113
|
+
errors.append(f"{label}.{side} must reference a primitive or previous operation")
|
|
114
|
+
elif value not in known_ids:
|
|
115
|
+
errors.append(f"{label}.{side} references unknown SDF id {value!r}")
|
|
116
|
+
if operation_type == "smooth-union":
|
|
117
|
+
_validate_positive(operation.get("radius"), f"{label}.radius", errors)
|
|
118
|
+
if "id" in operation and "output" in operation:
|
|
119
|
+
errors.append(f"{label}.id and output cannot both be set")
|
|
120
|
+
output = operation.get("id", operation.get("output", f"operation-{index}"))
|
|
121
|
+
if not isinstance(output, str) or not output.strip():
|
|
122
|
+
errors.append(f"{label}.id/output must be a non-empty string when present")
|
|
123
|
+
elif output in known_ids:
|
|
124
|
+
field = "id" if "id" in operation else "output"
|
|
125
|
+
errors.append(f"{label}.{field} duplicates existing SDF id {output!r}")
|
|
126
|
+
else:
|
|
127
|
+
known_ids.add(output)
|
|
128
|
+
_validate_finite(operation, label, errors)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def validate_sdf_descriptor(component_id: str, descriptor: Any, errors: list[str]) -> None:
|
|
132
|
+
"""Append schema errors for an opt-in component SDF descriptor."""
|
|
133
|
+
label = f"component {component_id!r} geometryDescriptor.sdf"
|
|
134
|
+
if not isinstance(descriptor, dict):
|
|
135
|
+
errors.append(f"{label} must be an object")
|
|
136
|
+
return
|
|
137
|
+
primitives = descriptor.get("primitives")
|
|
138
|
+
if not isinstance(primitives, list) or not primitives:
|
|
139
|
+
errors.append(f"{label}.primitives must be a non-empty array")
|
|
140
|
+
return
|
|
141
|
+
if len(primitives) > MAX_SDF_PRIMITIVES:
|
|
142
|
+
errors.append(f"{label}.primitives must not contain more than {MAX_SDF_PRIMITIVES} entries")
|
|
143
|
+
ids: set[str] = set()
|
|
144
|
+
for index, primitive in enumerate(primitives):
|
|
145
|
+
_validate_primitive(primitive, index, ids, errors)
|
|
146
|
+
operations = descriptor.get("operations", [])
|
|
147
|
+
if not isinstance(operations, list):
|
|
148
|
+
errors.append(f"{label}.operations must be an array")
|
|
149
|
+
else:
|
|
150
|
+
if len(operations) > MAX_SDF_OPERATIONS:
|
|
151
|
+
errors.append(f"{label}.operations must not contain more than {MAX_SDF_OPERATIONS} entries")
|
|
152
|
+
for index, operation in enumerate(operations):
|
|
153
|
+
_validate_operation(operation, index, ids, errors)
|
|
154
|
+
resolution = descriptor.get("resolution")
|
|
155
|
+
if not isinstance(resolution, int) or isinstance(resolution, bool) or resolution < 4:
|
|
156
|
+
errors.append(f"{label}.resolution must be an integer from 4 to 64")
|
|
157
|
+
elif resolution > 64:
|
|
158
|
+
errors.append(f"{label}.resolution must not exceed 64")
|
|
159
|
+
bounds = descriptor.get("bounds")
|
|
160
|
+
if bounds is not None:
|
|
161
|
+
if not isinstance(bounds, dict):
|
|
162
|
+
errors.append(f"{label}.bounds must be an object")
|
|
163
|
+
else:
|
|
164
|
+
minimum = bounds.get("min")
|
|
165
|
+
maximum = bounds.get("max")
|
|
166
|
+
_validate_vector(minimum, f"{label}.bounds.min", errors)
|
|
167
|
+
_validate_vector(maximum, f"{label}.bounds.max", errors)
|
|
168
|
+
if isinstance(minimum, list) and isinstance(maximum, list) and len(minimum) == len(maximum) == 3:
|
|
169
|
+
for index, (minimum_value, maximum_value) in enumerate(zip(minimum, maximum)):
|
|
170
|
+
if _is_number(minimum_value) and _is_number(maximum_value) and minimum_value >= maximum_value:
|
|
171
|
+
errors.append(f"{label}.bounds.min[{index}] must be less than bounds.max[{index}]")
|
|
172
|
+
_validate_finite(descriptor, label, errors)
|