Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.8

0.11.8 / tools / preview_fill.luc

## The captures of the surfacing plan's Stage 7, Fill Surface (preview_build.luc
## hands these scenes here):
##   surf_fill_waiting: an open box's top edge picked and Fill Surface started:
##     the whole hole taken, Quad G1, still waiting for boundaries; the
##     picks lit, a label on each boundary, the four corners' conflicts red.
##   surf_fill_quad: the same finished (a pillow on the walls), Continuity
##     Check on (try --mode 7 for zebra stripes across the walls).
##   surf_fill_lid: the same close up from above, its labels and the check
##     off, zebra stripes about X (try --mode 7: the stripes run smoothly
##     into the corners, where the fill turns onto the boundaries' plane).
##   surf_fill_lid_g2: the same at G2.
##   surf_fill_molded: the same lid N-sided (one trimmed face), its domain
##     Molded by Auto (the walls stand square to the hole's plane).
##   surf_fill_nsided: five wavy curves round a pentagon filled N-sided G1
##     to nothing but their positions (G0) through a bowed guide curve: one
##     trimmed face.
##   surf_fill_node: a CAD network's Fill Surface node on a box with its top
##     taken away, and its rows.
## And Stage 6's follow-ups:
##   surf_fillet_variable: Surface Fillet between a box's top and side,
##     Bias -0.4, its radius growing from 0.2 to 0.6 along the edge (try
##     --mode 7 for zebra across its contacts).
import tool_picks
import tool_run
import preview_support
import preview_blend
from luce_3d.graphics import Vector3
from app import Luce3D
import node_commands
import modeling_commands
import selection_commands
import edit_cad_surfaces
import blend_ops
import fill_ops
from luce_cad.cad_geometry import CadGeometry
from luce_cad.modeling import CadModeling
from luce_std import math

pub func scenes() -> list[str]:
    return ["surf_fill_waiting", "surf_fill_quad", "surf_fill_lid", "surf_fill_lid_g2", "surf_fill_molded", "surf_fill_nsided", "surf_fill_node", "surf_fillet_variable"]

