vibedgames 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-FXXVXDTW.js → chunk-24TITAFS.js} +1 -1
- package/dist/{chunk-OGX4DKIS.js → chunk-2C5PG2QO.js} +1 -1
- package/dist/{chunk-HYOXGNWS.js → chunk-2DEVOKI7.js} +1 -1
- package/dist/{chunk-RRI23NK2.js → chunk-2GHPYT2P.js} +1 -1
- package/dist/{chunk-S7HYWITX.js → chunk-2HXGMXGC.js} +1 -1
- package/dist/{chunk-N2UHAQXC.js → chunk-36FORP7T.js} +0 -1
- package/dist/{chunk-VB4WLJR2.js → chunk-3IXRQTRF.js} +1 -1
- package/dist/{chunk-2KVQJKIZ.js → chunk-4ENHS32B.js} +23 -36
- package/dist/{chunk-SXYQL4GK.js → chunk-4YHA32OE.js} +1 -1
- package/dist/{chunk-4FJXCS3K.js → chunk-4ZGQKPK5.js} +1 -1
- package/dist/{chunk-SBXCK2I2.js → chunk-6CLUPFQA.js} +2 -2
- package/dist/{chunk-TXOE5UY5.js → chunk-7WTF2BA4.js} +1 -1
- package/dist/{chunk-R2WVORGD.js → chunk-AAXZNK4Z.js} +1 -1
- package/dist/{chunk-DOOQUFPG.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-SUSX3QIA.js → chunk-E72TFJZP.js} +1 -1
- package/dist/{chunk-E3FJUPLT.js → chunk-EUAAQMUA.js} +2 -0
- package/dist/{chunk-U6DTE5IX.js → chunk-F7LYJSZE.js} +1 -1
- package/dist/{chunk-MEAO33XW.js → chunk-FMON3C74.js} +8 -8
- package/dist/{chunk-GLEW7VJQ.js → chunk-FPILHRLZ.js} +1 -1
- package/dist/{chunk-OPUCUUID.js → chunk-G63MXDX2.js} +4 -0
- 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-RKS7SI5L.js → chunk-NO6KPV64.js} +1 -1
- package/dist/{chunk-KJK5CB6E.js → chunk-NXW3Z4Y4.js} +1 -1
- package/dist/{chunk-7RPLQWR2.js → chunk-OHOAZGO4.js} +1 -1
- package/dist/chunk-PYJNI5WD.js +83 -0
- package/dist/{chunk-NCX6LYNJ.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-HX5Q63UA.js → chunk-T777EXAO.js} +1 -1
- package/dist/{chunk-UQ7VO6B3.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-ZHLPE6LI.js → chunk-UIKYK7KI.js} +1 -1
- package/dist/{chunk-KAGVI3CE.js → chunk-UJRSQO2B.js} +1 -1
- package/dist/{chunk-Q2QC6KAZ.js → chunk-V7LEYVXB.js} +29 -25
- package/dist/{chunk-DB7WVFS7.js → chunk-WRMQEXUC.js} +1 -1
- package/dist/{chunk-HSMG6U7J.js → chunk-WXSBNC67.js} +3 -9
- package/dist/{chunk-QLCVLCPM.js → chunk-X4QIOXNQ.js} +1 -1
- package/dist/{chunk-5YPLKGY3.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-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,406 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import shlex
|
|
6
|
+
import tempfile
|
|
7
|
+
from copy import deepcopy
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Final
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
SCHEMA_VERSION: Final = 1
|
|
13
|
+
STEP_STATUSES: Final = {"pending", "done", "skipped"}
|
|
14
|
+
REFINE_ACTIONS: Final = {"refine-spec", "refine-code"}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
SETUP_STEPS: Final = (
|
|
18
|
+
("image-analysis", "Read grimoire/intake/image_analysis.md and analyze {reference}"),
|
|
19
|
+
(
|
|
20
|
+
"reference-suitability",
|
|
21
|
+
"Read grimoire/intake/validation_rubric.md and record a pass, conditional, or reject verdict for {reference}",
|
|
22
|
+
),
|
|
23
|
+
("reference-admission", "vg asset rebuild-object check-reference-admission {reference}"),
|
|
24
|
+
("local-spec-search", "Run the local evidence search before authoring the assessment"),
|
|
25
|
+
("pre-spec-assessment", "vg asset rebuild-object new-pre-spec-assessment \"<name>\" --image {reference} --out assessment.json"),
|
|
26
|
+
("detail-inventory", "vg asset rebuild-object build-detail-inventory {reference} --mode grid-3x3 --out-dir detail-inventory --out di.json"),
|
|
27
|
+
(
|
|
28
|
+
"projection-route",
|
|
29
|
+
"Record whether projection is required; if required run solve_camera_pose.py, delight_albedo.py, and bake_projected_texture.py, otherwise skip with a reason",
|
|
30
|
+
),
|
|
31
|
+
("spec-authoring", "vg asset rebuild-object new-sculpt-spec \"<name>\" --image {reference} --assessment assessment.json --out object-sculpt-spec.json"),
|
|
32
|
+
(
|
|
33
|
+
"material-evidence",
|
|
34
|
+
"vg asset rebuild-object material-region-analysis --manifest material-regions.json --out-dir material-evidence --out material-analysis.json"
|
|
35
|
+
" (single-crop route: analyze_texture.py + extract_pbr_evidence.py per verified crop; otherwise skip with a reason)",
|
|
36
|
+
),
|
|
37
|
+
("material-spec-wiring", "vg asset rebuild-object apply-material-analysis {spec} material-analysis.json --in-place"),
|
|
38
|
+
("strict-validation", "vg asset rebuild-object validate-sculpt-spec {spec} --strict-quality"),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
CHARACTER_STEPS: Final = (
|
|
42
|
+
(
|
|
43
|
+
"character-contract-read",
|
|
44
|
+
"Read grimoire/character/reconstruction.md and grimoire/character/likeness_maximization.md completely",
|
|
45
|
+
),
|
|
46
|
+
(
|
|
47
|
+
"character-landmarks",
|
|
48
|
+
"vg asset rebuild-object extract-landmarks {reference} --out anatomy.json --overlay landmarks.png",
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
CS2_STEPS: Final = (
|
|
53
|
+
("cs2-contract-read", "Read grimoire/intake/cs2_intake_contract.md completely"),
|
|
54
|
+
("cs2-authoritative-classification", "Obtain an authoritative CS2 family/subtype classification record"),
|
|
55
|
+
("cs2-manifest", "vg asset rebuild-object cs2-manifest {reference} --classification classification.json --out cs2-intake.json"),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
PASS_STEPS: Final = (
|
|
59
|
+
("build-current-pass", "vg asset rebuild-object generate-threejs-factory {spec} --out src/createObjectModel.ts --pass-id {pass_id}"),
|
|
60
|
+
("render-capture", "Render {pass_id} and capture the fixed review view plus meaningful orbit views"),
|
|
61
|
+
("review-contract-read", "Read grimoire/review/gates_reference.md and grimoire/review/self_correction.md completely"),
|
|
62
|
+
("tier1-diagnostics", "vg asset rebuild-object diagnose-render --reference {reference} --render <shot> --spec {spec} --pass-id {pass_id} --in-place"),
|
|
63
|
+
("multi-angle-review", "vg asset rebuild-object diagnose-render-multi-angle --reference <fixed-shot> --orbit <orbit-shot> --orbit <orbit-shot>"),
|
|
64
|
+
("pass-gate-check", "vg asset rebuild-object orchestrate-passes check {spec} --pass-id {pass_id}"),
|
|
65
|
+
("ai-review-recorded", "Create the comparison sheet, inspect it with agent vision, and append exactly one review action"),
|
|
66
|
+
("pipeline-sync", "vg asset rebuild-object orchestrate-passes sync {spec} --in-place"),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
CS2_PASS_STEPS: Final = (
|
|
70
|
+
(
|
|
71
|
+
"cs2-review",
|
|
72
|
+
"vg asset rebuild-object cs2-review --manifest cs2-intake.json --metrics cs2-review-inputs.json --scene forge/tests/fixtures/knife_review_scene.json --out cs2-review.json",
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
FINAL_STEPS: Final = (
|
|
77
|
+
("part-coverage", "vg asset rebuild-object check-part-coverage --spec {spec} --manifest parts.json"),
|
|
78
|
+
("action-ready", "Verify explodable/clickable hierarchy, pivots, sockets, and root.userData.sculptRuntime"),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class WorkflowStateError(ValueError):
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _step(step_id: str, command: str, *, scope: str) -> dict[str, Any]:
|
|
87
|
+
return {
|
|
88
|
+
"id": step_id,
|
|
89
|
+
"scope": scope,
|
|
90
|
+
"status": "pending",
|
|
91
|
+
"evidence": [],
|
|
92
|
+
"reason": "",
|
|
93
|
+
"command": command,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def new_state(
|
|
98
|
+
reference: str,
|
|
99
|
+
*,
|
|
100
|
+
profile: str = "generic",
|
|
101
|
+
spec: str = "",
|
|
102
|
+
max_per_pass: int = 3,
|
|
103
|
+
max_total: int = 6,
|
|
104
|
+
) -> dict[str, Any]:
|
|
105
|
+
if profile not in {"generic", "cs2", "character"}:
|
|
106
|
+
raise WorkflowStateError("profile must be generic, cs2, or character")
|
|
107
|
+
if max_per_pass < 1 or max_total < 1 or max_per_pass > max_total:
|
|
108
|
+
raise WorkflowStateError("loop limits require 1 <= max-per-pass <= max-total")
|
|
109
|
+
setup = [_step(*item, scope="setup") for item in SETUP_STEPS]
|
|
110
|
+
insertion = next(index for index, item in enumerate(setup) if item["id"] == "local-spec-search")
|
|
111
|
+
if profile == "cs2":
|
|
112
|
+
setup[insertion:insertion] = [_step(*item, scope="setup") for item in CS2_STEPS]
|
|
113
|
+
elif profile == "character":
|
|
114
|
+
setup[insertion:insertion] = [_step(*item, scope="setup") for item in CHARACTER_STEPS]
|
|
115
|
+
pass_steps = list(PASS_STEPS)
|
|
116
|
+
if profile == "cs2":
|
|
117
|
+
review_index = next(index for index, item in enumerate(pass_steps) if item[0] == "ai-review-recorded")
|
|
118
|
+
pass_steps[review_index:review_index] = list(CS2_PASS_STEPS)
|
|
119
|
+
state = {
|
|
120
|
+
"schemaVersion": SCHEMA_VERSION,
|
|
121
|
+
"status": "active",
|
|
122
|
+
"profile": profile,
|
|
123
|
+
"currentStep": setup[0]["id"],
|
|
124
|
+
"currentPass": "",
|
|
125
|
+
"checklist": setup
|
|
126
|
+
+ [_step(*item, scope="pass") for item in pass_steps]
|
|
127
|
+
+ [_step(*item, scope="final") for item in FINAL_STEPS],
|
|
128
|
+
"loops": {
|
|
129
|
+
"perPass": {},
|
|
130
|
+
"total": 0,
|
|
131
|
+
"maxPerPass": max_per_pass,
|
|
132
|
+
"maxTotal": max_total,
|
|
133
|
+
},
|
|
134
|
+
"artifacts": {"reference": reference, "spec": spec},
|
|
135
|
+
"passHistory": [],
|
|
136
|
+
"reviewCursor": 0,
|
|
137
|
+
"iterationAction": "initial",
|
|
138
|
+
"stopReason": "",
|
|
139
|
+
}
|
|
140
|
+
recompute(state)
|
|
141
|
+
return state
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def validate_state(state: Any) -> dict[str, Any]:
|
|
145
|
+
if not isinstance(state, dict):
|
|
146
|
+
raise WorkflowStateError("state must be a JSON object")
|
|
147
|
+
if state.get("schemaVersion") != SCHEMA_VERSION:
|
|
148
|
+
raise WorkflowStateError(f"unsupported state schemaVersion: {state.get('schemaVersion')!r}")
|
|
149
|
+
if state.get("profile") not in {"generic", "cs2", "character"}:
|
|
150
|
+
raise WorkflowStateError("state profile is invalid")
|
|
151
|
+
checklist = state.get("checklist")
|
|
152
|
+
if not isinstance(checklist, list) or not checklist:
|
|
153
|
+
raise WorkflowStateError("state checklist must be a non-empty list")
|
|
154
|
+
seen: set[str] = set()
|
|
155
|
+
for entry in checklist:
|
|
156
|
+
if not isinstance(entry, dict) or not isinstance(entry.get("id"), str):
|
|
157
|
+
raise WorkflowStateError("every checklist entry needs a string id")
|
|
158
|
+
if entry["id"] in seen:
|
|
159
|
+
raise WorkflowStateError(f"duplicate checklist step: {entry['id']}")
|
|
160
|
+
seen.add(entry["id"])
|
|
161
|
+
if entry.get("scope") not in {"setup", "pass", "final"}:
|
|
162
|
+
raise WorkflowStateError(f"invalid checklist scope for {entry['id']}")
|
|
163
|
+
if entry.get("status") not in STEP_STATUSES:
|
|
164
|
+
raise WorkflowStateError(f"invalid checklist status for {entry['id']}")
|
|
165
|
+
loops = state.get("loops")
|
|
166
|
+
if not isinstance(loops, dict):
|
|
167
|
+
raise WorkflowStateError("state loops must be an object")
|
|
168
|
+
max_per_pass = loops.get("maxPerPass")
|
|
169
|
+
max_total = loops.get("maxTotal")
|
|
170
|
+
if not isinstance(max_per_pass, int) or not isinstance(max_total, int):
|
|
171
|
+
raise WorkflowStateError("loop limits must be integers")
|
|
172
|
+
if max_per_pass < 1 or max_total < 1 or max_per_pass > max_total:
|
|
173
|
+
raise WorkflowStateError("loop limits require 1 <= maxPerPass <= maxTotal")
|
|
174
|
+
artifacts = state.get("artifacts")
|
|
175
|
+
if not isinstance(artifacts, dict) or not artifacts.get("reference"):
|
|
176
|
+
raise WorkflowStateError("state artifacts.reference is required")
|
|
177
|
+
review_cursor = state.get("reviewCursor", 0)
|
|
178
|
+
if not isinstance(review_cursor, int) or review_cursor < 0:
|
|
179
|
+
raise WorkflowStateError("state reviewCursor must be a non-negative integer")
|
|
180
|
+
return state
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def load_state(path: Path) -> dict[str, Any]:
|
|
184
|
+
try:
|
|
185
|
+
state = json.loads(path.expanduser().read_text(encoding="utf-8"))
|
|
186
|
+
except FileNotFoundError as error:
|
|
187
|
+
raise WorkflowStateError(f"state file does not exist: {path}") from error
|
|
188
|
+
except json.JSONDecodeError as error:
|
|
189
|
+
raise WorkflowStateError(f"state file is not valid JSON: {path}") from error
|
|
190
|
+
return validate_state(state)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def save_state(path: Path, state: dict[str, Any]) -> None:
|
|
194
|
+
validate_state(state)
|
|
195
|
+
target = path.expanduser().resolve()
|
|
196
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
197
|
+
handle, temporary = tempfile.mkstemp(prefix=f".{target.name}.", suffix=".tmp", dir=target.parent)
|
|
198
|
+
try:
|
|
199
|
+
with os.fdopen(handle, "w", encoding="utf-8") as stream:
|
|
200
|
+
json.dump(state, stream, indent=2, ensure_ascii=False)
|
|
201
|
+
stream.write("\n")
|
|
202
|
+
stream.flush()
|
|
203
|
+
os.fsync(stream.fileno())
|
|
204
|
+
os.replace(temporary, target)
|
|
205
|
+
finally:
|
|
206
|
+
if os.path.exists(temporary):
|
|
207
|
+
os.unlink(temporary)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _entries(state: dict[str, Any], scope: str) -> list[dict[str, Any]]:
|
|
211
|
+
return [entry for entry in state["checklist"] if entry["scope"] == scope]
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _pending(entries: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
215
|
+
return [entry for entry in entries if entry["status"] == "pending"]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _format_command(state: dict[str, Any], entry: dict[str, Any]) -> str:
|
|
219
|
+
artifacts = state.get("artifacts", {})
|
|
220
|
+
command = str(entry["command"])
|
|
221
|
+
if entry["id"] == "build-current-pass":
|
|
222
|
+
action = state.get("iterationAction")
|
|
223
|
+
if action == "refine-code":
|
|
224
|
+
return "Refine the existing src/createObjectModel.ts from the latest review; do not regenerate it"
|
|
225
|
+
if action in {"new-pass", "refine-spec"}:
|
|
226
|
+
command += " --force"
|
|
227
|
+
return command.format(
|
|
228
|
+
reference=shlex.quote(str(artifacts.get("reference") or "<reference>")),
|
|
229
|
+
spec=shlex.quote(str(artifacts.get("spec") or "<spec>")),
|
|
230
|
+
pass_id=shlex.quote(str(state.get("currentPass") or "<pass>")),
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def next_entry(state: dict[str, Any]) -> dict[str, Any] | None:
|
|
235
|
+
setup_pending = _pending(_entries(state, "setup"))
|
|
236
|
+
if setup_pending:
|
|
237
|
+
return setup_pending[0]
|
|
238
|
+
if state.get("currentPass") != "complete":
|
|
239
|
+
pass_pending = _pending(_entries(state, "pass"))
|
|
240
|
+
if pass_pending:
|
|
241
|
+
return pass_pending[0]
|
|
242
|
+
return {
|
|
243
|
+
"id": "await-pass-transition",
|
|
244
|
+
"scope": "pass",
|
|
245
|
+
"status": "pending",
|
|
246
|
+
"command": "vg asset rebuild-object next --state .img2threejs/state.json {spec}",
|
|
247
|
+
}
|
|
248
|
+
final_pending = _pending(_entries(state, "final"))
|
|
249
|
+
return final_pending[0] if final_pending else None
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def recompute(state: dict[str, Any]) -> None:
|
|
253
|
+
entry = next_entry(state)
|
|
254
|
+
if state.get("status") == "stopped":
|
|
255
|
+
state["currentStep"] = "stopped"
|
|
256
|
+
elif entry is None:
|
|
257
|
+
state["status"] = "complete"
|
|
258
|
+
state["currentStep"] = "complete"
|
|
259
|
+
state["stopReason"] = ""
|
|
260
|
+
else:
|
|
261
|
+
state["status"] = "active"
|
|
262
|
+
state["currentStep"] = entry["id"]
|
|
263
|
+
state["stopReason"] = ""
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def mark_steps(
|
|
267
|
+
state: dict[str, Any],
|
|
268
|
+
step_ids: list[str],
|
|
269
|
+
*,
|
|
270
|
+
status: str,
|
|
271
|
+
evidence: list[str] | None = None,
|
|
272
|
+
reason: str = "",
|
|
273
|
+
) -> None:
|
|
274
|
+
if state.get("status") == "stopped":
|
|
275
|
+
raise WorkflowStateError("state is hard-stopped; do not mark more work complete")
|
|
276
|
+
if status not in {"done", "skipped", "pending"}:
|
|
277
|
+
raise WorkflowStateError("mark status must be done, skipped, or pending")
|
|
278
|
+
if status == "done" and not evidence:
|
|
279
|
+
raise WorkflowStateError("completing a mandatory step requires at least one --evidence value")
|
|
280
|
+
if status == "skipped" and not reason.strip():
|
|
281
|
+
raise WorkflowStateError("skipping a mandatory step requires --reason")
|
|
282
|
+
by_id = {entry["id"]: entry for entry in state["checklist"]}
|
|
283
|
+
missing = [step_id for step_id in step_ids if step_id not in by_id]
|
|
284
|
+
if missing:
|
|
285
|
+
raise WorkflowStateError(f"unknown checklist step(s): {', '.join(missing)}")
|
|
286
|
+
if status in {"done", "skipped"}:
|
|
287
|
+
for step_id in step_ids:
|
|
288
|
+
expected = next_entry(state)
|
|
289
|
+
if expected is None or expected["id"] != step_id:
|
|
290
|
+
expected_id = expected["id"] if expected else "complete"
|
|
291
|
+
raise WorkflowStateError(
|
|
292
|
+
f"out-of-order checklist update: expected {expected_id}, received {step_id}"
|
|
293
|
+
)
|
|
294
|
+
entry = by_id[step_id]
|
|
295
|
+
entry["status"] = status
|
|
296
|
+
entry["evidence"] = list(evidence or [])
|
|
297
|
+
entry["reason"] = reason.strip()
|
|
298
|
+
recompute(state)
|
|
299
|
+
return
|
|
300
|
+
for step_id in step_ids:
|
|
301
|
+
entry = by_id[step_id]
|
|
302
|
+
entry["status"] = status
|
|
303
|
+
entry["evidence"] = list(evidence or [])
|
|
304
|
+
entry["reason"] = reason.strip()
|
|
305
|
+
recompute(state)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def set_current_pass(state: dict[str, Any], pass_id: str) -> None:
|
|
309
|
+
normalized = pass_id.strip()
|
|
310
|
+
if not normalized:
|
|
311
|
+
raise WorkflowStateError("current pass cannot be empty")
|
|
312
|
+
previous = str(state.get("currentPass") or "")
|
|
313
|
+
if previous and previous != normalized:
|
|
314
|
+
state.setdefault("passHistory", []).append(
|
|
315
|
+
{
|
|
316
|
+
"passId": previous,
|
|
317
|
+
"checklist": deepcopy(_entries(state, "pass")),
|
|
318
|
+
}
|
|
319
|
+
)
|
|
320
|
+
if previous != normalized:
|
|
321
|
+
for entry in _entries(state, "pass"):
|
|
322
|
+
entry["status"] = "pending"
|
|
323
|
+
entry["evidence"] = []
|
|
324
|
+
entry["reason"] = ""
|
|
325
|
+
state["iterationAction"] = "new-pass" if previous else "initial"
|
|
326
|
+
state["currentPass"] = normalized
|
|
327
|
+
recompute(state)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def sync_from_spec(state: dict[str, Any], spec: dict[str, Any], current_pass: str) -> None:
|
|
331
|
+
set_current_pass(state, current_pass)
|
|
332
|
+
history = spec.get("reviewHistory", [])
|
|
333
|
+
if not isinstance(history, list):
|
|
334
|
+
history = []
|
|
335
|
+
review_cursor = min(int(state.get("reviewCursor", 0)), len(history))
|
|
336
|
+
new_reviews = history[review_cursor:]
|
|
337
|
+
refinements = [
|
|
338
|
+
entry
|
|
339
|
+
for entry in new_reviews
|
|
340
|
+
if isinstance(entry, dict)
|
|
341
|
+
and entry.get("passId") == current_pass
|
|
342
|
+
and entry.get("action") in REFINE_ACTIONS
|
|
343
|
+
]
|
|
344
|
+
if current_pass != "complete" and refinements:
|
|
345
|
+
state.setdefault("passHistory", []).append(
|
|
346
|
+
{
|
|
347
|
+
"passId": current_pass,
|
|
348
|
+
"iteration": "refine",
|
|
349
|
+
"checklist": deepcopy(_entries(state, "pass")),
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
for checklist_entry in _entries(state, "pass"):
|
|
353
|
+
checklist_entry["status"] = "pending"
|
|
354
|
+
checklist_entry["evidence"] = []
|
|
355
|
+
checklist_entry["reason"] = ""
|
|
356
|
+
state["iterationAction"] = refinements[-1]["action"]
|
|
357
|
+
state["reviewCursor"] = len(history)
|
|
358
|
+
per_pass: dict[str, int] = {}
|
|
359
|
+
total = 0
|
|
360
|
+
for entry in history:
|
|
361
|
+
if not isinstance(entry, dict) or entry.get("action") not in REFINE_ACTIONS:
|
|
362
|
+
continue
|
|
363
|
+
pass_id = str(entry.get("passId") or "unknown")
|
|
364
|
+
per_pass[pass_id] = per_pass.get(pass_id, 0) + 1
|
|
365
|
+
total += 1
|
|
366
|
+
loops = state["loops"]
|
|
367
|
+
loops["perPass"] = per_pass
|
|
368
|
+
loops["total"] = total
|
|
369
|
+
pass_count = per_pass.get(current_pass, 0)
|
|
370
|
+
if pass_count >= loops["maxPerPass"]:
|
|
371
|
+
state["status"] = "stopped"
|
|
372
|
+
state["currentStep"] = "stopped"
|
|
373
|
+
state["stopReason"] = f"max-correction-loops-reached:{current_pass}:{pass_count}/{loops['maxPerPass']}"
|
|
374
|
+
elif total >= loops["maxTotal"]:
|
|
375
|
+
state["status"] = "stopped"
|
|
376
|
+
state["currentStep"] = "stopped"
|
|
377
|
+
state["stopReason"] = f"max-total-correction-loops-reached:{total}/{loops['maxTotal']}"
|
|
378
|
+
else:
|
|
379
|
+
recompute(state)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def status_payload(state: dict[str, Any]) -> dict[str, Any]:
|
|
383
|
+
entry = next_entry(state)
|
|
384
|
+
current_pass = str(state.get("currentPass") or "")
|
|
385
|
+
loops = state["loops"]
|
|
386
|
+
visible_scopes = {"setup", "final"}
|
|
387
|
+
if current_pass != "complete":
|
|
388
|
+
visible_scopes.add("pass")
|
|
389
|
+
return {
|
|
390
|
+
"status": state["status"],
|
|
391
|
+
"currentStep": state["currentStep"],
|
|
392
|
+
"currentPass": current_pass,
|
|
393
|
+
"loop": {
|
|
394
|
+
"passCount": loops.get("perPass", {}).get(current_pass, 0),
|
|
395
|
+
"maxPerPass": loops["maxPerPass"],
|
|
396
|
+
"totalCount": loops["total"],
|
|
397
|
+
"maxTotal": loops["maxTotal"],
|
|
398
|
+
},
|
|
399
|
+
"nextCommand": None if state["status"] != "active" or entry is None else _format_command(state, entry),
|
|
400
|
+
"stopReason": state.get("stopReason") or None,
|
|
401
|
+
"pending": [
|
|
402
|
+
entry["id"]
|
|
403
|
+
for entry in state["checklist"]
|
|
404
|
+
if entry["scope"] in visible_scopes and entry["status"] == "pending"
|
|
405
|
+
],
|
|
406
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Runtime material-reference contracts for the img2threejs forge."""
|
|
2
|
+
|
|
3
|
+
from .reference import (
|
|
4
|
+
MaterialReferenceError,
|
|
5
|
+
build_assignment,
|
|
6
|
+
load_reference,
|
|
7
|
+
resolve_material,
|
|
8
|
+
validate_reference,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"MaterialReferenceError",
|
|
13
|
+
"build_assignment",
|
|
14
|
+
"load_reference",
|
|
15
|
+
"resolve_material",
|
|
16
|
+
"validate_reference",
|
|
17
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Check material bindings against geometry, UV, rig, collision and LOD contracts."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def check_compatibility(spec: dict[str, Any]) -> dict[str, Any]:
|
|
14
|
+
materials = {str(item.get("id")): item for item in spec.get("materials", []) if isinstance(item, dict) and item.get("id")}
|
|
15
|
+
components = [item for item in spec.get("componentTree", []) if isinstance(item, dict)]
|
|
16
|
+
failures: list[str] = []
|
|
17
|
+
warnings: list[str] = []
|
|
18
|
+
component_ids = {str(item.get("id")) for item in components if item.get("id")}
|
|
19
|
+
referenced: set[str] = set()
|
|
20
|
+
for component in components:
|
|
21
|
+
component_id = str(component.get("id") or component.get("name") or "(unnamed)")
|
|
22
|
+
material_id = component.get("material")
|
|
23
|
+
if material_id:
|
|
24
|
+
referenced.add(str(material_id))
|
|
25
|
+
if str(material_id) not in materials:
|
|
26
|
+
failures.append(f"component {component_id!r} references missing material {material_id!r}")
|
|
27
|
+
if component.get("materialRegions") and not material_id:
|
|
28
|
+
failures.append(f"component {component_id!r} has materialRegions but no material binding")
|
|
29
|
+
for material_id, material in materials.items():
|
|
30
|
+
reference = material.get("materialReference")
|
|
31
|
+
required_maps = reference.get("requiredMaps", []) if isinstance(reference, dict) else []
|
|
32
|
+
pbr = material.get("referencePbr") if isinstance(material.get("referencePbr"), dict) else {}
|
|
33
|
+
maps = pbr.get("maps", {}) if isinstance(pbr.get("maps"), dict) else {}
|
|
34
|
+
projection = material.get("textureProjection")
|
|
35
|
+
has_uv_contract = isinstance(projection, dict) or any(
|
|
36
|
+
isinstance(component.get("uv"), dict) or isinstance(component.get("uvContract"), dict)
|
|
37
|
+
for component in components if component.get("material") == material_id
|
|
38
|
+
)
|
|
39
|
+
if required_maps and not has_uv_contract:
|
|
40
|
+
failures.append(f"material {material_id!r} requires maps but no UV/textureProjection contract exists")
|
|
41
|
+
missing_maps = [channel for channel in required_maps if channel.endswith("Map") and channel not in maps and channel not in {"map", "normalMap"}]
|
|
42
|
+
if missing_maps and pbr:
|
|
43
|
+
warnings.append(f"material {material_id!r} profile requires map slots not present in extracted PBR maps: {missing_maps}")
|
|
44
|
+
unbound = sorted(set(materials) - referenced)
|
|
45
|
+
if unbound:
|
|
46
|
+
warnings.append(f"materials not referenced by componentTree: {unbound}")
|
|
47
|
+
rig = spec.get("rig")
|
|
48
|
+
rigged_components = {
|
|
49
|
+
str(item.get("component")) for item in (rig.get("bones", []) if isinstance(rig, dict) else [])
|
|
50
|
+
if isinstance(item, dict) and item.get("component")
|
|
51
|
+
}
|
|
52
|
+
for component_id in sorted(rigged_components & component_ids):
|
|
53
|
+
component = next(item for item in components if str(item.get("id")) == component_id)
|
|
54
|
+
if not component.get("material"):
|
|
55
|
+
failures.append(f"rigged component {component_id!r} lost its material binding")
|
|
56
|
+
lod = spec.get("lodPlan")
|
|
57
|
+
if lod is not None:
|
|
58
|
+
if not isinstance(lod, list):
|
|
59
|
+
failures.append("lodPlan must remain an array")
|
|
60
|
+
else:
|
|
61
|
+
for index, level in enumerate(lod):
|
|
62
|
+
if isinstance(level, dict):
|
|
63
|
+
ids = level.get("materialIds", level.get("materials", []))
|
|
64
|
+
if isinstance(ids, list):
|
|
65
|
+
missing = sorted({str(value) for value in ids} - set(materials))
|
|
66
|
+
if missing:
|
|
67
|
+
failures.append(f"lodPlan[{index}] references missing material IDs: {missing}")
|
|
68
|
+
collision = spec.get("collisionGroups", spec.get("colliders"))
|
|
69
|
+
if collision is not None and not isinstance(collision, (list, dict)):
|
|
70
|
+
failures.append("collisionGroups/colliders must remain an object or array")
|
|
71
|
+
return {
|
|
72
|
+
"schemaVersion": 1,
|
|
73
|
+
"passed": not failures,
|
|
74
|
+
"failures": failures,
|
|
75
|
+
"warnings": warnings,
|
|
76
|
+
"checked": {
|
|
77
|
+
"materialCount": len(materials),
|
|
78
|
+
"componentCount": len(components),
|
|
79
|
+
"referencedMaterialCount": len(referenced),
|
|
80
|
+
"riggedComponentCount": len(rigged_components),
|
|
81
|
+
"lodPresent": lod is not None,
|
|
82
|
+
"collisionPresent": collision is not None,
|
|
83
|
+
},
|
|
84
|
+
"invariant": "material IDs and UV/map contracts survive geometry, skinning, collision and LOD changes",
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def main(argv: list[str]) -> int:
|
|
89
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
90
|
+
parser.add_argument("spec", type=Path)
|
|
91
|
+
parser.add_argument("--out", type=Path)
|
|
92
|
+
args = parser.parse_args(argv)
|
|
93
|
+
try:
|
|
94
|
+
result = check_compatibility(json.loads(args.spec.read_text(encoding="utf-8")))
|
|
95
|
+
if args.out:
|
|
96
|
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
|
97
|
+
args.out.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8")
|
|
98
|
+
print(json.dumps(result, indent=2))
|
|
99
|
+
return 0 if result["passed"] else 2
|
|
100
|
+
except Exception as exc:
|
|
101
|
+
print(f"error: {exc}")
|
|
102
|
+
return 1
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
raise SystemExit(main(sys.argv[1:]))
|