Build From Hull Source: zone meshes, mount anchors and a collider from the package's hull.scad; Package retires a hull.scad that operator art replaces

Build refuses a source that breaks its language or brief, and a collection holding render meshes it did not make;
it replaces only objects marked aetheria.hull_source and writes no layout row. Package deletes hull.scad, and says so,
once the collection holds art and none of Build's objects. OpenSCAD path is an add-on preference.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-18 22:00:15 +02:00
commit 24f057d18f
2 changed files with 473 additions and 2 deletions

View file

@ -22,7 +22,7 @@ import bpy
import numpy
from mathutils import Matrix, Vector
from . import hull_grid
from . import hull_grid, hull_source
from .ship_cc import (HARDPOINT_MEMBERS, HARDPOINT_TYPE_NAMES, ROTATION_NAMES, capture_grease_pencil, decode_hardpoint,
encode_hardpoint, layout_revision, read, read_layout, replace_layout, replace_lines,
replace_visual, valid_ship_id)
@ -609,6 +609,9 @@ class AETHERIA_OT_capture_ship_lines(bpy.types.Operator):
return _refuse(self, exc)
DEFAULT_OPENSCAD = r"C:\Tools\OpenSCAD-2026.09.23-x86-64\openscad.com"
class AETHERIA_AP_preferences(bpy.types.AddonPreferences):
bl_idname = __package__
@ -636,8 +639,14 @@ class AETHERIA_AP_preferences(bpy.types.AddonPreferences):
name="Bake max ray distance", default=0.0, min=0.0, unit="LENGTH",
description="The longest ray, in metres, Bake From Source casts from the extruded surface. 0 means no limit")
openscad: bpy.props.StringProperty(
name="OpenSCAD", subtype="FILE_PATH", default=DEFAULT_OPENSCAD,
description="The OpenSCAD executable (openscad.com on Windows, 2026.09 or later: Build From Hull Source uses its "
"Manifold backend)")
def draw(self, context):
self.layout.prop(self, "game_folder")
self.layout.prop(self, "openscad")
self.layout.prop(self, "max_texture")
self.layout.prop(self, "bake_size")
self.layout.prop(self, "bake_cage_extrusion")
@ -1515,6 +1524,146 @@ def _frame_ship(context, collection, root, path, saved_shape):
_recentre(root, hull_grid.cell_centre((float(origin[0]), float(origin[1])), centre[0], centre[1]))
HULL_SOURCE_MARK = "aetheria.hull_source" # set on every object Build From Hull Source makes; Build replaces only these
HULL_COLLIDER = ("hull-collider", "collider", "Hull Collider")
def _hull_source_file(collection):
"""The bound package's hull.scad, or None. A package holds one next to its ship.cc while its hull is agent-built."""
stored = collection.get("aetheria.ship_cc")
if not stored or collection.get("aetheria.pending"):
return None
source = Path(bpy.path.abspath(stored)).with_name(hull_source.HULL_FILE)
return source if source.is_file() else None
def _hull_source_objects(collection):
return [obj for obj in collection.all_objects if obj.get(HULL_SOURCE_MARK)]
def _hull_material(ship_id, zone, colour, emissive=False):
"""The zone's material: a flat colour from the language palette, made once per ship and zone, recoloured on a rebuild."""
name = f"{ship_id}.{zone}"
material = bpy.data.materials.get(name) or bpy.data.materials.new(name)
material.use_nodes = True
shader = _principled(material)
shader.inputs["Base Color"].default_value = (*colour, 1.0)
shader.inputs["Metallic"].default_value = 0.0
shader.inputs["Roughness"].default_value = 0.85
shader.inputs["Emission Color"].default_value = (*colour, 1.0)
shader.inputs["Emission Strength"].default_value = 1.0 if emissive else 0.0
return material
def _hull_mesh(name, mesh, material, offset=(0.0, 0.0, 0.0), yaw=0.0):
"""A flat-shaded mesh of the hull source's, expressed in the frame of an object that stands at offset, turned yaw."""
cos, sin = math.cos(-yaw), math.sin(-yaw)
vertices = [((x - offset[0]) * cos - (y - offset[1]) * sin, (x - offset[0]) * sin + (y - offset[1]) * cos,
z - offset[2]) for x, y, z in mesh.vertices]
data = bpy.data.meshes.new(name)
data.from_pydata(vertices, [], [tuple(tri) for tri in mesh.triangles])
data.update()
data.materials.append(material)
return data
def _build_hull_source(context, collection, runner=None):
"""Replaces the objects Build made before with the hull source's zone meshes, anchors and collider under Ship Root.
Refuses, before anything changes, when the source cannot be read, breaks a check of its faction's language, or the
collection holds render meshes Build did not make (operator art: Build never overwrites it). Writes no layout row."""
source = _hull_source_file(collection)
if source is None:
raise ValueError("The bound package holds no hull.scad")
root = _ship_root(collection)
if root is not None:
_refuse_loose_meshes(context, collection)
if any(not obj.get(HULL_SOURCE_MARK) for obj in _own_meshes(collection)):
raise ValueError("The collection holds meshes the hull source did not make; Build From Hull Source "
"replaces only its own objects")
addon = context.preferences.addons.get(__package__)
executable = addon.preferences.openscad if addon and addon.preferences else DEFAULT_OPENSCAD
hull = hull_source.build(runner or hull_source.openscad_runner(executable, source))
broken = hull.failed()
if broken:
raise ValueError("The hull source breaks its faction's language or its brief: " + "; ".join(c.name for c in broken))
ship_id = collection["aetheria.id"]
if root is None:
root = bpy.data.objects.new(SHIP_ROOT, None)
root["aetheria.ship_root"] = True
collection.objects.link(root)
for obj in _hull_source_objects(collection):
_discard_object(obj)
def mark(obj):
obj[HULL_SOURCE_MARK] = True
return obj
def link(obj):
collection.objects.link(obj)
_attach_to_root(obj, root)
return mark(obj)
for zone, mesh in hull.zones.items():
name = zone.replace(":", ".")
link(bpy.data.objects.new(name, _hull_mesh(name, mesh, _hull_material(ship_id, name, hull.colours[zone]))))
placed, anchors = {}, {a.id: a for a in hull.anchors}
for anchor in hull.anchors: # a muzzle follows its mount in the echo order the source gave
yaw = math.radians(anchor.yaw)
if anchor.role in hull_source.MESH_ROLES:
colour, emissive = (hull.glow, True) if anchor.role == "thruster-emitter" else (hull.radiator, False)
material = _hull_material(ship_id, f"{anchor.role}.{anchor.id}", colour, emissive)
obj = link(bpy.data.objects.new(
anchor.id, _hull_mesh(anchor.id, hull.anchor_meshes[anchor.id], material, anchor.position, yaw)))
obj.location, obj.rotation_euler = anchor.position, (0.0, 0.0, yaw)
obj["aetheria.role"], obj["aetheria.id"] = anchor.role, anchor.id
elif anchor.role == "weapon-mount":
obj = mark(_make_empty(collection, anchor.id, anchor.role, root, anchor.position, yaw))
else:
mount = anchors[anchor.parent]
turn = -math.radians(mount.yaw)
dx, dy = anchor.position[0] - mount.position[0], anchor.position[1] - mount.position[1]
local = (dx * math.cos(turn) - dy * math.sin(turn), dx * math.sin(turn) + dy * math.cos(turn),
anchor.position[2] - mount.position[2])
order = 1 + len(_muzzles(placed[anchor.parent]))
obj = mark(_make_empty(collection, anchor.id, anchor.role, placed[anchor.parent], local, order=order))
placed[anchor.id] = obj
role, anchor_id, name = HULL_COLLIDER
collider = link(bpy.data.objects.new(name, _hull_mesh(
name, hull.zones[hull.body_zone], _hull_material(ship_id, "collider", (0.5, 0.5, 0.5)))))
collider["aetheria.role"], collider["aetheria.id"] = role, anchor_id
return hull
def _retire_hull_source(collection):
"""Deletes the package's hull.scad when operator art is what was packaged: the collection holds render meshes and
none of Build's objects. A hull never built, or built and packaged as it stands, keeps its source. Returns whether the
file was deleted."""
source = _hull_source_file(collection)
root = _ship_root(collection)
if source is None or root is None or _hull_source_objects(collection) or not _own_meshes(collection):
return False
source.unlink()
return True
class AETHERIA_OT_build_hull_source(bpy.types.Operator):
bl_idname = "aetheria.build_hull_source"
bl_label = "Build From Hull Source"
bl_description = ("Replace the hull's generated objects with the meshes, mount anchors and collider that the "
"package's hull.scad describes, after checking it against its faction's form language. Never "
"touches the layout or objects you made")
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
try:
collection, _ = _layout_path(context)
hull = _build_hull_source(context, collection)
self.report({"INFO"}, f"Built {len(hull.zones)} zones and {len(hull.anchors)} anchors from hull.scad")
return {"FINISHED"}
except _EXPECTED as exc:
return _refuse(self, exc)
class AETHERIA_OT_package_ship(bpy.types.Operator):
bl_idname = "aetheria.package_ship"
bl_label = "Package Ship"
@ -1567,6 +1716,8 @@ class AETHERIA_OT_package_ship(bpy.types.Operator):
self.report({"ERROR"}, scene.aetheria_package_report)
return {"CANCELLED"}
scene.aetheria_package_report = f"Packaged {len(anchors)} anchors; the validator accepted the ship"
if _retire_hull_source(collection):
scene.aetheria_package_report += "; deleted hull.scad: this package ships your art"
self.report({"INFO"}, scene.aetheria_package_report)
return {"FINISHED"}
@ -1610,6 +1761,11 @@ class AETHERIA_PT_ship(bpy.types.Panel):
row.operator("aetheria.flip_nose", icon="LOOP_BACK")
row.operator("aetheria.rasterise_hull", icon="MESH_GRID")
layout.operator("aetheria.bake_from_source", icon="RENDER_RESULT")
try:
if _hull_source_file(_ship_collection(context)) is not None:
layout.operator("aetheria.build_hull_source", icon="MESH_CUBE")
except ValueError:
pass
if not state.ship_id:
self._draw_package(context, layout)
return
@ -1685,7 +1841,8 @@ classes = (AETHERIA_PG_cell, AETHERIA_PG_hardpoint, AETHERIA_PG_layout,
AETHERIA_OT_save_layout, AETHERIA_OT_bind_ship_collection,
AETHERIA_OT_capture_ship_lines, AETHERIA_OT_new_ship, AETHERIA_OT_flip_nose,
AETHERIA_OT_bake_from_source,
AETHERIA_OT_rasterise_hull, AETHERIA_OT_package_ship, AETHERIA_AP_preferences, AETHERIA_PT_ship)
AETHERIA_OT_rasterise_hull, AETHERIA_OT_build_hull_source, AETHERIA_OT_package_ship,
AETHERIA_AP_preferences, AETHERIA_PT_ship)
def register():

