Add-on: schematic lines are hers (one Grease Pencil) else Build's from the kit; smoke and C# fact
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b982fb9cd0
commit
905074defb
5 changed files with 147 additions and 16 deletions
|
|
@ -120,4 +120,25 @@ public sealed class NakovalnyaPackageTests
|
|||
.Select(row => $"{row.Item1} refuses the {row.Item2}").ToArray();
|
||||
Assert.Empty(refused);
|
||||
}
|
||||
|
||||
// The package's schematic is the kit's (ruling agent-hull-schematic-from-kit): hull_source's silhouette first, then
|
||||
// the kit's lines; Studio fits their top view onto the hull Shape's whole cell rect.
|
||||
[Fact]
|
||||
public void SchematicLinesComeFromTheKit()
|
||||
{
|
||||
using var cache = Catalog();
|
||||
var hull = Hull(cache);
|
||||
var ship = cache.Get(new CultRecordRef<ShipAuthoring>(ShipModCatalog.AuthoringKey(Id)));
|
||||
var kitLayers = new[] { "outline", "step", "seam", "fitting" };
|
||||
|
||||
Assert.Equal("silhouette", ship.SchematicLines[0].Layer);
|
||||
Assert.True(ship.SchematicLines[0].Cyclic);
|
||||
Assert.True(ship.SchematicLines.Count(line => kitLayers.Contains(line.Layer)) > 20);
|
||||
Assert.All(ship.SchematicLines, line => Assert.Contains(line.Layer, kitLayers.Append("silhouette")));
|
||||
ShipAuthoringStore.Validate(hull, ship);
|
||||
|
||||
var fit = SchematicUnderlay.Fit(ship.SchematicLines, hull.Shape).SelectMany(line => line).ToArray();
|
||||
Assert.Equal((19, 30), (hull.Shape.Width, hull.Shape.Height));
|
||||
Assert.Equal((0f, 0f, 19f, 30f), (fit.Min(p => p.x), fit.Min(p => p.y), fit.Max(p => p.x), fit.Max(p => p.y)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -533,12 +533,11 @@ class AETHERIA_OT_bind_ship_collection(bpy.types.Operator):
|
|||
class AETHERIA_OT_capture_ship_lines(bpy.types.Operator):
|
||||
bl_idname = "aetheria.capture_ship_lines"
|
||||
bl_label = "Capture Ship Lines"
|
||||
bl_description = "Replace only the line slot in the selected typed ship .cc record"
|
||||
bl_description = "Replace only the line slot in the bound ship .cc record: from the Grease Pencil object, else from the hull source"
|
||||
bl_options = {"REGISTER"}
|
||||
|
||||
def execute(self, context):
|
||||
try:
|
||||
obj = context.active_object
|
||||
collection = _ship_collection(context)
|
||||
if not collection.get("aetheria.ship_cc"):
|
||||
raise ValueError("The ship collection has no bound .cc path")
|
||||
|
|
@ -546,10 +545,9 @@ class AETHERIA_OT_capture_ship_lines(bpy.types.Operator):
|
|||
cultlib = _brokkr_cultlib(context)
|
||||
if read(path, cultlib).ship.body[0] != collection["aetheria.id"]:
|
||||
raise ValueError("The bound collection ID does not match its .cc ship ID")
|
||||
lines = capture_grease_pencil(
|
||||
obj, context.evaluated_depsgraph_get(), context.scene.frame_current,
|
||||
evaluated=context.scene.aetheria_capture_evaluated_lines,
|
||||
)
|
||||
lines = _schematic_lines(context, collection)
|
||||
if lines is None:
|
||||
raise ValueError("No schematic lines were captured; the ship record was not changed")
|
||||
count = replace_lines(path, cultlib, lines)
|
||||
self.report({"INFO"}, f"Captured {count} lines")
|
||||
return {"FINISHED"}
|
||||
|
|
@ -1492,6 +1490,7 @@ def _frame_ship(context, collection, root, path, saved_shape):
|
|||
|
||||
|
||||
HULL_MAKER = "aetheria.hull_maker" # on the collection: the Faction key of the language Build judged the hull against
|
||||
HULL_LINES = "aetheria.hull_lines" # on the collection: [{layer, cyclic, points (flat), rgba}] the hull source's kit drew, in Ship Root's frame
|
||||
HULL_BUILT = "aetheria.hull_built" # on the collection: {object name: fingerprint} of what Build From Hull Source made
|
||||
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
|
||||
|
|
@ -1577,7 +1576,7 @@ def _build_hull_source(context, collection):
|
|||
executable = addon.preferences.openscad if addon and addon.preferences else DEFAULT_OPENSCAD
|
||||
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),
|
||||
hull_type)
|
||||
hull_type, hull_source.openscad_projector(executable))
|
||||
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))
|
||||
|
|
@ -1629,9 +1628,38 @@ def _build_hull_source(context, collection):
|
|||
collider["aetheria.role"], collider["aetheria.id"] = role, anchor_id
|
||||
collection[HULL_BUILT] = {obj.name: _fingerprint(obj) for obj in made}
|
||||
collection[HULL_MAKER] = hull.languages[hull.brief.faction].maker
|
||||
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]
|
||||
return hull
|
||||
|
||||
|
||||
def _schematic_lines(context, collection):
|
||||
"""The ShipAuthoring.SchematicLines rows Package and Capture write, and the only source of them: her Grease Pencil
|
||||
object if the collection has one (two or more are refused), else the lines Build recorded from the hull source's kit,
|
||||
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."""
|
||||
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)
|
||||
if record is None:
|
||||
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
|
||||
|
||||
|
||||
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,
|
||||
|
|
@ -1659,7 +1687,7 @@ def _retire_hull_source(collection):
|
|||
source = _hull_source_file(collection)
|
||||
if source is not None:
|
||||
source.unlink()
|
||||
for record in (HULL_BUILT, HULL_MAKER):
|
||||
for record in (HULL_BUILT, HULL_MAKER, HULL_LINES):
|
||||
if record in collection:
|
||||
del collection[record]
|
||||
return True
|
||||
|
|
@ -1708,7 +1736,7 @@ class AETHERIA_OT_package_ship(bpy.types.Operator):
|
|||
bl_idname = "aetheria.package_ship"
|
||||
bl_label = "Package Ship"
|
||||
bl_description = ("Put the grid's centre of mass at the world origin, derive the missing map icon, shield and "
|
||||
"tractor, write the anchors and ship.glb from the bound collection, capture its LineArt, and "
|
||||
"tractor, write the anchors and ship.glb from the bound collection, capture its schematic lines, and "
|
||||
"run AetherDb's validator")
|
||||
bl_options = {"REGISTER"}
|
||||
|
||||
|
|
@ -1738,11 +1766,9 @@ class AETHERIA_OT_package_ship(bpy.types.Operator):
|
|||
anchors = _anchors(collection)
|
||||
_export_glb(context, collection, str(Path(path).with_name(MODEL_ASSET)))
|
||||
replace_visual(path, cultlib, ship_id, MODEL_ASSET, anchors)
|
||||
pencils = [obj for obj in collection.all_objects if obj.type == "GREASEPENCIL"]
|
||||
if len(pencils) == 1:
|
||||
replace_lines(path, cultlib, capture_grease_pencil(
|
||||
pencils[0], context.evaluated_depsgraph_get(), scene.frame_current,
|
||||
evaluated=scene.aetheria_capture_evaluated_lines))
|
||||
lines = _schematic_lines(context, collection)
|
||||
if lines is not None:
|
||||
replace_lines(path, cultlib, lines)
|
||||
code, message = _aetherdb(context, "validate", path, ship_cc=path)
|
||||
except _EXPECTED as exc:
|
||||
scene.aetheria_package_report = f"Package failed: {_failure_text(exc)}"
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ def _stamped(record: Record, msgpack: Any):
|
|||
def replace_lines(path: str, cultlib_packages: str, lines: list[list[Any]]) -> int:
|
||||
file = read(path, cultlib_packages)
|
||||
if not lines:
|
||||
raise ValueError("No Grease Pencil strokes were captured; the ship record was not changed")
|
||||
raise ValueError("No schematic lines were captured; the ship record was not changed")
|
||||
file.ship.body[SCHEMATIC_LINES_SLOT] = lines
|
||||
file.store.push(_stamped(file.ship, file.msgpack))
|
||||
return len(lines)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ the hull.scad into the package and runs the panel's operators:
|
|||
or a product by another maker than the language Build judged it against (hull-names-its-own-faction); with a product by
|
||||
that maker it accepts, with hull.scad in the package or not (the guard keys on the hull's state), and a refused Package
|
||||
changes nothing in the scene. Her art needs no product.
|
||||
Schematic lines: after Build and Package the ship.cc's first line is the silhouette and the kit's lines follow (the Pirate
|
||||
hull's kit draws none); a Grease Pencil object in the collection replaces them with its own; a second one is refused by
|
||||
Package and Capture Ship Lines, and the slot is as it was. The Nakovalnya's hull.scad, read with the real kit, has a
|
||||
silhouette whose box is the zones' top-view box and a fitting octagon at every flak mount anchor.
|
||||
Build and Package refuse copies that share an aetheria.id, selecting the original and the copies, and delete nothing.
|
||||
Package moves no row and turns no mount: every layout row is as authored after it, and a hand-turned mount keeps its yaw.
|
||||
The ship.cc HullData.HullType decides whether the language's proportions judge the hull: a body far wider than the
|
||||
|
|
@ -366,6 +370,37 @@ def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palett
|
|||
require(saved == [(mount_id, cell) for mount_id, _, cell in rows], f"A row is not as authored after Package: {saved}")
|
||||
print(f"PASS {number}.5 Package accepts the built ship and keeps hull.scad")
|
||||
|
||||
# Schematic lines: Build's, else hers, and never two of hers.
|
||||
packaged = ship_lines(ship_cc)
|
||||
require(packaged and packaged[0][0] == "silhouette" and packaged[0][5] is True, f"The first line is not the silhouette: {packaged[:1]}")
|
||||
kit = packaged[1:]
|
||||
require(all(row[0] in hull_source.KIT_LAYERS and row[3] is None and row[4] is None and row[1] == "" for row in kit),
|
||||
"A kit line row is not shaped as Package writes it")
|
||||
require(bool(kit) == (fixture == "zh-ammo-tender"), f"The kit drew {len(kit)} lines for {fixture}")
|
||||
require(all(approx(row[6], hull_source.LINE_STYLE[row[0]]) for row in packaged), "A line lost its style")
|
||||
shipped_z = {round(c, 3) for row in packaged for c in row[2][2::3]}
|
||||
require(len(shipped_z) >= 1, "The lines have no height")
|
||||
pencil = grease_pencil(collection, "her lines", [(0, 0, 0), (1, 0, 0), (1, 1, 0)])
|
||||
select(box)
|
||||
result, message = run(bpy.ops.aetheria.package_ship)
|
||||
require(result == {"FINISHED"}, f"Package refused a ship with one Grease Pencil: {message!r}")
|
||||
hers = ship_lines(ship_cc)
|
||||
require(len(hers) == 1 and hers[0][0] == "hers" and len(hers[0][2]) == 9, f"Her Grease Pencil did not replace the kit's lines: {hers}")
|
||||
second = grease_pencil(collection, "second lines", [(0, 0, 0), (2, 0, 0)])
|
||||
before = ship_lines(ship_cc)
|
||||
for operator in (bpy.ops.aetheria.package_ship, bpy.ops.aetheria.capture_ship_lines):
|
||||
select(box)
|
||||
result, message = run(operator)
|
||||
require(result == {"CANCELLED"} and "Keep one Grease Pencil object" in (message + scene.aetheria_package_report),
|
||||
f"Two Grease Pencil objects were not refused: {message!r}")
|
||||
require(ship_lines(ship_cc) == before, "A refused schematic changed the line slot")
|
||||
for obj in (pencil, second):
|
||||
bpy.data.objects.remove(obj)
|
||||
select(box)
|
||||
result, message = run(bpy.ops.aetheria.package_ship)
|
||||
require(result == {"FINISHED"} and len(ship_lines(ship_cc)) == len(packaged), f"Without Grease Pencil the kit's lines are back: {message!r}")
|
||||
print(f"PASS {number}.5b the kit's lines ship, her Grease Pencil wins, two are refused")
|
||||
|
||||
# What Package did to the built objects is not an edit: Build still replaces them.
|
||||
select(box)
|
||||
result, message = run(bpy.ops.aetheria.build_hull_source)
|
||||
|
|
@ -566,6 +601,54 @@ def clear(collection):
|
|||
bpy.data.objects.remove(obj)
|
||||
|
||||
|
||||
def ship_lines(ship_path):
|
||||
"""The ShipAuthoring.SchematicLines rows of a ship.cc, as Package wrote them."""
|
||||
return sys.modules["aetheria_ships"].read(ship_path, PACKAGES).ship.body[sys.modules["aetheria_ships"].ship_cc.SCHEMATIC_LINES_SLOT]
|
||||
|
||||
|
||||
def grease_pencil(collection, name, points):
|
||||
"""A Grease Pencil object in the collection holding one stroke, layer named 'hers'."""
|
||||
data = bpy.data.grease_pencils.new(name)
|
||||
material = bpy.data.materials.new(name)
|
||||
bpy.data.materials.create_gpencil_data(material)
|
||||
data.materials.append(material)
|
||||
layer = data.layers.new("hers")
|
||||
drawing = layer.frames.new(1).drawing
|
||||
drawing.add_strokes([len(points)])
|
||||
for point, position in zip(drawing.strokes[0].points, points):
|
||||
point.position = position
|
||||
obj = bpy.data.objects.new(name, data)
|
||||
collection.objects.link(obj)
|
||||
return obj
|
||||
|
||||
|
||||
def nakovalnya_frames(executable):
|
||||
"""The Nakovalnya's hull.scad with the real kit: the silhouette is the zones' top view and a fitting octagon sits at
|
||||
every flak mount (the frame the kit placed the barrel in is the frame the anchor is in)."""
|
||||
source = REPO / "GameData" / "Mods" / "aetheria.nakovalnya" / "hull.scad"
|
||||
built = hull_source.build(hull_source.openscad_runner(executable, source), hull_source.language_library(executable),
|
||||
"Ship", hull_source.openscad_projector(executable))
|
||||
require(not built.failed(), f"The Nakovalnya breaks a check: {[c.name for c in built.failed()]}")
|
||||
silhouette = [row for row in built.lines if row.layer == "silhouette"]
|
||||
require(built.lines[0].layer == "silhouette" and len(silhouette) == 1, "The Nakovalnya silhouette is not one first contour")
|
||||
xs = [v[0] for mesh in built.zones.values() for v in mesh.vertices]
|
||||
ys = [v[1] for mesh in built.zones.values() for v in mesh.vertices]
|
||||
box = (min(xs), max(xs), min(ys), max(ys))
|
||||
flat = silhouette[0].points
|
||||
got = (min(p[0] for p in flat), max(p[0] for p in flat), min(p[1] for p in flat), max(p[1] for p in flat))
|
||||
require(approx(box, got, 1e-3), f"The silhouette box {got} is not the zones' top-view box {box}")
|
||||
octagons = [row.points for row in built.lines if row.layer == "fitting" and row.cyclic and len(row.points) == 8]
|
||||
centres = [(sum(p[0] for p in o) / 8, sum(p[1] for p in o) / 8) for o in octagons]
|
||||
mounts = [a for a in built.anchors if a.id.startswith("Gun.F") and a.role == "weapon-mount"]
|
||||
require(len(mounts) == 10, f"The Nakovalnya has {len(mounts)} flak mounts")
|
||||
for mount in mounts:
|
||||
near = min(math.hypot(mount.position[0] - c[0], mount.position[1] - c[1]) for c in centres)
|
||||
require(near <= 0.3, f"{mount.id} is {near:.2f} m from the nearest fitting octagon")
|
||||
kinds = {row.layer for row in built.lines}
|
||||
require({"silhouette", "outline", "step", "seam", "fitting"} <= kinds, f"The Nakovalnya lacks a layer: {kinds}")
|
||||
print(f"PASS frames the Nakovalnya's {len(built.lines)} lines are in the frame of its geometry")
|
||||
|
||||
|
||||
def aetherdb(ship_path, *args):
|
||||
"""Runs one AetherDb ship-authoring command through the add-on's own runner; returns its exit code."""
|
||||
return sys.modules["aetheria_ships"]._aetherdb(bpy.context, *args, ship_cc=ship_path)[0]
|
||||
|
|
@ -797,6 +880,7 @@ def main():
|
|||
clear(agent_guards(scene))
|
||||
clear(hull_type_gate(scene))
|
||||
never_built(scene)
|
||||
nakovalnya_frames(EXECUTABLE)
|
||||
|
||||
|
||||
created = not MODS.exists()
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ class ReplaceLinesTests(ShipFileCase):
|
|||
|
||||
def test_refuses_an_empty_capture_and_changes_nothing(self):
|
||||
before = self.bytes()
|
||||
with self.assertRaisesRegex(ValueError, "No Grease Pencil strokes"):
|
||||
with self.assertRaisesRegex(ValueError, "No schematic lines"):
|
||||
ship_cc.replace_lines(self.path, PACKAGES, [])
|
||||
self.assertEqual(before, self.bytes())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue