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.
Files changed (175) hide show
  1. package/assets/rebuild-object/.cache/spec-search/core_3d.json +1 -0
  2. package/assets/rebuild-object/.cache/spec-search/cs2.json +1 -0
  3. package/assets/rebuild-object/LICENSE +201 -0
  4. package/assets/rebuild-object/NOTICE +7 -0
  5. package/assets/rebuild-object/docs/materials/material-reference.json +2324 -0
  6. package/assets/rebuild-object/docs/specs/render-profile.v2.example.json +63 -0
  7. package/assets/rebuild-object/docs/specs/render-profile.v2.schema.json +56 -0
  8. package/assets/rebuild-object/docs/specs/vocabulary/README.md +86 -0
  9. package/assets/rebuild-object/docs/specs/vocabulary/core_3d.jsonl +12 -0
  10. package/assets/rebuild-object/docs/specs/vocabulary/core_3d_reconstruction.jsonl +37 -0
  11. package/assets/rebuild-object/docs/specs/vocabulary/cs2.jsonl +8 -0
  12. package/assets/rebuild-object/docs/specs/vocabulary/cs2_reconstruction.jsonl +62 -0
  13. package/assets/rebuild-object/forge/_shared/artifact_cache.py +54 -0
  14. package/assets/rebuild-object/forge/_shared/chirality.py +272 -0
  15. package/assets/rebuild-object/forge/_shared/color_metrics.py +107 -0
  16. package/assets/rebuild-object/forge/_shared/feature_acceptance_policy.py +113 -0
  17. package/assets/rebuild-object/forge/_shared/image_hash.py +113 -0
  18. package/assets/rebuild-object/forge/_shared/jpeg.py +448 -0
  19. package/assets/rebuild-object/forge/_shared/material_physics.py +253 -0
  20. package/assets/rebuild-object/forge/_shared/pipeline_routing.py +177 -0
  21. package/assets/rebuild-object/forge/_shared/scalp_field.py +302 -0
  22. package/assets/rebuild-object/forge/_shared/sdf_primitives.py +172 -0
  23. package/assets/rebuild-object/forge/_shared/spec_search.py +1792 -0
  24. package/assets/rebuild-object/forge/_shared/spec_search_profiles.json +58 -0
  25. package/assets/rebuild-object/forge/_shared/status_banner.py +35 -0
  26. package/assets/rebuild-object/forge/_shared/subdivision.py +232 -0
  27. package/assets/rebuild-object/forge/_shared/vertex_paint.py +236 -0
  28. package/assets/rebuild-object/forge/_shared/workflow_state.py +406 -0
  29. package/assets/rebuild-object/forge/materials/__init__.py +17 -0
  30. package/assets/rebuild-object/forge/materials/compatibility.py +106 -0
  31. package/assets/rebuild-object/forge/materials/reference.py +240 -0
  32. package/assets/rebuild-object/forge/next.py +116 -0
  33. package/assets/rebuild-object/forge/report.py +38 -0
  34. package/assets/rebuild-object/forge/requirements.txt +6 -0
  35. package/assets/rebuild-object/forge/stage1_intake/analyze_texture.py +255 -0
  36. package/assets/rebuild-object/forge/stage1_intake/bind_detail_properties.py +99 -0
  37. package/assets/rebuild-object/forge/stage1_intake/build_detail_inventory.py +349 -0
  38. package/assets/rebuild-object/forge/stage1_intake/camera_fitting_math.py +133 -0
  39. package/assets/rebuild-object/forge/stage1_intake/camera_fitting_solver.py +197 -0
  40. package/assets/rebuild-object/forge/stage1_intake/camera_fitting_types.py +291 -0
  41. package/assets/rebuild-object/forge/stage1_intake/camera_image_helpers.py +133 -0
  42. package/assets/rebuild-object/forge/stage1_intake/check_intake_correctness.py +116 -0
  43. package/assets/rebuild-object/forge/stage1_intake/check_reference_admission.py +203 -0
  44. package/assets/rebuild-object/forge/stage1_intake/cs2_foundation.py +139 -0
  45. package/assets/rebuild-object/forge/stage1_intake/cs2_manifest.py +230 -0
  46. package/assets/rebuild-object/forge/stage1_intake/cs2_review_contract.py +42 -0
  47. package/assets/rebuild-object/forge/stage1_intake/delight_albedo.py +352 -0
  48. package/assets/rebuild-object/forge/stage1_intake/detect_cs2.py +276 -0
  49. package/assets/rebuild-object/forge/stage1_intake/detect_reference_effects.py +275 -0
  50. package/assets/rebuild-object/forge/stage1_intake/extract_cs2_textures.py +126 -0
  51. package/assets/rebuild-object/forge/stage1_intake/extract_gradient_stops.py +149 -0
  52. package/assets/rebuild-object/forge/stage1_intake/extract_hair_evidence.py +385 -0
  53. package/assets/rebuild-object/forge/stage1_intake/extract_landmarks.py +456 -0
  54. package/assets/rebuild-object/forge/stage1_intake/extract_part_color_recipe.py +496 -0
  55. package/assets/rebuild-object/forge/stage1_intake/extract_pbr_evidence.py +843 -0
  56. package/assets/rebuild-object/forge/stage1_intake/fetch_cs2_metadata.py +147 -0
  57. package/assets/rebuild-object/forge/stage1_intake/label_glb_nodes.py +318 -0
  58. package/assets/rebuild-object/forge/stage1_intake/locate_cs2_vpk.py +73 -0
  59. package/assets/rebuild-object/forge/stage1_intake/material_region_analysis.py +227 -0
  60. package/assets/rebuild-object/forge/stage1_intake/probe_glb.py +357 -0
  61. package/assets/rebuild-object/forge/stage1_intake/probe_image.py +168 -0
  62. package/assets/rebuild-object/forge/stage1_intake/run_vision_adapter.py +45 -0
  63. package/assets/rebuild-object/forge/stage1_intake/search_specs.py +258 -0
  64. package/assets/rebuild-object/forge/stage1_intake/semantic_decomposition.py +119 -0
  65. package/assets/rebuild-object/forge/stage1_intake/solve_camera_pose.py +254 -0
  66. package/assets/rebuild-object/forge/stage2_spec/apply_material_analysis.py +192 -0
  67. package/assets/rebuild-object/forge/stage2_spec/cs2_adapters.py +62 -0
  68. package/assets/rebuild-object/forge/stage2_spec/derive_geometry.py +118 -0
  69. package/assets/rebuild-object/forge/stage2_spec/hair_profile.py +306 -0
  70. package/assets/rebuild-object/forge/stage2_spec/humanoid_proportions.py +214 -0
  71. package/assets/rebuild-object/forge/stage2_spec/new_pre_spec_assessment.py +343 -0
  72. package/assets/rebuild-object/forge/stage2_spec/new_sculpt_spec.py +2396 -0
  73. package/assets/rebuild-object/forge/stage2_spec/validate_sculpt_spec.py +2871 -0
  74. package/assets/rebuild-object/forge/stage3_build/bake_projected_texture.py +181 -0
  75. package/assets/rebuild-object/forge/stage3_build/decimate.py +272 -0
  76. package/assets/rebuild-object/forge/stage3_build/generate_threejs_factory.py +4099 -0
  77. package/assets/rebuild-object/forge/stage3_build/module_cache.py +155 -0
  78. package/assets/rebuild-object/forge/stage3_build/morph_targets.py +178 -0
  79. package/assets/rebuild-object/forge/stage3_build/orchestrate_passes.py +653 -0
  80. package/assets/rebuild-object/forge/stage3_build/uv_unwrap.py +622 -0
  81. package/assets/rebuild-object/forge/stage3_build/visual_hull.py +357 -0
  82. package/assets/rebuild-object/forge/stage4_review/_fit_divine_eye.py +64 -0
  83. package/assets/rebuild-object/forge/stage4_review/append_review.py +453 -0
  84. package/assets/rebuild-object/forge/stage4_review/attachment_anchor.py +349 -0
  85. package/assets/rebuild-object/forge/stage4_review/calibrate_eye.py +131 -0
  86. package/assets/rebuild-object/forge/stage4_review/check_part_coverage.py +298 -0
  87. package/assets/rebuild-object/forge/stage4_review/compare_region_passes.py +169 -0
  88. package/assets/rebuild-object/forge/stage4_review/correction_loop.py +258 -0
  89. package/assets/rebuild-object/forge/stage4_review/cs2_review.py +224 -0
  90. package/assets/rebuild-object/forge/stage4_review/diagnose_render.py +356 -0
  91. package/assets/rebuild-object/forge/stage4_review/diagnose_render_multi_angle.py +143 -0
  92. package/assets/rebuild-object/forge/stage4_review/divine_eye.py +461 -0
  93. package/assets/rebuild-object/forge/stage4_review/fit_params.py +381 -0
  94. package/assets/rebuild-object/forge/stage4_review/geometry_integrity.py +294 -0
  95. package/assets/rebuild-object/forge/stage4_review/hair_gate.py +216 -0
  96. package/assets/rebuild-object/forge/stage4_review/interior_difference.py +188 -0
  97. package/assets/rebuild-object/forge/stage4_review/joint_loops.py +209 -0
  98. package/assets/rebuild-object/forge/stage4_review/make_comparison_sheet.py +292 -0
  99. package/assets/rebuild-object/forge/stage4_review/material_comparator.py +181 -0
  100. package/assets/rebuild-object/forge/stage4_review/material_feedback.py +143 -0
  101. package/assets/rebuild-object/forge/stage4_review/material_gate.py +126 -0
  102. package/assets/rebuild-object/forge/stage4_review/material_views.py +184 -0
  103. package/assets/rebuild-object/forge/stage4_review/mesh_reference_compare.py +362 -0
  104. package/assets/rebuild-object/forge/stage4_review/multi_pass.py +102 -0
  105. package/assets/rebuild-object/forge/stage4_review/objectness.py +143 -0
  106. package/assets/rebuild-object/forge/stage4_review/pairwise_penetration.py +376 -0
  107. package/assets/rebuild-object/forge/stage4_review/per_feature.py +215 -0
  108. package/assets/rebuild-object/forge/stage4_review/render_bridge.py +556 -0
  109. package/assets/rebuild-object/forge/stage4_review/scalp_exposure.py +257 -0
  110. package/assets/rebuild-object/forge/stage4_review/self_intersection.py +592 -0
  111. package/assets/rebuild-object/forge/stage4_review/swept_arc_gate.py +336 -0
  112. package/assets/rebuild-object/forge/stage4_review/turntable_gate.py +415 -0
  113. package/assets/rebuild-object/forge/stage4_review/validate_render_profile.py +182 -0
  114. package/assets/rebuild-object/forge/stage4_review/vertex_region_gate.py +456 -0
  115. package/assets/rebuild-object/forge/stage4_review/vlm_gate.py +196 -0
  116. package/assets/rebuild-object/forge/stage5_rig/NOTES.md +149 -0
  117. package/assets/rebuild-object/forge/stage5_rig/__init__.py +6 -0
  118. package/assets/rebuild-object/forge/stage5_rig/emit_rig.py +420 -0
  119. package/assets/rebuild-object/forge/stage5_rig/geodesic_skinning.py +508 -0
  120. package/assets/rebuild-object/forge/stage5_rig/rig_spec.py +174 -0
  121. package/assets/rebuild-object/forge/stage5_rig/validate_rig_payload.py +195 -0
  122. package/assets/rebuild-object/forge/state.py +98 -0
  123. package/assets/rebuild-object/steps.json +381 -0
  124. package/dist/{chunk-FXXVXDTW.js → chunk-24TITAFS.js} +1 -1
  125. package/dist/{chunk-OGX4DKIS.js → chunk-2C5PG2QO.js} +1 -1
  126. package/dist/{chunk-HYOXGNWS.js → chunk-2DEVOKI7.js} +1 -1
  127. package/dist/{chunk-RRI23NK2.js → chunk-2GHPYT2P.js} +1 -1
  128. package/dist/{chunk-S7HYWITX.js → chunk-2HXGMXGC.js} +1 -1
  129. package/dist/{chunk-N2UHAQXC.js → chunk-36FORP7T.js} +0 -1
  130. package/dist/{chunk-VB4WLJR2.js → chunk-3IXRQTRF.js} +1 -1
  131. package/dist/{chunk-2KVQJKIZ.js → chunk-4ENHS32B.js} +23 -36
  132. package/dist/{chunk-SXYQL4GK.js → chunk-4YHA32OE.js} +1 -1
  133. package/dist/{chunk-4FJXCS3K.js → chunk-4ZGQKPK5.js} +1 -1
  134. package/dist/{chunk-SBXCK2I2.js → chunk-6CLUPFQA.js} +2 -2
  135. package/dist/{chunk-TXOE5UY5.js → chunk-7WTF2BA4.js} +1 -1
  136. package/dist/{chunk-R2WVORGD.js → chunk-AAXZNK4Z.js} +1 -1
  137. package/dist/{chunk-DOOQUFPG.js → chunk-ALLBT4FB.js} +1 -1
  138. package/dist/{chunk-HRKVAXNN.js → chunk-BAZDPPIG.js} +5 -5
  139. package/dist/{chunk-RPJR3S5S.js → chunk-CYDENLZ4.js} +5 -8
  140. package/dist/{chunk-I5LELJSK.js → chunk-DKSUD44G.js} +1 -1
  141. package/dist/{chunk-43P4U7CB.js → chunk-DWWSJKTE.js} +1 -1
  142. package/dist/{chunk-SUSX3QIA.js → chunk-E72TFJZP.js} +1 -1
  143. package/dist/{chunk-E3FJUPLT.js → chunk-EUAAQMUA.js} +2 -0
  144. package/dist/{chunk-U6DTE5IX.js → chunk-F7LYJSZE.js} +1 -1
  145. package/dist/{chunk-MEAO33XW.js → chunk-FMON3C74.js} +8 -8
  146. package/dist/{chunk-GLEW7VJQ.js → chunk-FPILHRLZ.js} +1 -1
  147. package/dist/{chunk-OPUCUUID.js → chunk-G63MXDX2.js} +4 -0
  148. package/dist/{chunk-4UU622RK.js → chunk-GGO6ZYYI.js} +1 -3
  149. package/dist/{chunk-2ZKS7V72.js → chunk-GZCRYYS6.js} +5 -5
  150. package/dist/{chunk-E7NDOZ27.js → chunk-LE4GVTYI.js} +8 -8
  151. package/dist/{chunk-RKS7SI5L.js → chunk-NO6KPV64.js} +1 -1
  152. package/dist/{chunk-KJK5CB6E.js → chunk-NXW3Z4Y4.js} +1 -1
  153. package/dist/{chunk-7RPLQWR2.js → chunk-OHOAZGO4.js} +1 -1
  154. package/dist/chunk-PYJNI5WD.js +83 -0
  155. package/dist/{chunk-NCX6LYNJ.js → chunk-Q4XAGTFX.js} +1 -1
  156. package/dist/{chunk-3UGGMFJJ.js → chunk-QMZBSVKF.js} +1 -1
  157. package/dist/{chunk-ABTUEIRC.js → chunk-QO66UBOS.js} +2 -2
  158. package/dist/{chunk-LONQWRTR.js → chunk-S4KVGQQO.js} +8 -8
  159. package/dist/{chunk-HX5Q63UA.js → chunk-T777EXAO.js} +1 -1
  160. package/dist/{chunk-UQ7VO6B3.js → chunk-TZZNRA3S.js} +1 -1
  161. package/dist/{chunk-CTY2WZQK.js → chunk-UC3QLWMQ.js} +1 -1
  162. package/dist/{chunk-MR5KIFI7.js → chunk-UDJH2RED.js} +3 -3
  163. package/dist/{chunk-ZHLPE6LI.js → chunk-UIKYK7KI.js} +1 -1
  164. package/dist/{chunk-KAGVI3CE.js → chunk-UJRSQO2B.js} +1 -1
  165. package/dist/{chunk-Q2QC6KAZ.js → chunk-V7LEYVXB.js} +29 -25
  166. package/dist/{chunk-DB7WVFS7.js → chunk-WRMQEXUC.js} +1 -1
  167. package/dist/{chunk-HSMG6U7J.js → chunk-WXSBNC67.js} +3 -9
  168. package/dist/{chunk-QLCVLCPM.js → chunk-X4QIOXNQ.js} +1 -1
  169. package/dist/{chunk-5YPLKGY3.js → chunk-Y6WHUK2O.js} +1 -1
  170. package/dist/{chunk-VZEJ2ZHE.js → chunk-Z3E7ORGQ.js} +5 -5
  171. package/dist/index.js +20 -20
  172. package/package.json +32 -22
  173. package/dist/{chunk-Q3XQPNF6.js → chunk-BN7TR6OR.js} +3 -3
  174. package/dist/{chunk-LORGE2NB.js → chunk-U2NCN5RO.js} +3 -3
  175. package/dist/{chunk-UPHB5HWO.js → chunk-VQTTSPA3.js} +3 -3
