Build and Package refuse objects that share an aetheria.id, by selection
One _refuse_shared_ids: a copy of the collider, an emitter, a radiator or a mount selects the original and the copy and names a count, not an object (follow-up hull-copy-refusals). smoke_hull_source covers it (not run: bpy smokes). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
eaf7b799d4
commit
adaa8b8865
2 changed files with 62 additions and 0 deletions
|
|
@ -818,6 +818,25 @@ def _refuse_loose_meshes(context, collection):
|
|||
_refuse_selecting(context, loose, f"{len(loose)} meshes in the ship collection are not under Ship Root; parent them to it")
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
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."""
|
||||
|
|
@ -1542,6 +1561,7 @@ def _build_hull_source(context, collection):
|
|||
untouched, changed = _hull_built(collection)
|
||||
if root is not None:
|
||||
_refuse_loose_meshes(context, collection)
|
||||
_refuse_shared_ids(context, collection)
|
||||
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 "
|
||||
|
|
@ -1653,6 +1673,7 @@ class AETHERIA_OT_package_ship(bpy.types.Operator):
|
|||
if collection.get("aetheria.pending"):
|
||||
raise ValueError("Save Layout first")
|
||||
_refuse_loose_meshes(context, collection)
|
||||
_refuse_shared_ids(context, collection)
|
||||
cultlib = _brokkr_cultlib(context)
|
||||
ship_id = collection["aetheria.id"]
|
||||
state = scene.aetheria_layout
|
||||
|
|
|
|||
|
|
@ -332,6 +332,7 @@ def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palett
|
|||
result, message = run(bpy.ops.aetheria.build_hull_source)
|
||||
require(result == {"CANCELLED"} and abs(mount.location.x - at[0] - 1.0) < 1e-6, f"Build discarded a moved mount: {message!r}")
|
||||
mount.location = at
|
||||
shared_ids_refused(scene, box, collection, ship_id, package, generated(collection), number)
|
||||
print(f"PASS {number}.8 Build refuses and keeps a copy and an edit of what it made")
|
||||
|
||||
# The author replaces the zone meshes with her art and keeps Build's anchors and collider: Package ships the ship
|
||||
|
|
@ -363,6 +364,46 @@ def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palett
|
|||
return collection
|
||||
|
||||
|
||||
def shared_ids_refused(scene, box, collection, ship_id, package, objects, number):
|
||||
"""A copy of the collider, an emitter or radiator mesh or a weapon mount shares its original's aetheria.id: Build and
|
||||
Package refuse by selecting the original and the copy, name a count and no input, and delete nothing."""
|
||||
glb = package / "ship.glb"
|
||||
glb_before = glb.read_bytes()
|
||||
seen = set()
|
||||
for obj in list(objects.values()):
|
||||
role = obj.get("aetheria.role")
|
||||
if role not in ("hull-collider", "thruster-emitter", "radiator-mesh", "weapon-mount") or role in seen:
|
||||
continue
|
||||
seen.add(role)
|
||||
twin = obj.copy()
|
||||
if obj.data is not None:
|
||||
twin.data = obj.data.copy()
|
||||
collection.objects.link(twin)
|
||||
twin.parent = obj.parent
|
||||
require(twin.get("aetheria.id") == obj.get("aetheria.id"), "The copy does not share its original's aetheria.id")
|
||||
names = sorted(o.name for o in collection.all_objects)
|
||||
for operator in (bpy.ops.aetheria.build_hull_source, bpy.ops.aetheria.package_ship):
|
||||
for other in bpy.context.view_layer.objects:
|
||||
other.select_set(False)
|
||||
select(box)
|
||||
result, message = run(operator)
|
||||
message = message or scene.aetheria_package_report
|
||||
require(result == {"CANCELLED"} and "2 objects share an aetheria.id" in message,
|
||||
f"A copy of a {role} was not refused by name of the shared id: {message!r}")
|
||||
for echoed in (ship_id, str(GAME), obj.name, twin.name, obj["aetheria.id"]):
|
||||
require(echoed not in message, f"The refusal echoes an input ({echoed})")
|
||||
require(obj.select_get() and twin.select_get() and not box.select_get(),
|
||||
f"The refusal did not select the original and the copy of a {role}")
|
||||
require(sorted(o.name for o in collection.all_objects) == names, "A refused operator deleted or added an object")
|
||||
require(glb.read_bytes() == glb_before, "A refused Package wrote ship.glb")
|
||||
mesh = twin.data
|
||||
bpy.data.objects.remove(twin)
|
||||
if mesh is not None and mesh.users == 0:
|
||||
bpy.data.meshes.remove(mesh)
|
||||
require(len(seen) >= 3, f"The copies covered too few roles: {sorted(seen)}")
|
||||
print(f"PASS {number}.8b copies of {sorted(seen)} are refused by Build and Package, selected, nothing deleted")
|
||||
|
||||
|
||||
def check_poses(collection, root, runner):
|
||||
"""Every built anchor stands where the hull source says in Ship Root's frame, turned as it says, and the emitter and
|
||||
radiator meshes are the source's meshes in that frame."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue