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,276 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Detect whether a reference image depicts a CS2 weapon/item.
|
|
3
|
+
|
|
4
|
+
This is a pre-analysis guard that runs BEFORE visual analysis. It uses
|
|
5
|
+
heuristic signals (aspect ratio, color distribution, known CS2 weapon
|
|
6
|
+
silhouette ratios) to route the pipeline to the CS2-specific track.
|
|
7
|
+
|
|
8
|
+
This script does NOT do visual analysis — it only reads file metadata
|
|
9
|
+
and performs basic image statistics. The agent's vision layer does the
|
|
10
|
+
real CS2 identification later in the pipeline.
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
python3 detect_cs2.py <image_path> [--threshold 0.3]
|
|
14
|
+
python3 detect_cs2.py <image_path> --json
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import json
|
|
21
|
+
import math
|
|
22
|
+
import struct
|
|
23
|
+
import sys
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
# Image format readers (pure stdlib, no PIL)
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
def _png_dimensions(data: bytes) -> tuple[int, int] | None:
|
|
32
|
+
if data.startswith(b"\x89PNG\r\n\x1a\n") and len(data) >= 24:
|
|
33
|
+
return struct.unpack(">II", data[16:24])
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _jpeg_dimensions(data: bytes) -> tuple[int, int] | None:
|
|
38
|
+
if not data.startswith(b"\xff\xd8"):
|
|
39
|
+
return None
|
|
40
|
+
idx = 2
|
|
41
|
+
while idx + 9 < len(data):
|
|
42
|
+
if data[idx] != 0xFF:
|
|
43
|
+
idx += 1
|
|
44
|
+
continue
|
|
45
|
+
marker = data[idx + 1]
|
|
46
|
+
idx += 2
|
|
47
|
+
if marker in {0xD8, 0xD9}:
|
|
48
|
+
continue
|
|
49
|
+
if idx + 2 > len(data):
|
|
50
|
+
return None
|
|
51
|
+
length = struct.unpack(">H", data[idx : idx + 2])[0]
|
|
52
|
+
if length < 2 or idx + length > len(data):
|
|
53
|
+
return None
|
|
54
|
+
if marker in {0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF}:
|
|
55
|
+
if length >= 7:
|
|
56
|
+
height, width = struct.unpack(">HH", data[idx + 3 : idx + 7])
|
|
57
|
+
return width, height
|
|
58
|
+
idx += length
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _gif_dimensions(data: bytes) -> tuple[int, int] | None:
|
|
63
|
+
if data[:6] in {b"GIF87a", b"GIF89a"} and len(data) >= 10:
|
|
64
|
+
return struct.unpack("<HH", data[6:10])
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _webp_dimensions(data: bytes) -> tuple[int, int] | None:
|
|
69
|
+
if len(data) < 30 or data[:4] != b"RIFF" or data[8:12] != b"WEBP":
|
|
70
|
+
return None
|
|
71
|
+
chunk = data[12:16]
|
|
72
|
+
if chunk == b"VP8X" and len(data) >= 30:
|
|
73
|
+
width = 1 + int.from_bytes(data[24:27], "little")
|
|
74
|
+
height = 1 + int.from_bytes(data[27:30], "little")
|
|
75
|
+
return width, height
|
|
76
|
+
if chunk == b"VP8 " and len(data) >= 30:
|
|
77
|
+
start = data.find(b"\x9d\x01\x2a")
|
|
78
|
+
if start != -1 and start + 7 <= len(data):
|
|
79
|
+
width, height = struct.unpack("<HH", data[start + 3 : start + 7])
|
|
80
|
+
return width, height
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _read_dimensions(data: bytes) -> tuple[int, int] | None:
|
|
85
|
+
return (
|
|
86
|
+
_png_dimensions(data)
|
|
87
|
+
or _jpeg_dimensions(data)
|
|
88
|
+
or _gif_dimensions(data)
|
|
89
|
+
or _webp_dimensions(data)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# ---------------------------------------------------------------------------
|
|
94
|
+
# CS2 detection heuristics
|
|
95
|
+
# ---------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
# Known CS2 weapon aspect ratios (width / height) from inventory icons and
|
|
98
|
+
# standard workshop reference poses. These are *approximate* — a real CS2
|
|
99
|
+
# detection needs the agent vision layer, but these ratios help the guard
|
|
100
|
+
# route early.
|
|
101
|
+
CS2_WEAPON_ASPECT_RATIOS: dict[str, tuple[float, float]] = {
|
|
102
|
+
# knives — typically shown at ~15-45° angle
|
|
103
|
+
"knife_long": (1.8, 4.0), # Bowie, M9, Bayonet, Falchion
|
|
104
|
+
"knife_curved": (0.8, 1.5), # Karambit, Talon
|
|
105
|
+
"knife_folder": (1.2, 2.5), # Flip, Gut, Navaja
|
|
106
|
+
"knife_butterfly": (0.6, 1.2),# Butterfly (open)
|
|
107
|
+
# rifles — shown horizontally or at slight angle
|
|
108
|
+
"rifle_horizontal": (2.5, 5.0), # AK-47, M4A4, AWP
|
|
109
|
+
# pistols — shown at ~20-45° angle
|
|
110
|
+
"pistol_angle": (1.0, 2.0), # Glock, USP, Deagle, AK pistol
|
|
111
|
+
# gloves — shown as pair or single
|
|
112
|
+
"gloves": (0.8, 1.5),
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _aspect_in_cs2_ranges(aspect: float) -> list[str]:
|
|
117
|
+
"""Return list of CS2 weapon categories whose aspect ratio matches."""
|
|
118
|
+
matches = []
|
|
119
|
+
for category, (lo, hi) in CS2_WEAPON_ASPECT_RATIOS.items():
|
|
120
|
+
if lo <= aspect <= hi:
|
|
121
|
+
matches.append(category)
|
|
122
|
+
return matches
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _color_energy(data: bytes, sample_points: int = 200) -> dict[str, float]:
|
|
126
|
+
"""Sample raw byte energy at evenly-spaced points to detect dominant color ranges.
|
|
127
|
+
|
|
128
|
+
This is a VERY rough heuristic — it reads raw file bytes, not decoded
|
|
129
|
+
pixels. For real detection, the agent vision layer handles this.
|
|
130
|
+
"""
|
|
131
|
+
if len(data) < sample_points * 4:
|
|
132
|
+
return {"dominant_range": "unknown", "energy": 0.0}
|
|
133
|
+
|
|
134
|
+
step = len(data) // sample_points
|
|
135
|
+
r_sum = g_sum = b_sum = 0
|
|
136
|
+
for i in range(sample_points):
|
|
137
|
+
offset = i * step
|
|
138
|
+
if offset + 3 < len(data):
|
|
139
|
+
r_sum += data[offset]
|
|
140
|
+
g_sum += data[offset + 1]
|
|
141
|
+
b_sum += data[offset + 2]
|
|
142
|
+
|
|
143
|
+
r_avg = r_sum / sample_points
|
|
144
|
+
g_avg = g_sum / sample_points
|
|
145
|
+
b_avg = b_sum / sample_points
|
|
146
|
+
|
|
147
|
+
# Detect common CS2 backgrounds: white/grey workshop renders
|
|
148
|
+
if r_avg > 200 and g_avg > 200 and b_avg > 200:
|
|
149
|
+
dominant = "light_background"
|
|
150
|
+
elif r_avg < 50 and g_avg < 50 and b_avg < 50:
|
|
151
|
+
dominant = "dark_background"
|
|
152
|
+
elif abs(r_avg - g_avg) < 20 and abs(g_avg - b_avg) < 20:
|
|
153
|
+
dominant = "neutral_grey"
|
|
154
|
+
else:
|
|
155
|
+
dominant = "colored"
|
|
156
|
+
|
|
157
|
+
energy = math.sqrt(r_avg**2 + g_avg**2 + b_avg**2)
|
|
158
|
+
return {"dominant_range": dominant, "energy": round(energy, 2)}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def detect_cs2_signals(path: Path) -> dict:
|
|
162
|
+
"""Analyze a reference image for CS2 weapon/item detection signals.
|
|
163
|
+
|
|
164
|
+
Returns a dict with:
|
|
165
|
+
- is_cs2_candidate: bool
|
|
166
|
+
- confidence: 0.0-1.0
|
|
167
|
+
- signals: list of detected signal descriptions
|
|
168
|
+
- weapon_categories: possible CS2 weapon categories
|
|
169
|
+
- dimensions: {width, height, aspectRatio}
|
|
170
|
+
- color_profile: dominant color range info
|
|
171
|
+
- note: explanation of detection limits
|
|
172
|
+
"""
|
|
173
|
+
data = path.read_bytes()
|
|
174
|
+
dims = _read_dimensions(data)
|
|
175
|
+
signals: list[str] = []
|
|
176
|
+
score = 0.0
|
|
177
|
+
|
|
178
|
+
# Signal 1: Aspect ratio matches known CS2 weapon profiles
|
|
179
|
+
if dims:
|
|
180
|
+
width, height = dims
|
|
181
|
+
aspect = width / height if height else 1.0
|
|
182
|
+
categories = _aspect_in_cs2_ranges(aspect)
|
|
183
|
+
if categories:
|
|
184
|
+
score += 0.3
|
|
185
|
+
signals.append(f"aspect_ratio_matches:{','.join(categories)}")
|
|
186
|
+
else:
|
|
187
|
+
aspect = None
|
|
188
|
+
categories = []
|
|
189
|
+
|
|
190
|
+
# Signal 2: Image dimensions suggest inventory/workshop render
|
|
191
|
+
if dims:
|
|
192
|
+
w, h = dims
|
|
193
|
+
# CS2 inventory icons are typically 512×512 or 256×256
|
|
194
|
+
if w == h and w in {256, 512, 1024}:
|
|
195
|
+
score += 0.2
|
|
196
|
+
signals.append("square_format_inventory_icon")
|
|
197
|
+
# Workshop renders are often wide format
|
|
198
|
+
elif w > h and w >= 512:
|
|
199
|
+
score += 0.1
|
|
200
|
+
signals.append("wide_format_workshop_render")
|
|
201
|
+
|
|
202
|
+
# Signal 3: Color profile suggests workshop render
|
|
203
|
+
color = _color_energy(data)
|
|
204
|
+
if color["dominant_range"] == "light_background":
|
|
205
|
+
score += 0.15
|
|
206
|
+
signals.append("light_background_workshop_style")
|
|
207
|
+
elif color["dominant_range"] == "neutral_grey":
|
|
208
|
+
score += 0.1
|
|
209
|
+
signals.append("neutral_background_steam_style")
|
|
210
|
+
|
|
211
|
+
# Signal 4: File size suggests rendered image (not photo)
|
|
212
|
+
file_size = len(data)
|
|
213
|
+
if 50_000 < file_size < 5_000_000:
|
|
214
|
+
score += 0.05
|
|
215
|
+
signals.append("typical_render_file_size")
|
|
216
|
+
|
|
217
|
+
is_cs2_candidate = score >= 0.3
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
"path": str(path),
|
|
221
|
+
"is_cs2_candidate": is_cs2_candidate,
|
|
222
|
+
"confidence": min(round(score, 2), 1.0),
|
|
223
|
+
"signals": signals,
|
|
224
|
+
"weapon_categories": categories,
|
|
225
|
+
"dimensions": {
|
|
226
|
+
"width": dims[0] if dims else None,
|
|
227
|
+
"height": dims[1] if dims else None,
|
|
228
|
+
"aspectRatio": round(aspect, 3) if aspect else None,
|
|
229
|
+
},
|
|
230
|
+
"color_profile": color,
|
|
231
|
+
"note": (
|
|
232
|
+
"This is a heuristic pre-analysis guard using file metadata and "
|
|
233
|
+
"basic byte statistics. It does NOT perform visual analysis. "
|
|
234
|
+
"The agent's vision layer (Step 1) performs definitive CS2 "
|
|
235
|
+
"identification using the M.C.M.T framework in "
|
|
236
|
+
"grimoire/intake/cs2_technical_analysis.md"
|
|
237
|
+
),
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
# ---------------------------------------------------------------------------
|
|
242
|
+
# CLI
|
|
243
|
+
# ---------------------------------------------------------------------------
|
|
244
|
+
|
|
245
|
+
def main(argv: list[str]) -> int:
|
|
246
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
247
|
+
parser.add_argument("image", type=Path, help="Path to reference image")
|
|
248
|
+
parser.add_argument("--json", action="store_true", help="Output raw JSON")
|
|
249
|
+
parser.add_argument("--threshold", type=float, default=0.3, help="CS2 candidate threshold (default: 0.3)")
|
|
250
|
+
args = parser.parse_args(argv)
|
|
251
|
+
|
|
252
|
+
if not args.image.exists():
|
|
253
|
+
print(json.dumps({"error": f"File not found: {args.image}"}))
|
|
254
|
+
return 1
|
|
255
|
+
|
|
256
|
+
result = detect_cs2_signals(args.image)
|
|
257
|
+
|
|
258
|
+
if args.json:
|
|
259
|
+
print(json.dumps(result, indent=2))
|
|
260
|
+
else:
|
|
261
|
+
status = "CS2_CANDIDATE" if result["is_cs2_candidate"] else "NON_CS2"
|
|
262
|
+
print(f"Status: {status}")
|
|
263
|
+
print(f"Confidence: {result['confidence']}")
|
|
264
|
+
print(f"Signals: {', '.join(result['signals']) or 'none'}")
|
|
265
|
+
if result["weapon_categories"]:
|
|
266
|
+
print(f"Weapon categories: {', '.join(result['weapon_categories'])}")
|
|
267
|
+
dims = result["dimensions"]
|
|
268
|
+
if dims["width"]:
|
|
269
|
+
print(f"Dimensions: {dims['width']}×{dims['height']} (aspect {dims['aspectRatio']})")
|
|
270
|
+
print(f"\n{result['note']}")
|
|
271
|
+
|
|
272
|
+
return 0
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
if __name__ == "__main__":
|
|
276
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Reference-effect detectors for the img2threejs presentation stage.
|
|
3
|
+
|
|
4
|
+
Post-processing (depth-of-field, bloom) is authorized on the PRESENTATION render
|
|
5
|
+
ONLY, and ONLY when the REFERENCE photo actually exhibits that characteristic.
|
|
6
|
+
These detectors look at the reference image and decide whether each effect is
|
|
7
|
+
warranted so that effects serve photographic fidelity, not decoration. They are
|
|
8
|
+
NEVER applied to the Eye's evaluation render.
|
|
9
|
+
|
|
10
|
+
Pure Python 3.10+ stdlib only. Reuses the stage1 loader (import, do NOT edit).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import json
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "stage1_intake"))
|
|
22
|
+
from extract_pbr_evidence import load_image, build_foreground_mask # noqa: E402
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# --------------------------------------------------------------------------- #
|
|
26
|
+
# Helpers
|
|
27
|
+
# --------------------------------------------------------------------------- #
|
|
28
|
+
def luma(r: int, g: int, b: int) -> float:
|
|
29
|
+
"""Rec.709 luma normalized to 0..1."""
|
|
30
|
+
return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255.0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _luma_grid(
|
|
34
|
+
width: int,
|
|
35
|
+
height: int,
|
|
36
|
+
pixels: list[tuple[int, int, int, int]],
|
|
37
|
+
step: int,
|
|
38
|
+
) -> tuple[list[float], int, int]:
|
|
39
|
+
"""Downsample the image to a manageable grid of luma values.
|
|
40
|
+
|
|
41
|
+
Samples every ``step`` pixels. Returns (grid, grid_width, grid_height) where
|
|
42
|
+
grid is row-major of length grid_width * grid_height.
|
|
43
|
+
"""
|
|
44
|
+
grid: list[float] = []
|
|
45
|
+
gw = 0
|
|
46
|
+
gh = 0
|
|
47
|
+
for y in range(0, height, step):
|
|
48
|
+
gh += 1
|
|
49
|
+
row_count = 0
|
|
50
|
+
for x in range(0, width, step):
|
|
51
|
+
r, g, b, _a = pixels[y * width + x]
|
|
52
|
+
grid.append(luma(r, g, b))
|
|
53
|
+
row_count += 1
|
|
54
|
+
gw = row_count
|
|
55
|
+
return grid, gw, gh
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _mask_grid(
|
|
59
|
+
width: int,
|
|
60
|
+
height: int,
|
|
61
|
+
mask: list[bool],
|
|
62
|
+
step: int,
|
|
63
|
+
) -> list[bool]:
|
|
64
|
+
"""Downsample the foreground mask on the same sampling lattice as _luma_grid."""
|
|
65
|
+
out: list[bool] = []
|
|
66
|
+
for y in range(0, height, step):
|
|
67
|
+
for x in range(0, width, step):
|
|
68
|
+
out.append(mask[y * width + x])
|
|
69
|
+
return out
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _grid_step(width: int, height: int, target: int = 160) -> int:
|
|
73
|
+
"""Pick a sampling step so the longer side is ~<= target cells."""
|
|
74
|
+
return max(1, max(width, height) // target)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def local_gradient_energy(
|
|
78
|
+
grid: list[float],
|
|
79
|
+
gw: int,
|
|
80
|
+
gh: int,
|
|
81
|
+
keep: list[bool] | None,
|
|
82
|
+
) -> float:
|
|
83
|
+
"""Mean of |L(x,y)-L(x-1,y)| + |L(x,y)-L(x,y-1)| over the selected region.
|
|
84
|
+
|
|
85
|
+
``keep`` selects which grid cells to include (True = include). When None,
|
|
86
|
+
every cell with x>=1 and y>=1 is included.
|
|
87
|
+
"""
|
|
88
|
+
total = 0.0
|
|
89
|
+
count = 0
|
|
90
|
+
for y in range(1, gh):
|
|
91
|
+
for x in range(1, gw):
|
|
92
|
+
idx = y * gw + x
|
|
93
|
+
if keep is not None and not keep[idx]:
|
|
94
|
+
continue
|
|
95
|
+
here = grid[idx]
|
|
96
|
+
dxe = abs(here - grid[idx - 1])
|
|
97
|
+
dye = abs(here - grid[idx - gw])
|
|
98
|
+
total += dxe + dye
|
|
99
|
+
count += 1
|
|
100
|
+
return total / count if count else 0.0
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# --------------------------------------------------------------------------- #
|
|
104
|
+
# Detectors
|
|
105
|
+
# --------------------------------------------------------------------------- #
|
|
106
|
+
def detect_background_blur(png_path: Path) -> dict[str, Any]:
|
|
107
|
+
"""Detect shallow depth-of-field: background much blurrier than the subject."""
|
|
108
|
+
width, height, pixels, _warnings = load_image(png_path)
|
|
109
|
+
mask, diag, _mask_warnings = build_foreground_mask(width, height, pixels)
|
|
110
|
+
coverage = float(diag.get("foregroundCoverage", 0.0))
|
|
111
|
+
|
|
112
|
+
step = _grid_step(width, height)
|
|
113
|
+
grid, gw, gh = _luma_grid(width, height, pixels, step)
|
|
114
|
+
mgrid = _mask_grid(width, height, mask, step)
|
|
115
|
+
|
|
116
|
+
subject_keep = mgrid
|
|
117
|
+
background_keep = [not value for value in mgrid]
|
|
118
|
+
|
|
119
|
+
subject_energy = local_gradient_energy(grid, gw, gh, subject_keep)
|
|
120
|
+
background_energy = local_gradient_energy(grid, gw, gh, background_keep)
|
|
121
|
+
ratio = background_energy / subject_energy if subject_energy > 0 else 1.0
|
|
122
|
+
|
|
123
|
+
has_background = 0.05 < coverage < 0.95
|
|
124
|
+
blurred = has_background and ratio < 0.5
|
|
125
|
+
|
|
126
|
+
if not has_background:
|
|
127
|
+
reason = (
|
|
128
|
+
f"no separable background (foreground coverage {coverage:.3f} outside "
|
|
129
|
+
f"0.05..0.95); depth-of-field not applicable"
|
|
130
|
+
)
|
|
131
|
+
elif blurred:
|
|
132
|
+
reason = (
|
|
133
|
+
f"background detail ({background_energy:.5f}) is under half the subject "
|
|
134
|
+
f"detail ({subject_energy:.5f}); ratio {ratio:.3f} < 0.5 indicates shallow "
|
|
135
|
+
f"depth-of-field"
|
|
136
|
+
)
|
|
137
|
+
else:
|
|
138
|
+
reason = (
|
|
139
|
+
f"background detail ({background_energy:.5f}) is comparable to subject "
|
|
140
|
+
f"detail ({subject_energy:.5f}); ratio {ratio:.3f} >= 0.5, scene reads sharp"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
"blurred": blurred,
|
|
145
|
+
"backgroundEnergy": round(background_energy, 6),
|
|
146
|
+
"subjectEnergy": round(subject_energy, 6),
|
|
147
|
+
"ratio": round(ratio, 4),
|
|
148
|
+
"reason": reason,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def detect_highlight_glow(png_path: Path) -> dict[str, Any]:
|
|
153
|
+
"""Detect bloom: clipped highlights surrounded by a gradual bright halo."""
|
|
154
|
+
width, height, pixels, _warnings = load_image(png_path)
|
|
155
|
+
total = max(1, width * height)
|
|
156
|
+
|
|
157
|
+
lumas = [luma(r, g, b) for r, g, b, _a in pixels]
|
|
158
|
+
hot_indices = [i for i, value in enumerate(lumas) if value > 0.92]
|
|
159
|
+
hot_fraction = len(hot_indices) / total
|
|
160
|
+
|
|
161
|
+
if not hot_indices:
|
|
162
|
+
return {
|
|
163
|
+
"glow": False,
|
|
164
|
+
"hotFraction": round(hot_fraction, 6),
|
|
165
|
+
"haloFraction": 0.0,
|
|
166
|
+
"reason": "no near-white highlights (luma > 0.92); nothing to bloom",
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# Sample the hot pixels so large clipped regions stay fast.
|
|
170
|
+
sample_limit = 200
|
|
171
|
+
if len(hot_indices) > sample_limit:
|
|
172
|
+
stride = len(hot_indices) // sample_limit
|
|
173
|
+
sampled = hot_indices[::stride][:sample_limit]
|
|
174
|
+
else:
|
|
175
|
+
sampled = hot_indices
|
|
176
|
+
|
|
177
|
+
# Ring of neighbors just outside the hot core (2-3px out, 8 compass dirs).
|
|
178
|
+
ring_offsets = [
|
|
179
|
+
(dx, dy)
|
|
180
|
+
for radius in (2, 3)
|
|
181
|
+
for dx, dy in (
|
|
182
|
+
(-radius, 0),
|
|
183
|
+
(radius, 0),
|
|
184
|
+
(0, -radius),
|
|
185
|
+
(0, radius),
|
|
186
|
+
(-radius, -radius),
|
|
187
|
+
(radius, -radius),
|
|
188
|
+
(-radius, radius),
|
|
189
|
+
(radius, radius),
|
|
190
|
+
)
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
haloed = 0
|
|
194
|
+
for idx in sampled:
|
|
195
|
+
x = idx % width
|
|
196
|
+
y = idx // width
|
|
197
|
+
elevated_neighbor = False
|
|
198
|
+
for dx, dy in ring_offsets:
|
|
199
|
+
nx = x + dx
|
|
200
|
+
ny = y + dy
|
|
201
|
+
if 0 <= nx < width and 0 <= ny < height:
|
|
202
|
+
neighbor = lumas[ny * width + nx]
|
|
203
|
+
if 0.6 <= neighbor <= 0.92:
|
|
204
|
+
elevated_neighbor = True
|
|
205
|
+
break
|
|
206
|
+
if elevated_neighbor:
|
|
207
|
+
haloed += 1
|
|
208
|
+
|
|
209
|
+
halo_fraction = haloed / len(sampled)
|
|
210
|
+
glow = hot_fraction > 0.005 and halo_fraction > 0.5
|
|
211
|
+
|
|
212
|
+
if glow:
|
|
213
|
+
reason = (
|
|
214
|
+
f"highlights present (hotFraction {hot_fraction:.4f} > 0.005) and "
|
|
215
|
+
f"{halo_fraction:.2%} of them fade through an elevated halo (0.6..0.92); "
|
|
216
|
+
f"bloom is warranted"
|
|
217
|
+
)
|
|
218
|
+
elif hot_fraction <= 0.005:
|
|
219
|
+
reason = (
|
|
220
|
+
f"highlights are negligible (hotFraction {hot_fraction:.4f} <= 0.005); "
|
|
221
|
+
f"no bloom"
|
|
222
|
+
)
|
|
223
|
+
else:
|
|
224
|
+
reason = (
|
|
225
|
+
f"highlights present but only {halo_fraction:.2%} bloom outward "
|
|
226
|
+
f"(<= 50%); hard edges, no gradual halo, so no bloom"
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
"glow": glow,
|
|
231
|
+
"hotFraction": round(hot_fraction, 6),
|
|
232
|
+
"haloFraction": round(halo_fraction, 4),
|
|
233
|
+
"reason": reason,
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def recommend_effects(png_path: Path) -> dict[str, Any]:
|
|
238
|
+
"""Run both detectors and recommend which post-fx the reference warrants."""
|
|
239
|
+
blur = detect_background_blur(png_path)
|
|
240
|
+
glow = detect_highlight_glow(png_path)
|
|
241
|
+
return {
|
|
242
|
+
"dof": blur["blurred"],
|
|
243
|
+
"bloom": glow["glow"],
|
|
244
|
+
"blur": blur,
|
|
245
|
+
"glow": glow,
|
|
246
|
+
"note": (
|
|
247
|
+
"post-fx authorized only for effects the reference actually exhibits; "
|
|
248
|
+
"applied on the presentation render only, never the Eye's evaluation render"
|
|
249
|
+
),
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
# --------------------------------------------------------------------------- #
|
|
254
|
+
# CLI
|
|
255
|
+
# --------------------------------------------------------------------------- #
|
|
256
|
+
def main(argv: list[str]) -> int:
|
|
257
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
258
|
+
parser.add_argument("image", type=Path)
|
|
259
|
+
parser.add_argument("--json", action="store_true", help="Print compact JSON")
|
|
260
|
+
args = parser.parse_args(argv)
|
|
261
|
+
|
|
262
|
+
try:
|
|
263
|
+
result = recommend_effects(args.image.expanduser().resolve())
|
|
264
|
+
if args.json:
|
|
265
|
+
print(json.dumps(result, ensure_ascii=False))
|
|
266
|
+
else:
|
|
267
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
268
|
+
return 0
|
|
269
|
+
except Exception as exc: # noqa: BLE001
|
|
270
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
271
|
+
return 2
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
if __name__ == "__main__":
|
|
275
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Optional exactness upgrade: extract a CS2 skin's authored paint textures from the user's own
|
|
3
|
+
legal install using Source2Viewer-CLI, then classify the output maps by convention. Degrades
|
|
4
|
+
gracefully -- every failure (no VPK, no extractor binary, subprocess error, non-zero exit) returns
|
|
5
|
+
a {"status": "fallback", "reason": ...} result so the pipeline can fall back to the image-only
|
|
6
|
+
path, never a wrong render. Extracted pixels are Valve IP: they stay in the gitignored cs2_textures/
|
|
7
|
+
workspace and are never committed. See grimoire/intake/cs2_texture_acquisition.md and openspec
|
|
8
|
+
add-cs2-item-reconstruction tasks 5.4/5.5.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import shutil
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
21
|
+
import locate_cs2_vpk # noqa: E402 (sibling module, resolved via the path insert above)
|
|
22
|
+
from cs2_foundation import classify_map_path # noqa: E402
|
|
23
|
+
|
|
24
|
+
SOURCE2VIEWER_BINARY = "Source2Viewer-CLI"
|
|
25
|
+
|
|
26
|
+
# Filename-convention buckets for Source 2 material maps. A map that matches nothing lands in
|
|
27
|
+
# "other" rather than being dropped, so an unexpected naming convention is visible, not silent.
|
|
28
|
+
_MAP_CLASSIFIERS = (
|
|
29
|
+
("color", ("_color", "_albedo", "_basecolor", "_diffuse")),
|
|
30
|
+
("normal", ("_normal", "_bump", "_nrm")),
|
|
31
|
+
("roughness_metalness", ("_rough", "_metal", "_orm", "_mrao", "_packed")),
|
|
32
|
+
("mask", ("_mask", "_ao", "_occlusion", "_pattern", "_wear")),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def source2viewer_available() -> bool:
|
|
37
|
+
"""True when the Source2Viewer-CLI binary is on PATH (it needs the .NET runtime to run)."""
|
|
38
|
+
return shutil.which(SOURCE2VIEWER_BINARY) is not None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def run_source2viewer(vpk: Path, out_dir: Path, filter_glob: str | None = None) -> subprocess.CompletedProcess:
|
|
42
|
+
"""Wrap the Source2Viewer-CLI extraction call. Raises FileNotFoundError if the binary is
|
|
43
|
+
absent; returns the CompletedProcess otherwise (caller inspects returncode)."""
|
|
44
|
+
cmd = [SOURCE2VIEWER_BINARY, "-i", str(vpk), "-o", str(out_dir), "-d", "-e", "vtex_c"]
|
|
45
|
+
if filter_glob:
|
|
46
|
+
cmd += ["-f", filter_glob]
|
|
47
|
+
return subprocess.run(cmd, capture_output=True, text=True)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def classify_extracted_maps(out_dir: Path) -> dict[str, list[str]]:
|
|
51
|
+
"""Bucket the files under out_dir into color / normal / roughness_metalness / mask / other by
|
|
52
|
+
filename convention."""
|
|
53
|
+
buckets: dict[str, list[str]] = {name: [] for name, _ in _MAP_CLASSIFIERS}
|
|
54
|
+
buckets["other"] = []
|
|
55
|
+
if not out_dir.is_dir():
|
|
56
|
+
return buckets
|
|
57
|
+
for path in sorted(out_dir.rglob("*")):
|
|
58
|
+
if not path.is_file():
|
|
59
|
+
continue
|
|
60
|
+
lower = path.name.lower()
|
|
61
|
+
for name, suffixes in _MAP_CLASSIFIERS:
|
|
62
|
+
if any(token in lower for token in suffixes):
|
|
63
|
+
buckets[name].append(str(path))
|
|
64
|
+
break
|
|
65
|
+
else:
|
|
66
|
+
buckets["other"].append(str(path))
|
|
67
|
+
return buckets
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def build_asset_records(out_dir: Path) -> list[dict]:
|
|
71
|
+
records = []
|
|
72
|
+
for path in sorted(out_dir.rglob("*")):
|
|
73
|
+
if path.is_file():
|
|
74
|
+
record = classify_map_path(path)
|
|
75
|
+
record.update({"source": "local-vpk", "ipBoundary": "local-user-install-not-redistributable"})
|
|
76
|
+
records.append(record)
|
|
77
|
+
return records
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def extract(out_dir: Path, vpk: Path | None, roots: list[Path] | None, filter_glob: str | None) -> dict:
|
|
81
|
+
if vpk is None:
|
|
82
|
+
vpk = locate_cs2_vpk.locate_vpk(roots)
|
|
83
|
+
if vpk is None:
|
|
84
|
+
return {"status": "fallback",
|
|
85
|
+
"reason": "no local CS2 VPK found; falling back to image-only reconstruction "
|
|
86
|
+
"(exact texture likeness unavailable)"}
|
|
87
|
+
if not source2viewer_available():
|
|
88
|
+
return {"status": "fallback",
|
|
89
|
+
"reason": f"{SOURCE2VIEWER_BINARY} not found on PATH; falling back to image-only "
|
|
90
|
+
"reconstruction (exact texture likeness unavailable)"}
|
|
91
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
92
|
+
try:
|
|
93
|
+
result = run_source2viewer(vpk, out_dir, filter_glob)
|
|
94
|
+
except OSError as exc:
|
|
95
|
+
return {"status": "fallback", "reason": f"{SOURCE2VIEWER_BINARY} failed to run ({exc}); "
|
|
96
|
+
"falling back to image-only reconstruction"}
|
|
97
|
+
if result.returncode != 0:
|
|
98
|
+
return {"status": "fallback",
|
|
99
|
+
"reason": f"{SOURCE2VIEWER_BINARY} exited {result.returncode}: "
|
|
100
|
+
f"{(result.stderr or '').strip()[:200]}; falling back to image-only"}
|
|
101
|
+
return {"status": "ok", "vpk": str(vpk), "outDir": str(out_dir),
|
|
102
|
+
"maps": classify_extracted_maps(out_dir), "assets": build_asset_records(out_dir)}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def main(argv: list[str]) -> int:
|
|
106
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
107
|
+
parser.add_argument("--out", type=Path, required=True, help="Output directory (gitignored cs2_textures/)")
|
|
108
|
+
parser.add_argument("--vpk", type=Path, help="Explicit pak01_dir.vpk path (skips locating)")
|
|
109
|
+
parser.add_argument("--root", type=Path, action="append", dest="roots",
|
|
110
|
+
help="Steam root to search when --vpk is omitted (repeatable)")
|
|
111
|
+
parser.add_argument("--filter", dest="filter_glob", help="Source2Viewer -f filter, e.g. a paint kit name")
|
|
112
|
+
parser.add_argument("--json", action="store_true", help="Emit a JSON result object")
|
|
113
|
+
args = parser.parse_args(argv)
|
|
114
|
+
|
|
115
|
+
result = extract(args.out.expanduser(), args.vpk, args.roots, args.filter_glob)
|
|
116
|
+
if args.json:
|
|
117
|
+
print(json.dumps(result, indent=2))
|
|
118
|
+
elif result["status"] == "ok":
|
|
119
|
+
print(f"extracted to {result['outDir']}")
|
|
120
|
+
else:
|
|
121
|
+
print(result["reason"], file=sys.stderr)
|
|
122
|
+
return 0 if result["status"] == "ok" else 1
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if __name__ == "__main__":
|
|
126
|
+
raise SystemExit(main(sys.argv[1:]))
|