## Scene `scene` before its first frame.
pub func setup(editor: Luce3D, scene: str) -> unit!:
    let w = editor.workspace
    if scene == "surf_fill_waiting" or scene == "surf_fill_quad" or scene.starts_with("surf_fill_lid") or scene == "surf_fill_molded":
        preview_blend.open_box(editor)
        preview_blend.click_edge(w, func (c: Vector3, n: Vector3) -> bool: return preview_blend.top_side(c, n, 0))
        tool_run.run(w, blend_ops.fill_verb)
        preview_support.settle(w)
        modeling_commands.set_last_step(w, fill_ops.quad_slot, 0.0 if scene == "surf_fill_molded" else 1.0, 0.0, 1.0)
        preview_support.settle(w)
        if scene != "surf_fill_waiting":
            let node = w.selected() else trap("no node")
            tool_picks.accept(w)
            preview_support.settle(w)
            tool_picks.accept(w)
            preview_support.settle(w)
            modeling_commands.set_last_step(w, fill_ops.continuity_slot, 3.0 if scene == "surf_fill_lid_g2" else 2.0, 0.0, 3.0)
            preview_support.settle(w)
        if scene.starts_with("surf_fill_lid") or scene == "surf_fill_molded":
            modeling_commands.set_last_step(w, fill_ops.labels_slot, 0.0, 0.0, 1.0)
            modeling_commands.set_last_step(w, fill_ops.check_slot, 0.0, 0.0, 1.0)
            preview_support.settle(w)
            # Stripes about X: about Y (the default) every dome shows the
            # cylinder's pole where its normal points up.
            w.display.zebra_axis = 0
            preview_blend.look(editor, 0.75, 0.8, 5.0, Vector3(0.0, 0.7, 0.0))
        else:
            preview_blend.look(editor, 0.75, 0.5, 7.5, Vector3(0.0, 0.6, 0.0))
    elif scene == "surf_fill_nsided":
        preview_blend.edit_cad(editor)
        # Five wavy sides round a pentagon, and a guide bowed above its
        # middle.
        let corners: list[Vector3] = []
        for k in 0..<5:
            let a = 2.0 * math.pi * float(k) / 5.0 + 0.3
            corners.append(Vector3(2.0 * math.cos(a), 0.25 * math.sin(3.0 * a), 2.0 * math.sin(a)))
        for k in 0..<5:
            let a = corners[k]
            let b = corners[(k + 1) % 5]
            let middle = a.add(b).multiply_scalar(0.5).add(Vector3(0.0, 0.3 if k % 2 == 0 else -0.2, 0.0))
            preview_blend.cv_curve(w, [a, a.multiply_scalar(0.7).add(middle.multiply_scalar(0.3)), middle, b.multiply_scalar(0.7).add(middle.multiply_scalar(0.3)), b])
        preview_blend.cv_curve(w, [Vector3(-1.0, 0.3, -0.2), Vector3(0.0, 0.9, 0.0), Vector3(1.0, 0.4, 0.2)])
        selection_commands.set_mode(w, 6)
        preview_support.settle(w)
        let mesh = preview_support.shown(w) else trap("no pick mesh")
        let names = mesh.find_attribute("cad_curve_name", 4)
        let order: list[str] = []
        let first: list[int] = []
        for edge in 0..<mesh.edge_count():
            let name = mesh.attribute_text(names, edge)
            if name != "" and not (name in order):
                order.append(name)
                first.append(edge)
        for k in 0..<5:
            selection_commands.choose_component(w, first[k], k > 0)
        preview_support.settle(w)
        tool_run.run(w, blend_ops.fill_verb)
        preview_support.settle(w)
        modeling_commands.set_last_step(w, fill_ops.continuity_slot, 1.0, 0.0, 3.0)
        let node = w.selected() else trap("no node")
        tool_picks.accept(w)
        preview_support.settle(w)
        selection_commands.choose_component(w, first[5], false)
        preview_support.settle(w)
        tool_picks.accept(w)
        preview_support.settle(w)
        preview_blend.look(editor, 0.6, 1.1, 8.0, Vector3(0.0, 0.2, 0.0))
    elif scene == "surf_fillet_variable":
        preview_blend.squares(editor)
        selection_commands.set_mode(w, 3)
        preview_support.settle(w)
        let mesh = preview_support.shown(w) else trap("no pick mesh")
        for wanted in [0, 1]:
            for polygon in 0..<mesh.face_count():
                let c = mesh.face_center(polygon)
                let n = mesh.face_normal(polygon)
                if (wanted == 0 and c.y > 0.99 and n.y > 0.99) or (wanted == 1 and c.x > 0.99 and n.x > 0.99):
                    selection_commands.choose_component(w, polygon, false)
                    break
            preview_support.settle(w)
            if wanted == 0:
                tool_run.run(w, blend_ops.fillet_verb)
                preview_support.settle(w)
        let node = w.selected() else trap("no node")
        tool_picks.accept(w)
        preview_support.settle(w)
        modeling_commands.set_last_step(w, blend_ops.size_slot, 0.2, 0.0, 100.0)
        modeling_commands.set_last_step(w, blend_ops.section_slot, 4.0, 0.0, 5.0)
        modeling_commands.set_last_step(w, blend_ops.bias_slot, -0.4, -1.0, 1.0)
        modeling_commands.set_last_step(w, blend_ops.variable_slot, 1.0, 0.0, 1.0)
        modeling_commands.set_last_step(w, blend_ops.variable_slot + 2, 0.6, 0.0, 100.0)
        preview_support.settle(w)
        preview_blend.look(editor, 0.75, 0.45, 7.0, Vector3(0.3, 0.3, 0.0))
    elif scene == "surf_fill_node":
        node_commands.delete_selected(w)
        node_commands.add_node(w, "CAD", 40.0, 40.0)
        node_commands.enter_group(w, w.network.selected)
        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 top = preview_blend.facing(model, Vector3(0.0, 1.0, 0.0))
        let plus = preview_blend.facing(model, Vector3(1.0, 0.0, 0.0))
        let height = CadModeling.face_point(model, top).point.y
        let reach = CadModeling.face_point(model, plus).point.x
        node_commands.add_node(w, edit_cad_surfaces.unstitch_verb, 40.0, 100.0)
        node_commands.set_text(w, 0, top)
        node_commands.add_node(w, "Remove", 40.0, 160.0)
        node_commands.set_text(w, 0, top)
        node_commands.add_node(w, blend_ops.fill_verb, 40.0, 220.0)
        node_commands.set_text(w, fill_ops.boundaries_text, f"edge {plus} {reach} {height} 0")
        node_commands.set_parameter(w, fill_ops.quad_slot, 1.0)
        node_commands.display_selected(w)
        preview_support.settle(w)
        preview_blend.look(editor, 0.7, 0.45, 80.0, Vector3(0.0, 18.0, 0.0))
    editor.panels.refresh()