@@ -0,0 +1,306 @@
1
+ #!/usr/bin/env python3
2
+ """The semantic description of a hairstyle: its schema and its validation rules.
3
+
4
+ WHAT THIS IS AND IS NOT, PRECISELY. This module defines and VALIDATES a `hairProfile`. It does not
5
+ compile one into geometry -- there is no profile-to-componentTree compiler yet, and a spec still
6
+ authors its hair components directly. Enforcement of the profile's rules today comes from the
7
+ validator here plus the `standProud` march the generator emits.
8
+
9
+ That distinction is stated first because getting it wrong is the specific way this subsystem is
10
+ likely to mislead someone: a schema is cheap to write and reads exactly like a working feature.
11
+
12
+ WHY A PROFILE AND NOT GEOMETRY. Everywhere else in this pipeline the model writes a spec and a
13
+ generator writes the geometry. Hair was the one subsystem where the model still placed vertices by
14
+ hand, and it showed: four separate attempts to fix one hairstyle by adjusting numbers, four wrong
15
+ diagnoses, and the only thing that ever caught them was measurement after the fact. A profile moves
16
+ hair onto the same footing as everything else -- the model reverse-engineers PARAMETERS from the
17
+ reference and a compiler owns topology. That compiler is not written yet -- see the header.
18
+
19
+ WHY THE COMPILER RUNS IN PYTHON. The obvious design puts a hair engine in the emitted TypeScript
20
+ and lets it generate guide curves at runtime. That would break the one property this project sells:
21
+ output a person can read. A hundred procedurally generated curves is not readable. So the profile is
22
+ intended to be compiled at spec time into a finite, named, readable set of masses. That step does
23
+ not exist yet; today the schema is validated and hair components are still authored directly.
24
+
25
+ WHY TIER 0 IS A SHELL. Measured on the reference this pipeline is calibrated against -- a 570,400
26
+ vertex merged scan -- the surface roughness over the hair is 0.00338 against a torso control of
27
+ 0.00312, a difference of 8%. Hair on a real reference at this fidelity is a SMOOTH SHELL whose
28
+ strand detail lives entirely in the diffuse and normal textures. There are no locks in it to copy.
29
+ Since this pipeline emits code and no textures, the strand impression has to come from faceting and
30
+ material response, not from lock geometry, and the default representation is therefore a shell with
31
+ masses layered on it.
32
+
33
+ WHAT IS NOT CALIBRATED. Every numeric bound below that could not be traced to a measurement is
34
+ listed in UNCALIBRATED_FIELDS and reported as such. No multipart GLB with separated hair geometry is
35
+ available, so lock-tier parameters -- taper ratios, cross-section aspect, lock counts -- have no
36
+ ground truth. They are derived from anatomy and declared derived. The alternative, quietly inventing
37
+ plausible numbers, is precisely how eleven hair locks all ended up with a tip radius of 0.0327.
38
+
39
+ Pure Python 3.10+ standard library.
40
+ """
41
+ from __future__ import annotations
42
+
43
+ from typing import Any
44
+
45
+ VALID_REPRESENTATION_TIERS = ("shell", "masses", "locks")
46
+ DEFAULT_REPRESENTATION_TIER = "shell"
47
+
48
+ VALID_HAIR_REGIONS = {
49
+ "crown", "fringe", "temple-left", "temple-right", "side-left", "side-right",
50
+ "rear", "nape", "sideburn-left", "sideburn-right", "tail", "stray",
51
+ }
52
+
53
+ # Primitives a hair mass may be built from, and why the obvious alternatives are not here.
54
+ #
55
+ # plane-card needs an alpha texture to read as hair. This pipeline emits code and no
56
+ # textures, so a card is a visible opaque rectangle. This is the decision left
57
+ # open in docs/UPGRADE_PLAN.md since v1.2 ("hair cards vs tube-along-curve per
58
+ # lock"), now closed by measurement: the review metrics respond to silhouette and
59
+ # banded interior luminance, both of which come from mass, not from card count.
60
+ # tube constant radius. A lock that does not taper reads as a noodle; that failure is
61
+ # already recorded in taper_risk().
62
+ VALID_HAIR_PRIMITIVES = {"tapered-sweep", "curve-sweep", "lathe", "ellipsoid", "instanced-cluster"}
63
+ REJECTED_HAIR_PRIMITIVES = {
64
+ "plane-card": (
65
+ "a card needs an alpha texture to read as hair, and this pipeline emits code with no "
66
+ "textures, so it renders as an opaque rectangle"
67
+ ),
68
+ "tube": (
69
+ "a tube has a constant radius, so a lock built from one reads as a noodle; use "
70
+ "'tapered-sweep', which can reach a real point"
71
+ ),
72
+ "box": "a box cannot describe a hair mass; use 'tapered-sweep' or 'lathe'",
73
+ }
74
+
75
+ # Fields whose numeric bounds are DERIVED, not measured, because no reference with separated hair
76
+ # geometry exists to calibrate them against. Anything listed here must carry uncalibrated: true.
77
+ UNCALIBRATED_FIELDS = (
78
+ "masses[].taper",
79
+ "masses[].crossSection.aspect",
80
+ "flowField.gravity",
81
+ "flowField.whorls[].strength",
82
+ )
83
+
84
+
85
+ def _is_number(value: Any) -> bool:
86
+ return isinstance(value, (int, float)) and not isinstance(value, bool)
87
+
88
+
89
+ def _unit(value: Any) -> bool:
90
+ return _is_number(value) and 0.0 <= float(value) <= 1.0
91
+
92
+
93
+ def _validate_hairline(hairline: Any, errors: list[str], warnings: list[str]) -> None:
94
+ """The hairline is five control points across the brow, held in scalp (u, v) coordinates.
95
+
96
+ It gets its own object because it drives the silhouette out of proportion to its size and
97
+ because the pipeline already has an unfilled `faceLandmarks.hairline` slot that nothing reads.
98
+ """
99
+ if hairline is None:
100
+ warnings.append(
101
+ "hairProfile.hairline is missing; the hairline sets where the face ends and the hair "
102
+ "begins, and without it the fringe has no anchor"
103
+ )
104
+ return
105
+ if not isinstance(hairline, dict):
106
+ errors.append("hairProfile.hairline must be an object")
107
+ return
108
+ points = hairline.get("controlPoints")
109
+ if not isinstance(points, list) or len(points) < 3:
110
+ errors.append(
111
+ "hairProfile.hairline.controlPoints needs at least 3 points "
112
+ "(temple-left, peak, temple-right at minimum)"
113
+ )
114
+ return
115
+ for index, point in enumerate(points):
116
+ label = f"hairProfile.hairline.controlPoints[{index}]"
117
+ if not isinstance(point, dict):
118
+ errors.append(f"{label} must be an object with u and v")
119
+ continue
120
+ if not _unit(point.get("u")) or not _unit(point.get("v")):
121
+ errors.append(f"{label} must carry u and v in [0,1] on the scalp surface")
122
+
123
+
124
+ def _validate_flow_field(flow: Any, errors: list[str], warnings: list[str]) -> None:
125
+ """Direction as a FIELD over the scalp rather than a direction per mass.
126
+
127
+ This is what makes a wide range of hairstyles reachable without authoring a direction for every
128
+ piece: a style is largely a part line, one or two whorls, how much gravity wins, and a sweep
129
+ direction. Roughly six numbers instead of thirty.
130
+ """
131
+ if flow is None:
132
+ warnings.append(
133
+ "hairProfile.flowField is missing; every mass will then need its own authored "
134
+ "direction, which is what produced fourteen competing directions in a recorded build"
135
+ )
136
+ return
137
+ if not isinstance(flow, dict):
138
+ errors.append("hairProfile.flowField must be an object")
139
+ return
140
+
141
+ gravity = flow.get("gravity")
142
+ if gravity is not None and not _unit(gravity):
143
+ errors.append("hairProfile.flowField.gravity must be a number in [0,1]")
144
+
145
+ part = flow.get("partLine")
146
+ if part is not None:
147
+ if not isinstance(part, dict):
148
+ errors.append("hairProfile.flowField.partLine must be an object")
149
+ elif not _unit(part.get("u")):
150
+ errors.append("hairProfile.flowField.partLine.u must be in [0,1]")
151
+
152
+ whorls = flow.get("whorls")
153
+ if whorls is not None:
154
+ if not isinstance(whorls, list):
155
+ errors.append("hairProfile.flowField.whorls must be an array")
156
+ else:
157
+ for index, whorl in enumerate(whorls):
158
+ label = f"hairProfile.flowField.whorls[{index}]"
159
+ if not isinstance(whorl, dict):
160
+ errors.append(f"{label} must be an object")
161
+ continue
162
+ if not _unit(whorl.get("u")) or not _unit(whorl.get("v")):
163
+ errors.append(f"{label} needs u and v in [0,1]")
164
+ strength = whorl.get("strength")
165
+ if strength is not None and not _unit(strength):
166
+ errors.append(f"{label}.strength must be in [0,1]")
167
+
168
+
169
+ def _validate_mass(index: int, mass: Any, tier: str, errors: list[str], warnings: list[str]) -> None:
170
+ label = f"hairProfile.masses[{index}]"
171
+ if not isinstance(mass, dict):
172
+ errors.append(f"{label} must be an object")
173
+ return
174
+
175
+ if not isinstance(mass.get("id"), str) or not str(mass.get("id")).strip():
176
+ errors.append(f"{label}.id is required")
177
+
178
+ region = mass.get("region")
179
+ if region is not None and region not in VALID_HAIR_REGIONS:
180
+ errors.append(
181
+ f"{label}.region {region!r} is not one of: {', '.join(sorted(VALID_HAIR_REGIONS))}"
182
+ )
183
+
184
+ primitive = mass.get("primitive")
185
+ if primitive in REJECTED_HAIR_PRIMITIVES:
186
+ errors.append(f"{label} may not use primitive {primitive!r}: {REJECTED_HAIR_PRIMITIVES[primitive]}")
187
+ elif primitive is not None and primitive not in VALID_HAIR_PRIMITIVES:
188
+ errors.append(
189
+ f"{label}.primitive {primitive!r} is not usable for hair; "
190
+ f"choose from: {', '.join(sorted(VALID_HAIR_PRIMITIVES))}"
191
+ )
192
+
193
+ # THE ROOT RULE. A root held as an absolute position can drift off the skull the moment the mass
194
+ # is resized -- which is the measured failure this whole subsystem exists to prevent. Held as
195
+ # (u, v) on the scalp it cannot: the surface carries it. This is the same binding Blender uses
196
+ # for hair, where a curve's root is a `surface_uv_coordinate` on the emitter mesh.
197
+ root = mass.get("root")
198
+ if not isinstance(root, dict):
199
+ errors.append(
200
+ f"{label}.root is required and must be {{u, v}} on the scalp surface"
201
+ )
202
+ elif "position" in root or "xyz" in root:
203
+ errors.append(
204
+ f"{label}.root must be scalp (u, v), not an absolute position: an absolute root slides "
205
+ f"off the skull when the mass is resized, which renders as a bald patch"
206
+ )
207
+ elif not _unit(root.get("u")) or not _unit(root.get("v")):
208
+ errors.append(f"{label}.root needs u and v in [0,1] on the scalp surface")
209
+
210
+ for field in ("length", "width", "thickness"):
211
+ value = mass.get(field)
212
+ if value is not None and (not _is_number(value) or float(value) <= 0.0):
213
+ errors.append(f"{label}.{field} must be a positive number")
214
+
215
+ taper = mass.get("taper")
216
+ if taper is not None:
217
+ if not _unit(taper):
218
+ errors.append(f"{label}.taper must be a tip/root ratio in [0,1]")
219
+ elif not mass.get("uncalibrated"):
220
+ warnings.append(
221
+ f"quality: {label}.taper is set but the mass is not marked uncalibrated; no "
222
+ f"reference with separated hair geometry exists to calibrate a taper ratio against"
223
+ )
224
+
225
+ if tier == "locks" and mass.get("primitive") not in (None, "tapered-sweep", "curve-sweep"):
226
+ warnings.append(
227
+ f"quality: {label} is in a 'locks' tier profile but is not a swept primitive; a lock "
228
+ f"has to reach a point and only the sweeps can"
229
+ )
230
+
231
+
232
+ def validate_hair_profile(profile: Any, errors: list[str], warnings: list[str]) -> None:
233
+ """Validate a `hairProfile` block. Appends to `errors` and `warnings` in place."""
234
+ if profile is None:
235
+ return
236
+ if not isinstance(profile, dict):
237
+ errors.append("hairProfile must be an object")
238
+ return
239
+
240
+ tier = profile.get("representationTier", DEFAULT_REPRESENTATION_TIER)
241
+ if tier not in VALID_REPRESENTATION_TIERS:
242
+ errors.append(
243
+ f"hairProfile.representationTier must be one of: {', '.join(VALID_REPRESENTATION_TIERS)}"
244
+ )
245
+ tier = DEFAULT_REPRESENTATION_TIER
246
+
247
+ scalp = profile.get("scalpComponentId")
248
+ if not isinstance(scalp, str) or not scalp.strip():
249
+ errors.append(
250
+ "hairProfile.scalpComponentId is required; it names the component whose surface hair "
251
+ "roots bind to and stand proud of"
252
+ )
253
+
254
+ _validate_hairline(profile.get("hairline"), errors, warnings)
255
+ _validate_flow_field(profile.get("flowField"), errors, warnings)
256
+
257
+ masses = profile.get("masses")
258
+ if masses is None:
259
+ if tier != "shell":
260
+ errors.append(f"hairProfile.masses is required for representationTier {tier!r}")
261
+ elif not isinstance(masses, list):
262
+ errors.append("hairProfile.masses must be an array")
263
+ else:
264
+ seen: set[str] = set()
265
+ for index, mass in enumerate(masses):
266
+ _validate_mass(index, mass, tier, errors, warnings)
267
+ if isinstance(mass, dict) and isinstance(mass.get("id"), str):
268
+ if mass["id"] in seen:
269
+ errors.append(f"hairProfile.masses has a duplicate id {mass['id']!r}")
270
+ seen.add(mass["id"])
271
+
272
+ if tier == "locks":
273
+ warnings.append(
274
+ "quality: representationTier 'locks' has no calibration reference. The available "
275
+ "reference GLB is one merged 570,400-vertex scan whose hair is a smooth shell "
276
+ "(surface roughness 0.00338 against a torso control of 0.00312), so it contains no "
277
+ "lock geometry to measure. Lock parameters here are derived, not observed."
278
+ )
279
+
280
+
281
+ def hair_profile_report(profile: Any) -> dict[str, Any]:
282
+ """A machine-readable summary, including what in it is uncalibrated."""
283
+ errors: list[str] = []
284
+ warnings: list[str] = []
285
+ validate_hair_profile(profile, errors, warnings)
286
+ tier = DEFAULT_REPRESENTATION_TIER
287
+ mass_count = 0
288
+ if isinstance(profile, dict):
289
+ tier = profile.get("representationTier", DEFAULT_REPRESENTATION_TIER)
290
+ masses = profile.get("masses")
291
+ mass_count = len(masses) if isinstance(masses, list) else 0
292
+ return {
293
+ "schemaVersion": 1,
294
+ "kind": "hair-profile-report",
295
+ "representationTier": tier,
296
+ "massCount": mass_count,
297
+ "errors": errors,
298
+ "warnings": warnings,
299
+ "uncalibratedFields": list(UNCALIBRATED_FIELDS),
300
+ "calibrationNote": (
301
+ "Shell-tier envelope values can be measured against the reference scan. Lock-tier "
302
+ "parameters cannot: that reference is one merged mesh whose hair is a smooth textured "
303
+ "shell, so it holds no lock geometry. A multipart GLB with a separated hair mesh is "
304
+ "required before those bounds mean anything."
305
+ ),
306
+ }
@@ -0,0 +1,214 @@
1
+ #!/usr/bin/env python3
2
+ """Canonical humanoid proportions, so a reference-free stylized figure can be specified.
3
+
4
+ `validate_sculpt_spec.py` blocks any character spec whose `anatomy.applies` is not true, and
5
+ tells the author to "fill anatomy (styleHeads, proportions, pose, faceLandmarks) from the
6
+ reference". That is the right demand when there IS a reference: a specific person's
7
+ proportions are evidence, and a canon table would be a fabrication of that evidence.
8
+
9
+ But it also made a reference-free request impossible to express. "Build me a 4-head stylized
10
+ low-poly humanoid" has no reference to measure, and the canon it should follow is public
11
+ figure-drawing convention, not an invented number. This module supplies that canon and marks
12
+ it as canon, so the two cases stay distinguishable downstream: anatomy derived here carries
13
+ `source: "canon-table"`, never `"reference"`.
14
+
15
+ ## Provenance of every number below
16
+
17
+ Cited to the low-poly humanoid research corpus (NotebookLM notebook
18
+ `ab7334f3-818b-427d-a7eb-96c0581d812f`, 77 sources) or marked DEFINITIONAL where the value
19
+ follows from the head-unit system itself rather than from a source.
20
+
21
+ | Landmark | 8-head | 4-head | Provenance |
22
+ |---------------------|---------|---------|--------------|
23
+ | head height / H | 0.125 | 0.25 | DEFINITIONAL (1/styleHeads) |
24
+ | shoulder width / H | 0.25 | -- | research |
25
+ | waist width / H | 0.125 | -- | research |
26
+ | hip width / H | 0.1875 | -- | research |
27
+ | hip line Y / H | 0.50 | -- | research |
28
+ | knee line Y / H | 0.25 | -- | research |
29
+ | upper arm / H | 0.187 | 0.125 | research |
30
+ | forearm / H | 0.187 | 0.125 | research |
31
+ | shin / H | 0.25 | 0.125 | research |
32
+
33
+ Values the research corpus did NOT supply are absent rather than guessed: chest width,
34
+ shoulder Y, waist Y, hand length, thigh length, foot length. `derive_anatomy()` reports them
35
+ in `unsourced` so a caller can see what it is NOT being told, instead of receiving a
36
+ confident-looking number nobody measured. Filling them in later is a research task, not an
37
+ editing task.
38
+ """
39
+
40
+ from __future__ import annotations
41
+
42
+ import argparse
43
+ import json
44
+ import sys
45
+ from pathlib import Path
46
+ from typing import Any
47
+
48
+ # Fractions of total height H. Only entries with a stated provenance above appear here.
49
+ #
50
+ # 8 is the only COMPLETE canon. The corpus supplies stylized limb lengths but was asked
51
+ # directly for the 4-head hip line, torso span, leg span and shoulder width and answered
52
+ # "NOT IN SOURCES" for all four. Without a hip line there is no torso/legs split, which is
53
+ # precisely what the character gate checks — so a 4-head figure cannot be derived honestly
54
+ # here yet, and `derive_anatomy()` says so instead of interpolating toward the 8-head row.
55
+ CANON_BY_HEADS: dict[int, dict[str, float]] = {
56
+ 8: {
57
+ "shoulderWidth": 0.25,
58
+ "waistWidth": 0.125,
59
+ "hipWidth": 0.1875,
60
+ "hipLineY": 0.50,
61
+ "kneeLineY": 0.25,
62
+ "upperArmLength": 0.187,
63
+ "forearmLength": 0.187,
64
+ "shinLength": 0.25,
65
+ },
66
+ }
67
+
68
+ # Sourced, but not enough on their own to satisfy the gate. Kept so the missing pieces are
69
+ # named rather than forgotten: filling in a 4-head hip line makes this row usable.
70
+ PARTIAL_CANON_BY_HEADS: dict[int, dict[str, float]] = {
71
+ 4: {
72
+ "upperArmLength": 0.125,
73
+ "forearmLength": 0.125,
74
+ "shinLength": 0.125,
75
+ },
76
+ }
77
+
78
+ REQUIRED_FOR_GATE: tuple[str, ...] = ("hipLineY",)
79
+
80
+ UNSOURCED_LANDMARKS: tuple[str, ...] = (
81
+ "chestWidth",
82
+ "shoulderLineY",
83
+ "waistLineY",
84
+ "handLength",
85
+ "thighLength",
86
+ "footLength",
87
+ )
88
+
89
+ # Face landmarks as a fraction of HEAD height, measured from the top of the skull down.
90
+ # DEFINITIONAL under the standard head-division convention: the eye line halves the head,
91
+ # the nose base and mouth line divide the lower half. The research corpus was not asked for
92
+ # these, so they are marked as convention rather than as measured evidence.
93
+ FACE_LANDMARKS_BY_HEAD_FRACTION: dict[str, float] = {
94
+ "eyeLine": 0.50,
95
+ "noseBase": 0.75,
96
+ "mouthLine": 0.85,
97
+ }
98
+
99
+ SUPPORTED_HEADS: tuple[int, ...] = tuple(sorted(CANON_BY_HEADS))
100
+
101
+
102
+ def nearest_supported_heads(style_heads: float) -> int:
103
+ """Snap to the nearest COMPLETE table, rather than interpolating between tables.
104
+
105
+ Interpolating would invent numbers with the same confident shape as the sourced ones,
106
+ which is exactly what this module exists to avoid.
107
+ """
108
+ return min(SUPPORTED_HEADS, key=lambda h: abs(h - style_heads))
109
+
110
+
111
+ def missing_for_heads(style_heads: float) -> list[str]:
112
+ """Name the landmarks that stop a head count from being derivable, or return []."""
113
+ heads = int(style_heads) if float(style_heads).is_integer() else None
114
+ if heads in CANON_BY_HEADS:
115
+ return []
116
+ partial = PARTIAL_CANON_BY_HEADS.get(heads or -1)
117
+ if partial is None:
118
+ return []
119
+ return [key for key in REQUIRED_FOR_GATE if key not in partial]
120
+
121
+
122
+ def derive_anatomy(style_heads: float) -> dict[str, Any]:
123
+ """Build an `anatomy` block from canon, explicitly labelled as canon.
124
+
125
+ The returned block satisfies `validate_sculpt_spec.py`'s character gate — `applies`,
126
+ `styleHeads`, `proportions` with torso/legs head-unit ratios, and `faceLandmarks` — while
127
+ `source` and `unsourced` keep it honest about where the numbers came from and what is
128
+ still missing.
129
+ """
130
+ if not isinstance(style_heads, (int, float)) or isinstance(style_heads, bool):
131
+ raise ValueError(f"styleHeads must be a number, got {style_heads!r}")
132
+ if style_heads <= 0:
133
+ raise ValueError(f"styleHeads must be greater than 0, got {style_heads}")
134
+
135
+ missing = missing_for_heads(style_heads)
136
+ if missing:
137
+ raise ValueError(
138
+ f"no complete canon for {style_heads} heads: the corpus supplies limb lengths but "
139
+ f"not {', '.join(missing)}, and without a hip line there is no torso/legs split for "
140
+ f"the character gate to check. Measure it from a reference, or extend "
141
+ f"CANON_BY_HEADS once a source states it. Complete tables: {list(SUPPORTED_HEADS)}"
142
+ )
143
+
144
+ heads = nearest_supported_heads(style_heads)
145
+ fractions = dict(CANON_BY_HEADS[heads])
146
+ head_height = 1.0 / style_heads
147
+
148
+ # The gate asks for head-unit ratios, so convert once here rather than at every call site.
149
+ def in_heads(fraction: float) -> float:
150
+ return round(fraction / head_height, 4)
151
+
152
+ legs_fraction = fractions.get("hipLineY")
153
+ return {
154
+ "applies": True,
155
+ "source": "canon-table",
156
+ "styleHeads": style_heads,
157
+ "snappedToHeads": heads,
158
+ "proportions": {
159
+ # Torso spans the hip line up to the shoulders; with no sourced shoulder Y the
160
+ # honest statement is "everything above the hips minus the head".
161
+ "torso": in_heads(1.0 - (legs_fraction or 0.5)) - 1.0 if legs_fraction else None,
162
+ "legs": in_heads(legs_fraction) if legs_fraction else None,
163
+ "headHeightFraction": round(head_height, 4),
164
+ **{key: round(value, 4) for key, value in fractions.items()},
165
+ },
166
+ "faceLandmarks": dict(FACE_LANDMARKS_BY_HEAD_FRACTION),
167
+ "pose": {"name": "bind", "description": "A-pose bind, arms lowered, palms inward"},
168
+ "unsourced": list(UNSOURCED_LANDMARKS),
169
+ }
170
+
171
+
172
+ def apply_to_spec(spec: dict[str, Any], style_heads: float) -> dict[str, Any]:
173
+ """Write a canon anatomy block into a spec's `preSpecAssessment`.
174
+
175
+ Refuses a spec that names a reference image: when a reference exists the anatomy is
176
+ supposed to be measured from it, and silently substituting canon would turn a gate that
177
+ demands evidence into one that accepts a default.
178
+ """
179
+ source_image = spec.get("sourceImage")
180
+ if isinstance(source_image, str) and source_image.strip() and source_image != "/dev/null":
181
+ raise ValueError(
182
+ f"spec names a reference image ({source_image}); measure anatomy from it rather "
183
+ "than substituting the canon table"
184
+ )
185
+ assessment = spec.setdefault("preSpecAssessment", {})
186
+ assessment["anatomy"] = derive_anatomy(style_heads)
187
+ return spec
188
+
189
+
190
+ def main(argv: list[str] | None = None) -> int:
191
+ parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
192
+ parser.add_argument("spec", type=Path, help="ObjectSculptSpec to fill")
193
+ parser.add_argument("--style-heads", type=float, required=True,
194
+ help="head-unit height of the figure (8 = realistic, 4 = stylized)")
195
+ parser.add_argument("--in-place", action="store_true")
196
+ args = parser.parse_args(argv)
197
+
198
+ spec = json.loads(args.spec.read_text(encoding="utf-8"))
199
+ try:
200
+ apply_to_spec(spec, args.style_heads)
201
+ except ValueError as error:
202
+ print(f"error: {error}", file=sys.stderr)
203
+ return 2
204
+ payload = json.dumps(spec, indent=2)
205
+ if args.in_place:
206
+ args.spec.write_text(payload + "\n", encoding="utf-8")
207
+ print(f"{args.spec}: anatomy filled from canon at {args.style_heads} heads")
208
+ else:
209
+ print(payload)
210
+ return 0
211
+
212
+
213
+ if __name__ == "__main__":
214
+ raise SystemExit(main())