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,2871 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Validate an ObjectSculptSpec JSON file for procedural Three.js generation."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "_shared"))
|
|
14
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "stage3_build"))
|
|
15
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
16
|
+
from chirality import CHARACTER_LEFT_SIGN, check_pair, find_pairs # noqa: E402
|
|
17
|
+
from feature_acceptance_policy import feature_gate_failures, feature_review_policy
|
|
18
|
+
from hair_profile import REJECTED_HAIR_PRIMITIVES, validate_hair_profile
|
|
19
|
+
from material_physics import check_material_physics, check_open_boundary_sides
|
|
20
|
+
from sdf_primitives import validate_sdf_descriptor
|
|
21
|
+
from vertex_paint import VertexPaintError, normalize_vertex_paint
|
|
22
|
+
from subdivision import (
|
|
23
|
+
ATTACHMENT_CYLINDER_SUBDIVISION_SOURCE_FACES,
|
|
24
|
+
MAX_SUBDIVISION_ITERATIONS,
|
|
25
|
+
MAX_SUBDIVISION_QUAD_FACES,
|
|
26
|
+
resolve_instanced_cluster_base,
|
|
27
|
+
SUBDIVISION_SOURCE_FACE_ESTIMATES,
|
|
28
|
+
)
|
|
29
|
+
from visual_hull import validate_visual_hull_descriptor
|
|
30
|
+
from pipeline_routing import resolve_pipeline_routing, validate_pipeline_routing
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
REQUIRED_TOP_LEVEL = {
|
|
34
|
+
"targetName": str,
|
|
35
|
+
"suitability": str,
|
|
36
|
+
"coordinateFrame": dict,
|
|
37
|
+
"silhouette": dict,
|
|
38
|
+
"componentTree": list,
|
|
39
|
+
"materials": list,
|
|
40
|
+
"proceduralStrategy": list,
|
|
41
|
+
}
|
|
42
|
+
VALID_SUITABILITY = {"pass", "conditional", "reject"}
|
|
43
|
+
VALID_PRIMITIVES = {
|
|
44
|
+
"box",
|
|
45
|
+
"sphere",
|
|
46
|
+
"ellipsoid",
|
|
47
|
+
"cylinder",
|
|
48
|
+
"cone",
|
|
49
|
+
"capsule",
|
|
50
|
+
"torus",
|
|
51
|
+
"tube",
|
|
52
|
+
"lathe",
|
|
53
|
+
"extrude",
|
|
54
|
+
"ground-blade",
|
|
55
|
+
"curve-sweep",
|
|
56
|
+
"tapered-sweep",
|
|
57
|
+
"plane-card",
|
|
58
|
+
"instanced-cluster",
|
|
59
|
+
}
|
|
60
|
+
VALID_COMPONENT_LEVELS = {"macro", "meso", "micro"}
|
|
61
|
+
# Roles that are expected to declare `standProud`. Hair is the only one so far, and it earned the
|
|
62
|
+
# place: it is the one subsystem that carried the requirement as prose while the garment beside it
|
|
63
|
+
# carried the same requirement as a measurement.
|
|
64
|
+
STAND_PROUD_EXPECTED_ROLES = {"hair"}
|
|
65
|
+
VALID_COMPLEXITY_TIERS = {"unassessed", "simple", "moderate", "complex", "ultra-complex"}
|
|
66
|
+
TERMINOLOGY_LIST_FIELDS = {"geometryTerms", "materialTerms", "lightingTerms"}
|
|
67
|
+
VALID_REVIEW_ACTIONS = {"continue", "refine-spec", "refine-code", "request-input", "stop"}
|
|
68
|
+
VALID_TOPOLOGY_CLASSES = {
|
|
69
|
+
"continuous-sculpt",
|
|
70
|
+
"assembled-solid",
|
|
71
|
+
"conforming-shell",
|
|
72
|
+
"surface-relief",
|
|
73
|
+
"fiber-strand",
|
|
74
|
+
"material-only",
|
|
75
|
+
"implicit",
|
|
76
|
+
# Plan 1.5: a zero-thickness, two-sided surface -- a wing membrane, a cape, a leaf,
|
|
77
|
+
# a fin. None of the other seven classes fit: it is not a volume (assembled-solid /
|
|
78
|
+
# continuous-sculpt / implicit all describe solids), and it is not relief carved into
|
|
79
|
+
# a host surface (surface-relief / conforming-shell). Before this class existed such a
|
|
80
|
+
# part had to be routed through `implicit`, but an SDF is a distance field to a
|
|
81
|
+
# *volume boundary* and cannot represent true zero thickness -- it is forced to
|
|
82
|
+
# thicken the membrane into a thin solid. This is the same field-representation limit
|
|
83
|
+
# TRELLIS.2's O-Voxel format removes; see docs/RESEARCH_TRELLIS2_TO_IMG2THREEJS.md
|
|
84
|
+
# section 1.1 and section 4. See validate_open_shell_topology below for what this forbids.
|
|
85
|
+
"open-shell",
|
|
86
|
+
}
|
|
87
|
+
CS2_ROUTES = {"reference-projection", "authored-texture", "procedural-finish"}
|
|
88
|
+
CS2_EXACTNESS_TIERS = {"image-only", "metadata-assisted", "exact-texture"}
|
|
89
|
+
# Plan 1.3 Workstream A: primitives that are structurally wrong for a given topology class.
|
|
90
|
+
# Prevents "Flat-Projection Bias" (e.g. a continuous organic bulge picked as a box-stack).
|
|
91
|
+
DISALLOWED_TOPOLOGY_PRIMITIVE_PAIRS: dict[str, set[str]] = {
|
|
92
|
+
"continuous-sculpt": {"box", "cylinder", "cone"},
|
|
93
|
+
"fiber-strand": {"box", "plane-card"},
|
|
94
|
+
}
|
|
95
|
+
TOPOLOGY_ALLOWED_HINT = {
|
|
96
|
+
"continuous-sculpt": "lathe, extrude, or curve-sweep",
|
|
97
|
+
"fiber-strand": "tube or instanced-cluster",
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Plan 1.5 — the recessed-feature gate (the US-004 defect: "the eye reads as a patch, not
|
|
102
|
+
# a recessed socket"). This is a spec-authoring failure, not a measurement failure, and it
|
|
103
|
+
# is undetectable downstream: a silhouette gate cannot see an interior concavity (a dimple
|
|
104
|
+
# inside the outline changes no silhouette in any view), and a dark-pixel ratio on a
|
|
105
|
+
# concave feature measures cavity SHADING, not material (the reference ear reads 14.3%
|
|
106
|
+
# "dark" from shading gradient alone, peaking at luminance 60-79, versus the wing's 32.9%
|
|
107
|
+
# near-black from actual material). So this class of defect has to be caught in the schema.
|
|
108
|
+
#
|
|
109
|
+
# How a component declares "recessed": we extend the existing free-text `role` field
|
|
110
|
+
# (already token-matched by ATTACHMENT_ROLES / component_requires_attachment below) rather
|
|
111
|
+
# than invent a parallel boolean field. A spec author names the part's role with one of
|
|
112
|
+
# these tokens (`role: "eye-socket"`, `"ear-canal"`, `"mouth-cavity"`, `"nostril"`, ...);
|
|
113
|
+
# `component.name`/`id` are checked too since components are commonly named after the
|
|
114
|
+
# feature they are. This was chosen over (a) a new `concave: true` field, which would be a
|
|
115
|
+
# second place to encode the same fact `role` already carries and would need its own
|
|
116
|
+
# authoring discipline, and (b) reusing `topologyClass` itself, which describes HOW a part
|
|
117
|
+
# is built, not WHAT it represents -- the whole point of this gate is to compare the two.
|
|
118
|
+
#
|
|
119
|
+
# Token design, revised after review — plain "socket" collides with a DIFFERENT, load-
|
|
120
|
+
# bearing meaning already in this file: ATTACHMENT_ROLES (below) uses bare "socket" for an
|
|
121
|
+
# attachment POINT (`attachment.parentSocket`, `actionProfile.sockets[]`), e.g. a handle's
|
|
122
|
+
# hilt socket. That is a real, common authoring case and is not a concavity, so bare
|
|
123
|
+
# "socket" is deliberately NOT a recessed-feature token. Instead we match the specific
|
|
124
|
+
# compound "eyesocket" as a normalized substring (hyphens/spaces/underscores stripped, so
|
|
125
|
+
# `role: "eye-socket"`, `"eye_socket"`, and `"eye socket"` all match) -- narrower than a
|
|
126
|
+
# bare word, so it cannot fire on a plain attachment socket. "hollow" and "concave" are
|
|
127
|
+
# real words but too easily legitimate outside a cavity context ("hollow tube", "concave
|
|
128
|
+
# lens" are both real, non-recessed parts), so they are matched against `role` ONLY, never
|
|
129
|
+
# against `name`/`id`, keeping them out of reach of incidental part-naming collisions.
|
|
130
|
+
# "dimple" was dropped entirely: a dimple is shallow by definition, so it is the wrong word
|
|
131
|
+
# to hold to a depth-requiring rule (below) in the first place.
|
|
132
|
+
#
|
|
133
|
+
# THE CONTRACT, spelled out because the rule below is now strict (allow-list: implicit +
|
|
134
|
+
# subtract, nothing else) and that strictness needs to be a stated trade, not a trap:
|
|
135
|
+
# the token IS the declaration. If a component's role/name/id calls it a cavity, canal, or
|
|
136
|
+
# recess, this rule holds it to building a REAL one. A shallow decorative relief -- a 0.2mm
|
|
137
|
+
# panel line, a knurl pattern -- is not a cavity; do not name it one. Rename it instead
|
|
138
|
+
# (e.g. `panel-relief`, `groove-relief`) and it is untouched by this gate, free to be
|
|
139
|
+
# `surface-relief` or any other topologyClass. That is the legitimate way out, and
|
|
140
|
+
# `test_shallow_relief_panel_without_a_cavity_token_is_accepted` in
|
|
141
|
+
# forge/tests/test_recessed_and_open_shell_topology.py proves it actually works.
|
|
142
|
+
RECESSED_FEATURE_TOKENS = {"cavity", "canal", "recess", "recessed", "nostril"}
|
|
143
|
+
RECESSED_FEATURE_COMPOUND_PHRASES = {"eyesocket"}
|
|
144
|
+
RECESSED_FEATURE_ROLE_ONLY_TOKENS = {"hollow", "concave"}
|
|
145
|
+
# A recessed feature is real concavity: it must be carved out of a volume (`implicit` +
|
|
146
|
+
# an SDF `subtract` operation -- see sdf_primitives.VALID_SDF_OPERATIONS). This is
|
|
147
|
+
# deliberately an ALLOW-list (state the one right shape), not a deny-list (enumerate every
|
|
148
|
+
# wrong one), after review found that a deny-list of {"surface-relief", "plane-card"} still
|
|
149
|
+
# let a THIRD route to the exact same US-004 defect through: `topologyClass:
|
|
150
|
+
# "assembled-solid"` + a convex sphere primitive is not surface-relief, is not plane-card,
|
|
151
|
+
# and never reaches the subtract check below (which was scoped to `implicit`) -- yet it is
|
|
152
|
+
# exactly a convex ball sitting where a recess belongs, and `assembled-solid` + sphere is
|
|
153
|
+
# the MOST likely authoring mistake of the three, since assembled-solid is the common
|
|
154
|
+
# default and a sphere is the obvious eye shape. A deny-list has to predict every wrong
|
|
155
|
+
# answer and a fourth route always remains possible; an allow-list only has to state the
|
|
156
|
+
# right one, so it closes all of them at once.
|
|
157
|
+
RECESSED_FEATURE_REQUIRED_TOPOLOGY = "implicit"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def component_role_tokens(component: dict[str, Any]) -> set[str]:
|
|
161
|
+
"""Same tokenization ATTACHMENT_ROLES matching uses: lowercase, split on non-alphanumerics,
|
|
162
|
+
across role/name/id so a part authored as e.g. `id: "left-eye-socket"` is caught even if
|
|
163
|
+
`role` itself is generic or absent. Fields are joined with a literal space, which also
|
|
164
|
+
acts as the token separator, so a word split across two fields (role="fake eye", name=
|
|
165
|
+
"socket-thing") can never merge into one token here."""
|
|
166
|
+
role = str(component.get("role") or "")
|
|
167
|
+
name = str(component.get("name") or "")
|
|
168
|
+
component_id = str(component.get("id") or "")
|
|
169
|
+
return set(re.findall(r"[a-z0-9]+", f"{role} {name} {component_id}".lower()))
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _normalize_identity_field(value: Any) -> str:
|
|
173
|
+
return re.sub(r"[\s_-]+", "", str(value or "").lower())
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def component_recessed_feature_matches(component: dict[str, Any]) -> set[str]:
|
|
177
|
+
"""Return which recessed-feature signal(s) fired, for both the boolean gate and the
|
|
178
|
+
error message. Compound phrases are checked per-field (role, name, id separately, never
|
|
179
|
+
concatenated) so a phrase can never assemble itself across a field boundary."""
|
|
180
|
+
matches = component_role_tokens(component) & RECESSED_FEATURE_TOKENS
|
|
181
|
+
normalized_fields = (
|
|
182
|
+
_normalize_identity_field(component.get("role")),
|
|
183
|
+
_normalize_identity_field(component.get("name")),
|
|
184
|
+
_normalize_identity_field(component.get("id")),
|
|
185
|
+
)
|
|
186
|
+
matches |= {
|
|
187
|
+
phrase
|
|
188
|
+
for phrase in RECESSED_FEATURE_COMPOUND_PHRASES
|
|
189
|
+
if any(phrase in field for field in normalized_fields)
|
|
190
|
+
}
|
|
191
|
+
role_tokens = set(re.findall(r"[a-z0-9]+", str(component.get("role") or "").lower()))
|
|
192
|
+
matches |= role_tokens & RECESSED_FEATURE_ROLE_ONLY_TOKENS
|
|
193
|
+
return matches
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def component_is_recessed_feature(component: dict[str, Any]) -> bool:
|
|
197
|
+
return bool(component_recessed_feature_matches(component))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def validate_recessed_feature_topology(component_id: str, component: dict[str, Any], errors: list[str]) -> None:
|
|
201
|
+
matches = component_recessed_feature_matches(component)
|
|
202
|
+
if not matches:
|
|
203
|
+
return
|
|
204
|
+
topology_class = component.get("topologyClass")
|
|
205
|
+
primitive = component.get("primitive")
|
|
206
|
+
if topology_class != RECESSED_FEATURE_REQUIRED_TOPOLOGY:
|
|
207
|
+
errors.append(
|
|
208
|
+
f"component {component_id!r} is authored as a recessed feature (role/name/id matches "
|
|
209
|
+
f"{', '.join(sorted(matches))!r}) but is "
|
|
210
|
+
f"topologyClass={topology_class!r} primitive={primitive!r} -- a recessed feature must be real "
|
|
211
|
+
"concavity carved OUT of a volume, not this shape or relief (a convex primitive, a flat "
|
|
212
|
+
"plane-card, and a surface-relief bump are all the same US-004 defect: an eye that reads as a "
|
|
213
|
+
"patch, not a recess) -- reclassify as topologyClass 'implicit' with a geometryDescriptor.sdf "
|
|
214
|
+
"whose operations include 'subtract' to carve the cavity out of the parent volume "
|
|
215
|
+
"(see forge/_shared/sdf_primitives.py VALID_SDF_OPERATIONS)"
|
|
216
|
+
)
|
|
217
|
+
return
|
|
218
|
+
# A rule should verify what it advises: the message above tells the author to use
|
|
219
|
+
# `implicit` + a `subtract` operation, so `implicit` alone is not enough -- an implicit
|
|
220
|
+
# component built ONLY from union/smooth-union operations is a bulge sticking OUT of its
|
|
221
|
+
# parent, not a cavity carved INTO it. That is the same US-004 defect (an eye that reads
|
|
222
|
+
# as a patch, not a recess) wearing a different disguise, and this gate would otherwise
|
|
223
|
+
# wave it through. `subtract` must be PRESENT among the operations, not the only one --
|
|
224
|
+
# a socket legitimately built by smooth-unioning two shapes and then subtracting the
|
|
225
|
+
# result is fine. If `geometryDescriptor.sdf` itself is missing, skip: the
|
|
226
|
+
# `topologyClass 'implicit' requires geometryDescriptor.sdf` check elsewhere already
|
|
227
|
+
# covers that structural case, so this stays free of a duplicate/confusing error.
|
|
228
|
+
descriptor = component.get("geometryDescriptor")
|
|
229
|
+
sdf = descriptor.get("sdf") if isinstance(descriptor, dict) else None
|
|
230
|
+
if isinstance(sdf, dict):
|
|
231
|
+
operations = sdf.get("operations")
|
|
232
|
+
operation_types = (
|
|
233
|
+
[operation.get("type") for operation in operations if isinstance(operation, dict)]
|
|
234
|
+
if isinstance(operations, list)
|
|
235
|
+
else []
|
|
236
|
+
)
|
|
237
|
+
if "subtract" not in operation_types:
|
|
238
|
+
found = ", ".join(sorted({str(item) for item in operation_types})) or "none"
|
|
239
|
+
errors.append(
|
|
240
|
+
f"component {component_id!r} is authored as a recessed feature (role/name/id matches "
|
|
241
|
+
f"{', '.join(sorted(matches))!r}) and is topologyClass 'implicit', but its "
|
|
242
|
+
f"geometryDescriptor.sdf.operations contain no 'subtract' operation (found: {found}) -- "
|
|
243
|
+
"a recessed feature must be carved OUT of a volume; building it only from "
|
|
244
|
+
"union/smooth-union operations produces a bulge sticking OUT, not a cavity, which is "
|
|
245
|
+
"the same US-004 defect (an eye that reads as a patch, not a recess) in disguise. Add a "
|
|
246
|
+
"'subtract' operation that removes volume from the parent shape "
|
|
247
|
+
"(see forge/_shared/sdf_primitives.py VALID_SDF_OPERATIONS)"
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
# Plan 1.5 — open-shell may not pair with a closed SDF: an SDF is a distance field to a
|
|
252
|
+
# volume boundary and has no way to express zero thickness, so combining `topologyClass:
|
|
253
|
+
# "open-shell"` with `geometryDescriptor.sdf` would silently thicken the membrane into a
|
|
254
|
+
# thin solid, defeating the reason open-shell exists. A double-sided material is required
|
|
255
|
+
# for the same reason a one-sided membrane renders invisible from behind: Three.js
|
|
256
|
+
# backface-culls a single-sided material, and an open-shell part is, by definition, seen
|
|
257
|
+
# from both sides.
|
|
258
|
+
def validate_open_shell_topology(
|
|
259
|
+
component_id: str,
|
|
260
|
+
component: dict[str, Any],
|
|
261
|
+
materials_by_id: dict[str, dict[str, Any]],
|
|
262
|
+
errors: list[str],
|
|
263
|
+
) -> None:
|
|
264
|
+
if component.get("topologyClass") != "open-shell":
|
|
265
|
+
return
|
|
266
|
+
descriptor = component.get("geometryDescriptor")
|
|
267
|
+
if isinstance(descriptor, dict) and "sdf" in descriptor:
|
|
268
|
+
errors.append(
|
|
269
|
+
f"component {component_id!r} topologyClass 'open-shell' cannot combine with "
|
|
270
|
+
"geometryDescriptor.sdf -- an SDF is a closed distance field and cannot represent zero "
|
|
271
|
+
"thickness, so it would silently thicken the membrane into a thin solid; drop the sdf "
|
|
272
|
+
"descriptor and build the open-shell surface directly (e.g. plane-card, curve-sweep, or "
|
|
273
|
+
"extrude)"
|
|
274
|
+
)
|
|
275
|
+
material_id = component.get("material")
|
|
276
|
+
material = materials_by_id.get(material_id) if isinstance(material_id, str) else None
|
|
277
|
+
if not isinstance(material, dict) or material.get("doubleSided") is not True:
|
|
278
|
+
errors.append(
|
|
279
|
+
f"component {component_id!r} topologyClass 'open-shell' is a zero-thickness two-sided "
|
|
280
|
+
f"surface but its material {material_id!r} does not set doubleSided: true -- a one-sided "
|
|
281
|
+
"membrane renders invisible from behind; set materials[].doubleSided = true on its material"
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
# Plan 1.3 G.1 — spec-level flatness gate (the karambit-blade defect signature).
|
|
286
|
+
# The robust discriminator is SEMANTIC, not a fragile geometric curvature estimate:
|
|
287
|
+
# `continuous-sculpt` asserts "a continuous volumetric 3D form", so pairing it with a
|
|
288
|
+
# THIN straight extrude (a flat slab) is a contradiction that will read as a flat plane
|
|
289
|
+
# from non-reference angles. A legitimately flat object is tagged surface-relief /
|
|
290
|
+
# conforming-shell / material-only, NOT continuous-sculpt, so it never reaches this gate.
|
|
291
|
+
FLATNESS_DEPTH_RATIO_MAX = 0.15 # depth/diagonal below this ⇒ thin slab
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _bbox_diagonal(points: list) -> float:
|
|
295
|
+
xs = [p[0] for p in points if isinstance(p, (list, tuple)) and len(p) >= 2]
|
|
296
|
+
ys = [p[1] for p in points if isinstance(p, (list, tuple)) and len(p) >= 2]
|
|
297
|
+
if not xs or not ys:
|
|
298
|
+
return 0.0
|
|
299
|
+
return ((max(xs) - min(xs)) ** 2 + (max(ys) - min(ys)) ** 2) ** 0.5
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
TAPER_RATIO_MAX = 0.55 # tip/root radius above this ⇒ it is not tapering, it is a tube
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def taper_risk(component_id: str, component: dict[str, Any]) -> tuple[str, str]:
|
|
306
|
+
"""Warn when a `tapered-sweep`'s stations do not actually taper.
|
|
307
|
+
|
|
308
|
+
Measured from a recovered build: eleven hair locks each ended at radius 0.0327 -- identical to
|
|
309
|
+
four decimals across every lock -- for tip/root ratios of 0.58 to 0.79. The machinery was
|
|
310
|
+
correct and the authored stations were not, so the locks came out blunt and read as noodles.
|
|
311
|
+
Nothing caught it, because a sweep that refuses to taper is still a valid sweep. The reference
|
|
312
|
+
those locks were built against measures 0.087.
|
|
313
|
+
"""
|
|
314
|
+
descriptor = component.get("geometryDescriptor")
|
|
315
|
+
if not isinstance(descriptor, dict):
|
|
316
|
+
return ("OK", "")
|
|
317
|
+
sweep = descriptor.get("taperedSweep")
|
|
318
|
+
if not isinstance(sweep, dict):
|
|
319
|
+
return ("OK", "")
|
|
320
|
+
stations = sweep.get("stations")
|
|
321
|
+
if not isinstance(stations, list) or len(stations) < 2:
|
|
322
|
+
return ("OK", "")
|
|
323
|
+
radii = [
|
|
324
|
+
max(
|
|
325
|
+
float(station.get("rx", 0.0)) if is_number(station.get("rx")) else 0.0,
|
|
326
|
+
float(station.get("rz", 0.0)) if is_number(station.get("rz")) else 0.0,
|
|
327
|
+
)
|
|
328
|
+
for station in stations
|
|
329
|
+
if isinstance(station, dict)
|
|
330
|
+
]
|
|
331
|
+
if len(radii) < 2:
|
|
332
|
+
return ("OK", "")
|
|
333
|
+
root, tip = max(radii), min(radii)
|
|
334
|
+
if root <= 0:
|
|
335
|
+
return ("OK", "")
|
|
336
|
+
# Narrowest station over widest, across ALL stations -- not first over last.
|
|
337
|
+
#
|
|
338
|
+
# Two things break an end-to-end reading. First, station order is not free: a sweep's stations
|
|
339
|
+
# run along its path, and reversing them reverses the triangle winding with them, so a limb
|
|
340
|
+
# authored tip-first renders as an open shell seen from the inside. A part may therefore
|
|
341
|
+
# legitimately be authored root-last, and reading station[0] as "the root" reported a real
|
|
342
|
+
# 0.53 taper as 1.89. Second, plenty of real forms are widest in the MIDDLE -- a barrel torso,
|
|
343
|
+
# a spindle, a lemon -- and their two ends are near-identical however hard they taper; the
|
|
344
|
+
# end-to-end reading called a torso that runs 0.055 to 0.213 and back a constant-radius noodle.
|
|
345
|
+
#
|
|
346
|
+
# The question this check is actually asking is whether the radii vary at all, and that has
|
|
347
|
+
# neither a direction nor a preferred pair of stations.
|
|
348
|
+
ratio = tip / root
|
|
349
|
+
if ratio > TAPER_RATIO_MAX:
|
|
350
|
+
return (
|
|
351
|
+
"HIGH",
|
|
352
|
+
f"quality: component {component_id!r} declares primitive 'tapered-sweep' but its "
|
|
353
|
+
f"stations barely taper (narrow/wide={ratio:.2f} > {TAPER_RATIO_MAX}); it will read as "
|
|
354
|
+
f"a constant-radius noodle. Either taper one end toward the fraction the reference "
|
|
355
|
+
f"measures, or use 'tube' and say so.",
|
|
356
|
+
)
|
|
357
|
+
return ("OK", "")
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def validate_chirality(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
361
|
+
"""Every `-l`/`-r` pair must be a sagittal MIRROR of each other, not a rotated copy.
|
|
362
|
+
|
|
363
|
+
WHY THIS IS A HARD GATE. Two chirality defects shipped in one figure and no gate saw either,
|
|
364
|
+
because both produce geometry that is internally tidy and only wrong against a convention that
|
|
365
|
+
lived in a comment.
|
|
366
|
+
|
|
367
|
+
The one this catches: a limb pair built by negating x AND z. That is a 180-degree rotation about
|
|
368
|
+
the vertical axis, and a rotation PRESERVES handedness, so both limbs come out the same hand.
|
|
369
|
+
Measured on the humanoid's thumb, whose tip sat at z +0.288 on one side and -0.288 on the other
|
|
370
|
+
where a mirror leaves z alone. Fixing it moved the hand region 46% closer to the reference in
|
|
371
|
+
the front view.
|
|
372
|
+
|
|
373
|
+
The one it CANNOT catch, stated here so nobody trusts a green result too far: a pair that is
|
|
374
|
+
wrong the SAME way on both sides is still a perfect mirror of itself. The humanoid's feet were
|
|
375
|
+
exactly that -- both had the big toe on the outer edge -- and this test passes them. That needs
|
|
376
|
+
`chirality.medial_lateral_bias` against a reference, which lives in the stage 4 gate.
|
|
377
|
+
"""
|
|
378
|
+
components = spec.get("componentTree")
|
|
379
|
+
if not isinstance(components, list):
|
|
380
|
+
return
|
|
381
|
+
|
|
382
|
+
positions: dict[str, list[float]] = {}
|
|
383
|
+
for component in components:
|
|
384
|
+
if not isinstance(component, dict) or not component.get("id"):
|
|
385
|
+
continue
|
|
386
|
+
transform = component.get("transform")
|
|
387
|
+
offset = transform.get("position") if isinstance(transform, dict) else None
|
|
388
|
+
if isinstance(offset, list) and len(offset) == 3 and all(
|
|
389
|
+
isinstance(v, (int, float)) and not isinstance(v, bool) for v in offset
|
|
390
|
+
):
|
|
391
|
+
positions[str(component["id"])] = [float(v) for v in offset]
|
|
392
|
+
|
|
393
|
+
for right_id, left_id in find_pairs(positions):
|
|
394
|
+
ok, message = check_pair(right_id.rsplit("-", 1)[0], positions[right_id], positions[left_id])
|
|
395
|
+
if not ok:
|
|
396
|
+
errors.append(f"chirality: {message}")
|
|
397
|
+
|
|
398
|
+
# A component whose id says left but whose position says right. Separate from the pair test
|
|
399
|
+
# because it fires even when only one half of the pair exists.
|
|
400
|
+
#
|
|
401
|
+
# Measured on WORLD x, not on the component's own transform. `transform.position` is relative
|
|
402
|
+
# to the parent, so a nested pair member -- a toe inside a left paw, a claw inside that toe --
|
|
403
|
+
# legitimately carries a negative local x while sitting on the character's left. Reading the
|
|
404
|
+
# local value flagged every inboard toe of a correctly mirrored pair, and the only way to
|
|
405
|
+
# silence it would have been to stop mirroring them, which is the defect this whole function
|
|
406
|
+
# exists to catch. The pair test above deliberately stays on LOCAL coordinates, where a
|
|
407
|
+
# mirrored pair under mirrored parents is exactly a sign flip.
|
|
408
|
+
parents = {
|
|
409
|
+
str(component["id"]): component.get("parent")
|
|
410
|
+
for component in components
|
|
411
|
+
if isinstance(component, dict) and component.get("id")
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
def world_x(component_id: str) -> float:
|
|
415
|
+
total = 0.0
|
|
416
|
+
seen: set[str] = set()
|
|
417
|
+
current = component_id
|
|
418
|
+
while isinstance(current, str) and current in positions and current not in seen:
|
|
419
|
+
seen.add(current)
|
|
420
|
+
total += positions[current][0]
|
|
421
|
+
current = parents.get(current)
|
|
422
|
+
return total
|
|
423
|
+
|
|
424
|
+
for component_id, _offset in sorted(positions.items()):
|
|
425
|
+
side = component_id.rsplit("-", 1)[-1] if "-" in component_id else ""
|
|
426
|
+
accumulated = world_x(component_id)
|
|
427
|
+
if side not in ("l", "r") or abs(accumulated) < 1e-9:
|
|
428
|
+
continue
|
|
429
|
+
expected = CHARACTER_LEFT_SIGN if side == "l" else -CHARACTER_LEFT_SIGN
|
|
430
|
+
if (accumulated > 0) != (expected > 0):
|
|
431
|
+
warnings.append(
|
|
432
|
+
f"quality: component {component_id!r} is named for the character's "
|
|
433
|
+
f"{'left' if side == 'l' else 'right'} but sits at world x {accumulated:+.4f}. With "
|
|
434
|
+
f"forward +Z and a right-handed frame the character's left is +X, so a pose or "
|
|
435
|
+
f"animation addressed by anatomical joint name would drive the wrong side."
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def validate_stand_proud(
|
|
440
|
+
component_id: str,
|
|
441
|
+
component: dict[str, Any],
|
|
442
|
+
errors: list[str],
|
|
443
|
+
warnings: list[str],
|
|
444
|
+
proud_refs: list[tuple[str, str]],
|
|
445
|
+
) -> None:
|
|
446
|
+
"""A component may declare that it must stay OUTSIDE another component's surface.
|
|
447
|
+
|
|
448
|
+
WHY THIS IS A SCHEMA PROPERTY AND NOT AUTHORING DISCIPLINE. The humanoid demo holds the same
|
|
449
|
+
requirement twice, in two different ways, with two different outcomes. The garment holds it as a
|
|
450
|
+
measurement -- `sectionedLoft`'s `hug` marches every vertex outward along its own spoke until a
|
|
451
|
+
signed distance field reads at least `clearance` -- and it works. The hair holds it as a comment:
|
|
452
|
+
|
|
453
|
+
EVERY piece must stand proud of the skull at its own height. Where the skull is proud of the
|
|
454
|
+
hair, the head renders bald there.
|
|
455
|
+
|
|
456
|
+
Widening the hair side masses by hand broke that comment and nothing objected. Closure went
|
|
457
|
+
42.2% to 40.9%, worse on all six views, and dark coverage went DOWN because the widened mass had
|
|
458
|
+
slid off the skull. Measured on the archived captures, crown scalp exposure rose on every view,
|
|
459
|
+
by 14.9 points on the worst one.
|
|
460
|
+
|
|
461
|
+
`clearance` is how far outside the target surface the component must sit. `maxPush` caps how far
|
|
462
|
+
a vertex may travel to get there, and is required rather than optional: an uncapped march walks
|
|
463
|
+
inner vertices straight through the target and out the far side, closing the very gap the
|
|
464
|
+
component exists to leave.
|
|
465
|
+
"""
|
|
466
|
+
proud = component.get("standProud")
|
|
467
|
+
if proud is None:
|
|
468
|
+
if str(component.get("role") or "").lower() in STAND_PROUD_EXPECTED_ROLES:
|
|
469
|
+
warnings.append(
|
|
470
|
+
f"quality: component {component_id!r} has role 'hair' but declares no standProud; "
|
|
471
|
+
f"nothing will stop it sinking into the head, which renders as a bald patch. "
|
|
472
|
+
f"Declare standProud against the head component, or say why it cannot sink."
|
|
473
|
+
)
|
|
474
|
+
return
|
|
475
|
+
|
|
476
|
+
if not isinstance(proud, dict):
|
|
477
|
+
errors.append(f"component {component_id!r} standProud must be an object")
|
|
478
|
+
return
|
|
479
|
+
|
|
480
|
+
against = proud.get("againstComponentId")
|
|
481
|
+
if not isinstance(against, str) or not against.strip():
|
|
482
|
+
errors.append(f"component {component_id!r} standProud.againstComponentId is required")
|
|
483
|
+
elif against == component_id:
|
|
484
|
+
errors.append(f"component {component_id!r} standProud references itself")
|
|
485
|
+
else:
|
|
486
|
+
proud_refs.append((component_id, against))
|
|
487
|
+
|
|
488
|
+
clearance = proud.get("clearance")
|
|
489
|
+
max_push = proud.get("maxPush")
|
|
490
|
+
if not is_number(clearance) or float(clearance) <= 0.0:
|
|
491
|
+
errors.append(
|
|
492
|
+
f"component {component_id!r} standProud.clearance must be a positive number "
|
|
493
|
+
f"(got {clearance!r}); a clearance of zero permits the surfaces to touch and z-fight"
|
|
494
|
+
)
|
|
495
|
+
return
|
|
496
|
+
if not is_number(max_push) or float(max_push) <= 0.0:
|
|
497
|
+
errors.append(
|
|
498
|
+
f"component {component_id!r} standProud.maxPush must be a positive number "
|
|
499
|
+
f"(got {max_push!r}); an uncapped march walks vertices through the target"
|
|
500
|
+
)
|
|
501
|
+
return
|
|
502
|
+
if float(max_push) < float(clearance):
|
|
503
|
+
errors.append(
|
|
504
|
+
f"component {component_id!r} standProud.maxPush ({max_push}) is below its clearance "
|
|
505
|
+
f"({clearance}); the march would stop before reaching the clearance it asks for"
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def flatness_risk(component_id: str, component: dict[str, Any]) -> tuple[str, str]:
|
|
510
|
+
"""Return ('HIGH'|'OK', message). HIGH when a component the spec declares to be a
|
|
511
|
+
continuous 3D form (`continuous-sculpt`, gated at the call site) is built as a THIN
|
|
512
|
+
straight extrude — a flat slab that only reads correctly from the reference angle.
|
|
513
|
+
The fix is `curve-sweep` (sweep a thin cross-section along a 3D spine)."""
|
|
514
|
+
descriptor = component.get("geometryDescriptor") if isinstance(component.get("geometryDescriptor"), dict) else {}
|
|
515
|
+
profile = descriptor.get("profile2D") if isinstance(descriptor.get("profile2D"), dict) else None
|
|
516
|
+
if not profile:
|
|
517
|
+
return ("OK", "")
|
|
518
|
+
points = profile.get("points")
|
|
519
|
+
depth = profile.get("depth")
|
|
520
|
+
if not isinstance(points, list) or not is_number(depth):
|
|
521
|
+
return ("OK", "")
|
|
522
|
+
diagonal = _bbox_diagonal(points)
|
|
523
|
+
if diagonal <= 0:
|
|
524
|
+
return ("OK", "")
|
|
525
|
+
depth_ratio = float(depth) / diagonal
|
|
526
|
+
if depth_ratio < FLATNESS_DEPTH_RATIO_MAX:
|
|
527
|
+
return (
|
|
528
|
+
"HIGH",
|
|
529
|
+
f"quality: component {component_id!r} flatness risk — declared continuous-sculpt (a "
|
|
530
|
+
f"continuous 3D form) but built as a thin straight extrude "
|
|
531
|
+
f"(depth/diagonal={depth_ratio:.3f} < {FLATNESS_DEPTH_RATIO_MAX}); it will read as a flat "
|
|
532
|
+
f"plane bent into a curve from non-reference angles. Use primitive 'curve-sweep' (sweep a "
|
|
533
|
+
f"thin cross-section along a 3D spine), or re-classify the topology if it really is flat.",
|
|
534
|
+
)
|
|
535
|
+
return ("OK", "")
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def schema_version_tuple(spec: dict[str, Any]) -> tuple[int, int]:
|
|
539
|
+
raw = spec.get("schemaVersion")
|
|
540
|
+
if not isinstance(raw, str):
|
|
541
|
+
return (0, 0)
|
|
542
|
+
parts = raw.split(".")
|
|
543
|
+
try:
|
|
544
|
+
return (int(parts[0]), int(parts[1]) if len(parts) > 1 else 0)
|
|
545
|
+
except ValueError:
|
|
546
|
+
return (0, 0)
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def requires_topology_classification(spec: dict[str, Any]) -> bool:
|
|
550
|
+
# Plan 1.3 Risk R2: only specs authored under schema 2.1+ are held to the new
|
|
551
|
+
# topologyClass/topologyRationale requirement, so pre-1.3 specs are not silently
|
|
552
|
+
# broken by a field they were never told to fill in.
|
|
553
|
+
return schema_version_tuple(spec) >= (2, 1)
|
|
554
|
+
VISUAL_PASS_IDS = {
|
|
555
|
+
"blockout",
|
|
556
|
+
"structural-pass",
|
|
557
|
+
"form-refinement",
|
|
558
|
+
"material-pass",
|
|
559
|
+
"surface-pass",
|
|
560
|
+
"lighting-pass",
|
|
561
|
+
"interaction-pass",
|
|
562
|
+
}
|
|
563
|
+
VALID_PIPELINE_PASS_IDS = VISUAL_PASS_IDS | {"optimization-pass"}
|
|
564
|
+
ATTACHMENT_ROLES = {
|
|
565
|
+
"appendage",
|
|
566
|
+
"branch",
|
|
567
|
+
"limb",
|
|
568
|
+
"arm",
|
|
569
|
+
"leg",
|
|
570
|
+
"handle",
|
|
571
|
+
"connector",
|
|
572
|
+
"tube",
|
|
573
|
+
"cable",
|
|
574
|
+
"horn",
|
|
575
|
+
"wing",
|
|
576
|
+
"tail",
|
|
577
|
+
"root",
|
|
578
|
+
"fork",
|
|
579
|
+
"rib",
|
|
580
|
+
"support",
|
|
581
|
+
"hinge",
|
|
582
|
+
"socket",
|
|
583
|
+
"pipe",
|
|
584
|
+
}
|
|
585
|
+
ATTACHMENT_PRIMITIVES = {"cylinder", "cone", "capsule", "tube", "curve-sweep"}
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def is_number(value: Any) -> bool:
|
|
589
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def validate_unit_interval(value: Any, label: str, errors: list[str]) -> None:
|
|
593
|
+
if not is_number(value) or value < 0 or value > 1:
|
|
594
|
+
errors.append(f"{label} must be a number from 0 to 1")
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def load_spec(path: Path) -> dict[str, Any]:
|
|
598
|
+
try:
|
|
599
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
600
|
+
except json.JSONDecodeError as exc:
|
|
601
|
+
raise ValueError(f"invalid JSON: {exc}") from exc
|
|
602
|
+
if not isinstance(payload, dict):
|
|
603
|
+
raise ValueError("spec must be a JSON object")
|
|
604
|
+
return payload
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
def as_number_list(value: Any, length: int) -> bool:
|
|
608
|
+
return (
|
|
609
|
+
isinstance(value, list)
|
|
610
|
+
and len(value) == length
|
|
611
|
+
and all(isinstance(item, (int, float)) for item in value)
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
def validate_score_block(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
616
|
+
scores = spec.get("scores")
|
|
617
|
+
if scores is None:
|
|
618
|
+
warnings.append("missing scores block; image validation evidence will be weaker")
|
|
619
|
+
return
|
|
620
|
+
if not isinstance(scores, dict):
|
|
621
|
+
errors.append("scores must be an object")
|
|
622
|
+
return
|
|
623
|
+
for key, value in scores.items():
|
|
624
|
+
if not isinstance(value, int) or value < 0 or value > 3:
|
|
625
|
+
errors.append(f"score {key!r} must be an integer from 0 to 3")
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def validate_nonnegative_int(value: Any, label: str, errors: list[str]) -> None:
|
|
629
|
+
if not isinstance(value, int) or isinstance(value, bool) or value < 0:
|
|
630
|
+
errors.append(f"{label} must be a non-negative integer")
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
def validate_pre_spec_assessment(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
634
|
+
assessment = spec.get("preSpecAssessment")
|
|
635
|
+
if assessment is None:
|
|
636
|
+
warnings.append("quality: missing preSpecAssessment; spec may be shallow because complexity was not assessed first")
|
|
637
|
+
return
|
|
638
|
+
if not isinstance(assessment, dict):
|
|
639
|
+
errors.append("preSpecAssessment must be an object")
|
|
640
|
+
return
|
|
641
|
+
object_class = assessment.get("objectClass")
|
|
642
|
+
if not isinstance(object_class, dict):
|
|
643
|
+
errors.append("preSpecAssessment.objectClass must be an object")
|
|
644
|
+
else:
|
|
645
|
+
primary_type = object_class.get("primaryType")
|
|
646
|
+
if primary_type is not None and not isinstance(primary_type, str):
|
|
647
|
+
errors.append("preSpecAssessment.objectClass.primaryType must be a string")
|
|
648
|
+
if primary_type in {None, "", "unassessed"}:
|
|
649
|
+
warnings.append("quality: preSpecAssessment.objectClass.primaryType is unassessed")
|
|
650
|
+
for field in ("formLanguage", "structureKind", "motionPotential", "materialFamilies"):
|
|
651
|
+
validate_string_array(object_class.get(field), f"preSpecAssessment.objectClass.{field}", errors)
|
|
652
|
+
if isinstance(object_class.get(field), list) and not object_class[field]:
|
|
653
|
+
warnings.append(f"quality: preSpecAssessment.objectClass.{field} is empty")
|
|
654
|
+
complexity = assessment.get("complexity")
|
|
655
|
+
if not isinstance(complexity, dict):
|
|
656
|
+
errors.append("preSpecAssessment.complexity must be an object")
|
|
657
|
+
else:
|
|
658
|
+
tier = complexity.get("tier")
|
|
659
|
+
if tier not in VALID_COMPLEXITY_TIERS:
|
|
660
|
+
errors.append(f"preSpecAssessment.complexity.tier must be one of: {', '.join(sorted(VALID_COMPLEXITY_TIERS))}")
|
|
661
|
+
if tier == "unassessed":
|
|
662
|
+
warnings.append("quality: preSpecAssessment.complexity.tier is unassessed")
|
|
663
|
+
scores = complexity.get("scores")
|
|
664
|
+
if not isinstance(scores, dict):
|
|
665
|
+
errors.append("preSpecAssessment.complexity.scores must be an object")
|
|
666
|
+
else:
|
|
667
|
+
for key, value in scores.items():
|
|
668
|
+
if not isinstance(value, int) or value < 0 or value > 3:
|
|
669
|
+
errors.append(f"preSpecAssessment.complexity.scores.{key} must be an integer from 0 to 3")
|
|
670
|
+
estimated = complexity.get("estimatedCounts")
|
|
671
|
+
if not isinstance(estimated, dict):
|
|
672
|
+
errors.append("preSpecAssessment.complexity.estimatedCounts must be an object")
|
|
673
|
+
else:
|
|
674
|
+
for field in ("macroComponents", "mesoComponents", "microFeatureGroups", "materialLayers", "repetitionSystems"):
|
|
675
|
+
if field in estimated:
|
|
676
|
+
validate_nonnegative_int(estimated[field], f"preSpecAssessment.complexity.estimatedCounts.{field}", errors)
|
|
677
|
+
validate_string_array(complexity.get("reasoning"), "preSpecAssessment.complexity.reasoning", errors)
|
|
678
|
+
decision = assessment.get("specDepthDecision")
|
|
679
|
+
if not isinstance(decision, dict):
|
|
680
|
+
errors.append("preSpecAssessment.specDepthDecision must be an object")
|
|
681
|
+
else:
|
|
682
|
+
required_depth = decision.get("requiredDepth")
|
|
683
|
+
if required_depth not in VALID_COMPLEXITY_TIERS:
|
|
684
|
+
errors.append("preSpecAssessment.specDepthDecision.requiredDepth must be a valid complexity tier")
|
|
685
|
+
if required_depth == "unassessed":
|
|
686
|
+
warnings.append("quality: preSpecAssessment.specDepthDecision.requiredDepth is unassessed")
|
|
687
|
+
validate_string_array(decision.get("minimumComponentLevels"), "preSpecAssessment.specDepthDecision.minimumComponentLevels", errors)
|
|
688
|
+
for field in (
|
|
689
|
+
"needsRepetitionSystems",
|
|
690
|
+
"needsMaterialLocalOverrides",
|
|
691
|
+
"needsMultipleReviewViews",
|
|
692
|
+
"needsActionReadyHierarchy",
|
|
693
|
+
):
|
|
694
|
+
if field in decision and not isinstance(decision[field], bool):
|
|
695
|
+
errors.append(f"preSpecAssessment.specDepthDecision.{field} must be boolean")
|
|
696
|
+
unknowns = assessment.get("unknownsToResolveBeforeImplementation")
|
|
697
|
+
validate_string_array(unknowns, "preSpecAssessment.unknownsToResolveBeforeImplementation", errors)
|
|
698
|
+
if isinstance(unknowns, list) and unknowns:
|
|
699
|
+
warnings.append("quality: preSpecAssessment has unresolved unknowns before implementation")
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def validate_terminology_profile(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
703
|
+
profile = spec.get("terminologyProfile")
|
|
704
|
+
if profile is None:
|
|
705
|
+
warnings.append("missing terminologyProfile; descriptions may drift into vague non-3D language")
|
|
706
|
+
return
|
|
707
|
+
if not isinstance(profile, dict):
|
|
708
|
+
errors.append("terminologyProfile must be an object")
|
|
709
|
+
return
|
|
710
|
+
for field in TERMINOLOGY_LIST_FIELDS:
|
|
711
|
+
value = profile.get(field)
|
|
712
|
+
if value is None:
|
|
713
|
+
warnings.append(f"terminologyProfile.{field} is missing")
|
|
714
|
+
continue
|
|
715
|
+
if not isinstance(value, list) or not all(isinstance(item, str) and item.strip() for item in value):
|
|
716
|
+
errors.append(f"terminologyProfile.{field} must be an array of non-empty strings")
|
|
717
|
+
rule = profile.get("descriptionRule")
|
|
718
|
+
if rule is not None and not isinstance(rule, str):
|
|
719
|
+
errors.append("terminologyProfile.descriptionRule must be a string")
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
def validate_evidence(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> set[str]:
|
|
723
|
+
refs: set[str] = set()
|
|
724
|
+
evidence = spec.get("viewEvidence", [])
|
|
725
|
+
if evidence is None:
|
|
726
|
+
return refs
|
|
727
|
+
if not isinstance(evidence, list):
|
|
728
|
+
errors.append("viewEvidence must be an array when present")
|
|
729
|
+
return refs
|
|
730
|
+
for index, item in enumerate(evidence):
|
|
731
|
+
if not isinstance(item, dict):
|
|
732
|
+
errors.append(f"viewEvidence[{index}] must be an object")
|
|
733
|
+
continue
|
|
734
|
+
evidence_id = item.get("id")
|
|
735
|
+
if not isinstance(evidence_id, str) or not evidence_id.strip():
|
|
736
|
+
errors.append(f"viewEvidence[{index}].id is required")
|
|
737
|
+
continue
|
|
738
|
+
if evidence_id in refs:
|
|
739
|
+
errors.append(f"duplicate viewEvidence id {evidence_id!r}")
|
|
740
|
+
refs.add(evidence_id)
|
|
741
|
+
confidence = item.get("confidence")
|
|
742
|
+
if confidence is not None:
|
|
743
|
+
validate_unit_interval(confidence, f"viewEvidence {evidence_id!r} confidence", errors)
|
|
744
|
+
region = item.get("imageRegion")
|
|
745
|
+
if region is not None:
|
|
746
|
+
if not isinstance(region, dict):
|
|
747
|
+
errors.append(f"viewEvidence {evidence_id!r} imageRegion must be an object")
|
|
748
|
+
else:
|
|
749
|
+
for key in ("x", "y", "width", "height"):
|
|
750
|
+
if key in region and not is_number(region[key]):
|
|
751
|
+
errors.append(f"viewEvidence {evidence_id!r} imageRegion.{key} must be numeric")
|
|
752
|
+
if not refs:
|
|
753
|
+
warnings.append("missing viewEvidence; local visual claims cannot be traced back to image regions")
|
|
754
|
+
return refs
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
def validate_material_scalar_or_layer(value: Any, label: str, errors: list[str]) -> None:
|
|
758
|
+
if value is None:
|
|
759
|
+
return
|
|
760
|
+
if is_number(value):
|
|
761
|
+
return
|
|
762
|
+
if not isinstance(value, dict):
|
|
763
|
+
errors.append(f"{label} must be a number or object")
|
|
764
|
+
return
|
|
765
|
+
base = value.get("base")
|
|
766
|
+
if base is not None and not is_number(base):
|
|
767
|
+
errors.append(f"{label}.base must be numeric")
|
|
768
|
+
variation = value.get("variation")
|
|
769
|
+
if variation is not None and not is_number(variation):
|
|
770
|
+
errors.append(f"{label}.variation must be numeric")
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
def validate_reference_pbr_map(value: Any, label: str, errors: list[str]) -> None:
|
|
774
|
+
if not isinstance(value, dict):
|
|
775
|
+
errors.append(f"{label} must be an object")
|
|
776
|
+
return
|
|
777
|
+
has_locator = False
|
|
778
|
+
for field in ("path", "url"):
|
|
779
|
+
item = value.get(field)
|
|
780
|
+
if item is not None:
|
|
781
|
+
if not isinstance(item, str) or not item.strip():
|
|
782
|
+
errors.append(f"{label}.{field} must be a non-empty string when present")
|
|
783
|
+
else:
|
|
784
|
+
has_locator = True
|
|
785
|
+
if not has_locator:
|
|
786
|
+
errors.append(f"{label} needs a path or url")
|
|
787
|
+
channel = value.get("channel")
|
|
788
|
+
if channel is not None and not isinstance(channel, str):
|
|
789
|
+
errors.append(f"{label}.channel must be a string")
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
def validate_reference_pbr(material_id: str, value: Any, errors: list[str], warnings: list[str]) -> None:
|
|
793
|
+
if value is None:
|
|
794
|
+
return
|
|
795
|
+
if not isinstance(value, dict):
|
|
796
|
+
errors.append(f"material {material_id!r} referencePbr must be an object")
|
|
797
|
+
return
|
|
798
|
+
for field in ("version", "sourceImage", "extractor", "method", "verdict", "hardLimit"):
|
|
799
|
+
item = value.get(field)
|
|
800
|
+
if item is not None and not isinstance(item, str):
|
|
801
|
+
errors.append(f"material {material_id!r} referencePbr.{field} must be a string")
|
|
802
|
+
usable = value.get("usable")
|
|
803
|
+
if usable is not None and not isinstance(usable, bool):
|
|
804
|
+
errors.append(f"material {material_id!r} referencePbr.usable must be boolean")
|
|
805
|
+
for field in ("confidence", "estimatedFidelity", "targetThreshold"):
|
|
806
|
+
item = value.get(field)
|
|
807
|
+
if item is not None:
|
|
808
|
+
validate_unit_interval(item, f"material {material_id!r} referencePbr.{field}", errors)
|
|
809
|
+
maps = value.get("maps")
|
|
810
|
+
if maps is None:
|
|
811
|
+
warnings.append(f"quality: material {material_id!r} referencePbr is missing maps")
|
|
812
|
+
return
|
|
813
|
+
if not isinstance(maps, dict):
|
|
814
|
+
errors.append(f"material {material_id!r} referencePbr.maps must be an object")
|
|
815
|
+
return
|
|
816
|
+
required = ("albedo", "roughness", "height", "normal", "ao")
|
|
817
|
+
for channel in required:
|
|
818
|
+
if channel not in maps:
|
|
819
|
+
warnings.append(f"quality: material {material_id!r} referencePbr.maps missing {channel}")
|
|
820
|
+
else:
|
|
821
|
+
validate_reference_pbr_map(maps[channel], f"material {material_id!r} referencePbr.maps.{channel}", errors)
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
def validate_cs2_view_dependent_environment(spec: dict[str, Any], errors: list[str]) -> None:
|
|
825
|
+
"""View-dependent CS2 finishes (anodized / anodized-multicolored) read their color from
|
|
826
|
+
environment reflections -- rendering one with no environment at all is a muddy-render gate
|
|
827
|
+
failure, not a quality nit. The code-generated default environment always exists unless
|
|
828
|
+
explicitly disabled (cs2Finish.environmentAvailable = false), so this only fires as the
|
|
829
|
+
last-resort guard described in design.md, never on the default image-only path.
|
|
830
|
+
See grimoire/build/cs2_finishes.md."""
|
|
831
|
+
materials = [m for m in spec.get("materials", []) if isinstance(m, dict)]
|
|
832
|
+
view_dependent = [m for m in materials if m.get("needsEnvironment") is True]
|
|
833
|
+
if not view_dependent:
|
|
834
|
+
return
|
|
835
|
+
cs2_finish = spec.get("cs2Finish")
|
|
836
|
+
environment_available = not (isinstance(cs2_finish, dict) and cs2_finish.get("environmentAvailable") is False)
|
|
837
|
+
if not environment_available:
|
|
838
|
+
names = ", ".join(str(m.get("id")) for m in view_dependent)
|
|
839
|
+
errors.append(
|
|
840
|
+
f"material(s) {names} are view-dependent and need an environment map (scene.environment) "
|
|
841
|
+
"or they render muddy, but cs2Finish.environmentAvailable is false -- enable the "
|
|
842
|
+
"code-generated default environment or supply a user HDRI before generating "
|
|
843
|
+
"(see grimoire/build/cs2_finishes.md)"
|
|
844
|
+
)
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
def validate_cs2_contract(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
848
|
+
intake = spec.get("cs2Intake")
|
|
849
|
+
if intake is None:
|
|
850
|
+
return
|
|
851
|
+
if not isinstance(intake, dict):
|
|
852
|
+
errors.append("cs2Intake must be an object")
|
|
853
|
+
return
|
|
854
|
+
route = intake.get("route")
|
|
855
|
+
tier = intake.get("exactnessTier")
|
|
856
|
+
if route not in CS2_ROUTES:
|
|
857
|
+
errors.append("cs2Intake.route must be a supported CS2 route")
|
|
858
|
+
if tier not in CS2_EXACTNESS_TIERS:
|
|
859
|
+
errors.append("cs2Intake.exactnessTier must be a supported exactness tier")
|
|
860
|
+
if intake.get("itemFamily") != "knife":
|
|
861
|
+
errors.append("cs2Intake requires the registered knife adapter")
|
|
862
|
+
if route == "reference-projection":
|
|
863
|
+
camera = spec.get("referenceCamera")
|
|
864
|
+
source = intake.get("deLitAlbedo") or intake.get("sourceImage")
|
|
865
|
+
if not isinstance(camera, dict) or camera.get("solved") is not True:
|
|
866
|
+
warnings.append("quality: reference-projection needs solved referenceCamera")
|
|
867
|
+
if not isinstance(source, str) or not source.strip():
|
|
868
|
+
errors.append("reference-projection requires a de-lit source image")
|
|
869
|
+
if route == "authored-texture":
|
|
870
|
+
materials = [item for item in spec.get("materials", []) if isinstance(item, dict)]
|
|
871
|
+
pbr = next((item.get("referencePbr") for item in materials if item.get("id") == "skin-finish"), None)
|
|
872
|
+
maps = pbr.get("maps") if isinstance(pbr, dict) else None
|
|
873
|
+
required = ("albedo", "normal", "roughness", "metalness")
|
|
874
|
+
if tier == "exact-texture" and (not isinstance(maps, dict) or not all(key in maps for key in required)):
|
|
875
|
+
errors.append("exact-texture authored route requires independent albedo, normal, roughness, and metalness maps")
|
|
876
|
+
if route == "procedural-finish" and tier == "exact-texture":
|
|
877
|
+
errors.append("procedural-finish cannot claim exact-texture")
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
def validate_pipeline_routing_contract(spec: dict[str, Any], errors: list[str]) -> None:
|
|
881
|
+
routing = spec.get("pipelineRouting")
|
|
882
|
+
legacy_cs2 = routing is None and spec.get("cs2Intake") is not None
|
|
883
|
+
if routing is None:
|
|
884
|
+
if spec.get("cs2Intake") is None:
|
|
885
|
+
return
|
|
886
|
+
routing = resolve_pipeline_routing(legacy_cs2=True)
|
|
887
|
+
routing_errors = validate_pipeline_routing(routing)
|
|
888
|
+
errors.extend(routing_errors)
|
|
889
|
+
if not isinstance(routing, dict) or routing.get("status") != "resolved":
|
|
890
|
+
errors.append("pipelineRouting must be resolved before validation")
|
|
891
|
+
return
|
|
892
|
+
routing_track = routing.get("track")
|
|
893
|
+
object_class = spec.get("preSpecAssessment", {}).get("objectClass", {})
|
|
894
|
+
if routing_track == "character-v1.5" and spec.get("cs2Intake") is not None:
|
|
895
|
+
errors.append("character-v1.5 routing cannot carry cs2Intake")
|
|
896
|
+
if routing_track == "character-v1.5" and object_class.get("primaryDomain") not in {"character", "hybrid"}:
|
|
897
|
+
errors.append("character-v1.5 routing requires the character template")
|
|
898
|
+
if routing_track == "weapon-v1.4" and not legacy_cs2 and object_class.get("cs2") is not True:
|
|
899
|
+
errors.append("weapon-v1.4 routing requires the CS2 weapon template")
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
def validate_materials(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> set[str]:
|
|
903
|
+
material_ids: set[str] = set()
|
|
904
|
+
for index, material in enumerate(spec.get("materials", [])):
|
|
905
|
+
if not isinstance(material, dict):
|
|
906
|
+
errors.append(f"materials[{index}] must be an object")
|
|
907
|
+
continue
|
|
908
|
+
material_id = material.get("id")
|
|
909
|
+
if not isinstance(material_id, str) or not material_id.strip():
|
|
910
|
+
errors.append(f"materials[{index}].id is required")
|
|
911
|
+
continue
|
|
912
|
+
if material_id in material_ids:
|
|
913
|
+
errors.append(f"duplicate material id {material_id!r}")
|
|
914
|
+
material_ids.add(material_id)
|
|
915
|
+
# What three.js will ACTUALLY do with these numbers -- gated features, clamps, values folded
|
|
916
|
+
# into one uniform, and the base-darkening sheen applies to itself. A value the engine ignores
|
|
917
|
+
# is worse than a missing one: it reads as authored evidence and renders as nothing.
|
|
918
|
+
# Derivation with every file:line: grimoire/build/threejs_skin_and_cloth_materials.md
|
|
919
|
+
physics_errors, physics_warnings = check_material_physics(material_id, material)
|
|
920
|
+
errors.extend(physics_errors)
|
|
921
|
+
warnings.extend(physics_warnings)
|
|
922
|
+
color = material.get("baseColor", material.get("color"))
|
|
923
|
+
if color is not None and not (isinstance(color, str) and color.startswith("#") and len(color) in {4, 7}):
|
|
924
|
+
errors.append(f"material {material_id!r} baseColor/color should be #RGB or #RRGGBB")
|
|
925
|
+
for field in ("shaderModel", "type"):
|
|
926
|
+
value = material.get(field)
|
|
927
|
+
if value is not None and not isinstance(value, str):
|
|
928
|
+
errors.append(f"material {material_id!r} {field} must be a string")
|
|
929
|
+
double_sided = material.get("doubleSided")
|
|
930
|
+
if double_sided is not None and not isinstance(double_sided, bool):
|
|
931
|
+
errors.append(f"material {material_id!r} doubleSided must be boolean")
|
|
932
|
+
for field in ("albedo", "ambientOcclusion"):
|
|
933
|
+
value = material.get(field)
|
|
934
|
+
if value is not None and not isinstance(value, dict):
|
|
935
|
+
errors.append(f"material {material_id!r} {field} must be an object")
|
|
936
|
+
validate_material_scalar_or_layer(material.get("roughness"), f"material {material_id!r} roughness", errors)
|
|
937
|
+
validate_material_scalar_or_layer(material.get("metalness"), f"material {material_id!r} metalness", errors)
|
|
938
|
+
for field in ("normal", "bump", "displacement", "wear", "dirt"):
|
|
939
|
+
value = material.get(field)
|
|
940
|
+
if value is not None and not isinstance(value, dict):
|
|
941
|
+
errors.append(f"material {material_id!r} {field} must be an object")
|
|
942
|
+
texture_resolution = material.get("textureResolution")
|
|
943
|
+
if texture_resolution is not None and (
|
|
944
|
+
not isinstance(texture_resolution, int)
|
|
945
|
+
or isinstance(texture_resolution, bool)
|
|
946
|
+
or texture_resolution < 64
|
|
947
|
+
or texture_resolution > 4096
|
|
948
|
+
):
|
|
949
|
+
errors.append(f"material {material_id!r} textureResolution must be an integer from 64 to 4096")
|
|
950
|
+
projection = material.get("textureProjection")
|
|
951
|
+
if projection is not None:
|
|
952
|
+
if not isinstance(projection, dict):
|
|
953
|
+
errors.append(f"material {material_id!r} textureProjection must be an object")
|
|
954
|
+
else:
|
|
955
|
+
mode = projection.get("mode")
|
|
956
|
+
if mode is not None and not isinstance(mode, str):
|
|
957
|
+
errors.append(f"material {material_id!r} textureProjection.mode must be a string")
|
|
958
|
+
repeat = projection.get("repeat")
|
|
959
|
+
if repeat is not None and not (
|
|
960
|
+
isinstance(repeat, list)
|
|
961
|
+
and len(repeat) == 2
|
|
962
|
+
and all(is_number(item) and item > 0 for item in repeat)
|
|
963
|
+
):
|
|
964
|
+
errors.append(f"material {material_id!r} textureProjection.repeat must contain two positive numbers")
|
|
965
|
+
anisotropy = projection.get("anisotropy")
|
|
966
|
+
if anisotropy is not None and (not is_number(anisotropy) or anisotropy < 1):
|
|
967
|
+
errors.append(f"material {material_id!r} textureProjection.anisotropy must be >= 1")
|
|
968
|
+
frequency_bands = material.get("surfaceFrequencyBands")
|
|
969
|
+
if frequency_bands is not None:
|
|
970
|
+
if not isinstance(frequency_bands, list):
|
|
971
|
+
errors.append(f"material {material_id!r} surfaceFrequencyBands must be an array")
|
|
972
|
+
else:
|
|
973
|
+
seen_band_ids: set[str] = set()
|
|
974
|
+
for band_index, band in enumerate(frequency_bands):
|
|
975
|
+
if not isinstance(band, dict):
|
|
976
|
+
errors.append(
|
|
977
|
+
f"material {material_id!r} surfaceFrequencyBands[{band_index}] must be an object"
|
|
978
|
+
)
|
|
979
|
+
continue
|
|
980
|
+
band_id = band.get("id")
|
|
981
|
+
if not isinstance(band_id, str) or not band_id.strip():
|
|
982
|
+
errors.append(
|
|
983
|
+
f"material {material_id!r} surfaceFrequencyBands[{band_index}].id is required"
|
|
984
|
+
)
|
|
985
|
+
elif band_id in seen_band_ids:
|
|
986
|
+
errors.append(f"material {material_id!r} has duplicate surface band {band_id!r}")
|
|
987
|
+
else:
|
|
988
|
+
seen_band_ids.add(band_id)
|
|
989
|
+
for field in ("frequency", "amplitude"):
|
|
990
|
+
value = band.get(field)
|
|
991
|
+
if not is_number(value) or value <= 0:
|
|
992
|
+
errors.append(
|
|
993
|
+
f"material {material_id!r} surfaceFrequencyBands[{band_index}].{field} "
|
|
994
|
+
"must be a positive number"
|
|
995
|
+
)
|
|
996
|
+
local_overrides = material.get("localOverrides", [])
|
|
997
|
+
if local_overrides is not None and not isinstance(local_overrides, list):
|
|
998
|
+
errors.append(f"material {material_id!r} localOverrides must be an array")
|
|
999
|
+
shader_notes = material.get("shaderNotes")
|
|
1000
|
+
if shader_notes is not None:
|
|
1001
|
+
validate_string_array(shader_notes, f"material {material_id!r} shaderNotes", errors)
|
|
1002
|
+
validate_textureless(material_id, material, errors)
|
|
1003
|
+
validate_reference_pbr(material_id, material.get("referencePbr"), errors, warnings)
|
|
1004
|
+
if not material_ids:
|
|
1005
|
+
errors.append("at least one material is required")
|
|
1006
|
+
return material_ids
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
def validate_material_pipeline_contract(spec: dict[str, Any], material_ids: set[str], errors: list[str], warnings: list[str]) -> None:
|
|
1010
|
+
"""Validate the optional v1.5 material-reference hand-off.
|
|
1011
|
+
|
|
1012
|
+
Legacy specs remain valid. Once ``materialPipeline`` is present, every
|
|
1013
|
+
analyzed region must point at a real spec material and retain evidence.
|
|
1014
|
+
"""
|
|
1015
|
+
pipeline = spec.get("materialPipeline")
|
|
1016
|
+
if pipeline is None:
|
|
1017
|
+
return
|
|
1018
|
+
if not isinstance(pipeline, dict):
|
|
1019
|
+
errors.append("materialPipeline must be an object")
|
|
1020
|
+
return
|
|
1021
|
+
if pipeline.get("schemaVersion") != 1:
|
|
1022
|
+
errors.append("materialPipeline.schemaVersion must be 1")
|
|
1023
|
+
status = pipeline.get("status")
|
|
1024
|
+
if status not in {"proceed", "probe"}:
|
|
1025
|
+
errors.append("materialPipeline.status must be proceed or probe")
|
|
1026
|
+
regions = pipeline.get("regions")
|
|
1027
|
+
if not isinstance(regions, list) or not regions:
|
|
1028
|
+
errors.append("materialPipeline.regions must be a non-empty array")
|
|
1029
|
+
return
|
|
1030
|
+
for index, region in enumerate(regions):
|
|
1031
|
+
if not isinstance(region, dict):
|
|
1032
|
+
errors.append(f"materialPipeline.regions[{index}] must be an object")
|
|
1033
|
+
continue
|
|
1034
|
+
material_id = region.get("specMaterialId")
|
|
1035
|
+
if material_id not in material_ids:
|
|
1036
|
+
errors.append(f"materialPipeline region {region.get('regionId')!r} references unknown material {material_id!r}")
|
|
1037
|
+
for field in ("componentId", "regionId", "profileId"):
|
|
1038
|
+
if not isinstance(region.get(field), str) or not region[field].strip():
|
|
1039
|
+
errors.append(f"materialPipeline.regions[{index}].{field} is required")
|
|
1040
|
+
registry = pipeline.get("registry")
|
|
1041
|
+
if not isinstance(registry, str) or not registry.strip():
|
|
1042
|
+
errors.append("materialPipeline.registry is required")
|
|
1043
|
+
elif not registry.endswith("material-reference.json"):
|
|
1044
|
+
warnings.append("quality: materialPipeline.registry does not point to material-reference.json")
|
|
1045
|
+
def validate_dimensions(component_id: str, dimensions: Any, errors: list[str]) -> None:
|
|
1046
|
+
if dimensions is None:
|
|
1047
|
+
return
|
|
1048
|
+
if not isinstance(dimensions, dict):
|
|
1049
|
+
errors.append(f"component {component_id!r} dimensions must be an object")
|
|
1050
|
+
return
|
|
1051
|
+
for field in ("width", "height", "depth", "radius", "length"):
|
|
1052
|
+
if field in dimensions and not is_number(dimensions[field]):
|
|
1053
|
+
errors.append(f"component {component_id!r} dimensions.{field} must be numeric")
|
|
1054
|
+
confidence = dimensions.get("confidence")
|
|
1055
|
+
if confidence is not None:
|
|
1056
|
+
validate_unit_interval(confidence, f"component {component_id!r} dimensions.confidence", errors)
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
def validate_geometry_descriptor(component_id: str, descriptor: Any, errors: list[str]) -> None:
|
|
1060
|
+
if descriptor is None:
|
|
1061
|
+
return
|
|
1062
|
+
if not isinstance(descriptor, dict):
|
|
1063
|
+
errors.append(f"component {component_id!r} geometryDescriptor must be an object")
|
|
1064
|
+
return
|
|
1065
|
+
for field in ("topologyIntent", "uvStrategy", "normalStrategy"):
|
|
1066
|
+
value = descriptor.get(field)
|
|
1067
|
+
if value is not None and not isinstance(value, str):
|
|
1068
|
+
errors.append(f"component {component_id!r} geometryDescriptor.{field} must be a string")
|
|
1069
|
+
edge = descriptor.get("edgeTreatment")
|
|
1070
|
+
if edge is not None:
|
|
1071
|
+
if not isinstance(edge, dict):
|
|
1072
|
+
errors.append(f"component {component_id!r} geometryDescriptor.edgeTreatment must be an object")
|
|
1073
|
+
else:
|
|
1074
|
+
if "bevelRadius" in edge and not is_number(edge["bevelRadius"]):
|
|
1075
|
+
errors.append(f"component {component_id!r} edgeTreatment.bevelRadius must be numeric")
|
|
1076
|
+
if "segments" in edge and not isinstance(edge["segments"], int):
|
|
1077
|
+
errors.append(f"component {component_id!r} edgeTreatment.segments must be an integer")
|
|
1078
|
+
stack = descriptor.get("deformationStack")
|
|
1079
|
+
if stack is not None and not isinstance(stack, list):
|
|
1080
|
+
errors.append(f"component {component_id!r} geometryDescriptor.deformationStack must be an array")
|
|
1081
|
+
subdivide = descriptor.get("subdivide")
|
|
1082
|
+
if subdivide is not None:
|
|
1083
|
+
if not isinstance(subdivide, dict):
|
|
1084
|
+
errors.append(f"component {component_id!r} geometryDescriptor.subdivide must be an object")
|
|
1085
|
+
elif "iterations" in subdivide:
|
|
1086
|
+
iterations = subdivide["iterations"]
|
|
1087
|
+
label = f"component {component_id!r} geometryDescriptor.subdivide.iterations"
|
|
1088
|
+
if not isinstance(iterations, int) or isinstance(iterations, bool) or iterations < 0:
|
|
1089
|
+
errors.append(f"{label} must be a non-negative integer")
|
|
1090
|
+
elif iterations > MAX_SUBDIVISION_ITERATIONS:
|
|
1091
|
+
errors.append(f"{label} must not exceed {MAX_SUBDIVISION_ITERATIONS}")
|
|
1092
|
+
decimate = descriptor.get("decimate")
|
|
1093
|
+
if decimate is not None:
|
|
1094
|
+
label = f"component {component_id!r} geometryDescriptor.decimate"
|
|
1095
|
+
if not isinstance(decimate, dict):
|
|
1096
|
+
errors.append(f"{label} must be an object")
|
|
1097
|
+
else:
|
|
1098
|
+
ratio = decimate.get("targetRatio")
|
|
1099
|
+
if isinstance(ratio, bool) or not isinstance(ratio, (int, float)):
|
|
1100
|
+
errors.append(f"{label}.targetRatio must be a number")
|
|
1101
|
+
elif not 0.0 < float(ratio) < 1.0:
|
|
1102
|
+
# 1.0 is rejected rather than treated as a no-op: asking to keep everything is
|
|
1103
|
+
# almost always a mistaken ratio, and paying for a quadric pass that removes
|
|
1104
|
+
# nothing is worse than being told.
|
|
1105
|
+
errors.append(f"{label}.targetRatio must be greater than 0 and less than 1")
|
|
1106
|
+
uv_strategy = str(descriptor.get("uvStrategy") or "")
|
|
1107
|
+
if "unwrap" in uv_strategy.lower() or "authored" in uv_strategy.lower():
|
|
1108
|
+
# Decimation keeps `position` and recomputes normals; a quadric collapse has no
|
|
1109
|
+
# correct answer for an authored UV at the merged vertex, so the seam would move.
|
|
1110
|
+
errors.append(
|
|
1111
|
+
f"{label} cannot combine with an authored/unwrapped uvStrategy "
|
|
1112
|
+
f"({uv_strategy!r}); decimation keeps position only and drops UVs"
|
|
1113
|
+
)
|
|
1114
|
+
if "sdf" in descriptor:
|
|
1115
|
+
validate_sdf_descriptor(component_id, descriptor["sdf"], errors)
|
|
1116
|
+
if "visualHull" in descriptor:
|
|
1117
|
+
validate_visual_hull_descriptor(component_id, descriptor["visualHull"], errors)
|
|
1118
|
+
if "sdf" in descriptor and "visualHull" in descriptor:
|
|
1119
|
+
errors.append(f"component {component_id!r} geometryDescriptor cannot combine sdf and visualHull")
|
|
1120
|
+
if "visualHull" in descriptor and "subdivide" in descriptor:
|
|
1121
|
+
errors.append(f"component {component_id!r} geometryDescriptor.visualHull cannot combine with subdivide")
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
def attachment_emits_cylinder(attachment: Any) -> bool:
|
|
1125
|
+
if not isinstance(attachment, dict):
|
|
1126
|
+
return False
|
|
1127
|
+
start = attachment.get("localStart")
|
|
1128
|
+
end = attachment.get("localEnd")
|
|
1129
|
+
start_vector = start if as_number_list(start, 3) else [0, 0, 0]
|
|
1130
|
+
end_vector = end if as_number_list(end, 3) else [0, 1, 0]
|
|
1131
|
+
return sum((float(end_vector[index]) - float(start_vector[index])) ** 2 for index in range(3)) > 0.0001**2
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
def emitted_subdivision_primitive(primitive: str, topology_class: Any, descriptor: dict[str, Any]) -> str:
|
|
1135
|
+
if topology_class == "implicit":
|
|
1136
|
+
return "implicit sdf"
|
|
1137
|
+
return resolve_instanced_cluster_base(primitive, descriptor, VALID_PRIMITIVES)
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
def validate_subdivision_budget(
|
|
1141
|
+
component_id: str,
|
|
1142
|
+
primitive: Any,
|
|
1143
|
+
topology_class: Any,
|
|
1144
|
+
descriptor: Any,
|
|
1145
|
+
attachment: Any,
|
|
1146
|
+
errors: list[str],
|
|
1147
|
+
) -> None:
|
|
1148
|
+
if not isinstance(primitive, str) or not isinstance(descriptor, dict):
|
|
1149
|
+
return
|
|
1150
|
+
subdivide = descriptor.get("subdivide")
|
|
1151
|
+
if not isinstance(subdivide, dict):
|
|
1152
|
+
return
|
|
1153
|
+
iterations = subdivide.get("iterations")
|
|
1154
|
+
if (
|
|
1155
|
+
not isinstance(iterations, int)
|
|
1156
|
+
or isinstance(iterations, bool)
|
|
1157
|
+
or iterations < 1
|
|
1158
|
+
or iterations > MAX_SUBDIVISION_ITERATIONS
|
|
1159
|
+
):
|
|
1160
|
+
return
|
|
1161
|
+
emitted_primitive = emitted_subdivision_primitive(primitive, topology_class, descriptor)
|
|
1162
|
+
if emitted_primitive == "implicit sdf":
|
|
1163
|
+
errors.append(
|
|
1164
|
+
f"component {component_id!r} geometryDescriptor.subdivide.iterations cannot statically budget "
|
|
1165
|
+
"emitted primitive 'implicit sdf'; subdivision is unsupported for this generator path"
|
|
1166
|
+
)
|
|
1167
|
+
return
|
|
1168
|
+
if emitted_primitive == "plane-card":
|
|
1169
|
+
errors.append(
|
|
1170
|
+
f"component {component_id!r} geometryDescriptor.subdivide.iterations plane-card subdivision topology is unsupported "
|
|
1171
|
+
"because generated PlaneGeometry has open boundary edges"
|
|
1172
|
+
)
|
|
1173
|
+
return
|
|
1174
|
+
uses_attachment_cylinder = attachment_emits_cylinder(attachment)
|
|
1175
|
+
if emitted_primitive == "torus" and not uses_attachment_cylinder:
|
|
1176
|
+
errors.append(
|
|
1177
|
+
f"component {component_id!r} geometryDescriptor.subdivide.iterations torus subdivision topology is unsupported "
|
|
1178
|
+
"because generated TorusGeometry has an open weld seam"
|
|
1179
|
+
)
|
|
1180
|
+
return
|
|
1181
|
+
source_faces = ATTACHMENT_CYLINDER_SUBDIVISION_SOURCE_FACES if uses_attachment_cylinder else SUBDIVISION_SOURCE_FACE_ESTIMATES.get(emitted_primitive)
|
|
1182
|
+
if source_faces is None:
|
|
1183
|
+
errors.append(
|
|
1184
|
+
f"component {component_id!r} geometryDescriptor.subdivide.iterations cannot statically budget "
|
|
1185
|
+
f"emitted primitive {emitted_primitive!r}; subdivision is unsupported for this generator path"
|
|
1186
|
+
)
|
|
1187
|
+
return
|
|
1188
|
+
projected_faces = source_faces * (4**iterations)
|
|
1189
|
+
if projected_faces > MAX_SUBDIVISION_QUAD_FACES:
|
|
1190
|
+
source_label = "attachment cylinder" if uses_attachment_cylinder else f"primitive {emitted_primitive!r}"
|
|
1191
|
+
errors.append(
|
|
1192
|
+
f"component {component_id!r} geometryDescriptor.subdivide.iterations would produce "
|
|
1193
|
+
f"{projected_faces} quad faces for {source_label}, exceeding "
|
|
1194
|
+
f"the maximum {MAX_SUBDIVISION_QUAD_FACES}"
|
|
1195
|
+
)
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
def validate_bool_object(value: Any, label: str, errors: list[str]) -> None:
|
|
1199
|
+
if value is None:
|
|
1200
|
+
return
|
|
1201
|
+
if not isinstance(value, dict):
|
|
1202
|
+
errors.append(f"{label} must be an object")
|
|
1203
|
+
return
|
|
1204
|
+
for key, item in value.items():
|
|
1205
|
+
if not isinstance(key, str):
|
|
1206
|
+
errors.append(f"{label} keys must be strings")
|
|
1207
|
+
if not isinstance(item, bool):
|
|
1208
|
+
errors.append(f"{label}.{key} must be boolean")
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
def validate_action_profile(component_id: str, profile: Any, errors: list[str], warnings: list[str]) -> None:
|
|
1212
|
+
if profile is None:
|
|
1213
|
+
warnings.append(f"component {component_id!r} is missing actionProfile; future animation/destruction may require refactor")
|
|
1214
|
+
return
|
|
1215
|
+
if not isinstance(profile, dict):
|
|
1216
|
+
errors.append(f"component {component_id!r} actionProfile must be an object")
|
|
1217
|
+
return
|
|
1218
|
+
role = profile.get("animationRole")
|
|
1219
|
+
if role is not None and not isinstance(role, str):
|
|
1220
|
+
errors.append(f"component {component_id!r} actionProfile.animationRole must be a string")
|
|
1221
|
+
pivot = profile.get("pivot")
|
|
1222
|
+
if pivot is not None:
|
|
1223
|
+
if not isinstance(pivot, dict):
|
|
1224
|
+
errors.append(f"component {component_id!r} actionProfile.pivot must be an object")
|
|
1225
|
+
else:
|
|
1226
|
+
mode = pivot.get("mode")
|
|
1227
|
+
if mode is not None and not isinstance(mode, str):
|
|
1228
|
+
errors.append(f"component {component_id!r} actionProfile.pivot.mode must be a string")
|
|
1229
|
+
for field in ("localPosition", "axis"):
|
|
1230
|
+
if field in pivot and not as_number_list(pivot[field], 3):
|
|
1231
|
+
errors.append(f"component {component_id!r} actionProfile.pivot.{field} must be [number, number, number]")
|
|
1232
|
+
confidence = pivot.get("confidence")
|
|
1233
|
+
if confidence is not None:
|
|
1234
|
+
validate_unit_interval(confidence, f"component {component_id!r} actionProfile.pivot.confidence", errors)
|
|
1235
|
+
validate_bool_object(profile.get("transformChannels"), f"component {component_id!r} actionProfile.transformChannels", errors)
|
|
1236
|
+
sockets = profile.get("sockets")
|
|
1237
|
+
if sockets is not None:
|
|
1238
|
+
if not isinstance(sockets, list):
|
|
1239
|
+
errors.append(f"component {component_id!r} actionProfile.sockets must be an array")
|
|
1240
|
+
else:
|
|
1241
|
+
for socket_index, socket in enumerate(sockets):
|
|
1242
|
+
if not isinstance(socket, dict):
|
|
1243
|
+
errors.append(f"component {component_id!r} actionProfile.sockets[{socket_index}] must be an object")
|
|
1244
|
+
continue
|
|
1245
|
+
socket_id = socket.get("id")
|
|
1246
|
+
if socket_id is not None and not isinstance(socket_id, str):
|
|
1247
|
+
errors.append(f"component {component_id!r} actionProfile.sockets[{socket_index}].id must be a string")
|
|
1248
|
+
for field in ("localPosition", "position", "localRotation", "rotation"):
|
|
1249
|
+
if field in socket and not as_number_list(socket[field], 3):
|
|
1250
|
+
errors.append(
|
|
1251
|
+
f"component {component_id!r} actionProfile.sockets[{socket_index}].{field} must be [number, number, number]"
|
|
1252
|
+
)
|
|
1253
|
+
collider = profile.get("collider")
|
|
1254
|
+
if collider is not None:
|
|
1255
|
+
if not isinstance(collider, dict):
|
|
1256
|
+
errors.append(f"component {component_id!r} actionProfile.collider must be an object")
|
|
1257
|
+
else:
|
|
1258
|
+
collider_type = collider.get("type")
|
|
1259
|
+
if collider_type is not None and not isinstance(collider_type, str):
|
|
1260
|
+
errors.append(f"component {component_id!r} actionProfile.collider.type must be a string")
|
|
1261
|
+
for field in ("offset", "scale"):
|
|
1262
|
+
if field in collider and not as_number_list(collider[field], 3):
|
|
1263
|
+
errors.append(f"component {component_id!r} actionProfile.collider.{field} must be [number, number, number]")
|
|
1264
|
+
if "isTrigger" in collider and not isinstance(collider["isTrigger"], bool):
|
|
1265
|
+
errors.append(f"component {component_id!r} actionProfile.collider.isTrigger must be boolean")
|
|
1266
|
+
constraints = profile.get("constraints")
|
|
1267
|
+
if constraints is not None and not isinstance(constraints, list):
|
|
1268
|
+
errors.append(f"component {component_id!r} actionProfile.constraints must be an array")
|
|
1269
|
+
destruction = profile.get("destruction")
|
|
1270
|
+
if destruction is not None:
|
|
1271
|
+
if not isinstance(destruction, dict):
|
|
1272
|
+
errors.append(f"component {component_id!r} actionProfile.destruction must be an object")
|
|
1273
|
+
else:
|
|
1274
|
+
if "breakable" in destruction and not isinstance(destruction["breakable"], bool):
|
|
1275
|
+
errors.append(f"component {component_id!r} actionProfile.destruction.breakable must be boolean")
|
|
1276
|
+
if "breakImpulse" in destruction and not is_number(destruction["breakImpulse"]):
|
|
1277
|
+
errors.append(f"component {component_id!r} actionProfile.destruction.breakImpulse must be numeric")
|
|
1278
|
+
for field in ("fractureGroup", "debrisMaterial"):
|
|
1279
|
+
value = destruction.get(field)
|
|
1280
|
+
if value is not None and not isinstance(value, str):
|
|
1281
|
+
errors.append(f"component {component_id!r} actionProfile.destruction.{field} must be a string")
|
|
1282
|
+
for field in ("seamRefs", "detachableFragments"):
|
|
1283
|
+
validate_string_array(destruction.get(field), f"component {component_id!r} actionProfile.destruction.{field}", errors)
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
def component_requires_attachment(component: dict[str, Any]) -> bool:
|
|
1287
|
+
if not component.get("parent"):
|
|
1288
|
+
return False
|
|
1289
|
+
role = str(component.get("role") or "").lower()
|
|
1290
|
+
name = str(component.get("name") or component.get("id") or "").lower()
|
|
1291
|
+
primitive = str(component.get("primitive") or "").lower()
|
|
1292
|
+
profile = component.get("actionProfile") if isinstance(component.get("actionProfile"), dict) else {}
|
|
1293
|
+
animation_role = str(profile.get("animationRole") or "").lower()
|
|
1294
|
+
tokens = {role, animation_role} | set(re.findall(r"[a-z0-9]+", name))
|
|
1295
|
+
return bool(tokens & ATTACHMENT_ROLES) or primitive in ATTACHMENT_PRIMITIVES
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
def has_attachment_number(value: Any) -> bool:
|
|
1299
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
def attachment_is_complete(attachment: dict[str, Any]) -> bool:
|
|
1303
|
+
has_endpoint = as_number_list(attachment.get("localStart"), 3) and as_number_list(attachment.get("localEnd"), 3)
|
|
1304
|
+
has_socket = isinstance(attachment.get("parentSocket"), str) and bool(attachment["parentSocket"].strip())
|
|
1305
|
+
has_parent_id = isinstance(attachment.get("parentId"), str) and bool(attachment["parentId"].strip())
|
|
1306
|
+
has_contact = isinstance(attachment.get("contactType"), str) and bool(attachment["contactType"].strip())
|
|
1307
|
+
has_overlap = (
|
|
1308
|
+
has_attachment_number(attachment.get("embedDepth"))
|
|
1309
|
+
and float(attachment["embedDepth"]) > 0
|
|
1310
|
+
) or (
|
|
1311
|
+
has_attachment_number(attachment.get("overlap"))
|
|
1312
|
+
and float(attachment["overlap"]) > 0
|
|
1313
|
+
)
|
|
1314
|
+
has_tolerance = has_attachment_number(attachment.get("gapTolerance"))
|
|
1315
|
+
return has_endpoint and (has_socket or has_parent_id) and has_contact and has_overlap and has_tolerance
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
def validate_attachment(
|
|
1319
|
+
component_id: str,
|
|
1320
|
+
parent: str | None,
|
|
1321
|
+
attachment: Any,
|
|
1322
|
+
required: bool,
|
|
1323
|
+
errors: list[str],
|
|
1324
|
+
warnings: list[str],
|
|
1325
|
+
) -> None:
|
|
1326
|
+
if attachment is None:
|
|
1327
|
+
if required:
|
|
1328
|
+
warnings.append(
|
|
1329
|
+
f"quality: component {component_id!r} requires attachment.parentSocket, localStart/localEnd, "
|
|
1330
|
+
"contactType, embedDepth or overlap, and gapTolerance"
|
|
1331
|
+
)
|
|
1332
|
+
return
|
|
1333
|
+
if not isinstance(attachment, dict):
|
|
1334
|
+
errors.append(f"component {component_id!r} attachment must be an object")
|
|
1335
|
+
return
|
|
1336
|
+
for field in ("parentId", "parentSocket", "contactType"):
|
|
1337
|
+
value = attachment.get(field)
|
|
1338
|
+
if value is not None and not isinstance(value, str):
|
|
1339
|
+
errors.append(f"component {component_id!r} attachment.{field} must be a string")
|
|
1340
|
+
if parent and isinstance(attachment.get("parentId"), str) and attachment["parentId"] != parent:
|
|
1341
|
+
warnings.append(
|
|
1342
|
+
f"quality: component {component_id!r} attachment.parentId {attachment['parentId']!r} "
|
|
1343
|
+
f"does not match parent {parent!r}"
|
|
1344
|
+
)
|
|
1345
|
+
for field in ("localStart", "localEnd", "contactNormal"):
|
|
1346
|
+
value = attachment.get(field)
|
|
1347
|
+
if value is not None and not as_number_list(value, 3):
|
|
1348
|
+
errors.append(f"component {component_id!r} attachment.{field} must be [number, number, number]")
|
|
1349
|
+
for field in ("embedDepth", "overlap", "gapTolerance", "baseRadius", "endRadius"):
|
|
1350
|
+
value = attachment.get(field)
|
|
1351
|
+
if value is not None and (not has_attachment_number(value) or float(value) < 0):
|
|
1352
|
+
errors.append(f"component {component_id!r} attachment.{field} must be a non-negative number")
|
|
1353
|
+
validate_string_array(attachment.get("evidenceRefs"), f"component {component_id!r} attachment.evidenceRefs", errors)
|
|
1354
|
+
if required and not attachment_is_complete(attachment):
|
|
1355
|
+
warnings.append(
|
|
1356
|
+
f"quality: component {component_id!r} requires attachment.parentSocket, localStart/localEnd, "
|
|
1357
|
+
"contactType, embedDepth or overlap, and gapTolerance"
|
|
1358
|
+
)
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
def validate_string_array(value: Any, label: str, errors: list[str]) -> None:
|
|
1362
|
+
if value is None:
|
|
1363
|
+
return
|
|
1364
|
+
if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
|
|
1365
|
+
errors.append(f"{label} must be an array of strings")
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
VALID_MATERIAL_CLASSES = {
|
|
1369
|
+
"metal", "plastic", "wood", "fabric", "skin", "glass", "ceramic", "rubber", "stone", "unknown",
|
|
1370
|
+
}
|
|
1371
|
+
# Alpha accepts "0", "1", "0.xxx", "1.xxx", or ".xxx" — must match what lab_to_rgba() in
|
|
1372
|
+
# extract_part_color_recipe.py actually emits (round(alpha, 3) renders full opacity as "1.0",
|
|
1373
|
+
# not bare "1"), or every extracted recipe fails this check on its own real output.
|
|
1374
|
+
RGBA_PATTERN = re.compile(r"^rgba\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*(?:(?:0|1)(?:\.\d+)?|\.\d+)\s*\)$")
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
def is_rgba_string(value: Any) -> bool:
|
|
1378
|
+
return isinstance(value, str) and bool(RGBA_PATTERN.match(value.strip()))
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
def validate_color_material_recipe(component_id: str, recipe: Any, warnings: list[str]) -> None:
|
|
1382
|
+
"""Plan 1.3 Workstream C: every non-material-only component needs a structured,
|
|
1383
|
+
evidence-linked colorMaterialRecipe instead of bare-word colors. Fires as a
|
|
1384
|
+
'quality:' warning so --strict-quality (not normal validation) enforces it,
|
|
1385
|
+
matching the topologyClass gating above."""
|
|
1386
|
+
if not isinstance(recipe, dict):
|
|
1387
|
+
warnings.append(f"quality: component {component_id!r} is missing colorMaterialRecipe")
|
|
1388
|
+
return
|
|
1389
|
+
for field in ("dominantAlbedo", "secondaryAlbedo"):
|
|
1390
|
+
if not is_rgba_string(recipe.get(field)):
|
|
1391
|
+
warnings.append(
|
|
1392
|
+
f"quality: component {component_id!r} colorMaterialRecipe.{field} must be an "
|
|
1393
|
+
f"'rgba(r, g, b, a)' string"
|
|
1394
|
+
)
|
|
1395
|
+
material_class = recipe.get("materialClass")
|
|
1396
|
+
if material_class not in VALID_MATERIAL_CLASSES:
|
|
1397
|
+
warnings.append(
|
|
1398
|
+
f"quality: component {component_id!r} colorMaterialRecipe.materialClass must be one "
|
|
1399
|
+
f"of: {', '.join(sorted(VALID_MATERIAL_CLASSES))}"
|
|
1400
|
+
)
|
|
1401
|
+
confidence = recipe.get("materialClassConfidence")
|
|
1402
|
+
if not is_number(confidence) or not (0.0 <= float(confidence) <= 1.0):
|
|
1403
|
+
warnings.append(
|
|
1404
|
+
f"quality: component {component_id!r} colorMaterialRecipe.materialClassConfidence "
|
|
1405
|
+
f"must be a number between 0.0 and 1.0"
|
|
1406
|
+
)
|
|
1407
|
+
gradient = recipe.get("colorGradient")
|
|
1408
|
+
if gradient is not None:
|
|
1409
|
+
if not isinstance(gradient, dict) or gradient.get("type") not in {"linear", "radial"}:
|
|
1410
|
+
warnings.append(
|
|
1411
|
+
f"quality: component {component_id!r} colorMaterialRecipe.colorGradient.type "
|
|
1412
|
+
f"must be 'linear' or 'radial'"
|
|
1413
|
+
)
|
|
1414
|
+
stops = gradient.get("stops") if isinstance(gradient, dict) else None
|
|
1415
|
+
if not isinstance(stops, list) or len(stops) < 2:
|
|
1416
|
+
warnings.append(
|
|
1417
|
+
f"quality: component {component_id!r} colorMaterialRecipe.colorGradient.stops "
|
|
1418
|
+
f"must have at least 2 entries"
|
|
1419
|
+
)
|
|
1420
|
+
elif any(not is_rgba_string(stop.get("color")) for stop in stops if isinstance(stop, dict)):
|
|
1421
|
+
warnings.append(
|
|
1422
|
+
f"quality: component {component_id!r} colorMaterialRecipe.colorGradient.stops[].color "
|
|
1423
|
+
f"must be 'rgba(r, g, b, a)' strings"
|
|
1424
|
+
)
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
def validate_components(
|
|
1428
|
+
spec: dict[str, Any],
|
|
1429
|
+
material_ids: set[str],
|
|
1430
|
+
evidence_ids: set[str],
|
|
1431
|
+
errors: list[str],
|
|
1432
|
+
warnings: list[str],
|
|
1433
|
+
) -> None:
|
|
1434
|
+
components = spec.get("componentTree", [])
|
|
1435
|
+
materials_by_id = {
|
|
1436
|
+
material.get("id"): material
|
|
1437
|
+
for material in spec.get("materials", [])
|
|
1438
|
+
if isinstance(material, dict) and isinstance(material.get("id"), str)
|
|
1439
|
+
}
|
|
1440
|
+
ids: set[str] = set()
|
|
1441
|
+
parent_refs: list[tuple[str, str]] = []
|
|
1442
|
+
proud_refs: list[tuple[str, str]] = []
|
|
1443
|
+
for index, component in enumerate(components):
|
|
1444
|
+
if not isinstance(component, dict):
|
|
1445
|
+
errors.append(f"componentTree[{index}] must be an object")
|
|
1446
|
+
continue
|
|
1447
|
+
component_id = component.get("id")
|
|
1448
|
+
if not isinstance(component_id, str) or not component_id.strip():
|
|
1449
|
+
errors.append(f"componentTree[{index}].id is required")
|
|
1450
|
+
continue
|
|
1451
|
+
if component_id in ids:
|
|
1452
|
+
errors.append(f"duplicate component id {component_id!r}")
|
|
1453
|
+
ids.add(component_id)
|
|
1454
|
+
primitive = component.get("primitive")
|
|
1455
|
+
if primitive not in VALID_PRIMITIVES:
|
|
1456
|
+
errors.append(
|
|
1457
|
+
f"component {component_id!r} primitive must be one of: {', '.join(sorted(VALID_PRIMITIVES))}"
|
|
1458
|
+
)
|
|
1459
|
+
# Plan 1.5: recessed-feature gate runs unconditionally (not schema-version gated like
|
|
1460
|
+
# topologyClass below) -- a flat patch faking a socket is a defect at any schema version.
|
|
1461
|
+
validate_recessed_feature_topology(component_id, component, errors)
|
|
1462
|
+
if requires_topology_classification(spec):
|
|
1463
|
+
topology_class = component.get("topologyClass")
|
|
1464
|
+
topology_rationale = component.get("topologyRationale")
|
|
1465
|
+
if topology_class not in VALID_TOPOLOGY_CLASSES:
|
|
1466
|
+
warnings.append(
|
|
1467
|
+
f"quality: component {component_id!r} missing or invalid topologyClass "
|
|
1468
|
+
f"(must be one of: {', '.join(sorted(VALID_TOPOLOGY_CLASSES))})"
|
|
1469
|
+
)
|
|
1470
|
+
else:
|
|
1471
|
+
if not isinstance(topology_rationale, str) or not topology_rationale.strip():
|
|
1472
|
+
warnings.append(
|
|
1473
|
+
f"quality: component {component_id!r} topologyRationale is required alongside topologyClass"
|
|
1474
|
+
)
|
|
1475
|
+
else:
|
|
1476
|
+
normalized_rationale = re.sub(r"[\s_-]+", "", topology_rationale.strip().lower())
|
|
1477
|
+
normalized_class = re.sub(r"[\s_-]+", "", topology_class.lower())
|
|
1478
|
+
if normalized_rationale == normalized_class:
|
|
1479
|
+
warnings.append(
|
|
1480
|
+
f"quality: component {component_id!r} topologyRationale restates the enum "
|
|
1481
|
+
f"value instead of citing visible evidence"
|
|
1482
|
+
)
|
|
1483
|
+
disallowed = DISALLOWED_TOPOLOGY_PRIMITIVE_PAIRS.get(topology_class, set())
|
|
1484
|
+
if primitive in disallowed:
|
|
1485
|
+
hint = TOPOLOGY_ALLOWED_HINT.get(topology_class, "an allowed primitive")
|
|
1486
|
+
warnings.append(
|
|
1487
|
+
f"quality: component {component_id!r} pairs topologyClass={topology_class!r} "
|
|
1488
|
+
f"with disallowed primitive {primitive!r} (use {hint} instead)"
|
|
1489
|
+
)
|
|
1490
|
+
# Plan 1.3 Workstream C: gated on topologyClass (already required above),
|
|
1491
|
+
# not colorMaterialRecipe.materialClass — that field only exists once the
|
|
1492
|
+
# recipe is present, so using it as its own gate would be circular.
|
|
1493
|
+
if topology_class != "material-only":
|
|
1494
|
+
validate_color_material_recipe(component_id, component.get("colorMaterialRecipe"), warnings)
|
|
1495
|
+
# Plan 1.3 G.1: flatness pre-check — catch a flat extrude faking a curved
|
|
1496
|
+
# 3D form BEFORE any render (the karambit-blade defect: a thin extrude of a
|
|
1497
|
+
# curved silhouette only looks right from the reference camera angle).
|
|
1498
|
+
if primitive == "extrude" and topology_class == "continuous-sculpt":
|
|
1499
|
+
severity, message = flatness_risk(component_id, component)
|
|
1500
|
+
if severity == "HIGH":
|
|
1501
|
+
warnings.append(message)
|
|
1502
|
+
taper_severity, taper_message = taper_risk(component_id, component)
|
|
1503
|
+
if taper_severity == "HIGH":
|
|
1504
|
+
warnings.append(taper_message)
|
|
1505
|
+
if topology_class == "implicit":
|
|
1506
|
+
descriptor = component.get("geometryDescriptor")
|
|
1507
|
+
if not isinstance(descriptor, dict) or "sdf" not in descriptor:
|
|
1508
|
+
errors.append(f"component {component_id!r} topologyClass 'implicit' requires geometryDescriptor.sdf")
|
|
1509
|
+
if topology_class == "open-shell":
|
|
1510
|
+
validate_open_shell_topology(component_id, component, materials_by_id, errors)
|
|
1511
|
+
level = component.get("level")
|
|
1512
|
+
if level is not None and level not in VALID_COMPONENT_LEVELS:
|
|
1513
|
+
errors.append(f"component {component_id!r} level must be macro, meso, or micro")
|
|
1514
|
+
for field in ("importance", "confidence"):
|
|
1515
|
+
value = component.get(field)
|
|
1516
|
+
if value is not None:
|
|
1517
|
+
validate_unit_interval(value, f"component {component_id!r} {field}", errors)
|
|
1518
|
+
parent = component.get("parent")
|
|
1519
|
+
if parent:
|
|
1520
|
+
if not isinstance(parent, str):
|
|
1521
|
+
errors.append(f"component {component_id!r} parent must be a string or null")
|
|
1522
|
+
else:
|
|
1523
|
+
parent_refs.append((component_id, parent))
|
|
1524
|
+
material = component.get("material")
|
|
1525
|
+
if material and material not in material_ids:
|
|
1526
|
+
errors.append(f"component {component_id!r} references unknown material {material!r}")
|
|
1527
|
+
validate_geometry_descriptor(component_id, component.get("geometryDescriptor"), errors)
|
|
1528
|
+
validate_stand_proud(component_id, component, errors, warnings, proud_refs)
|
|
1529
|
+
# three's Material.side defaults to FrontSide, which culls backfaces, so a garment opening
|
|
1530
|
+
# renders as a HOLE rather than as the inside of the sleeve -- indistinguishable at a glance
|
|
1531
|
+
# from a garment that is simply too short, and the two want opposite fixes.
|
|
1532
|
+
errors.extend(check_open_boundary_sides(component_id, component))
|
|
1533
|
+
# The decision left open in docs/UPGRADE_PLAN.md since v1.2 -- "hair cards vs
|
|
1534
|
+
# tube-along-curve per lock" -- closed here by what this pipeline can actually emit.
|
|
1535
|
+
if str(component.get("role") or "").lower() == "hair":
|
|
1536
|
+
reason = REJECTED_HAIR_PRIMITIVES.get(str(primitive))
|
|
1537
|
+
if reason:
|
|
1538
|
+
errors.append(
|
|
1539
|
+
f"component {component_id!r} has role 'hair' and may not use primitive "
|
|
1540
|
+
f"{primitive!r}: {reason}"
|
|
1541
|
+
)
|
|
1542
|
+
validate_subdivision_budget(
|
|
1543
|
+
component_id,
|
|
1544
|
+
primitive,
|
|
1545
|
+
component.get("topologyClass"),
|
|
1546
|
+
component.get("geometryDescriptor"),
|
|
1547
|
+
component.get("attachment"),
|
|
1548
|
+
errors,
|
|
1549
|
+
)
|
|
1550
|
+
material_layers = component.get("materialLayers")
|
|
1551
|
+
if material_layers is not None:
|
|
1552
|
+
validate_string_array(material_layers, f"component {component_id!r} materialLayers", errors)
|
|
1553
|
+
if isinstance(material_layers, list):
|
|
1554
|
+
for material_layer in material_layers:
|
|
1555
|
+
if material_layer not in material_ids:
|
|
1556
|
+
errors.append(
|
|
1557
|
+
f"component {component_id!r} materialLayers references unknown material {material_layer!r}"
|
|
1558
|
+
)
|
|
1559
|
+
validate_dimensions(component_id, component.get("dimensions"), errors)
|
|
1560
|
+
transform = component.get("transform", {})
|
|
1561
|
+
if transform is not None and not isinstance(transform, dict):
|
|
1562
|
+
errors.append(f"component {component_id!r} transform must be an object")
|
|
1563
|
+
elif isinstance(transform, dict):
|
|
1564
|
+
for field in ("position", "rotation", "scale"):
|
|
1565
|
+
if field in transform and not as_number_list(transform[field], 3):
|
|
1566
|
+
errors.append(f"component {component_id!r} transform.{field} must be [number, number, number]")
|
|
1567
|
+
validate_action_profile(component_id, component.get("actionProfile"), errors, warnings)
|
|
1568
|
+
validate_attachment(
|
|
1569
|
+
component_id,
|
|
1570
|
+
parent if isinstance(parent, str) else None,
|
|
1571
|
+
component.get("attachment"),
|
|
1572
|
+
component_requires_attachment(component),
|
|
1573
|
+
errors,
|
|
1574
|
+
warnings,
|
|
1575
|
+
)
|
|
1576
|
+
for field in ("deformations", "joints", "seams", "localFeatures"):
|
|
1577
|
+
value = component.get(field)
|
|
1578
|
+
if value is not None and not isinstance(value, list):
|
|
1579
|
+
errors.append(f"component {component_id!r} {field} must be an array")
|
|
1580
|
+
paint = component.get("vertexPaint")
|
|
1581
|
+
if paint is not None:
|
|
1582
|
+
try:
|
|
1583
|
+
normalize_vertex_paint(paint, f"component {component_id!r} vertexPaint")
|
|
1584
|
+
except VertexPaintError as error:
|
|
1585
|
+
errors.append(str(error))
|
|
1586
|
+
# Both write the geometry's `color` attribute, and the second one to run wins. A spec
|
|
1587
|
+
# declaring both is asking for two different colours on the same vertex and would get
|
|
1588
|
+
# whichever the emission order happens to apply last -- an ordering dependency no gate
|
|
1589
|
+
# can see, so it is refused at spec time instead.
|
|
1590
|
+
if component.get("rootTipGradient") is not None:
|
|
1591
|
+
errors.append(
|
|
1592
|
+
f"component {component_id!r} declares both vertexPaint and rootTipGradient; "
|
|
1593
|
+
"both write the vertex colour attribute, so only one may be used"
|
|
1594
|
+
)
|
|
1595
|
+
surface = component.get("surfaceDetail")
|
|
1596
|
+
if surface is not None:
|
|
1597
|
+
if not isinstance(surface, dict):
|
|
1598
|
+
errors.append(f"component {component_id!r} surfaceDetail must be an object")
|
|
1599
|
+
else:
|
|
1600
|
+
for field in ("macroRoughness", "microRoughness", "bumpAmplitude"):
|
|
1601
|
+
if field in surface and not is_number(surface[field]):
|
|
1602
|
+
errors.append(f"component {component_id!r} surfaceDetail.{field} must be numeric")
|
|
1603
|
+
evidence_refs = component.get("evidenceRefs")
|
|
1604
|
+
if evidence_refs is not None:
|
|
1605
|
+
validate_string_array(evidence_refs, f"component {component_id!r} evidenceRefs", errors)
|
|
1606
|
+
if isinstance(evidence_refs, list):
|
|
1607
|
+
for evidence_ref in evidence_refs:
|
|
1608
|
+
if evidence_ids and evidence_ref not in evidence_ids:
|
|
1609
|
+
errors.append(f"component {component_id!r} references missing evidence {evidence_ref!r}")
|
|
1610
|
+
for component_id, parent in parent_refs:
|
|
1611
|
+
if parent not in ids:
|
|
1612
|
+
errors.append(f"component {component_id!r} references missing parent {parent!r}")
|
|
1613
|
+
# Resolved after the loop, like parents: a component may legitimately stand proud of one that
|
|
1614
|
+
# appears later in the tree, and a forward reference is not a defect.
|
|
1615
|
+
for component_id, against in proud_refs:
|
|
1616
|
+
if against not in ids:
|
|
1617
|
+
errors.append(
|
|
1618
|
+
f"component {component_id!r} standProud references missing component {against!r}"
|
|
1619
|
+
)
|
|
1620
|
+
if not ids:
|
|
1621
|
+
errors.append("at least one component is required")
|
|
1622
|
+
if len(ids) == 1:
|
|
1623
|
+
warnings.append("only one component found; this is likely still blockout quality")
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
def validate_quality_targets(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
1627
|
+
targets = spec.get("qualityTargets")
|
|
1628
|
+
if targets is None:
|
|
1629
|
+
warnings.append("missing qualityTargets; self-correction loop has no explicit fidelity bar")
|
|
1630
|
+
return
|
|
1631
|
+
if not isinstance(targets, dict):
|
|
1632
|
+
errors.append("qualityTargets must be an object")
|
|
1633
|
+
return
|
|
1634
|
+
target_fidelity = targets.get("targetFidelity")
|
|
1635
|
+
if target_fidelity is not None:
|
|
1636
|
+
validate_unit_interval(target_fidelity, "qualityTargets.targetFidelity", errors)
|
|
1637
|
+
for field in ("mustMatch", "niceToHave", "reviewViewpoints"):
|
|
1638
|
+
validate_string_array(targets.get(field), f"qualityTargets.{field}", errors)
|
|
1639
|
+
|
|
1640
|
+
|
|
1641
|
+
def validate_quality_contract(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
1642
|
+
contract = spec.get("qualityContract")
|
|
1643
|
+
if contract is None:
|
|
1644
|
+
warnings.append("quality: missing qualityContract; no explicit definition of done prevents shallow specs")
|
|
1645
|
+
return
|
|
1646
|
+
if not isinstance(contract, dict):
|
|
1647
|
+
errors.append("qualityContract must be an object")
|
|
1648
|
+
return
|
|
1649
|
+
quality_bar = contract.get("qualityBar")
|
|
1650
|
+
if quality_bar is not None and not isinstance(quality_bar, str):
|
|
1651
|
+
errors.append("qualityContract.qualityBar must be a string")
|
|
1652
|
+
if quality_bar in {None, "", "unassessed"}:
|
|
1653
|
+
warnings.append("quality: qualityContract.qualityBar is unassessed")
|
|
1654
|
+
validate_string_array(contract.get("definitionOfDone"), "qualityContract.definitionOfDone", errors)
|
|
1655
|
+
if isinstance(contract.get("definitionOfDone"), list) and not contract["definitionOfDone"]:
|
|
1656
|
+
warnings.append("quality: qualityContract.definitionOfDone is empty")
|
|
1657
|
+
minimums = contract.get("minimumSpecDepth")
|
|
1658
|
+
if not isinstance(minimums, dict):
|
|
1659
|
+
errors.append("qualityContract.minimumSpecDepth must be an object")
|
|
1660
|
+
else:
|
|
1661
|
+
for field in (
|
|
1662
|
+
"macroComponents",
|
|
1663
|
+
"mesoComponents",
|
|
1664
|
+
"microFeatureGroups",
|
|
1665
|
+
"materialLayers",
|
|
1666
|
+
"repetitionSystems",
|
|
1667
|
+
"reviewViewpoints",
|
|
1668
|
+
):
|
|
1669
|
+
if field in minimums:
|
|
1670
|
+
validate_nonnegative_int(minimums[field], f"qualityContract.minimumSpecDepth.{field}", errors)
|
|
1671
|
+
feature_groups = contract.get("featureGroups")
|
|
1672
|
+
if not isinstance(feature_groups, list):
|
|
1673
|
+
errors.append("qualityContract.featureGroups must be an array")
|
|
1674
|
+
else:
|
|
1675
|
+
if len(feature_groups) < 3:
|
|
1676
|
+
warnings.append("quality: qualityContract.featureGroups has fewer than 3 groups; spec may miss important visual layers")
|
|
1677
|
+
for index, group in enumerate(feature_groups):
|
|
1678
|
+
if not isinstance(group, dict):
|
|
1679
|
+
errors.append(f"qualityContract.featureGroups[{index}] must be an object")
|
|
1680
|
+
continue
|
|
1681
|
+
for field in ("id", "name"):
|
|
1682
|
+
value = group.get(field)
|
|
1683
|
+
if not isinstance(value, str) or not value.strip():
|
|
1684
|
+
errors.append(f"qualityContract.featureGroups[{index}].{field} is required")
|
|
1685
|
+
if "required" in group and not isinstance(group["required"], bool):
|
|
1686
|
+
errors.append(f"qualityContract.featureGroups[{index}].required must be boolean")
|
|
1687
|
+
validate_string_array(group.get("qualityCriteria"), f"qualityContract.featureGroups[{index}].qualityCriteria", errors)
|
|
1688
|
+
validate_string_array(group.get("evidenceRefs"), f"qualityContract.featureGroups[{index}].evidenceRefs", errors)
|
|
1689
|
+
validate_string_array(group.get("failureModes"), f"qualityContract.featureGroups[{index}].failureModes", errors)
|
|
1690
|
+
if group.get("required") is True and not group.get("qualityCriteria"):
|
|
1691
|
+
warnings.append(f"quality: required feature group {group.get('id', index)!r} has no qualityCriteria")
|
|
1692
|
+
for field in ("visualDeltaChecks", "antiShallowSpecRules", "mustNotDo"):
|
|
1693
|
+
validate_string_array(contract.get(field), f"qualityContract.{field}", errors)
|
|
1694
|
+
if isinstance(contract.get(field), list) and not contract[field]:
|
|
1695
|
+
warnings.append(f"quality: qualityContract.{field} is empty")
|
|
1696
|
+
|
|
1697
|
+
|
|
1698
|
+
def validate_quality_depth(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
1699
|
+
contract = spec.get("qualityContract")
|
|
1700
|
+
if not isinstance(contract, dict) or not isinstance(contract.get("minimumSpecDepth"), dict):
|
|
1701
|
+
return
|
|
1702
|
+
minimums = contract["minimumSpecDepth"]
|
|
1703
|
+
components = [item for item in spec.get("componentTree", []) if isinstance(item, dict)]
|
|
1704
|
+
level_counts = {
|
|
1705
|
+
"macroComponents": sum(1 for item in components if item.get("level") == "macro"),
|
|
1706
|
+
"mesoComponents": sum(1 for item in components if item.get("level") == "meso"),
|
|
1707
|
+
"microFeatureGroups": sum(
|
|
1708
|
+
len(item.get("localFeatures", []))
|
|
1709
|
+
for item in components
|
|
1710
|
+
if isinstance(item.get("localFeatures", []), list)
|
|
1711
|
+
),
|
|
1712
|
+
"materialLayers": len([item for item in spec.get("materials", []) if isinstance(item, dict)]),
|
|
1713
|
+
"repetitionSystems": len([item for item in spec.get("repetitionSystems", []) if isinstance(item, dict)]),
|
|
1714
|
+
"reviewViewpoints": len(spec.get("qualityTargets", {}).get("reviewViewpoints", []))
|
|
1715
|
+
if isinstance(spec.get("qualityTargets"), dict)
|
|
1716
|
+
and isinstance(spec.get("qualityTargets", {}).get("reviewViewpoints"), list)
|
|
1717
|
+
else 0,
|
|
1718
|
+
}
|
|
1719
|
+
for field, actual in level_counts.items():
|
|
1720
|
+
required = minimums.get(field)
|
|
1721
|
+
if isinstance(required, int) and actual < required:
|
|
1722
|
+
warnings.append(f"quality: {field} below qualityContract minimum ({actual} < {required})")
|
|
1723
|
+
|
|
1724
|
+
|
|
1725
|
+
def validate_action_readiness(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
1726
|
+
readiness = spec.get("actionReadiness")
|
|
1727
|
+
if readiness is None:
|
|
1728
|
+
warnings.append("missing actionReadiness; generated model may not be ready for animation/transformation/destruction")
|
|
1729
|
+
return
|
|
1730
|
+
if not isinstance(readiness, dict):
|
|
1731
|
+
errors.append("actionReadiness must be an object")
|
|
1732
|
+
return
|
|
1733
|
+
for field in ("contract", "defaultRigType", "rootMotionNode"):
|
|
1734
|
+
value = readiness.get(field)
|
|
1735
|
+
if value is not None and not isinstance(value, str):
|
|
1736
|
+
errors.append(f"actionReadiness.{field} must be a string")
|
|
1737
|
+
for field in ("requiredComponentFields", "transformChannels", "authoringRules"):
|
|
1738
|
+
validate_string_array(readiness.get(field), f"actionReadiness.{field}", errors)
|
|
1739
|
+
policy = readiness.get("destructionPolicy")
|
|
1740
|
+
if policy is not None and not isinstance(policy, dict):
|
|
1741
|
+
errors.append("actionReadiness.destructionPolicy must be an object")
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
def validate_self_correct_loop(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
1745
|
+
loop = spec.get("selfCorrectLoop")
|
|
1746
|
+
if loop is None:
|
|
1747
|
+
warnings.append("missing selfCorrectLoop; construction may not review/refine after each pass")
|
|
1748
|
+
return
|
|
1749
|
+
if not isinstance(loop, dict):
|
|
1750
|
+
errors.append("selfCorrectLoop must be an object")
|
|
1751
|
+
return
|
|
1752
|
+
enabled = loop.get("enabled")
|
|
1753
|
+
if enabled is not None and not isinstance(enabled, bool):
|
|
1754
|
+
errors.append("selfCorrectLoop.enabled must be boolean")
|
|
1755
|
+
for field in ("reviewAfterPasses", "allowedActions", "specRefineTriggers", "codeRefineTriggers", "stopCriteria"):
|
|
1756
|
+
validate_string_array(loop.get(field), f"selfCorrectLoop.{field}", errors)
|
|
1757
|
+
actions = loop.get("allowedActions", [])
|
|
1758
|
+
if isinstance(actions, list):
|
|
1759
|
+
for action in actions:
|
|
1760
|
+
if action not in VALID_REVIEW_ACTIONS:
|
|
1761
|
+
errors.append(f"selfCorrectLoop.allowedActions contains invalid action {action!r}")
|
|
1762
|
+
visual_acceptance = loop.get("visualAcceptance")
|
|
1763
|
+
if visual_acceptance is None:
|
|
1764
|
+
warnings.append("quality: selfCorrectLoop.visualAcceptance is missing; AI vision cannot enforce visual fidelity")
|
|
1765
|
+
elif not isinstance(visual_acceptance, dict):
|
|
1766
|
+
errors.append("selfCorrectLoop.visualAcceptance must be an object")
|
|
1767
|
+
else:
|
|
1768
|
+
reviewer = visual_acceptance.get("reviewer")
|
|
1769
|
+
if reviewer is not None and not isinstance(reviewer, str):
|
|
1770
|
+
errors.append("selfCorrectLoop.visualAcceptance.reviewer must be a string")
|
|
1771
|
+
threshold = visual_acceptance.get("threshold")
|
|
1772
|
+
if threshold is None:
|
|
1773
|
+
warnings.append("quality: selfCorrectLoop.visualAcceptance.threshold is missing")
|
|
1774
|
+
else:
|
|
1775
|
+
validate_unit_interval(threshold, "selfCorrectLoop.visualAcceptance.threshold", errors)
|
|
1776
|
+
for field in (
|
|
1777
|
+
"comparisonArtifactRequired",
|
|
1778
|
+
"layerScoresRequired",
|
|
1779
|
+
"codePixelDiffIsAcceptanceAuthority",
|
|
1780
|
+
):
|
|
1781
|
+
value = visual_acceptance.get(field)
|
|
1782
|
+
if value is not None and not isinstance(value, bool):
|
|
1783
|
+
errors.append(f"selfCorrectLoop.visualAcceptance.{field} must be boolean")
|
|
1784
|
+
scoring_rule = visual_acceptance.get("scoringRule")
|
|
1785
|
+
if scoring_rule is not None and not isinstance(scoring_rule, str):
|
|
1786
|
+
errors.append("selfCorrectLoop.visualAcceptance.scoringRule must be a string")
|
|
1787
|
+
validate_string_array(
|
|
1788
|
+
visual_acceptance.get("requiredLayerScores"),
|
|
1789
|
+
"selfCorrectLoop.visualAcceptance.requiredLayerScores",
|
|
1790
|
+
errors,
|
|
1791
|
+
)
|
|
1792
|
+
feature_policy = visual_acceptance.get("featureReviewPolicy")
|
|
1793
|
+
if feature_policy is None:
|
|
1794
|
+
warnings.append("quality: visualAcceptance.featureReviewPolicy is missing")
|
|
1795
|
+
elif not isinstance(feature_policy, dict):
|
|
1796
|
+
errors.append("selfCorrectLoop.visualAcceptance.featureReviewPolicy must be an object")
|
|
1797
|
+
else:
|
|
1798
|
+
for field in (
|
|
1799
|
+
"enabled",
|
|
1800
|
+
"adaptiveEscalation",
|
|
1801
|
+
"singleImagePairOnly",
|
|
1802
|
+
):
|
|
1803
|
+
value = feature_policy.get(field)
|
|
1804
|
+
if value is not None and not isinstance(value, bool):
|
|
1805
|
+
errors.append(
|
|
1806
|
+
f"selfCorrectLoop.visualAcceptance.featureReviewPolicy.{field} must be boolean"
|
|
1807
|
+
)
|
|
1808
|
+
for field in ("maxCriticalFeaturesPerPass", "maxImportantFeaturesPerPass"):
|
|
1809
|
+
value = feature_policy.get(field)
|
|
1810
|
+
if value is not None:
|
|
1811
|
+
validate_nonnegative_int(
|
|
1812
|
+
value,
|
|
1813
|
+
f"selfCorrectLoop.visualAcceptance.featureReviewPolicy.{field}",
|
|
1814
|
+
errors,
|
|
1815
|
+
)
|
|
1816
|
+
for field in ("criticalDefaultThreshold", "importantAverageThreshold"):
|
|
1817
|
+
value = feature_policy.get(field)
|
|
1818
|
+
if value is not None:
|
|
1819
|
+
validate_unit_interval(
|
|
1820
|
+
value,
|
|
1821
|
+
f"selfCorrectLoop.visualAcceptance.featureReviewPolicy.{field}",
|
|
1822
|
+
errors,
|
|
1823
|
+
)
|
|
1824
|
+
for field in ("reviewUnit", "selectionRule"):
|
|
1825
|
+
value = feature_policy.get(field)
|
|
1826
|
+
if value is not None and not isinstance(value, str):
|
|
1827
|
+
errors.append(
|
|
1828
|
+
f"selfCorrectLoop.visualAcceptance.featureReviewPolicy.{field} must be a string"
|
|
1829
|
+
)
|
|
1830
|
+
policy = loop.get("screenshotPolicy")
|
|
1831
|
+
if policy is None:
|
|
1832
|
+
warnings.append("selfCorrectLoop.screenshotPolicy is missing; visual review may drift without screenshots")
|
|
1833
|
+
elif not isinstance(policy, dict):
|
|
1834
|
+
errors.append("selfCorrectLoop.screenshotPolicy must be an object")
|
|
1835
|
+
else:
|
|
1836
|
+
validate_string_array(policy.get("requiredForPasses"), "selfCorrectLoop.screenshotPolicy.requiredForPasses", errors)
|
|
1837
|
+
for field in (
|
|
1838
|
+
"preferredCapture",
|
|
1839
|
+
"fallbackCapture",
|
|
1840
|
+
"minimumEvidence",
|
|
1841
|
+
"reviewPairRule",
|
|
1842
|
+
"acceptanceAuthority",
|
|
1843
|
+
):
|
|
1844
|
+
value = policy.get(field)
|
|
1845
|
+
if value is not None and not isinstance(value, str):
|
|
1846
|
+
errors.append(f"selfCorrectLoop.screenshotPolicy.{field} must be a string")
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
def validate_visual_evidence_item(item: Any, label: str, errors: list[str]) -> None:
|
|
1850
|
+
if not isinstance(item, dict):
|
|
1851
|
+
errors.append(f"{label} must be an object")
|
|
1852
|
+
return
|
|
1853
|
+
for field in (
|
|
1854
|
+
"passId",
|
|
1855
|
+
"referenceScreenshot",
|
|
1856
|
+
"renderScreenshot",
|
|
1857
|
+
"comparisonImage",
|
|
1858
|
+
"cameraView",
|
|
1859
|
+
"notes",
|
|
1860
|
+
"aiVisionNotes",
|
|
1861
|
+
):
|
|
1862
|
+
value = item.get(field)
|
|
1863
|
+
if value is not None and not isinstance(value, str):
|
|
1864
|
+
errors.append(f"{label}.{field} must be a string")
|
|
1865
|
+
fidelity = item.get("estimatedFidelity")
|
|
1866
|
+
if fidelity is not None:
|
|
1867
|
+
validate_unit_interval(fidelity, f"{label}.estimatedFidelity", errors)
|
|
1868
|
+
score = item.get("aiVisionScore")
|
|
1869
|
+
if score is not None:
|
|
1870
|
+
validate_unit_interval(score, f"{label}.aiVisionScore", errors)
|
|
1871
|
+
threshold = item.get("visualAcceptanceThreshold")
|
|
1872
|
+
if threshold is not None:
|
|
1873
|
+
validate_unit_interval(threshold, f"{label}.visualAcceptanceThreshold", errors)
|
|
1874
|
+
layer_scores = item.get("layerScores")
|
|
1875
|
+
if layer_scores is not None:
|
|
1876
|
+
if not isinstance(layer_scores, dict):
|
|
1877
|
+
errors.append(f"{label}.layerScores must be an object")
|
|
1878
|
+
else:
|
|
1879
|
+
for key, value in layer_scores.items():
|
|
1880
|
+
if not isinstance(key, str):
|
|
1881
|
+
errors.append(f"{label}.layerScores keys must be strings")
|
|
1882
|
+
if not is_number(value) or value < 0 or value > 1:
|
|
1883
|
+
errors.append(f"{label}.layerScores.{key} must be a number from 0 to 1")
|
|
1884
|
+
|
|
1885
|
+
|
|
1886
|
+
def validate_feature_review_targets(
|
|
1887
|
+
spec: dict[str, Any],
|
|
1888
|
+
errors: list[str],
|
|
1889
|
+
warnings: list[str],
|
|
1890
|
+
) -> None:
|
|
1891
|
+
targets = spec.get("featureReviewTargets")
|
|
1892
|
+
policy = feature_review_policy(spec)
|
|
1893
|
+
if targets is None:
|
|
1894
|
+
if policy.get("enabled") is True:
|
|
1895
|
+
errors.append("featureReviewTargets must be an array when feature review is enabled")
|
|
1896
|
+
else:
|
|
1897
|
+
warnings.append("quality: featureReviewTargets is missing; feature-level visual gating is disabled")
|
|
1898
|
+
return
|
|
1899
|
+
if not isinstance(targets, list):
|
|
1900
|
+
errors.append("featureReviewTargets must be an array")
|
|
1901
|
+
return
|
|
1902
|
+
if not targets:
|
|
1903
|
+
warnings.append("quality: featureReviewTargets is empty; component-level visual gaps can hide in the overall score")
|
|
1904
|
+
return
|
|
1905
|
+
ids: set[str] = set()
|
|
1906
|
+
critical_by_pass: dict[str, int] = {}
|
|
1907
|
+
important_by_pass: dict[str, int] = {}
|
|
1908
|
+
for index, target in enumerate(targets):
|
|
1909
|
+
label = f"featureReviewTargets[{index}]"
|
|
1910
|
+
if not isinstance(target, dict):
|
|
1911
|
+
errors.append(f"{label} must be an object")
|
|
1912
|
+
continue
|
|
1913
|
+
target_id = target.get("id")
|
|
1914
|
+
if not isinstance(target_id, str) or not target_id.strip():
|
|
1915
|
+
errors.append(f"{label}.id is required")
|
|
1916
|
+
elif target_id in ids:
|
|
1917
|
+
errors.append(f"duplicate feature review target id {target_id!r}")
|
|
1918
|
+
else:
|
|
1919
|
+
ids.add(target_id)
|
|
1920
|
+
if not isinstance(target.get("name"), str) or not target["name"].strip():
|
|
1921
|
+
errors.append(f"{label}.name is required")
|
|
1922
|
+
tier = target.get("tier")
|
|
1923
|
+
if tier not in {"critical", "important", "detail"}:
|
|
1924
|
+
errors.append(f"{label}.tier must be critical, important, or detail")
|
|
1925
|
+
validate_string_array(target.get("passIds"), f"{label}.passIds", errors)
|
|
1926
|
+
validate_string_array(target.get("componentRefs"), f"{label}.componentRefs", errors)
|
|
1927
|
+
validate_string_array(target.get("evidenceRefs"), f"{label}.evidenceRefs", errors)
|
|
1928
|
+
minimum = target.get("minimumScore")
|
|
1929
|
+
if minimum is not None:
|
|
1930
|
+
validate_unit_interval(minimum, f"{label}.minimumScore", errors)
|
|
1931
|
+
for field in ("mustPass",):
|
|
1932
|
+
value = target.get(field)
|
|
1933
|
+
if value is not None and not isinstance(value, bool):
|
|
1934
|
+
errors.append(f"{label}.{field} must be boolean")
|
|
1935
|
+
if tier == "critical" or target.get("mustPass") is True:
|
|
1936
|
+
pass_ids = target.get("passIds", [])
|
|
1937
|
+
if isinstance(pass_ids, list):
|
|
1938
|
+
for pass_id in pass_ids:
|
|
1939
|
+
if isinstance(pass_id, str):
|
|
1940
|
+
critical_by_pass[pass_id] = critical_by_pass.get(pass_id, 0) + 1
|
|
1941
|
+
elif tier == "important":
|
|
1942
|
+
pass_ids = target.get("passIds", [])
|
|
1943
|
+
if isinstance(pass_ids, list):
|
|
1944
|
+
for pass_id in pass_ids:
|
|
1945
|
+
if isinstance(pass_id, str):
|
|
1946
|
+
important_by_pass[pass_id] = important_by_pass.get(pass_id, 0) + 1
|
|
1947
|
+
maximum = policy.get("maxCriticalFeaturesPerPass", 5)
|
|
1948
|
+
if is_number(maximum):
|
|
1949
|
+
for pass_id, count in critical_by_pass.items():
|
|
1950
|
+
if count > int(maximum):
|
|
1951
|
+
errors.append(
|
|
1952
|
+
f"pass {pass_id!r} has {count} critical feature targets; "
|
|
1953
|
+
f"maximum is {int(maximum)}"
|
|
1954
|
+
)
|
|
1955
|
+
important_maximum = policy.get("maxImportantFeaturesPerPass", 3)
|
|
1956
|
+
if is_number(important_maximum):
|
|
1957
|
+
for pass_id, count in important_by_pass.items():
|
|
1958
|
+
if count > int(important_maximum):
|
|
1959
|
+
errors.append(
|
|
1960
|
+
f"pass {pass_id!r} has {count} important feature targets; "
|
|
1961
|
+
f"maximum is {int(important_maximum)}"
|
|
1962
|
+
)
|
|
1963
|
+
assessment = spec.get("preSpecAssessment")
|
|
1964
|
+
complexity = (
|
|
1965
|
+
assessment.get("complexity", {}).get("tier")
|
|
1966
|
+
if isinstance(assessment, dict) and isinstance(assessment.get("complexity"), dict)
|
|
1967
|
+
else None
|
|
1968
|
+
)
|
|
1969
|
+
starter_ids = {
|
|
1970
|
+
"overall-silhouette",
|
|
1971
|
+
"primary-structure",
|
|
1972
|
+
"reference-material-system",
|
|
1973
|
+
}
|
|
1974
|
+
if complexity in {"moderate", "complex", "ultra-complex"} and ids.issubset(starter_ids):
|
|
1975
|
+
warnings.append(
|
|
1976
|
+
"quality: replace generic starter featureReviewTargets with object-specific "
|
|
1977
|
+
"identity-defining semantic systems before strict validation"
|
|
1978
|
+
)
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
def validate_feature_reviews(
|
|
1982
|
+
entry: dict[str, Any],
|
|
1983
|
+
label: str,
|
|
1984
|
+
errors: list[str],
|
|
1985
|
+
) -> None:
|
|
1986
|
+
reviews = entry.get("featureReviews")
|
|
1987
|
+
if reviews is None:
|
|
1988
|
+
return
|
|
1989
|
+
if not isinstance(reviews, list):
|
|
1990
|
+
errors.append(f"{label}.featureReviews must be an array")
|
|
1991
|
+
return
|
|
1992
|
+
ids: set[str] = set()
|
|
1993
|
+
for index, review in enumerate(reviews):
|
|
1994
|
+
item_label = f"{label}.featureReviews[{index}]"
|
|
1995
|
+
if not isinstance(review, dict):
|
|
1996
|
+
errors.append(f"{item_label} must be an object")
|
|
1997
|
+
continue
|
|
1998
|
+
feature_id = review.get("id")
|
|
1999
|
+
if not isinstance(feature_id, str) or not feature_id.strip():
|
|
2000
|
+
errors.append(f"{item_label}.id is required")
|
|
2001
|
+
elif feature_id in ids:
|
|
2002
|
+
errors.append(f"{label}.featureReviews has duplicate id {feature_id!r}")
|
|
2003
|
+
else:
|
|
2004
|
+
ids.add(feature_id)
|
|
2005
|
+
score = review.get("score")
|
|
2006
|
+
if score is not None:
|
|
2007
|
+
validate_unit_interval(score, f"{item_label}.score", errors)
|
|
2008
|
+
for field in ("notes",):
|
|
2009
|
+
value = review.get(field)
|
|
2010
|
+
if value is not None and not isinstance(value, str):
|
|
2011
|
+
errors.append(f"{item_label}.{field} must be a string")
|
|
2012
|
+
visible = review.get("visible")
|
|
2013
|
+
if visible is not None and not isinstance(visible, bool):
|
|
2014
|
+
errors.append(f"{item_label}.visible must be boolean")
|
|
2015
|
+
|
|
2016
|
+
|
|
2017
|
+
def validate_review_history(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
2018
|
+
history = spec.get("reviewHistory", [])
|
|
2019
|
+
if history is None:
|
|
2020
|
+
return
|
|
2021
|
+
if not isinstance(history, list):
|
|
2022
|
+
errors.append("reviewHistory must be an array")
|
|
2023
|
+
return
|
|
2024
|
+
for index, entry in enumerate(history):
|
|
2025
|
+
if not isinstance(entry, dict):
|
|
2026
|
+
errors.append(f"reviewHistory[{index}] must be an object")
|
|
2027
|
+
continue
|
|
2028
|
+
action = entry.get("action")
|
|
2029
|
+
if action is not None and action not in VALID_REVIEW_ACTIONS:
|
|
2030
|
+
errors.append(f"reviewHistory[{index}].action is invalid")
|
|
2031
|
+
fidelity = entry.get("estimatedFidelity")
|
|
2032
|
+
if fidelity is not None:
|
|
2033
|
+
validate_unit_interval(fidelity, f"reviewHistory[{index}].estimatedFidelity", errors)
|
|
2034
|
+
for field in ("matched", "mismatches", "specFixes", "codeFixes", "evidence"):
|
|
2035
|
+
validate_string_array(entry.get(field), f"reviewHistory[{index}].{field}", errors)
|
|
2036
|
+
visual = entry.get("visualEvidence")
|
|
2037
|
+
if visual is not None:
|
|
2038
|
+
validate_visual_evidence_item(visual, f"reviewHistory[{index}].visualEvidence", errors)
|
|
2039
|
+
validate_feature_reviews(entry, f"reviewHistory[{index}]", errors)
|
|
2040
|
+
pass_id = entry.get("passId")
|
|
2041
|
+
if (
|
|
2042
|
+
pass_id in VISUAL_PASS_IDS
|
|
2043
|
+
and action == "continue"
|
|
2044
|
+
and not (isinstance(visual, dict) and visual.get("renderScreenshot"))
|
|
2045
|
+
):
|
|
2046
|
+
warnings.append(
|
|
2047
|
+
f"reviewHistory[{index}] continues visual pass {pass_id!r} without a render screenshot"
|
|
2048
|
+
)
|
|
2049
|
+
if pass_id in VISUAL_PASS_IDS and action == "continue":
|
|
2050
|
+
if not isinstance(visual, dict) or not visual.get("comparisonImage"):
|
|
2051
|
+
warnings.append(
|
|
2052
|
+
f"quality: reviewHistory[{index}] continues visual pass {pass_id!r} without an AI vision comparison image"
|
|
2053
|
+
)
|
|
2054
|
+
score = entry.get("aiVisionScore")
|
|
2055
|
+
threshold = entry.get("visualAcceptanceThreshold", 0.7)
|
|
2056
|
+
if not is_number(score):
|
|
2057
|
+
warnings.append(
|
|
2058
|
+
f"quality: reviewHistory[{index}] continues visual pass {pass_id!r} without aiVisionScore"
|
|
2059
|
+
)
|
|
2060
|
+
elif is_number(threshold) and float(score) < float(threshold):
|
|
2061
|
+
warnings.append(
|
|
2062
|
+
f"quality: reviewHistory[{index}] aiVisionScore {score} is below threshold {threshold}"
|
|
2063
|
+
)
|
|
2064
|
+
loop = spec.get("selfCorrectLoop")
|
|
2065
|
+
acceptance = loop.get("visualAcceptance", {}) if isinstance(loop, dict) else {}
|
|
2066
|
+
if isinstance(acceptance, dict) and acceptance.get("layerScoresRequired") is True:
|
|
2067
|
+
layer_scores = entry.get("layerScores")
|
|
2068
|
+
if not isinstance(layer_scores, dict) or not layer_scores:
|
|
2069
|
+
warnings.append(
|
|
2070
|
+
f"quality: reviewHistory[{index}] continues visual pass {pass_id!r} without layerScores"
|
|
2071
|
+
)
|
|
2072
|
+
else:
|
|
2073
|
+
required_layers = acceptance.get("requiredLayerScores", [])
|
|
2074
|
+
if isinstance(required_layers, list):
|
|
2075
|
+
missing_layers = [
|
|
2076
|
+
layer
|
|
2077
|
+
for layer in required_layers
|
|
2078
|
+
if isinstance(layer, str) and layer not in layer_scores
|
|
2079
|
+
]
|
|
2080
|
+
if missing_layers:
|
|
2081
|
+
warnings.append(
|
|
2082
|
+
f"quality: reviewHistory[{index}] layerScores missing: "
|
|
2083
|
+
+ ", ".join(missing_layers)
|
|
2084
|
+
)
|
|
2085
|
+
failures = feature_gate_failures(spec, entry, str(pass_id))
|
|
2086
|
+
for failure in failures:
|
|
2087
|
+
warnings.append(
|
|
2088
|
+
f"quality: reviewHistory[{index}] feature gate failed: {failure}"
|
|
2089
|
+
)
|
|
2090
|
+
|
|
2091
|
+
|
|
2092
|
+
def validate_visual_evidence_history(spec: dict[str, Any], errors: list[str]) -> None:
|
|
2093
|
+
visual_history = spec.get("visualEvidence", [])
|
|
2094
|
+
if visual_history is None:
|
|
2095
|
+
return
|
|
2096
|
+
if not isinstance(visual_history, list):
|
|
2097
|
+
errors.append("visualEvidence must be an array")
|
|
2098
|
+
return
|
|
2099
|
+
for index, item in enumerate(visual_history):
|
|
2100
|
+
validate_visual_evidence_item(item, f"visualEvidence[{index}]", errors)
|
|
2101
|
+
|
|
2102
|
+
|
|
2103
|
+
def validate_build_passes(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> list[str]:
|
|
2104
|
+
build_passes = spec.get("buildPasses")
|
|
2105
|
+
if build_passes is None:
|
|
2106
|
+
warnings.append("quality: missing buildPasses; model construction can skip blockout/structural/material gates")
|
|
2107
|
+
return []
|
|
2108
|
+
if not isinstance(build_passes, list):
|
|
2109
|
+
errors.append("buildPasses must be an array")
|
|
2110
|
+
return []
|
|
2111
|
+
ids: list[str] = []
|
|
2112
|
+
for index, item in enumerate(build_passes):
|
|
2113
|
+
if not isinstance(item, dict):
|
|
2114
|
+
errors.append(f"buildPasses[{index}] must be an object")
|
|
2115
|
+
continue
|
|
2116
|
+
pass_id = item.get("id")
|
|
2117
|
+
if not isinstance(pass_id, str) or not pass_id.strip():
|
|
2118
|
+
errors.append(f"buildPasses[{index}].id is required")
|
|
2119
|
+
continue
|
|
2120
|
+
if pass_id in ids:
|
|
2121
|
+
errors.append(f"duplicate buildPasses id {pass_id!r}")
|
|
2122
|
+
ids.append(pass_id)
|
|
2123
|
+
for field in ("goal",):
|
|
2124
|
+
value = item.get(field)
|
|
2125
|
+
if value is not None and not isinstance(value, str):
|
|
2126
|
+
errors.append(f"buildPasses[{index}].{field} must be a string")
|
|
2127
|
+
validate_string_array(item.get("componentRefs"), f"buildPasses[{index}].componentRefs", errors)
|
|
2128
|
+
validate_string_array(item.get("acceptance"), f"buildPasses[{index}].acceptance", errors)
|
|
2129
|
+
if ids:
|
|
2130
|
+
if ids[0] != "blockout":
|
|
2131
|
+
warnings.append("quality: first build pass should be blockout")
|
|
2132
|
+
if "structural-pass" not in ids:
|
|
2133
|
+
warnings.append("quality: missing structural-pass; component hierarchy may be skipped")
|
|
2134
|
+
if not ({"material-pass", "surface-pass"} & set(ids)):
|
|
2135
|
+
warnings.append("quality: missing material/surface pass; model may stay as flat geometry")
|
|
2136
|
+
return ids
|
|
2137
|
+
|
|
2138
|
+
|
|
2139
|
+
def review_completes_pass(
|
|
2140
|
+
spec: dict[str, Any],
|
|
2141
|
+
entry: dict[str, Any],
|
|
2142
|
+
pass_id: str,
|
|
2143
|
+
) -> bool:
|
|
2144
|
+
if entry.get("passId") != pass_id or entry.get("action") != "continue":
|
|
2145
|
+
return False
|
|
2146
|
+
visual = entry.get("visualEvidence")
|
|
2147
|
+
if pass_id in VISUAL_PASS_IDS:
|
|
2148
|
+
if not (
|
|
2149
|
+
isinstance(visual, dict)
|
|
2150
|
+
and visual.get("renderScreenshot")
|
|
2151
|
+
and visual.get("comparisonImage")
|
|
2152
|
+
):
|
|
2153
|
+
return False
|
|
2154
|
+
score = entry.get("aiVisionScore")
|
|
2155
|
+
threshold = entry.get("visualAcceptanceThreshold", 0.7)
|
|
2156
|
+
if not is_number(score) or not is_number(threshold) or float(score) < float(threshold):
|
|
2157
|
+
return False
|
|
2158
|
+
if feature_gate_failures(spec, entry, pass_id):
|
|
2159
|
+
return False
|
|
2160
|
+
return True
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
def completed_passes_from_history(spec: dict[str, Any], pass_ids: list[str]) -> list[str]:
|
|
2164
|
+
history = spec.get("reviewHistory", [])
|
|
2165
|
+
if not isinstance(history, list):
|
|
2166
|
+
return []
|
|
2167
|
+
completed: list[str] = []
|
|
2168
|
+
for pass_id in pass_ids:
|
|
2169
|
+
if any(
|
|
2170
|
+
isinstance(entry, dict) and review_completes_pass(spec, entry, pass_id)
|
|
2171
|
+
for entry in history
|
|
2172
|
+
):
|
|
2173
|
+
completed.append(pass_id)
|
|
2174
|
+
else:
|
|
2175
|
+
break
|
|
2176
|
+
return completed
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
def validate_sculpt_pipeline(
|
|
2180
|
+
spec: dict[str, Any],
|
|
2181
|
+
build_pass_ids: list[str],
|
|
2182
|
+
errors: list[str],
|
|
2183
|
+
warnings: list[str],
|
|
2184
|
+
) -> None:
|
|
2185
|
+
pipeline = spec.get("sculptPipeline")
|
|
2186
|
+
if pipeline is None:
|
|
2187
|
+
warnings.append("quality: missing sculptPipeline; pass order is not locked and generation can skip build passes")
|
|
2188
|
+
return
|
|
2189
|
+
if not isinstance(pipeline, dict):
|
|
2190
|
+
errors.append("sculptPipeline must be an object")
|
|
2191
|
+
return
|
|
2192
|
+
pass_order = pipeline.get("passOrder")
|
|
2193
|
+
if pass_order is None:
|
|
2194
|
+
warnings.append("quality: sculptPipeline.passOrder is missing")
|
|
2195
|
+
pass_order_ids = build_pass_ids
|
|
2196
|
+
else:
|
|
2197
|
+
validate_string_array(pass_order, "sculptPipeline.passOrder", errors)
|
|
2198
|
+
pass_order_ids = [str(value) for value in pass_order] if isinstance(pass_order, list) else build_pass_ids
|
|
2199
|
+
if build_pass_ids and pass_order_ids and pass_order_ids != build_pass_ids:
|
|
2200
|
+
warnings.append("sculptPipeline.passOrder differs from buildPasses order; sync the pipeline before generation")
|
|
2201
|
+
current = pipeline.get("currentPass")
|
|
2202
|
+
if current is not None and current != "complete" and current not in (pass_order_ids or build_pass_ids):
|
|
2203
|
+
errors.append("sculptPipeline.currentPass must be a known build pass or complete")
|
|
2204
|
+
completed = pipeline.get("completedPasses", [])
|
|
2205
|
+
validate_string_array(completed, "sculptPipeline.completedPasses", errors)
|
|
2206
|
+
if isinstance(completed, list):
|
|
2207
|
+
expected = completed_passes_from_history(spec, pass_order_ids or build_pass_ids)
|
|
2208
|
+
if list(completed) != expected:
|
|
2209
|
+
warnings.append("sculptPipeline.completedPasses is out of sync with reviewHistory; run stage3_build/orchestrate_passes.py sync")
|
|
2210
|
+
for pass_id in completed:
|
|
2211
|
+
if pass_id not in (pass_order_ids or build_pass_ids):
|
|
2212
|
+
errors.append(f"sculptPipeline.completedPasses contains unknown pass {pass_id!r}")
|
|
2213
|
+
gate_mode = pipeline.get("passGateMode")
|
|
2214
|
+
if gate_mode != "locked-sequential":
|
|
2215
|
+
warnings.append("quality: sculptPipeline.passGateMode should be locked-sequential")
|
|
2216
|
+
validate_string_array(pipeline.get("nextRequiredEvidence"), "sculptPipeline.nextRequiredEvidence", errors)
|
|
2217
|
+
|
|
2218
|
+
|
|
2219
|
+
def has_non_empty_detail(value: Any) -> bool:
|
|
2220
|
+
if isinstance(value, str):
|
|
2221
|
+
return bool(value.strip()) and value.strip().lower() not in {"none", "unassessed", "n/a"}
|
|
2222
|
+
if isinstance(value, list):
|
|
2223
|
+
return any(has_non_empty_detail(item) for item in value)
|
|
2224
|
+
if isinstance(value, dict):
|
|
2225
|
+
return any(has_non_empty_detail(item) for item in value.values())
|
|
2226
|
+
if isinstance(value, (int, float)) and not isinstance(value, bool):
|
|
2227
|
+
return abs(float(value)) > 0
|
|
2228
|
+
return False
|
|
2229
|
+
|
|
2230
|
+
|
|
2231
|
+
def layer_number(value: Any, keys: tuple[str, ...]) -> float:
|
|
2232
|
+
if isinstance(value, (int, float)) and not isinstance(value, bool):
|
|
2233
|
+
return float(value)
|
|
2234
|
+
if isinstance(value, dict):
|
|
2235
|
+
for key in keys:
|
|
2236
|
+
item = value.get(key)
|
|
2237
|
+
if isinstance(item, (int, float)) and not isinstance(item, bool):
|
|
2238
|
+
return float(item)
|
|
2239
|
+
return 0.0
|
|
2240
|
+
|
|
2241
|
+
|
|
2242
|
+
def reference_pbr_usable(material: dict[str, Any], threshold: float) -> tuple[bool, str]:
|
|
2243
|
+
reference = material.get("referencePbr")
|
|
2244
|
+
material_id = str(material.get("id") or "(unnamed)")
|
|
2245
|
+
if not isinstance(reference, dict):
|
|
2246
|
+
return False, f"material {material_id!r} needs usable referencePbr extracted from source pixels"
|
|
2247
|
+
if reference.get("usable") is not True:
|
|
2248
|
+
return False, f"material {material_id!r} referencePbr.usable must be true"
|
|
2249
|
+
confidence = reference.get("confidence", reference.get("estimatedFidelity"))
|
|
2250
|
+
if not is_number(confidence) or float(confidence) < threshold:
|
|
2251
|
+
return False, f"material {material_id!r} referencePbr confidence must be >= {threshold}"
|
|
2252
|
+
maps = reference.get("maps")
|
|
2253
|
+
if not isinstance(maps, dict):
|
|
2254
|
+
return False, f"material {material_id!r} referencePbr needs maps"
|
|
2255
|
+
for channel in ("albedo", "roughness", "height", "normal", "ao"):
|
|
2256
|
+
entry = maps.get(channel)
|
|
2257
|
+
if not isinstance(entry, dict) or not has_non_empty_detail(entry.get("url") or entry.get("path")):
|
|
2258
|
+
return False, f"material {material_id!r} referencePbr missing {channel} map path/url"
|
|
2259
|
+
return True, ""
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
TEXTURE_AUTHORING_FIELDS = (
|
|
2263
|
+
"normal",
|
|
2264
|
+
"bump",
|
|
2265
|
+
"displacement",
|
|
2266
|
+
"surfaceFrequencyBands",
|
|
2267
|
+
"textureProjection",
|
|
2268
|
+
"textureResolution",
|
|
2269
|
+
"referencePbr",
|
|
2270
|
+
)
|
|
2271
|
+
|
|
2272
|
+
|
|
2273
|
+
def is_textureless(material: dict[str, Any]) -> bool:
|
|
2274
|
+
declaration = material.get("textureless")
|
|
2275
|
+
return isinstance(declaration, dict) and declaration.get("declared") is True
|
|
2276
|
+
|
|
2277
|
+
|
|
2278
|
+
def validate_textureless(material_id: str, material: dict[str, Any], errors: list[str]) -> None:
|
|
2279
|
+
"""A material may declare that its subject carries NO texture detail — with evidence.
|
|
2280
|
+
|
|
2281
|
+
WHY THIS EXISTS. The quality-first material bar below requires independent albedo, roughness,
|
|
2282
|
+
height, normal and AO channels at >= 1024, because the subjects it was written for are
|
|
2283
|
+
photographic and their identity lives in surface detail. Some subjects genuinely have none:
|
|
2284
|
+
a flat-shaded designer-toy render carries no grain, no print and no pores, and its identity is
|
|
2285
|
+
entirely silhouette, proportion and the boundaries between flat colour regions.
|
|
2286
|
+
|
|
2287
|
+
Without this declaration the only ways past that bar are to fabricate a texture resolution and
|
|
2288
|
+
frequency bands the renderer will never read, or to mislabel a hero material `qualityTier:
|
|
2289
|
+
"utility"`. Both put numbers in the spec that describe nothing — which is worse than a missing
|
|
2290
|
+
value, because they read as authored evidence.
|
|
2291
|
+
|
|
2292
|
+
So the escape is explicit, evidence-bearing, and closed on both sides: a textureless material
|
|
2293
|
+
must say what measurement supports the claim, and must NOT then carry any texture-authoring
|
|
2294
|
+
field, since a material cannot both have no texture and specify one.
|
|
2295
|
+
"""
|
|
2296
|
+
declaration = material.get("textureless")
|
|
2297
|
+
if declaration is None:
|
|
2298
|
+
return
|
|
2299
|
+
if not isinstance(declaration, dict):
|
|
2300
|
+
errors.append(f"material {material_id!r} textureless must be an object")
|
|
2301
|
+
return
|
|
2302
|
+
if declaration.get("declared") is not True:
|
|
2303
|
+
errors.append(
|
|
2304
|
+
f"material {material_id!r} textureless.declared must be true; remove the block instead "
|
|
2305
|
+
"of declaring it false"
|
|
2306
|
+
)
|
|
2307
|
+
return
|
|
2308
|
+
evidence = declaration.get("evidence")
|
|
2309
|
+
if not isinstance(evidence, list) or not [
|
|
2310
|
+
item for item in evidence if isinstance(item, str) and item.strip()
|
|
2311
|
+
]:
|
|
2312
|
+
errors.append(
|
|
2313
|
+
f"material {material_id!r} textureless.evidence must name at least one measurement or "
|
|
2314
|
+
"reference view supporting the claim that the subject carries no texture detail"
|
|
2315
|
+
)
|
|
2316
|
+
for field in TEXTURE_AUTHORING_FIELDS:
|
|
2317
|
+
if material.get(field) is not None:
|
|
2318
|
+
errors.append(
|
|
2319
|
+
f"material {material_id!r} declares textureless but also carries {field!r}; a "
|
|
2320
|
+
"material cannot both have no texture and specify one"
|
|
2321
|
+
)
|
|
2322
|
+
|
|
2323
|
+
|
|
2324
|
+
def validate_look_dev_targets(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
2325
|
+
targets = spec.get("lookDevTargets")
|
|
2326
|
+
if targets is None:
|
|
2327
|
+
warnings.append("quality: missing lookDevTargets; material/color/lighting passes may stay flat")
|
|
2328
|
+
elif not isinstance(targets, dict):
|
|
2329
|
+
errors.append("lookDevTargets must be an object")
|
|
2330
|
+
materials = [item for item in spec.get("materials", []) if isinstance(item, dict)]
|
|
2331
|
+
if materials:
|
|
2332
|
+
has_palette = any(
|
|
2333
|
+
has_non_empty_detail(item.get("colorVariation"))
|
|
2334
|
+
or has_non_empty_detail(item.get("albedo", {}).get("secondary") if isinstance(item.get("albedo"), dict) else None)
|
|
2335
|
+
for item in materials
|
|
2336
|
+
)
|
|
2337
|
+
has_response = any(
|
|
2338
|
+
layer_number(item.get("roughness"), ("variation", "base")) > 0
|
|
2339
|
+
or layer_number(item.get("normal"), ("strength", "amplitude")) > 0
|
|
2340
|
+
or layer_number(item.get("bump"), ("amplitude", "strength")) > 0
|
|
2341
|
+
or layer_number(item.get("displacement"), ("amplitude", "strength")) > 0
|
|
2342
|
+
for item in materials
|
|
2343
|
+
)
|
|
2344
|
+
has_locality = any(
|
|
2345
|
+
has_non_empty_detail(item.get("localOverrides"))
|
|
2346
|
+
or (
|
|
2347
|
+
isinstance(item.get("wear"), dict)
|
|
2348
|
+
and (
|
|
2349
|
+
layer_number(item["wear"].get("edgeWear"), ("base", "amount")) > 0
|
|
2350
|
+
or has_non_empty_detail(item["wear"].get("scratches"))
|
|
2351
|
+
or has_non_empty_detail(item["wear"].get("chips"))
|
|
2352
|
+
)
|
|
2353
|
+
)
|
|
2354
|
+
or (
|
|
2355
|
+
isinstance(item.get("dirt"), dict)
|
|
2356
|
+
and (
|
|
2357
|
+
layer_number(item["dirt"].get("amount"), ("base", "amount")) > 0
|
|
2358
|
+
or layer_number(item["dirt"].get("cavityBias"), ("base", "amount")) > 0
|
|
2359
|
+
)
|
|
2360
|
+
)
|
|
2361
|
+
or has_non_empty_detail(item.get("moss"))
|
|
2362
|
+
or has_non_empty_detail(item.get("stains"))
|
|
2363
|
+
or has_non_empty_detail(item.get("scratches"))
|
|
2364
|
+
or has_non_empty_detail(item.get("chips"))
|
|
2365
|
+
or has_non_empty_detail(item.get("wetness"))
|
|
2366
|
+
or has_non_empty_detail(item.get("patina"))
|
|
2367
|
+
for item in materials
|
|
2368
|
+
)
|
|
2369
|
+
if not has_palette:
|
|
2370
|
+
warnings.append("quality: material-pass needs reference-derived albedo palette or secondary/accent color zones")
|
|
2371
|
+
if not has_response:
|
|
2372
|
+
warnings.append("quality: material-pass needs roughness variation or normal/bump/displacement response")
|
|
2373
|
+
if not has_locality:
|
|
2374
|
+
warnings.append("quality: material-pass needs local overrides, AO, dirt, wear, stains, moss, chips, scratches, or equivalent masks")
|
|
2375
|
+
quality_first = isinstance(targets, dict) and targets.get("qualityPriority") == "reference-fidelity"
|
|
2376
|
+
if quality_first:
|
|
2377
|
+
material_targets = targets.get("materialPass", {})
|
|
2378
|
+
if not isinstance(material_targets, dict):
|
|
2379
|
+
warnings.append("quality: quality-first lookDevTargets.materialPass must be an object")
|
|
2380
|
+
material_targets = {}
|
|
2381
|
+
minimum_resolution = material_targets.get("minimumTextureResolution", 1024)
|
|
2382
|
+
if not isinstance(minimum_resolution, int) or isinstance(minimum_resolution, bool):
|
|
2383
|
+
warnings.append("quality: minimumTextureResolution must be an integer")
|
|
2384
|
+
minimum_resolution = 1024
|
|
2385
|
+
required_channels = {
|
|
2386
|
+
str(item).lower()
|
|
2387
|
+
for item in material_targets.get("independentMapChannels", [])
|
|
2388
|
+
if isinstance(item, str)
|
|
2389
|
+
}
|
|
2390
|
+
extraction_targets = material_targets.get("referencePbrExtraction", {})
|
|
2391
|
+
if not isinstance(extraction_targets, dict):
|
|
2392
|
+
extraction_targets = {}
|
|
2393
|
+
pbr_required = (
|
|
2394
|
+
extraction_targets.get("requiredWhenSourceImagePresent") is True
|
|
2395
|
+
and has_non_empty_detail(spec.get("sourceImage"))
|
|
2396
|
+
)
|
|
2397
|
+
pbr_threshold = extraction_targets.get("targetThreshold", 0.7)
|
|
2398
|
+
if not is_number(pbr_threshold):
|
|
2399
|
+
pbr_threshold = 0.7
|
|
2400
|
+
expected_channels = {"albedo", "roughness", "height", "normal", "ambient-occlusion"}
|
|
2401
|
+
if not expected_channels.issubset(required_channels):
|
|
2402
|
+
warnings.append(
|
|
2403
|
+
"quality: quality-first materialPass must require independent albedo, roughness, "
|
|
2404
|
+
"height, normal, and ambient-occlusion channels"
|
|
2405
|
+
)
|
|
2406
|
+
for material in materials:
|
|
2407
|
+
if material.get("qualityTier") == "utility":
|
|
2408
|
+
continue
|
|
2409
|
+
# A material that declares -- with evidence -- that its subject carries no texture
|
|
2410
|
+
# detail is not held to the texture-channel bar. See validate_textureless: the
|
|
2411
|
+
# declaration is hard-validated, so this skip cannot be taken without the evidence
|
|
2412
|
+
# and cannot coexist with any texture-authoring field.
|
|
2413
|
+
if is_textureless(material):
|
|
2414
|
+
continue
|
|
2415
|
+
material_id = str(material.get("id") or "(unnamed)")
|
|
2416
|
+
resolution = material.get("textureResolution")
|
|
2417
|
+
if not isinstance(resolution, int) or isinstance(resolution, bool) or resolution < minimum_resolution:
|
|
2418
|
+
warnings.append(
|
|
2419
|
+
f"quality: material {material_id!r} textureResolution must be >= {minimum_resolution}"
|
|
2420
|
+
)
|
|
2421
|
+
projection = material.get("textureProjection")
|
|
2422
|
+
if not isinstance(projection, dict) or not has_non_empty_detail(projection.get("mode")):
|
|
2423
|
+
warnings.append(
|
|
2424
|
+
f"quality: material {material_id!r} needs textureProjection.mode and texel-density intent"
|
|
2425
|
+
)
|
|
2426
|
+
bands = material.get("surfaceFrequencyBands")
|
|
2427
|
+
band_ids = {
|
|
2428
|
+
str(item.get("id")).lower()
|
|
2429
|
+
for item in bands
|
|
2430
|
+
if isinstance(item, dict) and has_non_empty_detail(item.get("id"))
|
|
2431
|
+
} if isinstance(bands, list) else set()
|
|
2432
|
+
missing_bands = {"macro", "meso", "micro"} - band_ids
|
|
2433
|
+
if missing_bands:
|
|
2434
|
+
warnings.append(
|
|
2435
|
+
f"quality: material {material_id!r} missing surface frequency bands: "
|
|
2436
|
+
+ ", ".join(sorted(missing_bands))
|
|
2437
|
+
)
|
|
2438
|
+
roughness = material.get("roughness")
|
|
2439
|
+
roughness_map = roughness.get("map") if isinstance(roughness, dict) else None
|
|
2440
|
+
if not has_non_empty_detail(roughness_map) or "albedo" in str(roughness_map).lower():
|
|
2441
|
+
warnings.append(f"quality: material {material_id!r} needs an independent roughness map")
|
|
2442
|
+
if not has_non_empty_detail(material.get("ambientOcclusion")):
|
|
2443
|
+
warnings.append(
|
|
2444
|
+
f"quality: material {material_id!r} needs an independent ambient-occlusion response"
|
|
2445
|
+
)
|
|
2446
|
+
if pbr_required:
|
|
2447
|
+
ok, message = reference_pbr_usable(material, float(pbr_threshold))
|
|
2448
|
+
if not ok:
|
|
2449
|
+
warnings.append(f"quality: {message}")
|
|
2450
|
+
lighting = spec.get("lightingFromPhoto", [])
|
|
2451
|
+
if not isinstance(lighting, list):
|
|
2452
|
+
errors.append("lightingFromPhoto must be an array")
|
|
2453
|
+
else:
|
|
2454
|
+
meaningful = [item for item in lighting if has_non_empty_detail(item)]
|
|
2455
|
+
if len(meaningful) < 3:
|
|
2456
|
+
warnings.append("quality: lighting-pass needs concrete key/fill/rim or environment light entries")
|
|
2457
|
+
lighting_text = " ".join(str(item).lower() for item in meaningful)
|
|
2458
|
+
if meaningful and not any(term in lighting_text for term in ("exposure", "tone", "aces", "filmic")):
|
|
2459
|
+
warnings.append("quality: lighting-pass needs exposure and tone mapping intent")
|
|
2460
|
+
if meaningful and not any(term in lighting_text for term in ("contact shadow", "ground shadow", "ambient occlusion", "ao")):
|
|
2461
|
+
warnings.append("quality: lighting-pass needs contact shadow or ground shadow behavior")
|
|
2462
|
+
|
|
2463
|
+
|
|
2464
|
+
VALID_DETAIL_KINDS = {
|
|
2465
|
+
"gloss", "bevel", "fastener", "linework", "contour", "seam", "stitch",
|
|
2466
|
+
"stain", "scratch", "chip", "decal", "emissive", "hole", "groove", "ridge",
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
|
|
2470
|
+
def _detail_link_keys(spec: dict[str, Any]) -> set[str]:
|
|
2471
|
+
"""Collect keys a detailInventory item may map to: component ids, local feature ids,
|
|
2472
|
+
material ids, and material localOverride ids (with and without owner prefix)."""
|
|
2473
|
+
keys: set[str] = set()
|
|
2474
|
+
for comp in spec.get("componentTree", []):
|
|
2475
|
+
if not isinstance(comp, dict):
|
|
2476
|
+
continue
|
|
2477
|
+
cid = comp.get("id")
|
|
2478
|
+
if isinstance(cid, str):
|
|
2479
|
+
keys.add(cid)
|
|
2480
|
+
for feat in comp.get("localFeatures", []) or []:
|
|
2481
|
+
if isinstance(feat, str):
|
|
2482
|
+
keys.add(feat)
|
|
2483
|
+
if isinstance(cid, str):
|
|
2484
|
+
keys.add(f"{cid}/{feat}")
|
|
2485
|
+
elif isinstance(feat, dict) and isinstance(feat.get("id"), str):
|
|
2486
|
+
keys.add(feat["id"])
|
|
2487
|
+
if isinstance(cid, str):
|
|
2488
|
+
keys.add(f"{cid}/{feat['id']}")
|
|
2489
|
+
for mat in spec.get("materials", []):
|
|
2490
|
+
if not isinstance(mat, dict):
|
|
2491
|
+
continue
|
|
2492
|
+
mid = mat.get("id")
|
|
2493
|
+
if isinstance(mid, str):
|
|
2494
|
+
keys.add(mid)
|
|
2495
|
+
for over in mat.get("localOverrides", []) or []:
|
|
2496
|
+
if isinstance(over, dict) and isinstance(over.get("id"), str):
|
|
2497
|
+
keys.add(over["id"])
|
|
2498
|
+
if isinstance(mid, str):
|
|
2499
|
+
keys.add(f"{mid}/{over['id']}")
|
|
2500
|
+
return keys
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
def _has_gloss_response(spec: dict[str, Any]) -> bool:
|
|
2504
|
+
for mat in spec.get("materials", []):
|
|
2505
|
+
if not isinstance(mat, dict):
|
|
2506
|
+
continue
|
|
2507
|
+
rough = mat.get("roughness")
|
|
2508
|
+
base = rough.get("base") if isinstance(rough, dict) else rough
|
|
2509
|
+
if is_number(base) and float(base) < 0.35:
|
|
2510
|
+
return True
|
|
2511
|
+
if is_number(mat.get("clearcoat")) or isinstance(mat.get("clearcoat"), dict):
|
|
2512
|
+
return True
|
|
2513
|
+
for over in mat.get("localOverrides", []) or []:
|
|
2514
|
+
if isinstance(over, dict) and is_number(over.get("roughness")) and float(over["roughness"]) < 0.3:
|
|
2515
|
+
return True
|
|
2516
|
+
return False
|
|
2517
|
+
|
|
2518
|
+
|
|
2519
|
+
def _has_repetition_or_small_parts(spec: dict[str, Any]) -> bool:
|
|
2520
|
+
for repetition in spec.get("repetitionSystems", []):
|
|
2521
|
+
if not isinstance(repetition, dict):
|
|
2522
|
+
continue
|
|
2523
|
+
if repetition.get("realization") == "map-only" or repetition.get("buildsGeometry") is False:
|
|
2524
|
+
continue
|
|
2525
|
+
if repetition.get("geometry") is not None or repetition.get("instances") is not None or repetition.get("buildsGeometry") is True:
|
|
2526
|
+
return True
|
|
2527
|
+
return any(
|
|
2528
|
+
isinstance(c, dict) and c.get("level") == "micro"
|
|
2529
|
+
for c in spec.get("componentTree", [])
|
|
2530
|
+
)
|
|
2531
|
+
|
|
2532
|
+
|
|
2533
|
+
def validate_detail_inventory(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
2534
|
+
"""Gate the detail inventory. Backward compatible: only enforced when a detailInventory
|
|
2535
|
+
block with a positive targetMinDetails is present (new-pipeline specs)."""
|
|
2536
|
+
assessment = spec.get("preSpecAssessment")
|
|
2537
|
+
if not isinstance(assessment, dict):
|
|
2538
|
+
return
|
|
2539
|
+
inv = assessment.get("detailInventory")
|
|
2540
|
+
if not isinstance(inv, dict):
|
|
2541
|
+
return
|
|
2542
|
+
details = inv.get("details", [])
|
|
2543
|
+
if not isinstance(details, list):
|
|
2544
|
+
errors.append("preSpecAssessment.detailInventory.details must be an array")
|
|
2545
|
+
return
|
|
2546
|
+
target = inv.get("targetMinDetails", 0)
|
|
2547
|
+
if not (isinstance(target, int) and not isinstance(target, bool) and target > 0):
|
|
2548
|
+
return # not a new-pipeline spec; skip enforcement
|
|
2549
|
+
if len(details) < target:
|
|
2550
|
+
warnings.append(
|
|
2551
|
+
f"quality: detailInventory has {len(details)} details but targetMinDetails is {target}; "
|
|
2552
|
+
"enumerate identity-defining details (gloss, bevel, fasteners, linework, stains) before code generation"
|
|
2553
|
+
)
|
|
2554
|
+
link_keys = _detail_link_keys(spec)
|
|
2555
|
+
has_gloss = has_fastener = False
|
|
2556
|
+
for index, detail in enumerate(details):
|
|
2557
|
+
if not isinstance(detail, dict):
|
|
2558
|
+
errors.append(f"detailInventory.details[{index}] must be an object")
|
|
2559
|
+
continue
|
|
2560
|
+
did = detail.get("id", index)
|
|
2561
|
+
kind = detail.get("kind")
|
|
2562
|
+
if kind not in VALID_DETAIL_KINDS:
|
|
2563
|
+
warnings.append(f"quality: detailInventory detail {did!r} has unknown kind {kind!r}")
|
|
2564
|
+
maps = detail.get("mapsTo")
|
|
2565
|
+
ref = maps.get("ref") if isinstance(maps, dict) else None
|
|
2566
|
+
if not (isinstance(ref, str) and ref in link_keys):
|
|
2567
|
+
warnings.append(
|
|
2568
|
+
f"quality: detailInventory detail {did!r} does not map to a component.localFeatures "
|
|
2569
|
+
"or material.localOverrides entry (no prose-only details)"
|
|
2570
|
+
)
|
|
2571
|
+
if kind == "gloss":
|
|
2572
|
+
has_gloss = True
|
|
2573
|
+
elif kind == "fastener":
|
|
2574
|
+
has_fastener = True
|
|
2575
|
+
if has_gloss and not _has_gloss_response(spec):
|
|
2576
|
+
warnings.append(
|
|
2577
|
+
"quality: detailInventory lists a gloss detail but no material provides low roughness or clearcoat response"
|
|
2578
|
+
)
|
|
2579
|
+
if has_fastener and not _has_repetition_or_small_parts(spec):
|
|
2580
|
+
warnings.append(
|
|
2581
|
+
"quality: detailInventory lists fastener details but no repetitionSystem/instancing or micro parts represent them"
|
|
2582
|
+
)
|
|
2583
|
+
|
|
2584
|
+
|
|
2585
|
+
def validate_character_track(spec: dict[str, Any], errors: list[str], warnings: list[str]) -> None:
|
|
2586
|
+
"""Gate the character track. Backward compatible: only enforced when primaryDomain is
|
|
2587
|
+
character or hybrid."""
|
|
2588
|
+
assessment = spec.get("preSpecAssessment")
|
|
2589
|
+
if not isinstance(assessment, dict):
|
|
2590
|
+
return
|
|
2591
|
+
object_class = assessment.get("objectClass")
|
|
2592
|
+
domain = object_class.get("primaryDomain") if isinstance(object_class, dict) else None
|
|
2593
|
+
if domain not in {"character", "hybrid"}:
|
|
2594
|
+
return
|
|
2595
|
+
anatomy = assessment.get("anatomy")
|
|
2596
|
+
if not isinstance(anatomy, dict) or anatomy.get("applies") is not True:
|
|
2597
|
+
warnings.append(
|
|
2598
|
+
"quality: primaryDomain is character/hybrid but anatomy.applies is not true; "
|
|
2599
|
+
"fill anatomy (styleHeads, proportions, pose, faceLandmarks) from the reference"
|
|
2600
|
+
)
|
|
2601
|
+
return
|
|
2602
|
+
if not (is_number(anatomy.get("styleHeads")) and float(anatomy["styleHeads"]) > 0):
|
|
2603
|
+
warnings.append("quality: character anatomy.styleHeads must be greater than 0 (head-unit proportion)")
|
|
2604
|
+
proportions = anatomy.get("proportions")
|
|
2605
|
+
if not (isinstance(proportions, dict) and any(
|
|
2606
|
+
is_number(proportions.get(k)) and float(proportions[k]) > 0 for k in ("torso", "legs")
|
|
2607
|
+
)):
|
|
2608
|
+
warnings.append("quality: character anatomy.proportions must set torso/legs head-unit ratios")
|
|
2609
|
+
landmarks = anatomy.get("faceLandmarks")
|
|
2610
|
+
if not (isinstance(landmarks, dict) and any(
|
|
2611
|
+
is_number(landmarks.get(k)) and float(landmarks[k]) > 0 for k in ("eyeLine", "noseBase", "mouthLine")
|
|
2612
|
+
)):
|
|
2613
|
+
warnings.append("quality: character anatomy.faceLandmarks must set eyeLine/noseBase/mouthLine from the reference")
|
|
2614
|
+
targets = spec.get("featureReviewTargets", [])
|
|
2615
|
+
character_ids = {"anatomy-proportion", "face-landmark-placement", "pose-silhouette", "outfit-and-palette"}
|
|
2616
|
+
if not any(isinstance(t, dict) and t.get("id") in character_ids for t in targets):
|
|
2617
|
+
warnings.append(
|
|
2618
|
+
"quality: character track needs featureReviewTargets covering anatomy/face/pose/outfit "
|
|
2619
|
+
"(add anatomy-proportion, face-landmark-placement, pose-silhouette, outfit-and-palette)"
|
|
2620
|
+
)
|
|
2621
|
+
|
|
2622
|
+
|
|
2623
|
+
# PLAN_1.5 §5.2 Half A — the Joint Admission Gate. Pure semantics and arithmetic, which is why it
|
|
2624
|
+
# folds into this file rather than becoming a new module: §5.2 says so explicitly, and warns that
|
|
2625
|
+
# `forge/stage4_review/geometry_integrity.py` already owns that name. Half B
|
|
2626
|
+
# (INSIDE_VOLUME / UNIFORM_BONE_SCALE / NO_PRE_ROTATION) needs real geometry and belongs to a Node
|
|
2627
|
+
# script at stage 4, not here.
|
|
2628
|
+
SYMMETRY_PARITY_TOLERANCE = 0.05
|
|
2629
|
+
POOL_FLOOR_MIN_BONES = 4
|
|
2630
|
+
# §5.2 states PROPORTION_LIMIT as "bone length against the head-unit template (e.g. femur <= 2.5
|
|
2631
|
+
# HU)". READING CHOSEN: the rig carries no head unit — demanding `anatomy.proportions` would reject
|
|
2632
|
+
# the default `--character` template, which has no anatomy block at all — so the limit is expressed
|
|
2633
|
+
# as a fraction of the skeleton's own height. That is scale-free and needs no external input. On a
|
|
2634
|
+
# 6.78-head figure the plan's 2.5 HU is 2.5/6.78 = 37% of height, so 0.40 sits just above it.
|
|
2635
|
+
PROPORTION_LIMIT_FRACTION = 0.40
|
|
2636
|
+
|
|
2637
|
+
|
|
2638
|
+
def _mirror_partner(bone_id: str) -> str | None:
|
|
2639
|
+
"""`upper-arm-l` -> `upper-arm-r`, `thumb-l-1` -> `thumb-r-1`. None when not a left id.
|
|
2640
|
+
|
|
2641
|
+
Digit ids carry the side in the MIDDLE (`thumb-l-1`), so matching only a trailing `-l` would
|
|
2642
|
+
silently skip all thirty phalanges — the majority of the skeleton.
|
|
2643
|
+
"""
|
|
2644
|
+
if bone_id.endswith("-l"):
|
|
2645
|
+
return bone_id[:-2] + "-r"
|
|
2646
|
+
if "-l-" in bone_id:
|
|
2647
|
+
return bone_id.replace("-l-", "-r-", 1)
|
|
2648
|
+
return None
|
|
2649
|
+
|
|
2650
|
+
|
|
2651
|
+
def validate_rig_admission(
|
|
2652
|
+
spec: dict[str, Any], errors: list[str], warnings: list[str]
|
|
2653
|
+
) -> None:
|
|
2654
|
+
"""The five Half-A checks. Runs only when a `rig` is present, so the pivot track is a no-op.
|
|
2655
|
+
|
|
2656
|
+
SYMMETRY_PARITY **snaps** rather than rejects, per §5.2's "On fail" column — an asymmetric
|
|
2657
|
+
pair is a fixable authoring slip, not a broken skeleton. The other four reject.
|
|
2658
|
+
"""
|
|
2659
|
+
rig = spec.get("rig")
|
|
2660
|
+
if not isinstance(rig, dict):
|
|
2661
|
+
return
|
|
2662
|
+
bones = [b for b in (rig.get("bones") or []) if isinstance(b, dict) and b.get("id")]
|
|
2663
|
+
if not bones:
|
|
2664
|
+
return
|
|
2665
|
+
by_id = {b["id"]: b for b in bones}
|
|
2666
|
+
|
|
2667
|
+
def joint(bone: dict[str, Any]) -> list[float]:
|
|
2668
|
+
return [float(v) for v in (bone.get("jointPos") or [0.0, 0.0, 0.0])]
|
|
2669
|
+
|
|
2670
|
+
def tip(bone: dict[str, Any]) -> list[float]:
|
|
2671
|
+
return [float(v) for v in (bone.get("tipPos") or [0.0, 0.0, 0.0])]
|
|
2672
|
+
|
|
2673
|
+
def length(bone: dict[str, Any]) -> float:
|
|
2674
|
+
j, t = joint(bone), tip(bone)
|
|
2675
|
+
return sum((t[i] - j[i]) ** 2 for i in range(3)) ** 0.5
|
|
2676
|
+
|
|
2677
|
+
# ---- NAME_UNIQUENESS ----
|
|
2678
|
+
ids = [b["id"] for b in bones]
|
|
2679
|
+
duplicates = sorted({i for i in ids if ids.count(i) > 1})
|
|
2680
|
+
if duplicates:
|
|
2681
|
+
errors.append(f"NAME_UNIQUENESS: duplicate bone id(s) {duplicates}")
|
|
2682
|
+
roots = [b for b in bones if b.get("parent") in (None, "")]
|
|
2683
|
+
if len(roots) != 1:
|
|
2684
|
+
errors.append(
|
|
2685
|
+
f"NAME_UNIQUENESS: exactly one root bone required (parent: null), found {len(roots)}"
|
|
2686
|
+
+ (f" ({sorted(b['id'] for b in roots)})" if roots else "")
|
|
2687
|
+
)
|
|
2688
|
+
for bone in bones:
|
|
2689
|
+
parent = bone.get("parent")
|
|
2690
|
+
if parent and parent not in by_id:
|
|
2691
|
+
errors.append(
|
|
2692
|
+
f"NAME_UNIQUENESS: bone {bone['id']!r} has unresolved parent {parent!r}"
|
|
2693
|
+
)
|
|
2694
|
+
|
|
2695
|
+
# ---- POOL_FLOOR ----
|
|
2696
|
+
if len(bones) < POOL_FLOOR_MIN_BONES:
|
|
2697
|
+
errors.append(
|
|
2698
|
+
f"POOL_FLOOR: the skeleton resolves only {len(bones)} bone(s); the weight function "
|
|
2699
|
+
f"keeps four influences per vertex, so fewer than {POOL_FLOOR_MIN_BONES} leaves slots "
|
|
2700
|
+
f"structurally unfillable"
|
|
2701
|
+
)
|
|
2702
|
+
|
|
2703
|
+
# ---- SYMMETRY_PARITY (snap, do not reject) ----
|
|
2704
|
+
for bone in bones:
|
|
2705
|
+
partner_id = _mirror_partner(bone["id"])
|
|
2706
|
+
if not partner_id or partner_id not in by_id:
|
|
2707
|
+
continue
|
|
2708
|
+
left, right = joint(bone), joint(by_id[partner_id])
|
|
2709
|
+
mirrored = [-left[0], left[1], left[2]]
|
|
2710
|
+
delta = max(abs(right[i] - mirrored[i]) for i in range(3))
|
|
2711
|
+
if delta > SYMMETRY_PARITY_TOLERANCE:
|
|
2712
|
+
by_id[partner_id]["jointPos"] = [round(v, 5) for v in mirrored]
|
|
2713
|
+
left_tip = tip(bone)
|
|
2714
|
+
by_id[partner_id]["tipPos"] = [round(v, 5) for v in
|
|
2715
|
+
(-left_tip[0], left_tip[1], left_tip[2])]
|
|
2716
|
+
warnings.append(
|
|
2717
|
+
f"SYMMETRY_PARITY: {partner_id!r} was {delta:.4f} off the mirror of "
|
|
2718
|
+
f"{bone['id']!r} (tolerance {SYMMETRY_PARITY_TOLERANCE}); snapped to the "
|
|
2719
|
+
f"mirrored coordinate rather than rejected"
|
|
2720
|
+
)
|
|
2721
|
+
|
|
2722
|
+
# ---- MONOTONIC_CHAIN ----
|
|
2723
|
+
# §5.2 words this as "cumulative length along a limb chain must increase monotonically; no
|
|
2724
|
+
# bone may fold back through its parent". READING CHOSEN: the operative clause is the second.
|
|
2725
|
+
#
|
|
2726
|
+
# I first implemented the first clause as euclidean distance from the root joint to each tip,
|
|
2727
|
+
# and it REJECTED the correct 49-bone template on ten bones — which is the strongest possible
|
|
2728
|
+
# evidence that a check is mis-specified rather than the model being wrong. The reason is
|
|
2729
|
+
# anatomy: a clavicle reaches 0.70 up at the shoulder, then the upper arm hangs DOWN so its
|
|
2730
|
+
# tip lands at 0.49, back toward the hips. Distance-from-root is legitimately non-monotonic
|
|
2731
|
+
# for any chain that goes out then down. (Read as arc length the clause is trivially true,
|
|
2732
|
+
# since bone lengths are positive, so that cannot be the intent either.)
|
|
2733
|
+
#
|
|
2734
|
+
# So this compares DIRECTION. A bone folds back only when it points substantially opposite
|
|
2735
|
+
# its parent. The threshold is generous on purpose: a thumb sits near 90 degrees to the palm
|
|
2736
|
+
# and must pass, while a genuinely inverted bone sits near 180 and must not.
|
|
2737
|
+
MONOTONIC_CHAIN_OPPOSED_DOT = -0.5 # ~120 degrees apart
|
|
2738
|
+
|
|
2739
|
+
def direction(bone: dict[str, Any]) -> list[float] | None:
|
|
2740
|
+
j, t = joint(bone), tip(bone)
|
|
2741
|
+
delta = [t[i] - j[i] for i in range(3)]
|
|
2742
|
+
norm = sum(d * d for d in delta) ** 0.5
|
|
2743
|
+
return [d / norm for d in delta] if norm > 1e-9 else None
|
|
2744
|
+
|
|
2745
|
+
for bone in bones:
|
|
2746
|
+
parent_id = bone.get("parent")
|
|
2747
|
+
parent = by_id.get(parent_id) if parent_id else None
|
|
2748
|
+
if not parent or parent.get("chain") != bone.get("chain"):
|
|
2749
|
+
continue # a limb leaving the spine is a branch, not a continuation
|
|
2750
|
+
child_dir, parent_dir = direction(bone), direction(parent)
|
|
2751
|
+
if not child_dir or not parent_dir:
|
|
2752
|
+
continue
|
|
2753
|
+
dot = sum(child_dir[i] * parent_dir[i] for i in range(3))
|
|
2754
|
+
if dot < MONOTONIC_CHAIN_OPPOSED_DOT:
|
|
2755
|
+
errors.append(
|
|
2756
|
+
f"MONOTONIC_CHAIN: bone {bone['id']!r} points {dot:.3f} against its parent "
|
|
2757
|
+
f"{parent_id!r} (limit {MONOTONIC_CHAIN_OPPOSED_DOT}) — it folds back through "
|
|
2758
|
+
f"its parent instead of extending the chain"
|
|
2759
|
+
)
|
|
2760
|
+
|
|
2761
|
+
# ---- PROPORTION_LIMIT ----
|
|
2762
|
+
ys = [v for bone in bones for v in (joint(bone)[1], tip(bone)[1])]
|
|
2763
|
+
skeleton_height = max(ys) - min(ys) if ys else 0.0
|
|
2764
|
+
if skeleton_height > 0:
|
|
2765
|
+
limit = skeleton_height * PROPORTION_LIMIT_FRACTION
|
|
2766
|
+
for bone in bones:
|
|
2767
|
+
if length(bone) > limit:
|
|
2768
|
+
errors.append(
|
|
2769
|
+
f"PROPORTION_LIMIT: bone {bone['id']!r} is {length(bone):.4f} long, over "
|
|
2770
|
+
f"{PROPORTION_LIMIT_FRACTION:.0%} of the skeleton's {skeleton_height:.4f} "
|
|
2771
|
+
f"height ({limit:.4f})"
|
|
2772
|
+
)
|
|
2773
|
+
|
|
2774
|
+
|
|
2775
|
+
def validate_spec(spec: dict[str, Any]) -> tuple[list[str], list[str]]:
|
|
2776
|
+
errors: list[str] = []
|
|
2777
|
+
warnings: list[str] = []
|
|
2778
|
+
for key, expected_type in REQUIRED_TOP_LEVEL.items():
|
|
2779
|
+
if key not in spec:
|
|
2780
|
+
errors.append(f"missing top-level field {key!r}")
|
|
2781
|
+
elif not isinstance(spec[key], expected_type):
|
|
2782
|
+
errors.append(f"field {key!r} must be {expected_type.__name__}")
|
|
2783
|
+
suitability = spec.get("suitability")
|
|
2784
|
+
if suitability not in VALID_SUITABILITY:
|
|
2785
|
+
errors.append("suitability must be pass, conditional, or reject")
|
|
2786
|
+
validate_pre_spec_assessment(spec, errors, warnings)
|
|
2787
|
+
validate_terminology_profile(spec, errors, warnings)
|
|
2788
|
+
validate_score_block(spec, errors, warnings)
|
|
2789
|
+
validate_quality_targets(spec, errors, warnings)
|
|
2790
|
+
validate_quality_contract(spec, errors, warnings)
|
|
2791
|
+
validate_action_readiness(spec, errors, warnings)
|
|
2792
|
+
validate_self_correct_loop(spec, errors, warnings)
|
|
2793
|
+
validate_feature_review_targets(spec, errors, warnings)
|
|
2794
|
+
validate_chirality(spec, errors, warnings)
|
|
2795
|
+
validate_hair_profile(spec.get("hairProfile"), errors, warnings)
|
|
2796
|
+
validate_review_history(spec, errors, warnings)
|
|
2797
|
+
validate_visual_evidence_history(spec, errors)
|
|
2798
|
+
build_pass_ids = validate_build_passes(spec, errors, warnings)
|
|
2799
|
+
validate_sculpt_pipeline(spec, build_pass_ids, errors, warnings)
|
|
2800
|
+
validate_look_dev_targets(spec, errors, warnings)
|
|
2801
|
+
evidence_ids = validate_evidence(spec, errors, warnings)
|
|
2802
|
+
material_ids = validate_materials(spec, errors, warnings)
|
|
2803
|
+
validate_material_pipeline_contract(spec, material_ids, errors, warnings)
|
|
2804
|
+
validate_cs2_contract(spec, errors, warnings)
|
|
2805
|
+
validate_pipeline_routing_contract(spec, errors)
|
|
2806
|
+
validate_cs2_view_dependent_environment(spec, errors)
|
|
2807
|
+
validate_components(spec, material_ids, evidence_ids, errors, warnings)
|
|
2808
|
+
lod_plan = spec.get("lodPlan")
|
|
2809
|
+
if lod_plan is not None and not isinstance(lod_plan, list):
|
|
2810
|
+
errors.append("lodPlan must be an array")
|
|
2811
|
+
performance = spec.get("performanceBudget")
|
|
2812
|
+
if performance is not None and not isinstance(performance, dict):
|
|
2813
|
+
errors.append("performanceBudget must be an object")
|
|
2814
|
+
validate_quality_depth(spec, errors, warnings)
|
|
2815
|
+
validate_detail_inventory(spec, errors, warnings)
|
|
2816
|
+
validate_character_track(spec, errors, warnings)
|
|
2817
|
+
validate_rig_admission(spec, errors, warnings)
|
|
2818
|
+
if suitability == "pass" and spec.get("risks"):
|
|
2819
|
+
warnings.append("suitability is pass but risks are present; confirm they are acceptable")
|
|
2820
|
+
return errors, warnings
|
|
2821
|
+
|
|
2822
|
+
|
|
2823
|
+
def main(argv: list[str]) -> int:
|
|
2824
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
2825
|
+
parser.add_argument("spec", type=Path)
|
|
2826
|
+
parser.add_argument("--json", action="store_true", help="Print machine-readable result")
|
|
2827
|
+
parser.add_argument(
|
|
2828
|
+
"--strict-quality",
|
|
2829
|
+
action="store_true",
|
|
2830
|
+
help="Treat quality warnings as validation errors before implementation/generation",
|
|
2831
|
+
)
|
|
2832
|
+
args = parser.parse_args(argv)
|
|
2833
|
+
|
|
2834
|
+
try:
|
|
2835
|
+
spec = load_spec(args.spec)
|
|
2836
|
+
errors, warnings = validate_spec(spec)
|
|
2837
|
+
except ValueError as exc:
|
|
2838
|
+
errors, warnings = [str(exc)], []
|
|
2839
|
+
|
|
2840
|
+
if args.strict_quality:
|
|
2841
|
+
errors.extend(
|
|
2842
|
+
f"strict quality failure: {warning.removeprefix('quality: ').strip()}"
|
|
2843
|
+
for warning in warnings
|
|
2844
|
+
if warning.startswith("quality:")
|
|
2845
|
+
)
|
|
2846
|
+
|
|
2847
|
+
ok = not errors
|
|
2848
|
+
result = {
|
|
2849
|
+
"ok": ok,
|
|
2850
|
+
"errors": errors,
|
|
2851
|
+
"warnings": warnings,
|
|
2852
|
+
"summary": {
|
|
2853
|
+
"targetName": spec.get("targetName") if "spec" in locals() else None,
|
|
2854
|
+
"suitability": spec.get("suitability") if "spec" in locals() else None,
|
|
2855
|
+
"components": len(spec.get("componentTree", [])) if "spec" in locals() else 0,
|
|
2856
|
+
"materials": len(spec.get("materials", [])) if "spec" in locals() else 0,
|
|
2857
|
+
},
|
|
2858
|
+
}
|
|
2859
|
+
if args.json:
|
|
2860
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
2861
|
+
else:
|
|
2862
|
+
print("PASS" if ok else "FAIL")
|
|
2863
|
+
for warning in warnings:
|
|
2864
|
+
print(f"warning: {warning}")
|
|
2865
|
+
for error in errors:
|
|
2866
|
+
print(f"error: {error}")
|
|
2867
|
+
return 0 if ok else 1
|
|
2868
|
+
|
|
2869
|
+
|
|
2870
|
+
if __name__ == "__main__":
|
|
2871
|
+
raise SystemExit(main(sys.argv[1:]))
|