"""Headless Blender smoke for New Ship, Rasterise, Flip Nose, the Grid object and the export exclusions. blender --background --factory-startup --python-use-system-env --python tools/blender/tests/smoke_frame.py Environment as smoke_package.py's header says: CULTLIB_PACKAGES, plus CULTLIB_ROOT and CULTMATH_ROOT at the pinned revisions for the 'dotnet run --project tools/AetherDb' calls, and msgpack importable. New Ship writes the ship under /GameData/Mods/smoke.frame, which this smoke removes when it ends. Pass 1 sends a UV sphere (1 x 0.6 x 0.4, long axis X, off the origin) through New Ship, length 10, like Djinni. Pass 2 adds a render mesh (a copy of the sphere) and a nub at the +Y end, rasterises, flips the nose, and requires the nub's cells to move from the aft rows to the forward rows. Pass 3 tags anchors, packages, and requires the GLB to hold neither the Source nor the Grid and the validator to accept it. """ import json import os import shutil import struct import sys import traceback from pathlib import Path import addon_utils import bmesh import bpy REPO = Path(__file__).resolve().parents[3] PACKAGES = os.environ.get("CULTLIB_PACKAGES") or sys.exit("Set CULTLIB_PACKAGES to CultLib's packages directory") SHIP_ID = "smoke.frame" MODS = REPO / "GameData" / "Mods" def new_object(collection, name, mesh, location=(0, 0, 0), parent=None): obj = bpy.data.objects.new(name, mesh) obj.location = location obj.parent = parent collection.objects.link(obj) return obj def box(name, half_x, half_y, half_z): mesh = bpy.data.meshes.new(name) corners = [(sx * half_x, sy * half_y, sz * half_z) for sx in (-1, 1) for sy in (-1, 1) for sz in (-1, 1)] mesh.from_pydata(corners, [], [(0, 1, 3, 2), (4, 6, 7, 5), (0, 4, 5, 1), (2, 3, 7, 6), (0, 2, 6, 4), (1, 5, 7, 3)]) return mesh def tetrahedron(name): mesh = bpy.data.meshes.new(name) mesh.from_pydata([(0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)], [], [(0, 2, 1), (0, 1, 3), (0, 3, 2), (1, 2, 3)]) return mesh def tag(obj, role, anchor_id): obj["aetheria.role"] = role obj["aetheria.id"] = anchor_id return obj def run(operator): try: result = operator() except RuntimeError as exc: result = {"CANCELLED"} print(f"OPERATOR error: {exc}") return result def require(condition, message): if not condition: raise SystemExit(message) def layout(path, aetheria_ships): shape, hardpoints, _ = aetheria_ships.ship_cc.read_layout(path, PACKAGES) width, height, cells = shape return width, height, {(i // height, i % height) for i, cell in enumerate(cells) if cell} def row_count(cells, y): return sum(1 for _, cy in cells if cy == y) def glb_node_names(path): data = Path(path).read_bytes() length, kind = struct.unpack_from(" forward, "The nub's cells are not on the aft rows before the flip") require(run(bpy.ops.aetheria.flip_nose) == {"FINISHED"}, "Flip Nose was refused") _, _, after = layout(path, aetheria_ships) require(row_count(after, height - 1) == aft and row_count(after, 0) == forward, "Flip Nose did not move the nub's cells from the aft rows to the forward rows") require({(width - 1 - x, height - 1 - y) for x, y in before} == after, "The flipped grid is not the turned grid") print("PASS 2 rasterise and flip nose ok") # Pass 3: Package leaves Source and Grid out of the GLB. tag(new_object(collection, "Map Icon", box("Map Icon", 0.5, 0.5, 0.01), (0, 0, -1), root), "map-icon", "map") tag(new_object(collection, "Hull Collider", tetrahedron("Hull Collider"), parent=root), "hull-collider", "collider") tag(new_object(collection, "Shield", None, parent=root), "shield", "shield") tag(new_object(collection, "Tractor", None, (0, 2, 0), root), "tractor", "tractor") bpy.context.view_layer.objects.active = render result = run(bpy.ops.aetheria.package_ship) report = scene.aetheria_package_report print(f"PACKAGE {sorted(result)}: {report}") require(result == {"FINISHED"}, "Package was refused") names = glb_node_names(Path(path).with_name("ship.glb")) print(f"GLB nodes: {sorted(n for n in names if n)}") require("Hull" in names and "Nub" in names, "The GLB lacks the render meshes") require("Source Sphere" not in names and "Grid" not in names, "The GLB holds the Source or the Grid") print("PASS 3 export ok") print("SMOKE_FRAME_OK") created_mods = not MODS.exists() existed = (MODS / SHIP_ID).exists() try: main() except SystemExit as stop: print(f"SMOKE_FRAME_FAILED: {stop}", flush=True) code = 1 except Exception: traceback.print_exc() print("SMOKE_FRAME_FAILED", flush=True) code = 1 else: code = 0 finally: if not existed: shutil.rmtree(MODS / SHIP_ID, ignore_errors=True) if created_mods and not existed: shutil.rmtree(MODS, ignore_errors=True) sys.stdout.flush() os._exit(code)