View file

@ -0,0 +1,314 @@
"""Headless Blender smoke for Build From Hull Source, with the real OpenSCAD and the real faction language files.
blender --background --factory-startup --python-use-system-env --python tools/blender/tests/smoke_hull_source.py
Environment: CULTLIB_PACKAGES and SMOKE_GAME_FOLDER as smoke_package.py's header says (the published AetherDb under
ModTools, GameData/Aetheria.cc), msgpack importable, and OpenSCAD 2026.09 or later at SMOKE_OPENSCAD (default: the add-on
preference's default). SMOKE_PID_LOG, when set, receives one line per OpenSCAD process. Each ship is created under
<game folder>/GameData/Mods/smoke.hull.*, which this smoke removes when it ends.
For each of the two fixture hulls (tests/fixtures/hulls: the Zhestokost ammunition tender and the Pirate fighter on a
Rossum & Douglas wedge) the smoke makes a ship from a stand-in box (New Ship), authors its gameplay layout separately
(rows named for the hull source's anchors, at cells that have nothing to do with where the model puts its gear), copies
the hull.scad into the package and runs the panel's operators:
Build: zone meshes with one palette material each, the mount anchors, the emitter and radiator meshes and a collider,
all marked aetheria.hull_source under Ship Root, and no layout row changed by Build itself.
A second Build replaces only its own objects: an object the author made, a mesh and an empty, is still there.
Build refuses, naming a rule and no input, a hull source that breaks its language's or brief's rule, and changes nothing.
Build refuses a collection that holds a render mesh it did not make, and changes nothing.
Package accepts the built ship (the C# validator), writes ship.glb with a node per anchor, and leaves hull.scad.
Once the author has taken the generated objects over (the mark is gone) Package deletes hull.scad and says so.
A hull that was never built keeps its hull.scad through the same deletion rule.
"""
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")
GAME = Path(os.environ.get("SMOKE_GAME_FOLDER") or sys.exit("Set SMOKE_GAME_FOLDER to a folder holding GameData/Aetheria.cc and ModTools/AetherDb"))
OPENSCAD = os.environ.get("SMOKE_OPENSCAD")
PID_LOG = os.environ.get("SMOKE_PID_LOG")
MODS = GAME / "GameData" / "Mods"
FIXTURES = REPO / "tools" / "blender" / "tests" / "fixtures" / "hulls"
THRUSTER, RADIATOR, BALLISTIC = "3", "6", "10"
# fixture folder, ship id, stand-in box (x, y) metres and its length in cells, then the layout rows: (mount id, kind, cell)
HULLS = (
("zh-ammo-tender", "smoke.hull.tender", (10.0, 23.4), 12,
(("Gun.D", BALLISTIC, (2, 3)), ("Th.L", THRUSTER, (0, 0)), ("Th.R", THRUSTER, (1, 0)),
("Ra.L", RADIATOR, (2, 0)), ("Ra.R", RADIATOR, (3, 0))),
{"primary": (0.42, 0.43, 0.45), "secondary": (0.20, 0.20, 0.22), "accent": (0.55, 0.22, 0.14), "recess": (0.08, 0.08, 0.09)}),
("pi-fighter", "smoke.hull.fighter", (8.0, 15.0), 8,
(("Gun.P", BALLISTIC, (3, 3)), ("Th.Main", THRUSTER, (0, 0)), ("Th.L", THRUSTER, (1, 0))),
{"rnd.primary": (0.72, 0.74, 0.76), "primer": (0.48, 0.27, 0.22), "weld": (0.70, 0.68, 0.62),
"accent": (0.10, 0.62, 0.60), "rnd.accent": (0.90, 0.89, 0.84)}),
)
def require(condition, message):
if not condition:
raise SystemExit(message)
def select(obj):
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
def run(operator):
try:
return operator(), ""
except RuntimeError as exc:
return {"CANCELLED"}, str(exc)
def approx(a, b, tolerance=1e-3):
return all(abs(x - y) <= tolerance for x, y in zip(a, b))
def generated(collection):
return {obj.name: obj for obj in collection.all_objects if obj.get("aetheria.hull_source")}
def layout_rows(scene):
return [(hp.mount_id, hp.kind, hp.armor, hp.firing_arc, hp.footprint) for hp in scene.aetheria_layout.hardpoints]
def glb_nodes(path):
data = Path(path).read_bytes()
length, kind = struct.unpack_from("<II", data, 12)
require(kind == 0x4E4F534A, "The GLB's first chunk is not JSON")
return json.loads(data[20:20 + length])["nodes"]
def make_ship(scene, fixture, ship_id, extent, length, rows):
"""A ship from a stand-in box, its layout authored by hand, hull.scad copied into its package; returns the collection."""
collection = bpy.data.collections.new(f"Smoke {ship_id}")
scene.collection.children.link(collection)
mesh = bpy.data.meshes.new(f"{ship_id} stand-in")
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0)
bm.to_mesh(mesh)
bm.free()
box = bpy.data.objects.new(f"{ship_id} stand-in", mesh)
box.scale = (extent[0], extent[1], 2.0)
collection.objects.link(box)
select(box)
scene.aetheria_new_ship_id, scene.aetheria_new_ship_name = ship_id, ship_id
scene.aetheria_new_ship_like, scene.aetheria_new_ship_length = "Djinni", length
result, message = run(bpy.ops.aetheria.new_ship)
require(result == {"FINISHED"}, f"New Ship was refused: {message}")
state = scene.aetheria_layout
for mount_id, kind, (x, y) in rows:
bpy.ops.aetheria.add_ship_hardpoint()
hp = state.hardpoints[len(state.hardpoints) - 1]
hp.mount_id, hp.kind, hp.x, hp.y, hp.footprint = mount_id, kind, x, y, "#"
result, message = run(bpy.ops.aetheria.save_ship_layout)
require(result == {"FINISHED"}, f"Save was refused: {message}")
package = MODS / ship_id
shutil.copy(FIXTURES / fixture / "hull.scad", package / "hull.scad")
select(box)
return collection, box, package
def check_built(collection, root, palette, anchors_by_role):
objects = generated(collection)
for zone, colour in palette.items():
obj = objects.get(zone)
require(obj is not None and obj.type == "MESH" and obj.parent == root and len(obj.data.polygons) > 0,
f"Zone {zone} is not a mesh under Ship Root")
material = obj.data.materials[0]
base = next(n for n in material.node_tree.nodes if n.type == "BSDF_PRINCIPLED").inputs["Base Color"].default_value
require(approx(tuple(base)[:3], colour), f"Zone {zone} is not its palette colour: {tuple(base)}")
require(not any(p.use_smooth for p in obj.data.polygons), f"Zone {zone} is not flat shaded")
for role, ids in anchors_by_role.items():
for anchor_id in ids:
obj = objects.get(anchor_id)
require(obj is not None and obj.get("aetheria.role") == role and obj.get("aetheria.id") == anchor_id and obj.parent is not None,
f"Anchor {anchor_id} ({role}) was not built")
colliders = [o for o in objects.values() if o.get("aetheria.role") == "hull-collider"]
require(len(colliders) == 1 and colliders[0].type == "MESH", "Build did not make exactly one collider mesh")
return objects
def one_hull(scene, number, fixture, ship_id, extent, length, rows, palette):
collection, box, package = make_ship(scene, fixture, ship_id, extent, length, rows)
state = scene.aetheria_layout
root = bpy.data.objects[next(o.name for o in collection.all_objects if o.get("aetheria.ship_root"))]
rows_before = layout_rows(scene)
source = package / "hull.scad"
require(source.is_file(), "The fixture hull.scad was not copied")
require("Build From Hull Source" == bpy.ops.aetheria.build_hull_source.get_rna_type().name, "Build is not registered")
# Build, and a rule that fails before anything changes.
result, message = run(bpy.ops.aetheria.build_hull_source)
require(result == {"FINISHED"}, f"Build was refused: {message}")
roles = {}
for obj in generated(collection).values():
role = obj.get("aetheria.role")
if role in ("weapon-mount", "thruster-emitter", "radiator-mesh", "weapon-muzzle"):
roles.setdefault(role, []).append(obj.name)
require(roles.get("weapon-mount") and roles.get("weapon-muzzle") and roles.get("thruster-emitter"), f"Anchors missing: {roles}")
first = check_built(collection, root, palette, roles)
for muzzle in roles["weapon-muzzle"]:
mount = first[muzzle].parent
require(mount.get("aetheria.role") == "weapon-mount" and first[muzzle].get("aetheria.order") == 1, "A muzzle is not ordered under its mount")
require(first[muzzle].matrix_world.translation.y < mount.matrix_world.translation.y, "A muzzle is not nose-ward of its mount")
require(layout_rows(scene) == rows_before, "Build changed the layout buffer")
print(f"PASS {number}.1 {fixture} builds: {len(first)} objects, {sum(len(v) for v in roles.values())} anchors")
# A second Build replaces only its own objects; the author's own empty and mesh (outside render meshes' reach: a mesh
# is tested separately) stay.
keep = bpy.data.objects.new("author note", None)
collection.objects.link(keep)
keep.parent = root
for obj in first.values():
obj["smoke.stale"] = True
select(box)
result, message = run(bpy.ops.aetheria.build_hull_source)
require(result == {"FINISHED"}, f"The second Build was refused: {message}")
second = generated(collection)
require(sorted(second) == sorted(first), "The second Build changed the set of generated objects")
require(not any(obj.get("smoke.stale") for obj in second.values()), "The second Build kept an object of the first")
require(bpy.data.objects.get("author note") is keep and keep.parent == root, "Build removed an object the author made")
require(len([o for o in collection.all_objects if o.name.startswith("Hull Collider")]) == 1, "A second Build left a second collider")
print(f"PASS {number}.2 a second Build replaces only its own objects")
# Operator art in the collection: Build refuses and changes nothing.
art_mesh = bpy.data.meshes.new("author hull")
art_mesh.from_pydata([(0, 0, 0), (1, 0, 0), (0, 1, 0)], [], [(0, 1, 2)])
art = bpy.data.objects.new("author hull", art_mesh)
collection.objects.link(art)
art.parent = root
names = sorted(o.name for o in collection.all_objects)
select(box)
result, message = run(bpy.ops.aetheria.build_hull_source)
require(result == {"CANCELLED"} and "did not make" in message, f"Build overwrote or ignored operator art: {message!r}")
require(sorted(o.name for o in collection.all_objects) == names, "A refused Build changed objects")
for echoed in (ship_id, str(GAME), "author hull"):
require(echoed not in message, f"The refusal echoes an input ({echoed})")
bpy.data.objects.remove(art)
print(f"PASS {number}.3 Build refuses operator art and changes nothing")
# A hull source that breaks the brief: the refusal names the rule and nothing changes.
original = source.read_text(encoding="utf-8")
source.write_text(original.replace("HULL_LENGTH = [", "HULL_LENGTH = [200, 300]; UNUSED = ["), encoding="utf-8")
names = sorted(o.name for o in collection.all_objects)
select(box)
result, message = run(bpy.ops.aetheria.build_hull_source)
require(result == {"CANCELLED"} and "the length lies inside the brief's range" in message, f"A broken brief was built: {message!r}")
require(sorted(o.name for o in collection.all_objects) == names, "A refused Build changed objects")
for echoed in (ship_id, str(GAME), fixture):
require(echoed not in message, f"The refusal echoes an input ({echoed})")
source.write_text(original, encoding="utf-8")
print(f"PASS {number}.4 Build refuses a hull that breaks its brief")
# Package: the validator accepts the built ship and the GLB holds a node per anchor.
select(box)
result, message = run(bpy.ops.aetheria.package_ship)
report = scene.aetheria_package_report
require(result == {"FINISHED"} and "validator accepted" in report, f"Package refused the built ship: {report!r} {message!r}")
require(source.is_file(), "Package deleted a hull source whose hull is still built from it")
nodes = {n.get("name"): n for n in glb_nodes(package / "ship.glb")}
for role, ids in roles.items():
for anchor_id in ids:
require(anchor_id in nodes, f"The GLB has no node for {anchor_id}")
for zone in palette:
require(zone in nodes, f"The GLB has no mesh node for zone {zone}")
moved = [r for r in (hp for hp in state.hardpoints) if r.mount_id in roles["weapon-mount"]]
print(f"INFO {number}.5 weapon rows after Package (fork package-derives-schematic-from-model): "
f"{[(hp.mount_id, (hp.x, hp.y)) for hp in moved]} (authored at {[r[2] for r in rows if r[1] == BALLISTIC]})")
print(f"PASS {number}.5 Package accepts the built ship and keeps hull.scad")
# The author takes the generated objects over: Package deletes hull.scad and says so.
for obj in generated(collection).values():
del obj["aetheria.hull_source"]
select(box)
result, message = run(bpy.ops.aetheria.package_ship)
report = scene.aetheria_package_report
require(result == {"FINISHED"} and "deleted hull.scad" in report, f"Package did not retire the hull source: {report!r} {message!r}")
require(not source.exists(), "hull.scad is still there after the author's art was packaged")
require(all(echoed not in report for echoed in (ship_id, str(GAME))), "The report echoes an input")
print(f"PASS {number}.6 operator art retires hull.scad, with a report")
return collection
def clear(collection):
"""Removes a finished ship's objects: Blender names objects once per file, and anchors are found by name."""
for obj in list(collection.all_objects if collection else ()):
bpy.data.objects.remove(obj)
def never_built(scene):
"""A hull.scad whose hull was never built has no art in the collection: the deletion rule keeps it."""
ship_id = "smoke.hull.unbuilt"
collection, box, package = make_ship(scene, "pi-fighter", ship_id, (8.0, 15.0), 8, ())
api = sys.modules["aetheria_ships"]
require(api._retire_hull_source(collection) is False and (package / "hull.scad").is_file(),
"A hull that was never built lost its hull.scad")
print("PASS 3 a hull that was never built keeps its hull.scad")
def main():
require(bpy.app.version[:2] == (5, 2), f"This smoke is for Blender 5.2; this is {bpy.app.version_string}")
bpy.data.objects.remove(bpy.data.objects["Cube"], do_unlink=True)
sys.path.insert(0, str(REPO / "tools" / "blender"))
addon_utils.enable("aetheria_ships", default_set=True, handle_error=None)
import aetheria_ships
aetheria_ships._brokkr_cultlib = lambda context: PACKAGES
preferences = bpy.context.preferences.addons["aetheria_ships"].preferences
preferences.game_folder = str(GAME)
if OPENSCAD:
preferences.openscad = OPENSCAD
real = aetheria_ships.hull_source.openscad_runner
def logged(executable, source, **kwargs):
def on_start(pid):
if PID_LOG:
with open(PID_LOG, "a") as log:
log.write(f"{pid}\n")
return real(executable, source, on_start=on_start, **kwargs)
aetheria_ships.hull_source.openscad_runner = logged
for _, ship_id, *_ in HULLS:
require(not (MODS / ship_id).exists(), f"{MODS / ship_id} exists; remove it first")
scene = bpy.context.scene
previous = None
for number, (fixture, ship_id, extent, length, rows, palette) in enumerate(HULLS, start=1):
clear(previous)
previous = one_hull(scene, number, fixture, ship_id, extent, length, rows, palette)
clear(previous)
never_built(scene)
created = not MODS.exists()
try:
main()
except SystemExit as stop:
print(f"SMOKE_HULL_SOURCE_FAILED: {stop}", flush=True)
code = 1
except Exception:
traceback.print_exc()
print("SMOKE_HULL_SOURCE_FAILED", flush=True)
code = 1
else:
print("SMOKE_HULL_SOURCE_OK", flush=True)
code = 0
finally:
for _, ship_id, *_ in HULLS + ((None, "smoke.hull.unbuilt"),):
shutil.rmtree(MODS / ship_id, ignore_errors=True)
if created:
shutil.rmtree(MODS, ignore_errors=True)
sys.stdout.flush()
os._exit(code)