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,149 @@
|
|
|
1
|
+
# Milestone 0 findings that don't belong in the gate report
|
|
2
|
+
|
|
3
|
+
These are things discovered while building the Milestone 0 rig emitter
|
|
4
|
+
(`forge/stage5_rig/`) that are true regardless of Milestone 0's pass/fail
|
|
5
|
+
result, and that matter to whoever does rig *integration* later. Read-only
|
|
6
|
+
findings — nothing here changes any file outside `forge/stage5_rig/` or
|
|
7
|
+
`forge/tests/test_rig_milestone0.py`.
|
|
8
|
+
|
|
9
|
+
## `THREE.CapsuleGeometry`'s raw seam is a real defect; the "66 non-manifold after weld" figure was not
|
|
10
|
+
|
|
11
|
+
> **CORRECTED 2026-07-30 (credit: worker-flatten).** The paragraph below
|
|
12
|
+
> originally claimed that even a "correct" weld of `THREE.CapsuleGeometry`
|
|
13
|
+
> left 66 non-manifold edges, and used that to argue the primitive needed a
|
|
14
|
+
> hand-built replacement rather than a better weld. That specific claim was
|
|
15
|
+
> wrong — it was a measurement artifact of `BufferGeometryUtils.mergeVertices`,
|
|
16
|
+
> not a real topology defect. I reproduced worker-flatten's finding
|
|
17
|
+
> independently (see below) before editing this file, rather than taking the
|
|
18
|
+
> correction on faith. The **raw boundary-edge finding (194 edges) is still
|
|
19
|
+
> real and still verified** — only the "non-manifold after weld" half of the
|
|
20
|
+
> story was wrong.
|
|
21
|
+
|
|
22
|
+
**What's actually true, verified directly:** the exact capsule call the
|
|
23
|
+
pipeline used to emit (`new THREE.CapsuleGeometry(0.35, 0.7, 16, 32)`, from
|
|
24
|
+
`CAPSULE_CAP_SEGMENTS = 16` / `CAPSULE_RADIAL_SEGMENTS = 32` — see "Update on
|
|
25
|
+
the real pipeline" below for what's changed since) has a genuine UV-seam
|
|
26
|
+
defect in its raw, unwelded form:
|
|
27
|
+
|
|
28
|
+
| Method | vertices | triangles | boundary edges | non-manifold edges |
|
|
29
|
+
|---|---|---|---|---|
|
|
30
|
+
| as-is, unwelded | 2178 | 4160 | **194** | 0 |
|
|
31
|
+
| position-only + `BufferGeometryUtils.mergeVertices(geometry, 1e-5)` | 2050 | 4160 | 0 | 66 *(artifact — see below)* |
|
|
32
|
+
| position-key dedup + **drop degenerate triangles** (no `mergeVertices`) | 2050 | 4096 (64 dropped) | 0 | **0** |
|
|
33
|
+
|
|
34
|
+
**Root cause of the "66" artifact:** `mergeVertices` re-indexes vertices by
|
|
35
|
+
position but does not drop triangles that become degenerate (two or more
|
|
36
|
+
corners collapsed to the same vertex) after that re-indexing. A degenerate
|
|
37
|
+
triangle `(a, a, b)` contributes the undirected edge `(a, b)` to the tally
|
|
38
|
+
**twice**, silently turning a legitimate 2-incidence (ordinary, non-manifold)
|
|
39
|
+
edge into an apparent 4 — which a naive `count > 2` check flags as
|
|
40
|
+
non-manifold even though the actual geometry, once the degenerate triangles
|
|
41
|
+
are also dropped, is a perfectly ordinary closed 2-manifold. There are
|
|
42
|
+
exactly 64 such degenerate triangles for this configuration — the "64
|
|
43
|
+
dropped" figure in the corrected row above, which I measured myself and
|
|
44
|
+
which matches worker-flatten's number exactly. This is
|
|
45
|
+
stable across weld tolerances from `1e-4` down to `1e-10` (ruling out a
|
|
46
|
+
tolerance-size explanation), and matches independently between two different
|
|
47
|
+
implementations (mine, replicated here; worker-flatten's, done separately in
|
|
48
|
+
`generate_threejs_factory.py`'s context) with the exact same numbers.
|
|
49
|
+
|
|
50
|
+
**So the raw-boundary finding (194 edges) stands, but the conclusion drawn
|
|
51
|
+
from it does not fully stand:** `THREE.CapsuleGeometry` is fixable with an
|
|
52
|
+
ordinary weld — it just needs a weld that also drops degenerate triangles,
|
|
53
|
+
which `mergeVertices` alone does not do. A hand-built watertight primitive
|
|
54
|
+
(what Milestone 0 uses; see below) is *a* valid fix, but it was not, as I
|
|
55
|
+
originally implied, the *only* practical one.
|
|
56
|
+
|
|
57
|
+
**Correction to my prior report to team-lead (kept for the record, still
|
|
58
|
+
accurate on its own terms):** I previously wrote that
|
|
59
|
+
`createRiggedDragon.ts:422-432`'s position-only `rawGeometry` strip-then-merge
|
|
60
|
+
pattern exists "exactly because" of the UV-seam attribute-matching problem
|
|
61
|
+
below. That was an inference from reading the code's *shape*, not something
|
|
62
|
+
the code itself states, and team-lead is right that it postdates a different
|
|
63
|
+
purpose (copying vertices out of a `MarchingCubes` result before a
|
|
64
|
+
scale/translate). What IS independently verified, not inferred, is that
|
|
65
|
+
`mergeVertices` only merges vertices where **every** attribute matches within
|
|
66
|
+
tolerance — I confirmed this by running `mergeVertices` on the *untouched*
|
|
67
|
+
geometry (all attributes intact) and getting the same 194 boundary edges, no
|
|
68
|
+
change, versus a real change once stripped to position-only. Whether the
|
|
69
|
+
dragon file's author had that same reasoning in mind is not established
|
|
70
|
+
either way.
|
|
71
|
+
|
|
72
|
+
**Reproduce (all three rows above, in one run):**
|
|
73
|
+
```bash
|
|
74
|
+
cd img2threejs-showcase
|
|
75
|
+
node --input-type=module -e "
|
|
76
|
+
import * as THREE from 'three';
|
|
77
|
+
import { mergeVertices } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
78
|
+
function edgeStats(idxArr, triCount) {
|
|
79
|
+
const edges = new Map();
|
|
80
|
+
for (let o = 0; o < triCount; o++) {
|
|
81
|
+
const tri = [idxArr[o*3], idxArr[o*3+1], idxArr[o*3+2]];
|
|
82
|
+
for (let e = 0; e < 3; e++) {
|
|
83
|
+
const u = tri[e], v = tri[(e+1)%3];
|
|
84
|
+
const k = u < v ? u+':'+v : v+':'+u;
|
|
85
|
+
edges.set(k, (edges.get(k) ?? 0) + 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { boundary: [...edges.values()].filter(c=>c===1).length, nonManifold: [...edges.values()].filter(c=>c>2).length };
|
|
89
|
+
}
|
|
90
|
+
const raw = new THREE.CapsuleGeometry(0.35, 0.7, 16, 32);
|
|
91
|
+
console.log('raw:', edgeStats(raw.index.array, raw.index.count/3));
|
|
92
|
+
const posOnly = new THREE.BufferGeometry();
|
|
93
|
+
posOnly.setAttribute('position', raw.getAttribute('position').clone());
|
|
94
|
+
posOnly.setIndex(raw.index.clone());
|
|
95
|
+
const merged = mergeVertices(posOnly, 1e-5);
|
|
96
|
+
console.log('mergeVertices (artifact):', edgeStats(merged.index.array, merged.index.count/3));
|
|
97
|
+
const pos = raw.getAttribute('position');
|
|
98
|
+
const keyOf = (i) => Math.round(pos.getX(i)*1e5)+':'+Math.round(pos.getY(i)*1e5)+':'+Math.round(pos.getZ(i)*1e5);
|
|
99
|
+
const remap = new Int32Array(pos.count); const seen = new Map(); let next = 0;
|
|
100
|
+
for (let i = 0; i < pos.count; i++) { const k = keyOf(i); if (!seen.has(k)) seen.set(k, next++); remap[i] = seen.get(k); }
|
|
101
|
+
let dropped = 0; const kept = [];
|
|
102
|
+
for (let o = 0; o < raw.index.count/3; o++) {
|
|
103
|
+
const a = remap[raw.index.array[o*3]], b = remap[raw.index.array[o*3+1]], c = remap[raw.index.array[o*3+2]];
|
|
104
|
+
if (a===b||b===c||a===c) { dropped++; continue; }
|
|
105
|
+
kept.push(a,b,c);
|
|
106
|
+
}
|
|
107
|
+
console.log('dedup + drop-degenerate (correct):', edgeStats(kept, kept.length/3), 'dropped', dropped);
|
|
108
|
+
"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**What Milestone 0 uses, and why it's still a reasonable choice even though
|
|
112
|
+
`THREE.CapsuleGeometry` turned out to be fixable:**
|
|
113
|
+
`forge/stage5_rig/emit_rig.py`'s `buildWatertightCapsule()` builds its own
|
|
114
|
+
grid from scratch — pole vertices shared once (not duplicated per fan
|
|
115
|
+
triangle), radial index taken `mod radialSegments` so the seam column never
|
|
116
|
+
exists as separate vertices in the first place. That's watertight by
|
|
117
|
+
construction rather than by a weld step (0 boundary / 0 non-manifold at every
|
|
118
|
+
configuration tried, no tolerance parameter to get wrong), which is still a
|
|
119
|
+
simpler property to depend on for a kill test than "call `mergeVertices`,
|
|
120
|
+
then remember it needs a degenerate-triangle-dropping pass too, on top of
|
|
121
|
+
being position-only." It is not a drop-in replacement for
|
|
122
|
+
`THREE.CapsuleGeometry` as used generally by the pipeline (arbitrary
|
|
123
|
+
placement/orientation via `component.geometryDescriptor`), and I have not
|
|
124
|
+
attempted to make it one.
|
|
125
|
+
|
|
126
|
+
**Update on the real pipeline:** at the time this was first written,
|
|
127
|
+
`generate_threejs_factory.py:1025` emitted the raw, unwelded
|
|
128
|
+
`THREE.CapsuleGeometry` call directly, so the 194-boundary-edge defect was
|
|
129
|
+
live in real output. `worker-flatten` has since ported an adapted copy of
|
|
130
|
+
`buildWatertightCapsule` into `generate_threejs_factory.py` for the general
|
|
131
|
+
"capsule" primitive (see `forge/tests/test_primitive_watertightness.py`), so
|
|
132
|
+
that specific defect is fixed in the real pipeline as of this writing — this
|
|
133
|
+
section is now a historical record of the investigation, not an open
|
|
134
|
+
blocker. Decision on keeping two independently-verified copies of the
|
|
135
|
+
builder (mine here, worker-flatten's in the factory) rather than a shared
|
|
136
|
+
runtime module: see the message thread with worker-flatten, 2026-07-30 —
|
|
137
|
+
`stage5_rig` is deliberately standalone until WS-C integration, and the two
|
|
138
|
+
copies have legitimate purpose-specific differences (UV attribute, normals
|
|
139
|
+
timing).
|
|
140
|
+
|
|
141
|
+
## Gate (b) needs the mesh to actually carry geometry near the joint
|
|
142
|
+
|
|
143
|
+
Documented in the gate report proper (message to team-lead), not repeated
|
|
144
|
+
here in full: the first version of `buildWatertightCapsule()` had exactly one
|
|
145
|
+
quad band for the whole cylindrical shaft, so no vertex existed anywhere near
|
|
146
|
+
an interior joint's pivot. Fixed by adding `heightSegments`, derived from the
|
|
147
|
+
smallest envelope radius in play (`RING_RESOLUTION_DIVISOR = 3.0` rings per
|
|
148
|
+
radius) rather than a hardcoded ring count, so resolution scales if the
|
|
149
|
+
capsule or the bone spacing changes.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Milestone 0 rig kill test — standalone, not wired into the main pipeline.
|
|
2
|
+
|
|
3
|
+
See docs/PLAN_1.5_ANIMATION_READY_RIGS.md. This package intentionally does not
|
|
4
|
+
import from or get imported by generate_threejs_factory.py: integration is a
|
|
5
|
+
later milestone. Everything here is pure Python 3.10+ stdlib.
|
|
6
|
+
"""
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
"""Milestone 0 rig emitter: RigSpec -> standalone TypeScript.
|
|
2
|
+
|
|
3
|
+
Turns a hand-written RigSpec (forge/stage5_rig/rig_spec.py) plus a small side
|
|
4
|
+
channel of component bounding-box extents into a self-contained .ts module
|
|
5
|
+
that builds a real THREE.Bone hierarchy + THREE.Skeleton, skins a single
|
|
6
|
+
capsule mesh with the weight function from PLAN_1.5 §4, and binds it.
|
|
7
|
+
|
|
8
|
+
Standalone on purpose. Does NOT import from or get called by
|
|
9
|
+
generate_threejs_factory.py — integration is a later milestone, and that file
|
|
10
|
+
is dirty in this checkout.
|
|
11
|
+
|
|
12
|
+
MILESTONE-0 SCOPE NOTE: the geometry this emitter builds is a synthetic
|
|
13
|
+
watertight capsule constructed directly from the bone chain span, not a
|
|
14
|
+
subject-derived mesh from the real pipeline (stage1/stage2 output). Wiring
|
|
15
|
+
this weight function to real emitted geometry is future work; this file only
|
|
16
|
+
answers "can a generator emit a working skinned rig from a spec at all."
|
|
17
|
+
|
|
18
|
+
MILESTONE-0 SIMPLIFICATION: the capsule builder assumes the bone chain is a
|
|
19
|
+
single straight line along local +Y/-Y (matching the capsule's own
|
|
20
|
+
construction axis). Off-axis or branching chains are out of scope here.
|
|
21
|
+
|
|
22
|
+
Pure Python 3.10+ stdlib. No pip installs, no string.Template brace-escaping
|
|
23
|
+
footguns — plain token replacement is used instead of str.format()/f-strings
|
|
24
|
+
against the JS/TS body, because that body is full of literal `{`/`}`.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import json
|
|
30
|
+
import math
|
|
31
|
+
from typing import Optional
|
|
32
|
+
|
|
33
|
+
from .rig_spec import BoneSpec, RigSpec, derive_envelope_radius, validate_rig_spec
|
|
34
|
+
|
|
35
|
+
_TEMPLATE = r"""// AUTO-GENERATED by forge/stage5_rig/emit_rig.py — Milestone 0 rig kill test.
|
|
36
|
+
// Do not hand-edit; regenerate from the RigSpec instead.
|
|
37
|
+
import * as THREE from 'three';
|
|
38
|
+
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// RigSpec-derived constants. Every number below traces to the hand-written
|
|
41
|
+
// RigSpec and the derived-not-proposed envelope radius formula (PLAN_1.5 §4.3).
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
export const BONE_IDS = __BONE_IDS_JSON__;
|
|
44
|
+
export const PARENT = __PARENT_JSON__;
|
|
45
|
+
export const JOINT_POS = __JOINT_POS_JSON__;
|
|
46
|
+
export const TIP_POS = __TIP_POS_JSON__;
|
|
47
|
+
export const ENVELOPE_RADIUS = __ENVELOPE_RADIUS_JSON__;
|
|
48
|
+
export const OVERLAP_FACTOR = __OVERLAP_FACTOR__;
|
|
49
|
+
|
|
50
|
+
const CAPSULE_RADIUS = __CAPSULE_RADIUS__;
|
|
51
|
+
const CAPSULE_CYL_LENGTH = __CAPSULE_CYL_LENGTH__;
|
|
52
|
+
const CAPSULE_CENTER_Y = __CAPSULE_CENTER_Y__;
|
|
53
|
+
const CAP_SEGMENTS = __CAP_SEGMENTS__;
|
|
54
|
+
const RADIAL_SEGMENTS = __RADIAL_SEGMENTS__;
|
|
55
|
+
const HEIGHT_SEGMENTS = __HEIGHT_SEGMENTS__;
|
|
56
|
+
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Watertight-by-construction capsule: shared pole vertices, modulo-wrapped
|
|
59
|
+
// radial rings (no UV-seam vertex duplication). three@0.169's own
|
|
60
|
+
// THREE.CapsuleGeometry was measured (during design of this emitter) to leave
|
|
61
|
+
// ~98 boundary edges even after BufferGeometryUtils.mergeVertices on a
|
|
62
|
+
// position-only copy of it, because its radial seam column is a genuine
|
|
63
|
+
// second set of vertex indices at (numerically, not exactly) the same
|
|
64
|
+
// position that a 1e-5 weld does not always collapse cleanly at the poles.
|
|
65
|
+
// Building the grid so the seam never exists (radial index taken mod
|
|
66
|
+
// RADIAL_SEGMENTS) sidesteps that fragility entirely and is exact, not
|
|
67
|
+
// tolerance-dependent.
|
|
68
|
+
//
|
|
69
|
+
// heightSegments subdivides the CYLINDRICAL band into multiple rings (not
|
|
70
|
+
// just the two equators). Without this, a single quad band spans the whole
|
|
71
|
+
// cylinder and no vertex sits anywhere near an interior bone's pivot, which
|
|
72
|
+
// silently defeats a pose-sweep gate: rotating a joint whose bone segment
|
|
73
|
+
// lies entirely inside that one quad band only swings a rigid cap, never
|
|
74
|
+
// actually samples deformation near the joint. heightSegments is chosen by
|
|
75
|
+
// the caller (see emit_typescript()) from the derived envelope radius, not
|
|
76
|
+
// hardcoded here.
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
function buildWatertightCapsule(radius, cylLength, capSegments, radialSegments, heightSegments) {
|
|
79
|
+
const positions = [];
|
|
80
|
+
const indices = [];
|
|
81
|
+
const halfCyl = cylLength / 2;
|
|
82
|
+
|
|
83
|
+
const bottomPoleIndex = positions.length / 3;
|
|
84
|
+
positions.push(0, -halfCyl - radius, 0);
|
|
85
|
+
|
|
86
|
+
const ringStarts = [];
|
|
87
|
+
for (let ring = 1; ring <= capSegments; ring++) {
|
|
88
|
+
const phi = (Math.PI / 2) * (ring / capSegments);
|
|
89
|
+
const y = -halfCyl - radius * Math.cos(phi);
|
|
90
|
+
const r = radius * Math.sin(phi);
|
|
91
|
+
const start = positions.length / 3;
|
|
92
|
+
ringStarts.push(start);
|
|
93
|
+
for (let radial = 0; radial < radialSegments; radial++) {
|
|
94
|
+
const theta = (radial / radialSegments) * Math.PI * 2;
|
|
95
|
+
positions.push(r * Math.cos(theta), y, r * Math.sin(theta));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Cylinder rings: heightSegments steps from the bottom equator (already the
|
|
100
|
+
// last entry of ringStarts, at y=-halfCyl) up to and including the top
|
|
101
|
+
// equator (y=+halfCyl). This is what puts real geometry along the whole
|
|
102
|
+
// shaft, not just at its two ends.
|
|
103
|
+
const cylinderRingStarts = [];
|
|
104
|
+
if (cylLength > 0) {
|
|
105
|
+
for (let step = 1; step <= heightSegments; step++) {
|
|
106
|
+
const y = -halfCyl + (cylLength * step) / heightSegments;
|
|
107
|
+
const start = positions.length / 3;
|
|
108
|
+
cylinderRingStarts.push(start);
|
|
109
|
+
for (let radial = 0; radial < radialSegments; radial++) {
|
|
110
|
+
const theta = (radial / radialSegments) * Math.PI * 2;
|
|
111
|
+
positions.push(radius * Math.cos(theta), y, radius * Math.sin(theta));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const topEquatorStart = cylLength > 0
|
|
116
|
+
? cylinderRingStarts[cylinderRingStarts.length - 1]
|
|
117
|
+
: ringStarts[ringStarts.length - 1];
|
|
118
|
+
|
|
119
|
+
const topRingStarts = [];
|
|
120
|
+
for (let ring = capSegments - 1; ring >= 1; ring--) {
|
|
121
|
+
const phi = (Math.PI / 2) * (ring / capSegments);
|
|
122
|
+
const y = halfCyl + radius * Math.cos(phi);
|
|
123
|
+
const r = radius * Math.sin(phi);
|
|
124
|
+
const start = positions.length / 3;
|
|
125
|
+
topRingStarts.push(start);
|
|
126
|
+
for (let radial = 0; radial < radialSegments; radial++) {
|
|
127
|
+
const theta = (radial / radialSegments) * Math.PI * 2;
|
|
128
|
+
positions.push(r * Math.cos(theta), y, r * Math.sin(theta));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const topPoleIndex = positions.length / 3;
|
|
133
|
+
positions.push(0, halfCyl + radius, 0);
|
|
134
|
+
|
|
135
|
+
const firstBottomRing = ringStarts[0];
|
|
136
|
+
for (let radial = 0; radial < radialSegments; radial++) {
|
|
137
|
+
const next = (radial + 1) % radialSegments;
|
|
138
|
+
indices.push(bottomPoleIndex, firstBottomRing + radial, firstBottomRing + next);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const allRings = [...ringStarts, ...cylinderRingStarts, ...topRingStarts];
|
|
142
|
+
for (let i = 0; i < allRings.length - 1; i++) {
|
|
143
|
+
const a = allRings[i];
|
|
144
|
+
const b = allRings[i + 1];
|
|
145
|
+
for (let radial = 0; radial < radialSegments; radial++) {
|
|
146
|
+
const next = (radial + 1) % radialSegments;
|
|
147
|
+
indices.push(a + radial, a + next, b + next);
|
|
148
|
+
indices.push(a + radial, b + next, b + radial);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const lastRing = allRings[allRings.length - 1];
|
|
153
|
+
for (let radial = 0; radial < radialSegments; radial++) {
|
|
154
|
+
const next = (radial + 1) % radialSegments;
|
|
155
|
+
indices.push(topPoleIndex, lastRing + next, lastRing + radial);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const geometry = new THREE.BufferGeometry();
|
|
159
|
+
geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(positions), 3));
|
|
160
|
+
geometry.setIndex(indices);
|
|
161
|
+
return geometry;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// PLAN_1.5 §4 weight function — the ONE function, evaluated over the
|
|
166
|
+
// complete bone set, for every mesh. No mesh-id / vertex-index branching:
|
|
167
|
+
// only positions, the segment endpoints, and the derived envelope radius.
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
const _closestScratch = new THREE.Vector3();
|
|
170
|
+
function closestPointOnSegment(p, s, e, out) {
|
|
171
|
+
const abx = e[0] - s[0];
|
|
172
|
+
const aby = e[1] - s[1];
|
|
173
|
+
const abz = e[2] - s[2];
|
|
174
|
+
const apx = p.x - s[0];
|
|
175
|
+
const apy = p.y - s[1];
|
|
176
|
+
const apz = p.z - s[2];
|
|
177
|
+
const abLenSq = abx * abx + aby * aby + abz * abz;
|
|
178
|
+
const t = abLenSq > 1e-12
|
|
179
|
+
? THREE.MathUtils.clamp((apx * abx + apy * aby + apz * abz) / abLenSq, 0, 1)
|
|
180
|
+
: 0;
|
|
181
|
+
out.set(s[0] + abx * t, s[1] + aby * t, s[2] + abz * t);
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function distanceToSegment(p, s, e) {
|
|
186
|
+
closestPointOnSegment(p, s, e, _closestScratch);
|
|
187
|
+
return p.distanceTo(_closestScratch);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Returns { indices: number[4], weights: number[4], fallback: boolean }. */
|
|
191
|
+
function computeVertexWeights(p, boneIndexOf) {
|
|
192
|
+
const scored = BONE_IDS.map((id) => {
|
|
193
|
+
const d = distanceToSegment(p, JOINT_POS[id], TIP_POS[id]);
|
|
194
|
+
const u = d / ENVELOPE_RADIUS[id];
|
|
195
|
+
const w = Math.max(0, 1 - u * u) ** 2;
|
|
196
|
+
return { id, d, w };
|
|
197
|
+
});
|
|
198
|
+
scored.sort((a, b) => b.w - a.w);
|
|
199
|
+
const kept = scored.slice(0, 4);
|
|
200
|
+
const total = kept.reduce((sum, c) => sum + c.w, 0);
|
|
201
|
+
|
|
202
|
+
const indices = [0, 0, 0, 0];
|
|
203
|
+
const weights = [0, 0, 0, 0];
|
|
204
|
+
|
|
205
|
+
if (total > 0) {
|
|
206
|
+
for (let slot = 0; slot < 4; slot++) {
|
|
207
|
+
if (slot < kept.length) {
|
|
208
|
+
indices[slot] = boneIndexOf.get(kept[slot].id);
|
|
209
|
+
weights[slot] = kept[slot].w / total;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return { indices, weights, fallback: false };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Mandatory zero-sum fallback (PLAN_1.5 §4 / ADR-8): every kept weight is
|
|
216
|
+
// zero (vertex outside every envelope). three.js's own
|
|
217
|
+
// normalizeSkinWeights() would otherwise rewrite this to (1,0,0,0) against
|
|
218
|
+
// bone 0 regardless of distance. Instead: find the absolutely nearest bone
|
|
219
|
+
// ignoring R_b and pin weight 1.0 to it.
|
|
220
|
+
let nearestId = BONE_IDS[0];
|
|
221
|
+
let nearestDistance = Infinity;
|
|
222
|
+
for (const id of BONE_IDS) {
|
|
223
|
+
const d = distanceToSegment(p, JOINT_POS[id], TIP_POS[id]);
|
|
224
|
+
if (d < nearestDistance) {
|
|
225
|
+
nearestDistance = d;
|
|
226
|
+
nearestId = id;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
indices[0] = boneIndexOf.get(nearestId);
|
|
230
|
+
weights[0] = 1;
|
|
231
|
+
return { indices, weights, fallback: true };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function createRigMilestone0() {
|
|
235
|
+
const bones = {};
|
|
236
|
+
for (const id of BONE_IDS) {
|
|
237
|
+
bones[id] = new THREE.Bone();
|
|
238
|
+
bones[id].name = id;
|
|
239
|
+
}
|
|
240
|
+
let root = null;
|
|
241
|
+
for (const id of BONE_IDS) {
|
|
242
|
+
const parentId = PARENT[id];
|
|
243
|
+
const j = JOINT_POS[id];
|
|
244
|
+
if (parentId === null) {
|
|
245
|
+
root = bones[id];
|
|
246
|
+
bones[id].position.set(j[0], j[1], j[2]);
|
|
247
|
+
} else {
|
|
248
|
+
const pj = JOINT_POS[parentId];
|
|
249
|
+
bones[id].position.set(j[0] - pj[0], j[1] - pj[1], j[2] - pj[2]);
|
|
250
|
+
bones[parentId].add(bones[id]);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const geometry = buildWatertightCapsule(CAPSULE_RADIUS, CAPSULE_CYL_LENGTH, CAP_SEGMENTS, RADIAL_SEGMENTS, HEIGHT_SEGMENTS);
|
|
255
|
+
geometry.translate(0, CAPSULE_CENTER_Y, 0);
|
|
256
|
+
|
|
257
|
+
const boneIndexOf = new Map(BONE_IDS.map((id, i) => [id, i]));
|
|
258
|
+
const position = geometry.getAttribute('position');
|
|
259
|
+
const skinIndices = new Uint16Array(position.count * 4);
|
|
260
|
+
const skinWeights = new Float32Array(position.count * 4);
|
|
261
|
+
const fallbackVertices = [];
|
|
262
|
+
const point = new THREE.Vector3();
|
|
263
|
+
for (let vertex = 0; vertex < position.count; vertex++) {
|
|
264
|
+
point.fromBufferAttribute(position, vertex);
|
|
265
|
+
const { indices, weights, fallback } = computeVertexWeights(point, boneIndexOf);
|
|
266
|
+
for (let slot = 0; slot < 4; slot++) {
|
|
267
|
+
skinIndices[vertex * 4 + slot] = indices[slot];
|
|
268
|
+
skinWeights[vertex * 4 + slot] = weights[slot];
|
|
269
|
+
}
|
|
270
|
+
if (fallback) fallbackVertices.push(vertex);
|
|
271
|
+
}
|
|
272
|
+
geometry.setAttribute('skinIndex', new THREE.Uint16BufferAttribute(skinIndices, 4));
|
|
273
|
+
geometry.setAttribute('skinWeight', new THREE.Float32BufferAttribute(skinWeights, 4));
|
|
274
|
+
geometry.computeVertexNormals();
|
|
275
|
+
geometry.computeBoundingBox();
|
|
276
|
+
geometry.computeBoundingSphere();
|
|
277
|
+
|
|
278
|
+
const mesh = new THREE.SkinnedMesh(geometry, new THREE.MeshBasicMaterial());
|
|
279
|
+
mesh.name = 'rig-milestone0-arm';
|
|
280
|
+
// AttachedBindMode (the default) requires the skeleton to share the mesh's
|
|
281
|
+
// world space, which requires the root bone to be a child of the mesh, not
|
|
282
|
+
// a sibling. Learned from createRiggedDragon.ts (`body.add(bones.root)`).
|
|
283
|
+
mesh.add(root);
|
|
284
|
+
const skeleton = new THREE.Skeleton(BONE_IDS.map((id) => bones[id]));
|
|
285
|
+
mesh.bindMode = THREE.AttachedBindMode;
|
|
286
|
+
mesh.bind(skeleton);
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
mesh,
|
|
290
|
+
skeleton,
|
|
291
|
+
bones,
|
|
292
|
+
meta: {
|
|
293
|
+
envelopeRadius: ENVELOPE_RADIUS,
|
|
294
|
+
jointPos: JOINT_POS,
|
|
295
|
+
tipPos: TIP_POS,
|
|
296
|
+
fallbackVertices,
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _fmt_num(value: float) -> str:
|
|
304
|
+
if float(value).is_integer():
|
|
305
|
+
return repr(float(value))
|
|
306
|
+
return repr(float(value))
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
# PLAN_1.5 §4's weight function is continuous, so it must actually be SAMPLED
|
|
310
|
+
# at a resolution finer than the smallest envelope radius in play, or a
|
|
311
|
+
# pose-sweep gate can silently test nothing near a joint (see
|
|
312
|
+
# emit_typescript()'s height_segments derivation below, and the Milestone 0
|
|
313
|
+
# report for the concrete failure this caught: a single quad band spanning
|
|
314
|
+
# the whole cylinder let the elbow's influenced region skip past the pivot
|
|
315
|
+
# entirely). 3 is not tuned per RigSpec; it is a fixed, stated ratio applied
|
|
316
|
+
# uniformly to whatever envelope radius the spec/components produce.
|
|
317
|
+
RING_RESOLUTION_DIVISOR = 3.0
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def emit_typescript(
|
|
321
|
+
spec: RigSpec,
|
|
322
|
+
component_extents: dict[str, tuple[float, float]],
|
|
323
|
+
capsule_radius: float,
|
|
324
|
+
overlap_factor: float = 1.2,
|
|
325
|
+
cap_segments: int = 8,
|
|
326
|
+
radial_segments: int = 16,
|
|
327
|
+
height_segments: Optional[int] = None,
|
|
328
|
+
) -> str:
|
|
329
|
+
"""Emit the Milestone 0 TypeScript module for `spec`.
|
|
330
|
+
|
|
331
|
+
`height_segments` subdivides the capsule's cylindrical band lengthwise.
|
|
332
|
+
Left as None (the default), it is DERIVED — not hand-picked per spec —
|
|
333
|
+
from the smallest derived envelope radius in play, at
|
|
334
|
+
RING_RESOLUTION_DIVISOR rings per radius, so every bone's influence band
|
|
335
|
+
is guaranteed several rings of real geometry rather than risking a single
|
|
336
|
+
quad spanning past it. Pass an explicit value only to override for
|
|
337
|
+
testing.
|
|
338
|
+
|
|
339
|
+
Fails closed (raises ValueError) on:
|
|
340
|
+
- a RigSpec that does not pass validate_rig_spec()
|
|
341
|
+
- a bone chain that is not a straight vertical line (the milestone-0
|
|
342
|
+
capsule-construction simplification stated in this module's docstring)
|
|
343
|
+
- a bone referencing a component id missing from component_extents
|
|
344
|
+
"""
|
|
345
|
+
errors = validate_rig_spec(spec)
|
|
346
|
+
if errors:
|
|
347
|
+
raise ValueError("RigSpec rejected by validate_rig_spec: " + "; ".join(errors))
|
|
348
|
+
|
|
349
|
+
tip_pos = spec.resolve_tip_positions()
|
|
350
|
+
joint_pos = {b.id: b.joint_pos for b in spec.bones}
|
|
351
|
+
parent = {b.id: b.parent for b in spec.bones}
|
|
352
|
+
bone_ids = [b.id for b in spec.bones]
|
|
353
|
+
|
|
354
|
+
envelope_radius: dict[str, float] = {}
|
|
355
|
+
by_id: dict[str, BoneSpec] = spec.bone_by_id()
|
|
356
|
+
for bone in spec.bones:
|
|
357
|
+
if bone.component is None:
|
|
358
|
+
raise ValueError(f"bone '{bone.id}' has no component; cannot derive envelope radius")
|
|
359
|
+
if bone.component not in component_extents:
|
|
360
|
+
raise ValueError(
|
|
361
|
+
f"bone '{bone.id}' references component '{bone.component}' "
|
|
362
|
+
f"which is not present in component_extents"
|
|
363
|
+
)
|
|
364
|
+
width, depth = component_extents[bone.component]
|
|
365
|
+
envelope_radius[bone.id] = derive_envelope_radius(width, depth, overlap_factor)
|
|
366
|
+
|
|
367
|
+
# Milestone-0 simplification check: every joint/tip position must lie on
|
|
368
|
+
# a single straight vertical (Y-axis) line, matching the capsule builder.
|
|
369
|
+
all_points = [joint_pos[b] for b in bone_ids] + [tip_pos[b] for b in bone_ids]
|
|
370
|
+
xs = {round(p[0], 9) for p in all_points}
|
|
371
|
+
zs = {round(p[2], 9) for p in all_points}
|
|
372
|
+
if len(xs) != 1 or len(zs) != 1:
|
|
373
|
+
raise ValueError(
|
|
374
|
+
"Milestone-0 capsule builder requires a straight chain along the Y axis "
|
|
375
|
+
"(constant x and z across every jointPos/tipPos); this RigSpec is not one. "
|
|
376
|
+
"This is a stated milestone-0 scope limit, not a general capability."
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
root_bone = spec.root()
|
|
380
|
+
chain_top_y = root_bone.joint_pos[1]
|
|
381
|
+
leaf_ids = [b.id for b in spec.bones if not spec.children_of(b.id)]
|
|
382
|
+
if len(leaf_ids) != 1:
|
|
383
|
+
raise ValueError(
|
|
384
|
+
f"Milestone-0 capsule builder requires exactly one leaf bone (a single "
|
|
385
|
+
f"linear chain), found {len(leaf_ids)}: {leaf_ids}"
|
|
386
|
+
)
|
|
387
|
+
chain_bottom_y = tip_pos[leaf_ids[0]][1]
|
|
388
|
+
total_length = abs(chain_top_y - chain_bottom_y)
|
|
389
|
+
cyl_length = total_length - 2 * capsule_radius
|
|
390
|
+
if cyl_length <= 0:
|
|
391
|
+
raise ValueError(
|
|
392
|
+
f"capsule_radius {capsule_radius} is too large for chain length {total_length}: "
|
|
393
|
+
f"cylindrical section would be non-positive ({cyl_length})"
|
|
394
|
+
)
|
|
395
|
+
center_y = (chain_top_y + chain_bottom_y) / 2
|
|
396
|
+
|
|
397
|
+
if height_segments is None:
|
|
398
|
+
target_ring_spacing = min(envelope_radius.values()) / RING_RESOLUTION_DIVISOR
|
|
399
|
+
height_segments = max(4, math.ceil(cyl_length / target_ring_spacing))
|
|
400
|
+
|
|
401
|
+
replacements = {
|
|
402
|
+
"__BONE_IDS_JSON__": json.dumps(bone_ids),
|
|
403
|
+
"__PARENT_JSON__": json.dumps(parent),
|
|
404
|
+
"__JOINT_POS_JSON__": json.dumps(joint_pos),
|
|
405
|
+
"__TIP_POS_JSON__": json.dumps(tip_pos),
|
|
406
|
+
"__ENVELOPE_RADIUS_JSON__": json.dumps(envelope_radius),
|
|
407
|
+
"__OVERLAP_FACTOR__": _fmt_num(overlap_factor),
|
|
408
|
+
"__CAPSULE_RADIUS__": _fmt_num(capsule_radius),
|
|
409
|
+
"__CAPSULE_CYL_LENGTH__": _fmt_num(cyl_length),
|
|
410
|
+
"__CAPSULE_CENTER_Y__": _fmt_num(center_y),
|
|
411
|
+
"__CAP_SEGMENTS__": str(int(cap_segments)),
|
|
412
|
+
"__RADIAL_SEGMENTS__": str(int(radial_segments)),
|
|
413
|
+
"__HEIGHT_SEGMENTS__": str(int(height_segments)),
|
|
414
|
+
}
|
|
415
|
+
source = _TEMPLATE
|
|
416
|
+
for token, value in replacements.items():
|
|
417
|
+
if token not in source:
|
|
418
|
+
raise AssertionError(f"template token {token} not found — template/replacement drift")
|
|
419
|
+
source = source.replace(token, value)
|
|
420
|
+
return source
|