Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.6

0.11.6 / tools / preview_kernel.luc

## The captures of the kernel work guided by the SMLib study
## (luce-cad/docs/research/SMLIB-STUDY.md, its comparison cases; preview_cad.luc
## hands these scenes here). Each in a CAD network, best at --cad-quality 64:
##   kernel_holed_ball: a ball of 10 with eight blind holes of 2 all round
##     it (six round Z at 45°, two along Z), the study's T2: every face
##     meshed at 64 divisions.
##   kernel_tee: a T of pipes of 5 and 3, its saddle filleted 1 (the
##     study's F7): the long pipe's face meshed at 64 divisions.
##   kernel_coincident: a box rounded G2 at its uprights (5) joined with
##     its copy moved half its height (the study's B9): the strips lie on
##     each other over their common half, imprinted, not traced.
##   kernel_six_holes: a ball of 10 with six blind holes of 2 along the
##     axes, through both poles of the sphere's chart: its faces meshed
##     about axes of their own (sphere_axis), at 32 divisions.
##   kernel_crossed_pipes: two pipes of 5 crossing at right angles, joined
##     (the study's B4): the two ellipses cut where the pipes touch.
##   kernel_shell: a box rounded G2 at its uprights (5), shelled 1 with its
##     top opened (the study's S2): the strips' offsets fitted B-splines.
##   kernel_overflow: a plate 4 thick, its top edge filleted 5 (the study's
##     F6), Overflow's Cliff off: notch, the bottom trims it.
##   kernel_cliff: a plate 4 thick on a ledge, its top edge filleted 5, Cliff
##     off: notch, the ledge covering its end.
##   kernel_cliff_edge: kernel_overflow's plate by default (Cliff on, More
##     options open): a cliff-edge blend, tangent to the top and through
##     the side face's bottom edge, as Fusion's.
##   kernel_rolled_on: the plate's bottom side edge rounded 3, its top edge
##     rounded 1.5: the ball rolls off the side face onto the round (smooth
##     overflow onto a curved tangent face).
##   kernel_rounded_shell: a 20 cube rounded 1 on every edge, shelled 2
##     with its top open: the rounds vanish from the hollow (its inside
##     sharp).
##   kernel_apex: a rectangular pyramid rounded 1 on every edge, G2: an
##     eight-quad setback patch closes its apex, built directly.
##   kernel_apex_g1: the same pyramid's four apex edges alone rounded 1,
##     G1: the patch's quads rational, the strips cylinders.
##   kernel_moved_top: a box rounded G2 at its uprights (5), its top moved
##     up 5: the strips extended naturally to meet it.
##   kernel_healed_corner: a pipe of 10 with a box boss on its side, the
##     boss's inside uprights rounded 1 and the rounds deleted: healed to
##     the sharp corner on the curved wall.
##   kernel_thin_stitch: a plate 0.002 thin, unstitched and stitched within
##     0.003: one closed body, no side glued to its own other side.
##   kernel_y_boss, kernel_y_boss_g2: a plate with a 6 cube boss, the
##     boss's upright and one foot edge filleted 1 in one feature (a Y
##     corner): the foot runs on, the upright's section rolls round its end
##     (a torus at G1, its section swept at G2), cut by the plate.
##   kernel_y_ell: an L's inside upright and one top edge filleted 2: the
##     top edge runs on, the upright's section rolls round its end.
##   kernel_mixed_g2: the boss's upright and both foot edges filleted 1, G2:
##     the feet's section rolled round the upright's end (Fusion's rolling
##     ball), built directly.
##   kernel_inside_rolled: a plate's wall 2 high, its top rounded 1.5, its
##     foot filleted 3: the ball rolls in the air onto the round (Fusion's).
##   kernel_notch_end: a cube's top edge rounded 4 where its side is
##     notched below one end: the notch's faces trim the fillet (Fusion's).
##   kernel_vertex_blend: an L's inside upright and both top edges filleted
##     2, Setback corner type (More options open): a vertex blend of six
##     quads, the fillets 2 r back, Corner edge shape and fullness rows.
##   kernel_g2_shell: a 20 cube rounded 3 G2 on every edge, shelled 1
##     closed (a void) and cut in half to show the wall: its corners'
##     offsets meet as tolerant vertices.
##   kernel_three_sided: a 20 cube's corner, its three edges filleted 4 G2
##     (Fusion's Rolling ball corner): the strips stop r from the corner,
##     three quads join their end sections (best with --mode 7, zebra).
##   kernel_ell_shell: an L rounded 1 on every edge, shelled 2 closed and
##     cut in half: the hollow from the cells of the L's planes, its convex
##     rounds swallowed, its inside round grown to 3 (Fusion's 3423.30).
import preview_support
from luce_3d.graphics import Vector3
from app import Luce3D
from workspace import Workspace
import node_commands
import edit_cad_faces
import cad_blends
import edit_cad_surfaces
from luce_cad.model import CadModel
from luce_cad.cad_geometry import CadGeometry
from luce_cad.modeling import CadModeling
from luce_std import math

