2026-09-26 18:14:36 +02:00
|
|
|
"""Aetheria ship authoring controls in Brokkr's Blender sidebar."""
|
|
|
|
|
|
|
|
|
|
bl_info = {
|
|
|
|
|
"name": "Aetheria Ships for Brokkr",
|
|
|
|
|
"author": "GameCult",
|
|
|
|
|
"version": (0, 1, 0),
|
|
|
|
|
"blender": (4, 3, 0),
|
|
|
|
|
"location": "View3D > Sidebar > Brokkr > Aetheria Ship",
|
2026-10-03 17:13:42 +02:00
|
|
|
"description": "Author a typed Aetheria ship package: layout, lines, anchors and its GLB",
|
2026-09-26 18:14:36 +02:00
|
|
|
"category": "Object",
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-08 19:35:47 +02:00
|
|
|
import math
|
2026-10-10 09:49:40 +02:00
|
|
|
import shutil
|
2026-10-03 17:13:42 +02:00
|
|
|
import subprocess
|
2026-10-10 06:53:03 +02:00
|
|
|
import sys
|
2026-10-10 09:49:40 +02:00
|
|
|
import traceback
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
from functools import partial
|
2026-10-03 17:13:42 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
2026-09-26 18:14:36 +02:00
|
|
|
import bpy
|
2026-10-08 19:35:47 +02:00
|
|
|
import numpy
|
2026-10-10 21:02:22 +02:00
|
|
|
from mathutils import Matrix, Vector
|
2026-09-26 18:14:36 +02:00
|
|
|
|
2026-10-18 22:00:15 +02:00
|
|
|
from . import hull_grid, hull_source
|
2026-10-22 16:55:50 +02:00
|
|
|
from .ship_cc import (HARDPOINT_MEMBERS, HARDPOINT_TYPE_NAMES, ROTATION_NAMES, capture_grease_pencil, clear_lines, decode_hardpoint,
|
2026-10-22 01:03:27 +02:00
|
|
|
encode_hardpoint, layout_revision, read, read_hull_type, read_layout, replace_layout, replace_lines,
|
2026-10-19 00:20:00 +02:00
|
|
|
product_makers, replace_visual, valid_ship_id)
|
2026-10-03 17:13:42 +02:00
|
|
|
|
|
|
|
|
MODEL_ASSET = "ship.glb"
|
2026-10-08 19:35:47 +02:00
|
|
|
SOURCE = "Source" # child collection: the Tripo mesh, input to Rasterise, never exported
|
2026-10-10 21:02:22 +02:00
|
|
|
GENERATED = "Generated" # child collection: derived objects, the Grid (never exported) and the anchors Package makes (exported)
|
2026-10-08 19:35:47 +02:00
|
|
|
SHIP_ROOT = "Ship Root"
|
2026-10-10 06:53:03 +02:00
|
|
|
AETHERDB_TIMEOUT = 120 # seconds
|
2026-09-26 19:23:01 +02:00
|
|
|
|
|
|
|
|
|
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
|
|
|
HARDPOINT_TYPES = tuple((str(i), name, name) for i, name in enumerate(HARDPOINT_TYPE_NAMES))
|
|
|
|
|
ROTATIONS = tuple((str(i), name, name) for i, name in enumerate(ROTATION_NAMES))
|
2026-09-26 19:23:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_PG_cell(bpy.types.PropertyGroup):
|
|
|
|
|
occupied: bpy.props.BoolProperty(name="Occupied")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_PG_hardpoint(bpy.types.PropertyGroup):
|
|
|
|
|
mount_id: bpy.props.StringProperty(name="Mount ID")
|
|
|
|
|
kind: bpy.props.EnumProperty(name="Type", items=HARDPOINT_TYPES)
|
|
|
|
|
x: bpy.props.IntProperty(name="X", min=0, max=31)
|
|
|
|
|
y: bpy.props.IntProperty(name="Y", min=0, max=31)
|
|
|
|
|
footprint: bpy.props.StringProperty(
|
|
|
|
|
name="Footprint", default="#", description="Top-to-bottom rows of # and ., separated by /"
|
|
|
|
|
)
|
|
|
|
|
rotation: bpy.props.EnumProperty(name="Rotation", items=ROTATIONS)
|
|
|
|
|
armor: bpy.props.FloatProperty(name="Armor", min=0)
|
|
|
|
|
firing_arc: bpy.props.FloatProperty(name="Firing Arc", min=0, max=360)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_PG_layout(bpy.types.PropertyGroup):
|
|
|
|
|
ship_id: bpy.props.StringProperty()
|
|
|
|
|
ship_cc: bpy.props.StringProperty()
|
|
|
|
|
revision: bpy.props.StringProperty()
|
|
|
|
|
width: bpy.props.IntProperty(default=1)
|
|
|
|
|
height: bpy.props.IntProperty(default=1)
|
|
|
|
|
new_width: bpy.props.IntProperty(name="Width", default=1, min=1, max=32)
|
|
|
|
|
new_height: bpy.props.IntProperty(name="Height", default=1, min=1, max=32)
|
|
|
|
|
cells: bpy.props.CollectionProperty(type=AETHERIA_PG_cell)
|
|
|
|
|
hardpoints: bpy.props.CollectionProperty(type=AETHERIA_PG_hardpoint)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _footprint(raw):
|
|
|
|
|
width, height, cells = raw[0]
|
|
|
|
|
return "/".join("".join("#" if cells[x * height + y] else "." for x in range(width))
|
|
|
|
|
for y in range(height - 1, -1, -1))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_footprint(text):
|
|
|
|
|
rows = text.split("/")
|
|
|
|
|
width = len(rows[0])
|
|
|
|
|
height = len(rows)
|
|
|
|
|
if not (1 <= width <= 32 and 1 <= height <= 32 and
|
|
|
|
|
all(len(row) == width and set(row) <= {"#", "."} for row in rows)):
|
|
|
|
|
raise ValueError("Footprint must use equal-width #/. rows separated by /")
|
|
|
|
|
return [[width, height, [rows[height - 1 - y][x] == "#"
|
|
|
|
|
for x in range(width) for y in range(height)]]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _layout_path(context):
|
|
|
|
|
collection = _ship_collection(context)
|
|
|
|
|
if not collection.get("aetheria.ship_cc"):
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("The ship collection has no bound .cc path")
|
2026-09-26 19:23:01 +02:00
|
|
|
return collection, bpy.path.abspath(collection["aetheria.ship_cc"])
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _set_cells(state, width, height, cells):
|
|
|
|
|
state.width = state.new_width = width
|
|
|
|
|
state.height = state.new_height = height
|
|
|
|
|
state.cells.clear()
|
|
|
|
|
for cell in cells:
|
|
|
|
|
state.cells.add().occupied = bool(cell)
|
|
|
|
|
|
|
|
|
|
|
2026-10-08 19:35:47 +02:00
|
|
|
def _load_layout(context, collection, path):
|
2026-10-10 09:49:40 +02:00
|
|
|
"""Fills the scene's layout buffer from the bound .cc and redraws the Grid; returns (width, height, hardpoints)."""
|
2026-10-08 19:35:47 +02:00
|
|
|
shape, hardpoints, revision = read_layout(path, _brokkr_cultlib(context))
|
|
|
|
|
width, height, cells = shape
|
|
|
|
|
state = context.scene.aetheria_layout
|
|
|
|
|
state.ship_id = collection["aetheria.id"]
|
|
|
|
|
state.ship_cc = path
|
|
|
|
|
state.revision = revision
|
2026-10-10 09:49:40 +02:00
|
|
|
_set_cells(state, width, height, cells)
|
2026-10-08 19:35:47 +02:00
|
|
|
state.hardpoints.clear()
|
|
|
|
|
for raw in hardpoints:
|
|
|
|
|
fields = decode_hardpoint(raw)
|
|
|
|
|
hp = state.hardpoints.add()
|
|
|
|
|
hp.kind = str(fields["Type"])
|
|
|
|
|
hp.x, hp.y = fields["Position"]
|
|
|
|
|
hp.footprint = _footprint(fields["Shape"])
|
|
|
|
|
hp.mount_id = fields["Transform"] or ""
|
|
|
|
|
hp.rotation = str(fields["Rotation"])
|
|
|
|
|
hp.armor = fields["Armor"]
|
|
|
|
|
hp.firing_arc = fields["FiringArc"]
|
|
|
|
|
_redraw_grid(collection, state)
|
|
|
|
|
return width, height, len(hardpoints)
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
_EXPECTED = (OSError, ValueError, RuntimeError, ImportError, KeyError)
|
|
|
|
|
|
|
|
|
|
|
2026-10-13 01:47:23 +02:00
|
|
|
class Refusal(ValueError):
|
|
|
|
|
"""A refusal Bake From Source raises itself: its message is fixed text that names no input. Blender's ValueError is not one."""
|
2026-10-13 01:10:34 +02:00
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _failure_text(exc):
|
|
|
|
|
"""What an operator reports for exc. This module's own ValueError and RuntimeError messages are fixed text that
|
|
|
|
|
names no input; any other error is reported by its type, and its text goes to the system console."""
|
2026-10-13 01:47:23 +02:00
|
|
|
if type(exc) in (ValueError, RuntimeError, Refusal):
|
2026-10-10 09:49:40 +02:00
|
|
|
return str(exc)
|
|
|
|
|
traceback.print_exception(exc)
|
|
|
|
|
return f"Stopped by {type(exc).__name__}; see the system console"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _refuse(operator, exc):
|
|
|
|
|
operator.report({"ERROR"}, _failure_text(exc))
|
|
|
|
|
return {"CANCELLED"}
|
|
|
|
|
|
|
|
|
|
|
2026-09-26 19:23:01 +02:00
|
|
|
class AETHERIA_OT_load_layout(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.load_ship_layout"
|
|
|
|
|
bl_label = "Load Ship Layout"
|
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
|
|
|
|
collection, path = _layout_path(context)
|
2026-10-10 09:49:40 +02:00
|
|
|
if collection.get("aetheria.pending"):
|
|
|
|
|
raise ValueError("Not saved yet; Save Layout creates it")
|
2026-10-08 19:35:47 +02:00
|
|
|
width, height, count = _load_layout(context, collection, path)
|
|
|
|
|
self.report({"INFO"}, f"Loaded {width}x{height} layout and {count} hardpoints")
|
2026-09-26 19:23:01 +02:00
|
|
|
return {"FINISHED"}
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
2026-09-26 19:23:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_resize_layout(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.resize_ship_layout"
|
|
|
|
|
bl_label = "Resize Grid"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
state = context.scene.aetheria_layout
|
|
|
|
|
old = [cell.occupied for cell in state.cells]
|
|
|
|
|
width, height = state.width, state.height
|
|
|
|
|
expanded = [old[x * height + y] if x < width and y < height else False
|
|
|
|
|
for x in range(state.new_width) for y in range(state.new_height)]
|
|
|
|
|
state.cells.clear()
|
|
|
|
|
for cell in expanded:
|
|
|
|
|
state.cells.add().occupied = cell
|
|
|
|
|
state.width, state.height = state.new_width, state.new_height
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_add_hardpoint(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.add_ship_hardpoint"
|
|
|
|
|
bl_label = "Add Hardpoint"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2026-10-12 03:45:12 +02:00
|
|
|
_add_row(context.scene.aetheria_layout)
|
2026-09-26 19:23:01 +02:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_remove_hardpoint(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.remove_ship_hardpoint"
|
|
|
|
|
bl_label = "Remove Hardpoint"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
index: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
state = context.scene.aetheria_layout
|
|
|
|
|
if 0 <= self.index < len(state.hardpoints):
|
|
|
|
|
state.hardpoints.remove(self.index)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2026-10-12 03:45:12 +02:00
|
|
|
|
|
|
|
|
MOUNT_ROLE = "weapon-mount"
|
|
|
|
|
MUZZLE_ROLE = "weapon-muzzle"
|
|
|
|
|
MUZZLE_OFFSET = (0.0, -0.5, 0.0) # in the mount's frame: half a metre along its facing
|
|
|
|
|
WEAPON_TYPES = tuple(item for item in HARDPOINT_TYPES if item[1] in ("Energy", "Ballistic", "Launcher"))
|
2026-10-19 00:16:35 +02:00
|
|
|
MODEL_TOLERANCE = 1e-3 # metres: a mount whose point is this close to Ship Root's X = 0 has no mirror image
|
2026-10-12 03:45:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _add_row(state, **fields):
|
|
|
|
|
"""The one row creation: a new layout row, with HardpointData's defaults for anything not named."""
|
|
|
|
|
hp = state.hardpoints.add()
|
|
|
|
|
for name, value in fields.items():
|
|
|
|
|
setattr(hp, name, value)
|
|
|
|
|
return hp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _mount_objects(collection):
|
|
|
|
|
"""The weapon-mount objects by their aetheria.id."""
|
|
|
|
|
return {obj["aetheria.id"]: obj for obj in collection.all_objects
|
|
|
|
|
if obj.get("aetheria.role") == MOUNT_ROLE and isinstance(obj.get("aetheria.id"), str)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _muzzles(mount):
|
|
|
|
|
return sorted((child for child in mount.children if child.get("aetheria.role") == MUZZLE_ROLE),
|
|
|
|
|
key=lambda child: (int(child.get("aetheria.order", 0)), child.name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _mount_frame(context):
|
2026-10-19 00:16:35 +02:00
|
|
|
"""(collection, layout buffer, Ship Root) for a mount helper: the buffer must be this ship's."""
|
2026-10-12 03:45:12 +02:00
|
|
|
collection, path = _layout_path(context)
|
|
|
|
|
state = context.scene.aetheria_layout
|
|
|
|
|
if state.ship_id != collection["aetheria.id"] or state.ship_cc != path:
|
|
|
|
|
raise ValueError("Load this collection's layout first")
|
|
|
|
|
root = _ship_root(collection)
|
2026-10-19 00:16:35 +02:00
|
|
|
if root is None:
|
|
|
|
|
raise ValueError("A mount needs the ship's Ship Root: Rasterise or Build From Hull Source first")
|
|
|
|
|
return collection, state, root
|
2026-10-12 03:45:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _root_local(root, obj):
|
|
|
|
|
"""obj's origin in Ship Root's frame."""
|
|
|
|
|
return root.matrix_world.inverted() @ obj.matrix_world.translation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _selected_mount(context, collection):
|
|
|
|
|
obj = context.active_object
|
|
|
|
|
if obj is None or obj.get("aetheria.role") != MOUNT_ROLE or obj.name not in collection.all_objects:
|
|
|
|
|
raise ValueError("Select a weapon mount")
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _mount_row(state, mount_id):
|
|
|
|
|
row = next((hp for hp in state.hardpoints if hp.mount_id == mount_id), None)
|
|
|
|
|
if row is None:
|
|
|
|
|
raise ValueError("The weapon mount has no layout row")
|
|
|
|
|
return row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _new_mount_id(collection, state):
|
|
|
|
|
taken = {hp.mount_id for hp in state.hardpoints} | set(_mount_objects(collection))
|
|
|
|
|
n = 1
|
|
|
|
|
while f"weapon.{n}" in taken:
|
|
|
|
|
n += 1
|
|
|
|
|
return f"weapon.{n}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _make_empty(collection, anchor_id, role, parent, local, yaw=0.0, order=None):
|
|
|
|
|
empty = bpy.data.objects.new(anchor_id, None)
|
|
|
|
|
empty["aetheria.role"] = role
|
|
|
|
|
empty["aetheria.id"] = anchor_id
|
|
|
|
|
if order is not None:
|
|
|
|
|
empty["aetheria.order"] = order
|
|
|
|
|
collection.objects.link(empty)
|
|
|
|
|
_attach_to_root(empty, parent)
|
|
|
|
|
empty.location = tuple(local)
|
|
|
|
|
empty.rotation_euler = (0.0, 0.0, yaw)
|
|
|
|
|
return empty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _make_muzzle(collection, mount, k, local, order):
|
|
|
|
|
return _make_empty(collection, f"{mount['aetheria.id']}.muzzle.{k}", MUZZLE_ROLE, mount, local, order=order)
|
|
|
|
|
|
|
|
|
|
|
2026-10-19 00:16:35 +02:00
|
|
|
def _add_mount(collection, state, root, kind, rotation, local, footprint="#", position=None):
|
|
|
|
|
"""A weapon-mount object under Ship Root and its row, as a matching pair; returns the mount. The row's Position is
|
|
|
|
|
the given schematic position, else HardpointData's default: the model point is never mapped to a cell."""
|
2026-10-12 03:45:12 +02:00
|
|
|
mount_id = _new_mount_id(collection, state)
|
|
|
|
|
mount = _make_empty(collection, mount_id, MOUNT_ROLE, root, local, hull_grid.facing_yaw(rotation))
|
2026-10-19 00:16:35 +02:00
|
|
|
fields = {} if position is None else {"x": position[0], "y": position[1]}
|
|
|
|
|
_add_row(state, kind=kind, mount_id=mount_id, rotation=str(rotation), footprint=footprint, **fields)
|
2026-10-12 03:45:12 +02:00
|
|
|
return mount
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_add_weapon(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.add_ship_weapon"
|
|
|
|
|
bl_label = "Add Weapon"
|
2026-10-19 00:16:35 +02:00
|
|
|
bl_description = ("Add a weapon mount and its first muzzle at the 3D cursor, with a layout row at the default Position, "
|
|
|
|
|
"to be authored in the layout panel")
|
2026-10-12 03:45:12 +02:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
kind: bpy.props.EnumProperty(name="Type", items=WEAPON_TYPES)
|
|
|
|
|
rotation: bpy.props.EnumProperty(name="Rotation", items=ROTATIONS)
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-19 00:16:35 +02:00
|
|
|
collection, state, root = _mount_frame(context)
|
2026-10-12 03:45:12 +02:00
|
|
|
local = root.matrix_world.inverted() @ context.scene.cursor.location
|
2026-10-19 00:16:35 +02:00
|
|
|
mount = _add_mount(collection, state, root, self.kind, int(self.rotation), local)
|
2026-10-12 03:45:12 +02:00
|
|
|
_make_muzzle(collection, mount, 1, MUZZLE_OFFSET, 1)
|
|
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_add_muzzle(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.add_ship_muzzle"
|
|
|
|
|
bl_label = "Add Muzzle"
|
|
|
|
|
bl_description = "Add a muzzle under the selected weapon mount"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-19 00:16:35 +02:00
|
|
|
collection, _, _ = _mount_frame(context)
|
2026-10-12 03:45:12 +02:00
|
|
|
mount = _selected_mount(context, collection)
|
|
|
|
|
existing = _muzzles(mount)
|
|
|
|
|
names = {child.name for child in existing}
|
|
|
|
|
k = len(existing) + 1
|
|
|
|
|
while f"{mount['aetheria.id']}.muzzle.{k}" in names:
|
|
|
|
|
k += 1
|
|
|
|
|
order = max((int(child.get("aetheria.order", 0)) for child in existing), default=0) + 1
|
|
|
|
|
_make_muzzle(collection, mount, k, MUZZLE_OFFSET, order)
|
|
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_mirror_mount(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.mirror_ship_mount"
|
|
|
|
|
bl_label = "Mirror Mount"
|
|
|
|
|
bl_description = "Duplicate the selected weapon mount and its muzzles across the centreline, as a new row"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-19 00:16:35 +02:00
|
|
|
collection, state, root = _mount_frame(context)
|
2026-10-12 03:45:12 +02:00
|
|
|
mount = _selected_mount(context, collection)
|
|
|
|
|
row = _mount_row(state, mount["aetheria.id"])
|
|
|
|
|
local = _root_local(root, mount)
|
2026-10-19 00:16:35 +02:00
|
|
|
# Each space mirrors within itself: the row in the layout (the author's Position), the object in the model.
|
|
|
|
|
width = _parse_footprint(row.footprint)[0][0]
|
|
|
|
|
twin = hull_grid.mirror_position((row.x, row.y), width, state.width)
|
|
|
|
|
if abs(local.x) < MODEL_TOLERANCE or twin == (row.x, row.y):
|
|
|
|
|
raise ValueError("The weapon mount has no mirror image")
|
|
|
|
|
mirrored = _add_mount(collection, state, root, row.kind, hull_grid.mirror_rotation(int(row.rotation)),
|
|
|
|
|
(-local.x, local.y, local.z), hull_grid.mirror_footprint(row.footprint), twin)
|
2026-10-12 03:45:12 +02:00
|
|
|
new_row = _mount_row(state, mirrored["aetheria.id"])
|
|
|
|
|
for name in ("armor", "firing_arc"): # the author's own numbers, copied; the helper invents none
|
|
|
|
|
setattr(new_row, name, getattr(row, name))
|
|
|
|
|
for k, muzzle in enumerate(_muzzles(mount), start=1):
|
|
|
|
|
_make_muzzle(collection, mirrored, k, (-muzzle.location.x, muzzle.location.y, muzzle.location.z),
|
|
|
|
|
int(muzzle.get("aetheria.order", 0)))
|
|
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_remove_mount(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.remove_ship_mount"
|
|
|
|
|
bl_label = "Remove Mount"
|
|
|
|
|
bl_description = "Delete the selected weapon mount, its muzzles and its layout row"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-19 00:16:35 +02:00
|
|
|
collection, state, _ = _mount_frame(context)
|
2026-10-12 03:45:12 +02:00
|
|
|
mount = _selected_mount(context, collection)
|
|
|
|
|
mount_id = mount["aetheria.id"]
|
|
|
|
|
for index in reversed(range(len(state.hardpoints))):
|
|
|
|
|
if state.hardpoints[index].mount_id == mount_id:
|
|
|
|
|
state.hardpoints.remove(index)
|
|
|
|
|
for muzzle in _muzzles(mount):
|
|
|
|
|
_discard_object(muzzle)
|
|
|
|
|
_discard_object(mount)
|
|
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _encode_buffer(state):
|
|
|
|
|
"""The layout buffer as ship_cc stores it: (shape, hardpoint rows)."""
|
|
|
|
|
shape = [state.width, state.height, [cell.occupied for cell in state.cells]]
|
|
|
|
|
rows = [encode_hardpoint(Type=int(hp.kind), Position=[hp.x, hp.y], Shape=_parse_footprint(hp.footprint),
|
|
|
|
|
Transform=hp.mount_id, Rotation=int(hp.rotation), Armor=hp.armor, FiringArc=hp.firing_arc)
|
|
|
|
|
for hp in state.hardpoints]
|
|
|
|
|
return shape, rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _save_layout(context, collection, state):
|
|
|
|
|
"""The one writer of the .cc layout: writes the layout buffer, creating the file first when the ship is pending. A
|
|
|
|
|
failure after the file was created removes what this save made. Returns the hardpoint count."""
|
|
|
|
|
if not collection.get("aetheria.ship_cc"):
|
|
|
|
|
raise ValueError("The ship collection has no bound .cc path")
|
|
|
|
|
path = bpy.path.abspath(collection["aetheria.ship_cc"])
|
|
|
|
|
ship_id = collection["aetheria.id"]
|
|
|
|
|
if state.ship_id != ship_id or state.ship_cc != path:
|
|
|
|
|
raise ValueError("Load this collection's layout before saving")
|
|
|
|
|
cultlib = _brokkr_cultlib(context)
|
|
|
|
|
shape, rows = _encode_buffer(state)
|
|
|
|
|
pending = collection.get("aetheria.pending")
|
|
|
|
|
folder = Path(path).parent
|
|
|
|
|
if pending and Path(path).exists():
|
2026-10-10 12:56:58 +02:00
|
|
|
raise ValueError("A ship file already exists at the bound path (Ctrl+Z past a first Save leaves it there); "
|
|
|
|
|
"use Bind Ship Collection with that ship.cc, then Load Layout")
|
2026-10-10 09:49:40 +02:00
|
|
|
made_folder = bool(pending) and not folder.exists()
|
|
|
|
|
revision = state.revision
|
|
|
|
|
try:
|
|
|
|
|
if pending:
|
|
|
|
|
code, output = _aetherdb(context, "create", path, ship_id, pending[0], "--like", pending[1], ship_cc=path)
|
|
|
|
|
if output:
|
|
|
|
|
print(output)
|
|
|
|
|
if code != 0:
|
|
|
|
|
raise RuntimeError("AetherDb refused to create the ship; its message is in the system console")
|
|
|
|
|
revision = read_layout(path, cultlib)[2]
|
|
|
|
|
revision = replace_layout(path, cultlib, ship_id, revision, shape, rows)
|
|
|
|
|
except Exception:
|
|
|
|
|
if pending:
|
|
|
|
|
Path(path).unlink(missing_ok=True)
|
|
|
|
|
if made_folder:
|
|
|
|
|
shutil.rmtree(folder, ignore_errors=True)
|
|
|
|
|
raise
|
|
|
|
|
state.revision = revision
|
|
|
|
|
if pending:
|
|
|
|
|
del collection["aetheria.pending"]
|
|
|
|
|
_redraw_grid(collection, state)
|
|
|
|
|
return len(rows)
|
|
|
|
|
|
|
|
|
|
|
2026-09-26 19:23:01 +02:00
|
|
|
class AETHERIA_OT_save_layout(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.save_ship_layout"
|
|
|
|
|
bl_label = "Save Layout to .cc"
|
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-10 09:49:40 +02:00
|
|
|
collection, _ = _layout_path(context)
|
|
|
|
|
count = _save_layout(context, collection, context.scene.aetheria_layout)
|
|
|
|
|
self.report({"INFO"}, f"Saved the layout and {count} hardpoints")
|
2026-09-26 19:23:01 +02:00
|
|
|
return {"FINISHED"}
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
2026-09-26 18:14:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _brokkr_cultlib(context):
|
|
|
|
|
brokkr = context.preferences.addons.get("brokkr_bridge")
|
|
|
|
|
if brokkr is None:
|
|
|
|
|
raise RuntimeError("Enable Brokkr before using Aetheria Ships")
|
|
|
|
|
return brokkr.preferences.cultlib_py_src
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _is_ship(collection):
|
|
|
|
|
return collection.get("aetheria.asset_kind") == "ship"
|
2026-09-26 19:10:44 +02:00
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _ship_collection(context, unbound_ok=False):
|
|
|
|
|
"""The one chooser: the ship collection holding the active object. unbound_ok (Bind, New Ship) also accepts the
|
|
|
|
|
active object's only collection when no ship collection holds it."""
|
2026-10-08 19:35:47 +02:00
|
|
|
obj = context.active_object
|
|
|
|
|
if obj is None:
|
2026-10-13 01:47:23 +02:00
|
|
|
raise Refusal("Select an object in the ship collection")
|
2026-10-10 09:49:40 +02:00
|
|
|
ships = [collection for collection in bpy.data.collections if _is_ship(collection) and obj.name in collection.all_objects]
|
|
|
|
|
if len(ships) == 1:
|
|
|
|
|
return ships[0]
|
|
|
|
|
if unbound_ok and not ships and len(obj.users_collection) == 1:
|
|
|
|
|
return obj.users_collection[0]
|
2026-10-13 01:47:23 +02:00
|
|
|
raise Refusal("Select an object in exactly one ship collection" if unbound_ok
|
2026-10-10 09:49:40 +02:00
|
|
|
else "Selected object must belong to exactly one bound ship collection")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _bind_collection(collection, path, ship_id, pending=None):
|
|
|
|
|
"""Binds the collection to the ship .cc at path (aetheria.asset_kind, .id and .ship_cc, and .pending = [name,
|
|
|
|
|
reference] for a ship whose file the first Save creates), or changes nothing."""
|
2026-10-08 19:35:47 +02:00
|
|
|
if collection.get("aetheria.asset_kind") not in (None, "ship"):
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("The collection has another aetheria.asset_kind")
|
2026-10-08 19:35:47 +02:00
|
|
|
if collection.get("aetheria.id") not in (None, ship_id):
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("The collection is bound to another ship ID")
|
2026-10-08 19:35:47 +02:00
|
|
|
stored = path
|
|
|
|
|
if bpy.data.filepath:
|
|
|
|
|
try:
|
|
|
|
|
stored = bpy.path.relpath(path)
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
2026-10-10 20:38:17 +02:00
|
|
|
keys = ("aetheria.asset_kind", "aetheria.id", "aetheria.ship_cc", "aetheria.pending")
|
|
|
|
|
before = {key: collection[key] for key in keys if key in collection}
|
|
|
|
|
values = {"aetheria.asset_kind": "ship", "aetheria.id": ship_id, "aetheria.ship_cc": stored}
|
2026-10-10 09:49:40 +02:00
|
|
|
if pending:
|
2026-10-10 20:38:17 +02:00
|
|
|
values["aetheria.pending"] = pending
|
|
|
|
|
try:
|
|
|
|
|
for key, value in values.items():
|
|
|
|
|
collection[key] = value
|
|
|
|
|
if not pending and "aetheria.pending" in collection:
|
|
|
|
|
del collection["aetheria.pending"]
|
|
|
|
|
except Exception:
|
|
|
|
|
for key in keys: # the ID-property store refused a value: put every key back as it was
|
|
|
|
|
if key in before:
|
|
|
|
|
collection[key] = before[key]
|
|
|
|
|
elif key in collection:
|
|
|
|
|
del collection[key]
|
|
|
|
|
raise
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
2026-09-26 19:10:44 +02:00
|
|
|
class AETHERIA_OT_bind_ship_collection(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.bind_ship_collection"
|
|
|
|
|
bl_label = "Bind Ship Collection"
|
|
|
|
|
bl_description = "Bind the active collection to one typed ship .cc record"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
|
|
|
|
if not context.scene.aetheria_ship_cc_path:
|
|
|
|
|
raise ValueError("Choose an existing ship authoring .cc file")
|
2026-10-10 09:49:40 +02:00
|
|
|
path = bpy.path.abspath(context.scene.aetheria_ship_cc_path)
|
|
|
|
|
collection = _ship_collection(context, unbound_ok=True)
|
|
|
|
|
_bind_collection(collection, path, read(path, _brokkr_cultlib(context)).ship.body[0])
|
|
|
|
|
self.report({"INFO"}, "Bound the ship collection")
|
2026-09-26 19:10:44 +02:00
|
|
|
return {"FINISHED"}
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
2026-09-26 19:10:44 +02:00
|
|
|
|
|
|
|
|
|
2026-09-26 18:14:36 +02:00
|
|
|
class AETHERIA_OT_capture_ship_lines(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.capture_ship_lines"
|
|
|
|
|
bl_label = "Capture Ship Lines"
|
2026-10-22 15:59:56 +02:00
|
|
|
bl_description = "Replace only the line slot in the bound ship .cc record: from the Grease Pencil object, else from the hull source"
|
2026-09-26 18:14:36 +02:00
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-09-26 19:10:44 +02:00
|
|
|
collection = _ship_collection(context)
|
|
|
|
|
if not collection.get("aetheria.ship_cc"):
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("The ship collection has no bound .cc path")
|
2026-09-26 19:10:44 +02:00
|
|
|
path = bpy.path.abspath(collection["aetheria.ship_cc"])
|
2026-09-26 18:14:36 +02:00
|
|
|
cultlib = _brokkr_cultlib(context)
|
2026-09-30 03:06:43 +02:00
|
|
|
if read(path, cultlib).ship.body[0] != collection["aetheria.id"]:
|
2026-09-26 19:10:44 +02:00
|
|
|
raise ValueError("The bound collection ID does not match its .cc ship ID")
|
2026-10-22 16:54:13 +02:00
|
|
|
saved_shape, _, _ = read_layout(path, cultlib)
|
|
|
|
|
root = _ship_root(collection)
|
|
|
|
|
if root is not None: # the frame Package would write the model in, so the lines match ship.glb
|
|
|
|
|
_frame_ship(context, collection, root, path, saved_shape)
|
2026-10-22 15:59:56 +02:00
|
|
|
lines = _schematic_lines(context, collection)
|
|
|
|
|
if lines is None:
|
|
|
|
|
raise ValueError("No schematic lines were captured; the ship record was not changed")
|
2026-09-26 18:14:36 +02:00
|
|
|
count = replace_lines(path, cultlib, lines)
|
2026-10-10 09:49:40 +02:00
|
|
|
self.report({"INFO"}, f"Captured {count} lines")
|
2026-09-26 18:14:36 +02:00
|
|
|
return {"FINISHED"}
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
2026-09-26 18:14:36 +02:00
|
|
|
|
|
|
|
|
|
2026-10-18 22:00:15 +02:00
|
|
|
DEFAULT_OPENSCAD = r"C:\Tools\OpenSCAD-2026.09.23-x86-64\openscad.com"
|
|
|
|
|
|
|
|
|
|
|
2026-10-03 17:13:42 +02:00
|
|
|
class AETHERIA_AP_preferences(bpy.types.AddonPreferences):
|
|
|
|
|
bl_idname = __package__
|
|
|
|
|
|
2026-10-10 06:53:03 +02:00
|
|
|
game_folder: bpy.props.StringProperty(
|
|
|
|
|
name="Game folder", subtype="DIR_PATH",
|
|
|
|
|
description="The folder whose GameData holds Aetheria.cc and Mods (the install folder); its ModTools holds "
|
|
|
|
|
"AetherDb. Empty: the nearest folder above the bound .cc whose GameData holds Aetheria.cc")
|
2026-10-03 17:13:42 +02:00
|
|
|
|
2026-10-12 05:37:50 +02:00
|
|
|
max_texture: bpy.props.IntProperty(
|
|
|
|
|
name="Max texture", default=2048, min=64, soft_max=8192,
|
|
|
|
|
description="The longest side, in pixels, a material image keeps in ship.glb; larger images are exported "
|
|
|
|
|
"scaled to it and the .blend's own images are left as they are")
|
|
|
|
|
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
bake_size: bpy.props.IntProperty(
|
|
|
|
|
name="Bake size", default=2048, min=64, soft_max=8192,
|
|
|
|
|
description="The side, in pixels, of the square albedo and normal images Bake From Source makes")
|
|
|
|
|
|
|
|
|
|
bake_cage_extrusion: bpy.props.FloatProperty(
|
|
|
|
|
name="Bake cage extrusion", default=0.05, min=0.0, unit="LENGTH",
|
|
|
|
|
description="How far, in metres, Bake From Source pushes each render mesh surface out along its normals before "
|
|
|
|
|
"casting rays at Source. Too small misses Source where it rises above the render mesh; too large "
|
|
|
|
|
"catches parts across a gap")
|
|
|
|
|
|
|
|
|
|
bake_max_ray_distance: bpy.props.FloatProperty(
|
|
|
|
|
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")
|
|
|
|
|
|
2026-10-18 22:00:15 +02:00
|
|
|
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)")
|
|
|
|
|
|
2026-10-03 17:13:42 +02:00
|
|
|
def draw(self, context):
|
2026-10-10 06:53:03 +02:00
|
|
|
self.layout.prop(self, "game_folder")
|
2026-10-18 22:00:15 +02:00
|
|
|
self.layout.prop(self, "openscad")
|
2026-10-12 05:37:50 +02:00
|
|
|
self.layout.prop(self, "max_texture")
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
self.layout.prop(self, "bake_size")
|
|
|
|
|
self.layout.prop(self, "bake_cage_extrusion")
|
|
|
|
|
self.layout.prop(self, "bake_max_ray_distance")
|
2026-10-03 17:13:42 +02:00
|
|
|
|
|
|
|
|
|
2026-10-10 06:53:03 +02:00
|
|
|
GAME_FOLDER_REFUSAL = ("Set the add-on's Game folder preference to the folder whose GameData holds Aetheria.cc "
|
|
|
|
|
"and whose ModTools holds AetherDb")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _game_folder(context, ship_cc=None):
|
|
|
|
|
"""The folder AetherDb runs against: the Game folder preference, else the nearest folder above the bound .cc whose
|
|
|
|
|
GameData holds Aetheria.cc. Refusals name the preference and never a path."""
|
2026-10-03 17:13:42 +02:00
|
|
|
addon = context.preferences.addons.get(__package__)
|
2026-10-10 06:53:03 +02:00
|
|
|
configured = addon.preferences.game_folder if addon and addon.preferences else ""
|
2026-10-03 17:13:42 +02:00
|
|
|
if configured:
|
2026-10-10 06:53:03 +02:00
|
|
|
folder = Path(bpy.path.abspath(configured))
|
|
|
|
|
if not (folder / "GameData" / "Aetheria.cc").is_file():
|
|
|
|
|
raise ValueError(GAME_FOLDER_REFUSAL)
|
|
|
|
|
return folder
|
|
|
|
|
if ship_cc:
|
|
|
|
|
for folder in Path(ship_cc).resolve().parents:
|
|
|
|
|
if (folder / "GameData" / "Aetheria.cc").is_file():
|
|
|
|
|
return folder
|
|
|
|
|
raise ValueError(GAME_FOLDER_REFUSAL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _aetherdb(context, *args, ship_cc=None):
|
|
|
|
|
"""Runs one AetherDb ship-authoring command from the game folder's ModTools; returns its exit code and its output,
|
|
|
|
|
stdout then stderr. ship_cc is the bound .cc the game folder is found from when the preference is empty."""
|
|
|
|
|
folder = _game_folder(context, ship_cc)
|
|
|
|
|
tool = folder / "ModTools" / ("AetherDb.exe" if sys.platform == "win32" else "AetherDb")
|
|
|
|
|
if not tool.is_file():
|
|
|
|
|
raise ValueError(GAME_FOLDER_REFUSAL)
|
2026-10-10 09:49:40 +02:00
|
|
|
try:
|
|
|
|
|
result = subprocess.run([str(tool), "ship-authoring", *args], cwd=folder, capture_output=True, text=True,
|
|
|
|
|
timeout=AETHERDB_TIMEOUT)
|
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
|
raise RuntimeError("AetherDb did not finish in time") from None
|
|
|
|
|
except OSError:
|
|
|
|
|
raise RuntimeError("AetherDb could not be started") from None
|
2026-10-10 07:25:05 +02:00
|
|
|
lines = (result.stdout + "\n" + result.stderr).splitlines()
|
|
|
|
|
return result.returncode, "\n".join(line for line in lines if line.strip())
|
2026-10-03 17:13:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _layer_collection(layer, collection):
|
|
|
|
|
if layer.collection == collection:
|
|
|
|
|
return layer
|
|
|
|
|
for child in layer.children:
|
|
|
|
|
found = _layer_collection(child, collection)
|
|
|
|
|
if found:
|
|
|
|
|
return found
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _anchors(collection):
|
|
|
|
|
"""One ShipAnchor row per object tagged aetheria.role. Its aetheria.id is both the anchor id and the GLB node id."""
|
|
|
|
|
rows = []
|
|
|
|
|
for obj in sorted(collection.all_objects, key=lambda candidate: candidate.name):
|
|
|
|
|
role = obj.get("aetheria.role")
|
|
|
|
|
if role is None:
|
|
|
|
|
continue
|
|
|
|
|
anchor_id = obj.get("aetheria.id")
|
|
|
|
|
if not isinstance(anchor_id, str) or not anchor_id.strip():
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("An object with aetheria.role has no aetheria.id")
|
2026-10-03 17:13:42 +02:00
|
|
|
parent = None
|
|
|
|
|
if role == "weapon-muzzle":
|
|
|
|
|
parent = obj.parent.get("aetheria.id") if obj.parent else None
|
|
|
|
|
if not parent:
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("A weapon-muzzle must be parented to its weapon mount object")
|
2026-10-03 17:13:42 +02:00
|
|
|
rows.append([anchor_id, str(role), anchor_id, parent, int(obj.get("aetheria.order", 0))])
|
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
2026-10-12 05:37:50 +02:00
|
|
|
DEFAULT_MAX_TEXTURE = 2048
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _max_texture(context):
|
|
|
|
|
addon = context.preferences.addons.get(__package__)
|
|
|
|
|
return addon.preferences.max_texture if addon and addon.preferences else DEFAULT_MAX_TEXTURE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _image_nodes(tree, seen=None):
|
|
|
|
|
"""Every Image Texture node of a node tree, node groups included."""
|
|
|
|
|
seen = set() if seen is None else seen
|
|
|
|
|
if tree is None or tree.name_full in seen:
|
|
|
|
|
return
|
|
|
|
|
seen.add(tree.name_full)
|
|
|
|
|
for node in tree.nodes:
|
|
|
|
|
if node.type == "TEX_IMAGE" and node.image is not None:
|
|
|
|
|
yield node
|
|
|
|
|
elif node.type == "GROUP":
|
|
|
|
|
yield from _image_nodes(node.node_tree, seen)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _swap_in_scaled_images(objects, limit, swaps):
|
|
|
|
|
"""Points each Image Texture node of the objects' materials that holds an image longer than limit at a scaled copy,
|
|
|
|
|
and appends each (node, original, copy) to swaps for _restore_images, so a failure part way still restores. The
|
|
|
|
|
originals are never modified."""
|
|
|
|
|
copies = {}
|
|
|
|
|
for obj in objects:
|
|
|
|
|
for slot in obj.material_slots:
|
|
|
|
|
for node in _image_nodes(slot.material.node_tree if slot.material else None):
|
|
|
|
|
original = node.image
|
|
|
|
|
longest = max(original.size)
|
|
|
|
|
if longest <= limit:
|
|
|
|
|
continue
|
|
|
|
|
if original not in copies:
|
|
|
|
|
copy = original.copy()
|
Guards fix: cultcache-py version is read from the imported module; texture cap boundary, rounding, orientation, group and failure cases pinned
Findings of verdict cut-ships-addon-guards.s1: guard-not-import (the version now comes from the checkout the imported
cultcache_py lives in, one owner, no pyproject-beside-a-path), prefix-compare-survives (0.3.0.1, 0.3.0rc1, 0.3.00
refused), cap-boundary-unpinned and group-restore-unpinned (smoke_package texture_boundary_cases: at the cap, one over,
height-long, non-square rounding, file/packed/node-group images, failed export restores). A copy whose scale raises is
removed. All commits build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 06:59:24 +02:00
|
|
|
try:
|
|
|
|
|
copy.scale(max(1, round(original.size[0] * limit / longest)),
|
|
|
|
|
max(1, round(original.size[1] * limit / longest)))
|
|
|
|
|
except BaseException:
|
|
|
|
|
bpy.data.images.remove(copy) # not yet in swaps, so _restore_images cannot find it
|
|
|
|
|
raise
|
2026-10-12 05:37:50 +02:00
|
|
|
copies[original] = copy
|
|
|
|
|
node.image = copies[original]
|
|
|
|
|
swaps.append((node, original, copies[original]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _restore_images(swaps):
|
|
|
|
|
for node, original, _ in swaps:
|
|
|
|
|
node.image = original
|
|
|
|
|
for copy in {id(copy): copy for _, _, copy in swaps}.values():
|
|
|
|
|
bpy.data.images.remove(copy)
|
|
|
|
|
|
|
|
|
|
|
2026-10-03 17:13:42 +02:00
|
|
|
def _export_glb(context, collection, filepath):
|
2026-10-10 21:02:22 +02:00
|
|
|
"""Exports the collection's objects with custom properties as node extras: Generated's anchors are exported; Grease
|
|
|
|
|
Pencil, Source and the Grid are not."""
|
2026-10-03 17:13:42 +02:00
|
|
|
view_layer = context.view_layer
|
|
|
|
|
layer = _layer_collection(view_layer.layer_collection, collection)
|
|
|
|
|
if layer is None:
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("The ship collection is not in the current view layer")
|
2026-10-03 17:13:42 +02:00
|
|
|
previous_layer = view_layer.active_layer_collection
|
|
|
|
|
previous_selection = [obj for obj in view_layer.objects if obj.select_get()]
|
|
|
|
|
previous_active = view_layer.objects.active
|
2026-10-12 05:37:50 +02:00
|
|
|
swaps = []
|
2026-10-03 17:13:42 +02:00
|
|
|
try:
|
|
|
|
|
view_layer.active_layer_collection = layer
|
|
|
|
|
for obj in previous_selection:
|
|
|
|
|
obj.select_set(False)
|
2026-10-08 19:35:47 +02:00
|
|
|
derived = _derived_names(collection)
|
2026-10-12 05:37:50 +02:00
|
|
|
exported = [obj for obj in collection.all_objects
|
|
|
|
|
if obj.type != "GREASEPENCIL" and obj.name not in derived and obj.name in view_layer.objects]
|
|
|
|
|
for obj in exported:
|
|
|
|
|
obj.select_set(True)
|
|
|
|
|
_swap_in_scaled_images(exported, _max_texture(context), swaps)
|
2026-10-03 17:13:42 +02:00
|
|
|
bpy.ops.export_scene.gltf(
|
|
|
|
|
filepath=filepath, export_format="GLB", use_active_collection=True, use_selection=True,
|
|
|
|
|
export_extras=True, export_yup=True, export_apply=True)
|
2026-10-10 12:20:41 +02:00
|
|
|
except RuntimeError: # the exporter's text holds paths and a traceback
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
raise RuntimeError("The GLB export failed; its message is in the system console") from None
|
2026-10-03 17:13:42 +02:00
|
|
|
finally:
|
2026-10-12 05:37:50 +02:00
|
|
|
_restore_images(swaps)
|
2026-10-03 17:13:42 +02:00
|
|
|
for obj in view_layer.objects:
|
|
|
|
|
obj.select_set(obj in previous_selection)
|
|
|
|
|
view_layer.objects.active = previous_active
|
|
|
|
|
view_layer.active_layer_collection = previous_layer
|
|
|
|
|
|
|
|
|
|
|
2026-10-08 19:35:47 +02:00
|
|
|
def _child(collection, kind):
|
|
|
|
|
"""The child collection tagged aetheria.frame == kind. Blender keeps collection names unique per file, so the
|
|
|
|
|
name 'Source' or 'Generated' cannot identify it."""
|
|
|
|
|
return next((child for child in collection.children if child.get("aetheria.frame") == kind), None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _child_or_new(collection, kind, name):
|
|
|
|
|
child = _child(collection, kind)
|
|
|
|
|
if child is None:
|
|
|
|
|
child = bpy.data.collections.new(name)
|
|
|
|
|
child["aetheria.frame"] = kind
|
|
|
|
|
collection.children.link(child)
|
|
|
|
|
return child
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _derived_names(collection):
|
2026-10-10 21:02:22 +02:00
|
|
|
"""Names of the objects that are never exported: Source's, and Generated's that carry no aetheria.role (the Grid)."""
|
2026-10-08 19:35:47 +02:00
|
|
|
return {obj.name for kind in (SOURCE, GENERATED) for child in [_child(collection, kind)] if child
|
2026-10-10 21:02:22 +02:00
|
|
|
for obj in child.all_objects if kind == SOURCE or "aetheria.role" not in obj}
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ship_root(collection):
|
|
|
|
|
return next((obj for obj in collection.objects if obj.get("aetheria.ship_root")), None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _meshes(objects):
|
|
|
|
|
return [obj for obj in objects if obj.type == "MESH"]
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 21:02:22 +02:00
|
|
|
def _own_meshes(collection):
|
|
|
|
|
"""The ship's own render meshes: Ship Root's descendants outside Source and Generated that carry no aetheria.role."""
|
2026-10-10 09:49:40 +02:00
|
|
|
derived = _derived_names(collection)
|
2026-10-10 21:02:22 +02:00
|
|
|
return [obj for obj in _meshes(_ship_root(collection).children_recursive)
|
|
|
|
|
if obj.name not in derived and "aetheria.role" not in obj]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _frame_meshes(collection):
|
|
|
|
|
"""The meshes Rasterise reads: the ship's own, the Source meshes while there are none."""
|
2026-10-10 09:49:40 +02:00
|
|
|
source = _child(collection, SOURCE)
|
2026-10-10 21:02:22 +02:00
|
|
|
return _own_meshes(collection) or (_meshes(source.all_objects) if source else [])
|
2026-10-10 09:49:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _loose_meshes(collection):
|
2026-10-10 12:20:41 +02:00
|
|
|
"""Meshes of a collection that has a Ship Root which are not under the root, Generated's apart. Source meshes count:
|
|
|
|
|
Rasterise reads them and Flip Nose turns only what hangs from Ship Root."""
|
2026-10-10 09:49:40 +02:00
|
|
|
root = _ship_root(collection)
|
|
|
|
|
if root is None:
|
|
|
|
|
return []
|
2026-10-10 12:20:41 +02:00
|
|
|
generated = _child(collection, GENERATED)
|
|
|
|
|
derived = {obj.name for obj in generated.all_objects} if generated else set()
|
2026-10-10 09:49:40 +02:00
|
|
|
framed = {obj.name for obj in root.children_recursive}
|
|
|
|
|
return [obj for obj in _meshes(collection.all_objects) if obj.name not in derived and obj.name not in framed]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _refuse_loose_meshes(context, collection):
|
|
|
|
|
"""Refuses while meshes sit outside Ship Root, selecting them so the author can parent them."""
|
|
|
|
|
loose = _loose_meshes(collection)
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
if loose:
|
|
|
|
|
_refuse_selecting(context, loose, f"{len(loose)} meshes in the ship collection are not under Ship Root; parent them to it")
|
2026-10-10 09:49:40 +02:00
|
|
|
|
|
|
|
|
|
2026-10-19 00:17:18 +02:00
|
|
|
def _shared_id_objects(collection):
|
|
|
|
|
"""The role-bearing objects of the collection that share an aetheria.id with another: every copy and its original."""
|
|
|
|
|
by_id = {}
|
|
|
|
|
for obj in collection.all_objects:
|
|
|
|
|
anchor_id = obj.get("aetheria.id")
|
|
|
|
|
if obj.get("aetheria.role") is not None and isinstance(anchor_id, str):
|
|
|
|
|
by_id.setdefault(anchor_id, []).append(obj)
|
|
|
|
|
return [obj for group in by_id.values() if len(group) > 1 for obj in group]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _refuse_shared_ids(context, collection):
|
|
|
|
|
"""Refuses while two role-bearing objects share an aetheria.id (a copy of a collider, emitter, radiator or mount),
|
|
|
|
|
selecting the original and the copies so the author can delete or re-id them. Nothing is deleted."""
|
|
|
|
|
shared = _shared_id_objects(collection)
|
|
|
|
|
if shared:
|
|
|
|
|
_refuse_selecting(context, shared, f"{len(shared)} objects share an aetheria.id; they are selected: delete the "
|
|
|
|
|
"copies or give each its own id")
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _frame_inputs(context, collection, state):
|
|
|
|
|
"""Ship Root and the meshes Rasterise reads, or the refusal that stops Rasterise and Flip Nose before they change
|
|
|
|
|
anything."""
|
|
|
|
|
root = _ship_root(collection)
|
|
|
|
|
if root is None:
|
|
|
|
|
raise ValueError("The ship collection has no Ship Root; run New Ship first")
|
|
|
|
|
if state.ship_id != collection["aetheria.id"]:
|
|
|
|
|
raise ValueError("Load this collection's layout first")
|
|
|
|
|
_refuse_loose_meshes(context, collection)
|
|
|
|
|
meshes = _frame_meshes(collection)
|
|
|
|
|
if not meshes:
|
|
|
|
|
raise ValueError("The ship collection has no render or Source mesh to rasterise")
|
|
|
|
|
return root, meshes
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _world_mesh(obj, depsgraph, matrix):
|
|
|
|
|
"""The evaluated mesh's points through matrix, as (points, triangles) numpy arrays."""
|
|
|
|
|
evaluated = obj.evaluated_get(depsgraph)
|
|
|
|
|
mesh = evaluated.to_mesh()
|
|
|
|
|
try:
|
|
|
|
|
points = numpy.empty(len(mesh.vertices) * 3, dtype=numpy.float32)
|
|
|
|
|
mesh.vertices.foreach_get("co", points)
|
|
|
|
|
mesh.calc_loop_triangles()
|
|
|
|
|
triangles = numpy.empty(len(mesh.loop_triangles) * 3, dtype=numpy.int32)
|
|
|
|
|
mesh.loop_triangles.foreach_get("vertices", triangles)
|
|
|
|
|
finally:
|
|
|
|
|
evaluated.to_mesh_clear()
|
|
|
|
|
linear = numpy.array(matrix, dtype=numpy.float64)
|
|
|
|
|
return points.reshape(-1, 3) @ linear[:3, :3].T + linear[:3, 3], triangles.reshape(-1, 3)
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 12:56:58 +02:00
|
|
|
def _held(matrix):
|
|
|
|
|
"""The world matrix an object holds after matrix_world = matrix: Blender keeps location, rotation and scale, so a
|
|
|
|
|
shear (a non-uniform scaled parent under rotation) is dropped. The hull the author sees afterwards is this one."""
|
|
|
|
|
return Matrix.LocRotScale(*matrix.decompose())
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 12:26:42 +02:00
|
|
|
def _triangles_xy(depsgraph, placements):
|
|
|
|
|
"""The top-down triangles of the evaluated meshes, each through its matrix: what the author sees from above.
|
|
|
|
|
placements is [(object, matrix)]."""
|
|
|
|
|
triangles = []
|
|
|
|
|
for obj, matrix in placements:
|
|
|
|
|
points, indices = _world_mesh(obj, depsgraph, matrix)
|
|
|
|
|
triangles += points[indices][:, :, :2].tolist()
|
|
|
|
|
return triangles
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _grid_current(collection, state):
|
|
|
|
|
"""Whether the Grid can be drawn: grid_origin was computed for the buffer's own size."""
|
|
|
|
|
origin = collection.get("aetheria.grid_origin")
|
|
|
|
|
return (origin is not None and len(origin) == 4 and (int(origin[2]), int(origin[3])) == (state.width, state.height)
|
|
|
|
|
and len(state.cells) == state.width * state.height)
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 21:02:22 +02:00
|
|
|
def _discard_object(obj):
|
|
|
|
|
"""Removes obj, then its mesh when nothing else uses it."""
|
|
|
|
|
mesh = obj.data if obj.type == "MESH" else None
|
|
|
|
|
bpy.data.objects.remove(obj)
|
|
|
|
|
if mesh is not None and mesh.users == 0:
|
|
|
|
|
bpy.data.meshes.remove(mesh)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _attach_to_root(obj, root):
|
|
|
|
|
"""Parents obj to root with an identity parent inverse and a zero local transform: its local frame is Ship Root's."""
|
|
|
|
|
obj.parent = root
|
|
|
|
|
obj.matrix_parent_inverse = Matrix.Identity(4)
|
|
|
|
|
obj.location = (0.0, 0.0, 0.0)
|
|
|
|
|
obj.rotation_mode = "XYZ"
|
|
|
|
|
obj.rotation_euler = (0.0, 0.0, 0.0)
|
|
|
|
|
obj.scale = (1.0, 1.0, 1.0)
|
|
|
|
|
|
|
|
|
|
|
2026-10-08 19:35:47 +02:00
|
|
|
def _redraw_grid(collection, state):
|
2026-10-10 09:49:40 +02:00
|
|
|
"""Redraws the Grid object from the layout buffer and the collection's aetheria.grid_origin while the origin was
|
|
|
|
|
computed for the buffer's size; otherwise removes the Grid. A collection without a Ship Root or a grid_origin has no
|
|
|
|
|
frame yet and gets no Grid."""
|
2026-10-08 19:35:47 +02:00
|
|
|
root = _ship_root(collection)
|
|
|
|
|
origin = collection.get("aetheria.grid_origin")
|
2026-10-10 09:49:40 +02:00
|
|
|
if root is None or origin is None:
|
|
|
|
|
return
|
|
|
|
|
generated = _child_or_new(collection, GENERATED, GENERATED)
|
|
|
|
|
grid = next((obj for obj in generated.objects if obj.get("aetheria.grid")), None)
|
|
|
|
|
if not _grid_current(collection, state):
|
|
|
|
|
if grid is not None:
|
2026-10-10 21:02:22 +02:00
|
|
|
_discard_object(grid)
|
2026-10-08 19:35:47 +02:00
|
|
|
return
|
|
|
|
|
origin = (float(origin[0]), float(origin[1]))
|
|
|
|
|
half = hull_grid.CELL_SIZE / 2
|
|
|
|
|
verts, edges, faces = [], [], []
|
|
|
|
|
for x in range(state.width):
|
|
|
|
|
for y in range(state.height):
|
|
|
|
|
cx, cy = hull_grid.cell_centre(origin, x, y)
|
|
|
|
|
i = len(verts)
|
|
|
|
|
verts += [(cx - half, cy - half, 0.0), (cx + half, cy - half, 0.0), (cx + half, cy + half, 0.0),
|
|
|
|
|
(cx - half, cy + half, 0.0)]
|
|
|
|
|
if state.cells[x * state.height + y].occupied:
|
|
|
|
|
faces.append((i, i + 1, i + 2, i + 3))
|
|
|
|
|
else:
|
|
|
|
|
edges += [(i, i + 1), (i + 1, i + 2), (i + 2, i + 3), (i + 3, i)]
|
|
|
|
|
mesh = bpy.data.meshes.new("Grid")
|
|
|
|
|
mesh.from_pydata(verts, edges, faces)
|
|
|
|
|
mesh.update(calc_edges=True)
|
|
|
|
|
if grid is None:
|
|
|
|
|
grid = bpy.data.objects.new("Grid", mesh)
|
|
|
|
|
grid["aetheria.grid"] = True
|
|
|
|
|
generated.objects.link(grid)
|
|
|
|
|
else:
|
|
|
|
|
previous, grid.data = grid.data, mesh
|
|
|
|
|
if previous.users == 0:
|
|
|
|
|
bpy.data.meshes.remove(previous)
|
2026-10-10 21:02:22 +02:00
|
|
|
_attach_to_root(grid, root)
|
2026-10-08 19:35:47 +02:00
|
|
|
grid.display_type = "WIRE"
|
|
|
|
|
|
|
|
|
|
|
2026-10-10 09:49:40 +02:00
|
|
|
def _rasterise(context, collection, state):
|
|
|
|
|
"""Proposes the hull's cells from the frame meshes, top-down in Ship Root's frame, into the layout buffer (its
|
2026-10-10 12:26:42 +02:00
|
|
|
hardpoints stay) and stores the grid's placement with the size it was computed for. Writes no file."""
|
2026-10-10 09:49:40 +02:00
|
|
|
root, meshes = _frame_inputs(context, collection, state)
|
2026-10-08 19:35:47 +02:00
|
|
|
to_root = root.matrix_world.inverted()
|
2026-10-10 12:26:42 +02:00
|
|
|
width, height, cells, origin = hull_grid.rasterise(_triangles_xy(
|
|
|
|
|
context.evaluated_depsgraph_get(), [(obj, to_root @ obj.matrix_world) for obj in meshes]))
|
|
|
|
|
_place_grid(collection, state, width, height, cells, origin)
|
|
|
|
|
return width, height
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _place_grid(collection, state, width, height, cells, origin):
|
|
|
|
|
"""Puts a rasterised hull into the layout buffer (its hardpoints stay), stores the grid's placement with the size it
|
|
|
|
|
was computed for and redraws the Grid. The only writer of aetheria.grid_origin."""
|
2026-10-10 09:49:40 +02:00
|
|
|
_set_cells(state, width, height, cells)
|
|
|
|
|
collection["aetheria.grid_origin"] = [float(origin[0]), float(origin[1]), width, height]
|
|
|
|
|
_redraw_grid(collection, state)
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
2026-10-10 21:02:22 +02:00
|
|
|
GENERATED_ROLES = (("map-icon", "map", "Map Icon"), ("shield", "shield", "Shield"), ("tractor", "tractor", "Tractor"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _recentre(root, point):
|
|
|
|
|
"""Moves Ship Root, and the ship with it, so that its local point (x, y) sits at world X = Y = 0."""
|
|
|
|
|
world = root.matrix_world @ Vector((point[0], point[1], 0.0))
|
|
|
|
|
moved = root.matrix_world.copy()
|
|
|
|
|
moved.translation.x -= world.x
|
|
|
|
|
moved.translation.y -= world.y
|
|
|
|
|
root.matrix_world = moved
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _regenerate_anchors(context, collection, root):
|
|
|
|
|
"""Rebuilds Generated's map-icon, shield and tractor from the render meshes (_own_meshes) in Ship Root's frame:
|
2026-10-10 22:55:18 +02:00
|
|
|
every anchor Package itself generated (marked aetheria.generated) and not marked aetheria.keep is discarded; anything
|
|
|
|
|
else in Generated, a collider included, is the operator's and stays. Then each of the three roles no other object in the
|
2026-10-10 21:02:22 +02:00
|
|
|
collection carries is made again. The operator's own object, or a kept one, owns its role. Everything that can
|
|
|
|
|
refuse comes before the first change."""
|
|
|
|
|
generated = _child_or_new(collection, GENERATED, GENERATED)
|
2026-10-10 22:55:18 +02:00
|
|
|
stale = [obj for obj in generated.all_objects if obj.get("aetheria.generated") and not obj.get("aetheria.keep")]
|
2026-10-10 21:02:22 +02:00
|
|
|
stale_names = {obj.name for obj in stale}
|
|
|
|
|
held = {obj["aetheria.role"] for obj in collection.all_objects
|
|
|
|
|
if "aetheria.role" in obj and obj.name not in stale_names}
|
|
|
|
|
meshes = _own_meshes(collection)
|
|
|
|
|
missing = [entry for entry in GENERATED_ROLES if meshes and entry[0] not in held]
|
|
|
|
|
made = []
|
|
|
|
|
if missing:
|
|
|
|
|
depsgraph = context.evaluated_depsgraph_get()
|
|
|
|
|
to_root = root.matrix_world.inverted()
|
|
|
|
|
points = numpy.vstack([_world_mesh(obj, depsgraph, to_root @ obj.matrix_world)[0] for obj in meshes])
|
|
|
|
|
if not len(points):
|
|
|
|
|
raise ValueError("The render meshes have no points to derive the map icon, shield and tractor from")
|
|
|
|
|
low, high = points.min(axis=0), points.max(axis=0)
|
|
|
|
|
centre, half = (low + high) / 2, (high - low) / 2
|
|
|
|
|
for role, anchor_id, name in missing:
|
|
|
|
|
if role == "map-icon":
|
|
|
|
|
outline = hull_grid.convex_outline(points[:, :2].tolist())
|
|
|
|
|
mesh = bpy.data.meshes.new(name)
|
|
|
|
|
mesh.from_pydata([(x, y, float(centre[2])) for x, y in outline], [], [tuple(range(len(outline)))])
|
|
|
|
|
mesh.update()
|
|
|
|
|
made.append((role, anchor_id, bpy.data.objects.new(name, mesh), None, None))
|
|
|
|
|
elif role == "shield":
|
|
|
|
|
empty = bpy.data.objects.new(name, None)
|
|
|
|
|
empty.empty_display_type = "SPHERE"
|
|
|
|
|
made.append((role, anchor_id, empty, tuple(float(v) for v in centre),
|
|
|
|
|
[max(1.15 * float(h), 0.1) for h in half]))
|
|
|
|
|
else:
|
|
|
|
|
empty = bpy.data.objects.new(name, None)
|
|
|
|
|
empty.empty_display_type = "ARROWS"
|
|
|
|
|
made.append((role, anchor_id, empty, (float(centre[0]), float(low[1]), float(centre[2])), None))
|
|
|
|
|
for obj in stale:
|
|
|
|
|
_discard_object(obj)
|
|
|
|
|
for role, anchor_id, obj, at, scale in made:
|
|
|
|
|
obj["aetheria.role"] = role
|
|
|
|
|
obj["aetheria.id"] = anchor_id
|
|
|
|
|
obj["aetheria.keep"] = False
|
2026-10-10 22:55:18 +02:00
|
|
|
obj["aetheria.generated"] = True
|
2026-10-10 21:02:22 +02:00
|
|
|
generated.objects.link(obj)
|
|
|
|
|
_attach_to_root(obj, root)
|
|
|
|
|
if at is not None:
|
|
|
|
|
obj.location = at
|
|
|
|
|
if scale is not None:
|
|
|
|
|
obj.scale = scale
|
|
|
|
|
|
|
|
|
|
|
2026-10-08 19:35:47 +02:00
|
|
|
class AETHERIA_OT_rasterise_hull(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.rasterise_hull"
|
|
|
|
|
bl_label = "Rasterise Hull"
|
2026-10-10 09:49:40 +02:00
|
|
|
bl_description = "Propose the hull's cells from its top-down silhouette; you edit them afterwards, then Save Layout"
|
2026-10-08 19:35:47 +02:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-10 09:49:40 +02:00
|
|
|
width, height = _rasterise(context, _ship_collection(context), context.scene.aetheria_layout)
|
2026-10-08 19:35:47 +02:00
|
|
|
self.report({"INFO"}, f"Rasterised a {width}x{height} hull")
|
|
|
|
|
return {"FINISHED"}
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_flip_nose(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.flip_nose"
|
|
|
|
|
bl_label = "Flip Nose"
|
|
|
|
|
bl_description = "Turn the hull 180 degrees about Ship Root's Z axis, then rasterise it again"
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-10 09:49:40 +02:00
|
|
|
collection = _ship_collection(context)
|
|
|
|
|
state = context.scene.aetheria_layout
|
|
|
|
|
root, _ = _frame_inputs(context, collection, state)
|
2026-10-08 19:35:47 +02:00
|
|
|
turn = root.matrix_world @ Matrix.Rotation(math.pi, 4, "Z") @ root.matrix_world.inverted()
|
|
|
|
|
for child in root.children:
|
|
|
|
|
child.matrix_world = turn @ child.matrix_world
|
2026-10-10 09:49:40 +02:00
|
|
|
try:
|
|
|
|
|
_rasterise(context, collection, state)
|
|
|
|
|
except Exception:
|
|
|
|
|
for child in root.children: # a half turn is its own inverse
|
|
|
|
|
child.matrix_world = turn @ child.matrix_world
|
|
|
|
|
raise
|
2026-10-08 19:35:47 +02:00
|
|
|
self.report({"INFO"}, "Turned the nose about Ship Root")
|
|
|
|
|
return {"FINISHED"}
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
BAKE_SAMPLES = 1 # one sample per texel: the maps are a starting point and the smoke runs on the CPU
|
|
|
|
|
BAKE_MAPS = (("albedo", "sRGB", {"type": "DIFFUSE", "pass_filter": {"COLOR"}}),
|
|
|
|
|
("normal", "Non-Color", {"type": "NORMAL", "normal_space": "TANGENT"}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _principled(material):
|
|
|
|
|
tree = material.node_tree if material else None
|
|
|
|
|
return next((node for node in tree.nodes if node.type == "BSDF_PRINCIPLED"), None) if tree else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _wired_image(material, kind):
|
|
|
|
|
"""The Image Texture node already feeding the material's Principled Base Color (albedo) or, through a Normal Map
|
|
|
|
|
node, its Normal."""
|
|
|
|
|
socket = _principled(material).inputs["Base Color" if kind == "albedo" else "Normal"]
|
|
|
|
|
node = socket.links[0].from_node if socket.is_linked else None
|
|
|
|
|
if kind == "normal" and node is not None and node.type == "NORMAL_MAP":
|
|
|
|
|
colour = node.inputs["Color"]
|
|
|
|
|
node = colour.links[0].from_node if colour.is_linked else None
|
|
|
|
|
return node if node is not None and node.type == "TEX_IMAGE" else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _select_only(context, objects):
|
|
|
|
|
keep = {obj.name for obj in objects}
|
|
|
|
|
for obj in context.view_layer.objects:
|
|
|
|
|
obj.select_set(obj.name in keep)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _refuse_selecting(context, offenders, message):
|
|
|
|
|
"""Selects the offenders and refuses with message, which names a count and never an object."""
|
|
|
|
|
_select_only(context, offenders)
|
2026-10-13 01:47:23 +02:00
|
|
|
raise Refusal(message)
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _bake_inputs(context, collection):
|
|
|
|
|
"""The ship ID, the Source meshes and the selected render meshes Bake From Source works on, or the refusal that
|
|
|
|
|
stops it before anything changes."""
|
|
|
|
|
if context.mode != "OBJECT":
|
2026-10-13 01:47:23 +02:00
|
|
|
raise Refusal("Switch to Object mode before baking")
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
source = _child(collection, SOURCE)
|
|
|
|
|
sources = _meshes(source.all_objects) if source else []
|
|
|
|
|
if _ship_root(collection) is None or not sources:
|
2026-10-13 01:47:23 +02:00
|
|
|
raise Refusal("Bake From Source needs a Ship Root and a mesh in Source; run New Ship first")
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
layer = context.view_layer
|
|
|
|
|
hidden = [obj for obj in sources if obj.name not in layer.objects or obj.hide_get()]
|
|
|
|
|
if hidden:
|
|
|
|
|
_refuse_selecting(context, [obj for obj in hidden if obj.name in layer.objects],
|
|
|
|
|
f"{len(hidden)} Source meshes are hidden or outside the view layer; show them to bake")
|
|
|
|
|
targets = [obj for obj in _own_meshes(collection) if obj.name in layer.objects and obj.select_get()]
|
|
|
|
|
if not targets:
|
2026-10-13 01:47:23 +02:00
|
|
|
raise Refusal("Select the render meshes to bake onto")
|
|
|
|
|
shared = {obj.data for obj in sources}
|
|
|
|
|
linked = [obj for obj in targets if obj.data in shared]
|
|
|
|
|
if linked: # a material slot belongs to the mesh data, so the bake would repoint Source's own slot
|
|
|
|
|
_refuse_selecting(context, linked, f"{len(linked)} selected meshes share their mesh data with a Source mesh; make them single user first")
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
flat = [obj for obj in targets if not obj.data.uv_layers]
|
|
|
|
|
if flat:
|
|
|
|
|
_refuse_selecting(context, flat, f"{len(flat)} selected meshes have no UV layer; unwrap them first")
|
|
|
|
|
bare = [obj for obj in targets if any(_principled(slot.material) is None for slot in obj.material_slots)]
|
|
|
|
|
if bare:
|
|
|
|
|
_refuse_selecting(context, bare, f"{len(bare)} selected meshes have a material without a Principled BSDF")
|
|
|
|
|
return collection["aetheria.id"], sources, targets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _target_materials(targets):
|
|
|
|
|
return list({slot.material.name: slot.material for obj in targets for slot in obj.material_slots}.values())
|
|
|
|
|
|
|
|
|
|
|
2026-10-13 01:10:34 +02:00
|
|
|
def _give_own_materials(sources, targets, undo):
|
|
|
|
|
"""Gives each target slot that holds a material a Source mesh also uses a copy of its own, so the bake rewires nothing
|
|
|
|
|
Source owns; returns how many materials were copied. undo gets the steps that put the slots back."""
|
|
|
|
|
owned = {slot.material.name for obj in sources for slot in obj.material_slots if slot.material}
|
|
|
|
|
copies = {}
|
|
|
|
|
for obj in targets:
|
|
|
|
|
for index, slot in enumerate(obj.material_slots):
|
|
|
|
|
original = slot.material
|
|
|
|
|
if original is None or original.name not in owned:
|
|
|
|
|
continue
|
|
|
|
|
if original.name not in copies:
|
|
|
|
|
copies[original.name] = original.copy()
|
|
|
|
|
undo.append(partial(_remove_material, copies[original.name].name))
|
|
|
|
|
undo.append(partial(_set_slot_material, obj.name, index, original.name))
|
|
|
|
|
slot.material = copies[original.name]
|
|
|
|
|
return len(copies)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _set_slot_material(object_name, index, material_name):
|
|
|
|
|
bpy.data.objects[object_name].material_slots[index].material = bpy.data.materials[material_name]
|
|
|
|
|
|
|
|
|
|
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
def _hold(owner, name, value, restore):
|
|
|
|
|
"""Sets owner.name to value for the bake; restore gets the step that puts the old value back."""
|
|
|
|
|
restore.append(partial(setattr, owner, name, getattr(owner, name)))
|
|
|
|
|
setattr(owner, name, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _isolate_sources(sources, restore):
|
|
|
|
|
"""The Source materials as the bake should see them: Metallic and Transmission Weight at 0, links into them muted."""
|
|
|
|
|
seen = set()
|
|
|
|
|
for obj in sources:
|
|
|
|
|
for slot in obj.material_slots:
|
|
|
|
|
for node in (slot.material.node_tree.nodes if slot.material and slot.material.node_tree else ()):
|
|
|
|
|
if node.type != "BSDF_PRINCIPLED" or (slot.material.name, node.name) in seen:
|
|
|
|
|
continue
|
|
|
|
|
seen.add((slot.material.name, node.name))
|
|
|
|
|
for name in ("Metallic", "Transmission Weight"):
|
|
|
|
|
socket = node.inputs[name]
|
|
|
|
|
for link in socket.links:
|
|
|
|
|
_hold(link, "is_muted", True, restore)
|
|
|
|
|
_hold(socket, "default_value", 0.0, restore)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _remove_image(name):
|
|
|
|
|
image = bpy.data.images.get(name)
|
|
|
|
|
if image:
|
|
|
|
|
bpy.data.images.remove(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _remove_node(material_name, node_name):
|
|
|
|
|
material = bpy.data.materials.get(material_name)
|
|
|
|
|
node = material.node_tree.nodes.get(node_name) if material and material.node_tree else None
|
|
|
|
|
if node:
|
|
|
|
|
material.node_tree.nodes.remove(node)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _remove_material(name):
|
|
|
|
|
material = bpy.data.materials.get(name)
|
|
|
|
|
if material:
|
|
|
|
|
bpy.data.materials.remove(material)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _clear_materials(mesh_name):
|
|
|
|
|
bpy.data.meshes[mesh_name].materials.clear()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _restore_link(material_name, node_name, input_name, previous):
|
|
|
|
|
tree = bpy.data.materials[material_name].node_tree
|
|
|
|
|
socket = tree.nodes[node_name].inputs[input_name]
|
|
|
|
|
for link in list(socket.links):
|
|
|
|
|
tree.links.remove(link)
|
|
|
|
|
if previous:
|
|
|
|
|
tree.links.new(next(out for out in tree.nodes[previous[0]].outputs if out.identifier == previous[1]), socket)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _set_node_image(material_name, node_name, image_name):
|
|
|
|
|
bpy.data.materials[material_name].node_tree.nodes[node_name].image = bpy.data.images.get(image_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _link_into(material, node, input_name, source, undo):
|
|
|
|
|
socket = node.inputs[input_name]
|
|
|
|
|
previous = (socket.links[0].from_node.name, socket.links[0].from_socket.identifier) if socket.is_linked else None
|
|
|
|
|
material.node_tree.links.new(source, socket)
|
|
|
|
|
undo.append(partial(_restore_link, material.name, node.name, input_name, previous))
|
|
|
|
|
|
|
|
|
|
|
2026-10-13 01:10:34 +02:00
|
|
|
def _refuse_taken_names(ship_id, targets):
|
2026-10-13 01:47:23 +02:00
|
|
|
"""The ship's pair is {ship_id}.albedo and {ship_id}.normal and there is one pair. An image holding a name must be one
|
|
|
|
|
this bake replaces (used only by the selected meshes' wiring) or one nothing uses; returns those images, which the bake
|
|
|
|
|
frees before it names its own. Any other holder refuses."""
|
2026-10-13 01:10:34 +02:00
|
|
|
materials = _target_materials(targets)
|
2026-10-13 01:47:23 +02:00
|
|
|
holders = []
|
2026-10-13 01:10:34 +02:00
|
|
|
for kind, _, _ in BAKE_MAPS:
|
|
|
|
|
image = bpy.data.images.get(f"{ship_id}.{kind}")
|
2026-10-13 01:47:23 +02:00
|
|
|
if image is None:
|
|
|
|
|
continue
|
2026-10-13 01:10:34 +02:00
|
|
|
wired = [node for node in (_wired_image(material, kind) for material in materials) if node is not None and node.image == image]
|
2026-10-13 01:47:23 +02:00
|
|
|
if image.use_fake_user or image.users != len(wired):
|
|
|
|
|
raise Refusal("The ship's baked image names are held by images this bake does not replace; select every "
|
2026-10-13 01:10:34 +02:00
|
|
|
"mesh that uses them, or rename the other images")
|
2026-10-13 01:47:23 +02:00
|
|
|
holders.append(image)
|
|
|
|
|
return holders
|
2026-10-13 01:10:34 +02:00
|
|
|
|
|
|
|
|
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
def _bake_map(context, sources, targets, settings, extrusion, max_distance, nodes):
|
|
|
|
|
"""Bakes one map from the Source meshes onto every target, the first target clearing the image and the later ones
|
|
|
|
|
adding to it. nodes maps a material's name to the Image Texture node that holds this map's image. This is the add-on's
|
|
|
|
|
only bake."""
|
|
|
|
|
layer = context.view_layer
|
|
|
|
|
for index, target in enumerate(targets):
|
|
|
|
|
_select_only(context, sources + [target])
|
|
|
|
|
layer.objects.active = target
|
|
|
|
|
for slot in target.material_slots:
|
|
|
|
|
slot.material.node_tree.nodes.active = nodes[slot.material.name]
|
2026-10-13 01:47:23 +02:00
|
|
|
bpy.ops.object.bake(
|
|
|
|
|
use_selected_to_active=True, cage_extrusion=extrusion, max_ray_distance=max_distance, use_clear=index == 0,
|
|
|
|
|
**settings)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _settle_images(ship_id, images, stale):
|
|
|
|
|
"""The commit's last step: frees the images the bake replaced and the unused ones that held the pair's names, then
|
|
|
|
|
names the new images {ship_id}.albedo and {ship_id}.normal."""
|
|
|
|
|
for image in {image.name: image for image in stale}.values(): # named before any is removed
|
|
|
|
|
if image.users == 0:
|
|
|
|
|
bpy.data.images.remove(image)
|
|
|
|
|
for kind, image in images.items():
|
|
|
|
|
image.name = f"{ship_id}.{kind}"
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _bake_from_source(context, collection, replace):
|
|
|
|
|
"""Bakes the Source meshes onto the selected render meshes' UV0 as one albedo and one normal image per ship, and wires
|
|
|
|
|
them into every material of those meshes. The images are new and are wired only after both bakes finish; any failure
|
|
|
|
|
puts every changed value back and removes what was made. The Source materials, scene settings and selection are as they
|
|
|
|
|
were afterwards."""
|
|
|
|
|
ship_id, sources, targets = _bake_inputs(context, collection)
|
|
|
|
|
if not replace and any(_wired_image(material, kind) for material in _target_materials(targets) for kind, _, _ in BAKE_MAPS):
|
2026-10-13 01:47:23 +02:00
|
|
|
raise Refusal("Selected meshes already have baked images; confirm the replace")
|
|
|
|
|
holders = _refuse_taken_names(ship_id, targets)
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
addon = context.preferences.addons[__package__].preferences
|
|
|
|
|
scene, layer = context.scene, context.view_layer
|
|
|
|
|
previous_selection = [obj for obj in layer.objects if obj.select_get()]
|
|
|
|
|
previous_active = layer.objects.active
|
|
|
|
|
restore, undo, replaced = [], [], {}
|
|
|
|
|
restore.append(lambda: ([obj.select_set(obj in previous_selection) for obj in layer.objects],
|
|
|
|
|
setattr(layer.objects, "active", previous_active)))
|
|
|
|
|
try:
|
|
|
|
|
_hold(scene.render, "engine", "CYCLES", restore)
|
|
|
|
|
_hold(scene.cycles, "samples", BAKE_SAMPLES, restore)
|
|
|
|
|
_hold(scene.cycles, "device", "CPU", restore)
|
2026-10-13 01:10:34 +02:00
|
|
|
copied = _give_own_materials(sources, targets, undo)
|
|
|
|
|
for obj in targets: # her unwrap is UV0, whichever layer is active
|
|
|
|
|
_hold(obj.data.uv_layers, "active_index", 0, restore)
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
_isolate_sources(sources, restore)
|
|
|
|
|
images = {}
|
|
|
|
|
for kind, space, _ in BAKE_MAPS:
|
|
|
|
|
image = bpy.data.images.new(f"{ship_id}.{kind}", addon.bake_size, addon.bake_size, alpha=False)
|
|
|
|
|
undo.append(partial(_remove_image, image.name))
|
|
|
|
|
image.colorspace_settings.name = space
|
|
|
|
|
images[kind] = image
|
|
|
|
|
hull = None
|
|
|
|
|
for obj in targets:
|
|
|
|
|
if not obj.data.materials:
|
|
|
|
|
if hull is None:
|
|
|
|
|
hull = bpy.data.materials.new(f"{ship_id}.hull")
|
|
|
|
|
hull.use_nodes = True
|
|
|
|
|
undo.append(partial(_remove_material, hull.name))
|
|
|
|
|
obj.data.materials.append(hull)
|
|
|
|
|
undo.append(partial(_clear_materials, obj.data.name))
|
|
|
|
|
materials = _target_materials(targets)
|
|
|
|
|
held = {kind: {} for kind, _, _ in BAKE_MAPS}
|
|
|
|
|
for material in materials:
|
|
|
|
|
for kind, _, _ in BAKE_MAPS:
|
|
|
|
|
node = material.node_tree.nodes.new("ShaderNodeTexImage")
|
|
|
|
|
node.image, node.label = images[kind], f"Baked {kind}"
|
|
|
|
|
undo.append(partial(_remove_node, material.name, node.name))
|
|
|
|
|
held[kind][material.name] = node
|
|
|
|
|
for kind, _, settings in BAKE_MAPS:
|
|
|
|
|
_bake_map(context, sources, targets, settings, addon.bake_cage_extrusion, addon.bake_max_ray_distance, held[kind])
|
|
|
|
|
for image in images.values():
|
|
|
|
|
image.pack()
|
|
|
|
|
for material in materials: # the commit: every step is in undo
|
|
|
|
|
bsdf = _principled(material)
|
|
|
|
|
for kind, _, _ in BAKE_MAPS:
|
|
|
|
|
node = held[kind][material.name]
|
|
|
|
|
old = _wired_image(material, kind)
|
|
|
|
|
if old is not None:
|
|
|
|
|
if old.image:
|
|
|
|
|
replaced[old.image.name] = old.image
|
|
|
|
|
undo.append(partial(_set_node_image, material.name, old.name, old.image.name if old.image else None))
|
|
|
|
|
old.image = images[kind]
|
|
|
|
|
_remove_node(material.name, node.name)
|
|
|
|
|
elif kind == "albedo":
|
|
|
|
|
_link_into(material, bsdf, "Base Color", node.outputs["Color"], undo)
|
|
|
|
|
else:
|
|
|
|
|
normal = material.node_tree.nodes.new("ShaderNodeNormalMap")
|
|
|
|
|
undo.append(partial(_remove_node, material.name, normal.name))
|
|
|
|
|
material.node_tree.links.new(node.outputs["Color"], normal.inputs["Color"])
|
|
|
|
|
_link_into(material, bsdf, "Normal", normal.outputs["Normal"], undo)
|
2026-10-13 01:47:23 +02:00
|
|
|
except BaseException:
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
for step in reversed(undo):
|
|
|
|
|
step()
|
|
|
|
|
raise
|
|
|
|
|
finally:
|
|
|
|
|
for step in reversed(restore):
|
|
|
|
|
step()
|
2026-10-13 01:47:23 +02:00
|
|
|
_settle_images(ship_id, images, [*replaced.values(), *holders])
|
2026-10-13 01:10:34 +02:00
|
|
|
return copied
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_bake_from_source(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.bake_from_source"
|
|
|
|
|
bl_label = "Bake From Source"
|
|
|
|
|
bl_description = ("Bake the Source meshes' colour and normal onto the selected render meshes' UV0 as the ship's albedo "
|
|
|
|
|
"and normal maps, and wire them into their materials. Nothing rebakes unless you press this")
|
|
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
replace: bpy.props.BoolProperty(
|
|
|
|
|
name="Replace", default=False, options={"SKIP_SAVE"},
|
|
|
|
|
description="Replace the images the selected meshes' materials already wire into Base Color and Normal")
|
|
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
|
try:
|
|
|
|
|
_, _, targets = _bake_inputs(context, _ship_collection(context))
|
2026-10-13 01:47:23 +02:00
|
|
|
except Exception:
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
return self.execute(context) # the same refusal, reported
|
|
|
|
|
if any(_wired_image(material, kind) for material in _target_materials(targets) for kind, _, _ in BAKE_MAPS):
|
|
|
|
|
self.replace = True
|
|
|
|
|
return context.window_manager.invoke_confirm(
|
|
|
|
|
self, event, message="The selected meshes already have baked images. Replace them?")
|
|
|
|
|
return self.execute(context)
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
try:
|
2026-10-13 01:10:34 +02:00
|
|
|
copied = _bake_from_source(context, _ship_collection(context), self.replace)
|
|
|
|
|
self.report({"INFO"}, "Baked the albedo and normal maps from Source" + (
|
2026-10-13 01:47:23 +02:00
|
|
|
f"; materials shared with Source, copied for the render meshes: {copied}" if copied else ""))
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
return {"FINISHED"}
|
2026-10-13 01:47:23 +02:00
|
|
|
except Exception as exc: # the one place a bake's error becomes report text
|
|
|
|
|
if type(exc) is Refusal:
|
|
|
|
|
return _refuse(self, exc)
|
|
|
|
|
traceback.print_exception(exc) # whatever else Blender raised names objects and images
|
|
|
|
|
self.report({"ERROR"}, "The bake failed; its message is in the system console")
|
|
|
|
|
return {"CANCELLED"}
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
|
|
|
|
|
|
2026-10-08 19:35:47 +02:00
|
|
|
def _new_ship(context, ship_id, name, reference, length):
|
2026-10-10 09:49:40 +02:00
|
|
|
"""Sets the active collection up as a pending ship: binds it, moves its meshes into Source under a Ship Root, turns
|
2026-10-10 12:26:42 +02:00
|
|
|
them nose to -Y, sizes them to length cells, fills the layout buffer and draws the Grid. The meshes keep their data:
|
|
|
|
|
the placement is the objects' own matrix, so modifiers act as the author saw them and the cells are the ones checked
|
|
|
|
|
here. Every check and the rasterising come first; after the bind nothing can refuse. Nothing is written to disk: the
|
|
|
|
|
first Save creates the file."""
|
2026-10-10 09:49:40 +02:00
|
|
|
if not valid_ship_id(ship_id):
|
|
|
|
|
raise ValueError("The ship ID must use lower-case letters, digits, dots, underscores or hyphens, must not end "
|
|
|
|
|
"in a dot, and must not be a Windows device name")
|
2026-10-08 19:35:47 +02:00
|
|
|
if not name.strip() or not reference.strip():
|
|
|
|
|
raise ValueError("Give the ship a display name and a reference hull")
|
2026-10-10 09:49:40 +02:00
|
|
|
path = _game_folder(context, bpy.data.filepath or None) / "GameData" / "Mods" / ship_id / "ship.cc"
|
|
|
|
|
if path.exists():
|
2026-10-10 12:56:58 +02:00
|
|
|
raise ValueError("A ship with this ID already exists under GameData/Mods (Ctrl+Z past a first Save leaves it "
|
|
|
|
|
"there); use Bind Ship Collection with its ship.cc, then Load Layout, or give the new ship "
|
|
|
|
|
"another ID")
|
2026-10-10 09:49:40 +02:00
|
|
|
collection = _ship_collection(context, unbound_ok=True)
|
|
|
|
|
if collection.get("aetheria.id") is not None or _ship_root(collection) is not None:
|
|
|
|
|
raise ValueError("The collection is already a ship")
|
2026-10-08 19:35:47 +02:00
|
|
|
meshes = _meshes(collection.objects)
|
|
|
|
|
if not meshes:
|
2026-10-10 09:49:40 +02:00
|
|
|
raise ValueError("The ship collection holds no mesh objects to make a ship from")
|
|
|
|
|
if len(_meshes(collection.all_objects)) != len(meshes):
|
|
|
|
|
raise ValueError("The ship collection's meshes must sit directly in it, not in child collections")
|
2026-10-08 19:35:47 +02:00
|
|
|
worlds = {obj: obj.matrix_world.copy() for obj in meshes}
|
|
|
|
|
depsgraph = context.evaluated_depsgraph_get()
|
|
|
|
|
points = numpy.vstack([_world_mesh(obj, depsgraph, worlds[obj])[0] for obj in meshes])
|
|
|
|
|
extent_x, extent_y = (float(v) for v in numpy.ptp(points, axis=0)[:2])
|
|
|
|
|
longest = max(extent_x, extent_y)
|
|
|
|
|
if longest <= 0:
|
|
|
|
|
raise ValueError("The hull meshes have no horizontal extent")
|
|
|
|
|
scale = length * hull_grid.CELL_SIZE / longest
|
|
|
|
|
transform = Matrix.Diagonal((scale, scale, scale, 1.0))
|
|
|
|
|
if extent_x > extent_y:
|
|
|
|
|
transform = transform @ Matrix.Rotation(math.pi / 2, 4, "Z")
|
2026-10-10 12:56:58 +02:00
|
|
|
placed = {obj: _held(transform @ worlds[obj]) for obj in meshes}
|
2026-10-10 12:26:42 +02:00
|
|
|
width, height, cells, origin = hull_grid.rasterise(_triangles_xy(depsgraph, [(obj, placed[obj]) for obj in meshes]))
|
2026-10-10 09:49:40 +02:00
|
|
|
_bind_collection(collection, str(path), ship_id, [name, reference])
|
2026-10-08 19:35:47 +02:00
|
|
|
source = _child_or_new(collection, SOURCE, SOURCE)
|
|
|
|
|
root = bpy.data.objects.new(SHIP_ROOT, None)
|
|
|
|
|
root["aetheria.ship_root"] = True
|
|
|
|
|
collection.objects.link(root)
|
|
|
|
|
for obj in meshes:
|
|
|
|
|
collection.objects.unlink(obj)
|
|
|
|
|
source.objects.link(obj)
|
|
|
|
|
obj.parent = root
|
|
|
|
|
obj.matrix_parent_inverse = Matrix.Identity(4)
|
2026-10-10 12:26:42 +02:00
|
|
|
obj.matrix_world = placed[obj]
|
2026-10-10 09:49:40 +02:00
|
|
|
state = context.scene.aetheria_layout
|
|
|
|
|
state.ship_id = ship_id
|
|
|
|
|
state.ship_cc = bpy.path.abspath(collection["aetheria.ship_cc"])
|
|
|
|
|
state.revision = ""
|
|
|
|
|
state.hardpoints.clear()
|
2026-10-10 12:26:42 +02:00
|
|
|
_place_grid(collection, state, width, height, cells, origin)
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AETHERIA_OT_new_ship(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.new_ship"
|
|
|
|
|
bl_label = "New Ship"
|
2026-10-10 09:49:40 +02:00
|
|
|
bl_description = ("Set the active collection up as a new ship: nose toward -Y, sized to the length, with a drafted "
|
|
|
|
|
"grid. Nothing is written until Save Layout")
|
2026-10-08 19:35:47 +02:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
scene = context.scene
|
|
|
|
|
try:
|
2026-10-10 09:49:40 +02:00
|
|
|
_new_ship(context, scene.aetheria_new_ship_id, scene.aetheria_new_ship_name,
|
|
|
|
|
scene.aetheria_new_ship_like, scene.aetheria_new_ship_length)
|
|
|
|
|
self.report({"INFO"}, "New ship set up; Save Layout creates its file")
|
2026-10-08 19:35:47 +02:00
|
|
|
return {"FINISHED"}
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
return _refuse(self, exc)
|
2026-10-08 19:35:47 +02:00
|
|
|
|
|
|
|
|
|
2026-10-10 21:02:22 +02:00
|
|
|
def _ship_centre(context, path):
|
|
|
|
|
"""The saved Shape's centre of mass in cell coordinates, from AetherDb: C# owns it."""
|
|
|
|
|
code, output = _aetherdb(context, "centre", path, ship_cc=path)
|
|
|
|
|
try:
|
|
|
|
|
parts = output.split()
|
|
|
|
|
if code != 0 or len(parts) != 2:
|
|
|
|
|
raise ValueError
|
|
|
|
|
centre = (float(parts[0]), float(parts[1]))
|
|
|
|
|
if not all(map(math.isfinite, centre)):
|
|
|
|
|
raise ValueError
|
|
|
|
|
except ValueError:
|
|
|
|
|
print(output)
|
|
|
|
|
raise RuntimeError("AetherDb could not report the ship centre; its message is in the system console") from None
|
|
|
|
|
return centre
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _frame_ship(context, collection, root, path, saved_shape):
|
|
|
|
|
"""Package's frame step for a ship with a Ship Root: the grid must match the saved layout, then the anchors are
|
|
|
|
|
regenerated and Ship Root is moved last, so that the saved Shape's centre of mass sits at the world origin. The
|
|
|
|
|
anchors are read from the children's world matrices, so they are made before the move."""
|
|
|
|
|
origin = collection.get("aetheria.grid_origin")
|
|
|
|
|
if origin is None or len(origin) != 4 or (int(origin[2]), int(origin[3])) != (saved_shape[0], saved_shape[1]):
|
|
|
|
|
raise ValueError("Rasterise again: the grid no longer matches the saved layout")
|
|
|
|
|
centre = _ship_centre(context, path)
|
|
|
|
|
_regenerate_anchors(context, collection, root)
|
|
|
|
|
_recentre(root, hull_grid.cell_centre((float(origin[0]), float(origin[1])), centre[0], centre[1]))
|
|
|
|
|
|
|
|
|
|
|
2026-10-19 00:20:00 +02:00
|
|
|
HULL_MAKER = "aetheria.hull_maker" # on the collection: the Faction key of the language Build judged the hull against
|
2026-10-22 15:59:56 +02:00
|
|
|
HULL_LINES = "aetheria.hull_lines" # on the collection: [{layer, cyclic, points (flat), rgba}] the hull source's kit drew, in Ship Root's frame
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
HULL_BUILT = "aetheria.hull_built" # on the collection: {object name: fingerprint} of what Build From Hull Source made
|
2026-10-19 13:11:09 +02:00
|
|
|
HULL_AGENT = "agent" # HS rows H5, H7-H10, H12: Build's judged body or record governs; Package checks the maker
|
|
|
|
|
HULL_ART = "art" # HS rows H4, H6, H11: her meshes replace Build's; Package ships them and retires the hull source
|
|
|
|
|
HULL_UNBUILT = "unbuilt" # HS row H3: an agent's hull.scad with nothing built and none of her art
|
|
|
|
|
HULL_PLAIN = "plain" # HS rows H1, H2: no agent hull; Package checks nothing and retires nothing
|
2026-10-18 22:00:15 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
def _fingerprint(obj):
|
|
|
|
|
"""What Build made of obj, as it stands: its place under its parent, the anchor properties and, for a mesh, its geometry.
|
|
|
|
|
A copy has another name and an edit changes this, so neither is taken for Build's own."""
|
|
|
|
|
values = [obj.parent.name if obj.parent else "", tuple(obj.location), tuple(obj.rotation_euler), tuple(obj.scale),
|
|
|
|
|
obj.get("aetheria.role", ""), obj.get("aetheria.id", ""), obj.get("aetheria.order", 0)]
|
|
|
|
|
if obj.type == "MESH":
|
|
|
|
|
values += [[tuple(v.co) for v in obj.data.vertices], [tuple(p.vertices) for p in obj.data.polygons]]
|
|
|
|
|
return hull_source.fingerprint(*values)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _hull_built(collection):
|
|
|
|
|
"""(untouched, changed): Build's objects found in the collection as it made them, and those it made that were edited.
|
|
|
|
|
The record is the only owner: an object is Build's when its name and fingerprint are the ones recorded."""
|
|
|
|
|
record = collection.get(HULL_BUILT)
|
|
|
|
|
record = record.to_dict() if record is not None else {}
|
|
|
|
|
present = {obj.name: obj for obj in collection.all_objects if obj.name in record}
|
|
|
|
|
untouched = [obj for name, obj in present.items() if _fingerprint(obj) == record[name]]
|
|
|
|
|
return untouched, [obj for obj in present.values() if obj not in untouched]
|
2026-10-18 22:00:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
def _build_hull_source(context, collection):
|
2026-10-18 22:00:15 +02:00
|
|
|
"""Replaces the objects Build made before with the hull source's zone meshes, anchors and collider under Ship Root.
|
2026-10-22 01:03:27 +02:00
|
|
|
Refuses, before anything changes, when the source cannot be read, breaks a check of its faction's language (whose
|
|
|
|
|
proportions judge a hull whose ship.cc HullData.HullType is Ship, and no other), its zones overflow the layout grid,
|
|
|
|
|
or the collection holds render meshes Build did not make (operator art: Build never overwrites it). Writes no layout
|
|
|
|
|
row."""
|
2026-10-18 22:00:15 +02:00
|
|
|
source = _hull_source_file(collection)
|
|
|
|
|
if source is None:
|
|
|
|
|
raise ValueError("The bound package holds no hull.scad")
|
|
|
|
|
root = _ship_root(collection)
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
untouched, changed = _hull_built(collection)
|
2026-10-18 22:00:15 +02:00
|
|
|
if root is not None:
|
|
|
|
|
_refuse_loose_meshes(context, collection)
|
2026-10-19 00:17:18 +02:00
|
|
|
_refuse_shared_ids(context, collection)
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
theirs = [obj for obj in _own_meshes(collection) if obj not in untouched]
|
|
|
|
|
if theirs or changed:
|
|
|
|
|
raise ValueError("The collection holds meshes the hull source did not make, or objects it made that were "
|
|
|
|
|
"changed; Build From Hull Source replaces only what it made and nobody touched")
|
2026-10-18 22:00:15 +02:00
|
|
|
addon = context.preferences.addons.get(__package__)
|
|
|
|
|
executable = addon.preferences.openscad if addon and addon.preferences else DEFAULT_OPENSCAD
|
2026-10-22 01:03:27 +02:00
|
|
|
hull_type = read_hull_type(bpy.path.abspath(collection["aetheria.ship_cc"]), _brokkr_cultlib(context))
|
|
|
|
|
hull = hull_source.build(hull_source.openscad_runner(executable, source), hull_source.language_library(executable),
|
2026-10-22 15:59:56 +02:00
|
|
|
hull_type, hull_source.openscad_projector(executable))
|
2026-10-18 22:00:15 +02:00
|
|
|
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)
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
for obj in untouched:
|
2026-10-18 22:00:15 +02:00
|
|
|
_discard_object(obj)
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
made = []
|
2026-10-18 22:00:15 +02:00
|
|
|
|
|
|
|
|
def mark(obj):
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
made.append(obj)
|
2026-10-18 22:00:15 +02:00
|
|
|
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
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
collection[HULL_BUILT] = {obj.name: _fingerprint(obj) for obj in made}
|
2026-10-19 00:20:00 +02:00
|
|
|
collection[HULL_MAKER] = hull.languages[hull.brief.faction].maker
|
2026-10-22 15:59:56 +02:00
|
|
|
collection[HULL_LINES] = [{"layer": line.layer, "cyclic": line.cyclic, "points": [c for p in line.points for c in p],
|
|
|
|
|
"rgba": list(line.rgba())} for line in hull.lines]
|
2026-10-18 22:00:15 +02:00
|
|
|
return hull
|
|
|
|
|
|
|
|
|
|
|
2026-10-22 15:59:56 +02:00
|
|
|
def _schematic_lines(context, collection):
|
|
|
|
|
"""The ShipAuthoring.SchematicLines rows Package and Capture write, and the only source of them: her Grease Pencil
|
2026-10-22 16:55:50 +02:00
|
|
|
object if the collection has one (two or more are refused), else the lines Build recorded from the hull source's kit
|
|
|
|
|
while the hull is still Build's (not _hull_state art), mapped through Ship Root's matrix_world (so after _frame_ship,
|
|
|
|
|
the frame her strokes are captured in), else None and the slot is left as it is. Package alone clears the slot, at
|
|
|
|
|
the moment her art takes over."""
|
2026-10-22 15:59:56 +02:00
|
|
|
pencils = [obj for obj in collection.all_objects if obj.type == "GREASEPENCIL"]
|
|
|
|
|
if len(pencils) > 1:
|
|
|
|
|
raise ValueError("Keep one Grease Pencil object: it is the ship's schematic")
|
|
|
|
|
scene = context.scene
|
|
|
|
|
if pencils:
|
|
|
|
|
return capture_grease_pencil(pencils[0], context.evaluated_depsgraph_get(), scene.frame_current,
|
|
|
|
|
evaluated=scene.aetheria_capture_evaluated_lines)
|
|
|
|
|
record = collection.get(HULL_LINES)
|
2026-10-22 16:55:50 +02:00
|
|
|
if record is None or _hull_state(collection) == HULL_ART: # her art took over: Build's lines are a retired hull's
|
2026-10-22 15:59:56 +02:00
|
|
|
return None
|
|
|
|
|
root = _ship_root(collection)
|
|
|
|
|
world = root.matrix_world if root is not None else Matrix.Identity(4)
|
|
|
|
|
rows = []
|
|
|
|
|
for line in record:
|
|
|
|
|
flat = list(line["points"])
|
|
|
|
|
points = []
|
|
|
|
|
for x, y, z in zip(flat[0::3], flat[1::3], flat[2::3]):
|
|
|
|
|
points.extend(float(c) for c in world @ Vector((x, y, z)))
|
|
|
|
|
rows.append([line["layer"], "", points, None, None, bool(line["cyclic"]), [float(c) for c in line["rgba"]]])
|
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
2026-10-19 13:11:09 +02:00
|
|
|
def _hull_state(collection):
|
|
|
|
|
"""The one owner of a ship collection's hull state (map HS), decided in this order: an untouched Build zone mesh
|
|
|
|
|
keeps the hull agent's; her meshes beside Build's record or hull.scad make it art; then Build's record is agent,
|
|
|
|
|
hull.scad alone is unbuilt, and nothing is plain. _refuse_wrong_maker and _retire_hull_source read this and nothing
|
|
|
|
|
else to decide the regime; Build's own write-safety rule is a separate decision."""
|
Agent hulls: the faction file owns its language; Build owns what it recorded, not what is marked
hull_source.build reads the faction's and donor's language from factions/<faction>.scad run alone and only compares the
hull's own lang echo with it; a hull that reassigns, re-echoes or shadows a language fails a check.
Build records what it made on the collection by name and fingerprint instead of marking objects. A copy (another name) or an
edit (another fingerprint) is the author's: Build refuses and deletes nothing. Package retires hull.scad when render meshes
that are not Build's remain and no zone mesh of Build's does, so keeping Build's anchors and collider no longer blocks
takeover.
Unit tests cover the runner (arguments, exit status, OPENSCADPATH), non-string names, the width/length bound, own-zone
colours and the language ownership; the smoke pins world poses of mounts, emitters and emitter meshes (a mount turned 90
degrees included), the language attacks with the real OpenSCAD, copy and edit, Build after Package and the takeover.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 22:34:41 +02:00
|
|
|
untouched, _ = _hull_built(collection)
|
2026-10-19 13:11:09 +02:00
|
|
|
if any(obj.type == "MESH" and "aetheria.role" not in obj for obj in untouched):
|
|
|
|
|
return HULL_AGENT
|
|
|
|
|
built = HULL_MAKER in collection
|
|
|
|
|
source = _hull_source_file(collection) is not None
|
|
|
|
|
if _ship_root(collection) is not None and (built or source) and [
|
|
|
|
|
obj for obj in _own_meshes(collection) if obj not in untouched]:
|
|
|
|
|
return HULL_ART
|
|
|
|
|
if built:
|
|
|
|
|
return HULL_AGENT
|
|
|
|
|
return HULL_UNBUILT if source else HULL_PLAIN
|
2026-10-19 00:20:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _retire_hull_source(collection):
|
2026-10-19 13:11:09 +02:00
|
|
|
"""Deletes Build's records, and the package's hull.scad if it is still there, when the hull is in the art state
|
|
|
|
|
(_hull_state: H4, H6, H11). The anchors and collider she kept are hers from then on. A hull never built and without
|
|
|
|
|
her art, or built and packaged as it stands, keeps its source. Returns whether art took over."""
|
|
|
|
|
if _hull_state(collection) != HULL_ART:
|
2026-10-18 22:00:15 +02:00
|
|
|
return False
|
2026-10-19 01:44:15 +02:00
|
|
|
source = _hull_source_file(collection)
|
|
|
|
|
if source is not None:
|
|
|
|
|
source.unlink()
|
2026-10-22 15:59:56 +02:00
|
|
|
for record in (HULL_BUILT, HULL_MAKER, HULL_LINES):
|
2026-10-19 00:20:00 +02:00
|
|
|
if record in collection:
|
|
|
|
|
del collection[record]
|
2026-10-18 22:00:15 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
2026-10-19 00:20:00 +02:00
|
|
|
def _refuse_wrong_maker(collection, path, cultlib):
|
2026-10-19 13:11:09 +02:00
|
|
|
"""Refuses, before Package writes anything, a hull in the agent state unless the package holds a product and every
|
|
|
|
|
product is by the maker of the language Build judged the hull against (ruling hull-faction-is-product-maker), and
|
|
|
|
|
refuses an unbuilt hull.scad. _hull_state is the owner of which state this is; this function reads neither hull.scad
|
|
|
|
|
nor the record's presence to decide it. Her art and a plain hull need no product."""
|
|
|
|
|
state = _hull_state(collection)
|
|
|
|
|
if state == HULL_UNBUILT:
|
|
|
|
|
raise ValueError("Build From Hull Source first, or put your own meshes under Ship Root: Package needs the maker "
|
|
|
|
|
"Build judged the hull against")
|
|
|
|
|
if state != HULL_AGENT:
|
2026-10-19 00:20:00 +02:00
|
|
|
return
|
|
|
|
|
maker = collection.get(HULL_MAKER)
|
|
|
|
|
if maker is None:
|
|
|
|
|
raise ValueError("Build From Hull Source first: Package needs the maker it judged the hull against")
|
|
|
|
|
makers = product_makers(path, cultlib)
|
|
|
|
|
if not makers:
|
|
|
|
|
raise ValueError("The package has no product: add one for the hull's maker before packaging")
|
|
|
|
|
if any(product != maker for product in makers):
|
|
|
|
|
raise ValueError("A product in the package is not by the maker of the hull's faction language")
|
|
|
|
|
|
|
|
|
|
|
2026-10-18 22:00:15 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
2026-10-03 17:13:42 +02:00
|
|
|
class AETHERIA_OT_package_ship(bpy.types.Operator):
|
|
|
|
|
bl_idname = "aetheria.package_ship"
|
|
|
|
|
bl_label = "Package Ship"
|
2026-10-10 21:02:22 +02:00
|
|
|
bl_description = ("Put the grid's centre of mass at the world origin, derive the missing map icon, shield and "
|
2026-10-22 15:59:56 +02:00
|
|
|
"tractor, write the anchors and ship.glb from the bound collection, capture its schematic lines, and "
|
2026-10-10 21:02:22 +02:00
|
|
|
"run AetherDb's validator")
|
2026-10-03 17:13:42 +02:00
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
scene = context.scene
|
|
|
|
|
try:
|
|
|
|
|
collection, path = _layout_path(context)
|
2026-10-10 09:49:40 +02:00
|
|
|
if collection.get("aetheria.pending"):
|
|
|
|
|
raise ValueError("Save Layout first")
|
|
|
|
|
_refuse_loose_meshes(context, collection)
|
2026-10-19 00:17:18 +02:00
|
|
|
_refuse_shared_ids(context, collection)
|
2026-10-03 17:13:42 +02:00
|
|
|
cultlib = _brokkr_cultlib(context)
|
2026-10-19 00:20:00 +02:00
|
|
|
_refuse_wrong_maker(collection, path, cultlib)
|
2026-10-03 17:13:42 +02:00
|
|
|
ship_id = collection["aetheria.id"]
|
2026-10-10 09:49:40 +02:00
|
|
|
state = scene.aetheria_layout
|
2026-10-10 21:02:22 +02:00
|
|
|
saved_shape, saved_rows, _ = read_layout(path, cultlib)
|
2026-10-10 09:49:40 +02:00
|
|
|
if state.ship_id == ship_id and state.ship_cc == path:
|
|
|
|
|
shape, rows = _encode_buffer(state)
|
|
|
|
|
if layout_revision(shape, rows) != layout_revision(
|
|
|
|
|
saved_shape, [row[:len(HARDPOINT_MEMBERS)] for row in saved_rows]):
|
|
|
|
|
raise ValueError("Save Layout first")
|
2026-10-03 17:13:42 +02:00
|
|
|
if read(path, cultlib).ship.body[0] != ship_id:
|
|
|
|
|
raise ValueError("The bound collection ID does not match its .cc ship ID")
|
2026-10-10 21:02:22 +02:00
|
|
|
root = _ship_root(collection)
|
|
|
|
|
if root is not None:
|
|
|
|
|
_frame_ship(context, collection, root, path, saved_shape)
|
2026-10-03 17:13:42 +02:00
|
|
|
anchors = _anchors(collection)
|
|
|
|
|
_export_glb(context, collection, str(Path(path).with_name(MODEL_ASSET)))
|
|
|
|
|
replace_visual(path, cultlib, ship_id, MODEL_ASSET, anchors)
|
2026-10-22 15:59:56 +02:00
|
|
|
lines = _schematic_lines(context, collection)
|
|
|
|
|
if lines is not None:
|
|
|
|
|
replace_lines(path, cultlib, lines)
|
2026-10-22 16:55:50 +02:00
|
|
|
elif _hull_state(collection) == HULL_ART: # the lines in the slot are the retired hull's, not hers
|
|
|
|
|
clear_lines(path, cultlib)
|
2026-10-10 06:53:03 +02:00
|
|
|
code, message = _aetherdb(context, "validate", path, ship_cc=path)
|
2026-10-10 09:49:40 +02:00
|
|
|
except _EXPECTED as exc:
|
|
|
|
|
scene.aetheria_package_report = f"Package failed: {_failure_text(exc)}"
|
2026-10-03 17:13:42 +02:00
|
|
|
self.report({"ERROR"}, scene.aetheria_package_report)
|
|
|
|
|
return {"CANCELLED"}
|
2026-10-10 12:20:41 +02:00
|
|
|
if message:
|
|
|
|
|
print(message)
|
2026-10-03 17:13:42 +02:00
|
|
|
if code != 0:
|
2026-10-10 12:20:41 +02:00
|
|
|
scene.aetheria_package_report = (f"Packaged {len(anchors)} anchors; the validator refused the ship; "
|
|
|
|
|
"its message is in the system console")
|
|
|
|
|
self.report({"ERROR"}, scene.aetheria_package_report)
|
2026-10-03 17:13:42 +02:00
|
|
|
return {"CANCELLED"}
|
2026-10-10 12:20:41 +02:00
|
|
|
scene.aetheria_package_report = f"Packaged {len(anchors)} anchors; the validator accepted the ship"
|
2026-10-18 22:00:15 +02:00
|
|
|
if _retire_hull_source(collection):
|
2026-10-19 13:11:09 +02:00
|
|
|
scene.aetheria_package_report += "; retired the agent hull source: this package ships your art"
|
2026-10-03 17:13:42 +02:00
|
|
|
self.report({"INFO"}, scene.aetheria_package_report)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
2026-09-26 18:14:36 +02:00
|
|
|
class AETHERIA_PT_ship(bpy.types.Panel):
|
|
|
|
|
bl_label = "Aetheria Ship"
|
|
|
|
|
bl_idname = "AETHERIA_PT_ship"
|
|
|
|
|
bl_space_type = "VIEW_3D"
|
|
|
|
|
bl_region_type = "UI"
|
|
|
|
|
bl_category = "Brokkr"
|
|
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
|
layout = self.layout
|
2026-10-08 19:35:47 +02:00
|
|
|
new = layout.box()
|
|
|
|
|
new.label(text="New Ship")
|
|
|
|
|
for prop in ("aetheria_new_ship_id", "aetheria_new_ship_name", "aetheria_new_ship_like",
|
|
|
|
|
"aetheria_new_ship_length"):
|
|
|
|
|
new.prop(context.scene, prop)
|
|
|
|
|
new.operator("aetheria.new_ship", icon="ADD")
|
2026-09-26 18:14:36 +02:00
|
|
|
layout.prop(context.scene, "aetheria_ship_cc_path")
|
2026-09-26 19:10:44 +02:00
|
|
|
layout.operator("aetheria.bind_ship_collection", icon="LINKED")
|
2026-09-26 18:14:36 +02:00
|
|
|
layout.prop(context.scene, "aetheria_capture_evaluated_lines")
|
|
|
|
|
obj = context.active_object
|
|
|
|
|
layout.label(text=f"Source: {obj.name if obj else '(none)'}")
|
2026-10-10 09:49:40 +02:00
|
|
|
state = context.scene.aetheria_layout
|
2026-09-26 19:10:44 +02:00
|
|
|
try:
|
|
|
|
|
collection = _ship_collection(context)
|
|
|
|
|
layout.label(text=f"Ship: {collection['aetheria.id']}")
|
2026-10-10 09:49:40 +02:00
|
|
|
if collection.get("aetheria.pending"):
|
|
|
|
|
layout.label(text="Not saved yet: Save Layout creates the file", icon="INFO")
|
|
|
|
|
elif (collection.get("aetheria.grid_origin") is not None and state.ship_id == collection["aetheria.id"]
|
|
|
|
|
and not _grid_current(collection, state)):
|
|
|
|
|
layout.label(text="Rasterise again: the grid no longer matches the layout", icon="INFO")
|
2026-09-26 19:10:44 +02:00
|
|
|
except (ValueError, KeyError):
|
|
|
|
|
layout.label(text="No bound ship collection", icon="ERROR")
|
2026-09-26 18:14:36 +02:00
|
|
|
layout.operator("aetheria.capture_ship_lines", icon="GREASEPENCIL")
|
|
|
|
|
|
2026-09-26 19:23:01 +02:00
|
|
|
layout.separator()
|
2026-10-08 19:35:47 +02:00
|
|
|
row = layout.row(align=True)
|
|
|
|
|
row.operator("aetheria.load_ship_layout", icon="IMPORT")
|
|
|
|
|
row.operator("aetheria.flip_nose", icon="LOOP_BACK")
|
|
|
|
|
row.operator("aetheria.rasterise_hull", icon="MESH_GRID")
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
layout.operator("aetheria.bake_from_source", icon="RENDER_RESULT")
|
2026-10-18 22:00:15 +02:00
|
|
|
try:
|
|
|
|
|
if _hull_source_file(_ship_collection(context)) is not None:
|
|
|
|
|
layout.operator("aetheria.build_hull_source", icon="MESH_CUBE")
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
2026-09-26 19:23:01 +02:00
|
|
|
if not state.ship_id:
|
2026-10-03 17:13:42 +02:00
|
|
|
self._draw_package(context, layout)
|
2026-09-26 19:23:01 +02:00
|
|
|
return
|
|
|
|
|
layout.label(text=f"Layout: {state.ship_id}")
|
|
|
|
|
dims = layout.row(align=True)
|
|
|
|
|
dims.prop(state, "new_width")
|
|
|
|
|
dims.prop(state, "new_height")
|
|
|
|
|
dims.operator("aetheria.resize_ship_layout", text="Resize")
|
|
|
|
|
grid = layout.box()
|
|
|
|
|
grid.label(text="Hull cells (top row first)")
|
|
|
|
|
if len(state.cells) == state.width * state.height:
|
|
|
|
|
for y in range(state.height - 1, -1, -1):
|
|
|
|
|
row = grid.row(align=True)
|
|
|
|
|
row.label(text=str(y))
|
|
|
|
|
for x in range(state.width):
|
|
|
|
|
row.prop(state.cells[x * state.height + y], "occupied", text="")
|
|
|
|
|
layout.label(text="Hardpoints")
|
2026-10-12 03:45:12 +02:00
|
|
|
try:
|
|
|
|
|
mounts = _mount_objects(_ship_collection(context))
|
|
|
|
|
except ValueError:
|
|
|
|
|
mounts = {}
|
2026-09-26 19:23:01 +02:00
|
|
|
for index, hp in enumerate(state.hardpoints):
|
|
|
|
|
box = layout.box()
|
|
|
|
|
header = box.row(align=True)
|
|
|
|
|
header.prop(hp, "mount_id")
|
2026-10-12 03:45:12 +02:00
|
|
|
if hp.mount_id not in mounts: # a mounted row goes with its object: Remove Mount
|
|
|
|
|
header.operator("aetheria.remove_ship_hardpoint", text="", icon="X").index = index
|
2026-09-26 19:23:01 +02:00
|
|
|
box.prop(hp, "kind")
|
|
|
|
|
position = box.row(align=True)
|
2026-10-12 03:45:12 +02:00
|
|
|
position.enabled = hp.mount_id not in mounts
|
2026-09-26 19:23:01 +02:00
|
|
|
position.prop(hp, "x")
|
|
|
|
|
position.prop(hp, "y")
|
2026-10-12 03:45:12 +02:00
|
|
|
if hp.mount_id in mounts:
|
|
|
|
|
box.label(text="Mount object: Position follows it", icon="EMPTY_ARROWS")
|
2026-09-26 19:23:01 +02:00
|
|
|
box.prop(hp, "footprint")
|
|
|
|
|
box.prop(hp, "rotation")
|
|
|
|
|
box.prop(hp, "armor")
|
|
|
|
|
box.prop(hp, "firing_arc")
|
|
|
|
|
layout.operator("aetheria.add_ship_hardpoint", icon="ADD")
|
2026-10-12 03:45:12 +02:00
|
|
|
mount_box = layout.box()
|
|
|
|
|
mount_box.label(text="Mounts")
|
|
|
|
|
mount_box.operator("aetheria.add_ship_weapon", icon="ADD")
|
|
|
|
|
mount_box.operator("aetheria.add_ship_muzzle", icon="ADD")
|
|
|
|
|
mount_box.operator("aetheria.mirror_ship_mount", icon="MOD_MIRROR")
|
|
|
|
|
mount_box.operator("aetheria.remove_ship_mount", icon="X")
|
2026-09-26 19:23:01 +02:00
|
|
|
layout.operator("aetheria.save_ship_layout", icon="FILE_TICK")
|
2026-10-03 17:13:42 +02:00
|
|
|
self._draw_package(context, layout)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _draw_package(context, layout):
|
|
|
|
|
layout.separator()
|
|
|
|
|
layout.operator("aetheria.package_ship", icon="PACKAGE")
|
2026-10-10 21:02:22 +02:00
|
|
|
obj = context.active_object
|
|
|
|
|
if obj is not None and "aetheria.role" in obj:
|
|
|
|
|
try:
|
|
|
|
|
generated = _child(_ship_collection(context), GENERATED)
|
|
|
|
|
except ValueError:
|
|
|
|
|
generated = None
|
|
|
|
|
if generated is not None and obj.name in generated.all_objects:
|
|
|
|
|
layout.prop(obj, '["aetheria.keep"]', text="Keep")
|
|
|
|
|
layout.label(text="Generated: Package rebuilds it unless Kept")
|
2026-10-03 17:13:42 +02:00
|
|
|
report = context.scene.aetheria_package_report
|
|
|
|
|
if report:
|
|
|
|
|
box = layout.box()
|
|
|
|
|
for line in report.splitlines():
|
|
|
|
|
box.label(text=line)
|
2026-09-26 19:23:01 +02:00
|
|
|
|
2026-09-26 18:14:36 +02:00
|
|
|
|
2026-09-26 19:23:01 +02:00
|
|
|
classes = (AETHERIA_PG_cell, AETHERIA_PG_hardpoint, AETHERIA_PG_layout,
|
|
|
|
|
AETHERIA_OT_load_layout, AETHERIA_OT_resize_layout,
|
|
|
|
|
AETHERIA_OT_add_hardpoint, AETHERIA_OT_remove_hardpoint,
|
2026-10-12 03:45:12 +02:00
|
|
|
AETHERIA_OT_add_weapon, AETHERIA_OT_add_muzzle, AETHERIA_OT_mirror_mount, AETHERIA_OT_remove_mount,
|
2026-09-26 19:23:01 +02:00
|
|
|
AETHERIA_OT_save_layout, AETHERIA_OT_bind_ship_collection,
|
2026-10-08 19:35:47 +02:00
|
|
|
AETHERIA_OT_capture_ship_lines, AETHERIA_OT_new_ship, AETHERIA_OT_flip_nose,
|
Bake From Source: Cycles Selected-to-Active from Source onto her UV0, one albedo and normal pair per ship
Adds aetheria.bake_from_source: bakes the Source meshes onto the selected render meshes as
'<ship id>.albedo' (sRGB) and '<ship id>.normal' (Non-Color), packed, wired into every material
(a shared '<ship id>.hull' material for a mesh with none). One routine serves both maps and every
target. The Source's Metallic and Transmission Weight are neutralised for the bake (the glTF importer
sets Metallic 1.0, which bakes black); engine, samples, device, selection and Source are restored in
a finally, and a failure removes everything made and puts every changed link back. Three bake
preferences, a panel button, the tripo-hull.glb LFS fixture and smoke_bake.py (4 passes).
_refuse_loose_meshes now shares the select-offenders refusal with the bake.
All commits build; no C# touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 00:38:26 +02:00
|
|
|
AETHERIA_OT_bake_from_source,
|
2026-10-18 22:00:15 +02:00
|
|
|
AETHERIA_OT_rasterise_hull, AETHERIA_OT_build_hull_source, AETHERIA_OT_package_ship,
|
|
|
|
|
AETHERIA_AP_preferences, AETHERIA_PT_ship)
|
2026-09-26 18:14:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def register():
|
2026-09-26 19:23:01 +02:00
|
|
|
for cls in classes:
|
|
|
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
bpy.types.Scene.aetheria_layout = bpy.props.PointerProperty(type=AETHERIA_PG_layout)
|
2026-09-26 18:14:36 +02:00
|
|
|
bpy.types.Scene.aetheria_ship_cc_path = bpy.props.StringProperty(
|
|
|
|
|
name="Ship .cc", subtype="FILE_PATH", description="Existing typed ship authoring record"
|
|
|
|
|
)
|
2026-10-08 19:35:47 +02:00
|
|
|
bpy.types.Scene.aetheria_new_ship_id = bpy.props.StringProperty(
|
|
|
|
|
name="ID", description="The new ship's ID; also the folder under GameData/Mods")
|
|
|
|
|
bpy.types.Scene.aetheria_new_ship_name = bpy.props.StringProperty(name="Name", description="Display name")
|
|
|
|
|
bpy.types.Scene.aetheria_new_ship_like = bpy.props.StringProperty(
|
|
|
|
|
name="Like", default="Djinni", description="Shipped hull whose stats the new ship starts from")
|
|
|
|
|
bpy.types.Scene.aetheria_new_ship_length = bpy.props.IntProperty(
|
|
|
|
|
name="Length (cells)", default=10, min=1, max=hull_grid.MAX_CELLS,
|
|
|
|
|
description="Cells from stern to nose; the hull's long axis becomes this many 2 m cells")
|
2026-10-03 17:13:42 +02:00
|
|
|
bpy.types.Scene.aetheria_package_report = bpy.props.StringProperty(
|
|
|
|
|
name="Package report", description="AetherDb's verdict on the last Package Ship")
|
2026-09-26 18:14:36 +02:00
|
|
|
bpy.types.Scene.aetheria_capture_evaluated_lines = bpy.props.BoolProperty(
|
|
|
|
|
name="Evaluated LineArt", default=True,
|
|
|
|
|
description="Capture the visible modifier result at the current frame",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def unregister():
|
2026-09-26 19:23:01 +02:00
|
|
|
del bpy.types.Scene.aetheria_layout
|
2026-09-26 18:14:36 +02:00
|
|
|
for cls in reversed(classes):
|
|
|
|
|
bpy.utils.unregister_class(cls)
|
|
|
|
|
del bpy.types.Scene.aetheria_capture_evaluated_lines
|
2026-10-08 19:35:47 +02:00
|
|
|
del bpy.types.Scene.aetheria_new_ship_length
|
|
|
|
|
del bpy.types.Scene.aetheria_new_ship_like
|
|
|
|
|
del bpy.types.Scene.aetheria_new_ship_name
|
|
|
|
|
del bpy.types.Scene.aetheria_new_ship_id
|
2026-10-03 17:13:42 +02:00
|
|
|
del bpy.types.Scene.aetheria_package_report
|
2026-09-26 18:14:36 +02:00
|
|
|
del bpy.types.Scene.aetheria_ship_cc_path
|
2026-10-10 09:49:40 +02:00
|
|
|
|