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,227 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Analyze admitted material regions and connect them to the registry.
|
|
3
|
+
|
|
4
|
+
Input manifest example::
|
|
5
|
+
|
|
6
|
+
{"referenceId":"armor-front", "regions":[
|
|
7
|
+
{"componentId":"torso-armor", "regionId":"paint", "sourceImage":"front.png",
|
|
8
|
+
"bbox":{"x":120,"y":80,"width":420,"height":300},
|
|
9
|
+
"family":"coating", "subtype":"paint-over-metal", "finish":"gloss-or-satin",
|
|
10
|
+
"materialSpecId":"armor-paint"}
|
|
11
|
+
]}
|
|
12
|
+
|
|
13
|
+
The command creates verified crops, runs the existing pixel/PBR evidence
|
|
14
|
+
extractor, resolves the canonical material profile, and emits one durable
|
|
15
|
+
``material-analysis.json`` artifact. It never silently promotes a low
|
|
16
|
+
confidence inference to ``proceed``.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import argparse
|
|
22
|
+
import json
|
|
23
|
+
import sys
|
|
24
|
+
from argparse import Namespace
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typing import Any
|
|
27
|
+
|
|
28
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
29
|
+
sys.path.insert(0, str(ROOT / "forge" / "stage1_intake"))
|
|
30
|
+
from analyze_texture import analyze # noqa: E402
|
|
31
|
+
from extract_pbr_evidence import extract, load_image, write_png_rgb # noqa: E402
|
|
32
|
+
|
|
33
|
+
sys.path.insert(0, str(ROOT / "forge"))
|
|
34
|
+
from materials.reference import build_assignment, load_reference # noqa: E402
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _bounded_bbox(raw: Any, width: int, height: int) -> tuple[int, int, int, int]:
|
|
38
|
+
if not isinstance(raw, dict):
|
|
39
|
+
raise ValueError("region bbox must be an object")
|
|
40
|
+
values = [raw.get(key) for key in ("x", "y", "width", "height")]
|
|
41
|
+
if not all(isinstance(value, (int, float)) and not isinstance(value, bool) for value in values):
|
|
42
|
+
raise ValueError("region bbox requires numeric x, y, width and height")
|
|
43
|
+
x, y, box_width, box_height = (float(value) for value in values)
|
|
44
|
+
if raw.get("normalized") is True:
|
|
45
|
+
x, box_width = x * width, box_width * width
|
|
46
|
+
y, box_height = y * height, box_height * height
|
|
47
|
+
x0 = max(0, min(width - 1, round(x)))
|
|
48
|
+
y0 = max(0, min(height - 1, round(y)))
|
|
49
|
+
x1 = max(x0 + 1, min(width, round(x + box_width)))
|
|
50
|
+
y1 = max(y0 + 1, min(height, round(y + box_height)))
|
|
51
|
+
if (x1 - x0) < 8 or (y1 - y0) < 8:
|
|
52
|
+
raise ValueError("material crop is too small; minimum crop dimension is 8 pixels")
|
|
53
|
+
return x0, y0, x1 - x0, y1 - y0
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def crop_region(source: Path, bbox: dict[str, Any], output: Path) -> dict[str, Any]:
|
|
57
|
+
width, height, pixels, warnings = load_image(source)
|
|
58
|
+
x0, y0, crop_width, crop_height = _bounded_bbox(bbox, width, height)
|
|
59
|
+
rgb = bytearray()
|
|
60
|
+
for y in range(y0, y0 + crop_height):
|
|
61
|
+
for x in range(x0, x0 + crop_width):
|
|
62
|
+
red, green, blue, alpha = pixels[y * width + x]
|
|
63
|
+
if alpha < 16:
|
|
64
|
+
red = green = blue = 0
|
|
65
|
+
rgb.extend((red, green, blue))
|
|
66
|
+
write_png_rgb(output, crop_width, crop_height, bytes(rgb))
|
|
67
|
+
return {
|
|
68
|
+
"path": str(output.resolve()),
|
|
69
|
+
"bbox": {"x": x0, "y": y0, "width": crop_width, "height": crop_height},
|
|
70
|
+
"sourceWidth": width,
|
|
71
|
+
"sourceHeight": height,
|
|
72
|
+
"loaderWarnings": warnings,
|
|
73
|
+
"coverage": round((crop_width * crop_height) / max(1, width * height), 4),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _observations(texture_report: dict[str, Any]) -> list[str]:
|
|
78
|
+
stats = texture_report.get("stats", {})
|
|
79
|
+
observations: list[str] = []
|
|
80
|
+
if float(stats.get("meanSaturation", 0.0)) < 0.18:
|
|
81
|
+
observations.append("near-neutral colour response")
|
|
82
|
+
else:
|
|
83
|
+
observations.append("chromatic base-colour response")
|
|
84
|
+
if float(stats.get("streakRatio", 1.0)) > 1.9 or float(stats.get("streakRatio", 1.0)) < 0.53:
|
|
85
|
+
observations.append("directional surface frequency")
|
|
86
|
+
if float(stats.get("mottle", 0.0)) > 0.038:
|
|
87
|
+
observations.append("visible meso/micro variation")
|
|
88
|
+
if float(stats.get("gradientStrength", 0.0)) > 0.18:
|
|
89
|
+
observations.append("strong image-space gradient; verify it is material pattern, not lighting")
|
|
90
|
+
observations.append("single-image PBR inference requires controlled render validation")
|
|
91
|
+
return observations
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def analyze_manifest(
|
|
95
|
+
manifest_path: Path,
|
|
96
|
+
out_dir: Path,
|
|
97
|
+
reference_path: Path | None = None,
|
|
98
|
+
registry_path: Path | None = None,
|
|
99
|
+
target_threshold: float = 0.7,
|
|
100
|
+
multi_view_reference: bool = False,
|
|
101
|
+
) -> dict[str, Any]:
|
|
102
|
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
103
|
+
if not isinstance(manifest, dict) or not isinstance(manifest.get("regions"), list):
|
|
104
|
+
raise ValueError("material region manifest must contain a regions array")
|
|
105
|
+
registry = load_reference(registry_path) if registry_path else load_reference()
|
|
106
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
107
|
+
regions: list[dict[str, Any]] = []
|
|
108
|
+
for index, region in enumerate(manifest["regions"]):
|
|
109
|
+
if not isinstance(region, dict):
|
|
110
|
+
raise ValueError(f"regions[{index}] must be an object")
|
|
111
|
+
component_id = str(region.get("componentId") or "").strip()
|
|
112
|
+
region_id = str(region.get("regionId") or "").strip()
|
|
113
|
+
if not component_id or not region_id:
|
|
114
|
+
raise ValueError(f"regions[{index}] requires componentId and regionId")
|
|
115
|
+
source = Path(region.get("sourceImage") or reference_path or "")
|
|
116
|
+
if not source.is_absolute():
|
|
117
|
+
source = (manifest_path.parent / source).resolve()
|
|
118
|
+
if not source.exists():
|
|
119
|
+
raise ValueError(f"region {region_id!r} source image does not exist: {source}")
|
|
120
|
+
crop_path = out_dir / f"{index:02d}-{region_id.replace('/', '-').replace(' ', '-')}.png"
|
|
121
|
+
crop_info = crop_region(source, region.get("bbox"), crop_path)
|
|
122
|
+
texture_report = analyze(crop_path)
|
|
123
|
+
pbr_dir = out_dir / f"pbr-{index:02d}-{region_id.replace('/', '-').replace(' ', '-')}"
|
|
124
|
+
args = Namespace(
|
|
125
|
+
image=crop_path,
|
|
126
|
+
out_dir=pbr_dir,
|
|
127
|
+
material_id=str(region.get("materialSpecId") or region_id),
|
|
128
|
+
size=512,
|
|
129
|
+
palette_size=5,
|
|
130
|
+
target_threshold=target_threshold,
|
|
131
|
+
url_prefix="",
|
|
132
|
+
multi_view_reference=multi_view_reference,
|
|
133
|
+
)
|
|
134
|
+
pbr_report, pbr_patch = extract(args)
|
|
135
|
+
hypothesis = {
|
|
136
|
+
"componentId": component_id,
|
|
137
|
+
"regionId": region_id,
|
|
138
|
+
"materialId": region.get("materialId"),
|
|
139
|
+
"family": region.get("family"),
|
|
140
|
+
"subtype": region.get("subtype"),
|
|
141
|
+
"finish": region.get("finish"),
|
|
142
|
+
"aliases": region.get("aliases", []),
|
|
143
|
+
"confidence": min(float(region.get("confidence", 1.0)), float(pbr_report["confidence"])),
|
|
144
|
+
"source": region.get("source", "vision"),
|
|
145
|
+
}
|
|
146
|
+
assignment = build_assignment(hypothesis, {
|
|
147
|
+
"crop": crop_info,
|
|
148
|
+
"pbr": pbr_report,
|
|
149
|
+
"texture": texture_report,
|
|
150
|
+
}, registry)
|
|
151
|
+
if pbr_report["confidence"] < target_threshold and assignment["status"] == "proceed":
|
|
152
|
+
assignment["status"] = "probe"
|
|
153
|
+
regions.append({
|
|
154
|
+
"componentId": component_id,
|
|
155
|
+
"regionId": region_id,
|
|
156
|
+
"materialSpecId": region.get("materialSpecId") or region_id,
|
|
157
|
+
"hypothesis": hypothesis,
|
|
158
|
+
"assignment": assignment,
|
|
159
|
+
"observations": _observations(texture_report),
|
|
160
|
+
"crop": crop_info,
|
|
161
|
+
"textureAnalysis": texture_report,
|
|
162
|
+
"pbrReport": pbr_report,
|
|
163
|
+
"referencePbr": pbr_patch["referencePbr"],
|
|
164
|
+
"maps": pbr_report.get("maps", {}),
|
|
165
|
+
})
|
|
166
|
+
not_observed = manifest.get("notObservedMaterials", [])
|
|
167
|
+
if not isinstance(not_observed, list):
|
|
168
|
+
raise ValueError("notObservedMaterials must be an array when present")
|
|
169
|
+
unresolved_not_observed = [
|
|
170
|
+
item for item in not_observed
|
|
171
|
+
if isinstance(item, dict) and item.get("status") in {"probe", "request-input", "unknown"}
|
|
172
|
+
]
|
|
173
|
+
return {
|
|
174
|
+
"schemaVersion": 1,
|
|
175
|
+
"kind": "img2threejs.material-analysis",
|
|
176
|
+
"referenceId": manifest.get("referenceId", manifest_path.stem),
|
|
177
|
+
"manifest": str(manifest_path.resolve()),
|
|
178
|
+
"registry": str((registry_path or ROOT / "docs/materials/material-reference.json").resolve()),
|
|
179
|
+
"targetThreshold": target_threshold,
|
|
180
|
+
"notObservedMaterials": not_observed,
|
|
181
|
+
"unresolvedNotObservedMaterials": unresolved_not_observed,
|
|
182
|
+
"regions": regions,
|
|
183
|
+
"status": (
|
|
184
|
+
"proceed"
|
|
185
|
+
if regions
|
|
186
|
+
and all(item["assignment"]["status"] == "proceed" for item in regions)
|
|
187
|
+
and not unresolved_not_observed
|
|
188
|
+
else "probe"
|
|
189
|
+
),
|
|
190
|
+
"limitations": [
|
|
191
|
+
"PBR extraction is reference-derived inference, not inverse rendering.",
|
|
192
|
+
"A crop must be checked against the component visible footprint before accepting material scores.",
|
|
193
|
+
],
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def main(argv: list[str]) -> int:
|
|
198
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
199
|
+
parser.add_argument("--manifest", type=Path, required=True)
|
|
200
|
+
parser.add_argument("--out-dir", type=Path, required=True)
|
|
201
|
+
parser.add_argument("--out", type=Path, required=True)
|
|
202
|
+
parser.add_argument("--reference", type=Path)
|
|
203
|
+
parser.add_argument("--registry", type=Path)
|
|
204
|
+
parser.add_argument("--target-threshold", type=float, default=0.7)
|
|
205
|
+
parser.add_argument("--multi-view-reference", action="store_true")
|
|
206
|
+
args = parser.parse_args(argv)
|
|
207
|
+
try:
|
|
208
|
+
result = analyze_manifest(
|
|
209
|
+
args.manifest,
|
|
210
|
+
args.out_dir,
|
|
211
|
+
args.reference,
|
|
212
|
+
args.registry,
|
|
213
|
+
max(0.0, min(1.0, args.target_threshold)),
|
|
214
|
+
args.multi_view_reference,
|
|
215
|
+
)
|
|
216
|
+
result["artifact"] = str(args.out.resolve())
|
|
217
|
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
|
218
|
+
args.out.write_text(json.dumps(result, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
219
|
+
print(json.dumps({"status": result["status"], "regions": len(result["regions"]), "out": str(args.out.resolve())}, indent=2))
|
|
220
|
+
return 0 if result["status"] == "proceed" else 2
|
|
221
|
+
except Exception as exc:
|
|
222
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
223
|
+
return 1
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
if __name__ == "__main__":
|
|
227
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Probe a binary glTF (GLB) as an explicit reference-mesh artifact.
|
|
3
|
+
|
|
4
|
+
This is metadata/provenance inspection only. It does not import, render, or copy
|
|
5
|
+
the source mesh into a procedural factory. The browser Three.js route remains the
|
|
6
|
+
authority for reference and output pixels.
|
|
7
|
+
|
|
8
|
+
Pure Python 3.10+ standard library; no PIL, numpy, Blender, or glTF dependency.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import hashlib
|
|
15
|
+
import json
|
|
16
|
+
import math
|
|
17
|
+
import struct
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from .semantic_decomposition import assess_semantic_decomposition
|
|
23
|
+
except ImportError: # pragma: no cover - direct script execution
|
|
24
|
+
from semantic_decomposition import assess_semantic_decomposition
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
GLB_MAGIC = b"glTF"
|
|
28
|
+
JSON_CHUNK = 0x4E4F534A
|
|
29
|
+
BIN_CHUNK = 0x004E4942
|
|
30
|
+
MAX_FALLBACK_BOUND_SAMPLES = 1_000_000
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def sha256(path: Path) -> str:
|
|
34
|
+
digest = hashlib.sha256()
|
|
35
|
+
with path.open("rb") as handle:
|
|
36
|
+
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
|
37
|
+
digest.update(chunk)
|
|
38
|
+
return digest.hexdigest()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _chunk_type_name(chunk_type: int) -> str:
|
|
42
|
+
try:
|
|
43
|
+
return chunk_type.to_bytes(4, "little").decode("ascii", errors="replace")
|
|
44
|
+
except OverflowError:
|
|
45
|
+
return hex(chunk_type)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_glb(path: Path) -> tuple[dict[str, Any], bytes, dict[str, Any]]:
|
|
49
|
+
data = path.read_bytes()
|
|
50
|
+
if len(data) < 12:
|
|
51
|
+
raise ValueError("GLB is shorter than the 12-byte header")
|
|
52
|
+
magic, version, declared_length = struct.unpack_from("<4sII", data, 0)
|
|
53
|
+
if magic != GLB_MAGIC:
|
|
54
|
+
raise ValueError("file does not start with the glTF binary magic")
|
|
55
|
+
if version != 2:
|
|
56
|
+
raise ValueError(f"unsupported GLB version {version}; expected 2")
|
|
57
|
+
if declared_length != len(data):
|
|
58
|
+
raise ValueError(f"header length {declared_length} does not match file size {len(data)}")
|
|
59
|
+
|
|
60
|
+
cursor = 12
|
|
61
|
+
json_payload: bytes | None = None
|
|
62
|
+
bin_payload = b""
|
|
63
|
+
chunks: list[dict[str, Any]] = []
|
|
64
|
+
while cursor < len(data):
|
|
65
|
+
if cursor + 8 > len(data):
|
|
66
|
+
raise ValueError("truncated GLB chunk header")
|
|
67
|
+
chunk_length, chunk_type = struct.unpack_from("<II", data, cursor)
|
|
68
|
+
cursor += 8
|
|
69
|
+
end = cursor + chunk_length
|
|
70
|
+
if end > len(data):
|
|
71
|
+
raise ValueError("GLB chunk extends beyond the declared file")
|
|
72
|
+
payload = data[cursor:end]
|
|
73
|
+
cursor = end
|
|
74
|
+
chunks.append({"type": _chunk_type_name(chunk_type), "bytes": chunk_length})
|
|
75
|
+
if chunk_type == JSON_CHUNK:
|
|
76
|
+
if json_payload is not None:
|
|
77
|
+
raise ValueError("GLB contains more than one JSON chunk")
|
|
78
|
+
json_payload = payload.rstrip(b" \t\r\n\x00")
|
|
79
|
+
elif chunk_type == BIN_CHUNK:
|
|
80
|
+
if bin_payload:
|
|
81
|
+
raise ValueError("GLB contains more than one BIN chunk")
|
|
82
|
+
bin_payload = payload
|
|
83
|
+
|
|
84
|
+
if json_payload is None:
|
|
85
|
+
raise ValueError("GLB has no JSON chunk")
|
|
86
|
+
try:
|
|
87
|
+
document = json.loads(json_payload.decode("utf-8"))
|
|
88
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
89
|
+
raise ValueError(f"GLB JSON chunk is invalid: {exc}") from exc
|
|
90
|
+
if not isinstance(document, dict):
|
|
91
|
+
raise ValueError("GLB JSON root must be an object")
|
|
92
|
+
return document, bin_payload, {
|
|
93
|
+
"version": version,
|
|
94
|
+
"declaredLength": declared_length,
|
|
95
|
+
"jsonChunkBytes": len(json_payload),
|
|
96
|
+
"binChunkBytes": len(bin_payload),
|
|
97
|
+
"chunks": chunks,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _buffer_view_bytes(document: dict[str, Any], bin_payload: bytes, view_index: int) -> bytes:
|
|
102
|
+
views = document.get("bufferViews", [])
|
|
103
|
+
if not isinstance(views, list) or not 0 <= view_index < len(views):
|
|
104
|
+
raise ValueError(f"accessor references missing bufferView {view_index}")
|
|
105
|
+
view = views[view_index]
|
|
106
|
+
if not isinstance(view, dict):
|
|
107
|
+
raise ValueError(f"bufferView {view_index} is not an object")
|
|
108
|
+
if view.get("buffer", 0) != 0:
|
|
109
|
+
raise ValueError("external/multi-buffer GLB references are not supported by the stdlib probe")
|
|
110
|
+
start = int(view.get("byteOffset", 0))
|
|
111
|
+
length = int(view.get("byteLength", 0))
|
|
112
|
+
end = start + length
|
|
113
|
+
if start < 0 or end > len(bin_payload):
|
|
114
|
+
raise ValueError(f"bufferView {view_index} exceeds the GLB BIN chunk")
|
|
115
|
+
return bin_payload[start:end]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
_COMPONENT_FORMATS: dict[int, tuple[str, int]] = {
|
|
119
|
+
5120: ("b", 1),
|
|
120
|
+
5121: ("B", 1),
|
|
121
|
+
5122: ("h", 2),
|
|
122
|
+
5123: ("H", 2),
|
|
123
|
+
5124: ("i", 4),
|
|
124
|
+
5125: ("I", 4),
|
|
125
|
+
5126: ("f", 4),
|
|
126
|
+
}
|
|
127
|
+
_TYPE_COMPONENTS = {"SCALAR": 1, "VEC2": 2, "VEC3": 3, "VEC4": 4, "MAT2": 4, "MAT3": 9, "MAT4": 16}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _accessor_bounds(
|
|
131
|
+
document: dict[str, Any], bin_payload: bytes, accessor_index: int
|
|
132
|
+
) -> tuple[list[float], list[float], list[str]]:
|
|
133
|
+
accessors = document.get("accessors", [])
|
|
134
|
+
warnings: list[str] = []
|
|
135
|
+
if not isinstance(accessors, list) or not 0 <= accessor_index < len(accessors):
|
|
136
|
+
raise ValueError(f"missing accessor {accessor_index}")
|
|
137
|
+
accessor = accessors[accessor_index]
|
|
138
|
+
if not isinstance(accessor, dict):
|
|
139
|
+
raise ValueError(f"accessor {accessor_index} is not an object")
|
|
140
|
+
if accessor.get("type") != "VEC3":
|
|
141
|
+
raise ValueError(f"POSITION accessor {accessor_index} is not VEC3")
|
|
142
|
+
minimum = accessor.get("min")
|
|
143
|
+
maximum = accessor.get("max")
|
|
144
|
+
if isinstance(minimum, list) and isinstance(maximum, list) and len(minimum) == 3 and len(maximum) == 3:
|
|
145
|
+
return [float(v) for v in minimum], [float(v) for v in maximum], warnings
|
|
146
|
+
|
|
147
|
+
count = int(accessor.get("count", 0))
|
|
148
|
+
if count <= 0:
|
|
149
|
+
raise ValueError(f"POSITION accessor {accessor_index} has no elements")
|
|
150
|
+
if count > MAX_FALLBACK_BOUND_SAMPLES:
|
|
151
|
+
warnings.append(
|
|
152
|
+
f"POSITION accessor {accessor_index} has {count} vertices and no min/max; bounds were not decoded"
|
|
153
|
+
)
|
|
154
|
+
return [math.nan] * 3, [math.nan] * 3, warnings
|
|
155
|
+
component_type = int(accessor.get("componentType", 5126))
|
|
156
|
+
fmt_info = _COMPONENT_FORMATS.get(component_type)
|
|
157
|
+
if fmt_info is None:
|
|
158
|
+
raise ValueError(f"unsupported POSITION componentType {component_type}")
|
|
159
|
+
fmt, component_bytes = fmt_info
|
|
160
|
+
view_index = accessor.get("bufferView")
|
|
161
|
+
if view_index is None:
|
|
162
|
+
raise ValueError(f"POSITION accessor {accessor_index} has no bufferView")
|
|
163
|
+
raw = _buffer_view_bytes(document, bin_payload, int(view_index))
|
|
164
|
+
view = document["bufferViews"][int(view_index)]
|
|
165
|
+
stride = int(view.get("byteStride", component_bytes * 3))
|
|
166
|
+
base = int(accessor.get("byteOffset", 0))
|
|
167
|
+
if stride < component_bytes * 3:
|
|
168
|
+
raise ValueError(f"bufferView stride is too small for POSITION accessor {accessor_index}")
|
|
169
|
+
mins = [float("inf")] * 3
|
|
170
|
+
maxs = [float("-inf")] * 3
|
|
171
|
+
for index in range(count):
|
|
172
|
+
offset = base + index * stride
|
|
173
|
+
if offset + component_bytes * 3 > len(raw):
|
|
174
|
+
raise ValueError(f"POSITION accessor {accessor_index} exceeds its bufferView")
|
|
175
|
+
values = struct.unpack_from(f"<3{fmt}", raw, offset)
|
|
176
|
+
for axis, value in enumerate(values):
|
|
177
|
+
mins[axis] = min(mins[axis], float(value))
|
|
178
|
+
maxs[axis] = max(maxs[axis], float(value))
|
|
179
|
+
return mins, maxs, warnings
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _merge_bounds(bounds: list[tuple[list[float], list[float]]]) -> dict[str, Any] | None:
|
|
183
|
+
valid = [item for item in bounds if all(math.isfinite(v) for v in item[0] + item[1])]
|
|
184
|
+
if not valid:
|
|
185
|
+
return None
|
|
186
|
+
minimum = [min(item[0][axis] for item in valid) for axis in range(3)]
|
|
187
|
+
maximum = [max(item[1][axis] for item in valid) for axis in range(3)]
|
|
188
|
+
size = [maximum[axis] - minimum[axis] for axis in range(3)]
|
|
189
|
+
return {
|
|
190
|
+
"space": "mesh-local-untransformed",
|
|
191
|
+
"min": minimum,
|
|
192
|
+
"max": maximum,
|
|
193
|
+
"size": size,
|
|
194
|
+
"center": [(minimum[axis] + maximum[axis]) / 2.0 for axis in range(3)],
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def probe_glb(path: Path) -> dict[str, Any]:
|
|
199
|
+
path = path.expanduser().resolve()
|
|
200
|
+
if not path.is_file():
|
|
201
|
+
raise ValueError(f"GLB does not exist: {path}")
|
|
202
|
+
document, bin_payload, binary = parse_glb(path)
|
|
203
|
+
warnings: list[str] = []
|
|
204
|
+
meshes = document.get("meshes", []) if isinstance(document.get("meshes", []), list) else []
|
|
205
|
+
nodes = document.get("nodes", []) if isinstance(document.get("nodes", []), list) else []
|
|
206
|
+
materials = document.get("materials", []) if isinstance(document.get("materials", []), list) else []
|
|
207
|
+
skins = document.get("skins", []) if isinstance(document.get("skins", []), list) else []
|
|
208
|
+
animations = document.get("animations", []) if isinstance(document.get("animations", []), list) else []
|
|
209
|
+
scenes = document.get("scenes", []) if isinstance(document.get("scenes", []), list) else []
|
|
210
|
+
textures = document.get("textures", []) if isinstance(document.get("textures", []), list) else []
|
|
211
|
+
|
|
212
|
+
mesh_records: list[dict[str, Any]] = []
|
|
213
|
+
all_bounds: list[tuple[list[float], list[float]]] = []
|
|
214
|
+
primitive_count = 0
|
|
215
|
+
for mesh_index, mesh in enumerate(meshes):
|
|
216
|
+
if not isinstance(mesh, dict):
|
|
217
|
+
warnings.append(f"mesh {mesh_index} is not an object")
|
|
218
|
+
continue
|
|
219
|
+
primitives = mesh.get("primitives", []) if isinstance(mesh.get("primitives", []), list) else []
|
|
220
|
+
primitive_records: list[dict[str, Any]] = []
|
|
221
|
+
mesh_bounds: list[tuple[list[float], list[float]]] = []
|
|
222
|
+
for primitive_index, primitive in enumerate(primitives):
|
|
223
|
+
primitive_count += 1
|
|
224
|
+
if not isinstance(primitive, dict):
|
|
225
|
+
warnings.append(f"mesh {mesh_index} primitive {primitive_index} is not an object")
|
|
226
|
+
continue
|
|
227
|
+
attributes = primitive.get("attributes", {}) if isinstance(primitive.get("attributes", {}), dict) else {}
|
|
228
|
+
record: dict[str, Any] = {
|
|
229
|
+
"index": primitive_index,
|
|
230
|
+
"mode": primitive.get("mode", 4),
|
|
231
|
+
"attributes": sorted(str(key) for key in attributes),
|
|
232
|
+
"material": primitive.get("material"),
|
|
233
|
+
}
|
|
234
|
+
position_accessor = attributes.get("POSITION")
|
|
235
|
+
if position_accessor is not None:
|
|
236
|
+
try:
|
|
237
|
+
minimum, maximum, accessor_warnings = _accessor_bounds(document, bin_payload, int(position_accessor))
|
|
238
|
+
record["positionBounds"] = {"min": minimum, "max": maximum}
|
|
239
|
+
mesh_bounds.append((minimum, maximum))
|
|
240
|
+
all_bounds.append((minimum, maximum))
|
|
241
|
+
warnings.extend(accessor_warnings)
|
|
242
|
+
except ValueError as exc:
|
|
243
|
+
warnings.append(f"mesh {mesh_index} primitive {primitive_index}: {exc}")
|
|
244
|
+
else:
|
|
245
|
+
warnings.append(f"mesh {mesh_index} primitive {primitive_index} has no POSITION attribute")
|
|
246
|
+
primitive_records.append(record)
|
|
247
|
+
mesh_record: dict[str, Any] = {
|
|
248
|
+
"index": mesh_index,
|
|
249
|
+
"name": mesh.get("name") or f"mesh-{mesh_index}",
|
|
250
|
+
"primitiveCount": len(primitives),
|
|
251
|
+
"primitives": primitive_records,
|
|
252
|
+
}
|
|
253
|
+
bounds = _merge_bounds(mesh_bounds)
|
|
254
|
+
if bounds:
|
|
255
|
+
mesh_record["bounds"] = bounds
|
|
256
|
+
mesh_records.append(mesh_record)
|
|
257
|
+
|
|
258
|
+
node_records = []
|
|
259
|
+
for index, node in enumerate(nodes):
|
|
260
|
+
if not isinstance(node, dict):
|
|
261
|
+
continue
|
|
262
|
+
node_records.append(
|
|
263
|
+
{
|
|
264
|
+
"index": index,
|
|
265
|
+
"name": node.get("name") or f"node-{index}",
|
|
266
|
+
"mesh": node.get("mesh"),
|
|
267
|
+
"skin": node.get("skin"),
|
|
268
|
+
"children": node.get("children", []),
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
material_records = [
|
|
272
|
+
{"index": index, "name": material.get("name") or f"material-{index}", "alphaMode": material.get("alphaMode", "OPAQUE")}
|
|
273
|
+
for index, material in enumerate(materials)
|
|
274
|
+
if isinstance(material, dict)
|
|
275
|
+
]
|
|
276
|
+
skeleton_records = [
|
|
277
|
+
{"index": index, "name": skin.get("name") or f"skin-{index}", "jointCount": len(skin.get("joints", []))}
|
|
278
|
+
for index, skin in enumerate(skins)
|
|
279
|
+
if isinstance(skin, dict)
|
|
280
|
+
]
|
|
281
|
+
bounds = _merge_bounds(all_bounds)
|
|
282
|
+
if not meshes:
|
|
283
|
+
warnings.append("GLB contains no meshes")
|
|
284
|
+
if not bin_payload:
|
|
285
|
+
warnings.append("GLB contains no BIN payload; external buffers are not accepted by this probe")
|
|
286
|
+
if not materials:
|
|
287
|
+
warnings.append("GLB contains no materials; visual appearance must be inferred or supplied separately")
|
|
288
|
+
if not skins:
|
|
289
|
+
warnings.append("GLB contains no skin; this is acceptable for static reference geometry but not animation evidence")
|
|
290
|
+
semantic_decomposition = assess_semantic_decomposition(
|
|
291
|
+
node_count=len(nodes),
|
|
292
|
+
mesh_count=len(meshes),
|
|
293
|
+
primitive_count=primitive_count,
|
|
294
|
+
material_count=len(materials),
|
|
295
|
+
nodes=node_records,
|
|
296
|
+
meshes=mesh_records,
|
|
297
|
+
materials=material_records,
|
|
298
|
+
texture_count=len(textures),
|
|
299
|
+
)
|
|
300
|
+
if semantic_decomposition["status"] == "insufficient":
|
|
301
|
+
warnings.append("GLB metadata has no reliable semantic part boundaries; request multipart GLB or capture ID masks")
|
|
302
|
+
return {
|
|
303
|
+
"schemaVersion": 1,
|
|
304
|
+
"kind": "glb-reference",
|
|
305
|
+
"path": str(path),
|
|
306
|
+
"sha256": sha256(path),
|
|
307
|
+
"bytes": path.stat().st_size,
|
|
308
|
+
"binary": binary,
|
|
309
|
+
"asset": {
|
|
310
|
+
"version": document.get("asset", {}).get("version") if isinstance(document.get("asset"), dict) else None,
|
|
311
|
+
"generator": document.get("asset", {}).get("generator") if isinstance(document.get("asset"), dict) else None,
|
|
312
|
+
},
|
|
313
|
+
"scene": {
|
|
314
|
+
"defaultScene": document.get("scene"),
|
|
315
|
+
"sceneCount": len(scenes),
|
|
316
|
+
"nodeCount": len(nodes),
|
|
317
|
+
"meshCount": len(meshes),
|
|
318
|
+
"primitiveCount": primitive_count,
|
|
319
|
+
"materialCount": len(materials),
|
|
320
|
+
"skinCount": len(skins),
|
|
321
|
+
"animationCount": len(animations),
|
|
322
|
+
},
|
|
323
|
+
"nodes": node_records,
|
|
324
|
+
"meshes": mesh_records,
|
|
325
|
+
"materials": material_records,
|
|
326
|
+
"skins": skeleton_records,
|
|
327
|
+
"bounds": bounds,
|
|
328
|
+
"semanticDecomposition": semantic_decomposition,
|
|
329
|
+
"referenceReadiness": "pass" if meshes and bin_payload else "reject",
|
|
330
|
+
"warnings": sorted(set(warnings)),
|
|
331
|
+
"note": "Metadata only. Render the GLB through the target Three.js route before using it as a visual baseline; do not copy its topology into a procedural factory.",
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def main(argv: list[str]) -> int:
|
|
336
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
337
|
+
parser.add_argument("glb", type=Path)
|
|
338
|
+
parser.add_argument("--out", type=Path, help="also write the machine-readable probe artifact")
|
|
339
|
+
args = parser.parse_args(argv)
|
|
340
|
+
try:
|
|
341
|
+
result = probe_glb(args.glb)
|
|
342
|
+
rendered = json.dumps(result, indent=2, ensure_ascii=False) + "\n"
|
|
343
|
+
if args.out:
|
|
344
|
+
output = args.out.expanduser().resolve()
|
|
345
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
346
|
+
temporary = output.with_suffix(output.suffix + ".tmp")
|
|
347
|
+
temporary.write_text(rendered, encoding="utf-8")
|
|
348
|
+
temporary.replace(output)
|
|
349
|
+
print(rendered, end="")
|
|
350
|
+
return 0
|
|
351
|
+
except Exception as exc: # noqa: BLE001
|
|
352
|
+
print(f"error: {exc}")
|
|
353
|
+
return 2
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
if __name__ == "__main__":
|
|
357
|
+
raise SystemExit(main(__import__("sys").argv[1:]))
|