pub func scenes() -> list[str]:
    return ["kernel_holed_ball", "kernel_tee", "kernel_coincident", "kernel_six_holes", "kernel_crossed_pipes", "kernel_shell", "kernel_overflow",
            "kernel_cliff", "kernel_rounded_shell", "kernel_apex", "kernel_apex_g1", "kernel_moved_top", "kernel_healed_corner", "kernel_thin_stitch", "kernel_g2_shell", "kernel_cliff_edge", "kernel_rolled_on",
            "kernel_y_boss", "kernel_y_boss_g2", "kernel_y_ell", "kernel_mixed_g2", "kernel_vertex_blend", "kernel_inside_rolled", "kernel_notch_end",
            "kernel_three_sided", "kernel_ell_shell"]

pub func setup(editor: Luce3D, scene: str) -> unit!:
    let w = editor.workspace
    node_commands.delete_selected(w)
    node_commands.add_node(w, "CAD", 40.0, 40.0)
    node_commands.enter_group(w, w.network.selected)
    if scene == "kernel_holed_ball":
        node_commands.add_node(w, "Solid Sphere", 40.0, 40.0)
        node_commands.set_parameter(w, 0, 10.0)
        var body = w.network.selected
        var k = 0
        for degrees in [90.0, 45.0, 135.0, -90.0, -45.0, -135.0]:
            let theta = degrees * math.pi / 180.0
            let axis = Vector3(-math.sin(theta), math.cos(theta), 0.0)
            body = cut(w, body, k, axis.multiply_scalar(8.0), Vector3(0.0, 0.0, degrees))
            k += 1
        for degrees in [90.0, -90.0]:
            let phi = degrees * math.pi / 180.0
            body = cut(w, body, k, Vector3(0.0, math.cos(phi), math.sin(phi)).multiply_scalar(8.0), Vector3(degrees, 0.0, 0.0))
            k += 1
        look(w, 0.6, 0.45, 42.0, Vector3())
    elif scene == "kernel_tee":
        node_commands.add_node(w, "Solid Cylinder", 40.0, 40.0)
        node_commands.set_parameter(w, 0, 5.0)
        node_commands.set_parameter(w, 1, 40.0)
        node_commands.add_node(w, "Transform", 40.0, 140.0)
        node_commands.set_parameter(w, 6, 90.0)
        let pipe = w.network.selected
        node_commands.add_node(w, "Solid Cylinder", 240.0, 40.0)
        node_commands.set_parameter(w, 0, 3.0)
        node_commands.set_parameter(w, 1, 15.0)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 2, 7.5)
        let branch = w.network.selected
        node_commands.select_node(w, pipe)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.connect(w, branch, w.network.selected, 1)
        let tee = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, tee).geometry, 0)
        let saddle: list[int] = []
        for face in 0..<model.face_count():
            for use in 0..<model.face_edge_count(face):
                let a = model.face_edge_point(face, use, 0.0)
                let m = model.face_edge_point(face, use, 0.5)
                let edge = model.face_edge_id(face, use)
                if math.abs(math.hypot(a.x, a.z) - 3.0) < 1e-6 and math.abs(math.hypot(m.x, m.z) - 3.0) < 1e-6 and a.y > 1.0 and a.y < 5.5 and m.y < 5.5 and not (edge in saddle):
                    saddle.append(edge)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, saddle))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.0)
        look(w, 0.7, 0.55, 30.0, Vector3(0.0, 4.0, 0.0))
    elif scene == "kernel_six_holes":
        node_commands.add_node(w, "Solid Sphere", 40.0, 40.0)
        node_commands.set_parameter(w, 0, 10.0)
        var body = w.network.selected
        var k = 0
        for axis in [Vector3(1.0, 0.0, 0.0), Vector3(-1.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), Vector3(0.0, -1.0, 0.0), Vector3(0.0, 0.0, 1.0), Vector3(0.0, 0.0, -1.0)]:
            let turn = Vector3(90.0 if axis.z != 0.0 else 0.0, 0.0, 90.0 if axis.x != 0.0 else 0.0)
            body = cut(w, body, k, axis.multiply_scalar(8.0), turn)
            k += 1
        look(w, 0.6, 0.5, 42.0, Vector3())
    elif scene == "kernel_crossed_pipes":
        node_commands.add_node(w, "Solid Cylinder", 40.0, 40.0)
        node_commands.set_parameter(w, 0, 5.0)
        node_commands.set_parameter(w, 1, 30.0)
        let first = w.network.selected
        node_commands.add_node(w, "Solid Cylinder", 240.0, 40.0)
        node_commands.set_parameter(w, 0, 5.0)
        node_commands.set_parameter(w, 1, 30.0)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 6, 90.0)
        let second = w.network.selected
        node_commands.select_node(w, first)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.connect(w, second, w.network.selected, 1)
        look(w, 0.7, 0.6, 55.0, Vector3())
    elif scene == "kernel_coincident":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let box = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, box).geometry, 0)
        let uprights: list[int] = []
        for face in 0..<model.face_count():
            for use in 0..<model.face_edge_count(face):
                let a = model.face_edge_point(face, use, 0.0)
                let b = model.face_edge_point(face, use, 1.0)
                let edge = model.face_edge_id(face, use)
                if math.abs(a.x - b.x) < 1e-9 and math.abs(a.z - b.z) < 1e-9 and not (edge in uprights):
                    uprights.append(edge)
        node_commands.add_node(w, "Fillet", 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, uprights))
        node_commands.set_parameter(w, cad_blends.size_slot, 5.0)
        node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0)
        let rounded = w.network.selected
        node_commands.add_node(w, "Transform", 240.0, 240.0)
        node_commands.set_parameter(w, 2, 10.0)
        let copy = w.network.selected
        node_commands.select_node(w, rounded)
        node_commands.add_node(w, "Combine", 40.0, 340.0)
        node_commands.connect(w, copy, w.network.selected, 1)
        look(w, 0.6, 0.35, 75.0, Vector3(0.0, 5.0, 0.0))
    elif scene == "kernel_shell":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let box = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, box).geometry, 0)
        let uprights: list[int] = []
        for face in 0..<model.face_count():
            for use in 0..<model.face_edge_count(face):
                let a = model.face_edge_point(face, use, 0.0)
                let b = model.face_edge_point(face, use, 1.0)
                let edge = model.face_edge_id(face, use)
                if math.abs(a.x - b.x) < 1e-9 and math.abs(a.z - b.z) < 1e-9 and not (edge in uprights):
                    uprights.append(edge)
        node_commands.add_node(w, "Fillet", 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, uprights))
        node_commands.set_parameter(w, cad_blends.size_slot, 5.0)
        node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0)
        let rounded = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        var top = ""
        for face in 0..<rounded.face_count():
            let name = CadModeling.face_name_of(rounded, face)
            let at = CadModeling.face_point(rounded, name)
            if at.found and at.normal.y > 0.999 and at.point.y > 9.0: top = name
        node_commands.add_node(w, "Shell", 40.0, 240.0)
        node_commands.set_text(w, 0, top)
        look(w, 0.6, 0.7, 70.0, Vector3(0.0, 2.0, 0.0))
    elif scene == "kernel_overflow":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        node_commands.set_parameter(w, 1, 4.0)
        let plate = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, plate).geometry, 0)
        let top_edge: list[int] = []
        for face in 0..<model.face_count():
            for use in 0..<model.face_edge_count(face):
                let a = model.face_edge_point(face, use, 0.0)
                let b = model.face_edge_point(face, use, 1.0)
                let edge = model.face_edge_id(face, use)
                if math.abs(a.x - 10.0) < 1e-9 and math.abs(b.x - 10.0) < 1e-9 and math.abs(a.y - 2.0) < 1e-9 and math.abs(b.y - 2.0) < 1e-9 and not (edge in top_edge):
                    top_edge.append(edge)
        node_commands.add_node(w, "Fillet", 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, top_edge))
        node_commands.set_parameter(w, cad_blends.size_slot, 5.0)
        node_commands.set_parameter(w, cad_blends.cliff_overflow_slot, 0.0)
        look(w, 0.9, 0.25, 45.0, Vector3(5.0, 0.0, 0.0))
    elif scene == "kernel_cliff_edge" or scene == "kernel_rolled_on":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        node_commands.set_parameter(w, 1, 4.0)
        var model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        let side_edge = func (a: Vector3, b: Vector3, y: float) -> bool:
            return math.abs(a.x - 10.0) < 1e-9 and math.abs(b.x - 10.0) < 1e-9 and math.abs(a.y - y) < 1e-9 and math.abs(b.y - y) < 1e-9
        var radius = 5.0
        if scene == "kernel_rolled_on":
            node_commands.add_node(w, "Fillet", 40.0, 140.0)
            node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
                return side_edge(a, b, -2.0))))
            node_commands.set_parameter(w, cad_blends.size_slot, 3.0)
            model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
            radius = 1.5
        node_commands.add_node(w, "Fillet", 40.0, 240.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return side_edge(a, b, 2.0))))
        node_commands.set_parameter(w, cad_blends.size_slot, radius)
        node_commands.set_parameter(w, cad_blends.more_slot, 1.0)
        if scene == "kernel_cliff_edge":
            look(w, 0.9, 0.25, 40.0, Vector3(6.0, 0.0, 0.0))
        else:
            look(w, 0.3, 0.2, 16.0, Vector3(9.0, 0.0, 6.0))
    elif scene == "kernel_y_boss" or scene == "kernel_y_boss_g2":
        let body = boss_on_plate(w)
        let model = CadGeometry.model(preview_support.cooked(w, body).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            let upright = a.x > 2.99 and b.x > 2.99 and a.z > 2.99 and b.z > 2.99 and a.y > 1.99 and b.y > 1.99
            let foot = math.abs(a.y - 2.0) < 1e-9 and math.abs(b.y - 2.0) < 1e-9 and math.abs(a.x - 3.0) < 1e-9 and math.abs(b.x - 3.0) < 1e-9 and math.abs(a.z) < 3.01 and math.abs(b.z) < 3.01
            return upright or foot)))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.0)
        node_commands.set_parameter(w, cad_blends.chain_slot, 0.0)
        if scene == "kernel_y_boss_g2": node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0)
        look(w, 0.75, 0.4, 13.0, Vector3(3.0, 3.0, 3.0))
    elif scene == "kernel_mixed_g2":
        let body = boss_on_plate(w)
        let model = CadGeometry.model(preview_support.cooked(w, body).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            let upright = a.x > 2.99 and b.x > 2.99 and a.z > 2.99 and b.z > 2.99 and a.y > 1.99 and b.y > 1.99
            let foot_x = math.abs(a.y - 2.0) < 1e-9 and math.abs(b.y - 2.0) < 1e-9 and math.abs(a.x - 3.0) < 1e-9 and math.abs(b.x - 3.0) < 1e-9 and math.abs(a.z) < 3.01 and math.abs(b.z) < 3.01
            let foot_z = math.abs(a.y - 2.0) < 1e-9 and math.abs(b.y - 2.0) < 1e-9 and math.abs(a.z - 3.0) < 1e-9 and math.abs(b.z - 3.0) < 1e-9 and math.abs(a.x) < 3.01 and math.abs(b.x) < 3.01
            return upright or foot_x or foot_z)))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.0)
        node_commands.set_parameter(w, cad_blends.chain_slot, 0.0)
        node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0)
        look(w, 0.75, 0.4, 13.0, Vector3(3.0, 3.0, 3.0))
    elif scene == "kernel_inside_rolled":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        node_commands.set_parameter(w, 1, 4.0)
        let plate = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 40.0)
        for (slot, value) in [(0, 4.0), (1, 2.0), (2, 20.0)]: node_commands.set_parameter(w, slot, value)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 1, -8.0)
        node_commands.set_parameter(w, 2, 3.0)
        let wall = w.network.selected
        node_commands.select_node(w, plate)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.connect(w, wall, w.network.selected, 1)
        var model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return math.abs(a.x + 6.0) < 1e-9 and math.abs(b.x + 6.0) < 1e-9 and math.abs(a.y - 4.0) < 1e-9 and math.abs(b.y - 4.0) < 1e-9)))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.5)
        model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 440.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return math.abs(a.x + 6.0) < 1e-9 and math.abs(b.x + 6.0) < 1e-9 and math.abs(a.y - 2.0) < 1e-9 and math.abs(b.y - 2.0) < 1e-9)))
        node_commands.set_parameter(w, cad_blends.size_slot, 3.0)
        node_commands.set_parameter(w, cad_blends.more_slot, 1.0)
        look(w, 0.25, 0.15, 22.0, Vector3(-6.0, 2.5, 6.0))
    elif scene == "kernel_notch_end":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let cube = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 40.0)
        for (slot, value) in [(0, 2.0), (1, 17.0), (2, 5.0)]: node_commands.set_parameter(w, slot, value)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        for (slot, value) in [(1, 9.0), (2, -1.5), (3, 7.5)]: node_commands.set_parameter(w, slot, value)
        let notch = w.network.selected
        node_commands.select_node(w, cube)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
        node_commands.connect(w, notch, w.network.selected, 1)
        let model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return math.abs(a.x - 10.0) < 1e-9 and math.abs(b.x - 10.0) < 1e-9 and math.abs(a.y - 10.0) < 1e-9 and math.abs(b.y - 10.0) < 1e-9)))
        node_commands.set_parameter(w, cad_blends.size_slot, 4.0)
        look(w, 0.9, 0.3, 40.0, Vector3(8.0, 6.0, 6.0))
    elif scene == "kernel_vertex_blend":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let cube = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 40.0)
        for (slot, value) in [(0, 10.0), (1, 22.0), (2, 10.0)]: node_commands.set_parameter(w, slot, value)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 1, 5.0)
        node_commands.set_parameter(w, 3, 5.0)
        let notch = w.network.selected
        node_commands.select_node(w, cube)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
        node_commands.connect(w, notch, w.network.selected, 1)
        let model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            let inside = math.abs(a.x) < 1e-9 and math.abs(b.x) < 1e-9 and math.abs(a.z) < 1e-9 and math.abs(b.z) < 1e-9
            let top_x = math.abs(a.y - 10.0) < 1e-9 and math.abs(b.y - 10.0) < 1e-9 and math.abs(a.z) < 1e-9 and math.abs(b.z) < 1e-9 and a.x > -1e-9 and b.x > -1e-9
            let top_z = math.abs(a.y - 10.0) < 1e-9 and math.abs(b.y - 10.0) < 1e-9 and math.abs(a.x) < 1e-9 and math.abs(b.x) < 1e-9 and a.z > -1e-9 and b.z > -1e-9
            return inside or top_x or top_z)))
        node_commands.set_parameter(w, cad_blends.size_slot, 2.0)
        node_commands.set_parameter(w, cad_blends.chain_slot, 0.0)
        node_commands.set_parameter(w, cad_blends.fillet_corner_slot, 1.0)
        node_commands.set_parameter(w, cad_blends.more_slot, 1.0)
        look(w, 0.6, 0.45, 30.0, Vector3(1.5, 7.0, 1.5))
    elif scene == "kernel_y_ell":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let cube = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 40.0)
        for (slot, value) in [(0, 10.0), (1, 22.0), (2, 10.0)]: node_commands.set_parameter(w, slot, value)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 1, 5.0)
        node_commands.set_parameter(w, 3, 5.0)
        let notch = w.network.selected
        node_commands.select_node(w, cube)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
        node_commands.connect(w, notch, w.network.selected, 1)
        let model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            let inside = math.abs(a.x) < 1e-9 and math.abs(b.x) < 1e-9 and math.abs(a.z) < 1e-9 and math.abs(b.z) < 1e-9
            let top = math.abs(a.y - 10.0) < 1e-9 and math.abs(b.y - 10.0) < 1e-9 and math.abs(a.z) < 1e-9 and math.abs(b.z) < 1e-9 and a.x > -1e-9 and b.x > -1e-9
            return inside or top)))
        node_commands.set_parameter(w, cad_blends.size_slot, 2.0)
        node_commands.set_parameter(w, cad_blends.chain_slot, 0.0)
        look(w, 0.6, 0.45, 30.0, Vector3(1.5, 7.0, 1.5))
    elif scene == "kernel_cliff":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        node_commands.set_parameter(w, 1, 4.0)
        let plate = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 40.0)
        node_commands.set_parameter(w, 0, 10.0)
        node_commands.set_parameter(w, 1, 4.0)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 1, 10.0)
        node_commands.set_parameter(w, 2, -4.0)
        let ledge = w.network.selected
        node_commands.select_node(w, plate)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.connect(w, ledge, w.network.selected, 1)
        let body = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, body).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return math.abs(a.x - 10.0) < 1e-9 and math.abs(b.x - 10.0) < 1e-9 and math.abs(a.y - 2.0) < 1e-9 and math.abs(b.y - 2.0) < 1e-9)))
        node_commands.set_parameter(w, cad_blends.size_slot, 5.0)
        node_commands.set_parameter(w, cad_blends.cliff_overflow_slot, 0.0)
        look(w, 0.9, 0.3, 55.0, Vector3(8.0, -2.0, 0.0))
    elif scene == "kernel_rounded_shell":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let box = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, box).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return true)))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.0)
        let rounded = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Shell", 40.0, 240.0)
        node_commands.set_text(w, 0, top_face(rounded, 9.0))
        node_commands.set_parameter(w, edit_cad_faces.thickness_slot, 2.0)
        # Smooth all over, the body is one tangent chain: the top alone.
        node_commands.set_parameter(w, edit_cad_faces.shell_chain_slot, 0.0)
        look(w, 0.6, 0.75, 60.0, Vector3(0.0, 2.0, 0.0))
    elif scene == "kernel_apex" or scene == "kernel_apex_g1":
        let pyramid = oblong_pyramid(w)
        let model = CadGeometry.model(preview_support.cooked(w, pyramid).geometry, 0)
        let every = scene == "kernel_apex"
        node_commands.add_node(w, "Fillet", 40.0, 640.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return every or a.y > 14.99 or b.y > 14.99)))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.0)
        node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0 if every else 0.0)
        look(w, 0.7, 0.35, 9.0, Vector3(0.0, 12.5, 0.0))
    elif scene == "kernel_moved_top":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let box = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, box).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return math.abs(a.x - b.x) < 1e-9 and math.abs(a.z - b.z) < 1e-9)))
        node_commands.set_parameter(w, cad_blends.size_slot, 5.0)
        node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0)
        let rounded = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Offset Face", 40.0, 240.0)
        node_commands.set_text(w, 0, top_face(rounded, 9.0))
        node_commands.set_parameter(w, 0, 5.0)
        look(w, 0.6, 0.35, 75.0, Vector3(0.0, 3.0, 0.0))
    elif scene == "kernel_healed_corner":
        node_commands.add_node(w, "Solid Cylinder", 40.0, 40.0)
        node_commands.set_parameter(w, 0, 10.0)
        node_commands.set_parameter(w, 1, 20.0)
        let pipe = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 40.0)
        node_commands.set_parameter(w, 0, 10.0)
        node_commands.set_parameter(w, 1, 8.0)
        node_commands.set_parameter(w, 2, 8.0)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 1, 12.0)
        let boss = w.network.selected
        node_commands.select_node(w, pipe)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.connect(w, boss, w.network.selected, 1)
        let body = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(body, edges_along(body, func (a: Vector3, b: Vector3) -> bool:
            return math.abs(a.x - b.x) < 1e-9 and math.abs(a.z - b.z) < 1e-9 and math.abs(a.y - b.y) > 1e-6 and a.x < 10.0 and a.x > 9.0)))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.0)
        let rounded = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        # The rounds: the faces the fillet made.
        let before: list[str] = []
        for face in 0..<body.face_count(): before.append(CadModeling.face_name_of(body, face))
        var rounds = ""
        for face in 0..<rounded.face_count():
            let name = CadModeling.face_name_of(rounded, face)
            if not (name in before): rounds = name if rounds == "" else rounds + ";" + name
        node_commands.add_node(w, "Delete Face", 40.0, 440.0)
        node_commands.set_text(w, 0, rounds)
        look(w, 0.35, 0.45, 48.0, Vector3(9.0, 0.0, 0.0))
    elif scene == "kernel_thin_stitch":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        node_commands.set_parameter(w, 1, 0.002)
        let plate = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, edit_cad_surfaces.unstitch_verb, 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.face_name_of(plate, 0))
        node_commands.add_node(w, edit_cad_surfaces.stitch_verb, 40.0, 240.0)
        node_commands.set_parameter(w, edit_cad_surfaces.gap_slot, 0.003)
        look(w, 0.6, 0.45, 40.0, Vector3())
    elif scene == "kernel_g2_shell":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let box = w.network.selected
        let model = CadGeometry.model(preview_support.cooked(w, box).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return true)))
        node_commands.set_parameter(w, cad_blends.size_slot, 3.0)
        node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0)
        let rounded = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Shell", 40.0, 240.0)
        node_commands.set_text(w, 1, CadModeling.face_name_of(rounded, 0))
        let shell = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 140.0)
        for slot in 0..<3: node_commands.set_parameter(w, slot, 40.0)
        node_commands.add_node(w, "Transform", 240.0, 240.0)
        node_commands.set_parameter(w, 3, 20.0)
        let cutter = w.network.selected
        node_commands.select_node(w, shell)
        node_commands.add_node(w, "Combine", 40.0, 340.0)
        node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
        node_commands.connect(w, cutter, w.network.selected, 1)
        look(w, 0.5, 0.45, 55.0, Vector3())
    elif scene == "kernel_three_sided":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 140.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return a.subtract(Vector3(10.0, 10.0, 10.0)).length() < 1e-9 or b.subtract(Vector3(10.0, 10.0, 10.0)).length() < 1e-9)))
        node_commands.set_parameter(w, cad_blends.size_slot, 4.0)
        node_commands.set_parameter(w, cad_blends.chain_slot, 0.0)
        node_commands.set_parameter(w, cad_blends.continuity_slot, 1.0)
        look(w, 0.75, 0.6, 26.0, Vector3(6.0, 6.0, 6.0))
    elif scene == "kernel_ell_shell":
        node_commands.add_node(w, "Solid Box", 40.0, 40.0)
        let cube = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 40.0)
        for (slot, value) in [(0, 10.0), (1, 22.0), (2, 10.0)]: node_commands.set_parameter(w, slot, value)
        node_commands.add_node(w, "Transform", 240.0, 140.0)
        node_commands.set_parameter(w, 1, 5.0)
        node_commands.set_parameter(w, 3, 5.0)
        let notch = w.network.selected
        node_commands.select_node(w, cube)
        node_commands.add_node(w, "Combine", 40.0, 240.0)
        node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
        node_commands.connect(w, notch, w.network.selected, 1)
        let model = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Fillet", 40.0, 340.0)
        node_commands.set_text(w, 0, CadModeling.edge_references(model, edges_along(model, func (a: Vector3, b: Vector3) -> bool:
            return true)))
        node_commands.set_parameter(w, cad_blends.size_slot, 1.0)
        node_commands.set_parameter(w, cad_blends.chain_slot, 0.0)
        let rounded = CadGeometry.model(preview_support.cooked(w, w.network.selected).geometry, 0)
        node_commands.add_node(w, "Shell", 40.0, 440.0)
        node_commands.set_text(w, 1, CadModeling.face_name_of(rounded, 0))
        node_commands.set_parameter(w, edit_cad_faces.thickness_slot, 2.0)
        let shell = w.network.selected
        node_commands.add_node(w, "Solid Box", 240.0, 340.0)
        for slot in 0..<3: node_commands.set_parameter(w, slot, 40.0)
        node_commands.add_node(w, "Transform", 240.0, 440.0)
        node_commands.set_parameter(w, 2, 20.0)
        let cutter = w.network.selected
        node_commands.select_node(w, shell)
        node_commands.add_node(w, "Combine", 40.0, 540.0)
        node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
        node_commands.connect(w, cutter, w.network.selected, 1)
        look(w, 0.55, 0.85, 36.0, Vector3(0.0, -4.0, 0.0))
    node_commands.display_selected(w)

