brokkr_kitbash.freeze and thaw: a cut object carries its evaluated mesh, its live mesh held in kit_frozen, its stack kept and off (cut kit-freeze, 2 of 2)
Blender re-evaluates every live collection Boolean after any datablock removal, hide or mesh read in the scene. freeze swaps in the evaluated mesh and turns every modifier off; thaw is its one undo. live() refuses a frozen object in set_params, boolean, cut, cut_many, ribs, a shell or hose rebuild and freeze. Live: three cut tanks frozen cost 0.0022 of what they cost live when an orphan mesh is removed (mutant F1, modifiers left on: 1.5; bound 0.057). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
1b0c1b0abd
commit
3cbb8f33a2
8 changed files with 543 additions and 38 deletions
|
|
@ -1,5 +1,5 @@
|
|||
"""Kitbash parts: place parametric machine parts from a kit, mate them socket to socket, cut them and any other
|
||||
mesh, and bake them.
|
||||
mesh, and freeze them.
|
||||
|
||||
A host add-on for Brokkr beside brokkr_mesh_polish and brokkr_rig (it imports the polish package's operator base,
|
||||
Refused and mesh_object, and nothing from Brokkr): brokkr_actions.json beside this file lists the operators agents
|
||||
|
|
@ -17,7 +17,9 @@ A connection belongs to the child: its parent pointer (under an identity parent
|
|||
properties, kit_socket, kit_parent_socket and kit_roll. Its matrix_basis is derived from them and both parts'
|
||||
params by core.mate; attach and set_params write it, and a report says how far the child stands from it.
|
||||
write_connection is the one writer of a connection. roll, aim and reach rewrite an attached part's roll through it,
|
||||
in place: roll states the roll, aim and reach solve it in closed form (core.aim_roll, core.reach_roll). Placing a
|
||||
in place: roll states the roll, aim and reach solve it in closed form (core.aim_roll, core.reach_roll). kit_frozen
|
||||
is the frozen state: freeze holds the live mesh there while the object carries its evaluated one with every modifier
|
||||
off, and thaw is its one undo. Placing a
|
||||
loose part, hiding a cutter, materials and export are Brokkr's own rows (setObjectTransform, setObjectVisibility,
|
||||
assignMaterial, exportGltf).
|
||||
|
||||
|
|
@ -32,7 +34,7 @@ identity parent inverse: its matrix_basis is the recess frame and its params the
|
|||
the cutter object moves the cut and its floor socket together, and nothing else stores either. Machinery attaches
|
||||
to a floor socket with the ordinary attach. Blender evaluates a changed target after every action, so each cut costs
|
||||
one Boolean evaluation; cut_many places many cutters for one. Every action that evaluates an object (boolean, cut,
|
||||
cut_many) first refuses one Blender does not evaluate (evaluable). A report's list that would not fit a
|
||||
cut_many, freeze) first refuses one Blender does not evaluate (evaluable). A report's list that would not fit a
|
||||
receipt is trimmed by fitted, the rows left off counted beside it: the scene keeps what they would have said.
|
||||
|
||||
ribs derives the frame under an armor cage from the cage: ribs behind the plate along plane sections, stopped where
|
||||
|
|
@ -86,6 +88,7 @@ from . import core, route
|
|||
|
||||
KIT, PART, PARAMS = "kit_kit", "kit_part", "kit_params"
|
||||
SOCKET, PARENT_SOCKET, ROLL = "kit_socket", "kit_parent_socket", "kit_roll"
|
||||
FROZEN = "kit_frozen" # on a frozen object: an ID pointer to its live mesh; its presence is the frozen state, freeze sets it and thaw deletes it
|
||||
CLOSE, CLOSE_TO, CLOSE_TO_SOCKET = "kit_close_socket", "kit_close_to", "kit_close_to_socket"
|
||||
HELD = 1e-5 # a connection or a closure holds when its residual is at most this (as RIGID)
|
||||
BEVEL = "Kit Bevel"
|
||||
|
|
@ -352,7 +355,15 @@ def part_report(obj, part, built) -> dict:
|
|||
return {"object": obj.name, "kit": part["kit"], "part": part["name"], "params": built.params,
|
||||
"faces": len(obj.data.polygons), "shells": built.shell_count, "bevel": round(built.bevel, 6),
|
||||
"sockets": core.socket_rows(built.sockets, np.array(obj.matrix_world)),
|
||||
"connection": connection_report(obj, part, built), "closure": closure_report(obj, part, built)}
|
||||
"connection": connection_report(obj, part, built), "closure": closure_report(obj, part, built),
|
||||
"frozen": FROZEN in obj}
|
||||
|
||||
|
||||
def live(obj, doing: str) -> None:
|
||||
"""Refuses a frozen object: its mesh is its frozen evaluation and its modifiers are off, so a write would land on
|
||||
a mesh thaw discards, or under a stack nothing evaluates."""
|
||||
if FROZEN in obj:
|
||||
raise Refused(f"{obj.name!r} is frozen, and {doing} it needs its live mesh and modifiers: thaw it first; nothing changed.")
|
||||
|
||||
|
||||
def own_mesh(obj, doing: str) -> None:
|
||||
|
|
@ -400,14 +411,14 @@ def uncut(target, cutter) -> None:
|
|||
|
||||
def evaluated_of(context, obj):
|
||||
"""(depsgraph, obj with its modifier stack evaluated). An Exact Boolean costs from a few tenths of a second (a
|
||||
kit part) to a few seconds (a subdivided shell), so only boolean and ribs call this; no report does."""
|
||||
kit part) to a few seconds (a subdivided shell), so only boolean, freeze (through evaluable) and ribs call this; no report does."""
|
||||
depsgraph = context.evaluated_depsgraph_get()
|
||||
return depsgraph, obj.evaluated_get(depsgraph)
|
||||
|
||||
|
||||
def evaluable(context, obj):
|
||||
"""evaluated_of, for an object Blender evaluates: refuses one the evaluated depsgraph does not hold, which has no
|
||||
evaluated mesh to cast at or cut. Membership of the depsgraph is the test, whatever keeps the object out
|
||||
evaluated mesh to cast at, cut or freeze. Membership of the depsgraph is the test, whatever keeps the object out
|
||||
of it. Every action that evaluates calls this before its first write."""
|
||||
depsgraph, evaluated = evaluated_of(context, obj)
|
||||
if not evaluated.is_evaluated:
|
||||
|
|
@ -470,6 +481,7 @@ def place_cutters(context, target, specs) -> list:
|
|||
first did, and no Boolean is evaluated here. Blender evaluates the changed target once after the action, however
|
||||
many cutters it placed."""
|
||||
rigid(target)
|
||||
live(target, "cutting")
|
||||
kit, made, names = core.load_kit(CUTTERS), [], set()
|
||||
for spec in specs:
|
||||
name = spec["name"]
|
||||
|
|
@ -556,6 +568,7 @@ class BROKKR_KITBASH_OT_set_params(PolishOperator):
|
|||
def work(self, context):
|
||||
obj = mesh_object(self.object_name)
|
||||
part, stored = kit_part_of(obj)
|
||||
live(obj, "setting params of")
|
||||
own_mesh(obj, "rebuilding")
|
||||
built = core.build(part, core.resolve_params(part, core.parse_params(self.params), stored))
|
||||
closing = closure(obj) # a closure this part is an end of must still be one its new sockets may make; where they stand is only reported
|
||||
|
|
@ -792,6 +805,7 @@ class BROKKR_KITBASH_OT_boolean(PolishOperator):
|
|||
raise Refused(f"{obj.name!r} cannot cut itself; nothing changed.")
|
||||
report = part_report(obj, *built_part(obj)) if PART in obj else {"object": obj.name}
|
||||
rigid(obj)
|
||||
live(obj, "cutting")
|
||||
uncut(obj, cutter)
|
||||
evaluable(context, obj)
|
||||
operation_collection(obj, self.operation, True).objects.link(cutter)
|
||||
|
|
@ -874,6 +888,68 @@ class BROKKR_KITBASH_OT_cut_many(PolishOperator):
|
|||
return report
|
||||
|
||||
|
||||
class BROKKR_KITBASH_OT_freeze(PolishOperator):
|
||||
"""Freeze a mesh object that has modifiers, a kit part or any other: its mesh becomes its evaluated mesh, its live
|
||||
mesh is held by its kit_frozen property, and every modifier stays in the stack, off in viewports and renders, with
|
||||
its collections; Blender then evaluates no Boolean for it until thaw"""
|
||||
bl_idname = "brokkr_kitbash.freeze"
|
||||
bl_label = "Freeze Cut Object"
|
||||
object_name: bpy.props.StringProperty(name="Object", description="A mesh with modifiers: a kit part, a shell or any mesh")
|
||||
|
||||
@kit_work
|
||||
def work(self, context):
|
||||
obj = mesh_object(self.object_name)
|
||||
live(obj, "freezing")
|
||||
if not obj.modifiers:
|
||||
raise Refused(f"{obj.name!r} has no modifiers to freeze; nothing changed.")
|
||||
off = [modifier.name for modifier in obj.modifiers if not (modifier.show_viewport and modifier.show_render)]
|
||||
if off:
|
||||
raise Refused(f"{obj.name!r} has {', '.join(off)} off in viewports or renders, and thaw turns every modifier on: "
|
||||
"it would not give this stack back. Show them, or remove them; nothing changed.")
|
||||
report = part_report(obj, *built_part(obj)) if PART in obj else {"object": obj.name}
|
||||
depsgraph, evaluated = evaluable(context, obj)
|
||||
slots = len(obj.data.materials)
|
||||
frozen = bpy.data.meshes.new_from_object(evaluated, preserve_all_data_layers=True, depsgraph=depsgraph)
|
||||
while len(frozen.materials) > slots and frozen.materials[len(frozen.materials) - 1] is None:
|
||||
frozen.materials.pop() # a Boolean gives a part that had no material slot one empty slot
|
||||
index = np.zeros(len(frozen.polygons), dtype=np.int32)
|
||||
frozen.polygons.foreach_get("material_index", index)
|
||||
if (index < 0).any(): # faces from a cutter's empty slot: slot 0, as faces from a cutter with no material
|
||||
frozen.polygons.foreach_set("material_index", np.maximum(index, 0))
|
||||
frozen.name = f"{obj.name} frozen"
|
||||
obj[FROZEN] = obj.data
|
||||
obj.data = frozen
|
||||
for modifier in obj.modifiers:
|
||||
modifier.show_viewport = modifier.show_render = False
|
||||
report.update(frozen=True, **measured(frozen), modifiers=[modifier.name for modifier in obj.modifiers])
|
||||
report["booleans"] = fitted(report, "booleans", booleans(obj))
|
||||
return report
|
||||
|
||||
|
||||
class BROKKR_KITBASH_OT_thaw(PolishOperator):
|
||||
"""Thaw a frozen object: its live mesh comes back from kit_frozen, every modifier is turned on, and the frozen mesh
|
||||
goes; evaluates nothing itself (Blender evaluates the object once afterwards)"""
|
||||
bl_idname = "brokkr_kitbash.thaw"
|
||||
bl_label = "Thaw Frozen Object"
|
||||
object_name: bpy.props.StringProperty(name="Object", description="A frozen mesh object")
|
||||
|
||||
@kit_work
|
||||
def work(self, context):
|
||||
obj = mesh_object(self.object_name)
|
||||
if FROZEN not in obj:
|
||||
raise Refused(f"{obj.name!r} is not frozen; nothing changed.")
|
||||
held, frozen = obj[FROZEN], obj.data
|
||||
if not isinstance(held, bpy.types.Mesh):
|
||||
raise Refused(f"{obj.name!r} is frozen and the live mesh its {FROZEN} held is gone: there is nothing to thaw to; nothing changed.")
|
||||
obj.data = held
|
||||
del obj[FROZEN]
|
||||
for modifier in obj.modifiers:
|
||||
modifier.show_viewport = modifier.show_render = True
|
||||
if frozen.users == 0:
|
||||
bpy.data.meshes.remove(frozen)
|
||||
return {"object": obj.name, "frozen": False, "modifiers": [modifier.name for modifier in obj.modifiers], "faces": len(held.polygons)}
|
||||
|
||||
|
||||
RIBS = "kit_ribs" # on a ribs object: the request that derived it, as JSON; nothing reads it to decide geometry
|
||||
SAMPLES_LIMIT = 20000 # section points in one ribs: every chain's length over step, summed
|
||||
SHELL_MODIFIERS = ("SOLIDIFY", "BEVEL", "BOOLEAN") # what makes a designed surface a cut plate: off, the cage shows the surface
|
||||
|
|
@ -985,6 +1061,7 @@ class BROKKR_KITBASH_OT_ribs(PolishOperator):
|
|||
def work(self, context):
|
||||
cage = mesh_object(self.object_name)
|
||||
rigid(cage)
|
||||
live(cage, "deriving ribs from")
|
||||
depsgraph, _ = evaluable(context, cage)
|
||||
if not 1 <= len(self.ribs_name) <= 63 or self.ribs_name in bpy.data.objects:
|
||||
raise Refused(f"ribs_name {self.ribs_name!r} must be 1 to 63 characters and no object's name; nothing changed.")
|
||||
|
|
@ -1292,6 +1369,7 @@ class BROKKR_KITBASH_OT_shell(PolishOperator):
|
|||
if obj.type != "MESH" or SHELL not in obj:
|
||||
raise Refused(f"An object named {obj.name!r} exists and is no shell (it carries no {SHELL}): shell rebuilds only what shell made; nothing changed.")
|
||||
rigid(obj)
|
||||
live(obj, "rebuilding")
|
||||
own_mesh(obj, "rebuilding")
|
||||
if self.count_folds:
|
||||
unseen = [modifier.name for modifier in obj.modifiers if modifier.name in (SUBSURF, SOLIDIFY) and not modifier.show_viewport]
|
||||
|
|
@ -1408,6 +1486,7 @@ class BROKKR_KITBASH_OT_hose(PolishOperator):
|
|||
if hose is not None:
|
||||
if hose.type != "MESH" or HOSE not in hose:
|
||||
raise Refused(f"An object named {hose.name!r} exists and is no hose (it carries no {HOSE}): hose rebuilds only what hose made; nothing changed.")
|
||||
live(hose, "rebuilding")
|
||||
own_mesh(hose, "rebuilding")
|
||||
sizes = route.bundle(self.count, self.radius, self.spread, self.clearance, self.bend)
|
||||
r, need, floor, lead, half_width = self.radius, sizes["need"], sizes["floor"], sizes["lead"], sizes["envelope"] - self.radius
|
||||
|
|
@ -1789,7 +1868,7 @@ class BROKKR_KITBASH_OT_describe(PolishOperator):
|
|||
|
||||
class BROKKR_KITBASH_OT_report(PolishOperator):
|
||||
"""Report placed kit parts as the scene has them: kit, part, params, faces, shells, each socket's world frame,
|
||||
the connection and the closure and whether each holds"""
|
||||
the connection and the closure and whether each holds, and whether the part is frozen"""
|
||||
bl_idname = "brokkr_kitbash.report"
|
||||
bl_label = "Report Kit Parts"
|
||||
bl_options = {"REGISTER"}
|
||||
|
|
@ -1804,7 +1883,8 @@ class BROKKR_KITBASH_OT_report(PolishOperator):
|
|||
|
||||
classes = (BROKKR_KITBASH_OT_place_part, BROKKR_KITBASH_OT_set_params, BROKKR_KITBASH_OT_describe, BROKKR_KITBASH_OT_report,
|
||||
BROKKR_KITBASH_OT_attach, BROKKR_KITBASH_OT_detach, BROKKR_KITBASH_OT_roll, BROKKR_KITBASH_OT_aim, BROKKR_KITBASH_OT_reach,
|
||||
BROKKR_KITBASH_OT_close, BROKKR_KITBASH_OT_boolean, BROKKR_KITBASH_OT_cut, BROKKR_KITBASH_OT_cut_many, BROKKR_KITBASH_OT_ribs,
|
||||
BROKKR_KITBASH_OT_close, BROKKR_KITBASH_OT_boolean, BROKKR_KITBASH_OT_cut, BROKKR_KITBASH_OT_cut_many, BROKKR_KITBASH_OT_freeze, BROKKR_KITBASH_OT_thaw,
|
||||
BROKKR_KITBASH_OT_ribs,
|
||||
BROKKR_KITBASH_OT_shell, BROKKR_KITBASH_OT_hose)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
},
|
||||
{
|
||||
"name": "brokkr_kitbash.set_params",
|
||||
"doc": "Change params of a placed kit part and rebuild its mesh in place; modifiers and materials stay, and its connection and the parts attached to it are seated again. Refuses a change that breaks a connection, a mesh another object shares and a scaled part. Reports as place_part.",
|
||||
"doc": "Change params of a placed kit part and rebuild its mesh in place; modifiers and materials stay, and its connection and the parts attached to it are seated again. Refuses a change that breaks a connection, a frozen part, a mesh another object shares and a scaled part. Reports as place_part.",
|
||||
"changesScene": true,
|
||||
"editModeSafe": false,
|
||||
"result": "brokkr_mesh_polish_result",
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
},
|
||||
{
|
||||
"name": "brokkr_kitbash.report",
|
||||
"doc": "Placed kit parts as the scene has them: kit, part, params, faces, shells, each socket's world 4x4, the connection (parent, sockets, roll, residual, holds). Evaluates no modifier. Refuses a part scaled in the world: resize with set_params.",
|
||||
"doc": "Placed kit parts as the scene has them: kit, part, params, faces, shells, each socket's world 4x4, the connection (parent, sockets, roll, residual, holds) and frozen. Evaluates no modifier. Refuses a part scaled in the world: resize with set_params.",
|
||||
"changesScene": false,
|
||||
"editModeSafe": true,
|
||||
"result": "brokkr_mesh_polish_result",
|
||||
|
|
@ -551,6 +551,38 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "brokkr_kitbash.freeze",
|
||||
"doc": "Freeze a mesh object that has modifiers (a kit part, a shell or any mesh) when its cuts are settled: its mesh becomes its evaluated mesh, its live mesh is held by its kit_frozen property, and every modifier stays in the stack, turned off, with its collections and cutters. Blender re-evaluates a live collection Boolean after any removal, hide or mesh read anywhere in the scene; a frozen object costs nothing there. Sockets, connections and report rows stay. set_params, boolean, cut, cut_many, ribs and a shell or hose rebuild refuse a frozen object: thaw it first. Refuses a frozen object, one with no modifiers, one with a modifier already off (named) and one Blender does not evaluate. Reports object (or the part), frozen, faces, volume, nonManifoldEdges, modifiers and booleans.",
|
||||
"changesScene": true,
|
||||
"editModeSafe": false,
|
||||
"result": "brokkr_mesh_polish_result",
|
||||
"fields": [
|
||||
{
|
||||
"name": "object_name",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"minLength": 1,
|
||||
"maxLength": 63
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "brokkr_kitbash.thaw",
|
||||
"doc": "Thaw a frozen object: its live mesh comes back, every modifier is turned on, and the frozen mesh is removed. Evaluates nothing; Blender evaluates the object once afterwards. Refuses an object that is not frozen or whose held mesh is gone. Reports object, frozen false, modifiers and the live mesh's faces.",
|
||||
"changesScene": true,
|
||||
"editModeSafe": false,
|
||||
"result": "brokkr_mesh_polish_result",
|
||||
"fields": [
|
||||
{
|
||||
"name": "object_name",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"minLength": 1,
|
||||
"maxLength": 63
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "brokkr_kitbash.ribs",
|
||||
"doc": "Derive the frame under an armor cage from the cage itself, so it fits the armor by construction: a rib along each plane's section of the cage's surface, set the standoff behind the plate's inner face (along the plate's normal, at any tilt of the plane and any curvature of the wall: its edge is cut from the inner face offset inward, then measured against the plate) and reaching depth inward, clipped inside a crease tighter than that; lightening holes through the ribs; posts that stand the plate off them; longerons through the ribs. The plate's two faces are read from the cage's one Solidify as it evaluates, whatever its thickness mode. A rib stops where the plate is open (a port cut through it), runs behind an opening shorter than bridge (a panel break) and under a recess: openings are read from the cage as it is cut, so cut first. Inward is the side the cage's normals face away from. Makes one mesh object, a child of the cage, baked at this call: after the cage or its cuts change, delete it and run ribs again (its kit_ribs property keeps the request). Every plane and longeron is checked before anything is written. Reports ribs, thickness, sections [{plane, chains, pieces, length, open}], posts, holes, longerons [{index, stations}], faces, volume and nonManifoldEdges.",
|
||||
|
|
|
|||
|
|
@ -479,7 +479,8 @@
|
|||
"brokkr_kitbash.boolean",
|
||||
"brokkr_kitbash.cut",
|
||||
"brokkr_kitbash.cut_many",
|
||||
"brokkr_kitbash.apply",
|
||||
"brokkr_kitbash.freeze",
|
||||
"brokkr_kitbash.thaw",
|
||||
"brokkr_kitbash.ribs",
|
||||
"brokkr_kitbash.shell",
|
||||
"brokkr_kitbash.hose"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"""Live proof, in a background Blender, of brokkr_kitbash assembly through run_intent: attach and its refusals,
|
||||
set_params seating a part and the parts attached to it again, a braced leg closed by close and what set_params,
|
||||
attach and detach then do, drift and how it is cleared, a roll that is not a number, detach, boolean (one Exact Boolean modifier per operation over a collection of cutters, self-intersection on, above the Bevel). Not part
|
||||
attach and detach then do, drift and how it is cleared, a roll that is not a number, detach, boolean (one Exact Boolean modifier per operation over a collection of cutters, self-intersection on, above the Bevel), and freeze and thaw: the frozen shape, the round trip, the refusals, and what a frozen part costs. Not part
|
||||
of the unittest run: it needs Blender.
|
||||
|
||||
blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/kitbash_assembly.py -- <out>
|
||||
|
|
@ -21,6 +21,7 @@ import math
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
import tempfile
|
||||
import types
|
||||
|
|
@ -85,6 +86,12 @@ KEPT = 2.1e-4
|
|||
# intersection off: overlapping shells cancel); separation 6.5 each side. A box through the barrel alone no longer
|
||||
# tells the two apart: the barrel is one shell.
|
||||
CUT = 0.039
|
||||
# Seconds the scene's update takes after an orphan mesh is removed with three cut tanks frozen, over the same with them
|
||||
# live (medians of three, interleaved; every other Boolean in the scene frozen first). Shipped 0.0022 (0.0023 s over 1.05 s); least
|
||||
# claimed mutant 1.5 (F1, freeze leaves the modifiers on: the Booleans run again, on the frozen mesh); the
|
||||
# geometric mean, separation 26 each side. A ratio of two times read in one process: what other work
|
||||
# on the machine does to it is far under the separation.
|
||||
FROZEN_COST = 0.057
|
||||
# Metres an attached child is moved to read holds false. HELD is a rule, 1e-5; least claimed mutant 1e-2 (K12);
|
||||
# the geometric mean of the two, separation 32 each side.
|
||||
NUDGE = 3.2e-4
|
||||
|
|
@ -178,6 +185,10 @@ def measure(mesh):
|
|||
return row
|
||||
|
||||
|
||||
def stack(obj):
|
||||
return [m.name for m in obj.modifiers]
|
||||
|
||||
|
||||
def evaluated(obj):
|
||||
"""(faces, volume, non-manifold edges, material slot names) of the object with its modifiers, read here and not through the add-on."""
|
||||
shown = obj.evaluated_get(bpy.context.evaluated_depsgraph_get())
|
||||
|
|
@ -598,6 +609,71 @@ try:
|
|||
and len(tank.data.polygons) == len(core.build(kit["parts"]["tank"], report["params"]).counts) != raw["faces"]
|
||||
and CUT < resized["volume"] < measure(tank.data)["volume"] - 0.005 and holds("Tee", "Tank", "b", "port_a", 180.0)[0], [receipt["message"], resized])
|
||||
|
||||
# --- freeze and thaw ----------------------------------------------------------------------------------------------------------
|
||||
THAW = "thaw it first"
|
||||
refused("freeze on a mesh with no modifiers", "brokkr_kitbash.freeze", {"object_name": "Plain"}, "'Plain' has no modifiers to freeze")
|
||||
refused("thaw on a live part", "brokkr_kitbash.thaw", {"object_name": "Tank"}, "'Tank' is not frozen")
|
||||
tank.modifiers["Kit Bevel"].show_render = False
|
||||
refused("freeze on a part with a modifier already off names it", "brokkr_kitbash.freeze", {"object_name": "Tank"}, "'Tank' has Kit Bevel off in viewports or renders")
|
||||
tank.modifiers["Kit Bevel"].show_render = True
|
||||
slots = [s.material and s.material.name for s in tank.material_slots]
|
||||
shown, shown_slots = evaluated(tank)
|
||||
index = np.zeros(len(tank.data.polygons), dtype=np.int32)
|
||||
tank.data.polygons.foreach_get("material_index", index)
|
||||
mesh_name, live_faces, meshes, collections = tank.data.name, len(tank.data.polygons), len(bpy.data.meshes), len(bpy.data.collections)
|
||||
sockets_before = send("brokkr_kitbash.report", object_name="Tank")[1]["parts"][0]["sockets"]
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Tank")
|
||||
after = np.zeros(len(tank.data.polygons), dtype=np.int32)
|
||||
tank.data.polygons.foreach_get("material_index", after)
|
||||
facts = frozen and {k: frozen[k] for k in ("faces", "volume", "nonManifoldEdges")}
|
||||
check("freeze makes the evaluated mesh the tank's mesh: the same faces, volume and non-manifold edges, and the tank still evaluates to them",
|
||||
receipt["status"] == "accepted" and facts == shown == measure(tank.data) == evaluated(tank)[0] and tank.data.name == "Tank frozen"
|
||||
and len(bpy.data.meshes) == meshes + 1, [receipt["message"], facts, shown])
|
||||
check("freeze holds the live mesh in kit_frozen and keeps the stack, off, with its collection and cutter", frozen and frozen["frozen"] is True
|
||||
and tank["kit_frozen"].name == mesh_name and len(tank["kit_frozen"].polygons) == live_faces and stack(tank) == frozen["modifiers"] == ["Kit Difference", "Kit Bevel"]
|
||||
and not any(m.show_viewport or m.show_render for m in tank.modifiers) and tank.modifiers["Kit Difference"].collection.objects[:] == [box]
|
||||
and frozen["booleans"] == [{"cutter": "Box", "operation": "DIFFERENCE"}] and len(bpy.data.collections) == collections and "Box" in bpy.context.scene.objects,
|
||||
[frozen, [(m.name, m.show_viewport, m.show_render) for m in tank.modifiers]])
|
||||
check("freeze keeps the material slots exactly, and faces of both materials", slots == shown_slots == ["Tank Paint", "Strap Steel"]
|
||||
and [s.material and s.material.name for s in tank.material_slots] == slots and [m and m.name for m in tank.data.materials] == slots
|
||||
and index.max() == 1 and sorted(set(after.tolist())) == [0, 1], [slots, [m and m.name for m in tank.data.materials], sorted(set(after.tolist()))])
|
||||
check("a frozen part keeps what it is", frozen and tank["kit_part"] == "tank" and json.loads(tank["kit_params"])["segments"] == 16 and frozen["part"] == "tank", dict(tank.items()))
|
||||
RAY = {"origin": [0.0, 0.0, 3.0], "direction": [0.0, 0.0, -1.0], "up": [0.0, 1.0, 0.0]}
|
||||
refused("set_params on a frozen part", "brokkr_kitbash.set_params", {"object_name": "Tank", "params": "length=1.0"}, THAW)
|
||||
refused("boolean on a frozen part", "brokkr_kitbash.boolean", {"object_name": "Tank", "cutter": "Plain"}, THAW)
|
||||
refused("cut on a frozen part", "brokkr_kitbash.cut", {"object_name": "Tank", "cutter_name": "Late", "part": "box", "origin_x": 0.0, "origin_y": 0.0, "origin_z": 3.0,
|
||||
"direction_x": 0.0, "direction_y": 0.0, "direction_z": -1.0, "up_y": 1.0, "up_z": 0.0}, THAW)
|
||||
refused("cut_many on a frozen part", "brokkr_kitbash.cut_many", {"object_name": "Tank", "cuts": json.dumps([{"name": "Late", "part": "box", **RAY}])}, THAW)
|
||||
refused("freeze on a frozen part", "brokkr_kitbash.freeze", {"object_name": "Tank"}, THAW)
|
||||
receipt, report = send("brokkr_kitbash.report", object_name="Tank")
|
||||
check("a frozen part still reports its sockets where its params put them, and what is attached to it still holds", report and report["parts"][0]["frozen"] is True
|
||||
and report["parts"][0]["sockets"] == sockets_before and report["parts"][0]["faces"] == frozen["faces"] and holds("Tee", "Tank", "b", "port_a", 180.0)[0]
|
||||
and holds("Nozzle", "Tee", "mount", "c", 37.0)[0], report)
|
||||
receipt, report = send("brokkr_kitbash.attach", object_name="Radiator", socket="base", parent_name="Tank", parent_socket="saddle")
|
||||
check("a new part attaches to a frozen one", receipt["status"] == "accepted" and held(report)
|
||||
and reading("seated", seated(radiator, "base", tank, "saddle", 0.0)) < SEATED, receipt["message"])
|
||||
receipt, chilled = send("brokkr_kitbash.freeze", object_name="Tee")
|
||||
receipt, report = send("brokkr_kitbash.roll", object_name="Tee", roll=90.0)
|
||||
check("a frozen child rolls where it hangs on a frozen parent, and what hangs on it follows", receipt["status"] == "accepted" and chilled and chilled["frozen"] is True
|
||||
and holds("Tee", "Tank", "b", "port_a", 90.0)[0] and reading("seated", seated(tee, "b", tank, "port_a", 90.0)) < SEATED
|
||||
and holds("Nozzle", "Tee", "mount", "c", 37.0)[0], [receipt["message"], connection("Tee")])
|
||||
send("brokkr_kitbash.roll", object_name="Tee", roll=180.0)
|
||||
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
|
||||
check("the held live mesh survives a purge of orphans", bpy.data.meshes.get(mesh_name) is not None and tank["kit_frozen"] == bpy.data.meshes[mesh_name]
|
||||
and len(tank["kit_frozen"].polygons) == live_faces, sorted(m.name for m in bpy.data.meshes))
|
||||
for name in ("Tee", "Tank"):
|
||||
receipt, thawed = send("brokkr_kitbash.thaw", object_name=name)
|
||||
check("thaw puts the live mesh back, turns every modifier on and removes the frozen mesh", receipt["status"] == "accepted" and tank.data.name == mesh_name and "kit_frozen" not in tank
|
||||
and thawed == {"object": "Tank", "frozen": False, "modifiers": ["Kit Difference", "Kit Bevel"], "faces": live_faces} and stack(tank) == ["Kit Difference", "Kit Bevel"]
|
||||
and all(m.show_viewport and m.show_render for m in tank.modifiers) and "Tank frozen" not in bpy.data.meshes and "kit_frozen" not in tee
|
||||
and len(bpy.data.collections) == collections, [receipt["message"], thawed, sorted(m.name for m in bpy.data.meshes)])
|
||||
check("the thawed tank evaluates to what it did before freeze, and reports frozen false", evaluated(tank)[0] == shown
|
||||
and send("brokkr_kitbash.report", object_name="Tank")[1]["parts"][0]["frozen"] is False, [evaluated(tank)[0], shown])
|
||||
lost = place("Lost", "plate", location=[0.0, -24.0, 0.0])
|
||||
send("brokkr_kitbash.freeze", object_name="Lost")
|
||||
bpy.data.meshes.remove(lost["kit_frozen"])
|
||||
refused("thaw on a frozen part whose held mesh was removed", "brokkr_kitbash.thaw", {"object_name": "Lost"}, "the live mesh its kit_frozen held is gone")
|
||||
|
||||
# --- the second target: a plate with no material slot, cut twice ----------------------------------------------------------------------
|
||||
plate = place("Plate", "plate", location=[0.0, -3.0, 0.0])
|
||||
send("createObject", objectType="MESH", name="Slot", location=[0.1, -3.0, 0.0], size=0.1)
|
||||
|
|
@ -612,9 +688,35 @@ try:
|
|||
and all(m.use_self and m.solver == "EXACT" for m in plate.modifiers if m.type == "BOOLEAN"),
|
||||
[[m.name for m in plate.modifiers], first and first["evaluated"], second and second["evaluated"]])
|
||||
R["plate"] = {"raw": measure(plate.data), "slot": first and first["evaluated"], "slotAndHole": second and second["evaluated"]}
|
||||
twin = plate.copy() # a linked duplicate: it shares the live mesh, and keeps it
|
||||
twin.name = "Plate_twin"
|
||||
bpy.context.scene.collection.objects.link(twin)
|
||||
shown, shown_slots = evaluated(plate)
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Plate")
|
||||
check("freeze on a part with no material slot leaves the frozen mesh with none (Blender's Boolean shows it with one empty slot); a linked duplicate keeps the live mesh",
|
||||
receipt["status"] == "accepted" and shown_slots == [None] and len(plate.data.materials) == 0 and len(plate.material_slots) == 0
|
||||
and frozen["booleans"] == second["booleans"] and {k: frozen[k] for k in ("faces", "volume", "nonManifoldEdges")} == shown
|
||||
and twin.data.name == "Plate" and plate["kit_frozen"] == twin.data and all(m.show_viewport for m in twin.modifiers),
|
||||
[shown_slots, len(plate.data.materials), len(plate.material_slots), frozen])
|
||||
bpy.data.objects.remove(twin)
|
||||
send("brokkr_kitbash.thaw", object_name="Plate")
|
||||
send("assignMaterial", targetObjectName="Plate", materialName="Plate Paint", color=[0.35, 0.35, 0.35])
|
||||
send("createObject", objectType="MESH", name="Boss", location=[0.0, -3.0, 0.1], size=0.06)
|
||||
send("assignMaterial", targetObjectName="Boss", materialName="Boss Brass", color=[0.6, 0.5, 0.2])
|
||||
send("setObjectTransform", targetObjectName="Boss", location=[0.0, -3.0, 0.02])
|
||||
receipt, third = send("brokkr_kitbash.boolean", object_name="Plate", cutter="Boss", operation="UNION")
|
||||
shown, shown_slots = evaluated(plate)
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Plate")
|
||||
used = np.zeros(len(plate.data.polygons), dtype=np.int32)
|
||||
plate.data.polygons.foreach_get("material_index", used)
|
||||
check("a thawed part is cut and frozen again; a cutter that has a material brings it after the part's own slots, on the faces it made",
|
||||
receipt["status"] == "accepted" and third["booleans"][-1] == {"cutter": "Boss", "operation": "UNION"} and third["frozen"] is False and frozen["frozen"] is True
|
||||
and third["evaluated"]["volume"] > R["plate"]["slotAndHole"]["volume"] and shown_slots == ["Plate Paint", "Boss Brass"]
|
||||
and [m and m.name for m in plate.data.materials] == ["Plate Paint", "Boss Brass"] and sorted(set(used.tolist())) == [0, 1]
|
||||
and stack(plate) == ["Kit Difference", "Kit Union", "Kit Bevel"], [third and third["evaluated"], shown_slots, [m and m.name for m in plate.data.materials], sorted(set(used.tolist()))])
|
||||
vent = place("Vent", "vent", "width=0.2; height=0.15")
|
||||
receipt, report = send("brokkr_kitbash.attach", object_name="Vent", socket="back", parent_name="Plate", parent_socket="front")
|
||||
check("a vent that fits attaches to the cut plate's front", receipt["status"] == "accepted" and held(report)
|
||||
check("a vent that fits attaches to the frozen plate's front", receipt["status"] == "accepted" and held(report)
|
||||
and reading("seated", seated(vent, "back", plate, "front", 0.0)) < SEATED, receipt["message"])
|
||||
refused("a loop of two", "brokkr_kitbash.attach", {"object_name": "Plate", "socket": "back", "parent_name": "Vent", "parent_socket": "back"},
|
||||
"'Vent' is below 'Plate'")
|
||||
|
|
@ -631,6 +733,82 @@ try:
|
|||
check("a tee with a box cut from it has no non-manifold edge: its branch hub is narrower than its run hub", receipt["status"] == "accepted" and cut
|
||||
and cut["evaluated"]["nonManifoldEdges"] == 0 and 0.004 < cut["evaluated"]["volume"] < 0.008, [receipt["message"], cut and cut["evaluated"]])
|
||||
|
||||
# --- freeze and empty material slots ----------------------------------------------------------------------------------------------
|
||||
keeper = place("Keeper", "plate", location=[0.0, -9.0, 0.0])
|
||||
send("assignMaterial", targetObjectName="Keeper", materialName="Plate Paint", color=[0.35, 0.35, 0.35])
|
||||
keeper.data.materials.append(None) # an empty last slot the part was given
|
||||
send("createObject", objectType="MESH", name="Bare", location=[0.1, -9.0, 0.0], size=0.1)
|
||||
send("brokkr_kitbash.boolean", object_name="Keeper", cutter="Bare")
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Keeper")
|
||||
check("freeze keeps a part's own empty last slot when the cutter has no material", receipt["status"] == "accepted" and keeper.data.name == "Keeper frozen"
|
||||
and [m and m.name for m in keeper.data.materials] == ["Plate Paint", None] and len(keeper.material_slots) == 2,
|
||||
[receipt["message"], [m and m.name for m in keeper.data.materials]])
|
||||
gapped = place("Gapped", "plate", location=[0.0, -12.0, 0.0])
|
||||
send("assignMaterial", targetObjectName="Gapped", materialName="Plate Paint", color=[0.35, 0.35, 0.35])
|
||||
send("createObject", objectType="MESH", name="Gap", location=[0.1, -12.0, 0.0], size=0.1)
|
||||
gap = bpy.data.objects["Gap"]
|
||||
gap.data.materials.append(None) # the cutter's faces are in an empty first slot
|
||||
gap.data.materials.append(bpy.data.materials["Boss Brass"])
|
||||
gap.data.polygons[0].material_index = gap.data.polygons[1].material_index = 1 # two of its faces are brass; the rest stay in the empty slot
|
||||
send("brokkr_kitbash.boolean", object_name="Gapped", cutter="Gap")
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Gapped")
|
||||
used = np.zeros(len(gapped.data.polygons), dtype=np.int32)
|
||||
gapped.data.polygons.foreach_get("material_index", used)
|
||||
check("freeze leaves no face outside the material slots when a cutter's first slot is empty", receipt["status"] == "accepted" and len(used) > 44
|
||||
and used.min() >= 0 and used.max() < len(gapped.data.materials) and not gapped.data.validate_material_indices() and not gapped.data.validate(verbose=False),
|
||||
[receipt["message"], int(used.min()), int(used.max()), [m and m.name for m in gapped.data.materials]])
|
||||
names = [m and m.name for m in gapped.data.materials]
|
||||
brass = [p.index for p in gapped.data.polygons if "Boss Brass" in names and p.material_index == names.index("Boss Brass")]
|
||||
far = [p.index for p in gapped.data.polygons if (gapped.matrix_world @ p.center).x < -0.05] # the plate's half the cutter does not reach
|
||||
check("and each face keeps its own slot: the cutter's brass faces are brass, the faces from its empty slot and the plate's own are the plate's paint",
|
||||
names[0] == "Plate Paint" and 0 < len(brass) < len(used) and far and all(used[i] == 0 for i in far)
|
||||
and all(abs((gapped.matrix_world @ gapped.data.polygons[i].center).x - 0.1) < 0.051 for i in brass), [names, len(brass), len(far), sorted(set(used.tolist()))])
|
||||
|
||||
# --- a frozen part is cheap -------------------------------------------------------------------------------------------------------
|
||||
# Blender re-evaluates every live collection Boolean in the scene after any datablock is removed (docs/kitbash.md). Every
|
||||
# other cut object is frozen first, so the update timed here evaluates the three tanks' Booleans or none.
|
||||
for obj in [o for o in bpy.context.scene.objects if o.type == "MESH" and any(m.type == "BOOLEAN" and m.show_viewport for m in o.modifiers)]:
|
||||
send("brokkr_kitbash.freeze", object_name=obj.name)
|
||||
tanks = []
|
||||
for n in range(3):
|
||||
tanks.append(place(f"Cold{n}", "tank", location=[6.0, 3.0 * n, 0.0]))
|
||||
send("createObject", objectType="MESH", name=f"ColdBox{n}", location=[6.3, 3.0 * n, 0.0], size=0.3)
|
||||
send("brokkr_kitbash.boolean", object_name=f"Cold{n}", cutter=f"ColdBox{n}")
|
||||
SEEN = []
|
||||
|
||||
def seen(scene, depsgraph):
|
||||
SEEN.extend(u.id.original.name for u in depsgraph.updates if isinstance(u.id, bpy.types.Object) and u.is_updated_geometry
|
||||
and u.id.original.type == "MESH" and any(m.type == "BOOLEAN" and m.show_viewport for m in u.id.original.modifiers))
|
||||
|
||||
def orphan_removed():
|
||||
"""(seconds the scene's update takes after an orphan mesh is removed, the objects with a shown Boolean it re-evaluated)"""
|
||||
mesh = bpy.data.meshes.new("Orphan")
|
||||
bpy.context.view_layer.update()
|
||||
SEEN.clear()
|
||||
start = time.perf_counter()
|
||||
bpy.data.meshes.remove(mesh)
|
||||
bpy.context.view_layer.update()
|
||||
return time.perf_counter() - start, sorted(set(SEEN))
|
||||
|
||||
bpy.app.handlers.depsgraph_update_post.append(seen)
|
||||
costs = {"live": [], "frozen": []}
|
||||
for _ in range(3):
|
||||
bpy.context.view_layer.update()
|
||||
costs["live"].append(orphan_removed())
|
||||
for obj in tanks:
|
||||
send("brokkr_kitbash.freeze", object_name=obj.name)
|
||||
bpy.context.view_layer.update()
|
||||
costs["frozen"].append(orphan_removed())
|
||||
for obj in tanks:
|
||||
send("brokkr_kitbash.thaw", object_name=obj.name)
|
||||
bpy.app.handlers.depsgraph_update_post.remove(seen)
|
||||
medians = {state: sorted(seconds for seconds, _ in rows)[1] for state, rows in costs.items()}
|
||||
R["frozenCost"] = {"liveSeconds": round(medians["live"], 4), "frozenSeconds": round(medians["frozen"], 5),
|
||||
"live": [[round(s, 4), names] for s, names in costs["live"]], "frozen": [[round(s, 5), names] for s, names in costs["frozen"]]}
|
||||
check("removing an orphan mesh re-evaluates the three live cut tanks, and none of them frozen", all(names == ["Cold0", "Cold1", "Cold2"] for _, names in costs["live"])
|
||||
and all(names == [] for _, names in costs["frozen"]), R["frozenCost"])
|
||||
check("and the update with them frozen costs under the bound of what it costs with them live",
|
||||
reading("frozenCost", medians["frozen"] / medians["live"]) < FROZEN_COST, R["frozenCost"])
|
||||
except Exception: # noqa: BLE001 whatever it was, it is a failed check with a name, printed and written, not a missing result file
|
||||
check(f"no uncaught error after: {R['checks'][-1]['name'] if R['checks'] else 'the start'}", False, traceback.format_exc().splitlines()[-6:])
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a part nobody attached reports connection null and baked false",
|
||||
"name": "a part nobody attached reports connection null",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
|
|
@ -497,42 +497,97 @@
|
|||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: apply on a mesh that is not a kit part",
|
||||
"name": "refused, scene unchanged: freeze on a mesh with no modifiers",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "apply makes the evaluated mesh the tank's mesh: the same faces and volume, no modifiers, one mesh datablock of the old name",
|
||||
"name": "refused, scene unchanged: thaw on a live part",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "apply keeps the material slots exactly, and faces of both materials",
|
||||
"name": "refused, scene unchanged: freeze on a part with a modifier already off names it",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "apply marks the part baked and keeps what it is",
|
||||
"name": "freeze makes the evaluated mesh the tank's mesh: the same faces, volume and non-manifold edges, and the tank still evaluates to them",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: set_params on a baked part",
|
||||
"name": "freeze holds the live mesh in kit_frozen and keeps the stack, off, with its collection and cutter",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: apply on a baked part with no modifiers left",
|
||||
"name": "freeze keeps the material slots exactly, and faces of both materials",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a baked part still reports its sockets where its params put them, and what is attached to it still holds",
|
||||
"name": "a frozen part keeps what it is",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a new part attaches to a baked one",
|
||||
"name": "refused, scene unchanged: set_params on a frozen part",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: boolean on a frozen part",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: cut on a frozen part",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: cut_many on a frozen part",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: freeze on a frozen part",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a frozen part still reports its sockets where its params put them, and what is attached to it still holds",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a new part attaches to a frozen one",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a frozen child rolls where it hangs on a frozen parent, and what hangs on it follows",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "the held live mesh survives a purge of orphans",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "thaw puts the live mesh back, turns every modifier on and removes the frozen mesh",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "the thawed tank evaluates to what it did before freeze, and reports frozen false",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: thaw on a frozen part whose held mesh was removed",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
|
|
@ -542,22 +597,17 @@
|
|||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: apply on a mesh a linked duplicate shares",
|
||||
"name": "freeze on a part with no material slot leaves the frozen mesh with none (Blender's Boolean shows it with one empty slot); a linked duplicate keeps the live mesh",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "apply on a part with no material slot leaves it with none (Blender's Boolean shows it with one empty slot)",
|
||||
"name": "a thawed part is cut and frozen again; a cutter that has a material brings it after the part's own slots, on the faces it made",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a baked part is cut and baked again; a cutter that has a material brings it after the part's own slots, on the faces it made",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "a vent that fits attaches to the baked plate's front",
|
||||
"name": "a vent that fits attaches to the frozen plate's front",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
|
|
@ -577,12 +627,12 @@
|
|||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "apply keeps a part's own empty last slot when the cutter has no material",
|
||||
"name": "freeze keeps a part's own empty last slot when the cutter has no material",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "apply leaves no face outside the material slots when a cutter's first slot is empty",
|
||||
"name": "freeze leaves no face outside the material slots when a cutter's first slot is empty",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
|
|
@ -590,6 +640,16 @@
|
|||
"name": "and each face keeps its own slot: the cutter's brass faces are brass, the faces from its empty slot and the plate's own are the plate's paint",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "removing an orphan mesh re-evaluates the three live cut tanks, and none of them frozen",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "and the update with them frozen costs under the bound of what it costs with them live",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
}
|
||||
],
|
||||
"hostErrors": [],
|
||||
|
|
@ -598,6 +658,7 @@
|
|||
"close nudged": 0.00032,
|
||||
"closed": 3.9e-07,
|
||||
"cut": 0.25,
|
||||
"frozenCost": 0.0016,
|
||||
"kept": 6e-08,
|
||||
"nudged": 0.00032,
|
||||
"roll": 6.6e-06,
|
||||
|
|
@ -637,5 +698,49 @@
|
|||
"volume": 0.006031088,
|
||||
"nonManifoldEdges": 0
|
||||
},
|
||||
"frozenCost": {
|
||||
"liveSeconds": 1.0356,
|
||||
"frozenSeconds": 0.00168,
|
||||
"live": [
|
||||
[
|
||||
1.0412,
|
||||
[
|
||||
"Cold0",
|
||||
"Cold1",
|
||||
"Cold2"
|
||||
]
|
||||
],
|
||||
[
|
||||
1.0356,
|
||||
[
|
||||
"Cold0",
|
||||
"Cold1",
|
||||
"Cold2"
|
||||
]
|
||||
],
|
||||
[
|
||||
0.9348,
|
||||
[
|
||||
"Cold0",
|
||||
"Cold1",
|
||||
"Cold2"
|
||||
]
|
||||
]
|
||||
],
|
||||
"frozen": [
|
||||
[
|
||||
0.00168,
|
||||
[]
|
||||
],
|
||||
[
|
||||
0.00264,
|
||||
[]
|
||||
],
|
||||
[
|
||||
0.00165,
|
||||
[]
|
||||
]
|
||||
]
|
||||
},
|
||||
"ok": true
|
||||
}
|
||||
|
|
@ -398,6 +398,57 @@ try:
|
|||
receipt["status"] == "accepted" and stack(plate) == ["Kit Difference", "Kit Union", "Kit Intersect", "Kit Bevel"]
|
||||
and report["booleans"] == [{"cutter": "Hole", "operation": "DIFFERENCE"}, {"cutter": "Boss", "operation": "UNION"}, {"cutter": "Keep", "operation": "INTERSECT"}]
|
||||
and report["evaluated"]["nonManifoldEdges"] == 0 and report["kit"] == "mechanical", [stack(plate), report and report["booleans"]])
|
||||
THAW = "thaw it first"
|
||||
shown, cage_shown, collections = evaluated(plate)[0], evaluated(cage)[0], len(bpy.data.collections)
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Plate")
|
||||
check("freeze keeps the three modifiers, off, the three collections they read and every cutter in the scene", receipt["status"] == "accepted"
|
||||
and frozen["booleans"] == report["booleans"] and len(bpy.data.collections) == collections and frozen["modifiers"] == stack(plate) == ["Kit Difference", "Kit Union", "Kit Intersect", "Kit Bevel"]
|
||||
and not any(m.show_viewport or m.show_render for m in plate.modifiers) and {k: frozen[k] for k in ("faces", "volume", "nonManifoldEdges")} == shown == evaluated(plate)[0]
|
||||
and all(name in bpy.context.scene.objects for name in ("Hole", "Boss", "Keep")), [receipt["message"], frozen, shown])
|
||||
cage_stack, cage_mesh = stack(cage), cage.data.name
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Cage")
|
||||
check("freeze takes the cage, which is not a kit part: its evaluated wall, its stack off, its cutters still its children", receipt["status"] == "accepted" and frozen["object"] == "Cage"
|
||||
and "kit" not in frozen and frozen["frozen"] is True and {k: frozen[k] for k in ("faces", "volume", "nonManifoldEdges")} == cage_shown == evaluated(cage)[0]
|
||||
and frozen["modifiers"] == stack(cage) == cage_stack and not any(m.show_viewport or m.show_render for m in cage.modifiers) and cage.data.name == "Cage frozen"
|
||||
and bpy.data.objects["Bay"].parent == cage and len(bpy.data.collections) == collections, [receipt["message"], frozen and frozen["modifiers"], cage_shown])
|
||||
refused("ribs from a frozen cage", "brokkr_kitbash.ribs", {"object_name": "Cage", "ribs_name": "ColdRibs", "planes": json.dumps([{"origin": [0.0, 0.0, 0.5], "normal": [0.0, 0.0, 1.0]}])}, THAW)
|
||||
refused("cut on a frozen cage", "brokkr_kitbash.cut", {"object_name": "Cage", "cutter_name": "Late", "part": "box", "origin_x": 3.0, "origin_y": 0.0, "origin_z": 0.1,
|
||||
"direction_x": -1.0, "direction_y": 0.0, "direction_z": 0.0}, THAW)
|
||||
refused("cut_many on a frozen cage", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{"name": "Late", "part": "box", "origin": [3.0, 0.0, 0.1], "direction": [-1.0, 0.0, 0.0]}])}, THAW)
|
||||
refused("boolean on a frozen cage", "brokkr_kitbash.boolean", {"object_name": "Cage", "cutter": "Hole"}, THAW)
|
||||
for name in ("Plate", "Cage"):
|
||||
receipt, thawed = send("brokkr_kitbash.thaw", object_name=name)
|
||||
check("thaw gives both back: the live meshes, every modifier on, the frozen meshes gone, and the same evaluated shapes", receipt["status"] == "accepted"
|
||||
and thawed == {"object": "Cage", "frozen": False, "modifiers": cage_stack, "faces": len(cage.data.polygons)} and cage.data.name == cage_mesh
|
||||
and all(m.show_viewport and m.show_render for o in (plate, cage) for m in o.modifiers) and not any(n in bpy.data.meshes for n in ("Cage frozen", "Plate frozen"))
|
||||
and "kit_frozen" not in cage and "kit_frozen" not in plate and evaluated(plate)[0] == shown and evaluated(cage)[0] == cage_shown,
|
||||
[receipt["message"], thawed, sorted(m.name for m in bpy.data.meshes)])
|
||||
twin = place("Twin", "plate", location=[0.0, -15.0, 0.0])
|
||||
send("createObject", objectType="MESH", name="TwinHole", location=[0.0, -15.0, 0.0], size=0.05)
|
||||
send("brokkr_kitbash.boolean", object_name="Twin", cutter="TwinHole")
|
||||
copied = twin.copy() # a copied part: its own mesh, and a Kit Difference modifier that reads the same collection
|
||||
copied.data = twin.data.copy()
|
||||
bpy.context.scene.collection.objects.link(copied)
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Twin")
|
||||
kept = bpy.data.collections.get("Twin difference")
|
||||
check("M6: a frozen part and its copy still read the one collection, and the copy stays live", receipt["status"] == "accepted" and kept is not None
|
||||
and twin.modifiers["Kit Difference"].collection == kept == copied.modifiers["Kit Difference"].collection and [o.name for o in kept.objects] == ["TwinHole"]
|
||||
and "kit_frozen" in twin and all(m.show_viewport for m in copied.modifiers), [receipt["message"], [c.name for c in bpy.data.collections]])
|
||||
send("brokkr_kitbash.thaw", object_name="Twin")
|
||||
RINGS = [[[x, y, 0.1 - x * x] for x in (-0.3, -0.1, 0.1, 0.3)] for y in (0.0, 0.2, 0.4)]
|
||||
lid = {"object_name": "Lid", "sheet": json.dumps({"rings": RINGS}), "thickness": 0.02, "levels": 2}
|
||||
send("brokkr_kitbash.shell", **lid)
|
||||
send("setObjectTransform", targetObjectName="Lid", location=[0.0, -30.0, 0.0])
|
||||
wall = evaluated(bpy.data.objects["Lid"])[0]
|
||||
receipt, frozen = send("brokkr_kitbash.freeze", object_name="Lid")
|
||||
check("freeze takes a shell: the wall its Kit Subsurf and Kit Solidify make", receipt["status"] == "accepted" and frozen["modifiers"] == ["Kit Subsurf", "Kit Solidify"]
|
||||
and {k: frozen[k] for k in ("faces", "volume", "nonManifoldEdges")} == wall and wall["faces"] > 2 * 6 * 16, [receipt["message"], frozen, wall])
|
||||
refused("a rebuild of a frozen shell", "brokkr_kitbash.shell", lid, THAW)
|
||||
refused("a rebuild of a frozen shell that counts folds", "brokkr_kitbash.shell", {**lid, "count_folds": True}, THAW)
|
||||
send("brokkr_kitbash.thaw", object_name="Lid")
|
||||
receipt, rebuilt = send("brokkr_kitbash.shell", **lid)
|
||||
check("and thawed, the shell rebuilds", receipt["status"] == "accepted" and rebuilt["rebuilt"] is True and evaluated(bpy.data.objects["Lid"])[0] == wall, [receipt["message"], rebuilt])
|
||||
|
||||
# --- cut-refusals -----------------------------------------------------------------------------------------------------------
|
||||
section('cut-refusals')
|
||||
RAY = {"object_name": "Cage", "cutter_name": "New", "part": "box", "origin_x": 3.0, "origin_y": 0.0, "origin_z": 0.1, "direction_x": -1.0, "direction_y": 0.0, "direction_z": 0.0}
|
||||
|
|
@ -454,6 +505,8 @@ try:
|
|||
refused(f"cut_many on a target {why}", "brokkr_kitbash.cut_many",
|
||||
{"object_name": name, "cuts": json.dumps([{"name": "Unseen", "part": "box", "origin": [0.1, 0.1, 3.0], "direction": [0.0, 0.0, -1.0], "up": [0.0, 1.0, 0.0]}])}, NOT)
|
||||
refused(f"boolean on a target {why}", "brokkr_kitbash.boolean", {"object_name": name, "cutter": "Sheet"}, NOT)
|
||||
refused("freeze on a part disabled in viewports", "brokkr_kitbash.freeze", {"object_name": "Plate"}, "Blender does not evaluate 'Plate' in this view layer")
|
||||
refused("freeze on a part in a collection outside the view layer", "brokkr_kitbash.freeze", {"object_name": "Loose"}, "Blender does not evaluate 'Loose' in this view layer")
|
||||
veil.hide_viewport = plate.hide_viewport = False
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
|
|
|
|||
|
|
@ -222,17 +222,62 @@
|
|||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "apply removes the three collections its modifiers held and leaves every cutter in the scene",
|
||||
"name": "freeze keeps the three modifiers, off, the three collections they read and every cutter in the scene",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: apply on the cage, which is not a kit part",
|
||||
"name": "freeze takes the cage, which is not a kit part: its evaluated wall, its stack off, its cutters still its children",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "M6: apply keeps a collection a copied part's modifier still reads",
|
||||
"name": "refused, scene unchanged: ribs from a frozen cage",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: cut on a frozen cage",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: cut_many on a frozen cage",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: boolean on a frozen cage",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "thaw gives both back: the live meshes, every modifier on, the frozen meshes gone, and the same evaluated shapes",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "M6: a frozen part and its copy still read the one collection, and the copy stays live",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "freeze takes a shell: the wall its Kit Subsurf and Kit Solidify make",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: a rebuild of a frozen shell",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: a rebuild of a frozen shell that counts folds",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "and thawed, the shell rebuilds",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
|
|
@ -327,12 +372,12 @@
|
|||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: apply on a part disabled in viewports",
|
||||
"name": "refused, scene unchanged: freeze on a part disabled in viewports",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: apply on a part in a collection outside the view layer",
|
||||
"name": "refused, scene unchanged: freeze on a part in a collection outside the view layer",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1812,7 +1812,7 @@ class SheetTests(unittest.TestCase):
|
|||
|
||||
ROWS = ["brokkr_kitbash.place_part", "brokkr_kitbash.set_params", "brokkr_kitbash.describe", "brokkr_kitbash.report",
|
||||
"brokkr_kitbash.attach", "brokkr_kitbash.detach", "brokkr_kitbash.roll", "brokkr_kitbash.aim", "brokkr_kitbash.reach", "brokkr_kitbash.close",
|
||||
"brokkr_kitbash.boolean", "brokkr_kitbash.cut", "brokkr_kitbash.cut_many", "brokkr_kitbash.ribs",
|
||||
"brokkr_kitbash.boolean", "brokkr_kitbash.cut", "brokkr_kitbash.cut_many", "brokkr_kitbash.freeze", "brokkr_kitbash.thaw", "brokkr_kitbash.ribs",
|
||||
"brokkr_kitbash.shell", "brokkr_kitbash.hose"]
|
||||
|
||||
|
||||
|
|
@ -1859,6 +1859,7 @@ class HostFileTests(unittest.TestCase):
|
|||
self.assertEqual(at.validate(boolean, host)["operation"], "DIFFERENCE")
|
||||
for bad in ({**attach, "roll": 360.5}, {**attach, "socket": "a b"}, {**attach, "parent_socket": ""}, {**attach, "matrix": [1, 0, 0]},
|
||||
{**boolean, "operation": "SLICE"}, {**boolean, "solver": "EXACT"}, {**boolean, "cutter": ""},
|
||||
{**envelope, "action": "brokkr_kitbash.freeze"}, {**envelope, "action": "brokkr_kitbash.thaw", "object_name": ""},
|
||||
{**envelope, "action": "brokkr_kitbash.detach", "object_name": "x" * 64},
|
||||
{**close, "socket": "end b"}, {**close, "other_socket": "x" * 33}, {**close, "other_name": ""}, {**close, "roll": 10},
|
||||
{k: v for k, v in close.items() if k != "other_socket"}):
|
||||
|
|
@ -1973,10 +1974,20 @@ class OwnershipTests(unittest.TestCase):
|
|||
self.assertLess(place.index("modifier.show_viewport = False"), place.index("evaluable("))
|
||||
self.assertLess(place.index("evaluable("), place.index("modifier.show_viewport = True"))
|
||||
# unevaluable-target: every action that evaluates refuses an object Blender does not evaluate before its first write
|
||||
for body, first_write in ((place, "bpy.data.meshes.new("), (bodies["boolean"], ".objects.link("),
|
||||
for body, first_write in ((place, "bpy.data.meshes.new("), (bodies["boolean"], ".objects.link("), (bodies["freeze"], "bpy.data.meshes.new_from_object("),
|
||||
(bodies["ribs"], "show_viewport = False"), (bodies["shell"], "clear_geometry()")):
|
||||
self.assertLess(body.index("evaluable("), body.index(first_write))
|
||||
self.assertEqual([name for name, body in bodies.items() if "evaluable(" in body], ["boolean", "ribs", "shell", "hose"])
|
||||
self.assertEqual([name for name, body in bodies.items() if "evaluable(" in body], ["boolean", "freeze", "ribs", "shell", "hose"])
|
||||
# frozen: thaw evaluates nothing, and every action that writes a mesh or a modifier stack refuses a frozen object before its first write
|
||||
for call in ("evaluable(", "evaluated_of(", "to_mesh(", "depsgraph", "view_layer.update"):
|
||||
self.assertNotIn(call, bodies["thaw"])
|
||||
for body, first_write in ((place, "bpy.data.meshes.new("), (bodies["boolean"], ".objects.link("), (bodies["freeze"], "bpy.data.meshes.new_from_object("),
|
||||
(bodies["ribs"], "show_viewport = False"), (bodies["shell"], "clear_geometry()"), (bodies["set_params"], "write_mesh("),
|
||||
(bodies["hose"], "write_mesh(")):
|
||||
self.assertLess(body.index("live("), body.index(first_write))
|
||||
self.assertEqual((source.count("obj[FROZEN] ="), source.count("del obj[FROZEN]"), source.count("live(")), (1, 1, 8)) # its def and the seven callers above
|
||||
self.assertIn("obj[FROZEN] =", bodies["freeze"])
|
||||
self.assertIn("del obj[FROZEN]", bodies["thaw"])
|
||||
ribs = bodies["ribs"] # every refusal before the ribs object is written, and the cage's modifiers shown again whatever happened
|
||||
self.assertLess(ribs.rindex("raise Refused("), ribs.index("mesh = bpy.data.meshes.new(self.ribs_name)"))
|
||||
self.assertLess(ribs.index("finally:"), ribs.index("modifier.show_viewport = True"))
|
||||
|
|
@ -2100,7 +2111,7 @@ class OwnershipTests(unittest.TestCase):
|
|||
self.assertEqual(assigned, [" obj[CLOSE], obj[CLOSE_TO], obj[CLOSE_TO_SOCKET] = self.socket, other, self.other_socket"])
|
||||
self.assertIn(assigned[0], bodies["close"])
|
||||
deleted = re.findall(r"[^\n]*\(SOCKET, PARENT_SOCKET, ROLL, CLOSE, CLOSE_TO, CLOSE_TO_SOCKET\)[^\n]*\n[^\n]*\n\s*del obj\[key\]", source)
|
||||
self.assertEqual((len(deleted), source.count("del obj["), "del obj[key]" in bodies["detach"]), (1, 1, True))
|
||||
self.assertEqual((len(deleted), source.count("del obj["), "del obj[key]" in bodies["detach"]), (1, 2, True)) # detach's keys, and thaw's kit_frozen
|
||||
self.assertEqual(source.count("CLOSE_TO]"), 1) # the one subscript write above; every read goes through .get
|
||||
placing = r"matrix_basis|matrix_world\s*=(?!=)|matrix_parent_inverse|\.parent\s*=(?!=)|\bseat\(|\.location|\.rotation"
|
||||
self.assertIsNone(re.search(placing, bodies["close"]))
|
||||
|
|
|
|||
Loading…
Reference in a new issue