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,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"profile_schema_version": 1,
|
|
3
|
+
"defaults": {
|
|
4
|
+
"encoding": "utf-8",
|
|
5
|
+
"languages": [
|
|
6
|
+
"en",
|
|
7
|
+
"vi"
|
|
8
|
+
],
|
|
9
|
+
"source_extensions": [
|
|
10
|
+
".md",
|
|
11
|
+
".json",
|
|
12
|
+
".jsonl"
|
|
13
|
+
],
|
|
14
|
+
"tokenizer": {
|
|
15
|
+
"version": "1",
|
|
16
|
+
"unicode_normalization": "NFKC",
|
|
17
|
+
"casefold": true,
|
|
18
|
+
"accent_fold": "vi",
|
|
19
|
+
"preserve_identifiers": true,
|
|
20
|
+
"preserve_numbers": true
|
|
21
|
+
},
|
|
22
|
+
"aliases": {
|
|
23
|
+
"enabled": true,
|
|
24
|
+
"max_expansions": 1
|
|
25
|
+
},
|
|
26
|
+
"bm25": {
|
|
27
|
+
"k1": 1.5,
|
|
28
|
+
"b": 0.75
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"collections": {
|
|
32
|
+
"cs2": {
|
|
33
|
+
"source_roots": [],
|
|
34
|
+
"optional_source_roots": [
|
|
35
|
+
"docs/cs2/",
|
|
36
|
+
"docs/cs2-anatomy/"
|
|
37
|
+
],
|
|
38
|
+
"distilled_records": [
|
|
39
|
+
"docs/specs/vocabulary/cs2.jsonl",
|
|
40
|
+
"docs/specs/vocabulary/cs2_reconstruction.jsonl",
|
|
41
|
+
"docs/specs/vocabulary/core_3d.jsonl",
|
|
42
|
+
"docs/specs/vocabulary/core_3d_reconstruction.jsonl"
|
|
43
|
+
],
|
|
44
|
+
"documentation": "docs/specs/vocabulary/README.md",
|
|
45
|
+
"cache": ".cache/spec-search/cs2.json"
|
|
46
|
+
},
|
|
47
|
+
"core_3d": {
|
|
48
|
+
"source_roots": [],
|
|
49
|
+
"optional_source_roots": [],
|
|
50
|
+
"distilled_records": [
|
|
51
|
+
"docs/specs/vocabulary/core_3d.jsonl",
|
|
52
|
+
"docs/specs/vocabulary/core_3d_reconstruction.jsonl"
|
|
53
|
+
],
|
|
54
|
+
"documentation": "docs/specs/vocabulary/README.md",
|
|
55
|
+
"cache": ".cache/spec-search/core_3d.json"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, TextIO
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _pipeline(spec: dict[str, Any] | None) -> tuple[str, int, str, str]:
|
|
10
|
+
if not isinstance(spec, dict):
|
|
11
|
+
return "unknown", 0, "spec not loaded", "vg asset rebuild-object next <spec>"
|
|
12
|
+
pipeline = spec.get("sculptPipeline")
|
|
13
|
+
if not isinstance(pipeline, dict):
|
|
14
|
+
return "unknown", 0, "sculptPipeline is missing", "vg asset rebuild-object next <spec>"
|
|
15
|
+
current = str(pipeline.get("currentPass") or "unknown")
|
|
16
|
+
completed = pipeline.get("completedPasses", [])
|
|
17
|
+
count = len(completed) if isinstance(completed, list) else 0
|
|
18
|
+
reason = str(pipeline.get("blockedReason") or "none")
|
|
19
|
+
next_command = "none (pipeline complete)" if current == "complete" else "vg asset rebuild-object next <spec>"
|
|
20
|
+
return current, count, reason, next_command
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def emit_status(spec: dict[str, Any] | None = None, *, next_command: str | None = None, stream: TextIO = sys.stdout) -> None:
|
|
24
|
+
current, count, reason, default_next = _pipeline(spec)
|
|
25
|
+
print(f"STATUS pass={current} completed={count} blocked={reason} next={next_command or default_next}", file=stream)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def load_optional_spec(path: str | Path | None) -> dict[str, Any] | None:
|
|
29
|
+
if not path:
|
|
30
|
+
return None
|
|
31
|
+
try:
|
|
32
|
+
payload = json.loads(Path(path).expanduser().read_text(encoding="utf-8"))
|
|
33
|
+
except (OSError, json.JSONDecodeError):
|
|
34
|
+
return None
|
|
35
|
+
return payload if isinstance(payload, dict) else None
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
MAX_SUBDIVISION_ITERATIONS = 4
|
|
2
|
+
MAX_SUBDIVISION_QUAD_FACES = 100_000
|
|
3
|
+
|
|
4
|
+
CYLINDER_RADIAL_SEGMENTS = 48
|
|
5
|
+
CYLINDER_HEIGHT_SEGMENTS = 16
|
|
6
|
+
ATTACHMENT_CYLINDER_RADIAL_SEGMENTS = 32
|
|
7
|
+
ATTACHMENT_CYLINDER_HEIGHT_SEGMENTS = 12
|
|
8
|
+
CONE_SUBDIVISION_TOP_RADIUS = 0.0001
|
|
9
|
+
# A tapering ConeGeometry, unlike a constant-radius CylinderGeometry, does not weld
|
|
10
|
+
# cleanly at CYLINDER_HEIGHT_SEGMENTS (16): measured 2448 raw / 2160 welded boundary
|
|
11
|
+
# edges (a real topology defect, not a benign UV seam -- box/cylinder/sphere/torus/
|
|
12
|
+
# ellipsoid all weld to 0/0 at their own segment counts). A cone built with
|
|
13
|
+
# heightSegments=1 (three.js's own default) welds cleanly to 0/0, verified directly;
|
|
14
|
+
# a solid cone's lateral surface does not need internal height rings for shading or
|
|
15
|
+
# silhouette quality at rest, only the subdivision-requested substitute (a near-
|
|
16
|
+
# degenerate CylinderGeometry, unaffected by this constant) needs a denser cage.
|
|
17
|
+
CONE_HEIGHT_SEGMENTS = 1
|
|
18
|
+
SPHERE_WIDTH_SEGMENTS = 64
|
|
19
|
+
SPHERE_HEIGHT_SEGMENTS = 40
|
|
20
|
+
CAPSULE_CAP_SEGMENTS = 16
|
|
21
|
+
CAPSULE_RADIAL_SEGMENTS = 32
|
|
22
|
+
TORUS_TUBULAR_SEGMENTS = 24
|
|
23
|
+
TORUS_RADIAL_SEGMENTS = 96
|
|
24
|
+
PLANE_WIDTH_SEGMENTS = 24
|
|
25
|
+
PLANE_HEIGHT_SEGMENTS = 24
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# --- Tessellation tiers -------------------------------------------------------
|
|
29
|
+
#
|
|
30
|
+
# The constants above are the `hero` tier and stay the module-level defaults, so
|
|
31
|
+
# every existing caller keeps its current output byte-for-byte. A spec that wants
|
|
32
|
+
# a cheaper mesh selects a tier via `performanceBudget.targetTriangles`, which
|
|
33
|
+
# was already in the schema and read by nothing (`lodPlan` has the same problem;
|
|
34
|
+
# see decimate.py's docstring).
|
|
35
|
+
#
|
|
36
|
+
# Two floors are load-bearing and are asserted by `validate_tier()`:
|
|
37
|
+
#
|
|
38
|
+
# * HEIGHT segments >= MIN_JOINT_HEIGHT_SEGMENTS on anything a bone deforms. One
|
|
39
|
+
# quad spanning a joint leaves no vertex at the pivot, so the influenced region
|
|
40
|
+
# skips the joint entirely and the elbow collapses instead of bending.
|
|
41
|
+
#
|
|
42
|
+
# The value is 4, not the 3 of the standard "rule of three" (one loop on the
|
|
43
|
+
# joint plane, one supporting loop each side). External practice says 3 is the
|
|
44
|
+
# minimum; this repository already decided 3 was not enough. `emit_rig.py:399`
|
|
45
|
+
# derives its own ring count as `max(4, ceil(cyl_length / target_ring_spacing))`
|
|
46
|
+
# -- a hard floor of 4 -- in the same module whose NOTES.md documents the
|
|
47
|
+
# single-quad-band joint-pinch failure this floor exists to prevent. Where an
|
|
48
|
+
# in-repo measurement and an external rule of thumb disagree, the measurement
|
|
49
|
+
# wins, so this matches emit_rig.py rather than the textbook.
|
|
50
|
+
# * RADIAL segments >= MIN_RADIAL_SEGMENTS, below which a swept primitive stops
|
|
51
|
+
# reading as a round limb and the silhouette goes visibly polygonal.
|
|
52
|
+
MIN_JOINT_HEIGHT_SEGMENTS = 4
|
|
53
|
+
MIN_RADIAL_SEGMENTS = 6
|
|
54
|
+
|
|
55
|
+
# Deliberately NOT tiered. A tapering cone does not weld cleanly at higher height
|
|
56
|
+
# segment counts -- 2448 raw / 2160 welded boundary edges, a real topology defect,
|
|
57
|
+
# see the comment on CONE_HEIGHT_SEGMENTS above -- and 1 is the value that welds to
|
|
58
|
+
# 0/0. `validate_tier()` pins it so a future tier cannot quietly reintroduce that
|
|
59
|
+
# defect while chasing a triangle budget.
|
|
60
|
+
REQUIRED_CONE_HEIGHT_SEGMENTS = 1
|
|
61
|
+
|
|
62
|
+
TESSELLATION_TIERS: dict[str, dict[str, int]] = {
|
|
63
|
+
"low": {
|
|
64
|
+
"CYLINDER_RADIAL_SEGMENTS": 10,
|
|
65
|
+
"CYLINDER_HEIGHT_SEGMENTS": 4,
|
|
66
|
+
"ATTACHMENT_CYLINDER_RADIAL_SEGMENTS": 8,
|
|
67
|
+
"ATTACHMENT_CYLINDER_HEIGHT_SEGMENTS": 4,
|
|
68
|
+
"CONE_HEIGHT_SEGMENTS": 1,
|
|
69
|
+
"SPHERE_WIDTH_SEGMENTS": 16,
|
|
70
|
+
"SPHERE_HEIGHT_SEGMENTS": 10,
|
|
71
|
+
"CAPSULE_CAP_SEGMENTS": 4,
|
|
72
|
+
"CAPSULE_RADIAL_SEGMENTS": 8,
|
|
73
|
+
"TORUS_TUBULAR_SEGMENTS": 8,
|
|
74
|
+
"TORUS_RADIAL_SEGMENTS": 16,
|
|
75
|
+
"PLANE_WIDTH_SEGMENTS": 4,
|
|
76
|
+
"PLANE_HEIGHT_SEGMENTS": 4,
|
|
77
|
+
"BOX_SEGMENTS": 1,
|
|
78
|
+
"SDF_MAX_RESOLUTION": 24,
|
|
79
|
+
},
|
|
80
|
+
"standard": {
|
|
81
|
+
"CYLINDER_RADIAL_SEGMENTS": 24,
|
|
82
|
+
"CYLINDER_HEIGHT_SEGMENTS": 8,
|
|
83
|
+
"ATTACHMENT_CYLINDER_RADIAL_SEGMENTS": 16,
|
|
84
|
+
"ATTACHMENT_CYLINDER_HEIGHT_SEGMENTS": 6,
|
|
85
|
+
"CONE_HEIGHT_SEGMENTS": 1,
|
|
86
|
+
"SPHERE_WIDTH_SEGMENTS": 32,
|
|
87
|
+
"SPHERE_HEIGHT_SEGMENTS": 20,
|
|
88
|
+
"CAPSULE_CAP_SEGMENTS": 8,
|
|
89
|
+
"CAPSULE_RADIAL_SEGMENTS": 16,
|
|
90
|
+
"TORUS_TUBULAR_SEGMENTS": 12,
|
|
91
|
+
"TORUS_RADIAL_SEGMENTS": 48,
|
|
92
|
+
"PLANE_WIDTH_SEGMENTS": 12,
|
|
93
|
+
"PLANE_HEIGHT_SEGMENTS": 12,
|
|
94
|
+
"BOX_SEGMENTS": 4,
|
|
95
|
+
"SDF_MAX_RESOLUTION": 40,
|
|
96
|
+
},
|
|
97
|
+
"hero": {
|
|
98
|
+
"CYLINDER_RADIAL_SEGMENTS": CYLINDER_RADIAL_SEGMENTS,
|
|
99
|
+
"CYLINDER_HEIGHT_SEGMENTS": CYLINDER_HEIGHT_SEGMENTS,
|
|
100
|
+
"ATTACHMENT_CYLINDER_RADIAL_SEGMENTS": ATTACHMENT_CYLINDER_RADIAL_SEGMENTS,
|
|
101
|
+
"ATTACHMENT_CYLINDER_HEIGHT_SEGMENTS": ATTACHMENT_CYLINDER_HEIGHT_SEGMENTS,
|
|
102
|
+
"CONE_HEIGHT_SEGMENTS": CONE_HEIGHT_SEGMENTS,
|
|
103
|
+
"SPHERE_WIDTH_SEGMENTS": SPHERE_WIDTH_SEGMENTS,
|
|
104
|
+
"SPHERE_HEIGHT_SEGMENTS": SPHERE_HEIGHT_SEGMENTS,
|
|
105
|
+
"CAPSULE_CAP_SEGMENTS": CAPSULE_CAP_SEGMENTS,
|
|
106
|
+
"CAPSULE_RADIAL_SEGMENTS": CAPSULE_RADIAL_SEGMENTS,
|
|
107
|
+
"TORUS_TUBULAR_SEGMENTS": TORUS_TUBULAR_SEGMENTS,
|
|
108
|
+
"TORUS_RADIAL_SEGMENTS": TORUS_RADIAL_SEGMENTS,
|
|
109
|
+
"PLANE_WIDTH_SEGMENTS": PLANE_WIDTH_SEGMENTS,
|
|
110
|
+
"PLANE_HEIGHT_SEGMENTS": PLANE_HEIGHT_SEGMENTS,
|
|
111
|
+
"BOX_SEGMENTS": 12,
|
|
112
|
+
"SDF_MAX_RESOLUTION": 64,
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
DEFAULT_TESSELLATION_TIER = "hero"
|
|
117
|
+
|
|
118
|
+
# Measured, not guessed: a 61-component humanoid spec generated at `hero` builds
|
|
119
|
+
# 14,208 triangles (counted by constructing the emitted factory under node, not
|
|
120
|
+
# by parsing the source). The same primitive mix at each tier, using three.js's
|
|
121
|
+
# own triangle formulas, is what these thresholds are drawn from.
|
|
122
|
+
TIER_TRIANGLE_CEILINGS: tuple[tuple[int, str], ...] = (
|
|
123
|
+
(6_000, "low"),
|
|
124
|
+
(60_000, "standard"),
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def tier_for_target_triangles(target_triangles: object) -> str:
|
|
129
|
+
"""Pick a tessellation tier from `performanceBudget.targetTriangles`.
|
|
130
|
+
|
|
131
|
+
Anything missing, non-numeric or non-positive keeps the current behaviour
|
|
132
|
+
(`hero`), so specs written before this existed are unaffected.
|
|
133
|
+
"""
|
|
134
|
+
if isinstance(target_triangles, bool) or not isinstance(target_triangles, (int, float)):
|
|
135
|
+
return DEFAULT_TESSELLATION_TIER
|
|
136
|
+
if target_triangles <= 0:
|
|
137
|
+
return DEFAULT_TESSELLATION_TIER
|
|
138
|
+
for ceiling, tier in TIER_TRIANGLE_CEILINGS:
|
|
139
|
+
if target_triangles <= ceiling:
|
|
140
|
+
return tier
|
|
141
|
+
return DEFAULT_TESSELLATION_TIER
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def validate_tier(name: str) -> dict[str, int]:
|
|
145
|
+
"""Return a tier's segment table, refusing one that would break deformation."""
|
|
146
|
+
if name not in TESSELLATION_TIERS:
|
|
147
|
+
raise ValueError(
|
|
148
|
+
f"unknown tessellation tier {name!r}; expected one of {sorted(TESSELLATION_TIERS)}"
|
|
149
|
+
)
|
|
150
|
+
table = TESSELLATION_TIERS[name]
|
|
151
|
+
for key in ("CYLINDER_HEIGHT_SEGMENTS", "ATTACHMENT_CYLINDER_HEIGHT_SEGMENTS"):
|
|
152
|
+
if table[key] < MIN_JOINT_HEIGHT_SEGMENTS:
|
|
153
|
+
raise ValueError(
|
|
154
|
+
f"tier {name!r} sets {key}={table[key]}, below the "
|
|
155
|
+
f"{MIN_JOINT_HEIGHT_SEGMENTS}-segment floor a bone needs to deform a joint"
|
|
156
|
+
)
|
|
157
|
+
for key in (
|
|
158
|
+
"CYLINDER_RADIAL_SEGMENTS",
|
|
159
|
+
"ATTACHMENT_CYLINDER_RADIAL_SEGMENTS",
|
|
160
|
+
"CAPSULE_RADIAL_SEGMENTS",
|
|
161
|
+
):
|
|
162
|
+
if table[key] < MIN_RADIAL_SEGMENTS:
|
|
163
|
+
raise ValueError(
|
|
164
|
+
f"tier {name!r} sets {key}={table[key]}, below the "
|
|
165
|
+
f"{MIN_RADIAL_SEGMENTS}-segment floor a swept primitive needs to read as round"
|
|
166
|
+
)
|
|
167
|
+
if table["CONE_HEIGHT_SEGMENTS"] != REQUIRED_CONE_HEIGHT_SEGMENTS:
|
|
168
|
+
raise ValueError(
|
|
169
|
+
f"tier {name!r} sets CONE_HEIGHT_SEGMENTS={table['CONE_HEIGHT_SEGMENTS']}; a cone "
|
|
170
|
+
f"only welds cleanly at {REQUIRED_CONE_HEIGHT_SEGMENTS} and this is not a budget knob"
|
|
171
|
+
)
|
|
172
|
+
return table
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def segments_for_spec(spec: object) -> dict[str, int]:
|
|
176
|
+
"""Resolve the segment table a spec should generate with."""
|
|
177
|
+
budget = spec.get("performanceBudget") if isinstance(spec, dict) else None
|
|
178
|
+
target = budget.get("targetTriangles") if isinstance(budget, dict) else None
|
|
179
|
+
return validate_tier(tier_for_target_triangles(target))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def cylinder_source_face_count(radial_segments: int, height_segments: int) -> int:
|
|
183
|
+
return radial_segments * (height_segments + 1)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def capsule_source_face_count(cap_segments: int, radial_segments: int, height_segments: int = 1) -> int:
|
|
187
|
+
"""Return the exact triangle count emitted by `buildWatertightCapsule` in
|
|
188
|
+
generate_threejs_factory.py, which replaced THREE.CapsuleGeometry as the capsule
|
|
189
|
+
primitive's construction (see that file's `geometry_for()` and the
|
|
190
|
+
`buildWatertightCapsule` helper it emits). Raw THREE.CapsuleGeometry duplicates
|
|
191
|
+
every UV-seam vertex, same benign pattern as box/cylinder/sphere/torus -- it is
|
|
192
|
+
NOT actually non-manifold (a naive vertex-only mergeVertices() reports 64 such
|
|
193
|
+
edges, but that is a counting artifact from degenerate near-pole triangles, not
|
|
194
|
+
a real defect; confirmed by replicating subdivideCatmullClark's own degenerate-
|
|
195
|
+
aware vertex identity). `buildWatertightCapsule` is worth having regardless: it
|
|
196
|
+
is closed by construction (shared poles, radial index taken `% radialSegments`)
|
|
197
|
+
rather than relying on a weld, and has a smaller, exact triangle count: 2 pole
|
|
198
|
+
fans of `radial_segments` triangles each, plus `(2*cap_segments + height_segments
|
|
199
|
+
- 2)` ring bands of `2*radial_segments` triangles each -- fewer vertices for the
|
|
200
|
+
per-vertex skinning weight pass to visit. `height_segments` defaults to 1,
|
|
201
|
+
matching the one call site.
|
|
202
|
+
"""
|
|
203
|
+
return 2 * radial_segments * (2 * cap_segments + height_segments - 1)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def resolve_instanced_cluster_base(
|
|
207
|
+
primitive: str,
|
|
208
|
+
descriptor: dict[str, object],
|
|
209
|
+
valid_primitives: set[str],
|
|
210
|
+
) -> str:
|
|
211
|
+
if primitive != "instanced-cluster":
|
|
212
|
+
return primitive
|
|
213
|
+
base = descriptor.get("baseGeometry")
|
|
214
|
+
if isinstance(base, str) and base not in {"", "instanced-cluster"} and base in valid_primitives:
|
|
215
|
+
return base
|
|
216
|
+
return "box"
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
SUBDIVISION_SOURCE_FACE_ESTIMATES: dict[str, int] = {
|
|
220
|
+
"box": 6,
|
|
221
|
+
"sphere": 2 * SPHERE_WIDTH_SEGMENTS * SPHERE_HEIGHT_SEGMENTS,
|
|
222
|
+
"ellipsoid": 2 * SPHERE_WIDTH_SEGMENTS * SPHERE_HEIGHT_SEGMENTS,
|
|
223
|
+
"cylinder": cylinder_source_face_count(CYLINDER_RADIAL_SEGMENTS, CYLINDER_HEIGHT_SEGMENTS),
|
|
224
|
+
"cone": cylinder_source_face_count(CYLINDER_RADIAL_SEGMENTS, CYLINDER_HEIGHT_SEGMENTS),
|
|
225
|
+
"capsule": capsule_source_face_count(CAPSULE_CAP_SEGMENTS, CAPSULE_RADIAL_SEGMENTS),
|
|
226
|
+
"torus": 2 * TORUS_TUBULAR_SEGMENTS * TORUS_RADIAL_SEGMENTS,
|
|
227
|
+
"plane-card": 2 * PLANE_WIDTH_SEGMENTS * PLANE_HEIGHT_SEGMENTS,
|
|
228
|
+
}
|
|
229
|
+
ATTACHMENT_CYLINDER_SUBDIVISION_SOURCE_FACES = cylinder_source_face_count(
|
|
230
|
+
ATTACHMENT_CYLINDER_RADIAL_SEGMENTS,
|
|
231
|
+
ATTACHMENT_CYLINDER_HEIGHT_SEGMENTS,
|
|
232
|
+
)
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Region-painted vertex colour: the shape predicates, shared by the validator, the gate and TS.
|
|
2
|
+
|
|
3
|
+
WHY THIS EXISTS. A subject whose identity is a set of flat colour regions with hard boundaries --
|
|
4
|
+
a tuxedo cat's blaze, bib and socks; a livery stripe; a painted marking -- cannot be reproduced by
|
|
5
|
+
`rootTipGradient`, which is a single linear ramp along one axis, and must not be reproduced by a
|
|
6
|
+
texture, because this pipeline emits code and no image assets. The remaining honest representation
|
|
7
|
+
is per-vertex colour driven by a declared region shape.
|
|
8
|
+
|
|
9
|
+
The predicates live here, in Python, rather than only inside the emitted TypeScript, because the
|
|
10
|
+
region boundary is an identity feature and therefore has to be GATED -- and a gate that can only run
|
|
11
|
+
after a browser render is a gate that runs too late. `vg asset rebuild-object vertex-region-gate`
|
|
12
|
+
evaluates these same functions on exported geometry. `_VERTEX_PAINT_HELPER_SOURCE` in
|
|
13
|
+
generate_threejs_factory.py implements the identical maths in TS, and
|
|
14
|
+
`forge/tests/test_vertex_paint.py` holds the two to the same numbers on a fixture so they cannot
|
|
15
|
+
drift apart silently.
|
|
16
|
+
|
|
17
|
+
Three shapes, deliberately not more. Each earns its place on a real boundary class:
|
|
18
|
+
|
|
19
|
+
- `axis-band` a slab between two planes on one local axis -- a sock ending at an ankle height.
|
|
20
|
+
- `ellipsoid` a closed blob -- a nose pad, a moustache patch, an inner ear.
|
|
21
|
+
- `tapered-capsule` a segment whose radius varies from end to end -- a blaze running down a nose
|
|
22
|
+
bridge, a bib widening under the chin and tapering down the chest. This is the shape a constant
|
|
23
|
+
radius capsule cannot express, and it is the one the bib actually needs.
|
|
24
|
+
|
|
25
|
+
Every shape takes a `softness` in the component's own local units. `softness: 0` is a hard
|
|
26
|
+
boundary. A non-zero softness is a smooth ramp and is the ONLY approximation offered here -- it is
|
|
27
|
+
not fur, and anything using it to stand in for a fur fringe must say so.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import math
|
|
33
|
+
from typing import Any, Iterable, Sequence
|
|
34
|
+
|
|
35
|
+
VALID_REGION_KINDS = {"axis-band", "ellipsoid", "tapered-capsule"}
|
|
36
|
+
VALID_AXES = {"x", "y", "z"}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class VertexPaintError(ValueError):
|
|
40
|
+
"""Raised when a paint declaration cannot be evaluated as written."""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _as_vec3(value: Any, label: str) -> tuple[float, float, float]:
|
|
44
|
+
if not isinstance(value, (list, tuple)) or len(value) != 3:
|
|
45
|
+
raise VertexPaintError(f"{label} must be a 3-number array")
|
|
46
|
+
out = []
|
|
47
|
+
for item in value:
|
|
48
|
+
if isinstance(item, bool) or not isinstance(item, (int, float)):
|
|
49
|
+
raise VertexPaintError(f"{label} must be a 3-number array")
|
|
50
|
+
out.append(float(item))
|
|
51
|
+
return (out[0], out[1], out[2])
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _as_number(value: Any, label: str, *, minimum: float | None = None) -> float:
|
|
55
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
56
|
+
raise VertexPaintError(f"{label} must be a number")
|
|
57
|
+
number = float(value)
|
|
58
|
+
if minimum is not None and number < minimum:
|
|
59
|
+
raise VertexPaintError(f"{label} must be >= {minimum}")
|
|
60
|
+
return number
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def parse_hex_color(value: Any, label: str) -> tuple[float, float, float]:
|
|
64
|
+
"""`#rrggbb` to linear-ish 0..1 floats.
|
|
65
|
+
|
|
66
|
+
No colour-space conversion is applied: Three.js decides how to interpret a colour set from a
|
|
67
|
+
hex string, and doing a second conversion here would put the gate and the renderer on two
|
|
68
|
+
different values for the same authored colour.
|
|
69
|
+
"""
|
|
70
|
+
if not isinstance(value, str) or not value.startswith("#") or len(value) != 7:
|
|
71
|
+
raise VertexPaintError(f"{label} must be a '#rrggbb' string")
|
|
72
|
+
try:
|
|
73
|
+
red = int(value[1:3], 16)
|
|
74
|
+
green = int(value[3:5], 16)
|
|
75
|
+
blue = int(value[5:7], 16)
|
|
76
|
+
except ValueError as error:
|
|
77
|
+
raise VertexPaintError(f"{label} must be a '#rrggbb' string") from error
|
|
78
|
+
return (red / 255.0, green / 255.0, blue / 255.0)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def normalize_region(region: Any, label: str) -> dict[str, Any]:
|
|
82
|
+
"""Validate one region and return it in canonical form."""
|
|
83
|
+
if not isinstance(region, dict):
|
|
84
|
+
raise VertexPaintError(f"{label} must be an object")
|
|
85
|
+
kind = region.get("kind")
|
|
86
|
+
if kind not in VALID_REGION_KINDS:
|
|
87
|
+
raise VertexPaintError(
|
|
88
|
+
f"{label}.kind must be one of: {', '.join(sorted(VALID_REGION_KINDS))}"
|
|
89
|
+
)
|
|
90
|
+
region_id = region.get("id")
|
|
91
|
+
if not isinstance(region_id, str) or not region_id:
|
|
92
|
+
raise VertexPaintError(f"{label}.id must be a non-empty string")
|
|
93
|
+
color = region.get("color")
|
|
94
|
+
parse_hex_color(color, f"{label}.color")
|
|
95
|
+
softness = _as_number(region.get("softness", 0.0), f"{label}.softness", minimum=0.0)
|
|
96
|
+
|
|
97
|
+
canonical: dict[str, Any] = {
|
|
98
|
+
"id": region_id,
|
|
99
|
+
"kind": kind,
|
|
100
|
+
"color": color,
|
|
101
|
+
"softness": softness,
|
|
102
|
+
}
|
|
103
|
+
if kind == "axis-band":
|
|
104
|
+
axis = region.get("axis")
|
|
105
|
+
if axis not in VALID_AXES:
|
|
106
|
+
raise VertexPaintError(f"{label}.axis must be one of: x, y, z")
|
|
107
|
+
low = _as_number(region.get("min"), f"{label}.min")
|
|
108
|
+
high = _as_number(region.get("max"), f"{label}.max")
|
|
109
|
+
if high <= low:
|
|
110
|
+
raise VertexPaintError(f"{label}.max must be greater than {label}.min")
|
|
111
|
+
canonical.update({"axis": axis, "min": low, "max": high})
|
|
112
|
+
elif kind == "ellipsoid":
|
|
113
|
+
canonical["center"] = list(_as_vec3(region.get("center"), f"{label}.center"))
|
|
114
|
+
radii = _as_vec3(region.get("radii"), f"{label}.radii")
|
|
115
|
+
if min(radii) <= 0.0:
|
|
116
|
+
raise VertexPaintError(f"{label}.radii must all be positive")
|
|
117
|
+
canonical["radii"] = list(radii)
|
|
118
|
+
else:
|
|
119
|
+
canonical["start"] = list(_as_vec3(region.get("start"), f"{label}.start"))
|
|
120
|
+
canonical["end"] = list(_as_vec3(region.get("end"), f"{label}.end"))
|
|
121
|
+
start_radius = _as_number(region.get("startRadius"), f"{label}.startRadius", minimum=0.0)
|
|
122
|
+
end_radius = _as_number(region.get("endRadius"), f"{label}.endRadius", minimum=0.0)
|
|
123
|
+
if start_radius <= 0.0 and end_radius <= 0.0:
|
|
124
|
+
raise VertexPaintError(f"{label} needs at least one positive radius")
|
|
125
|
+
if canonical["start"] == canonical["end"]:
|
|
126
|
+
raise VertexPaintError(f"{label}.start and {label}.end must differ")
|
|
127
|
+
canonical.update({"startRadius": start_radius, "endRadius": end_radius})
|
|
128
|
+
return canonical
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def normalize_vertex_paint(paint: Any, label: str = "vertexPaint") -> dict[str, Any]:
|
|
132
|
+
"""Validate a whole `vertexPaint` block and return it in canonical form."""
|
|
133
|
+
if not isinstance(paint, dict):
|
|
134
|
+
raise VertexPaintError(f"{label} must be an object")
|
|
135
|
+
base_color = paint.get("baseColor")
|
|
136
|
+
parse_hex_color(base_color, f"{label}.baseColor")
|
|
137
|
+
regions = paint.get("regions")
|
|
138
|
+
if not isinstance(regions, list) or not regions:
|
|
139
|
+
raise VertexPaintError(f"{label}.regions must be a non-empty array")
|
|
140
|
+
seen: set[str] = set()
|
|
141
|
+
canonical_regions = []
|
|
142
|
+
for index, region in enumerate(regions):
|
|
143
|
+
canonical = normalize_region(region, f"{label}.regions[{index}]")
|
|
144
|
+
if canonical["id"] in seen:
|
|
145
|
+
raise VertexPaintError(f"{label}.regions has a duplicate id {canonical['id']!r}")
|
|
146
|
+
seen.add(canonical["id"])
|
|
147
|
+
canonical_regions.append(canonical)
|
|
148
|
+
return {"baseColor": base_color, "regions": canonical_regions}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _smoothstep(edge0: float, edge1: float, value: float) -> float:
|
|
152
|
+
if edge1 <= edge0:
|
|
153
|
+
return 0.0 if value < edge1 else 1.0
|
|
154
|
+
t = (value - edge0) / (edge1 - edge0)
|
|
155
|
+
t = 0.0 if t < 0.0 else 1.0 if t > 1.0 else t
|
|
156
|
+
return t * t * (3.0 - 2.0 * t)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def signed_distance(region: dict[str, Any], point: Sequence[float]) -> float:
|
|
160
|
+
"""Distance from `point` to the region boundary: negative inside, positive outside.
|
|
161
|
+
|
|
162
|
+
Reported in the component's own local units so `softness` is expressed in the same units as
|
|
163
|
+
the geometry, not in a normalised parameter nobody can measure against the reference.
|
|
164
|
+
"""
|
|
165
|
+
x, y, z = float(point[0]), float(point[1]), float(point[2])
|
|
166
|
+
kind = region["kind"]
|
|
167
|
+
if kind == "axis-band":
|
|
168
|
+
value = {"x": x, "y": y, "z": z}[region["axis"]]
|
|
169
|
+
low, high = region["min"], region["max"]
|
|
170
|
+
if value < low:
|
|
171
|
+
return low - value
|
|
172
|
+
if value > high:
|
|
173
|
+
return value - high
|
|
174
|
+
return -min(value - low, high - value)
|
|
175
|
+
if kind == "ellipsoid":
|
|
176
|
+
cx, cy, cz = region["center"]
|
|
177
|
+
rx, ry, rz = region["radii"]
|
|
178
|
+
# Scaled-space distance times the smallest radius: an exact SDF for a sphere and a
|
|
179
|
+
# conservative, continuous approximation for a general ellipsoid. It is monotonic in the
|
|
180
|
+
# true distance, which is all the boundary test and the softness ramp need.
|
|
181
|
+
q = math.sqrt(((x - cx) / rx) ** 2 + ((y - cy) / ry) ** 2 + ((z - cz) / rz) ** 2)
|
|
182
|
+
return (q - 1.0) * min(rx, ry, rz)
|
|
183
|
+
ax, ay, az = region["start"]
|
|
184
|
+
bx, by, bz = region["end"]
|
|
185
|
+
abx, aby, abz = bx - ax, by - ay, bz - az
|
|
186
|
+
apx, apy, apz = x - ax, y - ay, z - az
|
|
187
|
+
denominator = abx * abx + aby * aby + abz * abz
|
|
188
|
+
t = (apx * abx + apy * aby + apz * abz) / denominator if denominator > 0.0 else 0.0
|
|
189
|
+
t = 0.0 if t < 0.0 else 1.0 if t > 1.0 else t
|
|
190
|
+
closest = (ax + abx * t, ay + aby * t, az + abz * t)
|
|
191
|
+
distance = math.sqrt(
|
|
192
|
+
(x - closest[0]) ** 2 + (y - closest[1]) ** 2 + (z - closest[2]) ** 2
|
|
193
|
+
)
|
|
194
|
+
radius = region["startRadius"] + (region["endRadius"] - region["startRadius"]) * t
|
|
195
|
+
return distance - radius
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def region_weight(region: dict[str, Any], point: Sequence[float]) -> float:
|
|
199
|
+
"""How strongly a region claims a point: 1 well inside, 0 well outside."""
|
|
200
|
+
distance = signed_distance(region, point)
|
|
201
|
+
softness = region["softness"]
|
|
202
|
+
if softness <= 0.0:
|
|
203
|
+
return 1.0 if distance <= 0.0 else 0.0
|
|
204
|
+
return 1.0 - _smoothstep(-softness * 0.5, softness * 0.5, distance)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def paint_point(paint: dict[str, Any], point: Sequence[float]) -> tuple[float, float, float]:
|
|
208
|
+
"""The final colour at one local-space point, regions applied in declaration order."""
|
|
209
|
+
color = list(parse_hex_color(paint["baseColor"], "vertexPaint.baseColor"))
|
|
210
|
+
for region in paint["regions"]:
|
|
211
|
+
weight = region_weight(region, point)
|
|
212
|
+
if weight <= 0.0:
|
|
213
|
+
continue
|
|
214
|
+
target = parse_hex_color(region["color"], "region.color")
|
|
215
|
+
for channel in range(3):
|
|
216
|
+
color[channel] += (target[channel] - color[channel]) * weight
|
|
217
|
+
return (color[0], color[1], color[2])
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def dominant_region(paint: dict[str, Any], point: Sequence[float], threshold: float = 0.5) -> str:
|
|
221
|
+
"""Which region owns a point, or `'base'`.
|
|
222
|
+
|
|
223
|
+
Later regions win ties, matching `paint_point`'s ordered application: the last region to claim
|
|
224
|
+
a point is the one whose colour ends up dominating it.
|
|
225
|
+
"""
|
|
226
|
+
owner = "base"
|
|
227
|
+
for region in paint["regions"]:
|
|
228
|
+
if region_weight(region, point) >= threshold:
|
|
229
|
+
owner = region["id"]
|
|
230
|
+
return owner
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def classify_points(
|
|
234
|
+
paint: dict[str, Any], points: Iterable[Sequence[float]], threshold: float = 0.5
|
|
235
|
+
) -> list[str]:
|
|
236
|
+
return [dominant_region(paint, point, threshold) for point in points]
|