## The edges of `model` from `a` to `b` that `keep` takes, each once.
func edges_along(model: CadModel, keep: func(Vector3, Vector3) -> bool) -> list[int]!:
    let found: list[int] = []
    for face in 0..<model.face_count():
        for use in 0..<model.face_edge_count(face):
            let edge = model.face_edge_id(face, use)
            if keep(model.face_edge_point(face, use, 0.0), model.face_edge_point(face, use, 1.0)) and not (edge in found):
                found.append(edge)
    return found

## A 20 x 4 x 20 plate with a 6 cube boss on it (y 2 to 8), joined: the
## Combine node, selected.
func boss_on_plate(w: Workspace) -> int!:
    node_commands.add_node(w, "Solid Box", 40.0, 40.0)
    node_commands.set_parameter(w, 1, 4.0)
    let plate = w.network.selected
    node_commands.add_node(w, "Solid Box", 240.0, 40.0)
    for slot in 0..<3: node_commands.set_parameter(w, slot, 6.0)
    node_commands.add_node(w, "Transform", 240.0, 140.0)
    node_commands.set_parameter(w, 2, 5.0)
    let boss = w.network.selected
    node_commands.select_node(w, plate)
    node_commands.add_node(w, "Combine", 40.0, 240.0)
    node_commands.connect(w, boss, w.network.selected, 1)
    return w.network.selected

