Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.9

0.11.9 / src / tool_mirror_body.luc

## Mirror Body: the bodies reflected across the plane through the origin
## facing X, Y or Z, joined or kept apart; the copy's faces named apart from
## the original's. A node of a CAD network.
from luce_cad.cad_geometry import CadGeometry
from luce_cad.modeling import CadModeling
from luce_3d.graphics import Vector3
from tool_record import Tool, ToolEntry, Pick, Invocation
from geometry_data import GeometryData
from parameter_rows import Parameter, toggle, menu
import cad_cook

pub func entry() -> ToolEntry:
    return ToolEntry("Mirror Body", "Mirror Body", "mirror-modifier", "Modify", [cad_cook.context], [], made)

func made() -> Tool:
    let none_picked: list[Pick] = []
    return entry().tool("Modify", "Bodies", "Reflect the bodies across an origin plane, joined or apart", none_picked, rows(), cook)

func cook(call: Invocation, data: GeometryData, tag: str) -> GeometryData!:
    let v = call.numbers
    let body = cad_cook.body_of(data, "first")
    let axis = int(v[0])
    let flip = Vector3(-1.0 if axis == 0 else 1.0, -1.0 if axis == 1 else 1.0, -1.0 if axis == 2 else 1.0)
    # The copy's faces named apart from the original's.
    let reflected = CadModeling.prefixed(body, f"{tag}.1:").transformed(Vector3(), Vector3(), flip)
    if v[1] != 0.0:
        return GeometryData(geometry = CadGeometry.of_model(body)).merged(GeometryData(geometry = CadGeometry.of_model(reflected)))
    return GeometryData(geometry = CadGeometry.of_model(CadModeling.combined(body, reflected, 0)))

func rows() -> list[Parameter]:
    return [menu("Plane", 0, "YZ (across X)|ZX (across Y)|XY (across Z)", 0.0, "The plane through the origin the body is mirrored across."),
            toggle("Separate bodies", 1, 0.0, "Keep the mirror image a body of its own instead of joining it.")]