Keep authored JSON separate from generated output. Export rotated model bounds for SDK-free navigation and check grazing voxel corners. Include unretouched in-game before/after captures and explicit art/performance limits; pilots are an intermediate pass, not completion of the full asset set. Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Export conservative model bounds for SDK-free chassis navigation."""
|
||||
import itertools
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def model_bounds(model):
|
||||
points = []
|
||||
for element in model.get("elements", []):
|
||||
rotation = element.get("rotation")
|
||||
for point in itertools.product(*zip(element["from"], element["to"])):
|
||||
point = list(point)
|
||||
if rotation:
|
||||
axis = "xyz".index(rotation["axis"])
|
||||
a, b = (axis + 1) % 3, (axis + 2) % 3
|
||||
origin = rotation["origin"]
|
||||
x, y = point[a] - origin[a], point[b] - origin[b]
|
||||
angle = math.radians(rotation["angle"])
|
||||
# Rescaled rotations expand in the plane perpendicular to the rotation axis.
|
||||
scale = 1 / math.cos(angle) if rotation.get("rescale") else 1
|
||||
point[a] = origin[a] + (x * math.cos(angle) - y * math.sin(angle)) * scale
|
||||
point[b] = origin[b] + (x * math.sin(angle) + y * math.cos(angle)) * scale
|
||||
points.append(point)
|
||||
if not points:
|
||||
return None
|
||||
return tuple([min(p[a] for p in points) for a in range(3)]), tuple([max(p[a] for p in points) for a in range(3)])
|
||||
|
||||
|
||||
def write_rust_bounds(stage):
|
||||
stage = Path(stage)
|
||||
rows = ["// Generated by tools/gen_models.py from the final staged models; do not edit.\n",
|
||||
"pub fn bounds(id: &str) -> Option<([f64; 3], [f64; 3])> {\n Some(match id {\n"]
|
||||
for path in sorted((stage / "assets/airdef/models/block").glob("*.json")):
|
||||
bounds = model_bounds(json.loads(path.read_text(encoding="utf-8")))
|
||||
if bounds:
|
||||
lo, hi = ([round(float(x), 6) for x in corner] for corner in bounds)
|
||||
rows.append(f' "airdef:{path.stem}" => ({lo}, {hi}),\n')
|
||||
rows.append(" _ => return None,\n })\n}\n")
|
||||
target = stage / "src/sim/generated_bounds.rs"
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text("".join(rows), encoding="utf-8")
|
||||
@@ -0,0 +1,40 @@
|
||||
"""Resource registrations and localization, independent of geometry and raster generation."""
|
||||
import json
|
||||
import os
|
||||
|
||||
def write_json(path, obj):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(obj, f, ensure_ascii=False, indent=1)
|
||||
|
||||
|
||||
|
||||
def write_registry(out, namespace, models, items, camera_models):
|
||||
a = os.path.join(out, "assets", namespace)
|
||||
d = os.path.join(out, "data", namespace, "horizon")
|
||||
lang = {}
|
||||
NS = namespace
|
||||
for name, title in models:
|
||||
write_json(os.path.join(a, "blockstates", name + ".json"), {"variants": {"": {"model": f"{NS}:block/{name}"}}})
|
||||
write_json(os.path.join(d, "block", name + ".json"),
|
||||
{"template": "minecraft:stone", "item": False})
|
||||
lang[f"block.{NS}.{name}"] = title
|
||||
for name, title, _ in items:
|
||||
write_json(os.path.join(a, "models", "item", name + ".json"),
|
||||
{"parent": "minecraft:item/generated", "textures": {"layer0": f"{NS}:item/{name}"}})
|
||||
write_json(os.path.join(a, "items", name + ".json"),
|
||||
{"model": {"type": "minecraft:model", "model": f"{NS}:item/{name}"}})
|
||||
write_json(os.path.join(d, "item", name + ".json"), {"template": "minecraft:stick", "max_stack_size": 1})
|
||||
lang[f"item.{NS}.{name}"] = title
|
||||
# Предметы-иконки для камеры монитора: 3D-модель цели в интерфейсе.
|
||||
for name in camera_models:
|
||||
title = dict(models)[name]
|
||||
write_json(os.path.join(a, "models", "item", "cam_" + name + ".json"),
|
||||
{"parent": f"{NS}:block/{name}",
|
||||
"display": {"gui": {"rotation": [20, 145, 0], "translation": [0, 0, 0], "scale": [0.36, 0.36, 0.36]}}})
|
||||
write_json(os.path.join(a, "items", "cam_" + name + ".json"),
|
||||
{"model": {"type": "minecraft:model", "model": f"{NS}:item/cam_{name}"}})
|
||||
write_json(os.path.join(d, "item", "cam_" + name + ".json"), {"template": "minecraft:stick", "max_stack_size": 1})
|
||||
lang[f"item.{NS}.cam_{name}"] = title
|
||||
write_json(os.path.join(a, "lang", "en_us.json"), lang)
|
||||
write_json(os.path.join(a, "lang", "ru_ru.json"), lang)
|
||||
+6
-30
@@ -24,6 +24,8 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from PIL import Image
|
||||
import gen_tex as GT
|
||||
from airdef_assets import pipeline
|
||||
from airdef_assets.bounds import write_rust_bounds
|
||||
from airdef_assets.registry import write_json, write_registry
|
||||
from airdef_assets.texture_catalog import RINGED, STRETCH_FN, TEXTURES
|
||||
from airdef_assets.icons import ITEMS, render_icon
|
||||
ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "airdef-mod"))
|
||||
@@ -1042,11 +1044,6 @@ WRECKS = ["patriot_trailer", "patriot_launcher", "gepard_hull", "gepard_turret",
|
||||
|
||||
CAM_MODELS = ["shahed", "geran3", "lancet", "gerbera", "kh101", "kalibr", "kh22", "zircon", "iskander", "kinzhal", "reentry"]
|
||||
|
||||
def write_json(path, obj):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(obj, f, ensure_ascii=False, indent=1)
|
||||
|
||||
|
||||
def generate(out):
|
||||
# Пишет весь набор в каталог out (зеркало airdef-mod/). Звуки (tools/gen_sounds.py) и sounds.json не трогаем.
|
||||
@@ -1054,37 +1051,15 @@ def generate(out):
|
||||
d = os.path.join(out, "data", NS, "horizon")
|
||||
os.makedirs(os.path.join(a, "textures", "block"))
|
||||
os.makedirs(os.path.join(a, "textures", "item"))
|
||||
lang = {}
|
||||
for wid in WRECKS:
|
||||
fn, title = MODELS[wid]
|
||||
MODELS[wid + "_burnt"] = ((lambda fn=fn, wid=wid: burnt_parts(fn(), zlib.crc32(wid.encode()))), title + " (остов)")
|
||||
for name, (fn, title) in MODELS.items():
|
||||
for name, (fn, _) in MODELS.items():
|
||||
write_json(os.path.join(a, "models", "block", name + ".json"), model(fn(), name.endswith("_burnt")))
|
||||
write_json(os.path.join(a, "blockstates", name + ".json"), {"variants": {"": {"model": f"{NS}:block/{name}"}}})
|
||||
write_json(os.path.join(d, "block", name + ".json"),
|
||||
{"template": "minecraft:stone", "item": False})
|
||||
lang[f"block.{NS}.{name}"] = title
|
||||
GT.write_block_textures(a, TEXTURES, VARIANTS, STRETCH_FN)
|
||||
for i, (name, title, color) in enumerate(ITEMS):
|
||||
for name, _, color in ITEMS:
|
||||
GT.write_item_icon(a, name, render_icon(name, color, zlib.crc32(name.encode())))
|
||||
write_json(os.path.join(a, "models", "item", name + ".json"),
|
||||
{"parent": "minecraft:item/generated", "textures": {"layer0": f"{NS}:item/{name}"}})
|
||||
write_json(os.path.join(a, "items", name + ".json"),
|
||||
{"model": {"type": "minecraft:model", "model": f"{NS}:item/{name}"}})
|
||||
write_json(os.path.join(d, "item", name + ".json"), {"template": "minecraft:stick", "max_stack_size": 1})
|
||||
lang[f"item.{NS}.{name}"] = title
|
||||
# Предметы-иконки для камеры монитора: 3D-модель цели в интерфейсе.
|
||||
for name in CAM_MODELS:
|
||||
title = MODELS[name][1]
|
||||
write_json(os.path.join(a, "models", "item", "cam_" + name + ".json"),
|
||||
{"parent": f"{NS}:block/{name}",
|
||||
"display": {"gui": {"rotation": [20, 145, 0], "translation": [0, 0, 0], "scale": [0.36, 0.36, 0.36]}}})
|
||||
write_json(os.path.join(a, "items", "cam_" + name + ".json"),
|
||||
{"model": {"type": "minecraft:model", "model": f"{NS}:item/cam_{name}"}})
|
||||
write_json(os.path.join(d, "item", "cam_" + name + ".json"), {"template": "minecraft:stick", "max_stack_size": 1})
|
||||
lang[f"item.{NS}.cam_{name}"] = title
|
||||
write_json(os.path.join(a, "lang", "en_us.json"), lang)
|
||||
write_json(os.path.join(a, "lang", "ru_ru.json"), lang)
|
||||
write_registry(out, NS, [(name, title) for name, (_, title) in MODELS.items()], ITEMS, CAM_MODELS)
|
||||
return len(MODELS), len(ITEMS), len(TEXTURES)
|
||||
|
||||
|
||||
@@ -1210,6 +1185,7 @@ def regenerate(root=ROOT, source_root=None, manifest=None, *, check=False, repor
|
||||
if errors:
|
||||
details = "\n".join(f" - {err}" for err in errors)
|
||||
raise ValueError(f"ПРОВЕРКА НАБОРА НЕ ПРОЙДЕНА, ошибок: {len(errors)}. Ничего не записано в {root}.\n{details}")
|
||||
write_rust_bounds(stage)
|
||||
new = {}
|
||||
for dirpath, dirs, names in os.walk(stage):
|
||||
dirs.sort()
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export the three art pilots to authored JSON. Run gen_models.py afterwards.
|
||||
|
||||
The JSON under source-assets is the editable deliverable. This optional authoring helper
|
||||
only rewrites its explicitly named pilots; the normal generator never calls it.
|
||||
Existing origins, launcher grid and animation parts are retained.
|
||||
"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import zlib
|
||||
import gen_models as g
|
||||
|
||||
ROOT = Path(g.ROOT)
|
||||
SOURCE = ROOT / "source-assets/assets/airdef/models/block"
|
||||
|
||||
|
||||
def tire(x0, x1, z, radius=4.5):
|
||||
"""Five voxel strips: rounded silhouette, without overlapping rotated squares' star tips."""
|
||||
parts = []
|
||||
for lo, hi, width in [(-1, -.6, .6), (-.6, -.2, .92), (-.2, .2, 1), (.2, .6, .92), (.6, 1, .6)]:
|
||||
parts += g.both(g.el((x0, radius + lo * radius, z - width * radius),
|
||||
(x1, radius + hi * radius, z + width * radius), "tire"))
|
||||
parts += g.both(g.el((x0 - .05, radius - 2.2, z - 2.2),
|
||||
(x0, radius + 2.2, z + 2.2), "hub"))
|
||||
return parts
|
||||
|
||||
|
||||
def s400_chassis():
|
||||
parts = [p for p in g.maz_chassis("ru_green") if p["tex"] != "tire"]
|
||||
for z in [-10.5, -1.5, 16.5, 25.5]:
|
||||
parts += tire(-9, -5.5, z)
|
||||
# Cab roof and inset windscreen separate the cabin from the flat cargo deck.
|
||||
for x0, x1 in [(-5.7, 2.7), (13.3, 21.7)]:
|
||||
parts += [g.el((x0, 19, -15), (x1, 19.5, -7), "ru_green"),
|
||||
g.el((x0 + .5, 15, -15.8), (x1 - .5, 18.5, -15.55), "glass_cab", rot=("x", 22.5))]
|
||||
parts += g.both(g.B(-14.5, 8.3, -12.5, -14, 8.8, -7, "dark_metal"))
|
||||
parts += g.both(g.B(-14.4, 13, -10.2, -14.1, 13.4, -8.4, "bare_antenna"))
|
||||
# Underbody rails and an engine-deck grille read at normal gameplay distance.
|
||||
parts += [g.el((1, 4.2, -8), (3, 5, 29), "dark_metal"),
|
||||
g.el((13, 4.2, -8), (15, 5, 29), "dark_metal"),
|
||||
g.el((-3, 13.1, -3), (19, 13.5, 3), "bare_nozzle")]
|
||||
return parts
|
||||
|
||||
|
||||
def s400_tubes():
|
||||
parts = []
|
||||
# Same four centres and 7-unit diameter as Muzzle::Grid; pivots are unchanged.
|
||||
for x in [.5, 8.5]:
|
||||
for y in [0, 8]:
|
||||
for lo, hi, width in [(-1, -.6, .6), (-.6, -.2, .92), (-.2, .2, 1), (.2, .6, .92), (.6, 1, .6)]:
|
||||
parts.append(g.el((x + 3.5 - 3.5 * width, y + 3.5 + lo * 3.5, -16),
|
||||
(x + 3.5 + 3.5 * width, y + 3.5 + hi * 3.5, 32),
|
||||
"tube", {"north": "tube_cap", "south": "tube_cap"}))
|
||||
for z in [-1, 26]:
|
||||
parts.append(g.el((x - .15, y + 2.6, z), (x + 7.15, y + 4.4, z + 1), "dark_metal"))
|
||||
parts += [g.el((-.5, 0, 26), (16.5, 1, 29), "dark_metal")]
|
||||
return parts
|
||||
|
||||
|
||||
def gepard_hull():
|
||||
parts = [g.el((-10, 4, -8), (26, 15, 30), "flecktarn"),
|
||||
g.el((-10, 4, -15), (26, 9, -8), "flecktarn"),
|
||||
g.el((-9.5, 9, -14), (25.5, 13, -7), "flecktarn", rot=("x", -22.5)),
|
||||
g.el((-9, 15, -4), (25, 16.5, 18), "flecktarn"),
|
||||
g.el((-8, 15, 18), (24, 16, 30), "dark_metal"),
|
||||
g.el((-6, 16.6, -6), (3, 17.2, -1), "metal")]
|
||||
# Side tracks remain a continuous loop; visible road wheels replace a featureless slab.
|
||||
parts += g.both(g.el((-14, 0, -14), (-10, 8.8, 31), "track"))
|
||||
for z in [-10, -4, 2, 8, 14, 20, 26]:
|
||||
for lo, hi, width in [(-1, -.5, .65), (-.5, .5, 1), (.5, 1, .65)]:
|
||||
parts += g.both(g.el((-14.08, 4.3 + lo * 3.5, z - width * 2.8),
|
||||
(-14.02, 4.3 + hi * 3.5, z + width * 2.8), "hub"))
|
||||
parts += g.both(g.el((-14.5, 8.6, -14), (-10, 10, 31), "flecktarn"))
|
||||
for z in [20, 24, 28]:
|
||||
parts += [g.el((-6, 16.1, z), (22, 16.3, z + 1), "bare_nozzle")]
|
||||
return parts
|
||||
|
||||
|
||||
def gepard_turret():
|
||||
# Preserve the aiming origin, gun pack, tracking radar and search-dish attachment.
|
||||
parts = [g.el((-4, 0, -5), (20, 5, 16), "flecktarn"),
|
||||
g.el((-2.5, 5, -5), (18.5, 12, 15), "flecktarn"),
|
||||
g.el((-2, 12, -2), (18, 13, 14), "flecktarn"),
|
||||
g.el((3, 4, -10), (13, 12, -6), "radar_face"),
|
||||
g.el((7, 13, 10), (9, 18, 12), "metal")]
|
||||
parts += g.both(g.el((-4.7, 4.8, -4), (-2.5, 10.7, 14), "flecktarn", rot=("z", 22.5)))
|
||||
parts += [g.el((0, 13.05, 2), (5, 13.7, 8), "dark_metal"),
|
||||
g.el((10, 13.05, 2), (15, 13.7, 8), "dark_metal")]
|
||||
parts += g.decal("mk_de", 6, 9, -4, 2, 10.5)
|
||||
return parts
|
||||
|
||||
|
||||
def shahed():
|
||||
parts = g.ogive(-16, -9, 2.5, "shahed_nose", 4) + g.oct_z(-9, 22, 2.5, "shahed")
|
||||
parts += g.delta2("shahed", "kh101_belly", -2, 21, 26, 21, 12, 7.5, 8.3)
|
||||
parts += g.both(g.B(-20.8, 7.6, 18, -20.1, 13.2, 26, "shahed"))
|
||||
parts += g.oct_z(22, 28, 1.8, "dark_metal")
|
||||
parts += g.both(g.B(.8, 5.5, 24, 1.5, 6.6, 28, "bare_nozzle"))
|
||||
parts += [g.B(-1.3, 10.5, -3, 1.3, 10.8, 7, "shahed")]
|
||||
return parts
|
||||
|
||||
|
||||
def export(name, parts, burnt=False):
|
||||
model = g.model(parts, burnt=burnt)
|
||||
# The authoring tool reuses existing textures; it never creates untracked palette variants.
|
||||
for key, value in model["textures"].items():
|
||||
if not (ROOT / "assets/airdef/textures" / (value.split(":", 1)[1] + ".png")).exists():
|
||||
base = g.VARIANTS[key][0]
|
||||
candidate = base + "_b" if burnt else base
|
||||
if not (ROOT / "assets/airdef/textures/block" / (candidate + ".png")).exists():
|
||||
candidate = base
|
||||
model["textures"][key] = "airdef:block/" + candidate
|
||||
SOURCE.mkdir(parents=True, exist_ok=True)
|
||||
(SOURCE / (name + ".json")).write_text(json.dumps(model, indent=1) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for name, make in [("s400_chassis", s400_chassis), ("s400_tubes", s400_tubes),
|
||||
("gepard_hull", gepard_hull), ("gepard_turret", gepard_turret), ("shahed", shahed)]:
|
||||
parts = make()
|
||||
export(name, parts)
|
||||
if name != "shahed":
|
||||
export(name + "_burnt", g.burnt_parts(parts, zlib.crc32(name.encode())), burnt=True)
|
||||
print(name, len(parts), "elements")
|
||||
@@ -0,0 +1,36 @@
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from airdef_assets.bounds import model_bounds, write_rust_bounds
|
||||
from airdef_assets.pipeline import overlay_sources
|
||||
|
||||
|
||||
class BoundsTests(unittest.TestCase):
|
||||
def test_rotated_wheel_bounds_include_the_corners_outside_its_original_box(self):
|
||||
lo, hi = model_bounds({"elements": [{"from": [-1, -1, -1], "to": [1, 1, 1],
|
||||
"rotation": {"axis": "x", "angle": 45, "origin": [0, 0, 0]}}]})
|
||||
self.assertAlmostEqual(hi[1], math.sqrt(2))
|
||||
self.assertAlmostEqual(lo[2], -math.sqrt(2))
|
||||
self.assertEqual((lo[0], hi[0]), (-1, 1))
|
||||
|
||||
def test_final_authored_override_controls_exported_bounds(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
rel = Path("assets/airdef/models/block/test.json")
|
||||
stage, source = root / "stage", root / "source"
|
||||
for folder, extent in [(stage, 1), (source, 30)]:
|
||||
(folder / rel).parent.mkdir(parents=True)
|
||||
(folder / rel).write_text(json.dumps({"elements": [{"from": [0, 0, 0], "to": [extent, 2, 3]}]}))
|
||||
overlay_sources(stage, source)
|
||||
write_rust_bounds(stage)
|
||||
text = (stage / "src/sim/generated_bounds.rs").read_text()
|
||||
self.assertIn('"airdef:test"', text)
|
||||
self.assertIn("[30.0, 2.0, 3.0]", text)
|
||||
self.assertEqual(json.loads((source / rel).read_text())["elements"][0]["to"][0], 30)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user