## The name of `model`'s face facing up above `height`.
func top_face(model: CadModel, height: float) -> str!:
    for face in 0..<model.face_count():
        let name = CadModeling.face_name_of(model, face)
        let at = CadModeling.face_point(model, name)
        if at.found and at.normal.y > 0.999 and at.point.y > height: return name
    return ""

## A pyramid over a 20 by 12 base at y = 0, its apex at y = 15 (the
## study's F8b): a box less four blocks beyond its sides; the last Combine.
func oblong_pyramid(w: Workspace) -> int!:
    node_commands.add_node(w, "Solid Box", 40.0, 40.0)
    node_commands.set_parameter(w, 1, 15.0)
    node_commands.set_parameter(w, 2, 12.0)
    node_commands.add_node(w, "Transform", 40.0, 140.0)
    node_commands.set_parameter(w, 2, 7.5)
    var body = w.network.selected
    let alpha = math.atan2(10.0, 15.0)
    let beta = math.atan2(6.0, 15.0)
    let cuts = [(Vector3(10.0, 0.0, 0.0), Vector3(math.cos(alpha), math.sin(alpha), 0.0), Vector3(0.0, 0.0, alpha)),
                (Vector3(-10.0, 0.0, 0.0), Vector3(-math.cos(alpha), math.sin(alpha), 0.0), Vector3(0.0, 0.0, -alpha)),
                (Vector3(0.0, 0.0, 6.0), Vector3(0.0, math.sin(beta), math.cos(beta)), Vector3(-beta, 0.0, 0.0)),
                (Vector3(0.0, 0.0, -6.0), Vector3(0.0, math.sin(beta), -math.cos(beta)), Vector3(beta, 0.0, 0.0))]
    var k = 0
    for (at, out, turn) in cuts:
        let x = 240.0 + float(k) * 120.0
        node_commands.add_node(w, "Solid Box", x, 40.0)
        for slot in 0..<3: node_commands.set_parameter(w, slot, 60.0)
        node_commands.add_node(w, "Transform", x, 140.0)
        let centre = at.add(out.multiply_scalar(30.0))
        let degrees = turn.multiply_scalar(180.0 / math.pi)
        for (slot, value) in [(1, centre.x), (2, centre.y), (3, centre.z), (4, degrees.x), (5, degrees.y), (6, degrees.z)]:
            node_commands.set_parameter(w, slot, value)
        let tool = w.network.selected
        node_commands.select_node(w, body)
        node_commands.add_node(w, "Combine", 40.0, 240.0 + float(k) * 100.0)
        node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
        node_commands.connect(w, tool, w.network.selected, 1)
        body = w.network.selected
        k += 1
    return body

