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,357 @@
|
|
|
1
|
+
"""Visual-hull descriptor validation, and the space carving it describes.
|
|
2
|
+
|
|
3
|
+
Until now this module only VALIDATED a `visualHull` descriptor; nothing carved one. A schema without
|
|
4
|
+
an implementation reads downstream as a shipped capability, and the pipeline's own docs cite visual
|
|
5
|
+
hull as a way to constrain hidden geometry it never actually constrained. `carve_visual_hull` closes
|
|
6
|
+
that: it consumes exactly the descriptor `validate_visual_hull_descriptor` accepts and returns a real
|
|
7
|
+
mesh.
|
|
8
|
+
|
|
9
|
+
What a visual hull can and cannot do, stated here because the caller must not over-read the result:
|
|
10
|
+
it is the INTERSECTION OF SILHOUETTE CONES, so it is an upper bound on the true shape. It can never
|
|
11
|
+
represent a concavity that does not break the silhouette from some supplied view -- an eye socket, the
|
|
12
|
+
inside of a cupped ear, the hollow of a bowl. With two views it is the intersection of two prisms,
|
|
13
|
+
which is loose; the third axis is unconstrained and the result extrudes along it. `carve_visual_hull`
|
|
14
|
+
reports `unconstrainedAxes` and `limitations` for exactly this reason: a hull is evidence about the
|
|
15
|
+
silhouette, not about the surface.
|
|
16
|
+
|
|
17
|
+
Image conventions, fixed here so a caller can match them:
|
|
18
|
+
front columns follow +x left-to-right, rows follow -y top-to-bottom
|
|
19
|
+
side columns follow +z left-to-right, rows follow -y top-to-bottom
|
|
20
|
+
top columns follow +x left-to-right, rows follow +z top-to-bottom
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import json
|
|
27
|
+
import math
|
|
28
|
+
import sys
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
from typing import Any
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
MAX_VISUAL_HULL_RESOLUTION = 32
|
|
34
|
+
MAX_VISUAL_HULL_TRIANGLES = 400_000
|
|
35
|
+
MIN_VISUAL_HULL_MASK_DIMENSION = 4
|
|
36
|
+
MAX_VISUAL_HULL_MASK_DIMENSION = 256
|
|
37
|
+
VALID_VISUAL_HULL_AXES = {"front", "side", "top"}
|
|
38
|
+
_DESCRIPTOR_FIELDS = {"projection", "boundsSpace", "bounds", "resolution", "triangleBudget", "views", "hiddenRegions"}
|
|
39
|
+
_VIEW_FIELDS = {"axis", "confidence", "mask"}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _is_number(value: Any) -> bool:
|
|
43
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _validate_vector(value: Any, label: str, errors: list[str]) -> None:
|
|
47
|
+
if not isinstance(value, list) or len(value) != 3:
|
|
48
|
+
errors.append(f"{label} must be [number, number, number]")
|
|
49
|
+
return
|
|
50
|
+
for index, item in enumerate(value):
|
|
51
|
+
if not _is_number(item):
|
|
52
|
+
errors.append(f"{label}[{index}] must be numeric")
|
|
53
|
+
elif not math.isfinite(float(item)):
|
|
54
|
+
errors.append(f"{label}[{index}] must be finite")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _validate_mask(value: Any, label: str, errors: list[str]) -> None:
|
|
58
|
+
if not isinstance(value, list) or not value:
|
|
59
|
+
errors.append(f"{label} must be a non-empty array of binary strings")
|
|
60
|
+
return
|
|
61
|
+
if len(value) < MIN_VISUAL_HULL_MASK_DIMENSION or len(value) > MAX_VISUAL_HULL_MASK_DIMENSION:
|
|
62
|
+
errors.append(
|
|
63
|
+
f"{label} height must be from {MIN_VISUAL_HULL_MASK_DIMENSION} to {MAX_VISUAL_HULL_MASK_DIMENSION}"
|
|
64
|
+
)
|
|
65
|
+
width: int | None = None
|
|
66
|
+
foreground = 0
|
|
67
|
+
for index, row in enumerate(value):
|
|
68
|
+
row_label = f"{label}[{index}]"
|
|
69
|
+
if not isinstance(row, str) or not row:
|
|
70
|
+
errors.append(f"{row_label} must be a non-empty binary string")
|
|
71
|
+
continue
|
|
72
|
+
if any(bit not in {"0", "1"} for bit in row):
|
|
73
|
+
errors.append(f"{row_label} must contain only '0' and '1'")
|
|
74
|
+
if width is None:
|
|
75
|
+
width = len(row)
|
|
76
|
+
elif len(row) != width:
|
|
77
|
+
errors.append(f"{label} rows must all have the same width")
|
|
78
|
+
foreground += row.count("1")
|
|
79
|
+
if width is not None and (width < MIN_VISUAL_HULL_MASK_DIMENSION or width > MAX_VISUAL_HULL_MASK_DIMENSION):
|
|
80
|
+
errors.append(
|
|
81
|
+
f"{label} width must be from {MIN_VISUAL_HULL_MASK_DIMENSION} to {MAX_VISUAL_HULL_MASK_DIMENSION}"
|
|
82
|
+
)
|
|
83
|
+
if foreground == 0:
|
|
84
|
+
errors.append(f"{label} must contain at least one foreground pixel")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def validate_visual_hull_descriptor(component_id: str, descriptor: Any, errors: list[str]) -> None:
|
|
88
|
+
label = f"component {component_id!r} geometryDescriptor.visualHull"
|
|
89
|
+
if not isinstance(descriptor, dict):
|
|
90
|
+
errors.append(f"{label} must be an object")
|
|
91
|
+
return
|
|
92
|
+
for field in descriptor:
|
|
93
|
+
if field not in _DESCRIPTOR_FIELDS:
|
|
94
|
+
errors.append(f"{label}.{field} is not supported")
|
|
95
|
+
if descriptor.get("projection") != "orthographic":
|
|
96
|
+
errors.append(f"{label}.projection must be 'orthographic'")
|
|
97
|
+
if descriptor.get("boundsSpace") != "component-local":
|
|
98
|
+
errors.append(f"{label}.boundsSpace must be 'component-local'")
|
|
99
|
+
bounds = descriptor.get("bounds")
|
|
100
|
+
if not isinstance(bounds, dict):
|
|
101
|
+
errors.append(f"{label}.bounds must be an object")
|
|
102
|
+
else:
|
|
103
|
+
minimum = bounds.get("min")
|
|
104
|
+
maximum = bounds.get("max")
|
|
105
|
+
_validate_vector(minimum, f"{label}.bounds.min", errors)
|
|
106
|
+
_validate_vector(maximum, f"{label}.bounds.max", errors)
|
|
107
|
+
if isinstance(minimum, list) and isinstance(maximum, list) and len(minimum) == len(maximum) == 3:
|
|
108
|
+
for index, (minimum_value, maximum_value) in enumerate(zip(minimum, maximum)):
|
|
109
|
+
if _is_number(minimum_value) and _is_number(maximum_value) and minimum_value >= maximum_value:
|
|
110
|
+
errors.append(f"{label}.bounds.min[{index}] must be less than bounds.max[{index}]")
|
|
111
|
+
resolution = descriptor.get("resolution")
|
|
112
|
+
if not isinstance(resolution, int) or isinstance(resolution, bool) or resolution < MIN_VISUAL_HULL_MASK_DIMENSION:
|
|
113
|
+
errors.append(f"{label}.resolution must be an integer from {MIN_VISUAL_HULL_MASK_DIMENSION} to {MAX_VISUAL_HULL_RESOLUTION}")
|
|
114
|
+
elif resolution > MAX_VISUAL_HULL_RESOLUTION:
|
|
115
|
+
errors.append(f"{label}.resolution must not exceed {MAX_VISUAL_HULL_RESOLUTION}")
|
|
116
|
+
triangle_budget = descriptor.get("triangleBudget")
|
|
117
|
+
if not isinstance(triangle_budget, int) or isinstance(triangle_budget, bool) or triangle_budget < 1:
|
|
118
|
+
errors.append(f"{label}.triangleBudget must be a positive integer")
|
|
119
|
+
elif triangle_budget > MAX_VISUAL_HULL_TRIANGLES:
|
|
120
|
+
errors.append(f"{label}.triangleBudget must not exceed {MAX_VISUAL_HULL_TRIANGLES}")
|
|
121
|
+
elif isinstance(resolution, int) and not isinstance(resolution, bool) and resolution >= MIN_VISUAL_HULL_MASK_DIMENSION:
|
|
122
|
+
worst_case_triangles = resolution**3 * 12
|
|
123
|
+
if triangle_budget < worst_case_triangles:
|
|
124
|
+
errors.append(
|
|
125
|
+
f"{label}.triangleBudget requires at least {worst_case_triangles} triangles for resolution {resolution}"
|
|
126
|
+
)
|
|
127
|
+
views = descriptor.get("views")
|
|
128
|
+
if not isinstance(views, list) or len(views) < 2:
|
|
129
|
+
errors.append(f"{label}.views must contain at least two views")
|
|
130
|
+
elif len(views) > len(VALID_VISUAL_HULL_AXES):
|
|
131
|
+
errors.append(f"{label}.views must not contain more than {len(VALID_VISUAL_HULL_AXES)} views")
|
|
132
|
+
axes: set[str] = set()
|
|
133
|
+
if isinstance(views, list):
|
|
134
|
+
for index, view in enumerate(views):
|
|
135
|
+
view_label = f"{label}.views[{index}]"
|
|
136
|
+
if not isinstance(view, dict):
|
|
137
|
+
errors.append(f"{view_label} must be an object")
|
|
138
|
+
continue
|
|
139
|
+
for field in view:
|
|
140
|
+
if field not in _VIEW_FIELDS:
|
|
141
|
+
errors.append(f"{view_label}.{field} is not supported")
|
|
142
|
+
axis = view.get("axis")
|
|
143
|
+
if axis not in VALID_VISUAL_HULL_AXES:
|
|
144
|
+
errors.append(f"{view_label}.axis must be one of: {', '.join(sorted(VALID_VISUAL_HULL_AXES))}")
|
|
145
|
+
elif axis in axes:
|
|
146
|
+
errors.append(f"{label}.views must use distinct axes")
|
|
147
|
+
else:
|
|
148
|
+
axes.add(axis)
|
|
149
|
+
confidence = view.get("confidence")
|
|
150
|
+
if not _is_number(confidence) or not 0 <= float(confidence) <= 1:
|
|
151
|
+
errors.append(f"{view_label}.confidence must be a number from 0 to 1")
|
|
152
|
+
_validate_mask(view.get("mask"), f"{view_label}.mask", errors)
|
|
153
|
+
hidden_regions = descriptor.get("hiddenRegions")
|
|
154
|
+
if hidden_regions is not None and (
|
|
155
|
+
not isinstance(hidden_regions, list)
|
|
156
|
+
or not all(isinstance(region, str) and region.strip() for region in hidden_regions)
|
|
157
|
+
):
|
|
158
|
+
errors.append(f"{label}.hiddenRegions must be an array of non-empty strings")
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
# ---------------------------------------------------------------------------
|
|
162
|
+
# Space carving
|
|
163
|
+
# ---------------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
# Which world axis each view's image column and row follow, and whether that axis runs backwards.
|
|
166
|
+
# Keeping this as data rather than branches means a new view axis is one table row, and means the
|
|
167
|
+
# convention documented in the module docstring is the convention the code actually uses.
|
|
168
|
+
_VIEW_AXES: dict[str, tuple[int, bool, int, bool]] = {
|
|
169
|
+
# axis: (column world axis, column reversed, row world axis, row reversed)
|
|
170
|
+
"front": (0, False, 1, True),
|
|
171
|
+
"side": (2, False, 1, True),
|
|
172
|
+
"top": (0, False, 2, False),
|
|
173
|
+
}
|
|
174
|
+
# The world axis each view leaves unconstrained -- the direction its camera looks along.
|
|
175
|
+
_VIEW_FREE_AXIS = {"front": 2, "side": 0, "top": 1}
|
|
176
|
+
_AXIS_NAMES = ("x", "y", "z")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _mask_lookup(mask: list[str]) -> tuple[int, int, list[str]]:
|
|
180
|
+
return len(mask[0]), len(mask), mask
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _sample_mask(mask: list[str], column: float, row: float) -> bool:
|
|
184
|
+
"""Nearest-texel test. Returns False outside the mask rather than raising.
|
|
185
|
+
|
|
186
|
+
Out-of-range means the voxel projects off the edge of that view's image, which is evidence the
|
|
187
|
+
voxel is NOT in the silhouette -- treating it as background is the conservative reading and keeps
|
|
188
|
+
the hull an upper bound rather than letting unseen space leak into the result.
|
|
189
|
+
"""
|
|
190
|
+
width, height, rows = _mask_lookup(mask)
|
|
191
|
+
x = int(column * width)
|
|
192
|
+
y = int(row * height)
|
|
193
|
+
if x < 0 or y < 0 or x >= width or y >= height:
|
|
194
|
+
return False
|
|
195
|
+
return rows[y][x] == "1"
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def carve_visual_hull(descriptor: dict[str, Any]) -> dict[str, Any]:
|
|
199
|
+
"""Intersect the supplied silhouette cones on a voxel grid and emit the boundary surface.
|
|
200
|
+
|
|
201
|
+
A voxel survives only if it lands on foreground in EVERY view. That is the definition of the
|
|
202
|
+
visual hull, and it is why one bad mask erases the model rather than degrading it -- the caller
|
|
203
|
+
should check `occupiedVoxelCount` before trusting a mesh, which is why it is reported.
|
|
204
|
+
"""
|
|
205
|
+
errors: list[str] = []
|
|
206
|
+
validate_visual_hull_descriptor("carve", descriptor, errors)
|
|
207
|
+
if errors:
|
|
208
|
+
raise ValueError("; ".join(errors))
|
|
209
|
+
|
|
210
|
+
bounds = descriptor["bounds"]
|
|
211
|
+
low = [float(v) for v in bounds["min"]]
|
|
212
|
+
high = [float(v) for v in bounds["max"]]
|
|
213
|
+
resolution = int(descriptor["resolution"])
|
|
214
|
+
views = descriptor["views"]
|
|
215
|
+
step = [(high[axis] - low[axis]) / resolution for axis in range(3)]
|
|
216
|
+
|
|
217
|
+
def centre(index: int, axis: int) -> float:
|
|
218
|
+
return low[axis] + (index + 0.5) * step[axis]
|
|
219
|
+
|
|
220
|
+
occupied: set[tuple[int, int, int]] = set()
|
|
221
|
+
for ix in range(resolution):
|
|
222
|
+
cx = centre(ix, 0)
|
|
223
|
+
for iy in range(resolution):
|
|
224
|
+
cy = centre(iy, 1)
|
|
225
|
+
for iz in range(resolution):
|
|
226
|
+
cz = centre(iz, 2)
|
|
227
|
+
point = (cx, cy, cz)
|
|
228
|
+
inside = True
|
|
229
|
+
for view in views:
|
|
230
|
+
column_axis, column_flip, row_axis, row_flip = _VIEW_AXES[view["axis"]]
|
|
231
|
+
span_c = high[column_axis] - low[column_axis]
|
|
232
|
+
span_r = high[row_axis] - low[row_axis]
|
|
233
|
+
u = (point[column_axis] - low[column_axis]) / span_c
|
|
234
|
+
v = (point[row_axis] - low[row_axis]) / span_r
|
|
235
|
+
if column_flip:
|
|
236
|
+
u = 1.0 - u
|
|
237
|
+
if row_flip:
|
|
238
|
+
v = 1.0 - v
|
|
239
|
+
if not _sample_mask(view["mask"], u, v):
|
|
240
|
+
inside = False
|
|
241
|
+
break
|
|
242
|
+
if inside:
|
|
243
|
+
occupied.add((ix, iy, iz))
|
|
244
|
+
|
|
245
|
+
vertices, indices = _boundary_surface(occupied, low, step, resolution)
|
|
246
|
+
|
|
247
|
+
covered_axes = {_VIEW_FREE_AXIS[view["axis"]] for view in views}
|
|
248
|
+
unconstrained = [_AXIS_NAMES[axis] for axis in range(3) if axis not in covered_axes]
|
|
249
|
+
triangle_count = len(indices) // 3
|
|
250
|
+
budget = int(descriptor["triangleBudget"])
|
|
251
|
+
|
|
252
|
+
limitations = [
|
|
253
|
+
"a visual hull is the intersection of silhouette cones: it is an upper bound on the true "
|
|
254
|
+
"shape and can never contain a concavity that no supplied view sees as background",
|
|
255
|
+
]
|
|
256
|
+
if len(views) < 3:
|
|
257
|
+
limitations.append(
|
|
258
|
+
f"only {len(views)} views supplied, so the hull extrudes along "
|
|
259
|
+
f"{', '.join(unconstrained) or 'no'} and is loose in that direction"
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
"vertices": vertices,
|
|
264
|
+
"indices": indices,
|
|
265
|
+
"triangleCount": triangle_count,
|
|
266
|
+
# Reported for context only. There is deliberately no budget-overrun verdict here: the
|
|
267
|
+
# descriptor validator already requires triangleBudget >= resolution**3 * 12, the worst case
|
|
268
|
+
# for this grid, so a carve cannot exceed it and a boolean saying so could never be False.
|
|
269
|
+
# A check that cannot fail is worse than no check -- it reads as coverage that isn't there.
|
|
270
|
+
"triangleBudget": budget,
|
|
271
|
+
"resolution": resolution,
|
|
272
|
+
"occupiedVoxelCount": len(occupied),
|
|
273
|
+
"totalVoxelCount": resolution**3,
|
|
274
|
+
"occupiedFraction": round(len(occupied) / max(1, resolution**3), 6),
|
|
275
|
+
"viewAxes": [view["axis"] for view in views],
|
|
276
|
+
"unconstrainedAxes": unconstrained,
|
|
277
|
+
"limitations": limitations,
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _boundary_surface(
|
|
282
|
+
occupied: set[tuple[int, int, int]],
|
|
283
|
+
low: list[float],
|
|
284
|
+
step: list[float],
|
|
285
|
+
resolution: int,
|
|
286
|
+
) -> tuple[list[list[float]], list[int]]:
|
|
287
|
+
"""Emit only the faces between an occupied voxel and empty space.
|
|
288
|
+
|
|
289
|
+
Emitting all six faces of every voxel would produce a mesh with interior walls, which is not a
|
|
290
|
+
surface: every shared face would be a duplicated, oppositely-wound pair and the result would fail
|
|
291
|
+
the watertightness gate for reasons that have nothing to do with the carve. Corners are welded
|
|
292
|
+
through a cache so the output is a closed 2-manifold.
|
|
293
|
+
"""
|
|
294
|
+
vertex_ids: dict[tuple[int, int, int], int] = {}
|
|
295
|
+
vertices: list[list[float]] = []
|
|
296
|
+
|
|
297
|
+
def corner(gx: int, gy: int, gz: int) -> int:
|
|
298
|
+
key = (gx, gy, gz)
|
|
299
|
+
found = vertex_ids.get(key)
|
|
300
|
+
if found is not None:
|
|
301
|
+
return found
|
|
302
|
+
index = len(vertices)
|
|
303
|
+
vertex_ids[key] = index
|
|
304
|
+
vertices.append([low[0] + gx * step[0], low[1] + gy * step[1], low[2] + gz * step[2]])
|
|
305
|
+
return index
|
|
306
|
+
|
|
307
|
+
indices: list[int] = []
|
|
308
|
+
# (axis, direction) -> the four grid corners of that face, wound so the normal points outward.
|
|
309
|
+
faces = {
|
|
310
|
+
(0, 1): ((1, 0, 0), (1, 1, 0), (1, 1, 1), (1, 0, 1)),
|
|
311
|
+
(0, -1): ((0, 0, 0), (0, 0, 1), (0, 1, 1), (0, 1, 0)),
|
|
312
|
+
(1, 1): ((0, 1, 0), (0, 1, 1), (1, 1, 1), (1, 1, 0)),
|
|
313
|
+
(1, -1): ((0, 0, 0), (1, 0, 0), (1, 0, 1), (0, 0, 1)),
|
|
314
|
+
(2, 1): ((0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1)),
|
|
315
|
+
(2, -1): ((0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0)),
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
for (ix, iy, iz) in sorted(occupied):
|
|
319
|
+
for (axis, direction), offsets in faces.items():
|
|
320
|
+
neighbour = [ix, iy, iz]
|
|
321
|
+
neighbour[axis] += direction
|
|
322
|
+
if tuple(neighbour) in occupied:
|
|
323
|
+
continue
|
|
324
|
+
quad = [corner(ix + dx, iy + dy, iz + dz) for dx, dy, dz in offsets]
|
|
325
|
+
indices.extend([quad[0], quad[1], quad[2], quad[0], quad[2], quad[3]])
|
|
326
|
+
return vertices, indices
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def main(argv: list[str]) -> int:
|
|
330
|
+
parser = argparse.ArgumentParser(description="Carve a visual hull from a descriptor JSON.")
|
|
331
|
+
parser.add_argument("descriptor", type=Path, help="JSON file holding the visualHull descriptor")
|
|
332
|
+
parser.add_argument("--out", type=Path, help="write the carved mesh JSON here")
|
|
333
|
+
parser.add_argument("--json", action="store_true", help="print the full result as JSON")
|
|
334
|
+
args = parser.parse_args(argv)
|
|
335
|
+
try:
|
|
336
|
+
descriptor = json.loads(args.descriptor.read_text())
|
|
337
|
+
result = carve_visual_hull(descriptor)
|
|
338
|
+
except Exception as exc:
|
|
339
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
340
|
+
return 2
|
|
341
|
+
if args.out:
|
|
342
|
+
args.out.write_text(json.dumps(result))
|
|
343
|
+
if args.json:
|
|
344
|
+
print(json.dumps(result, indent=2))
|
|
345
|
+
else:
|
|
346
|
+
print(
|
|
347
|
+
f"carved {result['occupiedVoxelCount']}/{result['totalVoxelCount']} voxels "
|
|
348
|
+
f"({result['occupiedFraction']:.4f}) into {result['triangleCount']} triangles "
|
|
349
|
+
f"from views {result['viewAxes']}"
|
|
350
|
+
)
|
|
351
|
+
for line in result["limitations"]:
|
|
352
|
+
print(f" note: {line}")
|
|
353
|
+
return 0
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
if __name__ == "__main__":
|
|
357
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _approval_state(
|
|
8
|
+
result: Mapping[str, object],
|
|
9
|
+
input_error: Callable[[str, str], ValueError],
|
|
10
|
+
field: str,
|
|
11
|
+
) -> tuple[list[str], str | None, str | None, bool]:
|
|
12
|
+
hard_gates = result.get("hardGateFailures", [])
|
|
13
|
+
if not isinstance(hard_gates, list) or not all(isinstance(tag, str) for tag in hard_gates):
|
|
14
|
+
raise input_error(f"{field}.hardGateFailures", "must be a list of strings")
|
|
15
|
+
action = result.get("action")
|
|
16
|
+
verdict = result.get("verdict")
|
|
17
|
+
if action is not None and not isinstance(action, str):
|
|
18
|
+
raise input_error(f"{field}.action", "must be a string")
|
|
19
|
+
if verdict is not None and not isinstance(verdict, str):
|
|
20
|
+
raise input_error(f"{field}.verdict", "must be a string")
|
|
21
|
+
approved = not hard_gates and action in (None, "continue") and verdict in (None, "pass")
|
|
22
|
+
return hard_gates, action, verdict, approved
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def is_approved_divine_eye_result(
|
|
26
|
+
result: Mapping[str, object],
|
|
27
|
+
input_error: Callable[[str, str], ValueError],
|
|
28
|
+
field: str,
|
|
29
|
+
) -> bool:
|
|
30
|
+
return _approval_state(result, input_error, field)[3]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def normalize_history(
|
|
34
|
+
results: Sequence[Mapping[str, object]],
|
|
35
|
+
fidelity: Callable[[Mapping[str, object]], float],
|
|
36
|
+
input_error: Callable[[str, str], ValueError],
|
|
37
|
+
) -> list[dict[str, object]]:
|
|
38
|
+
if isinstance(results, str | bytes) or not isinstance(results, Sequence):
|
|
39
|
+
raise input_error("results", "must be a sequence of mappings")
|
|
40
|
+
history: list[dict[str, object]] = []
|
|
41
|
+
accepted_fidelity: float | None = None
|
|
42
|
+
for index, result in enumerate(results):
|
|
43
|
+
if not isinstance(result, Mapping):
|
|
44
|
+
raise input_error(f"results[{index}]", "must be a mapping")
|
|
45
|
+
score = fidelity(result)
|
|
46
|
+
hard_gates, action, verdict, approved = _approval_state(result, input_error, f"results[{index}]")
|
|
47
|
+
pending_review = not approved
|
|
48
|
+
reverted = accepted_fidelity is not None and score < accepted_fidelity
|
|
49
|
+
entry = {
|
|
50
|
+
"fidelity": score,
|
|
51
|
+
"defectTags": hard_gates.copy(),
|
|
52
|
+
"hardGateFailures": hard_gates.copy(),
|
|
53
|
+
"reverted": reverted,
|
|
54
|
+
"pendingReview": pending_review,
|
|
55
|
+
"divineEye": deepcopy(dict(result)),
|
|
56
|
+
}
|
|
57
|
+
if action is not None:
|
|
58
|
+
entry["divineEyeAction"] = action
|
|
59
|
+
if verdict is not None:
|
|
60
|
+
entry["divineEyeVerdict"] = verdict
|
|
61
|
+
history.append(entry)
|
|
62
|
+
if approved and (accepted_fidelity is None or score > accepted_fidelity):
|
|
63
|
+
accepted_fidelity = score
|
|
64
|
+
return history
|