pub func act(editor: Luce3D, scene: str, frame: int, last: int) -> unit!:
    _ = editor
    _ = scene
    _ = frame
    _ = last

## `body` less cylinder `k` (radius 2, 8 long) turned by `turn` degrees and
## moved to `at`: the Combine node, selected.
func cut(w: Workspace, body: int, k: int, at: Vector3, turn: Vector3) -> int!:
    let x = 240.0 + float(k) * 120.0
    node_commands.add_node(w, "Solid Cylinder", x, 40.0)
    node_commands.set_parameter(w, 0, 2.0)
    node_commands.set_parameter(w, 1, 8.0)
    node_commands.add_node(w, "Transform", x, 140.0)
    for (slot, value) in [(1, at.x), (2, at.y), (3, at.z), (4, turn.x), (5, turn.y), (6, turn.z)]:
        node_commands.set_parameter(w, slot, value)
    let tool = w.network.selected
    node_commands.select_node(w, body)
    node_commands.add_node(w, "Combine", 40.0, 140.0 + float(k) * 100.0)
    node_commands.set_parameter(w, edit_cad_faces.combine_slot, 1.0)
    node_commands.connect(w, tool, w.network.selected, 1)
    return w.network.selected

func look(w: Workspace, yaw: float, pitch: float, distance: float, target: Vector3) -> unit!:
    w.view.yaw = yaw
    w.view.pitch = pitch
    w.view.distance = distance
    w.view.target = target
    w.view.update_camera()